@pyreon/document-primitives 0.3.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.
Files changed (3) hide show
  1. package/lib/index.d.ts +1039 -0
  2. package/lib/index.js +447 -0
  3. package/package.json +63 -0
package/lib/index.js ADDED
@@ -0,0 +1,447 @@
1
+ import { extractDocumentTree, extractDocumentTree as extractDocumentTree$1, resolveStyles } from "@pyreon/connector-document";
2
+ import { Element, Text } from "@pyreon/elements";
3
+ import rocketstyle from "@pyreon/rocketstyle";
4
+
5
+ //#region src/DocumentPreview.ts
6
+ const DocumentPreview = rocketstyle({
7
+ dimensions: { sizes: "size" },
8
+ useBooleans: true
9
+ })({
10
+ name: "DocumentPreview",
11
+ component: Element
12
+ }).theme({
13
+ backgroundColor: "#f5f5f5",
14
+ padding: 40
15
+ }).sizes({
16
+ A4: {
17
+ width: "210mm",
18
+ minHeight: "297mm"
19
+ },
20
+ A3: {
21
+ width: "297mm",
22
+ minHeight: "420mm"
23
+ },
24
+ A5: {
25
+ width: "148mm",
26
+ minHeight: "210mm"
27
+ },
28
+ letter: {
29
+ width: "8.5in",
30
+ minHeight: "11in"
31
+ },
32
+ legal: {
33
+ width: "8.5in",
34
+ minHeight: "14in"
35
+ }
36
+ }).styles((css) => css`
37
+ display: flex;
38
+ flex-direction: column;
39
+ align-items: center;
40
+ min-height: 100vh;
41
+
42
+ & > * {
43
+ background: white;
44
+ padding: 25mm;
45
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
46
+ margin: 20px 0;
47
+ }
48
+ `).statics({ _documentType: "document" }).attrs((props) => ({
49
+ tag: "div",
50
+ _documentProps: {
51
+ ...props.size ? { size: props.size } : { size: "A4" },
52
+ ...props.showPageBreaks ? { showPageBreaks: props.showPageBreaks } : {}
53
+ }
54
+ }));
55
+
56
+ //#endregion
57
+ //#region src/primitives/DocButton.ts
58
+ const DocButton = rocketstyle({
59
+ dimensions: { variants: "variant" },
60
+ useBooleans: true
61
+ })({
62
+ name: "DocButton",
63
+ component: Text
64
+ }).theme({
65
+ fontSize: 14,
66
+ fontWeight: "bold",
67
+ padding: "10px 24px",
68
+ borderRadius: 4,
69
+ textAlign: "center",
70
+ textDecoration: "none"
71
+ }).variants({
72
+ primary: {
73
+ backgroundColor: "#4f46e5",
74
+ color: "#ffffff"
75
+ },
76
+ secondary: {
77
+ backgroundColor: "#ffffff",
78
+ color: "#4f46e5",
79
+ borderWidth: 1,
80
+ borderColor: "#4f46e5",
81
+ borderStyle: "solid"
82
+ }
83
+ }).statics({ _documentType: "button" }).attrs((props) => ({
84
+ tag: "a",
85
+ _documentProps: { href: props.href ?? "#" }
86
+ }));
87
+
88
+ //#endregion
89
+ //#region src/primitives/DocCode.ts
90
+ const DocCode = rocketstyle()({
91
+ name: "DocCode",
92
+ component: Text
93
+ }).theme({
94
+ fontFamily: "ui-monospace, monospace",
95
+ fontSize: 13,
96
+ backgroundColor: "#f5f5f5",
97
+ padding: "8px 12px",
98
+ borderRadius: 4
99
+ }).statics({ _documentType: "code" }).attrs((props) => ({
100
+ tag: "pre",
101
+ _documentProps: props.language ? { language: props.language } : {}
102
+ }));
103
+
104
+ //#endregion
105
+ //#region src/primitives/DocColumn.ts
106
+ const DocColumn = rocketstyle()({
107
+ name: "DocColumn",
108
+ component: Element
109
+ }).statics({ _documentType: "column" }).attrs((props) => ({
110
+ tag: "div",
111
+ _documentProps: props.width != null ? { width: props.width } : {}
112
+ }));
113
+
114
+ //#endregion
115
+ //#region src/primitives/DocDivider.ts
116
+ const DocDivider = rocketstyle()({
117
+ name: "DocDivider",
118
+ component: Element
119
+ }).theme({
120
+ borderColor: "#dddddd",
121
+ borderWidth: 1
122
+ }).statics({ _documentType: "divider" }).attrs((props) => ({
123
+ tag: "hr",
124
+ _documentProps: {
125
+ ...props.color ? { color: props.color } : {},
126
+ ...props.thickness ? { thickness: props.thickness } : {}
127
+ }
128
+ }));
129
+
130
+ //#endregion
131
+ //#region src/primitives/DocDocument.ts
132
+ const DocDocument = rocketstyle()({
133
+ name: "DocDocument",
134
+ component: Element
135
+ }).statics({ _documentType: "document" }).attrs((props) => ({
136
+ tag: "div",
137
+ _documentProps: {
138
+ ...props.title ? { title: props.title } : {},
139
+ ...props.author ? { author: props.author } : {},
140
+ ...props.subject ? { subject: props.subject } : {}
141
+ }
142
+ }));
143
+
144
+ //#endregion
145
+ //#region src/primitives/DocHeading.ts
146
+ const DocHeading = rocketstyle({
147
+ dimensions: { levels: "level" },
148
+ useBooleans: true
149
+ })({
150
+ name: "DocHeading",
151
+ component: Text
152
+ }).theme({
153
+ fontWeight: "bold",
154
+ color: "#1a1a2e",
155
+ marginBottom: 12
156
+ }).levels({
157
+ h1: {
158
+ fontSize: 32,
159
+ lineHeight: 1.2
160
+ },
161
+ h2: {
162
+ fontSize: 24,
163
+ lineHeight: 1.3
164
+ },
165
+ h3: {
166
+ fontSize: 20,
167
+ lineHeight: 1.4
168
+ },
169
+ h4: {
170
+ fontSize: 18,
171
+ lineHeight: 1.4
172
+ },
173
+ h5: {
174
+ fontSize: 16,
175
+ lineHeight: 1.5
176
+ },
177
+ h6: {
178
+ fontSize: 14,
179
+ lineHeight: 1.5
180
+ }
181
+ }).statics({ _documentType: "heading" }).attrs((props) => {
182
+ const lvl = props.level ?? "h1";
183
+ return {
184
+ tag: lvl,
185
+ _documentProps: { level: Number.parseInt(String(lvl).replace("h", ""), 10) || 1 }
186
+ };
187
+ });
188
+
189
+ //#endregion
190
+ //#region src/primitives/DocImage.ts
191
+ const DocImage = rocketstyle()({
192
+ name: "DocImage",
193
+ component: Element
194
+ }).statics({ _documentType: "image" }).attrs((props) => ({
195
+ tag: "img",
196
+ _documentProps: {
197
+ src: props.src ?? "",
198
+ ...props.alt ? { alt: props.alt } : {},
199
+ ...props.width ? { width: props.width } : {},
200
+ ...props.height ? { height: props.height } : {},
201
+ ...props.caption ? { caption: props.caption } : {}
202
+ }
203
+ }));
204
+
205
+ //#endregion
206
+ //#region src/primitives/DocLink.ts
207
+ const DocLink = rocketstyle()({
208
+ name: "DocLink",
209
+ component: Text
210
+ }).theme({
211
+ color: "#4f46e5",
212
+ textDecoration: "underline"
213
+ }).statics({ _documentType: "link" }).attrs((props) => ({
214
+ tag: "a",
215
+ _documentProps: { href: props.href ?? "#" }
216
+ }));
217
+
218
+ //#endregion
219
+ //#region src/primitives/DocList.ts
220
+ const DocList = rocketstyle()({
221
+ name: "DocList",
222
+ component: Element
223
+ }).theme({
224
+ marginBottom: 8,
225
+ paddingLeft: 20
226
+ }).statics({ _documentType: "list" }).attrs((props) => ({
227
+ tag: props.ordered ? "ol" : "ul",
228
+ _documentProps: props.ordered ? { ordered: props.ordered } : {}
229
+ }));
230
+
231
+ //#endregion
232
+ //#region src/primitives/DocListItem.ts
233
+ const DocListItem = rocketstyle()({
234
+ name: "DocListItem",
235
+ component: Text
236
+ }).theme({
237
+ fontSize: 14,
238
+ lineHeight: 1.5
239
+ }).statics({ _documentType: "list-item" }).attrs((_props) => ({
240
+ tag: "li",
241
+ _documentProps: {}
242
+ }));
243
+
244
+ //#endregion
245
+ //#region src/primitives/DocPage.ts
246
+ const DocPage = rocketstyle()({
247
+ name: "DocPage",
248
+ component: Element
249
+ }).theme({
250
+ backgroundColor: "#ffffff",
251
+ padding: "25mm"
252
+ }).statics({ _documentType: "page" }).attrs((props) => ({
253
+ tag: "div",
254
+ _documentProps: {
255
+ ...props.size ? { size: props.size } : {},
256
+ ...props.orientation ? { orientation: props.orientation } : {}
257
+ }
258
+ }));
259
+
260
+ //#endregion
261
+ //#region src/primitives/DocPageBreak.ts
262
+ const DocPageBreak = rocketstyle()({
263
+ name: "DocPageBreak",
264
+ component: Element
265
+ }).statics({ _documentType: "page-break" }).attrs((_props) => ({
266
+ tag: "div",
267
+ _documentProps: {}
268
+ }));
269
+
270
+ //#endregion
271
+ //#region src/primitives/DocQuote.ts
272
+ const DocQuote = rocketstyle()({
273
+ name: "DocQuote",
274
+ component: Element
275
+ }).theme({
276
+ borderColor: "#4f46e5",
277
+ padding: "8px 16px",
278
+ fontStyle: "italic",
279
+ color: "#666666"
280
+ }).statics({ _documentType: "quote" }).attrs((props) => ({
281
+ tag: "blockquote",
282
+ _documentProps: props.borderColor ? { borderColor: props.borderColor } : {}
283
+ }));
284
+
285
+ //#endregion
286
+ //#region src/primitives/DocRow.ts
287
+ const DocRow = rocketstyle()({
288
+ name: "DocRow",
289
+ component: Element
290
+ }).theme({ direction: "row" }).statics({ _documentType: "row" }).attrs((_props) => ({
291
+ tag: "div",
292
+ _documentProps: {}
293
+ }));
294
+
295
+ //#endregion
296
+ //#region src/primitives/DocSection.ts
297
+ const DocSection = rocketstyle({
298
+ dimensions: { directions: "direction" },
299
+ useBooleans: false
300
+ })({
301
+ name: "DocSection",
302
+ component: Element
303
+ }).theme({ padding: 0 }).directions({
304
+ column: {},
305
+ row: { direction: "row" }
306
+ }).statics({ _documentType: "section" }).attrs((props) => ({
307
+ tag: "div",
308
+ _documentProps: { direction: props.direction ?? "column" }
309
+ }));
310
+
311
+ //#endregion
312
+ //#region src/primitives/DocSpacer.ts
313
+ const DocSpacer = rocketstyle()({
314
+ name: "DocSpacer",
315
+ component: Element
316
+ }).statics({ _documentType: "spacer" }).attrs((props) => ({
317
+ tag: "div",
318
+ _documentProps: { height: props.height ?? 16 }
319
+ }));
320
+
321
+ //#endregion
322
+ //#region src/primitives/DocTable.ts
323
+ const DocTable = rocketstyle({
324
+ dimensions: { variants: "variant" },
325
+ useBooleans: true
326
+ })({
327
+ name: "DocTable",
328
+ component: Element
329
+ }).theme({
330
+ fontSize: 14,
331
+ borderColor: "#dddddd"
332
+ }).statics({ _documentType: "table" }).attrs((props) => ({
333
+ tag: "table",
334
+ _documentProps: {
335
+ columns: props.columns ?? [],
336
+ rows: props.rows ?? [],
337
+ ...props.headerStyle ? { headerStyle: props.headerStyle } : {},
338
+ ...props.striped ? { striped: props.striped } : {},
339
+ ...props.bordered ? { bordered: props.bordered } : {},
340
+ ...props.caption ? { caption: props.caption } : {}
341
+ }
342
+ }));
343
+
344
+ //#endregion
345
+ //#region src/primitives/DocText.ts
346
+ const DocText = rocketstyle({
347
+ dimensions: {
348
+ variants: "variant",
349
+ weights: "weight"
350
+ },
351
+ useBooleans: true
352
+ })({
353
+ name: "DocText",
354
+ component: Text
355
+ }).theme({
356
+ color: "#333333",
357
+ lineHeight: 1.5,
358
+ marginBottom: 8
359
+ }).variants({
360
+ body: { fontSize: 14 },
361
+ caption: {
362
+ fontSize: 12,
363
+ color: "#666666"
364
+ },
365
+ label: {
366
+ fontSize: 11,
367
+ fontWeight: "bold"
368
+ }
369
+ }).weights({
370
+ normal: { fontWeight: "normal" },
371
+ bold: { fontWeight: "bold" }
372
+ }).statics({ _documentType: "text" }).attrs((_props) => ({
373
+ tag: "p",
374
+ _documentProps: {}
375
+ }));
376
+
377
+ //#endregion
378
+ //#region src/theme.ts
379
+ const documentTheme = {
380
+ colors: {
381
+ primary: "#4f46e5",
382
+ text: "#333333",
383
+ textSecondary: "#666666",
384
+ background: "#ffffff",
385
+ border: "#dddddd",
386
+ headerBg: "#1a1a2e",
387
+ headerText: "#ffffff",
388
+ stripedRow: "#f9f9f9"
389
+ },
390
+ fonts: {
391
+ heading: "system-ui, -apple-system, sans-serif",
392
+ body: "system-ui, -apple-system, sans-serif",
393
+ mono: "ui-monospace, monospace"
394
+ },
395
+ sizes: {
396
+ h1: 32,
397
+ h2: 24,
398
+ h3: 20,
399
+ h4: 18,
400
+ h5: 16,
401
+ h6: 14,
402
+ body: 14,
403
+ caption: 12,
404
+ label: 11
405
+ },
406
+ spacing: {
407
+ xs: 4,
408
+ sm: 8,
409
+ md: 16,
410
+ lg: 24,
411
+ xl: 40
412
+ }
413
+ };
414
+
415
+ //#endregion
416
+ //#region src/useDocumentExport.ts
417
+ /**
418
+ * Create a document export helper from a template function.
419
+ *
420
+ * The template function should return a VNode tree built with
421
+ * document primitives (DocHeading, DocText, DocTable, etc.).
422
+ *
423
+ * ```ts
424
+ * const doc = createDocumentExport(() =>
425
+ * DocDocument({ title: 'Report', children: [
426
+ * DocHeading({ h1: true, children: 'Sales Report' }),
427
+ * DocText({ children: 'Q4 summary.' }),
428
+ * ]})
429
+ * )
430
+ *
431
+ * const tree = doc.getDocNode()
432
+ * // Pass to @pyreon/document's render() for any format
433
+ * ```
434
+ *
435
+ * When @pyreon/document is published, this will also expose
436
+ * convenience methods like toPdf(), toDocx(), download(), etc.
437
+ */
438
+ function createDocumentExport(templateFn, options = {}) {
439
+ const getDocNode = () => {
440
+ return extractDocumentTree$1(templateFn(), options);
441
+ };
442
+ return { getDocNode };
443
+ }
444
+
445
+ //#endregion
446
+ export { DocButton, DocCode, DocColumn, DocDivider, DocDocument, DocHeading, DocImage, DocLink, DocList, DocListItem, DocPage, DocPageBreak, DocQuote, DocRow, DocSection, DocSpacer, DocTable, DocText, DocumentPreview, createDocumentExport, documentTheme, extractDocumentTree, resolveStyles };
447
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@pyreon/document-primitives",
3
+ "version": "0.3.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/pyreon/ui-system",
7
+ "directory": "packages/document-primitives"
8
+ },
9
+ "description": "Rocketstyle document components — render in browser, export to 18 formats",
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "sideEffects": false,
13
+ "exports": {
14
+ "source": "./src/index.ts",
15
+ "import": "./lib/index.js",
16
+ "types": "./lib/index.d.ts"
17
+ },
18
+ "types": "./lib/index.d.ts",
19
+ "main": "./lib/index.js",
20
+ "files": [
21
+ "lib",
22
+ "!lib/**/*.map",
23
+ "!lib/analysis",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "engines": {
28
+ "node": ">= 18"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "prepublish": "bun run build",
35
+ "build": "bun run vl_rolldown_build",
36
+ "build:watch": "bun run vl_rolldown_build-watch",
37
+ "lint": "biome check src/",
38
+ "test": "vitest run",
39
+ "test:coverage": "vitest run --coverage",
40
+ "test:watch": "vitest",
41
+ "typecheck": "tsc --noEmit"
42
+ },
43
+ "peerDependencies": {
44
+ "@pyreon/core": ">=0.7.0",
45
+ "@pyreon/document": ">=0.10.0",
46
+ "@pyreon/elements": ">=0.3.0",
47
+ "@pyreon/rocketstyle": ">=0.3.0",
48
+ "@pyreon/styler": ">=0.3.0",
49
+ "@pyreon/ui-core": ">=0.3.0"
50
+ },
51
+ "dependencies": {
52
+ "@pyreon/connector-document": "workspace:*"
53
+ },
54
+ "devDependencies": {
55
+ "@pyreon/core": "^0.7.0",
56
+ "@pyreon/elements": "workspace:*",
57
+ "@pyreon/rocketstyle": "workspace:*",
58
+ "@pyreon/styler": "workspace:*",
59
+ "@pyreon/ui-core": "workspace:*",
60
+ "@vitus-labs/tools-rolldown": "^1.15.4",
61
+ "@pyreon/typescript": "^0.7.4"
62
+ }
63
+ }