@formancy/report-render-pdf 0.1.0 → 0.2.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 +447 -14
- package/dist/bill-fonts-CFSgj0iW.mjs +18 -0
- package/dist/bill-fonts-CFSgj0iW.mjs.map +1 -0
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.mjs +54 -13
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +30 -15
- package/dist/index.mjs.map +1 -1
- package/dist/render-DkPoADDg.mjs +3228 -0
- package/dist/render-DkPoADDg.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 +9 -7
- package/dist/render-Bs7DXIYJ.mjs +0 -1943
- package/dist/render-Bs7DXIYJ.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bill-fonts-CFSgj0iW.mjs","names":["regular"],"sources":["../src/bill-fonts.ts"],"sourcesContent":["import bold from '../fonts/LiberationSans-Bold.ttf'\nimport regular from '../fonts/LiberationSans-Regular.ttf'\n\n/**\n * Liberation Sans 2.1.5's two faces as base64, for the browser entry's\n * virtual files: the bytes of the package's own `fonts` directory, which the\n * build writes into a chunk of their own (`font-plugin.ts`, in tsdown's\n * build and in Vitest's tests). The browser entry imports this module the first\n * time a document has a payment part, never before, so that a host that\n * never prints a bill never loads it.\n */\nexport const LIBERATION_SANS = { normal: regular, bold } as const\n"],"mappings":";;;;;;;;;;AAWA,MAAa,kBAAkB;CAAE,QAAQA;CAAS,MAAA;AAAK"}
|
package/dist/browser.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.mts","names":["ResolvedDocument"],"sources":["../src/browser.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"browser.d.mts","names":["ResolvedDocument"],"sources":["../src/browser.ts"],"mappings":";;;;;;;;wBAqGgB,UAAU,UAAUA,oBAAkB,SAAS,gBAAgB,QAAQ"}
|
package/dist/browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { a as FACES, c as loadOnce, i as BILL_FACES, l as written, n as LIBERATION_SANS, o as glyphsOf, r as fromBase64, s as glyphsOnce, t as render } from "./render-DkPoADDg.mjs";
|
|
2
2
|
import { REFUSAL_CODES, RenderRefusal } from "@formancy/report-runtime";
|
|
3
3
|
import pdfmake from "pdfmake/build/pdfmake.js";
|
|
4
4
|
import vfs from "pdfmake/build/vfs_fonts.js";
|
|
@@ -9,7 +9,19 @@ import vfs from "pdfmake/build/vfs_fonts.js";
|
|
|
9
9
|
* pdfmake's package as base64 -- the same bytes, which a test holds, so the
|
|
10
10
|
* same OFL-1.1 fonts the dependency-licence guard reads (0006). Nothing here
|
|
11
11
|
* touches a file system: the fonts are pdfmake's virtual files, and every
|
|
12
|
-
* address is denied.
|
|
12
|
+
* address is denied. An e-invoice's PDF/A output intent is the ICC profile
|
|
13
|
+
* the browser build carries as base64 (`build/pdfmake.js` 20777), the very
|
|
14
|
+
* bytes of PDFKit's file, which `browser.test.ts` holds.
|
|
15
|
+
*
|
|
16
|
+
* A QR-bill's slip and an EPC QR code's caption print in Liberation Sans
|
|
17
|
+
* 2.1.5, whose two faces come as base64 in a module of their own
|
|
18
|
+
* (`bill-fonts.ts`), the very bytes of this package's `fonts` directory,
|
|
19
|
+
* which a test holds too. It is imported the first time a document has a
|
|
20
|
+
* payment part or a captioned EPC QR code, and never otherwise: the build
|
|
21
|
+
* makes it a chunk of its own, and an app's bundler loads that chunk only
|
|
22
|
+
* when a bill or a caption asks for it. An import that failed is not kept:
|
|
23
|
+
* the document it failed for fails, and the next one imports the chunk
|
|
24
|
+
* again.
|
|
13
25
|
*
|
|
14
26
|
* Everything but the fonts and the build is the Node entry's own
|
|
15
27
|
* (`render.ts`), so the two hand pdfmake the same definitions.
|
|
@@ -25,30 +37,59 @@ const FILES = {
|
|
|
25
37
|
italics: "Roboto-Italic.ttf",
|
|
26
38
|
bolditalics: "Roboto-MediumItalic.ttf"
|
|
27
39
|
};
|
|
40
|
+
const BILL_FILES = {
|
|
41
|
+
normal: "LiberationSans-Regular.ttf",
|
|
42
|
+
bold: "LiberationSans-Bold.ttf"
|
|
43
|
+
};
|
|
28
44
|
const own = (file) => `formancy-report-render-pdf/${file}`;
|
|
45
|
+
/** Liberation Sans's faces as base64, once a document with a bill or a captioned code has loaded them. */
|
|
46
|
+
let billFonts;
|
|
47
|
+
/**
|
|
48
|
+
* Liberation Sans's glyphs, from the faces in the chunk that carries them:
|
|
49
|
+
* imported by the first document with a bill or a captioned code and kept
|
|
50
|
+
* once they have been read, and imported again by the next such document
|
|
51
|
+
* after an import that failed, which would otherwise fail every bill and
|
|
52
|
+
* caption until the page reloaded (`loadOnce`).
|
|
53
|
+
*/
|
|
54
|
+
const billGlyphs = loadOnce(async () => {
|
|
55
|
+
const { LIBERATION_SANS: faces } = await import("./bill-fonts-CFSgj0iW.mjs");
|
|
56
|
+
const glyphs = await glyphsOf(BILL_FACES, async (face) => fromBase64(faces[face]));
|
|
57
|
+
billFonts = faces;
|
|
58
|
+
return glyphs;
|
|
59
|
+
});
|
|
29
60
|
function fontFiles() {
|
|
30
|
-
|
|
61
|
+
const roboto = Object.values(FILES).map((file) => {
|
|
31
62
|
const data = vfs[file];
|
|
32
63
|
if (data === void 0) throw new Error(`pdfmake's vfs_fonts.js has no ${file}`);
|
|
33
64
|
return [own(file), data];
|
|
34
|
-
})
|
|
65
|
+
});
|
|
66
|
+
const loaded = billFonts;
|
|
67
|
+
const liberation = loaded === void 0 ? [] : BILL_FACES.map((face) => [own(BILL_FILES[face]), loaded[face]]);
|
|
68
|
+
return Object.fromEntries([...roboto, ...liberation]);
|
|
35
69
|
}
|
|
36
|
-
const FONTS = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
const FONTS = {
|
|
71
|
+
Roboto: {
|
|
72
|
+
normal: own(FILES.normal),
|
|
73
|
+
bold: own(FILES.bold),
|
|
74
|
+
italics: own(FILES.italics),
|
|
75
|
+
bolditalics: own(FILES.bolditalics)
|
|
76
|
+
},
|
|
77
|
+
[LIBERATION_SANS]: {
|
|
78
|
+
normal: own(BILL_FILES.normal),
|
|
79
|
+
bold: own(BILL_FILES.bold)
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
async function run(definition, finish) {
|
|
43
83
|
pdfmake.addVirtualFileSystem(fontFiles());
|
|
44
84
|
pdfmake.setFonts(FONTS);
|
|
45
85
|
pdfmake.setUrlAccessPolicy(() => false);
|
|
46
|
-
return
|
|
86
|
+
return written(pdfmake.createPdf(definition).getStream(), finish);
|
|
47
87
|
}
|
|
48
88
|
/** pdfmake's browser build, and the glyphs of the very virtual files it embeds. */
|
|
49
89
|
const engine = {
|
|
50
90
|
run,
|
|
51
|
-
glyphs: glyphsOnce((face) => Promise.resolve(fromBase64(vfs[FILES[face]])))
|
|
91
|
+
glyphs: glyphsOnce(FACES, (face) => Promise.resolve(fromBase64(vfs[FILES[face]]))),
|
|
92
|
+
billGlyphs
|
|
52
93
|
};
|
|
53
94
|
/**
|
|
54
95
|
* Renders `document` to a PDF in a browser, or rejects with a
|
package/dist/browser.mjs.map
CHANGED
|
@@ -1 +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 {
|
|
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 { BILL_FACES, FACES, glyphsOf, glyphsOnce, loadOnce, written, type Engine } from './engine.js'\nimport type { BillFace } from './glyphs.js'\nimport type { RenderOptions } from './options.js'\nimport type { Finish } from './pdfa.js'\nimport { render } from './render.js'\nimport { LIBERATION_SANS } from './style.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. An e-invoice's PDF/A output intent is the ICC profile\n * the browser build carries as base64 (`build/pdfmake.js` 20777), the very\n * bytes of PDFKit's file, which `browser.test.ts` holds.\n *\n * A QR-bill's slip and an EPC QR code's caption print in Liberation Sans\n * 2.1.5, whose two faces come as base64 in a module of their own\n * (`bill-fonts.ts`), the very bytes of this package's `fonts` directory,\n * which a test holds too. It is imported the first time a document has a\n * payment part or a captioned EPC QR code, and never otherwise: the build\n * makes it a chunk of its own, and an app's bundler loads that chunk only\n * when a bill or a caption asks for it. An import that failed is not kept:\n * the document it failed for fails, and the next one imports the chunk\n * again.\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 BILL_FILES = { normal: 'LiberationSans-Regular.ttf', bold: 'LiberationSans-Bold.ttf' } as const\nconst own = (file: string): string => `formancy-report-render-pdf/${file}`\n\n/** Liberation Sans's faces as base64, once a document with a bill or a captioned code has loaded them. */\nlet billFonts: Readonly<Record<BillFace, string>> | undefined\n\n/**\n * Liberation Sans's glyphs, from the faces in the chunk that carries them:\n * imported by the first document with a bill or a captioned code and kept\n * once they have been read, and imported again by the next such document\n * after an import that failed, which would otherwise fail every bill and\n * caption until the page reloaded (`loadOnce`).\n */\nconst billGlyphs = loadOnce(async () => {\n const { LIBERATION_SANS: faces } = await import('./bill-fonts.js')\n const glyphs = await glyphsOf(BILL_FACES, async (face) => fromBase64(faces[face]))\n billFonts = faces\n return glyphs\n})\n\nfunction fontFiles(): Record<string, string> {\n const roboto = 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] as const\n })\n const loaded = billFonts\n const liberation = loaded === undefined ? [] : BILL_FACES.map((face) => [own(BILL_FILES[face]), loaded[face]] as const)\n return Object.fromEntries([...roboto, ...liberation])\n}\n\nconst FONTS = {\n Roboto: { normal: own(FILES.normal), bold: own(FILES.bold), italics: own(FILES.italics), bolditalics: own(FILES.bolditalics) },\n [LIBERATION_SANS]: { normal: own(BILL_FILES.normal), bold: own(BILL_FILES.bold) },\n}\n\nasync function run(definition: TDocumentDefinitions, finish?: Finish): Promise<Uint8Array> {\n pdfmake.addVirtualFileSystem(fontFiles())\n pdfmake.setFonts(FONTS)\n pdfmake.setUrlAccessPolicy(() => false)\n return written(pdfmake.createPdf(definition).getStream(), finish)\n}\n\n/** pdfmake's browser build, and the glyphs of the very virtual files it embeds. */\nconst engine: Engine = {\n run,\n glyphs: glyphsOnce(FACES, (face) => Promise.resolve(fromBase64(vfs[FILES[face]] as string))),\n billGlyphs,\n}\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,QAAQ;CAAE,QAAQ;CAAsB,MAAM;CAAqB,SAAS;CAAqB,aAAa;AAA0B;AAC9I,MAAM,aAAa;CAAE,QAAQ;CAA8B,MAAM;AAA0B;AAC3F,MAAM,OAAO,SAAyB,8BAA8B;;AAGpE,IAAI;;;;;;;;AASJ,MAAM,aAAa,SAAS,YAAY;CACtC,MAAM,EAAE,iBAAiB,UAAU,MAAM,OAAO;CAChD,MAAM,SAAS,MAAM,SAAS,YAAY,OAAO,SAAS,WAAW,MAAM,KAAK,CAAC;CACjF,YAAY;CACZ,OAAO;AACT,CAAC;AAED,SAAS,YAAoC;CAC3C,MAAM,SAAS,OAAO,OAAO,KAAK,CAAC,CAAC,KAAK,SAAS;EAChD,MAAM,OAAO,IAAI;EACjB,IAAI,SAAS,KAAA,GAAW,MAAM,IAAI,MAAM,iCAAiC,MAAM;EAC/E,OAAO,CAAC,IAAI,IAAI,GAAG,IAAI;CACzB,CAAC;CACD,MAAM,SAAS;CACf,MAAM,aAAa,WAAW,KAAA,IAAY,CAAC,IAAI,WAAW,KAAK,SAAS,CAAC,IAAI,WAAW,KAAK,GAAG,OAAO,KAAK,CAAU;CACtH,OAAO,OAAO,YAAY,CAAC,GAAG,QAAQ,GAAG,UAAU,CAAC;AACtD;AAEA,MAAM,QAAQ;CACZ,QAAQ;EAAE,QAAQ,IAAI,MAAM,MAAM;EAAG,MAAM,IAAI,MAAM,IAAI;EAAG,SAAS,IAAI,MAAM,OAAO;EAAG,aAAa,IAAI,MAAM,WAAW;CAAE;EAC5H,kBAAkB;EAAE,QAAQ,IAAI,WAAW,MAAM;EAAG,MAAM,IAAI,WAAW,IAAI;CAAE;AAClF;AAEA,eAAe,IAAI,YAAkC,QAAsC;CACzF,QAAQ,qBAAqB,UAAU,CAAC;CACxC,QAAQ,SAAS,KAAK;CACtB,QAAQ,yBAAyB,KAAK;CACtC,OAAO,QAAQ,QAAQ,UAAU,UAAU,CAAC,CAAC,UAAU,GAAG,MAAM;AAClE;;AAGA,MAAM,SAAiB;CACrB;CACA,QAAQ,WAAW,QAAQ,SAAS,QAAQ,QAAQ,WAAW,IAAI,MAAM,MAAgB,CAAC,CAAC;CAC3F;AACF;;;;;;AAOA,SAAgB,UAAU,UAA4B,SAA6C;CACjG,OAAO,OAAO,QAAQ,UAAU,OAAO;AACzC"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["ResolvedDocument"],"sources":["../src/node.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["ResolvedDocument"],"sources":["../src/node.ts"],"mappings":";;;;;;;;;;wBAiEgB,UAAU,UAAUA,oBAAkB,SAAS,gBAAgB,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { a as FACES, i as BILL_FACES, l as written, n as LIBERATION_SANS, s as glyphsOnce, t as render } from "./render-DkPoADDg.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
5
6
|
import pdfmake from "pdfmake";
|
|
6
7
|
import { REFUSAL_CODES, RenderRefusal } from "@formancy/report-runtime";
|
|
7
8
|
//#region src/node.ts
|
|
8
9
|
/**
|
|
9
10
|
* The renderer in Node: pdfmake's Node build, reading Roboto 3.014 from the
|
|
10
|
-
* four font files in pdfmake's own package
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* four font files in pdfmake's own package, and Liberation Sans 2.1.5, for
|
|
12
|
+
* a QR-bill's slip, from the two in this package's `fonts` directory -- all
|
|
13
|
+
* of which the dependency-licence guard reads as OFL-1.1 (0006) -- and no
|
|
14
|
+
* other file, and no address at all; but for an e-invoice, whose PDF/A
|
|
15
|
+
* output intent PDFKit reads from its own `data/sRGB_IEC61966_2_1.icc`
|
|
16
|
+
* with `fs`, past pdfmake's policy (pdfkit.js 5265), a profile the guard
|
|
17
|
+
* holds to its reviewed digest (0031). The renderer reads the same files
|
|
18
|
+
* once, for the characters they have glyphs for (`glyphs.ts`): Roboto's
|
|
19
|
+
* for the first document, Liberation Sans's for the first with a bill.
|
|
14
20
|
*
|
|
15
21
|
* pdfmake is one configuration per process. It is set again before every
|
|
16
22
|
* document, in the same synchronous step as `createPdf`, which reads it, so
|
|
@@ -22,23 +28,32 @@ import { REFUSAL_CODES, RenderRefusal } from "@formancy/report-runtime";
|
|
|
22
28
|
const require = createRequire(import.meta.url);
|
|
23
29
|
const pdfmakeDirectory = path.dirname(require.resolve("pdfmake/package.json"));
|
|
24
30
|
const roboto = (file) => path.join(pdfmakeDirectory, "fonts", "Roboto", file).split(path.sep).join("/");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
/** One of this package's own fonts, in its `fonts` directory, which stands beside `dist` as beside `src`. */
|
|
32
|
+
const own = (file) => fileURLToPath(new URL(`../fonts/${file}`, import.meta.url)).split(path.sep).join("/");
|
|
33
|
+
const FONTS = {
|
|
34
|
+
Roboto: {
|
|
35
|
+
normal: roboto("Roboto-Regular.ttf"),
|
|
36
|
+
bold: roboto("Roboto-Medium.ttf"),
|
|
37
|
+
italics: roboto("Roboto-Italic.ttf"),
|
|
38
|
+
bolditalics: roboto("Roboto-MediumItalic.ttf")
|
|
39
|
+
},
|
|
40
|
+
[LIBERATION_SANS]: {
|
|
41
|
+
normal: own("LiberationSans-Regular.ttf"),
|
|
42
|
+
bold: own("LiberationSans-Bold.ttf")
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const FONT_FILES = /* @__PURE__ */ new Set([...Object.values(FONTS.Roboto), ...Object.values(FONTS[LIBERATION_SANS])]);
|
|
46
|
+
async function run(definition, finish) {
|
|
33
47
|
pdfmake.setFonts(FONTS);
|
|
34
48
|
pdfmake.setUrlAccessPolicy(() => false);
|
|
35
49
|
pdfmake.setLocalAccessPolicy((file) => FONT_FILES.has(file));
|
|
36
|
-
return
|
|
50
|
+
return written(pdfmake.createPdf(definition).getStream(), finish);
|
|
37
51
|
}
|
|
38
52
|
/** pdfmake in Node, and the glyphs of the very font files it embeds. */
|
|
39
53
|
const engine = {
|
|
40
54
|
run,
|
|
41
|
-
glyphs: glyphsOnce(async (face) => new Uint8Array(await readFile(FONTS.Roboto[face])))
|
|
55
|
+
glyphs: glyphsOnce(FACES, async (face) => new Uint8Array(await readFile(FONTS.Roboto[face]))),
|
|
56
|
+
billGlyphs: glyphsOnce(BILL_FACES, async (face) => new Uint8Array(await readFile(FONTS[LIBERATION_SANS][face])))
|
|
42
57
|
};
|
|
43
58
|
/**
|
|
44
59
|
* Renders `document` to a PDF, or rejects with a `RenderRefusal` saying why
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +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 {
|
|
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 { fileURLToPath } from 'node:url'\nimport pdfmake from 'pdfmake'\nimport type { TDocumentDefinitions } from 'pdfmake/interfaces.js'\nimport type { ResolvedDocument } from '@formancy/report-runtime'\nimport { BILL_FACES, FACES, glyphsOnce, written, type Engine } from './engine.js'\nimport type { RenderOptions } from './options.js'\nimport type { Finish } from './pdfa.js'\nimport { render } from './render.js'\nimport { LIBERATION_SANS } from './style.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, and Liberation Sans 2.1.5, for\n * a QR-bill's slip, from the two in this package's `fonts` directory -- all\n * of which the dependency-licence guard reads as OFL-1.1 (0006) -- and no\n * other file, and no address at all; but for an e-invoice, whose PDF/A\n * output intent PDFKit reads from its own `data/sRGB_IEC61966_2_1.icc`\n * with `fs`, past pdfmake's policy (pdfkit.js 5265), a profile the guard\n * holds to its reviewed digest (0031). The renderer reads the same files\n * once, for the characters they have glyphs for (`glyphs.ts`): Roboto's\n * for the first document, Liberation Sans's for the first with a bill.\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('/')\n/** One of this package's own fonts, in its `fonts` directory, which stands beside `dist` as beside `src`. */\nconst own = (file: string): string => fileURLToPath(new URL(`../fonts/${file}`, import.meta.url)).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 [LIBERATION_SANS]: { normal: own('LiberationSans-Regular.ttf'), bold: own('LiberationSans-Bold.ttf') },\n}\nconst FONT_FILES: ReadonlySet<string> = new Set([...Object.values(FONTS.Roboto), ...Object.values(FONTS[LIBERATION_SANS])])\n\nasync function run(definition: TDocumentDefinitions, finish?: Finish): Promise<Uint8Array> {\n pdfmake.setFonts(FONTS)\n pdfmake.setUrlAccessPolicy(() => false)\n pdfmake.setLocalAccessPolicy((file) => FONT_FILES.has(file))\n return written(pdfmake.createPdf(definition).getStream(), finish)\n}\n\n/** pdfmake in Node, and the glyphs of the very font files it embeds. */\nconst engine: Engine = {\n run,\n glyphs: glyphsOnce(FACES, async (face) => new Uint8Array(await readFile(FONTS.Roboto[face]))),\n billGlyphs: glyphsOnce(BILL_FACES, async (face) => new Uint8Array(await readFile(FONTS[LIBERATION_SANS][face]))),\n}\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,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;;AAEtH,MAAM,OAAO,SAAyB,cAAc,IAAI,IAAI,YAAY,QAAQ,YAAY,GAAG,CAAC,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG;AAC1H,MAAM,QAAQ;CACZ,QAAQ;EAAE,QAAQ,OAAO,oBAAoB;EAAG,MAAM,OAAO,mBAAmB;EAAG,SAAS,OAAO,mBAAmB;EAAG,aAAa,OAAO,yBAAyB;CAAE;EACvK,kBAAkB;EAAE,QAAQ,IAAI,4BAA4B;EAAG,MAAM,IAAI,yBAAyB;CAAE;AACvG;AACA,MAAM,6BAAkC,IAAI,IAAI,CAAC,GAAG,OAAO,OAAO,MAAM,MAAM,GAAG,GAAG,OAAO,OAAO,MAAM,gBAAgB,CAAC,CAAC;AAE1H,eAAe,IAAI,YAAkC,QAAsC;CACzF,QAAQ,SAAS,KAAK;CACtB,QAAQ,yBAAyB,KAAK;CACtC,QAAQ,sBAAsB,SAAS,WAAW,IAAI,IAAI,CAAC;CAC3D,OAAO,QAAQ,QAAQ,UAAU,UAAU,CAAC,CAAC,UAAU,GAAG,MAAM;AAClE;;AAGA,MAAM,SAAiB;CACrB;CACA,QAAQ,WAAW,OAAO,OAAO,SAAS,IAAI,WAAW,MAAM,SAAS,MAAM,OAAO,KAAK,CAAC,CAAC;CAC5F,YAAY,WAAW,YAAY,OAAO,SAAS,IAAI,WAAW,MAAM,SAAS,MAAM,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACjH;;;;;;;;AASA,SAAgB,UAAU,UAA4B,SAA6C;CACjG,OAAO,OAAO,QAAQ,UAAU,OAAO;AACzC"}
|