@weasyprint-tsx/ui 0.1.2 → 0.1.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weasyprint-tsx/ui",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "exports": {
5
5
  ".": "./src/index.ts"
6
6
  },
package/src/BlockBox.tsx CHANGED
@@ -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";
package/src/CodeBlock.tsx CHANGED
@@ -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;
package/src/DotLine.tsx CHANGED
@@ -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;
package/src/Equation.tsx CHANGED
@@ -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
- ${tex}
27
+ ${numberFormated}
25
28
  \\end{aligned}`
26
- : tex;
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 Eq(props: SymbolProps) {
84
+ return symbolFactory((_, children) => {
85
+ return formatNumber(children);
86
+ })(props);
87
+ }
package/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/src/Page.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ComponentProps } from "preact";
2
2
  import styles from "./Page.module.css";
3
3
  import { joinClasses, mergeStyle } from "./utils";
4
- interface PageProps {
4
+ export interface PageProps {
5
5
  page?: string;
6
6
  }
7
7
 
package/src/Stack.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
  }
package/src/Table.tsx CHANGED
@@ -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;
package/src/Titles.tsx CHANGED
@@ -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/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 { Equation } from "./Equation";
6
+ export type { DotLineProps } from "./DotLine";
7
+ export {
8
+ Eq, Equation,
9
+ functionFactory, 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