@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-Bs7DXIYJ.mjs","names":["pageOf","pageOf"],"sources":["../src/glyphs.ts","../src/engine.ts","../src/bytes.ts","../src/build.ts","../src/style.ts","../src/breaks.ts","../src/table-rules.ts","../src/widths.ts","../src/table.ts","../src/words.ts","../src/content.ts","../src/bound.ts","../src/assets.ts","../src/check.ts","../src/definition.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. 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 */\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 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 TrueType font maps to a glyph other than glyph 0, from\n * its Unicode BMP character map: the Windows (3, 1) or Unicode (0, 3)\n * subtable, in format 4. A font without one is not one this renderer\n * embeds, and is an error, not a document's refusal.\n */\nexport function characterMap(font: Uint8Array): ReadonlySet<number> {\n const view = new DataView(font.buffer, font.byteOffset, font.byteLength)\n const tables = view.getUint16(4)\n let cmap: number | undefined\n for (let index = 0; index < tables; index++) {\n const record = 12 + 16 * index\n if (String.fromCharCode(...font.subarray(record, record + 4)) === 'cmap') cmap = view.getUint32(record + 8)\n }\n if (cmap === undefined) throw new Error('the font has no character map')\n const encodings = view.getUint16(cmap + 2)\n for (let index = 0; index < encodings; index++) {\n const record = cmap + 4 + 8 * index\n const [platform, encoding] = [view.getUint16(record), view.getUint16(record + 2)]\n const subtable = cmap + view.getUint32(record + 4)\n const unicode = (platform === 3 && encoding === 1) || (platform === 0 && encoding === 3)\n if (unicode && view.getUint16(subtable) === 4) return format4(view, subtable)\n }\n throw new Error('the font has no Unicode character map in format 4')\n}\n\n/** A format 4 subtable's segments, each mapping a range of code points by a delta or through the glyph array; glyph 0 is no glyph. */\nfunction format4(view: DataView, table: number): ReadonlySet<number> {\n const segments = view.getUint16(table + 6) / 2\n const ends = table + 14\n const starts = ends + 2 * segments + 2\n const deltas = starts + 2 * segments\n const offsets = deltas + 2 * segments\n const mapped = new Set<number>()\n for (let segment = 0; segment < segments; segment++) {\n const end = view.getUint16(ends + 2 * segment)\n const start = view.getUint16(starts + 2 * segment)\n const delta = view.getUint16(deltas + 2 * segment)\n const offsetAt = offsets + 2 * segment\n const offset = view.getUint16(offsetAt)\n for (let point = start; point <= end; point++) {\n const indexed = offset === 0 ? point : view.getUint16(offsetAt + offset + 2 * (point - start))\n const glyph = offset !== 0 && indexed === 0 ? 0 : (indexed + delta) & 0xffff\n if (glyph !== 0) mapped.add(point)\n }\n }\n return mapped\n}\n","import type { TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport { characterMap, type Face, type Glyphs } from './glyphs.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.ts`) configures it: what runs a\n * definition and returns the PDF's bytes, and the characters the faces it\n * embeds have glyphs for. Everything else a render does is the same in both\n * (`render.ts`).\n */\nexport interface Engine {\n readonly run: (definition: TDocumentDefinitions) => Promise<Uint8Array>\n readonly glyphs: () => Promise<Glyphs>\n}\n\n/** The glyphs of the four faces, from their bytes, read once by `read` and kept: the fonts do not change while the process runs. */\nexport function glyphsOnce(read: (face: Face) => Promise<Uint8Array>): () => Promise<Glyphs> {\n let glyphs: Promise<Glyphs> | undefined\n return () =>\n (glyphs ??= (async () => {\n const faces: readonly Face[] = ['normal', 'bold', 'italics', 'bolditalics']\n const maps = await Promise.all(faces.map(async (face) => [face, characterMap(await read(face))] as const))\n return Object.fromEntries(maps) as unknown as Glyphs\n })())\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'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","/**\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.ts`).\n */\n\n/** CRC-32 as PNG and zlib compute it: the reflected polynomial 0xedb88320, every bit inverted before and after. */\nconst CRC_TABLE: readonly number[] = Array.from({ length: 256 }, (_, byte) => {\n let crc = byte\n for (let bit = 0; bit < 8; bit++) crc = crc & 1 ? 0xedb88320 ^ (crc >>> 1) : crc >>> 1\n return crc >>> 0\n})\n\nexport function crc32(bytes: Uint8Array): number {\n let crc = 0xffffffff\n for (const byte of bytes) crc = CRC_TABLE[(crc ^ byte) & 0xff]! ^ (crc >>> 8)\n return (crc ^ 0xffffffff) >>> 0\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]! +\n BASE64[((a & 3) << 4) | (b >> 4)]! +\n (left > 1 ? BASE64[((b & 15) << 2) | (c >> 6)]! : '=') +\n (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, ImageAsset, Table, TableRow } from '@formancy/report-runtime'\nimport type { Pixels } from './assets.js'\nimport type { KeepBlock } from './breaks.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/** 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. */\n readonly bodyTop: number\n /** Where it ends. */\n readonly bodyBottom: number\n readonly plans: ReadonlyMap<Table, TablePlan>\n /** Each image's size in pixels, as the asset checks read it. */\n readonly pixels: ReadonlyMap<ImageAsset, Pixels>\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. */\n readonly measuredRows: Map<Table, readonly { readonly kind: RowKind; readonly mark: number }[]>\n /** Where each paragraph stands in the document, `body[2]`, for a refusal to name. */\n readonly paths: ReadonlyMap<Block, string>\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 /** The next unused mark. */\n next: number\n}\n\nexport function newBuild(\n mode: Build['mode'],\n checked: { readonly pixels: ReadonlyMap<ImageAsset, Pixels>; readonly paths: ReadonlyMap<Block, string> },\n body: { readonly top: number; readonly bottom: number } = { top: 0, bottom: 0 },\n plans: ReadonlyMap<Table, TablePlan> = new Map(),\n): Build {\n const { pixels, paths } = checked\n return { mode, bodyTop: body.top, bodyBottom: body.bottom, plans, pixels, paths, imageKeys: new Map(), images: {}, rules: new Map(), measuredRows: new Map(), words: [], next: 1 }\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((other) => other.id !== undefined && ids.has(other.id) && other.startPosition.pageNumber === page)\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 { 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 one family the renderer embeds. */\nexport const ROBOTO = 'Roboto'\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 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 = 2400 / 2048\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/** pdfmake's text properties for a style, the renderer's own defaults under it. Only what is set is written. */\nexport function textProperties(style: TextStyle, defaults: { readonly size: number; readonly bold?: boolean; readonly italic?: boolean }): 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: FONTS[style.font] }),\n ...(bold === undefined ? {} : { bold }),\n ...(italic === undefined ? {} : { italics: italic }),\n ...(style.color === undefined ? {} : { color: style.color }),\n }\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 * And a table's closing rows -- a group's footers, the totals under the\n * last row -- with the row before them, and with its group header when that\n * row is the group's first: a quotation's subtotal, VAT and total on one\n * page with the last line item, a subtotal on the page of the rows it adds\n * up, never alone under a repeated column 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/**\n * The blocks of rows of these kinds that stand on one page, overlapping\n * ones merged, in order. Closing rows are kept with the row before them only\n * when `closing`: a table whose rows may split across pages has no row\n * height to keep them by.\n */\nexport function keepBlocks(kinds: readonly RowKind[], closing: boolean): KeepBlock[] {\n const blocks: KeepBlock[] = []\n kinds.forEach((kind, index) => {\n if (kind === 'groupHeader' && index + 1 < kinds.length) blocks.push({ first: index, last: 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 let last = index\n while (kinds[last + 1] !== undefined && CLOSING.has(kinds[last + 1]!)) last++\n const anchor = index - 1\n blocks.push({ first: kinds[anchor - 1] === 'groupHeader' ? anchor - 1 : anchor, last })\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/** 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(pitches: readonly number[], blocks: readonly KeepBlock[], first: number, geometry: Geometry): { 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 or last row has no text cannot be kept: there is nothing on\n * the page for the rule to find.\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 { mark, UNPLANNED, type Build, type RowKind } from './build.js'\nimport { textProperties } from './style.js'\nimport { 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 rule that keeps a group header with the row it heads.\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\nconst 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/** 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/** 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(table: Table, build: Build, place: { readonly width: number; readonly kept: boolean; readonly record: boolean; readonly top: number }): Content {\n const { kept } = place\n const measuring = build.mode === 'measure'\n const columns = table.columns.length\n const widths = columnWidths(table.columns.map((column) => column.width), place.width).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] }),\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 empty = !table.rows.some((row) => row.kind === 'detail')\n const rows: Row[] = [\n { kind: 'header', cells: table.header.map((text, column) => cell(text, column, 'header', table.headerStyle ?? {})) },\n ...(empty ? [{ kind: 'empty' as const, cells: [cell(table.emptyText, 0, 'empty', { italic: true }, columns), ...covered()] }] : []),\n ...table.rows.map((row): Row => {\n const style = (column: number): TextStyle => row.cellStyles?.[column] ?? row.style ?? {}\n if (row.across === true) return { kind: row.kind, cells: [cell(row.cells[0]!, 0, row.kind, style(0), columns), ...covered()] }\n return { kind: row.kind, cells: row.cells.map((text, column) => cell(text, column, row.kind, style(column))) }\n }),\n ]\n if (place.record) recordWords(table, rows, widths, across, build)\n const plan = build.plans.get(table) ?? UNPLANNED\n if (measuring) {\n build.measuredRows.set(table, rows.map((row) => ({ kind: row.kind, mark: mark(row.cells[0]!, build) })))\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.\n tableRules(rows, plan, build, place.top === build.bodyTop ? build.bodyTop + RULE + (plan.pitches[0] ?? 0) : undefined)\n }\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: rows.map((row): TableCell[] => [...row.cells]),\n },\n 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 = 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({ node: cell, width: spans ? across : widths[column]!, lines: 1, what: spans ? which : `${which}, column ${column + 1}`, subject: table.id })\n })\n }\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 *\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}\n\n/** How much wider than its room a word may measure and still be laid out unbroken: rounding, not layout. */\nconst 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 } 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('content-too-large', `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`, subject)\n }\n}\n","import type { Content, CustomTableLayout } from 'pdfmake/interfaces.js'\nimport type { Block, Columns, Image, ImageAsset, Inline, Paragraph, Rectangle, Rule, Section } from '@formancy/report-runtime'\nimport { base64 } from './bytes.js'\nimport { startsOnPage, type Build, type Fields } from './build.js'\nimport { DEFAULT_SIZE, textProperties } from './style.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. */\n readonly top: number\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/** Content for the body's blocks, laid out `width` wide, or a page region's when `fields` are given. */\nexport function contentOf(blocks: readonly Block[], build: Build, width: number, fields?: Fields): Content[] {\n const record = fields === undefined || build.mode === 'measure'\n return sequence(blocks, build, fields === undefined ? { width, kept: false, top: build.bodyTop, record } : { width, kept: true, top: 0, fields, record })\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) => node.startPosition.top > scope.top + AT_TOP && !startsOnPage(queries, ids, node.startPosition.pageNumber))\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 readonly stack?: readonly Anchor[]\n readonly columns?: readonly Anchor[]\n readonly table?: { readonly body: readonly (readonly Anchor[])[] }\n id?: string\n headlineLevel?: number\n}\n\n/** The first node of `node` that prints text, or an image when no text comes first: where pdfmake records the content's start. */\nfunction anchorOf(node: Anchor): Anchor | undefined {\n const inner = node.stack ?? node.columns ?? node.table?.body.flat()\n if (inner !== undefined) {\n for (const each of inner) {\n const anchor = anchorOf(each)\n if (anchor !== undefined) return anchor\n }\n return undefined\n }\n // A paragraph's text is an array of runs, and the renderer keeps nothing with a paragraph that prints nothing.\n const printsText = typeof node.text === 'string' ? node.text.trim() !== '' : Array.isArray(node.text)\n return printsText || node.image !== undefined ? node : undefined\n}\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 or an image, past spacers,\n * rules, rectangles and other keep-with-next paragraphs, so that a run of\n * headings moves as one. None when a page break or the end of the list comes\n * 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 '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 }\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)),\n alignment: style.align ?? 'left',\n ...textProperties(style, { size: DEFAULT_SIZE }),\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 return content\n}\n\nfunction inline(run: Inline, fields: Fields | undefined): { text: string; bold?: boolean } {\n if ('text' in run) return run.bold === undefined ? { text: run.text } : { text: run.text, bold: run.bold }\n // The renderer refuses a page field outside a page region before building anything.\n if (fields === undefined) throw new Error(`a ${run.field} field outside a page region`)\n return { text: String(fields[run.field]) }\n}\n\n/**\n * An image in its box, which the layout reserves whole. `cover` is pdfmake's\n * own: the box clipped, the image scaled to fill it and centred. `contain`\n * is drawn at the size the box allows at the image's proportions, read from\n * its pixels, and centred in the box by margins that make up the rest of it.\n */\nfunction imageContent(image: Image, build: Build): Content {\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 // The asset checks read every image's pixels before anything is built.\n const pixels = build.pixels.get(image.asset)!\n const scale = Math.min(image.width / pixels.width, image.height / pixels.height)\n const [width, height] = [pixels.width * scale, pixels.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 { canvas: color === undefined ? [] : [{ type: 'rect', x: 0, y: 0, w: width, h: height, color, lineWidth: 0 }], margin: [0, 0, 0, color === undefined ? height : 0] }\n }\n const half = OUTLINE / 2\n return {\n canvas: [{ type: 'rect', x: half, y: half, w: width - OUTLINE, h: height - OUTLINE, lineWidth: OUTLINE, lineColor: stroke, ...(fill === undefined ? {} : { color: fill }) }],\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(columns.columns.map((slot) => slot.width), scope.width)\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, type Block, type Table, type TextStyle } from '@formancy/report-runtime'\nimport { frameOf } from './content.js'\nimport { DEFAULT_SIZE, LINE_FACTOR } from './style.js'\nimport { PADDING_Y, TABLE_SIZE } 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 line of text is one line of its size, however it wraps; a\n * table row one line of its largest text and its padding, without its rule;\n * an image, a rectangle and a rule their own height, without the space\n * around a rule; a frame its border and padding once. A spacer and a page\n * break count nothing, since a spacer at the foot of a page gives up its\n * space, and a page region is not body.\n */\nexport function leastHeight(blocks: readonly Block[]): number {\n return blocks.reduce((sum, block) => sum + least(block), 0)\n}\n\nfunction least(block: Block): number {\n switch (block.kind) {\n case 'paragraph':\n return block.runs.length === 0 ? 0 : line(block.style, DEFAULT_SIZE)\n case 'table':\n return tableHeight(block)\n case 'image':\n case 'rectangle':\n return block.height\n case 'rule':\n return block.thickness\n case 'spacer':\n case 'pageBreak':\n return 0\n case 'keepTogether':\n return leastHeight(block.blocks)\n case 'section':\n return leastHeight(block.blocks) + 2 * frameOf(block)\n case 'columns':\n return Math.max(0, ...block.columns.map((slot) => leastHeight(slot.blocks)))\n }\n}\n\nfunction line(style: TextStyle | null | undefined, size: number): number {\n return (style?.size ?? size) * LINE_FACTOR\n}\n\n/** A row: one line of the largest text in it, and the cells' padding above and below. */\nfunction rowHeight(cells: readonly string[], style: (column: number) => TextStyle | null | undefined): number {\n return Math.max(0, ...cells.map((text, column) => (text === '' ? 0 : line(style(column), TABLE_SIZE)))) + 2 * PADDING_Y\n}\n\n/** The header once, and each row. */\nfunction tableHeight(table: Table): number {\n const header = rowHeight(table.header, () => table.headerStyle)\n return table.rows.reduce((sum, row) => sum + rowHeight(row.cells, (column) => row.cellStyles?.[column] ?? row.style), header)\n}\n\n/** Refuses a body whose least height needs more than `maxPages` pages of `bodyHeight`. */\nexport function refuseOversized(blocks: readonly Block[], bodyHeight: number, maxPages: number): void {\n const height = leastHeight(blocks)\n if (height > maxPages * bodyHeight) {\n throw new RenderRefusal('too-many-pages', `the report needs more than ${maxPages} pages: its body is at least ${height.toFixed(2)} pt tall, and ${maxPages} pages hold ${(maxPages * bodyHeight).toFixed(2)} pt`)\n }\n}\n","import { MAX_ASSET_BYTES, RenderRefusal, type ImageAsset } from '@formancy/report-runtime'\nimport { crc32, 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; for a PNG, every chunk's length and CRC,\n * the header, and that the image data inflates to exactly the scanlines the\n * header promises, each with a known filter; for a JPEG, the segment\n * structure up to the scan, the frame header's size, and the end marker. A\n * JPEG's entropy-coded scan is not decoded: a corrupt scan inside an\n * otherwise well-formed JPEG still reaches the PDF.\n *\n * The size returned is the size the image is shown at: a JPEG whose Exif\n * orientation turns it a quarter turn is as wide as its frame is tall, as\n * PDFKit draws it. The check runs on the standard library alone, so that the\n * browser entry makes exactly the same one (`bytes.ts`).\n */\n\n/** Pixels a side. */\nexport const MAX_ASSET_SIDE = 4096\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/** An image's size in pixels, as it is shown, and how many bytes of image data it holds once a PNG's are inflated. */\nexport interface Pixels {\n readonly width: number\n readonly height: number\n readonly data: number\n}\n\n/** The asset's size in pixels, once its bytes pass; refused as `invalid-asset`, naming it and why, when they do not. */\nexport async function checkImageAsset(asset: ImageAsset): Promise<Pixels> {\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's size in pixels, or what is wrong with it. */\nasync function readAsset(asset: ImageAsset): Promise<Pixels | 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 isPng = startsWith(bytes, PNG_SIGNATURE)\n const isJpeg = bytes[0] === 0xff && bytes[1] === 0xd8\n if (asset.mediaType === 'image/png') return isPng ? readPng(bytes) : `is declared a PNG and is not one${isJpeg ? ': it is a JPEG' : ''}`\n if (asset.mediaType === 'image/jpeg') return isJpeg ? readJpeg(bytes) : `is declared a JPEG and is not one${isPng ? ': it is a PNG' : ''}`\n return `is of a media type the renderer does not draw (${String(asset.mediaType)})`\n}\n\nfunction sizeProblem(width: number, height: number): string | undefined {\n if (width === 0 || height === 0) return `has no pixels (${width} × ${height})`\n if (width > MAX_ASSET_SIDE || height > MAX_ASSET_SIDE) return `is ${width} × ${height} pixels; the limit is ${MAX_ASSET_SIDE} pixels a side`\n return undefined\n}\n\nconst PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a] as const\n\n/** Channels per pixel for each PNG colour type, and the bit depths it allows. */\nconst PNG_COLOUR_TYPES: ReadonlyMap<number, { channels: number; depths: readonly number[] }> = new Map([\n [0, { channels: 1, depths: [1, 2, 4, 8, 16] }],\n [2, { channels: 3, depths: [8, 16] }],\n [3, { channels: 1, depths: [1, 2, 4, 8] }],\n [4, { channels: 2, depths: [8, 16] }],\n [6, { channels: 4, depths: [8, 16] }],\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\ninterface PngHeader {\n readonly width: number\n readonly height: number\n readonly bitsPerPixel: number\n readonly interlaced: boolean\n readonly paletted: boolean\n}\n\nasync function readPng(bytes: Uint8Array): Promise<Pixels | string> {\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n let header: PngHeader | undefined\n let palette = false\n const data: Uint8Array[] = []\n for (let offset: number = PNG_SIGNATURE.length; ; ) {\n // A chunk is its length, its type, its data and its CRC: 12 bytes and the data.\n if (offset + 12 > bytes.length || offset + 12 + view.getUint32(offset) > bytes.length) return `is cut off at byte ${offset}`\n const length = view.getUint32(offset)\n const end = offset + 12 + length\n const type = String.fromCharCode(...bytes.subarray(offset + 4, offset + 8))\n const body = bytes.subarray(offset + 8, offset + 8 + length)\n if (crc32(bytes.subarray(offset + 4, offset + 8 + length)) !== view.getUint32(offset + 8 + length)) return `has the wrong CRC on its ${type} chunk`\n if (header === undefined) {\n if (type !== 'IHDR') return 'does not start with its header chunk'\n const parsed = pngHeader(body)\n if (typeof parsed === 'string') return parsed\n header = parsed\n } else if (type === 'PLTE') {\n palette = true\n } else if (type === 'IDAT') {\n data.push(body)\n } else if (type === 'IEND') {\n if (end !== bytes.length) return 'has bytes after its end chunk'\n break\n }\n offset = end\n }\n if (header.paletted && !palette) return 'is paletted and has no palette'\n return (await scanlineProblem(header, data)) ?? { width: header.width, height: header.height, data: inflatedLength(header) }\n}\n\nfunction pngHeader(body: Uint8Array): PngHeader | string {\n if (body.length !== 13) return 'has a header chunk of the wrong length'\n const view = new DataView(body.buffer, body.byteOffset, body.byteLength)\n const width = view.getUint32(0)\n const height = view.getUint32(4)\n const size = sizeProblem(width, height)\n if (size !== undefined) return size\n const [depth = 0, colourType = 0, compression, filter, interlace = 0] = body.subarray(8)\n const colour = PNG_COLOUR_TYPES.get(colourType)\n if (colour === undefined || !colour.depths.includes(depth)) return `has an invalid colour type and bit depth (${colourType}, ${depth})`\n if (compression !== 0 || filter !== 0 || interlace > 1) return 'has an unknown compression, filter or interlace method'\n return { width, height, bitsPerPixel: colour.channels * depth, interlaced: interlace === 1, paletted: colourType === 3 }\n}\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 ? ADAM7.map(([x, y, dx, dy]) => [Math.ceil((header.width - x) / dx), Math.ceil((header.height - y) / dy)] as const) : [[header.width, header.height] as const]\n return passes.filter(([width, height]) => width > 0 && height > 0).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, data: readonly Uint8Array[]): Promise<string | undefined> {\n if (data.length === 0) return 'has no image data'\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(concat(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\n/** Start-of-frame markers: every SOFn but DHT (C4), JPG (C8) and DAC (CC). */\nconst JPEG_FRAMES = new Set([0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf])\n\n/** APP1, where an Exif block lives. */\nconst APP1 = 0xe1\n\n/**\n * The segments before the scan, each a marker and a length, as a baseline or\n * progressive encoder writes them. Fill bytes between segments, which the\n * standard allows and encoders do not write, are refused with the rest of\n * what is malformed: failing closed costs a JPEG that could have been drawn.\n */\nfunction readJpeg(bytes: Uint8Array): Pixels | string {\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n let pixels: Pixels | undefined\n let orientation: number | undefined\n for (let offset = 2; offset + 4 <= bytes.length; ) {\n const marker = bytes[offset + 1]!\n if (bytes[offset] !== 0xff || marker === 0xff) return `has a malformed segment at byte ${offset}`\n const length = view.getUint16(offset + 2)\n if (length < 2 || offset + 2 + length > bytes.length) return `has a segment that runs past its end at byte ${offset}`\n if (JPEG_FRAMES.has(marker)) {\n if (length < 8) return 'has a frame header of the wrong length'\n const [width, height] = [view.getUint16(offset + 7), view.getUint16(offset + 5)]\n const size = sizeProblem(width, height)\n if (size !== undefined) return size\n pixels = { width, height, data: bytes.length }\n }\n if (marker === APP1 && orientation === undefined && startsWith(bytes.subarray(offset + 4), EXIF)) orientation = exifOrientation(bytes.subarray(offset + 4 + EXIF.length, offset + 2 + length))\n if (marker === 0xda) {\n if (pixels === undefined) return 'has image data before its frame header'\n if (bytes[bytes.length - 2] !== 0xff || bytes[bytes.length - 1] !== 0xd9) return 'is cut off: it does not end with an end-of-image marker'\n // Orientations 5 to 8 turn the image a quarter turn, as PDFKit draws it.\n return (orientation ?? 0) > 4 ? { ...pixels, width: pixels.height, height: pixels.width } : pixels\n }\n offset += 2 + length\n }\n return 'is cut off before its image data'\n}\n\n/** What an APP1 segment that holds Exif data starts with. */\nconst EXIF = [0x45, 0x78, 0x69, 0x66, 0, 0] as const\n\n/**\n * The orientation the first Exif block gives its image, read as PDFKit reads\n * it: the Orientation tag (0x0112) of the first image file directory, from 1\n * to 8. Anything else -- a block cut short, no such tag, a value out of\n * range -- is no orientation, which PDFKit draws as 1, upright. Only the\n * first Exif block counts, for PDFKit and here, so `0` stands for one read\n * without an orientation.\n */\nfunction exifOrientation(block: Uint8Array): number {\n if (block.length < 8) return 0\n const tiff = new DataView(block.buffer, block.byteOffset, block.byteLength)\n const order = tiff.getUint16(0)\n if (order !== 0x4949 && order !== 0x4d4d) return 0\n const little = order === 0x4949\n if (tiff.getUint16(2, little) !== 42) return 0\n const directory = tiff.getUint32(4, little)\n if (directory + 2 > tiff.byteLength) return 0\n const entries = tiff.getUint16(directory, little)\n for (let index = 0; index < entries; index++) {\n const entry = directory + 2 + index * 12\n if (entry + 12 > tiff.byteLength) return 0\n if (tiff.getUint16(entry, little) === 0x0112) {\n const value = tiff.getUint16(entry + 8, little)\n return value >= 1 && value <= 8 ? value : 0\n }\n }\n return 0\n}\n\nfunction startsWith(bytes: Uint8Array, prefix: readonly number[]): boolean {\n return prefix.every((byte, index) => bytes[index] === byte)\n}\n\nfunction concat(parts: readonly Uint8Array[]): Uint8Array<ArrayBuffer> {\n const joined = new Uint8Array(parts.reduce((total, part) => total + part.length, 0))\n let offset = 0\n for (const part of parts) {\n joined.set(part, offset)\n offset += part.length\n }\n return joined\n}\n","import { RenderRefusal, type Block, type Columns, type Image, type ImageAsset, type KeepTogether, type Rectangle, type ResolvedDocument, type Section, type Table, type TextStyle } from '@formancy/report-runtime'\nimport { checkImageAsset, MAX_IMAGE_DATA, type Pixels } from './assets.js'\nimport { frameOf, RULE_GAP } from './content.js'\nimport { codePoint, faceOf, missingGlyph, type Glyphs } from './glyphs.js'\nimport { COLOR, FONTS, LINE_FACTOR } from './style.js'\nimport { KIND_BOLD, PADDING_X, PADDING_Y } from './table.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, and text with a character the face\n * it prints in has no glyph for (`glyphs.ts`). Every refusal names where the\n * problem is -- `body[2].blocks[0]`, a table's id, an asset's id -- and none\n * of them is a 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.\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\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}\n\nexport interface Checked {\n readonly page: Page\n readonly creationDate: Date\n /** Every image's size in pixels, as it is shown. */\n readonly pixels: ReadonlyMap<ImageAsset, Pixels>\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}\n\n/** Where a block stands. */\ninterface Place {\n readonly region: 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\ninterface Walk {\n readonly glyphs: Glyphs\n readonly paths: Map<Block, string>\n readonly images: { readonly image: Image; readonly at: string }[]\n readonly tall: Tall[]\n readonly measured: Measured[]\n}\n\nexport async function checkDocument(document: ResolvedDocument, glyphs: Glyphs): Promise<Checked> {\n const creationDate = new Date(document.info.creationDate)\n if (Number.isNaN(creationDate.getTime())) 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 const page = pageOf(document.page)\n const walk: Walk = { glyphs, paths: new Map(), images: [], tall: [], measured: [] }\n const top: Omit<Place, 'region'> = { kept: false, column: false, width: page.width, inset: 0, depth: 0 }\n checkBlocks(document.pageHeader, 'pageHeader', { ...top, region: true }, walk)\n checkBlocks(document.pageFooter, 'pageFooter', { ...top, region: true }, walk)\n checkBlocks(document.body, 'body', { ...top, region: false }, walk)\n const pixels = new Map<ImageAsset, Pixels>()\n let data = 0\n for (const { image } of walk.images) {\n if (pixels.has(image.asset)) continue\n const read = await checkImageAsset(image.asset)\n data += read.data\n if (data > MAX_IMAGE_DATA) throw new RenderRefusal('content-too-large', `the images up to ${image.asset.id} hold ${data} bytes of image data; a render may hold ${MAX_IMAGE_DATA}`, image.asset.id)\n pixels.set(image.asset, read)\n }\n return { page, creationDate, pixels, tall: walk.tall, paths: walk.paths, measured: walk.measured }\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') 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) 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.region && block.runs.some((run) => 'field' in run)) {\n throw new RenderRefusal('unsupported', `${at} prints a page field; pdfmake knows the page number only in the page header and footer`, at)\n }\n checkStyle(block.style, at)\n if (block.runs.some((run) => !('text' in run) && run.field !== 'pageNumber' && run.field !== 'pageCount')) throw new RenderRefusal('unsupported', `${at} prints a field the renderer does not know`, at)\n for (const run of block.runs) {\n if ('text' in run) checkText(run.text, faceOf(run.bold ?? block.style?.bold ?? false, block.style?.italic ?? false), walk, at)\n }\n tall(walk, place, (block.style?.size ?? 0) * LINE_FACTOR, `a line of ${at}`, at)\n return\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)\n checkTableText(block, walk)\n tall(walk, place, tallestCellLine(block), `a line of table ${block.id}`, block.id)\n if (!place.region && !place.kept) walk.measured.push({ block, at, width: place.width, inset: place.inset })\n return\n case 'image':\n checkImage(block, place, walk)\n walk.images.push({ image: block, at })\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 })\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/** 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. */\nfunction 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\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 -- and to the face it\n * prints in, which must have a glyph for each of its characters.\n */\nfunction checkText(text: unknown, face: keyof Glyphs, 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 const missing = missingGlyph(text, walk.glyphs[face])\n if (missing !== undefined) {\n throw new RenderRefusal('unsupported', `${at} prints ${codePoint(missing)}, which Roboto 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`, subject)\n }\n}\n\n/** Every cell of `table` as text in the face it prints in: the renderer's weight for its row's kind, under the cell's style. */\nfunction checkTableText(table: Table, walk: Walk): void {\n const at = `table ${table.id}`\n const face = (style: TextStyle | null | undefined, bold: boolean, italic = false): keyof Glyphs => faceOf(style?.bold ?? bold, style?.italic ?? italic)\n table.header.forEach((text, column) => checkText(text, face(table.headerStyle, KIND_BOLD.header), walk, `${at}'s header, column ${column + 1},`, table.id))\n checkText(table.emptyText, face(undefined, KIND_BOLD.empty, true), walk, `${at}'s empty text`, table.id)\n table.rows.forEach((row, index) => {\n row.cells.forEach((text, column) => {\n checkText(text, face(row.cellStyles?.[column] ?? row.style, KIND_BOLD[row.kind]), walk, `${at}, row ${index}, column ${column + 1},`, table.id)\n })\n })\n}\n\nfunction checkStyle(style: TextStyle | undefined, at: string): void {\n if (style === undefined) return\n // Own tokens only: 'constructor' would find Object's, and crash pdfmake.\n if (style.font !== undefined && !Object.hasOwn(FONTS, style.font)) {\n throw new RenderRefusal('unsupported', `${at} is set in the ${String(style.font)} font; the renderer embeds Roboto alone, as the sans font, and prints no other in its place`, at)\n }\n if (style.size !== undefined && !(style.size > 0 && Number.isFinite(style.size))) throw new RenderRefusal('unsupported', `${at} is set at ${style.size} pt`, at)\n if (style.align !== undefined && style.align !== 'left' && style.align !== 'center' && style.align !== 'right') throw new RenderRefusal('unsupported', `${at} is aligned '${String(style.align)}'`, at)\n checkColor(style.color, at)\n}\n\nfunction checkColor(color: string | undefined, at: string): void {\n // pdfmake prints a colour it cannot read as black, without a word.\n if (color !== undefined && !COLOR.test(color)) throw new RenderRefusal('unsupported', `${at} names the colour '${color}', which is not #rrggbb in lower case`, at)\n}\n\nfunction checkTable(table: Table, width: number): 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')) throw new RenderRefusal('unsupported', `table ${table.id} aligns a column in a way the renderer does not know`, table.id)\n if (table.header.length !== columns) 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('unsupported', `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`}`, table.id)\n }\n if (row.cellStyles !== undefined && row.cellStyles.length !== row.cells.length) {\n throw new RenderRefusal('unsupported', `row ${index} of table ${table.id} has ${row.cellStyles.length} cell styles for ${row.cells.length} cells`, table.id)\n }\n for (const style of [row.style, ...(row.cellStyles ?? [])]) checkStyle(style ?? undefined, table.id)\n })\n checkStyle(table.headerStyle, table.id)\n const narrow = table.columns.find((column) => column.width !== 'fill' && !(column.width > 2 * PADDING_X && Number.isFinite(column.width)))\n if (narrow !== undefined) 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\n/** The tallest line a cell of the table prints, with the cell's padding: a row no page can start. */\nfunction tallestCellLine(table: Table): number {\n const styles = [table.headerStyle, ...table.rows.flatMap((row) => [row.style, ...(row.cellStyles ?? [])])]\n const size = Math.max(0, ...styles.map((style) => style?.size ?? 0))\n return size * LINE_FACTOR + 2 * PADDING_Y\n}\n\nfunction checkImage(image: Image, place: Place, walk: Walk): void {\n const { id } = image.asset\n if (image.fit !== 'contain' && image.fit !== 'cover') 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) 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\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) 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)))) 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) 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))) 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))) 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('content-too-large', `${each.what} is ${each.height.toFixed(2)} pt tall; the body is ${(bodyHeight - each.inset).toFixed(2)} pt where it stands`, each.subject)\n }\n }\n}\n","import type { Content, DynamicContent, TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport { RenderRefusal, type Block, type ResolvedDocument, type Table } from '@formancy/report-runtime'\nimport { newBuild, type Build, type Fields, type TablePlan } from './build.js'\nimport type { Checked, Measured, Page } from './check.js'\nimport { contentOf } from './content.js'\nimport { DEFAULT_SIZE, ROBOTO } from './style.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.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\nexport const DEFAULT_STYLE = { font: ROBOTO, fontSize: DEFAULT_SIZE }\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}\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(document: ResolvedDocument, checked: Checked, maxPages: number): 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 const build = newBuild('measure', checked)\n return { present, build, items: present.map((blocks): Content => ({ stack: contentOf(blocks, build, checked.page.width, fields) })) }\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: Checked): Measurement {\n const build = newBuild('measure', checked)\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/**\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 */\nexport function layoutDefinition(\n document: ResolvedDocument,\n checked: Checked,\n regions: Regions,\n plans: ReadonlyMap<Table, TablePlan>,\n maxPages: number,\n): TDocumentDefinitions {\n const page: Page = checked.page\n const { margins } = page\n const bodyTop = margins.top + regions.header\n const bodyBottom = page.paperHeight - margins.bottom - regions.footer\n const build = newBuild('render', checked, { top: bodyTop, bottom: bodyBottom }, plans)\n const region = (blocks: readonly Block[], margin: [number, number, number, number]): DynamicContent | undefined => {\n if (blocks.length === 0) return undefined\n return (pageNumber, pageCount) => ({ stack: contentOf(blocks, build, page.width, { pageNumber, pageCount }), margin })\n }\n const header = region(document.pageHeader, [margins.left, margins.top, margins.right, 0])\n const footer = region(document.pageFooter, [margins.left, REGION_GAP, margins.right, 0])\n // Once now, so that their images are in the dictionary before pdfmake reads it.\n header?.(1, 1, { width: page.paperWidth, height: page.paperHeight, orientation: document.page.orientation })\n footer?.(1, 1, { width: page.paperWidth, height: page.paperHeight, orientation: document.page.orientation })\n return {\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: DEFAULT_STYLE,\n content: contentOf(document.body, build, page.width),\n images: build.images,\n ...(header === undefined ? {} : { header }),\n ...(footer === undefined ? {} : { footer }),\n background: (number) => {\n // pdfmake has measured every word, and laid out no line yet.\n if (number === 1) checkWords(build.words)\n if (number > maxPages) throw new RenderRefusal('too-many-pages', `the report needs more than ${maxPages} pages`)\n return 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","import type { Content, TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport { keepBlocks, keptBlocks } from './breaks.js'\nimport type { RowKind, TablePlan } from './build.js'\nimport type { Engine } from './engine.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 {\n readonly tops: ReadonlyMap<number, number>\n constructor(tops: ReadonlyMap<number, number>) {\n this.tops = tops\n }\n}\n\n/** Sentinels are marked with negative numbers, so that they never meet the marks content carries. */\nconst sentinel = (index: number): Content => ({ text: '.', fontSize: 1, 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/**\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.\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 words: readonly WordRoom[],\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`).\n if (number === 1) checkWords(words)\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)\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 * How a table breaks across pages of a body `bodyHeight` tall, from its\n * measured rows, the header row first:\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 table\n * whose rows may split keeps only its group headers with what they head.\n */\nexport function tablePlan(rows: readonly { readonly kind: RowKind; readonly pitch: number }[], bodyHeight: number): TablePlan {\n const [header, ...body] = rows\n const room = bodyHeight - RULE - (header?.pitch ?? 0) - FIT_SLACK\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(rows.map((row) => row.kind), dontBreakRows)\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 { TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport { RenderRefusal, type Block, type ResolvedDocument, type Table } from '@formancy/report-runtime'\nimport { refuseOversized } from './bound.js'\nimport type { TablePlan } from './build.js'\nimport { checkDocument, refuseTall, type Checked } from './check.js'\nimport { bodyMeasurement, DEFAULT_STYLE, layoutDefinition, REGION_GAP, regionsMeasurement, type Regions } from './definition.js'\nimport type { Engine } from './engine.js'\nimport { FIT_SLACK, measure, rowPitches, SENTINEL_ROOM, tablePlan } from './measure.js'\nimport type { RenderOptions } from './options.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`); between them it\n * decides the page margins, refuses what cannot fit on any page or within\n * the page limit (`bound.ts`), and chooses how each table breaks.\n */\n\nexport async function render(engine: Engine, document: ResolvedDocument, options: RenderOptions): Promise<Uint8Array> {\n const { signal, maxPages } = 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 stopIfCancelled(signal)\n const checked = await checkDocument(document, await engine.glyphs())\n await stopIfCancelledSoon(signal)\n const regions = await measureRegions(engine, document, checked, 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 refuseTall(checked.tall, bodyHeight)\n refuseOversized(document.body, bodyHeight, maxPages)\n const plans = await measureBody(engine, checked, bodyHeight, maxPages)\n await stopIfCancelledSoon(signal)\n const pdf = await engine.run(layoutDefinition(document, checked, regions, plans, maxPages))\n await stopIfCancelledSoon(signal)\n return pdf\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 */\nasync function measureRegions(engine: Engine, document: ResolvedDocument, checked: Checked, maxPages: number): Promise<Regions> {\n const { present, items, build } = regionsMeasurement(document, checked, maxPages)\n if (present.length === 0) return { header: 0, footer: 0 }\n const { page } = checked\n const { heights } = await 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(build.images),\n () => new RenderRefusal('content-too-large', 'the page header and footer are taller than the printable area'),\n build.words,\n )\n const space = (blocks: readonly Block[]): number => (blocks.length === 0 ? 0 : heights[present.indexOf(blocks)]! + REGION_GAP)\n return { header: space(document.pageHeader), footer: space(document.pageFooter) }\n}\n\n/**\n * Measures the body's keep-together blocks and tables, refuses a block no\n * page can hold, and plans how each table breaks. On a page as tall as the\n * page limit's bodies and one more: content that does not fit on it needs\n * more pages than the limit, whatever else the body holds, so it is refused\n * here, after laying out at most that much of it.\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(engine: Engine, checked: Checked, bodyHeight: number, maxPages: number): Promise<ReadonlyMap<Table, TablePlan>> {\n const { measured, page } = checked\n if (measured.length === 0) return new Map()\n const { items, build } = bodyMeasurement(measured, checked)\n const { heights, top, ends } = await measure(\n engine,\n { width: page.paperWidth, height: (maxPages + 1) * bodyHeight + SENTINEL_ROOM * (items.length + 2), left: page.margins.left, right: page.margins.right },\n items,\n resources(build.images),\n () => new RenderRefusal('too-many-pages', `the report needs more than ${maxPages} pages`),\n build.words,\n )\n const plans = new Map<Table, TablePlan>()\n measured.forEach(({ block, at, inset }, index) => {\n const room = bodyHeight - inset\n if (block.kind === 'keepTogether' && heights[index]! > room - FIT_SLACK) {\n throw new RenderRefusal('content-too-large', `the keep-together block ${at} is ${heights[index]!.toFixed(2)} pt tall; a page's body is ${room.toFixed(2)} pt where it stands`, at)\n }\n if (block.kind === 'table') {\n const rows = build.measuredRows.get(block)!\n const pitches = rowPitches(rows.map((row) => row.mark), top, ends[index]!)\n plans.set(block, tablePlan(rows.map((row, at) => ({ kind: row.kind, pitch: pitches[at]! })), room))\n }\n })\n return plans\n}\n\nfunction resources(images: Record<string, string>): Required<Pick<TDocumentDefinitions, 'defaultStyle' | 'images'>> {\n return { defaultStyle: DEFAULT_STYLE, 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":";;;AA2BA,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;;;;;;;AAQA,SAAgB,aAAa,MAAuC;CAClE,MAAM,OAAO,IAAI,SAAS,KAAK,QAAQ,KAAK,YAAY,KAAK,UAAU;CACvE,MAAM,SAAS,KAAK,UAAU,CAAC;CAC/B,IAAI;CACJ,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,SAAS;EAC3C,MAA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