@pyreon/document-primitives 0.11.0 → 0.11.2
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/package.json +22 -20
- package/src/DocumentPreview.ts +50 -0
- package/src/__tests__/primitives-attrs.test.ts +566 -0
- package/src/__tests__/primitives.test.ts +104 -0
- package/src/__tests__/useDocumentExport.test.ts +92 -0
- package/src/index.ts +37 -0
- package/src/primitives/DocButton.ts +37 -0
- package/src/primitives/DocCode.ts +18 -0
- package/src/primitives/DocColumn.ts +13 -0
- package/src/primitives/DocDivider.ts +23 -0
- package/src/primitives/DocDocument.ts +21 -0
- package/src/primitives/DocHeading.ts +33 -0
- package/src/primitives/DocImage.ts +25 -0
- package/src/primitives/DocLink.ts +15 -0
- package/src/primitives/DocList.ts +15 -0
- package/src/primitives/DocListItem.ts +15 -0
- package/src/primitives/DocPage.ts +23 -0
- package/src/primitives/DocPageBreak.ts +11 -0
- package/src/primitives/DocQuote.ts +19 -0
- package/src/primitives/DocRow.ts +14 -0
- package/src/primitives/DocSection.ts +23 -0
- package/src/primitives/DocSpacer.ts +11 -0
- package/src/primitives/DocTable.ts +36 -0
- package/src/primitives/DocText.ts +35 -0
- package/src/theme.ts +37 -0
- package/src/useDocumentExport.ts +47 -0
package/src/theme.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const documentTheme = {
|
|
2
|
+
colors: {
|
|
3
|
+
primary: "#4f46e5",
|
|
4
|
+
text: "#333333",
|
|
5
|
+
textSecondary: "#666666",
|
|
6
|
+
background: "#ffffff",
|
|
7
|
+
border: "#dddddd",
|
|
8
|
+
headerBg: "#1a1a2e",
|
|
9
|
+
headerText: "#ffffff",
|
|
10
|
+
stripedRow: "#f9f9f9",
|
|
11
|
+
},
|
|
12
|
+
fonts: {
|
|
13
|
+
heading: "system-ui, -apple-system, sans-serif",
|
|
14
|
+
body: "system-ui, -apple-system, sans-serif",
|
|
15
|
+
mono: "ui-monospace, monospace",
|
|
16
|
+
},
|
|
17
|
+
sizes: {
|
|
18
|
+
h1: 32,
|
|
19
|
+
h2: 24,
|
|
20
|
+
h3: 20,
|
|
21
|
+
h4: 18,
|
|
22
|
+
h5: 16,
|
|
23
|
+
h6: 14,
|
|
24
|
+
body: 14,
|
|
25
|
+
caption: 12,
|
|
26
|
+
label: 11,
|
|
27
|
+
},
|
|
28
|
+
spacing: {
|
|
29
|
+
xs: 4,
|
|
30
|
+
sm: 8,
|
|
31
|
+
md: 16,
|
|
32
|
+
lg: 24,
|
|
33
|
+
xl: 40,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type DocumentTheme = typeof documentTheme
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DocNode, ExtractOptions } from "@pyreon/connector-document"
|
|
2
|
+
import { extractDocumentTree } from "@pyreon/connector-document"
|
|
3
|
+
|
|
4
|
+
export interface DocumentExportOptions extends ExtractOptions {
|
|
5
|
+
/** Theme object to provide during extraction. */
|
|
6
|
+
theme?: Record<string, unknown>
|
|
7
|
+
/** Mode: 'light' or 'dark'. */
|
|
8
|
+
mode?: "light" | "dark"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface DocumentExport {
|
|
12
|
+
/** Extract the DocNode tree from the template. */
|
|
13
|
+
getDocNode: () => DocNode
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create a document export helper from a template function.
|
|
18
|
+
*
|
|
19
|
+
* The template function should return a VNode tree built with
|
|
20
|
+
* document primitives (DocHeading, DocText, DocTable, etc.).
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* const doc = createDocumentExport(() =>
|
|
24
|
+
* DocDocument({ title: 'Report', children: [
|
|
25
|
+
* DocHeading({ h1: true, children: 'Sales Report' }),
|
|
26
|
+
* DocText({ children: 'Q4 summary.' }),
|
|
27
|
+
* ]})
|
|
28
|
+
* )
|
|
29
|
+
*
|
|
30
|
+
* const tree = doc.getDocNode()
|
|
31
|
+
* // Pass to @pyreon/document's render() for any format
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* When @pyreon/document is published, this will also expose
|
|
35
|
+
* convenience methods like toPdf(), toDocx(), download(), etc.
|
|
36
|
+
*/
|
|
37
|
+
export function createDocumentExport(
|
|
38
|
+
templateFn: () => unknown,
|
|
39
|
+
options: DocumentExportOptions = {},
|
|
40
|
+
): DocumentExport {
|
|
41
|
+
const getDocNode = (): DocNode => {
|
|
42
|
+
const vnode = templateFn()
|
|
43
|
+
return extractDocumentTree(vnode, options)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { getDocNode }
|
|
47
|
+
}
|