@lpdfio/lpdf 0.22.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/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;
package/dist/layout.d.ts CHANGED
@@ -1,189 +1,4 @@
1
- import type { PageScope } from './_shared';
2
- export interface StackAttr {
3
- gap?: string;
4
- padding?: string;
5
- background?: string;
6
- align?: string;
7
- justify?: string;
8
- width?: string;
9
- height?: string;
10
- border?: string;
11
- radius?: string;
12
- debug?: string;
13
- }
14
- export interface FlankAttr {
15
- gap?: string;
16
- padding?: string;
17
- background?: string;
18
- align?: string;
19
- justify?: string;
20
- end?: string;
21
- width?: string;
22
- height?: string;
23
- border?: string;
24
- radius?: string;
25
- debug?: string;
26
- }
27
- export interface SplitAttr {
28
- gap?: string;
29
- padding?: string;
30
- background?: string;
31
- align?: string;
32
- equal?: string;
33
- width?: string;
34
- height?: string;
35
- border?: string;
36
- radius?: string;
37
- debug?: string;
38
- }
39
- export interface ClusterAttr {
40
- gap?: string;
41
- padding?: string;
42
- background?: string;
43
- align?: string;
44
- justify?: string;
45
- width?: string;
46
- height?: string;
47
- border?: string;
48
- radius?: string;
49
- debug?: string;
50
- }
51
- export interface GridAttr {
52
- cols?: string;
53
- colWidth?: string;
54
- gap?: string;
55
- equal?: string;
56
- padding?: string;
57
- background?: string;
58
- width?: string;
59
- height?: string;
60
- border?: string;
61
- radius?: string;
62
- debug?: string;
63
- }
64
- export interface FrameAttr {
65
- width?: string;
66
- height?: string;
67
- padding?: string;
68
- background?: string;
69
- border?: string;
70
- radius?: string;
71
- align?: string;
72
- debug?: string;
73
- }
74
- export interface LinkAttr {
75
- url?: string;
76
- gap?: string;
77
- width?: string;
78
- height?: string;
79
- debug?: string;
80
- }
81
- export interface TableAttr {
82
- cols: string;
83
- border?: string;
84
- stripe?: string;
85
- gap?: string;
86
- padding?: string;
87
- background?: string;
88
- width?: string;
89
- height?: string;
90
- repeat?: string;
91
- debug?: string;
92
- }
93
- export interface TheadAttr {
94
- background?: string;
95
- }
96
- export interface TrAttr {
97
- background?: string;
98
- }
99
- export interface TdAttr {
100
- padding?: string;
101
- background?: string;
102
- align?: string;
103
- valign?: string;
104
- border?: string;
105
- radius?: string;
106
- gap?: string;
107
- debug?: string;
108
- }
109
- export interface TextAttr {
110
- font?: string;
111
- fontSize?: string;
112
- textAlign?: string;
113
- color?: string;
114
- bold?: string;
115
- end?: string;
116
- padding?: string;
117
- background?: string;
118
- width?: string;
119
- height?: string;
120
- border?: string;
121
- radius?: string;
122
- repeat?: string;
123
- debug?: string;
124
- }
125
- export interface SpanAttr {
126
- font?: string;
127
- fontSize?: string;
128
- color?: string;
129
- bold?: string;
130
- url?: string;
131
- underline?: string;
132
- strike?: string;
133
- }
134
- export interface DividerAttr {
135
- color?: string;
136
- thickness?: string;
137
- direction?: string;
138
- debug?: string;
139
- }
140
- export interface ImgAttr {
141
- name: string;
142
- height?: string;
143
- width?: string;
144
- font?: string;
145
- fontSize?: string;
146
- gap?: string;
147
- padding?: string;
148
- background?: string;
149
- border?: string;
150
- radius?: string;
151
- repeat?: string;
152
- debug?: string;
153
- }
154
- export interface BarcodeAttr {
155
- type: string;
156
- data: string;
157
- size?: string;
158
- width?: string;
159
- height?: string;
160
- ec?: string;
161
- hrt?: string;
162
- color?: string;
163
- background?: string;
164
- repeat?: string;
165
- debug?: string;
166
- }
167
- export interface FieldAttr {
168
- label?: string;
169
- value?: string;
170
- options?: string;
171
- group?: string;
172
- checked?: string;
173
- required?: string;
174
- readonly?: string;
175
- maxLen?: string;
176
- actionUrl?: string;
177
- width?: string;
178
- height?: string;
179
- debug?: string;
180
- }
181
- export interface RegionAttr {
182
- pin: string;
183
- page?: PageScope | string;
184
- w?: string;
185
- debug?: string;
186
- }
1
+ import type { StackAttr, FlankAttr, SplitAttr, ClusterAttr, GridAttr, FrameAttr, LinkAttr, TableAttr, TheadAttr, TrAttr, TdAttr, TextAttr, SpanAttr, DividerAttr, ImgAttr, BarcodeAttr, FieldAttr, RegionAttr } from './attrs';
187
2
  export interface LpdfSpanNode {
188
3
  type: 'span';
189
4
  attrs: Record<string, string>;
@@ -232,7 +47,7 @@ export interface LpdfTableNode {
232
47
  nodes: (LpdfTheadNode | LpdfTrNode)[];
233
48
  }
234
49
  export interface LpdfRegionNode {
235
- type: 'layout-region';
50
+ type: 'region';
236
51
  attrs: Record<string, string>;
237
52
  nodes: LpdfNode[];
238
53
  }
@@ -241,24 +56,24 @@ export interface LpdfFieldNode {
241
56
  attrs: Record<string, string>;
242
57
  }
243
58
  export type LpdfNode = LpdfContainerNode | LpdfTextNode | LpdfDividerNode | LpdfTableNode | LpdfImgNode | LpdfBarcodeNode | LpdfRegionNode | LpdfFieldNode;
244
- declare function stack(attrs: StackAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
245
- declare function flank(attrs: FlankAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
246
- declare function split(attrs: SplitAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
247
- declare function cluster(attrs: ClusterAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
248
- declare function grid(attrs: GridAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
249
- declare function frame(attrs: FrameAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
250
- declare function link(attrs: LinkAttr | null, nodes: LpdfNode[]): LpdfContainerNode;
251
- declare function table(attrs: TableAttr, nodes: (LpdfTheadNode | LpdfTrNode)[]): LpdfTableNode;
252
- declare function thead(attrs: TheadAttr | null, nodes: LpdfTdNode[]): LpdfTheadNode;
253
- declare function tr(attrs: TrAttr | null, nodes: LpdfTdNode[]): LpdfTrNode;
254
- declare function td(attrs: TdAttr | null, nodes: LpdfNode[]): LpdfTdNode;
255
- declare function text(attrs: TextAttr | null, nodes: (string | LpdfSpanNode)[]): LpdfTextNode;
256
- declare function span(attrs: SpanAttr | null, nodes: string[]): LpdfSpanNode;
257
- declare function divider(attrs: DividerAttr | null): LpdfDividerNode;
59
+ declare function stack(attrs: StackAttr | null, nodes?: LpdfNode[]): LpdfContainerNode;
60
+ declare function flank(attrs: FlankAttr | null, nodes?: LpdfNode[]): LpdfContainerNode;
61
+ declare function split(attrs: SplitAttr | null, nodes?: LpdfNode[]): LpdfContainerNode;
62
+ declare function cluster(attrs: ClusterAttr | null, nodes?: LpdfNode[]): LpdfContainerNode;
63
+ declare function grid(attrs: GridAttr | null, nodes?: LpdfNode[]): LpdfContainerNode;
64
+ declare function frame(attrs: FrameAttr | null, nodes?: LpdfNode[]): LpdfContainerNode;
65
+ declare function link(attrs: LinkAttr, nodes?: LpdfNode[]): LpdfContainerNode;
66
+ declare function table(attrs: TableAttr, nodes?: (LpdfTheadNode | LpdfTrNode)[]): LpdfTableNode;
67
+ declare function thead(attrs: TheadAttr | null, nodes?: LpdfTdNode[]): LpdfTheadNode;
68
+ declare function tr(attrs: TrAttr | null, nodes?: LpdfTdNode[]): LpdfTrNode;
69
+ declare function td(attrs: TdAttr | null, nodes?: LpdfNode[]): LpdfTdNode;
70
+ declare function text(attrs: TextAttr | null, nodes?: (string | LpdfSpanNode)[]): LpdfTextNode;
71
+ declare function span(attrs: SpanAttr | null, nodes?: string[]): LpdfSpanNode;
72
+ declare function divider(attrs?: DividerAttr | null): LpdfDividerNode;
258
73
  declare function img(attrs: ImgAttr): LpdfImgNode;
259
74
  declare function barcode(attrs: BarcodeAttr): LpdfBarcodeNode;
260
- declare function region(attrs: RegionAttr, nodes: LpdfNode[]): LpdfRegionNode;
261
- declare function field(type: string, name: string, attrs?: FieldAttr | null): LpdfFieldNode;
75
+ declare function region(attrs: RegionAttr, nodes?: LpdfNode[]): LpdfRegionNode;
76
+ declare function field(attrs: FieldAttr): LpdfFieldNode;
262
77
  export declare const LpdfLayout: Readonly<{
263
78
  stack: typeof stack;
264
79
  flank: typeof flank;
package/dist/layout.js CHANGED
@@ -1,120 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LpdfLayout = void 0;
4
- // ── camelCase → kebab-case helper ─────────────────────────────────────────────
5
- function attrKey(camel) {
6
- return camel.replace(/[A-Z]/g, c => '-' + c.toLowerCase());
7
- }
8
- function buildAttrs(options) {
9
- const result = {};
10
- for (const [key, val] of Object.entries(options)) {
11
- if (val !== undefined) {
12
- result[attrKey(key)] = val;
13
- }
14
- }
15
- return result;
16
- }
4
+ const _shared_1 = require("./_shared");
17
5
  // ── Helper ────────────────────────────────────────────────────────────────────
18
6
  function makeContainer(type, attrs, nodes) {
19
- return { type, attrs: buildAttrs(attrs ?? {}), nodes };
7
+ return { type, attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
20
8
  }
21
9
  // ── LpdfLayout factory ────────────────────────────────────────────────────────
22
- function stack(attrs, nodes) {
10
+ function stack(attrs, nodes = []) {
23
11
  return makeContainer('stack', attrs, nodes);
24
12
  }
25
- function flank(attrs, nodes) {
13
+ function flank(attrs, nodes = []) {
26
14
  return makeContainer('flank', attrs, nodes);
27
15
  }
28
- function split(attrs, nodes) {
16
+ function split(attrs, nodes = []) {
29
17
  return makeContainer('split', attrs, nodes);
30
18
  }
31
- function cluster(attrs, nodes) {
19
+ function cluster(attrs, nodes = []) {
32
20
  return makeContainer('cluster', attrs, nodes);
33
21
  }
34
- function grid(attrs, nodes) {
22
+ function grid(attrs, nodes = []) {
35
23
  return makeContainer('grid', attrs, nodes);
36
24
  }
37
- function frame(attrs, nodes) {
25
+ function frame(attrs, nodes = []) {
38
26
  return makeContainer('frame', attrs, nodes);
39
27
  }
40
- function link(attrs, nodes) {
28
+ function link(attrs, nodes = []) {
41
29
  return makeContainer('link', attrs, nodes);
42
30
  }
43
- function table(attrs, nodes) {
44
- return {
45
- type: 'table',
46
- attrs: buildAttrs(attrs),
47
- nodes,
48
- };
49
- }
50
- function thead(attrs, nodes) {
51
- return {
52
- type: 'thead',
53
- attrs: buildAttrs((attrs ?? {})),
54
- nodes,
55
- };
56
- }
57
- function tr(attrs, nodes) {
58
- return {
59
- type: 'tr',
60
- attrs: buildAttrs((attrs ?? {})),
61
- nodes,
62
- };
63
- }
64
- function td(attrs, nodes) {
65
- return {
66
- type: 'td',
67
- attrs: buildAttrs((attrs ?? {})),
68
- nodes,
69
- };
70
- }
71
- function text(attrs, nodes) {
72
- return {
73
- type: 'text',
74
- attrs: buildAttrs((attrs ?? {})),
75
- nodes,
76
- };
77
- }
78
- function span(attrs, nodes) {
79
- return {
80
- type: 'span',
81
- attrs: buildAttrs((attrs ?? {})),
82
- nodes,
83
- };
84
- }
85
- function divider(attrs) {
86
- return {
87
- type: 'divider',
88
- attrs: buildAttrs((attrs ?? {})),
89
- };
31
+ function table(attrs, nodes = []) {
32
+ return { type: 'table', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
33
+ }
34
+ function thead(attrs, nodes = []) {
35
+ return { type: 'thead', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
36
+ }
37
+ function tr(attrs, nodes = []) {
38
+ return { type: 'tr', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
39
+ }
40
+ function td(attrs, nodes = []) {
41
+ return { type: 'td', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
42
+ }
43
+ function text(attrs, nodes = []) {
44
+ return { type: 'text', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
45
+ }
46
+ function span(attrs, nodes = []) {
47
+ return { type: 'span', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
48
+ }
49
+ function divider(attrs = null) {
50
+ return { type: 'divider', attrs: (0, _shared_1.buildAttrs)(attrs) };
90
51
  }
91
52
  function img(attrs) {
92
- return {
93
- type: 'img',
94
- attrs: buildAttrs(attrs),
95
- };
53
+ return { type: 'img', attrs: (0, _shared_1.buildAttrs)(attrs) };
96
54
  }
97
55
  function barcode(attrs) {
98
- return {
99
- type: 'barcode',
100
- attrs: buildAttrs(attrs),
101
- };
102
- }
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
- }
113
- function field(type, name, attrs) {
114
- const a = { type, name };
115
- if (attrs)
116
- Object.assign(a, buildAttrs(attrs));
117
- return { type: 'field', attrs: a };
56
+ return { type: 'barcode', attrs: (0, _shared_1.buildAttrs)(attrs) };
57
+ }
58
+ function region(attrs, nodes = []) {
59
+ return { type: 'region', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
60
+ }
61
+ function field(attrs) {
62
+ return { type: 'field', attrs: (0, _shared_1.buildAttrs)(attrs) };
118
63
  }
119
64
  exports.LpdfLayout = Object.freeze({
120
65
  stack,
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpdfio/lpdf",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Node.js SDK for Lpdf — PDF as Code on every platform. You describe a document as code or XML. Lpdf renders a compact, pixel-perfect PDF — identical across platforms.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",