@formancy/report-render-pdf 0.1.0 → 0.3.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.
- package/NOTICE +8 -0
- package/README.md +907 -37
- package/dist/bill-fonts-B61mmaVd.mjs +16 -0
- package/dist/bill-fonts-B61mmaVd.mjs.map +1 -0
- package/dist/browser.d.mts +8 -3
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.mjs +90 -20
- package/dist/browser.mjs.map +1 -1
- package/dist/chart-draw-CUcWXjN9.mjs +1056 -0
- package/dist/chart-draw-CUcWXjN9.mjs.map +1 -0
- package/dist/index.d.mts +1 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +59 -23
- package/dist/index.mjs.map +1 -1
- package/dist/{options-wLxIWA87.d.mts → options-B7fd-ZYd.d.mts} +13 -3
- package/dist/options-B7fd-ZYd.d.mts.map +1 -0
- package/dist/render-D4q7IZ7I.mjs +5139 -0
- package/dist/render-D4q7IZ7I.mjs.map +1 -0
- package/fonts/AUTHORS-LiberationSans.txt +16 -0
- package/fonts/LICENSE-LiberationSans.txt +102 -0
- package/fonts/LiberationSans-Bold.ttf +0 -0
- package/fonts/LiberationSans-Regular.ttf +0 -0
- package/package.json +12 -7
- package/dist/options-wLxIWA87.d.mts.map +0 -1
- package/dist/render-Bs7DXIYJ.mjs +0 -1943
- package/dist/render-Bs7DXIYJ.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-D4q7IZ7I.mjs","names":["characterMap","readCharacterMap","characterMap","pageOf","wordOf","converterOptions","CROSS","pageOf","line","refusal","refusal","INSTRUCTION","CORNER","blocks","FIELD_GAP","TITLE","RECEIPT_WIDTH","SEPARATION","ACCEPTANCE","CODE"],"sources":["../src/glyphs.ts","../src/image-order.ts","../src/engine.ts","../src/style.ts","../src/bill.ts","../src/bytes.ts","../src/build.ts","../src/chart-content.ts","../src/qr.ts","../src/epc.ts","../src/words.ts","../src/shifted.ts","../src/svg-content.ts","../src/breaks.ts","../src/table-rules.ts","../src/widths.ts","../src/table.ts","../src/content.ts","../src/bound.ts","../src/chart-held.ts","../src/chart-option.ts","../src/chart-empty.ts","../src/chart-faces.ts","../src/check-faces.ts","../src/check-walk.ts","../src/check-chart.ts","../src/assets.ts","../src/e-invoice.ts","../src/pdfa-check.ts","../src/svg-pdfa.ts","../src/check-images.ts","../src/kept-rows.ts","../src/check-table.ts","../src/check.ts","../src/pdfa.ts","../src/slip.ts","../src/definition.ts","../src/face-identity.ts","../src/strip-layout.ts","../src/host-fonts.ts","../src/measure.ts","../src/render.ts"],"sourcesContent":["/**\n * Which characters the renderer can draw: those the faces it embeds map to\n * a glyph, read from each face's own character map.\n *\n * pdfmake, through fontkit, draws a character its font has no glyph for as\n * glyph 0 -- an empty box, or nothing -- and writes U+0000 to the text\n * layer, so the text is lost on the page and in a search alike, and the\n * render still succeeds: 'Customer: 山田太郎 様' printed as 'Customer: '\n * and a run of empty boxes. So every character a document prints is held to\n * the face it prints in before anything is laid out, and one the face has\n * no glyph for is refused as `unsupported`, naming the block and the\n * character. Fallback fonts, which would draw it, are plan section 19's,\n * and not built.\n *\n * The maps are read from the very bytes pdfmake embeds -- the font files in\n * Node, the virtual files in a browser -- so they cannot drift from the\n * fonts, and by report-spec's reader, through the runtime, which reads the\n * subtable fontkit lays text out with, in format 4 or 12 (0040): the one\n * reader of a font's glyphs, which a host's font will be read by too.\n * Roboto 3.014 maps the Basic Multilingual Plane only, in a format 4\n * subtable; a character past it, an emoji among them, has no glyph here.\n */\nimport { characterMap as readCharacterMap, type BillFace } from '@formancy/report-runtime'\n\n/** pdfmake's names for a family's four faces. */\nexport type Face = 'normal' | 'bold' | 'italics' | 'bolditalics'\n\n/** The characters each face has a glyph for, by code point. */\nexport type Glyphs = Readonly<Record<Face, ReadonlySet<number>>>\n\n/** The two faces of Liberation Sans a QR-bill's slip prints in (`style.ts`), its values, and its titles and headings: the runtime's, which names them for every engine. */\nexport type { BillFace }\n\n/** The characters each of them has a glyph for. */\nexport type BillGlyphs = Readonly<Record<BillFace, ReadonlySet<number>>>\n\n/** The face text in this weight and slant prints in. */\nexport function faceOf(bold: boolean, italic: boolean): Face {\n return bold ? (italic ? 'bolditalics' : 'bold') : italic ? 'italics' : 'normal'\n}\n\n/** A line break: pdfmake breaks the line there and draws nothing for it. */\nconst LINE_BREAKS: ReadonlySet<number> = new Set([0x0a, 0x0d])\n\n/** The first character of `text` that `face` has no glyph for, as its code point; undefined when it has a glyph for every one. */\nexport function missingGlyph(text: string, face: ReadonlySet<number>): number | undefined {\n for (const character of text) {\n const point = character.codePointAt(0) as number\n if (!face.has(point) && !LINE_BREAKS.has(point)) return point\n }\n return undefined\n}\n\n/** A code point as Unicode writes it: U+5C71. */\nexport function codePoint(point: number): string {\n return `U+${point.toString(16).toUpperCase().padStart(4, '0')}`\n}\n\n/**\n * The code points a font this renderer embeds maps to a glyph other than\n * glyph 0, as report-spec's `characterMap` reads them. A face the reader\n * refuses -- no character map, none in Unicode in format 4 or 12, one\n * broken -- is not one this renderer embeds, and is an error, not a\n * document's refusal.\n */\nexport function characterMap(font: Uint8Array): ReadonlySet<number> {\n const read = readCharacterMap(font)\n if (!read.ok) throw new Error(`the font ${read.message}`)\n return read.characters\n}\n","/**\n * The images PDFKit decodes before it embeds them, written in the order\n * pdfmake opened them, so that one document renders to the same bytes\n * however its decodes finish (0035).\n *\n * pdfmake opens each image as it lays the page out, in the document's\n * order, and PDFKit numbers the image's object then (pdfkit.js 3888). A\n * PNG with a palette's transparency, an alpha channel or interlacing is\n * decoded first, by png-js's `decodePixels`, whose inflate calls back\n * when it is done (pdfkit.js 3926-3931): in Node from libuv's thread pool,\n * in pdfmake's browser build from a timer. The callback calls\n * `this.finalize()` (3974, 3990, 3996), which numbers the soft mask and\n * writes the mask and the image (3935-3953). Left alone, then, both the\n * masks' numbers and where each image is written follow whichever decode\n * finishes first, and two renders of one document differed so.\n *\n * Each image still decoding when pdfmake hands the document over has its\n * `finalize` wrapped, for this document alone: an image whose decode has\n * finished waits for every one opened before it, and is written as soon\n * as they are. Nothing is renumbered and nothing written twice: PDFKit\n * writes every object itself, in the order its images were opened.\n *\n * It rests on what `written` hands it: PDFKit's document laid out and not\n * yet ended, before any decode has called back -- which none can, since\n * pdfmake lays the document out in one synchronous step after its last\n * await, and both callbacks wait for the event loop to turn. And on three\n * details of PDFKit 0.19.1, read and wrapped here and typed at the\n * boundary, as `pdfa.ts` types `file`: the registry pdfmake keeps the\n * images it opened in, by the names the renderer gives them, `image0`,\n * `image1`... (`content.ts`), which no array index is, so in the order it\n * added them, each embedded before it is added (`PDFDocument.js` 108-109)\n * and so decoding already if it decodes; a PNG's `image`, which is set\n * until the image is written; and `finalize`, called through `this`.\n *\n * A PDFKit within pdfmake's range that moved one of them meets one of two\n * ends. One that finds nothing still decoding, or an image it cannot\n * wrap, wraps none and leaves the images to be written as their decodes\n * finish: a report prints as it did in 0.2.0, in bytes that may vary. One\n * that kept `finalize` but called it otherwise than through `this` on one\n * of its three decodes would write that image unseen by its wrapper, and\n * every image opened after it would wait for it forever: the render would\n * never end. The install gate, which installs the PDFKit a host resolves,\n * draws an image of each of the three ahead of another, and fails on\n * either end.\n */\n\n/** One of PDFKit's images as pdfmake's registry holds it: a PNG, a JPEG (pdfkit.js 3807-3999). */\ninterface PdfKitImage {\n /** png-js's decoder of a PNG, set until `finalize` has written the image; a JPEG has none. */\n readonly image?: unknown\n /** Numbers the image's soft mask, if it has one, and writes the mask and the image. */\n finalize?: () => unknown\n}\n\n/** PDFKit's document as `written` receives it: the images pdfmake opened, by name, in the order it opened them (pdfmake's `PDFDocument.js` 77-110). */\nexport interface PdfKitImages {\n readonly _imageRegistry?: Readonly<Record<string, PdfKitImage>>\n}\n\n/** Has every image of `document` still decoding written in the order pdfmake opened it, whichever decode finishes first. */\nexport function finalizeInOrder(document: PdfKitImages): void {\n const decoding = Object.values(document._imageRegistry ?? {}).filter((image) => image.image != null)\n const finalizers = decoding.map((image) => image.finalize)\n // One left unwrapped would hold every image after it forever, and the document would never end;\n // a wrapped one whose decode calls `finalize` past its wrapper would do the same, and is the install gate's to find.\n if (!finalizers.every((finalize) => typeof finalize === 'function')) return\n const decoded = new Set<number>()\n let next = 0\n decoding.forEach((image, at) => {\n image.finalize = () => {\n decoded.add(at)\n for (; decoded.has(next); next += 1) finalizers[next]!.call(decoding[next])\n }\n })\n}\n","import type { TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport { characterMap, type BillFace, type BillGlyphs, type Face, type Glyphs } from './glyphs.js'\nimport type { HostFontFiles } from './host-fonts.js'\nimport { finalizeInOrder, type PdfKitImages } from './image-order.js'\nimport type { Finish, PdfKitDocument } from './pdfa.js'\n\n/**\n * pdfmake with the renderer's fonts and access policies, as Node's entry\n * (`node.ts`) or the browser's (`browser-engine.ts`) configures it: what\n * runs a definition and returns the PDF's bytes, the characters the faces\n * it embeds have glyphs for, and the widths a chart's words are laid out by,\n * measured in those faces. Everything else a render does is the same in\n * both (`render.ts`).\n */\nexport interface Engine {\n /**\n * The PDF of `definition`, with `host`'s faces registered in pdfmake's\n * virtual files for this run and removed after it, whether it wrote a\n * PDF, measured or threw (0043). `finish`, where\n * given, acts on PDFKit's document once pdfmake has laid it out and before\n * it is ended, which is where an e-invoice's file and XMP are added\n * (`pdfa.ts`): only the final pass gives one, since a measuring pass\n * throws before its end.\n */\n readonly run: (definition: TDocumentDefinitions, host: HostFontFiles, finish?: Finish) => Promise<Uint8Array>\n /** Roboto's four faces, which a report's own text prints in. */\n readonly glyphs: () => Promise<Glyphs>\n /**\n * Liberation Sans's two faces, which a QR-bill's slip and an EPC QR\n * code's caption print in: read the first time a document has a payment\n * part or a captioned code, and in a browser loaded then, so that a host\n * that never prints either never loads them. Once they are read, `run`\n * has them for a document that prints them.\n */\n readonly billGlyphs: () => Promise<BillGlyphs>\n /**\n * `faces` opened for measuring a chart's words: from a document of the\n * entry's own pdfmake, its fonts and access policies set as `run` sets\n * them, each face opened at once with pdfmake's `provideFont` -- the\n * call a pass opens a text node's face with -- while `host`'s virtual\n * files are registered, and the files removed after, as `run` removes\n * them, whether every face opened or one threw (0043). The document holds\n * no content and is never ended, so it writes no PDF.\n */\n readonly widths: (host: HostFontFiles, faces: readonly MeasuredFace[]) => Promise<FaceWidths>\n}\n\n/** A face a chart's words are measured in: its pdfmake family, and which of the family's faces. */\nexport interface MeasuredFace {\n readonly family: string\n readonly face: Face\n}\n\n/** Widths as pdfmake measures them, in the faces `Engine.widths` opened. */\nexport interface FaceWidths {\n /**\n * The width of `text` at `size` in `family`'s `face`: PDFKit's\n * `widthOfString` of the face pdfmake opened. That is the width pdfmake\n * gives a text node it lays out without wrapping only for text with no\n * whitespace at either end and no tab: pdfmake cuts a run's leading and\n * trailing `\\s` -- no-break spaces among them -- out of its width, and\n * expands a tab to four spaces before it measures, and this does neither\n * (`engine.test.ts`). A word reaches it trimmed and without a tab, or is\n * measured apart from how pdfmake prints it. Throws for a face that was\n * not opened: its virtual file is gone by now.\n */\n width(family: string, face: Face, size: number, text: string): number\n}\n\n/** pdfmake's virtual file system, as both builds expose it: a plain `storage` object the renderer writes a host face into and removes after, since it has no delete (0043). */\nexport interface VirtualFs {\n readonly storage: Record<string, unknown>\n}\n\n/**\n * Writes `host`'s faces into `virtualfs` for one pass and returns the\n * cleanup that removes them: pdfmake's virtual files are process-wide and\n * have no delete, so each pass adds its render's host faces and takes them\n * out again, and a process holds the faces of the renders in flight and no\n * other. The names are the render's own (`host-fonts.ts`), so a cleanup\n * removes no file another render still reads (0043).\n */\nexport function registerHostFonts(virtualfs: VirtualFs, host: HostFontFiles): () => void {\n for (const [name, bytes] of host.files) virtualfs.storage[name] = bytes\n return () => {\n for (const name of host.files.keys()) delete virtualfs.storage[name]\n }\n}\n\n/** Roboto's faces, as pdfmake names them. */\nexport const FACES: readonly Face[] = ['normal', 'bold', 'italics', 'bolditalics']\n\n/** Liberation Sans's, as pdfmake names them. */\nexport const BILL_FACES: readonly BillFace[] = ['normal', 'bold']\n\n/**\n * What `load` loads, loaded by the first call and kept for every call after\n * it: the fonts do not change while the process or the page runs. Calls made\n * while it loads share the one load. A load that fails is not kept: the\n * calls that shared it fail, and the next call loads again, so that a file\n * the process could not open just then, or a chunk the browser could not\n * fetch, fails the documents that asked for it and no document after.\n */\nexport function loadOnce<T>(load: () => Promise<T>): () => Promise<T> {\n let loading: Promise<T> | undefined\n return () =>\n (loading ??= load().catch((error: unknown) => {\n loading = undefined\n throw error\n }))\n}\n\n/** The glyphs of `faces`, from the bytes `read` reads for each. */\nexport async function glyphsOf<F extends string>(\n faces: readonly F[],\n read: (face: F) => Promise<Uint8Array>,\n): Promise<Readonly<Record<F, ReadonlySet<number>>>> {\n const maps = await Promise.all(faces.map(async (face) => [face, characterMap(await read(face))] as const))\n return Object.fromEntries(maps) as Record<F, ReadonlySet<number>>\n}\n\n/** The glyphs of `faces`, read by `read` the first time they are asked for and kept once every face has been read (`loadOnce`). */\nexport function glyphsOnce<F extends string>(\n faces: readonly F[],\n read: (face: F) => Promise<Uint8Array>,\n): () => Promise<Readonly<Record<F, ReadonlySet<number>>>> {\n return loadOnce(() => glyphsOf(faces, read))\n}\n\n/** PDFKit's document, as both of pdfmake's builds hand it out: a readable stream, ended to be written. */\nexport interface PdfStream {\n on(event: 'data', listener: (chunk: Uint8Array) => void): unknown\n on(event: 'end', listener: () => void): unknown\n on(event: 'error', listener: (error: unknown) => void): unknown\n end(): unknown\n}\n\n/**\n * The PDF of the document `getStream` hands over, `finish` acting on it\n * first: what each entry's `run` does once it has configured its pdfmake.\n * The images PDFKit is still decoding are written in the order pdfmake\n * opened them, whichever decode finishes first (`image-order.ts`, 0035).\n */\nexport async function written(document: Promise<unknown>, finish: Finish | undefined): Promise<Uint8Array> {\n const pdf = (await document) as PdfStream & PdfKitDocument & PdfKitImages\n finalizeInOrder(pdf)\n finish?.(pdf)\n return collect(pdf)\n}\n\n/** PDFKit's face as pdfmake's `provideFont` opens it, as far as measuring reads it. */\ninterface PdfKitFace {\n widthOfString(text: string, size: number): number\n}\n\n/** pdfmake's PDFKit document, as far as measuring reads it: what opens a face of its font table. */\ninterface FaceProvider {\n provideFont(family: string, bold: boolean, italics: boolean): PdfKitFace\n}\n\n/**\n * `faces` opened at once on the document `getStream` hands over, a document\n * of the entry's pdfmake made while the render's virtual files are\n * registered: what each entry's `widths` does once it has configured its\n * pdfmake, as `written` is what its `run` does.\n */\nexport async function faceWidths(document: Promise<unknown>, faces: readonly MeasuredFace[]): Promise<FaceWidths> {\n const pdf = (await document) as FaceProvider\n const opened = new Map(\n faces.map(({ family, face }) => [\n `${family}/${face}`,\n pdf.provideFont(family, face === 'bold' || face === 'bolditalics', face === 'italics' || face === 'bolditalics'),\n ]),\n )\n return {\n width: (family, face, size, text) => {\n const font = opened.get(`${family}/${face}`)\n if (font === undefined) throw new Error(`no face ${family} ${face} was opened for measuring`)\n return font.widthOfString(text, size)\n },\n }\n}\n\n/**\n * The PDF's bytes, read from PDFKit's stream. pdfmake's own `getBuffer`\n * listens for the end of the stream and never for an error, so a stream that\n * fails leaves its promise pending forever; this one rejects.\n */\nexport function collect(stream: PdfStream): Promise<Uint8Array> {\n return new Promise((resolve, reject) => {\n const chunks: Uint8Array[] = []\n stream.on('data', (chunk) => chunks.push(chunk))\n stream.on('error', reject)\n stream.on('end', () => {\n const bytes = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0))\n let offset = 0\n for (const chunk of chunks) {\n bytes.set(chunk, offset)\n offset += chunk.length\n }\n resolve(bytes)\n })\n stream.end()\n })\n}\n","import type { FontFamily, TextStyle } from '@formancy/report-runtime'\n\n/**\n * A document's text styles as pdfmake's: the one place a font token becomes\n * a font, and a style becomes pdfmake's properties.\n *\n * **Fonts.** pdfmake ships one family, Roboto 3.014, under the SIL Open Font\n * License 1.1, which allows embedding in documents\n * ([0006](../../../docs/decisions/0006-dependencies-and-fonts-allow-public-source-and-licensed-production.md)).\n * `sans` is Roboto. `serif` and `mono` have no font here, and a report that\n * asks for one is refused as `unsupported` before anything is laid out\n * (`check.ts`): printing it in Roboto would be a substitution nobody sees\n * until the PDF is read, which plan section 20 rules out. Bold is Roboto\n * Medium, the heaviest face pdfmake ships, and italic its italic.\n */\n\n/** pdfmake's name for the family a report's own text prints in. */\nexport const ROBOTO = 'Roboto'\n\n/**\n * pdfmake's name for Liberation Sans 2.1.5, under the SIL Open Font License\n * 1.1, which the package ships in its `fonts` directory: the family a\n * QR-bill's slip prints in, and nothing else. SIX allows Arial, Frutiger,\n * Helvetica and Liberation Sans on a slip (IG 3.4), and Roboto is none of\n * them. Regular and bold; SIX allows no italics.\n */\nexport const LIBERATION_SANS = 'LiberationSans'\n\n/**\n * Liberation Sans's ascender and its line, ascender less descender, as\n * multiples of the font size: 1854 and 2288 of its 2048 units per em, from\n * its `hhea` table, Arial's metrics. pdfmake sets a line's baseline its\n * ascender below the line's top, and lays the line out its line tall times\n * the node's `lineHeight`.\n */\nexport const LIBERATION_ASCENDER = 1854 / 2048\nexport const LIBERATION_LINE = 2288 / 2048\n\n/** The font each token prints in; a token without one is refused. */\nexport const FONTS: Readonly<Partial<Record<NonNullable<TextStyle['font']>, string>>> = { sans: ROBOTO }\n\n/**\n * Roboto's ascender and descender, as multiples of the font size: 1900 and\n * -500 of its 2048 units per em, from its `hhea` table, the same in all\n * four faces. pdfmake sets a line's baseline its ascender below the line's\n * top; a chart's word, placed in its line by ECharts, is boxed from them.\n */\nexport const ROBOTO_ASCENT = 1900 / 2048\nexport const ROBOTO_DESCENT = -500 / 2048\n\n/**\n * Roboto's line, as a multiple of the font size: its ascender less its\n * descender, 2400 of its 2048 units per em. pdfmake lays out a line exactly\n * this tall.\n */\nexport const LINE_FACTOR = ROBOTO_ASCENT - ROBOTO_DESCENT\n\n/** Text when a paragraph names no size. */\nexport const DEFAULT_SIZE = 10\n\n/** A colour as the document writes one, and as pdfmake reads one: `#` and six lower-case hex digits. */\nexport const COLOR = /^#[0-9a-f]{6}$/\n\n/**\n * pdfmake's text properties for a style, the renderer's own defaults under\n * it. Only what is set is written. A font token becomes the pdfmake family\n * `familyOf` names it -- Roboto, or the host family the report maps it to\n * (0043) -- and a style with no token prints in the document's default\n * family, which pdfmake inherits.\n */\nexport function textProperties(\n style: TextStyle,\n defaults: { readonly size: number; readonly bold?: boolean; readonly italic?: boolean },\n familyOf: (token: FontFamily) => string,\n): Record<string, unknown> {\n const bold = style.bold ?? defaults.bold\n const italic = style.italic ?? defaults.italic\n return {\n fontSize: style.size ?? defaults.size,\n ...(style.font === undefined ? {} : { font: familyOf(style.font) }),\n ...(bold === undefined ? {} : { bold }),\n ...(italic === undefined ? {} : { italics: italic }),\n ...(style.color === undefined ? {} : { color: style.color }),\n }\n}\n","import { checkQrBill, refuseBillPage, type CheckedBill, type PageSetup, type QrBill } from '@formancy/report-runtime'\nimport { codePoint, missingGlyph, type BillGlyphs } from './glyphs.js'\n\n/**\n * A QR-bill's payment part held to what the renderer draws, before\n * anything is laid out, and its Swiss QR Code, encoded once.\n *\n * What refuses a bill is the runtime's, decided once below every engine\n * (`checkQrBill`, 0075): the kind, the page, text that is not text, an\n * amount or currency SIX does not print, the number of lines, the longest\n * value and the code's size, each in words the Word writer refuses it in\n * too. What is the renderer's own is what only it knows: the glyphs of\n * the Liberation Sans it embeds, which every text the slip prints is held\n * to here, in the face it prints in.\n */\n\nexport type { CheckedBill }\n\n/** Refuses `page` for a slip, with `above` printed under its top margin: the runtime's rule, which is report-spec's. */\nexport const refusePage: (page: PageSetup, above?: number) => void = refuseBillPage\n\n/** Refuses what the renderer cannot draw of `bill` on `page`, the top margin alone before the header is measured, and encodes its code. */\nexport function checkBill(bill: QrBill, page: PageSetup, glyphs: BillGlyphs): CheckedBill {\n return checkQrBill(bill, page, (text, face) => {\n const missing = missingGlyph(text, glyphs[face])\n return missing === undefined ? undefined : `prints ${codePoint(missing)}, which Liberation Sans has no glyph for: it would print as an empty box`\n })\n}\n","/**\n * Byte arithmetic the renderer needs in Node and in a browser alike, written\n * on the standard library alone: neither `Buffer` nor `node:zlib` exists in a\n * browser, and the browser entry shares every line of this package but its\n * font loading (`browser-engine.ts`).\n */\n\nconst BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'\n\n/** Standard base64 with padding, as a `data:` URL carries bytes. */\nexport function base64(bytes: Uint8Array): string {\n const parts: string[] = []\n for (let offset = 0; offset < bytes.length; offset += 3) {\n const [a = 0, b = 0, c = 0] = [bytes[offset], bytes[offset + 1], bytes[offset + 2]]\n const left = bytes.length - offset\n parts.push(\n BASE64[a >> 2]! + BASE64[((a & 3) << 4) | (b >> 4)]! + (left > 1 ? BASE64[((b & 15) << 2) | (c >> 6)]! : '=') + (left > 2 ? BASE64[c & 63]! : '='),\n )\n }\n return parts.join('')\n}\n\n/** The bytes standard base64 with padding spells, as pdfmake's virtual files hold fonts; whitespace ignored, anything else not base64 refused. */\nexport function fromBase64(text: string): Uint8Array {\n const digits = text.replace(/\\s+/g, '').replace(/=+$/, '')\n const bytes = new Uint8Array(Math.floor((digits.length * 3) / 4))\n let bits = 0\n let held = 0\n let at = 0\n for (const digit of digits) {\n const value = BASE64.indexOf(digit)\n if (value === -1) throw new Error('not base64')\n bits = (bits << 6) | value\n held += 6\n if (held >= 8) {\n held -= 8\n bytes[at++] = (bits >> held) & 0xff\n }\n }\n return bytes\n}\n\n/** What inflating gave: every chunk in order, or why it stopped. */\nexport type Inflated = { readonly kind: 'done'; readonly length: number } | { readonly kind: 'too-long' } | { readonly kind: 'invalid' }\n\n/**\n * Inflates zlib-wrapped `data` -- a PNG's image data -- with the platform's\n * own `DecompressionStream`, handing each chunk to `each` as it arrives and\n * stopping, without reading further, once more than `limit` bytes have come\n * out: the limit is what the image's header promises, so a PNG whose data\n * inflates to gigabytes costs no more than one that keeps its promise.\n *\n * Data that is not a whole zlib stream is `invalid`, and so is data with\n * bytes after the stream's end, which Node's `inflateSync` would ignore and\n * the Compression Streams standard refuses: refusing them costs a PNG some\n * decoder would have drawn, and keeps Node and a browser in agreement.\n */\nexport async function inflate(data: Uint8Array<ArrayBuffer>, limit: number, each: (chunk: Uint8Array, offset: number) => void): Promise<Inflated> {\n const reader = new Blob([data]).stream().pipeThrough(new DecompressionStream('deflate')).getReader()\n let length = 0\n try {\n for (;;) {\n const { done, value } = await reader.read()\n if (done) return { kind: 'done', length }\n if (length + value.length > limit) {\n await reader.cancel()\n return { kind: 'too-long' }\n }\n each(value, length)\n length += value.length\n }\n } catch {\n return { kind: 'invalid' }\n }\n}\n","import type { Node, NodeQueries } from 'pdfmake/interfaces.js'\nimport type { Block, Chart, EpcQrCode, FontFamily, ImageAsset, QrCode, QrSymbol, Table, TableRow } from '@formancy/report-runtime'\nimport type { CheckedImage } from './assets.js'\nimport type { KeepBlock } from './breaks.js'\nimport type { DrawnChart } from './chart-draw.js'\nimport type { PlacedWord } from './chart-svg.js'\nimport type { FaceWanted, RenderFonts } from './host-fonts.js'\nimport type { ShiftedRoom } from './shifted.js'\nimport type { WordRoom } from './words.js'\n\n/**\n * What building one pdfmake document from a resolved one accumulates, in one\n * of two modes. `render` is what the PDF is made of. `measure` is the same\n * content made fully breakable, with a mark on each table row, for the passes\n * that measure heights before the PDF is laid out (`measure.ts`).\n *\n * pdfmake knows nothing of keep-with-next or group headers. Both are rules\n * run by its `pageBreakBefore` hook, which it calls for each node once it\n * has laid the document out, and lays it out again whenever a rule asks for\n * a break. The node a rule runs for is found by its `headlineLevel`, which\n * pdfmake passes to the hook and otherwise ignores: here it is not a level\n * but a number that names the node.\n *\n * The node a rule looks for -- the row a group header heads, the block a\n * heading is kept with -- carries an `id` as well, and the rule reads the\n * page it starts on. pdfmake records the position of a node inside an\n * unbreakable block (a row it keeps whole, a keep-together block) before it\n * moves the block to the next page, and corrects the page afterwards only\n * for a node with an id; without one, a row moved to the next page still\n * says it is on the last. The cost: every id is also a named destination in\n * the PDF.\n */\n\n/** A rule run when pdfmake asks whether to break before a marked node: true to break. */\nexport type BreakRule = (node: Node, queries: NodeQueries) => boolean\n\n/** How a table in the body is broken across pages, decided from its measured rows (`tablePlan`). */\nexport interface TablePlan {\n /** Every row fits on a page under what repeats or moves with it, so none is split. */\n readonly dontBreakRows: boolean\n /** Rows after the header that move to the next page with it, so the header never ends a page. */\n readonly keepWithHeaderRows: number\n /** Each row's height and the rule under it, as measured, the header first. */\n readonly pitches: readonly number[]\n /** The rows the table's rules keep on one page (`breaks.ts`). */\n readonly blocks: readonly KeepBlock[]\n}\n\n/** The plan of a table nothing measured: a table in a keep-together block or a page region, which no rule breaks. */\nexport const UNPLANNED: TablePlan = { dontBreakRows: false, keepWithHeaderRows: 0, pitches: [], blocks: [] }\n\n/** What a row of a table is, as pdfmake lays it out: the column header, the empty text, or one of the document's rows. */\nexport type RowKind = TableRow['kind'] | 'header' | 'empty'\n\n/** A chart as the render drew it (`drawCharts`): ECharts' marks and its words (`chart-draw.ts`), or, for a chart with nothing to draw, its words alone, which the renderer placed (`chart-empty.ts`). */\nexport type ChartDrawing = DrawnChart | { readonly words: readonly PlacedWord[] }\n\n/** A table's row as the body pass measures it: its kind, the mark on its first cell, the rows it keeps and whether it prints, as its plan reads them. */\nexport interface MeasuredRow {\n readonly kind: RowKind\n readonly mark: number\n readonly keep: number\n readonly prints: boolean\n}\n\n/** The values of the page fields, known only in a page region and only to pdfmake's header and footer functions. */\nexport interface Fields {\n readonly pageNumber: number\n readonly pageCount: number\n}\n\nexport interface Build {\n readonly mode: 'measure' | 'render'\n /** Where the body starts on every page, from the top of the paper: under the page header, and on page 1 too but where page 1 prints a header of its own (`firstShift`). */\n readonly bodyTop: number\n /** Where it ends. */\n readonly bodyBottom: number\n /**\n * How much lower page 1's body starts than `bodyTop`: the room page 1's\n * own header takes less the page header's (0060), negative where it takes\n * less; nothing where page 1 prints the page header.\n */\n readonly firstShift: number\n readonly plans: ReadonlyMap<Table, TablePlan>\n /** Each image asset as the asset checks read it. */\n readonly assets: ReadonlyMap<ImageAsset, CheckedImage>\n /** Each QR code's and EPC QR code's symbol, as the checks encoded it. */\n readonly codes: ReadonlyMap<QrCode | EpcQrCode, QrSymbol>\n /** Each chart of the body as the render drew it, every pass alike; none in a build made before the charts are drawn, the page regions', where check.ts refuses a chart. */\n readonly charts: ReadonlyMap<Chart, ChartDrawing>\n /** Filled in: each asset's key in pdfmake's image dictionary, and the dictionary. */\n readonly imageKeys: Map<ImageAsset, string>\n readonly images: Record<string, string>\n /** Filled in: the rules for marked nodes, by mark. */\n readonly rules: Map<number, BreakRule>\n /** Filled in, in measure mode: each table's rows as pdfmake lays them out, with the mark on each one's first cell, how many rows each keeps and whether it prints (`breaks.ts`). */\n readonly measuredRows: Map<Table, readonly MeasuredRow[]>\n /** Where each paragraph stands in the document, `body[2]`, for a refusal to name. */\n readonly paths: ReadonlyMap<Block, string>\n /** The pdfmake family a font token prints in (0043): Roboto, or the host family the report maps it to. */\n readonly familyOf: (token: FontFamily) => string\n /** The line of the face a run prints in, as a fraction of its size: check.ts resolved every face a block prints in before anything is built. */\n readonly lineOf: (wanted: FaceWanted) => number\n /** Filled in: every text node whose widest word is held to its room once pdfmake has measured it (`words.ts`). */\n readonly words: WordRoom[]\n /** Filled in: every paragraph that sets a run below or above the line, whose words are held to it once pdfmake has measured them (`shifted.ts`). */\n readonly shifted: ShiftedRoom[]\n /** The next unused mark. */\n next: number\n}\n\nexport function newBuild(\n mode: Build['mode'],\n checked: {\n readonly assets: ReadonlyMap<ImageAsset, CheckedImage>\n readonly codes: ReadonlyMap<QrCode | EpcQrCode, QrSymbol>\n readonly paths: ReadonlyMap<Block, string>\n readonly charts: ReadonlyMap<Chart, ChartDrawing>\n },\n fonts: RenderFonts,\n body: { readonly top: number; readonly bottom: number; readonly firstShift?: number } = { top: 0, bottom: 0 },\n plans: ReadonlyMap<Table, TablePlan> = new Map(),\n): Build {\n const { assets, codes, paths, charts } = checked\n return {\n mode,\n bodyTop: body.top,\n bodyBottom: body.bottom,\n firstShift: body.firstShift ?? 0,\n plans,\n assets,\n codes,\n charts,\n paths,\n familyOf: fonts.familyOf,\n lineOf: (wanted) => fonts.face(wanted.token, wanted.bold, wanted.italic, '').lineFactor,\n imageKeys: new Map(),\n images: {},\n rules: new Map(),\n measuredRows: new Map(),\n words: [],\n shifted: [],\n next: 1,\n }\n}\n\n/** Marks `node`, keeping a mark it already has, and returns the mark. */\nexport function mark(node: { headlineLevel?: number }, build: Build): number {\n return (node.headlineLevel ??= build.next++)\n}\n\n/** Whether a node with one of `ids`, among those pdfmake has on this page and the next, starts on `page`. */\nexport function startsOnPage(queries: NodeQueries, ids: ReadonlySet<string>, page: number): boolean {\n return [...queries.getFollowingNodesOnPage(), ...queries.getNodesOnNextPage()].some(\n (other) => other.id !== undefined && ids.has(other.id) && other.startPosition.pageNumber === page,\n )\n}\n\n/**\n * The page a node handed to pdfmake starts on in its last layout, read from\n * the node itself: pdfmake records each node's positions on it, and reports\n * the first as the node's `startPosition`. `startsOnPage` asks pdfmake's\n * queries, each of which walks every node to the end of the document, so a\n * rule per row of a long table made the rules' work grow with the square of\n * the table; this is one read. Undefined for a node pdfmake laid out\n * nowhere. `pdfmake.test.ts` holds that 0.3.11 still records positions here.\n */\nexport function pageOf(node: object): number | undefined {\n return (node as { readonly positions?: readonly { readonly pageNumber: number }[] }).positions?.[0]?.pageNumber\n}\n","import type { Content } from 'pdfmake/interfaces.js'\nimport { RenderRefusal, type Chart } from '@formancy/report-runtime'\nimport type { Build } from './build.js'\nimport type { PlacedWord } from './chart-svg.js'\nimport type { ConvertedSvg, ConverterOptions } from './svg-content.js'\n\n/**\n * A chart as pdfmake content (0058): its box, as the render drew it\n * (`drawCharts`), one unbreakable stack, in every pass, of\n *\n * 1. its marks: the drawing ECharts laid out, without a word or a style\n * sheet (`chart-svg.ts`), handed to pdfmake's SVG converter in the\n * box, whose callbacks refuse rather than draw it otherwise, detached\n * at the box's top left;\n * 2. each of its words as pdfmake text, unbroken, in its face, size and\n * colour, detached at its box's top left, and held, once pdfmake has\n * measured it, to its box's width (`words.ts`), the advance the\n * drawing placed it by;\n * 3. a spacer of the box's height, the one node that takes the flow's room.\n *\n * pdfmake lays a detached node out from where the flow stands, moved by\n * its offset, and takes none of the flow's room, so that the spacer alone\n * moves the flow (`pdfmake.test.ts`). Inside an unbreakable block pdfmake\n * 0.3.11 fits no node: the block's room is `NaN` (src/ElementWriter.js\n * 410 reads a page's `height`, which a page does not have), so every node\n * of the stack is placed where its offset says, and the stack is fitted\n * once, as a fragment as tall as the spacer moved the flow\n * (src/PageElementWriter.js 138) -- moved to the next page whole where\n * the box does not fit at the foot of one, and measured, in a\n * keep-together block, as the box. Were pdfmake to read that room, a\n * detached node would be fitted where it stands, against the room at the\n * box's top and not below its offset, so that a word at the box's foot\n * would still never go to another page than its chart. The words are\n * painted after the marks, over them, in the order pdfmake is handed\n * them. A word stands where ECharts placed it, which pdfmake prints it\n * at: its box's top half its face's line above the line's centre,\n * `dominant-baseline: central`, and its baseline the face's ascent below\n * its top, where pdfmake sets a line's.\n *\n * A chart with nothing to draw has no marks: its title and its empty text\n * are its words, in its box, and no SVG is handed to the converter.\n */\nexport function chartContent(chart: Chart, build: Build): Content {\n const drawing = build.charts.get(chart)\n // render.ts draws every chart check.ts collected before a build holds one, and check.ts refuses one in a page region, whose build is made before.\n if (drawing === undefined) throw new Error(`the chart ${chart.id} reached the pdfmake content undrawn`)\n const marks = 'svg' in drawing ? [marksOf(chart, drawing.svg)] : []\n const words = drawing.words.map((word) => wordOf(chart, word, build))\n return { stack: [...marks, ...words, { stack: [], margin: [0, chart.height, 0, 0] }], unbreakable: true }\n}\n\n/** `svg`, `chart`'s drawing, in its box at its top left, under the converter's callbacks for it. */\nfunction marksOf(chart: Chart, svg: string): ConvertedSvg & { readonly relativePosition: { readonly x: number; readonly y: number } } {\n return { svg, width: chart.width, height: chart.height, options: converterOptions(chart), relativePosition: { x: 0, y: 0 } }\n}\n\n/**\n * The converter's options for `chart`'s drawing: both callbacks refusing\n * it, naming it and quoting nothing the converter says, as an SVG asset's\n * do (`svg-content.ts`). The drawing holds only what ECharts 6.1.0 was\n * seen to write and nothing the converter would open, so either is a\n * converter that draws it otherwise than it was read, which is refused\n * rather than printed partly.\n */\nfunction converterOptions(chart: Chart): ConverterOptions {\n return {\n imageCallback: () => {\n throw new RenderRefusal(\n 'unsupported',\n `ECharts' drawing of the chart ${chart.id} asks pdfmake's SVG converter to open an image, which the renderer never lets it do`,\n chart.id,\n )\n },\n warningCallback: () => {\n throw new RenderRefusal(\n 'unsupported',\n `pdfmake's SVG converter could not draw the chart ${chart.id} as ECharts laid it out: it warned, and the renderer draws a chart whole or not at all`,\n chart.id,\n )\n },\n }\n}\n\n/** `word`, of `chart`, as pdfmake text at its box's top left, recorded for the word check with its box's width as its room, refused, should pdfmake measure it wider, in a chart's words. */\nfunction wordOf(chart: Chart, word: PlacedWord, build: Build): Content {\n const { family, face, size, font } = word.face\n const node = {\n text: word.text,\n noWrap: true,\n alignment: 'left',\n font: family,\n fontSize: size,\n bold: face === 'bold' || face === 'bolditalics',\n italics: face === 'italics' || face === 'bolditalics',\n color: font.color,\n relativePosition: { x: word.x, y: word.top },\n } satisfies Content\n const refused = (widest: number): string =>\n `a word of the chart ${chart.id} is ${widest.toFixed(2)} pt wide as pdfmake measures it, and the drawing placed it in ${word.width.toFixed(2)} pt: a chart's word prints in the advance it was laid out by, or not at all`\n build.words.push({ node, width: word.width, lines: 1, what: `the chart ${chart.id}`, subject: chart.id, refused })\n return node\n}\n","import type { ContentSvg } from 'pdfmake/interfaces.js'\nimport { QR_QUIET_ZONE, SWISS_CODE_SIZE, SWISS_CROSS as CROSS, type QrSymbol } from '@formancy/report-runtime'\n\nexport { SWISS_CODE_SIZE }\n\n/**\n * A QR code (ISO/IEC 18004), drawn as vectors.\n *\n * Its symbol is the runtime's (`qrSymbol`, 0074), where what a code is\n * refused by is decided once for every engine: the text is encoded once,\n * when the document is checked (`check.ts`), and the symbol that check\n * returns is the one every pass draws, so what is refused and what is\n * drawn are one decision.\n *\n * The square is the code's `size`, its quiet zone inside it: four modules\n * on every side, white, the symbol between them, so a module is the size\n * over the symbol's modules and eight. The white is drawn whole under the\n * code, so it scans on a tinted section, and the dark modules over it are\n * one path, filled once (`qrContent`).\n */\n\n/**\n * The code's square, exactly `size` points a side: white, and over it its\n * dark modules in black, one path filled once, each run of them in a row a\n * rectangle of it. Drawn in modules, the square's own units, and scaled to\n * `size`.\n *\n * Filled once, because a run filled on its own is blended into the page on\n * its own: where two rows meet inside a pixel, each covers part of it, and\n * a viewer draws a light line between them. The path is drawn as an SVG,\n * because pdfmake 0.3.11 cannot place one in a canvas: its `offsetVector`\n * (`helpers/tools.js`) moves a canvas's rectangles, lines and polylines to\n * where the canvas stands, never a `path`, which stays at the page's\n * corner; and a polyline's points, moved in place, are not put back when a\n * page break makes it lay the document out again. An SVG it places as it\n * places an image.\n */\nexport function qrContent(symbol: QrSymbol, size: number): ContentSvg {\n const across = symbol.modules.length + 2 * QR_QUIET_ZONE\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${size}\" height=\"${size}\" viewBox=\"0 0 ${across} ${across}\"><rect width=\"${across}\" height=\"${across}\" fill=\"#ffffff\"/><path d=\"${darkRuns(symbol, QR_QUIET_ZONE)}\" fill=\"#000000\"/></svg>`\n return { svg, width: size, height: size }\n}\n\n/** The symbol's dark modules as one path's subpaths, a rectangle for each run of them in a row, `offset` modules in from the square's corner. */\nexport function darkRuns(symbol: QrSymbol, offset: number): string {\n const runs: string[] = []\n symbol.modules.forEach((row, y) => {\n for (let x = 0; x < row.length; x++) {\n if (!row[x]) continue\n const start = x\n while (row[x + 1] === true) x++\n const length = x + 1 - start\n runs.push(`M${offset + start} ${offset + y}h${length}v1h-${length}z`)\n }\n })\n return runs.join('')\n}\n\n/**\n * The Swiss QR Code's square, 46 mm a side, without a quiet zone of its own:\n * the slip leaves 5 mm unprinted around it (IG 3.5.2, 6.4.1). White, its\n * dark modules in black as one path filled once, as a `qrCode`'s are, and\n * over them the Swiss cross: its white square, its black square, and its\n * white cross, one path. Drawn in modules and scaled to the side.\n */\nexport function swissCodeContent(symbol: QrSymbol): ContentSvg {\n const across = symbol.modules.length\n const unit = across / 46\n const centre = across / 2\n const square = (side: number, fill: string): string =>\n `<rect x=\"${centre - (side * unit) / 2}\" y=\"${centre - (side * unit) / 2}\" width=\"${side * unit}\" height=\"${side * unit}\" fill=\"${fill}\"/>`\n const [arm, span] = [(CROSS.arm * unit) / 2, (CROSS.span * unit) / 2]\n const corners: readonly (readonly [number, number])[] = [\n [-arm, -span],\n [arm, -span],\n [arm, -arm],\n [span, -arm],\n [span, arm],\n [arm, arm],\n [arm, span],\n [-arm, span],\n [-arm, arm],\n [-span, arm],\n [-span, -arm],\n [-arm, -arm],\n ]\n const cross = `M${corners.map(([x, y]) => `${centre + x} ${centre + y}`).join('L')}z`\n const size = SWISS_CODE_SIZE\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${size}\" height=\"${size}\" viewBox=\"0 0 ${across} ${across}\"><rect width=\"${across}\" height=\"${across}\" fill=\"#ffffff\"/><path d=\"${darkRuns(symbol, 0)}\" fill=\"#000000\"/>${square(CROSS.white, '#ffffff')}${square(CROSS.black, '#000000')}<path d=\"${cross}\" fill=\"#ffffff\"/></svg>`\n return { svg, width: size, height: size }\n}\n","import type { ContentSvg } from 'pdfmake/interfaces.js'\nimport { EPC_CAPTION, EPC_FRAME, epcModule, qrSymbolVersion, type EpcQrCode, type QrSymbol } from '@formancy/report-runtime'\nimport { darkRuns, qrContent } from './qr.js'\nimport { LIBERATION_SANS } from './style.js'\nimport type { ConvertedSvg } from './svg-content.js'\n\n/**\n * An EPC QR code (EPC069-12 v3.1), drawn as a QR code is (0020): its\n * symbol the runtime's (`epcSymbol`, 0074), encoded once when the document\n * is checked, its dark modules one path filled once over a white square\n * exactly its size.\n *\n * Without a caption it is a QR code's square, its quiet zone of four\n * modules inside it. With Austria's caption it is the PSA's (PSA v3.0 5),\n * laid out by report-spec's `epc-print.ts`, the one place its rules are\n * decided: a frame of half a module with corners of two, four modules\n * from the symbol, and \"Zahlen mit Code\" at 7 pt in Liberation Sans,\n * reading from bottom to top on the right.\n */\n\n/**\n * Between each end of the caption and the frame's right line, which is\n * broken where the caption stands: one module. The PSA's figure leaves\n * about that, and gives no number.\n */\nconst CAPTION_GAP = 1\n\n/**\n * Fails the render on anything the SVG converter would otherwise only\n * warn about and draw past: above all a face it could not open, which it\n * would replace by whatever face it last drew in, without a word.\n */\nfunction refuseWarning(warning: string): never {\n throw new Error(`pdfmake's SVG converter could not draw an EPC QR code's caption as written: ${warning}`)\n}\n\n/** The code's square: a QR code's without a caption, the PSA's with one. */\nexport function epcContent(symbol: QrSymbol, code: EpcQrCode): ContentSvg | ConvertedSvg {\n return code.caption === undefined ? qrContent(symbol, code.size) : captionedContent(symbol, code.size)\n}\n\n/**\n * A captioned code's square, `size` points a side, drawn in points: white,\n * the frame, the symbol's dark modules as one path, and the caption.\n *\n * Across, from the left, it is what `epcModule` counts: the frame's line,\n * half a module; four modules; the symbol; four modules; and the caption's\n * band, 7 pt, which holds the caption and the frame's right line along\n * its baseline, the line's outer edge the square's right edge. So the\n * frame spans the square's width. Down, the frame is the symbol and four\n * and a half modules above and below it, less than the square by the\n * band and half a module, and stands in the middle of the square's\n * height. The caption reads from bottom to top, its letters' tops towards\n * the symbol, centred on the symbol and no longer than it (report-spec\n * refuses a version whose symbol is shorter), and the frame's right line\n * is broken a module beyond each end of it.\n *\n * The caption is text, drawn by pdfmake's SVG converter in Liberation\n * Sans: it is in the PDF's text, and a reader finds it.\n *\n * What that takes of a 30 mm square (85.04 pt), measured on the PDF on 17\n * October 2026 (`epc-qr-code.test.ts`): the EPC's first example drawn in\n * version 8, modules of 0.479 mm; across, 8.5 modules and the band, 18.54\n * pt, so that the symbol is 78.2 % of the side; down, 9 modules, with\n * 3.16 pt of the square white above the frame and below it. At its\n * corners the frame, rounded by two modules as the PSA's figure is, comes\n * within 3.49 modules of both of the symbol's edges -- 4.93 from its\n * corner, straight -- and so half a module into the square of four\n * modules ISO/IEC 18004 keeps quiet; along the sides, four.\n */\nfunction captionedContent(symbol: QrSymbol, size: number): ConvertedSvg {\n const modules = symbol.modules.length\n const module = epcModule(size, qrSymbolVersion(symbol), 'zahlenMitCode')\n const line = EPC_FRAME.line * module\n const inset = line + EPC_FRAME.distance * module\n const side = modules * module\n const frame = side + 2 * inset\n const top = (size - frame) / 2\n // The frame's line along its middle: its outer edge on the square's sides, and on the frame's top and foot.\n const [left, right, upper, lower] = [line / 2, size - line / 2, top + line / 2, top + frame - line / 2]\n const radius = EPC_FRAME.radius * module\n const centre = top + inset + side / 2\n const broken = (EPC_CAPTION.advance * EPC_CAPTION.size) / 2 + CAPTION_GAP * module\n const corner = (x: number, y: number): string => `A${radius} ${radius} 0 0 1 ${x} ${y}`\n const path = `M${right} ${centre + broken}V${lower - radius}${corner(right - radius, lower)}H${left + radius}${corner(left, lower - radius)}V${upper + radius}${corner(left + radius, upper)}H${right - radius}${corner(right, upper + radius)}V${centre - broken}`\n const svg = [\n `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${size}\" height=\"${size}\" viewBox=\"0 0 ${size} ${size}\">`,\n `<rect width=\"${size}\" height=\"${size}\" fill=\"#ffffff\"/>`,\n `<path d=\"${path}\" fill=\"none\" stroke=\"#000000\" stroke-width=\"${line}\"/>`,\n `<path transform=\"translate(${inset} ${top + inset}) scale(${module})\" d=\"${darkRuns(symbol, 0)}\" fill=\"#000000\"/>`,\n `<text transform=\"translate(${right} ${centre}) rotate(-90)\" text-anchor=\"middle\" font-family=\"${LIBERATION_SANS}\" font-size=\"${EPC_CAPTION.size}\" fill=\"#000000\">${EPC_CAPTION.words}</text>`,\n '</svg>',\n ].join('')\n return { svg, width: size, height: size, options: { warningCallback: refuseWarning } }\n}\n","import { RenderRefusal } from '@formancy/report-runtime'\n\n/**\n * Words wider than where they stand, refused before pdfmake breaks them.\n *\n * pdfmake measures every word of a document before it lays out a line --\n * the widest unbreakable run of each text node is its `_minWidth` -- and\n * only then breaks the lines. A word wider than its line it breaks one line\n * at a time, measuring all that is left of the word for each: 16,384 W in a\n * 20pt table column took 42 seconds (measured on 2026-10-15, on an Intel\n * i9-10900K under Node 24.21). And a word broken anywhere can print as\n * something else: 'CHF 10,612,357.00' in an 85pt column printed\n * 'CHF 10,612,357.0' on one line and '0' on the next.\n *\n * So once pdfmake has measured the words and before it lays out the first\n * line -- from the function it calls for the first page's background --\n * every recorded text node's widest word is held to its room:\n * - **a table cell** to its column, less its padding: a word wider than\n * that is refused, naming the table, the row and the column. A cell's\n * value is often a number or an identifier, which no break may split.\n * - **a paragraph** to `MAX_WORD_LINES` lines of its width: a longer word,\n * such as an identifier with no space in it, breaks across lines, as the\n * corpus's `long-paragraph` fixture asks; one longer than that is\n * refused, naming the block, before pdfmake breaks a line of it.\n * - **a chart's word** to the advance the drawing placed it by, which\n * pdfmake prints it unbroken in (`chart-content.ts`): one pdfmake\n * measures wider is refused, naming the chart, in a sentence of its own.\n *\n * `_minWidth` is pdfmake's own, not part of its API; `pdfmake.test.ts`\n * holds that 0.3.11 still writes it where the renderer reads it.\n */\n\n/**\n * The most lines one word of a paragraph may be broken across. Chosen: the\n * corpus's 300-character identifier takes four lines of the page; sixteen\n * lines of the narrowest column a document can have stay a moment's work.\n */\nexport const MAX_WORD_LINES = 16\n\n/** A text node pdfmake measures, and the room its widest word has. */\nexport interface WordRoom {\n /** The node as handed to pdfmake, which writes `_minWidth` onto it. */\n readonly node: object\n /** The width of one line, in points. */\n readonly width: number\n /** The lines its widest word may take: 1 for a table cell. */\n readonly lines: number\n /** Where it is, for a person: \"row 3 of table lines, column 2\". */\n readonly what: string\n readonly subject: string\n /** What the refusal of a word `widest` points wide says, where the room is neither a table cell's nor a paragraph's lines: a chart's word, placed by its advance. */\n readonly refused?: (widest: number) => string\n}\n\n/** How much wider than its room a word may measure and still be laid out unbroken: rounding, not layout. A word that holds a run set below or above the line is held to its line with it (`shifted.ts`). */\nexport const SLACK = 0.001\n\n/** Refuses the first text node whose widest word, as pdfmake measured it, is wider than its room. Nodes pdfmake has not measured are passed over. */\nexport function checkWords(rooms: readonly WordRoom[]): void {\n for (const { node, width, lines, what, subject, refused } of rooms) {\n const widest = (node as { readonly _minWidth?: unknown })._minWidth\n if (typeof widest !== 'number' || widest <= width * lines + SLACK) continue\n const room = lines === 1 ? `its column holds ${width.toFixed(2)} pt` : `${lines} lines of its width are ${(width * lines).toFixed(2)} pt`\n throw new RenderRefusal(\n 'content-too-large',\n refused?.(widest) ??\n `a word of ${what} is ${widest.toFixed(2)} pt wide, and ${room}; a word is broken only in a paragraph, and across no more than ${MAX_WORD_LINES} lines`,\n subject,\n )\n }\n}\n","import { BASELINE_SHIFTS, RenderRefusal, SHIFTED_RISE, SHIFTED_SIZE, type Inline, type Paragraph } from '@formancy/report-runtime'\nimport { SLACK } from './words.js'\n\n/**\n * A run set below or above the line (0061), held to a word with a run on\n * the line before pdfmake lays out a line of it.\n *\n * pdfmake sets such a run at 0.58 of its size (`TextInlines.js`) and lays\n * the line out as tall as its runs' own lines, its baseline its tallest\n * ascender down (`Line.js`); it moves the run up or down only when it draws\n * it (`Renderer.js`'s `offsetText`). A line of nothing but such runs is laid\n * out at their small height and drawn above its own top, into the line\n * before. pdfmake breaks a line only between its words: the inlines\n * `TextBreaker` chains with `noNewLine`, where a run's last word and the\n * next run's first make one, are one word, which `LayoutBuilder` puts on a\n * line whole once it starts one.\n *\n * So once pdfmake has measured the words and before it lays out the first\n * line -- from the function it calls for the first page's background, as\n * `words.ts` does -- each recorded paragraph's words are read from pdfmake\n * itself, `_inlines`, and every word that holds a run set below or above\n * the line must:\n * - **hold a run on the line**, one set on it that prints a character other\n * than a space: a word whose only other run prints a space, or nothing,\n * stands as alone as one of no other run, and is refused as\n * `unsupported`, naming the paragraph;\n * - **fit its line**, measured as pdfmake measures a word that starts one\n * (`Line.hasEnoughSpaceForInline`): its inlines' widths, less the first's\n * leading cut and every one's trailing cut. pdfmake breaks a word wider\n * than its line anywhere, and a piece of it could hold such a run alone:\n * refused as `content-too-large`, naming the paragraph.\n *\n * Only a paragraph that holds such a run is recorded, so every other is\n * laid out as it was. `_inlines`, `noNewLine`, `sup`, `sub`, `width`,\n * `leadingCut` and `trailingCut` are pdfmake's own, not part of its API;\n * `pdfmake.test.ts` holds that 0.3.11 still writes them where this reads.\n *\n * And a line that holds a run set below the line is given room below it,\n * `LOWERED_LINE`, for a raised run on the line under it.\n */\n\n/**\n * How tall a line that holds a run set below the line is laid out, at\n * least, as a fraction of its paragraph's size: the lowered run's drop, a\n * raised run's rise on the next line and the small run's own size, 1.218,\n * so that a lowered run and a raised one under it are set solid, their\n * baselines the small run's size apart, and their boxes as the corpus draws\n * them -- one size tall, a fifth below the baseline -- meet nowhere. A\n * face's own line of 1.218 ems or more needs none. pdfmake lays a line out\n * as tall as its runs' own lines, its baseline its tallest ascender down,\n * and moves a run set off it only when it draws it (`Line.js`,\n * `Renderer.js`), so the room is asked as the lowered run's own line,\n * `loweredLineHeight`, and falls below the baseline. Room above a raised\n * run cannot be asked of pdfmake at all.\n */\nexport const LOWERED_LINE = SHIFTED_SIZE + SHIFTED_RISE.superscript - SHIFTED_RISE.subscript\n\n/**\n * pdfmake's `lineHeight` for a run set below the line in a face whose line\n * is `lineFactor` of its size: what makes that run's line, at\n * `SHIFTED_SIZE` of its paragraph's size, `LOWERED_LINE` of the\n * paragraph's size (`TextInlines.js` multiplies a run's line by it).\n */\nexport function loweredLineHeight(lineFactor: number): number {\n return LOWERED_LINE / (SHIFTED_SIZE * lineFactor)\n}\n\n/** A paragraph holding a run set below or above the line, as handed to pdfmake, and the width of its lines. */\nexport interface ShiftedRoom {\n /** The node as handed to pdfmake, which writes its words onto it as `_inlines`. */\n readonly node: object\n /** The width of one line, in points. */\n readonly width: number\n /** Where it is, `body[2]`, for a refusal to name. */\n readonly subject: string\n}\n\n/** One of pdfmake's words, as far as the check reads it: its width and its cuts as `TextInlines.measure` writes them on every word. */\ninterface Word {\n readonly text: string\n readonly width: number\n readonly leadingCut: number\n readonly trailingCut: number\n readonly sup?: boolean\n readonly sub?: boolean\n readonly noNewLine?: boolean\n}\n\n/** Whether a run of the document is set below or above the line. */\nexport function isShifted(run: Inline): boolean {\n return 'text' in run && run.baseline !== undefined\n}\n\n/**\n * Refuses a paragraph that sets a run off the line in a way the renderer\n * does not know: a baseline other than report-spec's, or one on a page\n * field, which takes none. pdfmake would print either on the line, as\n * though nothing were set (0011). Called by check.ts, before anything is\n * built.\n */\nexport function checkBaselines(paragraph: Paragraph, at: string): void {\n const known = paragraph.runs.every((run) => {\n const { baseline } = run as { readonly baseline?: unknown }\n return baseline === undefined || ('text' in run && BASELINE_SHIFTS.some((shift) => shift === baseline))\n })\n if (!known) throw new RenderRefusal('unsupported', `${at} sets a run below or above the line in a way the renderer does not know`, at)\n}\n\n/** Refuses the first recorded paragraph with a word that could leave a run set below or above the line alone on a line. */\nexport function checkShifted(rooms: readonly ShiftedRoom[]): void {\n for (const { node, width, subject } of rooms) {\n const inlines = (node as { readonly _inlines?: unknown })._inlines\n // Every recorded node is measured before the first page's background: one without words is a pdfmake that measures otherwise.\n if (!Array.isArray(inlines)) throw new Error(`pdfmake has measured no words of ${subject}, which sets a run below or above the line`)\n for (const word of words(inlines as readonly Word[])) {\n if (!word.some((inline) => inline.sup === true || inline.sub === true)) continue\n if (!word.some(onLine)) {\n throw new RenderRefusal(\n 'unsupported',\n `${subject} sets a run below or above the line in a word with no text on the line, which pdfmake could print on a line of its own, drawn into the line before; write it against its word with no space, or with a no-break space (U+00A0)`,\n subject,\n )\n }\n const wide = word.reduce((sum, inline) => sum + inline.width - inline.trailingCut, 0) - word[0]!.leadingCut\n // A word without its width or its cuts would measure as no number, and pass: a pdfmake that measures otherwise stops the render.\n if (!Number.isFinite(wide)) throw new Error(`pdfmake has measured a word of ${subject} without its width and its cuts`)\n if (wide > width + SLACK) {\n throw new RenderRefusal(\n 'content-too-large',\n `a word of ${subject} that sets a run below or above the line is ${wide.toFixed(2)} pt wide, and its line ${width.toFixed(2)} pt; pdfmake would break it, and could leave that run on a line of its own`,\n subject,\n )\n }\n }\n }\n}\n\n/** A run set on the line that prints a character other than a space: what keeps a line its full height and a run beside it off the line before. */\nfunction onLine(inline: Word): boolean {\n return inline.sup !== true && inline.sub !== true && /\\S/u.test(inline.text)\n}\n\n/** pdfmake's words: each inline with those it is chained to by `noNewLine`, which no line break separates. */\nfunction words(inlines: readonly Word[]): Word[][] {\n const found: Word[][] = []\n let current: Word[] = []\n for (const inline of inlines) {\n current.push(inline)\n if (inline.noNewLine === true) continue\n found.push(current)\n current = []\n }\n if (current.length > 0) found.push(current)\n return found\n}\n","import type { ContentSvg } from 'pdfmake/interfaces.js'\nimport { RenderRefusal, type Image } from '@formancy/report-runtime'\nimport type { Vector } from './assets.js'\n\n/**\n * An SVG asset as pdfmake draws it (0030): the drawing `checkSvg` accepted,\n * handed to the SVG converter pdfmake 0.3.11 vendors, svg-to-pdfkit, as the\n * very text that was approved, in the image's box. The converter fits the\n * drawing's viewBox into the box itself, centred: `contain` is its\n * `xMidYMid meet`, all of the drawing as large as the box allows, and\n * `cover` its `xMidYMid slice`, the box filled and what falls outside it\n * clipped by the outer svg's viewport, which the converter clips to\n * (`pdfmake.test.ts` holds both). Nothing is drawn outside the box.\n *\n * What decides is the check: bytes that are not exactly what `cleanSvg`\n * writes never get this far (`assets.ts`). Two guards stand behind it, so\n * that a bug in the cleaner does not reach the converter as it would a\n * customer's file:\n *\n * - **The renderer's own list of elements.** Before it is handed on, the\n * text is held to the elements a cleaned drawing may hold, written here\n * and not taken from report-spec's tables, so that the two would have to\n * be wrong together: printable ASCII, no entity, and every tag one of\n * `DRAWN`. A link, an image, text, `use`, a style sheet, a comment or a\n * DOCTYPE is refused.\n * - **Callbacks that throw.** The converter would open an `<image>`'s file\n * past pdfmake's local access policy, or a virtual file in a browser, and\n * draws on past what it cannot read, saying so only to the console. Its\n * `imageCallback` and `warningCallback` throw instead, and its\n * `documentCallback` is left unset, so that it follows no reference out of\n * the drawing. They do not stop a link: the converter writes a link\n * annotation for an `<a>` whatever its callbacks say (`pdfmake.test.ts`),\n * which is why the list above refuses one.\n */\n\n/** The elements of a drawing in the form `cleanSvg` writes (0030), the renderer's own copy: it may refuse more than report-spec's tables, never less, and `svg-threats.test.ts` holds it to them. */\nexport const DRAWN: ReadonlySet<string> = new Set([\n 'svg',\n 'g',\n 'defs',\n 'path',\n 'rect',\n 'circle',\n 'ellipse',\n 'line',\n 'polyline',\n 'polygon',\n 'linearGradient',\n 'radialGradient',\n 'stop',\n 'clipPath',\n])\n\n/** A tag's name as a refusal may repeat it: short, and nothing but a name's characters. */\nconst NAME = /^[A-Za-z][A-Za-z0-9:._-]{0,63}$/\n\n/**\n * What in `svg` the renderer never hands the converter, or nothing: a\n * character that is not printable ASCII, an entity, or a tag -- an end tag,\n * a comment, a DOCTYPE or a processing instruction among them -- that is\n * not one of `DRAWN`.\n */\nexport function foreignMarkup(svg: string): string | undefined {\n if (/[^\\x20-\\x7e]/.test(svg)) return 'a character that is not printable ASCII'\n if (svg.includes('&')) return 'an entity'\n for (const [, name = ''] of svg.matchAll(/<\\/?([^\\s/>]*)/g)) {\n if (!DRAWN.has(name)) return NAME.test(name) ? `the element ${name}` : 'markup that is not an element'\n }\n return undefined\n}\n\n/** What pdfmake's SVG converter is handed beside the drawing, which pdfmake 0.3.11 passes on (`Renderer.renderSVG`) and its types do not declare. */\nexport interface ConverterOptions {\n readonly preserveAspectRatio?: string\n readonly imageCallback?: (href: string) => never\n readonly warningCallback: (warning: string) => never\n}\n\n/** An SVG node with options for pdfmake's SVG converter. */\nexport type ConvertedSvg = ContentSvg & { readonly options: ConverterOptions }\n\n/**\n * The converter's options for the asset `id` drawn as `fit` says: the\n * viewBox fitted into the box, and both callbacks refusing the asset.\n * Neither repeats what the converter was handed: a callback is what holds\n * only where the check has failed, and then the drawing may hold anything\n * -- a file's path, an id, a word -- which the converter's warnings quote.\n */\nexport function converterOptions(id: string, fit: Image['fit']): ConverterOptions {\n return {\n preserveAspectRatio: fit === 'cover' ? 'xMidYMid slice' : 'xMidYMid meet',\n imageCallback: () => {\n throw new RenderRefusal('invalid-asset', `the image asset ${id} asks pdfmake's SVG converter to open an image, which the renderer never lets it do`, id)\n },\n warningCallback: () => {\n throw new RenderRefusal(\n 'invalid-asset',\n `pdfmake's SVG converter could not draw the image asset ${id} as it was approved: it warned, and the renderer draws an SVG whole or not at all`,\n id,\n )\n },\n }\n}\n\n/** The drawings that have passed the list: one in a page region is built anew for every page, and read once. */\nconst PASSED = new WeakSet<Vector>()\n\n/** `image`, an SVG whose drawing the checks read as `vector`, as pdfmake's node: the drawing in the image's box, guarded and under the converter's options. */\nexport function svgContent(image: Image, vector: Vector): ConvertedSvg {\n const { id } = image.asset\n if (!PASSED.has(vector)) {\n const foreign = foreignMarkup(vector.svg)\n if (foreign !== undefined)\n throw new RenderRefusal('invalid-asset', `the image asset ${id} holds ${foreign}, which the renderer never hands pdfmake's SVG converter`, id)\n PASSED.add(vector)\n }\n return { svg: vector.svg, width: image.width, height: image.height, options: converterOptions(id, image.fit) }\n}\n","import type { RowKind } from './build.js'\n\n/**\n * Which rows of a table must share a page, and where a table's page breaks\n * fall once they do: pure arithmetic on the row heights the body pass\n * measured (`measure.ts`), which `table.ts` turns into pdfmake's rules.\n *\n * **What is kept together.** A group header with the row it heads, so a\n * group never starts at the foot of a page with nothing under its heading,\n * or with as many of its group's first rows as its row keeps and a page\n * holds (`keptCounts`, 0059). And a table's closing rows -- a group's\n * footers, the totals under the last row -- with the row before them, and\n * with its group header when that row is the group's first: a quotation's\n * subtotal, VAT and total on one page with the last line item, a subtotal\n * on the page of the rows it adds up, never alone under a repeated column\n * header. Each is a `KeepBlock`.\n *\n * **Why plan the breaks.** pdfmake asks the renderer's rule for each marked\n * node once its layout is done, and lays the whole document out again for\n * the first rule that asks for a break. A rule fires about once a page, so\n * a long grouped table was laid out once per page: 1,600 groups over 134\n * pages took 60 seconds (measured on 2026-10-15, on an Intel i9-10900K under\n * Node 24.21). So when the first row of a table is laid out, the breaks its\n * rules will ask for are worked out here, from the measured heights, where\n * the first row stands and where a row starts under the repeated header,\n * and are all made in the next layout. The rules stay, and hold the next\n * layout to them: a break the plan missed is still made, one layout later.\n */\n\n/** Rows from `first` to `last`, indices into the table's rows as pdfmake lays them out (the column header at 0), that stand on one page. */\nexport interface KeepBlock {\n readonly first: number\n readonly last: number\n}\n\n/** Rows that close what is above them: a group's footer, a total. */\nconst CLOSING: ReadonlySet<RowKind> = new Set(['groupFooter', 'total'])\n\n/** The last of the closing rows that close the row `row`, a detail row or the empty text, where `closing`; `row` itself where none do. */\nfunction closedAt(kinds: readonly RowKind[], row: number, closing: boolean): number {\n let last = row\n if (closing && (kinds[row] === 'detail' || kinds[row] === 'empty')) while (kinds[last + 1] !== undefined && CLOSING.has(kinds[last + 1]!)) last++\n return last\n}\n\n/**\n * The blocks of rows of these kinds that stand on one page, overlapping\n * ones merged, in order: a group header with as many rows as `counts`\n * says, one where it says nothing. Closing rows are kept with the row\n * before them only when `closing`: a table whose rows may split across\n * pages has no row height to keep them by.\n */\nexport function keepBlocks(kinds: readonly RowKind[], closing: boolean, counts: readonly number[] = []): KeepBlock[] {\n const blocks: KeepBlock[] = []\n kinds.forEach((kind, index) => {\n if (kind === 'groupHeader' && index + 1 < kinds.length) blocks.push({ first: index, last: index + (counts[index] ?? 1) })\n const before = kinds[index - 1]\n if (!closing || !CLOSING.has(kind) || before === undefined || CLOSING.has(before) || (before !== 'detail' && before !== 'empty')) return\n const anchor = index - 1\n blocks.push({ first: kinds[anchor - 1] === 'groupHeader' ? anchor - 1 : anchor, last: closedAt(kinds, anchor, closing) })\n })\n const merged: KeepBlock[] = []\n for (const block of blocks.sort((a, b) => a.first - b.first)) {\n const previous = merged.at(-1)\n if (previous !== undefined && block.first <= previous.last) merged[merged.length - 1] = { first: previous.first, last: Math.max(previous.last, block.last) }\n else merged.push(block)\n }\n return merged\n}\n\n/** A table's row as its plan reads it: its kind, its pitch, how many rows it keeps -- a group header's, one for any other -- and whether any of its cells prints. */\nexport interface PlannedRow {\n readonly kind: RowKind\n readonly pitch: number\n readonly keep: number\n readonly prints: boolean\n}\n\n/**\n * How many of its first rows each group header is kept with, one for every\n * other row (0059): the most, up to the number its row keeps, whose block\n * -- the header, those rows, and the footers and totals that close them\n * where they reach the group's last row and `closing` -- fits `room`, a\n * page under the repeated header, and has a row that prints from the last\n * of those rows on. A rule finds a row on its page by its text alone, and\n * holds the last of its block's rows that prints to the header's page\n * (`tableRules`): a block short of its group, whose last row printed\n * nothing, would be held to an earlier row, and the plan, which counts\n * every row, would break where the rule does not. A block that runs into\n * the group's footers is held by the last of them that prints, a footer\n * row or a total after it that prints nothing standing in the block, as it\n * stands in the closing rows' own block of the group's last row. Where no\n * number above one does, one: the block every header has had, which\n * `keepBlocks` makes, `keptBlocks` drops where it does not fit, and a rule\n * leaves where it falls where its first row prints nothing. A header that\n * prints nothing keeps one too: no rule can find it, and the rows that\n * move with the column header, which read no text, would otherwise take\n * its count with them.\n */\nexport function keptCounts(rows: readonly PlannedRow[], closing: boolean, room: number): number[] {\n const kinds = rows.map((row) => row.kind)\n const pitches = rows.map((row) => row.pitch)\n return rows.map((row, index) => {\n for (let count = row.kind === 'groupHeader' && row.prints ? row.keep : 1; count > 1; count--) {\n const block = { first: index, last: closedAt(kinds, index + count, closing) }\n const held = rows.slice(index + count, block.last + 1).some((each) => each.prints)\n if (held && blockHeight(pitches, block) <= room) return count\n }\n return 1\n })\n}\n\n/** The rows' height from `first` to `last`, each row's pitch being its height and the rule under it. */\nexport function blockHeight(pitches: readonly number[], block: KeepBlock): number {\n return pitches.slice(block.first, block.last + 1).reduce((sum, pitch) => sum + pitch, 0)\n}\n\n/** The blocks a table's rules can keep: each fits under the repeated header, and starts after the rows that move with it. */\nexport function keptBlocks(blocks: readonly KeepBlock[], pitches: readonly number[], keepWithHeaderRows: number, room: number): KeepBlock[] {\n return blocks.filter((block) => block.first > keepWithHeaderRows && blockHeight(pitches, block) <= room)\n}\n\n/** Where a table stands on the pages its body pass did not see: what the first layout showed. */\nexport interface Geometry {\n /** The top of the row `first`, on its page. */\n readonly top: number\n /** Where a row starts on a page the table continues on: under the repeated column header. */\n readonly continued: number\n /** The foot of every page's body. */\n readonly bottom: number\n}\n\n/** A height closer than this to what is left of a page could fall either way in pdfmake's arithmetic: the plan stops there and leaves the rest to the rules. */\nconst UNSURE = 0.01\n\n/**\n * The rows, from `first` on, that the `blocks`' rules will break before,\n * laid out row after row as pdfmake lays out rows it keeps whole: a row\n * that does not fit in what is left of a page starts the next one. `sure`\n * is false when a height came too close to the foot of a page to say, and\n * the breaks are then those before it.\n */\nexport function plannedBreaks(\n pitches: readonly number[],\n blocks: readonly KeepBlock[],\n first: number,\n geometry: Geometry,\n): { readonly breaks: readonly number[]; readonly sure: boolean } {\n const { continued, bottom } = geometry\n const starts = new Map(blocks.map((block) => [block.first, block]))\n const breaks: number[] = []\n let y = geometry.top\n /** Whether `height` fits below `y`, or undefined when that is too close to say. */\n const fits = (height: number): boolean | undefined => {\n const left = bottom - y - height\n return Math.abs(left) < UNSURE ? undefined : left > 0\n }\n for (let row = first; row < pitches.length; row++) {\n // A row that does not fit starts the next page by itself, and its block with it.\n const fitting = fits(pitches[row]!)\n if (fitting === undefined) return { breaks, sure: false }\n if (!fitting) y = continued\n const block = starts.get(row)\n if (block !== undefined && y > continued + UNSURE) {\n const whole = fits(blockHeight(pitches, block))\n if (whole === undefined) return { breaks, sure: false }\n if (!whole) {\n breaks.push(row)\n y = continued\n }\n }\n y += pitches[row]!\n }\n return { breaks, sure: true }\n}\n\n/** Where a row stands when nothing breaks the table but pdfmake: the page, counting the first row's as 0; its top; whether it is first on that page. */\nexport interface Placed {\n readonly page: number\n readonly top: number\n readonly first: boolean\n}\n\n/** Where each row from `first` on stands when no rule breaks the table: how pdfmake lays out rows it keeps whole. */\nexport function naturalLayout(pitches: readonly number[], first: number, geometry: Geometry): Placed[] {\n const placed: Placed[] = []\n let [y, page] = [geometry.top, 0]\n for (let row = first; row < pitches.length; row++) {\n const moves = y + pitches[row]! > geometry.bottom\n if (moves) [y, page] = [geometry.continued, page + 1]\n placed.push({ page, top: y, first: moves || row === first })\n y += pitches[row]!\n }\n return placed\n}\n","import type { Node, NodeQueries } from 'pdfmake/interfaces.js'\nimport { naturalLayout, plannedBreaks, type Geometry, type KeepBlock } from './breaks.js'\nimport { mark, pageOf, type BreakRule, type Build, type TablePlan } from './build.js'\nimport type { Cell, Row } from './table.js'\n\n/**\n * The rules that keep a table's blocks of rows on one page (`breaks.ts`),\n * as pdfmake runs them: each cell of a block's first row that prints is\n * marked with a rule, each cell of its first and last rows that prints gets\n * an id, and when none of the last row's starts on the first row's page,\n * the first row breaks to the next page, under the repeated column header.\n * pdfmake breaks before a cell, not a row, so every cell of the row that\n * prints carries the rule, and the first to break sets the break on the\n * others: one at a time, each left a piece of the row's rule at the foot of\n * the page, and took a layout of its own. The ids are what make a row's\n * page right: pdfmake corrects the page of a node it moved whole to the\n * next page only when it has one, and without it a row that did not fit\n * reported the page before, and its rule broke before a row already first\n * on its page, for another layout. Every id is a named destination in the\n * PDF, two to a block.\n *\n * A block first on its page always fits: the table's plan keeps only\n * blocks that fit under the repeated header, and none that start among the\n * rows that move with the header (`keepWithHeaderRows`), where a break\n * inside pdfmake's unbreakable block would lose the rows after it. A block\n * whose first row has no text, or none of whose other rows has, cannot be\n * kept: there is nothing on the page for the rule to find. One that has\n * holds the last of its rows that prints to the first one's page; a group\n * header that keeps more than one row has a block in which such a row\n * stands at or after the last row it counts (`keptCounts`), so that the\n * rule holds every row the count names. Rows after it that print nothing\n * -- a blank footer row under a subtotal -- stand in the block's height,\n * as in a closing rows' block, though no rule holds them.\n *\n * In the body, outside any frame, a table whose rows are kept whole also\n * has its breaks planned. The first body row after those that move with\n * the header carries one more rule, which pdfmake asks before any block's\n * once its first layout is done. It reads where that row stands, works out\n * every break the blocks' rules would ask for (`plannedBreaks`), and makes\n * them all in the next layout -- the first through its own rule's answer,\n * the rest by setting the break on their cells -- so that a table of any\n * length is laid out about twice, not once a page.\n *\n * pdfmake reports where a row of a table it keeps whole starts: its row's\n * top, on its page. Not for a row that did not fit, which reports where it\n * would have stood, at the foot of the page before, nor for the rows that\n * move with the header, which report where they stand in the block they\n * move in. So the plan starts from the first row after those, and before it\n * plans anything it lays the table out by its own arithmetic and compares\n * every row pdfmake reports on that page and the next, other than the first\n * of a page: if one differs, nothing is planned, and the rules alone break\n * the table, one layout each.\n */\n\n/** Where a page's first row starts on the pages a table continues on; `undefined` where its breaks are not planned. */\nexport type Continued = number | undefined\n\nexport function tableRules(rows: readonly Row[], plan: TablePlan, build: Build, continued: Continued): void {\n const forced = new Set<Cell>()\n const ruled = plan.blocks.flatMap((block) => {\n const starts = printing(rows[block.first]!)\n const end = rows.slice(block.first + 1, block.last + 1).findLast((row) => printing(row).length > 0)\n if (starts.length === 0 || end === undefined) return []\n const ends = printing(end)\n for (const cell of [...starts, ...ends]) cell.id ??= `row-${build.next++}`\n for (const cell of starts) {\n add(\n cell,\n (node) => {\n const breaks = forced.has(cell) || !ends.some((other) => pageOf(other) === node.startPosition.pageNumber)\n if (breaks) for (const other of starts) if (other !== cell) other.pageBreak = 'before'\n return breaks\n },\n build,\n )\n }\n return [block]\n })\n if (continued === undefined || !plan.dontBreakRows || ruled.length === 0) return\n // Every row's first printing cell is marked, so that a row is found among the nodes pdfmake reports by its mark.\n const rowOf = new Map<number, number>()\n rows.forEach((row, index) => {\n const [first] = printing(row)\n if (first !== undefined && index > 0) rowOf.set(mark(first, build), index)\n })\n const hookRow = rows.findIndex((row, index) => index > plan.keepWithHeaderRows && printing(row).length > 0)\n if (hookRow === -1 || hookRow > ruled[0]!.first) return\n const hook = printing(rows[hookRow]!)[0]!\n let done = false\n const planning: BreakRule = (node, queries) => {\n if (!done) {\n done = true\n const geometry: Geometry = { top: node.startPosition.top, continued, bottom: build.bodyBottom }\n for (const [index, row] of planBreaks(plan, ruled, hookRow, geometry, node, queries, rowOf).entries()) {\n // The first break is made by its first cell's own rule, which pdfmake asks next; the rest are set here.\n printing(rows[row]!).forEach((cell, at) => (index === 0 && at === 0 ? forced.add(cell) : (cell.pageBreak = 'before')))\n }\n }\n return forced.has(hook)\n }\n add(hook, planning, build)\n}\n\n/** The rows the blocks' rules will break before, from row `hookRow` on; none when what pdfmake reports of this page and the next is not what the arithmetic gives. */\nfunction planBreaks(\n plan: TablePlan,\n blocks: readonly KeepBlock[],\n hookRow: number,\n geometry: Geometry,\n node: Node,\n queries: NodeQueries,\n rowOf: ReadonlyMap<number, number>,\n): readonly number[] {\n // A row that did not fit reports where it would have stood, and nothing can be planned from it.\n if (geometry.top + plan.pitches[hookRow]! > geometry.bottom) return []\n const placed = naturalLayout(plan.pitches, hookRow, geometry)\n const page = node.startPosition.pageNumber\n for (const other of [...queries.getFollowingNodesOnPage(), ...queries.getNodesOnNextPage()]) {\n const row = other.headlineLevel === undefined ? undefined : rowOf.get(other.headlineLevel)\n const at = row === undefined ? undefined : placed[row - hookRow]\n if (at === undefined || at.first) continue\n if (other.startPosition.pageNumber !== page + at.page || Math.abs(other.startPosition.top - at.top) > 0.01) return []\n }\n return plannedBreaks(plan.pitches, blocks, hookRow, geometry).breaks\n}\n\n/** Sets `rule` on `cell`'s mark, asked before a rule it has: the planning rule, before the block rule of a row that starts a block. */\nfunction add(cell: Cell, rule: BreakRule, build: Build): void {\n const at = mark(cell, build)\n const had = build.rules.get(at)\n build.rules.set(at, had === undefined ? rule : (node, queries) => rule(node, queries) || had(node, queries))\n}\n\n/** The cells of a row that have text. */\nexport function printing(row: Row): Cell[] {\n return row.cells.filter((cell) => cell.text.trim() !== '')\n}\n","import type { TableColumn } from '@formancy/report-runtime'\n\n/** Points, or `'fill'` for an equal share of what the fixed widths leave. */\ntype Width = TableColumn['width']\n\n/**\n * Widths as the renderer hands them to pdfmake: always a number of points.\n * pdfmake widens a column it is handed as `'*'` to its longest word, so a\n * table, a columns block or a frame grew past the page with a long word in\n * it; a fill column is therefore its share of the width worked out here,\n * the one place the check (`check.ts`) and the content (`content.ts`,\n * `table.ts`) take it from.\n */\n\n/** Points, or nothing for `'fill'`. */\nexport function fixedWidth(width: Width): number {\n return width === 'fill' ? 0 : width\n}\n\n/** The width each `'fill'` gets of `width`: what the fixed widths leave, shared equally. Infinity when there is none. */\nexport function fillWidth(widths: readonly Width[], width: number): number {\n const fixed = widths.reduce<number>((sum, each) => sum + fixedWidth(each), 0)\n const fills = widths.filter((each) => each === 'fill').length\n return fills === 0 ? Infinity : (width - fixed) / fills\n}\n\n/** Each column's width in points, of `width`: a fixed one its own, each fill its share. */\nexport function columnWidths(widths: readonly Width[], width: number): number[] {\n const fill = fillWidth(widths, width)\n return widths.map((each) => (each === 'fill' ? fill : each))\n}\n","import type { Content, CustomTableLayout, TableCell } from 'pdfmake/interfaces.js'\nimport type { Table, TableColumn, TextStyle } from '@formancy/report-runtime'\nimport type { PlannedRow } from './breaks.js'\nimport { mark, UNPLANNED, type Build, type RowKind } from './build.js'\nimport type { FaceWanted } from './host-fonts.js'\nimport { textProperties } from './style.js'\nimport { printing, tableRules } from './table-rules.js'\nimport { columnWidths } from './widths.js'\n\n/**\n * A table as pdfmake content: its header row repeated on every page it\n * spans, its rows styled, a row across the table as one cell spanning every\n * column, and the rules that keep a group header with the rows it heads.\n *\n * A table the runtime writes without a header row (0078) is handed to\n * pdfmake under a header of no height: each of its cells an empty stack,\n * with no padding and no rule under it. pdfmake keeps a table's first rows\n * on a page with its header row alone (`keepWithHeaderRows` counts from\n * `headerRows`), and repeats with it the table's top rule on every page the\n * table continues on, so the table keeps its first group header with the\n * rows it heads, and breaks, as a table with a header does, and prints\n * nothing where a header would stand: its first row stands under its top\n * rule where it would in a table of no header row (`pdfmake.test.ts`).\n */\n\n/** A table's cells, whose size the document does not set: the body size the corpus's geometry assumes. */\nexport const TABLE_SIZE = 9\n\n/** The table layout: horizontal rules of half a point, no vertical ones, 4pt of padding at the sides and 2pt above and below. */\nexport const RULE = 0.5\nexport const PADDING_X = 4\nexport const PADDING_Y = 2\nexport const TABLE_LAYOUT: CustomTableLayout = {\n hLineWidth: () => RULE,\n vLineWidth: () => 0,\n hLineColor: (index) => (index === 1 ? '#000000' : '#bfbfbf'),\n paddingLeft: () => PADDING_X,\n paddingRight: () => PADDING_X,\n paddingTop: () => PADDING_Y,\n paddingBottom: () => PADDING_Y,\n}\n\n/** The layout of a table under a header of no height: the header row has no padding and no rule under it, which is the one rule drawn black. */\nexport const UNSEEN_LAYOUT: CustomTableLayout = {\n ...TABLE_LAYOUT,\n hLineWidth: (index) => (index === 1 ? 0 : RULE),\n paddingTop: (index) => (index === 0 ? 0 : PADDING_Y),\n paddingBottom: (index) => (index === 0 ? 0 : PADDING_Y),\n}\n\n/**\n * The header of no height pdfmake is handed for a table without one, as\n * the plan reads it: of no pitch, keeping nothing and printing nothing.\n * The body pass, in which pdfmake repeats no header, lays the table out\n * without it, since it takes no room; the plan reads it first all the same.\n */\nexport const UNSEEN_HEADER: PlannedRow = { kind: 'header', pitch: 0, keep: 1, prints: false }\n\n/** That header as the rules read it: a row of no cell that prints. */\nconst UNSEEN_ROW: Row = { kind: 'header', cells: [] }\n\n/** Laid out as one line of text, as wide as a space, that no line break can fall in. */\nconst NO_BREAK_SPACE = String.fromCodePoint(0xa0)\n\n/** The renderer's own style for a row of each kind, under the document's: the column header and every row but a detail row in bold. */\nexport const KIND_BOLD: Readonly<Record<RowKind, boolean>> = { header: true, empty: false, detail: false, groupHeader: true, groupFooter: true, total: true }\n\n/** Whether `table` prints its empty text, in italic, in place of detail rows: where it has none, whatever else its rows are. */\nexport function printsEmptyText(table: Table): boolean {\n return !table.rows.some((row) => row.kind === 'detail')\n}\n\n/**\n * A row as `tableContent` lays it out, before it is pdfmake's: its kind,\n * where it stands in the table's rows -- none for the header and the empty\n * text, which the renderer adds -- its cells' text, the style each cell\n * prints in, and whether its one cell spans every column.\n */\nexport interface StyledRow {\n readonly kind: RowKind\n readonly index: number | undefined\n readonly cells: readonly string[]\n readonly styles: readonly TextStyle[]\n readonly across: boolean\n}\n\n/** A cell neither it nor its row styles. */\nconst UNSTYLED: TextStyle = {}\n\n/** The empty text's style: italic, at the table's size. */\nconst EMPTY_TEXT: TextStyle = { italic: true }\n\n/**\n * Every row of `table` as `tableContent` lays it out, each cell in the\n * style it prints in: the header in the header's style, where the table\n * has one (0078); the empty text, in italic and across the table, where\n * the table prints it; and each of its rows, a cell in its own style\n * where it has one, else its row's -- a null cell style is the runtime's\n * for a column with no style of its own -- else none. The one walk of a\n * table's cells: `tableContent` builds its\n * rows from it, check.ts holds every cell's text and line to it, and\n * bound.ts counts every row's least line by it, so that no two of them can\n * take a cell's style, its size or its face from different places. Each\n * row's cell count is check.ts's to have held to its columns first.\n */\nexport function styledRows(table: Table): StyledRow[] {\n const style = table.headerStyle ?? UNSTYLED\n const { header } = table\n const rows: StyledRow[] = header === undefined ? [] : [{ kind: 'header', index: undefined, cells: header, styles: header.map(() => style), across: false }]\n if (printsEmptyText(table)) rows.push({ kind: 'empty', index: undefined, cells: [table.emptyText], styles: [EMPTY_TEXT], across: true })\n table.rows.forEach((row, index) => {\n rows.push({\n kind: row.kind,\n index,\n cells: row.cells,\n styles: row.cells.map((_, column) => row.cellStyles?.[column] ?? row.style ?? UNSTYLED),\n across: row.across === true,\n })\n })\n return rows\n}\n\n/** The size a cell prints at: its style's, else the table's. */\nexport function cellSize(style: TextStyle): number {\n return style.size ?? TABLE_SIZE\n}\n\n/**\n * The face a cell of a row of `kind` prints in, as `tableContent` hands it\n * to pdfmake: its style's token, its style's weight where it sets one and\n * else the kind's, and its style's slant.\n */\nexport function cellFace(style: TextStyle, kind: RowKind): FaceWanted {\n return { token: style.font, bold: style.bold ?? KIND_BOLD[kind], italic: style.italic ?? false }\n}\n\n/** A table cell as the renderer makes it. A cell a column span covers is one too, as pdfmake requires, and pdfmake lays out nothing of it. */\nexport interface Cell {\n readonly text: string\n readonly alignment: TableColumn['align']\n readonly colSpan?: number\n headlineLevel?: number\n id?: string\n /** Set by a table's planned breaks (`table-rules.ts`). */\n pageBreak?: 'before'\n}\n\n/** A row as pdfmake lays it out: the header, the empty text in place of detail rows when there are none, the document's rows. */\nexport interface Row {\n readonly kind: RowKind\n readonly cells: readonly Cell[]\n}\n\n/**\n * The content of `table`, standing `width` wide: `kept` inside a keep-together\n * block or a page region, where no rule may break it; `record`ing its cells\n * for the word check; `top` the body's top, outside any frame, where its\n * breaks can be planned (`table-rules.ts`). Every column is handed to pdfmake\n * as a number, a fill column as its share, never as `'*'`, which pdfmake\n * widens to its longest word (`widths.ts`).\n */\nexport function tableContent(\n table: Table,\n build: Build,\n place: { readonly width: number; readonly kept: boolean; readonly record: boolean; readonly top: number },\n): Content {\n const { kept } = place\n const measuring = build.mode === 'measure'\n const columns = table.columns.length\n const widths = columnWidths(\n table.columns.map((column) => column.width),\n place.width,\n ).map((width) => width - 2 * PADDING_X)\n const across = place.width - 2 * PADDING_X\n // A no-break space where a cell is empty while measuring: every cell then\n // lays out one line, as tall as a cell of text beside it, so each row has a\n // first cell to mark.\n const cell = (text: string, column: number, kind: RowKind, style: TextStyle, span?: number): Cell => ({\n text: measuring && text === '' ? NO_BREAK_SPACE : text,\n alignment: style.align ?? table.columns[column]!.align,\n ...textProperties(style, { size: TABLE_SIZE, bold: KIND_BOLD[kind] }, build.familyOf),\n ...(span === undefined ? {} : { colSpan: span }),\n })\n // The cells a span covers: one per column after the first, laid out as nothing.\n const covered = (): Cell[] => table.columns.slice(1).map((_, index) => cell('', index + 1, 'detail', {}))\n const styled = styledRows(table)\n const rows = styled.map(({ kind, cells, styles, across }): Row => {\n if (across) return { kind, cells: [cell(cells[0]!, 0, kind, styles[0]!, columns), ...covered()] }\n return { kind, cells: cells.map((text, column) => cell(text, column, kind, styles[column]!)) }\n })\n if (place.record) recordWords(table, rows, widths, across, build)\n // Under a header of no height where the table has none, and pdfmake repeats a header: in the PDF's passes, never the body pass.\n const unseen = table.header === undefined && !measuring\n const plan = build.plans.get(table) ?? UNPLANNED\n if (measuring) {\n // A no-break space is no text to `printing`, as the empty cell it stands for prints none: the plan reads the rows the rules will.\n build.measuredRows.set(\n table,\n rows.map((row, at) => {\n const index = styled[at]!.index\n return {\n kind: row.kind,\n mark: mark(row.cells[0]!, build),\n keep: (index === undefined ? undefined : table.rows[index]!.keepWithRows) ?? 1,\n prints: printing(row).length > 0,\n }\n }),\n )\n } else if (!kept) {\n // In the body outside any frame, a page the table continues on starts under its top rule and repeated header, of no pitch where it has none.\n tableRules(unseen ? [UNSEEN_ROW, ...rows] : rows, plan, build, place.top === build.bodyTop ? build.bodyTop + RULE + (plan.pitches[0] ?? 0) : undefined)\n }\n const cells = rows.map((row): TableCell[] => [...row.cells])\n return {\n table: {\n headerRows: measuring ? 0 : 1,\n ...(measuring || plan.keepWithHeaderRows === 0 ? {} : { keepWithHeaderRows: plan.keepWithHeaderRows }),\n ...(measuring ? {} : { dontBreakRows: plan.dontBreakRows }),\n widths,\n body: unseen ? [table.columns.map((): TableCell => ({ stack: [] })), ...cells] : cells,\n },\n layout: unseen ? UNSEEN_LAYOUT : TABLE_LAYOUT,\n fontSize: TABLE_SIZE,\n }\n}\n\n/** Every cell of the table, held to its column's width, or the table's for a cell across it (`words.ts`). */\nfunction recordWords(table: Table, rows: readonly Row[], widths: readonly number[], across: number, build: Build): void {\n let row = 0\n for (const { kind, cells } of rows) {\n const which =\n kind === 'header' ? `the header of table ${table.id}` : kind === 'empty' ? `the empty text of table ${table.id}` : `row ${row++} of table ${table.id}`\n cells.forEach((cell, column) => {\n if (cell.text === '') return\n const spans = cell.colSpan !== undefined\n build.words.push({\n node: cell,\n width: spans ? across : widths[column]!,\n lines: 1,\n what: spans ? which : `${which}, column ${column + 1}`,\n subject: table.id,\n })\n })\n }\n}\n","import type { Content, CustomTableLayout } from 'pdfmake/interfaces.js'\nimport type { Block, Columns, Image, ImageAsset, Inline, Paragraph, Rectangle, Rule, Section, TextStyle } from '@formancy/report-runtime'\nimport { base64 } from './bytes.js'\nimport { startsOnPage, type Build, type Fields } from './build.js'\nimport { chartContent } from './chart-content.js'\nimport { epcContent } from './epc.js'\nimport type { FaceWanted } from './host-fonts.js'\nimport { qrContent } from './qr.js'\nimport { isShifted, loweredLineHeight } from './shifted.js'\nimport { DEFAULT_SIZE, textProperties } from './style.js'\nimport { svgContent } from './svg-content.js'\nimport { tableContent } from './table.js'\nimport { columnWidths } from './widths.js'\nimport { MAX_WORD_LINES } from './words.js'\n\n/**\n * The document's blocks as pdfmake content (`build.ts` says what a build\n * accumulates, and in which mode).\n *\n * Most blocks are one pdfmake node each. A section is its blocks: in a stack\n * of their own when it has no frame, as though it were not there, and in a\n * table of one cell when it has one, whose borders pdfmake draws around the\n * part of it on each page. A columns block is pdfmake's columns, with no gap\n * between them but what their widths leave.\n */\n\n/** Space above and below a rule's line. A rule block takes its line and both. */\nexport const RULE_GAP = 3\n\n/** The weight a rectangle's outline is drawn at, inside its box: the table rules' weight. */\nexport const OUTLINE = 0.5\n\n/** How far a node may start below the top of what it sits under and still be first there: rounding, not layout. */\nconst AT_TOP = 0.5\n\n/** Where a list of blocks stands. */\ninterface Scope {\n /** The width the blocks are laid out across. */\n readonly width: number\n /** No rule may break inside: a keep-together block, a page region, a column. */\n readonly kept: boolean\n /** Where a page's first line of these blocks would start: the body's top, below every frame around them; on page 1, `Build.firstShift` lower. */\n readonly top: number\n /** The page fields' values, in a page region pdfmake draws on every page; none in page 1's own header (0060), which holds none. */\n readonly fields?: Fields\n /** Whether its text nodes are recorded for the word check: not a page region's in the last pass, which pdfmake builds anew for each page and a measuring pass has checked. */\n readonly record: boolean\n}\n\n/**\n * Content for the body's blocks, laid out `width` wide, or a page region's\n * when `region` is given: kept, so that no rule breaks it and no node of it\n * gets an id, with the values of its page fields where it has them -- page\n * 1's own header (0060) has none, and is a page region all the same.\n */\nexport function contentOf(blocks: readonly Block[], build: Build, width: number, region?: { readonly fields?: Fields }): Content[] {\n const record = region === undefined || build.mode === 'measure'\n if (region === undefined) return sequence(blocks, build, { width, kept: false, top: build.bodyTop, record })\n return sequence(blocks, build, { width, kept: true, top: 0, record, ...(region.fields === undefined ? {} : { fields: region.fields }) })\n}\n\n/** Border and padding on each side of a section: what it takes from the width, and from a page's height above and below. */\nexport function frameOf(section: Section): number {\n return (section.border?.thickness ?? 0) + (section.padding ?? 0)\n}\n\n/** A section with neither border, fill nor padding is its blocks and nothing more. */\nfunction framed(section: Section): boolean {\n return section.border !== undefined || section.fill !== undefined || (section.padding ?? 0) > 0\n}\n\n/** The blocks with every section that has no frame replaced by its blocks, which flow as though they stood in its place. */\nfunction unframed(blocks: readonly Block[]): Block[] {\n return blocks.flatMap((block) => (block.kind === 'section' && !framed(block) ? unframed(block.blocks) : [block]))\n}\n\n/**\n * The blocks' content. Outside a kept scope, a keep-with-next paragraph\n * breaks to the next page when the block it is kept with does not start on\n * its page -- unless it is first on its page already, where a break would\n * leave the page empty and the paragraph no better kept on the next.\n */\nfunction sequence(given: readonly Block[], build: Build, scope: Scope): Content[] {\n const blocks = unframed(given)\n const contents = blocks.map((block) => blockContent(block, build, scope))\n if (build.mode !== 'render' || scope.kept) return contents\n blocks.forEach((block, index) => {\n if (block.kind !== 'paragraph' || block.keepWithNext !== true) return\n const anchor = keptWith(blocks, contents, index)\n if (anchor === undefined) return\n anchor.id ??= `kept-${build.next++}`\n const ids = new Set([anchor.id])\n const own = build.next++\n ;(contents[index] as Anchor).headlineLevel = own\n build.rules.set(own, (node, queries) => {\n const { top, pageNumber } = node.startPosition\n // Page 1's body starts below its own header where it has one (0060), and a node first there is first on its page.\n const first = scope.top + (pageNumber === 1 ? build.firstShift : 0)\n return top > first + AT_TOP && !startsOnPage(queries, ids, pageNumber)\n })\n })\n return contents\n}\n\n/** A node of the content the renderer builds, as far as a rule needs to know it: always an object, every table cell and column included. */\ninterface Anchor {\n readonly text?: unknown\n readonly image?: unknown\n /** A QR code or an EPC QR code, or a chart's marks: what the renderer draws as an SVG (`qr.ts`, `epc.ts`, `chart-content.ts`). */\n readonly svg?: unknown\n readonly stack?: readonly Anchor[]\n readonly columns?: readonly Anchor[]\n /** A table, its rows as pdfmake takes them: `headerRows` of them first, which pdfmake repeats on every page the table continues on. */\n readonly table?: { readonly headerRows?: number; readonly body: readonly (readonly Anchor[])[] }\n /** A keep-together block in the PDF's pass, or a chart: laid out where it starts and moved whole. */\n readonly unbreakable?: boolean\n id?: string\n headlineLevel?: number\n}\n\n/**\n * The first node of `node` that prints text, or an image or a QR code when\n * no text comes first: where pdfmake records the content's start. Of a\n * table, the first of its body rows' cells, and of its header rows' only\n * where none of those prints: pdfmake writes the page each repetition of\n * a table's header stands on into the start of the header's cells, so\n * that one says the table starts on the last page it reaches\n * (`pdfmake.test.ts`), and a heading kept with it moved to the next page\n * whenever the table ran past its own. Of an unbreakable node -- a\n * keep-together block, a chart -- the first that prints text wherever it\n * stands in it, a table's header first, and an image or an SVG only where\n * none does: pdfmake records where each of its nodes starts on the page\n * its layout began on, and corrects that page, once it moves the node to\n * the next, for text with an id alone (`pdfmake.test.ts`); a chart paints\n * its marks before its first word; and no header repeats inside a block\n * that moves whole.\n */\nfunction anchorOf(node: Anchor): Anchor | undefined {\n if (node.unbreakable === true) return firstOf(node, printsText) ?? firstOf(node, prints)\n const inner = node.table === undefined ? innerOf(node) : bodyFirst(node.table)\n if (inner === undefined) return prints(node) ? node : undefined\n for (const each of inner) {\n const anchor = anchorOf(each)\n if (anchor !== undefined) return anchor\n }\n return undefined\n}\n\n/** The nodes `node` holds, in the order pdfmake lays them out: a stack's, columns', or a table's cells, row by row; none for a leaf. */\nconst innerOf = (node: Anchor): readonly Anchor[] | undefined => node.stack ?? node.columns ?? node.table?.body.flat()\n\n/** A table's cells, row by row, its body rows' before its header rows', which pdfmake repeats on every page the table continues on. */\nfunction bodyFirst({ headerRows = 0, body }: NonNullable<Anchor['table']>): readonly Anchor[] {\n return [...body.slice(headerRows), ...body.slice(0, headerRows)].flat()\n}\n\n/** The first node of `node`, itself or one it holds, in the order pdfmake lays them out, that `takes`. */\nfunction firstOf(node: Anchor, takes: (leaf: Anchor) => boolean): Anchor | undefined {\n const inner = innerOf(node)\n if (inner === undefined) return takes(node) ? node : undefined\n for (const each of inner) {\n const found = firstOf(each, takes)\n if (found !== undefined) return found\n }\n return undefined\n}\n\n/** Whether `leaf` prints text: a paragraph's text is an array of runs, and the renderer keeps nothing with a paragraph that prints nothing. */\nconst printsText = (leaf: Anchor): boolean => (typeof leaf.text === 'string' ? leaf.text.trim() !== '' : Array.isArray(leaf.text))\n\n/** Whether `leaf` prints text, an image or an SVG. */\nconst prints = (leaf: Anchor): boolean => printsText(leaf) || leaf.image !== undefined || leaf.svg !== undefined\n\n/**\n * Where the block a keep-with-next paragraph at `index` stays with starts:\n * the anchor of the next block that prints text, an image, a QR code or a\n * chart, past spacers, rules, rectangles and other keep-with-next paragraphs, so\n * that a run of headings moves as one. None when a page break or the end of\n * the list comes first: a heading over nothing is not kept with anything.\n */\nfunction keptWith(blocks: readonly Block[], contents: readonly Content[], index: number): Anchor | undefined {\n for (let next = index + 1; next < blocks.length; next++) {\n const block = blocks[next]!\n if (block.kind === 'pageBreak') return undefined\n const anchor = block.kind === 'paragraph' && block.keepWithNext === true ? undefined : anchorOf(contents[next] as Anchor)\n if (anchor !== undefined) return anchor\n }\n return undefined\n}\n\nfunction blockContent(block: Block, build: Build, scope: Scope): Content {\n switch (block.kind) {\n case 'paragraph':\n return paragraphContent(block, build, scope)\n case 'table':\n return tableContent(block, build, scope)\n case 'image':\n return imageContent(block, build)\n case 'qrCode':\n // check.ts encodes every QR code before anything is built.\n return qrContent(build.codes.get(block)!, block.size)\n case 'epcQrCode':\n // And every EPC QR code.\n return epcContent(build.codes.get(block)!, block)\n case 'rule':\n return ruleContent(block, scope.width)\n case 'rectangle':\n return rectangleContent(block)\n // An empty stack, never empty text: pdfmake lays out empty text as one\n // line of the default size, which would add 11.7pt to every spacer and\n // to the top of the page after every break. At the foot of a page with\n // less room than it asks for, a spacer moves to the next page and starts\n // there, without the space.\n case 'spacer':\n return { stack: [], margin: [0, block.height, 0, 0] }\n case 'pageBreak':\n return { stack: [], pageBreak: 'before' }\n case 'keepTogether':\n return { stack: sequence(block.blocks, build, { ...scope, kept: true }), unbreakable: build.mode === 'render' }\n case 'columns':\n return columnsContent(block, build, scope)\n case 'section':\n return sectionContent(block, build, scope)\n case 'chart':\n return chartContent(block, build)\n }\n}\n\nfunction paragraphContent(paragraph: Paragraph, build: Build, scope: Scope): Content {\n const style = paragraph.style ?? {}\n const content = {\n text: paragraph.runs.length === 0 ? '' : paragraph.runs.map((run) => inline(run, scope.fields, () => build.lineOf(runFace(paragraph.style, run)))),\n alignment: style.align ?? 'left',\n ...textProperties(style, { size: DEFAULT_SIZE }, build.familyOf),\n }\n // check.ts walks every paragraph, and records where it stands, before anything is built.\n const at = build.paths.get(paragraph) as string\n if (scope.record) build.words.push({ node: content, width: scope.width, lines: MAX_WORD_LINES, what: at, subject: at })\n if (scope.record && paragraph.runs.some(isShifted)) build.shifted.push({ node: content, width: scope.width, subject: at })\n return content\n}\n\n/**\n * The face a paragraph's run prints in, as `inline` hands it to pdfmake:\n * the paragraph's token and slant, and the run's own weight where it sets\n * one, which pdfmake sets over the paragraph's; a page field prints in the\n * paragraph's own face. check.ts holds a run's text to this face, and\n * bound.ts counts the paragraph's least line by it.\n */\nexport function runFace(style: TextStyle | undefined, run: Inline): FaceWanted {\n return { token: style?.font, bold: ('text' in run ? run.bold : undefined) ?? style?.bold ?? false, italic: style?.italic ?? false }\n}\n\n/** pdfmake's own property for a run set below or above the line (0061), which sets it at the size and the move the document states. */\nconst SHIFT = { subscript: { sub: true }, superscript: { sup: true } } as const\n\n/** A run as pdfmake takes it; one set below the line asks for its line's room, `lineOf` being the line of the face it prints in (`shifted.ts`). */\nfunction inline(run: Inline, fields: Fields | undefined, lineOf: () => number): { text: string; bold?: boolean; sub?: true; sup?: true; lineHeight?: number } {\n if ('text' in run)\n return {\n text: run.text,\n ...(run.bold === undefined ? {} : { bold: run.bold }),\n ...(run.baseline === undefined ? {} : SHIFT[run.baseline]),\n ...(run.baseline === 'subscript' ? { lineHeight: loweredLineHeight(lineOf()) } : {}),\n }\n // The renderer refuses a page field outside the page header and footer before building anything, page 1's own header among them.\n if (fields === undefined) throw new Error(`a ${run.field} field outside the page header and footer`)\n return { text: String(fields[run.field]) }\n}\n\n/**\n * An image in its box, which the layout reserves whole. An SVG is drawn in\n * the box itself, by pdfmake's SVG converter, which fits and centres it\n * (`svg-content.ts`). For a PNG or a JPEG, `cover` is pdfmake's own: the box\n * clipped, the image scaled to fill it and centred. `contain` is drawn at\n * the size the box allows at the image's proportions, read from its pixels,\n * and centred in the box by margins that make up the rest of it.\n */\nfunction imageContent(image: Image, build: Build): Content {\n // The asset checks read every image's asset before anything is built.\n const checked = build.assets.get(image.asset)!\n if (checked.kind === 'vector') return svgContent(image, checked)\n const key = imageKey(image.asset, build)\n if (image.fit === 'cover') return { image: key, cover: { width: image.width, height: image.height, align: 'center', valign: 'center' } }\n const scale = Math.min(image.width / checked.width, image.height / checked.height)\n const [width, height] = [checked.width * scale, checked.height * scale]\n const [x, y] = [(image.width - width) / 2, (image.height - height) / 2]\n return { image: key, width, height, margin: [x, y, image.width - width - x, y] }\n}\n\nfunction imageKey(asset: ImageAsset, build: Build): string {\n const known = build.imageKeys.get(asset)\n if (known !== undefined) return known\n const key = `image${build.imageKeys.size}`\n build.imageKeys.set(asset, key)\n build.images[key] = `data:${asset.mediaType};base64,${base64(asset.bytes)}`\n return key\n}\n\n/**\n * pdfmake makes a canvas as tall as its lowest point and strokes a line half\n * its width to either side: the line half its width down, and the other half\n * of it in the margin below.\n */\nfunction ruleContent(rule: Rule, width: number): Content {\n const half = rule.thickness / 2\n return {\n canvas: [{ type: 'line', x1: 0, y1: half, x2: width, y2: half, lineWidth: rule.thickness, lineColor: rule.color ?? '#000000' }],\n margin: [0, RULE_GAP, 0, RULE_GAP + half],\n }\n}\n\n/**\n * A rectangle's box, exactly: its outline is stroked inside it, half the\n * weight in from each edge, and the canvas, as tall as its lowest point,\n * takes the rest of the box in a margin. A box no wider or taller than two\n * outlines is all outline, and is filled with the outline's colour.\n */\nfunction rectangleContent(rectangle: Rectangle): Content {\n const { width, height, fill, stroke } = rectangle\n if (stroke === undefined || Math.min(width, height) <= 2 * OUTLINE) {\n const color = stroke ?? fill\n return {\n canvas: color === undefined ? [] : [{ type: 'rect', x: 0, y: 0, w: width, h: height, color, lineWidth: 0 }],\n margin: [0, 0, 0, color === undefined ? height : 0],\n }\n }\n const half = OUTLINE / 2\n return {\n canvas: [\n {\n type: 'rect',\n x: half,\n y: half,\n w: width - OUTLINE,\n h: height - OUTLINE,\n lineWidth: OUTLINE,\n lineColor: stroke,\n ...(fill === undefined ? {} : { color: fill }),\n },\n ],\n margin: [0, 0, 0, half],\n }\n}\n\n/** Columns at the widths worked out here, never pdfmake's `'*'`, which a long word widens past the page (`widths.ts`). */\nfunction columnsContent(columns: Columns, build: Build, scope: Scope): Content {\n const widths = columnWidths(\n columns.columns.map((slot) => slot.width),\n scope.width,\n )\n return {\n columns: columns.columns.map((slot, index) => {\n const width = widths[index]!\n return { width, stack: sequence(slot.blocks, build, { ...scope, width, kept: true }) }\n }),\n columnGap: 0,\n }\n}\n\n/**\n * A section with a frame is a table of one cell: pdfmake draws its border\n * and fill around the part of it on each page, and lays out its blocks\n * inside the padding as it lays out the body, tables with their repeated\n * headers and page breaks included.\n */\nfunction sectionContent(section: Section, build: Build, scope: Scope): Content {\n const frame = frameOf(section)\n const border = section.border?.thickness ?? 0\n const color = section.border?.color ?? '#000000'\n const padding = section.padding ?? 0\n const fill = section.fill\n const layout: CustomTableLayout = {\n hLineWidth: () => border,\n vLineWidth: () => border,\n hLineColor: () => color,\n vLineColor: () => color,\n paddingLeft: () => padding,\n paddingRight: () => padding,\n paddingTop: () => padding,\n paddingBottom: () => padding,\n ...(fill === undefined ? {} : { fillColor: () => fill }),\n }\n const width = scope.width - 2 * frame\n const inner = sequence(section.blocks, build, { ...scope, width, top: scope.top + frame })\n return { table: { widths: [width], body: [[{ stack: inner }]] }, layout }\n}\n","import { RenderRefusal, SHIFTED_SIZE, type Block, type Paragraph, type Table, type TextStyle } from '@formancy/report-runtime'\nimport type { RowKind } from './build.js'\nimport { frameOf, runFace } from './content.js'\nimport type { FaceWanted, RenderFonts } from './host-fonts.js'\nimport { isShifted, loweredLineHeight } from './shifted.js'\nimport { DEFAULT_SIZE } from './style.js'\nimport { cellFace, cellSize, PADDING_Y, styledRows } from './table.js'\n\n/**\n * A height the body cannot be shorter than, worked out from the document\n * alone, so that a job too long for its page limit is refused before\n * pdfmake measures it.\n *\n * pdfmake measures every node of a document before it lays out the first\n * page, and the page limit stops only the layout: refusing 100,000 table\n * rows against five pages took 20 seconds, all of it measuring, and nothing\n * could interrupt it (measured on 2026-10-15, on an Intel i9-10900K under\n * Node 24.21). A document whose least height is more than the limit's pages\n * of body is refused here, for nothing.\n *\n * Least, never more than pdfmake lays out, so that nothing that fits is\n * refused: a paragraph is one line of its size, however it wraps, as tall\n * as its tallest run, since pdfmake lays a line out as tall as the tallest\n * run on it; a table's row, the header and the empty text among them, one\n * line of its tallest cell of text, each cell as `styledRows` styles it,\n * and its padding, without its rule; an image, a rectangle and a rule\n * their own height, without the space around a rule, and a QR code and an\n * EPC QR code its side; a frame its border and padding once. A spacer and\n * a page break count nothing, since a spacer at the foot of a page gives\n * up its space, and a page region is not body.\n *\n * A line is its size times the line of the face it prints in (0043), the\n * face check.ts held its text to, never another face the report maps: a\n * host face of a shorter line than Roboto's lowers no bound but its own\n * text's, and none lower than report-spec's reader admits,\n * `MIN_FONT_LINE` ems.\n */\nexport function leastHeight(blocks: readonly Block[], fonts: Pick<RenderFonts, 'face'>): number {\n return blocks.reduce((sum, block) => sum + least(block, fonts), 0)\n}\n\nfunction least(block: Block, fonts: Pick<RenderFonts, 'face'>): number {\n switch (block.kind) {\n case 'paragraph':\n return paragraphLine(block, fonts)\n case 'table':\n return tableHeight(block, fonts)\n case 'image':\n case 'rectangle':\n case 'chart':\n return block.height\n case 'qrCode':\n case 'epcQrCode':\n return block.size\n case 'rule':\n return block.thickness\n case 'spacer':\n case 'pageBreak':\n return 0\n case 'keepTogether':\n return leastHeight(block.blocks, fonts)\n case 'section':\n return leastHeight(block.blocks, fonts) + 2 * frameOf(block)\n case 'columns':\n return Math.max(0, ...block.columns.map((slot) => leastHeight(slot.blocks, fonts)))\n }\n}\n\n/** A line of `size` in the face `wanted` names: check.ts resolved every face a block prints in before the bound is taken, so none is refused here. */\nfunction line(size: number, wanted: FaceWanted, fonts: Pick<RenderFonts, 'face'>): number {\n return size * fonts.face(wanted.token, wanted.bold, wanted.italic, '').lineFactor\n}\n\n/**\n * One line of the paragraph, as tall as its tallest run's, since pdfmake\n * lays a line out as tall as the tallest run on it; nothing for a paragraph\n * of no runs. A run set below or above the line is laid out at\n * `SHIFTED_SIZE` of the paragraph's size, as pdfmake sets it, and one below\n * it with the room the renderer asks of pdfmake for it, `loweredLineHeight`\n * (0061). It is the least a paragraph takes of the body, and a line of it\n * no page can hold, which check.ts refuses where it is taller than the body.\n */\nexport function paragraphLine(paragraph: Paragraph, fonts: Pick<RenderFonts, 'face'>): number {\n const size = paragraph.style?.size ?? DEFAULT_SIZE\n let tallest = 0\n for (const run of paragraph.runs) {\n const wanted = runFace(paragraph.style, run)\n const own = line(isShifted(run) ? SHIFTED_SIZE * size : size, wanted, fonts)\n const room = 'text' in run && run.baseline === 'subscript' ? loweredLineHeight(line(1, wanted, fonts)) : 1\n tallest = Math.max(tallest, own * room)\n }\n return tallest\n}\n\n/** A cell's line: its size times the line of the face it prints in, as `styledRows` styles it. check.ts refuses a row whose cell's line, with its padding, is taller than the body. */\nexport function cellLine(style: TextStyle, kind: RowKind, fonts: Pick<RenderFonts, 'face'>): number {\n return line(cellSize(style), cellFace(style, kind), fonts)\n}\n\n/** Each row the table lays out: one line of the tallest cell of text in it, and the cells' padding above and below. */\nfunction tableHeight(table: Table, fonts: Pick<RenderFonts, 'face'>): number {\n let height = 0\n for (const row of styledRows(table)) {\n let tallest = 0\n row.cells.forEach((text, column) => {\n if (text !== '') tallest = Math.max(tallest, cellLine(row.styles[column]!, row.kind, fonts))\n })\n height += tallest + 2 * PADDING_Y\n }\n return height\n}\n\n/**\n * Refuses a body whose least height needs more than `maxPages` pages of\n * body -- page 1's, `bodies.first`, under its own header where it has one\n * (0060), and the later pages', `bodies.later` -- with `reserved` points\n * more at its end: the room a QR-bill's slip keeps on the last page. That\n * room is less than a page's body, so it takes at least its own height of\n * the pages whether it ends the last page of the body or starts one of its\n * own, and the two heights together stay a least height.\n */\nexport function refuseOversized(\n blocks: readonly Block[],\n bodies: { readonly first: number; readonly later: number },\n maxPages: number,\n fonts: Pick<RenderFonts, 'face'>,\n reserved = 0,\n): void {\n const height = leastHeight(blocks, fonts) + reserved\n const room = maxPages * bodies.later + (bodies.first - bodies.later)\n if (height > room) {\n const slip = reserved > 0 ? `, the ${reserved.toFixed(2)} pt the payment part's slip keeps at its end included` : ''\n throw new RenderRefusal(\n 'too-many-pages',\n `the report needs more than ${maxPages} pages: its body is at least ${height.toFixed(2)} pt tall${slip}, and ${maxPages} pages hold ${room.toFixed(2)} pt`,\n )\n }\n}\n","import { RenderRefusal, type Chart } from '@formancy/report-runtime'\nimport type { ChartLayout } from './chart-option.js'\nimport type { PlacedWord } from './chart-svg.js'\n\n/**\n * Where a chart's words may stand (0058): inside its box, apart from each\n * other, and, but for a value's label, out of its plot. pdfmake prints\n * every word where it is placed, so a word past the box would print over\n * what stands beside the chart, and two that meet one over the other: the\n * chart is refused, naming it and its box, and quoting no word. The one\n * statement of the rule, for a chart ECharts laid out (`chart-draw.ts`)\n * and one with nothing to draw, whose title and empty text the renderer\n * places itself (`chart-empty.ts`). It imports nothing of ECharts, so\n * that a document whose only chart is empty loads none.\n */\n\n/** What a refusal of `chart` starts with: its id and its box. */\nexport const named = (chart: Chart): string => `the chart ${chart.id}, ${String(chart.width)} by ${String(chart.height)} points, `\n\n/** A refusal of `chart` whose content does not fit, saying what it `has`. */\nexport function tooLarge(chart: Chart, has: string): never {\n throw new RenderRefusal('content-too-large', `${named(chart)}${has}`, chart.id)\n}\n\n/** `size` points, to the hundredth, as a refusal says it. */\nexport const points = (size: number): string => String(Math.round(size * 100) / 100)\n\n/** A plot, or a pie's square, in points from the chart's top left. */\nexport type Plot = NonNullable<ChartLayout['plot']>\n\n/** What a box is to the rules: a word's, a plot's or a pie's square, from the chart's top left. */\ninterface Box {\n readonly x: number\n readonly top: number\n readonly width: number\n readonly height: number\n}\n\n/** Whether `a` and `b` overlap: boxes that share an edge do not meet. */\nconst meet = (a: Box, b: Box): boolean => a.x < b.x + b.width && b.x < a.x + a.width && a.top < b.top + b.height && b.top < a.top + a.height\n\n/**\n * `words`, of `chart`, on `plot` where it has one, refused where a word\n * stands past the box, a word but a value's label stands in the plot, or\n * two words meet; returned as they are otherwise.\n */\nexport function held(chart: Chart, words: readonly PlacedWord[], plot?: Plot): readonly PlacedWord[] {\n const past = ({ x, top, width, height }: PlacedWord): boolean => x < 0 || top < 0 || x + width > chart.width || top + height > chart.height\n if (words.some(past)) tooLarge(chart, 'has a word that would leave its box')\n if (plot !== undefined) {\n const area: Box = { x: plot.left, top: plot.top, width: plot.width, height: plot.height }\n if (words.some((word) => !word.key.startsWith('value/') && meet(word, area))) tooLarge(chart, 'has a word that would stand in its plot')\n }\n if (words.some((word, index) => words.slice(index + 1).some((other) => meet(word, other)))) tooLarge(chart, 'has two words that would meet')\n return words\n}\n","import { RenderRefusal, type AxisChart, type Chart, type ChartSeriesValues, type ChartValue, type PieChart } from '@formancy/report-runtime'\nimport type { BarSeriesOption, LineSeriesOption, PieSeriesOption } from 'echarts/charts'\nimport type { GridComponentOption, LegendComponentOption, TitleComponentOption } from 'echarts/components'\nimport type { ComposeOption } from 'echarts/core'\nimport type { ChartFace, ChartFaces } from './chart-faces.js'\n\n/**\n * The option ECharts is handed for a chart (0058): ECharts lays the chart\n * out and draws its marks, and pdfmake prints each of its words where\n * ECharts placed it, so the option holds everything ECharts could decide\n * otherwise than the report did, and nothing it could round or rewrite.\n *\n * - **Numbers.** The value axis is the runtime's ticks, fixed, in places:\n * tick i stands at place i, from 0 at the lowest to the last index at\n * the highest, each a gridline, and every `tickEvery`-th from the lowest\n * labelled. A value stands at its distance from the lowest tick in the\n * ticks' interval (`placesOf`), worked out from the runtime's decimal\n * strings exactly but for the one division that makes it a coordinate,\n * and a bar stands on zero's place. ECharts never sees a value, so it\n * neither rounds nor formats one, and places each mark where its value\n * stands among the ticks, however close the ticks stand for their size:\n * the values' doubles would put ticks that share fifteen leading digits\n * up to half an interval from their places, and draw two ticks that\n * share seventeen as one. This is what the drawing's fixed value axis\n * is: the runtime's ticks by their places, never their doubles; and\n * every number ECharts is handed is a place, or a slice's share of its\n * pie worked out the same way, or `NO_SHARE` for a slice of none, never\n * `Number(exact)`. Every word it prints is the runtime's, looked up by\n * index.\n * - **Words.** ECharts sees a category as its key (`c0`) and a series as\n * its (`s0`). Every word comes from a formatter -- the chart's title and\n * its axes' titles from the block itself -- and a formatter asked for an\n * index, a key or a place the block does not have throws, naming the\n * chart and counts and quoting no word. Every word is the one pdfmake\n * prints, trimmed as pdfmake trims a run (`chartText`), for ECharts and\n * for the words a layout prints alike. Nothing wraps, cuts, hides,\n * turns or reads a word as markup: no text width, overflow, ellipsis,\n * rich text, string formatter, rotation, hideOverlap or automatic\n * interval, and no showMinLabel or showMaxLabel, which set either way\n * hide a label that meets its neighbour, where unset with a fixed axis\n * and every category labelled ECharts hides none (AxisBuilder.js\n * `fixMinMaxLabelShow`).\n * - **Colours.** Every colour it paints is the block's -- each series' or\n * slice's and each legend entry's -- the grid's or the axis's, the\n * words' style's, or transparent; none is left to ECharts' theme.\n * - **Styles.** Every word in its face's font (`chart-faces.ts`), the\n * title's or the words', colour included.\n *\n * What it paints, which 0058 states and the corpus reads: bars, slices\n * and line markers filled in their colour, each with no border, and\n * nothing of a slice of no share (`NO_SHARE`); lines, gridlines and the\n * category axis's line stroked, that line a horizontal stroke in the\n * axis's colour beside the gridlines; legend swatches filled and stroked\n * in their colour, a slice of no share's among them; nothing else -- no\n * tick, no value axis line, no background, and no border or background on\n * the title or the legend.\n *\n * It imports ECharts' types alone, so that a module reading a chart's\n * words loads no ECharts: the drawing, which a document with a chart\n * loads, hands the option over (`chart-draw.ts`).\n */\n\n/** Of a category's slot: the room left between one category's bars and the next's, ECharts' `barCategoryGap`. Chosen, as a table's padding is. */\nexport const BAR_CATEGORY_GAP = 0.2\n\n/** Of a bar's width: the room between the bars of one category, ECharts' `barGap`. Chosen. */\nexport const BAR_GAP = 0.25\n\n/** Points: a line's marker's radius, the line's width, and the stroke round a legend's swatch. Chosen. */\nexport const POINT_RADIUS = 2\nexport const LINE_WIDTH = 1.5\nexport const SWATCH_BORDER = 0.5\n\n/** Points: how far a value's label stands from its bar's end or its line's point, ECharts' own default, stated, since the room kept for a label holds it too. */\nexport const VALUE_LABEL_DISTANCE = 5\n\n/** Points: how far the category labels stand under the plot's foot, ECharts' own default, stated, since a bar below zero labelled under its end widens it. */\nexport const CATEGORY_LABEL_MARGIN = 8\n\n/** Points: how far a chart's title stands below its box's top, ECharts' own default padding, stated, since an empty chart's title, which the renderer places, stands there too (`chart-empty.ts`). */\nexport const TITLE_PADDING = 5\n\n/** Whether `value` is below zero, the one test of it the option and the check make: a bar of it stands down from zero, labelled under its end, and a slice of it is refused (`check-chart.ts`). */\nexport const belowZero = (value: ChartValue): boolean => value.exact.startsWith('-')\n\n/** The value axis's gridlines, one at every tick, and the category axis's line: the renderer's, as a table's rules are. Chosen. */\nexport const GRID = { color: '#d9d9d9', width: 0.5 } as const\nexport const AXIS = { color: '#000000', width: 0.75 } as const\n\n/** One word a chart may print, by which of its words it is, in the title's face or the words'. */\nexport interface ChartWord {\n /** 'title', 'categoryTitle', 'valueTitle', 'category/i', 'tick/i', 'value/s/i' (series s, category i), 'legend/j', or an empty chart's 'empty'. */\n readonly key: string\n readonly text: string\n /** Whether it prints in the title's face. */\n readonly title: boolean\n}\n\n/** One layout of a chart: the ticks it labels, and, once a layout before it has read them, its bands and its plot. */\nexport interface ChartLayout {\n /** Every `tickEvery`-th tick from the lowest is labelled, 1 labelling each; every tick is a gridline. */\n readonly tickEvery: number\n /** Set by the first layout: the title's band at the top, with a value label's line and its distance from its mark where values are labelled, or a line's marker's radius where they are not; the legend's rows at the foot. */\n readonly bands?: { readonly top: number; readonly bottom: number }\n /** Set by the second: the plot (axis charts) or the pie's square, in points, snapped. */\n readonly plot?: { readonly left: number; readonly top: number; readonly width: number; readonly height: number }\n}\n\n/**\n * A pie's series as the option holds it: its `labelLayout` null, which\n * ECharts 6.1.0 reads as no layout of its labels and its types do not\n * admit. Its default, `{ hideOverlap: true }`, lays a pie's hidden slice\n * labels out in zrender's own 12px sans-serif, which the measurer refuses\n * (`echarts.test.ts`).\n */\ntype PieSeries = Omit<PieSeriesOption, 'labelLayout'> & { labelLayout: null }\n\nexport type ChartOption = ComposeOption<BarSeriesOption | LineSeriesOption | PieSeries | GridComponentOption | LegendComponentOption | TitleComponentOption>\n\n/** A bar's width in a slot `slot` points wide, of `series` bars, as ECharts 6.1.0 lays it out by `BAR_CATEGORY_GAP` and `BAR_GAP` (layout/barGrid.js). */\nexport function barWidth(slot: number, series: number): number {\n return (slot * (1 - BAR_CATEGORY_GAP)) / (series + (series - 1) * BAR_GAP)\n}\n\n/** A category's key, which ECharts places it by, and a series' -- or for a pie, its legend's entries, which are its categories. */\nconst categoryKey = (index: number): string => `c${String(index)}`\nconst seriesKey = (index: number): string => `s${String(index)}`\n\n/** The ticks a layout labels, every `tickEvery`-th from the lowest, each with its index among all the chart's ticks, which is its place on the axis. */\nfunction labelledTicks(chart: AxisChart, tickEvery: number): { readonly index: number; readonly tick: ChartValue }[] {\n if (!Number.isInteger(tickEvery) || tickEvery < 1) throw new Error(`the chart ${chart.id} cannot label every ${String(tickEvery)}th tick`)\n return chart.ticks.flatMap((tick, index) => (index % tickEvery === 0 ? [{ index, tick }] : []))\n}\n\n/**\n * A control character -- Unicode's general category Cc, which holds the\n * tab and every line break but two -- or one of those two, the line and\n * paragraph separators U+2028 and U+2029. zrender 6.1.0 splits a word into lines at a line\n * feed alone (`parseText.js`), and pdfmake's `noWrap` keeps a run whole,\n * as one word (`TextBreaker.js`); but pdfmake prints a tab four spaces\n * wide, and any other control character as its face's glyph for it --\n * Roboto's for U+0000 and U+0002 is empty -- while the PDF's text and\n * ECharts' SVG hold the character itself. Refusing the whole set is\n * fail-closed: wider than the characters either engine was read to break\n * a line at, so that a chart's word prints as it is written or not at all.\n */\nconst CONTROL = /[\\p{Cc}\\u2028\\u2029]/u\n\n/**\n * `text`, a word of the chart `id`, as the chart prints it: trimmed of the\n * whitespace pdfmake cuts from either end of a run it prints, JavaScript's\n * `\\s`, the no-break spaces U+00A0 and U+202F among it, so that ECharts\n * measures and places the very word pdfmake prints (`FaceWidths.width`),\n * which may be empty. A word holding a control character (`CONTROL`) is\n * refused, naming the chart and quoting nothing: it would print otherwise\n * than it is written. So is one that is not text, which pdfmake would read\n * as inlines, a link among them, or neither could print.\n */\nexport function chartText(text: unknown, id: string): string {\n if (typeof text !== 'string') throw new RenderRefusal('unsupported', `the chart ${id} has a word that is not text`, id)\n if (CONTROL.test(text))\n throw new RenderRefusal(\n 'unsupported',\n `the chart ${id} has a word with a tab, a line break or another control character in it, which a chart never prints`,\n id,\n )\n return text.trim()\n}\n\n/** A word the chart `id` may hold or not -- its title, an axis's, its empty text -- as it prints (`chartText`), '' where it holds none: a word that prints nothing asks for no face. */\nexport const wordOf = (text: string | undefined, id: string): string => (text === undefined ? '' : chartText(text, id))\n\n/**\n * Every word `chart` may print, in the order listed at `ChartWord.key`;\n * with a layout's `tickEvery`, the words that layout prints, its ticks\n * every `tickEvery`-th from the lowest. A value prints only where the\n * chart labels its values and it has one. Each word is as the chart\n * prints it (`chartText`), and a word empty once trimmed is no word: it\n * prints nothing, so nothing could prove it printed, and its slot -- a\n * category's, a legend entry's -- stays.\n */\nexport function chartWords(chart: Chart, layout?: Pick<ChartLayout, 'tickEvery'>): ChartWord[] {\n const words: ChartWord[] = []\n const push = (key: string, word: string, title = false): void => {\n if (word !== '') words.push({ key, text: word, title })\n }\n const add = (key: string, text: unknown): void => {\n push(key, chartText(text, chart.id))\n }\n push('title', wordOf(chart.title, chart.id), true)\n if (chart.chart !== 'pie') {\n push('categoryTitle', wordOf(chart.categoryTitle, chart.id))\n push('valueTitle', wordOf(chart.valueTitle, chart.id))\n chart.categories.forEach((text, index) => {\n add(`category/${String(index)}`, text)\n })\n for (const { index, tick } of labelledTicks(chart, layout?.tickEvery ?? 1)) add(`tick/${String(index)}`, tick.text)\n if (chart.valueLabels)\n chart.series.forEach(({ values }, series) => {\n values.forEach((each, index) => {\n if (each !== null) add(`value/${String(series)}/${String(index)}`, each.text)\n })\n })\n }\n chart.legend.forEach(({ text }, index) => {\n add(`legend/${String(index)}`, text)\n })\n push('empty', wordOf(chart.empty, chart.id))\n return words\n}\n\n/**\n * What ECharts is handed to lay `chart` out in `layout`, its words in\n * `faces`. A chart with nothing to draw is refused: it prints its title\n * and its empty text, and nothing ECharts would draw.\n */\nexport function chartOption(chart: Chart, faces: ChartFaces, layout: ChartLayout): ChartOption {\n if (chart.empty !== undefined) throw new Error(`the chart ${chart.id} has nothing to draw, and is printed without a layout`)\n const palette = chart.chart === 'pie' ? chart.slices.map(({ color }) => color) : chart.series.map(({ color }) => color)\n const frame: ChartOption = {\n animation: false,\n backgroundColor: 'transparent',\n color: palette,\n ...titleOf(chart, faces),\n ...legendOf(chart, faces.words),\n }\n return chart.chart === 'pie' ? { ...frame, series: [pieSeries(chart, layout)] } : { ...frame, ...axesOf(chart, faces.words, layout) }\n}\n\n/** The chart's title, at the top, `TITLE_PADDING` below it, centred, in the title's face, with no border or background; or none where it has none, or one that is empty once trimmed. */\nfunction titleOf(chart: Chart, faces: ChartFaces): Pick<ChartOption, 'title'> {\n const text = wordOf(chart.title, chart.id)\n if (text === '') return {}\n if (faces.title === undefined) throw new Error(`the chart ${chart.id} has a title and no face to print it in`)\n return {\n title: {\n text,\n left: 'center',\n top: 0,\n padding: TITLE_PADDING,\n textStyle: { ...faces.title.font },\n borderWidth: 0,\n borderColor: 'transparent',\n backgroundColor: 'transparent',\n },\n }\n}\n\n/**\n * The chart's legend, at the foot, ECharts' plain legend, whose entries\n * wrap into rows: each a square swatch an em wide, filled and stroked in\n * its colour, and its words, looked up by the key of what it names -- a\n * series', or for a pie a category's. None where the chart has no legend.\n */\nfunction legendOf(chart: Chart, words: ChartFace): Pick<ChartOption, 'legend'> {\n if (chart.legend.length === 0) return {}\n const keyOf = chart.chart === 'pie' ? categoryKey : seriesKey\n const keys = chart.legend.map((_, index) => keyOf(index))\n return {\n legend: {\n bottom: 0,\n icon: 'rect',\n itemWidth: words.size,\n itemHeight: words.size,\n borderWidth: 0,\n borderColor: 'transparent',\n backgroundColor: 'transparent',\n textStyle: { ...words.font },\n data: chart.legend.map(({ color }, index) => ({ name: keyOf(index), itemStyle: { color, borderColor: color, borderWidth: SWATCH_BORDER } })),\n formatter: (name: string) => {\n const index = keys.indexOf(name)\n if (index < 0) throw new Error(`the chart ${chart.id} was asked for a legend entry by a key it does not have, of ${String(keys.length)}`)\n return chartText(nth(chart.legend, index, 'legend entry', chart.id).text, chart.id)\n },\n },\n }\n}\n\n/** The plot: between the bands, or the whole box, which ECharts shrinks until its axes' words fit inside; once the drawing has snapped it, exactly where it stands. */\nfunction gridOf({ bands, plot }: ChartLayout): GridComponentOption {\n if (plot !== undefined) return { left: plot.left, top: plot.top, width: plot.width, height: plot.height, outerBoundsMode: 'none' }\n const { top, bottom } = bands ?? { top: 0, bottom: 0 }\n return { left: 0, right: 0, top, bottom, outerBoundsMode: 'same', outerBoundsContain: 'all' }\n}\n\n/** A decimal as the runtime writes one (`ChartValue.exact`): its units, and how many of its digits are places. */\ninterface Exact {\n readonly units: bigint\n readonly scale: number\n}\n\n/** `exact` read as the runtime writes a decimal -- a minus or none, digits, and a point and digits or none -- or undefined for anything else, which a chart's check refuses before it is laid out (`check-chart.ts`). */\nexport function exactOf(exact: unknown): Exact | undefined {\n const match = typeof exact === 'string' ? /^(-?)(\\d+)(?:\\.(\\d+))?$/.exec(exact) : null\n if (match === null) return undefined\n const [, sign = '', whole = '', fraction = ''] = match\n const units = BigInt(whole + fraction)\n return { units: sign === '-' ? -units : units, scale: fraction.length }\n}\n\n/** `exact`, a value of the chart `id`, read as a decimal; one that is not is an invariant of the renderer's, since the chart's check refuses it first. */\nfunction decimalOf(exact: string, id: string): Exact {\n const read = exactOf(exact)\n if (read === undefined) throw new Error(`the chart ${id} holds a value that is not a decimal, which its check refuses before it is laid out`)\n return read\n}\n\n/** `each`'s units at `scale`, as many places as its own or more. */\nconst unitsAt = (each: Exact, scale: number): bigint => each.units * 10n ** BigInt(scale - each.scale)\n\n/**\n * The places a quotient of decimals is worked out to before it is made a\n * double: a value's place on the value axis, a slice's share of its pie.\n * Seventeen, because a double holds about 15.9 significant digits: a\n * place on an axis of the runtime's few intervals, or a share, is a\n * quotient below ten, which to seventeen places keeps every digit a\n * double can hold of it, so that `Number`'s rounding is the only one that\n * shows, and tick i's place is i exactly. Cut to three, a value a\n * ten-thousandth of an interval below a tick would stand at the tick, on\n * a plot as tall as an A4 page 0.76 points from its place\n * (`chart-option.test.ts`).\n */\nexport const QUOTIENT_UNIT = 10n ** 17n\n\n/** `numerator / denominator`, the denominator more than 0, worked out in BigInt to `QUOTIENT_UNIT` and made a double at the end. */\nconst quotient = (numerator: bigint, denominator: bigint): number => Number((numerator * QUOTIENT_UNIT) / denominator) / Number(QUOTIENT_UNIT)\n\n/**\n * Where a value of `chart` stands on its value axis: its distance from the\n * lowest tick, in the ticks' interval, on the decimals' units -- a\n * `quotient`, made a double at the end. Never a double less a double: a value of 308 digits at 20 places is 328\n * digits of units, which as a double is infinite. The runtime's ticks are\n * two or more, ascending in equal steps, so tick i stands at i; any others\n * are undefined, which the chart's check refuses before it is laid out,\n * as it refuses a value that is no decimal first (`check-chart.ts`).\n */\nexport function placesOf(chart: AxisChart): ((exact: string) => number) | undefined {\n const [lowest, next] = chart.ticks.map(({ exact }) => decimalOf(exact, chart.id))\n if (lowest === undefined || next === undefined) return undefined\n const scale = Math.max(lowest.scale, next.scale)\n if (unitsAt(next, scale) <= unitsAt(lowest, scale)) return undefined\n const place = (exact: string): number => {\n const value = decimalOf(exact, chart.id)\n const common = Math.max(value.scale, scale)\n const step = unitsAt(next, common) - unitsAt(lowest, common)\n return quotient(unitsAt(value, common) - unitsAt(lowest, common), step)\n }\n return chart.ticks.every(({ exact }, index) => place(exact) === index) ? place : undefined\n}\n\n/**\n * A bar or a line chart's plot, axes and series. The category axis stands\n * at the plot's foot -- which on an axis of places is zero's place for\n * ECharts, so that its own `onZero` would stand it there too; `onZero` is\n * off all the same, so that no value axis ever moves it into the plot --\n * with a slot for each category, a line's as a bar's (`boundaryGap`). Its\n * labels stand `CATEGORY_LABEL_MARGIN` under the foot, and a value\n * label's line and its distance further where a labelled bar is below\n * zero, so that its label stands between them and the foot, and ECharts\n * fits that room with them; its title is centred under its labels, where\n * ECharts moves it clear of them. The value axis is the runtime's ticks\n * at their places (`placesOf`), its title at its end, across. Neither axis\n * has a tick, and the value axis no line, which is ECharts' own for a\n * value axis.\n */\nfunction axesOf(chart: AxisChart, words: ChartFace, layout: ChartLayout): Pick<ChartOption, 'grid' | 'xAxis' | 'yAxis' | 'series'> {\n const place = placesOf(chart)\n if (place === undefined) throw new Error(`the chart ${chart.id} has ticks that do not ascend evenly, which its check refuses before it is laid out`)\n const labelled = labelledTicks(chart, layout.tickEvery)\n const [categoryTitle, valueTitle] = [wordOf(chart.categoryTitle, chart.id), wordOf(chart.valueTitle, chart.id)]\n const under = chart.chart === 'bar' && chart.valueLabels && chart.series.some(({ values }) => values.some((each) => each !== null && belowZero(each)))\n return {\n grid: gridOf(layout),\n xAxis: {\n type: 'category',\n data: chart.categories.map((_, index) => categoryKey(index)),\n boundaryGap: true,\n ...(categoryTitle === '' ? {} : { name: categoryTitle, nameLocation: 'middle', nameTextStyle: { ...words.font } }),\n axisTick: { show: false },\n axisLine: { show: true, onZero: false, lineStyle: { color: AXIS.color, width: AXIS.width } },\n axisLabel: {\n interval: 0,\n margin: CATEGORY_LABEL_MARGIN + (under ? words.line + VALUE_LABEL_DISTANCE : 0),\n ...words.font,\n formatter: (key: string, index: number) => {\n const text = nth(chart.categories, index, 'category', chart.id)\n if (key !== categoryKey(index)) throw new Error(`the chart ${chart.id} was asked for category ${String(index)} by another category's key`)\n return chartText(text, chart.id)\n },\n },\n },\n yAxis: {\n type: 'value',\n min: 0,\n max: chart.ticks.length - 1,\n // ECharts draws a bar from its axis's start value, which unless it is told another is 0, the lowest tick's place: a bar stands on zero's.\n ...(chart.chart === 'bar' ? { startValue: place('0') } : {}),\n ...(valueTitle === '' ? {} : { name: valueTitle, nameLocation: 'end', nameTextStyle: { ...words.font } }),\n axisTick: { show: false, customValues: chart.ticks.map((_, index) => index) },\n splitLine: { show: true, lineStyle: { color: GRID.color, width: GRID.width } },\n axisLabel: {\n customValues: labelled.map(({ index }) => index),\n ...words.font,\n formatter: (placed: number, index: number) => {\n const { index: tickPlace, tick } = nth(labelled, index, 'labelled tick', chart.id)\n if (placed !== tickPlace) throw new Error(`the chart ${chart.id} was asked for labelled tick ${String(index)} at another place`)\n return chartText(tick.text, chart.id)\n },\n },\n },\n series: chart.series.map((series, index) =>\n chart.chart === 'bar' ? barSeries(chart, series, index, words, place) : lineSeries(chart, series, index, words, place),\n ),\n }\n}\n\n/** One series of bars, each at its value's place: filled in its colour with no border, its value's label above its end, below it for a bar below zero. */\nfunction barSeries(chart: AxisChart, { color, values }: ChartSeriesValues, index: number, words: ChartFace, place: (exact: string) => number): BarSeriesOption {\n return {\n type: 'bar',\n name: seriesKey(index),\n data: values.map((each) => {\n if (each === null) return null\n const at = place(each.exact)\n return chart.valueLabels && belowZero(each) ? { value: at, label: { position: 'bottom' } } : at\n }),\n barCategoryGap: `${String(BAR_CATEGORY_GAP * 100)}%`,\n barGap: `${String(BAR_GAP * 100)}%`,\n itemStyle: { color, borderWidth: 0 },\n label: valueLabel(chart, values, index, words),\n }\n}\n\n/**\n * One line: stroked in its colour, broken where it has no value, each\n * value a marker at its place, filled in its colour with no border, its\n * label above it. Every category is labelled, so ECharts hides no marker\n * (LineView.js `getIsIgnoreFunc`); and no clip, so it hides none past the\n * plot either (SymbolDraw.js `clipShape`), where no value the check admits\n * stands. ECharts still draws the line inside a clip, of the plot widened\n * by its longer side, which the drawing's reader takes out (`chart-svg.ts`).\n */\nfunction lineSeries(\n chart: AxisChart,\n { color, values }: ChartSeriesValues,\n index: number,\n words: ChartFace,\n place: (exact: string) => number,\n): LineSeriesOption {\n return {\n type: 'line',\n name: seriesKey(index),\n data: values.map((each) => (each === null ? null : place(each.exact))),\n clip: false,\n connectNulls: false,\n symbol: 'circle',\n symbolSize: 2 * POINT_RADIUS,\n lineStyle: { color, width: LINE_WIDTH },\n itemStyle: { color, borderWidth: 0 },\n label: valueLabel(chart, values, index, words),\n }\n}\n\n/** A series' value labels: none where the chart labels no value; otherwise above each mark, each its value's text by its index. */\nfunction valueLabel(chart: AxisChart, values: readonly (ChartValue | null)[], series: number, words: ChartFace) {\n if (!chart.valueLabels) return { show: false }\n return {\n show: true,\n position: 'top' as const,\n distance: VALUE_LABEL_DISTANCE,\n ...words.font,\n formatter: ({ dataIndex }: { readonly dataIndex: number }) => {\n const each = nth(values, dataIndex, 'value', chart.id)\n if (each === null) throw new Error(`the chart ${chart.id} was asked to label value ${String(dataIndex)} of series ${String(series)}, which has none`)\n return chartText(each.text, chart.id)\n },\n }\n}\n\n/**\n * Each slice's share of `chart`'s total, worked out from the runtime's\n * decimals as a place is (`quotient`): ECharts sizes a slice by its\n * value's share of the sum it is handed, and as doubles the slices of the\n * largest values sum past the largest double, to infinity, which would\n * leave every slice nothing. A pie whose slices sum to nothing holds its\n * empty text, never slices: any other has no shares, undefined, which the\n * chart's check refuses before it is laid out (`check-chart.ts`).\n */\nexport function sharesOf(chart: PieChart): { readonly color: string; readonly share: number }[] | undefined {\n const slices = chart.slices.map(({ color, value }) => ({ color, value: decimalOf(value.exact, chart.id) }))\n const scale = Math.max(...slices.map(({ value }) => value.scale))\n const total = slices.reduce((sum, { value }) => sum + unitsAt(value, scale), 0n)\n if (total <= 0n) return undefined\n return slices.map(({ color, value }) => ({ color, share: quotient(unitsAt(value, scale), total) }))\n}\n\n/**\n * What ECharts is handed for a slice of no share -- a zero, or a value\n * under one part in `QUOTIENT_UNIT` of its pie's total, whose `quotient`\n * is 0 -- in place of that share: a value below zero, which ECharts 6.1.0\n * leaves out of the pie's data before it lays the pie out\n * (processor/negativeDataFilter.js, which chart/pie/install.js registers),\n * so that it draws nothing of the slice; while the legend names each entry\n * the series' data holds before any is left out\n * (visual/LegendVisualProvider.js `containName`, of the raw data), so that\n * the slice's entry prints, its swatch in the colour `legendOf` names for\n * it, without which ECharts paints it in the first slice's. Of a share of\n * 0, ECharts draws a sector of no sweep, a path in the slice's colour from\n * the pie's centre to its rim, which may print as a hairline; of a value\n * it reads as missing, '-' or null, a path with no outline in zrender's\n * default black, a colour the drawing refuses as one the option did not\n * name (`chart-svg.ts`); and of a slice left out of the option's data, no\n * legend entry, its words printed nowhere. Never a share: the chart's\n * check refuses a slice below zero before it is laid out (`check-chart.ts`).\n */\nconst NO_SHARE = -1\n\n/** A pie's circle: its centre, in points from the chart's top left, and its radius. */\nexport interface PieCircle {\n readonly centre: readonly [number, number]\n readonly radius: number\n}\n\n/**\n * The circle a pie is drawn on in `square`, the drawing's: its middle, and\n * half its side. ECharts is handed it, and the drawing writes the pie's\n * arcs again on it (`chart-arcs.ts`).\n */\nexport function pieCircle(square: NonNullable<ChartLayout['plot']>): PieCircle {\n return { centre: [square.left + square.width / 2, square.top + square.height / 2], radius: Math.min(square.width, square.height) / 2 }\n}\n\n/**\n * A pie: a slice for each category, its share of the pie's total, from\n * noon and clockwise, each filled in its colour with no border and no\n * label or label line -- its words print in the legend alone -- and a\n * slice of no share drawn as nothing (`NO_SHARE`), in the square the\n * drawing gives it, once it has: until then, where ECharts puts it, since\n * the first layout is read for its title and its legend alone.\n */\nfunction pieSeries(chart: PieChart, { plot }: ChartLayout): PieSeries {\n const shares = sharesOf(chart)\n if (shares === undefined) throw new Error(`the chart ${chart.id} has slices that sum to nothing, which its check refuses before it is laid out`)\n const circle = plot === undefined ? undefined : pieCircle(plot)\n return {\n type: 'pie',\n ...(circle === undefined ? {} : { center: [...circle.centre], radius: circle.radius }),\n startAngle: 90,\n clockwise: true,\n label: { show: false },\n labelLine: { show: false },\n labelLayout: null,\n itemStyle: { borderWidth: 0 },\n data: shares.map(({ color, share }, index) => ({ name: categoryKey(index), value: share === 0 ? NO_SHARE : share, itemStyle: { color, borderWidth: 0 } })),\n }\n}\n\n/** The `index`th of `entries`, which ECharts asked a formatter of the chart `id` for: an index the chart does not have is refused, naming what was asked and how many there are. */\nfunction nth<T>(entries: readonly T[], index: number, what: string, id: string): T {\n const entry = Number.isInteger(index) && index >= 0 ? entries[index] : undefined\n if (entry === undefined) throw new Error(`the chart ${id} was asked for ${what} ${String(index)} of ${String(entries.length)}`)\n return entry\n}\n","import type { Chart } from '@formancy/report-runtime'\nimport type { ChartFaces } from './chart-faces.js'\nimport { held } from './chart-held.js'\nimport { chartWords, TITLE_PADDING } from './chart-option.js'\nimport type { PlacedWord } from './chart-svg.js'\nimport type { FaceWidths } from './engine.js'\n\n/**\n * A chart with nothing to draw -- no rows, a bar or a line chart with no\n * value, a pie of nothing (R7, R8) -- placed by the renderer, and never\n * handed to ECharts, which would draw nothing of it but its words: its box\n * reserved whole, its title where a drawn chart's stands, `TITLE_PADDING`\n * below the box's top, centred across it, in the title's face, and its\n * empty text, the report's words, centred in the box, each measured as\n * pdfmake prints it (`Engine.widths`). No axis and no mark. Its words\n * are held as a drawn chart's are (`chart-held.ts`): one past the box, or\n * the two meeting, refuse it. It imports nothing of ECharts.\n */\nexport function drawEmpty(chart: Chart, faces: ChartFaces, widths: FaceWidths): readonly PlacedWord[] {\n const words = chartWords(chart).map((word): PlacedWord => {\n const face = word.title ? faces.title : faces.words\n // chartFaces gives a title its face wherever chartWords lists one.\n if (face === undefined) throw new Error(`the chart ${chart.id}'s title was placed with no face to print it in`)\n const width = widths.width(face.family, face.face, face.size, word.text)\n const top = word.title ? TITLE_PADDING : (chart.height - face.line) / 2\n return { ...word, face, x: (chart.width - width) / 2, top, width, height: face.line }\n })\n return held(chart, words)\n}\n","import { assetDigest, type Chart } from '@formancy/report-runtime'\nimport { wordOf } from './chart-option.js'\nimport { type Face, faceOf } from './glyphs.js'\nimport type { FaceWanted, RenderFonts } from './host-fonts.js'\n\n/**\n * The faces a chart's words print in, and what ECharts is told of each\n * (0058). ECharts lays a chart out and pdfmake prints its words where\n * ECharts placed them, so each word must be measured in the face, at the\n * size and in the line pdfmake prints it in: the face is the plan's\n * (`host-fonts.ts`), refused there as any text's is, and the widths are the\n * engine's (`Engine.widths`).\n *\n * A chart's words take its style's font token, size, weight, slant and\n * colour; its `align` is not read, since ECharts places each word, and an\n * alignment means nothing for a word placed. Its title is bold in the same\n * token. This module imports nothing of ECharts or zrender.\n */\n\n/** Points: the size a chart's words print in where its style names none. */\nexport const CHART_TEXT_SIZE = 8\n\n/** One face a chart's words print in, its measures in points at its size. */\nexport interface ChartFace {\n /** pdfmake's family, and which of its faces. */\n readonly family: string\n readonly face: Face\n readonly size: number\n /** The line pdfmake lays a word out in, which zrender asks for as the width of `国`. */\n readonly line: number\n /** The face's ascender and descender at `size`: the descender negative, below the baseline, and `line` their difference. */\n readonly ascent: number\n readonly descent: number\n /**\n * What ECharts is told. Its `fontFamily` is the family, a comma, and `f`\n * and the hex of the SHA-256 of the face's key (`RenderFace.key`):\n * zrender keeps widths process-wide by the whole font string, so two\n * faces of other bytes are never measured alike, and the drawing's reader\n * knows a word's face by it. pdfmake draws every word, and no `<text>`\n * reaches its SVG converter, so nothing else reads it. Neither part holds\n * `\"`, `;`, `:` or `,` but the separator, since zrender writes a\n * text's attributes unescaped. The whole digest and not a part of it: a\n * prefix two crafted fonts shared would lay one's words out by the\n * other's widths.\n */\n readonly font: {\n readonly fontFamily: string\n readonly fontWeight: 'normal' | 'bold'\n readonly fontStyle: 'normal' | 'italic'\n readonly fontSize: number\n /** The chart's style's colour, else black: no word is left to ECharts' theme. */\n readonly color: string\n }\n}\n\n/** A chart's words' face, and its title's where it has a title. */\nexport interface ChartFaces {\n readonly words: ChartFace\n /** Bold in the words' token, size, slant and colour; absent for a chart without a title, or with one that prints nothing once trimmed, which asks the plan for no bold face. */\n readonly title?: ChartFace\n}\n\n/** What a chart's words print in where its style names no colour. */\nconst BLACK = '#000000'\n\n/** What a word of `chart` asks the render's plan for: its style's token and slant, and bold where the style is, or for its title. The check holds each word to this face (`check-chart.ts`), and the drawing prints it in this face. */\nexport function chartFace(chart: Chart, title: boolean): FaceWanted {\n const style = chart.style ?? {}\n return { token: style.font, bold: title || (style.bold ?? false), italic: style.italic ?? false }\n}\n\n/** The faces `chart` prints its words and its title in, from `fonts`, the render's plan, which refuses a face the report does not map, naming the chart. */\nexport function chartFaces(chart: Chart, fonts: RenderFonts): ChartFaces {\n const style = chart.style ?? {}\n const family = style.font === undefined ? fonts.defaultFamily : fonts.familyOf(style.font)\n const size = style.size ?? CHART_TEXT_SIZE\n const color = style.color ?? BLACK\n const faceOfChart = (title: boolean): ChartFace => {\n const { token, bold, italic } = chartFace(chart, title)\n const planned = fonts.face(token, bold, italic, chart.id)\n return {\n family,\n face: faceOf(bold, italic),\n size,\n line: planned.lineFactor * size,\n ascent: planned.ascent * size,\n descent: planned.descent * size,\n font: {\n fontFamily: `${family}, f${hexDigest(planned.key())}`,\n fontWeight: bold ? 'bold' : 'normal',\n fontStyle: italic ? 'italic' : 'normal',\n fontSize: size,\n color,\n },\n }\n }\n return { words: faceOfChart(false), ...(wordOf(chart.title, chart.id) === '' ? {} : { title: faceOfChart(true) }) }\n}\n\n/** The hex digits of the SHA-256 of `key`'s UTF-8: a host face's key holds a colon, which a font string may not. */\nfunction hexDigest(key: string): string {\n return assetDigest(new TextEncoder().encode(key)).slice('sha256:'.length)\n}\n","import { MAX_FONT_SIZE, MIN_FONT_SIZE, refusedCharacter, RenderRefusal, type TextStyle } from '@formancy/report-runtime'\nimport { codePoint, missingGlyph } from './glyphs.js'\nimport type { FaceWanted, RenderFonts } from './host-fonts.js'\nimport { COLOR } from './style.js'\nimport type { Walk } from './check-walk.js'\n\n/**\n * Text, held to being a string -- an array would reach pdfmake as inlines\n * carrying any property of its own, a link among them -- to the characters\n * a report prints (report-spec's `refusedCharacter`), and to the face it\n * prints in, which must have a glyph for each of them. The characters come\n * first: one outside Latin, Greek and Cyrillic and what is written with\n * them is refused even where the face maps it, since pdfmake reorders\n * nothing and the renderer shapes nothing (0043, FT-Q16).\n */\nexport function checkText(text: unknown, wanted: FaceWanted, walk: Walk, at: string, subject = at): void {\n if (typeof text !== 'string') throw new RenderRefusal('unsupported', `${at} prints something that is not text`, subject)\n for (const character of text) {\n const point = character.codePointAt(0) as number\n const refused = refusedCharacter(point)\n if (refused === 'script')\n throw new RenderRefusal(\n 'unsupported',\n `${at} prints ${codePoint(point)}, which is in no script the renderer prints: it prints Latin, Greek and Cyrillic, with the punctuation, symbols and marks written with them, and lays out no right-to-left text, no shaped script and no CJK`,\n subject,\n )\n if (refused === 'bidi-control')\n throw new RenderRefusal(\n 'unsupported',\n `${at} prints ${codePoint(point)}, a bidirectional control: pdfmake lays text out left to right alone, and would print it as a space`,\n subject,\n )\n }\n const face = walk.fonts.face(wanted.token, wanted.bold, wanted.italic, subject)\n const missing = missingGlyph(text, face.glyphs)\n if (missing !== undefined) {\n throw new RenderRefusal(\n 'unsupported',\n `${at} prints ${codePoint(missing)}, which ${face.name} has no glyph for: it would print as an empty box, and as nothing in the PDF's text, and no other font is embedded`,\n subject,\n )\n }\n}\n\n/** `style`, which the text `at` prints in, held to what the renderer prints: refused naming `subject`, the block or the table it is. */\nexport function checkStyle(style: TextStyle | undefined, at: string, fonts: RenderFonts, subject = at): void {\n if (style === undefined) return\n // A font token the report maps, or sans, which is Roboto; serif and mono the report does not map are refused, as before a report could name a host font.\n if (style.font !== undefined && !((style.font === 'sans' || style.font === 'serif' || style.font === 'mono') && fonts.usable(style.font))) {\n throw new RenderRefusal(\n 'unsupported',\n `${at} is set in the ${String(style.font)} font, which the report maps to no host font; the renderer embeds Roboto alone, as the sans font, and prints no other in its place`,\n subject,\n )\n }\n // The format's sizes, which a document the runtime resolved holds to: the page bound counts a line as its size, and 0.001 pt put 20,000 lines on one page.\n if (style.size !== undefined && !(style.size >= MIN_FONT_SIZE && style.size <= MAX_FONT_SIZE))\n throw new RenderRefusal('unsupported', `${at} is set at ${style.size} pt; a report's text is ${MIN_FONT_SIZE} to ${MAX_FONT_SIZE} pt`, subject)\n if (style.align !== undefined && style.align !== 'left' && style.align !== 'center' && style.align !== 'right')\n throw new RenderRefusal('unsupported', `${at} is aligned '${String(style.align)}'`, subject)\n checkColor(style.color, at, subject)\n}\n\nexport function checkColor(color: string | undefined, at: string, subject = at): void {\n // pdfmake prints a colour it cannot read as black, without a word.\n if (color !== undefined && !COLOR.test(color))\n throw new RenderRefusal('unsupported', `${at} names the colour '${color}', which is not #rrggbb in lower case`, subject)\n}\n","import type { Block, Chart, EpcQrCode, KeepTogether, QrCode, QrSymbol, Table } from '@formancy/report-runtime'\nimport type { PlacedImage } from './check-images.js'\nimport type { RenderFonts } from './host-fonts.js'\nimport type { RowLine } from './check-table.js'\n\n/** A block that is drawn at a fixed height, which no page may be too short for. */\nexport interface Tall {\n readonly height: number\n /** The vertical space framed sections around it take from a page: their borders and padding, above and below. */\n readonly inset: number\n readonly what: string\n readonly subject: string\n}\n\n/** A table or keep-together block of the body that the body pass measures, at the width it stands at. */\nexport interface Measured {\n readonly block: Table | KeepTogether\n readonly at: string\n readonly width: number\n readonly inset: number\n /** A table's tallest line under its header (`checkTableCells`); none for a keep-together block. */\n readonly under: RowLine | undefined\n}\n\n/** Where a block stands. */\nexport interface Place {\n /** In a page region, not the body: the page header or footer, or page 1's own header. */\n readonly region: boolean\n /** In a region pdfmake draws on every page, the page header or footer, knowing the page's number and the count: not page 1's own header, nor the body. */\n readonly everyPage: boolean\n /** Inside a keep-together block. */\n readonly kept: boolean\n /** Inside a columns block. */\n readonly column: boolean\n readonly width: number\n readonly inset: number\n readonly depth: number\n}\n\nexport interface Walk {\n readonly fonts: RenderFonts\n readonly paths: Map<Block, string>\n readonly images: PlacedImage[]\n readonly codes: Map<QrCode | EpcQrCode, QrSymbol>\n captioned: boolean\n readonly tall: Tall[]\n readonly measured: Measured[]\n /** Every chart of the body the checks passed, and where it stands: what the drawing lays out (`check-chart.ts`). */\n readonly charts: { readonly block: Chart; readonly at: string }[]\n}\n\n/** Something drawn at a fixed height in the body: judged against the body once the regions are measured. A page region's is judged by measuring the region. */\nexport function tall(walk: Walk, place: Place, height: number, what: string, subject: string): void {\n if (!place.region) walk.tall.push({ height, inset: place.inset, what, subject })\n}\n","import { MAX_CHART_CATEGORIES, MAX_CHART_SERIES, MAX_TICK_INTERVALS, RenderRefusal, type AxisChart, type Chart, type PieChart } from '@formancy/report-runtime'\nimport { chartFace } from './chart-faces.js'\nimport { belowZero, chartWords, exactOf, placesOf, sharesOf } from './chart-option.js'\nimport { checkColor, checkStyle, checkText } from './check-faces.js'\nimport { tall, type Place, type Walk } from './check-walk.js'\n\n/**\n * A chart, held to what the renderer draws before anything is laid out\n * (0058), so that ECharts is handed only a chart it can lay out whole and\n * the option's own guards are invariants: each refusal names the chart by\n * its id, and the sizes or the counts that do not hold, and quotes none\n * of its words or values, each of which may be the data's. In order:\n *\n * - **Where it stands.** In the body, in a column, a section or a\n * keep-together block; never in a page region, which is measured before\n * the body and drawn on every page -- or, page 1's own header (0060),\n * once, in page 1's background -- and where the runtime never puts a\n * chart.\n * - **What it is.** A kind the renderer knows, a box of a size, within the\n * bounds no chart the runtime resolves passes (`checkBounds`), every\n * colour it paints and its words' style as a paragraph's are held\n * (`checkColor`, `checkStyle`): its words take the style's font token,\n * size, weight, slant and colour, and its title is bold in the same\n * token. The style's alignment is held to the values a paragraph's is,\n * and is not read: ECharts places each word, and an alignment means\n * nothing for a word placed.\n * - **Its parts, matched.** Each series a value or null at every category\n * and none past them; a legend naming every series, or a pie's every\n * slice, in its colour, or none; a chart with nothing to draw holding\n * its title and its empty text alone, and any other a value to draw. The\n * runtime resolves no other (`chart-document.ts`); the renderer would\n * draw one with some of it left out, or a legend that names a series by\n * another's colour.\n * - **Its words**, every one it may print, every tick among them before\n * the layout thins them (`chartWords`): each text, with no control\n * character, trimmed of the whitespace pdfmake cuts, and held as a\n * paragraph's is to the scripts the renderer prints and to the face it\n * prints in (`checkText`, `chartFace`). A word blank once trimmed prints\n * nothing, and asks for no face: a title of whitespace asks for no bold\n * one.\n * - **Its numbers**, as the runtime writes them: every value a decimal;\n * the ticks two or more, ascending in equal steps (`placesOf`), holding\n * every value, and a bar chart's holding zero, which its bars stand on;\n * a pie's slices none below zero, and more than nothing together\n * (`sharesOf`). The option reads them through the same functions and\n * holds each as an invariant, which this refuses first. Two of them are\n * the runtime's decisions, re-held as what the drawing needs:\n * `chartTicks`' axis, which holds every value and a bar's zero\n * (`chart-ticks.ts`), and `chart-negative-share`, its refusal of a pie\n * of a negative value (`lower-chart.ts`); a change to either is a\n * change here.\n * - **Its size**: no wider than where it stands, as `content-too-large`,\n * and its height judged against the body's once the page regions are\n * measured (`tall`).\n *\n * What passes is collected, where it stands, for the drawing. Whether its\n * words fit the box ECharts lays them out in is the drawing's to say\n * (`chart-draw.ts`).\n */\nexport function checkChart(chart: Chart, at: string, place: Place, walk: Walk): void {\n const named = `the chart ${chart.id}`\n if (place.region)\n throw refusal(\n chart,\n `${named} stands in ${place.everyPage ? 'a page region, which is drawn on every page' : \"page 1's own header, a page region drawn in page 1's background\"}: a chart is drawn in the body`,\n )\n const kind: string = chart.chart\n if (kind !== 'bar' && kind !== 'line' && kind !== 'pie') throw refusal(chart, `${named} is of a kind the renderer does not know`)\n const { width, height } = chart\n if (!(width > 0 && height > 0 && Number.isFinite(width) && Number.isFinite(height))) throw refusal(chart, `${named} is drawn ${width} × ${height} pt`)\n checkBounds(chart)\n checkStyle(chart.style, named, walk.fonts, chart.id)\n for (const color of marks(chart)) checkColor(color, named, chart.id)\n for (const { color } of chart.legend) checkColor(color, named, chart.id)\n checkParts(chart)\n for (const { key, text, title } of chartWords(chart)) checkText(text, chartFace(chart, title), walk, wordAt(key, named), chart.id)\n if (chart.empty === undefined) {\n if (chart.chart === 'pie') checkSlices(chart)\n else checkAxis(chart)\n }\n if (width > place.width) throw new RenderRefusal('content-too-large', `${named} is ${width} pt wide; it stands ${place.width.toFixed(2)} pt wide`, chart.id)\n tall(walk, place, height, named, chart.id)\n walk.charts.push({ block: chart, at })\n}\n\n/**\n * What drawing one render's charts may cost, in units of what one more\n * point of a line chart of 8 series and 200 categories costs a render.\n * Each chart costs its kind's weight (`CHART_WEIGHT`), a unit for each\n * series at each category or each slice of a pie, and its word's weight\n * for each word it places (`WORD_WEIGHT`), as `MAX_SVG_DRAWING` weighs an\n * SVG (`chartUnits`). ECharts lays out every chart of a render three\n * times, a pie twice, before the body is paginated, and a reader draws\n * every one. Beyond its points and its words, a chart costs the render\n * its layouts and a reader its paint. Each weight is the larger of what it\n * costs the render and a reader, in the one unit, rounded up: a kind's to\n * ten, a word's to a whole unit.\n *\n * It holds one layout pass. pdfmake lays the document out again for each\n * page where a kept heading moves to the next, as often as where the\n * pages break decides, which no bound before the layout can count: 17 bar\n * charts of 123 one-letter categories, which the bound admits, each 290\n * points tall behind a keep-with-next heading, took a median of 1,475 ms\n * where with plain headings they took 574, two and a half times as long,\n * at a load of 3.2 to 3.7 (seven interleaved runs); 20 of them, past the\n * bound, 1,887 against 637 at a load of 3.9 to 4.3, three times as long.\n *\n * Measured on 2026-11-15 on a Mac (Apple M2, 8 cores) under Node 22.23.4,\n * ECharts 6.1.0, pdfmake 0.3.11 and pdfjs-dist 6.4.299. The weights came\n * from one run at a load average of 12 to 20: every document rendered and\n * its page drawn by PDF.js at scale 1 in the same seven rounds, each\n * difference read against its own round's unit, 0.15 to 0.50 ms as the\n * load fell, and the median of the seven taken. A word's is the\n * difference between one-page documents of the same charts with and\n * without words of its kind: a value label 0.85 units on a bar and 0.67\n * on a line, a category label 0.48, a legend entry 2.36 on a pie and 4.02\n * on an axis chart, a title 2.74, each the render's, and a tick 0.35, a\n * reader's. A kind's is its barest chart of one category, N against 2N,\n * less its points and its words: a bar of 8 series 34 to the render, and\n * a pie of one slice 8.\n *\n * A line's was measured again once the drawing took ECharts' clip of\n * its series out (`chart-svg.ts`), by the same run at a load of 3.0 to\n * 3.2, its unit 0.092 ms: a line of 8 series costs 59 to the render, and\n * a reader no more than its points and its words, where its eight\n * soft-masked groups had cost a reader 482; a line of one series 27 to\n * the render. A reader's cost no longer goes by series, and the render's\n * by about 4.5 units a series, which the one weight, the eight series',\n * holds. In that run a title cost 5.3 units and a tick 1.6, above the\n * first run's 2.74 and 0.35, and a bar of 8 series 36 and a pie of one\n * slice 7, within their weights. A word's weight is the larger of the two\n * runs', rounded up: a title 6 and a tick 2, the rest as the first run\n * set them.\n *\n * The bound is set by the slowest of seven interleaved runs of the\n * costliest of the forms tried, and it keeps 2 s only at a quiet load: at\n * a load of 10 to 18.6 the documents it admitted, a line still weighing\n * 490, ran far slower at their slowest, a page of nine line charts of 8\n * series and one category 5.5 s, and a page of one 8 × 200 line beside\n * five 8 × 1 lines 9.45 s. The forms were packed as many to a render as\n * the bound holds, in the densest grid each draws in on A4 landscape pages\n * without margins, across pages, and as many as one page holds: charts of\n * one category of each kind, of 1 and 8 series, bare, dressed and\n * value-labelled; the largest the earlier cost run tried, lines of\n * 8 × 200, of 8 × 123 one-letter categories and of 1 × 200, bars of\n * 1 × 186, 2 × 83, 8 × 19 and 1 × 123, and a dressed pie of eight slices;\n * bars of 120 and 186 categories and lines of 8 × 200, every value\n * labelled at 4 points, report-spec's least size; pies of eight slices,\n * bare and with every slice in the legend; and a page of one 8 × 200 line\n * beside lines of 8 series and one category.\n *\n * The bound was set at 5,000 when a line weighed 490, at a load of 3.3 to\n * 5.6: the slowest render, 263 dressed pies of one slice on 3 pages, took\n * 878 ms at its slowest, and the slowest page, one 8 × 200 line beside\n * five 8 × 1 lines, cost PDF.js 1,614 ms at its slowest and 723 at its\n * median, a spike: the page's other six stood at 0.66 to 1.10 times the\n * reference render's in their rounds. At 0.332 ms a unit it reaches 2 s\n * at about 6,017 units, and 6,000 would leave about 10 ms, so the bound is\n * 5,000. A review's run at a load of 4.2 to 5.5 put 17 value-labelled bars\n * of 120 categories (1,258 ms) ahead of the pies (1,235). With a line at\n * 60 and a pie of eight slices at most, a title still at 3 and a tick at\n * 1, the forms were run again at a load of 3.0 to 3.9, among them pies of\n * eight slices in place of 200, 53 line charts of twelve months and one\n * series, titled, a review's, and three 8 × 200 lines on one page, then\n * admitted at 4,998 units: the slowest render, the 53 lines, took 1,202 ms\n * at its slowest, one round's spike against a median of 338, the next 18\n * dressed bar charts of 8 × 19 at 551; the slowest page, the three 8 × 200\n * lines, cost PDF.js 142 ms. A title at 6 and a tick at 2 only admit less:\n * 49 of those line charts fit, at 102 units each, and the third 8 × 200\n * line brings its page to 5,016. None measured the slowest the bound\n * admits.\n */\nexport const MAX_CHART_DRAWING = 5000\n\n/** What each kind of chart costs beyond its points and its words, in `MAX_CHART_DRAWING`'s units: the larger of what its layouts cost the render and what its drawing costs a reader, rounded up to ten. */\nexport const CHART_WEIGHT = { bar: 40, line: 60, pie: 10 } as const satisfies Readonly<Record<Chart['chart'], number>>\n\n/** What each word a chart places costs, by what it is, in `MAX_CHART_DRAWING`'s units: the larger of what it costs the render and a reader, rounded up. A title is the chart's or an axis's. */\nexport const WORD_WEIGHT = { title: 6, legend: 5, tick: 2, category: 1, value: 1 } as const\n\n/**\n * What drawing `chart` costs, in `MAX_CHART_DRAWING`'s units: its kind's\n * weight, a unit for each series at each category, null or not, or for\n * each of a pie's slices, one of no share among them, and each word it\n * places, as `chartWords` lists them, its word's weight. A chart with\n * nothing to draw costs none: ECharts never lays it out (`drawEmpty`),\n * and it paints no mark.\n */\nexport function chartUnits(chart: Chart): number {\n if (chart.empty !== undefined) return 0\n const points = chart.chart === 'pie' ? chart.slices.length : chart.series.length * chart.categories.length\n return chartWords(chart).reduce((units, { key }) => units + wordWeight(key, chart.id), CHART_WEIGHT[chart.chart] + points)\n}\n\n/** The weight of the word `key` (`ChartWord.key`) of the chart `id`, by what the word is. */\nfunction wordWeight(key: string, id: string): number {\n const [role] = key.split('/')\n switch (role) {\n case 'title':\n case 'categoryTitle':\n case 'valueTitle':\n return WORD_WEIGHT.title\n case 'legend':\n return WORD_WEIGHT.legend\n case 'tick':\n return WORD_WEIGHT.tick\n case 'category':\n return WORD_WEIGHT.category\n case 'value':\n return WORD_WEIGHT.value\n default:\n // An empty text, which only a chart with nothing to draw prints, or a word chartWords never lists.\n throw new Error(`the chart ${id} has a word ${key} that a chart with something to draw never places`)\n }\n}\n\n/**\n * A render's charts, as the walk listed them, held to what drawing all of\n * them costs together, before any of them is laid out: past\n * `MAX_CHART_DRAWING`, refused as `content-too-large` at the chart that\n * crossed it, naming the count and the bound and quoting none of its\n * words, as `MAX_SVG_DRAWING` holds a render's SVGs (`check.ts`).\n */\nexport function checkChartDrawing(charts: Walk['charts']): void {\n let total = 0\n for (const { block } of charts) {\n total += chartUnits(block)\n if (total > MAX_CHART_DRAWING) {\n throw new RenderRefusal(\n 'content-too-large',\n `the charts up to ${block.id} cost ${String(total)} units to draw, each its kind's weight, one for each series at each category or each slice of a pie, and its words' weights; a render may draw ${String(MAX_CHART_DRAWING)}`,\n block.id,\n )\n }\n }\n}\n\n/** An `unsupported` refusal of `chart`, saying `message`. */\nconst refusal = (chart: Chart, message: string): RenderRefusal => new RenderRefusal('unsupported', message, chart.id)\n\n/** `count` of a thing, in the words for one of it and for more. */\nconst counted = (count: number, one: string, more: string): string => `${String(count)} ${count === 1 ? one : more}`\n\n/**\n * `chart` held to the bounds no chart the runtime resolves passes, each\n * read from where it is decided: a bar or a line chart's categories to the\n * runtime's `MAX_CHART_CATEGORIES`, a bound on the work a chart costs, as\n * `content-too-large`; a pie's slices, and a chart's series, to\n * report-spec's `MAX_CHART_SERIES`, the most colours a palette holds, one\n * for each, as the runtime holds a pie's categories to its palette\n * (`lower-chart.ts`); and its ticks to the `MAX_TICK_INTERVALS` intervals\n * `chartTicks` writes at most; each of the last three as `unsupported`, a\n * chart of a form no runtime resolves. Held before its words are read, so\n * that a chart built by hand past them costs the check nothing more, and\n * ECharts never lays it out.\n */\nfunction checkBounds(chart: Chart): void {\n const named = `the chart ${chart.id}`\n if (chart.chart === 'pie') {\n if (chart.slices.length > MAX_CHART_SERIES)\n throw refusal(\n chart,\n `${named} has ${String(chart.slices.length)} slices; a pie has at most ${String(MAX_CHART_SERIES)}, one colour each from its palette`,\n )\n return\n }\n if (chart.categories.length > MAX_CHART_CATEGORIES) {\n throw new RenderRefusal(\n 'content-too-large',\n `${named} has ${String(chart.categories.length)} categories; a chart has at most ${String(MAX_CHART_CATEGORIES)}`,\n chart.id,\n )\n }\n if (chart.series.length > MAX_CHART_SERIES)\n throw refusal(\n chart,\n `${named} has ${String(chart.series.length)} series; a chart has at most ${String(MAX_CHART_SERIES)}, one colour each from its palette`,\n )\n if (chart.ticks.length > MAX_TICK_INTERVALS + 1)\n throw refusal(chart, `the value axis of ${named} has ${String(chart.ticks.length)} ticks; an axis has at most ${String(MAX_TICK_INTERVALS + 1)}`)\n}\n\n/** The colours `chart` paints its marks in: its series' (bar, line), or its slices' (pie). */\nconst marks = (chart: Chart): readonly string[] => (chart.chart === 'pie' ? chart.slices : chart.series).map(({ color }) => color)\n\n/**\n * `chart`'s parts, matched as the runtime resolves them: a series' values\n * one to each category, a legend's entries one to each series or slice in\n * its colour or none, and an empty chart nothing but its title and its\n * empty text, any other something to draw.\n */\nfunction checkParts(chart: Chart): void {\n const named = `the chart ${chart.id}`\n const axis = chart.chart !== 'pie'\n if (axis) {\n chart.series.forEach(({ values }, index) => {\n if (values.length !== chart.categories.length)\n throw refusal(\n chart,\n `series ${String(index)} of ${named} has ${counted(values.length, 'value', 'values')} for ${counted(chart.categories.length, 'category', 'categories')}`,\n )\n })\n }\n const mark = axis ? 'series' : 'slice'\n const marked = marks(chart)\n if (chart.legend.length !== 0 && chart.legend.length !== marked.length) {\n const what = axis ? counted(marked.length, 'series', 'series') : counted(marked.length, 'slice', 'slices')\n throw refusal(\n chart,\n `${named} has ${counted(chart.legend.length, 'legend entry', 'legend entries')} for ${what}, and names every ${mark} in its legend or none`,\n )\n }\n chart.legend.forEach(({ color }, index) => {\n if (color !== marked[index]) throw refusal(chart, `legend entry ${String(index)} of ${named} is not in the colour of the ${mark} it names`)\n })\n if (chart.empty !== undefined) {\n const more = axis\n ? chart.categoryTitle !== undefined || chart.valueTitle !== undefined || chart.categories.length + chart.series.length + chart.ticks.length > 0\n : chart.slices.length > 0\n // A legend names a series or a slice, which such a chart has none of, and is refused above.\n if (more) throw refusal(chart, `${named} has nothing to draw, and holds more than its title and its empty text, which is all such a chart prints`)\n } else if (axis && !chart.series.some(({ values }) => values.some((value) => value !== null))) {\n throw refusal(chart, `${named} has no value to draw, and no empty text to print in its place`)\n }\n}\n\n/**\n * A bar or a line chart's numbers: every one a decimal, its ticks an axis\n * (`placesOf`) that holds every value, and a bar chart's zero, as\n * `chartTicks` writes one (`chart-ticks.ts`): the plot's clip would cut a\n * value its ticks do not hold, and a bar stands on zero's place.\n */\nfunction checkAxis(chart: AxisChart): void {\n const named = `the chart ${chart.id}`\n const values = chart.series.flatMap(({ values: each }) => each.flatMap((value) => (value === null ? [] : [value.exact])))\n if ([...chart.ticks.map(({ exact }) => exact), ...values].some((exact) => exactOf(exact) === undefined))\n throw refusal(chart, `${named} holds a value that is not a decimal`)\n const place = placesOf(chart)\n if (place === undefined)\n throw refusal(chart, `the value axis of ${named} is ${counted(chart.ticks.length, 'tick', 'ticks')}, and not two or more ascending in equal steps`)\n const highest = chart.ticks.length - 1\n const held = (exact: string): boolean => {\n const at = place(exact)\n return at >= 0 && at <= highest\n }\n if (!values.every(held)) throw refusal(chart, `${named} has a value its ticks do not hold, which would be drawn past its plot`)\n if (chart.chart === 'bar' && !held('0')) throw refusal(chart, `${named} is a bar chart whose ticks do not hold zero, which its bars stand on`)\n}\n\n/** A pie's numbers: every slice a decimal; none below zero (`belowZero`), which the runtime refuses as `chart-negative-share` (`lower-chart.ts`) and a share of which would be no slice; and together more than nothing (`sharesOf`). */\nfunction checkSlices(chart: PieChart): void {\n const named = `the chart ${chart.id}`\n if (chart.slices.some(({ value }) => exactOf(value.exact) === undefined)) throw refusal(chart, `${named} holds a value that is not a decimal`)\n if (chart.slices.some(({ value }) => belowZero(value))) throw refusal(chart, `${named} is a pie with a slice below zero, which is no share of a whole`)\n if (sharesOf(chart) === undefined) throw refusal(chart, `${named} is a pie whose slices sum to nothing, and holds no empty text to print in their place`)\n}\n\n/**\n * Where the word `key` (`ChartWord.key`) of the chart `named` stands, for\n * a refusal: by what it is and its index in the block, as a table's row\n * is, and never by its text.\n */\nfunction wordAt(key: string, named: string): string {\n const [role, first = '', second = ''] = key.split('/')\n switch (role) {\n case 'title':\n return `the title of ${named}`\n case 'categoryTitle':\n return `the category axis's title of ${named}`\n case 'valueTitle':\n return `the value axis's title of ${named}`\n case 'category':\n return `category ${first} of ${named}`\n case 'tick':\n return `tick ${first} of ${named}`\n case 'value':\n return `the value of series ${first} at category ${second} of ${named}`\n case 'legend':\n return `legend entry ${first} of ${named}`\n case 'empty':\n return `the empty text of ${named}`\n default:\n throw new Error(`${named} has a word ${key}, which chartWords never lists`)\n }\n}\n","import {\n checkSvg,\n imageHeader,\n MAX_ASSET_BYTES,\n MAX_ASSET_SIDE,\n RenderRefusal,\n sniffImage,\n type CheckedSvg,\n type ImageAsset,\n type PngHeader,\n type SvgExtent,\n} from '@formancy/report-runtime'\nimport { inflate } from './bytes.js'\n\n/**\n * Image assets checked before pdfmake sees them. pdfmake, through PDFKit,\n * copies a PNG's compressed data and a JPEG's scan into the PDF without\n * decoding either, so bytes that only look like an image arrive in the PDF\n * as a broken one, and bytes that do not look like one at all fail with an\n * error that names no asset. Both are refused here instead, naming it, as\n * `invalid-asset`.\n *\n * What is checked: the size limits; a PNG's or a JPEG's structure, by\n * report-spec's `imageHeader`, which a builder refuses an image a person\n * adds by too (0033) -- for a PNG, every chunk's length and CRC, the header\n * and the palette, and for a JPEG, the segment structure up to the scan,\n * one frame header, read where PDFKit reads it, its size and its component\n * count, and the end marker; and here, that a PNG's image data inflates to\n * exactly the scanlines the header promises, each with a known filter,\n * which needs the platform's decompressor. A JPEG's entropy-coded scan is\n * not decoded: a corrupt scan inside an otherwise well-formed JPEG still\n * reaches the PDF.\n *\n * An SVG is checked by report-spec's `checkSvg`, which the runtime hands\n * on: its bytes must be exactly the drawing `cleanSvg` writes, so that what\n * prints is in the form that was approved, and nothing is cleaned, dropped\n * or rewritten at print (0030). Its size is its viewBox's, and with it come\n * what it costs to draw, which `check.ts` holds a render to.\n *\n * The size returned is the size the image is shown at, as `imageHeader`\n * reads it: a JPEG whose Exif orientation turns it a quarter turn is as wide\n * as its frame is tall, as PDFKit draws it. The check runs on the standard\n * library alone, so that the browser entry makes exactly the same one\n * (`bytes.ts`).\n */\n\n/**\n * The image data one render may hold, once inflated: two images of the\n * largest kind an asset may be, 4096 by 4096 pixels of 16-bit RGBA, whose\n * scanlines inflate to 134,221,824 bytes each. PDFKit decodes such a PNG to\n * embed it: one took 1.8 seconds and grew the process by 343 MB, two 3.4\n * seconds, four 6.5 seconds (measured on 2026-10-15, on an Intel i9-10900K\n * under Node 24.21). A JPEG is embedded as it is, and counts its bytes.\n */\nexport const MAX_IMAGE_DATA = 2 * MAX_ASSET_SIDE * (1 + MAX_ASSET_SIDE * 8)\n\n/** A PNG's or a JPEG's size in pixels, as it is shown, how many bytes of image data it holds once a PNG's are inflated, and whether PDFKit draws it in DeviceCMYK. */\nexport interface Raster {\n readonly kind: 'raster'\n readonly width: number\n readonly height: number\n readonly data: number\n /**\n * A JPEG whose frame header says four components, which PDFKit draws in\n * DeviceCMYK (pdfkit.js 3808-3812), as it draws one of three in\n * DeviceRGB and one of one in DeviceGray, and no other count, which the\n * check refuses; never a PNG, which PDFKit draws in RGB or grey. A PDF/A,\n * an e-invoice's or a PDF/A-2b, cannot hold one.\n */\n readonly cmyk: boolean\n}\n\n/**\n * An SVG in the form `cleanSvg` writes: its viewBox, whose proportions\n * `contain` and `cover` keep; the drawing, as the ASCII text it is, which\n * every pass hands pdfmake unchanged; what it costs, as `checkSvg` counts\n * it and `drawingUnits` weights it; and how far the converter's numbers for\n * it reach, which a PDF/A holds it to (`svg-pdfa.ts`).\n */\nexport interface Vector {\n readonly kind: 'vector'\n /** The viewBox's origin. */\n readonly x: number\n readonly y: number\n /** The viewBox's size. */\n readonly width: number\n readonly height: number\n readonly svg: string\n /** What a reader paints for it, in `MAX_SVG_SEGMENTS`' weighted segments. */\n readonly segments: number\n /** The page-sized transparency groups it makes, in `MAX_SVG_GROUPS`' units. */\n readonly groups: number\n /** What drawing it once costs the renderer, in `MAX_SVG_DRAWING`'s units. */\n readonly units: number\n /** How far the numbers the converter writes for it reach wherever it is placed, and how deep it nests the graphics state, as `checkSvg` measures them. */\n readonly extent: SvgExtent\n}\n\n/** An image asset as the checks read it. */\nexport type CheckedImage = Raster | Vector\n\n/** The asset as it is drawn, once its bytes pass; refused as `invalid-asset`, naming it and why, when they do not. */\nexport async function checkImageAsset(asset: ImageAsset): Promise<CheckedImage> {\n const read = await readAsset(asset)\n if (typeof read === 'string') throw new RenderRefusal('invalid-asset', `the image asset ${asset.id} ${read}`, asset.id)\n return read\n}\n\n/** The asset as it is drawn, or what is wrong with it. */\nasync function readAsset(asset: ImageAsset): Promise<CheckedImage | string> {\n const { bytes } = asset\n if (!(bytes instanceof Uint8Array)) return 'has no bytes'\n if (bytes.length > MAX_ASSET_BYTES) return `is ${bytes.length} bytes; the limit is ${MAX_ASSET_BYTES} (20 MB)`\n const sniffed = sniffImage(bytes)\n const isPng = sniffed === 'image/png'\n const isJpeg = sniffed === 'image/jpeg'\n // Read as an SVG only to say what bytes declared otherwise are; cleanSvg refuses bytes past a mebibyte unread.\n const actually = (): string => (isPng ? ': it is a PNG' : isJpeg ? ': it is a JPEG' : checkSvg(bytes).ok ? ': it is an SVG' : '')\n if (asset.mediaType === 'image/png') return isPng ? readRaster(bytes) : `is declared a PNG and is not one${actually()}`\n if (asset.mediaType === 'image/jpeg') return isJpeg ? readRaster(bytes) : `is declared a JPEG and is not one${actually()}`\n if (asset.mediaType === 'image/svg+xml') return isPng || isJpeg ? `is declared an SVG and is not one${actually()}` : readSvg(bytes)\n return `is of a media type the renderer does not draw (${String(asset.mediaType)})`\n}\n\n/**\n * The drawing one render may cost the renderer, in units of what\n * svg-to-pdfkit does each time it draws an SVG: once for each image of it in\n * the body, and on every page for one in a page region, which pdfmake lays\n * out and draws anew on each page (0030). A move, a line or a close is one\n * unit; a curve, an element, a gradient stop and a page-sized transparency\n * group are weighted by what each costs beside a line, rounded up; and every\n * `DRAWING_WEIGHT.bytes` bytes of the drawing are one unit more, since\n * pdfmake reads the whole text again with xmldoc in every pass and the\n * converter on every draw, whatever it draws. At the budget the renderer\n * spends about 2.9 seconds drawing SVGs, about what `MAX_IMAGE_DATA`'s two\n * largest PNGs cost it to decode.\n *\n * Measured on 2026-10-18 on an Intel i9-10900K, shared with other work,\n * under Node 24.21.0 with pdfmake 0.3.11: whole renders, every pass, of an\n * SVG 15 mm square in the page header of a report of so many pages, against\n * the same report with an SVG of one rectangle in its place, medians of five\n * (three at 400 pages). A line costs 2.9 microseconds a page (30,000 lines on\n * 32 pages, 2.79 s more); a cubic 6.8, 2.3 lines (9,999 on 32 pages, 2.18 s);\n * an element 33 beyond its segments, 11.4 lines (6,001 rectangles on 8 pages,\n * 2.29 s); a gradient stop 17, 5.9 lines (a 64-stop gradient on 400\n * rectangles on 7 pages, 3.2 s); a transparency group 0.10 ms beyond its\n * element and segments, 34 to 36 lines (four clipped shapes, and two shapes\n * painted with a translucent gradient, on 400 pages, 0.32 s and 0.25 s).\n * Those lines were short, seven bytes each. On 16 pages a line of 18.7\n * bytes cost 4.4 microseconds a page and one of 37 bytes 5.2, against 3.1\n * for a short one; and 10,506 arcs that draw nothing, a mebibyte of\n * seventeen-digit numbers, cost 109 ms a page on 8 pages, what 35,000 short\n * lines do, though each is counted as a line. With a unit more for every 32\n * bytes, each of these drawings costs from 13 % less than its units say\n * (900 rectangles of seventeen-digit numbers and dash arrays) to 27 % more\n * (the 37-byte lines).\n */\nexport const MAX_SVG_DRAWING = 1_000_000\n\n/** What each thing svg-to-pdfkit draws costs the renderer, in lines' worth of its time, rounded up, and how many bytes of the drawing are one more unit (`MAX_SVG_DRAWING`). */\nconst DRAWING_WEIGHT = { curve: 3, element: 12, stop: 6, group: 40, bytes: 32 } as const\n\n/** What drawing an SVG once costs the renderer, in `MAX_SVG_DRAWING`'s units. */\nexport function drawingUnits(checked: Pick<CheckedSvg, 'bytes' | 'drawn' | 'groups'>): number {\n const { lines, curves, elements, stops } = checked.drawn\n const commands =\n lines + DRAWING_WEIGHT.curve * curves + DRAWING_WEIGHT.element * elements + DRAWING_WEIGHT.stop * stops + DRAWING_WEIGHT.group * checked.groups\n return commands + Math.ceil(checked.bytes.length / DRAWING_WEIGHT.bytes)\n}\n\n/** An SVG's drawing, when its bytes are exactly what `cleanSvg` writes; report-spec's refusal, which repeats no value, when they are not. */\nfunction readSvg(bytes: Uint8Array): Vector | string {\n const checked = checkSvg(bytes)\n if (!checked.ok) return `is not an SVG the renderer draws: ${checked.message}`\n const { viewBox, segments, groups, extent } = checked\n return {\n kind: 'vector',\n x: viewBox.x,\n y: viewBox.y,\n width: viewBox.width,\n height: viewBox.height,\n svg: ascii(checked.bytes),\n segments,\n groups,\n units: drawingUnits(checked),\n extent,\n }\n}\n\n/** ASCII bytes as text, a chunk at a time: a mebibyte is more than one call takes as arguments. */\nfunction ascii(bytes: Uint8Array): string {\n let text = ''\n for (let start = 0; start < bytes.length; start += 0x2000) text += String.fromCharCode(...bytes.subarray(start, start + 0x2000))\n return text\n}\n\n/**\n * A PNG or a JPEG as it is drawn, once its structure, read by\n * `imageHeader`, and a PNG's image data pass. A JPEG is embedded as it is,\n * and counts its bytes; a PNG counts its scanlines, which PDFKit decodes.\n */\nasync function readRaster(bytes: Uint8Array): Promise<Raster | string> {\n const header = imageHeader(bytes)\n if (!header.ok) return header.message\n if (header.mediaType === 'image/jpeg')\n return { kind: 'raster', width: header.width, height: header.height, data: bytes.length, cmyk: header.components === 4 }\n return (await scanlineProblem(header)) ?? { kind: 'raster', width: header.width, height: header.height, data: inflatedLength(header), cmyk: false }\n}\n\n/** Adam7's seven passes: the first column and row of each, and the steps between them. */\nconst ADAM7 = [\n [0, 0, 8, 8],\n [4, 0, 8, 8],\n [0, 4, 4, 8],\n [2, 0, 4, 4],\n [0, 2, 2, 4],\n [1, 0, 2, 2],\n [0, 1, 1, 2],\n] as const\n\n/** The scanlines of each pass of the image: the bytes of one, its filter byte included, and how many there are. */\nfunction scanlines(header: PngHeader): { readonly bytes: number; readonly count: number }[] {\n const passes = header.interlaced\n ? ADAM7.map(([x, y, dx, dy]) => [Math.ceil((header.width - x) / dx), Math.ceil((header.height - y) / dy)] as const)\n : [[header.width, header.height] as const]\n return passes\n .filter(([width, height]) => width > 0 && height > 0)\n .map(([width, height]) => ({ bytes: 1 + Math.ceil((width * header.bitsPerPixel) / 8), count: height }))\n}\n\n/** The bytes the image data inflates to, as the header promises. */\nfunction inflatedLength(header: PngHeader): number {\n return scanlines(header).reduce((total, row) => total + row.bytes * row.count, 0)\n}\n\n/**\n * Whether the image data inflates to exactly the scanlines the header\n * promises, each starting with a filter type PNG defines. Read as it\n * inflates: the filter bytes are where the scanlines say, so nothing of the\n * image is kept.\n */\nasync function scanlineProblem(header: PngHeader): Promise<string | undefined> {\n const rows = scanlines(header)\n const expected = inflatedLength(header)\n const filters = filterOffsets(rows)\n let next = filters.next()\n let unknown: number | undefined\n const inflated = await inflate(header.data, expected, (chunk, offset) => {\n while (unknown === undefined && !next.done && next.value < offset + chunk.length) {\n const filter = chunk[next.value - offset]!\n if (filter > 4) unknown = filter\n next = filters.next()\n }\n })\n if (inflated.kind === 'too-long') return `has more image data than the ${expected} bytes its header promises`\n if (inflated.kind === 'invalid') return 'has image data that does not inflate'\n if (inflated.length < expected) return `has image data of ${inflated.length} bytes where its header promises ${expected}`\n return unknown === undefined ? undefined : `has a scanline with an unknown filter type (${unknown})`\n}\n\n/** Where each scanline's filter byte is in the inflated data, in order. */\nfunction* filterOffsets(rows: readonly { readonly bytes: number; readonly count: number }[]): Generator<number, void> {\n let offset = 0\n for (const row of rows) {\n for (let index = 0; index < row.count; index++, offset += row.bytes) yield offset\n }\n}\n","import { FACTUR_X, FACTUR_X_PROFILES, RenderRefusal, XRECHNUNG, XRECHNUNG_COPY_PARAGRAPH, XRECHNUNG_VERSIONS } from '@formancy/report-runtime'\nimport type { Block, EInvoiceFile, FacturXFile, XRechnungFile } from '@formancy/report-runtime'\n\n/**\n * The e-invoice a document carries (0027), by its kind: the XML the runtime\n * wrote from the values the page prints, and what it is. A Factur-X file\n * says what to embed it as -- the file's name, its relationship to the PDF\n * and the conformance level the PDF's XMP states, report-spec's `FACTUR_X`\n * and `FACTUR_X_PROFILES` handed on by the runtime -- and is drawn as a\n * PDF/A-3b that embeds it (`pdfa.ts`, 0031). An XRechnung's says its\n * syntax, guideline and version, report-spec's `XRECHNUNG`: its XML is the\n * invoice a host sends, and its document is drawn as a plain PDF, the copy,\n * labelled so on every page by the runtime (0038). The renderer decides\n * none of them, and writes nothing of the XML. What the document is drawn\n * as is decided in `pdfa-check.ts`, from the file once it is known here.\n *\n * **What it does not know it refuses**, before pdfmake sees the document:\n * a file it is not handed as one, of a kind it does not know, XML that is\n * not text or that holds a lone surrogate, which UTF-8 cannot encode as it\n * stands, a name, a conformance level, a relationship, a syntax, a\n * guideline or a version that is not report-spec's, and an XRechnung whose\n * pages are not labelled as the copy in the runtime's own paragraph. A\n * file from a runtime that names it otherwise would be embedded as\n * something its reader does not look for, or drawn as something it is\n * not. A refusal names what is unknown, never a value: the XML holds\n * people's names, accounts and VAT identifiers.\n */\n\nconst refusal = (message: string): RenderRefusal => new RenderRefusal('unsupported', message, 'eInvoice')\n\n/** A Factur-X file, once the renderer knows it: report-spec's name, one of its profiles' conformance levels, and that profile's relationship. */\nfunction checkFacturX(file: Record<string, unknown>, xml: string): FacturXFile {\n const { fileName, relationship, conformanceLevel } = file\n if (fileName !== FACTUR_X.fileName) throw refusal('the e-invoice is embedded under a file name the renderer does not know')\n // Each profile's own terms, by value: a lookup by the level's name would find 'constructor' on every object.\n const profile = Object.values(FACTUR_X_PROFILES).find((each) => each.conformanceLevel === conformanceLevel)\n if (profile === undefined) throw refusal('the e-invoice states a conformance level the renderer does not know')\n if (relationship !== profile.relationship) throw refusal('the e-invoice is related to the PDF otherwise than a file of its conformance level is')\n return { kind: 'facturX', xml, fileName, relationship: profile.relationship, conformanceLevel: profile.conformanceLevel }\n}\n\n/** An XRechnung's file, once the renderer knows it: one of report-spec's versions, and that version's syntax and guideline. */\nfunction checkXRechnung(file: Record<string, unknown>, xml: string): XRechnungFile {\n const { syntax, guideline, version } = file\n // A version by the list, never by a lookup that would find 'constructor' on every object.\n const known = XRECHNUNG_VERSIONS.find((each) => each === version)\n if (known === undefined) throw refusal('the XRechnung is of a version the renderer does not know')\n const terms = XRECHNUNG[known]\n if (syntax !== terms.syntax) throw refusal('the XRechnung is written in a syntax the renderer does not know')\n if (guideline !== terms.guideline) throw refusal('the XRechnung names another specification identifier than its version has')\n return { kind: 'xrechnung', xml, syntax: terms.syntax, guideline: terms.guideline, version: known }\n}\n\n/** `file`, once the renderer knows it: its XML text an encoder writes as it stands, and its kind's terms report-spec's. */\nexport function checkEInvoice(file: unknown): EInvoiceFile {\n if (typeof file !== 'object' || file === null) throw refusal('the e-invoice is not a file the renderer knows')\n const { kind, xml } = file as Record<string, unknown>\n if (typeof xml !== 'string') throw refusal(\"the e-invoice's XML is not text\")\n // An encoder writes U+FFFD for a lone surrogate without a word: the PDF would embed other bytes than the runtime wrote.\n if (LONE_SURROGATE.test(xml)) throw refusal(\"the e-invoice's XML holds a lone surrogate, which UTF-8 cannot encode as it stands\")\n if (kind === 'facturX') return checkFacturX(file as Record<string, unknown>, xml)\n if (kind === 'xrechnung') return checkXRechnung(file as Record<string, unknown>, xml)\n throw refusal('the e-invoice is of a kind the renderer does not know')\n}\n\n/**\n * Refuses an XRechnung's document whose page header, or page 1's own\n * header where it has one (0060), does not open with the runtime's label\n * paragraph, `XRECHNUNG_COPY_PARAGRAPH`, as the runtime writes it: its\n * text, `XRECHNUNG_COPY_LABEL`, the one run, at its size, bold and in its\n * colour, and nothing else. One of the two heads every page, so the label\n * opening each is on every page, and no block of a header's is drawn over\n * another: blocks flow. A copy drawn without it\n * would be a final picture of an invoice that says nothing of what it is\n * (0038), and so would one whose label is drawn in white or at one point,\n * where PDF.js still finds the text. The runtime writes it; a document\n * made otherwise, or by a runtime that forgot, is refused here. What this\n * does not see: the label names no font, and prints in the renderer's\n * default, and the paper is white because the renderer draws none.\n */\nexport function checkCopyLabel(header: readonly Block[], name: 'pageHeader' | 'firstPageHeader'): void {\n if (!samePlain(header[0], XRECHNUNG_COPY_PARAGRAPH)) {\n throw new RenderRefusal(\n 'unsupported',\n `an XRechnung's PDF is a copy of its XML, labelled so at the top of every page, and this document's ${name === 'pageHeader' ? 'page header' : 'first page header'} does not open with the label as the runtime writes it`,\n name,\n )\n }\n}\n\n/** Whether two values of a resolved document are the same data: equal primitives, or two arrays, or two objects that are not, of the same keys holding the same values. */\nfunction samePlain(a: unknown, b: unknown): boolean {\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) return a === b\n if (Array.isArray(a) !== Array.isArray(b)) return false\n const [left, right] = [Object.keys(a), Object.keys(b)]\n return (\n left.length === right.length &&\n left.every((key) => right.includes(key) && samePlain((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]))\n )\n}\n\nconst LONE_SURROGATE = /[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/\n","import { E_INVOICE_PREVIEW_LABEL, PREVIEW_LABEL, readCopyLabel, RenderRefusal } from '@formancy/report-runtime'\nimport type { Block, EInvoiceFile, ResolvedDocument } from '@formancy/report-runtime'\nimport { checkCopyLabel, checkEInvoice } from './e-invoice.js'\nimport type { PdfA } from './pdfa.js'\n\n/**\n * What a document is drawn as, decided once, before pdfmake sees it: a\n * Factur-X e-invoice as the PDF/A-3b that embeds its XML (0031); an\n * XRechnung as the plain copy its label says it is (0038); a document a\n * host asks for as `pdfa: '2b'` as a PDF/A-2b, which embeds nothing\n * (0057); and every other document as a plain PDF, as it always was. The\n * definition, the final pass's hook and the image checks read the one\n * answer, `Checked.pdfa`, and none of them decides it again.\n *\n * **What a PDF/A-2b cannot be it refuses**, as `unsupported`, saying to\n * render it without `pdfa`: a Factur-X, whose PDF/A-3b is the one PDF that\n * may embed its XML, and which drawn as a 2b would be a picture of the\n * invoice in an archive that cannot hold the invoice; an XRechnung's copy,\n * whose invoice is its XML, which a host sends, and whose PDF says on\n * every page it is not the invoice; a preview the runtime labels so,\n * which says on every page it is not the report, and would be kept as the\n * report; and a copy of an e-invoice the runtime labels so (0077), which\n * carries no e-invoice, says on every page it is not the invoice, and\n * would be kept as the invoice -- read by the runtime's `readCopyLabel`\n * on the page header and on page 1's own (0060), whatever its style. Without `pdfa` a copy is a document like any other,\n * drawn as a plain PDF that embeds nothing. An e-invoice the renderer does not know is refused first,\n * whatever was asked, for what it is (`e-invoice.ts`).\n *\n * The renderer has no mode: a resolved document carries none, and the\n * runtime's manifest, which says preview, is the host's. So it reads the\n * runtime's own labels, as it reads the copy's: a page header that opens\n * with a paragraph of one run, `PREVIEW_LABEL` or `E_INVOICE_PREVIEW_LABEL`,\n * is a preview, whatever its style. A preview of a report that is no\n * e-invoice and lacks nothing carries no label, is the same document as its\n * final render, and is drawn as one. What this does not see: a label among\n * other runs or below another block, and a preview made otherwise and left\n * unlabelled, are documents like any other.\n *\n * And it refuses, in whichever PDF/A, a title PDFKit cannot write into its\n * XMP (`checkPdfATitle`), naming the title and never quoting it.\n */\n\nconst refusal = (message: string, subject: string): RenderRefusal => new RenderRefusal('unsupported', message, subject)\n\n/** What `document` is drawn as, `asked` the host's `pdfa`: a PDF/A, or undefined for a plain PDF; refused where it can be neither as it was asked. */\nexport function checkPdfA(document: ResolvedDocument, asked: '2b' | undefined): PdfA | undefined {\n // An e-invoice it does not know is refused, never embedded as something else or drawn as a plain PDF (`e-invoice.ts`), whatever was asked.\n const eInvoice = document.eInvoice === undefined ? undefined : checkEInvoice(document.eInvoice)\n if (asked === '2b') refuseAs2b(eInvoice, document)\n // An XRechnung's PDF is a plain copy, labelled so on every page (0038): page 1 by its own header, where it has one (0060).\n if (eInvoice?.kind === 'xrechnung') {\n checkCopyLabel(document.pageHeader, 'pageHeader')\n if (document.firstPageHeader !== undefined) checkCopyLabel(document.firstPageHeader, 'firstPageHeader')\n }\n const pdfa: PdfA | undefined = eInvoice?.kind === 'facturX' ? { subset: 'PDF/A-3b', file: eInvoice } : asked === '2b' ? { subset: 'PDF/A-2b' } : undefined\n if (pdfa !== undefined) checkPdfATitle(document.info.title, pdfa)\n return pdfa\n}\n\n/** Refuses a document asked for as a PDF/A-2b that cannot be one: a Factur-X, an XRechnung's copy, a preview the runtime labels so, and a copy of an e-invoice it labels so on any header. */\nfunction refuseAs2b(eInvoice: EInvoiceFile | undefined, { pageHeader, firstPageHeader }: ResolvedDocument): void {\n if (eInvoice?.kind === 'facturX') {\n throw refusal(\n 'a Factur-X e-invoice is drawn as the PDF/A-3b that embeds its XML, and a PDF/A-2b may embed no such file: render it without pdfa',\n 'eInvoice',\n )\n }\n if (eInvoice?.kind === 'xrechnung') {\n throw refusal(\"an XRechnung's PDF is the plain copy of its XML, labelled so on every page, and never an archival PDF/A: render it without pdfa\", 'eInvoice')\n }\n if (labelledPreview(pageHeader)) {\n throw refusal(\n 'this document is a preview, labelled on every page as not a final report, and a PDF/A-2b of it would be kept as the report: draw the final render as PDF/A-2b, and the preview without pdfa',\n 'pageHeader',\n )\n }\n // Page 1's own header too (0060): a copy labelled there alone is still archived as the invoice by the page a reader opens first.\n for (const [subject, header] of [['pageHeader', pageHeader] as const, ['firstPageHeader', firstPageHeader ?? []] as const]) {\n if (readCopyLabel(header) !== undefined) {\n throw refusal(\n 'this document is a copy of an e-invoice, labelled on every page as not the invoice, and a PDF/A-2b of it would be kept as the invoice: keep the invoice, and draw the copy without pdfa',\n subject,\n )\n }\n }\n}\n\n/** Whether a page header opens as the runtime heads a preview's every page: a paragraph of its label, the one run. */\nfunction labelledPreview(pageHeader: readonly Block[]): boolean {\n const first = pageHeader[0]\n if (first?.kind !== 'paragraph' || first.runs.length !== 1) return false\n const run = first.runs[0]!\n return 'text' in run && (run.text === PREVIEW_LABEL || run.text === E_INVOICE_PREVIEW_LABEL)\n}\n\n/**\n * Refuses a PDF/A's title that PDFKit cannot write into its XMP: it puts\n * the title into `dc:title` as it stands, unescaped (pdfkit.js 6025-6032;\n * `pdfmake.test.ts` holds it), so an ampersand or an angle bracket, or a\n * character XML 1.0 cannot write, leaves the XMP not well-formed -- a PDF\n * that says it is a PDF/A and is not one (veraPDF 6.6.2.1-4). report-spec\n * refuses such a title in an e-invoice report, so an e-invoice the runtime\n * resolved never reaches this; a report that is none may hold one, and as\n * a PDF/A-2b is refused here, as is a document made otherwise, naming the\n * title and not quoting it. The information dictionary would hold it as\n * written, and in a report drawn as no PDF/A it reaches no XMP and is\n * drawn.\n */\nexport function checkPdfATitle(title: string, pdfa: PdfA): void {\n if (/[&<>]/.test(title) || [...title].some((character) => !xmlCharacter(character.codePointAt(0)!))) {\n throw refusal(\n pdfa.subset === 'PDF/A-3b'\n ? \"an e-invoice's title is written into its PDF/A's XMP as it stands, where it may hold no &, < or > and no character XML 1.0 cannot write: this one does\"\n : \"a PDF/A-2b's title is written into its XMP as it stands, where it may hold no &, < or > and no character XML 1.0 cannot write: this one does\",\n 'info.title',\n )\n }\n}\n\n/** Refuses the CMYK JPEG `id`, which a PDF/A cannot hold beside its sRGB output intent (veraPDF 6.2.4.3-3), naming it. */\nexport function refuseCmyk(id: string, pdfa: PdfA): never {\n throw refusal(\n pdfa.subset === 'PDF/A-3b'\n ? `the image ${id} is a CMYK JPEG, which an e-invoice cannot hold: it is drawn as a PDF/A-3 whose output intent is sRGB, beside which no image may be CMYK`\n : `the image ${id} is a CMYK JPEG, which a PDF/A-2b cannot hold: its output intent is sRGB, beside which no image may be CMYK`,\n id,\n )\n}\n\n/** XML 1.0's Char: tab, line feed and carriage return, and every code point from U+0020 but the surrogates, U+FFFE and U+FFFF. A lone surrogate is read as its own code point, and is none. */\nfunction xmlCharacter(code: number): boolean {\n return (\n code === 0x9 ||\n code === 0xa ||\n code === 0xd ||\n (code >= 0x20 && code <= 0xd7ff) ||\n (code >= 0xe000 && code <= 0xfffd) ||\n (code >= 0x10000 && code <= 0x10ffff)\n )\n}\n","import { MAX_SVG_COORDINATE, MAX_SVG_DEPTH, RenderRefusal, type Image } from '@formancy/report-runtime'\nimport type { Vector } from './assets.js'\nimport type { PdfA } from './pdfa.js'\n\n/**\n * An SVG in a PDF/A (0030, beside 0031): what the PDF/A-3 an e-invoice or a\n * PDF/A-2b is drawn as holds an image of one to, checked before pdfmake\n * runs. PDF/A-2 and -3 make ISO 32000-1's implementation limits\n * requirements (ISO 19005-2, 6.1.13): no integer past 2,147,483,647 in\n * magnitude, and the graphics state nested no deeper than 28. PDFKit\n * writes a whole number with no point, as an integer (pdfkit.js 173-178),\n * and svg-to-pdfkit computes some of its numbers through the inverse of\n * the drawing's matrix and the image's box: a drawing whose clip and\n * transparency are shrunk a millionfold, drawn a point square, wrote a\n * group's /BBox of 78,520,000,000 into an e-invoice that said it was a\n * PDF/A-3b, which veraPDF 1.30.3 failed on its rule 6.1.13-1 (measured\n * 18 October 2026).\n *\n * So the check bounds, from above, every number the converter writes for\n * an image -- from report-spec's extent of the drawing (`svg-extent.ts`),\n * the image's box and fit, and the page, the image standing anywhere on it,\n * since where pdfmake puts it is not known before it runs -- and refuses an\n * image whose bound passes `SVG_INTEGER_BOUND`, or whose drawing nests\n * deeper than `PDF_A_NESTING`, as `unsupported`, naming it and saying what\n * to do. pdfmake draws an image in the page's own stream, whether it stands\n * in the body, a page region, a section, columns or a keep-together block,\n * and nests nothing around it (measured that day with veraPDF), so the\n * drawing's nesting is the stream's. A report drawn as no PDF/A draws\n * such an image as it always did.\n */\n\n/** The largest integer, in magnitude, a PDF/A-2 or -3 may hold (ISO 19005-2, 6.1.13; veraPDF's rule 6.1.13-1). A real may reach 3.403 × 10^38, past the 10^21 at which PDFKit throws. */\nexport const PDF_A_INTEGER = 2_147_483_647\n\n/** The deepest a PDF/A-2 or -3 may nest the graphics state, q inside q (ISO 19005-2, 6.1.13; veraPDF's rule 6.1.13-8). */\nexport const PDF_A_NESTING = 28\n\n/**\n * What floating point may put between the bound and what the converter\n * writes, relative, derived and not measured. The groups' term is computed\n * from the matrix the cleaner composed, and the converter composes the same\n * matrices in its own order, the page's flip and the fit's scale first, and\n * inverts the product to find a group's box. Below the svg at most\n * `MAX_SVG_DEPTH` - 1 elements bring a matrix each, and the fit comes\n * before them, so the product is at most `MAX_SVG_DEPTH` products (the\n * flip is exact); an entry of a product's linear part is two products\n * summed, so each rounds it at most twice, by 2^-53 of an entry that no\n * cancellation shrank: 2 × `MAX_SVG_DEPTH` units. Inverting magnifies that\n * by the matrix's condition number, at most 4 × `MAX_SVG_COORDINATE`² for\n * a matrix whose entries and whose inverse's are each at most\n * `MAX_SVG_COORDINATE`, as the cleaner's `compose` holds them; and twice\n * that, for the two computations: 2 × 4 × 10^12 × 2 × 32 × 2^-53, 5.7 %.\n * The other terms invert nothing, and lose less. Not bounded by it:\n * matrices built to cancel one another term by term, whose products\n * floating point gets wrong in both (0030).\n */\nexport const SVG_INTEGER_MARGIN = 2 * (4 * MAX_SVG_COORDINATE ** 2) * (2 * MAX_SVG_DEPTH) * 2 ** -53\n\n/** The largest an SVG's numbers may be bounded at in a PDF/A: `PDF_A_INTEGER` less `SVG_INTEGER_MARGIN`. */\nexport const SVG_INTEGER_BOUND = Math.floor(PDF_A_INTEGER * (1 - SVG_INTEGER_MARGIN))\n\n/**\n * What the converter writes of the drawing besides its outlines' points,\n * which the extent's `own` holds: each element's own matrix, a stroke's\n * width and dashes, a gradient's ends, each a number the cleaner holds to\n * `MAX_SVG_COORDINATE`; and a radial gradient's focus, which the converter\n * moves inside its circle (`source.js:1884-1888`), within twice it.\n */\nconst WRITTEN = 2 * MAX_SVG_COORDINATE\n\n/** The paper, in points. */\nexport interface Paper {\n readonly paperWidth: number\n readonly paperHeight: number\n}\n\n/**\n * The largest magnitude, from above, of a number svg-to-pdfkit writes for\n * `vector` drawn as `image` anywhere on `paper`. The converter fits the\n * viewBox to the box with a scale `s` and the offset `d` that centres it\n * (`parseAspectRatio`, source.js:624-637); PDFKit's page matrix flips the\n * page, and the image's corner is somewhere on it. So a page corner, back\n * through the page and the image's corner, is at most the page's longer\n * side away from it in each coordinate, and back through the fit at most\n * that and `d`, over `s`, from the viewBox's origin. Then:\n *\n * - the fit itself is written as `s`, and `d` less `s` times the origin;\n * - a group's /BBox is that through the inverse of its matrix: at most\n * where the inverse takes the origin, and its row sum times the rest;\n * - a gradient's /Matrix outside every group is the page's and the fit's\n * times its own: `s` times its linear part, and its translation from the\n * origin `s` times as far from the image's corner, `d` and the page's\n * side further;\n * - a gradient's inside a group, and a clip's box, are the drawing's own,\n * wherever it stands: `local`;\n * - the outlines' points are written in their own coordinates: `own`.\n */\nexport function svgReach(vector: Vector, image: Pick<Image, 'width' | 'height' | 'fit'>, paper: Paper): number {\n return Math.max(placed(vector, image, paper), outlines(vector))\n}\n\n/** The numbers the drawing itself writes, wherever it is placed: its outlines' points, and the rest at `WRITTEN`. */\nfunction outlines({ extent }: Vector): number {\n return Math.max(WRITTEN, extent.own)\n}\n\n/** The numbers that grow with where the drawing is placed and how large: `svgReach`'s fit, groups, gradients and what is written in a group's own coordinates. */\nfunction placed(vector: Vector, image: Pick<Image, 'width' | 'height' | 'fit'>, paper: Paper): number {\n const { extent } = vector\n const across = { x: image.width / vector.width, y: image.height / vector.height }\n const s = image.fit === 'cover' ? Math.max(across.x, across.y) : Math.min(across.x, across.y)\n const dx = (image.width - vector.width * s) / 2\n const dy = (image.height - vector.height * s) / 2\n const side = Math.max(paper.paperWidth, paper.paperHeight)\n const d = Math.max(Math.abs(dx), Math.abs(dy))\n const fit = Math.max(s, Math.abs(dx - s * vector.x), Math.abs(dy - s * vector.y))\n const groups = extent.groups.inverse === 0 ? 0 : extent.groups.origin + (extent.groups.inverse * (side + d)) / s\n const patterns = Math.max(s * extent.patterns.linear, extent.patterns.linear === 0 ? 0 : side + s * extent.patterns.offset + d)\n return Math.max(fit, groups, patterns, extent.local)\n}\n\n/** Refuses `image`, an SVG of `vector`, where the PDF/A `pdfa` cannot hold what the converter writes for it on `paper`. */\nexport function checkSvgInPdfA(vector: Vector, image: Image, paper: Paper, pdfa: PdfA): void {\n const drawn = pdfa.subset === 'PDF/A-3b' ? 'an e-invoice is drawn as a PDF/A-3, which' : 'a PDF/A-2b'\n const { id } = image.asset\n if (vector.extent.nesting > PDF_A_NESTING) {\n throw new RenderRefusal(\n 'unsupported',\n `the image ${id} is an SVG that pdfmake's converter draws ${vector.extent.nesting} graphics states deep, and ${drawn} nests them ${PDF_A_NESTING} deep at most: flatten the groups it nests`,\n id,\n )\n }\n const own = outlines(vector)\n const reach = Math.max(own, placed(vector, image, paper))\n if (reach > SVG_INTEGER_BOUND) {\n const advice =\n own === reach\n ? 'save it again from the drawing program, its arcs drawn with radii that reach their ends and its smooth curves with control points of their own'\n : 'draw it larger, or flatten the transforms under its clips, its transparency and its gradients'\n throw new RenderRefusal(\n 'unsupported',\n `the image ${id} is an SVG whose numbers, drawn ${image.width} × ${image.height} pt, could reach ${Math.ceil(reach)}, and ${drawn} holds an integer to ${PDF_A_INTEGER}, ${SVG_INTEGER_BOUND} with the renderer's margin for rounding: ${advice}`,\n id,\n )\n }\n}\n","import { MAX_SVG_GROUPS, MAX_SVG_SEGMENTS, RenderRefusal, type Image, type ImageAsset } from '@formancy/report-runtime'\nimport { checkImageAsset, MAX_IMAGE_DATA, MAX_SVG_DRAWING, type CheckedImage, type Vector } from './assets.js'\nimport { refuseCmyk } from './pdfa-check.js'\nimport type { PdfA } from './pdfa.js'\nimport { checkSvgInPdfA, type Paper } from './svg-pdfa.js'\n\n/**\n * What a render's images cost together, judged once the walk (`check.ts`)\n * has found every one and where it stands, and the place each asset is\n * read: apart from the walk, since what a render may hold of images is\n * decided by what they cost, not by where a block may stand.\n */\n\n/** An image the walk found, and whether it is drawn on every page: one in the page header or footer, which pdfmake draws on each. */\nexport interface PlacedImage {\n readonly image: Image\n readonly everyPage: boolean\n}\n\n/**\n * Every image's asset, read once however many images draw it, and what the\n * images cost together, each refusal naming the asset whose image crossed\n * it:\n *\n * - the image data the PNGs and JPEGs hold, once for each asset, against\n * `MAX_IMAGE_DATA`, as `content-too-large`: each is embedded once;\n * - in a PDF/A, an e-invoice's PDF/A-3b or a PDF/A-2b (`pdfa-check.ts`),\n * a JPEG PDFKit draws in DeviceCMYK, refused as `unsupported`: the\n * PDF/A has an sRGB output intent, beside which no image may be CMYK\n * (veraPDF 6.2.4.3-3), and a second intent would have to share its\n * profile (6.2.3-2);\n * - in a PDF/A, an image of an SVG whose numbers, at its box and on its\n * page, could pass the integers a PDF/A holds, or whose drawing nests\n * the graphics state deeper than one may, refused as `unsupported`\n * (`svg-pdfa.ts`): each image, since its box decides;\n * - what drawing the SVGs costs the renderer, for every image of one,\n * against `MAX_SVG_DRAWING`, as `content-too-large`: the converter draws an SVG wherever it\n * stands, and one in the page header or footer on every page, counted as `maxPages`,\n * the pages the report may have, which is known before the render; one\n * in page 1's own header (0060) is drawn on page 1 alone, and counted once;\n * - what the SVGs cost a reader to paint, against `MAX_SVG_SEGMENTS` and\n * `MAX_SVG_GROUPS`, as `content-too-large`, the bounds of one drawing, measured as what one page\n * may cost: every SVG image of the body counted as though all of them fell\n * on one page, beside those of the page regions, which every page draws,\n * and page 1's own header's. Which page each lands on is known only once\n * pdfmake has laid the body out.\n */\nexport async function checkImages(\n images: readonly PlacedImage[],\n maxPages: number,\n pdfa: PdfA | undefined,\n paper: Paper,\n): Promise<ReadonlyMap<ImageAsset, CheckedImage>> {\n const assets = new Map<ImageAsset, CheckedImage>()\n const total = { data: 0, units: 0, segments: 0, groups: 0 }\n for (const { image, everyPage } of images) {\n const { id } = image.asset\n let read = assets.get(image.asset)\n if (read === undefined) {\n read = await checkImageAsset(image.asset)\n if (pdfa !== undefined && read.kind === 'raster' && read.cmyk) refuseCmyk(id, pdfa)\n assets.set(image.asset, read)\n total.data += read.kind === 'raster' ? read.data : 0\n if (total.data > MAX_IMAGE_DATA)\n throw new RenderRefusal('content-too-large', `the images up to ${id} hold ${total.data} bytes of image data; a render may hold ${MAX_IMAGE_DATA}`, id)\n }\n if (pdfa !== undefined && read.kind === 'vector') checkSvgInPdfA(read, image, paper, pdfa)\n if (read.kind === 'vector') addVector(total, read, everyPage ? maxPages : 1, id)\n }\n return assets\n}\n\n/** One more SVG image, drawn `times` times, added to what the render's SVG images cost; refused past a bound. */\nfunction addVector(total: { units: number; segments: number; groups: number }, vector: Vector, times: number, id: string): void {\n total.units += vector.units * times\n total.segments += vector.segments\n total.groups += vector.groups\n if (total.units > MAX_SVG_DRAWING) {\n throw new RenderRefusal(\n 'content-too-large',\n `the SVG images up to ${id} cost ${total.units} units to draw, each in the page header or footer counted on every page the report may have, one in page 1's own header once; a render may draw ${MAX_SVG_DRAWING}`,\n id,\n )\n }\n const onePage = 'on one page, every SVG image of the body counted as though it fell there beside those of the page regions'\n if (total.segments > MAX_SVG_SEGMENTS)\n throw new RenderRefusal(\n 'content-too-large',\n `the SVG images up to ${id} would cost a reader ${total.segments} weighted segments to paint ${onePage}; a page may cost ${MAX_SVG_SEGMENTS}`,\n id,\n )\n if (total.groups > MAX_SVG_GROUPS)\n throw new RenderRefusal(\n 'content-too-large',\n `the SVG images up to ${id} would make ${total.groups} units of page-sized transparency groups ${onePage}; a page may make ${MAX_SVG_GROUPS}`,\n id,\n )\n}\n","import { MAX_KEEP_WITH_ROWS, RenderRefusal, type Table } from '@formancy/report-runtime'\n\n/**\n * Refuses a table whose rows keep rows otherwise than the runtime writes\n * them (0059), naming the table and the row, never a cell's text: a count\n * on a row that is no group header; one that is not a whole number from 2\n * to `MAX_KEEP_WITH_ROWS`, the one row every header keeps being no member;\n * and one past the detail rows under its header, before the next row of\n * another kind. How many rows a group has is the runtime's to count, once;\n * the plan reads the count as given (`breaks.ts`), and a count the runtime\n * could not have written -- a header of two rows keeping three, the next\n * group's header among them, or text where a number stands -- is never\n * guessed at. If the two ever disagree, the render says so.\n */\nexport function checkKeptRows(table: Table): void {\n table.rows.forEach((row, index) => {\n const count: unknown = row.keepWithRows\n if (count === undefined) return\n const at = `row ${index} of table ${table.id}`\n if (row.kind !== 'groupHeader') throw new RenderRefusal('unsupported', `${at} keeps rows with it, and only a group header does`, table.id)\n if (!(typeof count === 'number' && Number.isInteger(count) && count >= 2 && count <= MAX_KEEP_WITH_ROWS)) {\n // A value that is no number is named by its type alone, never quoted.\n const keeps = typeof count === 'number' ? `${count} rows` : `rows by a count of type ${typeof count}`\n throw new RenderRefusal(\n 'unsupported',\n `${at}, a group header, keeps ${keeps}; a group header keeps a whole number of them from 2 to ${MAX_KEEP_WITH_ROWS}, and only its first where it says none`,\n table.id,\n )\n }\n let details = 0\n while (table.rows[index + 1 + details]?.kind === 'detail') details++\n if (count > details) throw new RenderRefusal('unsupported', `${at}, a group header, keeps ${count} rows, and ${details} detail rows follow it`, table.id)\n })\n}\n","import { RenderRefusal, type Table, type TableRow } from '@formancy/report-runtime'\nimport { cellLine } from './bound.js'\nimport { checkStyle, checkText } from './check-faces.js'\nimport { tall, type Place, type Walk } from './check-walk.js'\nimport type { RenderFonts } from './host-fonts.js'\nimport { checkKeptRows } from './kept-rows.js'\nimport { cellFace, PADDING_X, PADDING_Y, styledRows, type StyledRow } from './table.js'\nimport { fillWidth, fixedWidth } from './widths.js'\n\n/** The tallest line of a table's rows under its header, or under its top rule where it has none, and the row it is in: what every page the table reaches must hold under the repeated header (`refuseLineUnderHeader`). */\nexport interface RowLine {\n readonly line: number\n /** \"row 2 of table lines, a total row,\" or \"the empty text of table lines\": the row, for a refusal, never its text. */\n readonly what: string\n}\n\n/**\n * Every cell of `table`, each as `styledRows` styles it, the walk\n * `tableContent` builds the table from: its text in the face it prints in\n * -- the renderer's weight for its row's kind under the cell's style's\n * font token, weight and slant; the empty text in italic, and only where\n * the table prints it, so a table of rows never asks for the face -- and\n * its line, the tallest of which is a row no page can start, and which\n * pdfmake would drop without a word: every cell's, at its size or the\n * table's, in the face it prints in (`cellLine`), so a host face of a\n * taller line than Roboto's is measured by its own. An empty cell's line\n * is counted too, since the measuring pass lays it out as a no-break\n * space of its size.\n *\n * Returns the tallest line of the rows under the header, and its row: one\n * that a page the table continues on cannot hold under the repeated header\n * is refused once the header is measured (`refuseLineUnderHeader`). There\n * is always one, since a table of no detail row prints its empty text.\n */\nexport function checkTableCells(table: Table, place: Place, walk: Walk): RowLine {\n const at = `table ${table.id}`\n let tallest = 0\n let under: RowLine | undefined\n // A running max, never a spread of one array per cell: a 100,000-row table would overflow the call stack.\n for (const row of styledRows(table)) {\n let line = 0\n row.cells.forEach((text, column) => {\n const style = row.styles[column]!\n const where =\n row.index !== undefined\n ? `${at}, row ${row.index}, column ${column + 1},`\n : row.kind === 'header'\n ? `${at}'s header, column ${column + 1},`\n : `${at}'s empty text`\n checkText(text, cellFace(style, row.kind), walk, where, table.id)\n line = Math.max(line, cellLine(style, row.kind, walk.fonts))\n })\n tallest = Math.max(tallest, line)\n const { kind } = row\n if (kind !== 'header' && line > (under?.line ?? 0)) under = { line, what: rowWords(table, kind, row.index) }\n }\n tall(walk, place, tallest + 2 * PADDING_Y, `a line of ${at}`, table.id)\n return under!\n}\n\n/** A row of the document's in a person's words, by its kind. */\nconst ROW_WORDS: Readonly<Record<TableRow['kind'], string>> = {\n detail: 'a detail row',\n groupHeader: 'a group header row',\n groupFooter: 'a group footer row',\n total: 'a total row',\n}\n\n/** A row under the header of `table`, for a refusal: the empty text, or where the row stands among the table's rows, `index`, and its kind. */\nfunction rowWords(table: Table, kind: Exclude<StyledRow['kind'], 'header'>, index: number | undefined): string {\n return kind === 'empty' ? `the empty text of table ${table.id}` : `row ${String(index)} of table ${table.id}, ${ROW_WORDS[kind]},`\n}\n\nexport function checkTable(table: Table, width: number, fonts: RenderFonts): void {\n const columns = table.columns.length\n if (columns === 0) throw new RenderRefusal('unsupported', `table ${table.id} has no columns`, table.id)\n if (table.columns.some((column) => column.align !== 'left' && column.align !== 'center' && column.align !== 'right'))\n throw new RenderRefusal('unsupported', `table ${table.id} aligns a column in a way the renderer does not know`, table.id)\n if (table.header !== undefined && table.header.length !== columns)\n throw new RenderRefusal('unsupported', `the header of table ${table.id} has ${table.header.length} cells for ${columns} columns`, table.id)\n table.rows.forEach((row, index) => {\n const cells = row.across === true ? 1 : columns\n if (row.cells.length !== cells) {\n throw new RenderRefusal(\n 'unsupported',\n `row ${index} of table ${table.id} has ${row.cells.length} cells for ${row.across === true ? 'a row across the table, which has one' : `${columns} columns`}`,\n table.id,\n )\n }\n if (row.cellStyles !== undefined && row.cellStyles.length !== row.cells.length) {\n throw new RenderRefusal(\n 'unsupported',\n `row ${index} of table ${table.id} has ${row.cellStyles.length} cell styles for ${row.cells.length} cells`,\n table.id,\n )\n }\n for (const style of [row.style, ...(row.cellStyles ?? [])]) checkStyle(style ?? undefined, table.id, fonts)\n })\n checkKeptRows(table)\n checkStyle(table.headerStyle, table.id, fonts)\n const narrow = table.columns.find((column) => column.width !== 'fill' && !(column.width > 2 * PADDING_X && Number.isFinite(column.width)))\n if (narrow !== undefined)\n throw new RenderRefusal('unsupported', `table ${table.id} has a column of ${String(narrow.width)} pt, no wider than its cell padding`, table.id)\n const widths = table.columns.map((column) => column.width)\n const fixed = widths.reduce<number>((sum, each) => sum + fixedWidth(each), 0)\n if (fixed > width || fillWidth(widths, width) <= 2 * PADDING_X) {\n throw new RenderRefusal('content-too-large', `table ${table.id}'s fixed columns are ${fixed} pt wide; it stands ${width.toFixed(2)} pt wide`, table.id)\n }\n}\n","import {\n epcSymbol,\n qrSymbol,\n RenderRefusal,\n type Block,\n type Chart,\n type Columns,\n type EpcQrCode,\n type Image,\n type ImageAsset,\n type QrCode,\n type QrSymbol,\n type Rectangle,\n type ResolvedDocument,\n type Section,\n} from '@formancy/report-runtime'\nimport type { CheckedImage } from './assets.js'\nimport { paragraphLine } from './bound.js'\nimport { checkChart, checkChartDrawing } from './check-chart.js'\nimport { checkColor, checkStyle, checkText } from './check-faces.js'\nimport { checkImages } from './check-images.js'\nimport { checkTable, checkTableCells } from './check-table.js'\nimport { tall, type Measured, type Place, type Tall, type Walk } from './check-walk.js'\nimport { frameOf, RULE_GAP, runFace } from './content.js'\nimport type { RenderFonts } from './host-fonts.js'\nimport { checkPdfA } from './pdfa-check.js'\nimport type { PdfA } from './pdfa.js'\nimport { checkBaselines } from './shifted.js'\nimport { fillWidth, fixedWidth } from './widths.js'\n\n/**\n * What the renderer refuses before pdfmake sees the document: what pdfmake\n * cannot print, what is malformed, what stands where it cannot be laid out,\n * what is wider than where it stands, text with a character the face it\n * prints in has no glyph for (`glyphs.ts`), an e-invoice the renderer does\n * not know (`e-invoice.ts`), and what a PDF/A cannot hold (`pdfa-check.ts`):\n * a title PDFKit cannot write into its XMP, a CMYK JPEG beside its sRGB\n * output intent, an SVG whose numbers could pass its integers' range or\n * whose nesting its graphics state's (`svg-pdfa.ts`), and a Factur-X, an\n * XRechnung's copy or a labelled preview asked for as a PDF/A-2b. Every\n * refusal names where the problem is -- `body[2].blocks[0]`, a table's id,\n * an asset's id -- and none of them is a\n * partial render: a document that is refused has drawn nothing.\n *\n * The walk also collects what can only be judged once the page regions are\n * measured -- whatever is too tall for any page's body -- and what the body\n * pass measures: its tables and keep-together blocks, each at the width it\n * stands at. It asks the runtime for every QR code's and EPC QR code's\n * symbol, once, and that symbol is what every pass draws (`qr.ts`,\n * `epc.ts`). It finds every\n * image, and `check-images.ts` reads each asset once and holds the render to\n * what its images cost together. It holds the render to what its charts\n * cost to draw together (`checkChartDrawing`).\n *\n * Page 1's own header (0060) is walked as a page region, but drawn once, in\n * page 1's background, before the pages are counted: no page field stands\n * in it, and its images are counted once.\n */\n\n/** The paper and its printable area, in points. */\nexport interface Page {\n readonly paperWidth: number\n readonly paperHeight: number\n readonly margins: ResolvedDocument['page']['margins']\n readonly width: number\n readonly height: number\n}\n\n/** Portrait sizes in points, as PDF engines write them: ISO A4 is 210 by 297 millimetres, US Letter 8.5 by 11 inches. */\nconst PAPER: Readonly<Record<ResolvedDocument['page']['size'], { readonly width: number; readonly height: number }>> = {\n A4: { width: 595.28, height: 841.89 },\n Letter: { width: 612, height: 792 },\n}\n\n/**\n * How deep blocks may nest. report-spec allows four containers; the\n * renderer recurses through whatever it is given, so a hostile document of\n * ten thousand nested sections would end in a stack overflow rather than a\n * refusal. This bounds the recursion, not a layout.\n */\nexport const MAX_DEPTH = 16\n\nexport interface Checked {\n readonly page: Page\n readonly creationDate: Date\n /** What the document is drawn as, decided once (`pdfa-check.ts`): an e-invoice's PDF/A-3b with the file it embeds, the PDF/A-2b a host asked for, or, undefined, a plain PDF. */\n readonly pdfa: PdfA | undefined\n /** Every image asset as the checks read it: a PNG's or a JPEG's size in pixels, as it is shown, or an SVG's drawing. */\n readonly assets: ReadonlyMap<ImageAsset, CheckedImage>\n /** Every QR code's and EPC QR code's symbol, encoded once. */\n readonly codes: ReadonlyMap<QrCode | EpcQrCode, QrSymbol>\n /** Whether an EPC QR code is captioned: its caption prints in Liberation Sans, which the engine loads for it. */\n readonly captioned: boolean\n /** In the body: judged against its height once the regions are measured. */\n readonly tall: readonly Tall[]\n /** Where each paragraph stands, for a refusal about its words to name. */\n readonly paths: ReadonlyMap<Block, string>\n readonly measured: readonly Measured[]\n /** Every chart of the body, and where it stands, each held to what the drawing lays out (`check-chart.ts`). */\n readonly charts: readonly { readonly block: Chart; readonly at: string }[]\n}\n\nexport async function checkDocument(document: ResolvedDocument, fonts: RenderFonts, maxPages: number, asked: '2b' | undefined): Promise<Checked> {\n const creationDate = new Date(document.info.creationDate)\n if (Number.isNaN(creationDate.getTime()))\n throw new RenderRefusal('unsupported', `the creation date '${document.info.creationDate}' is not a date`, 'info.creationDate')\n // The title goes into the PDF's metadata, never onto a page, so it is held to being text and not to the font.\n if (typeof document.info.title !== 'string') throw new RenderRefusal('unsupported', 'the title is not text', 'info.title')\n // What it is drawn as -- a Factur-X's PDF/A-3b, an XRechnung's plain copy, the PDF/A-2b asked for -- and what it cannot be, refused (`pdfa-check.ts`).\n const pdfa = checkPdfA(document, asked)\n const page = pageOf(document.page)\n const walk: Walk = { fonts, paths: new Map(), images: [], codes: new Map(), captioned: false, tall: [], measured: [], charts: [] }\n const top: Omit<Place, 'region' | 'everyPage'> = { kept: false, column: false, width: page.width, inset: 0, depth: 0 }\n checkBlocks(document.pageHeader, 'pageHeader', { ...top, region: true, everyPage: true }, walk)\n if (document.firstPageHeader !== undefined) checkBlocks(document.firstPageHeader, 'firstPageHeader', { ...top, region: true, everyPage: false }, walk)\n checkBlocks(document.pageFooter, 'pageFooter', { ...top, region: true, everyPage: true }, walk)\n checkBlocks(document.body, 'body', { ...top, region: false, everyPage: false }, walk)\n checkChartDrawing(walk.charts)\n const assets = await checkImages(walk.images, maxPages, pdfa, page)\n return {\n page,\n creationDate,\n pdfa,\n assets,\n codes: walk.codes,\n captioned: walk.captioned,\n tall: walk.tall,\n paths: walk.paths,\n measured: walk.measured,\n charts: walk.charts,\n }\n}\n\nfunction pageOf(setup: ResolvedDocument['page']): Page {\n // Own sizes only: 'constructor' or 'toString' would find Object's, and crash pdfmake.\n const paper = Object.hasOwn(PAPER, setup.size) ? PAPER[setup.size] : undefined\n if (paper === undefined) throw new RenderRefusal('unsupported', `the page size '${String(setup.size)}' is not one the renderer knows`, 'page.size')\n if (setup.orientation !== 'portrait' && setup.orientation !== 'landscape')\n throw new RenderRefusal('unsupported', `the orientation '${String(setup.orientation)}' is not one the renderer knows`, 'page.orientation')\n const [paperWidth, paperHeight] = setup.orientation === 'portrait' ? [paper.width, paper.height] : [paper.height, paper.width]\n const { margins } = setup\n if (![margins.top, margins.right, margins.bottom, margins.left].every((margin) => Number.isFinite(margin) && margin >= 0)) {\n throw new RenderRefusal('unsupported', 'a page margin is negative or not a number', 'page.margins')\n }\n const width = paperWidth - margins.left - margins.right\n const height = paperHeight - margins.top - margins.bottom\n if (width <= 0 || height <= 0)\n throw new RenderRefusal('content-too-large', `the margins leave no printable area (${width.toFixed(2)} × ${height.toFixed(2)} pt)`, 'page.margins')\n return { paperWidth, paperHeight, margins, width, height }\n}\n\nfunction checkBlocks(blocks: readonly Block[], path: string, place: Place, walk: Walk): void {\n if (place.depth > MAX_DEPTH) throw new RenderRefusal('unsupported', `${path} is nested more than ${MAX_DEPTH} blocks deep`, path)\n blocks.forEach((block, index) => checkBlock(block, `${path}[${index}]`, place, walk))\n}\n\nfunction checkBlock(block: Block, at: string, place: Place, walk: Walk): void {\n switch (block.kind) {\n case 'paragraph': {\n walk.paths.set(block, at)\n if (!place.everyPage && block.runs.some((run) => 'field' in run)) {\n const why = place.region\n ? \"page 1's own header is drawn before the pages are counted, and page 1's number and count print in the page footer\"\n : 'pdfmake knows the page number only in the page header and footer'\n throw new RenderRefusal('unsupported', `${at} prints a page field; ${why}`, at)\n }\n checkStyle(block.style, at, walk.fonts)\n if (block.runs.some((run) => !('text' in run) && run.field !== 'pageNumber' && run.field !== 'pageCount'))\n throw new RenderRefusal('unsupported', `${at} prints a field the renderer does not know`, at)\n checkBaselines(block, at)\n for (const run of block.runs) {\n if ('text' in run) checkText(run.text, runFace(block.style, run), walk, at)\n }\n // A page number or count prints its digits in the paragraph's face, which a host face may lack: held to it as any text is.\n const field = block.runs.find((run) => 'field' in run)\n if (field !== undefined) checkText(PAGE_DIGITS, runFace(block.style, field), walk, `${at}'s page field`, at)\n // A line as tall as its tallest run's face lays it out (`bound.ts`): taller than the body, pdfmake drops the whole line without a word.\n tall(walk, place, paragraphLine(block, walk.fonts), `a line of ${at}`, at)\n return\n }\n case 'table': {\n if (place.column) throw new RenderRefusal('unsupported', `table ${block.id} stands inside a columns block; a table is part of the flow`, block.id)\n checkTable(block, place.width, walk.fonts)\n const under = checkTableCells(block, place, walk)\n if (!place.region && !place.kept) walk.measured.push({ block, at, width: place.width, inset: place.inset, under })\n return\n }\n case 'image':\n checkImage(block, place, walk)\n walk.images.push({ image: block, everyPage: place.everyPage })\n return\n case 'qrCode':\n checkQrCode(block, place, walk)\n return\n case 'epcQrCode':\n checkEpcQrCode(block, place, walk)\n return\n case 'chart':\n checkChart(block, at, place, walk)\n return\n case 'rule':\n if (!(block.thickness > 0 && Number.isFinite(block.thickness))) throw new RenderRefusal('unsupported', `${at} is a rule ${block.thickness} pt thick`, at)\n checkColor(block.color, at)\n // Its line and the space above and below it (`ruleContent`): taller than the body, it was stroked over the footer and off the paper, or crashed pdfmake.\n tall(walk, place, block.thickness + 2 * RULE_GAP, `the rule ${at}`, at)\n return\n case 'rectangle':\n checkRectangle(block, at, place, walk)\n return\n case 'spacer':\n if (!(block.height >= 0 && Number.isFinite(block.height))) throw new RenderRefusal('unsupported', `${at} is a spacer ${block.height} pt tall`, at)\n return\n case 'pageBreak': {\n const inside = place.region ? 'page region' : place.kept ? 'keep-together block' : place.column ? 'columns block' : undefined\n if (inside !== undefined) throw new RenderRefusal('unsupported', `${at} is a page break inside a ${inside}`, at)\n return\n }\n case 'keepTogether':\n if (!place.region && !place.kept) walk.measured.push({ block, at, width: place.width, inset: place.inset, under: undefined })\n checkBlocks(block.blocks, `${at}.blocks`, { ...place, kept: true, depth: place.depth + 1 }, walk)\n return\n case 'columns':\n checkColumns(block, at, place, walk)\n return\n case 'section':\n checkSection(block, at, place, walk)\n return\n default:\n // A document from a runtime that knows a block this renderer does not.\n throw new RenderRefusal('unsupported', `${at} is a ${String((block as { kind?: unknown }).kind)} block, which the renderer does not know`, at)\n }\n}\n\n/** The digits a page number or count prints. */\nconst PAGE_DIGITS = '0123456789'\n\nfunction checkImage(image: Image, place: Place, walk: Walk): void {\n const { id } = image.asset\n if (image.fit !== 'contain' && image.fit !== 'cover')\n throw new RenderRefusal('unsupported', `the image ${id} is fitted '${String(image.fit)}', which the renderer does not know`, id)\n if (!(image.width > 0 && image.height > 0 && Number.isFinite(image.width) && Number.isFinite(image.height))) {\n throw new RenderRefusal('unsupported', `the image ${id} is drawn ${image.width} × ${image.height} pt`, id)\n }\n if (image.width > place.width)\n throw new RenderRefusal('content-too-large', `the image ${id} is ${image.width} pt wide; it stands ${place.width.toFixed(2)} pt wide`, id)\n tall(walk, place, image.height, `the image ${id}`, id)\n}\n\n/** A QR code is a square that stands where an image may; its symbol, and what refuses it but a body too short, are the runtime's (0074). */\nfunction checkQrCode(code: QrCode, place: Place, walk: Walk): void {\n walk.codes.set(code, qrSymbol(code, place.width))\n tall(walk, place, code.size, `the QR code ${code.id}`, code.id)\n}\n\n/** An EPC QR code is a square that stands where a QR code may, and its caption, when it has one, is drawn inside it. */\nfunction checkEpcQrCode(code: EpcQrCode, place: Place, walk: Walk): void {\n walk.codes.set(code, epcSymbol(code, place.width))\n walk.captioned ||= code.caption !== undefined\n tall(walk, place, code.size, `the EPC QR code ${code.id}`, code.id)\n}\n\nfunction checkRectangle(rectangle: Rectangle, at: string, place: Place, walk: Walk): void {\n if (!(rectangle.width > 0 && rectangle.height > 0 && Number.isFinite(rectangle.width) && Number.isFinite(rectangle.height))) {\n throw new RenderRefusal('unsupported', `${at} is a rectangle of ${rectangle.width} × ${rectangle.height} pt`, at)\n }\n checkColor(rectangle.fill, at)\n checkColor(rectangle.stroke, at)\n if (rectangle.width > place.width)\n throw new RenderRefusal('content-too-large', `${at} is a rectangle ${rectangle.width} pt wide; it stands ${place.width.toFixed(2)} pt wide`, at)\n tall(walk, place, rectangle.height, `the rectangle ${at}`, at)\n}\n\nfunction checkColumns(columns: Columns, at: string, place: Place, walk: Walk): void {\n if (columns.columns.length === 0) throw new RenderRefusal('unsupported', `${at} is a columns block with no columns`, at)\n const widths = columns.columns.map((slot) => slot.width)\n if (widths.some((width) => width !== 'fill' && !(width > 0 && Number.isFinite(width))))\n throw new RenderRefusal('unsupported', `${at} has a column of no width`, at)\n const fixed = widths.reduce<number>((sum, each) => sum + fixedWidth(each), 0)\n const fill = fillWidth(widths, place.width)\n if (fixed > place.width || fill <= 0)\n throw new RenderRefusal('content-too-large', `${at}'s fixed columns are ${fixed} pt wide; it stands ${place.width.toFixed(2)} pt wide`, at)\n columns.columns.forEach((slot, index) => {\n const width = slot.width === 'fill' ? fill : slot.width\n checkBlocks(slot.blocks, `${at}.columns[${index}].blocks`, { ...place, column: true, width, depth: place.depth + 1 }, walk)\n })\n}\n\nfunction checkSection(section: Section, at: string, place: Place, walk: Walk): void {\n if (section.border !== undefined) {\n if (!(section.border.thickness > 0 && Number.isFinite(section.border.thickness)))\n throw new RenderRefusal('unsupported', `${at} has a border ${section.border.thickness} pt thick`, at)\n checkColor(section.border.color, at)\n }\n checkColor(section.fill, at)\n if (section.padding !== undefined && !(section.padding >= 0 && Number.isFinite(section.padding)))\n throw new RenderRefusal('unsupported', `${at} has a padding of ${section.padding} pt`, at)\n const frame = frameOf(section)\n const width = place.width - 2 * frame\n if (width <= 0) throw new RenderRefusal('content-too-large', `${at}'s border and padding leave its blocks no width`, at)\n // Its border and padding above and below, on every page it reaches: taller than the body, they leave its blocks no height.\n if (frame > 0) tall(walk, place, 2 * frame, `the border and padding of ${at}`, at)\n checkBlocks(section.blocks, `${at}.blocks`, { ...place, width, inset: place.inset + 2 * frame, depth: place.depth + 1 }, walk)\n}\n\n/**\n * Refuses what the body cannot hold once its height is known: a block of\n * fixed height, or a line, taller than a page's body less the frames around\n * it. pdfmake would draw it past the foot of the page, or not at all.\n */\nexport function refuseTall(tall: readonly Tall[], bodyHeight: number): void {\n for (const each of tall) {\n if (each.height > bodyHeight - each.inset) {\n throw new RenderRefusal(\n 'content-too-large',\n `${each.what} is ${each.height.toFixed(2)} pt tall; the body is ${(bodyHeight - each.inset).toFixed(2)} pt where it stands`,\n each.subject,\n )\n }\n }\n}\n","import { FACTUR_X } from '@formancy/report-runtime'\nimport type { FacturXFile } from '@formancy/report-runtime'\n\n/**\n * An e-invoice drawn as what it is (0031, extending 0027): a PDF/A-3b that\n * embeds the XML the runtime wrote, as `factur-x.xml`, and says so in its\n * XMP. pdfmake takes the PDF/A part of it as two options of the definition\n * (`PDF_A_3B`), and PDFKit writes the rest -- the pdfaid identification,\n * the sRGB output intent and its ICC profile -- as it ends the document.\n * The file and the fx properties have no key in pdfmake's definition, so\n * they are added to PDFKit's document between layout and `end`, the one\n * hook the engines take (`Engine.run`'s `finish`), on the final pass alone.\n *\n * A final render a host asks for as `pdfa: '2b'` is a PDF/A-2b (0057),\n * the archival PDF of a report that is no e-invoice: the same version, its\n * own subset, `PDF_A_2B`, and no hook, so that it embeds no file and its\n * XMP is PDFKit's alone. Which a document is drawn as, if either, is\n * `checkPdfA`'s (`pdfa-check.ts`), and every other report is drawn as it\n * always was.\n *\n * The renderer decides none of what the file says. The XML is the\n * runtime's, encoded as UTF-8 and changed in nothing; its name, its\n * relationship and the conformance level are the document's, held to\n * report-spec's by `checkEInvoice`; the fx namespace, prefix, document type\n * and version are report-spec's `FACTUR_X`. Only the words that describe\n * the four properties in the extension schema are the renderer's own:\n * PDF/A asks that an extension schema describe each property it declares,\n * and no specification's wording is copied for it.\n */\n\n/**\n * pdfmake's options for a PDF/A-3b. Level b is the one within reach: level\n * a needs a structure tree, which pdfmake does not build, and PDFKit has\n * no level u (pdfkit.js 5320-5332). The version must be given, or PDFKit writes a PDF 1.3\n * with no XMP and says nothing (pdfkit.js 6070; `pdfmake.test.ts`).\n */\nexport const PDF_A_3B = { version: '1.7', subset: 'PDF/A-3b' } as const\n\n/** pdfmake's options for a PDF/A-2b: level b for the reason `PDF_A_3B` gives, and the version for the same reason, without which PDFKit writes no XMP at all. */\nexport const PDF_A_2B = { version: '1.7', subset: 'PDF/A-2b' } as const\n\n/** What a document is drawn as when it is a PDF/A (`checkPdfA`): an e-invoice's PDF/A-3b with the Factur-X file it embeds, or the PDF/A-2b a host asked for, which embeds none. */\nexport type PdfA = { readonly subset: 'PDF/A-3b'; readonly file: FacturXFile } | { readonly subset: 'PDF/A-2b' }\n\n/** The definition's version and subset for `pdfa`. */\nexport function pdfaOptions(pdfa: PdfA): typeof PDF_A_3B | typeof PDF_A_2B {\n return pdfa.subset === 'PDF/A-3b' ? PDF_A_3B : PDF_A_2B\n}\n\n/** What `file` takes in PDFKit 0.19.1 (pdfkit.js 5160-5244): `relationship` among it, which @types/pdfkit 0.17.6 leaves out (`pdfmake.test.ts` pins it). */\nexport interface PdfKitFileOptions {\n readonly name: string\n /** The media type, written as the stream's /Subtype. */\n readonly type: string\n readonly description: string\n /** Written as the file specification's /AFRelationship. */\n readonly relationship: string\n readonly creationDate: Date\n readonly modifiedDate: Date\n}\n\n/**\n * PDFKit's document as pdfmake's `getStream` hands it over in either build,\n * laid out and not yet ended: the two of its methods an e-invoice adds\n * through, typed here at the boundary rather than through @types/pdfkit,\n * whose `file` options lack the relationship.\n */\nexport interface PdfKitDocument {\n /** `src` an ArrayBuffer: a typed array that is not a Node Buffer falls through to `fs.readFileSync(src)` (pdfkit.js 5172-5184). */\n file(src: ArrayBuffer, options: PdfKitFileOptions): unknown\n appendXML(xml: string): unknown\n}\n\n/** What acts on PDFKit's document between layout and `end`: the final pass's alone. */\nexport type Finish = (document: PdfKitDocument) => void\n\n/**\n * The hook that makes the final pass's PDF the e-invoice: `file` embedded,\n * dated `created`, the document's own creation date -- so that the same\n * document renders to the same bytes, and no file system's clock reaches\n * the PDF: PDFKit dates a file it reads from a path by `fs.statSync`, and\n * one it is handed by nothing but these options (pdfkit.js 5184-5200) --\n * and the fx properties appended to the XMP.\n */\nexport function embedEInvoice(file: FacturXFile, created: Date): Finish {\n const xml = exactBuffer(new TextEncoder().encode(file.xml))\n const description = `E-invoice XML, ${file.conformanceLevel}`\n return (document) => {\n document.file(xml, {\n name: file.fileName,\n type: FACTUR_X.mediaType,\n description,\n relationship: file.relationship,\n creationDate: created,\n modifiedDate: created,\n })\n document.appendXML(facturXmp(file))\n }\n}\n\n/** The ArrayBuffer of exactly `bytes`: an encoder's view may sit in a larger buffer, all of which PDFKit would embed. */\nfunction exactBuffer(bytes: Uint8Array): ArrayBuffer {\n return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer\n}\n\n/**\n * The extension schemas' own namespaces: the container's as veraPDF's rule\n * 6.6.2.3.3-1 names it, and the schema's and the property's as akretion's\n * factur-x and PDFlib's sample extension schema write them [S], which\n * veraPDF 1.30.3's 6.6.2.3.3 rules pass (0031; report-corpus's\n * `XMP_NAMESPACES` says the same).\n */\nconst PDFA_EXTENSION = 'http://www.aiim.org/pdfa/ns/extension/'\nconst PDFA_SCHEMA = 'http://www.aiim.org/pdfa/ns/schema#'\nconst PDFA_PROPERTY = 'http://www.aiim.org/pdfa/ns/property#'\n\n/**\n * The extension schema's name, as the Factur-X specification gives it in\n * its section 6.3.1 [S], as 0031 gives it: a name, the one item here not a value, and\n * one no validator in the gate reads.\n */\nconst SCHEMA_NAME = 'Factur-X PDFA Extension Schema'\n\n/** The four fx properties, each with its description: the renderer's own words, a Text of the external category, as PDF/A has an extension schema declare a property (6.6.2.3.3). */\nconst PROPERTIES = [\n ['DocumentFileName', 'The name under which this PDF embeds the invoice as XML'],\n ['DocumentType', 'What kind of business document the embedded XML is'],\n ['Version', 'The version of the hybrid format this PDF and its XML follow'],\n ['ConformanceLevel', 'The profile the embedded XML conforms to'],\n] as const\n\n/** Text as XML writes it between tags and in a double-quoted attribute. Every value here is report-spec's or checked against it, and is escaped all the same. */\nconst escaped = (text: string): string => text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"')\n\n/**\n * The fx description and the extension schema that declares its four\n * properties, as two `rdf:Description`s PDFKit puts into the packet before\n * its own (pdfkit.js 6011-6013). Without the schema, veraPDF fails the\n * properties (6.6.2.3.1-1, -2).\n */\nfunction facturXmp(file: FacturXFile): string {\n const fx = FACTUR_X.xmpPrefix\n const values: Readonly<Record<(typeof PROPERTIES)[number][0], string>> = {\n DocumentFileName: file.fileName,\n DocumentType: FACTUR_X.documentType,\n Version: FACTUR_X.version,\n ConformanceLevel: file.conformanceLevel,\n }\n const property = ([name, description]: (typeof PROPERTIES)[number]): string =>\n `<rdf:li rdf:parseType=\"Resource\"><pdfaProperty:name>${name}</pdfaProperty:name><pdfaProperty:valueType>Text</pdfaProperty:valueType><pdfaProperty:category>external</pdfaProperty:category><pdfaProperty:description>${escaped(description)}</pdfaProperty:description></rdf:li>`\n return [\n `<rdf:Description rdf:about=\"\" xmlns:${fx}=\"${escaped(FACTUR_X.xmpNamespace)}\">`,\n ...PROPERTIES.map(([name]) => `<${fx}:${name}>${escaped(values[name])}</${fx}:${name}>`),\n '</rdf:Description>',\n `<rdf:Description rdf:about=\"\" xmlns:pdfaExtension=\"${PDFA_EXTENSION}\" xmlns:pdfaSchema=\"${PDFA_SCHEMA}\" xmlns:pdfaProperty=\"${PDFA_PROPERTY}\">`,\n '<pdfaExtension:schemas><rdf:Bag><rdf:li rdf:parseType=\"Resource\">',\n `<pdfaSchema:schema>${SCHEMA_NAME}</pdfaSchema:schema>`,\n `<pdfaSchema:namespaceURI>${escaped(FACTUR_X.xmpNamespace)}</pdfaSchema:namespaceURI>`,\n `<pdfaSchema:prefix>${fx}</pdfaSchema:prefix>`,\n `<pdfaSchema:property><rdf:Seq>${PROPERTIES.map(property).join('')}</rdf:Seq></pdfaSchema:property>`,\n '</rdf:li></rdf:Bag></pdfaExtension:schemas>',\n '</rdf:Description>',\n ].join('\\n')\n}\n","import type { Content, ContentCanvas, ContentStack, ContentSvg, ContentText } from 'pdfmake/interfaces.js'\nimport {\n QR_BILL_SIZE,\n SLIP_ACCEPTANCE as ACCEPTANCE,\n SLIP_CODE as CODE,\n SLIP_CORNER as CORNER,\n SLIP_FIELD_GAP as FIELD_GAP,\n SLIP_INSTRUCTION as INSTRUCTION,\n SLIP_PAYMENT_PART,\n SLIP_RECEIPT,\n SLIP_RECEIPT_WIDTH as RECEIPT_WIDTH,\n SLIP_SEPARATION as SEPARATION,\n SLIP_TITLE as TITLE,\n slipBlocks as blocks,\n type QrBill,\n type SlipPart as Part,\n} from '@formancy/report-runtime'\nimport type { CheckedBill } from './bill.js'\nimport { swissCodeContent } from './qr.js'\nimport { LIBERATION_ASCENDER, LIBERATION_LINE, LIBERATION_SANS } from './style.js'\n\n/**\n * A QR-bill's slip, the receipt and the payment part, as pdfmake content:\n * where SIX puts each heading, value, field, line and the code, and at what\n * size, in Liberation Sans. Nothing here formats a value: the runtime hands\n * every text as it prints (report-runtime's `QrBill`).\n *\n * Where each part stands and at what size is SIX's, stated once below\n * every engine (report-runtime's `slip-print.ts`, 0075), which the Word\n * writer lays its slip out by too. What is the renderer's own is how it is\n * drawn: pdfmake's content, the scissors, and the face's own line.\n *\n * Positions are in points from the slip's top left. The slip is\n * report-spec's `QR_BILL_SIZE`, 210 by 105 mm, and stands at its\n * `QR_BILL_TOP`, spanning the paper's width and ending at its foot (IG\n * 3.1): the size and the place the editor draws its band at and refuses a\n * page by, decided there once. The layout draws it as the last page's\n * footer (`definition.ts`), each part placed on its own.\n */\n\n/** Millimetres in points. */\nconst mm = (value: number): number => (value * 72) / 25.4\n\n/** How far above the slip its drawing starts: the top of the instruction's line. The body ends above it. */\nexport const ABOVE_SLIP = INSTRUCTION.gap + LIBERATION_ASCENDER * INSTRUCTION.size\n\n/**\n * The scissors symbol on the line between the receipt and the payment\n * part. IG 3.7 asks that each line \"bear the scissors symbol or\n * alternatively the instruction ... above the line (outside the payment\n * part)\": the line across the paper has the instruction above it, and a\n * line down the slip has no \"above\" outside the payment part, so it bears\n * the symbol. SIX gives it no size or place. It is manuelbl's generator's\n * (`BillLayout.drawBorder`, read on 17 October 2026): 3 mm tall, on the\n * line from 5 mm below the slip's top, the line broken where it stands.\n * 2.5 mm wide, so that it keeps to the 5 mm left unprinted on either side\n * of the line (SG 6). Drawn here, since Liberation Sans has no glyph for\n * U+2702, and the same in every language. In millimetres.\n */\nconst SCISSORS = { top: 5, width: 2.5, height: 3 }\n\n/** The receipt and the payment part, as the runtime states them. */\nexport const RECEIPT = SLIP_RECEIPT\nexport const PAYMENT_PART = SLIP_PAYMENT_PART\n\nconst ascender = (size: number): number => LIBERATION_ASCENDER * size\n\n/** A circle about `x`, `y` of radius `r`, as an SVG path of four quarters, each ending at one of its extremes. */\nfunction circle(x: number, y: number, r: number): string {\n const k = 0.5523 * r\n return `M${x + r} ${y}C${x + r} ${y + k} ${x + k} ${y + r} ${x} ${y + r}C${x - k} ${y + r} ${x - r} ${y + k} ${x - r} ${y}C${x - r} ${y - k} ${x - k} ${y - r} ${x} ${y - r}C${x + k} ${y - r} ${x + r} ${y - k} ${x + r} ${y}Z`\n}\n\n/**\n * The scissors, open, their points down the line they cut along, drawn in\n * tenths of a millimetre across `SCISSORS`. A ring either side of the line\n * at the top, 1.2 mm across and 0.2 mm thick, each touching the symbol's\n * side, filled with its hole left out; and from each ring a blade, a wedge\n * from the ring's side towards the line to a point 0.45 mm past it at the\n * symbol's foot, the two crossing on the line. Drawn here after the symbol\n * IG 3.7 prints, none of it taken from another generator's drawing.\n */\nfunction scissorsContent(): ContentSvg {\n const [across, tall] = [SCISSORS.width * 10, SCISSORS.height * 10]\n const [line, ring, hole, past] = [across / 2, 6, 4, 4.5]\n const sides = [-1, 1].map((sign) => {\n const centre = line + sign * (line - ring)\n const toward = (degrees: number): string => {\n const radians = (degrees * Math.PI) / 180\n return `${(centre - sign * ring * Math.cos(radians)).toFixed(3)} ${(ring + ring * Math.sin(radians)).toFixed(3)}`\n }\n return { rings: `${circle(centre, ring, ring)}${circle(centre, ring, hole)}`, blade: `M${toward(30)}L${toward(75)}L${line - sign * past} ${tall}Z` }\n })\n const [width, height] = [mm(SCISSORS.width), mm(SCISSORS.height)]\n const blades = sides.map(({ blade }) => `<path d=\"${blade}\" fill=\"#000000\"/>`).join('')\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${width}\" height=\"${height}\" viewBox=\"0 0 ${across} ${tall}\"><path d=\"${sides.map(({ rings }) => rings).join('')}\" fill=\"#000000\" fill-rule=\"evenodd\"/>${blades}</svg>`\n return { svg, width, height }\n}\n\n/** One line of text in Liberation Sans, `lineHeight` times its line tall. */\nfunction line(text: string, size: number, bold: boolean, lineHeight = 1): ContentText {\n return { text, font: LIBERATION_SANS, fontSize: size, bold, lineHeight }\n}\n\n/** A blank field's four corners, each two arms of a polyline, stroked inside the box `width` by `height` from the canvas's corner. */\nfunction corners(width: number, height: number): ContentCanvas['canvas'] {\n const [inset, arm] = [CORNER.weight / 2, CORNER.arm]\n const corner = (points: readonly (readonly [number, number])[]): ContentCanvas['canvas'][number] => ({\n type: 'polyline',\n points: points.map(([x, y]) => ({ x, y })),\n lineWidth: CORNER.weight,\n lineColor: '#000000',\n })\n const [left, top, right, bottom] = [inset, inset, width - inset, height - inset]\n return [\n corner([\n [left, arm],\n [left, top],\n [arm, top],\n ]),\n corner([\n [width - arm, top],\n [right, top],\n [right, arm],\n ]),\n corner([\n [right, height - arm],\n [right, bottom],\n [width - arm, bottom],\n ]),\n corner([\n [arm, bottom],\n [left, bottom],\n [left, height - arm],\n ]),\n ]\n}\n\n/**\n * A part's information, as one stack laid out from its section's top: the\n * first heading's line at the top, every line's baseline `pitch` below the\n * one before, and a blank line between blocks (SG 15). pdfmake sets each\n * baseline its ascender below its line's top, so a heading's line is made\n * shorter than the pitch by what a value's ascender is longer, and the\n * space before a heading longer by as much.\n */\nexport function informationContent(bill: QrBill, part: Part): Content[] {\n const { heading, value, pitch } = part.lettering\n const shift = ascender(value) - ascender(heading)\n return blocks(bill, part).flatMap((block, index): Content[] => {\n const title: ContentText = {\n ...line(block.heading, heading, true, (pitch - shift) / (LIBERATION_LINE * heading)),\n margin: [0, index === 0 ? 0 : pitch + shift, 0, 0],\n }\n if ('field' in block) return [title, { canvas: corners(block.field.width, block.field.height), margin: [0, FIELD_GAP, 0, CORNER.weight / 2] }]\n return [title, ...block.values.map((text) => line(text, value, false, pitch / (LIBERATION_LINE * value)))]\n })\n}\n\n/** `content` placed with its top left at `x`, `y` on the page, measured from the footer's top, `origin`, where pdfmake lays the footer out. */\nfunction at(content: ContentText | ContentStack | ContentCanvas | ContentSvg, x: number, y: number, origin: number): Content {\n return { ...content, absolutePosition: { x, y: y - origin } }\n}\n\n/** `content` laid out `width` wide where it is placed, on a page `paperWidth` wide. */\nfunction within(content: Content[], x: number, width: number, paperWidth: number): ContentStack {\n return { stack: [{ stack: content, margin: [0, 0, paperWidth - x - width, 0] }] }\n}\n\n/** A part's title, its amount section and its information, each placed on the page whose slip starts at `top`. */\nfunction partContent(bill: QrBill, part: Part, top: number, origin: number, paperWidth: number): Content[] {\n const { heading, value } = part.lettering\n const { amount } = part\n const headingTop = top + amount.top\n const amountTop = headingTop + ascender(heading) + amount.pitch - ascender(value)\n const field = part.amountField\n return [\n at(line(bill.headings[part.title.heading], TITLE, true), part.title.x, top + part.title.top, origin),\n at(line(bill.headings.currency, heading, true), amount.x, headingTop, origin),\n at(line(bill.currency, value, false), amount.x, amountTop, origin),\n at(line(bill.headings.amount, heading, true), amount.x + amount.indent, headingTop, origin),\n bill.amount === null\n ? at({ canvas: corners(field.width, field.height) }, field.x, field.onAmountLine ? amountTop : headingTop, origin)\n : at(line(bill.amount, value, false), amount.x + amount.indent, amountTop, origin),\n at(within(informationContent(bill, part), part.information.x, part.information.width, paperWidth), part.information.x, top + part.information.top, origin),\n ]\n}\n\n/**\n * The slip, as the last page's footer lays it out, its top `top` points\n * down a page `paperWidth` wide: the lines it is cut along, the\n * instruction above the one across and the scissors on the one down, the\n * receipt with its acceptance point, and the payment part with its code.\n * Made anew for each layout, since pdfmake writes its positions into the\n * content it lays out.\n */\nexport function slipContent({ bill, symbol }: CheckedBill, top: number, origin: number, paperWidth: number): Content[] {\n const down = (from: number, to: number): ContentCanvas['canvas'][number] => ({\n type: 'line',\n x1: RECEIPT_WIDTH,\n y1: from,\n x2: RECEIPT_WIDTH,\n y2: to,\n lineWidth: SEPARATION,\n lineColor: '#000000',\n })\n const separation: ContentCanvas = {\n canvas: [\n { type: 'line', x1: 0, y1: 0, x2: QR_BILL_SIZE.width, y2: 0, lineWidth: SEPARATION, lineColor: '#000000' },\n down(0, mm(SCISSORS.top)),\n down(mm(SCISSORS.top + SCISSORS.height), QR_BILL_SIZE.height),\n ],\n }\n const instruction: ContentText = { ...line(bill.headings.separate, INSTRUCTION.size, false), alignment: 'center' }\n const acceptance: ContentText = { ...line(bill.headings.acceptancePoint, RECEIPT.lettering.heading, true), alignment: 'right' }\n return [\n at(instruction, 0, top - ABOVE_SLIP, origin),\n at(separation, 0, top, origin),\n at(scissorsContent(), RECEIPT_WIDTH - mm(SCISSORS.width / 2), top + mm(SCISSORS.top), origin),\n ...partContent(bill, RECEIPT, top, origin, paperWidth),\n at(within([acceptance], RECEIPT.information.x, ACCEPTANCE.right - RECEIPT.information.x, paperWidth), RECEIPT.information.x, top + ACCEPTANCE.top, origin),\n ...partContent(bill, PAYMENT_PART, top, origin, paperWidth),\n at(swissCodeContent(symbol), CODE.x, top + CODE.top, origin),\n ]\n}\n","import type { Content, DynamicContent, TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport { QR_BILL_TOP, RenderRefusal, type Block, type ResolvedDocument, type Table } from '@formancy/report-runtime'\nimport type { CheckedBill } from './bill.js'\nimport { newBuild, type Build, type Fields, type TablePlan } from './build.js'\nimport type { Checked, Page } from './check.js'\nimport type { Measured } from './check-walk.js'\nimport { contentOf } from './content.js'\nimport { pdfaOptions } from './pdfa.js'\nimport { ABOVE_SLIP, slipContent } from './slip.js'\nimport type { RenderFonts } from './host-fonts.js'\nimport { DEFAULT_SIZE } from './style.js'\nimport { checkShifted } from './shifted.js'\nimport { checkWords } from './words.js'\n\n/**\n * The pdfmake document definitions a render hands pdfmake, built from the\n * resolved document and what was measured: pure, the same in Node and in a\n * browser, and the one place either entry's definitions come from. What\n * runs them is the entry's own (`node.ts`, `browser-engine.ts`).\n *\n * The page regions: pdfmake draws its header inside the top page margin and\n * its footer inside the bottom one, and lays the body out between. So\n * pdfmake's margins are the document's enlarged by each region's measured\n * height and a 6pt gap, and each region is drawn at the document's own\n * margin: the header from the top of the printable area down, the footer\n * ending at its bottom. Nothing of the body can reach into either.\n *\n * Page 1's own header (0060): the header's box is the top margin, one for\n * every page, so a header of page 1's own taller than the page header could\n * not be drawn there whole, nor given room there without taking it from\n * every later page. It is drawn in page 1's background, which pdfmake lays\n * out in a box as large as the page, at the document's own margin, where\n * the page header would stand; the page header's function draws nothing on\n * page 1; and page 1's body is moved by the difference between the two\n * headers' rooms, an empty node with that top margin at its head, down or\n * up (`pdfmake.test.ts` holds all three).\n */\n\n/** The document's default text style: the font token-less text prints in -- the mapped `sans` host family, or Roboto -- at the default size (0043). */\nexport function defaultStyle(fonts: RenderFonts): { readonly font: string; readonly fontSize: number } {\n return { font: fonts.defaultFamily, fontSize: DEFAULT_SIZE }\n}\n\n/** Between the page header and the body, and between the body and the page footer. */\nexport const REGION_GAP = 6\n\n/** Space each page region takes from the printable area, its gap to the body included; nothing for a region with no blocks. */\nexport interface Regions {\n readonly header: number\n readonly footer: number\n /** What page 1's header takes: its own where the document has one (0060), nothing for its none, and `header` where page 1 prints the page header. */\n readonly first: number\n}\n\n/** The document as the checks read it, its charts drawn (`drawCharts`): what the body's builds are made from, the PDF's among them. */\nexport type Drawn = Omit<Checked, 'charts'> & { readonly charts: Build['charts'] }\n\n/** The drawn charts of a build made before the charts are drawn: none, since a chart stands in the body alone. */\nconst UNDRAWN: Build['charts'] = new Map()\n\n/** What a measuring pass lays out: one item per thing measured, and the build that holds their images and marks. */\nexport interface Measurement {\n readonly items: readonly Content[]\n readonly build: Build\n}\n\n/**\n * The page header and footer that have blocks, each one item, with every\n * page field printed as the page limit: as many digits as the field can\n * have. A region that wraps only for some page numbers is measured at its\n * widest, which is not the same thing, and is not refused.\n */\nexport function regionsMeasurement(\n document: ResolvedDocument,\n checked: Checked,\n fonts: RenderFonts,\n maxPages: number,\n): Measurement & { readonly present: readonly (readonly Block[])[] } {\n const fields: Fields = { pageNumber: maxPages, pageCount: maxPages }\n const present = [document.pageHeader, document.pageFooter].filter((blocks) => blocks.length > 0)\n // The page regions hold no chart: check.ts refuses one there.\n const build = newBuild('measure', { ...checked, charts: UNDRAWN }, fonts)\n return { present, build, items: present.map((blocks): Content => ({ stack: contentOf(blocks, build, checked.page.width, { fields }) })) }\n}\n\n/** Page 1's own header (0060), one item, laid out as page 1's background lays it out: a page region with no page field. */\nexport function firstPageHeaderMeasurement(blocks: readonly Block[], checked: Checked, fonts: RenderFonts): Measurement {\n // Page 1's own header holds no chart, as the page regions hold none: check.ts refuses one there.\n const build = newBuild('measure', { ...checked, charts: UNDRAWN }, fonts)\n return { build, items: [{ stack: contentOf(blocks, build, checked.page.width, {}) }] }\n}\n\n/** The body's tables and keep-together blocks, each one item laid out at the width it stands at. */\nexport function bodyMeasurement(measured: readonly Measured[], checked: Drawn, fonts: RenderFonts): Measurement {\n const build = newBuild('measure', checked, fonts)\n const items = measured.map(({ block, width }): Content => ({ stack: contentOf([block], build, width), margin: [0, 0, checked.page.width - width, 0] }))\n return { items, build }\n}\n\n/** Where the body starts and ends on every page, from the top of the paper: inside the margins and below and above the page regions; page 1's body starts `first - header` lower (0060). */\nexport function bodyBounds(page: Page, regions: Regions): { readonly top: number; readonly bottom: number } {\n return { top: page.margins.top + regions.header, bottom: page.paperHeight - page.margins.bottom - regions.footer }\n}\n\n/**\n * How much of the last page's body a QR-bill's slip takes: from where its\n * drawing starts, the instruction above it, to the body's foot. Nothing if\n * the body ends above the slip on every page.\n */\nexport function slipReservation(page: Page, regions: Regions): number {\n return Math.max(0, bodyBounds(page, regions).bottom - (QR_BILL_TOP - ABOVE_SLIP))\n}\n\n/**\n * The PDF's definition. pdfmake's own page limit, `maxPagesNumber`, cuts the\n * document short; the renderer's throws out of the layout instead, from the\n * function pdfmake calls for each page's background, as the page after the\n * last one allowed is added. So no more than one page past the limit is ever\n * laid out, and nothing is written.\n *\n * A QR-bill's slip is the last page's footer, in place of the page footer:\n * pdfmake lays the footer out once every page is, knowing their count, and\n * gives what is placed above the footer's top the room down to the paper's\n * foot (`pdfmake.test.ts` holds both). The body keeps the slip's room at\n * its end, a spacer as tall as `slipReservation`: where the last page has\n * less room left, pdfmake moves to a new page and starts it without the\n * space, and the slip has that page to itself.\n *\n * A document drawn as a PDF/A -- an e-invoice's PDF/A-3b, or the PDF/A-2b\n * a host asked for (`pdfa-check.ts`) -- has its version and subset in the\n * definition (`pdfaOptions`); a PDF/A-3b's file and XMP are the final\n * pass's hook (`render.ts`), and a PDF/A-2b has none. Neither moves a\n * line: the measuring passes, which have neither, lay the page out as this\n * one does.\n */\nexport function layoutDefinition(\n document: ResolvedDocument,\n checked: Drawn,\n regions: Regions,\n plans: ReadonlyMap<Table, TablePlan>,\n fonts: RenderFonts,\n maxPages: number,\n bill?: CheckedBill,\n): TDocumentDefinitions {\n const page: Page = checked.page\n const { margins } = page\n const { top: bodyTop, bottom: bodyBottom } = bodyBounds(page, regions)\n const firstShift = regions.first - regions.header\n const build = newBuild('render', checked, fonts, { top: bodyTop, bottom: bodyBottom, firstShift }, plans)\n /** A page region's content, built anew for each page pdfmake draws it on, which changes what it lays out. */\n const region = (blocks: readonly Block[], margin: [number, number, number, number]): ((fields?: Fields) => Content) | undefined => {\n if (blocks.length === 0) return undefined\n return (fields) => ({ stack: contentOf(blocks, build, page.width, fields === undefined ? {} : { fields }), margin })\n }\n const pageHeader = region(document.pageHeader, [margins.left, margins.top, margins.right, 0])\n const pageFooter = region(document.pageFooter, [margins.left, REGION_GAP, margins.right, 0])\n const own = document.firstPageHeader\n const firstPage = own === undefined ? undefined : region(own, [margins.left, margins.top, margins.right, 0])\n const header: DynamicContent | undefined =\n pageHeader === undefined ? undefined : (pageNumber, pageCount) => (own !== undefined && pageNumber === 1 ? null : pageHeader({ pageNumber, pageCount }))\n const footer: DynamicContent | undefined = pageFooter === undefined ? undefined : (pageNumber, pageCount) => pageFooter({ pageNumber, pageCount })\n // Once now, so that their images are in the dictionary before pdfmake reads it.\n pageHeader?.({ pageNumber: 1, pageCount: 1 })\n pageFooter?.({ pageNumber: 1, pageCount: 1 })\n firstPage?.()\n // pdfmake lays the footer out from the body's foot, so the slip's parts are placed from there.\n const slip = bill === undefined ? undefined : (): Content => ({ stack: slipContent(bill, QR_BILL_TOP, bodyBottom, page.paperWidth) })\n const last: DynamicContent | undefined =\n slip === undefined ? footer : (pageNumber, pageCount, size) => (pageNumber === pageCount ? slip() : footer?.(pageNumber, pageCount, size))\n const reserved = bill === undefined ? [] : [{ stack: [], margin: [0, slipReservation(page, regions), 0, 0] } satisfies Content]\n // Page 1's body moved to start below the header page 1 prints, where that is not the page header (0060).\n const shifted = firstShift === 0 ? [] : [{ stack: [], margin: [0, firstShift, 0, 0] } satisfies Content]\n return {\n ...(checked.pdfa === undefined ? {} : pdfaOptions(checked.pdfa)),\n info: { title: document.info.title, creationDate: checked.creationDate },\n pageSize: { width: page.paperWidth, height: page.paperHeight },\n pageMargins: [margins.left, bodyTop, margins.right, page.paperHeight - bodyBottom],\n defaultStyle: defaultStyle(fonts),\n content: [...shifted, ...contentOf(document.body, build, page.width), ...reserved],\n images: build.images,\n ...(header === undefined ? {} : { header }),\n ...(last === undefined ? {} : { footer: last }),\n background: (number) => {\n // pdfmake has measured every word, and laid out no line yet.\n if (number === 1) {\n checkWords(build.words)\n checkShifted(build.shifted)\n }\n if (number > maxPages) throw new RenderRefusal('too-many-pages', `the report needs more than ${maxPages} pages`)\n // Page 1's own header, in a box as large as the page; its words were held to their room when it was measured.\n return number === 1 && firstPage !== undefined ? firstPage() : null\n },\n pageBreakBefore: (node, queries) => {\n const rule = node.headlineLevel === undefined ? undefined : build.rules.get(node.headlineLevel)\n return rule?.(node, queries) ?? false\n },\n }\n}\n","/**\n * How PDFKit tells one face of a render from another, and the host faces\n * the renderer refuses because it would not (0043).\n *\n * PDFKit 0.19.1 keeps a document's fonts in a plain object keyed by the\n * PostScript name fontkit reads (`font()`, pdfkit.js 2826-2869), and\n * pdfmake opens every face it reads from bytes through it with no key of\n * its own (`PDFDocument.provideFont`): each host face, and in a browser\n * Roboto and Liberation Sans as well. Three things follow.\n *\n * - **Two faces of one name are drawn as one.** A face whose PostScript\n * name, `head.checkSumAdjustment` and naming table are those of a face\n * already open is drawn as that face (`isEqualFont`, pdfkit.js 2803),\n * whichever pdfmake opened first: its glyphs, its line and its widths,\n * while check.ts and bound.ts measured each by its own. Nothing checks\n * the checksum, so a copy of a face's naming table and header field is\n * enough: a mono that was Roboto Regular with only its line changed\n * printed the Roboto text beside it at its own line, and a 96 pt line was\n * gone; a sans that was Liberation Sans with a 4 em line laid a QR-bill's\n * slip out in its own line, and 7 of the slip's runs were gone (review of\n * P07, 22 October 2026).\n * - **A face of bytes is looked up under `null` first**, and takes\n * whatever face is kept there, comparing nothing: a face whose PostScript\n * name is `null` was the face every face opened after it printed in.\n * - **A name `Object.prototype` holds is a font already.** Looked up under\n * `constructor`, `toString` or `__proto__`, PDFKit finds a function, and\n * throws a TypeError naming nothing.\n *\n * So a host face is refused as `invalid-asset`, in numbers and its id\n * alone, where one of its PostScript names is `null` or a name of\n * `Object.prototype`, or is the name of another face of the render with\n * other bytes: another host asset, or one of the renderer's own six faces,\n * whether or not the document prints in it. Every name its records of name\n * ID 6 hold is read, report-spec's `postScriptNames`, since which of them\n * fontkit returns depends on their order and languages. That refuses more\n * than PDFKit merges -- a face of another checksum or naming table would\n * print as itself -- and fails closed. Faces of the same bytes are allowed:\n * two host assets of one font are stripped alike and drawn as one, which\n * they are, and a host face of the renderer's own bytes is embedded as the\n * renderer embeds that face, its layout tables kept, so that what PDFKit\n * draws is the same whichever copy it opened first. Its bytes are known by\n * their digest, taken here from the bytes, never from the asset's word.\n */\nimport { assetDigest, RenderRefusal, type FontAsset } from '@formancy/report-runtime'\n\n/** One of the renderer's own faces: what a refusal calls it, the PostScript name fontkit reads in it, and its bytes' digest. `fonts.test.ts` holds each to the file pdfmake or this package ships. */\nexport interface OwnFace {\n readonly name: string\n readonly postScriptName: string\n readonly digest: string\n}\n\n/** Roboto 3.014's four faces, from pdfmake 0.3.11's package and its `vfs_fonts.js`, and Liberation Sans 2.1.5's two, from this package's `fonts`. */\nexport const OWN_FACES: readonly OwnFace[] = [\n { name: 'Roboto Regular', postScriptName: 'Roboto-Regular', digest: 'sha256:ab9c18a75da1636435afd2398ffce325496644a8f258f918c92c4baf34a68625' },\n { name: 'Roboto Medium', postScriptName: 'Roboto-Medium', digest: 'sha256:4cb9d8a346d7d9190ef145daad9a85d58e2592043b199cdb8ed52ff535c64047' },\n { name: 'Roboto Italic', postScriptName: 'Roboto-Italic', digest: 'sha256:b9e7d02d28dd215bd1dbb164d2d75bc1bbccf754a17390efc8678feb78017577' },\n { name: 'Roboto Medium Italic', postScriptName: 'Roboto-MediumItalic', digest: 'sha256:1b4daee5311f0bcd8e1b79d44d1d5ba675a72abb6624d2b0ed77fda1c65d77b1' },\n { name: 'Liberation Sans Regular', postScriptName: 'LiberationSans', digest: 'sha256:76d04c18ea243f426b7de1f3ad208e927008f961dc5945e5aad352d0dfde8ee8' },\n { name: 'Liberation Sans Bold', postScriptName: 'LiberationSans-Bold', digest: 'sha256:788abee4c806d660e8aee46689dd8540cd4bb98da03dcc9d171ce3efd99a9173' },\n]\n\n/** A host face as the plan read it: its asset, and every PostScript name it states. */\nexport interface HostFace {\n readonly asset: FontAsset\n readonly postScriptNames: readonly string[]\n}\n\n/** The key PDFKit looks a face opened from bytes up by before its name: `null`, as a property name. */\nconst UNKEYED = 'null'\n\n/**\n * What PDFKit draws `face` as, beside `others`, the host faces this render\n * read before it: the renderer's own face whose bytes it has, which the\n * engine embeds as the renderer embeds that face, or undefined for a face\n * PDFKit draws as itself. A face PDFKit could draw as another, or fail on,\n * is refused.\n */\nexport function drawnAs(face: HostFace, others: readonly HostFace[]): OwnFace | undefined {\n const { id } = face.asset\n if (face.postScriptNames.some((name) => name === UNKEYED || name in Object.prototype)) {\n throw new RenderRefusal(\n 'invalid-asset',\n `the font asset ${id} has a PostScript name PDFKit keeps fonts under before it reads one, and would draw it as another face or fail on it`,\n id,\n )\n }\n let digest: string | undefined\n const digestOf = (): string => (digest ??= assetDigest(face.asset.bytes))\n const shares = (names: readonly string[]): boolean => names.some((name) => face.postScriptNames.includes(name))\n for (const other of others) {\n if (other.asset.id !== id && shares(other.postScriptNames) && assetDigest(other.asset.bytes) !== digestOf()) {\n throw new RenderRefusal(\n 'invalid-asset',\n `the font asset ${id} has a PostScript name of the font asset ${other.asset.id}, with other bytes: PDFKit draws two faces of one PostScript name as whichever it opened first`,\n id,\n )\n }\n }\n const own = OWN_FACES.find((each) => shares([each.postScriptName]))\n if (own === undefined) return undefined\n if (digestOf() !== own.digest) {\n throw new RenderRefusal(\n 'invalid-asset',\n `the font asset ${id} has the PostScript name of the renderer's own ${own.name}, with other bytes: PDFKit draws two faces of one PostScript name as whichever it opened first, and accepts only the renderer's own bytes under that name`,\n id,\n )\n }\n return own\n}\n","/**\n * A host face's layout tables, removed before the renderer embeds it\n * (0043), closing the risk 0040 left open.\n *\n * report-spec's `readFont` says whether a font may be embedded and which\n * characters it draws, but it does not read the layout tables fontkit runs\n * at print: GSUB, GPOS, kern and the AAT `morx` state machine. PDFKit lays\n * every run out with fontkit before it subsets, and a crafted one can make\n * that run never end -- a `morx` table of one state whose one entry does not\n * advance held a render's thread past twenty seconds on 22 October 2026\n * (0040), and a render pass cannot be interrupted (0011). So before a host\n * face is embedded, the records for the tables fontkit's layout reads are\n * removed from the font's table directory, by setting each one's recorded\n * length to zero: fontkit sees a table only where its recorded length is\n * not zero (`TTFFont`), so with them zeroed it builds no advanced layout\n * engine and runs no kern processor, and `font.layout` falls back to the\n * one-glyph-per-code-point mapping and unicode positioning, which is\n * bounded by the text's length.\n *\n * What it loses: ligatures, kerning, and the contextual and complex shaping\n * those tables drive -- exactly what the scripts this release refuses\n * (right-to-left, Indic, Thai, CJK) would need, and nothing the Latin,\n * Greek and Cyrillic text a host face prints does. PDFKit always subsets\n * from the outlines and never embeds a layout table, so the embedded font\n * is unchanged by the removal; only what fontkit does while measuring is.\n *\n * Nothing else is touched: the table data stays where it is, every other\n * record keeps its offset and length, and the count of tables is unchanged,\n * so the glyph outlines, the character map and the metrics the renderer and\n * fontkit read are exactly the font's own. A host face of the very bytes of\n * one of the renderer's own faces is not stripped: it is that face, which\n * fontkit lays out with its tables in every render, and PDFKit draws the two\n * as one (`face-identity.ts`).\n */\n\n/** The tables fontkit's layout engine reads, each the reason it would run: an advanced engine (OpenType or AAT), its mark and class data, or the kern processor. */\nexport const LAYOUT_TABLES: readonly string[] = ['GSUB', 'GPOS', 'GDEF', 'kern', 'morx']\n\n/** A table tag's four bytes, as the directory holds them. */\nfunction tagAt(bytes: Uint8Array, at: number): string {\n return String.fromCharCode(bytes[at]!, bytes[at + 1]!, bytes[at + 2]!, bytes[at + 3]!)\n}\n\n/**\n * `bytes` with the layout tables' directory records' lengths zeroed, so\n * fontkit sees none of them; a copy, leaving the font the report pinned\n * untouched. Returns the bytes unchanged when the file is too short to hold\n * a table directory -- `readFont` has already accepted it, so this only\n * guards the read, never judges the font.\n */\nexport function withoutLayoutTables(bytes: Uint8Array): Uint8Array {\n if (bytes.length < 12) return bytes\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n const tables = view.getUint16(4)\n if (bytes.length < 12 + 16 * tables) return bytes\n const stripped = Uint8Array.from(bytes)\n const out = new DataView(stripped.buffer)\n for (let index = 0; index < tables; index += 1) {\n const record = 12 + 16 * index\n if (LAYOUT_TABLES.includes(tagAt(stripped, record))) out.setUint32(record + 12, 0)\n }\n return stripped\n}\n","/**\n * How a document's font tokens become the faces the renderer embeds and\n * measures text in (0043).\n *\n * A report maps each of `sans`, `serif` and `mono` to the faces a host\n * approved, resolved by the runtime to their bytes (`ResolvedFonts`). Here\n * each face is read once more with report-spec's `readFont` -- the renderer\n * is a package boundary that refuses what it cannot draw (0011) -- refused\n * where PDFKit would draw it as another face (`face-identity.ts`), its\n * layout tables stripped so fontkit cannot hang a render\n * (`strip-layout.ts`) unless it is one of the renderer's own faces, and\n * the bytes go into pdfmake's virtual files under a name of this render's\n * own. The plan then answers, for any\n * token and weight and slant: the characters that face draws, the line\n * pdfmake lays it out by (its hhea, ascender less descender, over its\n * units, which report-spec's reader holds to `MIN_FONT_LINE` to\n * `MAX_FONT_LINE` ems) and its baseline in that line, the key a measurer\n * keeps its widths by -- the digest of the bytes it embeds, taken only for\n * a face a chart prints in -- and the pdfmake family a style names it by.\n *\n * A token a report does not map prints in the renderer's own face: `sans`\n * is Roboto, and `serif` and `mono` are refused, exactly as before a report\n * could name a host's font. Text with no token prints in the mapped `sans`\n * where there is one, else Roboto. A face a style asks for and the family\n * does not map is refused, never synthesised: pdfmake's faux bold and\n * oblique are a substitution nobody sees until the PDF is read (plan 20).\n *\n * Nothing outlives the render. Each plan reads the bytes it is handed, so\n * what a face prints is always the bytes this document carries, never a\n * face another render read under the same digest; and its virtual files\n * are named by the render, `formancy-report-render-pdf/font/<render>/<n>.ttf`,\n * so two renders at once never share one, and one that ends never takes\n * another's file from under it (`engine.ts` writes them for each pass and\n * deletes them after). Reading a face again costs a millisecond for a\n * typical font (0043).\n */\nimport {\n assetDigest,\n faceKey,\n type FontAsset,\n type FontFaceKey,\n type FontFamily,\n readFont,\n RenderRefusal,\n type ResolvedFaces,\n type ResolvedFonts,\n} from '@formancy/report-runtime'\nimport { drawnAs, type HostFace } from './face-identity.js'\nimport { type Face, faceOf, type Glyphs } from './glyphs.js'\nimport { withoutLayoutTables } from './strip-layout.js'\nimport { LINE_FACTOR, ROBOTO, ROBOTO_ASCENT, ROBOTO_DESCENT } from './style.js'\n\n/** What the renderer needs of one face to check, lay out and measure text: the characters it draws, the line pdfmake lays it out by, as a multiple of the font size, where its baseline stands, what a measurer knows it by, and what a refusal calls it. */\nexport interface RenderFace {\n readonly glyphs: ReadonlySet<number>\n readonly lineFactor: number\n /** Its ascender and its descender over its units per em, from the horizontal header its line is read from: the descender is negative, below the baseline, and the line their difference: what a chart's word, placed in its line, is boxed by from its baseline. */\n readonly ascent: number\n readonly descent: number\n /**\n * What a measurer that keeps widths by face knows it by -- zrender's,\n * process-wide, which ECharts measures a chart's words through: the\n * digest of the bytes this render embeds for it, stripped as they are\n * embedded, never the digest it was handed under, which nothing holds to\n * its bytes; or `Roboto/<face>` for the renderer's own, whose bytes a\n * release fixes. Two faces of one key draw every word alike.\n *\n * Taken the first time it is asked for, and kept for the render: a\n * SHA-256 of Liberation Serif's 384 KiB took 3.3 ms, and six of them a\n * quarter of the corpus's `host-fonts` render, which draws no chart\n * (measured on 12 November 2026, Node 22.23.3 on an Apple M2).\n */\n readonly key: () => string\n /** \"Roboto\", or \"the serif font's bold face, the asset brand-bold,\": the face a refusal says a character is missing from. */\n readonly name: string\n}\n\n/** What text asks the plan for: the token it is set in, or none, and whether it prints bold and italic. */\nexport interface FaceWanted {\n readonly token: FontFamily | undefined\n readonly bold: boolean\n readonly italic: boolean\n}\n\n/** The pdfmake font families and virtual files a document's host faces add, which the engine registers for each pass and removes after it. */\nexport interface HostFontFiles {\n /** Each pdfmake family name to its faces' virtual-file names; merged over the renderer's own Roboto and Liberation Sans. */\n readonly families: Readonly<Record<string, Partial<Record<Face, string>>>>\n /** Each virtual-file name to the stripped bytes to embed. */\n readonly files: ReadonlyMap<string, Uint8Array>\n}\n\n/** The plan a render reads: resolve a style's face, name a token's family, the default family for text with no token, and the files the engine adds. */\nexport interface RenderFonts {\n face(token: FontFamily | undefined, bold: boolean, italic: boolean, subject: string): RenderFace\n /** Whether a style may name `token`: `sans` always (Roboto), `serif` and `mono` only where the report maps them. */\n usable(token: FontFamily): boolean\n readonly familyOf: (token: FontFamily) => string\n readonly defaultFamily: string\n readonly engine: HostFontFiles\n}\n\n/** pdfmake's face name for report-spec's face key: pdfmake calls the slanted faces `italics` and `bolditalics`. */\nconst PDFMAKE_FACE: Readonly<Record<FontFaceKey, Face>> = { normal: 'normal', bold: 'bold', italic: 'italics', boldItalic: 'bolditalics' }\n\n/** A face key in a person's words. */\nconst FACE_WORDS: { readonly [K in FontFaceKey]: string } = { normal: 'regular', bold: 'bold', italic: 'italic', boldItalic: 'bold italic' }\n\n/** The pdfmake family name a mapped token prints in: its own, so a host's family of the same name as the renderer's cannot replace it. */\nconst hostFamily = (token: FontFamily): string => `formancy-host-${token}`\n\n/** Renders planned in this process or page, so that each names its virtual files apart from every other's. */\nlet renders = 0\n\n/** A face read for this render: its glyphs, its line and baseline, its key, what a refusal calls it, and the virtual file the engine embeds it from. */\ninterface PlannedFace extends RenderFace {\n readonly file: string\n}\n\n/** A face asset as this render read it, before a token and a face name it. */\ntype ReadFace = Omit<PlannedFace, 'name'>\n\n/**\n * The plan for `fonts` -- the document's resolved font map -- over the\n * renderer's own Roboto, whose glyphs `roboto` holds. `undefined` fonts, or\n * a token left out, prints in Roboto (`sans`) or is refused (`serif`,\n * `mono`), as before. Each face asset is read once however many tokens and\n * faces name it, and refused as `invalid-asset`, naming it, where `readFont`\n * refuses its bytes, PDFKit would draw it as another face\n * (`face-identity.ts`), or its id is handed again in other bytes.\n */\nexport function planFonts(fonts: ResolvedFonts | undefined, roboto: Glyphs): RenderFonts {\n const render = (renders += 1)\n const read = new Map<string, ReadFace & { readonly bytes: Uint8Array }>()\n const hosts: HostFace[] = []\n const files = new Map<string, Uint8Array>()\n /**\n * `asset` read and stripped, the first time this render meets it: a face\n * of the renderer's own bytes is embedded as the renderer embeds it,\n * layout tables and all. Met again by its id in other bytes -- a\n * document built by hand; the runtime resolves each id once -- it is\n * refused, since a face read by that id would print in the first bytes.\n */\n const readAsset = (asset: FontAsset): ReadFace => {\n const known = read.get(asset.id)\n if (known !== undefined) {\n if (known.bytes !== asset.bytes && assetDigest(known.bytes) !== assetDigest(asset.bytes)) {\n throw new RenderRefusal(\n 'invalid-asset',\n `the font asset ${asset.id} is handed to the renderer twice, in other bytes the second time: an asset is one font, read by its id`,\n asset.id,\n )\n }\n return known\n }\n const font = readFont(asset.bytes)\n if (!font.ok) throw new RenderRefusal('invalid-asset', `the font asset ${asset.id} ${font.message}`, asset.id)\n const host = { asset, postScriptNames: font.names.postScriptNames }\n const own = drawnAs(host, hosts)\n hosts.push(host)\n const { ascender, descender, unitsPerEm } = font.metrics\n const file = `formancy-report-render-pdf/font/${render}/${read.size}.ttf`\n const embedded = own === undefined ? withoutLayoutTables(asset.bytes) : asset.bytes\n let digest: string | undefined\n const made = {\n bytes: asset.bytes,\n glyphs: font.characters,\n lineFactor: (ascender - descender) / unitsPerEm,\n ascent: ascender / unitsPerEm,\n descent: descender / unitsPerEm,\n key: (): string => (digest ??= assetDigest(embedded)),\n file,\n }\n read.set(asset.id, made)\n files.set(file, embedded)\n return made\n }\n\n const mapped: { -readonly [F in FontFamily]?: Partial<Record<FontFaceKey, PlannedFace>> } = {}\n const families: Record<string, Partial<Record<Face, string>>> = {}\n for (const token of ['sans', 'serif', 'mono'] as const) {\n const resolved: ResolvedFaces | undefined = fonts?.[token]\n if (resolved === undefined) continue\n const faces: { -readonly [K in FontFaceKey]?: PlannedFace } = {}\n const byName: Partial<Record<Face, string>> = {}\n for (const key of ['normal', 'bold', 'italic', 'boldItalic'] as const) {\n const asset = resolved[key]\n if (asset === undefined) continue\n const face = readAsset(asset)\n faces[key] = { ...face, name: `the ${token} font's ${FACE_WORDS[key]} face, the asset ${asset.id},` }\n byName[PDFMAKE_FACE[key]] = face.file\n }\n mapped[token] = faces\n families[hostFamily(token)] = byName\n }\n const defaultFamily = mapped.sans === undefined ? ROBOTO : hostFamily('sans')\n\n const face = (token: FontFamily | undefined, bold: boolean, italic: boolean, subject: string): RenderFace => {\n const effective: FontFamily = token ?? 'sans'\n const faces = mapped[effective]\n if (faces === undefined) {\n if (effective === 'sans') {\n const robotoFace = faceOf(bold, italic)\n return {\n glyphs: roboto[robotoFace],\n lineFactor: LINE_FACTOR,\n ascent: ROBOTO_ASCENT,\n descent: ROBOTO_DESCENT,\n key: () => `${ROBOTO}/${robotoFace}`,\n name: 'Roboto',\n }\n }\n throw new RenderRefusal(\n 'unsupported',\n `${subject} is set in the ${token} font, which the report maps to no host font; the renderer embeds Roboto alone, as the sans font, and prints no other in its place`,\n subject,\n )\n }\n const key = faceKey(bold, italic)\n const planned = faces[key]\n if (planned === undefined)\n throw new RenderRefusal(\n 'unsupported',\n `${subject} prints ${WEIGHT[key]} in the ${effective} font, which maps no ${key} face; the renderer never synthesises one`,\n subject,\n )\n return planned\n }\n\n const familyOf = (token: FontFamily): string => (mapped[token] === undefined ? ROBOTO : hostFamily(token))\n const usable = (token: FontFamily): boolean => token === 'sans' || mapped[token] !== undefined\n\n return { face, usable, familyOf, defaultFamily, engine: { families, files } }\n}\n\n/** What a face key prints, for a refusal a person reads. */\nconst WEIGHT: { readonly [K in FontFaceKey]: string } = { normal: 'text', bold: 'bold text', italic: 'italic text', boldItalic: 'bold italic text' }\n","import type { Content, TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport { RenderRefusal, type Table } from '@formancy/report-runtime'\nimport { keepBlocks, keptBlocks, keptCounts, type PlannedRow } from './breaks.js'\nimport type { TablePlan } from './build.js'\nimport type { RowLine } from './check-table.js'\nimport type { Engine } from './engine.js'\nimport type { HostFontFiles } from './host-fonts.js'\nimport { LINE_FACTOR, ROBOTO } from './style.js'\nimport { checkShifted, type ShiftedRoom } from './shifted.js'\nimport { checkWords, type WordRoom } from './words.js'\nimport { PADDING_Y, RULE } from './table.js'\n\n/**\n * Heights measured by laying content out with pdfmake itself, before the\n * PDF is laid out: pdfmake has no measuring call of its own, and the\n * renderer needs heights it cannot compute -- how tall the page header is,\n * whether a keep-together block or a table row fits on a page -- because\n * pdfmake drops content that does not fit where it must, without a word: a\n * page header taller than its margin loses lines, and an unbreakable block\n * or row taller than the page is not drawn at all.\n *\n * How: the items go on one tall page, one after another, each between two\n * sentinels -- one-point text, so that each has a position -- and the first\n * call of `pageBreakBefore`, which pdfmake makes once the layout is done,\n * reads the top of every marked node on the page and throws, so that no PDF\n * is written. A page break means the items did not fit on the page; the\n * `background` function pdfmake calls for every new page throws then.\n */\n\n/** The result of measuring: each item's height and where it ends, and the top of every node marked with a headline level, on the measuring page. */\nexport interface Measured {\n readonly heights: readonly number[]\n readonly ends: readonly number[]\n /** Throws for a mark pdfmake laid out no node for. */\n readonly top: (mark: number) => number\n}\n\n/** Thrown out of pdfmake's layout with what was read; never seen outside `measure`. */\nclass Measurement extends Error {\n readonly tops: ReadonlyMap<number, number>\n constructor(tops: ReadonlyMap<number, number>) {\n super('pdfmake was stopped once it had measured')\n this.tops = tops\n }\n}\n\n/** Sentinels are marked with negative numbers, so that they never meet the marks content carries; in Roboto, so their one line is its known height whatever the document's default face lays out (0043). */\nconst sentinel = (index: number): Content => ({ text: '.', fontSize: 1, font: ROBOTO, headlineLevel: -1 - index })\n\n/** Room left on the measuring page for the sentinels: each is one line of one-point text, 1.17pt in Roboto. */\nexport const SENTINEL_ROOM = 2\n\n/** A sentinel's height exactly: one line of one-point Roboto, for a page that must hold its items and nothing more. */\nexport const SENTINEL_LINE = LINE_FACTOR\n\n/**\n * Lays `items` out on one page `height` tall, between those side margins,\n * and measures them; `overflow` is what to throw when they do not fit on it.\n * Before a line is laid out, the words of the items are held to their\n * room, so that pdfmake never breaks one too wide for it, and those of a run\n * set below or above the line to a run on the line (`shifted.ts`).\n */\nexport async function measure(\n engine: Engine,\n page: { readonly width: number; readonly height: number; readonly left: number; readonly right: number },\n items: readonly Content[],\n resources: Required<Pick<TDocumentDefinitions, 'defaultStyle' | 'images'>>,\n overflow: () => Error,\n rooms: { readonly words: readonly WordRoom[]; readonly shifted: readonly ShiftedRoom[] },\n host: HostFontFiles,\n): Promise<Measured> {\n const definition: TDocumentDefinitions = {\n pageSize: { width: page.width, height: page.height },\n pageMargins: [page.left, 0, page.right, 0],\n ...resources,\n content: [sentinel(0), sentinel(1), ...items.flatMap((item, index) => [item, sentinel(index + 2)])],\n background: (number) => {\n // pdfmake has measured every word, and laid out no line yet (`words.ts`, `shifted.ts`).\n if (number === 1) {\n checkWords(rooms.words)\n checkShifted(rooms.shifted)\n }\n if (number > 1) throw overflow()\n return null\n },\n pageBreakBefore: (node, queries) => {\n const tops = new Map<number, number>()\n for (const each of [node, ...queries.getFollowingNodesOnPage()]) {\n if (each.headlineLevel !== undefined) tops.set(each.headlineLevel, each.startPosition.top)\n }\n throw new Measurement(tops)\n },\n }\n let tops: ReadonlyMap<number, number>\n try {\n await engine.run(definition, host)\n throw new Error('pdfmake wrote a PDF instead of measuring')\n } catch (error) {\n if (!(error instanceof Measurement)) throw error\n tops = error.tops\n }\n const top = (mark: number): number => {\n const found = tops.get(mark)\n if (found === undefined) throw new Error(`pdfmake laid out no node marked ${mark}`)\n return found\n }\n const pitch = top(-2) - top(-1)\n const ends = items.map((_, index) => top(-3 - index))\n return { heights: ends.map((end, index) => end - top(-2 - index) - pitch), ends, top }\n}\n\n/**\n * Each row's height, from the tops of the marks on their first cells: a\n * row's top to the next one's is its height and the rule under it. The last\n * row ends where the table does, which is where the sentinel after it\n * starts, measured from the top of its cell, which stands `PADDING_Y` below\n * the row's top.\n */\nexport function rowPitches(marks: readonly number[], top: Measured['top'], tableEnd: number): number[] {\n return marks.map((mark, index) => {\n const next = marks[index + 1]\n return next === undefined ? tableEnd - top(mark) + PADDING_Y : top(next) - top(mark)\n })\n}\n\n/**\n * pdfmake loses unbreakable content that misses its page by any amount.\n * Heights measured in one layout and used in another agree to the last bit\n * in practice; this much slack keeps rounding from ever deciding it.\n */\nexport const FIT_SLACK = 1\n\n/**\n * What a page of a body `bodyHeight` tall holds of a table's rows under its\n * column header, which pdfmake 0.3.11 repeats at the top of every page the\n * table reaches (`headerRows: 1`, `table.ts`) as the block it laid the\n * header out in: the table's top rule, the header row and the rule under\n * it (`TableProcessor.beginTable` and `endRow`, `currentBlockToRepeatable`),\n * `RULE` and the header's pitch, which is 0 for the header of no height a\n * table without one is handed (0078). Less `FIT_SLACK`. pdfmake repeats the\n * column header alone, never a group header, and has no footer rows of its\n * own: a group's footer and a total are rows under the header like any other.\n */\nfunction underHeader(headerPitch: number, bodyHeight: number): number {\n return bodyHeight - RULE - headerPitch - FIT_SLACK\n}\n\n/**\n * Refuses `table` when the tallest line of its rows under the header,\n * `under`, does not fit on a page under the repeated header, `headerPitch`\n * tall as measured, in a body `bodyHeight` tall where the table stands.\n *\n * pdfmake lays a row it may split out line by line. A line that does not\n * fit what is left of a page goes to the next, under the repeated header,\n * and one that does not fit there either goes to the page after and is\n * dropped without a word (`LayoutBuilder.processLeaf`,\n * `PageElementWriter._fitOnPage`, where `addLine` returns false): a row of\n * one 40 pt line under a 40 pt header, in a body that held the row alone,\n * printed five pages of the header and no row. On a page the table\n * continues on, a row's line stands under its padding, with its padding\n * and the rule under it kept below it (`TableProcessor.beginRow` and\n * `onRowBreak`): it needs the header as it repeats, the line, its padding\n * and three rules. A row kept whole (`dontBreakRows`) needs no less, so\n * every table the body pass measures is held to it, whatever its plan.\n */\nexport function refuseLineUnderHeader(table: Table, under: RowLine, headerPitch: number, bodyHeight: number): void {\n const row = PADDING_Y + under.line + PADDING_Y + RULE\n if (row <= underHeader(headerPitch, bodyHeight)) return\n const needs = RULE + headerPitch + row\n const above = table.header === undefined ? \"the table's top rule\" : \"the table's repeated header\"\n throw new RenderRefusal(\n 'content-too-large',\n `${under.what} has a line that needs ${needs.toFixed(2)} pt of a page under ${above}, and a point more for rounding; a page's body is ${bodyHeight.toFixed(2)} pt where it stands`,\n table.id,\n )\n}\n\n/**\n * How a table breaks across pages of a body `bodyHeight` tall, from its\n * measured rows, the header row first -- the header of no height pdfmake\n * is handed for a table without one among them (`UNSEEN_HEADER`):\n *\n * - rows are kept whole (`dontBreakRows`) only when every one fits on a\n * page under the repeated header, and the first row of each group under\n * its group header as well. pdfmake's option is the whole table's, so one\n * row that does not lets every row of the table split. Split is what a row\n * taller than the page needs, since pdfmake would otherwise not draw it,\n * and what the first row of a group needs to start on its group header's\n * page when the two cannot share one whole;\n * - the header moves with the first row, or with the first two when the\n * first is a group header, so that neither ends a page alone, and with\n * every row of a block of rows kept together that starts among them --\n * a one-line quotation's totals; not when they do not fit on a page\n * together, for the same reason;\n * - the rows kept together (`breaks.ts`) are the blocks that fit on a page\n * under the header and start after the rows that move with it, a group\n * header's with as many of the rows it keeps as fit there (`keptCounts`).\n * A table whose rows may split keeps only its group headers with what\n * they head.\n */\nexport function tablePlan(rows: readonly PlannedRow[], bodyHeight: number): TablePlan {\n const [header, ...body] = rows\n const room = underHeader(header?.pitch ?? 0, bodyHeight)\n const under = (index: number): number => (body[index - 1]?.kind === 'groupHeader' ? body[index - 1]!.pitch : 0)\n const dontBreakRows = body.every((row, index) => under(index) + row.pitch <= room)\n const pitches = rows.map((row) => row.pitch)\n const blocks = keepBlocks(\n rows.map((row) => row.kind),\n dontBreakRows,\n keptCounts(rows, dontBreakRows, room),\n )\n const first = body[0]?.kind === 'groupHeader' && body.length > 1 ? 2 : 1\n let lead = first\n for (const block of blocks) if (block.first <= lead) lead = Math.max(lead, block.last)\n const fits = (count: number): boolean => body.slice(0, count).reduce((sum, row) => sum + row.pitch, 0) <= room\n const keepWithHeaderRows = fits(lead) ? lead : fits(first) ? first : 0\n return { dontBreakRows, keepWithHeaderRows, pitches, blocks: keptBlocks(blocks, pitches, keepWithHeaderRows, room) }\n}\n","import type { Content, TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport { RenderRefusal, type Block, type Chart, type PageSetup, type ResolvedDocument, type Table } from '@formancy/report-runtime'\nimport { checkBill, refusePage, type CheckedBill } from './bill.js'\nimport { refuseOversized } from './bound.js'\nimport type { Build, ChartDrawing, TablePlan } from './build.js'\nimport { drawEmpty } from './chart-empty.js'\nimport { chartFaces, type ChartFace, type ChartFaces } from './chart-faces.js'\nimport { checkDocument, refuseTall, type Checked, type Page } from './check.js'\nimport {\n bodyMeasurement,\n defaultStyle,\n firstPageHeaderMeasurement,\n layoutDefinition,\n REGION_GAP,\n regionsMeasurement,\n slipReservation,\n type Drawn,\n type Regions,\n} from './definition.js'\nimport { loadOnce, type Engine, type MeasuredFace } from './engine.js'\nimport { planFonts, type RenderFonts } from './host-fonts.js'\nimport { FIT_SLACK, measure, refuseLineUnderHeader, rowPitches, SENTINEL_LINE, SENTINEL_ROOM, tablePlan } from './measure.js'\nimport type { RenderOptions } from './options.js'\nimport { embedEInvoice } from './pdfa.js'\nimport { ABOVE_SLIP, informationContent, PAYMENT_PART, RECEIPT } from './slip.js'\nimport { UNSEEN_HEADER } from './table.js'\n\n/**\n * A resolved document rendered with pdfmake, refused rather than truncated,\n * clipped or dropped: the renderer both entries share, given the one thing\n * they do differently, the engine that runs a pdfmake definition with its\n * fonts ([0005](../../../docs/decisions/0005-pdfmake-renders-reports-behind-one-adapter.md)).\n *\n * Three passes, each a pdfmake layout. The first measures the page header\n * and footer, and the second the body's keep-together blocks and table rows\n * (`measure.ts`), because pdfmake loses what does not fit where it must\n * without saying so. The third is the PDF, laid out again by pdfmake for\n * each page break a keep-with-next or table rule asks for. Before them the\n * renderer refuses what it cannot draw (`check.ts`, and `bill.ts` for a\n * QR-bill); between them it decides the page margins, refuses what cannot\n * fit on any page or within the page limit (`bound.ts`), draws the body's\n * charts (`drawCharts`), which both later passes lay out alike, and\n * chooses how each table breaks. A document with a QR-bill has two passes\n * more, one for each part of its slip, which measure their information\n * (`measureSlip`).\n * A document with a Factur-X e-invoice is drawn as a PDF/A-3b on the third\n * pass, which alone embeds its XML (`pdfa.ts`); one with an XRechnung as a\n * plain PDF, the copy its label says it is (0038); and a final render a\n * host asks for as `pdfa: '2b'` as a PDF/A-2b, which embeds nothing and\n * runs no hook (`pdfa-check.ts`, 0057).\n *\n * A document that gives page 1 a header of its own (0060) has one pass\n * more, which measures it as the page header is measured, and two bodies:\n * page 1's, under its own header, and every later page's, under the page\n * header. What a page must hold whole -- a keep-together block, a table's\n * line under its repeated header -- is held to the later pages' body,\n * where pdfmake moves what page 1 cannot hold; a block of fixed height and\n * a line to the shorter of the two, since pdfmake draws an image or an SVG\n * on a page that holds nothing whatever its room, and page 1 under a\n * header of space alone holds nothing; and the page limit to page 1's body\n * and the later pages' it leaves.\n */\n\nexport async function render(engine: Engine, document: ResolvedDocument, options: RenderOptions): Promise<Uint8Array> {\n const { signal, maxPages, pdfa } = options\n if (!Number.isSafeInteger(maxPages) || maxPages < 1) throw new RangeError(`maxPages must be a whole number of pages, at least 1; it is ${String(maxPages)}`)\n // A level misspelt or not drawn would otherwise be a plain PDF a host files as an archival one.\n if (pdfa !== undefined && pdfa !== '2b') throw new RangeError(`pdfa must be '2b' or left out; it is ${String(pdfa)}`)\n stopIfCancelled(signal)\n // Each host face read with readFont, its layout tables stripped, and the engine's virtual files made, before anything is laid out (0043).\n const fonts = planFonts(document.fonts, await engine.glyphs())\n const checked = await checkDocument(document, fonts, maxPages, pdfa)\n const bill = document.paymentPart === undefined ? undefined : checkBill(document.paymentPart, document.page, await engine.billGlyphs())\n // An EPC QR code's caption prints in Liberation Sans too, which a browser loads only when asked; its words are the PSA's, which the face has glyphs for.\n if (checked.captioned) await engine.billGlyphs()\n await stopIfCancelledSoon(signal)\n const regions = await measureRegions(engine, document, checked, fonts, maxPages)\n await stopIfCancelledSoon(signal)\n const bodyHeight = checked.page.height - regions.header - regions.footer\n if (bodyHeight <= 0) throw new RenderRefusal('content-too-large', `the page header and footer leave no room for the body (${bodyHeight.toFixed(2)} pt)`)\n // Page 1's body, under its own header where it has one (0060): the same as every page's where it prints the page header.\n const firstBody = checked.page.height - regions.first - regions.footer\n if (firstBody <= 0)\n throw new RenderRefusal(\n 'content-too-large',\n `the first page header and the page footer leave page 1 no room for its body (${firstBody.toFixed(2)} pt)`,\n 'firstPageHeader',\n )\n if (bill !== undefined) await measureSlip(engine, bill, checked.page, document.page, regions, fonts)\n refuseTall(checked.tall, Math.min(bodyHeight, firstBody))\n refuseOversized(document.body, { first: firstBody, later: bodyHeight }, maxPages, fonts, bill === undefined ? 0 : slipReservation(checked.page, regions))\n const drawn: Drawn = { ...checked, charts: await drawCharts(engine, checked.charts, fonts) }\n await stopIfCancelledSoon(signal)\n const plans = await measureBody(engine, drawn, fonts, { first: firstBody, later: bodyHeight }, maxPages)\n await stopIfCancelledSoon(signal)\n const finish = checked.pdfa?.subset === 'PDF/A-3b' ? embedEInvoice(checked.pdfa.file, checked.creationDate) : undefined\n const pdf = await engine.run(layoutDefinition(document, drawn, regions, plans, fonts, maxPages, bill), fonts.engine, finish)\n await stopIfCancelledSoon(signal)\n return pdf\n}\n\n/** How much taller than its section a slip's information may lay out and still fit: rounding, not layout. */\nconst SECTION_SLACK = 0.01\n\n/**\n * Refuses a QR-bill's slip that cannot be drawn whole where SIX puts it: on\n * a page whose top margin, with the header under it and the instruction to\n * separate over the slip, reaches into it, by report-spec's rule\n * (`refusePage`); or with information taller than its section (SG 6),\n * which would run into the section below it or off the paper. Each part's\n * information is laid out as the slip lays it out (`slip.ts`), on a sheet\n * as tall as its section and the three sentinels around it: what does not\n * fit on the sheet is taller than the section, and pdfmake's next page\n * refuses it. The header is the taller of page 1's and the page header\n * (0060): the slip prints on the last page, which is known only once the\n * pages are laid out, and on a one-page report is page 1.\n */\nasync function measureSlip(engine: Engine, bill: CheckedBill, page: Page, setup: PageSetup, regions: Regions, fonts: RenderFonts): Promise<void> {\n refusePage(setup, Math.max(regions.header, regions.first) + ABOVE_SLIP)\n for (const part of [PAYMENT_PART, RECEIPT]) {\n const { width, height, millimetres } = part.information\n const refusal = (): RenderRefusal =>\n new RenderRefusal(\n 'content-too-large',\n `${part.name}'s information is taller than its section: SIX gives it ${millimetres} mm (${height.toFixed(2)} pt)`,\n 'paymentPart',\n )\n const item: Content = { stack: informationContent(bill.bill, part), margin: [0, 0, page.paperWidth - width, 0] }\n const sheet = { width: page.paperWidth, height: height + 3 * SENTINEL_LINE + SECTION_SLACK, left: 0, right: 0 }\n await measure(engine, sheet, [item], resources(fonts, {}), refusal, { words: [], shifted: [] }, fonts.engine)\n }\n}\n\n/**\n * The page header's and footer's heights, measured once, on a page as tall\n * as the printable area: two regions that do not fit on it leave no body.\n * Page 1's own header (0060) is measured on a page of its own, as tall:\n * what does not fit on it is taller than the printable area.\n */\nasync function measureRegions(engine: Engine, document: ResolvedDocument, checked: Checked, fonts: RenderFonts, maxPages: number): Promise<Regions> {\n const { present, items, build } = regionsMeasurement(document, checked, fonts, maxPages)\n const heights =\n present.length === 0\n ? []\n : (await measureOnPrintable(engine, checked, fonts, items, build, 'the page header and footer are taller than the printable area')).heights\n const space = (blocks: readonly Block[]): number => (blocks.length === 0 ? 0 : heights[present.indexOf(blocks)]! + REGION_GAP)\n const header = space(document.pageHeader)\n const own = document.firstPageHeader\n if (own === undefined) return { header, footer: space(document.pageFooter), first: header }\n if (own.length === 0) return { header, footer: space(document.pageFooter), first: 0 }\n const first = firstPageHeaderMeasurement(own, checked, fonts)\n const measured = await measureOnPrintable(\n engine,\n checked,\n fonts,\n first.items,\n first.build,\n 'the first page header is taller than the printable area',\n 'firstPageHeader',\n )\n return { header, footer: space(document.pageFooter), first: measured.heights[0]! + REGION_GAP }\n}\n\n/** `items` measured on a page as tall as the printable area and their sentinels, refused as `content-too-large` when they do not fit on it. */\nasync function measureOnPrintable(\n engine: Engine,\n checked: Checked,\n fonts: RenderFonts,\n items: readonly Content[],\n build: Pick<Build, 'images' | 'words' | 'shifted'>,\n overflow: string,\n subject?: string,\n): Promise<{ readonly heights: readonly number[] }> {\n const { page } = checked\n return measure(\n engine,\n { width: page.paperWidth, height: page.height + SENTINEL_ROOM * (items.length + 2), left: page.margins.left, right: page.margins.right },\n items,\n resources(fonts, build.images),\n () => new RenderRefusal('content-too-large', overflow, subject),\n build,\n fonts.engine,\n )\n}\n\n/** The drawing, which alone imports ECharts (`chart-draw.ts`): imported the first time a document holds a chart that is not empty, and kept (`loadOnce`). */\nconst chartDraw = loadOnce(() => import('./chart-draw.js'))\n\n/**\n * The body's charts, as `check.ts` collected them, drawn (0058): each\n * chart's faces read from the plan (`chartFaces`), every face any of them\n * prints in opened once for measuring, in the engine's own pdfmake\n * (`Engine.widths`), and each laid out by ECharts (`drawChart`) -- or,\n * with nothing to draw, its title and its empty text placed without it\n * (`drawEmpty`). ECharts is imported where a chart is not empty, and never\n * otherwise (R23). The widths are the render's alone, dropped with it, as\n * every face it reads is (0043).\n */\nasync function drawCharts(engine: Engine, charts: Checked['charts'], fonts: RenderFonts): Promise<Build['charts']> {\n if (charts.length === 0) return new Map()\n const faces = new Map(charts.map(({ block }): [Chart, ChartFaces] => [block, chartFaces(block, fonts)]))\n const measured = new Map<string, MeasuredFace>()\n for (const { words, title } of faces.values())\n for (const { family, face } of [words, ...(title === undefined ? [] : [title])] satisfies ChartFace[]) measured.set(`${family}/${face}`, { family, face })\n const widths = await engine.widths(fonts.engine, [...measured.values()])\n const drawing = charts.some(({ block }) => block.empty === undefined) ? await chartDraw() : undefined\n return new Map(\n charts.map(({ block }): [Chart, ChartDrawing] => {\n const each = faces.get(block)!\n return [block, drawing === undefined || block.empty !== undefined ? { words: drawEmpty(block, each, widths) } : drawing.drawChart(block, each, widths)]\n }),\n )\n}\n\n/**\n * Measures the body's keep-together blocks and tables, refuses a block no\n * page can hold and a table's line no page holds under its repeated header\n * (`refuseLineUnderHeader`), and plans how each table breaks. On a page as tall as the\n * page limit's bodies and one more -- page 1's, under its own header where\n * it has one (0060), and the later pages' -- content that does not fit on\n * it needs more pages than the limit, whatever else the body holds, so it\n * is refused here, after laying out at most that much of it. What a page\n * must hold whole is held to the later pages' body, where pdfmake moves\n * what page 1 cannot hold.\n *\n * A block inside framed sections has less of each page than the body: their\n * borders and padding above and below it, which is what `inset` holds.\n */\nasync function measureBody(\n engine: Engine,\n checked: Drawn,\n fonts: RenderFonts,\n bodies: { readonly first: number; readonly later: number },\n maxPages: number,\n): Promise<ReadonlyMap<Table, TablePlan>> {\n const { measured, page } = checked\n if (measured.length === 0) return new Map()\n const bodyHeight = bodies.later\n const { items, build } = bodyMeasurement(measured, checked, fonts)\n const sheet = (maxPages + 1) * bodyHeight + (bodies.first - bodyHeight)\n const { heights, top, ends } = await measure(\n engine,\n { width: page.paperWidth, height: sheet + SENTINEL_ROOM * (items.length + 2), left: page.margins.left, right: page.margins.right },\n items,\n resources(fonts, build.images),\n () => new RenderRefusal('too-many-pages', `the report needs more than ${maxPages} pages`),\n build,\n fonts.engine,\n )\n const plans = new Map<Table, TablePlan>()\n measured.forEach(({ block, at, inset, under }, index) => {\n const room = bodyHeight - inset\n if (block.kind === 'keepTogether' && heights[index]! > room - FIT_SLACK) {\n throw new RenderRefusal(\n 'content-too-large',\n `the keep-together block ${at} is ${heights[index]!.toFixed(2)} pt tall; a page's body is ${room.toFixed(2)} pt where it stands`,\n at,\n )\n }\n if (block.kind === 'table') {\n const rows = build.measuredRows.get(block)!\n const pitches = rowPitches(\n rows.map((row) => row.mark),\n top,\n ends[index]!,\n )\n const planned = rows.map((row, at) => ({ kind: row.kind, pitch: pitches[at]!, keep: row.keep, prints: row.prints }))\n // A table without a header row is laid out here without the header of no height pdfmake is handed, which the plan reads first.\n const headed = block.header !== undefined\n refuseLineUnderHeader(block, under!, headed ? pitches[0]! : 0, room)\n plans.set(block, tablePlan(headed ? planned : [UNSEEN_HEADER, ...planned], room))\n }\n })\n return plans\n}\n\nfunction resources(fonts: RenderFonts, images: Record<string, string>): Required<Pick<TDocumentDefinitions, 'defaultStyle' | 'images'>> {\n return { defaultStyle: defaultStyle(fonts), images }\n}\n\nfunction stopIfCancelled(signal: AbortSignal | undefined): void {\n if (signal?.aborted === true) throw new RenderRefusal('cancelled', 'the render was cancelled')\n}\n\n/**\n * `stopIfCancelled`, once the event loop has turned. Every await of a pass\n * resolves without it turning -- pdfmake's work is synchronous and PDFKit's\n * stream events come on the microtask queue -- so without this an abort\n * from a timer arrived only once the PDF was written: a 417-page render\n * resolved after 10.7 seconds with a PDF its caller had abandoned after 50\n * milliseconds (2026-10-15).\n */\nasync function stopIfCancelledSoon(signal: AbortSignal | undefined): Promise<void> {\n if (signal !== undefined) await new Promise((resolve) => setTimeout(resolve, 0))\n stopIfCancelled(signal)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,OAAO,MAAe,QAAuB;CAC3D,OAAO,OAAQ,SAAS,gBAAgB,SAAU,SAAS,YAAY;AACzE;;AAGA,MAAM,8BAAmC,IAAI,IAAI,CAAC,IAAM,EAAI,CAAC;;AAG7D,SAAgB,aAAa,MAAc,MAA+C;CACxF,KAAK,MAAM,aAAa,MAAM;EAC5B,MAAM,QAAQ,UAAU,YAAY,CAAC;EACrC,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,CAAC,YAAY,IAAI,KAAK,GAAG,OAAO;CAC1D;AAEF;;AAGA,SAAgB,UAAU,OAAuB;CAC/C,OAAO,KAAK,MAAM,SAAS,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,GAAG,GAAG;AAC9D;;;;;;;;AASA,SAAgBA,eAAa,MAAuC;CAClE,MAAM,OAAOC,aAAiB,IAAI;CAClC,IAAI,CAAC,KAAK,IAAI,MAAM,IAAI,MAAM,YAAY,KAAK,SAAS;CACxD,OAAO,KAAK;AACd;;;ACTA,SAAgB,gBAAgB,UAA8B;CAC5D,MAAM,WAAW,OAAO,OAAO,SAAS,kBAAkB,CAAC,CAAC,CAAC,CAAC,QAAQ,UAAU,MAAM,SAAS,IAAI;CACnG,MAAM,aAAa,SAAS,KAAK,UAAU,MAAM,QAAQ;CAG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