@broadpaper/blocks 0.1.1

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.
@@ -0,0 +1,312 @@
1
+ import * as _broadpaper_core from '@broadpaper/core';
2
+ import { VNode, RichTextDoc, ConditionGroup, Theme, BlockDefinition, RegistryOptions, BlockRegistry } from '@broadpaper/core';
3
+
4
+ /**
5
+ * Structural nodes. They are hidden from the palette; the editor creates them
6
+ * through layout tools (add section, add row with a column layout).
7
+ */
8
+ declare const sectionBlock: _broadpaper_core.BlockDefinition<{
9
+ padding: number;
10
+ background?: string;
11
+ label?: string;
12
+ }>;
13
+ declare const rowBlock: _broadpaper_core.BlockDefinition<{
14
+ layout: number[];
15
+ allowSplit: boolean;
16
+ verticalAlign: "top" | "middle" | "bottom" | "stretch";
17
+ }>;
18
+ declare const columnBlock: _broadpaper_core.BlockDefinition<{
19
+ span: number;
20
+ }>;
21
+ declare const repeaterItemBlock: _broadpaper_core.BlockDefinition<{
22
+ index: number;
23
+ count: number;
24
+ }>;
25
+ declare function stack(h: typeof _broadpaper_core.h, children: VNode[], gap: number, extra?: Record<string, unknown>): VNode;
26
+
27
+ declare const headingBlock: _broadpaper_core.BlockDefinition<{
28
+ text: string;
29
+ level: "h1" | "h2" | "h3" | "h4";
30
+ }>;
31
+ declare const textBlock: _broadpaper_core.BlockDefinition<{
32
+ content: RichTextDoc;
33
+ }>;
34
+ declare const imageBlock: _broadpaper_core.BlockDefinition<{
35
+ src: string;
36
+ alt: string;
37
+ fit: "contain" | "cover";
38
+ width: number | null;
39
+ height: number | null;
40
+ align: "left" | "center" | "right";
41
+ radius: number;
42
+ link: string;
43
+ }>;
44
+ declare const logoBlock: _broadpaper_core.BlockDefinition<{
45
+ variant: "auto" | "light" | "dark";
46
+ height: number;
47
+ align: "left" | "center" | "right";
48
+ }>;
49
+ declare const dividerBlock: _broadpaper_core.BlockDefinition<{
50
+ thickness: number;
51
+ color: string;
52
+ lineStyle: "solid" | "dashed" | "dotted";
53
+ width: number;
54
+ }>;
55
+ declare const spacerBlock: _broadpaper_core.BlockDefinition<{
56
+ height: number;
57
+ }>;
58
+ declare const buttonBlock: _broadpaper_core.BlockDefinition<{
59
+ label: string;
60
+ url: string;
61
+ variant: "filled" | "outline" | "link";
62
+ color: string;
63
+ align: "left" | "center" | "right";
64
+ size: "sm" | "md" | "lg";
65
+ }>;
66
+ declare const calloutBlock: _broadpaper_core.BlockDefinition<{
67
+ title: string;
68
+ content: RichTextDoc;
69
+ tone: "info" | "success" | "warning" | "danger" | "neutral";
70
+ icon: boolean;
71
+ }>;
72
+ declare function mixWithWhite(hex: string, amount?: number): string;
73
+ declare const quoteBlock: _broadpaper_core.BlockDefinition<{
74
+ content: RichTextDoc;
75
+ attribution: string;
76
+ }>;
77
+ declare const fieldBlock: _broadpaper_core.BlockDefinition<{
78
+ label: string;
79
+ value: string;
80
+ layout: "stacked" | "inline";
81
+ fallback: string;
82
+ labelWidth: number;
83
+ }>;
84
+ declare const kpiBlock: _broadpaper_core.BlockDefinition<{
85
+ label: string;
86
+ value: string;
87
+ caption: string;
88
+ trend: string;
89
+ trendFormat: "percent" | "number" | "text";
90
+ accent: string;
91
+ align: "left" | "center" | "right";
92
+ size: "sm" | "md" | "lg";
93
+ }>;
94
+ declare const signatureBlock: _broadpaper_core.BlockDefinition<{
95
+ label: string;
96
+ name: string;
97
+ role: string;
98
+ showDate: boolean;
99
+ lineWidth: number;
100
+ }>;
101
+ declare const dateBlock: _broadpaper_core.BlockDefinition<{
102
+ source: "now" | "binding";
103
+ value: string;
104
+ pattern: string;
105
+ prefix: string;
106
+ }>;
107
+ declare const pageNumberBlock: _broadpaper_core.BlockDefinition<{
108
+ format: string;
109
+ align: "left" | "center" | "right";
110
+ }>;
111
+ declare const timestampBlock: _broadpaper_core.BlockDefinition<{
112
+ prefix: string;
113
+ pattern: string;
114
+ align: "left" | "center" | "right";
115
+ }>;
116
+
117
+ declare const containerBlock: _broadpaper_core.BlockDefinition<{
118
+ padding: number;
119
+ gap: number | null;
120
+ }>;
121
+ declare const cardBlock: _broadpaper_core.BlockDefinition<{
122
+ title: string;
123
+ padding: number | null;
124
+ accent: boolean;
125
+ accentColor: string;
126
+ }>;
127
+ declare const pageBreakBlock: _broadpaper_core.BlockDefinition<Record<string, never>>;
128
+ declare const keepTogetherBlock: _broadpaper_core.BlockDefinition<{
129
+ label: string;
130
+ }>;
131
+ declare const conditionalBlock: _broadpaper_core.BlockDefinition<{
132
+ condition: string | ConditionGroup;
133
+ label: string;
134
+ }>;
135
+ declare const repeaterBlock: _broadpaper_core.BlockDefinition<{
136
+ source: string;
137
+ alias: string;
138
+ keepItemTogether: boolean;
139
+ gap: number | null;
140
+ limit: number | null;
141
+ emptyMessage: string;
142
+ separator: boolean;
143
+ }>;
144
+
145
+ interface TableColumn {
146
+ id: string;
147
+ header: string;
148
+ /** Expression evaluated per row, e.g. `holding.value | currency`. */
149
+ value: string;
150
+ align?: "left" | "center" | "right";
151
+ /** Width as a percentage of the table width; null = auto (equal share of the rest). */
152
+ width?: number | null;
153
+ bold?: boolean;
154
+ /** Summary function for the totals row. */
155
+ total?: "none" | "sum" | "avg" | "count" | "min" | "max";
156
+ /** Expression for the totals cell (overrides `total`), evaluated in the table scope with `rows` available. */
157
+ totalExpr?: string;
158
+ /** Formatting pipe applied to the total, e.g. `currency:"GBP"`. */
159
+ totalFormat?: string;
160
+ wrap?: boolean;
161
+ }
162
+ interface ConditionalFormat {
163
+ id: string;
164
+ /** Column id, or "*" for the whole row. */
165
+ columnId: string;
166
+ /** Expression evaluated per row. */
167
+ condition: string;
168
+ color?: string;
169
+ background?: string;
170
+ bold?: boolean;
171
+ }
172
+ interface TableProps extends Record<string, unknown> {
173
+ source: string;
174
+ alias: string;
175
+ columns: TableColumn[];
176
+ showHeader: boolean;
177
+ repeatHeader: boolean;
178
+ zebra: boolean;
179
+ borders: "inherit" | "all" | "horizontal" | "outer" | "none";
180
+ compact: boolean;
181
+ fontSize: number | null;
182
+ headerBackground: string;
183
+ headerColor: string;
184
+ sortBy: string;
185
+ sortDir: "asc" | "desc";
186
+ emptyMessage: string;
187
+ totalsLabel: string;
188
+ conditionalFormats: ConditionalFormat[];
189
+ designRows: number;
190
+ rowLimit: number | null;
191
+ }
192
+ declare const tableBlock: _broadpaper_core.BlockDefinition<TableProps>;
193
+ declare const keyValueListBlock: _broadpaper_core.BlockDefinition<{
194
+ items: Array<{
195
+ id: string;
196
+ label: string;
197
+ value: string;
198
+ }>;
199
+ layout: "inline" | "stacked" | "grid";
200
+ labelWidth: number;
201
+ dividers: boolean;
202
+ columns: number;
203
+ }>;
204
+
205
+ type ChartType = "bar" | "horizontalBar" | "line" | "area" | "pie" | "donut";
206
+ interface ChartSeriesData {
207
+ label: string;
208
+ values: Array<number | null>;
209
+ color: string;
210
+ }
211
+ interface ChartData {
212
+ categories: string[];
213
+ series: ChartSeriesData[];
214
+ }
215
+ /**
216
+ * One thing a reader can point at: a bar, a slice, a marker on a line.
217
+ *
218
+ * The chart records these as it draws, because it is the only code that knows
219
+ * which mark is which datum. Nothing is drawn for them and no geometry is
220
+ * duplicated — the mark itself carries `data-bp-hit="<index>"`, so a screen
221
+ * renderer can find the element and use its real shape, and a PDF renderer can
222
+ * drop the attribute and produce exactly the vectors it produced before.
223
+ */
224
+ interface ChartHit {
225
+ /** Index into the chart's category list. */
226
+ categoryIndex: number;
227
+ category: string;
228
+ seriesIndex: number;
229
+ series: string;
230
+ value: number | null;
231
+ /** The value as the report itself formats it. */
232
+ formatted: string;
233
+ color: string;
234
+ /** For pie and donut: this slice's share of the whole. */
235
+ share?: number;
236
+ }
237
+ interface ChartRenderOptions {
238
+ type: ChartType;
239
+ width: number;
240
+ height: number;
241
+ theme: Theme;
242
+ fontFamily: string;
243
+ showLegend: boolean;
244
+ showValues: boolean;
245
+ showGrid: boolean;
246
+ stacked: boolean;
247
+ smooth: boolean;
248
+ /** Formats axis ticks and value labels. */
249
+ formatValue: (n: number) => string;
250
+ /** Formats pie/donut percentages. */
251
+ formatPercent: (fraction: number) => string;
252
+ innerLabel?: string;
253
+ /**
254
+ * Filled in as the chart draws, in the same order as the `data-bp-hit`
255
+ * indices on the marks. Left out entirely when nobody is going to read it.
256
+ */
257
+ hits?: ChartHit[];
258
+ }
259
+ declare function colorAt(data: ChartData, i: number): string;
260
+ /** Renders a chart to an SVG VNode. Pure and deterministic. */
261
+ declare function renderChart(data: ChartData, opts: ChartRenderOptions): VNode;
262
+
263
+ interface ChartSeries {
264
+ id: string;
265
+ label: string;
266
+ /** Expression evaluated per item. */
267
+ value: string;
268
+ color?: string;
269
+ }
270
+ interface ChartProps extends Record<string, unknown> {
271
+ chartType: ChartType;
272
+ source: string;
273
+ alias: string;
274
+ label: string;
275
+ series: ChartSeries[];
276
+ height: number;
277
+ title: string;
278
+ showLegend: boolean;
279
+ showValues: boolean;
280
+ showGrid: boolean;
281
+ stacked: boolean;
282
+ smooth: boolean;
283
+ valueFormat: string;
284
+ percentDecimals: number;
285
+ innerLabel: string;
286
+ limit: number | null;
287
+ }
288
+ declare const chartBlock: _broadpaper_core.BlockDefinition<ChartProps>;
289
+ declare const progressBlock: _broadpaper_core.BlockDefinition<{
290
+ value: string;
291
+ max: number;
292
+ label: string;
293
+ caption: string;
294
+ variant: "bar" | "gauge";
295
+ color: string;
296
+ trackColor: string;
297
+ showValue: boolean;
298
+ format: "percent" | "value" | "fraction";
299
+ thresholds: Array<{
300
+ id: string;
301
+ upTo: number;
302
+ color: string;
303
+ }>;
304
+ height: number;
305
+ }>;
306
+
307
+ /** Every built-in block, in palette order. */
308
+ declare const builtInBlocks: Array<BlockDefinition<any>>;
309
+ /** Creates a registry with every built-in block plus any custom blocks. */
310
+ declare function createRegistry(custom?: Array<BlockDefinition<any>>, opts?: RegistryOptions): BlockRegistry;
311
+
312
+ export { type ChartData, type ChartHit, type ChartProps, type ChartRenderOptions, type ChartSeries, type ChartSeriesData, type ChartType, type ConditionalFormat, type TableColumn, type TableProps, builtInBlocks, buttonBlock, calloutBlock, cardBlock, chartBlock, colorAt, columnBlock, conditionalBlock, containerBlock, createRegistry, dateBlock, dividerBlock, fieldBlock, headingBlock, imageBlock, keepTogetherBlock, keyValueListBlock, kpiBlock, logoBlock, mixWithWhite, pageBreakBlock, pageNumberBlock, progressBlock, quoteBlock, renderChart, repeaterBlock, repeaterItemBlock, rowBlock, sectionBlock, signatureBlock, spacerBlock, stack, tableBlock, textBlock, timestampBlock };