@lpdfio/lpdf 0.26.0 → 0.27.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/README.md CHANGED
@@ -19,9 +19,9 @@ const { L, NoAttr } = require('@lpdfio/lpdf')
19
19
 
20
20
  const engine = L.engine()
21
21
 
22
- const doc = L.document({ size: 'letter', margin: '48pt' }, [
22
+ const doc = L.document({ size: 'letter' }, [
23
23
  L.section(NoAttr, [
24
- L.layout(NoAttr, [
24
+ L.layout({ margin: '48pt' }, [
25
25
  L.column({ gap: '24pt' }, [
26
26
  L.row({ justify: 'between' }, [
27
27
  L.text({ fontSize: '8pt', color: '#888888' }, ['ACME CORP']),
package/dist/L.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare const NoAttr: null;
5
5
  /**
6
6
  * Unified lpdf facade.
7
7
  *
8
- * All document, layout, and canvas factory methods are available as flat
8
+ * All document, layout, and layer factory methods are available as flat
9
9
  * properties on this object. Construction-time configuration is handled via
10
10
  * `L.engine()`.
11
11
  *
@@ -30,9 +30,8 @@ export declare const L: Readonly<{
30
30
  /** Convert a `PdfDocument` tree to an lpdf XML string. */
31
31
  toXml: (doc: PdfDocument) => string;
32
32
  document: (attrs: import("./kit").DocumentAttr | null, nodes?: import("./kit").LpdfSectionNode[]) => PdfDocument;
33
- section: (attrs: import("./kit").SectionAttr | null, nodes?: (import("./layout").LpdfBookmarkNode | 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;
33
+ section: (attrs: import("./kit").SectionAttr | null, nodes?: import("./kit").LpdfSectionChild[]) => import("./kit").LpdfSectionNode;
34
+ layout: (attrs: import("./attrs").LayoutAttr | null, nodes?: import("./layout").LpdfNode[]) => import("./kit").LpdfLayoutBlock;
36
35
  assets: (attrs: DocumentAssets) => DocumentAssets;
37
36
  tokens: (attrs: DocumentTokens) => DocumentTokens;
38
37
  column: (attrs: import("./attrs").ColumnAttr | null, nodes?: import("./layout").LpdfNode[]) => import("./layout").LpdfContainerNode;
@@ -58,6 +57,7 @@ export declare const L: Readonly<{
58
57
  ellipse: (attrs: import("./attrs").EllipseAttr) => import("./canvas").LpdfCanvasEllipseNode;
59
58
  circle: (attrs: import("./attrs").CircleAttr) => import("./canvas").LpdfCanvasCircleNode;
60
59
  path: (attrs: import("./attrs").PathAttr) => import("./canvas").LpdfCanvasPathNode;
61
- textAt: (attrs: import("./attrs").CanvasTextAttr, nodes?: (string | import("./layout").LpdfSpanNode)[]) => import("./canvas").LpdfCanvasTextNode;
62
- imgAt: (attrs: import("./attrs").CanvasImgAttr) => import("./canvas").LpdfCanvasImgNode;
60
+ textAt: (attrs: import("./attrs").TextAtAttr, nodes?: (string | import("./layout").LpdfSpanNode)[]) => import("./canvas").LpdfCanvasTextAtNode;
61
+ imgAt: (attrs: import("./attrs").ImgAtAttr) => import("./canvas").LpdfCanvasImgAtNode;
62
+ barcodeAt: (attrs: import("./attrs").BarcodeAtAttr) => import("./canvas").LpdfCanvasBarcodeAtNode;
63
63
  }>;
package/dist/L.js CHANGED
@@ -11,7 +11,7 @@ exports.NoAttr = null;
11
11
  /**
12
12
  * Unified lpdf facade.
13
13
  *
14
- * All document, layout, and canvas factory methods are available as flat
14
+ * All document, layout, and layer factory methods are available as flat
15
15
  * properties on this object. Construction-time configuration is handled via
16
16
  * `L.engine()`.
17
17
  *
@@ -39,7 +39,6 @@ exports.L = Object.freeze({
39
39
  document: kit_1.LpdfKit.document,
40
40
  section: kit_1.LpdfKit.section,
41
41
  layout: kit_1.LpdfKit.layout,
42
- canvas: kit_1.LpdfKit.canvas,
43
42
  assets: (attrs) => attrs,
44
43
  tokens: (attrs) => attrs,
45
44
  // ── Layout ────────────────────────────────────────────────────────────────
@@ -60,7 +59,7 @@ exports.L = Object.freeze({
60
59
  region: layout_1.LpdfLayout.region,
61
60
  field: layout_1.LpdfLayout.field,
62
61
  bookmark: layout_1.LpdfLayout.bookmark,
63
- // ── Canvas ────────────────────────────────────────────────────────────────
62
+ // ── Layers ────────────────────────────────────────────────────────────────
64
63
  layer: canvas_1.LpdfCanvas.layer,
65
64
  rect: canvas_1.LpdfCanvas.rect,
66
65
  line: canvas_1.LpdfCanvas.line,
@@ -69,4 +68,5 @@ exports.L = Object.freeze({
69
68
  path: canvas_1.LpdfCanvas.path,
70
69
  textAt: canvas_1.LpdfCanvas.textAt,
71
70
  imgAt: canvas_1.LpdfCanvas.imgAt,
71
+ barcodeAt: canvas_1.LpdfCanvas.barcodeAt,
72
72
  });
package/dist/attrs.d.ts CHANGED
@@ -215,7 +215,11 @@ export interface SpanAttr {
215
215
  strike?: string;
216
216
  }
217
217
  /**
218
- * Attributes of the `img` element.
218
+ * An image. It is never stretched. With only a width or a height, the other follows the image's
219
+ * proportions. With both, they are a maximum: the image takes the largest size that fits in them,
220
+ * and its box becomes that size, which the parent's align places. To put images of different shapes
221
+ * in slots of one size, wrap each in a frame of that size. With neither, the image has its natural
222
+ * size.
219
223
  */
220
224
  export interface ImgAttr {
221
225
  name: string;
@@ -237,23 +241,34 @@ export interface ImgAttr {
237
241
  debug?: string;
238
242
  }
239
243
  /**
240
- * Attributes of the `barcode` element.
244
+ * A QR code, a Code 128 or an EAN-13. It is never stretched. With only a width or a height, the
245
+ * other follows the barcode's proportions. With both, they are a maximum: the barcode takes the
246
+ * largest size that fits in them, and its box becomes that size, which the parent's align places.
247
+ * To put barcodes in slots of one size, wrap each in a frame of that size.
241
248
  */
242
249
  export interface BarcodeAttr {
243
250
  type: string;
244
251
  data: string;
245
- size?: string;
246
252
  /**
247
- * Width of the element. A length fixes it. fill, in a row, takes the width its line leaves after
248
- * the other children, shared equally if several on the line use fill, and never moves to the next
249
- * line; in a column it takes the full width.
253
+ * Height of the whole barcode, with the digits of hrt inside it: they take the bottom 12pt and
254
+ * the bars the rest. A barcode is never stretched. With only a height, the width follows the
255
+ * barcode's proportions. With both width and height, they are a maximum: the barcode takes the
256
+ * largest size that fits in them, and its box becomes that size. A QR code is square, so it takes
257
+ * the smaller of the two. Without a size, a code128 is as wide as its bars at 1pt per module and
258
+ * its bars are 40pt high, and an ean13 is the standard symbol, 0.33mm per module and bars 22.85mm
259
+ * high. The digits of hrt add 12pt to either.
250
260
  */
251
- width?: string;
252
261
  height?: string;
253
262
  ec?: string;
254
263
  hrt?: string;
255
264
  color?: string;
256
265
  background?: string;
266
+ /**
267
+ * Width of the element. A length fixes it. fill, in a row, takes the width its line leaves after
268
+ * the other children, shared equally if several on the line use fill, and never moves to the next
269
+ * line; in a column it takes the full width.
270
+ */
271
+ width?: string;
257
272
  paginate?: string;
258
273
  debug?: string;
259
274
  }
@@ -432,21 +447,32 @@ export interface RegionAttr {
432
447
  debug?: string;
433
448
  }
434
449
  /**
435
- * Groups canvas shapes and sets what applies to all of them: which pages they appear on, opacity,
436
- * transform and clip. Layers cannot be nested.
450
+ * Draws shapes, text, images and barcodes at exact positions on the page, independent of the
451
+ * flowing layout: watermarks, stamps, page furniture. Coordinates start at the top left corner of
452
+ * the whole page, not inside the layout's margin, and y grows downward. A layer before the
453
+ * section's layout paints under it, and one after paints over it. It sets what applies to all of
454
+ * its content: which pages it appears on, opacity, transform and clip. Layers cannot be nested.
437
455
  */
438
456
  export interface LayerAttr {
439
457
  page?: string;
458
+ /**
459
+ * How opaque everything in the layer is, from 0 to 1. To fade one element, put it in a layer of
460
+ * its own.
461
+ */
440
462
  opacity?: string;
441
463
  transform?: string;
464
+ /**
465
+ * A rectangle that cuts off what the layer draws outside it: x y w h, in points from the top left
466
+ * corner of the page.
467
+ */
442
468
  clip?: string;
443
469
  }
444
470
  /**
445
- * Attributes of the `rect` element on the canvas.
471
+ * Attributes of the `rect` element in a layer.
446
472
  */
447
473
  export interface RectAttr {
448
- w: string;
449
- h: string;
474
+ width: string;
475
+ height: string;
450
476
  x?: string;
451
477
  y?: string;
452
478
  anchor?: string;
@@ -455,39 +481,56 @@ export interface RectAttr {
455
481
  stroke?: string;
456
482
  strokeWidth?: string;
457
483
  strokeDash?: string;
458
- opacity?: string;
459
484
  }
460
485
  /**
461
- * Attributes of the `circle` element on the canvas.
486
+ * Attributes of the `circle` element in a layer.
462
487
  */
463
488
  export interface CircleAttr {
464
489
  r: string;
465
- cx?: string;
466
- cy?: string;
490
+ /**
491
+ * Where the circle's box goes, the square of side 2r around it: its left edge, or with anchor, an
492
+ * offset from that point of the page, where the box's matching point goes. The centre is r
493
+ * further in.
494
+ */
495
+ x?: string;
496
+ /**
497
+ * Where the circle's box goes, the square of side 2r around it: its top edge, or with anchor, an
498
+ * offset from that point of the page, where the box's matching point goes. The centre is r
499
+ * further in.
500
+ */
501
+ y?: string;
467
502
  anchor?: string;
468
503
  fill?: string;
469
504
  stroke?: string;
470
505
  strokeWidth?: string;
471
506
  strokeDash?: string;
472
- opacity?: string;
473
507
  }
474
508
  /**
475
- * Attributes of the `ellipse` element on the canvas.
509
+ * Attributes of the `ellipse` element in a layer.
476
510
  */
477
511
  export interface EllipseAttr {
478
512
  rx: string;
479
513
  ry: string;
480
- cx?: string;
481
- cy?: string;
514
+ /**
515
+ * Where the ellipse's box goes, 2rx wide and 2ry high around it: its left edge, or with anchor,
516
+ * an offset from that point of the page, where the box's matching point goes. The centre is rx
517
+ * further in.
518
+ */
519
+ x?: string;
520
+ /**
521
+ * Where the ellipse's box goes, 2rx wide and 2ry high around it: its top edge, or with anchor, an
522
+ * offset from that point of the page, where the box's matching point goes. The centre is ry
523
+ * further in.
524
+ */
525
+ y?: string;
482
526
  anchor?: string;
483
527
  fill?: string;
484
528
  stroke?: string;
485
529
  strokeWidth?: string;
486
530
  strokeDash?: string;
487
- opacity?: string;
488
531
  }
489
532
  /**
490
- * Attributes of the `line` element on the canvas.
533
+ * Attributes of the `line` element in a layer.
491
534
  */
492
535
  export interface LineAttr {
493
536
  x1: string;
@@ -500,7 +543,7 @@ export interface LineAttr {
500
543
  lineCap?: string;
501
544
  }
502
545
  /**
503
- * Attributes of the `path` element on the canvas.
546
+ * Attributes of the `path` element in a layer.
504
547
  */
505
548
  export interface PathAttr {
506
549
  d: string;
@@ -510,33 +553,104 @@ export interface PathAttr {
510
553
  strokeWidth?: string;
511
554
  strokeDash?: string;
512
555
  lineCap?: string;
513
- opacity?: string;
514
556
  }
515
557
  /**
516
- * Text at an exact position on the page: either x and y, or an anchor with optional offsets.
558
+ * Text at a fixed place on the page. It is the text of the layout, with the same defaults: the
559
+ * document's font or Helvetica, 11pt and the text colour. It is one line unless told otherwise;
560
+ * give width to cut it off at a width or to wrap it with max-lines. x and y place its box: the
561
+ * top-left corner, or with anchor, an offset from that point of the page, where the box's matching
562
+ * point goes. {page} and {pages} in it count within the section, and a text that comes from data
563
+ * belongs in the layout, since a longer text loses its end here without a warning.
517
564
  */
518
- export interface CanvasTextAttr {
565
+ export interface TextAtAttr {
519
566
  x?: string;
520
567
  y?: string;
521
568
  anchor?: string;
522
- font?: string;
523
569
  fontSize?: string;
570
+ font?: string;
571
+ /**
572
+ * Use the bold face of the font. It applies to the 14 built-in fonts: Helvetica becomes
573
+ * Helvetica-Bold, Times-Roman becomes Times-Bold, Courier becomes Courier-Bold, and the oblique
574
+ * and italic faces their bold forms. A custom font has no bold face to pick, so name one in font.
575
+ */
576
+ bold?: string;
524
577
  color?: string;
525
578
  align?: string;
526
- w?: string;
579
+ /**
580
+ * Width of the box. Without it the text is one line of the width its characters need, and align
581
+ * has no effect; a long text runs on past the edge of the page, which cuts it off, but stays in
582
+ * the PDF. With it, a line past the width is cut off at it, or ends in an ellipsis with ellipsis,
583
+ * and max-lines above 1 wraps the text within it.
584
+ */
585
+ width?: string;
586
+ /**
587
+ * The most lines drawn, 1 by default. Above 1 it needs a width to wrap at, and wraps the text
588
+ * within it; only whole lines are drawn, and the rest of the text is dropped.
589
+ */
590
+ maxLines?: string;
591
+ /**
592
+ * End the last line drawn in an ellipsis when the text does not fit its width and max-lines. Off
593
+ * by default: the line is cut off at the width.
594
+ */
595
+ ellipsis?: string;
596
+ /** The distance between lines, as a factor of the font size. Default 1.2. */
527
597
  lineHeight?: string;
528
- opacity?: string;
529
598
  }
530
599
  /**
531
- * Attributes of the `img` element on the canvas.
600
+ * An image at a fixed place on the page. It needs width or height, and the other follows the
601
+ * image's proportions. With both, they are a maximum: the image takes the largest size that fits in
602
+ * them, and its box becomes that size, so an anchor places the image itself. x and y place its box:
603
+ * the top-left corner, or with anchor, an offset from that point of the page, where the box's
604
+ * matching point goes.
532
605
  */
533
- export interface CanvasImgAttr {
606
+ export interface ImgAtAttr {
534
607
  name: string;
535
- w: string;
536
- h: string;
537
608
  x?: string;
538
609
  y?: string;
539
610
  anchor?: string;
611
+ width?: string;
612
+ height?: string;
613
+ }
614
+ /**
615
+ * A barcode at a fixed place on the page. It needs width or height, and the other follows the
616
+ * barcode's proportions. With both, they are a maximum: the barcode takes the largest size that
617
+ * fits in them, and its box becomes that size, so an anchor places the barcode itself. x and y
618
+ * place its box: the top-left corner, or with anchor, an offset from that point of the page, where
619
+ * the box's matching point goes.
620
+ */
621
+ export interface BarcodeAtAttr {
622
+ type: string;
623
+ data: string;
624
+ /**
625
+ * Height of the whole barcode, with the digits of hrt inside it: they take the bottom 12pt and
626
+ * the bars the rest. A barcode is never stretched. With only a height, the width follows the
627
+ * barcode's proportions. With both width and height, they are a maximum: the barcode takes the
628
+ * largest size that fits in them, and its box becomes that size. A QR code is square, so it takes
629
+ * the smaller of the two. Without a size, a code128 is as wide as its bars at 1pt per module and
630
+ * its bars are 40pt high, and an ean13 is the standard symbol, 0.33mm per module and bars 22.85mm
631
+ * high. The digits of hrt add 12pt to either.
632
+ */
633
+ height?: string;
634
+ ec?: string;
635
+ hrt?: string;
636
+ color?: string;
637
+ background?: string;
638
+ x?: string;
639
+ y?: string;
640
+ anchor?: string;
641
+ width?: string;
642
+ }
643
+ /**
644
+ * The flowing content of a section. Elements stack down the page, and a new page starts when one
645
+ * runs out of room. Put headers and footers in a region, which sits outside the flow.
646
+ */
647
+ export interface LayoutAttr {
648
+ /**
649
+ * The space between the page edges and the flowing content and its regions: one value for all
650
+ * four sides, or two to four in the order top, right, bottom, left. Defaults to 36pt. Layers
651
+ * ignore it and measure from the page edges.
652
+ */
653
+ margin?: string;
540
654
  }
541
655
  /**
542
656
  * Declares a font that text can be set in by name, with the font attribute. A built-in PDF font is
package/dist/browser.js CHANGED
@@ -119,7 +119,7 @@ var LpdfEngine = class {
119
119
  }
120
120
  }
121
121
  /**
122
- * Render a JSON kit-tree or canvas-tree document to PDF bytes.
122
+ * Render a JSON kit-tree document to PDF bytes.
123
123
  *
124
124
  * This is the JSON counterpart of `render_pdf`. The Node adapter uses it
125
125
  * when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
package/dist/canvas.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { RectAttr, CircleAttr, EllipseAttr, LineAttr, PathAttr, CanvasTextAttr, CanvasImgAttr, LayerAttr } from './attrs';
1
+ import type { RectAttr, CircleAttr, EllipseAttr, LineAttr, PathAttr, TextAtAttr, ImgAtAttr, BarcodeAtAttr, LayerAttr } from './attrs';
2
2
  import type { LpdfSpanNode } from './layout';
3
3
  /**
4
4
  * Builds the `transform` string of a layer. `String(CanvasTransform.rotate(45))` is
@@ -41,16 +41,20 @@ export interface LpdfCanvasPathNode {
41
41
  type: 'path';
42
42
  attrs: Record<string, string>;
43
43
  }
44
- export interface LpdfCanvasTextNode {
45
- type: 'text';
44
+ export interface LpdfCanvasTextAtNode {
45
+ type: 'text-at';
46
46
  attrs: Record<string, string>;
47
47
  nodes: (string | LpdfSpanNode)[];
48
48
  }
49
- export interface LpdfCanvasImgNode {
50
- type: 'img';
49
+ export interface LpdfCanvasImgAtNode {
50
+ type: 'img-at';
51
51
  attrs: Record<string, string>;
52
52
  }
53
- export type LpdfCanvasPrimitiveNode = LpdfCanvasRectNode | LpdfCanvasLineNode | LpdfCanvasEllipseNode | LpdfCanvasCircleNode | LpdfCanvasPathNode | LpdfCanvasTextNode | LpdfCanvasImgNode;
53
+ export interface LpdfCanvasBarcodeAtNode {
54
+ type: 'barcode-at';
55
+ attrs: Record<string, string>;
56
+ }
57
+ export type LpdfCanvasPrimitiveNode = LpdfCanvasRectNode | LpdfCanvasLineNode | LpdfCanvasEllipseNode | LpdfCanvasCircleNode | LpdfCanvasPathNode | LpdfCanvasTextAtNode | LpdfCanvasImgAtNode | LpdfCanvasBarcodeAtNode;
54
58
  export interface LpdfCanvasLayerNode {
55
59
  type: 'layer';
56
60
  attrs: Record<string, string>;
@@ -61,8 +65,9 @@ declare function line(attrs: LineAttr): LpdfCanvasLineNode;
61
65
  declare function ellipse(attrs: EllipseAttr): LpdfCanvasEllipseNode;
62
66
  declare function circle(attrs: CircleAttr): LpdfCanvasCircleNode;
63
67
  declare function path(attrs: PathAttr): LpdfCanvasPathNode;
64
- declare function textAt(attrs: CanvasTextAttr, nodes?: (string | LpdfSpanNode)[]): LpdfCanvasTextNode;
65
- declare function imgAt(attrs: CanvasImgAttr): LpdfCanvasImgNode;
68
+ declare function textAt(attrs: TextAtAttr, nodes?: (string | LpdfSpanNode)[]): LpdfCanvasTextAtNode;
69
+ declare function imgAt(attrs: ImgAtAttr): LpdfCanvasImgAtNode;
70
+ declare function barcodeAt(attrs: BarcodeAtAttr): LpdfCanvasBarcodeAtNode;
66
71
  declare function layer(attrs: LayerAttr | null, nodes?: LpdfCanvasPrimitiveNode[]): LpdfCanvasLayerNode;
67
72
  export declare const LpdfCanvas: Readonly<{
68
73
  rect: typeof rect;
@@ -72,6 +77,7 @@ export declare const LpdfCanvas: Readonly<{
72
77
  path: typeof path;
73
78
  textAt: typeof textAt;
74
79
  imgAt: typeof imgAt;
80
+ barcodeAt: typeof barcodeAt;
75
81
  layer: typeof layer;
76
82
  }>;
77
83
  export {};
package/dist/canvas.js CHANGED
@@ -67,10 +67,13 @@ function path(attrs) {
67
67
  return { type: 'path', attrs: (0, _shared_1.buildAttrs)(attrs) };
68
68
  }
69
69
  function textAt(attrs, nodes = []) {
70
- return { type: 'text', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
70
+ return { type: 'text-at', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
71
71
  }
72
72
  function imgAt(attrs) {
73
- return { type: 'img', attrs: (0, _shared_1.buildAttrs)(attrs) };
73
+ return { type: 'img-at', attrs: (0, _shared_1.buildAttrs)(attrs) };
74
+ }
75
+ function barcodeAt(attrs) {
76
+ return { type: 'barcode-at', attrs: (0, _shared_1.buildAttrs)(attrs) };
74
77
  }
75
78
  function layer(attrs, nodes = []) {
76
79
  return { type: 'layer', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
@@ -83,5 +86,6 @@ exports.LpdfCanvas = Object.freeze({
83
86
  path,
84
87
  textAt,
85
88
  imgAt,
89
+ barcodeAt,
86
90
  layer,
87
91
  });
package/dist/index.d.ts CHANGED
@@ -2,9 +2,9 @@ export { PdfEngine, LpdfRenderError } from './engine';
2
2
  export type { EncryptPermissions, EncryptOptions } from './engine';
3
3
  export type { RenderOptions, EngineOptions } from './_shared';
4
4
  export { FieldType, Pin, Orientation, SectionType, BuiltinFont, PageScope } from './constants';
5
- export type { PdfDocument, LpdfSectionNode, LpdfLayoutBlock, LpdfCanvasBlock, DocumentTokens, DocumentAssets, DocumentMeta, SectionAttr, DocumentAttr, } from './kit';
6
- export type { ColumnAttr, RowAttr, GridAttr, FrameAttr, LinkAttr, TableAttr, TheadAttr, TrAttr, TdAttr, TextAttr, SpanAttr, DividerAttr, ImgAttr, BarcodeAttr, RegionAttr, FieldAttr, BookmarkAttr, LayerAttr, RectAttr, CircleAttr, EllipseAttr, LineAttr, PathAttr, CanvasTextAttr, CanvasImgAttr, FontAttr, ImageAttr, } from './attrs';
5
+ export type { PdfDocument, LpdfSectionNode, LpdfSectionChild, LpdfLayoutBlock, DocumentTokens, DocumentAssets, DocumentMeta, SectionAttr, DocumentAttr, } from './kit';
6
+ export type { ColumnAttr, RowAttr, GridAttr, FrameAttr, LinkAttr, TableAttr, TheadAttr, TrAttr, TdAttr, TextAttr, SpanAttr, DividerAttr, ImgAttr, BarcodeAttr, RegionAttr, FieldAttr, BookmarkAttr, LayerAttr, RectAttr, CircleAttr, EllipseAttr, LineAttr, PathAttr, TextAtAttr, ImgAtAttr, BarcodeAtAttr, FontAttr, ImageAttr, LayoutAttr, } from './attrs';
7
7
  export type { LpdfNode, LpdfContainerNode, LpdfTextNode, LpdfSpanNode, LpdfDividerNode, LpdfImgNode, LpdfBarcodeNode, LpdfTableNode, LpdfTheadNode, LpdfTrNode, LpdfTdNode, LpdfRegionNode, LpdfFieldNode, LpdfBookmarkNode, } from './layout';
8
8
  export { CanvasTransform } from './canvas';
9
- export type { LpdfCanvasLayerNode, LpdfCanvasPrimitiveNode, LpdfCanvasRectNode, LpdfCanvasLineNode, LpdfCanvasEllipseNode, LpdfCanvasCircleNode, LpdfCanvasPathNode, LpdfCanvasTextNode, LpdfCanvasImgNode, } from './canvas';
9
+ export type { LpdfCanvasLayerNode, LpdfCanvasPrimitiveNode, LpdfCanvasRectNode, LpdfCanvasLineNode, LpdfCanvasEllipseNode, LpdfCanvasCircleNode, LpdfCanvasPathNode, LpdfCanvasTextAtNode, LpdfCanvasImgAtNode, LpdfCanvasBarcodeAtNode, } from './canvas';
10
10
  export { L, NoAttr } from './L';
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ Object.defineProperty(exports, "Orientation", { enumerable: true, get: function
13
13
  Object.defineProperty(exports, "SectionType", { enumerable: true, get: function () { return constants_1.SectionType; } });
14
14
  Object.defineProperty(exports, "BuiltinFont", { enumerable: true, get: function () { return constants_1.BuiltinFont; } });
15
15
  Object.defineProperty(exports, "PageScope", { enumerable: true, get: function () { return constants_1.PageScope; } });
16
- // ── Canvas types ──────────────────────────────────────────────────────────────
16
+ // ── Layer types ───────────────────────────────────────────────────────────────
17
17
  var canvas_1 = require("./canvas");
18
18
  Object.defineProperty(exports, "CanvasTransform", { enumerable: true, get: function () { return canvas_1.CanvasTransform; } });
19
19
  // ── Facade ────────────────────────────────────────────────────────────────────
package/dist/kit.d.ts CHANGED
@@ -1,31 +1,27 @@
1
1
  /**
2
2
  * LpdfKit — document skeleton assembly.
3
3
  *
4
- * Assembles sections (containing layout and canvas blocks) into a document
5
- * tree ready for `LpdfEngine.renderPdf()` or `kitToXml()`.
4
+ * Assembles sections (layers and a layout) into a document tree ready for
5
+ * `PdfEngine.render()` or `L.toXml()`. A section holds layers, then at most
6
+ * one layout, then layers: the layers before the layout paint under it, and
7
+ * the layers after it paint over it.
6
8
  *
7
9
  * @example
8
10
  * ```ts
9
- * import { LpdfEngine, LpdfKit, LpdfLayout, LpdfCanvas } from 'lpdf';
11
+ * import { L, NoAttr } from '@lpdfio/lpdf';
10
12
  *
11
- * const doc = LpdfKit.document({
12
- * sections: [
13
- * LpdfKit.section({
14
- * nodes: [
15
- * LpdfKit.canvas([ LpdfCanvas.layer([ LpdfCanvas.rect(0, 0, 595, 842) ]) ]),
16
- * LpdfKit.layout([ LpdfLayout.text(['Hello']) ]),
17
- * ],
18
- * options: { size: 'a4', margin: '28pt' },
19
- * }),
20
- * ],
21
- * options: { meta: { title: 'My Doc' } },
22
- * });
23
- * const bytes = await new LpdfEngine(key).renderPdf(doc);
13
+ * const doc = L.document({ meta: { title: 'My Doc' } }, [
14
+ * L.section({ size: 'a4' }, [
15
+ * L.layer(NoAttr, [ L.rect({ x: '0pt', y: '0pt', width: '595pt', height: '842pt', fill: '#f5f5f5' }) ]),
16
+ * L.layout({ margin: '28pt' }, [ L.text(NoAttr, ['Hello']) ]),
17
+ * ]),
18
+ * ]);
19
+ * const bytes = await L.engine().setLicenseKey(key).render(doc);
24
20
  * ```
25
21
  */
26
22
  import type { LpdfBookmarkNode, LpdfNode } from './layout';
27
23
  import type { LpdfCanvasLayerNode } from './canvas';
28
- import type { FontAttr, ImageAttr } from './attrs';
24
+ import type { FontAttr, ImageAttr, LayoutAttr } from './attrs';
29
25
  export interface DocumentTokens {
30
26
  colors?: Record<string, string>;
31
27
  space?: Record<string, string>;
@@ -53,7 +49,6 @@ export interface DocumentMeta {
53
49
  export interface SectionAttr {
54
50
  size?: string;
55
51
  orientation?: string;
56
- margin?: string;
57
52
  background?: string;
58
53
  title?: string;
59
54
  debug?: string;
@@ -63,7 +58,6 @@ export interface SectionAttr {
63
58
  export interface DocumentAttr {
64
59
  size?: string;
65
60
  orientation?: string;
66
- margin?: string;
67
61
  background?: string;
68
62
  font?: string;
69
63
  assets?: DocumentAssets;
@@ -74,31 +68,30 @@ export interface DocumentAttr {
74
68
  /** A layout block — wraps an ordered list of layout nodes. */
75
69
  export interface LpdfLayoutBlock {
76
70
  type: 'layout';
71
+ attrs: Record<string, string>;
77
72
  nodes: LpdfNode[];
78
73
  }
79
- /** A canvas block — wraps an ordered list of canvas layers. */
80
- export interface LpdfCanvasBlock {
81
- type: 'canvas';
82
- nodes: LpdfCanvasLayerNode[];
83
- }
84
74
  export interface LpdfSectionNode {
85
75
  type: 'section';
86
76
  attrs: Record<string, string>;
87
- nodes: (LpdfBookmarkNode | LpdfLayoutBlock | LpdfCanvasBlock)[];
77
+ nodes: LpdfSectionChild[];
88
78
  }
79
+ /**
80
+ * What a section holds: a bookmark first, then layers, then at most one layout, then layers. Layers before
81
+ * the layout paint under it, and layers after it paint over it.
82
+ */
83
+ export type LpdfSectionChild = LpdfBookmarkNode | LpdfCanvasLayerNode | LpdfLayoutBlock;
89
84
  export interface PdfDocument {
90
85
  version: 1;
91
86
  type: 'document';
92
87
  attrs: Record<string, unknown>;
93
88
  nodes: LpdfSectionNode[];
94
89
  }
95
- declare function layout(_attrs: null, nodes?: LpdfNode[]): LpdfLayoutBlock;
96
- declare function canvas(_attrs: null, layers?: LpdfCanvasLayerNode[]): LpdfCanvasBlock;
97
- declare function section(attrs: SectionAttr | null, nodes?: (LpdfBookmarkNode | LpdfLayoutBlock | LpdfCanvasBlock)[]): LpdfSectionNode;
90
+ declare function layout(attrs: LayoutAttr | null, nodes?: LpdfNode[]): LpdfLayoutBlock;
91
+ declare function section(attrs: SectionAttr | null, nodes?: LpdfSectionChild[]): LpdfSectionNode;
98
92
  declare function document(attrs: DocumentAttr | null, nodes?: LpdfSectionNode[]): PdfDocument;
99
93
  export declare const LpdfKit: Readonly<{
100
94
  layout: typeof layout;
101
- canvas: typeof canvas;
102
95
  section: typeof section;
103
96
  document: typeof document;
104
97
  }>;
package/dist/kit.js CHANGED
@@ -2,37 +2,30 @@
2
2
  /**
3
3
  * LpdfKit — document skeleton assembly.
4
4
  *
5
- * Assembles sections (containing layout and canvas blocks) into a document
6
- * tree ready for `LpdfEngine.renderPdf()` or `kitToXml()`.
5
+ * Assembles sections (layers and a layout) into a document tree ready for
6
+ * `PdfEngine.render()` or `L.toXml()`. A section holds layers, then at most
7
+ * one layout, then layers: the layers before the layout paint under it, and
8
+ * the layers after it paint over it.
7
9
  *
8
10
  * @example
9
11
  * ```ts
10
- * import { LpdfEngine, LpdfKit, LpdfLayout, LpdfCanvas } from 'lpdf';
12
+ * import { L, NoAttr } from '@lpdfio/lpdf';
11
13
  *
12
- * const doc = LpdfKit.document({
13
- * sections: [
14
- * LpdfKit.section({
15
- * nodes: [
16
- * LpdfKit.canvas([ LpdfCanvas.layer([ LpdfCanvas.rect(0, 0, 595, 842) ]) ]),
17
- * LpdfKit.layout([ LpdfLayout.text(['Hello']) ]),
18
- * ],
19
- * options: { size: 'a4', margin: '28pt' },
20
- * }),
21
- * ],
22
- * options: { meta: { title: 'My Doc' } },
23
- * });
24
- * const bytes = await new LpdfEngine(key).renderPdf(doc);
14
+ * const doc = L.document({ meta: { title: 'My Doc' } }, [
15
+ * L.section({ size: 'a4' }, [
16
+ * L.layer(NoAttr, [ L.rect({ x: '0pt', y: '0pt', width: '595pt', height: '842pt', fill: '#f5f5f5' }) ]),
17
+ * L.layout({ margin: '28pt' }, [ L.text(NoAttr, ['Hello']) ]),
18
+ * ]),
19
+ * ]);
20
+ * const bytes = await L.engine().setLicenseKey(key).render(doc);
25
21
  * ```
26
22
  */
27
23
  Object.defineProperty(exports, "__esModule", { value: true });
28
24
  exports.LpdfKit = void 0;
29
25
  const _shared_1 = require("./_shared");
30
26
  // ── Factory functions ─────────────────────────────────────────────────────────
31
- function layout(_attrs, nodes = []) {
32
- return { type: 'layout', nodes };
33
- }
34
- function canvas(_attrs, layers = []) {
35
- return { type: 'canvas', nodes: layers };
27
+ function layout(attrs, nodes = []) {
28
+ return { type: 'layout', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
36
29
  }
37
30
  function section(attrs, nodes = []) {
38
31
  return {
@@ -64,7 +57,6 @@ function document(attrs, nodes = []) {
64
57
  // ── LpdfKit export ────────────────────────────────────────────────────────────
65
58
  exports.LpdfKit = Object.freeze({
66
59
  layout,
67
- canvas,
68
60
  section,
69
61
  document,
70
62
  });
@@ -120,7 +120,7 @@ export class LpdfEngine {
120
120
  }
121
121
  }
122
122
  /**
123
- * Render a JSON kit-tree or canvas-tree document to PDF bytes.
123
+ * Render a JSON kit-tree document to PDF bytes.
124
124
  *
125
125
  * This is the JSON counterpart of `render_pdf`. The Node adapter uses it
126
126
  * when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
package/dist/wasm/lpdf.js CHANGED
@@ -120,7 +120,7 @@ class LpdfEngine {
120
120
  }
121
121
  }
122
122
  /**
123
- * Render a JSON kit-tree or canvas-tree document to PDF bytes.
123
+ * Render a JSON kit-tree document to PDF bytes.
124
124
  *
125
125
  * This is the JSON counterpart of `render_pdf`. The Node adapter uses it
126
126
  * when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpdfio/lpdf",
3
- "version": "0.26.0",
3
+ "version": "0.27.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",