@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/dist/canvas.js CHANGED
@@ -60,6 +60,10 @@ function rect(x, y, w, h, style) {
60
60
  attrs['stroke-dash'] = style.strokeDash.join(' ');
61
61
  if (style?.borderRadius !== undefined)
62
62
  attrs['radius'] = String(style.borderRadius);
63
+ if (style?.opacity !== undefined)
64
+ attrs['opacity'] = String(style.opacity);
65
+ if (style?.anchor !== undefined)
66
+ attrs['anchor'] = style.anchor;
63
67
  return { type: 'canvas-rect', attrs };
64
68
  }
65
69
  function line(x1, y1, x2, y2, style) {
@@ -90,6 +94,10 @@ function ellipse(cx, cy, rx, ry, style) {
90
94
  attrs['stroke-width'] = String(style.strokeWidth);
91
95
  if (style?.strokeDash !== undefined)
92
96
  attrs['stroke-dash'] = style.strokeDash.join(' ');
97
+ if (style?.opacity !== undefined)
98
+ attrs['opacity'] = String(style.opacity);
99
+ if (style?.anchor !== undefined)
100
+ attrs['anchor'] = style.anchor;
93
101
  return { type: 'canvas-ellipse', attrs };
94
102
  }
95
103
  function circle(cx, cy, r, style) {
@@ -104,6 +112,10 @@ function circle(cx, cy, r, style) {
104
112
  attrs['stroke-width'] = String(style.strokeWidth);
105
113
  if (style?.strokeDash !== undefined)
106
114
  attrs['stroke-dash'] = style.strokeDash.join(' ');
115
+ if (style?.opacity !== undefined)
116
+ attrs['opacity'] = String(style.opacity);
117
+ if (style?.anchor !== undefined)
118
+ attrs['anchor'] = style.anchor;
107
119
  return { type: 'canvas-circle', attrs };
108
120
  }
109
121
  function path(d, style) {
@@ -122,9 +134,11 @@ function path(d, style) {
122
134
  attrs['line-cap'] = style.lineCap;
123
135
  if (style?.lineJoin !== undefined)
124
136
  attrs['line-join'] = style.lineJoin;
137
+ if (style?.opacity !== undefined)
138
+ attrs['opacity'] = String(style.opacity);
125
139
  return { type: 'canvas-path', attrs };
126
140
  }
127
- function canvasText(x, y, content, style, runs) {
141
+ function textAt(x, y, content, style, runs) {
128
142
  const attrs = { x: String(x), y: String(y) };
129
143
  if (style?.font !== undefined)
130
144
  attrs['font'] = style.font;
@@ -138,6 +152,10 @@ function canvasText(x, y, content, style, runs) {
138
152
  attrs['line-height'] = String(style.lineHeight);
139
153
  if (style?.width !== undefined)
140
154
  attrs['w'] = String(style.width);
155
+ if (style?.opacity !== undefined)
156
+ attrs['opacity'] = String(style.opacity);
157
+ if (style?.anchor !== undefined)
158
+ attrs['anchor'] = style.anchor;
141
159
  const node = { type: 'canvas-text', text: content, attrs };
142
160
  if (runs && runs.length > 0) {
143
161
  node.runs = runs.map(r => {
@@ -153,21 +171,21 @@ function canvasText(x, y, content, style, runs) {
153
171
  }
154
172
  return node;
155
173
  }
156
- function img(x, y, w, h, name) {
157
- return {
158
- type: 'canvas-img',
159
- attrs: { x: String(x), y: String(y), w: String(w), h: String(h), name },
160
- };
174
+ function imgAt(x, y, w, h, name, anchor) {
175
+ const attrs = { x: String(x), y: String(y), w: String(w), h: String(h), name };
176
+ if (anchor !== undefined)
177
+ attrs['anchor'] = anchor;
178
+ return { type: 'canvas-img', attrs };
161
179
  }
162
- function layer(nodes, options) {
163
- const attrs = {};
164
- if (options?.page !== undefined)
165
- attrs['page'] = options.page;
166
- if (options?.opacity !== undefined)
167
- attrs['opacity'] = String(options.opacity);
168
- if (options?.transform !== undefined)
169
- attrs['transform'] = options.transform.toString();
170
- return { type: 'canvas-layer', attrs, nodes };
180
+ function layer(attrs, nodes) {
181
+ const a = {};
182
+ if (attrs?.page !== undefined)
183
+ a['page'] = attrs.page;
184
+ if (attrs?.opacity !== undefined)
185
+ a['opacity'] = String(attrs.opacity);
186
+ if (attrs?.transform !== undefined)
187
+ a['transform'] = attrs.transform.toString();
188
+ return { type: 'canvas-layer', attrs: a, nodes };
171
189
  }
172
190
  exports.LpdfCanvas = Object.freeze({
173
191
  rect,
@@ -175,7 +193,7 @@ exports.LpdfCanvas = Object.freeze({
175
193
  ellipse,
176
194
  circle,
177
195
  path,
178
- text: canvasText,
179
- img,
196
+ textAt,
197
+ imgAt,
180
198
  layer,
181
199
  });
package/dist/engine.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { RenderOptions } from './_shared';
2
- import type { LpdfDocument } from './kit';
2
+ import type { PdfDocument } from './kit';
3
3
  /** Thrown when the lpdf engine returns a layout or parse error. */
4
4
  export declare class LpdfRenderError extends Error {
5
5
  constructor(message: string);
@@ -15,7 +15,7 @@ export interface EncryptPermissions {
15
15
  assemble?: boolean;
16
16
  print_hq?: boolean;
17
17
  }
18
- /** RC4-128 encryption options passed to {@link LpdfEngine.setEncryption}. */
18
+ /** RC4-128 encryption options passed to {@link PdfEngine.setEncryption}. */
19
19
  export interface EncryptOptions {
20
20
  /** Open password shown to readers. Empty string = no open password required. */
21
21
  userPassword: string;
@@ -24,26 +24,29 @@ export interface EncryptOptions {
24
24
  /** Permission flags applied to the document. Omitted flags default to `true`. */
25
25
  permissions?: EncryptPermissions;
26
26
  }
27
- export declare class LpdfEngine {
28
- private readonly _licenseKey;
29
- private readonly _opts;
27
+ export declare class PdfEngine {
28
+ private _licenseKey;
30
29
  private readonly _fonts;
31
30
  private readonly _images;
32
31
  private _disposed;
33
32
  private _encrypt;
34
- constructor(licenseKey: string, options?: RenderOptions);
33
+ constructor();
34
+ /**
35
+ * Set the license key. Returns `this` for chaining.
36
+ */
37
+ setLicenseKey(key: string): this;
35
38
  /**
36
39
  * Register raw TTF/OTF bytes for a custom font name used in `<font src="…">`.
37
- * Call before `renderPdf`. Returns `this` for chaining.
40
+ * Call before `render`. Returns `this` for chaining.
38
41
  */
39
42
  loadFont(name: string, bytes: Uint8Array): this;
40
43
  /**
41
44
  * Register raw image bytes (PNG or JPEG) for an image name used in `<img name="…">`.
42
- * Call before `renderPdf`. Returns `this` for chaining.
45
+ * Call before `render`. Returns `this` for chaining.
43
46
  */
44
47
  loadImage(name: string, bytes: Uint8Array): this;
45
48
  /**
46
- * Configure RC4-128 encryption for all subsequent `renderPdf` calls.
49
+ * Configure RC4-128 encryption for all subsequent `render` calls.
47
50
  * Returns `this` for chaining.
48
51
  */
49
52
  setEncryption(options: EncryptOptions): this;
@@ -53,7 +56,7 @@ export declare class LpdfEngine {
53
56
  */
54
57
  clearEncryption(): this;
55
58
  /**
56
- * Release held resources. Idempotent. Subsequent `renderPdf` / `loadFont`
59
+ * Release held resources. Idempotent. Subsequent `render` / `loadFont`
57
60
  * calls after disposal will throw.
58
61
  */
59
62
  dispose(): void;
@@ -62,9 +65,9 @@ export declare class LpdfEngine {
62
65
  /**
63
66
  * Render an lpdf XML string to PDF bytes (Node.js).
64
67
  */
65
- renderPdf(input: string, callOptions?: RenderOptions): Promise<Uint8Array>;
68
+ render(input: string, callOptions?: RenderOptions): Promise<Uint8Array>;
66
69
  /**
67
- * Render an `LpdfDocument` tree (built with `LpdfKit`) to PDF bytes (Node.js).
70
+ * Render a `PdfDocument` tree (built with `Pdf.document`) to PDF bytes (Node.js).
68
71
  */
69
- renderPdf(input: LpdfDocument, callOptions?: RenderOptions): Promise<Uint8Array>;
72
+ render(input: PdfDocument, callOptions?: RenderOptions): Promise<Uint8Array>;
70
73
  }
package/dist/engine.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LpdfEngine = exports.LpdfRenderError = void 0;
3
+ exports.PdfEngine = exports.LpdfRenderError = void 0;
4
4
  const node_fs_1 = require("node:fs");
5
5
  // require() path is relative to the compiled output at dist/engine.js.
6
6
  // In the published package, wasm-pack artifacts live in dist/wasm/.
@@ -16,18 +16,25 @@ class LpdfRenderError extends Error {
16
16
  }
17
17
  }
18
18
  exports.LpdfRenderError = LpdfRenderError;
19
- class LpdfEngine {
20
- constructor(licenseKey, options = {}) {
19
+ class PdfEngine {
20
+ constructor() {
21
+ this._licenseKey = '';
21
22
  this._fonts = new Map();
22
23
  this._images = new Map();
23
24
  this._disposed = false;
24
25
  this._encrypt = null;
25
- this._licenseKey = licenseKey;
26
- this._opts = options;
26
+ }
27
+ /**
28
+ * Set the license key. Returns `this` for chaining.
29
+ */
30
+ setLicenseKey(key) {
31
+ this._throwIfDisposed();
32
+ this._licenseKey = key;
33
+ return this;
27
34
  }
28
35
  /**
29
36
  * Register raw TTF/OTF bytes for a custom font name used in `<font src="…">`.
30
- * Call before `renderPdf`. Returns `this` for chaining.
37
+ * Call before `render`. Returns `this` for chaining.
31
38
  */
32
39
  loadFont(name, bytes) {
33
40
  this._throwIfDisposed();
@@ -36,7 +43,7 @@ class LpdfEngine {
36
43
  }
37
44
  /**
38
45
  * Register raw image bytes (PNG or JPEG) for an image name used in `<img name="…">`.
39
- * Call before `renderPdf`. Returns `this` for chaining.
46
+ * Call before `render`. Returns `this` for chaining.
40
47
  */
41
48
  loadImage(name, bytes) {
42
49
  this._throwIfDisposed();
@@ -44,7 +51,7 @@ class LpdfEngine {
44
51
  return this;
45
52
  }
46
53
  /**
47
- * Configure RC4-128 encryption for all subsequent `renderPdf` calls.
54
+ * Configure RC4-128 encryption for all subsequent `render` calls.
48
55
  * Returns `this` for chaining.
49
56
  */
50
57
  setEncryption(options) {
@@ -62,7 +69,7 @@ class LpdfEngine {
62
69
  return this;
63
70
  }
64
71
  /**
65
- * Release held resources. Idempotent. Subsequent `renderPdf` / `loadFont`
72
+ * Release held resources. Idempotent. Subsequent `render` / `loadFont`
66
73
  * calls after disposal will throw.
67
74
  */
68
75
  dispose() {
@@ -71,28 +78,20 @@ class LpdfEngine {
71
78
  [Symbol.dispose]() { this.dispose(); }
72
79
  _throwIfDisposed() {
73
80
  if (this._disposed)
74
- throw new Error('LpdfEngine has been disposed.');
81
+ throw new Error('PdfEngine has been disposed.');
75
82
  }
76
- async renderPdf(input, callOptions = {}) {
83
+ async render(input, callOptions = {}) {
77
84
  this._throwIfDisposed();
78
- // Merge fonts: instance-level loadFont() calls take precedence over the
79
- // deprecated fontBytes option, which is kept for one-version compat.
80
- const allFonts = new Map(this._fonts);
81
- const extraBytes = { ...this._opts.fontBytes, ...callOptions.fontBytes };
82
- for (const [name, bytes] of Object.entries(extraBytes)) {
83
- if (!allFonts.has(name))
84
- allFonts.set(name, bytes);
85
- }
86
85
  const engine = new WasmEngine(this._licenseKey);
87
- const createdOn = callOptions.createdOn ?? this._opts.createdOn;
88
- if (createdOn) {
89
- engine.set_created_on(createdOn);
86
+ if (callOptions.createdOn) {
87
+ engine.set_created_on(callOptions.createdOn);
90
88
  }
91
89
  let pdf;
92
90
  try {
93
91
  if (typeof input === 'string') {
94
92
  // XML path — auto-load fonts and images declared via src="…".
95
93
  const xml = input;
94
+ const allFonts = new Map(this._fonts);
96
95
  for (const [key, src] of extractAssetSrcs(xml, 'font')) {
97
96
  if (!allFonts.has(key)) {
98
97
  try {
@@ -126,6 +125,7 @@ class LpdfEngine {
126
125
  else {
127
126
  // JSON (Kit tree) path — pass JSON directly to render_tree_pdf.
128
127
  const json = JSON.stringify(input);
128
+ const allFonts = new Map(this._fonts);
129
129
  for (const [key, src] of extractFontSrcsFromJson(json)) {
130
130
  if (!allFonts.has(key)) {
131
131
  try {
@@ -156,7 +156,7 @@ class LpdfEngine {
156
156
  return pdf;
157
157
  }
158
158
  }
159
- exports.LpdfEngine = LpdfEngine;
159
+ exports.PdfEngine = PdfEngine;
160
160
  // ── Helpers ───────────────────────────────────────────────────────────────────
161
161
  /** Extract `ref??name → src` pairs from `<font>` or `<image>` tags in XML. */
162
162
  function extractAssetSrcs(xml, tag) {
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, FieldAttr, } from './layout';
6
+ export type { LpdfNode, LpdfContainerNode, LpdfTextNode, LpdfSpanNode, LpdfDividerNode, LpdfImgNode, LpdfBarcodeNode, LpdfTableNode, LpdfTheadNode, LpdfTrNode, LpdfTdNode, LpdfRegionNode, LpdfFieldNode, } 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 './L';
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 L_1 = require("./L");
13
+ Object.defineProperty(exports, "L", { enumerable: true, get: function () { return L_1.L; } });
14
+ Object.defineProperty(exports, "NoAttr", { enumerable: true, get: function () { return L_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
@@ -32,7 +32,7 @@ export interface LpdfTokens {
32
32
  border?: Record<string, string>;
33
33
  radius?: Record<string, string>;
34
34
  width?: Record<string, string>;
35
- text?: Record<string, string>;
35
+ textSize?: Record<string, string>;
36
36
  fonts?: Record<string, LpdfFontDef>;
37
37
  }
38
38
  export type LpdfFontDef = {
@@ -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,35 @@ 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
- if (tokens !== undefined)
62
- attrs['tokens'] = tokens;
61
+ if (tokens !== undefined) {
62
+ const { textSize, ...rest } = tokens;
63
+ attrsObj['tokens'] = textSize !== undefined ? { 'text-size': textSize, ...rest } : rest;
64
+ }
63
65
  if (meta !== undefined)
64
- attrs['meta'] = meta;
66
+ attrsObj['meta'] = meta;
65
67
  return {
66
68
  version: 1,
67
69
  type: 'document',
68
- attrs,
69
- nodes: input.sections ?? [],
70
+ attrs: attrsObj,
71
+ nodes,
70
72
  };
71
73
  }
72
74
  // ── LpdfKit export ────────────────────────────────────────────────────────────