@pyreon/document-primitives 0.24.5 → 0.24.6
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/lib/index.d.ts +6 -6
- package/package.json +17 -19
- package/src/DocumentPreview.ts +0 -48
- package/src/__tests__/document-primitives.browser.test.ts +0 -253
- package/src/__tests__/manifest-snapshot.test.ts +0 -45
- package/src/__tests__/primitives-attrs.test.ts +0 -517
- package/src/__tests__/primitives.test.ts +0 -104
- package/src/__tests__/reactivity.test.ts +0 -415
- package/src/__tests__/useDocumentExport.test.ts +0 -366
- package/src/index.ts +0 -37
- package/src/manifest.ts +0 -388
- package/src/primitives/DocButton.ts +0 -37
- package/src/primitives/DocCode.ts +0 -18
- package/src/primitives/DocColumn.ts +0 -11
- package/src/primitives/DocDivider.ts +0 -21
- package/src/primitives/DocDocument.ts +0 -69
- package/src/primitives/DocHeading.ts +0 -33
- package/src/primitives/DocImage.ts +0 -23
- package/src/primitives/DocLink.ts +0 -15
- package/src/primitives/DocList.ts +0 -15
- package/src/primitives/DocListItem.ts +0 -15
- package/src/primitives/DocPage.ts +0 -21
- package/src/primitives/DocPageBreak.ts +0 -11
- package/src/primitives/DocQuote.ts +0 -17
- package/src/primitives/DocRow.ts +0 -19
- package/src/primitives/DocSection.ts +0 -23
- package/src/primitives/DocSpacer.ts +0 -11
- package/src/primitives/DocTable.ts +0 -57
- package/src/primitives/DocText.ts +0 -31
- package/src/theme.ts +0 -37
- package/src/useDocumentExport.ts +0 -84
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Element } from '@pyreon/elements'
|
|
2
|
-
import rocketstyle from '@pyreon/rocketstyle'
|
|
3
|
-
|
|
4
|
-
const DocPage = rocketstyle()({ name: 'DocPage', component: Element })
|
|
5
|
-
.theme({
|
|
6
|
-
backgroundColor: '#ffffff',
|
|
7
|
-
padding: '25mm',
|
|
8
|
-
})
|
|
9
|
-
.statics({ _documentType: 'page' as const })
|
|
10
|
-
.attrs<{
|
|
11
|
-
size?: string
|
|
12
|
-
orientation?: string
|
|
13
|
-
}>((props) => ({
|
|
14
|
-
tag: 'div',
|
|
15
|
-
_documentProps: {
|
|
16
|
-
...(props.size ? { size: props.size } : {}),
|
|
17
|
-
...(props.orientation ? { orientation: props.orientation } : {}),
|
|
18
|
-
},
|
|
19
|
-
}))
|
|
20
|
-
|
|
21
|
-
export default DocPage
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Element } from '@pyreon/elements'
|
|
2
|
-
import rocketstyle from '@pyreon/rocketstyle'
|
|
3
|
-
|
|
4
|
-
const DocPageBreak = rocketstyle()({ name: 'DocPageBreak', component: Element })
|
|
5
|
-
.statics({ _documentType: 'page-break' as const })
|
|
6
|
-
.attrs(() => ({
|
|
7
|
-
tag: 'div',
|
|
8
|
-
_documentProps: {},
|
|
9
|
-
}))
|
|
10
|
-
|
|
11
|
-
export default DocPageBreak
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Element } from '@pyreon/elements'
|
|
2
|
-
import rocketstyle from '@pyreon/rocketstyle'
|
|
3
|
-
|
|
4
|
-
const DocQuote = rocketstyle()({ name: 'DocQuote', component: Element })
|
|
5
|
-
.theme({
|
|
6
|
-
borderColor: '#4f46e5',
|
|
7
|
-
padding: '8px 16px',
|
|
8
|
-
fontStyle: 'italic',
|
|
9
|
-
color: '#666666',
|
|
10
|
-
})
|
|
11
|
-
.statics({ _documentType: 'quote' as const })
|
|
12
|
-
.attrs<{ borderColor?: string }>((props) => ({
|
|
13
|
-
tag: 'blockquote',
|
|
14
|
-
_documentProps: props.borderColor ? { borderColor: props.borderColor } : {},
|
|
15
|
-
}))
|
|
16
|
-
|
|
17
|
-
export default DocQuote
|
package/src/primitives/DocRow.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Element } from '@pyreon/elements'
|
|
2
|
-
import rocketstyle from '@pyreon/rocketstyle'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Horizontal row of inline children. Per project conventions, layout
|
|
6
|
-
* props (`direction`, `gap`) live in `.attrs()`, not `.theme()`. The
|
|
7
|
-
* Element base accepts `direction: 'inline' | 'rows' | 'reverseInline'
|
|
8
|
-
* | 'reverseRows'` — `'row'` is not a valid value.
|
|
9
|
-
*/
|
|
10
|
-
const DocRow = rocketstyle()({ name: 'DocRow', component: Element })
|
|
11
|
-
.statics({ _documentType: 'row' as const })
|
|
12
|
-
.attrs(() => ({
|
|
13
|
-
tag: 'div',
|
|
14
|
-
direction: 'inline' as const,
|
|
15
|
-
gap: 8,
|
|
16
|
-
_documentProps: {},
|
|
17
|
-
}))
|
|
18
|
-
|
|
19
|
-
export default DocRow
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Element } from '@pyreon/elements'
|
|
2
|
-
import rocketstyle from '@pyreon/rocketstyle'
|
|
3
|
-
|
|
4
|
-
const DocSection = rocketstyle({
|
|
5
|
-
dimensions: {
|
|
6
|
-
directions: 'direction',
|
|
7
|
-
},
|
|
8
|
-
useBooleans: false,
|
|
9
|
-
})({ name: 'DocSection', component: Element })
|
|
10
|
-
.theme({
|
|
11
|
-
padding: 0,
|
|
12
|
-
})
|
|
13
|
-
.directions({
|
|
14
|
-
column: {},
|
|
15
|
-
row: { direction: 'row' },
|
|
16
|
-
})
|
|
17
|
-
.statics({ _documentType: 'section' as const })
|
|
18
|
-
.attrs<{ direction?: string }>((props) => ({
|
|
19
|
-
tag: 'div',
|
|
20
|
-
_documentProps: { direction: props.direction ?? 'column' },
|
|
21
|
-
}))
|
|
22
|
-
|
|
23
|
-
export default DocSection
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Element } from '@pyreon/elements'
|
|
2
|
-
import rocketstyle from '@pyreon/rocketstyle'
|
|
3
|
-
|
|
4
|
-
const DocSpacer = rocketstyle()({ name: 'DocSpacer', component: Element })
|
|
5
|
-
.statics({ _documentType: 'spacer' as const })
|
|
6
|
-
.attrs<{ height?: number }>((props) => ({
|
|
7
|
-
tag: 'div',
|
|
8
|
-
_documentProps: { height: props.height ?? 16 },
|
|
9
|
-
}))
|
|
10
|
-
|
|
11
|
-
export default DocSpacer
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Element } from '@pyreon/elements'
|
|
2
|
-
import rocketstyle from '@pyreon/rocketstyle'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Tabular data primitive.
|
|
6
|
-
*
|
|
7
|
-
* The `columns`, `rows`, `headerStyle`, `striped`, `bordered`, and
|
|
8
|
-
* `caption` props are document-export metadata — they belong in
|
|
9
|
-
* `_documentProps` only and must NOT be forwarded to the rendered
|
|
10
|
-
* `<table>` element. The `filter` option on `.attrs()` strips them
|
|
11
|
-
* from the props that flow into the DOM.
|
|
12
|
-
*
|
|
13
|
-
* Why this matters: HTMLTableElement's `rows` property is a
|
|
14
|
-
* read-only `HTMLCollection` of `<tr>` elements. If `rows` were
|
|
15
|
-
* forwarded as a DOM attr, the runtime would call
|
|
16
|
-
* `el.rows = [...]` and crash with
|
|
17
|
-
* `TypeError: Cannot set property rows of [object Object] which has
|
|
18
|
-
* only a getter`. Same family for `columns` (`HTMLTableColElement`'s
|
|
19
|
-
* column collection on parent table). Filtering them at the
|
|
20
|
-
* rocketstyle layer keeps the DOM render path clean.
|
|
21
|
-
*/
|
|
22
|
-
const DocTable = rocketstyle({
|
|
23
|
-
dimensions: {
|
|
24
|
-
variants: 'variant',
|
|
25
|
-
},
|
|
26
|
-
useBooleans: true,
|
|
27
|
-
})({ name: 'DocTable', component: Element })
|
|
28
|
-
.theme({
|
|
29
|
-
fontSize: 14,
|
|
30
|
-
borderColor: '#dddddd',
|
|
31
|
-
})
|
|
32
|
-
.statics({ _documentType: 'table' as const })
|
|
33
|
-
.attrs<{
|
|
34
|
-
columns?: unknown[]
|
|
35
|
-
rows?: unknown[]
|
|
36
|
-
headerStyle?: Record<string, unknown>
|
|
37
|
-
striped?: boolean
|
|
38
|
-
bordered?: boolean
|
|
39
|
-
caption?: string
|
|
40
|
-
}>(
|
|
41
|
-
(props) => ({
|
|
42
|
-
tag: 'table',
|
|
43
|
-
_documentProps: {
|
|
44
|
-
columns: props.columns ?? [],
|
|
45
|
-
rows: props.rows ?? [],
|
|
46
|
-
...(props.headerStyle ? { headerStyle: props.headerStyle } : {}),
|
|
47
|
-
...(props.striped ? { striped: props.striped } : {}),
|
|
48
|
-
...(props.bordered ? { bordered: props.bordered } : {}),
|
|
49
|
-
...(props.caption ? { caption: props.caption } : {}),
|
|
50
|
-
},
|
|
51
|
-
}),
|
|
52
|
-
{
|
|
53
|
-
filter: ['columns', 'rows', 'headerStyle', 'striped', 'bordered', 'caption'],
|
|
54
|
-
},
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
export default DocTable
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Text } from '@pyreon/elements'
|
|
2
|
-
import rocketstyle from '@pyreon/rocketstyle'
|
|
3
|
-
|
|
4
|
-
const DocText = rocketstyle({
|
|
5
|
-
dimensions: {
|
|
6
|
-
variants: 'variant',
|
|
7
|
-
weights: 'weight',
|
|
8
|
-
},
|
|
9
|
-
useBooleans: true,
|
|
10
|
-
})({ name: 'DocText', component: Text })
|
|
11
|
-
.theme({
|
|
12
|
-
color: '#333333',
|
|
13
|
-
lineHeight: 1.5,
|
|
14
|
-
marginBottom: 8,
|
|
15
|
-
})
|
|
16
|
-
.variants({
|
|
17
|
-
body: { fontSize: 14 },
|
|
18
|
-
caption: { fontSize: 12, color: '#666666' },
|
|
19
|
-
label: { fontSize: 11, fontWeight: 'bold' },
|
|
20
|
-
})
|
|
21
|
-
.weights({
|
|
22
|
-
normal: { fontWeight: 'normal' },
|
|
23
|
-
bold: { fontWeight: 'bold' },
|
|
24
|
-
})
|
|
25
|
-
.statics({ _documentType: 'text' as const })
|
|
26
|
-
.attrs(() => ({
|
|
27
|
-
tag: 'p',
|
|
28
|
-
_documentProps: {},
|
|
29
|
-
}))
|
|
30
|
-
|
|
31
|
-
export default DocText
|
package/src/theme.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
package/src/useDocumentExport.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
* One-step helper: extract a DocNode tree from a template function.
|
|
18
|
-
*
|
|
19
|
-
* Equivalent to `createDocumentExport(templateFn).getDocNode()` but
|
|
20
|
-
* without the wrapper-object indirection. Use this when you just
|
|
21
|
-
* need the tree to feed into `@pyreon/document`'s `render()` or
|
|
22
|
-
* `download()` — which is the only thing the wrapper object was
|
|
23
|
-
* ever used for in practice.
|
|
24
|
-
*
|
|
25
|
-
* ```ts
|
|
26
|
-
* import { extractDocNode } from '@pyreon/document-primitives'
|
|
27
|
-
* import { download } from '@pyreon/document'
|
|
28
|
-
*
|
|
29
|
-
* function ResumeTemplate({ resume }: { resume: () => Resume }) {
|
|
30
|
-
* return (
|
|
31
|
-
* <DocDocument title={() => `${resume().name} — Resume`}>
|
|
32
|
-
* <DocPage>...</DocPage>
|
|
33
|
-
* </DocDocument>
|
|
34
|
-
* )
|
|
35
|
-
* }
|
|
36
|
-
*
|
|
37
|
-
* // Export click handler:
|
|
38
|
-
* const tree = extractDocNode(() => <ResumeTemplate resume={store.resume} />)
|
|
39
|
-
* await download(tree, 'resume.pdf')
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* The two-step `createDocumentExport` form is still exported for
|
|
43
|
-
* backward compatibility and for callers that want to pass the
|
|
44
|
-
* helper object around (e.g. to wrapper components that take a
|
|
45
|
-
* `DocumentExport` instance). New code should prefer this one-step
|
|
46
|
-
* form unless you specifically need the helper object.
|
|
47
|
-
*/
|
|
48
|
-
export function extractDocNode(
|
|
49
|
-
templateFn: () => unknown,
|
|
50
|
-
options: DocumentExportOptions = {},
|
|
51
|
-
): DocNode {
|
|
52
|
-
return extractDocumentTree(templateFn(), options)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Create a document export helper from a template function.
|
|
57
|
-
*
|
|
58
|
-
* The template function should return a VNode tree built with
|
|
59
|
-
* document primitives (DocHeading, DocText, DocTable, etc.).
|
|
60
|
-
*
|
|
61
|
-
* ```ts
|
|
62
|
-
* const doc = createDocumentExport(() =>
|
|
63
|
-
* DocDocument({ title: 'Report', children: [
|
|
64
|
-
* DocHeading({ h1: true, children: 'Sales Report' }),
|
|
65
|
-
* DocText({ children: 'Q4 summary.' }),
|
|
66
|
-
* ]})
|
|
67
|
-
* )
|
|
68
|
-
*
|
|
69
|
-
* const tree = doc.getDocNode()
|
|
70
|
-
* // Pass to @pyreon/document's render() for any format
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* **Most consumers should use `extractDocNode(templateFn)` instead**
|
|
74
|
-
* — it's the same operation in one call without the wrapper
|
|
75
|
-
* object. `createDocumentExport` is kept for callers that want to
|
|
76
|
-
* pass the helper object around.
|
|
77
|
-
*/
|
|
78
|
-
export function createDocumentExport(
|
|
79
|
-
templateFn: () => unknown,
|
|
80
|
-
options: DocumentExportOptions = {},
|
|
81
|
-
): DocumentExport {
|
|
82
|
-
const getDocNode = (): DocNode => extractDocNode(templateFn, options)
|
|
83
|
-
return { getDocNode }
|
|
84
|
-
}
|