@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/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,14 @@ 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
+ gap?: string;
76
77
  width?: string;
77
78
  height?: string;
78
79
  debug?: string;
79
80
  }
80
- export interface TableOptions {
81
+ export interface TableAttr {
81
82
  cols: string;
82
83
  border?: string;
83
84
  stripe?: string;
@@ -89,13 +90,13 @@ export interface TableOptions {
89
90
  repeat?: string;
90
91
  debug?: string;
91
92
  }
92
- export interface TheadOptions {
93
+ export interface TheadAttr {
93
94
  background?: string;
94
95
  }
95
- export interface TrOptions {
96
+ export interface TrAttr {
96
97
  background?: string;
97
98
  }
98
- export interface TdOptions {
99
+ export interface TdAttr {
99
100
  padding?: string;
100
101
  background?: string;
101
102
  align?: string;
@@ -105,7 +106,7 @@ export interface TdOptions {
105
106
  gap?: string;
106
107
  debug?: string;
107
108
  }
108
- export interface TextOptions {
109
+ export interface TextAttr {
109
110
  font?: string;
110
111
  fontSize?: string;
111
112
  textAlign?: string;
@@ -121,7 +122,7 @@ export interface TextOptions {
121
122
  repeat?: string;
122
123
  debug?: string;
123
124
  }
124
- export interface SpanOptions {
125
+ export interface SpanAttr {
125
126
  font?: string;
126
127
  fontSize?: string;
127
128
  color?: string;
@@ -130,13 +131,13 @@ export interface SpanOptions {
130
131
  underline?: string;
131
132
  strike?: string;
132
133
  }
133
- export interface DividerOptions {
134
+ export interface DividerAttr {
134
135
  color?: string;
135
136
  thickness?: string;
136
137
  direction?: string;
137
138
  debug?: string;
138
139
  }
139
- export interface ImgOptions {
140
+ export interface ImgAttr {
140
141
  name: string;
141
142
  height?: string;
142
143
  width?: string;
@@ -150,7 +151,7 @@ export interface ImgOptions {
150
151
  repeat?: string;
151
152
  debug?: string;
152
153
  }
153
- export interface BarcodeOptions {
154
+ export interface BarcodeAttr {
154
155
  type: string;
155
156
  data: string;
156
157
  size?: string;
@@ -163,7 +164,22 @@ export interface BarcodeOptions {
163
164
  repeat?: string;
164
165
  debug?: string;
165
166
  }
166
- export interface RegionOptions {
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;
167
183
  page?: PageScope | string;
168
184
  w?: string;
169
185
  debug?: string;
@@ -220,24 +236,29 @@ export interface LpdfRegionNode {
220
236
  attrs: Record<string, string>;
221
237
  nodes: LpdfNode[];
222
238
  }
223
- 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;
239
+ export interface LpdfFieldNode {
240
+ type: 'field';
241
+ attrs: Record<string, string>;
242
+ }
243
+ 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;
258
+ declare function img(attrs: ImgAttr): LpdfImgNode;
259
+ 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;
241
262
  export declare const LpdfLayout: Readonly<{
242
263
  stack: typeof stack;
243
264
  flank: typeof flank;
@@ -256,5 +277,6 @@ export declare const LpdfLayout: Readonly<{
256
277
  tr: typeof tr;
257
278
  td: typeof td;
258
279
  region: typeof region;
280
+ field: typeof field;
259
281
  }>;
260
282
  export {};
package/dist/layout.js CHANGED
@@ -15,100 +15,106 @@ 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
+ }
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 };
112
118
  }
113
119
  exports.LpdfLayout = Object.freeze({
114
120
  stack,
@@ -128,4 +134,5 @@ exports.LpdfLayout = Object.freeze({
128
134
  tr,
129
135
  td,
130
136
  region,
137
+ field,
131
138
  });
@@ -205,6 +205,79 @@ export class LpdfEngine {
205
205
  }
206
206
  if (Symbol.dispose) LpdfEngine.prototype[Symbol.dispose] = LpdfEngine.prototype.free;
207
207
 
208
+ /**
209
+ * Generate SDK source code from one or more bare Lpdf XML elements (a fragment).
210
+ *
211
+ * Unlike `codegen_wasm`, this accepts a snippet without the `<lpdf>` wrapper and
212
+ * returns just the node expression(s) — no imports, no engine setup, no boilerplate.
213
+ * Ideal for documentation code examples where the same XML snippet should be shown
214
+ * in multiple target languages.
215
+ *
216
+ * `options_json` accepts the same shape as `codegen_wasm`:
217
+ * - `target`: `"js"`, `"dotnet"`, `"php"`, or `"python"` (required)
218
+ * - `indent`: `2` or `4` (optional, default `4`)
219
+ * @param {string} xml
220
+ * @param {string} options_json
221
+ * @returns {string}
222
+ */
223
+ export function codegen_fragment_wasm(xml, options_json) {
224
+ let deferred4_0;
225
+ let deferred4_1;
226
+ try {
227
+ const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
228
+ const len0 = WASM_VECTOR_LEN;
229
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
230
+ const len1 = WASM_VECTOR_LEN;
231
+ const ret = wasm.codegen_fragment_wasm(ptr0, len0, ptr1, len1);
232
+ var ptr3 = ret[0];
233
+ var len3 = ret[1];
234
+ if (ret[3]) {
235
+ ptr3 = 0; len3 = 0;
236
+ throw takeFromExternrefTable0(ret[2]);
237
+ }
238
+ deferred4_0 = ptr3;
239
+ deferred4_1 = len3;
240
+ return getStringFromWasm0(ptr3, len3);
241
+ } finally {
242
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Generate SDK source code from an Lpdf XML string.
248
+ *
249
+ * `options_json` is a JSON object with:
250
+ * - `target`: `"js"` (required)
251
+ * - `indent`: `2` or `4` (optional, default `4`)
252
+ *
253
+ * Returns the generated source code as a string.
254
+ * @param {string} xml
255
+ * @param {string} options_json
256
+ * @returns {string}
257
+ */
258
+ export function codegen_wasm(xml, options_json) {
259
+ let deferred4_0;
260
+ let deferred4_1;
261
+ try {
262
+ const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
263
+ const len0 = WASM_VECTOR_LEN;
264
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
265
+ const len1 = WASM_VECTOR_LEN;
266
+ const ret = wasm.codegen_wasm(ptr0, len0, ptr1, len1);
267
+ var ptr3 = ret[0];
268
+ var len3 = ret[1];
269
+ if (ret[3]) {
270
+ ptr3 = 0; len3 = 0;
271
+ throw takeFromExternrefTable0(ret[2]);
272
+ }
273
+ deferred4_0 = ptr3;
274
+ deferred4_1 = len3;
275
+ return getStringFromWasm0(ptr3, len3);
276
+ } finally {
277
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
278
+ }
279
+ }
280
+
208
281
  /**
209
282
  * Convert a JSON kit-tree (produced by `LpdfKit` in any adapter) to an lpdf
210
283
  * XML string.
package/dist/wasm/lpdf.js CHANGED
@@ -206,6 +206,81 @@ class LpdfEngine {
206
206
  if (Symbol.dispose) LpdfEngine.prototype[Symbol.dispose] = LpdfEngine.prototype.free;
207
207
  exports.LpdfEngine = LpdfEngine;
208
208
 
209
+ /**
210
+ * Generate SDK source code from one or more bare Lpdf XML elements (a fragment).
211
+ *
212
+ * Unlike `codegen_wasm`, this accepts a snippet without the `<lpdf>` wrapper and
213
+ * returns just the node expression(s) — no imports, no engine setup, no boilerplate.
214
+ * Ideal for documentation code examples where the same XML snippet should be shown
215
+ * in multiple target languages.
216
+ *
217
+ * `options_json` accepts the same shape as `codegen_wasm`:
218
+ * - `target`: `"js"`, `"dotnet"`, `"php"`, or `"python"` (required)
219
+ * - `indent`: `2` or `4` (optional, default `4`)
220
+ * @param {string} xml
221
+ * @param {string} options_json
222
+ * @returns {string}
223
+ */
224
+ function codegen_fragment_wasm(xml, options_json) {
225
+ let deferred4_0;
226
+ let deferred4_1;
227
+ try {
228
+ const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
229
+ const len0 = WASM_VECTOR_LEN;
230
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
231
+ const len1 = WASM_VECTOR_LEN;
232
+ const ret = wasm.codegen_fragment_wasm(ptr0, len0, ptr1, len1);
233
+ var ptr3 = ret[0];
234
+ var len3 = ret[1];
235
+ if (ret[3]) {
236
+ ptr3 = 0; len3 = 0;
237
+ throw takeFromExternrefTable0(ret[2]);
238
+ }
239
+ deferred4_0 = ptr3;
240
+ deferred4_1 = len3;
241
+ return getStringFromWasm0(ptr3, len3);
242
+ } finally {
243
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
244
+ }
245
+ }
246
+ exports.codegen_fragment_wasm = codegen_fragment_wasm;
247
+
248
+ /**
249
+ * Generate SDK source code from an Lpdf XML string.
250
+ *
251
+ * `options_json` is a JSON object with:
252
+ * - `target`: `"js"` (required)
253
+ * - `indent`: `2` or `4` (optional, default `4`)
254
+ *
255
+ * Returns the generated source code as a string.
256
+ * @param {string} xml
257
+ * @param {string} options_json
258
+ * @returns {string}
259
+ */
260
+ function codegen_wasm(xml, options_json) {
261
+ let deferred4_0;
262
+ let deferred4_1;
263
+ try {
264
+ const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
265
+ const len0 = WASM_VECTOR_LEN;
266
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
267
+ const len1 = WASM_VECTOR_LEN;
268
+ const ret = wasm.codegen_wasm(ptr0, len0, ptr1, len1);
269
+ var ptr3 = ret[0];
270
+ var len3 = ret[1];
271
+ if (ret[3]) {
272
+ ptr3 = 0; len3 = 0;
273
+ throw takeFromExternrefTable0(ret[2]);
274
+ }
275
+ deferred4_0 = ptr3;
276
+ deferred4_1 = len3;
277
+ return getStringFromWasm0(ptr3, len3);
278
+ } finally {
279
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
280
+ }
281
+ }
282
+ exports.codegen_wasm = codegen_wasm;
283
+
209
284
  /**
210
285
  * Convert a JSON kit-tree (produced by `LpdfKit` in any adapter) to an lpdf
211
286
  * XML string.
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lpdfio/lpdf",
3
- "version": "0.6.0",
4
- "description": "Node.js adapter for Lpdf — PDF as Code, on every platform. Describe your document structure in code using the programming Kit, or XML. Every PDF is compact, pixel-perfect, and identical across platforms.",
3
+ "version": "0.8.0",
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",
7
7
  "exports": {