@formepdf/react 0.10.4 → 0.10.5
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/components.d.ts +131 -1
- package/dist/components.js +156 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/serialize.js +396 -23
- package/dist/types.d.ts +131 -0
- package/package.json +1 -1
package/dist/components.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DocumentProps, PageProps, ViewProps, TextProps, ImageProps, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, CanvasProps, WatermarkProps, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, TextFieldProps, CheckboxProps, DropdownProps, RadioButtonProps } from './types.js';
|
|
1
|
+
import type { DocumentProps, PageProps, ViewProps, TextProps, HeadingProps, OrderedListProps, UnorderedListProps, ListItemProps, StrongProps, EmProps, CodeProps, LinkProps, ImageProps, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, CanvasProps, WatermarkProps, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, TextFieldProps, CheckboxProps, DropdownProps, RadioButtonProps } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Root document container. Must be the top-level element in every Forme document.
|
|
4
4
|
*
|
|
@@ -75,6 +75,136 @@ export declare function View(_props: ViewProps): null;
|
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
77
|
export declare function Text(_props: TextProps): null;
|
|
78
|
+
/**
|
|
79
|
+
* Semantic heading components. `<H1>` … `<H6>`. Each level has sensible
|
|
80
|
+
* defaults (font size, weight, margin-top, margin-bottom) tuned for
|
|
81
|
+
* document layout; pass `style` to override individual properties (your
|
|
82
|
+
* values win on conflict).
|
|
83
|
+
*
|
|
84
|
+
* In tagged PDFs (`<Document tagged>` or `<Document pdfUa>`), headings
|
|
85
|
+
* map to the corresponding `/H1` – `/H6` PDF structure elements
|
|
86
|
+
* automatically — useful for screen-reader accessibility and for tools
|
|
87
|
+
* that build a table of contents from the structure tree.
|
|
88
|
+
*
|
|
89
|
+
* Inline formatting components work inside: `<H1>Chapter <Em>1</Em></H1>`.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* <H1>Annual Report</H1>
|
|
94
|
+
* <H2 style={{ marginTop: 32 }}>Executive Summary</H2>
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function H1(_props: HeadingProps): null;
|
|
98
|
+
export declare function H2(_props: HeadingProps): null;
|
|
99
|
+
export declare function H3(_props: HeadingProps): null;
|
|
100
|
+
export declare function H4(_props: HeadingProps): null;
|
|
101
|
+
export declare function H5(_props: HeadingProps): null;
|
|
102
|
+
export declare function H6(_props: HeadingProps): null;
|
|
103
|
+
/**
|
|
104
|
+
* An ordered (numbered) list. Children must be `<ListItem>` elements.
|
|
105
|
+
*
|
|
106
|
+
* Numbering continues across page breaks. The marker gutter is sized
|
|
107
|
+
* automatically to fit the widest number the list will render.
|
|
108
|
+
*
|
|
109
|
+
* @param props.type - Numbering style. `'decimal'` (default) | `'lower-alpha'`
|
|
110
|
+
* | `'upper-alpha'` | `'lower-roman'` | `'upper-roman'`.
|
|
111
|
+
* @param props.start - Starting index. Defaults to `1`.
|
|
112
|
+
* @param props.style - Container style overrides.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```tsx
|
|
116
|
+
* <OrderedList type="lower-alpha">
|
|
117
|
+
* <ListItem>first</ListItem>
|
|
118
|
+
* <ListItem>second</ListItem>
|
|
119
|
+
* </OrderedList>
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function OrderedList(_props: OrderedListProps): null;
|
|
123
|
+
/**
|
|
124
|
+
* An unordered (bulleted) list. Children must be `<ListItem>` elements.
|
|
125
|
+
*
|
|
126
|
+
* v1 ships with the standard "•" bullet glyph for `disc`, `circle`, and
|
|
127
|
+
* `square` (proper distinct glyphs for circle and square are a follow-up).
|
|
128
|
+
* `none` suppresses the marker entirely.
|
|
129
|
+
*
|
|
130
|
+
* @param props.marker - Bullet style. `'disc'` (default) | `'circle'`
|
|
131
|
+
* | `'square'` | `'none'`.
|
|
132
|
+
* @param props.style - Container style overrides.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```tsx
|
|
136
|
+
* <UnorderedList>
|
|
137
|
+
* <ListItem>first</ListItem>
|
|
138
|
+
* <ListItem>second</ListItem>
|
|
139
|
+
* </UnorderedList>
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export declare function UnorderedList(_props: UnorderedListProps): null;
|
|
143
|
+
/**
|
|
144
|
+
* One item inside an `<OrderedList>` or `<UnorderedList>`. Content can
|
|
145
|
+
* be text, inline-formatted runs, nested lists, or any Forme content
|
|
146
|
+
* node — the marker is rendered to the left, content (including any
|
|
147
|
+
* wrapped lines) aligns to the right of the marker gutter.
|
|
148
|
+
*/
|
|
149
|
+
export declare function ListItem(_props: ListItemProps): null;
|
|
150
|
+
/**
|
|
151
|
+
* Inline bold text. Use inside `<Text>` for runs of bold content.
|
|
152
|
+
* Equivalent to wrapping content in a `<Text style={{ fontWeight: 700 }}>`
|
|
153
|
+
* — just shorter. Composes with nested inline-formatting components
|
|
154
|
+
* (e.g. `<Strong><Em>both</Em></Strong>` produces bold + italic).
|
|
155
|
+
*
|
|
156
|
+
* @param props.style - Optional style overrides (merged on top of the
|
|
157
|
+
* default `fontWeight: 700`)
|
|
158
|
+
* @param props.children - Inline content (text, numbers, or other inline
|
|
159
|
+
* components like `<Em>`)
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```tsx
|
|
163
|
+
* <Text>Read the <Strong>fine print</Strong> carefully.</Text>
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare function Strong(_props: StrongProps): null;
|
|
167
|
+
/**
|
|
168
|
+
* Inline italic text. Use inside `<Text>` for runs of emphasized
|
|
169
|
+
* content. Equivalent to `<Text style={{ fontStyle: 'italic' }}>`.
|
|
170
|
+
*
|
|
171
|
+
* @param props.style - Optional style overrides
|
|
172
|
+
* @param props.children - Inline content
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```tsx
|
|
176
|
+
* <Text>This is <Em>important</Em> to remember.</Text>
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function Em(_props: EmProps): null;
|
|
180
|
+
/**
|
|
181
|
+
* Inline monospace text with a subtle background — like Markdown's
|
|
182
|
+
* `` `code` ``. Use inside `<Text>` for runs of inline code or paths.
|
|
183
|
+
*
|
|
184
|
+
* @param props.style - Optional style overrides (merged on top of the
|
|
185
|
+
* default font/background/padding)
|
|
186
|
+
* @param props.children - Inline content
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```tsx
|
|
190
|
+
* <Text>Run <Code>npm install</Code> to get started.</Text>
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export declare function Code(_props: CodeProps): null;
|
|
194
|
+
/**
|
|
195
|
+
* Inline hyperlink. Renders blue + underlined and is clickable in the
|
|
196
|
+
* output PDF. Use inside `<Text>` for inline links.
|
|
197
|
+
*
|
|
198
|
+
* @param props.href - The URL to link to (required)
|
|
199
|
+
* @param props.style - Optional style overrides
|
|
200
|
+
* @param props.children - Inline link content (the visible link text)
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```tsx
|
|
204
|
+
* <Text>See the <Link href="https://docs.formepdf.com">docs</Link>.</Text>
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export declare function Link(_props: LinkProps): null;
|
|
78
208
|
/**
|
|
79
209
|
* An image element. Supports JPEG, PNG, and WebP via data URIs or file paths.
|
|
80
210
|
*
|
package/dist/components.js
CHANGED
|
@@ -84,6 +84,162 @@ export function View(_props) {
|
|
|
84
84
|
export function Text(_props) {
|
|
85
85
|
return null;
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Semantic heading components. `<H1>` … `<H6>`. Each level has sensible
|
|
89
|
+
* defaults (font size, weight, margin-top, margin-bottom) tuned for
|
|
90
|
+
* document layout; pass `style` to override individual properties (your
|
|
91
|
+
* values win on conflict).
|
|
92
|
+
*
|
|
93
|
+
* In tagged PDFs (`<Document tagged>` or `<Document pdfUa>`), headings
|
|
94
|
+
* map to the corresponding `/H1` – `/H6` PDF structure elements
|
|
95
|
+
* automatically — useful for screen-reader accessibility and for tools
|
|
96
|
+
* that build a table of contents from the structure tree.
|
|
97
|
+
*
|
|
98
|
+
* Inline formatting components work inside: `<H1>Chapter <Em>1</Em></H1>`.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* <H1>Annual Report</H1>
|
|
103
|
+
* <H2 style={{ marginTop: 32 }}>Executive Summary</H2>
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export function H1(_props) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
export function H2(_props) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
export function H3(_props) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
export function H4(_props) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
export function H5(_props) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
export function H6(_props) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* An ordered (numbered) list. Children must be `<ListItem>` elements.
|
|
126
|
+
*
|
|
127
|
+
* Numbering continues across page breaks. The marker gutter is sized
|
|
128
|
+
* automatically to fit the widest number the list will render.
|
|
129
|
+
*
|
|
130
|
+
* @param props.type - Numbering style. `'decimal'` (default) | `'lower-alpha'`
|
|
131
|
+
* | `'upper-alpha'` | `'lower-roman'` | `'upper-roman'`.
|
|
132
|
+
* @param props.start - Starting index. Defaults to `1`.
|
|
133
|
+
* @param props.style - Container style overrides.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```tsx
|
|
137
|
+
* <OrderedList type="lower-alpha">
|
|
138
|
+
* <ListItem>first</ListItem>
|
|
139
|
+
* <ListItem>second</ListItem>
|
|
140
|
+
* </OrderedList>
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export function OrderedList(_props) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* An unordered (bulleted) list. Children must be `<ListItem>` elements.
|
|
148
|
+
*
|
|
149
|
+
* v1 ships with the standard "•" bullet glyph for `disc`, `circle`, and
|
|
150
|
+
* `square` (proper distinct glyphs for circle and square are a follow-up).
|
|
151
|
+
* `none` suppresses the marker entirely.
|
|
152
|
+
*
|
|
153
|
+
* @param props.marker - Bullet style. `'disc'` (default) | `'circle'`
|
|
154
|
+
* | `'square'` | `'none'`.
|
|
155
|
+
* @param props.style - Container style overrides.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```tsx
|
|
159
|
+
* <UnorderedList>
|
|
160
|
+
* <ListItem>first</ListItem>
|
|
161
|
+
* <ListItem>second</ListItem>
|
|
162
|
+
* </UnorderedList>
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export function UnorderedList(_props) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* One item inside an `<OrderedList>` or `<UnorderedList>`. Content can
|
|
170
|
+
* be text, inline-formatted runs, nested lists, or any Forme content
|
|
171
|
+
* node — the marker is rendered to the left, content (including any
|
|
172
|
+
* wrapped lines) aligns to the right of the marker gutter.
|
|
173
|
+
*/
|
|
174
|
+
export function ListItem(_props) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Inline bold text. Use inside `<Text>` for runs of bold content.
|
|
179
|
+
* Equivalent to wrapping content in a `<Text style={{ fontWeight: 700 }}>`
|
|
180
|
+
* — just shorter. Composes with nested inline-formatting components
|
|
181
|
+
* (e.g. `<Strong><Em>both</Em></Strong>` produces bold + italic).
|
|
182
|
+
*
|
|
183
|
+
* @param props.style - Optional style overrides (merged on top of the
|
|
184
|
+
* default `fontWeight: 700`)
|
|
185
|
+
* @param props.children - Inline content (text, numbers, or other inline
|
|
186
|
+
* components like `<Em>`)
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```tsx
|
|
190
|
+
* <Text>Read the <Strong>fine print</Strong> carefully.</Text>
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export function Strong(_props) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Inline italic text. Use inside `<Text>` for runs of emphasized
|
|
198
|
+
* content. Equivalent to `<Text style={{ fontStyle: 'italic' }}>`.
|
|
199
|
+
*
|
|
200
|
+
* @param props.style - Optional style overrides
|
|
201
|
+
* @param props.children - Inline content
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```tsx
|
|
205
|
+
* <Text>This is <Em>important</Em> to remember.</Text>
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export function Em(_props) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Inline monospace text with a subtle background — like Markdown's
|
|
213
|
+
* `` `code` ``. Use inside `<Text>` for runs of inline code or paths.
|
|
214
|
+
*
|
|
215
|
+
* @param props.style - Optional style overrides (merged on top of the
|
|
216
|
+
* default font/background/padding)
|
|
217
|
+
* @param props.children - Inline content
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```tsx
|
|
221
|
+
* <Text>Run <Code>npm install</Code> to get started.</Text>
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export function Code(_props) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Inline hyperlink. Renders blue + underlined and is clickable in the
|
|
229
|
+
* output PDF. Use inside `<Text>` for inline links.
|
|
230
|
+
*
|
|
231
|
+
* @param props.href - The URL to link to (required)
|
|
232
|
+
* @param props.style - Optional style overrides
|
|
233
|
+
* @param props.children - Inline link content (the visible link text)
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```tsx
|
|
237
|
+
* <Text>See the <Link href="https://docs.formepdf.com">docs</Link>.</Text>
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export function Link(_props) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
87
243
|
/**
|
|
88
244
|
* An image element. Supports JPEG, PNG, and WebP via data URIs or file paths.
|
|
89
245
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot, TextField, Checkbox, Dropdown, RadioButton } from './components.js';
|
|
1
|
+
export { Document, Page, View, Text, H1, H2, H3, H4, H5, H6, OrderedList, UnorderedList, ListItem, Strong, Em, Code, Link, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot, TextField, Checkbox, Dropdown, RadioButton } from './components.js';
|
|
2
2
|
export { LegacyBarChart, LegacyLineChart, LegacyPieChart } from './charts.js';
|
|
3
3
|
export { serialize, serializeTemplate, mapStyle, mapDimension, parseColor, expandEdges, expandCorners } from './serialize.js';
|
|
4
4
|
export { StyleSheet } from './stylesheet.js';
|
|
@@ -7,4 +7,4 @@ export type { FontRegistration } from './font.js';
|
|
|
7
7
|
export { createDataProxy, isRefMarker, isEachMarker, isExprMarker } from './template-proxy.js';
|
|
8
8
|
export { expr } from './expr.js';
|
|
9
9
|
export { render, renderToObject } from './render.js';
|
|
10
|
-
export type { Style, GridTrackSize, Edges, Corners, EdgeColors, DocumentProps, PageProps, ViewProps, TextProps, ImageProps, ColumnDef, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, BarcodeFormat, CanvasProps, CanvasContext, CanvasOp, WatermarkProps, ChartDataPoint, PieDataPoint, ChartSeries, DotPlotGroup, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, TextFieldProps, CheckboxProps, DropdownProps, RadioButtonProps, TextRun, CertificationConfig, SignatureConfig, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormePageConfig, FormePageSize, FormeEdges, FormeMetadata, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, } from './types.js';
|
|
10
|
+
export type { Style, GridTrackSize, Edges, Corners, EdgeColors, DocumentProps, PageProps, ViewProps, TextProps, HeadingProps, OrderedListProps, UnorderedListProps, ListItemProps, ListMarker, StrongProps, EmProps, CodeProps, LinkProps, ImageProps, ColumnDef, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, BarcodeFormat, CanvasProps, CanvasContext, CanvasOp, WatermarkProps, ChartDataPoint, PieDataPoint, ChartSeries, DotPlotGroup, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, TextFieldProps, CheckboxProps, DropdownProps, RadioButtonProps, TextRun, CertificationConfig, SignatureConfig, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormePageConfig, FormePageSize, FormeEdges, FormeMetadata, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Components
|
|
2
|
-
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot, TextField, Checkbox, Dropdown, RadioButton } from './components.js';
|
|
2
|
+
export { Document, Page, View, Text, H1, H2, H3, H4, H5, H6, OrderedList, UnorderedList, ListItem, Strong, Em, Code, Link, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot, TextField, Checkbox, Dropdown, RadioButton } from './components.js';
|
|
3
3
|
export { LegacyBarChart, LegacyLineChart, LegacyPieChart } from './charts.js';
|
|
4
4
|
// Serialization
|
|
5
5
|
export { serialize, serializeTemplate, mapStyle, mapDimension, parseColor, expandEdges, expandCorners } from './serialize.js';
|
package/dist/serialize.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isValidElement, Children, Fragment } from 'react';
|
|
2
|
-
import { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot, TextField, Checkbox, Dropdown, RadioButton } from './components.js';
|
|
2
|
+
import { Document, Page, View, Text, H1, H2, H3, H4, H5, H6, OrderedList, UnorderedList, ListItem, Strong, Em, Code, Link, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot, TextField, Checkbox, Dropdown, RadioButton } from './components.js';
|
|
3
3
|
import { Font } from './font.js';
|
|
4
4
|
import { isRefMarker, getRefPath, isEachMarker, getEachPath, getEachTemplate, isExprMarker, getExpr, REF_SENTINEL, REF_SENTINEL_END, } from './template-proxy.js';
|
|
5
5
|
const VALID_PARENTS = {
|
|
@@ -263,6 +263,24 @@ function serializeChild(child, parent = null) {
|
|
|
263
263
|
if (element.type === Text) {
|
|
264
264
|
return serializeText(element);
|
|
265
265
|
}
|
|
266
|
+
if (element.type === H1)
|
|
267
|
+
return serializeHeading(element, 1);
|
|
268
|
+
if (element.type === H2)
|
|
269
|
+
return serializeHeading(element, 2);
|
|
270
|
+
if (element.type === H3)
|
|
271
|
+
return serializeHeading(element, 3);
|
|
272
|
+
if (element.type === H4)
|
|
273
|
+
return serializeHeading(element, 4);
|
|
274
|
+
if (element.type === H5)
|
|
275
|
+
return serializeHeading(element, 5);
|
|
276
|
+
if (element.type === H6)
|
|
277
|
+
return serializeHeading(element, 6);
|
|
278
|
+
if (element.type === OrderedList)
|
|
279
|
+
return serializeList(element, true);
|
|
280
|
+
if (element.type === UnorderedList)
|
|
281
|
+
return serializeList(element, false);
|
|
282
|
+
if (element.type === ListItem)
|
|
283
|
+
return serializeListItem(element);
|
|
266
284
|
if (element.type === Image) {
|
|
267
285
|
return serializeImage(element);
|
|
268
286
|
}
|
|
@@ -375,32 +393,83 @@ function serializeView(element, _parent = null) {
|
|
|
375
393
|
node.href = props.href;
|
|
376
394
|
return node;
|
|
377
395
|
}
|
|
396
|
+
// Inline formatting components produce TextRuns with these default styles
|
|
397
|
+
// (merged under any user-supplied style, so user style wins).
|
|
398
|
+
const STRONG_DEFAULTS = { fontWeight: 700 };
|
|
399
|
+
const EM_DEFAULTS = { fontStyle: 'italic' };
|
|
400
|
+
const CODE_DEFAULTS = {
|
|
401
|
+
fontFamily: 'Courier',
|
|
402
|
+
backgroundColor: '#F4F4F5',
|
|
403
|
+
};
|
|
404
|
+
const LINK_DEFAULTS = {
|
|
405
|
+
color: '#2563EB',
|
|
406
|
+
textDecoration: 'underline',
|
|
407
|
+
};
|
|
408
|
+
/** Return the component-default style for a recognized inline component,
|
|
409
|
+
* or `null` if the element isn't a recognized inline component.
|
|
410
|
+
* `Text` returns `{}` because it carries no defaults beyond the user's style. */
|
|
411
|
+
function inlineDefaults(type) {
|
|
412
|
+
switch (type) {
|
|
413
|
+
case Text: return {};
|
|
414
|
+
case Strong: return STRONG_DEFAULTS;
|
|
415
|
+
case Em: return EM_DEFAULTS;
|
|
416
|
+
case Code: return CODE_DEFAULTS;
|
|
417
|
+
case Link: return LINK_DEFAULTS;
|
|
418
|
+
default: return null;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Recursively flatten children of a `<Text>` into TextRuns, accumulating
|
|
423
|
+
* styles and href as we descend. Outer style is overlaid by each inline
|
|
424
|
+
* component's defaults, which are in turn overlaid by the user-supplied
|
|
425
|
+
* `style` on that element — so user style wins at every level while
|
|
426
|
+
* still inheriting whatever wasn't explicitly set.
|
|
427
|
+
*
|
|
428
|
+
* E.g. `<Strong><Em>both</Em></Strong>` produces a single run with
|
|
429
|
+
* `{ fontWeight: 700, fontStyle: 'italic' }`. A `<Link href>` nested in a
|
|
430
|
+
* `<Strong>` produces a bold underlined blue run with the href set.
|
|
431
|
+
*/
|
|
432
|
+
function buildTextRuns(children, accStyle = {}, accHref = undefined) {
|
|
433
|
+
const out = [];
|
|
434
|
+
const elements = flattenChildren(children);
|
|
435
|
+
for (const child of elements) {
|
|
436
|
+
if (child === null || child === undefined || typeof child === 'boolean')
|
|
437
|
+
continue;
|
|
438
|
+
if (typeof child === 'string' || typeof child === 'number') {
|
|
439
|
+
const content = String(child);
|
|
440
|
+
if (content === '')
|
|
441
|
+
continue;
|
|
442
|
+
const run = { content };
|
|
443
|
+
if (Object.keys(accStyle).length > 0)
|
|
444
|
+
run.style = mapStyle(accStyle);
|
|
445
|
+
if (accHref)
|
|
446
|
+
run.href = accHref;
|
|
447
|
+
out.push(run);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (!isValidElement(child))
|
|
451
|
+
continue;
|
|
452
|
+
const defaults = inlineDefaults(child.type);
|
|
453
|
+
if (defaults === null)
|
|
454
|
+
continue; // unknown element inside <Text> — skip
|
|
455
|
+
const childProps = child.props;
|
|
456
|
+
// Cascade: outer accumulated → this component's defaults → user style.
|
|
457
|
+
// Later spreads win, so user style overrides defaults and outer.
|
|
458
|
+
const nextStyle = { ...accStyle, ...defaults, ...(childProps.style || {}) };
|
|
459
|
+
const nextHref = childProps.href ?? accHref;
|
|
460
|
+
out.push(...buildTextRuns(childProps.children, nextStyle, nextHref));
|
|
461
|
+
}
|
|
462
|
+
return out;
|
|
463
|
+
}
|
|
378
464
|
function serializeText(element) {
|
|
379
465
|
const props = element.props;
|
|
380
466
|
const childElements = flattenChildren(props.children);
|
|
381
|
-
//
|
|
382
|
-
|
|
467
|
+
// Detect mixed content: any inline element child (<Text>, <Strong>, <Em>,
|
|
468
|
+
// <Code>, <Link>) means we need TextRuns rather than a flat content string.
|
|
469
|
+
const hasInlineChild = childElements.some(c => isValidElement(c) && inlineDefaults(c.type) !== null);
|
|
383
470
|
const kind = { type: 'Text', content: '' };
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
-
const runs = [];
|
|
387
|
-
for (const child of childElements) {
|
|
388
|
-
if (typeof child === 'string' || typeof child === 'number') {
|
|
389
|
-
runs.push({ content: String(child) });
|
|
390
|
-
}
|
|
391
|
-
else if (isValidElement(child) && child.type === Text) {
|
|
392
|
-
const childProps = child.props;
|
|
393
|
-
const run = {
|
|
394
|
-
content: flattenTextContent(childProps.children),
|
|
395
|
-
};
|
|
396
|
-
if (childProps.style)
|
|
397
|
-
run.style = mapStyle(childProps.style);
|
|
398
|
-
if (childProps.href)
|
|
399
|
-
run.href = childProps.href;
|
|
400
|
-
runs.push(run);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
kind.runs = runs;
|
|
471
|
+
if (hasInlineChild) {
|
|
472
|
+
kind.runs = buildTextRuns(props.children);
|
|
404
473
|
}
|
|
405
474
|
else {
|
|
406
475
|
kind.content = flattenTextContent(props.children);
|
|
@@ -417,6 +486,120 @@ function serializeText(element) {
|
|
|
417
486
|
node.bookmark = props.bookmark;
|
|
418
487
|
return node;
|
|
419
488
|
}
|
|
489
|
+
// Default style per heading level. Tuned for typical document layout —
|
|
490
|
+
// users override individual properties via `style` on the heading element.
|
|
491
|
+
// margin top/bottom are in points; font sizes are points.
|
|
492
|
+
const HEADING_DEFAULTS = {
|
|
493
|
+
1: { fontSize: 32, fontWeight: 700, marginTop: 24, marginBottom: 16 },
|
|
494
|
+
2: { fontSize: 24, fontWeight: 700, marginTop: 20, marginBottom: 14 },
|
|
495
|
+
3: { fontSize: 20, fontWeight: 600, marginTop: 16, marginBottom: 12 },
|
|
496
|
+
4: { fontSize: 18, fontWeight: 600, marginTop: 14, marginBottom: 10 },
|
|
497
|
+
5: { fontSize: 16, fontWeight: 600, marginTop: 12, marginBottom: 8 },
|
|
498
|
+
6: { fontSize: 14, fontWeight: 600, marginTop: 10, marginBottom: 6 },
|
|
499
|
+
};
|
|
500
|
+
/**
|
|
501
|
+
* Serialize an H1-H6 element. Mirrors serializeText for the children
|
|
502
|
+
* machinery (mixed strings + inline-formatting components produce runs)
|
|
503
|
+
* but emits the engine's `Heading { level }` node kind so the tagged-PDF
|
|
504
|
+
* builder can pick up the semantic role. Default styles per level are
|
|
505
|
+
* merged BEFORE the user's `style` prop, so user values win.
|
|
506
|
+
*/
|
|
507
|
+
function serializeHeading(element, level) {
|
|
508
|
+
const props = element.props;
|
|
509
|
+
const childElements = flattenChildren(props.children);
|
|
510
|
+
const hasInlineChild = childElements.some((c) => isValidElement(c) && inlineDefaults(c.type) !== null);
|
|
511
|
+
const kind = {
|
|
512
|
+
type: 'Heading',
|
|
513
|
+
level,
|
|
514
|
+
content: '',
|
|
515
|
+
};
|
|
516
|
+
if (hasInlineChild) {
|
|
517
|
+
kind.runs = buildTextRuns(props.children);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
kind.content = flattenTextContent(props.children);
|
|
521
|
+
}
|
|
522
|
+
if (props.href)
|
|
523
|
+
kind.href = props.href;
|
|
524
|
+
// Defaults underlay; user style wins on conflicting keys.
|
|
525
|
+
const mergedStyle = { ...HEADING_DEFAULTS[level], ...(props.style || {}) };
|
|
526
|
+
const node = {
|
|
527
|
+
kind,
|
|
528
|
+
style: mapStyle(mergedStyle),
|
|
529
|
+
children: [],
|
|
530
|
+
sourceLocation: extractSourceLocation(element),
|
|
531
|
+
};
|
|
532
|
+
if (props.bookmark)
|
|
533
|
+
node.bookmark = props.bookmark;
|
|
534
|
+
return node;
|
|
535
|
+
}
|
|
536
|
+
// React `list-style-type`-shaped string → engine wire enum value.
|
|
537
|
+
function mapListMarker(marker, defaultValue) {
|
|
538
|
+
switch (marker) {
|
|
539
|
+
case 'disc': return 'disc';
|
|
540
|
+
case 'circle': return 'circle';
|
|
541
|
+
case 'square': return 'square';
|
|
542
|
+
case 'none': return 'none';
|
|
543
|
+
case 'decimal': return 'decimal';
|
|
544
|
+
case 'lower-alpha': return 'lowerAlpha';
|
|
545
|
+
case 'upper-alpha': return 'upperAlpha';
|
|
546
|
+
case 'lower-roman': return 'lowerRoman';
|
|
547
|
+
case 'upper-roman': return 'upperRoman';
|
|
548
|
+
default: return defaultValue;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
function serializeList(element, ordered) {
|
|
552
|
+
const props = element.props;
|
|
553
|
+
const markerType = ordered
|
|
554
|
+
? mapListMarker(props.type, 'decimal')
|
|
555
|
+
: mapListMarker(props.marker, 'disc');
|
|
556
|
+
const start = typeof props.start === 'number' && props.start >= 1 ? props.start : 1;
|
|
557
|
+
// Children must be ListItems — anything else is silently dropped to
|
|
558
|
+
// keep the serializer tolerant. (We don't throw on stray content because
|
|
559
|
+
// a Fragment / null child in JSX is too common to be a real error.)
|
|
560
|
+
const childElements = flattenChildren(props.children).filter((c) => isValidElement(c) && c.type === ListItem);
|
|
561
|
+
const children = childElements.map((c) => serializeListItem(c));
|
|
562
|
+
const node = {
|
|
563
|
+
kind: { type: 'List', ordered, marker_type: markerType, start },
|
|
564
|
+
style: mapStyle(props.style),
|
|
565
|
+
children,
|
|
566
|
+
sourceLocation: extractSourceLocation(element),
|
|
567
|
+
};
|
|
568
|
+
if (props.bookmark)
|
|
569
|
+
node.bookmark = props.bookmark;
|
|
570
|
+
return node;
|
|
571
|
+
}
|
|
572
|
+
function serializeListItem(element) {
|
|
573
|
+
const props = element.props;
|
|
574
|
+
// ListItem content is layed out by the engine using layout_children, so
|
|
575
|
+
// we serialize whatever the user put inside as the node's children. This
|
|
576
|
+
// covers plain strings, JSX text, nested lists, formatted runs via
|
|
577
|
+
// <Text>, etc.
|
|
578
|
+
const rawChildren = flattenChildren(props.children);
|
|
579
|
+
const children = [];
|
|
580
|
+
for (const c of rawChildren) {
|
|
581
|
+
if (typeof c === 'string' || typeof c === 'number') {
|
|
582
|
+
// Auto-wrap raw strings in a Text node so the engine has something
|
|
583
|
+
// concrete to render. Matches the convention everywhere else.
|
|
584
|
+
children.push({
|
|
585
|
+
kind: { type: 'Text', content: String(c) },
|
|
586
|
+
style: {},
|
|
587
|
+
children: [],
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
else if (isValidElement(c)) {
|
|
591
|
+
const node = serializeChild(c, null);
|
|
592
|
+
if (node)
|
|
593
|
+
children.push(node);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return {
|
|
597
|
+
kind: { type: 'ListItem' },
|
|
598
|
+
style: mapStyle(props.style),
|
|
599
|
+
children,
|
|
600
|
+
sourceLocation: extractSourceLocation(element),
|
|
601
|
+
};
|
|
602
|
+
}
|
|
420
603
|
function serializeImage(element) {
|
|
421
604
|
const props = element.props;
|
|
422
605
|
const kind = { type: 'Image', src: props.src };
|
|
@@ -1120,6 +1303,16 @@ export function mapStyle(style) {
|
|
|
1120
1303
|
if (parsed)
|
|
1121
1304
|
result.boxShadow = parsed;
|
|
1122
1305
|
}
|
|
1306
|
+
if (style.transform !== undefined) {
|
|
1307
|
+
const parsed = parseTransform(style.transform);
|
|
1308
|
+
if (parsed && parsed.length > 0)
|
|
1309
|
+
result.transform = parsed;
|
|
1310
|
+
}
|
|
1311
|
+
if (style.transformOrigin !== undefined) {
|
|
1312
|
+
const parsed = parseTransformOrigin(style.transformOrigin);
|
|
1313
|
+
if (parsed)
|
|
1314
|
+
result.transformOrigin = parsed;
|
|
1315
|
+
}
|
|
1123
1316
|
if (style.textDecoration !== undefined)
|
|
1124
1317
|
result.textDecoration = TEXT_DECORATION_MAP[style.textDecoration];
|
|
1125
1318
|
if (style.textTransform !== undefined)
|
|
@@ -1377,6 +1570,186 @@ export function parseColor(hex) {
|
|
|
1377
1570
|
// Fallback: black
|
|
1378
1571
|
return { r: 0, g: 0, b: 0, a: 1 };
|
|
1379
1572
|
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Parse a CSS-like `transform` string into the engine's TransformOp[].
|
|
1575
|
+
*
|
|
1576
|
+
* Accepted syntax (space- or comma-separated ops, in any order):
|
|
1577
|
+
* `rotate(45deg)`, `rotate(-15deg)`, `rotate(0.5turn)`, `rotate(1.2rad)`
|
|
1578
|
+
* `scale(1.5)`, `scale(2, 0.5)`
|
|
1579
|
+
* `translate(10, -4)`, `translate(10px, -4pt)`
|
|
1580
|
+
*
|
|
1581
|
+
* Lengths are interpreted as points (px/pt suffix accepted and ignored;
|
|
1582
|
+
* Forme is a print-first engine — 1 point = 1 point). Returns `null` on
|
|
1583
|
+
* unparseable input (the property is silently dropped, matching the
|
|
1584
|
+
* boxShadow precedent).
|
|
1585
|
+
*/
|
|
1586
|
+
function parseTransform(val) {
|
|
1587
|
+
const ops = [];
|
|
1588
|
+
// Match `name(args)` pairs. Names: ASCII letters. Args: anything between
|
|
1589
|
+
// parentheses (no nesting in this grammar).
|
|
1590
|
+
const re = /([a-zA-Z]+)\s*\(([^)]*)\)/g;
|
|
1591
|
+
let m;
|
|
1592
|
+
let matched = false;
|
|
1593
|
+
while ((m = re.exec(val)) !== null) {
|
|
1594
|
+
matched = true;
|
|
1595
|
+
const name = m[1].toLowerCase();
|
|
1596
|
+
const args = m[2]
|
|
1597
|
+
.split(/[,\s]+/)
|
|
1598
|
+
.map((s) => s.trim())
|
|
1599
|
+
.filter((s) => s.length > 0);
|
|
1600
|
+
if (name === 'rotate' || name === 'rotatez') {
|
|
1601
|
+
if (args.length !== 1)
|
|
1602
|
+
return null;
|
|
1603
|
+
const deg = parseAngle(args[0]);
|
|
1604
|
+
if (deg === null)
|
|
1605
|
+
return null;
|
|
1606
|
+
ops.push({ type: 'rotate', deg });
|
|
1607
|
+
}
|
|
1608
|
+
else if (name === 'scale') {
|
|
1609
|
+
if (args.length === 0 || args.length > 2)
|
|
1610
|
+
return null;
|
|
1611
|
+
const x = parseFloat(args[0]);
|
|
1612
|
+
if (Number.isNaN(x))
|
|
1613
|
+
return null;
|
|
1614
|
+
const y = args.length === 2 ? parseFloat(args[1]) : x;
|
|
1615
|
+
if (Number.isNaN(y))
|
|
1616
|
+
return null;
|
|
1617
|
+
ops.push({ type: 'scale', x, y });
|
|
1618
|
+
}
|
|
1619
|
+
else if (name === 'scalex') {
|
|
1620
|
+
if (args.length !== 1)
|
|
1621
|
+
return null;
|
|
1622
|
+
const x = parseFloat(args[0]);
|
|
1623
|
+
if (Number.isNaN(x))
|
|
1624
|
+
return null;
|
|
1625
|
+
ops.push({ type: 'scale', x, y: 1 });
|
|
1626
|
+
}
|
|
1627
|
+
else if (name === 'scaley') {
|
|
1628
|
+
if (args.length !== 1)
|
|
1629
|
+
return null;
|
|
1630
|
+
const y = parseFloat(args[0]);
|
|
1631
|
+
if (Number.isNaN(y))
|
|
1632
|
+
return null;
|
|
1633
|
+
ops.push({ type: 'scale', x: 1, y });
|
|
1634
|
+
}
|
|
1635
|
+
else if (name === 'translate') {
|
|
1636
|
+
if (args.length === 0 || args.length > 2)
|
|
1637
|
+
return null;
|
|
1638
|
+
const x = parseLengthPt(args[0]);
|
|
1639
|
+
if (x === null)
|
|
1640
|
+
return null;
|
|
1641
|
+
const y = args.length === 2 ? parseLengthPt(args[1]) : 0;
|
|
1642
|
+
if (y === null)
|
|
1643
|
+
return null;
|
|
1644
|
+
ops.push({ type: 'translate', x, y });
|
|
1645
|
+
}
|
|
1646
|
+
else if (name === 'translatex') {
|
|
1647
|
+
if (args.length !== 1)
|
|
1648
|
+
return null;
|
|
1649
|
+
const x = parseLengthPt(args[0]);
|
|
1650
|
+
if (x === null)
|
|
1651
|
+
return null;
|
|
1652
|
+
ops.push({ type: 'translate', x, y: 0 });
|
|
1653
|
+
}
|
|
1654
|
+
else if (name === 'translatey') {
|
|
1655
|
+
if (args.length !== 1)
|
|
1656
|
+
return null;
|
|
1657
|
+
const y = parseLengthPt(args[0]);
|
|
1658
|
+
if (y === null)
|
|
1659
|
+
return null;
|
|
1660
|
+
ops.push({ type: 'translate', x: 0, y });
|
|
1661
|
+
}
|
|
1662
|
+
else {
|
|
1663
|
+
// Unknown op (e.g. skew, matrix) — reject the whole transform so
|
|
1664
|
+
// users notice rather than getting silently-half-applied transforms.
|
|
1665
|
+
return null;
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
if (!matched)
|
|
1669
|
+
return null;
|
|
1670
|
+
return ops;
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* Parse an angle in `deg` / `rad` / `turn` (no unit defaults to deg).
|
|
1674
|
+
* Returns the angle in DEGREES, or null on parse failure.
|
|
1675
|
+
*/
|
|
1676
|
+
function parseAngle(s) {
|
|
1677
|
+
const t = s.trim().toLowerCase();
|
|
1678
|
+
let mult = 1;
|
|
1679
|
+
let body = t;
|
|
1680
|
+
if (t.endsWith('deg')) {
|
|
1681
|
+
body = t.slice(0, -3);
|
|
1682
|
+
}
|
|
1683
|
+
else if (t.endsWith('rad')) {
|
|
1684
|
+
body = t.slice(0, -3);
|
|
1685
|
+
mult = 180 / Math.PI;
|
|
1686
|
+
}
|
|
1687
|
+
else if (t.endsWith('turn')) {
|
|
1688
|
+
body = t.slice(0, -4);
|
|
1689
|
+
mult = 360;
|
|
1690
|
+
}
|
|
1691
|
+
const n = parseFloat(body);
|
|
1692
|
+
if (Number.isNaN(n))
|
|
1693
|
+
return null;
|
|
1694
|
+
return n * mult;
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* Parse a length value — accepts a bare number or `<n>px`/`<n>pt` and
|
|
1698
|
+
* returns the value in points. Forme is print-first; px/pt are treated
|
|
1699
|
+
* as the same unit at the React layer.
|
|
1700
|
+
*/
|
|
1701
|
+
function parseLengthPt(s) {
|
|
1702
|
+
const t = s.trim().toLowerCase();
|
|
1703
|
+
const body = t.endsWith('px') || t.endsWith('pt') ? t.slice(0, -2) : t;
|
|
1704
|
+
const n = parseFloat(body);
|
|
1705
|
+
return Number.isNaN(n) ? null : n;
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Parse a `transformOrigin` value into a `[x, y]` tuple of fractions
|
|
1709
|
+
* (0.0–1.0). Accepts the user-side tuple shape directly, or a CSS-like
|
|
1710
|
+
* string with two tokens (`"50% 50%"`, `"0% 100%"`, `"center top"`,
|
|
1711
|
+
* `"left bottom"`, etc.). Returns null on unparseable input.
|
|
1712
|
+
*/
|
|
1713
|
+
function parseTransformOrigin(val) {
|
|
1714
|
+
if (Array.isArray(val)) {
|
|
1715
|
+
const [x, y] = val;
|
|
1716
|
+
if (typeof x !== 'number' || typeof y !== 'number')
|
|
1717
|
+
return null;
|
|
1718
|
+
return [x, y];
|
|
1719
|
+
}
|
|
1720
|
+
const tokens = val.trim().split(/\s+/).filter((t) => t.length > 0);
|
|
1721
|
+
if (tokens.length === 0 || tokens.length > 2)
|
|
1722
|
+
return null;
|
|
1723
|
+
const x = parseOriginToken(tokens[0], 'x');
|
|
1724
|
+
if (x === null)
|
|
1725
|
+
return null;
|
|
1726
|
+
const y = tokens.length === 2 ? parseOriginToken(tokens[1], 'y') : 0.5;
|
|
1727
|
+
if (y === null)
|
|
1728
|
+
return null;
|
|
1729
|
+
return [x, y];
|
|
1730
|
+
}
|
|
1731
|
+
function parseOriginToken(token, axis) {
|
|
1732
|
+
const t = token.toLowerCase();
|
|
1733
|
+
if (t === 'center')
|
|
1734
|
+
return 0.5;
|
|
1735
|
+
if (axis === 'x') {
|
|
1736
|
+
if (t === 'left')
|
|
1737
|
+
return 0;
|
|
1738
|
+
if (t === 'right')
|
|
1739
|
+
return 1;
|
|
1740
|
+
}
|
|
1741
|
+
else {
|
|
1742
|
+
if (t === 'top')
|
|
1743
|
+
return 0;
|
|
1744
|
+
if (t === 'bottom')
|
|
1745
|
+
return 1;
|
|
1746
|
+
}
|
|
1747
|
+
if (t.endsWith('%')) {
|
|
1748
|
+
const n = parseFloat(t.slice(0, -1));
|
|
1749
|
+
return Number.isNaN(n) ? null : n / 100;
|
|
1750
|
+
}
|
|
1751
|
+
return null;
|
|
1752
|
+
}
|
|
1380
1753
|
/**
|
|
1381
1754
|
* Parse a `boxShadow` value (object form or CSS-like string
|
|
1382
1755
|
* `"offsetX offsetY blur color"`) into the engine's FormeBoxShadow shape.
|
package/dist/types.d.ts
CHANGED
|
@@ -130,6 +130,25 @@ export interface Style {
|
|
|
130
130
|
*/
|
|
131
131
|
background?: string;
|
|
132
132
|
opacity?: number;
|
|
133
|
+
/**
|
|
134
|
+
* Paint-only transform applied around the element's origin (default:
|
|
135
|
+
* center). Layout flow is NOT affected — matches CSS `transform`.
|
|
136
|
+
*
|
|
137
|
+
* Accepts a CSS-like string with one or more space-separated ops:
|
|
138
|
+
* `"rotate(45deg)"`
|
|
139
|
+
* `"rotate(-15deg) scale(1.2)"`
|
|
140
|
+
* `"translate(10, -4) rotate(30deg)"`
|
|
141
|
+
*
|
|
142
|
+
* Supported ops: `rotate(<deg>deg)`, `scale(<x>[, <y>])`,
|
|
143
|
+
* `translate(<x>[, <y>])`. Angles are degrees, lengths are points.
|
|
144
|
+
*/
|
|
145
|
+
transform?: string;
|
|
146
|
+
/**
|
|
147
|
+
* Origin of the transform as fractions of the element box.
|
|
148
|
+
* `"50% 50%"` (default) = center, `"0% 0%"` = top-left, `"100% 0%"`
|
|
149
|
+
* = top-right, etc. Also accepts a tuple `[x, y]` where each is 0–1.
|
|
150
|
+
*/
|
|
151
|
+
transformOrigin?: string | [number, number];
|
|
133
152
|
borderWidth?: number | Edges;
|
|
134
153
|
borderTopWidth?: number;
|
|
135
154
|
borderRightWidth?: number;
|
|
@@ -241,6 +260,86 @@ export interface TextProps {
|
|
|
241
260
|
bookmark?: string;
|
|
242
261
|
children?: ReactNode;
|
|
243
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Marker style for an ordered or unordered list. Matches CSS
|
|
265
|
+
* `list-style-type` for the supported values.
|
|
266
|
+
*/
|
|
267
|
+
export type ListMarker = 'disc' | 'circle' | 'square' | 'none' | 'decimal' | 'lower-alpha' | 'upper-alpha' | 'lower-roman' | 'upper-roman';
|
|
268
|
+
/**
|
|
269
|
+
* An ordered (numbered) list. Children must be `<ListItem>`s.
|
|
270
|
+
*/
|
|
271
|
+
export interface OrderedListProps {
|
|
272
|
+
/** Marker style. Defaults to `'decimal'`. */
|
|
273
|
+
type?: 'decimal' | 'lower-alpha' | 'upper-alpha' | 'lower-roman' | 'upper-roman';
|
|
274
|
+
/** Starting index. Defaults to `1`. */
|
|
275
|
+
start?: number;
|
|
276
|
+
style?: Style;
|
|
277
|
+
bookmark?: string;
|
|
278
|
+
children?: ReactNode;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* An unordered (bulleted) list. Children must be `<ListItem>`s.
|
|
282
|
+
*/
|
|
283
|
+
export interface UnorderedListProps {
|
|
284
|
+
/** Bullet glyph style. Defaults to `'disc'`. */
|
|
285
|
+
marker?: 'disc' | 'circle' | 'square' | 'none';
|
|
286
|
+
style?: Style;
|
|
287
|
+
bookmark?: string;
|
|
288
|
+
children?: ReactNode;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* One item inside an `<OrderedList>` or `<UnorderedList>`. Content can be
|
|
292
|
+
* text, inline-formatted runs, nested lists, or any other Forme node.
|
|
293
|
+
*/
|
|
294
|
+
export interface ListItemProps {
|
|
295
|
+
style?: Style;
|
|
296
|
+
children?: ReactNode;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Semantic heading. Renders text with sensible default styling per level
|
|
300
|
+
* (size, weight, margin) AND tags the element as `/H1`–`/H6` in tagged
|
|
301
|
+
* PDFs (PDF/UA / PDF/A-2a), so screen readers and the PDF outline
|
|
302
|
+
* builder treat it as a heading. Inline formatting components like
|
|
303
|
+
* `<Strong>` and `<Em>` work inside.
|
|
304
|
+
*/
|
|
305
|
+
export interface HeadingProps {
|
|
306
|
+
style?: Style;
|
|
307
|
+
href?: string;
|
|
308
|
+
bookmark?: string;
|
|
309
|
+
children?: ReactNode;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Inline bold text. Only meaningful as a child of `<Text>` — produces a
|
|
313
|
+
* TextRun with `fontWeight: 700` merged with any provided `style`.
|
|
314
|
+
*/
|
|
315
|
+
export interface StrongProps {
|
|
316
|
+
style?: Style;
|
|
317
|
+
children?: ReactNode;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Inline italic text. Only meaningful as a child of `<Text>`.
|
|
321
|
+
*/
|
|
322
|
+
export interface EmProps {
|
|
323
|
+
style?: Style;
|
|
324
|
+
children?: ReactNode;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Inline monospace text with a subtle background. Only meaningful as a
|
|
328
|
+
* child of `<Text>`.
|
|
329
|
+
*/
|
|
330
|
+
export interface CodeProps {
|
|
331
|
+
style?: Style;
|
|
332
|
+
children?: ReactNode;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Inline hyperlink. Renders blue + underlined; clickable in the rendered
|
|
336
|
+
* PDF. Only meaningful as a child of `<Text>`.
|
|
337
|
+
*/
|
|
338
|
+
export interface LinkProps {
|
|
339
|
+
href: string;
|
|
340
|
+
style?: Style;
|
|
341
|
+
children?: ReactNode;
|
|
342
|
+
}
|
|
244
343
|
export interface ImageProps {
|
|
245
344
|
src: string;
|
|
246
345
|
width?: number;
|
|
@@ -675,6 +774,23 @@ export interface FormeBoxShadow {
|
|
|
675
774
|
a: number;
|
|
676
775
|
};
|
|
677
776
|
}
|
|
777
|
+
/** Engine wire format for list marker type — matches the Rust enum's
|
|
778
|
+
* serde camelCase output. */
|
|
779
|
+
export type FormeListMarkerType = 'disc' | 'circle' | 'square' | 'none' | 'decimal' | 'lowerAlpha' | 'upperAlpha' | 'lowerRoman' | 'upperRoman';
|
|
780
|
+
/** A single transform operation in the engine wire format. The discriminator
|
|
781
|
+
* is `type` matching the engine's serde tag. */
|
|
782
|
+
export type FormeTransformOp = {
|
|
783
|
+
type: 'rotate';
|
|
784
|
+
deg: number;
|
|
785
|
+
} | {
|
|
786
|
+
type: 'scale';
|
|
787
|
+
x: number;
|
|
788
|
+
y: number;
|
|
789
|
+
} | {
|
|
790
|
+
type: 'translate';
|
|
791
|
+
x: number;
|
|
792
|
+
y: number;
|
|
793
|
+
};
|
|
678
794
|
export interface FormeGradientStop {
|
|
679
795
|
position: number;
|
|
680
796
|
color: {
|
|
@@ -730,6 +846,19 @@ export type FormeNodeKind = {
|
|
|
730
846
|
content: string;
|
|
731
847
|
href?: string;
|
|
732
848
|
runs?: TextRun[];
|
|
849
|
+
} | {
|
|
850
|
+
type: 'Heading';
|
|
851
|
+
level: number;
|
|
852
|
+
content: string;
|
|
853
|
+
href?: string;
|
|
854
|
+
runs?: TextRun[];
|
|
855
|
+
} | {
|
|
856
|
+
type: 'List';
|
|
857
|
+
ordered: boolean;
|
|
858
|
+
marker_type: FormeListMarkerType;
|
|
859
|
+
start: number;
|
|
860
|
+
} | {
|
|
861
|
+
type: 'ListItem';
|
|
733
862
|
} | {
|
|
734
863
|
type: 'Image';
|
|
735
864
|
src: string;
|
|
@@ -946,6 +1075,8 @@ export interface FormeStyle {
|
|
|
946
1075
|
letterSpacing?: number;
|
|
947
1076
|
wordSpacing?: number;
|
|
948
1077
|
boxShadow?: FormeBoxShadow;
|
|
1078
|
+
transform?: FormeTransformOp[];
|
|
1079
|
+
transformOrigin?: [number, number];
|
|
949
1080
|
textDecoration?: string;
|
|
950
1081
|
textTransform?: string;
|
|
951
1082
|
hyphens?: string;
|