boxpdf-html 1.0.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.
@@ -0,0 +1,88 @@
1
+ import { RGB, Node } from 'boxpdf';
2
+ import { PDFFont, PDFImage } from 'pdf-lib';
3
+
4
+ interface HtmlToBoxpdfOptions {
5
+ font: PDFFont;
6
+ boldFont?: PDFFont;
7
+ italicFont?: PDFFont;
8
+ resolveFont?: HtmlFontResolver;
9
+ resolveImage?: HtmlImageResolver;
10
+ baseUrl?: string;
11
+ width?: number;
12
+ defaultFontSize?: number;
13
+ defaultLineHeight?: number;
14
+ defaultColor?: RGB;
15
+ profile?: HtmlProfileCallback;
16
+ diagnostics?: HtmlDiagnosticsOptions;
17
+ }
18
+ interface HtmlDiagnosticsOptions {
19
+ unsupportedCss?: boolean;
20
+ sampleLimit?: number;
21
+ }
22
+ interface HtmlProfileEvent {
23
+ phase: "start" | "parse-html" | "parse-css" | "compute-styles" | "render-tree" | "finish";
24
+ elapsedMs: number;
25
+ htmlBytes?: number;
26
+ domNodes?: number;
27
+ stylesheets?: number;
28
+ cssRules?: number;
29
+ styledNodes?: number;
30
+ boxNodes?: number;
31
+ paragraphs?: number;
32
+ textRuns?: number;
33
+ }
34
+ type HtmlProfileCallback = (event: HtmlProfileEvent) => void;
35
+ type FontWeight = "normal" | "bold" | number;
36
+ type FontStyle = "normal" | "italic";
37
+ interface HtmlFontRequest {
38
+ families: string[];
39
+ weight: FontWeight;
40
+ style: FontStyle;
41
+ }
42
+ type HtmlFontResolver = (request: HtmlFontRequest) => PDFFont | undefined;
43
+ type HtmlImageResolver = (request: HtmlImageRequest) => PDFImage | undefined;
44
+ interface HtmlImageRequest {
45
+ url: string;
46
+ baseUrl?: string;
47
+ }
48
+ interface HtmlTextNode {
49
+ kind: "text";
50
+ value: string;
51
+ parent?: HtmlElementNode;
52
+ }
53
+ interface HtmlElementNode {
54
+ kind: "element";
55
+ tag: string;
56
+ attrs: Record<string, string>;
57
+ children: HtmlNode[];
58
+ parent?: HtmlElementNode;
59
+ }
60
+ type HtmlNode = HtmlTextNode | HtmlElementNode;
61
+ interface ParsedHtml {
62
+ root: HtmlElementNode;
63
+ stylesheets: string[];
64
+ }
65
+ interface RenderResult {
66
+ nodes: Node[];
67
+ warnings: string[];
68
+ diagnostics?: HtmlDiagnostics;
69
+ }
70
+ interface HtmlDiagnostics {
71
+ unsupportedCss: HtmlUnsupportedCss[];
72
+ }
73
+ interface HtmlUnsupportedCss {
74
+ property: string;
75
+ value: string;
76
+ count: number;
77
+ samples?: string[];
78
+ }
79
+
80
+ type FontFamilyFace = PDFFont | Partial<Record<FontStyle | "bold" | "boldItalic" | `${number}`, PDFFont>>;
81
+ type FontFamilyMap = Record<string, FontFamilyFace>;
82
+ declare function fontFamily(families: FontFamilyMap): HtmlFontResolver;
83
+
84
+ declare function parseHtml(html: string): ParsedHtml;
85
+
86
+ declare function htmlToBoxpdf(html: string, options: HtmlToBoxpdfOptions): RenderResult;
87
+
88
+ export { type FontFamilyFace, type FontFamilyMap, type FontStyle, type FontWeight, type HtmlDiagnostics, type HtmlDiagnosticsOptions, type HtmlFontRequest, type HtmlFontResolver, type HtmlProfileCallback, type HtmlProfileEvent, type HtmlToBoxpdfOptions, type HtmlUnsupportedCss, type ParsedHtml, type RenderResult, fontFamily, htmlToBoxpdf, parseHtml };
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import {
2
+ fontFamily,
3
+ htmlToBoxpdf,
4
+ parseHtml
5
+ } from "./chunk-23KN7BKZ.js";
6
+ export {
7
+ fontFamily,
8
+ htmlToBoxpdf,
9
+ parseHtml
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "boxpdf-html",
3
+ "version": "1.0.0",
4
+ "description": "Readable HTML-to-PDF translator built on boxpdf.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "bin": {
10
+ "boxpdf-html": "dist/cli.js"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "keywords": [
25
+ "pdf",
26
+ "html",
27
+ "css",
28
+ "boxpdf",
29
+ "html-to-pdf"
30
+ ],
31
+ "license": "MIT",
32
+ "author": {
33
+ "name": "Erik Aronesty",
34
+ "email": "erik@q32.com"
35
+ },
36
+ "homepage": "https://github.com/earonesty/boxpdf-html#readme",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/earonesty/boxpdf-html.git"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/earonesty/boxpdf-html/issues"
43
+ },
44
+ "dependencies": {
45
+ "boxpdf": "^1.7.0",
46
+ "css-tree": "^3.1.0",
47
+ "parse5": "^8.0.0",
48
+ "pdf-lib": "^1.17.1"
49
+ },
50
+ "devDependencies": {
51
+ "@tailwindcss/cli": "^4.3.0",
52
+ "@types/node": "^22.19.19",
53
+ "tailwindcss": "^4.3.0",
54
+ "tsup": "^8.5.1",
55
+ "typescript": "^5.9.3",
56
+ "vitest": "^4.1.6"
57
+ },
58
+ "engines": {
59
+ "node": ">=18"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public"
63
+ },
64
+ "packageManager": "pnpm@10.30.3"
65
+ }