1
1
import pathlib
2
2
from typing import List , Optional , TypeVar , overload , Dict , Union , Literal
3
3
4
- PathLike = TypeVar ("PathLike " , str , pathlib .Path )
4
+ Input = TypeVar ("Input " , str , pathlib .Path , bytes )
5
5
OutputFormat = Literal ["pdf" , "svg" , "png" , "html" ]
6
6
7
7
class Compiler :
8
8
def __init__ (
9
9
self ,
10
- input : PathLike ,
11
- root : Optional [PathLike ] = None ,
12
- font_paths : List [PathLike ] = [],
10
+ input : Input ,
11
+ root : Optional [Input ] = None ,
12
+ font_paths : List [Input ] = [],
13
13
ignore_system_fonts : bool = False ,
14
14
sys_inputs : Dict [str , str ] = {},
15
15
pdf_standards : Optional [Union [Literal ["1.7" , "a-2b" , "a-3b" ], List [Literal ["1.7" , "a-2b" , "a-3b" ]]]] = []
16
16
) -> None :
17
17
"""Initialize a Typst compiler.
18
18
Args:
19
- input (PathLike): Project 's main .typ file.
19
+ input: .typ file bytes or path to project 's main .typ file.
20
20
root (Optional[PathLike], optional): Root path for the Typst project.
21
21
font_paths (List[PathLike]): Folders with fonts.
22
22
ignore_system_fonts (bool): Ignore system fonts.
@@ -25,7 +25,7 @@ class Compiler:
25
25
26
26
def compile (
27
27
self ,
28
- output : Optional [PathLike ] = None ,
28
+ output : Optional [Input ] = None ,
29
29
format : Optional [OutputFormat ] = None ,
30
30
ppi : Optional [float ] = None ,
31
31
) -> Optional [Union [bytes , List [bytes ]]]:
@@ -59,10 +59,10 @@ class Compiler:
59
59
60
60
@overload
61
61
def compile (
62
- input : PathLike ,
63
- output : PathLike ,
64
- root : Optional [PathLike ] = None ,
65
- font_paths : List [PathLike ] = [],
62
+ input : Input ,
63
+ output : Input ,
64
+ root : Optional [Input ] = None ,
65
+ font_paths : List [Input ] = [],
66
66
ignore_system_fonts : bool = False ,
67
67
format : Optional [OutputFormat ] = None ,
68
68
ppi : Optional [float ] = None ,
@@ -71,21 +71,21 @@ def compile(
71
71
) -> None : ...
72
72
@overload
73
73
def compile (
74
- input : PathLike ,
74
+ input : Input ,
75
75
output : None = None ,
76
- root : Optional [PathLike ] = None ,
77
- font_paths : List [PathLike ] = [],
76
+ root : Optional [Input ] = None ,
77
+ font_paths : List [Input ] = [],
78
78
ignore_system_fonts : bool = False ,
79
79
format : Optional [OutputFormat ] = None ,
80
80
ppi : Optional [float ] = None ,
81
81
sys_inputs : Dict [str , str ] = {},
82
82
pdf_standards : Optional [Union [Literal ["1.7" , "a-2b" , "a-3b" ], List [Literal ["1.7" , "a-2b" , "a-3b" ]]]] = []
83
83
) -> bytes : ...
84
84
def compile (
85
- input : PathLike ,
86
- output : Optional [PathLike ] = None ,
87
- root : Optional [PathLike ] = None ,
88
- font_paths : List [PathLike ] = [],
85
+ input : Input ,
86
+ output : Optional [Input ] = None ,
87
+ root : Optional [Input ] = None ,
88
+ font_paths : List [Input ] = [],
89
89
ignore_system_fonts : bool = False ,
90
90
format : Optional [OutputFormat ] = None ,
91
91
ppi : Optional [float ] = None ,
@@ -94,7 +94,7 @@ def compile(
94
94
) -> Optional [Union [bytes , List [bytes ]]]:
95
95
"""Compile a Typst project.
96
96
Args:
97
- input (PathLike): Project 's main .typ file.
97
+ input: .typ file bytes or path to project 's main .typ file.
98
98
output (Optional[PathLike], optional): Path to save the compiled file.
99
99
Allowed extensions are `.pdf`, `.svg` and `.png`
100
100
root (Optional[PathLike], optional): Root path for the Typst project.
@@ -109,19 +109,19 @@ def compile(
109
109
"""
110
110
111
111
def query (
112
- input : PathLike ,
112
+ input : Input ,
113
113
selector : str ,
114
114
field : Optional [str ] = None ,
115
115
one : bool = False ,
116
116
format : Optional [Literal ["json" , "yaml" ]] = None ,
117
- root : Optional [PathLike ] = None ,
118
- font_paths : List [PathLike ] = [],
117
+ root : Optional [Input ] = None ,
118
+ font_paths : List [Input ] = [],
119
119
ignore_system_fonts : bool = False ,
120
120
sys_inputs : Dict [str , str ] = {},
121
121
) -> str :
122
122
"""Query a Typst document.
123
123
Args:
124
- input (PathLike): Project 's main .typ file.
124
+ input: .typ file bytes or path to project 's main .typ file.
125
125
selector (str): Typst selector like `<label>`.
126
126
field (Optional[str], optional): Field to query.
127
127
one (bool, optional): Query only one element.
0 commit comments