@lpdfio/lpdf 0.21.0 → 0.23.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
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LpdfCanvas = exports.CanvasTransform = void 0;
4
+ const _shared_1 = require("./_shared");
4
5
  // ── CanvasTransform ───────────────────────────────────────────────────────────
6
+ /**
7
+ * Builds the `transform` string of a layer. `String(CanvasTransform.rotate(45))` is
8
+ * `matrix(...)`, which a layer's `transform` attribute accepts like `rotate(45)`.
9
+ */
5
10
  class CanvasTransform {
6
11
  constructor(matrix) {
7
12
  this.matrix = matrix;
@@ -39,153 +44,36 @@ class CanvasTransform {
39
44
  b1 * e2 + d1 * f2 + f1,
40
45
  ]);
41
46
  }
42
- /** Serialise to the `"matrix(a,b,c,d,e,f)"` string form that Rust `jattr()` reads. */
47
+ /** The `"matrix(a,b,c,d,e,f)"` form of the transform. */
43
48
  toString() {
44
49
  return `matrix(${this.matrix.join(',')})`;
45
50
  }
46
51
  }
47
52
  exports.CanvasTransform = CanvasTransform;
48
53
  // ── LpdfCanvas factory ────────────────────────────────────────────────────────
49
- function rect(x, y, w, h, style) {
50
- const attrs = {
51
- x: String(x), y: String(y), w: String(w), h: String(h),
52
- };
53
- if (style?.fill !== undefined)
54
- attrs['fill'] = style.fill;
55
- if (style?.stroke !== undefined)
56
- attrs['stroke'] = style.stroke;
57
- if (style?.strokeWidth !== undefined)
58
- attrs['stroke-width'] = String(style.strokeWidth);
59
- if (style?.strokeDash !== undefined)
60
- attrs['stroke-dash'] = style.strokeDash.join(' ');
61
- if (style?.borderRadius !== undefined)
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;
67
- return { type: 'canvas-rect', attrs };
54
+ function rect(attrs) {
55
+ return { type: 'rect', attrs: (0, _shared_1.buildAttrs)(attrs) };
68
56
  }
69
- function line(x1, y1, x2, y2, style) {
70
- const attrs = {
71
- x1: String(x1), y1: String(y1), x2: String(x2), y2: String(y2),
72
- };
73
- if (style?.stroke !== undefined)
74
- attrs['stroke'] = style.stroke;
75
- if (style?.strokeWidth !== undefined)
76
- attrs['stroke-width'] = String(style.strokeWidth);
77
- if (style?.strokeDash !== undefined)
78
- attrs['stroke-dash'] = style.strokeDash.join(' ');
79
- if (style?.lineCap !== undefined)
80
- attrs['line-cap'] = style.lineCap;
81
- if (style?.lineJoin !== undefined)
82
- attrs['line-join'] = style.lineJoin;
83
- return { type: 'canvas-line', attrs };
57
+ function line(attrs) {
58
+ return { type: 'line', attrs: (0, _shared_1.buildAttrs)(attrs) };
84
59
  }
85
- function ellipse(cx, cy, rx, ry, style) {
86
- const attrs = {
87
- cx: String(cx), cy: String(cy), rx: String(rx), ry: String(ry),
88
- };
89
- if (style?.fill !== undefined)
90
- attrs['fill'] = style.fill;
91
- if (style?.stroke !== undefined)
92
- attrs['stroke'] = style.stroke;
93
- if (style?.strokeWidth !== undefined)
94
- attrs['stroke-width'] = String(style.strokeWidth);
95
- if (style?.strokeDash !== undefined)
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;
101
- return { type: 'canvas-ellipse', attrs };
60
+ function ellipse(attrs) {
61
+ return { type: 'ellipse', attrs: (0, _shared_1.buildAttrs)(attrs) };
102
62
  }
103
- function circle(cx, cy, r, style) {
104
- const attrs = {
105
- cx: String(cx), cy: String(cy), r: String(r),
106
- };
107
- if (style?.fill !== undefined)
108
- attrs['fill'] = style.fill;
109
- if (style?.stroke !== undefined)
110
- attrs['stroke'] = style.stroke;
111
- if (style?.strokeWidth !== undefined)
112
- attrs['stroke-width'] = String(style.strokeWidth);
113
- if (style?.strokeDash !== undefined)
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;
119
- return { type: 'canvas-circle', attrs };
63
+ function circle(attrs) {
64
+ return { type: 'circle', attrs: (0, _shared_1.buildAttrs)(attrs) };
120
65
  }
121
- function path(d, style) {
122
- const attrs = { d };
123
- if (style?.fill !== undefined)
124
- attrs['fill'] = style.fill;
125
- if (style?.stroke !== undefined)
126
- attrs['stroke'] = style.stroke;
127
- if (style?.strokeWidth !== undefined)
128
- attrs['stroke-width'] = String(style.strokeWidth);
129
- if (style?.strokeDash !== undefined)
130
- attrs['stroke-dash'] = style.strokeDash.join(' ');
131
- if (style?.fillRuleEvenodd !== undefined)
132
- attrs['fill-rule'] = style.fillRuleEvenodd ? 'evenodd' : 'nonzero';
133
- if (style?.lineCap !== undefined)
134
- attrs['line-cap'] = style.lineCap;
135
- if (style?.lineJoin !== undefined)
136
- attrs['line-join'] = style.lineJoin;
137
- if (style?.opacity !== undefined)
138
- attrs['opacity'] = String(style.opacity);
139
- return { type: 'canvas-path', attrs };
66
+ function path(attrs) {
67
+ return { type: 'path', attrs: (0, _shared_1.buildAttrs)(attrs) };
140
68
  }
141
- function textAt(x, y, content, style, runs) {
142
- const attrs = { x: String(x), y: String(y) };
143
- if (style?.font !== undefined)
144
- attrs['font'] = style.font;
145
- if (style?.size !== undefined)
146
- attrs['font-size'] = String(style.size);
147
- if (style?.color !== undefined)
148
- attrs['color'] = style.color;
149
- if (style?.align !== undefined)
150
- attrs['align'] = style.align;
151
- if (style?.lineHeight !== undefined)
152
- attrs['line-height'] = String(style.lineHeight);
153
- if (style?.width !== undefined)
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;
159
- const node = { type: 'canvas-text', text: content, attrs };
160
- if (runs && runs.length > 0) {
161
- node.runs = runs.map(r => {
162
- const runAttrs = {};
163
- if (r.font !== undefined)
164
- runAttrs['font'] = r.font;
165
- if (r.size !== undefined)
166
- runAttrs['font-size'] = String(r.size);
167
- if (r.color !== undefined)
168
- runAttrs['color'] = r.color;
169
- return { text: r.text, attrs: runAttrs };
170
- });
171
- }
172
- return node;
69
+ function textAt(attrs, nodes = []) {
70
+ return { type: 'text', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
173
71
  }
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 };
72
+ function imgAt(attrs) {
73
+ return { type: 'img', attrs: (0, _shared_1.buildAttrs)(attrs) };
179
74
  }
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 };
75
+ function layer(attrs, nodes = []) {
76
+ return { type: 'layer', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
189
77
  }
190
78
  exports.LpdfCanvas = Object.freeze({
191
79
  rect,
@@ -0,0 +1,50 @@
1
+ /** The values of the `type` attribute of a field. */
2
+ export declare const FieldType: {
3
+ readonly Text: "text";
4
+ readonly Checkbox: "checkbox";
5
+ readonly Dropdown: "dropdown";
6
+ readonly Radio: "radio";
7
+ readonly Button: "button";
8
+ };
9
+ export type FieldType = (typeof FieldType)[keyof typeof FieldType];
10
+ /** The values of the `pin` attribute of a region. */
11
+ export declare const Pin: {
12
+ readonly Top: "top";
13
+ readonly Bottom: "bottom";
14
+ readonly Left: "left";
15
+ readonly Right: "right";
16
+ };
17
+ export type Pin = (typeof Pin)[keyof typeof Pin];
18
+ /** The values of the `orientation` attribute of a document or a section. */
19
+ export declare const Orientation: {
20
+ readonly Portrait: "portrait";
21
+ readonly Landscape: "landscape";
22
+ };
23
+ export type Orientation = (typeof Orientation)[keyof typeof Orientation];
24
+ /** The values of the `core` attribute of a font: the built-in PDF fonts, which need no file. */
25
+ export declare const BuiltinFont: {
26
+ readonly Courier: "Courier";
27
+ readonly CourierBold: "Courier-Bold";
28
+ readonly CourierOblique: "Courier-Oblique";
29
+ readonly CourierBoldOblique: "Courier-BoldOblique";
30
+ readonly Helvetica: "Helvetica";
31
+ readonly HelveticaBold: "Helvetica-Bold";
32
+ readonly HelveticaOblique: "Helvetica-Oblique";
33
+ readonly HelveticaBoldOblique: "Helvetica-BoldOblique";
34
+ readonly TimesRoman: "Times-Roman";
35
+ readonly TimesBold: "Times-Bold";
36
+ readonly TimesItalic: "Times-Italic";
37
+ readonly TimesBoldItalic: "Times-BoldItalic";
38
+ readonly Symbol: "Symbol";
39
+ readonly ZapfDingbats: "ZapfDingbats";
40
+ };
41
+ export type BuiltinFont = (typeof BuiltinFont)[keyof typeof BuiltinFont];
42
+ /** The named values of the `page` attribute of a layer or a region. A range such as 2-4 or 1,3-5 is a string. */
43
+ export declare const PageScope: {
44
+ readonly Each: "each";
45
+ readonly First: "first";
46
+ readonly Last: "last";
47
+ readonly Odd: "odd";
48
+ readonly Even: "even";
49
+ };
50
+ export type PageScope = (typeof PageScope)[keyof typeof PageScope];
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ // Generated from lpdf.xsd by scripts/gen-sdk-api.mjs.
3
+ // Do not edit: change the schema and run `make gen-sdk-api`.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.PageScope = exports.BuiltinFont = exports.Orientation = exports.Pin = exports.FieldType = void 0;
6
+ /** The values of the `type` attribute of a field. */
7
+ exports.FieldType = {
8
+ Text: 'text',
9
+ Checkbox: 'checkbox',
10
+ Dropdown: 'dropdown',
11
+ Radio: 'radio',
12
+ Button: 'button',
13
+ };
14
+ /** The values of the `pin` attribute of a region. */
15
+ exports.Pin = {
16
+ Top: 'top',
17
+ Bottom: 'bottom',
18
+ Left: 'left',
19
+ Right: 'right',
20
+ };
21
+ /** The values of the `orientation` attribute of a document or a section. */
22
+ exports.Orientation = {
23
+ Portrait: 'portrait',
24
+ Landscape: 'landscape',
25
+ };
26
+ /** The values of the `core` attribute of a font: the built-in PDF fonts, which need no file. */
27
+ exports.BuiltinFont = {
28
+ Courier: 'Courier',
29
+ CourierBold: 'Courier-Bold',
30
+ CourierOblique: 'Courier-Oblique',
31
+ CourierBoldOblique: 'Courier-BoldOblique',
32
+ Helvetica: 'Helvetica',
33
+ HelveticaBold: 'Helvetica-Bold',
34
+ HelveticaOblique: 'Helvetica-Oblique',
35
+ HelveticaBoldOblique: 'Helvetica-BoldOblique',
36
+ TimesRoman: 'Times-Roman',
37
+ TimesBold: 'Times-Bold',
38
+ TimesItalic: 'Times-Italic',
39
+ TimesBoldItalic: 'Times-BoldItalic',
40
+ Symbol: 'Symbol',
41
+ ZapfDingbats: 'ZapfDingbats',
42
+ };
43
+ /** The named values of the `page` attribute of a layer or a region. A range such as 2-4 or 1,3-5 is a string. */
44
+ exports.PageScope = {
45
+ Each: 'each',
46
+ First: 'first',
47
+ Last: 'last',
48
+ Odd: 'odd',
49
+ Even: 'even',
50
+ };
package/dist/engine.js CHANGED
@@ -153,10 +153,11 @@ class PdfEngine {
153
153
  pdf = engine.render_pdf(xml, dataJson);
154
154
  }
155
155
  else {
156
- // JSON (Kit tree) path — pass JSON directly to render_tree_pdf.
156
+ // JSON (Kit tree) path — pass JSON directly to render_tree_pdf. Fonts and images the
157
+ // document declares with a src are read from there, as on the XML path.
157
158
  const json = JSON.stringify(input);
158
159
  const allFonts = new Map(this._fonts);
159
- for (const [key, src] of extractFontSrcsFromJson(json)) {
160
+ for (const [key, src] of assetSrcsOfDocument(input, 'fonts')) {
160
161
  if (!allFonts.has(key)) {
161
162
  try {
162
163
  allFonts.set(key, (0, node_fs_1.readFileSync)(src));
@@ -167,7 +168,16 @@ class PdfEngine {
167
168
  for (const [name, bytes] of allFonts) {
168
169
  engine.load_font(name, bytes);
169
170
  }
170
- for (const [name, bytes] of this._images) {
171
+ const allImages = new Map(this._images);
172
+ for (const [key, src] of assetSrcsOfDocument(input, 'images')) {
173
+ if (!allImages.has(key)) {
174
+ try {
175
+ allImages.set(key, (0, node_fs_1.readFileSync)(src));
176
+ }
177
+ catch { /* skip unresolvable image */ }
178
+ }
179
+ }
180
+ for (const [name, bytes] of allImages) {
171
181
  engine.load_image(name, bytes);
172
182
  }
173
183
  if (this._encrypt) {
@@ -203,19 +213,13 @@ function extractAssetSrcs(xml, tag) {
203
213
  }
204
214
  return result;
205
215
  }
206
- /** Extract `ref??name → src` pairs from `attrs.tokens.fonts[name].src` in a kit JSON string. */
207
- function extractFontSrcsFromJson(json) {
216
+ /** The `ref ?? name → src` pairs of the fonts or images a document declares in `attrs.assets`. */
217
+ function assetSrcsOfDocument(document, kind) {
208
218
  const result = new Map();
209
- try {
210
- const doc = JSON.parse(json);
211
- const fonts = doc?.attrs?.tokens?.fonts ?? {};
212
- for (const [name, def] of Object.entries(fonts)) {
213
- if (def.src) {
214
- const key = def.ref ?? name;
215
- result.set(key, def.src);
216
- }
217
- }
219
+ const declared = document.attrs['assets']?.[kind] ?? [];
220
+ for (const { name, ref, src } of declared) {
221
+ if (src)
222
+ result.set(ref ?? name, src);
218
223
  }
219
- catch { /* ignore */ }
220
224
  return result;
221
225
  }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export { PdfEngine, LpdfRenderError } from './engine';
2
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';
3
+ export type { RenderOptions, EngineOptions } from './_shared';
4
+ export { FieldType, Pin, Orientation, BuiltinFont, PageScope } from './constants';
5
+ export type { PdfDocument, LpdfSectionNode, LpdfLayoutBlock, LpdfCanvasBlock, DocumentTokens, DocumentAssets, DocumentMeta, SectionAttr, DocumentAttr, } from './kit';
6
+ export type { StackAttr, FlankAttr, SplitAttr, ClusterAttr, GridAttr, FrameAttr, LinkAttr, TableAttr, TheadAttr, TrAttr, TdAttr, TextAttr, SpanAttr, DividerAttr, ImgAttr, BarcodeAttr, RegionAttr, FieldAttr, LayerAttr, RectAttr, CircleAttr, EllipseAttr, LineAttr, PathAttr, CanvasTextAttr, CanvasImgAttr, FontAttr, ImageAttr, } from './attrs';
6
7
  export type { LpdfNode, LpdfContainerNode, LpdfTextNode, LpdfSpanNode, LpdfDividerNode, LpdfImgNode, LpdfBarcodeNode, LpdfTableNode, LpdfTheadNode, LpdfTrNode, LpdfTdNode, LpdfRegionNode, LpdfFieldNode, } from './layout';
7
8
  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 type { LpdfCanvasLayerNode, LpdfCanvasPrimitiveNode, LpdfCanvasRectNode, LpdfCanvasLineNode, LpdfCanvasEllipseNode, LpdfCanvasCircleNode, LpdfCanvasPathNode, LpdfCanvasTextNode, LpdfCanvasImgNode, } from './canvas';
9
10
  export { L, NoAttr } from './L';
package/dist/index.js CHANGED
@@ -1,10 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoAttr = exports.L = exports.CanvasTransform = exports.LpdfRenderError = exports.PdfEngine = void 0;
3
+ exports.NoAttr = exports.L = exports.CanvasTransform = exports.PageScope = exports.BuiltinFont = exports.Orientation = exports.Pin = exports.FieldType = exports.LpdfRenderError = exports.PdfEngine = void 0;
4
4
  // ── Engine ────────────────────────────────────────────────────────────────────
5
5
  var engine_1 = require("./engine");
6
6
  Object.defineProperty(exports, "PdfEngine", { enumerable: true, get: function () { return engine_1.PdfEngine; } });
7
7
  Object.defineProperty(exports, "LpdfRenderError", { enumerable: true, get: function () { return engine_1.LpdfRenderError; } });
8
+ // ── Constants for the schema's enumerations ───────────────────────────────────
9
+ var constants_1 = require("./constants");
10
+ Object.defineProperty(exports, "FieldType", { enumerable: true, get: function () { return constants_1.FieldType; } });
11
+ Object.defineProperty(exports, "Pin", { enumerable: true, get: function () { return constants_1.Pin; } });
12
+ Object.defineProperty(exports, "Orientation", { enumerable: true, get: function () { return constants_1.Orientation; } });
13
+ Object.defineProperty(exports, "BuiltinFont", { enumerable: true, get: function () { return constants_1.BuiltinFont; } });
14
+ Object.defineProperty(exports, "PageScope", { enumerable: true, get: function () { return constants_1.PageScope; } });
8
15
  // ── Canvas types ──────────────────────────────────────────────────────────────
9
16
  var canvas_1 = require("./canvas");
10
17
  Object.defineProperty(exports, "CanvasTransform", { enumerable: true, get: function () { return canvas_1.CanvasTransform; } });
package/dist/kit.d.ts CHANGED
@@ -25,7 +25,8 @@
25
25
  */
26
26
  import type { LpdfNode } from './layout';
27
27
  import type { LpdfCanvasLayerNode } from './canvas';
28
- export interface LpdfTokens {
28
+ import type { FontAttr, ImageAttr } from './attrs';
29
+ export interface DocumentTokens {
29
30
  colors?: Record<string, string>;
30
31
  space?: Record<string, string>;
31
32
  grid?: Record<string, string>;
@@ -33,16 +34,16 @@ export interface LpdfTokens {
33
34
  radius?: Record<string, string>;
34
35
  width?: Record<string, string>;
35
36
  textSize?: Record<string, string>;
36
- fonts?: Record<string, LpdfFontDef>;
37
37
  }
38
- export type LpdfFontDef = {
39
- src: string;
40
- builtin?: never;
41
- } | {
42
- builtin: string;
43
- src?: never;
44
- };
45
- export interface LpdfMeta {
38
+ /**
39
+ * The fonts and images the document declares, as the `assets` element of the XML does. A font or image
40
+ * is picked by its `name`: text sets `font` to a font's name, an `img` sets `name` to an image's.
41
+ */
42
+ export interface DocumentAssets {
43
+ fonts?: FontAttr[];
44
+ images?: ImageAttr[];
45
+ }
46
+ export interface DocumentMeta {
46
47
  title?: string;
47
48
  author?: string;
48
49
  subject?: string;
@@ -62,8 +63,10 @@ export interface DocumentAttr {
62
63
  orientation?: string;
63
64
  margin?: string;
64
65
  background?: string;
65
- tokens?: LpdfTokens;
66
- meta?: LpdfMeta;
66
+ font?: string;
67
+ assets?: DocumentAssets;
68
+ tokens?: DocumentTokens;
69
+ meta?: DocumentMeta;
67
70
  debug?: string;
68
71
  }
69
72
  /** A layout block — wraps an ordered list of layout nodes. */
@@ -87,10 +90,10 @@ export interface PdfDocument {
87
90
  attrs: Record<string, unknown>;
88
91
  nodes: LpdfSectionNode[];
89
92
  }
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;
93
+ declare function layout(_attrs: null, nodes?: LpdfNode[]): LpdfLayoutBlock;
94
+ declare function canvas(_attrs: null, layers?: LpdfCanvasLayerNode[]): LpdfCanvasBlock;
95
+ declare function section(attrs: SectionAttr | null, nodes?: (LpdfLayoutBlock | LpdfCanvasBlock)[]): LpdfSectionNode;
96
+ declare function document(attrs: DocumentAttr | null, nodes?: LpdfSectionNode[]): PdfDocument;
94
97
  export declare const LpdfKit: Readonly<{
95
98
  layout: typeof layout;
96
99
  canvas: typeof canvas;
package/dist/kit.js CHANGED
@@ -26,38 +26,28 @@
26
26
  */
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
28
  exports.LpdfKit = void 0;
29
- // ── camelCase → kebab-case helper ─────────────────────────────────────────────
30
- function attrKey(camel) {
31
- return camel.replace(/[A-Z]/g, c => '-' + c.toLowerCase());
32
- }
33
- function buildAttrs(options) {
34
- const result = {};
35
- for (const [key, val] of Object.entries(options)) {
36
- if (val !== undefined) {
37
- result[attrKey(key)] = val;
38
- }
39
- }
40
- return result;
41
- }
29
+ const _shared_1 = require("./_shared");
42
30
  // ── Factory functions ─────────────────────────────────────────────────────────
43
- function layout(_attrs, nodes) {
31
+ function layout(_attrs, nodes = []) {
44
32
  return { type: 'layout', nodes };
45
33
  }
46
- function canvas(_attrs, layers) {
34
+ function canvas(_attrs, layers = []) {
47
35
  return { type: 'canvas', nodes: layers };
48
36
  }
49
- function section(attrs, nodes) {
37
+ function section(attrs, nodes = []) {
50
38
  return {
51
39
  type: 'section',
52
- attrs: buildAttrs((attrs ?? {})),
40
+ attrs: (0, _shared_1.buildAttrs)(attrs),
53
41
  nodes,
54
42
  };
55
43
  }
56
- function document(attrs, nodes) {
57
- const { tokens, meta, ...restOpts } = attrs ?? {};
44
+ function document(attrs, nodes = []) {
45
+ const { assets, tokens, meta, ...restOpts } = attrs ?? {};
58
46
  const attrsObj = {
59
- ...buildAttrs(restOpts),
47
+ ...(0, _shared_1.buildAttrs)(restOpts),
60
48
  };
49
+ if (assets !== undefined)
50
+ attrsObj['assets'] = assets;
61
51
  if (tokens !== undefined) {
62
52
  const { textSize, ...rest } = tokens;
63
53
  attrsObj['tokens'] = textSize !== undefined ? { 'text-size': textSize, ...rest } : rest;