@formancy/report-runtime 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/README.md CHANGED
@@ -8,6 +8,8 @@ totals with exact decimals, and formats each value for the report's locale,
8
8
  once. No framework, no PDF engine, no Node. What it decides, and why, is
9
9
  decision
10
10
  [0010](../../docs/decisions/0010-the-runtime-resolves-a-report-into-a-renderer-neutral-document.md).
11
+ It also holds the one rule every engine draws a code's symbol by
12
+ ([A code's symbol](#a-codes-symbol)).
11
13
 
12
14
  ## Resolve
13
15
 
@@ -27,7 +29,7 @@ const images: ImageResolver = ({ asset, digest }) => approvedAssets.get(`${asset
27
29
  const resolution = resolveReport(report, data, { mode: 'final', parameters: { copies: '2' }, images, creationDate: '2026-10-15T08:00:00Z', timeZone: 'Europe/Zurich' })
28
30
  if (resolution.ok) {
29
31
  resolution.document // what @formancy/report-render-pdf draws
30
- resolution.manifest // the report's hash, locale, zone, mode, consistency, completeness, parameters
32
+ resolution.manifest // the report's hash, locale, zone, mode, consistency, completeness, parameters, and the data's source where it names one
31
33
  } else {
32
34
  resolution.errors // each with the stage that found it, a stable code, a JSON Pointer, never a value
33
35
  }
@@ -43,11 +45,48 @@ if (resolution.ok) {
43
45
  the column or the aggregate and the row;
44
46
  - a value a format cannot show, a locale or time zone the engine lacks
45
47
  (`format`);
46
- - an image the host has no bytes for, or bytes past 20 MB, and a total that
47
- cannot be computed (`resolve`).
48
+ - an image the host has no bytes for, or bytes past 20 MB -- an SVG's past
49
+ 1 MiB, `MAX_SVG_BYTES` -- and a total that cannot be computed
50
+ (`resolve`);
51
+ - a QR-bill that breaks one of SIX's rules once its data has resolved it
52
+ (`resolve`, `invalid-qr-bill`): an account, a reference, an address part,
53
+ a message or an amount, named by the field and the rule, never by the
54
+ value;
55
+ - an EPC QR code that breaks one of the EPC's rules once its data has
56
+ resolved it (`resolve`, `invalid-epc-qr-code`): an IBAN, a BIC or none
57
+ where the account needs one, a name, a reference, a text, an amount, or a
58
+ payload past 331 bytes, named by the code, the field and the rule, never
59
+ by the value;
60
+ - an e-invoice that breaks one of EN 16931's rules once its data has
61
+ resolved it (`resolve`, `invalid-e-invoice`): a text, a date, a line's
62
+ term, a table of no rows in a final render, or a payment code that asks
63
+ for another amount or account than the e-invoice names, each named by
64
+ where it stands, its business term and its rule, never by the value;
65
+ - a chart of more categories than `MAX_CHART_CATEGORIES`, or a pie of
66
+ more categories than its palette has colours (`resolve`,
67
+ `chart-too-many-categories`), and a pie with a negative value
68
+ (`chart-negative-share`), each naming the chart by its id and saying
69
+ counts, never a value or a category: see [A chart](#a-chart);
70
+ - a locale the report is not written in (`resolve`, `undeclared-locale`),
71
+ and a word missing in the one it names (`expressions`, `word-missing`):
72
+ see [A report in several languages](#a-report-in-several-languages).
48
73
 
49
74
  It never returns part of a document.
50
75
 
76
+ A table's group header row carries `keepWithRows`, how many of its group's
77
+ first rows an engine keeps it on its page with: the number its group
78
+ states, or the group's rows where it has fewer, and only where that is
79
+ more than one. How many rows a group has is this package's grouping,
80
+ counted once, and a report that states no count resolves to the document
81
+ it did before
82
+ ([0059](../../docs/decisions/0059-a-group-header-is-kept-on-its-page-with-as-many-of-its-groups-first-rows-as-the-report-states-or-as-fit.md)).
83
+
84
+ A table every column of which a render shows is titled with nothing, or
85
+ with white space alone, resolves with no `header` and no `headerStyle`,
86
+ decided here once, so that no engine prints a band of nothing over its
87
+ rows: code that reads a resolved table's `header` takes one without it
88
+ ([0078](../../docs/decisions/0078-a-table-whose-every-column-title-prints-nothing-has-no-header-row.md)).
89
+
51
90
  ## The data
52
91
 
53
92
  One header record and one detail list, with what the provider says about
@@ -60,33 +99,595 @@ them. Every value is held to its field's type before anything reads it:
60
99
  | `date` | `YYYY-MM-DD`, a day on the calendar from 0001 to 9999 |
61
100
  | `datetime` | `YYYY-MM-DDTHH:mm:ss`, with up to nine digits of a second, no zone |
62
101
  | `instant` | an ISO 8601 date-time with its zone, held in UTC |
63
- | `image` | `{ asset, digest }`, an approved asset, never an address |
102
+ | `image` | `{ asset, digest }`, an approved asset, never an address: a PNG, a JPEG or an SVG |
64
103
 
65
104
  A field the report does not declare is refused: a report never carries what
66
105
  it does not print. Null prints as nothing; a field the data lacks is an
67
- error in a final render, never an empty cell. A final render refuses data
68
- the provider calls incomplete. A **preview** prints what it has, warns once
69
- for each field it lacks, labels every page as a preview of incomplete data,
70
- and says so in its manifest. The host's objects are read once, as data: a
71
- getter is never run, and a proxy that throws is refused.
106
+ error in a final render, never an empty cell. A code is the exception: a
107
+ final render refuses a value that is null in a QR code's content or in a
108
+ QR-bill's or an EPC QR code's text (`no-qr-value`) -- but in an EPC QR
109
+ code's optional text that prints nothing else, which is that text left
110
+ out -- and a QR code whose content prints nothing
111
+ (`empty-qr-code`), since a scanner cannot see the gap a reader would. A
112
+ final render refuses data the provider calls incomplete. A **preview**
113
+ prints what it has, encodes a QR code as its content resolves, warns once
114
+ for each field it lacks, labels every page as a preview of incomplete
115
+ data, and says so in its manifest. A QR-bill is held to SIX's rules in a
116
+ preview too, and an EPC QR code to the EPC's: one that a missing value
117
+ leaves without a text its rules require is refused, and the error says the
118
+ preview lacked a value for it, since its code would scan as a payment no
119
+ bank makes. The host's objects are read
120
+ once, as data: a getter is never run, and a proxy that throws is refused.
121
+
122
+ **Where it came from.** The data may name its `source`, and the manifest
123
+ carries it as `source`, so that a PDF kept with its manifest says what
124
+ collected its data
125
+ ([0041](../../docs/decisions/0041-a-renders-manifest-names-where-its-data-came-from-by-identifiers-alone.md)):
126
+
127
+ ```ts
128
+ // Read from a formancy form: each submission, with the form's id and the schemaHash of the version that collected it.
129
+ source: { provider: 'formancy-form', submissions: [{ id: 'b682a5ed-ed01-4f8c-8d80-cf53db4e8380', form: 'site-visit', formHash: '767a65b36d4c02adf432d91ccdf7f8f285eebdbfc2987fb08fecd846b721dc42' }] }
130
+ // Read from Formancy Data: the published form each dataset was read from, as @formancy/report-data-provider names it.
131
+ source: { provider: 'formancy-data', forms: { header: 'order', detail: 'order-line' } }
132
+ ```
133
+
134
+ The form's id is each submission's, since a new version of a form may
135
+ change it. A source is for identifiers alone, since a manifest is kept
136
+ longer than any log, and is held to their syntax, not their meaning. A form's id
137
+ and a version's hash are held to the rules a report's provenance is,
138
+ report-spec's `isFormId` and `isSchemaHash`; a submission's id is
139
+ letters, digits, `.`, `_` and `-`, starting with a letter or a digit, at
140
+ most 128 characters, the rule `isSubmissionId` exports, which the form
141
+ bridge holds an id to before it reads a submission
142
+ ([0042](../../docs/decisions/0042-a-report-reads-a-formancy-forms-submissions-against-the-exact-version-that-collected-them-as-the-host-hands-them-over.md)).
143
+ So a space, an `@`, a `/`, a `:`, a letter beyond
144
+ ASCII or a 129th character is refused, and with them a full name or an
145
+ email address; a single word, a personal number or any 64 hex digits as a
146
+ hash fits, and the syntax cannot tell it from an identifier. A key a
147
+ source's shape does not name, more submissions than the detail rows given
148
+ (or than one where none are), a submission named twice, a Formancy Data
149
+ source naming no form, a form for a dataset the report does not declare
150
+ or none for one it does, and a provider the runtime does not know are
151
+ each refused, as `invalid-source`, never naming the value or the key. Its
152
+ syntax is checked, not its truth: that the host read what it names is the
153
+ provider's word, as its completeness is. Data that names no source is
154
+ read as before, and its manifest has none. A formancy form's source names
155
+ the `locale` its labels were read in, where that is not the report's own,
156
+ held to the syntax a report's locale is (report-spec's `isLocale`): see
157
+ [A report in several languages](#a-report-in-several-languages).
158
+
159
+ ## A report in several languages
160
+
161
+ A report may write its own words in each language its `translations`
162
+ declare, and a render names the one it prints in with `locale`
163
+ ([0063](../../docs/decisions/0063-a-reports-own-words-are-written-in-each-language-it-declares-and-a-render-names-the-one-it-prints-in.md)):
164
+
165
+ ```ts
166
+ const french = resolveReport(report, data, { mode: 'final', creationDate: '2026-10-15T08:00:00Z', locale: 'fr-CH' })
167
+ ```
168
+
169
+ - **A declared locale, exactly.** The report's own `locale` or one its
170
+ translations declare; any other is refused as `undeclared-locale`, a
171
+ near one among them: `fr-FR` is not `fr-CH`, and `fr` is neither. A
172
+ render that names none prints in the report's own, and one that names
173
+ the report's own prints the same document as one that names none.
174
+ - **The report written in it.** What every stage reads is report-spec's
175
+ `reportIn`: each word and each expression that prints words in that
176
+ language, `locale` the render's, so that its values are formatted, its
177
+ rows, groups and a chart's categories ordered, in it, and a QR-bill's
178
+ headings in its language where SIX has headings in it. No stage of the
179
+ runtime has a language step of its own.
180
+ - **An error refuses its own language.** Of report-core's diagnostics, an
181
+ error that names a language -- a word missing in it, `word-missing`, a
182
+ translated expression that would print another thing -- refuses a
183
+ render in that language alone; one that names none refuses every
184
+ render. A report whose French lacks a word prints in German as the same
185
+ report without translations does. A word is never printed in another
186
+ language than the one a render names.
187
+ - **The manifest** names the template's hash, translations and all, and
188
+ the locale the render printed in.
189
+ - **A form's labels in it.** Data read from a formancy form whose labels
190
+ were read in another locale than the render's is refused as
191
+ `labels-locale-differs`: a source that names no locale was read in the
192
+ report's own, so submissions read once in German are refused in a French
193
+ render rather than print German labels in it. A report's other data, a
194
+ parameter's value among it, prints as the host hands it over, in
195
+ whatever language the host chose.
196
+
197
+ The runtime's own words -- a preview's label, an XRechnung copy's label and
198
+ paragraph, a boolean's `true` and `false` -- are English in every
199
+ language. The one exception is the label of a copy of an e-invoice, which
200
+ is written in the language the render prints in, or refused
201
+ ([0077](../../docs/decisions/0077-a-report-that-carries-an-e-invoice-is-written-into-a-word-file-as-the-copy-the-runtime-labels-on-every-page.md)). A translation's locale the engine's `Intl` cannot write is
202
+ refused as `unsupported-locale`, at the translation that declares it.
203
+
204
+ ## Several tables
205
+
206
+ A report may hold several tables over its detail rows
207
+ ([0062](../../docs/decisions/0062-a-report-holds-several-tables-over-its-detail-rows-each-printing-and-totalling-the-rows-its-condition-selects.md)), and each prints the rows its own condition selects:
208
+
209
+ - **Its condition**, `rowsWhen`, is read once a detail row, in the row's
210
+ scope and the data's order, before anything is ordered, each reading
211
+ within the render's step budget; a table without one has every row.
212
+ One that fails for a row refuses the render (`evaluation`), naming the
213
+ row by its index in the data. A preview whose data lacks a field it
214
+ reads leaves the row out of that table, warned once for the field.
215
+ - **Its order and groups** are `sort-group.ts`'s, over the rows it
216
+ selected, each kept at its index in the data, so an error names the row
217
+ the provider gave and a total reads the right row's value.
218
+ - **Its totals** are the declared aggregates over those rows, by the
219
+ function a group's are, `Totals.over`, rounded once, read as
220
+ `table.<id>` in its total rows and its group's header and footer. A
221
+ table without a condition is handed the report's totals themselves, so
222
+ `table.net` and `totals.net` are one value there, and a report without
223
+ conditions resolves to the document it did. `totals` is every detail
224
+ row's everywhere, under such a table as in the summary, a payment code,
225
+ the e-invoice and a chart.
226
+ - **A table that selects no row** prints its empty text, and its total
227
+ rows beneath it, a count and a sum of nothing 0 and the rest nothing.
228
+
229
+ The document is unchanged: a table is the rows it prints, and the
230
+ renderer draws any number of them.
231
+
232
+ ## A QR-bill
233
+
234
+ A report's payment part resolves to the document's `paymentPart`
235
+ ([0022](../../docs/decisions/0022-a-report-carries-one-swiss-qr-bill-at-the-foot-of-its-last-page.md)): the
236
+ Swiss QR Code's payload, in the order of SIX's Table 8, and every text its
237
+ slip prints -- the headings in its language, the account, the reference
238
+ and the amount grouped as SIX prints them, the addresses line by line. The
239
+ rules a text is held to are report-spec's, the same functions its
240
+ validator applies to a literal. An amount is a decimal, or null for the
241
+ payer to fill in, and is never rounded: one with a third decimal is
242
+ refused. The bill has no "do not use for payment" variant and no
243
+ alternative procedure, and its ultimate creditor is empty, as SIX keeps it
244
+ for later use.
245
+
246
+ ## An EPC QR code
247
+
248
+ An `epcQrCode` component resolves to an `epcQrCode` block
249
+ ([0025](../../docs/decisions/0025-a-report-prints-an-epc-qr-code-held-to-the-epc-rules-beside-the-qr-bill.md)): its id, its
250
+ square, Austria's caption when the template asks for it, and the payload
251
+ of EPC069-12 version 3.1, section 2.2 -- `BCD`, the version, character set
252
+ `1` for UTF-8, `SCT`, then the BIC, the name, the IBAN, the amount in euro,
253
+ the purpose, the reference, the text and the information, each on its own
254
+ line, every element up to the last the code holds a line, empty when it is
255
+ unused, and nothing after the last. A code with a BIC is version `001`, as
256
+ the EPC's first example is: version 3.1 of the guidelines keeps both
257
+ versions, and a code with a BIC is what `001` asks for. One without is
258
+ `002`, the version that lets the BIC be left empty. The EPC's first
259
+ example is written byte for byte; its second, which is in ISO 8859-1, is
260
+ written in UTF-8: character set `1` where the example has
261
+ `2`, and one byte longer for its ç. No other character set is written.
262
+
263
+ Every text is read as a paragraph with the same runs prints it, and held to
264
+ report-spec's rules, the same functions its validator applies to a
265
+ literal: the IBAN's spaces are dropped and its letters made capitals, and
266
+ it must be of a country of SEPA, of that country's length, its check
267
+ digits right, and no QR-IBAN; the BIC, when there is one, a BIC of the
268
+ account's country, and required for an account outside the EEA; the
269
+ reference a creditor reference (ISO 11649), checked as a QR-bill's is and
270
+ written in capitals. Which texts are optional, and what a refusal calls
271
+ each, is report-spec's `EPC_TEXT_FIELDS`. An optional text the data gives
272
+ empty, blank or null is an element the code leaves unused, in a final
273
+ render as in a preview: a nullable field's null is how data says "none".
274
+ A null among runs that print something is refused, as a text cut short. The amount is a decimal,
275
+ or null for the payer to fill in, written as short as it can be --
276
+ `EUR12.3`, `EUR45` -- from 0.01 to 999999999.99, and never rounded: one
277
+ with a third decimal is refused. The whole payload is at most 331 bytes in
278
+ UTF-8, counted in bytes, not in characters.
279
+
280
+ ## A code's symbol
281
+
282
+ What a QR code, an EPC QR code and a QR-bill's Swiss QR Code are drawn
283
+ from, and what each is refused by, is decided here once, for every
284
+ engine
285
+ ([0074](../../docs/decisions/0074-a-qr-code-and-an-epc-qr-code-are-written-into-a-word-file-and-what-refuses-a-code-stands-below-both-engines.md)).
286
+ The document carries a code's text; an engine asks for its symbol when it
287
+ checks the document, once, and draws what it is handed:
288
+
289
+ ```ts
290
+ import { epcSymbol, qrSymbol, swissSymbol } from '@formancy/report-runtime'
291
+
292
+ qrSymbol(code, width) // a `qrCode` block's symbol where it stands `width` points wide
293
+ epcSymbol(code, width) // an `epcQrCode` block's
294
+ swissSymbol(payload) // a QR-bill's Swiss QR Code's
295
+ ```
296
+
297
+ Each returns a `QrSymbol`, the rows of its modules without a quiet zone,
298
+ or throws the `RenderRefusal` an engine refuses the document with, naming
299
+ the code by its id and never quoting what it holds. The text is encoded by
300
+ [uqr](https://github.com/unjs/uqr) 0.1.3, this package's one dependency
301
+ that is not formancy's: as UTF-8 in byte mode, or in the denser modes for
302
+ digits and capitals, in the smallest version that holds it at its level,
303
+ which is never raised.
304
+
305
+ - **A QR code** ([0020](../../docs/decisions/0020-a-qr-code-is-drawn-from-its-own-matrix-and-refused-where-it-may-not-scan.md)) is refused as `unsupported` where its size is
306
+ no positive number, its level none of L, M, Q and H, or its text no
307
+ string or half of a surrogate pair; and as `content-too-large` where it
308
+ is wider than where it stands, holds more than `QR_MAX_CHARACTERS`
309
+ characters, 7089, refused before it is encoded, or more bytes than a
310
+ version holds at its level, or would have modules finer than
311
+ `QR_MIN_MODULE`, 0.4 mm, in its square with its `QR_QUIET_ZONE` of four
312
+ modules a side.
313
+ - **An EPC QR code** ([0025](../../docs/decisions/0025-a-report-prints-an-epc-qr-code-held-to-the-epc-rules-beside-the-qr-bill.md)) is encoded at level M, in version 13 at
314
+ the most, and held to the same square and, without a caption, the same
315
+ floor; with Austria's caption, to the squares report-spec's
316
+ `epcCaptionBreak` prints one in, before it is encoded, and at the least
317
+ version whose modules are the PSA's (`epcLeastVersion`), to that
318
+ version's modules after.
319
+ - **A Swiss QR Code** ([0022](../../docs/decisions/0022-a-report-carries-one-swiss-qr-bill-at-the-foot-of-its-last-page.md)) is encoded at level M, in version 25 at
320
+ the most, and refused past `SWISS_QR_MAX_CHARACTERS`, 997, naming the
321
+ payment part. SIX prints it at 46 mm whatever its version, so it is
322
+ held to no floor.
323
+
324
+ `qrSymbolVersion(symbol)` is the version a symbol is. Whether a page is
325
+ tall enough for a code is an engine's to say: the PDF renderer measures
326
+ its body, and the Word writer its printable area. Resolving a report
327
+ calls none of these: a report whose code is too long for its square
328
+ resolves, and is refused where it is drawn or written.
329
+
330
+ ## A QR-bill's slip
331
+
332
+ What refuses a QR-bill before an engine lays its slip out, and where SIX
333
+ puts each part of the slip, stand here too, below every engine
334
+ ([0075](../../docs/decisions/0075-a-qr-bills-slip-is-written-into-a-word-file-on-a-page-of-its-own-and-every-line-of-it-is-shown-to-fit.md)):
335
+ the PDF renderer draws the slip at the foot of the last page and the
336
+ Word writer on a page of the file's own, from one set of numbers, and
337
+ both refuse the same bills in the same words.
338
+
339
+ `checkQrBill(bill, page, undrawn)` returns the bill with its Swiss QR
340
+ Code's symbol, encoded once, or throws the `RenderRefusal` an engine
341
+ refuses the document with, naming `paymentPart` and the field and never
342
+ quoting a value: a kind nobody knows, a page that is not A4 upright or
343
+ whose top margin reaches into the slip (`refuseBillPage`, report-spec's
344
+ `qrBillPageBreak`), text that is not text, a value longer than any SIX
345
+ allows, an address of other than two or three lines, more than two lines
346
+ of additional information, a currency that is none of
347
+ `QR_BILL_CURRENCIES`, and an amount not written as a slip prints one or
348
+ past SIX's range. `undrawn` is the one thing an engine says itself, since
349
+ only it knows the face it draws in: for a text and the face it prints in
350
+ (`BillFace`, each heading's in `BILL_HEADING_FACES`), the rest of the
351
+ sentence that says what its face does not draw, or nothing.
352
+
353
+ `SLIP_RECEIPT` and `SLIP_PAYMENT_PART` are the two parts as SIX's style
354
+ guide lays them out, in points from the slip's top left: where the
355
+ title, the information and the amount section stand, the sizes of
356
+ headings and values and the pitch of their lines, and the blank fields.
357
+ `slipBlocks(bill, part)` is a part's information in SIX's order, each
358
+ heading over its values or over a blank field. Beside them stand
359
+ `SLIP_RECEIPT_WIDTH`, `SLIP_CODE`, `SLIP_ACCEPTANCE`, `SLIP_INSTRUCTION`,
360
+ `SLIP_SEPARATION`, `SLIP_CORNER`, `SLIP_FIELD_GAP` and `SLIP_TITLE`, and
361
+ the code's `SWISS_CODE_SIZE`, 46 mm, and `SWISS_CROSS`. Resolving a
362
+ report calls none of these.
363
+
364
+ ## An e-invoice
365
+
366
+ A report's `eInvoice` (report-spec's, [0027](../../docs/decisions/0027-a-report-carries-one-en-16931-invoice-written-from-the-values-its-page-prints.md)) resolves, in a final render, to the
367
+ document's `eInvoice`, an `EInvoiceFile` of its kind:
368
+
369
+ - **A Factur-X file** (`FacturXFile`, `kind: 'facturX'`): the CII XML of a
370
+ Factur-X 1.09.2 / ZUGFeRD 2.5.2 invoice in the EN 16931 profile, and what
371
+ the renderer embeds it as, `fileName`, `relationship` and
372
+ `conformanceLevel`, report-spec's `FACTUR_X` and `FACTUR_X_PROFILES` [S].
373
+ - **An XRechnung's file** (`XRechnungFile`, `kind: 'xrechnung'`,
374
+ [0038](../../docs/decisions/0038-a-reports-e-invoice-may-be-an-xrechnung-3-0-whose-xml-a-host-takes-and-whose-pdf-is-its-labelled-copy.md)):
375
+ the CII XML of an XRechnung 3.0, the invoice itself, which a host takes
376
+ from the document and sends -- to a portal, by email or over Peppol, as
377
+ the buyer asks; nothing here sends it -- with its `syntax`, `'cii'`, its
378
+ `guideline`, BT-24, and its `version`, report-spec's `XRECHNUNG`. Its XML
379
+ is the very XML a Factur-X invoice of the same terms is, BT-24 apart: one
380
+ writer. Every page of the document is headed `XRECHNUNG_COPY_LABEL`,
381
+ since a PDF drawn of it is a copy, in the paragraph the runtime exports
382
+ frozen as `XRECHNUNG_COPY_PARAGRAPH`, small, bold and red; the renderer
383
+ draws the document as a plain PDF that embeds nothing, and refuses one
384
+ whose page header, or page 1's own header where it has one, does not
385
+ open with that paragraph, style and all.
386
+
387
+ ```ts
388
+ const resolution = resolveReport(xrechnung, data, { mode: 'final', creationDate })
389
+ if (resolution.ok && resolution.document.eInvoice?.kind === 'xrechnung') send(resolution.document.eInvoice.xml)
390
+ ```
391
+
392
+ - **The lines are the table's.** Each row of the table the e-invoice names
393
+ is a line. The four columns it names -- the item, the quantity, the net
394
+ price and the net amount -- are read once for every row, before the
395
+ totals, and the table prints the value kept, so the page and the XML read
396
+ one evaluation of each line, in the order the table prints them. The
397
+ line's identifier, unit and VAT category are read from each row. A net
398
+ amount is refused unless it is its quantity times its net price, rounded
399
+ once to the cent, as EN 16931 defines it and Mustang recomputes it; a
400
+ line identifier unless no earlier line has it; and a quantity or a net
401
+ price that its column's format prints at fewer places than it has.
402
+ - **The totals are computed once, here** (`e-invoice-totals.ts`), in
403
+ `Decimal`: the sum of the lines, each category's basis, its tax -- the
404
+ basis times the rate over 100, rounded once to two places, half away from
405
+ zero, per category and never per line -- the VAT, the total with it, and
406
+ the amount due: the total less what was paid. The page reads them as
407
+ `invoice`, `vatBasis` and `vatAmount`, the very values the XML is written
408
+ from; a category no line is in is null, and has no breakdown in the XML.
409
+ - **Every text is held to EN 16931's rules**, report-spec's functions, the
410
+ ones its validator applies to a literal, once the data has resolved it:
411
+ a code from its closed list, a VAT identifier's prefix, an IBAN and a
412
+ BIC, a day on the calendar, a net price not below zero, a net amount of
413
+ whole cents, never rounded, a category the invoice declares, a character
414
+ XML can hold, and no white space a token collapses in an identifier or a
415
+ code the XML writes as one, and a contact's telephone number and email
416
+ address to XRechnung's shapes, and an electronic address under 0204 to a
417
+ Leitweg-ID's shape and check digits. An XRechnung's texts are held to its
418
+ kind's rules: each term XRechnung needs is needed, the contact's three
419
+ among them, and its payment terms hold no line led by `#`, which
420
+ XRechnung reads as its Skonto syntax. An optional text that prints nothing is
421
+ left out -- the business process, an electronic address with its scheme,
422
+ and the contact whole where it has none of its three, though a contact
423
+ given in part is refused at each term it lacks, since a contact gives
424
+ all three or none
425
+ ([0037](../../docs/decisions/0037-an-e-invoice-may-name-electronic-addresses-the-sellers-contact-and-its-business-process-none-needed-for-german-b2b.md)); a needed one is
426
+ refused by the rule that needs it; one that prints something around a
427
+ null is refused as cut short. What only the whole says -- the seller's
428
+ and the buyer's identifiers, the time of supply, an exempt category's
429
+ reason -- is said of the categories the lines are in.
430
+ - **A payment code printed with it** -- the QR-bill, an EPC QR code -- asks
431
+ for the amount due, or leaves the amount to the payer, and to be paid to
432
+ the e-invoice's account, compared by value once both have resolved.
433
+ - **The XML** is written one way (`xml.ts`, `cii.ts`, `cii-parties.ts`):
434
+ its declaration, no byte order mark, a line feed after each line, two
435
+ spaces a level, each element in the profile XSD's order at the path
436
+ CEN's binding gives its term, amounts at two places from their own
437
+ digits, dates as format 102. Text is escaped, a carriage return as a
438
+ reference so that a parser gives it back; a character XML 1.0 cannot hold
439
+ is refused where it is read. The same report and data are the same
440
+ bytes.
441
+ - **A copy, where a host asks for one**
442
+ ([0077](../../docs/decisions/0077-a-report-that-carries-an-e-invoice-is-written-into-a-word-file-as-the-copy-the-runtime-labels-on-every-page.md)).
443
+ `resolveReport(report, data, { mode: 'final', eInvoice: 'copy' })`
444
+ resolves the same final render as its copy: the page header, and page
445
+ 1's own where the report has one, each open with the copy's label, the
446
+ manifest says `eInvoice: 'copy'`, and the document carries no
447
+ `eInvoice`, so nothing can embed or send an invoice from it. It is
448
+ what a Word file is written of. The terms are held and the XML written
449
+ as for the invoice, then dropped, so a copy is refused wherever the
450
+ invoice is. The label says that the page is a copy, what the invoice
451
+ is -- the PDF that embeds its XML, of a Factur-X, or its XML, of an
452
+ XRechnung, whose copy carries this label in the place of
453
+ `XRECHNUNG_COPY_LABEL` -- and that this document is not it, in the
454
+ language of the render's locale: `E_INVOICE_COPY_LABELS`, written in
455
+ `E_INVOICE_COPY_LANGUAGES`, German, English, Spanish, French, Italian
456
+ and Dutch, four of which no native speaker has read.
457
+ `eInvoiceCopyParagraph(kind, locale)` is the paragraph as the runtime
458
+ writes it, frozen, and `readCopyLabel(header)` says which label a
459
+ header opens with and whether it stands as written, which is how an
460
+ engine knows a copy. Refused, `no-e-invoice-copy`: a copy of a preview,
461
+ which writes no XML to be a copy of; a copy in a language no label is
462
+ written in, at the locale; and any other value of the option. Of a
463
+ report that carries no e-invoice the option says nothing.
464
+ - **A preview is not the invoice.** It prints the totals of what it has,
465
+ takes a term it has no value for as one it lacks and holds what the data
466
+ does give to the rules; it writes no XML, warns `e-invoice-preview`, and
467
+ labels every page, `E_INVOICE_PREVIEW_LABEL` where nothing else is
468
+ lacking and `PREVIEW_LABEL` where data is.
469
+
470
+ At `MAX_DETAIL_ROWS` the XML is large: 100,000 lines of short names wrote
471
+ 117,280,919 bytes, 1,173 a line, and `resolveReport` took a median of 5.4
472
+ seconds, against 2.0 for the same report and rows without the e-invoice;
473
+ 10,000 lines wrote 11,710,910 bytes in a median of 0.44 seconds, against
474
+ 0.23 (five runs each, from the built package, Node 24.21.0, an Intel
475
+ i9-10900K, 17 October 2026). The e-invoice has no bound of its own yet.
476
+
477
+ ## A chart
478
+
479
+ A `chart` component resolves to a `chart` block (`Chart`, an `AxisChart`
480
+ or a `PieChart`), which holds every word the chart prints and every number
481
+ as its exact digits beside its text
482
+ ([0055](../../docs/decisions/0055-the-runtime-resolves-a-chart-exactly-its-totals-as-every-total-and-every-word-it-prints.md),
483
+ [0052](../../docs/decisions/0052-a-report-draws-a-bar-line-or-pie-chart-of-its-detail-rows-each-series-a-total-of-one-field-per-category.md)):
484
+
485
+ ```ts
486
+ // A bar chart of sales by region, beside a table grouped by region, in a format of two places:
487
+ const chart = resolution.document.body.find((block) => block.kind === 'chart')
488
+ if (chart?.kind === 'chart' && chart.chart !== 'pie' && chart.empty === undefined) {
489
+ chart.categories // ['North', 'South', 'No region']: each key in the category's format, the rows without one under nullLabel
490
+ chart.series[0]?.values[0] // { exact: '10.25', text: '10.25' }: a coordinate from exact, the text printed; null where a series has no value
491
+ chart.ticks.map(({ text }) => text) // ['0.00', '5.00', '10.00', '15.00', '20.00', '25.00']: the value axis, fixed
492
+ }
493
+ ```
494
+
495
+ - **Its categories** are grouped where a table's rows are: sorted by the
496
+ table's own order, the rows without one last, or in the order the data
497
+ first gives each, one key each, so that 1.0 and 1.00 are one category,
498
+ printed with no format as its first row in the data's order spells it.
499
+ The rows without a category are one category under its `nullLabel`. A
500
+ chart with no `nullLabel`, possible only over a field that may not be
501
+ null, prints an empty label in a preview that lacks the field, the data
502
+ check having warned; one with a label prints its label.
503
+ - **Each series** is totalled by `totalOf`, the function every aggregate
504
+ and every group's total is, in the decimals report-core's `seriesType`
505
+ gives an aggregate of the same function over the same field: a bar
506
+ prints what the table's group footer of the same rows prints in the same
507
+ format, a declared rounding applied once, and a rounding of an integer
508
+ total refused as `rounding-not-decimal`, as an aggregate's is.
509
+ - **The value axis** of a bar or a line chart is one, two or five times a
510
+ power of ten, the finest step that covers every value of every series
511
+ in at most `MAX_TICK_INTERVALS` intervals and no finer than the value
512
+ format prints, found by BigInt division. A bar's axis holds zero, and
513
+ so does a flat line's; any other line's is ticked over its own range.
514
+ An author cannot set either.
515
+ - **A pie's share** of each slice is its exact ratio to the sum of its
516
+ slices as they are totalled, rounded once, half away from zero, to
517
+ `SHARE_PLACES` places of a percentage, and printed by the formatter's
518
+ `percent`, which refuses a fraction Intl would round again
519
+ (`percent-rounds-again`), as no share is. Shares need not add up to
520
+ 100.0 %, and a legend entry that labels its value reads
521
+ `label: value (share)` in every language. A slice's value prints only
522
+ in its legend entry, and a pie whose values its format cannot print is
523
+ refused though it labels none of them.
524
+ - **Nothing to draw** -- no rows, a bar or a line chart with no value, a
525
+ pie whose values are all zero -- is the chart's title and its empty text
526
+ alone, with no axis and no axis title.
527
+ - **Its colours** are the chart's own `palette` or `CHART_PALETTE`, a
528
+ series' at its place and a slice's at its category's.
529
+
530
+ A renderer prints the block's strings and no others, a pie's values only
531
+ in its legend, makes a coordinate of a value's `exact`, and formats no
532
+ number. This release's renderer does not
533
+ draw a chart yet, and refuses one.
534
+
535
+ ## Page 1's own header
536
+
537
+ A report whose regions hold `firstPageHeader` gives page 1 a header of its
538
+ own, which page 1 prints in place of the page header
539
+ ([0060](../../docs/decisions/0060-a-reports-first-page-may-print-a-header-of-its-own-or-none-in-place-of-the-page-header.md)).
540
+ The document carries it as `firstPageHeader`, beside `pageHeader`, present
541
+ exactly when the report's is:
542
+
543
+ - **Lowered as the page header is**, each component to the block it
544
+ prints, a component whose condition does not hold left out; one whose
545
+ every component is hidden is an empty list, page 1 with no header, never
546
+ the page header's blocks: the choice is the report's, not the data's.
547
+ - **An empty list is none.** Page 1 prints no header, and its body starts
548
+ at the top margin. A report without the region resolves to a document
549
+ without the key, as it always did.
550
+ - **Labelled as the page header is.** A preview's label, an e-invoice
551
+ preview's and an XRechnung's `XRECHNUNG_COPY_PARAGRAPH` head it too,
552
+ each header with a paragraph of its own, so that page 1 says it as every
553
+ page does; page 1's header that is none is the label alone.
554
+ - **No page field.** report-spec refuses a page number or count in it,
555
+ since the renderer draws it before the pages are counted; which page
556
+ prints which header is the renderer's to decide, and nothing here
557
+ evaluates anything per page.
558
+
559
+ ## A run below or above the line
560
+
561
+ A paragraph's run carries the `baseline` its report's run sets,
562
+ `subscript` or `superscript`, a field's, a parameter's, an expression's
563
+ and an aggregate's value as literal text's, and a run that sets none
564
+ carries no key, so the document of a report that sets none is the one it
565
+ was ([0061](../../docs/decisions/0061-a-paragraphs-run-may-be-set-below-or-above-the-line-in-any-character-its-face-draws-and-prints-only-beside-a-run-on-the-line.md)).
566
+ A table's cell joins its runs into one string, as before, where
567
+ report-spec refuses a baseline. What such a run prints as is the
568
+ document's, for any engine:
569
+
570
+ ```ts
571
+ import { SHIFTED_RISE, SHIFTED_SIZE } from '@formancy/report-runtime'
572
+
573
+ SHIFTED_SIZE // 0.58: the run's size, of its paragraph's, in the paragraph's face
574
+ SHIFTED_RISE // { superscript: 0.75 * 0.58, subscript: -0.35 * 0.58 }: its baseline's move, of the paragraph's size, up positive
575
+ ```
576
+
577
+ They are pdfmake 0.3.11's own figures, 0.435 up and 0.203 down, which
578
+ the renderer has pdfmake draw and the corpus reads a PDF by: a renderer
579
+ that drew another fails there. `BASELINE_SHIFTS` and `BaselineShift` are
580
+ report-spec's, handed on, so that the format and the document name a
581
+ shift alike.
72
582
 
73
583
  ## What else is exported
74
584
 
75
585
  Each stage is exported for a host or a tool that needs one alone:
76
586
  `checkReport`, `checkData`, `checkParameters`, `readValue`,
77
- `prepareExpressions`, `createFormatter`, `orderTable` and the decimal
78
- arithmetic. The document's types, `RenderRefusal` and `REFUSAL_CODES` are
79
- the renderer's contract, declared here so that no engine defines them.
587
+ `isSubmissionId`, `prepareExpressions`, `createFormatter`, `orderTable`
588
+ -- given the rows a table's condition selected, as its optional fourth
589
+ argument, those alone, each kept at its index in the data (0062) -- and
590
+ the decimal arithmetic; the form bridge reads `readValue`,
591
+ `MAX_STRING_LENGTH`, `isSubmissionId` and `SUBMISSION_ID_SYNTAX`, the
592
+ words a refusal says that rule in, so that it holds an answer and an id
593
+ by this package's rules, and says them in its words, rather than a copy
594
+ of them (0042). `checkReport(report, locale?)` checks a report for a
595
+ render in a locale and hands back both the copy validation read and
596
+ `printed`, that copy written in the locale; `checkData` checks data
597
+ against the printed copy, told the report's own locale by
598
+ `reportLocale` (0063). The document's types, `RenderRefusal` and `REFUSAL_CODES` are
599
+ the renderer's contract, declared here so that no engine defines them; a
600
+ chart's among them, and `MAX_CHART_CATEGORIES`, `MAX_TICK_INTERVALS` and
601
+ `SHARE_PLACES`, the runtime's bounds on a chart, which a host that tells an
602
+ author of them reads rather than copies (0055), with report-spec's
603
+ `MAX_CHART_SERIES` beside them, which the renderer holds a chart's block to;
604
+ and `MAX_KEEP_WITH_ROWS`, report-spec's bound on the rows a group header
605
+ row keeps, is handed on for an engine to hold that row to (0059).
606
+ What report-spec decides of a QR-bill that an engine needs to draw its
607
+ slip is handed on as report-spec's own objects: `QR_BILL_SIZE` and
608
+ `QR_BILL_TOP`, the slip's size and place; `qrBillPageBreak` and its type
609
+ `QrBillPageBreak`, the page it is printed on; `QR_BILL_CURRENCIES`;
610
+ `checkQrBillAmount`, the amounts a bill pays; and
611
+ `MAX_QR_BILL_ADDITIONAL_INFORMATION`, the longest value SIX allows. So is
612
+ what report-spec decides of how an EPC QR code is printed:
613
+ `EPC_MAX_BYTES` and `EPC_MAX_VERSION`, the most bytes and the largest
614
+ version the EPC allows; `qrSymbolModules`
615
+ and `epcModule`, the modules a symbol has and the side of one in a square;
616
+ and `EPC_FRAME`, `EPC_CAPTION`, `EPC_CAPTION_MODULE`, `epcLeastVersion`
617
+ and `epcCaptionBreak`, Austria's frame and caption, the modules' widths
618
+ they are printed at and the least version that prints them. And of how an
619
+ e-invoice is embedded: `FACTUR_X`, the file's name and media type and the
620
+ XMP's namespace, prefix, document type and version, and
621
+ `FACTUR_X_PROFILES`, each profile's specification identifier,
622
+ conformance level and relationship [S]; and of what an XRechnung's file
623
+ says it is: `XRECHNUNG` and `XRECHNUNG_VERSIONS`, each version's
624
+ specification identifier, release and syntax (0038). And of an SVG asset
625
+ ([0030](../../docs/decisions/0030-an-image-asset-may-be-an-svg-of-drawing-elements-alone-cleaned-once-and-refused-at-print-in-any-other-form.md)):
626
+ `checkSvg`, which accepts only the drawing `cleanSvg` writes and says what
627
+ it costs to draw and how far the numbers the converter writes for it reach
628
+ (`SvgExtent`); `cleanSvg` itself, for a host that approves assets beside
629
+ its render code; `SVG_REFUSAL_CODES`; `SVG_ELEMENTS`, the elements an
630
+ approved drawing is written with, which an engine's own guard is held to;
631
+ `MAX_SVG_BYTES`; `MAX_SVG_SEGMENTS` and `MAX_SVG_GROUPS`, what a page
632
+ may cost a reader to paint; and `MAX_SVG_COORDINATE` and `MAX_SVG_DEPTH`,
633
+ from which an engine derives how far its arithmetic may stray from that
634
+ extent. And of an image's bytes, where a builder reads them when a person
635
+ adds an image (0033): `MAX_ASSET_BYTES`, the most an asset may have, which
636
+ this package held before and report-spec holds now, exported under the same
637
+ name; `MAX_ASSET_SIDE`, the most pixels a side of a PNG or a JPEG;
638
+ `sniffImage`, what bytes are by their first bytes; and `imageHeader` with
639
+ `IMAGE_REFUSAL_CODES`, a PNG's or a JPEG's structure, read whole but for a
640
+ PNG's image data, which an engine inflates itself. And of a font's bytes
641
+ ([0040](../../docs/decisions/0040-a-font-is-read-by-report-specs-own-reader-which-says-what-it-may-be-embedded-as-and-which-characters-it-draws.md)):
642
+ `readFont`, a font read whole or refused, for a host that approves fonts
643
+ beside its render code; `characterMap`, the characters a face maps as
644
+ fontkit maps them, which an engine reads its own faces with;
645
+ `FONT_REFUSAL_CODES`, `FONT_FORMATS` and `FONT_EMBEDDING_REFUSALS`; and
646
+ `MAX_FONT_BYTES` and `MAX_FONT_CHARACTERS`; `MIN_FONT_LINE` and
647
+ `MAX_FONT_LINE`, the line in ems a face may lay out, and `MIN_FONT_SIZE` and
648
+ `MAX_FONT_SIZE`, the sizes a report's text is set at, which an engine's page
649
+ bound counts a line by; and `PRINTED_BLOCKS`,
650
+ `BIDI_CONTROLS` and `refusedCharacter`, the characters a report prints,
651
+ Latin, Greek and Cyrillic and what is written with them (0043). An engine
652
+ depends on the runtime alone, and draws and refuses by the one decision the
653
+ editor refuses by.
654
+
655
+ A report that **maps** a font token to a host's font resolves to the bytes
656
+ the engine embeds ([0043](../../docs/decisions/0043-a-report-maps-its-font-tokens-to-fonts-the-host-approved-pinned-by-digest-and-the-renderer-embeds-them.md)):
657
+ `resolveReport` asks the host's lookup -- the image resolver, widened and
658
+ renamed `AssetResolver`, with `ImageResolver` kept as an alias -- for each
659
+ face by id and digest, reads its bytes with `readFont` before it hands them
660
+ on, and refuses the render where a mapped face cannot be had, is past
661
+ `MAX_FONT_BYTES`, which it holds before it copies the bytes, or the reader
662
+ refuses it, in a preview too. `ResolvedDocument.fonts` holds each token's
663
+ faces, bytes and all.
80
664
 
81
665
  ## What it does not do
82
666
 
83
667
  - **Fetch anything.** The data and the asset bytes are the host's to hand
84
668
  over; the runtime reads no database and follows no address.
85
- - **Check an image's digest.** It has no hash function without Node or the
86
- DOM; the host's lookup is trusted to return the bytes the digest pins.
669
+ - **Check an image's digest.** The host's lookup is trusted to return the
670
+ bytes the digest pins. Not for want of a hash: a pure SHA-256,
671
+ `@noble/hashes`', reaches the runtime through `@formancy/spec`, and
672
+ report-spec's `assetDigest` names an added image by it; checking
673
+ digests changes what every host's resolver must satisfy, and is a
674
+ decision of its own
675
+ ([0030](../../docs/decisions/0030-an-image-asset-may-be-an-svg-of-drawing-elements-alone-cleaned-once-and-refused-at-print-in-any-other-form.md)).
676
+ So what prints of an SVG is in the approved form, and that it is the
677
+ approved drawing is the host's to keep.
87
678
  - **Format with one engine's results everywhere.** Grouping marks, month
88
679
  names and currency symbols are the engine's ICU's, so the same report can
89
680
  print differently on two engines.
681
+ - **Embed an e-invoice, make a PDF/A, or send an XRechnung.** It writes a
682
+ Factur-X invoice's XML and names the file; the engine embeds it, changed
683
+ in nothing, in the PDF/A-3b it draws
684
+ ([0031](../../docs/decisions/0031-an-e-invoice-is-drawn-as-a-pdf-a-3b-that-embeds-its-xml.md)).
685
+ An XRechnung's XML no engine embeds: the host takes it from the
686
+ document and sends it, and nothing here sends it (0038).
687
+ - **Encode a QR code.** It hands the engine the text a QR code's content
688
+ prints, formatted as a paragraph with the same content prints it, and a
689
+ QR-bill's and an EPC QR code's payloads; the engine encodes and draws
690
+ them, lays the slip out, and frames and captions the EPC QR code.
90
691
  - **Compile once per render.** Each expression is compiled twice: once by
91
692
  `diagnose`, once to evaluate.
92
693