@lpdfio/lpdf 0.5.0 → 0.7.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/dist/index.d.ts CHANGED
@@ -1,45 +1,9 @@
1
- export * from './engine';
2
- export * from './kit';
3
- export * from './layout';
4
- export * from './canvas';
5
- export * from './_shared';
6
- export { kitToXml } from './kit-to-xml';
7
- import { LpdfEngine } from './engine';
8
- export declare const Lpdf: Readonly<{
9
- Engine: typeof LpdfEngine;
10
- Kit: Readonly<{
11
- layout: (nodes?: import("./layout").LpdfNode[]) => import("./kit").LpdfLayoutBlock;
12
- canvas: (layers?: import("./canvas").LpdfCanvasLayerNode[]) => import("./kit").LpdfCanvasBlock;
13
- section: (input?: import("./kit").SectionInput) => import("./kit").LpdfSectionNode;
14
- document: (input?: import("./kit").DocumentInput) => import("./kit").LpdfDocument;
15
- }>;
16
- Layout: Readonly<{
17
- stack: (nodes?: import("./layout").LpdfNode[], options?: import("./layout").StackOptions) => import("./layout").LpdfContainerNode;
18
- flank: (nodes?: import("./layout").LpdfNode[], options?: import("./layout").FlankOptions) => import("./layout").LpdfContainerNode;
19
- split: (nodes?: import("./layout").LpdfNode[], options?: import("./layout").SplitOptions) => import("./layout").LpdfContainerNode;
20
- cluster: (nodes?: import("./layout").LpdfNode[], options?: import("./layout").ClusterOptions) => import("./layout").LpdfContainerNode;
21
- grid: (nodes?: import("./layout").LpdfNode[], options?: import("./layout").GridOptions) => import("./layout").LpdfContainerNode;
22
- frame: (nodes?: import("./layout").LpdfNode[], options?: import("./layout").FrameOptions) => import("./layout").LpdfContainerNode;
23
- link: (nodes?: import("./layout").LpdfNode[], options?: import("./layout").LinkOptions) => import("./layout").LpdfContainerNode;
24
- text: (nodes?: (string | import("./layout").LpdfSpanNode)[], options?: import("./layout").TextOptions) => import("./layout").LpdfTextNode;
25
- span: (nodes?: string[], options?: import("./layout").SpanOptions) => import("./layout").LpdfSpanNode;
26
- divider: (options?: import("./layout").DividerOptions) => import("./layout").LpdfDividerNode;
27
- img: (options: import("./layout").ImgOptions) => import("./layout").LpdfImgNode;
28
- barcode: (options: import("./layout").BarcodeOptions) => import("./layout").LpdfBarcodeNode;
29
- table: (options: import("./layout").TableOptions, nodes?: (import("./layout").LpdfTheadNode | import("./layout").LpdfTrNode)[]) => import("./layout").LpdfTableNode;
30
- thead: (nodes?: import("./layout").LpdfTdNode[], options?: import("./layout").TheadOptions) => import("./layout").LpdfTheadNode;
31
- tr: (nodes?: import("./layout").LpdfTdNode[], options?: import("./layout").TrOptions) => import("./layout").LpdfTrNode;
32
- td: (nodes?: import("./layout").LpdfNode[], options?: import("./layout").TdOptions) => import("./layout").LpdfTdNode;
33
- region: (pin: string, nodes?: import("./layout").LpdfNode[], options?: import("./layout").RegionOptions) => import("./layout").LpdfRegionNode;
34
- }>;
35
- Canvas: Readonly<{
36
- rect: (x: number, y: number, w: number, h: number, style?: import("./canvas").CanvasRectStyle) => import("./canvas").LpdfCanvasRectNode;
37
- line: (x1: number, y1: number, x2: number, y2: number, style?: import("./canvas").CanvasLineStyle) => import("./canvas").LpdfCanvasLineNode;
38
- ellipse: (cx: number, cy: number, rx: number, ry: number, style?: import("./canvas").CanvasEllipseStyle) => import("./canvas").LpdfCanvasEllipseNode;
39
- circle: (cx: number, cy: number, r: number, style?: import("./canvas").CanvasEllipseStyle) => import("./canvas").LpdfCanvasCircleNode;
40
- path: (d: string, style?: import("./canvas").CanvasPathStyle) => import("./canvas").LpdfCanvasPathNode;
41
- text: (x: number, y: number, content: string, style?: import("./canvas").CanvasTextStyle, runs?: import("./canvas").CanvasRun[]) => import("./canvas").LpdfCanvasTextNode;
42
- img: (x: number, y: number, w: number, h: number, name: string) => import("./canvas").LpdfCanvasImgNode;
43
- layer: (nodes: import("./canvas").LpdfCanvasPrimitiveNode[], options?: import("./canvas").CanvasLayerOptions) => import("./canvas").LpdfCanvasLayerNode;
44
- }>;
45
- }>;
1
+ export { PdfEngine, LpdfRenderError } from './engine';
2
+ export type { EncryptPermissions, EncryptOptions } from './engine';
3
+ export type { RenderOptions, EngineOptions, PageScope } from './_shared';
4
+ export type { PdfDocument, LpdfSectionNode, LpdfLayoutBlock, LpdfCanvasBlock, LpdfTokens, LpdfFontDef, LpdfMeta, SectionAttr, DocumentAttr, } from './kit';
5
+ export type { StackAttr, FlankAttr, SplitAttr, ClusterAttr, GridAttr, FrameAttr, LinkAttr, TableAttr, TheadAttr, TrAttr, TdAttr, TextAttr, SpanAttr, DividerAttr, ImgAttr, BarcodeAttr, RegionAttr, } from './layout';
6
+ export type { LpdfNode, LpdfContainerNode, LpdfTextNode, LpdfSpanNode, LpdfDividerNode, LpdfImgNode, LpdfBarcodeNode, LpdfTableNode, LpdfTheadNode, LpdfTrNode, LpdfTdNode, LpdfRegionNode, } from './layout';
7
+ export { CanvasTransform } from './canvas';
8
+ export type { LineCap, LineJoin, TextAlign, LayerAttr, CanvasRun, CanvasRectStyle, CanvasLineStyle, CanvasEllipseStyle, CanvasPathStyle, CanvasTextStyle, LpdfCanvasLayerNode, LpdfCanvasPrimitiveNode, LpdfCanvasRectNode, LpdfCanvasLineNode, LpdfCanvasEllipseNode, LpdfCanvasCircleNode, LpdfCanvasPathNode, LpdfCanvasTextNode, LpdfCanvasImgNode, } from './canvas';
9
+ export { L, NoAttr } from './pdf';
package/dist/index.js CHANGED
@@ -1,34 +1,14 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Lpdf = exports.kitToXml = void 0;
18
- __exportStar(require("./engine"), exports);
19
- __exportStar(require("./kit"), exports);
20
- __exportStar(require("./layout"), exports);
21
- __exportStar(require("./canvas"), exports);
22
- __exportStar(require("./_shared"), exports);
23
- var kit_to_xml_1 = require("./kit-to-xml");
24
- Object.defineProperty(exports, "kitToXml", { enumerable: true, get: function () { return kit_to_xml_1.kitToXml; } });
25
- const engine_1 = require("./engine");
26
- const kit_1 = require("./kit");
27
- const layout_1 = require("./layout");
28
- const canvas_1 = require("./canvas");
29
- exports.Lpdf = Object.freeze({
30
- Engine: engine_1.LpdfEngine,
31
- Kit: kit_1.LpdfKit,
32
- Layout: layout_1.LpdfLayout,
33
- Canvas: canvas_1.LpdfCanvas,
34
- });
3
+ exports.NoAttr = exports.L = exports.CanvasTransform = exports.LpdfRenderError = exports.PdfEngine = void 0;
4
+ // ── Engine ────────────────────────────────────────────────────────────────────
5
+ var engine_1 = require("./engine");
6
+ Object.defineProperty(exports, "PdfEngine", { enumerable: true, get: function () { return engine_1.PdfEngine; } });
7
+ Object.defineProperty(exports, "LpdfRenderError", { enumerable: true, get: function () { return engine_1.LpdfRenderError; } });
8
+ // ── Canvas types ──────────────────────────────────────────────────────────────
9
+ var canvas_1 = require("./canvas");
10
+ Object.defineProperty(exports, "CanvasTransform", { enumerable: true, get: function () { return canvas_1.CanvasTransform; } });
11
+ // ── Facade ────────────────────────────────────────────────────────────────────
12
+ var pdf_1 = require("./pdf");
13
+ Object.defineProperty(exports, "L", { enumerable: true, get: function () { return pdf_1.L; } });
14
+ Object.defineProperty(exports, "NoAttr", { enumerable: true, get: function () { return pdf_1.NoAttr; } });
@@ -16,7 +16,7 @@
16
16
  * console.log(xml);
17
17
  * ```
18
18
  */
19
- import type { LpdfDocument } from './kit';
19
+ import type { PdfDocument } from './kit';
20
20
  /**
21
21
  * Convert an `LpdfDocument` tree (built with `LpdfKit`) into an lpdf XML
22
22
  * string.
@@ -27,4 +27,4 @@ import type { LpdfDocument } from './kit';
27
27
  * @param doc - The document tree returned by `LpdfKit.document(...)`.
28
28
  * @returns A well-formed XML string with an `<?xml ...?>` declaration.
29
29
  */
30
- export declare function kitToXml(doc: LpdfDocument): string;
30
+ export declare function kitToXml(doc: PdfDocument): string;
package/dist/kit.d.ts CHANGED
@@ -49,7 +49,7 @@ export interface LpdfMeta {
49
49
  keywords?: string;
50
50
  creator?: string;
51
51
  }
52
- export interface SectionOptions {
52
+ export interface SectionAttr {
53
53
  size?: string;
54
54
  orientation?: string;
55
55
  margin?: string;
@@ -57,7 +57,7 @@ export interface SectionOptions {
57
57
  title?: string;
58
58
  debug?: string;
59
59
  }
60
- export interface DocumentOptions {
60
+ export interface DocumentAttr {
61
61
  size?: string;
62
62
  orientation?: string;
63
63
  margin?: string;
@@ -81,25 +81,16 @@ export interface LpdfSectionNode {
81
81
  attrs: Record<string, string>;
82
82
  nodes: (LpdfLayoutBlock | LpdfCanvasBlock)[];
83
83
  }
84
- export interface LpdfDocument {
84
+ export interface PdfDocument {
85
85
  version: 1;
86
86
  type: 'document';
87
87
  attrs: Record<string, unknown>;
88
88
  nodes: LpdfSectionNode[];
89
89
  }
90
- export interface SectionInput {
91
- nodes?: (LpdfLayoutBlock | LpdfCanvasBlock)[];
92
- options?: SectionOptions;
93
- }
94
- export interface DocumentInput {
95
- /** Sections — serialised as `nodes` on the wire (matching kit_to_xml and parse_tree). */
96
- sections?: LpdfSectionNode[];
97
- options?: DocumentOptions;
98
- }
99
- declare function layout(nodes?: LpdfNode[]): LpdfLayoutBlock;
100
- declare function canvas(layers?: LpdfCanvasLayerNode[]): LpdfCanvasBlock;
101
- declare function section(input?: SectionInput): LpdfSectionNode;
102
- declare function document(input?: DocumentInput): LpdfDocument;
90
+ declare function layout(_attrs: null, nodes: LpdfNode[]): LpdfLayoutBlock;
91
+ declare function canvas(_attrs: null, layers: LpdfCanvasLayerNode[]): LpdfCanvasBlock;
92
+ declare function section(attrs: SectionAttr | null, nodes: (LpdfLayoutBlock | LpdfCanvasBlock)[]): LpdfSectionNode;
93
+ declare function document(attrs: DocumentAttr | null, nodes: LpdfSectionNode[]): PdfDocument;
103
94
  export declare const LpdfKit: Readonly<{
104
95
  layout: typeof layout;
105
96
  canvas: typeof canvas;
package/dist/kit.js CHANGED
@@ -40,33 +40,33 @@ function buildAttrs(options) {
40
40
  return result;
41
41
  }
42
42
  // ── Factory functions ─────────────────────────────────────────────────────────
43
- function layout(nodes = []) {
43
+ function layout(_attrs, nodes) {
44
44
  return { type: 'layout', nodes };
45
45
  }
46
- function canvas(layers = []) {
46
+ function canvas(_attrs, layers) {
47
47
  return { type: 'canvas', nodes: layers };
48
48
  }
49
- function section(input = {}) {
49
+ function section(attrs, nodes) {
50
50
  return {
51
51
  type: 'section',
52
- attrs: buildAttrs((input.options ?? {})),
53
- nodes: input.nodes ?? [],
52
+ attrs: buildAttrs((attrs ?? {})),
53
+ nodes,
54
54
  };
55
55
  }
56
- function document(input = {}) {
57
- const { tokens, meta, ...restOpts } = input.options ?? {};
58
- const attrs = {
56
+ function document(attrs, nodes) {
57
+ const { tokens, meta, ...restOpts } = attrs ?? {};
58
+ const attrsObj = {
59
59
  ...buildAttrs(restOpts),
60
60
  };
61
61
  if (tokens !== undefined)
62
- attrs['tokens'] = tokens;
62
+ attrsObj['tokens'] = tokens;
63
63
  if (meta !== undefined)
64
- attrs['meta'] = meta;
64
+ attrsObj['meta'] = meta;
65
65
  return {
66
66
  version: 1,
67
67
  type: 'document',
68
- attrs,
69
- nodes: input.sections ?? [],
68
+ attrs: attrsObj,
69
+ nodes,
70
70
  };
71
71
  }
72
72
  // ── LpdfKit export ────────────────────────────────────────────────────────────
package/dist/layout.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { PageScope } from './_shared';
2
- export interface StackOptions {
2
+ export interface StackAttr {
3
3
  gap?: string;
4
4
  padding?: string;
5
5
  background?: string;
@@ -11,7 +11,7 @@ export interface StackOptions {
11
11
  radius?: string;
12
12
  debug?: string;
13
13
  }
14
- export interface FlankOptions {
14
+ export interface FlankAttr {
15
15
  gap?: string;
16
16
  padding?: string;
17
17
  background?: string;
@@ -24,7 +24,7 @@ export interface FlankOptions {
24
24
  radius?: string;
25
25
  debug?: string;
26
26
  }
27
- export interface SplitOptions {
27
+ export interface SplitAttr {
28
28
  gap?: string;
29
29
  padding?: string;
30
30
  background?: string;
@@ -36,7 +36,7 @@ export interface SplitOptions {
36
36
  radius?: string;
37
37
  debug?: string;
38
38
  }
39
- export interface ClusterOptions {
39
+ export interface ClusterAttr {
40
40
  gap?: string;
41
41
  padding?: string;
42
42
  background?: string;
@@ -48,7 +48,7 @@ export interface ClusterOptions {
48
48
  radius?: string;
49
49
  debug?: string;
50
50
  }
51
- export interface GridOptions {
51
+ export interface GridAttr {
52
52
  cols?: string;
53
53
  colWidth?: string;
54
54
  gap?: string;
@@ -61,7 +61,7 @@ export interface GridOptions {
61
61
  radius?: string;
62
62
  debug?: string;
63
63
  }
64
- export interface FrameOptions {
64
+ export interface FrameAttr {
65
65
  width?: string;
66
66
  height?: string;
67
67
  padding?: string;
@@ -71,13 +71,13 @@ export interface FrameOptions {
71
71
  align?: string;
72
72
  debug?: string;
73
73
  }
74
- export interface LinkOptions {
74
+ export interface LinkAttr {
75
75
  url?: string;
76
76
  width?: string;
77
77
  height?: string;
78
78
  debug?: string;
79
79
  }
80
- export interface TableOptions {
80
+ export interface TableAttr {
81
81
  cols: string;
82
82
  border?: string;
83
83
  stripe?: string;
@@ -89,13 +89,13 @@ export interface TableOptions {
89
89
  repeat?: string;
90
90
  debug?: string;
91
91
  }
92
- export interface TheadOptions {
92
+ export interface TheadAttr {
93
93
  background?: string;
94
94
  }
95
- export interface TrOptions {
95
+ export interface TrAttr {
96
96
  background?: string;
97
97
  }
98
- export interface TdOptions {
98
+ export interface TdAttr {
99
99
  padding?: string;
100
100
  background?: string;
101
101
  align?: string;
@@ -105,7 +105,7 @@ export interface TdOptions {
105
105
  gap?: string;
106
106
  debug?: string;
107
107
  }
108
- export interface TextOptions {
108
+ export interface TextAttr {
109
109
  font?: string;
110
110
  fontSize?: string;
111
111
  textAlign?: string;
@@ -121,7 +121,7 @@ export interface TextOptions {
121
121
  repeat?: string;
122
122
  debug?: string;
123
123
  }
124
- export interface SpanOptions {
124
+ export interface SpanAttr {
125
125
  font?: string;
126
126
  fontSize?: string;
127
127
  color?: string;
@@ -130,13 +130,13 @@ export interface SpanOptions {
130
130
  underline?: string;
131
131
  strike?: string;
132
132
  }
133
- export interface DividerOptions {
133
+ export interface DividerAttr {
134
134
  color?: string;
135
135
  thickness?: string;
136
136
  direction?: string;
137
137
  debug?: string;
138
138
  }
139
- export interface ImgOptions {
139
+ export interface ImgAttr {
140
140
  name: string;
141
141
  height?: string;
142
142
  width?: string;
@@ -150,7 +150,7 @@ export interface ImgOptions {
150
150
  repeat?: string;
151
151
  debug?: string;
152
152
  }
153
- export interface BarcodeOptions {
153
+ export interface BarcodeAttr {
154
154
  type: string;
155
155
  data: string;
156
156
  size?: string;
@@ -163,7 +163,8 @@ export interface BarcodeOptions {
163
163
  repeat?: string;
164
164
  debug?: string;
165
165
  }
166
- export interface RegionOptions {
166
+ export interface RegionAttr {
167
+ pin: string;
167
168
  page?: PageScope | string;
168
169
  w?: string;
169
170
  debug?: string;
@@ -221,23 +222,23 @@ export interface LpdfRegionNode {
221
222
  nodes: LpdfNode[];
222
223
  }
223
224
  export type LpdfNode = LpdfContainerNode | LpdfTextNode | LpdfDividerNode | LpdfTableNode | LpdfImgNode | LpdfBarcodeNode | LpdfRegionNode;
224
- declare function stack(nodes?: LpdfNode[], options?: StackOptions): LpdfContainerNode;
225
- declare function flank(nodes?: LpdfNode[], options?: FlankOptions): LpdfContainerNode;
226
- declare function split(nodes?: LpdfNode[], options?: SplitOptions): LpdfContainerNode;
227
- declare function cluster(nodes?: LpdfNode[], options?: ClusterOptions): LpdfContainerNode;
228
- declare function grid(nodes?: LpdfNode[], options?: GridOptions): LpdfContainerNode;
229
- declare function frame(nodes?: LpdfNode[], options?: FrameOptions): LpdfContainerNode;
230
- declare function link(nodes?: LpdfNode[], options?: LinkOptions): LpdfContainerNode;
231
- declare function table(options: TableOptions, nodes?: (LpdfTheadNode | LpdfTrNode)[]): LpdfTableNode;
232
- declare function thead(nodes?: LpdfTdNode[], options?: TheadOptions): LpdfTheadNode;
233
- declare function tr(nodes?: LpdfTdNode[], options?: TrOptions): LpdfTrNode;
234
- declare function td(nodes?: LpdfNode[], options?: TdOptions): LpdfTdNode;
235
- declare function text(nodes?: (string | LpdfSpanNode)[], options?: TextOptions): LpdfTextNode;
236
- declare function span(nodes?: string[], options?: SpanOptions): LpdfSpanNode;
237
- declare function divider(options?: DividerOptions): LpdfDividerNode;
238
- declare function img(options: ImgOptions): LpdfImgNode;
239
- declare function barcode(options: BarcodeOptions): LpdfBarcodeNode;
240
- declare function region(pin: string, nodes?: LpdfNode[], options?: RegionOptions): LpdfRegionNode;
225
+ declare function stack(attrs: StackAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
226
+ declare function flank(attrs: FlankAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
227
+ declare function split(attrs: SplitAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
228
+ declare function cluster(attrs: ClusterAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
229
+ declare function grid(attrs: GridAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
230
+ declare function frame(attrs: FrameAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
231
+ declare function link(attrs: LinkAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
232
+ declare function table(attrs: TableAttr, nodes: (LpdfTheadNode | LpdfTrNode)[]): LpdfTableNode;
233
+ declare function thead(attrs: TheadAttr | null, nodes: LpdfTdNode[]): LpdfTheadNode;
234
+ declare function tr(attrs: TrAttr | null, nodes: LpdfTdNode[]): LpdfTrNode;
235
+ declare function td(attrs: TdAttr | null, nodes: LpdfNode[]): LpdfTdNode;
236
+ declare function text(attrs: TextAttr | null, nodes: (string | LpdfSpanNode)[]): LpdfTextNode;
237
+ declare function span(attrs: SpanAttr | null, nodes: string[]): LpdfSpanNode;
238
+ declare function divider(attrs: DividerAttr | null): LpdfDividerNode;
239
+ declare function img(attrs: ImgAttr): LpdfImgNode;
240
+ declare function barcode(attrs: BarcodeAttr): LpdfBarcodeNode;
241
+ declare function region(attrs: RegionAttr, nodes: LpdfNode[]): LpdfRegionNode;
241
242
  export declare const LpdfLayout: Readonly<{
242
243
  stack: typeof stack;
243
244
  flank: typeof flank;
package/dist/layout.js CHANGED
@@ -15,100 +15,100 @@ function buildAttrs(options) {
15
15
  return result;
16
16
  }
17
17
  // ── Helper ────────────────────────────────────────────────────────────────────
18
- function makeContainer(type, nodes, options) {
19
- return { type, attrs: buildAttrs(options ?? {}), nodes };
18
+ function makeContainer(type, attrs, nodes) {
19
+ return { type, attrs: buildAttrs(attrs ?? {}), nodes };
20
20
  }
21
21
  // ── LpdfLayout factory ────────────────────────────────────────────────────────
22
- function stack(nodes = [], options) {
23
- return makeContainer('stack', nodes, options);
22
+ function stack(attrs, nodes) {
23
+ return makeContainer('stack', attrs, nodes);
24
24
  }
25
- function flank(nodes = [], options) {
26
- return makeContainer('flank', nodes, options);
25
+ function flank(attrs, nodes) {
26
+ return makeContainer('flank', attrs, nodes);
27
27
  }
28
- function split(nodes = [], options) {
29
- return makeContainer('split', nodes, options);
28
+ function split(attrs, nodes) {
29
+ return makeContainer('split', attrs, nodes);
30
30
  }
31
- function cluster(nodes = [], options) {
32
- return makeContainer('cluster', nodes, options);
31
+ function cluster(attrs, nodes) {
32
+ return makeContainer('cluster', attrs, nodes);
33
33
  }
34
- function grid(nodes = [], options) {
35
- return makeContainer('grid', nodes, options);
34
+ function grid(attrs, nodes) {
35
+ return makeContainer('grid', attrs, nodes);
36
36
  }
37
- function frame(nodes = [], options) {
38
- return makeContainer('frame', nodes, options);
37
+ function frame(attrs, nodes) {
38
+ return makeContainer('frame', attrs, nodes);
39
39
  }
40
- function link(nodes = [], options) {
41
- return makeContainer('link', nodes, options);
40
+ function link(attrs, nodes) {
41
+ return makeContainer('link', attrs, nodes);
42
42
  }
43
- function table(options, nodes = []) {
43
+ function table(attrs, nodes) {
44
44
  return {
45
45
  type: 'table',
46
- attrs: buildAttrs(options),
46
+ attrs: buildAttrs(attrs),
47
47
  nodes,
48
48
  };
49
49
  }
50
- function thead(nodes = [], options) {
50
+ function thead(attrs, nodes) {
51
51
  return {
52
52
  type: 'thead',
53
- attrs: buildAttrs((options ?? {})),
53
+ attrs: buildAttrs((attrs ?? {})),
54
54
  nodes,
55
55
  };
56
56
  }
57
- function tr(nodes = [], options) {
57
+ function tr(attrs, nodes) {
58
58
  return {
59
59
  type: 'tr',
60
- attrs: buildAttrs((options ?? {})),
60
+ attrs: buildAttrs((attrs ?? {})),
61
61
  nodes,
62
62
  };
63
63
  }
64
- function td(nodes = [], options) {
64
+ function td(attrs, nodes) {
65
65
  return {
66
66
  type: 'td',
67
- attrs: buildAttrs((options ?? {})),
67
+ attrs: buildAttrs((attrs ?? {})),
68
68
  nodes,
69
69
  };
70
70
  }
71
- function text(nodes = [], options) {
71
+ function text(attrs, nodes) {
72
72
  return {
73
73
  type: 'text',
74
- attrs: buildAttrs((options ?? {})),
74
+ attrs: buildAttrs((attrs ?? {})),
75
75
  nodes,
76
76
  };
77
77
  }
78
- function span(nodes = [], options) {
78
+ function span(attrs, nodes) {
79
79
  return {
80
80
  type: 'span',
81
- attrs: buildAttrs((options ?? {})),
81
+ attrs: buildAttrs((attrs ?? {})),
82
82
  nodes,
83
83
  };
84
84
  }
85
- function divider(options) {
85
+ function divider(attrs) {
86
86
  return {
87
87
  type: 'divider',
88
- attrs: buildAttrs((options ?? {})),
88
+ attrs: buildAttrs((attrs ?? {})),
89
89
  };
90
90
  }
91
- function img(options) {
91
+ function img(attrs) {
92
92
  return {
93
93
  type: 'img',
94
- attrs: buildAttrs(options),
94
+ attrs: buildAttrs(attrs),
95
95
  };
96
96
  }
97
- function barcode(options) {
97
+ function barcode(attrs) {
98
98
  return {
99
99
  type: 'barcode',
100
- attrs: buildAttrs(options),
100
+ attrs: buildAttrs(attrs),
101
101
  };
102
102
  }
103
- function region(pin, nodes = [], options) {
104
- const attrs = { pin };
105
- if (options?.page !== undefined)
106
- attrs['page'] = options.page;
107
- if (options?.w !== undefined)
108
- attrs['w'] = options.w;
109
- if (options?.debug !== undefined)
110
- attrs['debug'] = options.debug;
111
- return { type: 'layout-region', attrs, nodes };
103
+ function region(attrs, nodes) {
104
+ const a = { pin: attrs.pin };
105
+ if (attrs.page !== undefined)
106
+ a['page'] = attrs.page;
107
+ if (attrs.w !== undefined)
108
+ a['w'] = attrs.w;
109
+ if (attrs.debug !== undefined)
110
+ a['debug'] = attrs.debug;
111
+ return { type: 'layout-region', attrs: a, nodes };
112
112
  }
113
113
  exports.LpdfLayout = Object.freeze({
114
114
  stack,
package/dist/pdf.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ import type { 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
+ stack: (attrs: import("./layout").StackAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
37
+ flank: (attrs: import("./layout").FlankAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
38
+ split: (attrs: import("./layout").SplitAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
39
+ cluster: (attrs: import("./layout").ClusterAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
40
+ grid: (attrs: import("./layout").GridAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
41
+ frame: (attrs: import("./layout").FrameAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
42
+ link: (attrs: import("./layout").LinkAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
43
+ table: (attrs: import("./layout").TableAttr, nodes: (import("./layout").LpdfTheadNode | import("./layout").LpdfTrNode)[]) => import("./layout").LpdfTableNode;
44
+ thead: (attrs: import("./layout").TheadAttr | null, nodes: import("./layout").LpdfTdNode[]) => import("./layout").LpdfTheadNode;
45
+ tr: (attrs: import("./layout").TrAttr | null, nodes: import("./layout").LpdfTdNode[]) => import("./layout").LpdfTrNode;
46
+ td: (attrs: import("./layout").TdAttr | null, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfTdNode;
47
+ text: (attrs: import("./layout").TextAttr | null, nodes: (string | import("./layout").LpdfSpanNode)[]) => import("./layout").LpdfTextNode;
48
+ span: (attrs: import("./layout").SpanAttr | null, nodes: string[]) => import("./layout").LpdfSpanNode;
49
+ divider: (attrs: import("./layout").DividerAttr | null) => import("./layout").LpdfDividerNode;
50
+ img: (attrs: import("./layout").ImgAttr) => import("./layout").LpdfImgNode;
51
+ barcode: (attrs: import("./layout").BarcodeAttr) => import("./layout").LpdfBarcodeNode;
52
+ region: (attrs: import("./layout").RegionAttr, nodes: import("./layout").LpdfNode[]) => import("./layout").LpdfRegionNode;
53
+ layer: (attrs: import("./canvas").LayerAttr | null, nodes: import("./canvas").LpdfCanvasPrimitiveNode[]) => import("./canvas").LpdfCanvasLayerNode;
54
+ rect: (x: number, y: number, w: number, h: number, style?: import("./canvas").CanvasRectStyle) => import("./canvas").LpdfCanvasRectNode;
55
+ line: (x1: number, y1: number, x2: number, y2: number, style?: import("./canvas").CanvasLineStyle) => import("./canvas").LpdfCanvasLineNode;
56
+ ellipse: (cx: number, cy: number, rx: number, ry: number, style?: import("./canvas").CanvasEllipseStyle) => import("./canvas").LpdfCanvasEllipseNode;
57
+ circle: (cx: number, cy: number, r: number, style?: import("./canvas").CanvasEllipseStyle) => import("./canvas").LpdfCanvasCircleNode;
58
+ path: (d: string, style?: import("./canvas").CanvasPathStyle) => import("./canvas").LpdfCanvasPathNode;
59
+ textAt: (x: number, y: number, content: string, style?: import("./canvas").CanvasTextStyle, runs?: import("./canvas").CanvasRun[]) => import("./canvas").LpdfCanvasTextNode;
60
+ imgAt: (x: number, y: number, w: number, h: number, name: string) => import("./canvas").LpdfCanvasImgNode;
61
+ }>;