@formancy/report-render-pdf 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +161 -0
- package/NOTICE +9 -0
- package/README.md +182 -2
- package/dist/browser.d.mts +12 -0
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.mjs +64 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +56 -0
- package/dist/index.mjs.map +1 -0
- package/dist/options-wLxIWA87.d.mts +24 -0
- package/dist/options-wLxIWA87.d.mts.map +1 -0
- package/dist/render-Bs7DXIYJ.mjs +1943 -0
- package/dist/render-Bs7DXIYJ.mjs.map +1 -0
- package/package.json +53 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Formancy Report Source-Available Licence
|
|
2
|
+
|
|
3
|
+
**Version 1 — in force from 14 October 2026. Not reviewed by a lawyer.**
|
|
4
|
+
|
|
5
|
+
This text states the terms Formancy Report is offered under. Version 1 is in
|
|
6
|
+
force from 14 October 2026. Its terms are those of the Formancy Data
|
|
7
|
+
Source-Available Licence, Version 1.1, with this product's names and with the
|
|
8
|
+
documents a reporting product generates named as yours. **This version has
|
|
9
|
+
not been reviewed by a lawyer.** It is published in the repository so that
|
|
10
|
+
the terms are visible to everyone who reads the source. Production licences,
|
|
11
|
+
which section 3 describes, can be had as section 9 says.
|
|
12
|
+
|
|
13
|
+
This is not an open-source licence. It is not Apache-2.0, and it is not the
|
|
14
|
+
licence of [formancy](https://github.com/sharkysan/formancy.ai), on which this
|
|
15
|
+
software builds and whose packages keep their own Apache-2.0 terms.
|
|
16
|
+
|
|
17
|
+
## The terms in one table
|
|
18
|
+
|
|
19
|
+
| Use | Terms |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| Read the source and fork the repository | Free |
|
|
22
|
+
| Evaluate, develop and test — including in companies | Free |
|
|
23
|
+
| Run in production, internally or customer-facing | Paid licence |
|
|
24
|
+
| Redistribute inside another software product | Separate commercial agreement |
|
|
25
|
+
| Customer data, report templates and generated documents | Remain the customer's |
|
|
26
|
+
|
|
27
|
+
The rest of this document says what each row means.
|
|
28
|
+
|
|
29
|
+
## 1. Definitions
|
|
30
|
+
|
|
31
|
+
**The Software** means the source code, declarations, documentation and
|
|
32
|
+
packages in this repository and the packages published from it under the
|
|
33
|
+
`@formancy/report-*` names, in any version, including modified versions.
|
|
34
|
+
|
|
35
|
+
**The Rightsholder** means Daniel Bacher, or whoever the Rightsholder later
|
|
36
|
+
designates in a revision of this document.
|
|
37
|
+
|
|
38
|
+
**Production Use** means running the Software, or anything that incorporates
|
|
39
|
+
it, in a way that serves real end users or real business operations: an
|
|
40
|
+
application people other than its developers and testers rely on, whether
|
|
41
|
+
inside one organisation or offered to others, whether or not it earns money.
|
|
42
|
+
Production is defined by operational use, not by revenue.
|
|
43
|
+
|
|
44
|
+
**Development Use** means any use that is not Production Use: reading,
|
|
45
|
+
evaluating, building, modifying, testing, demonstrating and running in
|
|
46
|
+
development, test, staging and continuous-integration environments, including
|
|
47
|
+
by and within a commercial organisation. A staging environment that real
|
|
48
|
+
users depend on is Production Use whatever it is called.
|
|
49
|
+
|
|
50
|
+
**Redistribution** means delivering the Software, or anything that
|
|
51
|
+
incorporates it, to a third party as part of a software product, a managed
|
|
52
|
+
service, a platform or a toolkit, such that the third party runs it rather
|
|
53
|
+
than you.
|
|
54
|
+
|
|
55
|
+
**Customer Data** means the contents of any dataset, submission, database or
|
|
56
|
+
file the Software is given or connects to, and anything the Software reads
|
|
57
|
+
from or writes to it.
|
|
58
|
+
|
|
59
|
+
**Generated Definitions** means the report definitions, templates, bindings,
|
|
60
|
+
styles, parameter forms, policies and other configuration the Software
|
|
61
|
+
generates or that a person creates with it, and the documents rendered from
|
|
62
|
+
them, PDF files included.
|
|
63
|
+
|
|
64
|
+
## 2. What is free
|
|
65
|
+
|
|
66
|
+
Subject to section 4, the Rightsholder grants you a worldwide, royalty-free,
|
|
67
|
+
non-exclusive licence to:
|
|
68
|
+
|
|
69
|
+
1. read, copy, fork and modify the Software;
|
|
70
|
+
2. use the Software and your modifications for Development Use, without limit
|
|
71
|
+
of time, number of people or size of organisation;
|
|
72
|
+
3. share the Software and your modifications with others for their
|
|
73
|
+
Development Use, under this licence and with this document attached.
|
|
74
|
+
|
|
75
|
+
No production licence is required to evaluate the Software for as long as you
|
|
76
|
+
like, and no evaluation period expires.
|
|
77
|
+
|
|
78
|
+
## 3. What is paid
|
|
79
|
+
|
|
80
|
+
**Production Use requires a production licence from the Rightsholder.** A
|
|
81
|
+
production licence is a separate written agreement. It is expected to be
|
|
82
|
+
granted per application, to cover that application's development, test and
|
|
83
|
+
replica environments without further charge, to specify support and update
|
|
84
|
+
entitlements, and to leave you the right to keep running the versions you
|
|
85
|
+
licensed if you later choose not to renew. Those are intentions; the agreement
|
|
86
|
+
you sign is what governs.
|
|
87
|
+
|
|
88
|
+
**Redistribution requires a separate commercial agreement.** Shipping the
|
|
89
|
+
Software inside a product, a platform or a managed service that other parties
|
|
90
|
+
run is not covered by a production licence for your own applications.
|
|
91
|
+
|
|
92
|
+
Running the Software in production without a production licence is a breach of
|
|
93
|
+
this licence.
|
|
94
|
+
|
|
95
|
+
## 4. Conditions
|
|
96
|
+
|
|
97
|
+
1. **Notices travel.** A copy of this document, and the NOTICE file, stays
|
|
98
|
+
with every copy and every modified version of the Software.
|
|
99
|
+
2. **Modified versions carry these terms.** A modified version of the Software
|
|
100
|
+
is the Software for the purposes of this licence. You may not remove or
|
|
101
|
+
circumvent the terms by modifying it.
|
|
102
|
+
3. **No trademark grant.** This licence grants no right to use the names
|
|
103
|
+
"Formancy", "Formancy Report", "Formancy Report Studio", "formancy.ai" or
|
|
104
|
+
any associated logo, beyond what is needed to identify the Software
|
|
105
|
+
truthfully.
|
|
106
|
+
4. **Third-party components keep their own licences.** The Software depends on
|
|
107
|
+
packages licensed under the Apache License, Version 2.0, among others. Those
|
|
108
|
+
licences continue to govern those components, their notices are preserved
|
|
109
|
+
in NOTICE, and nothing in this document narrows the rights they grant.
|
|
110
|
+
|
|
111
|
+
## 5. What stays yours
|
|
112
|
+
|
|
113
|
+
**Customer Data remains the customer's.** This licence grants the Rightsholder
|
|
114
|
+
no right of any kind over the data the Software is given or reads, and the
|
|
115
|
+
Software is designed not to send any of it anywhere.
|
|
116
|
+
|
|
117
|
+
**Generated Definitions remain yours.** Report definitions, templates,
|
|
118
|
+
bindings and policies you generate or author with the Software, and the
|
|
119
|
+
documents rendered from them, are yours, under whatever terms you choose.
|
|
120
|
+
They are not the Software, and this licence does not restrict them —
|
|
121
|
+
including after a production licence ends. A logo, a font or another asset
|
|
122
|
+
you place in a report keeps the rights it came with.
|
|
123
|
+
|
|
124
|
+
## 6. Contributions
|
|
125
|
+
|
|
126
|
+
Contributions to the Software are accepted under the Contributor License
|
|
127
|
+
Agreement in `CLA.md`, which grants the Rightsholder the right to distribute
|
|
128
|
+
them under this licence and under commercial agreements, and transfers no
|
|
129
|
+
ownership.
|
|
130
|
+
|
|
131
|
+
## 7. Termination
|
|
132
|
+
|
|
133
|
+
Your rights under this licence end automatically if you breach it and do not
|
|
134
|
+
cure the breach within thirty days of becoming aware of it. The rights in
|
|
135
|
+
section 5 do not end: your data, your definitions and your documents stay
|
|
136
|
+
yours in every case.
|
|
137
|
+
|
|
138
|
+
## 8. No warranty, limited liability
|
|
139
|
+
|
|
140
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
141
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
142
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
143
|
+
RIGHTSHOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
144
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
145
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
146
|
+
|
|
147
|
+
A production licence may provide warranties and support; this document does
|
|
148
|
+
not.
|
|
149
|
+
|
|
150
|
+
## 9. Obtaining a production licence
|
|
151
|
+
|
|
152
|
+
Production licences are requested from the Rightsholder at info@formancy.ai.
|
|
153
|
+
The separate commercial agreement that Redistribution requires, which
|
|
154
|
+
section 3 describes, is requested at the same address. The Software is new
|
|
155
|
+
and has no published price; the plan is to set the price after the first
|
|
156
|
+
design partners have established what the Software is worth to them.
|
|
157
|
+
|
|
158
|
+
## 10. Governing law and place of jurisdiction
|
|
159
|
+
|
|
160
|
+
This licence is governed by Swiss law, excluding its conflict-of-laws rules.
|
|
161
|
+
The place of jurisdiction is the Rightsholder's domicile in Switzerland.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Formancy Report
|
|
2
|
+
Copyright 2026 Daniel Bacher
|
|
3
|
+
|
|
4
|
+
This product is distributed under the Formancy Report Source-Available Licence
|
|
5
|
+
(LICENSE.md). It is not open source.
|
|
6
|
+
|
|
7
|
+
This product includes software developed by the formancy project
|
|
8
|
+
(https://github.com/sharkysan/formancy.ai), licensed under the Apache License,
|
|
9
|
+
Version 2.0. Those packages keep their licence; nothing here changes it.
|
package/README.md
CHANGED
|
@@ -1,3 +1,183 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @formancy/report-render-pdf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Formancy Report PDF renderer: it draws a resolved report with
|
|
4
|
+
[pdfmake](https://github.com/bpampuch/pdfmake), and refuses what it cannot
|
|
5
|
+
draw whole rather than return a truncated or partial PDF. It takes the
|
|
6
|
+
renderer-neutral document `@formancy/report-runtime` resolves a report to,
|
|
7
|
+
with the approved asset bytes already in it, and never a database
|
|
8
|
+
connection, a file name or an address. Why pdfmake, and what its adapter
|
|
9
|
+
has to work around, is decision
|
|
10
|
+
[0005](../../docs/decisions/0005-pdfmake-renders-reports-behind-one-adapter.md);
|
|
11
|
+
what the renderer refuses beyond it, and why, is
|
|
12
|
+
[0011](../../docs/decisions/0011-report-render-pdf-draws-the-document-and-refuses-what-it-cannot.md).
|
|
13
|
+
|
|
14
|
+
## Render
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { renderPdf, RenderRefusal } from '@formancy/report-render-pdf'
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const pdf: Uint8Array = await renderPdf(document, { maxPages: 200, signal })
|
|
21
|
+
// the whole report, every page of it
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (!(error instanceof RenderRefusal)) throw error // the engine failing, not the report
|
|
24
|
+
// error.code says what stopped it; error.subject names the asset, table
|
|
25
|
+
// or block, such as 'logo' or 'body[3].blocks[0]', when it is about one
|
|
26
|
+
console.warn(`${error.code}: ${error.message}`)
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`renderPdf` resolves to the PDF's bytes, or rejects with a `RenderRefusal`.
|
|
31
|
+
A refusal is decided before the PDF is written: a refused report has no
|
|
32
|
+
PDF at all. Anything else it rejects with is a fault, and a `maxPages` that
|
|
33
|
+
is not a whole number of pages, at least 1, is the caller's: a `RangeError`.
|
|
34
|
+
|
|
35
|
+
The same document renders to the same bytes: the creation date is the
|
|
36
|
+
document's own (`info.creationDate`), and nothing else in the file varies.
|
|
37
|
+
|
|
38
|
+
## Node and the browser
|
|
39
|
+
|
|
40
|
+
| Entry | pdfmake | Fonts |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| `@formancy/report-render-pdf` | the Node build | the four Roboto files in pdfmake's package, read from disk |
|
|
43
|
+
| `@formancy/report-render-pdf/browser` | the browser build, `pdfmake/build/pdfmake.js` | the same Roboto, from pdfmake's `build/vfs_fonts.js` |
|
|
44
|
+
|
|
45
|
+
The two entries share everything but the build of pdfmake and where the
|
|
46
|
+
fonts come from: the checks, the measuring passes and the document
|
|
47
|
+
definitions are one module both import. The browser entry touches no file
|
|
48
|
+
system and imports no `node:` module.
|
|
49
|
+
|
|
50
|
+
What the tests show about the browser entry, run in Node: for every fixture
|
|
51
|
+
in the corpus it hands pdfmake the definitions the Node entry does, its PDFs
|
|
52
|
+
pass the corpus's checks, it places every run and image where the Node entry
|
|
53
|
+
does, and it reaches no Node module. What they do not show is the browser
|
|
54
|
+
build in a browser. That is the Studio's browser gate's to check, and it
|
|
55
|
+
does not exist yet.
|
|
56
|
+
|
|
57
|
+
pdfmake is one configuration per process, or per page in a browser: fonts
|
|
58
|
+
and access policies are global to it. The renderer sets its own again
|
|
59
|
+
before every render, so a host that configures pdfmake for something else
|
|
60
|
+
cannot change what a report renders with. The cost runs the other way too:
|
|
61
|
+
after a report, the renderer's configuration is in place.
|
|
62
|
+
|
|
63
|
+
## What it draws
|
|
64
|
+
|
|
65
|
+
Every block of the resolved document:
|
|
66
|
+
|
|
67
|
+
- **Paragraphs**, in their size, weight, slant, colour and alignment, and
|
|
68
|
+
a run in bold inside a paragraph that is not.
|
|
69
|
+
- **Tables**, their header row repeated on every page they span, each row
|
|
70
|
+
in its kind's style or its own, each cell in its own when it has one, each
|
|
71
|
+
column aligned as it says unless a cell says otherwise. A group header
|
|
72
|
+
`across` the table is one cell over every column. A group header is never
|
|
73
|
+
the last row on a page, and a row that fits on a page is never split. A
|
|
74
|
+
group's footers and the totals under the last row stand on the page of
|
|
75
|
+
the row before them, and with its group header when that row is its
|
|
76
|
+
group's first: a subtotal or a total never stands alone at the top of a
|
|
77
|
+
page. Every column is as wide as it says, a fill column its share of
|
|
78
|
+
what the fixed ones leave, never wider for a long word in it.
|
|
79
|
+
- **Images**, in a box the layout reserves whole: `contain` draws all of
|
|
80
|
+
the image at its proportions, as large as the box allows, centred in it;
|
|
81
|
+
`cover` fills the box, centred, and is clipped to it. A JPEG is fitted by
|
|
82
|
+
the size it is shown at, after its Exif orientation.
|
|
83
|
+
- **Rules**, at their thickness and colour, across the width they stand in,
|
|
84
|
+
with 3 pt above and below.
|
|
85
|
+
- **Rectangles**, filled, outlined or both, their outline drawn inside the
|
|
86
|
+
box at half a point.
|
|
87
|
+
- **Columns**, side by side at their widths, with no gap but what the widths
|
|
88
|
+
leave; a column longer than the page continues on the next.
|
|
89
|
+
- **Sections**: with a border, a fill or padding, a frame drawn around the
|
|
90
|
+
part of the section on each page, its blocks laid out inside it as in the
|
|
91
|
+
body, tables and page breaks included; without one, its blocks and nothing
|
|
92
|
+
more.
|
|
93
|
+
- **Keep-together blocks**, moved whole to the next page when they do not
|
|
94
|
+
fit, and paragraphs **kept with the next** block.
|
|
95
|
+
- **The page header and footer**, on every page, with the page number and
|
|
96
|
+
the page count. The body is laid out between them, after both are
|
|
97
|
+
measured.
|
|
98
|
+
|
|
99
|
+
## What it refuses
|
|
100
|
+
|
|
101
|
+
| Code | When |
|
|
102
|
+
|---|---|
|
|
103
|
+
| `too-many-pages` | The report needs more pages than `maxPages`. pdfmake's own limit would return the first pages as though they were all of it. A body whose least height already needs more is refused before pdfmake measures it. |
|
|
104
|
+
| `content-too-large` | Something no page can hold: a keep-together block, an image, a rectangle, a rule, a frame's border and padding, or a line of text taller than the body where it stands; anything wider than where it stands; a word in a table cell wider than its column, or a word in a paragraph longer than 16 lines of it; images holding more than 268,443,648 bytes of image data together; page regions that leave no body. |
|
|
105
|
+
| `invalid-asset` | An image's bytes are not the PNG or JPEG they are declared as, are cut off, or are past the limits: 20 MB, 4096 pixels a side. |
|
|
106
|
+
| `cancelled` | The signal was aborted. |
|
|
107
|
+
| `unsupported` | What the renderer cannot draw as written: a character the font has no glyph for, a font other than `sans`, text that is not a string, a colour that is not `#rrggbb` in lower case, a page field outside the page header and footer, a page break inside a page region, a keep-together block or a column, a table inside a column, a table row of the wrong number of cells, a block kind, page size or page field it does not know, blocks nested past 16 deep. |
|
|
108
|
+
|
|
109
|
+
## Fonts
|
|
110
|
+
|
|
111
|
+
Every report prints in **Roboto 3.014**, from pdfmake's own package, under
|
|
112
|
+
the SIL Open Font License 1.1, which allows embedding fonts in documents.
|
|
113
|
+
The dependency-licence guard reads that licence from the font files
|
|
114
|
+
themselves ([0006](../../docs/decisions/0006-dependencies-and-fonts-allow-public-source-and-licensed-production.md)).
|
|
115
|
+
The browser entry's copy in `vfs_fonts.js` is base64 inside a script, which
|
|
116
|
+
the guard cannot read; a test holds it to the very bytes of those files.
|
|
117
|
+
Each PDF embeds the subset of each face it uses.
|
|
118
|
+
|
|
119
|
+
- `sans` is Roboto. **`serif` and `mono` are refused** as `unsupported`:
|
|
120
|
+
pdfmake ships no serif or monospaced font, and printing one in Roboto would
|
|
121
|
+
be a substitution nobody sees until they read the PDF. They need fonts
|
|
122
|
+
whose licence the guard allows, and none is shipped yet.
|
|
123
|
+
- Bold is **Roboto Medium**, the heaviest face pdfmake ships, and italic is
|
|
124
|
+
Roboto Italic.
|
|
125
|
+
- **Every character is held to the face it prints in**, read from the
|
|
126
|
+
faces' own character maps, and one without a glyph is refused as
|
|
127
|
+
`unsupported`, naming the block and the code point: pdfmake would print
|
|
128
|
+
it as an empty box, and as U+0000 in the PDF's text. One font means no
|
|
129
|
+
fallback: CJK, Hebrew, Arabic, Thai and emoji are refused, and so is an
|
|
130
|
+
fr-FR amount, which Intl groups with a narrow no-break space (U+202F)
|
|
131
|
+
that Roboto lacks. Swiss amounts, de-CH and fr-CH alike, print.
|
|
132
|
+
|
|
133
|
+
## What it does not do
|
|
134
|
+
|
|
135
|
+
- **Cancel inside a pass.** pdfmake measures, lays out and writes a
|
|
136
|
+
document in one synchronous step. The render yields to the event loop
|
|
137
|
+
between passes, so an abort from a timer or a closed request arrives, and
|
|
138
|
+
it reads the signal before the first pass, between passes, and before the
|
|
139
|
+
PDF is returned: a cancelled render resolves nothing, but a pass under way
|
|
140
|
+
runs to its end. A host that must stop at once runs renders in a worker
|
|
141
|
+
it can terminate.
|
|
142
|
+
- **Bound measuring by the page limit, always.** A body whose least height
|
|
143
|
+
needs more pages than the limit is refused before pdfmake sees it; one
|
|
144
|
+
that fits its least height and not its real one is measured whole first.
|
|
145
|
+
- **Break a word in a table cell.** A number or an identifier broken across
|
|
146
|
+
lines reads as two, so a cell's word wider than its column is refused,
|
|
147
|
+
and the template gives the column the width.
|
|
148
|
+
- **Keep a paragraph with the next block everywhere.** Not inside a
|
|
149
|
+
keep-together block, a column or a page region, and not past the end of a
|
|
150
|
+
framed section: a heading that ends a framed section is not kept with
|
|
151
|
+
what follows it.
|
|
152
|
+
- **Refuse a spacer at the foot of a page.** One that does not fit what is
|
|
153
|
+
left of a page moves to the next and starts there, without its space.
|
|
154
|
+
- **Measure page regions per page.** They are measured once, every page
|
|
155
|
+
field printed as `maxPages`, so a region that wraps only for some page
|
|
156
|
+
numbers is measured at its widest.
|
|
157
|
+
- **Decode a JPEG's scan.** Its structure is checked, up to the scan, and a
|
|
158
|
+
corrupt scan inside a well-formed JPEG reaches the PDF. A PNG's image data
|
|
159
|
+
is inflated and checked; data with bytes after its zlib stream is refused,
|
|
160
|
+
as the Compression Streams standard refuses it.
|
|
161
|
+
|
|
162
|
+
## Tests
|
|
163
|
+
|
|
164
|
+
`pnpm --filter @formancy/report-render-pdf test` renders every fixture of
|
|
165
|
+
`@formancy/report-corpus` and proves each PDF with the corpus's checks, or
|
|
166
|
+
holds a refusal to the one the fixture allows
|
|
167
|
+
([0003](../../docs/decisions/0003-a-rendered-report-is-proved-on-the-pdf-it-produced.md)).
|
|
168
|
+
These are the tests decision 0005 names. Each block kind is read back from
|
|
169
|
+
the PDF it produced: its text and images with PDF.js, through the corpus's
|
|
170
|
+
reader, and its lines, rectangles, clips and text colours from the PDF's own
|
|
171
|
+
content streams (`src/testing/drawing.ts`), which PDF.js's text does not
|
|
172
|
+
show. `starters.test.ts` resolves the three starters with the runtime and
|
|
173
|
+
proves their PDFs, swept across page ends.
|
|
174
|
+
|
|
175
|
+
`scripts/readme-pictures.ts` draws the repository README's pictures of the
|
|
176
|
+
starters with PDF.js, and `pictures.test.ts` holds each to the text of the
|
|
177
|
+
page it was drawn from:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
pnpm --filter @formancy/report-render-pdf exec unrun scripts/readme-pictures.ts
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Source-available, not open source: see [`LICENSE.md`](../../LICENSE.md).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as RenderOptions } from "./options-wLxIWA87.mjs";
|
|
2
|
+
import { REFUSAL_CODES, RefusalCode, RenderRefusal, ResolvedDocument, ResolvedDocument as ResolvedDocument$1 } from "@formancy/report-runtime";
|
|
3
|
+
//#region src/browser.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Renders `document` to a PDF in a browser, or rejects with a
|
|
6
|
+
* `RenderRefusal` saying why it was not printed, exactly as the Node entry
|
|
7
|
+
* does: the same refusals, the same pages.
|
|
8
|
+
*/
|
|
9
|
+
export declare function renderPdf(document: ResolvedDocument$1, options: RenderOptions): Promise<Uint8Array>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { REFUSAL_CODES, type RefusalCode, type RenderOptions, RenderRefusal, type ResolvedDocument };
|
|
12
|
+
//# sourceMappingURL=browser.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.mts","names":["ResolvedDocument"],"sources":["../src/browser.ts"],"mappings":";;;;;;;;wBA4DgB,UAAU,UAAUA,oBAAkB,SAAS,gBAAgB,QAAQ"}
|
package/dist/browser.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { i as glyphsOnce, n as fromBase64, r as collect, t as render } from "./render-Bs7DXIYJ.mjs";
|
|
2
|
+
import { REFUSAL_CODES, RenderRefusal } from "@formancy/report-runtime";
|
|
3
|
+
import pdfmake from "pdfmake/build/pdfmake.js";
|
|
4
|
+
import vfs from "pdfmake/build/vfs_fonts.js";
|
|
5
|
+
//#region src/browser.ts
|
|
6
|
+
/**
|
|
7
|
+
* The renderer in a browser: pdfmake's browser build, with Roboto 3.014
|
|
8
|
+
* from pdfmake's `vfs_fonts.js`, which carries the four font files of
|
|
9
|
+
* pdfmake's package as base64 -- the same bytes, which a test holds, so the
|
|
10
|
+
* same OFL-1.1 fonts the dependency-licence guard reads (0006). Nothing here
|
|
11
|
+
* touches a file system: the fonts are pdfmake's virtual files, and every
|
|
12
|
+
* address is denied.
|
|
13
|
+
*
|
|
14
|
+
* Everything but the fonts and the build is the Node entry's own
|
|
15
|
+
* (`render.ts`), so the two hand pdfmake the same definitions.
|
|
16
|
+
*
|
|
17
|
+
* The fonts go into pdfmake's virtual file system under names of the
|
|
18
|
+
* renderer's own, so that a host's files of the same name and the renderer's
|
|
19
|
+
* cannot replace each other, and they and the font table are set again
|
|
20
|
+
* before every document, as in Node: pdfmake is one configuration per page.
|
|
21
|
+
*/
|
|
22
|
+
const FILES = {
|
|
23
|
+
normal: "Roboto-Regular.ttf",
|
|
24
|
+
bold: "Roboto-Medium.ttf",
|
|
25
|
+
italics: "Roboto-Italic.ttf",
|
|
26
|
+
bolditalics: "Roboto-MediumItalic.ttf"
|
|
27
|
+
};
|
|
28
|
+
const own = (file) => `formancy-report-render-pdf/${file}`;
|
|
29
|
+
function fontFiles() {
|
|
30
|
+
return Object.fromEntries(Object.values(FILES).map((file) => {
|
|
31
|
+
const data = vfs[file];
|
|
32
|
+
if (data === void 0) throw new Error(`pdfmake's vfs_fonts.js has no ${file}`);
|
|
33
|
+
return [own(file), data];
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
const FONTS = { Roboto: {
|
|
37
|
+
normal: own(FILES.normal),
|
|
38
|
+
bold: own(FILES.bold),
|
|
39
|
+
italics: own(FILES.italics),
|
|
40
|
+
bolditalics: own(FILES.bolditalics)
|
|
41
|
+
} };
|
|
42
|
+
async function run(definition) {
|
|
43
|
+
pdfmake.addVirtualFileSystem(fontFiles());
|
|
44
|
+
pdfmake.setFonts(FONTS);
|
|
45
|
+
pdfmake.setUrlAccessPolicy(() => false);
|
|
46
|
+
return collect(await pdfmake.createPdf(definition).getStream());
|
|
47
|
+
}
|
|
48
|
+
/** pdfmake's browser build, and the glyphs of the very virtual files it embeds. */
|
|
49
|
+
const engine = {
|
|
50
|
+
run,
|
|
51
|
+
glyphs: glyphsOnce((face) => Promise.resolve(fromBase64(vfs[FILES[face]])))
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Renders `document` to a PDF in a browser, or rejects with a
|
|
55
|
+
* `RenderRefusal` saying why it was not printed, exactly as the Node entry
|
|
56
|
+
* does: the same refusals, the same pages.
|
|
57
|
+
*/
|
|
58
|
+
function renderPdf(document, options) {
|
|
59
|
+
return render(engine, document, options);
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { REFUSAL_CODES, RenderRefusal, renderPdf };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.mjs","names":[],"sources":["../src/browser.ts"],"sourcesContent":["import pdfmake from 'pdfmake/build/pdfmake.js'\nimport vfs from 'pdfmake/build/vfs_fonts.js'\nimport type { TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport type { ResolvedDocument } from '@formancy/report-runtime'\nimport { fromBase64 } from './bytes.js'\nimport { collect, glyphsOnce, type Engine, type PdfStream } from './engine.js'\nimport type { RenderOptions } from './options.js'\nimport { render } from './render.js'\n\nexport { REFUSAL_CODES, RenderRefusal } from '@formancy/report-runtime'\nexport type { RefusalCode, ResolvedDocument } from '@formancy/report-runtime'\nexport type { RenderOptions } from './options.js'\n\n/**\n * The renderer in a browser: pdfmake's browser build, with Roboto 3.014\n * from pdfmake's `vfs_fonts.js`, which carries the four font files of\n * pdfmake's package as base64 -- the same bytes, which a test holds, so the\n * same OFL-1.1 fonts the dependency-licence guard reads (0006). Nothing here\n * touches a file system: the fonts are pdfmake's virtual files, and every\n * address is denied.\n *\n * Everything but the fonts and the build is the Node entry's own\n * (`render.ts`), so the two hand pdfmake the same definitions.\n *\n * The fonts go into pdfmake's virtual file system under names of the\n * renderer's own, so that a host's files of the same name and the renderer's\n * cannot replace each other, and they and the font table are set again\n * before every document, as in Node: pdfmake is one configuration per page.\n */\n\nconst FILES = { normal: 'Roboto-Regular.ttf', bold: 'Roboto-Medium.ttf', italics: 'Roboto-Italic.ttf', bolditalics: 'Roboto-MediumItalic.ttf' } as const\nconst own = (file: string): string => `formancy-report-render-pdf/${file}`\n\nfunction fontFiles(): Record<string, string> {\n return Object.fromEntries(\n Object.values(FILES).map((file) => {\n const data = vfs[file]\n if (data === undefined) throw new Error(`pdfmake's vfs_fonts.js has no ${file}`)\n return [own(file), data]\n }),\n )\n}\n\nconst FONTS = { Roboto: { normal: own(FILES.normal), bold: own(FILES.bold), italics: own(FILES.italics), bolditalics: own(FILES.bolditalics) } }\n\nasync function run(definition: TDocumentDefinitions): Promise<Uint8Array> {\n pdfmake.addVirtualFileSystem(fontFiles())\n pdfmake.setFonts(FONTS)\n pdfmake.setUrlAccessPolicy(() => false)\n return collect((await pdfmake.createPdf(definition).getStream()) as unknown as PdfStream)\n}\n\n/** pdfmake's browser build, and the glyphs of the very virtual files it embeds. */\nconst engine: Engine = { run, glyphs: glyphsOnce((face) => Promise.resolve(fromBase64(vfs[FILES[face]] as string))) }\n\n/**\n * Renders `document` to a PDF in a browser, or rejects with a\n * `RenderRefusal` saying why it was not printed, exactly as the Node entry\n * does: the same refusals, the same pages.\n */\nexport function renderPdf(document: ResolvedDocument, options: RenderOptions): Promise<Uint8Array> {\n return render(engine, document, options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,QAAQ;CAAE,QAAQ;CAAsB,MAAM;CAAqB,SAAS;CAAqB,aAAa;AAA0B;AAC9I,MAAM,OAAO,SAAyB,8BAA8B;AAEpE,SAAS,YAAoC;CAC3C,OAAO,OAAO,YACZ,OAAO,OAAO,KAAK,CAAC,CAAC,KAAK,SAAS;EACjC,MAAM,OAAO,IAAI;EACjB,IAAI,SAAS,KAAA,GAAW,MAAM,IAAI,MAAM,iCAAiC,MAAM;EAC/E,OAAO,CAAC,IAAI,IAAI,GAAG,IAAI;CACzB,CAAC,CACH;AACF;AAEA,MAAM,QAAQ,EAAE,QAAQ;CAAE,QAAQ,IAAI,MAAM,MAAM;CAAG,MAAM,IAAI,MAAM,IAAI;CAAG,SAAS,IAAI,MAAM,OAAO;CAAG,aAAa,IAAI,MAAM,WAAW;AAAE,EAAE;AAE/I,eAAe,IAAI,YAAuD;CACxE,QAAQ,qBAAqB,UAAU,CAAC;CACxC,QAAQ,SAAS,KAAK;CACtB,QAAQ,yBAAyB,KAAK;CACtC,OAAO,QAAS,MAAM,QAAQ,UAAU,UAAU,CAAC,CAAC,UAAU,CAA0B;AAC1F;;AAGA,MAAM,SAAiB;CAAE;CAAK,QAAQ,YAAY,SAAS,QAAQ,QAAQ,WAAW,IAAI,MAAM,MAAgB,CAAC,CAAC;AAAE;;;;;;AAOpH,SAAgB,UAAU,UAA4B,SAA6C;CACjG,OAAO,OAAO,QAAQ,UAAU,OAAO;AACzC"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { t as RenderOptions } from "./options-wLxIWA87.mjs";
|
|
2
|
+
import { REFUSAL_CODES, RefusalCode, RenderRefusal, ResolvedDocument, ResolvedDocument as ResolvedDocument$1 } from "@formancy/report-runtime";
|
|
3
|
+
//#region src/node.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Renders `document` to a PDF, or rejects with a `RenderRefusal` saying why
|
|
6
|
+
* it was not printed: `too-many-pages`, `content-too-large`,
|
|
7
|
+
* `invalid-asset`, `cancelled` or `unsupported`. A refused render returns
|
|
8
|
+
* nothing, never a truncated or partial PDF. The same document renders to
|
|
9
|
+
* the same bytes.
|
|
10
|
+
*/
|
|
11
|
+
export declare function renderPdf(document: ResolvedDocument$1, options: RenderOptions): Promise<Uint8Array>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { REFUSAL_CODES, type RefusalCode, type RenderOptions, RenderRefusal, type ResolvedDocument };
|
|
14
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["ResolvedDocument"],"sources":["../src/node.ts"],"mappings":";;;;;;;;;;wBAkDgB,UAAU,UAAUA,oBAAkB,SAAS,gBAAgB,QAAQ"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { i as glyphsOnce, r as collect, t as render } from "./render-Bs7DXIYJ.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import pdfmake from "pdfmake";
|
|
6
|
+
import { REFUSAL_CODES, RenderRefusal } from "@formancy/report-runtime";
|
|
7
|
+
//#region src/node.ts
|
|
8
|
+
/**
|
|
9
|
+
* The renderer in Node: pdfmake's Node build, reading Roboto 3.014 from the
|
|
10
|
+
* four font files in pdfmake's own package -- which the dependency-licence
|
|
11
|
+
* guard reads as OFL-1.1 (0006) -- and no other file, and no address at all.
|
|
12
|
+
* The renderer reads the same four files once, for the characters they have
|
|
13
|
+
* glyphs for (`glyphs.ts`).
|
|
14
|
+
*
|
|
15
|
+
* pdfmake is one configuration per process. It is set again before every
|
|
16
|
+
* document, in the same synchronous step as `createPdf`, which reads it, so
|
|
17
|
+
* that nothing else in the process that configures pdfmake can change the
|
|
18
|
+
* fonts or the access policies a render runs with. The cost runs the other
|
|
19
|
+
* way too: a host that uses pdfmake for something of its own finds this
|
|
20
|
+
* configuration in place after every report.
|
|
21
|
+
*/
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const pdfmakeDirectory = path.dirname(require.resolve("pdfmake/package.json"));
|
|
24
|
+
const roboto = (file) => path.join(pdfmakeDirectory, "fonts", "Roboto", file).split(path.sep).join("/");
|
|
25
|
+
const FONTS = { Roboto: {
|
|
26
|
+
normal: roboto("Roboto-Regular.ttf"),
|
|
27
|
+
bold: roboto("Roboto-Medium.ttf"),
|
|
28
|
+
italics: roboto("Roboto-Italic.ttf"),
|
|
29
|
+
bolditalics: roboto("Roboto-MediumItalic.ttf")
|
|
30
|
+
} };
|
|
31
|
+
const FONT_FILES = new Set(Object.values(FONTS.Roboto));
|
|
32
|
+
async function run(definition) {
|
|
33
|
+
pdfmake.setFonts(FONTS);
|
|
34
|
+
pdfmake.setUrlAccessPolicy(() => false);
|
|
35
|
+
pdfmake.setLocalAccessPolicy((file) => FONT_FILES.has(file));
|
|
36
|
+
return collect(await pdfmake.createPdf(definition).getStream());
|
|
37
|
+
}
|
|
38
|
+
/** pdfmake in Node, and the glyphs of the very font files it embeds. */
|
|
39
|
+
const engine = {
|
|
40
|
+
run,
|
|
41
|
+
glyphs: glyphsOnce(async (face) => new Uint8Array(await readFile(FONTS.Roboto[face])))
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Renders `document` to a PDF, or rejects with a `RenderRefusal` saying why
|
|
45
|
+
* it was not printed: `too-many-pages`, `content-too-large`,
|
|
46
|
+
* `invalid-asset`, `cancelled` or `unsupported`. A refused render returns
|
|
47
|
+
* nothing, never a truncated or partial PDF. The same document renders to
|
|
48
|
+
* the same bytes.
|
|
49
|
+
*/
|
|
50
|
+
function renderPdf(document, options) {
|
|
51
|
+
return render(engine, document, options);
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { REFUSAL_CODES, RenderRefusal, renderPdf };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/node.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport path from 'node:path'\nimport pdfmake from 'pdfmake'\nimport type { TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport type { ResolvedDocument } from '@formancy/report-runtime'\nimport { collect, glyphsOnce, type Engine, type PdfStream } from './engine.js'\nimport type { RenderOptions } from './options.js'\nimport { render } from './render.js'\n\n/**\n * The renderer in Node: pdfmake's Node build, reading Roboto 3.014 from the\n * four font files in pdfmake's own package -- which the dependency-licence\n * guard reads as OFL-1.1 (0006) -- and no other file, and no address at all.\n * The renderer reads the same four files once, for the characters they have\n * glyphs for (`glyphs.ts`).\n *\n * pdfmake is one configuration per process. It is set again before every\n * document, in the same synchronous step as `createPdf`, which reads it, so\n * that nothing else in the process that configures pdfmake can change the\n * fonts or the access policies a render runs with. The cost runs the other\n * way too: a host that uses pdfmake for something of its own finds this\n * configuration in place after every report.\n */\n\nconst require = createRequire(import.meta.url)\nconst pdfmakeDirectory = path.dirname(require.resolve('pdfmake/package.json'))\nconst roboto = (file: string): string => path.join(pdfmakeDirectory, 'fonts', 'Roboto', file).split(path.sep).join('/')\nconst FONTS = {\n Roboto: { normal: roboto('Roboto-Regular.ttf'), bold: roboto('Roboto-Medium.ttf'), italics: roboto('Roboto-Italic.ttf'), bolditalics: roboto('Roboto-MediumItalic.ttf') },\n}\nconst FONT_FILES: ReadonlySet<string> = new Set(Object.values(FONTS.Roboto))\n\nasync function run(definition: TDocumentDefinitions): Promise<Uint8Array> {\n pdfmake.setFonts(FONTS)\n pdfmake.setUrlAccessPolicy(() => false)\n pdfmake.setLocalAccessPolicy((file) => FONT_FILES.has(file))\n return collect((await pdfmake.createPdf(definition).getStream()) as unknown as PdfStream)\n}\n\n/** pdfmake in Node, and the glyphs of the very font files it embeds. */\nconst engine: Engine = { run, glyphs: glyphsOnce(async (face) => new Uint8Array(await readFile(FONTS.Roboto[face]))) }\n\n/**\n * Renders `document` to a PDF, or rejects with a `RenderRefusal` saying why\n * it was not printed: `too-many-pages`, `content-too-large`,\n * `invalid-asset`, `cancelled` or `unsupported`. A refused render returns\n * nothing, never a truncated or partial PDF. The same document renders to\n * the same bytes.\n */\nexport function renderPdf(document: ResolvedDocument, options: RenderOptions): Promise<Uint8Array> {\n return render(engine, document, options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,UAAU,cAAc,YAAY,GAAG;AAC7C,MAAM,mBAAmB,KAAK,QAAQ,QAAQ,QAAQ,sBAAsB,CAAC;AAC7E,MAAM,UAAU,SAAyB,KAAK,KAAK,kBAAkB,SAAS,UAAU,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG;AACtH,MAAM,QAAQ,EACZ,QAAQ;CAAE,QAAQ,OAAO,oBAAoB;CAAG,MAAM,OAAO,mBAAmB;CAAG,SAAS,OAAO,mBAAmB;CAAG,aAAa,OAAO,yBAAyB;AAAE,EAC1K;AACA,MAAM,aAAkC,IAAI,IAAI,OAAO,OAAO,MAAM,MAAM,CAAC;AAE3E,eAAe,IAAI,YAAuD;CACxE,QAAQ,SAAS,KAAK;CACtB,QAAQ,yBAAyB,KAAK;CACtC,QAAQ,sBAAsB,SAAS,WAAW,IAAI,IAAI,CAAC;CAC3D,OAAO,QAAS,MAAM,QAAQ,UAAU,UAAU,CAAC,CAAC,UAAU,CAA0B;AAC1F;;AAGA,MAAM,SAAiB;CAAE;CAAK,QAAQ,WAAW,OAAO,SAAS,IAAI,WAAW,MAAM,SAAS,MAAM,OAAO,KAAK,CAAC,CAAC;AAAE;;;;;;;;AASrH,SAAgB,UAAU,UAA4B,SAA6C;CACjG,OAAO,OAAO,QAAQ,UAAU,OAAO;AACzC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/options.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* What a caller passes `renderPdf`, in a module of its own: the package's
|
|
4
|
+
* published types import nothing of pdfmake's, whose types are a
|
|
5
|
+
* devDependency a consumer does not install.
|
|
6
|
+
*/
|
|
7
|
+
interface RenderOptions {
|
|
8
|
+
/** The most pages the PDF may have. A document that needs more is refused with `too-many-pages`, never cut short. */
|
|
9
|
+
readonly maxPages: number;
|
|
10
|
+
/**
|
|
11
|
+
* Cancels the render: it rejects with `cancelled` and resolves nothing.
|
|
12
|
+
* The render yields to the event loop between its passes, so that an
|
|
13
|
+
* abort from a timer or a closed request can arrive, and reads the signal
|
|
14
|
+
* before the first pass, between passes and once more before the PDF is
|
|
15
|
+
* returned. A pass itself -- pdfmake measuring and laying out a whole
|
|
16
|
+
* document, a second or more for a long one -- runs in one synchronous
|
|
17
|
+
* step that no signal can interrupt; a host that must stop a render at
|
|
18
|
+
* once runs it in a worker it can terminate.
|
|
19
|
+
*/
|
|
20
|
+
readonly signal?: AbortSignal;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { RenderOptions as t };
|
|
24
|
+
//# sourceMappingURL=options-wLxIWA87.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-wLxIWA87.d.mts","names":[],"sources":["../src/options.ts"],"mappings":";;;;;;UAKiB;;WAEN;;;;;;;;;;;WAWA,SAAS"}
|