@pyreon/document 0.0.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.
- package/LICENSE +21 -0
- package/lib/analysis/index.js.html +5406 -0
- package/lib/chunk-ErZ26oRB.js +48 -0
- package/lib/confluence-Va8e7RxQ.js +192 -0
- package/lib/confluence-Va8e7RxQ.js.map +1 -0
- package/lib/csv-2c38ub-Y.js +32 -0
- package/lib/csv-2c38ub-Y.js.map +1 -0
- package/lib/discord-DAoUZqvE.js +134 -0
- package/lib/discord-DAoUZqvE.js.map +1 -0
- package/lib/dist-BsqdI2nY.js +20179 -0
- package/lib/dist-BsqdI2nY.js.map +1 -0
- package/lib/docx-CorFwEH9.js +450 -0
- package/lib/docx-CorFwEH9.js.map +1 -0
- package/lib/email-Bn_Brjdp.js +131 -0
- package/lib/email-Bn_Brjdp.js.map +1 -0
- package/lib/exceljs-BoIDUUaw.js +34377 -0
- package/lib/exceljs-BoIDUUaw.js.map +1 -0
- package/lib/google-chat-B6I017I1.js +125 -0
- package/lib/google-chat-B6I017I1.js.map +1 -0
- package/lib/html-De_iS_f0.js +151 -0
- package/lib/html-De_iS_f0.js.map +1 -0
- package/lib/index.js +619 -0
- package/lib/index.js.map +1 -0
- package/lib/markdown-BYC_3C9i.js +75 -0
- package/lib/markdown-BYC_3C9i.js.map +1 -0
- package/lib/notion-DHaQHO6P.js +187 -0
- package/lib/notion-DHaQHO6P.js.map +1 -0
- package/lib/pdf-CDPc5Itc.js +419 -0
- package/lib/pdf-CDPc5Itc.js.map +1 -0
- package/lib/pdfmake-DnmLxK4Q.js +55511 -0
- package/lib/pdfmake-DnmLxK4Q.js.map +1 -0
- package/lib/pptx-DKQU6bjq.js +252 -0
- package/lib/pptx-DKQU6bjq.js.map +1 -0
- package/lib/pptxgen.es-COcgXsyx.js +5697 -0
- package/lib/pptxgen.es-COcgXsyx.js.map +1 -0
- package/lib/slack-CJRJgkag.js +139 -0
- package/lib/slack-CJRJgkag.js.map +1 -0
- package/lib/svg-BM8biZmL.js +187 -0
- package/lib/svg-BM8biZmL.js.map +1 -0
- package/lib/teams-S99tonRG.js +176 -0
- package/lib/teams-S99tonRG.js.map +1 -0
- package/lib/telegram-CbEO_2PN.js +77 -0
- package/lib/telegram-CbEO_2PN.js.map +1 -0
- package/lib/text-B5U8ucRr.js +75 -0
- package/lib/text-B5U8ucRr.js.map +1 -0
- package/lib/types/index.d.ts +528 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/vfs_fonts-Df1kkZ4Y.js +19 -0
- package/lib/vfs_fonts-Df1kkZ4Y.js.map +1 -0
- package/lib/whatsapp-DJ2D1jGG.js +64 -0
- package/lib/whatsapp-DJ2D1jGG.js.map +1 -0
- package/lib/xlsx-D47x-gZ5.js +199 -0
- package/lib/xlsx-D47x-gZ5.js.map +1 -0
- package/package.json +62 -0
- package/src/builder.ts +266 -0
- package/src/download.ts +76 -0
- package/src/env.d.ts +17 -0
- package/src/index.ts +98 -0
- package/src/nodes.ts +315 -0
- package/src/render.ts +222 -0
- package/src/renderers/confluence.ts +231 -0
- package/src/renderers/csv.ts +67 -0
- package/src/renderers/discord.ts +192 -0
- package/src/renderers/docx.ts +612 -0
- package/src/renderers/email.ts +230 -0
- package/src/renderers/google-chat.ts +211 -0
- package/src/renderers/html.ts +225 -0
- package/src/renderers/markdown.ts +144 -0
- package/src/renderers/notion.ts +264 -0
- package/src/renderers/pdf.ts +427 -0
- package/src/renderers/pptx.ts +353 -0
- package/src/renderers/slack.ts +192 -0
- package/src/renderers/svg.ts +254 -0
- package/src/renderers/teams.ts +234 -0
- package/src/renderers/telegram.ts +137 -0
- package/src/renderers/text.ts +154 -0
- package/src/renderers/whatsapp.ts +121 -0
- package/src/renderers/xlsx.ts +342 -0
- package/src/tests/document.test.ts +2920 -0
- package/src/types.ts +291 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// ─── Node Types ─────────────────────────────────────────────────────────────
|
|
2
|
+
|
|
3
|
+
export type NodeType =
|
|
4
|
+
| 'document'
|
|
5
|
+
| 'page'
|
|
6
|
+
| 'section'
|
|
7
|
+
| 'row'
|
|
8
|
+
| 'column'
|
|
9
|
+
| 'heading'
|
|
10
|
+
| 'text'
|
|
11
|
+
| 'link'
|
|
12
|
+
| 'image'
|
|
13
|
+
| 'table'
|
|
14
|
+
| 'list'
|
|
15
|
+
| 'list-item'
|
|
16
|
+
| 'page-break'
|
|
17
|
+
| 'code'
|
|
18
|
+
| 'divider'
|
|
19
|
+
| 'spacer'
|
|
20
|
+
| 'button'
|
|
21
|
+
| 'quote'
|
|
22
|
+
|
|
23
|
+
/** A format-agnostic document node. */
|
|
24
|
+
export interface DocNode {
|
|
25
|
+
type: NodeType
|
|
26
|
+
props: Record<string, unknown>
|
|
27
|
+
children: DocChild[]
|
|
28
|
+
/** Resolved styles from ui-system connector (optional). */
|
|
29
|
+
styles?: ResolvedStyles
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type DocChild = DocNode | string
|
|
33
|
+
|
|
34
|
+
// ─── Style Types ────────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
export interface ResolvedStyles {
|
|
37
|
+
fontSize?: number
|
|
38
|
+
fontFamily?: string
|
|
39
|
+
fontWeight?: 'normal' | 'bold' | number
|
|
40
|
+
fontStyle?: 'normal' | 'italic'
|
|
41
|
+
textDecoration?: 'none' | 'underline' | 'line-through'
|
|
42
|
+
color?: string
|
|
43
|
+
backgroundColor?: string
|
|
44
|
+
textAlign?: 'left' | 'center' | 'right' | 'justify'
|
|
45
|
+
lineHeight?: number
|
|
46
|
+
letterSpacing?: number
|
|
47
|
+
padding?: number | [number, number] | [number, number, number, number]
|
|
48
|
+
margin?: number | [number, number] | [number, number, number, number]
|
|
49
|
+
borderRadius?: number
|
|
50
|
+
borderWidth?: number
|
|
51
|
+
borderColor?: string
|
|
52
|
+
borderStyle?: 'solid' | 'dashed' | 'dotted'
|
|
53
|
+
width?: number | string
|
|
54
|
+
height?: number | string
|
|
55
|
+
maxWidth?: number | string
|
|
56
|
+
opacity?: number
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ─── Component Props ────────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
export interface DocumentProps {
|
|
62
|
+
title?: string
|
|
63
|
+
author?: string
|
|
64
|
+
subject?: string
|
|
65
|
+
keywords?: string[]
|
|
66
|
+
language?: string
|
|
67
|
+
children?: unknown
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type PageSize = 'A4' | 'A3' | 'A5' | 'letter' | 'legal' | 'tabloid'
|
|
71
|
+
export type PageOrientation = 'portrait' | 'landscape'
|
|
72
|
+
|
|
73
|
+
export interface PageProps {
|
|
74
|
+
size?: PageSize
|
|
75
|
+
orientation?: PageOrientation
|
|
76
|
+
margin?: number | [number, number] | [number, number, number, number]
|
|
77
|
+
children?: unknown
|
|
78
|
+
/** Header content for this page (PDF/DOCX). */
|
|
79
|
+
header?: DocNode
|
|
80
|
+
/** Footer content for this page (PDF/DOCX). */
|
|
81
|
+
footer?: DocNode
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface SectionProps {
|
|
85
|
+
direction?: 'column' | 'row'
|
|
86
|
+
gap?: number
|
|
87
|
+
padding?: number | [number, number] | [number, number, number, number]
|
|
88
|
+
background?: string
|
|
89
|
+
borderRadius?: number
|
|
90
|
+
border?: string
|
|
91
|
+
children?: unknown
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface RowProps {
|
|
95
|
+
gap?: number
|
|
96
|
+
align?: 'start' | 'center' | 'end' | 'stretch'
|
|
97
|
+
children?: unknown
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface ColumnProps {
|
|
101
|
+
width?: number | string
|
|
102
|
+
align?: 'start' | 'center' | 'end'
|
|
103
|
+
children?: unknown
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface HeadingProps {
|
|
107
|
+
level?: 1 | 2 | 3 | 4 | 5 | 6
|
|
108
|
+
color?: string
|
|
109
|
+
align?: 'left' | 'center' | 'right'
|
|
110
|
+
children?: unknown
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface TextProps {
|
|
114
|
+
size?: number
|
|
115
|
+
color?: string
|
|
116
|
+
bold?: boolean
|
|
117
|
+
italic?: boolean
|
|
118
|
+
underline?: boolean
|
|
119
|
+
strikethrough?: boolean
|
|
120
|
+
align?: 'left' | 'center' | 'right' | 'justify'
|
|
121
|
+
lineHeight?: number
|
|
122
|
+
children?: unknown
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface LinkProps {
|
|
126
|
+
href: string
|
|
127
|
+
color?: string
|
|
128
|
+
children?: unknown
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface ImageProps {
|
|
132
|
+
src: string
|
|
133
|
+
width?: number
|
|
134
|
+
height?: number
|
|
135
|
+
alt?: string
|
|
136
|
+
align?: 'left' | 'center' | 'right'
|
|
137
|
+
caption?: string
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface TableColumn {
|
|
141
|
+
header: string
|
|
142
|
+
width?: number | string
|
|
143
|
+
align?: 'left' | 'center' | 'right'
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface TableProps {
|
|
147
|
+
columns: (string | TableColumn)[]
|
|
148
|
+
rows: (string | number)[][]
|
|
149
|
+
headerStyle?: {
|
|
150
|
+
background?: string
|
|
151
|
+
color?: string
|
|
152
|
+
bold?: boolean
|
|
153
|
+
}
|
|
154
|
+
striped?: boolean
|
|
155
|
+
bordered?: boolean
|
|
156
|
+
caption?: string
|
|
157
|
+
/** Keep table together on one page — avoid page breaks within table (PDF/DOCX). */
|
|
158
|
+
keepTogether?: boolean
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface ListProps {
|
|
162
|
+
ordered?: boolean
|
|
163
|
+
children?: unknown
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface ListItemProps {
|
|
167
|
+
children?: unknown
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface CodeProps {
|
|
171
|
+
language?: string
|
|
172
|
+
children?: unknown
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface DividerProps {
|
|
176
|
+
color?: string
|
|
177
|
+
thickness?: number
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface SpacerProps {
|
|
181
|
+
height: number
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface ButtonProps {
|
|
185
|
+
href: string
|
|
186
|
+
background?: string
|
|
187
|
+
color?: string
|
|
188
|
+
borderRadius?: number
|
|
189
|
+
padding?: number | [number, number]
|
|
190
|
+
align?: 'left' | 'center' | 'right'
|
|
191
|
+
children?: unknown
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface QuoteProps {
|
|
195
|
+
borderColor?: string
|
|
196
|
+
children?: unknown
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ─── Render Types ───────────────────────────────────────────────────────────
|
|
200
|
+
|
|
201
|
+
export type OutputFormat =
|
|
202
|
+
| 'html'
|
|
203
|
+
| 'pdf'
|
|
204
|
+
| 'docx'
|
|
205
|
+
| 'pptx'
|
|
206
|
+
| 'email'
|
|
207
|
+
| 'xlsx'
|
|
208
|
+
| 'md'
|
|
209
|
+
| 'text'
|
|
210
|
+
| 'csv'
|
|
211
|
+
| 'svg'
|
|
212
|
+
| 'slack'
|
|
213
|
+
| 'teams'
|
|
214
|
+
| 'discord'
|
|
215
|
+
| 'telegram'
|
|
216
|
+
| 'notion'
|
|
217
|
+
| 'confluence'
|
|
218
|
+
| 'whatsapp'
|
|
219
|
+
| 'google-chat'
|
|
220
|
+
|
|
221
|
+
export interface RenderOptions {
|
|
222
|
+
/** Custom styles to apply (overrides component styles). */
|
|
223
|
+
styles?: Record<string, ResolvedStyles>
|
|
224
|
+
/** Base URL for relative image sources. */
|
|
225
|
+
baseUrl?: string
|
|
226
|
+
/** Text direction — 'ltr' (default) or 'rtl'. */
|
|
227
|
+
direction?: 'ltr' | 'rtl'
|
|
228
|
+
/** Custom font configuration for PDF. */
|
|
229
|
+
fonts?: Record<
|
|
230
|
+
string,
|
|
231
|
+
{ normal?: string; bold?: string; italics?: string; bolditalics?: string }
|
|
232
|
+
>
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export type RenderResult = string | Uint8Array
|
|
236
|
+
|
|
237
|
+
/** A document renderer that converts a node tree to a specific format. */
|
|
238
|
+
export interface DocumentRenderer {
|
|
239
|
+
render(node: DocNode, options?: RenderOptions): Promise<RenderResult>
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ─── Builder Types ──────────────────────────────────────────────────────────
|
|
243
|
+
|
|
244
|
+
export interface DocumentBuilder {
|
|
245
|
+
heading(text: string, props?: Omit<HeadingProps, 'children'>): DocumentBuilder
|
|
246
|
+
text(text: string, props?: Omit<TextProps, 'children'>): DocumentBuilder
|
|
247
|
+
paragraph(text: string, props?: Omit<TextProps, 'children'>): DocumentBuilder
|
|
248
|
+
image(src: string, props?: Omit<ImageProps, 'src'>): DocumentBuilder
|
|
249
|
+
table(props: TableProps): DocumentBuilder
|
|
250
|
+
list(items: string[], props?: Omit<ListProps, 'children'>): DocumentBuilder
|
|
251
|
+
code(text: string, props?: Omit<CodeProps, 'children'>): DocumentBuilder
|
|
252
|
+
divider(props?: DividerProps): DocumentBuilder
|
|
253
|
+
spacer(height: number): DocumentBuilder
|
|
254
|
+
quote(text: string, props?: Omit<QuoteProps, 'children'>): DocumentBuilder
|
|
255
|
+
button(text: string, props: Omit<ButtonProps, 'children'>): DocumentBuilder
|
|
256
|
+
link(text: string, props: Omit<LinkProps, 'children'>): DocumentBuilder
|
|
257
|
+
pageBreak(): DocumentBuilder
|
|
258
|
+
/** Add a chart snapshot from a @pyreon/charts instance. */
|
|
259
|
+
chart(
|
|
260
|
+
instance: unknown,
|
|
261
|
+
props?: { width?: number; height?: number; caption?: string },
|
|
262
|
+
): DocumentBuilder
|
|
263
|
+
/** Add a flow diagram snapshot from a @pyreon/flow instance. */
|
|
264
|
+
flow(
|
|
265
|
+
instance: unknown,
|
|
266
|
+
props?: { width?: number; height?: number; caption?: string },
|
|
267
|
+
): DocumentBuilder
|
|
268
|
+
/** Build the document node tree. */
|
|
269
|
+
build(): DocNode
|
|
270
|
+
/** Render to a specific format. */
|
|
271
|
+
toHtml(options?: RenderOptions): Promise<string>
|
|
272
|
+
toPdf(options?: RenderOptions): Promise<Uint8Array>
|
|
273
|
+
toDocx(options?: RenderOptions): Promise<Uint8Array>
|
|
274
|
+
toPptx(options?: RenderOptions): Promise<Uint8Array>
|
|
275
|
+
toEmail(options?: RenderOptions): Promise<string>
|
|
276
|
+
toXlsx(options?: RenderOptions): Promise<Uint8Array>
|
|
277
|
+
toMarkdown(options?: RenderOptions): Promise<string>
|
|
278
|
+
toText(options?: RenderOptions): Promise<string>
|
|
279
|
+
toCsv(options?: RenderOptions): Promise<string>
|
|
280
|
+
toSlack(options?: RenderOptions): Promise<string>
|
|
281
|
+
toSvg(options?: RenderOptions): Promise<string>
|
|
282
|
+
toTeams(options?: RenderOptions): Promise<string>
|
|
283
|
+
toDiscord(options?: RenderOptions): Promise<string>
|
|
284
|
+
toTelegram(options?: RenderOptions): Promise<string>
|
|
285
|
+
toNotion(options?: RenderOptions): Promise<string>
|
|
286
|
+
toConfluence(options?: RenderOptions): Promise<string>
|
|
287
|
+
toWhatsApp(options?: RenderOptions): Promise<string>
|
|
288
|
+
toGoogleChat(options?: RenderOptions): Promise<string>
|
|
289
|
+
/** Download the document (browser only). */
|
|
290
|
+
download(filename: string, options?: RenderOptions): Promise<void>
|
|
291
|
+
}
|