@lpdfio/lpdf 0.6.0 → 0.8.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 CHANGED
@@ -10,13 +10,21 @@ License inquiries: license@lpdf.io
10
10
 
11
11
  Lpdf is available under three license tiers: a free Community License for individuals and qualifying organizations, a Professional License for mid-size commercial use, and an Enterprise License for larger organizations. All license tiers receive the complete feature set — no capabilities are gated behind paid plans.
12
12
 
13
+ ### Definitions
14
+
15
+ "Production environment" means any environment in which the Software processes real user data or supports live business operations, including staging environments accessible by end users.
16
+
17
+ "Production Context" means a distinct, independently operated system, application, or automated workflow that uses the Software in a production environment, where "independently operated" means it serves a separate and identifiable purpose, user base, or business function. For the avoidance of doubt: multiple delivery channels (web, mobile, desktop, API) of the same system serving the same purpose and user base constitute a single Production Context; all internal business operations of an organization where the organization's own personnel are the sole end users constitute a single Production Context regardless of the number of internal systems or services involved; a service or component that operates exclusively as part of a larger system and has no independent production deployment is not a separate Production Context.
18
+
13
19
  ### Equal Features Across All Tiers
14
20
 
15
21
  Every user of Lpdf, regardless of license tier, has access to the same library, the same layout engine, the same adapters, and the same output quality. Licensing determines the terms of use, not the features available.
16
22
 
17
23
  ### Transitive Dependency
18
24
 
19
- If Lpdf is pulled in as an indirect dependency of another library or framework rather than used directly in your project, the Community License applies automatically, regardless of your organization's revenue.
25
+ If Lpdf is pulled in as an indirect dependency of another library or framework rather than used directly in your project, the Community License terms apply automatically with respect to revenue thresholds — no upgrade to a Professional or Enterprise License is required solely on account of the indirect dependency.
26
+
27
+ The author of the wrapping library or framework is responsible for obtaining a valid license key; end users of that library or framework are not required to obtain a separate Lpdf license key for their indirect use.
20
28
 
21
29
  This exemption does not apply if the dependency was introduced, created, or controlled by the licensee's organization for the purpose of circumventing license requirements.
22
30
 
@@ -36,13 +44,11 @@ Organizations whose revenue crosses the 1,000,000 USD threshold have a **90-day
36
44
 
37
45
  ### Mid-Size Businesses
38
46
 
39
- Companies and organizations whose total annual gross revenue exceeded **1,000,000 USD** but did not exceed **10,000,000 USD** in the most recent 12-month fiscal year must obtain a Professional License to use Lpdf in production environments.
40
-
41
- "Production environment" means any environment in which the Software processes real user data or supports live business operations, including staging environments accessible by end users.
47
+ Companies and organizations whose total annual gross revenue exceeded **1,000,000 USD** but did not exceed **10,000,000 USD** in the most recent 12-month fiscal year must obtain a Professional License for each Production Context in which they use the Software.
42
48
 
43
49
  ### Larger Businesses
44
50
 
45
- Companies and organizations whose total annual gross revenue exceeded **10,000,000 USD** in the most recent 12-month fiscal year must obtain an Enterprise License to use Lpdf in production environments.
51
+ Companies and organizations whose total annual gross revenue exceeded **10,000,000 USD** in the most recent 12-month fiscal year must obtain an Enterprise License for each Production Context in which they use the Software.
46
52
 
47
53
  Organizations whose revenue crosses the 10,000,000 USD threshold have a **90-day grace period** following the close of their fiscal year to obtain an Enterprise license. During this grace period, continued use under a Professional License is permitted. The licensee remains subject to the terms of their existing Professional License and does not gain Enterprise rights until an Enterprise License is obtained.
48
54
 
@@ -52,6 +58,18 @@ Paid licenses directly fund the continued development, maintenance, and improvem
52
58
 
53
59
  ---
54
60
 
61
+ ## Unregistered Use
62
+
63
+ Use of the Software without a valid license key ("Unregistered Use") is permitted solely for evaluation and local testing. It does not constitute a license for use in a production environment, commercial deployment, or distribution.
64
+
65
+ Unregistered Use is subject to the following restriction:
66
+
67
+ **Attribution.** Each document rendered shall include an attribution notice in the form specified in the Software documentation. This notice may not be suppressed, removed, or obscured.
68
+
69
+ This restriction is lifted upon obtaining a valid license key. Community keys are available at no cost at lpdf.io.
70
+
71
+ ---
72
+
55
73
  ## Lpdf Community License
56
74
 
57
75
  *Applies to: individuals, open-source projects, non-profit organizations, and companies with annual gross revenue under 1,000,000 USD.*
@@ -60,9 +78,17 @@ Permission is hereby granted, free of charge, to any person or qualifying organi
60
78
 
61
79
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Any redistribution of the Software must be made under the terms of this Community License and may not be sublicensed under different terms.
62
80
 
81
+ ### License Key
82
+
83
+ A license key issued under this license may be used by you, your employees, and contractors working on your behalf on your projects. You may not share, distribute, or otherwise make your license key available to individuals or organizations outside your own. Any person or organization outside your own that wishes to use Lpdf must obtain their own license key at lpdf.io.
84
+
63
85
  All modifications to the Software made by the licensee remain the intellectual property of the licensee. Codesense LLC claims no ownership over modifications unless they are voluntarily submitted as contributions to the Lpdf project under a separate Contributor License Agreement.
64
86
 
65
- If your organization's annual gross revenue exceeds 1,000,000 USD, your rights under this Community License are automatically terminated upon expiration of the 90-day grace period described above, and you must obtain a Professional or Enterprise license before continuing to use Lpdf in production.
87
+ If your organization's annual gross revenue exceeds 1,000,000 USD, your rights under this Community License to use the Software in commercial Production Contexts are automatically terminated upon expiration of the 90-day grace period described above, and you must obtain a Professional or Enterprise license for each such Production Context. Use under this Community License by individuals, open-source projects, and non-profit organizations is not subject to revenue thresholds and is unaffected by this provision.
88
+
89
+ ### License Key Expiration
90
+
91
+ License keys issued under this license are valid for one year from the date of issuance. Before expiry, a new key must be generated from the portal and deployed in place of the expiring key. A key may be renewed at no cost provided the licensee continues to qualify under this Community License. Use of an expired key is treated as Unregistered Use — documents rendered without a valid key will include an attribution notice as described above.
66
92
 
67
93
  ### Governing Law
68
94
 
@@ -76,28 +102,36 @@ THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
76
102
 
77
103
  ## Lpdf Professional License
78
104
 
79
- *Applies to: companies and organizations with annual gross revenue exceeding 1,000,000 USD and not exceeding 10,000,000 USD.*
105
+ *Minimum required for companies and organizations with annual gross revenue exceeding 1,000,000 USD and not exceeding 10,000,000 USD.*
80
106
 
81
107
  ### Conduct
82
108
 
83
109
  Licensees agree not to make false statements of fact about Lpdf, Codesense LLC, or its contributors that are intended to cause material harm to the reputation of the project or the company. This clause does not restrict good-faith criticism, bug reports, public discussion of software deficiencies, or reviews based on the licensee's genuine experience.
84
110
 
85
- License rights may not be rented, leased, or transferred to any third party.
111
+ License rights may not be rented, leased, or transferred to any third party. A license key issued under this license may be used by the licensee's employees and contractors working on the licensee's behalf; the licensee may not share or distribute a license key to individuals or organizations outside their own, who must obtain their own license key.
86
112
 
87
113
  ### License Grant
88
114
 
89
- Subject to payment of the applicable license fee, Codesense LLC grants the licensee a non-exclusive, worldwide, royalty-free license to:
115
+ Subject to payment of the applicable license fee per Production Context, Codesense LLC grants the licensee a non-exclusive, worldwide, royalty-free license to use the Software within a single licensed Production Context:
90
116
 
91
- - Use, copy, modify, and integrate the Software into unlimited applications and projects
92
- - Distribute the Software as part of compiled or packaged commercial products
93
- - Deploy the Software across unlimited servers, environments, and infrastructure
117
+ - Use, copy, modify, and integrate the Software into the licensed Production Context
118
+ - Deploy the Software across any number of servers, environments, and infrastructure serving that Production Context
119
+ - Distribute the Software as a component of the licensed Production Context
120
+
121
+ A separate license is required for each additional Production Context in which the licensee uses the Software in a production environment.
122
+
123
+ **Tier compliance.** Licensee is responsible for ensuring their use of the Software complies with the applicable license tier at all times. If the licensee's annual gross revenue crosses 10,000,000 USD, the licensee must obtain an Enterprise License for each affected Production Context within 90 days of the close of the fiscal year in which the threshold was crossed. Use of a Professional License key while qualifying for the Enterprise tier is a material breach of this Agreement.
94
124
 
95
125
  ### License Fees and Evaluation
96
126
 
97
- A license fee is required for use of Lpdf in production environments (as defined above). Evaluation and testing in non-production environments is permitted without a license for a period not exceeding 30 days.
127
+ A license fee is required per Production Context for use of the Software in a production environment (as defined above). Evaluation and testing in non-production environments is permitted without a license for a period not exceeding 30 days.
98
128
 
99
129
  Upon payment, the licensee receives a perpetual license for the version of Lpdf current at the time of purchase, plus one year of updates, new features, and security patches. Continued access to new versions after the first year requires annual renewal. Cancellation of renewal does not affect the perpetual license for the version already held.
100
130
 
131
+ License keys issued under this license are valid for one year and are renewed automatically upon annual payment. An expired key reverts to Unregistered Use behavior — documents rendered without a valid key will include an attribution notice. A valid key is required to exercise the license grant in any production environment.
132
+
133
+ **Active subscription required.** The license grant is contingent on an active subscription in good standing. A technically valid key does not authorize use of the Software after the subscription has expired or been cancelled. Use of any key following subscription lapse — including keys that remain technically valid — constitutes unauthorized use and a material breach of this Agreement.
134
+
101
135
  ### Support
102
136
 
103
137
  Professional License holders receive email support from Codesense LLC with a target response time of 3 business days for standard inquiries. Support terms are further detailed at lpdf.io/support.
@@ -140,28 +174,37 @@ Notwithstanding the foregoing, either party may seek injunctive or other equitab
140
174
 
141
175
  ## Lpdf Enterprise License
142
176
 
143
- *Applies to: companies and organizations with annual gross revenue exceeding 10,000,000 USD.*
177
+ *Required for companies and organizations with annual gross revenue exceeding 10,000,000 USD. Available to any organization that prefers Enterprise license terms.*
144
178
 
145
179
  ### Conduct
146
180
 
147
181
  Licensees agree not to make false statements of fact about Lpdf, Codesense LLC, or its contributors that are intended to cause material harm to the reputation of the project or the company. This clause does not restrict good-faith criticism, bug reports, public discussion of software deficiencies, or reviews based on the licensee's genuine experience.
148
182
 
149
- License rights may not be rented, leased, or transferred to any third party, except as expressly permitted under the subsidiary grant below.
183
+ License rights may not be rented, leased, or transferred to any third party. A license key issued under this license may be used by the licensee's employees, contractors, and personnel of Controlled Entities (as defined in the License Grant below) working on Production Contexts licensed by the licensee. The licensee may not share or distribute a license key for use in Production Contexts not licensed by the licensee; any Production Context operated independently by a Controlled Entity requires its own license obtained by that entity.
150
184
 
151
185
  ### License Grant
152
186
 
153
- Subject to payment of the applicable license fee, Codesense LLC grants the licensee a non-exclusive, worldwide, royalty-free license for an unlimited number of developers within the licensee's organization to:
187
+ Subject to payment of the applicable license fee per Production Context, Codesense LLC grants the licensee a non-exclusive, worldwide, royalty-free license for an unlimited number of developers within the licensee's organization to use the Software within a single licensed Production Context:
188
+
189
+ - Use, copy, modify, and integrate the Software into the licensed Production Context
190
+ - Deploy the Software across any number of servers, environments, and infrastructure serving that Production Context
191
+ - Distribute the Software as a component of the licensed Production Context
192
+
193
+ A separate license is required for each additional Production Context in which the licensee uses the Software in a production environment.
194
+
195
+ **Controlled Entities.** "Controlled Entities" means wholly owned subsidiaries and entities in which the licensee holds more than 50% ownership or voting control. Personnel of Controlled Entities may use license keys issued under this license solely for Production Contexts licensed by the licensee. This does not extend the license to Production Contexts operated independently by a Controlled Entity; each such Production Context requires its own license obtained by the Controlled Entity at the tier applicable to that entity's annual gross revenue.
154
196
 
155
- - Use, copy, modify, and integrate the Software into unlimited applications and projects
156
- - Distribute the Software as part of compiled or packaged commercial products
157
- - Deploy the Software across unlimited servers, environments, and infrastructure
158
- - Extend license rights to wholly owned subsidiaries and entities in which the licensee holds more than 50% ownership or voting control ("Controlled Entities"), provided such Controlled Entities are identified to Codesense LLC upon request and remain subject to the terms of this license
197
+ **Tier compliance.** Licensee is responsible for ensuring their use of the Software complies with the applicable license tier at all times. Each Controlled Entity using the Software must qualify for the tier under which they operate. If a Controlled Entity's annual gross revenue would independently qualify that entity for a different tier, that entity must obtain its own license at the applicable tier for any Production Context it independently operates.
159
198
 
160
199
  ### License Fees and Evaluation
161
200
 
162
- A license fee is required for use of Lpdf in production environments (as defined above). Evaluation and testing in non-production environments is permitted without a license for a period not exceeding 30 days.
201
+ A license fee is required per Production Context for use of the Software in a production environment (as defined above). Evaluation and testing in non-production environments is permitted without a license for a period not exceeding 30 days.
163
202
 
164
- Upon payment, the licensee receives a perpetual license for the version of Lpdf current at the time of purchase, plus one year of updates, new features, and security patches. Continued access to new versions after the first year requires annual renewal. Cancellation of renewal does not affect the perpetual license for the version already held.
203
+ Upon payment, the licensee receives a perpetual license for the major version of Lpdf current at the time of purchase, plus access to updates, new features, and security patches within that major version for the duration of the active subscription. Cancellation of renewal does not affect the perpetual license for the major version already held.
204
+
205
+ **License keys.** License keys issued under this license are locked to the major version of Lpdf current at the time of generation and carry no date expiry. While the subscription is active and in good standing, the licensee may generate new keys for the current major version from the portal at any time. When a new major version of Lpdf is released, a new key must be generated from the portal to use that version; keys generated for a prior major version continue to function with that version only. The right to generate new keys requires an active subscription; key generation rights terminate upon subscription lapse.
206
+
207
+ **Active subscription required.** The license grant is contingent on an active subscription in good standing. A technically valid key does not authorize use of the Software after the subscription has expired or been cancelled. Use of any key following subscription lapse — including keys that carry no date expiry and remain technically valid — constitutes unauthorized use and a material breach of this Agreement.
165
208
 
166
209
  ### Support
167
210
 
@@ -173,7 +216,7 @@ Enterprise licensees may request a Master Service Agreement (MSA) in place of th
173
216
 
174
217
  ### Audit
175
218
 
176
- Codesense LLC may, upon 30 days' written notice and no more than once per calendar year, request a written certification from the licensee confirming their applicable license tier and annual gross revenue for the most recent fiscal year, and may request a list of Controlled Entities covered under the subsidiary grant. The licensee agrees to provide such certification within 15 business days of the request. For Enterprise licensees under an MSA, audit rights may be further defined therein.
219
+ Codesense LLC may, upon 30 days' written notice and no more than once per calendar year, request a written certification from the licensee confirming their applicable license tier and annual gross revenue for the most recent fiscal year, and may request a list of Controlled Entities whose personnel have been granted access to the licensee's license keys. The licensee agrees to provide such certification within 15 business days of the request. For Enterprise licensees under an MSA, audit rights may be further defined therein.
177
220
 
178
221
  ### Ownership and Modifications
179
222
 
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # @lpdfio/lpdf
4
4
 
5
- Node.js adapter for [Lpdf](https://lpdf.io) — PDF as Code, on every platform.
5
+ **Node.js SDK for [Lpdf](https://lpdf.io) — PDF as Code on every platform**
6
6
 
7
- Describe your document structure in code using the programming Kit or XML. Every PDF is compact, pixel-perfect, and identical across platforms.
7
+ You describe a document as code or XML. Lpdf renders a compact, pixel-perfect PDF — identical across platforms.
8
8
 
9
9
  ## Installation
10
10
 
@@ -15,48 +15,41 @@ npm install @lpdfio/lpdf
15
15
  ## Usage — Node.js
16
16
 
17
17
  ```ts
18
- import { LpdfEngine } from '@lpdfio/lpdf';
19
- import { readFileSync, writeFileSync } from 'node:fs';
20
-
21
- const engine = new LpdfEngine('');
22
-
23
- engine.loadFont('montserrat', readFileSync('fonts/Montserrat-Regular.ttf'));
24
- engine.loadImage('logo', readFileSync('images/logo.png'));
25
-
26
- const xml = readFileSync('document.xml', 'utf8');
27
- const pdf = await engine.renderPdf(xml);
28
-
29
- writeFileSync('output.pdf', pdf);
18
+ import { L, NoAttr } from 'lpdf'
19
+
20
+ const engine = L.engine()
21
+
22
+ const doc = L.document({ size: 'letter', margin: '48pt' }, [
23
+ L.section(NoAttr, [
24
+ L.layout(NoAttr, [
25
+ L.stack({ gap: '24pt' }, [
26
+ L.split(NoAttr, [
27
+ L.text({ fontSize: '8pt', color: '#888888' }, ['ACME CORP']),
28
+ L.text({ fontSize: '22pt', bold: 'true' }, ['Project Proposal']),
29
+ ]),
30
+ L.divider({ thickness: 'xs' }),
31
+ L.text({ fontSize: '13pt', bold: 'true' }, ['Scope of Work']),
32
+ L.flank({ gap: '12pt', align: 'start' }, [
33
+ L.text({ color: '#888888', width: '24pt' }, ['01']),
34
+ L.text(NoAttr, ['Discovery & Research']),
35
+ ]),
36
+ ]),
37
+ ]),
38
+ ]),
39
+ ])
40
+
41
+ const pdf = await engine.render(doc)
30
42
  ```
31
43
 
32
- ## Usage — Browser
33
-
34
- ```ts
35
- import { LpdfEngine } from '@lpdfio/lpdf/browser';
44
+ ## Requirements
36
45
 
37
- const engine = new LpdfEngine('');
46
+ - Node.js 16+
47
+ - No external runtime dependencies — the WASM engine is embedded in the package.
38
48
 
39
- const xml = `<stack><text>Hello, Lpdf</text></stack>`;
40
- const pdf = await engine.renderPdf(xml);
49
+ ## Docs
41
50
 
42
- const blob = new Blob([pdf], { type: 'application/pdf' });
43
- window.open(URL.createObjectURL(blob));
44
- ```
45
-
46
- ## XML format
47
-
48
- Documents are defined in a layout XML format. See the [Lpdf documentation](https://lpdf.io/docs) and [examples](https://github.com/lpdfio/lpdf/tree/main/docs/examples) for the full schema.
49
-
50
- ```xml
51
- <stack spacing="m" padding="l">
52
- <text font-size="xl" font="Montserrat-Bold">Invoice #1001</text>
53
- <grid columns="2">
54
- <text>Date</text> <text>2026-04-25</text>
55
- <text>Due</text> <text>2026-05-25</text>
56
- </grid>
57
- </stack>
58
- ```
51
+ [lpdf.io/docs/js](https://lpdf.io/docs/js)
59
52
 
60
- ## License
53
+ --
61
54
 
62
55
  Dual-licensed: Community License (free) and Commercial License (paid). See [LICENSE](LICENSE) for full terms.
package/dist/L.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ import type { LpdfTokens, PdfDocument } from './kit';
2
+ import { PdfEngine } from './engine';
3
+ /** Pass as `attrs` when a node has no attributes. Equivalent to `null`. */
4
+ export declare const NoAttr: null;
5
+ /**
6
+ * Unified lpdf facade.
7
+ *
8
+ * All document, layout, and canvas factory methods are available as flat
9
+ * properties on this object. Construction-time configuration is handled via
10
+ * `L.engine()`.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { L, NoAttr } from 'lpdf';
15
+ *
16
+ * const engine = L.engine().setLicenseKey(process.env.LPDF_KEY);
17
+ *
18
+ * const doc = L.document(NoAttr, [
19
+ * L.section(NoAttr, [
20
+ * L.layout(null, [ L.text(NoAttr, ['Hello']) ]),
21
+ * ]),
22
+ * ]);
23
+ *
24
+ * const pdf = await engine.render(doc);
25
+ * ```
26
+ */
27
+ export declare const L: Readonly<{
28
+ /** Create a new {@link PdfEngine} instance. Call `.setLicenseKey()` to configure. */
29
+ engine: () => PdfEngine;
30
+ /** Convert a `PdfDocument` tree to an lpdf XML string. */
31
+ toXml: (doc: PdfDocument) => string;
32
+ document: (attrs: import("./kit").DocumentAttr | null, nodes: import("./kit").LpdfSectionNode[]) => PdfDocument;
33
+ section: (attrs: import("./kit").SectionAttr | null, nodes: (import("./kit").LpdfLayoutBlock | import("./kit").LpdfCanvasBlock)[]) => import("./kit").LpdfSectionNode;
34
+ layout: (_attrs: null, nodes: import("./layout").LpdfNode[]) => import("./kit").LpdfLayoutBlock;
35
+ canvas: (_attrs: null, layers: import("./canvas").LpdfCanvasLayerNode[]) => import("./kit").LpdfCanvasBlock;
36
+ tokens: (attrs: LpdfTokens) => LpdfTokens;
37
+ stack: (attrs: import("./layout").StackAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
38
+ flank: (attrs: import("./layout").FlankAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
39
+ split: (attrs: import("./layout").SplitAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
40
+ cluster: (attrs: import("./layout").ClusterAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
41
+ grid: (attrs: import("./layout").GridAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
42
+ frame: (attrs: import("./layout").FrameAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
43
+ link: (attrs: import("./layout").LinkAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
44
+ table: (attrs: import("./layout").TableAttr, nodes: (import("./layout").LpdfTheadNode | import("./layout").LpdfTrNode)[]) => import("./layout").LpdfTableNode;
45
+ thead: (attrs: import("./layout").TheadAttr | null, nodes: import("./layout").LpdfTdNode[]) => import("./layout").LpdfTheadNode;
46
+ tr: (attrs: import("./layout").TrAttr | null, nodes: import("./layout").LpdfTdNode[]) => import("./layout").LpdfTrNode;
47
+ td: (attrs: import("./layout").TdAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfTdNode;
48
+ text: (attrs: import("./layout").TextAttr | null, nodes: (string | import("./layout").LpdfSpanNode)[]) => import("./layout").LpdfTextNode;
49
+ span: (attrs: import("./layout").SpanAttr | null, nodes: string[]) => import("./layout").LpdfSpanNode;
50
+ divider: (attrs: import("./layout").DividerAttr | null) => import("./layout").LpdfDividerNode;
51
+ img: (attrs: import("./layout").ImgAttr) => import("./layout").LpdfImgNode;
52
+ barcode: (attrs: import("./layout").BarcodeAttr) => import("./layout").LpdfBarcodeNode;
53
+ region: (attrs: import("./layout").RegionAttr, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfRegionNode;
54
+ field: (type: string, name: string, attrs?: import("./layout").FieldAttr | null) => import("./layout").LpdfFieldNode;
55
+ layer: (attrs: import("./canvas").LayerAttr | null, nodes: import("./canvas").LpdfCanvasPrimitiveNode[]) => import("./canvas").LpdfCanvasLayerNode;
56
+ rect: (x: number, y: number, w: number, h: number, style?: import("./canvas").CanvasRectStyle) => import("./canvas").LpdfCanvasRectNode;
57
+ line: (x1: number, y1: number, x2: number, y2: number, style?: import("./canvas").CanvasLineStyle) => import("./canvas").LpdfCanvasLineNode;
58
+ ellipse: (cx: number, cy: number, rx: number, ry: number, style?: import("./canvas").CanvasEllipseStyle) => import("./canvas").LpdfCanvasEllipseNode;
59
+ circle: (cx: number, cy: number, r: number, style?: import("./canvas").CanvasEllipseStyle) => import("./canvas").LpdfCanvasCircleNode;
60
+ path: (d: string, style?: import("./canvas").CanvasPathStyle) => import("./canvas").LpdfCanvasPathNode;
61
+ textAt: (x: number, y: number, content: string, style?: import("./canvas").CanvasTextStyle, runs?: import("./canvas").CanvasRun[]) => import("./canvas").LpdfCanvasTextNode;
62
+ imgAt: (x: number, y: number, w: number, h: number, name: string, anchor?: string) => import("./canvas").LpdfCanvasImgNode;
63
+ }>;
package/dist/L.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.L = exports.NoAttr = void 0;
4
+ const kit_1 = require("./kit");
5
+ const layout_1 = require("./layout");
6
+ const canvas_1 = require("./canvas");
7
+ const engine_1 = require("./engine");
8
+ const kit_to_xml_1 = require("./kit-to-xml");
9
+ /** Pass as `attrs` when a node has no attributes. Equivalent to `null`. */
10
+ exports.NoAttr = null;
11
+ /**
12
+ * Unified lpdf facade.
13
+ *
14
+ * All document, layout, and canvas factory methods are available as flat
15
+ * properties on this object. Construction-time configuration is handled via
16
+ * `L.engine()`.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { L, NoAttr } from 'lpdf';
21
+ *
22
+ * const engine = L.engine().setLicenseKey(process.env.LPDF_KEY);
23
+ *
24
+ * const doc = L.document(NoAttr, [
25
+ * L.section(NoAttr, [
26
+ * L.layout(null, [ L.text(NoAttr, ['Hello']) ]),
27
+ * ]),
28
+ * ]);
29
+ *
30
+ * const pdf = await engine.render(doc);
31
+ * ```
32
+ */
33
+ exports.L = Object.freeze({
34
+ /** Create a new {@link PdfEngine} instance. Call `.setLicenseKey()` to configure. */
35
+ engine: () => new engine_1.PdfEngine(),
36
+ /** Convert a `PdfDocument` tree to an lpdf XML string. */
37
+ toXml: (doc) => (0, kit_to_xml_1.kitToXml)(doc),
38
+ // ── Kit ───────────────────────────────────────────────────────────────────
39
+ document: kit_1.LpdfKit.document,
40
+ section: kit_1.LpdfKit.section,
41
+ layout: kit_1.LpdfKit.layout,
42
+ canvas: kit_1.LpdfKit.canvas,
43
+ tokens: (attrs) => attrs,
44
+ // ── Layout ────────────────────────────────────────────────────────────────
45
+ stack: layout_1.LpdfLayout.stack,
46
+ flank: layout_1.LpdfLayout.flank,
47
+ split: layout_1.LpdfLayout.split,
48
+ cluster: layout_1.LpdfLayout.cluster,
49
+ grid: layout_1.LpdfLayout.grid,
50
+ frame: layout_1.LpdfLayout.frame,
51
+ link: layout_1.LpdfLayout.link,
52
+ table: layout_1.LpdfLayout.table,
53
+ thead: layout_1.LpdfLayout.thead,
54
+ tr: layout_1.LpdfLayout.tr,
55
+ td: layout_1.LpdfLayout.td,
56
+ text: layout_1.LpdfLayout.text,
57
+ span: layout_1.LpdfLayout.span,
58
+ divider: layout_1.LpdfLayout.divider,
59
+ img: layout_1.LpdfLayout.img,
60
+ barcode: layout_1.LpdfLayout.barcode,
61
+ region: layout_1.LpdfLayout.region,
62
+ field: layout_1.LpdfLayout.field,
63
+ // ── Canvas ────────────────────────────────────────────────────────────────
64
+ layer: canvas_1.LpdfCanvas.layer,
65
+ rect: canvas_1.LpdfCanvas.rect,
66
+ line: canvas_1.LpdfCanvas.line,
67
+ ellipse: canvas_1.LpdfCanvas.ellipse,
68
+ circle: canvas_1.LpdfCanvas.circle,
69
+ path: canvas_1.LpdfCanvas.path,
70
+ textAt: canvas_1.LpdfCanvas.textAt,
71
+ imgAt: canvas_1.LpdfCanvas.imgAt,
72
+ });
package/dist/_shared.d.ts CHANGED
@@ -1,13 +1,10 @@
1
1
  /**
2
2
  * Shared types used by both the Node.js and browser entry points.
3
3
  */
4
+ /** Construction-time configuration for {@link PdfEngine}. Node has no infra options. */
5
+ export interface EngineOptions {
6
+ }
4
7
  export interface RenderOptions {
5
- /**
6
- * Pre-loaded font bytes for custom fonts referenced via <fonts src="…">.
7
- * Keys are the font names used in the document; values are raw TTF/OTF bytes.
8
- * @deprecated Pass font bytes via `LpdfEngine.loadFont()` instead.
9
- */
10
- fontBytes?: Record<string, Uint8Array>;
11
8
  /**
12
9
  * Optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`).
13
10
  * When provided, written as `/CreationDate` in the PDF info dictionary.
package/dist/browser.js CHANGED
@@ -378,63 +378,12 @@ async function __wbg_init(module_or_path) {
378
378
  return __wbg_finalize_init(instance, module);
379
379
  }
380
380
 
381
- // src/kit.ts
382
- function attrKey(camel) {
383
- return camel.replace(/[A-Z]/g, (c) => "-" + c.toLowerCase());
384
- }
385
- function buildAttrs(options) {
386
- const result = {};
387
- for (const [key, val] of Object.entries(options)) {
388
- if (val !== void 0) {
389
- result[attrKey(key)] = val;
390
- }
391
- }
392
- return result;
393
- }
394
- function layout(nodes = []) {
395
- return { type: "layout", nodes };
396
- }
397
- function canvas(layers = []) {
398
- return { type: "canvas", nodes: layers };
399
- }
400
- function section(input = {}) {
401
- return {
402
- type: "section",
403
- attrs: buildAttrs(input.options ?? {}),
404
- nodes: input.nodes ?? []
405
- };
406
- }
407
- function document(input = {}) {
408
- const { tokens, meta, ...restOpts } = input.options ?? {};
409
- const attrs = {
410
- ...buildAttrs(restOpts)
411
- };
412
- if (tokens !== void 0) attrs["tokens"] = tokens;
413
- if (meta !== void 0) attrs["meta"] = meta;
414
- return {
415
- version: 1,
416
- type: "document",
417
- attrs,
418
- nodes: input.sections ?? []
419
- };
420
- }
421
- var LpdfKit = Object.freeze({
422
- layout,
423
- canvas,
424
- section,
425
- document
426
- });
427
-
428
381
  // src/browser.ts
429
- async function initLpdf(wasmSource, licenseKey = "", initOptions = {}) {
382
+ var NoAttr = null;
383
+ async function initLpdf(wasmSource, licenseKey = "") {
430
384
  await __wbg_init(wasmSource);
431
385
  const fontMap = /* @__PURE__ */ new Map();
432
386
  const imageMap = /* @__PURE__ */ new Map();
433
- if (initOptions.fontBytes) {
434
- for (const [name, bytes] of Object.entries(initOptions.fontBytes)) {
435
- fontMap.set(name, bytes);
436
- }
437
- }
438
387
  return {
439
388
  loadFont(name, bytes) {
440
389
  fontMap.set(name, bytes);
@@ -442,27 +391,37 @@ async function initLpdf(wasmSource, licenseKey = "", initOptions = {}) {
442
391
  loadImage(name, bytes) {
443
392
  imageMap.set(name, bytes);
444
393
  },
445
- async renderPdf(xml, callOptions = {}) {
394
+ async render(input, callOptions = {}) {
446
395
  const engine = new LpdfEngine(licenseKey);
447
396
  for (const [name, bytes] of fontMap) {
448
397
  engine.load_font(name, bytes);
449
398
  }
450
- if (callOptions.fontBytes) {
451
- for (const [name, bytes] of Object.entries(callOptions.fontBytes)) {
452
- if (!fontMap.has(name)) engine.load_font(name, bytes);
453
- }
454
- }
455
399
  for (const [name, bytes] of imageMap) {
456
400
  engine.load_image(name, bytes);
457
401
  }
458
- const dataJson = callOptions.data != null ? JSON.stringify(callOptions.data) : null;
459
- const pdf = engine.render_pdf(xml, dataJson);
402
+ if (callOptions.createdOn) {
403
+ engine.set_created_on(callOptions.createdOn);
404
+ }
405
+ let pdf;
406
+ if (typeof input === "string") {
407
+ const dataJson = callOptions.data != null ? JSON.stringify(callOptions.data) : null;
408
+ pdf = engine.render_pdf(input, dataJson);
409
+ } else {
410
+ const wasmExt = engine;
411
+ if (typeof wasmExt.render_tree_pdf === "function") {
412
+ pdf = wasmExt.render_tree_pdf(JSON.stringify(input));
413
+ } else {
414
+ const mod = engine;
415
+ const xml = mod.constructor.kit_to_xml?.(JSON.stringify(input)) ?? "";
416
+ pdf = engine.render_pdf(xml, null);
417
+ }
418
+ }
460
419
  engine.free();
461
420
  return pdf;
462
421
  }
463
422
  };
464
423
  }
465
424
  export {
466
- LpdfKit,
425
+ NoAttr,
467
426
  initLpdf
468
427
  };
package/dist/canvas.d.ts CHANGED
@@ -8,6 +8,8 @@ export interface CanvasRectStyle {
8
8
  strokeWidth?: number;
9
9
  strokeDash?: number[];
10
10
  borderRadius?: number;
11
+ opacity?: number;
12
+ anchor?: string;
11
13
  }
12
14
  export interface CanvasLineStyle {
13
15
  stroke?: string;
@@ -21,6 +23,8 @@ export interface CanvasEllipseStyle {
21
23
  stroke?: string;
22
24
  strokeWidth?: number;
23
25
  strokeDash?: number[];
26
+ opacity?: number;
27
+ anchor?: string;
24
28
  }
25
29
  export interface CanvasPathStyle {
26
30
  fill?: string;
@@ -30,6 +34,7 @@ export interface CanvasPathStyle {
30
34
  fillRuleEvenodd?: boolean;
31
35
  lineCap?: LineCap;
32
36
  lineJoin?: LineJoin;
37
+ opacity?: number;
33
38
  }
34
39
  export interface CanvasTextStyle {
35
40
  font?: string;
@@ -38,6 +43,8 @@ export interface CanvasTextStyle {
38
43
  align?: TextAlign;
39
44
  lineHeight?: number;
40
45
  width?: number;
46
+ opacity?: number;
47
+ anchor?: string;
41
48
  }
42
49
  export interface CanvasRun {
43
50
  text: string;
@@ -100,7 +107,9 @@ export interface LpdfCanvasImgNode {
100
107
  attrs: Record<string, string>;
101
108
  }
102
109
  export type LpdfCanvasPrimitiveNode = LpdfCanvasRectNode | LpdfCanvasLineNode | LpdfCanvasEllipseNode | LpdfCanvasCircleNode | LpdfCanvasPathNode | LpdfCanvasTextNode | LpdfCanvasImgNode;
103
- export interface CanvasLayerOptions {
110
+ /** @deprecated Use {@link LayerAttr} */
111
+ export type CanvasLayerOptions = LayerAttr;
112
+ export interface LayerAttr {
104
113
  page?: PageScope | string;
105
114
  opacity?: number;
106
115
  transform?: CanvasTransform;
@@ -115,17 +124,17 @@ declare function line(x1: number, y1: number, x2: number, y2: number, style?: Ca
115
124
  declare function ellipse(cx: number, cy: number, rx: number, ry: number, style?: CanvasEllipseStyle): LpdfCanvasEllipseNode;
116
125
  declare function circle(cx: number, cy: number, r: number, style?: CanvasEllipseStyle): LpdfCanvasCircleNode;
117
126
  declare function path(d: string, style?: CanvasPathStyle): LpdfCanvasPathNode;
118
- declare function canvasText(x: number, y: number, content: string, style?: CanvasTextStyle, runs?: CanvasRun[]): LpdfCanvasTextNode;
119
- declare function img(x: number, y: number, w: number, h: number, name: string): LpdfCanvasImgNode;
120
- declare function layer(nodes: LpdfCanvasPrimitiveNode[], options?: CanvasLayerOptions): LpdfCanvasLayerNode;
127
+ declare function textAt(x: number, y: number, content: string, style?: CanvasTextStyle, runs?: CanvasRun[]): LpdfCanvasTextNode;
128
+ declare function imgAt(x: number, y: number, w: number, h: number, name: string, anchor?: string): LpdfCanvasImgNode;
129
+ declare function layer(attrs: LayerAttr | null, nodes: LpdfCanvasPrimitiveNode[]): LpdfCanvasLayerNode;
121
130
  export declare const LpdfCanvas: Readonly<{
122
131
  rect: typeof rect;
123
132
  line: typeof line;
124
133
  ellipse: typeof ellipse;
125
134
  circle: typeof circle;
126
135
  path: typeof path;
127
- text: typeof canvasText;
128
- img: typeof img;
136
+ textAt: typeof textAt;
137
+ imgAt: typeof imgAt;
129
138
  layer: typeof layer;
130
139
  }>;
131
140
  export {};