weasyprint-tsx 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/README.md +1 -0
- package/ReadMe.pdf +0 -0
- package/bun.lock +166 -0
- package/global.d.ts +16 -0
- package/package.json +11 -0
- package/packages/build/package.json +20 -0
- package/packages/build/src/build.ts +100 -0
- package/packages/build/src/cli.ts +13 -0
- package/packages/build/src/config.ts +90 -0
- package/packages/build/src/orchestrator.ts +61 -0
- package/packages/build/src/server.ts +36 -0
- package/packages/create/cli.js +28 -0
- package/packages/create/package.json +10 -0
- package/packages/create/template/global.d.ts +16 -0
- package/packages/create/template/package.json +18 -0
- package/packages/create/template/src/index.css +21 -0
- package/packages/create/template/src/index.tsx +25 -0
- package/packages/create/template/tsconfig.json +11 -0
- package/packages/create/template/weasyprint-tsx.config.ts +17 -0
- package/packages/ui/package.json +8 -0
- package/packages/ui/src/BlockBox.module.css +16 -0
- package/packages/ui/src/BlockBox.tsx +66 -0
- package/packages/ui/src/CodeBlock.tsx +17 -0
- package/packages/ui/src/DotLine.module.css +24 -0
- package/packages/ui/src/DotLine.tsx +45 -0
- package/packages/ui/src/Equation.module.css +4 -0
- package/packages/ui/src/Equation.tsx +38 -0
- package/packages/ui/src/List.module.css +53 -0
- package/packages/ui/src/List.tsx +120 -0
- package/packages/ui/src/Page.module.css +14 -0
- package/packages/ui/src/Page.tsx +33 -0
- package/packages/ui/src/Table.module.css +55 -0
- package/packages/ui/src/Table.tsx +164 -0
- package/packages/ui/src/Title.module.css +75 -0
- package/packages/ui/src/Titles.tsx +105 -0
- package/packages/ui/src/index.ts +9 -0
- package/packages/ui/src/utils.tsx +26 -0
- package/src/index.css +0 -0
- package/src/index.tsx +16 -0
- package/tsconfig.json +16 -0
- package/weasyprint-tsx.config.ts +7 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComponentChild,
|
|
3
|
+
ComponentProps,
|
|
4
|
+
toChildArray,
|
|
5
|
+
VNode
|
|
6
|
+
} from "preact";
|
|
7
|
+
import styles from "./Table.module.css";
|
|
8
|
+
import { joinClasses, mergeStyle } from "./utils";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export interface TableEntryProps extends ComponentProps<"th"> {
|
|
13
|
+
content: ComponentChild[];
|
|
14
|
+
contentClass?: string;
|
|
15
|
+
headerBg?: string;
|
|
16
|
+
cellBg?: string;
|
|
17
|
+
headerFontSize?: string;
|
|
18
|
+
cellFontSize?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Entry(_props: TableEntryProps): null {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface TableProps extends ComponentProps<"table"> {
|
|
26
|
+
orientation?: "col" | "row";
|
|
27
|
+
contentClass?: string;
|
|
28
|
+
headerClass?: string;
|
|
29
|
+
headerBg?: string;
|
|
30
|
+
cellBg?: string;
|
|
31
|
+
headerFontSize?: string;
|
|
32
|
+
cellFontSize?: string;
|
|
33
|
+
borderWidth?: string;
|
|
34
|
+
borderColor?: string;
|
|
35
|
+
children: VNode<TableEntryProps> | VNode<TableEntryProps>[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export function Table({
|
|
40
|
+
children,
|
|
41
|
+
orientation = "col",
|
|
42
|
+
className,
|
|
43
|
+
style,
|
|
44
|
+
contentClass: parentContentClass = "",
|
|
45
|
+
headerClass,
|
|
46
|
+
headerBg,
|
|
47
|
+
cellBg,
|
|
48
|
+
headerFontSize,
|
|
49
|
+
cellFontSize,
|
|
50
|
+
borderWidth,
|
|
51
|
+
borderColor,
|
|
52
|
+
...props
|
|
53
|
+
}: TableProps) {
|
|
54
|
+
const headers = toChildArray(children)
|
|
55
|
+
.filter((child) => (child as VNode).type === Entry)
|
|
56
|
+
.map((child) => (child as VNode<TableEntryProps>).props);
|
|
57
|
+
|
|
58
|
+
const tableClass = joinClasses(
|
|
59
|
+
className,
|
|
60
|
+
styles.table,
|
|
61
|
+
styles[orientation],
|
|
62
|
+
).trim();
|
|
63
|
+
|
|
64
|
+
const tableStyle = mergeStyle(style, {
|
|
65
|
+
"--table-header-color": headerBg,
|
|
66
|
+
"--table-cell-color": cellBg,
|
|
67
|
+
"--table-header-fontsize": headerFontSize,
|
|
68
|
+
"--table-cell-fontsize": cellFontSize,
|
|
69
|
+
"--table-border-width": borderWidth,
|
|
70
|
+
"--table-border-color": borderColor,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (orientation === "row") {
|
|
74
|
+
return (
|
|
75
|
+
<table className={tableClass} style={tableStyle} {...props}>
|
|
76
|
+
<tbody>
|
|
77
|
+
{headers.map(
|
|
78
|
+
({
|
|
79
|
+
children,
|
|
80
|
+
content,
|
|
81
|
+
className,
|
|
82
|
+
contentClass,
|
|
83
|
+
style,
|
|
84
|
+
headerBg,
|
|
85
|
+
cellBg,
|
|
86
|
+
headerFontSize,
|
|
87
|
+
cellFontSize,
|
|
88
|
+
...props
|
|
89
|
+
}, i) => (
|
|
90
|
+
<tr key={i}>
|
|
91
|
+
<th
|
|
92
|
+
scope="row"
|
|
93
|
+
className={joinClasses(className, headerClass)}
|
|
94
|
+
style={mergeStyle(style, {
|
|
95
|
+
"--table-header-color": headerBg,
|
|
96
|
+
"--table-header-fontsize": headerFontSize,
|
|
97
|
+
})}
|
|
98
|
+
{...props}
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
</th>
|
|
102
|
+
{content.map((cell, j) => (
|
|
103
|
+
<td
|
|
104
|
+
key={j}
|
|
105
|
+
className={joinClasses(contentClass, parentContentClass)}
|
|
106
|
+
style={{ "--table-cell-color": cellBg, "--table-cell-fontsize": cellFontSize }}
|
|
107
|
+
>
|
|
108
|
+
{cell}
|
|
109
|
+
</td>
|
|
110
|
+
))}
|
|
111
|
+
</tr>
|
|
112
|
+
),
|
|
113
|
+
)}
|
|
114
|
+
</tbody>
|
|
115
|
+
</table>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const rowCount = Math.max(...headers.map((h) => h.content.length));
|
|
120
|
+
return (
|
|
121
|
+
<table className={tableClass} style={tableStyle} {...props}>
|
|
122
|
+
<thead>
|
|
123
|
+
<tr>
|
|
124
|
+
{headers.map(
|
|
125
|
+
(
|
|
126
|
+
{ children, content, className, contentClass, style, headerBg, cellBg, headerFontSize, cellFontSize, ...props },
|
|
127
|
+
i,
|
|
128
|
+
) => (
|
|
129
|
+
<th
|
|
130
|
+
key={i}
|
|
131
|
+
className={joinClasses(className, headerClass)}
|
|
132
|
+
style={mergeStyle(style, {
|
|
133
|
+
"--table-header-color": headerBg,
|
|
134
|
+
"--table-header-fontsize": headerFontSize,
|
|
135
|
+
})}
|
|
136
|
+
{...props}
|
|
137
|
+
>
|
|
138
|
+
{children}
|
|
139
|
+
</th>
|
|
140
|
+
),
|
|
141
|
+
)}
|
|
142
|
+
</tr>
|
|
143
|
+
</thead>
|
|
144
|
+
<tbody>
|
|
145
|
+
{Array.from({ length: rowCount }, (_, rowIdx) => (
|
|
146
|
+
<tr key={rowIdx}>
|
|
147
|
+
{headers.map(
|
|
148
|
+
({ content, children, contentClass = "", cellBg, cellFontSize, ...props }, colIdx) => (
|
|
149
|
+
<td
|
|
150
|
+
key={colIdx}
|
|
151
|
+
{...props}
|
|
152
|
+
className={joinClasses(contentClass, parentContentClass)}
|
|
153
|
+
style={{ "--table-cell-color": cellBg, "--table-cell-fontsize": cellFontSize }}
|
|
154
|
+
>
|
|
155
|
+
{content[rowIdx]}
|
|
156
|
+
</td>
|
|
157
|
+
),
|
|
158
|
+
)}
|
|
159
|
+
</tr>
|
|
160
|
+
))}
|
|
161
|
+
</tbody>
|
|
162
|
+
</table>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
.h1,
|
|
3
|
+
.h2,
|
|
4
|
+
.h3,
|
|
5
|
+
.h4,
|
|
6
|
+
.h5,
|
|
7
|
+
.h6 {
|
|
8
|
+
&::before {
|
|
9
|
+
float: left;
|
|
10
|
+
clear: left;
|
|
11
|
+
}
|
|
12
|
+
&[data-marker]::before {
|
|
13
|
+
content: attr(data-marker);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
.h1 {
|
|
19
|
+
color: var(--h1-color, inherit);
|
|
20
|
+
font-size: var(--h1-fontsize, inherit);
|
|
21
|
+
counter-reset: count-h2 count-h3 count-h4 count-h5 count-h6;
|
|
22
|
+
counter-increment: count-h1;
|
|
23
|
+
&::before {
|
|
24
|
+
content: counter(count-h1, upper-roman) ". ";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.h2 {
|
|
29
|
+
color: var(--h2-color, inherit);
|
|
30
|
+
font-size: var(--h2-fontsize, inherit);
|
|
31
|
+
counter-reset: count-h3 count-h4 count-h5 count-h6;
|
|
32
|
+
counter-increment: count-h2;
|
|
33
|
+
&::before {
|
|
34
|
+
content: counter(count-h2, decimal) ". ";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.h3 {
|
|
39
|
+
color: var(--h3-color, inherit);
|
|
40
|
+
font-size: var(--h3-fontsize, inherit);
|
|
41
|
+
counter-reset: count-h4 count-h5 count-h6;
|
|
42
|
+
counter-increment: count-h3;
|
|
43
|
+
&::before {
|
|
44
|
+
content: counter(count-h3, lower-alpha) ". ";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.h4 {
|
|
49
|
+
color: var(--h4-color, inherit);
|
|
50
|
+
font-size: var(--h4-fontsize, inherit);
|
|
51
|
+
counter-reset: count-h5 count-h6;
|
|
52
|
+
counter-increment: count-h4;
|
|
53
|
+
&::before {
|
|
54
|
+
content: counter(count-h4, lower-alpha) ". ";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.h5 {
|
|
59
|
+
color: var(--h5-color, inherit);
|
|
60
|
+
font-size: var(--h5-fontsize, inherit);
|
|
61
|
+
counter-reset: count-h6;
|
|
62
|
+
counter-increment: count-h5;
|
|
63
|
+
&::before {
|
|
64
|
+
content: counter(count-h5, lower-alpha) ". ";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.h6 {
|
|
69
|
+
color: var(--h6-color, inherit);
|
|
70
|
+
font-size: var(--h6-fontsize, inherit);
|
|
71
|
+
counter-increment: count-h6;
|
|
72
|
+
&::before {
|
|
73
|
+
content: counter(count-h6, lower-alpha) ". ";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ComponentProps, ComponentType } from "preact";
|
|
2
|
+
import styles from "./Title.module.css";
|
|
3
|
+
import { joinClasses, mergeStyle } from "./utils";
|
|
4
|
+
|
|
5
|
+
type Htype = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
6
|
+
|
|
7
|
+
type Hprops<h extends Htype> = ComponentProps<h> & {
|
|
8
|
+
marker?: string;
|
|
9
|
+
color?: string;
|
|
10
|
+
fontSize?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function H1({ className = "", marker, color, fontSize, style, ...props }: Hprops<"h1">) {
|
|
14
|
+
return (
|
|
15
|
+
<h1
|
|
16
|
+
data-marker={marker}
|
|
17
|
+
className={joinClasses(className, styles.h1)}
|
|
18
|
+
style={mergeStyle(style, { "--h1-color": color, "--h1-fontsize": fontSize })}
|
|
19
|
+
{...props}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
export function H2({ className = "", marker, color, fontSize, style, ...props }: Hprops<"h2">) {
|
|
24
|
+
return (
|
|
25
|
+
<h2
|
|
26
|
+
data-marker={marker}
|
|
27
|
+
className={joinClasses(className, styles.h2)}
|
|
28
|
+
style={mergeStyle(style, { "--h2-color": color, "--h2-fontsize": fontSize })}
|
|
29
|
+
{...props}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
export function H3({ className = "", marker, color, fontSize, style, ...props }: Hprops<"h3">) {
|
|
34
|
+
return (
|
|
35
|
+
<h3
|
|
36
|
+
data-marker={marker}
|
|
37
|
+
className={joinClasses(className, styles.h3)}
|
|
38
|
+
style={mergeStyle(style, { "--h3-color": color, "--h3-fontsize": fontSize })}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
export function H4({ className = "", marker, color, fontSize, style, ...props }: Hprops<"h4">) {
|
|
44
|
+
return (
|
|
45
|
+
<h4
|
|
46
|
+
data-marker={marker}
|
|
47
|
+
className={joinClasses(className, styles.h4)}
|
|
48
|
+
style={mergeStyle(style, { "--h4-color": color, "--h4-fontsize": fontSize })}
|
|
49
|
+
{...props}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
export function H5({ className = "", marker, color, fontSize, style, ...props }: Hprops<"h5">) {
|
|
54
|
+
return (
|
|
55
|
+
<h5
|
|
56
|
+
data-marker={marker}
|
|
57
|
+
className={joinClasses(className, styles.h5)}
|
|
58
|
+
style={mergeStyle(style, { "--h5-color": color, "--h5-fontsize": fontSize })}
|
|
59
|
+
{...props}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
export function H6({ className = "", marker, color, fontSize, style, ...props }: Hprops<"h6">) {
|
|
64
|
+
return (
|
|
65
|
+
<h6
|
|
66
|
+
data-marker={marker}
|
|
67
|
+
className={joinClasses(className, styles.h6)}
|
|
68
|
+
style={mergeStyle(style, { "--h6-color": color, "--h6-fontsize": fontSize })}
|
|
69
|
+
{...props}
|
|
70
|
+
/>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const TAG_MAP = { h1: H1, h2: H2, h3: H3, h4: H4, h5: H5, h6: H6 };
|
|
75
|
+
|
|
76
|
+
type TitleProps<h extends Htype> = Hprops<h> & { type: h };
|
|
77
|
+
export function Title<h extends Htype>({ type, ...props }: TitleProps<h>) {
|
|
78
|
+
const Tag = TAG_MAP[type] as ComponentType<Hprops<h>>;
|
|
79
|
+
return <Tag {...(props as Hprops<h>)} />;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function ResetCounter({
|
|
83
|
+
type,
|
|
84
|
+
value,
|
|
85
|
+
}: {
|
|
86
|
+
type: Htype | Htype[];
|
|
87
|
+
value?: number | (number | null)[];
|
|
88
|
+
}) {
|
|
89
|
+
const types = Array.isArray(type) ? type : [type];
|
|
90
|
+
const values = Array.isArray(value) ? value : [value];
|
|
91
|
+
return (
|
|
92
|
+
<div
|
|
93
|
+
style={{
|
|
94
|
+
counterReset: types
|
|
95
|
+
.map((t, k) =>
|
|
96
|
+
`count-${t} ${(values[k % types.length] ?? 1) - 1}`.trim(),
|
|
97
|
+
)
|
|
98
|
+
.join(" "),
|
|
99
|
+
visibility: "hidden",
|
|
100
|
+
height: 0,
|
|
101
|
+
width: 0,
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Block, BlockBox } from "./BlockBox";
|
|
2
|
+
export { CodeBlock } from "./CodeBlock";
|
|
3
|
+
export { DotLine } from "./DotLine";
|
|
4
|
+
export { Equation } from "./Equation";
|
|
5
|
+
export { LI, OL, UL } from "./List";
|
|
6
|
+
export { Page, PageBreak } from "./Page";
|
|
7
|
+
export { Entry, Table } from "./Table";
|
|
8
|
+
export { H1, H2, H3, H4, H5, H6, ResetCounter, Title } from "./Titles";
|
|
9
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CSSProperties, SignalLike, Signalish } from "preact";
|
|
2
|
+
|
|
3
|
+
export const cssString = (v: string | undefined) =>
|
|
4
|
+
v !== undefined ? `"${v}"` : undefined;
|
|
5
|
+
|
|
6
|
+
export function joinClasses(
|
|
7
|
+
...classes: (string | SignalLike<string | undefined> | undefined)[]
|
|
8
|
+
): string {
|
|
9
|
+
return classes.join(" ").trim();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function mergeStyle(
|
|
13
|
+
base: Signalish<string | CSSProperties | undefined>,
|
|
14
|
+
extra: CSSProperties,
|
|
15
|
+
): CSSProperties | string {
|
|
16
|
+
if (typeof base === "string") {
|
|
17
|
+
const extraStr = Object.entries(extra)
|
|
18
|
+
.filter(([, v]) => v != null)
|
|
19
|
+
.map(
|
|
20
|
+
([k, v]) => `${k.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}:${v}`,
|
|
21
|
+
)
|
|
22
|
+
.join(";");
|
|
23
|
+
return extraStr ? `${base};${extraStr}` : base;
|
|
24
|
+
}
|
|
25
|
+
return { ...(base?.value as CSSProperties), ...extra };
|
|
26
|
+
}
|
package/src/index.css
ADDED
|
File without changes
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { H1 } from "@weasyprint-tsx/ui";
|
|
2
|
+
import "./index.css";
|
|
3
|
+
|
|
4
|
+
export default function Document() {
|
|
5
|
+
return (
|
|
6
|
+
<html>
|
|
7
|
+
<head>
|
|
8
|
+
<title>Weasyprint-tsx - ReadMe</title>
|
|
9
|
+
<link rel="stylesheet" href="index.css" />
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<H1>HEHE</H1>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
15
|
+
);
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"jsx": "react-jsx",
|
|
4
|
+
"jsxImportSource": "preact",
|
|
5
|
+
"types": ["bun-types"],
|
|
6
|
+
"strict": true,
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"target": "ESNext",
|
|
10
|
+
"paths": {
|
|
11
|
+
"@weasyprint-tsx/ui": ["./packages/ui/src"],
|
|
12
|
+
"@weasyprint-tsx/ui/*": ["./packages/ui/src/*"],
|
|
13
|
+
"@weasyprint-tsx/build": ["./packages/build/src"]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|