@pdfme/jsx 6.1.1-dev.8 → 6.1.2-dev.11
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 +104 -12
- package/dist/components.d.ts +12 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +655 -58
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +89 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,15 +4,23 @@ Small JSX authoring layer for creating pdfme templates from stacking layout prim
|
|
|
4
4
|
|
|
5
5
|
```tsx
|
|
6
6
|
/** @jsxImportSource @pdfme/jsx */
|
|
7
|
-
import { Page, Stack, Text, renderToTemplate } from '@pdfme/jsx';
|
|
7
|
+
import { Document, MultiVariableText, Page, Stack, Text, renderToTemplate } from '@pdfme/jsx';
|
|
8
8
|
|
|
9
9
|
const { template, inputs } = await renderToTemplate(
|
|
10
|
-
<
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
<Document margin={{ x: 12, y: 16 }}>
|
|
11
|
+
<Page>
|
|
12
|
+
<Stack gap={4}>
|
|
13
|
+
<Text size={18}>Invoice</Text>
|
|
14
|
+
<Text name="customerName">Alice</Text>
|
|
15
|
+
<MultiVariableText
|
|
16
|
+
name="message"
|
|
17
|
+
text="Hello **{name}**, status: `{status}`"
|
|
18
|
+
values={{ name: 'Alice **literal**', status: 'draft' }}
|
|
19
|
+
textFormat="inline-markdown"
|
|
20
|
+
/>
|
|
21
|
+
</Stack>
|
|
22
|
+
</Page>
|
|
23
|
+
</Document>,
|
|
16
24
|
);
|
|
17
25
|
```
|
|
18
26
|
|
|
@@ -22,11 +30,95 @@ it provides its own `jsx-runtime` and `jsx-dev-runtime`.
|
|
|
22
30
|
|
|
23
31
|
## MVP constraints
|
|
24
32
|
|
|
25
|
-
- `Text`
|
|
26
|
-
Pass an explicit `height` when you need a fixed field box.
|
|
33
|
+
- `Text` and `MultiVariableText` heights are measured with pdfme's text/rich text wrapping helpers
|
|
34
|
+
when `height` is omitted. Pass an explicit `height` when you need a fixed field box.
|
|
35
|
+
- `Text textFormat="inline-markdown"` is read-only only. Editable `Text` values use plain content.
|
|
36
|
+
- `MultiVariableText` uses `text` or children as the template string and stores `values` as the
|
|
37
|
+
JSON input. Variable names are inferred from `{name}` placeholders and can also be passed with
|
|
38
|
+
`variables`.
|
|
39
|
+
- `Image` uses `src` as its initial content and is intended to be self-closing.
|
|
40
|
+
- `Svg` uses `svg` or children as its initial content.
|
|
41
|
+
- With `name`, `Image` and `Svg` become input-backed schemas; without `name`, they are read-only
|
|
42
|
+
content.
|
|
43
|
+
- `Rectangle`, `Ellipse`, and `Line` are static visual schemas for backgrounds, dividers, and simple
|
|
44
|
+
shapes.
|
|
45
|
+
- `Document` is the root component for document-level settings and repeated static content. It can
|
|
46
|
+
contain `Header`, `Footer`, `Static`, and `Page` children.
|
|
47
|
+
- `Document` props are defaults, not deep-merged style objects. If a `Page` specifies `margin`,
|
|
48
|
+
`size`, `orientation`, or `font`, that `Page` value replaces the `Document` value for that prop.
|
|
49
|
+
The generated blank `basePdf.padding` comes from the resolved margin of the first rendered page.
|
|
50
|
+
- `Header` and `Footer` render read-only content into blank `basePdf.staticSchema`. `Header` uses the
|
|
51
|
+
top margin area and `Footer` uses the bottom margin area, so body content stays inside the `Page`
|
|
52
|
+
margin frame.
|
|
53
|
+
- `Static` is a lower-level repeated overlay that uses full-page coordinates. It is useful for
|
|
54
|
+
watermarks and other fixed page-coordinate content. Custom `basePdf` is not supported when
|
|
55
|
+
document static content is present.
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
<Document size="A4" margin={{ x: 16, y: 18 }}>
|
|
59
|
+
<Header>
|
|
60
|
+
<Text height={8}>Header</Text>
|
|
61
|
+
</Header>
|
|
62
|
+
<Footer>
|
|
63
|
+
<Text height={8}>Footer</Text>
|
|
64
|
+
</Footer>
|
|
65
|
+
<Page>
|
|
66
|
+
<Text height={8}>Body</Text>
|
|
67
|
+
</Page>
|
|
68
|
+
</Document>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- `Header`, `Footer`, and `Static` must be direct children of `Document`. They are intentionally not
|
|
72
|
+
allowed inside `Page`, because they render into document-level `staticSchema` and are repeated on
|
|
73
|
+
every page.
|
|
74
|
+
- Multiple `Static` blocks with the same placement are concatenated in declaration order. Top blocks
|
|
75
|
+
start at the top of the page; bottom blocks are stacked together in declaration order and anchored
|
|
76
|
+
to the page bottom, so the last bottom block sits at the page edge. If static content overlaps the
|
|
77
|
+
header/footer/body areas, pdfme will draw the schemas in static schema order.
|
|
78
|
+
- Static content currently accepts read-only `Stack`, `Row`, `Box`, `Spacer`, `Text`, `Image`, `Svg`,
|
|
79
|
+
`Rectangle`, `Ellipse`, and `Line` content. `MultiVariableText`, `List`, `Table`, input-backed
|
|
80
|
+
schemas, and `PageBreak` are rejected.
|
|
81
|
+
- `Absolute` can be used inside `Page`, `Header`, `Footer`, top `Static`, or `Box` as a small manual
|
|
82
|
+
placement escape hatch. It uses the parent layout frame as its coordinate origin and does not
|
|
83
|
+
advance the surrounding stack/row flow. When `width` or `height` is omitted, it uses the remaining
|
|
84
|
+
parent frame size from `x` / `y`. Direct `Stack` / `Row` support is intentionally left for later;
|
|
85
|
+
wrap with an explicit-size `Box` when you need a local manual-placement frame inside flow content.
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
<Page margin={12}>
|
|
89
|
+
<Text height={8}>Body starts here</Text>
|
|
90
|
+
<Absolute x={120} y={0} width={60}>
|
|
91
|
+
<Text height={6}>Top-right note</Text>
|
|
92
|
+
</Absolute>
|
|
93
|
+
</Page>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- Layout children can use `margin`. `Stack` and `Row` support `alignItems` for simple cross-axis
|
|
97
|
+
alignment without trying to implement full CSS/Flexbox.
|
|
98
|
+
- `Stack` and `Row` support `justifyContent="start" | "center" | "end" | "space-between"` for
|
|
99
|
+
main-axis spacing. `Stack` uses this most predictably with an explicit `height`; `Row` uses it most
|
|
100
|
+
predictably with an explicit `width`.
|
|
101
|
+
- `Stack` defaults to `alignItems="stretch"` to preserve full-width stacking. Use an explicit child
|
|
102
|
+
`width` when you want `alignItems="center"` or `"end"` to visibly move that child.
|
|
103
|
+
- `Row` defaults to `alignItems="start"` and intentionally does not support cross-axis stretch yet.
|
|
104
|
+
- Row children can use `flexGrow` or `flex` as a grow weight. If `width` is also set, it is used as
|
|
105
|
+
the basis before remaining width is distributed.
|
|
106
|
+
`flex` is only a short alias for `flexGrow`, not the CSS `flex` shorthand.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
<Row width={120}>
|
|
110
|
+
<Text width={20} flex={1}>A</Text>
|
|
111
|
+
<Text width={20} flex={3}>B</Text>
|
|
112
|
+
</Row>
|
|
113
|
+
// A width: 40, B width: 80
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
- `flexGrow={0}` without `width` produces a zero-width Row child.
|
|
27
117
|
- `PageBreak` is supported only along a `Page` / `Stack` / `Box` layout path. It is rejected inside
|
|
28
|
-
`Row`,
|
|
118
|
+
`Row`, leaf schemas, `List`, and `Table`.
|
|
29
119
|
- All `Page` nodes in one `renderToTemplate` call must use the same page size, orientation, and
|
|
30
120
|
margin because a pdfme blank `basePdf` has one shared size and padding.
|
|
31
|
-
- `Table
|
|
32
|
-
`
|
|
121
|
+
- `Table columnWeights` are relative column width weights, not millimeter widths. They are
|
|
122
|
+
normalized to pdfme `headWidthPercentages`, for example `columnWeights={[70, 30]}`.
|
|
123
|
+
Missing or invalid weights default to `1`, so pass one weight per column when you need exact
|
|
124
|
+
ratios. Earlier beta builds used `widths`; use `columnWeights` going forward.
|
package/dist/components.d.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import type { BoxProps, ListProps, PageBreakProps, PageProps, RowProps, SpacerProps, StackProps, TableProps, TextProps } from './types.js';
|
|
1
|
+
import type { AbsoluteProps, BoxProps, DocumentProps, EllipseProps, FooterProps, HeaderProps, ImageProps, LineProps, ListProps, MultiVariableTextProps, PageBreakProps, PageProps, RectangleProps, RowProps, SpacerProps, StackProps, StaticProps, SvgProps, TableProps, TextProps } from './types.js';
|
|
2
|
+
export declare const Document: (props: DocumentProps) => import("./types.js").PdfJsxElement<"document">;
|
|
2
3
|
export declare const Page: (props: PageProps) => import("./types.js").PdfJsxElement<"page">;
|
|
4
|
+
export declare const Static: (props: StaticProps) => import("./types.js").PdfJsxElement<"static">;
|
|
5
|
+
export declare const Header: (props: HeaderProps) => import("./types.js").PdfJsxElement<"header">;
|
|
6
|
+
export declare const Footer: (props: FooterProps) => import("./types.js").PdfJsxElement<"footer">;
|
|
7
|
+
export declare const Absolute: (props: AbsoluteProps) => import("./types.js").PdfJsxElement<"absolute">;
|
|
3
8
|
export declare const Stack: (props: StackProps) => import("./types.js").PdfJsxElement<"stack">;
|
|
4
9
|
export declare const Row: (props: RowProps) => import("./types.js").PdfJsxElement<"row">;
|
|
5
10
|
export declare const Box: (props: BoxProps) => import("./types.js").PdfJsxElement<"box">;
|
|
6
11
|
export declare const Spacer: (props: SpacerProps) => import("./types.js").PdfJsxElement<"spacer">;
|
|
7
12
|
export declare const Text: (props: TextProps) => import("./types.js").PdfJsxElement<"text">;
|
|
13
|
+
export declare const MultiVariableText: (props: MultiVariableTextProps) => import("./types.js").PdfJsxElement<"multiVariableText">;
|
|
14
|
+
export declare const Image: (props: ImageProps) => import("./types.js").PdfJsxElement<"image">;
|
|
15
|
+
export declare const Svg: (props: SvgProps) => import("./types.js").PdfJsxElement<"svg">;
|
|
16
|
+
export declare const Rectangle: (props: RectangleProps) => import("./types.js").PdfJsxElement<"rectangle">;
|
|
17
|
+
export declare const Ellipse: (props: EllipseProps) => import("./types.js").PdfJsxElement<"ellipse">;
|
|
18
|
+
export declare const Line: (props: LineProps) => import("./types.js").PdfJsxElement<"line">;
|
|
8
19
|
export declare const List: (props: ListProps) => import("./types.js").PdfJsxElement<"list">;
|
|
9
20
|
export declare const Table: (props: TableProps) => import("./types.js").PdfJsxElement<"table">;
|
|
10
21
|
export declare const PageBreak: (props?: PageBreakProps) => import("./types.js").PdfJsxElement<"pagebreak">;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Box, List, Page, PageBreak, Row, Spacer, Stack, Table, Text } from './components.js';
|
|
1
|
+
export { Absolute, Box, Document, Ellipse, Footer, Header, Image, Line, List, MultiVariableText, Page, PageBreak, Rectangle, Row, Spacer, Stack, Static, Svg, Table, Text, } from './components.js';
|
|
2
2
|
export { renderToTemplate } from './render.js';
|
|
3
|
-
export type { BoxProps, BoxSides, CellStyle, ListItem, ListProps, PageBreakProps, PageOrientation, PageProps, PageSize, PageSizePreset, PdfJsxChild, PdfJsxElement, RenderOptions, RenderResult, RowProps, SpacerProps, StackProps, TableProps, TextProps, } from './types.js';
|
|
3
|
+
export type { AbsoluteProps, BoxProps, BoxSides, CellStyle, DocumentProps, EllipseProps, FooterProps, HeaderProps, ImageProps, LineProps, ListItem, ListProps, MultiVariableTextProps, MultiVariableTextValues, PageBreakProps, PageOrientation, PageProps, PageSize, PageSizePreset, PdfJsxChild, PdfJsxElement, RectangleProps, RenderOptions, RenderResult, RowProps, SpacerProps, StackProps, StaticPlacement, StaticProps, SvgProps, TableProps, TextProps, } from './types.js';
|