-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy path_types.py
61 lines (47 loc) · 1.29 KB
/
_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from __future__ import annotations
from dataclasses import dataclass
from decimal import Decimal
from typing import TYPE_CHECKING, Union
if TYPE_CHECKING:
from typing_extensions import Literal
Number = Union[Decimal, float, int]
@dataclass
class Length:
"""
https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#length
"""
value: Number
unit: Literal["em", "ex", "px", "pt", "pc", "cm", "mm", "in", "%"]
def __str__(self) -> str:
return f"{self.value}{self.unit}"
@dataclass
class PreserveAspectRatio:
"""
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio
"""
alignment: Literal[
"none",
"xMinYMin",
"xMidYMin",
"xMaxYMin",
"xMinYMid",
"xMidYMid",
"xMaxYMid",
"xMinYMax",
"xMidYMax",
"xMaxYMax",
] = "xMidYMid"
scale_type: Literal["meet", "slice"] = "meet"
def __str__(self) -> str:
return f"{self.alignment} {self.scale_type}"
@dataclass
class ViewBoxSpec:
"""
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
"""
min_x: Number
min_y: Number
width: Number
height: Number
def __str__(self) -> str:
return f"{self.min_x} {self.min_y} {self.width} {self.height}"