weasyprint-tsx 0.1.1 → 0.1.3
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 -1
- package/package.json +1 -1
- package/packages/build/package.json +1 -1
- package/packages/build/src/config.ts +3 -3
- package/packages/build/src/orchestrator.ts +1 -9
- package/packages/ui/package.json +3 -2
- package/packages/ui/src/BlockBox.tsx +2 -2
- package/packages/ui/src/CodeBlock.tsx +1 -1
- package/packages/ui/src/DotLine.tsx +1 -1
- package/packages/ui/src/Equation.tsx +53 -4
- package/packages/ui/src/List.module.css +1 -1
- package/packages/ui/src/List.tsx +4 -4
- package/packages/ui/src/Page.tsx +1 -1
- package/packages/ui/src/Stack.tsx +1 -1
- package/packages/ui/src/Table.tsx +1 -1
- package/packages/ui/src/Titles.tsx +3 -3
- package/packages/ui/src/index.ts +15 -1
- package/src/index.tsx +2 -4
- package/testUI/index.tsx +7 -5
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ export interface Config {
|
|
|
11
11
|
stylesheets?: string[];
|
|
12
12
|
};
|
|
13
13
|
weasyprint?: {
|
|
14
|
-
path
|
|
14
|
+
path?: string;
|
|
15
15
|
verbose?: boolean;
|
|
16
16
|
pdf_forms?: boolean;
|
|
17
17
|
optimize_images?: boolean;
|
|
@@ -48,7 +48,7 @@ const defaultConfig = {
|
|
|
48
48
|
},
|
|
49
49
|
} satisfies Config;
|
|
50
50
|
|
|
51
|
-
export type DConfig = typeof defaultConfig
|
|
51
|
+
export type DConfig = Config & typeof defaultConfig;
|
|
52
52
|
|
|
53
53
|
export function isObject(item: any) {
|
|
54
54
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
@@ -81,7 +81,7 @@ export async function loadConfig(): Promise<DConfig> {
|
|
|
81
81
|
let config = defaultConfig;
|
|
82
82
|
try {
|
|
83
83
|
const { default: userConfig } = await import(`${configPath}`);
|
|
84
|
-
config = mergeDeep(config, userConfig) as
|
|
84
|
+
config = mergeDeep(config, userConfig) as Config as DConfig;
|
|
85
85
|
} catch (e) {
|
|
86
86
|
process.stdout.write(
|
|
87
87
|
`No config file at ${configPath} found, using default.`,
|
|
@@ -7,17 +7,9 @@ import { bumpPing, startServer } from "./server";
|
|
|
7
7
|
export async function buildOnce(output?: string) {
|
|
8
8
|
const cfg = await loadConfig();
|
|
9
9
|
if (output) cfg.io.output = output;
|
|
10
|
-
let t0 = performance.now();
|
|
11
10
|
|
|
12
11
|
await buildHTML(cfg);
|
|
13
|
-
process.stdout.write(
|
|
14
|
-
`Bun HTML build -- ${(performance.now() - t0).toFixed(2)} ms`,
|
|
15
|
-
);
|
|
16
12
|
await buildPDF(cfg);
|
|
17
|
-
t0 = performance.now();
|
|
18
|
-
process.stdout.write(
|
|
19
|
-
`Weasyprint PDF build -- ${(performance.now() - t0).toFixed(2)} ms → ${cfg.io.output}`,
|
|
20
|
-
);
|
|
21
13
|
}
|
|
22
14
|
|
|
23
15
|
export async function devMode(output?: string) {
|
|
@@ -25,7 +17,7 @@ export async function devMode(output?: string) {
|
|
|
25
17
|
const WATCH_DIRS = cfg.dev.watch.map((p) => join(process.cwd(), p));
|
|
26
18
|
|
|
27
19
|
if (output) cfg.io.output = cfg.io.output ?? output;
|
|
28
|
-
process.stdout.write(`Dev: http://localhost:${cfg.dev.port}`);
|
|
20
|
+
process.stdout.write(`Dev: http://localhost:${cfg.dev.port}\n`);
|
|
29
21
|
|
|
30
22
|
let pdfBusy = false;
|
|
31
23
|
let lastHash: number | BigInt = 0;
|
package/packages/ui/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasyprint-tsx/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": "./src/index.ts"
|
|
6
6
|
},
|
|
7
7
|
"types": "./src/index.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"highlight.js": "11.11.1"
|
|
9
|
+
"highlight.js": "11.11.1",
|
|
10
|
+
"katex": "^0.16.47"
|
|
10
11
|
}
|
|
11
12
|
}
|
|
@@ -2,7 +2,7 @@ import { ComponentProps, toChildArray, VNode } from "preact";
|
|
|
2
2
|
import styles from "./BlockBox.module.css";
|
|
3
3
|
import { joinClasses, mergeStyle } from "./utils";
|
|
4
4
|
|
|
5
|
-
interface BlockBoxProps extends ComponentProps<"div"> {
|
|
5
|
+
export interface BlockBoxProps extends ComponentProps<"div"> {
|
|
6
6
|
children: VNode<BlockProps>[] | VNode<BlockProps>;
|
|
7
7
|
gap?: string;
|
|
8
8
|
basis?: number;
|
|
@@ -10,7 +10,7 @@ interface BlockBoxProps extends ComponentProps<"div"> {
|
|
|
10
10
|
align?: "middle" | "top" | "bottom";
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
interface BlockProps extends ComponentProps<"div"> {
|
|
13
|
+
export interface BlockProps extends ComponentProps<"div"> {
|
|
14
14
|
ratio?: number;
|
|
15
15
|
centered?: boolean;
|
|
16
16
|
align?: "middle" | "top" | "bottom";
|
|
@@ -4,7 +4,7 @@ import { ComponentProps } from "preact";
|
|
|
4
4
|
import styles from "./CodeBlock.module.css";
|
|
5
5
|
import { joinClasses, mergeStyle } from "./utils";
|
|
6
6
|
|
|
7
|
-
interface CodeBlockProps extends Omit<ComponentProps<"code">, "children"> {
|
|
7
|
+
export interface CodeBlockProps extends Omit<ComponentProps<"code">, "children"> {
|
|
8
8
|
language: string;
|
|
9
9
|
code: string;
|
|
10
10
|
bgColor?: string;
|
|
@@ -2,7 +2,7 @@ import { ComponentProps } from "preact";
|
|
|
2
2
|
import styles from "./DotLine.module.css";
|
|
3
3
|
import { joinClasses, mergeStyle } from "./utils";
|
|
4
4
|
|
|
5
|
-
interface DotLineProps extends ComponentProps<"span"> {
|
|
5
|
+
export interface DotLineProps extends ComponentProps<"span"> {
|
|
6
6
|
num?: number;
|
|
7
7
|
width?: number | string;
|
|
8
8
|
inline?: boolean;
|
|
@@ -5,11 +5,12 @@ import { ComponentProps } from "preact";
|
|
|
5
5
|
import styles from "./Equation.module.css";
|
|
6
6
|
import { joinClasses } from "./utils";
|
|
7
7
|
|
|
8
|
-
interface EquationProps extends Omit<ComponentProps<"span">, "children"> {
|
|
8
|
+
export interface EquationProps extends Omit<ComponentProps<"span">, "children"> {
|
|
9
9
|
tex: string;
|
|
10
10
|
displayMode?: boolean;
|
|
11
11
|
aligned?: boolean;
|
|
12
12
|
chemical?: boolean;
|
|
13
|
+
numberFormat?: boolean;
|
|
13
14
|
}
|
|
14
15
|
export function Equation({
|
|
15
16
|
tex,
|
|
@@ -17,15 +18,16 @@ export function Equation({
|
|
|
17
18
|
className = "",
|
|
18
19
|
aligned = false,
|
|
19
20
|
chemical = false,
|
|
21
|
+
numberFormat = true,
|
|
20
22
|
...props
|
|
21
23
|
}: EquationProps) {
|
|
24
|
+
const numberFormated = numberFormat ? formatNumber(tex) : tex;
|
|
22
25
|
const alignedCode = aligned
|
|
23
26
|
? `\\begin{aligned}
|
|
24
|
-
${
|
|
27
|
+
${numberFormated}
|
|
25
28
|
\\end{aligned}`
|
|
26
|
-
:
|
|
29
|
+
: numberFormated;
|
|
27
30
|
const chemCode = chemical ? `\\ce{${alignedCode}}` : alignedCode;
|
|
28
|
-
|
|
29
31
|
return (
|
|
30
32
|
<span
|
|
31
33
|
dangerouslySetInnerHTML={{
|
|
@@ -36,3 +38,50 @@ ${tex}
|
|
|
36
38
|
/>
|
|
37
39
|
);
|
|
38
40
|
}
|
|
41
|
+
|
|
42
|
+
export interface SymbolProps {
|
|
43
|
+
children?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function symbolFactory(
|
|
47
|
+
fn: (txt?: string, children?: string) => string | undefined,
|
|
48
|
+
txt?: string,
|
|
49
|
+
init?: string,
|
|
50
|
+
) {
|
|
51
|
+
return function ({ children = init }: SymbolProps) {
|
|
52
|
+
return <Equation tex={fn(txt, children) ?? ""} />;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function underscriptFactory(txt: string, init?: string) {
|
|
57
|
+
return symbolFactory(
|
|
58
|
+
(txt, children) => (children ? `${txt}_{${children}}` : `${txt}`),
|
|
59
|
+
txt,
|
|
60
|
+
init,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function functionFactory(txt: string, init: string = "x") {
|
|
65
|
+
return symbolFactory(
|
|
66
|
+
(txt, children) => (children ? `${txt}(${children})` : `${txt}`),
|
|
67
|
+
txt,
|
|
68
|
+
init,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function formatNumber(tex: string | undefined) {
|
|
73
|
+
if (!tex) return "";
|
|
74
|
+
return tex.replace(/\d+(?:\.\d+)?/g, (match) => {
|
|
75
|
+
const [intPart, decPart] = match.split(".");
|
|
76
|
+
const formattedInt = intPart.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1\\,");
|
|
77
|
+
if (decPart === undefined) return formattedInt;
|
|
78
|
+
const formattedDec = decPart.replace(/(\d{3})(?=\d)/g, "$1\\,");
|
|
79
|
+
return `${formattedInt},${formattedDec}\\:`;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function LtX(props: SymbolProps) {
|
|
84
|
+
return symbolFactory((_, children) => {
|
|
85
|
+
return formatNumber(children);
|
|
86
|
+
})(props);
|
|
87
|
+
}
|
package/packages/ui/src/List.tsx
CHANGED
|
@@ -9,24 +9,24 @@ export type CounterType =
|
|
|
9
9
|
| "lower-roman"
|
|
10
10
|
| "upper-roman";
|
|
11
11
|
|
|
12
|
-
interface ListItemProps extends ComponentProps<"div"> {
|
|
12
|
+
export interface ListItemProps extends ComponentProps<"div"> {
|
|
13
13
|
count?: number;
|
|
14
14
|
marker?: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
interface ListProps extends ComponentProps<"div"> {
|
|
17
|
+
export interface ListProps extends ComponentProps<"div"> {
|
|
18
18
|
pre?: ComponentChildren;
|
|
19
19
|
gap?: string | number;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
interface OLProps extends ListProps {
|
|
22
|
+
export interface OLProps extends ListProps {
|
|
23
23
|
start?: number;
|
|
24
24
|
counterType?: CounterType;
|
|
25
25
|
markerPre?: string;
|
|
26
26
|
markerPost?: string;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
interface ULProps extends ListProps {
|
|
29
|
+
export interface ULProps extends ListProps {
|
|
30
30
|
marker?: string;
|
|
31
31
|
}
|
|
32
32
|
|
package/packages/ui/src/Page.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { ComponentProps } from "preact";
|
|
|
2
2
|
import styles from "./Stack.module.css";
|
|
3
3
|
import { joinClasses, mergeStyle } from "./utils";
|
|
4
4
|
|
|
5
|
-
interface StackProps extends ComponentProps<"div"> {
|
|
5
|
+
export interface StackProps extends ComponentProps<"div"> {
|
|
6
6
|
gap?: number | string;
|
|
7
7
|
align?: "left" | "right";
|
|
8
8
|
}
|
|
@@ -22,7 +22,7 @@ export function Entry(_props: TableEntryProps): null {
|
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
interface TableProps extends ComponentProps<"table"> {
|
|
25
|
+
export interface TableProps extends ComponentProps<"table"> {
|
|
26
26
|
orientation?: "col" | "row";
|
|
27
27
|
contentClass?: string;
|
|
28
28
|
headerClass?: string;
|
|
@@ -2,9 +2,9 @@ import { ComponentProps, ComponentType } from "preact";
|
|
|
2
2
|
import styles from "./Title.module.css";
|
|
3
3
|
import { joinClasses, mergeStyle } from "./utils";
|
|
4
4
|
|
|
5
|
-
type Htype = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
5
|
+
export type Htype = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
6
6
|
|
|
7
|
-
type Hprops<h extends Htype> = ComponentProps<h> & {
|
|
7
|
+
export type Hprops<h extends Htype> = ComponentProps<h> & {
|
|
8
8
|
marker?: string;
|
|
9
9
|
color?: string;
|
|
10
10
|
fontSize?: string;
|
|
@@ -73,7 +73,7 @@ export function H6({ className = "", marker, color, fontSize, style, ...props }:
|
|
|
73
73
|
|
|
74
74
|
const TAG_MAP = { h1: H1, h2: H2, h3: H3, h4: H4, h5: H5, h6: H6 };
|
|
75
75
|
|
|
76
|
-
type TitleProps<h extends Htype> = Hprops<h> & { type: h };
|
|
76
|
+
export type TitleProps<h extends Htype> = Hprops<h> & { type: h };
|
|
77
77
|
export function Title<h extends Htype>({ type, ...props }: TitleProps<h>) {
|
|
78
78
|
const Tag = TAG_MAP[type] as ComponentType<Hprops<h>>;
|
|
79
79
|
return <Tag {...(props as Hprops<h>)} />;
|
package/packages/ui/src/index.ts
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
export { Block, BlockBox } from "./BlockBox";
|
|
2
|
+
export type { BlockBoxProps, BlockProps } from "./BlockBox";
|
|
2
3
|
export { CodeBlock } from "./CodeBlock";
|
|
4
|
+
export type { CodeBlockProps } from "./CodeBlock";
|
|
3
5
|
export { DotLine } from "./DotLine";
|
|
4
|
-
export {
|
|
6
|
+
export type { DotLineProps } from "./DotLine";
|
|
7
|
+
export {
|
|
8
|
+
Equation,
|
|
9
|
+
functionFactory, LtX, symbolFactory,
|
|
10
|
+
underscriptFactory
|
|
11
|
+
} from "./Equation";
|
|
12
|
+
export type { EquationProps, SymbolProps } from "./Equation";
|
|
5
13
|
export { LI, OL, UL } from "./List";
|
|
14
|
+
export type { CounterType, ListItemProps, ListProps, OLProps, ULProps } from "./List";
|
|
6
15
|
export { Page, PageBreak } from "./Page";
|
|
16
|
+
export type { PageProps } from "./Page";
|
|
7
17
|
export { Stack } from "./Stack";
|
|
18
|
+
export type { StackProps } from "./Stack";
|
|
8
19
|
export { Entry, Table } from "./Table";
|
|
20
|
+
export type { TableEntryProps, TableProps } from "./Table";
|
|
9
21
|
export { H1, H2, H3, H4, H5, H6, ResetCounter, Title } from "./Titles";
|
|
22
|
+
export type { Hprops, Htype, TitleProps } from "./Titles";
|
|
23
|
+
export * from "./utils";
|
|
10
24
|
|
package/src/index.tsx
CHANGED
|
@@ -82,11 +82,9 @@ export default function Document() {
|
|
|
82
82
|
</UL>
|
|
83
83
|
</div>
|
|
84
84
|
<div className="w-1/2">
|
|
85
|
-
<H3 color="#1e40af">
|
|
86
|
-
Quick start
|
|
87
|
-
</H3>
|
|
85
|
+
<H3 color="#1e40af">Quick start</H3>
|
|
88
86
|
<OL>
|
|
89
|
-
<LI>bunx
|
|
87
|
+
<LI>bunx @weasyprint-tsx/create my-doc</LI>
|
|
90
88
|
<LI>cd my-doc && bun install</LI>
|
|
91
89
|
<LI>bun run dev</LI>
|
|
92
90
|
</OL>
|
package/testUI/index.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Eq, Equation, functionFactory } from "@weasyprint-tsx/ui";
|
|
2
2
|
import "./index.css";
|
|
3
3
|
|
|
4
|
+
const S = functionFactory("S" , "x")
|
|
5
|
+
|
|
4
6
|
export default function Document() {
|
|
5
7
|
return (
|
|
6
8
|
<html>
|
|
@@ -10,10 +12,10 @@ export default function Document() {
|
|
|
10
12
|
<link rel="stylesheet" href="index.css" />
|
|
11
13
|
</head>
|
|
12
14
|
<body>
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
</
|
|
15
|
+
<Equation tex="C_m = 50000.0000000000000000001 g/L"></Equation>
|
|
16
|
+
<Eq>151545312313513.13543545345343 a151515131 .13513513</Eq>
|
|
17
|
+
<S/>
|
|
18
|
+
<S>g</S>
|
|
17
19
|
</body>
|
|
18
20
|
</html>
|
|
19
21
|
);
|