writer started
This commit is contained in:
parent
c163ac2fc1
commit
0d3fae94bd
119
css.py
119
css.py
@ -1,8 +1,24 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional, Tuple, List, Union
|
from typing import Optional, Tuple, Union, Dict, List
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
css_final:List[str] = []
|
||||||
|
css_lines:List[str] = []
|
||||||
|
|
||||||
|
def css_class(css_context:str):
|
||||||
|
global css_lines
|
||||||
|
output = f'{css_context}{{ {"".join(css_lines)} }}'
|
||||||
|
css_lines = []
|
||||||
|
css_final.append(output)
|
||||||
|
|
||||||
|
def css_write(str:str):
|
||||||
|
css_lines.append(str)
|
||||||
|
|
||||||
|
def css_dump():
|
||||||
|
global css_final
|
||||||
|
output = "".join(css_final)
|
||||||
|
css_final = []
|
||||||
|
return output
|
||||||
class Unit():
|
class Unit():
|
||||||
unit = "px"
|
unit = "px"
|
||||||
def __init__(self, amount:float):
|
def __init__(self, amount:float):
|
||||||
@ -19,12 +35,26 @@ class EM(Unit):
|
|||||||
class REM(Unit):
|
class REM(Unit):
|
||||||
unit = "rem"
|
unit = "rem"
|
||||||
|
|
||||||
|
|
||||||
class Cluster():
|
class Cluster():
|
||||||
|
|
||||||
|
map:Dict[str, str] = {}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.key = random.randrange(1000, 5000)
|
||||||
pass
|
pass
|
||||||
def __repr__(self)->str:
|
def __repr__(self)->str:
|
||||||
|
print("repr called on cluster")
|
||||||
#todo: flesh this out / provide overrides for each inheriting class
|
#todo: flesh this out / provide overrides for each inheriting class
|
||||||
return ""
|
return self.render()
|
||||||
|
|
||||||
|
def render(self)->str:
|
||||||
|
output:List[str] = []
|
||||||
|
for key in self.map:
|
||||||
|
value = self.__getattribute__(self.map[key])
|
||||||
|
if value:
|
||||||
|
output.append(f'{key}:{value};')
|
||||||
|
return "\n".join(output)
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Font(Cluster):
|
class Font(Cluster):
|
||||||
@ -32,57 +62,70 @@ class Font(Cluster):
|
|||||||
kerning: Optional[str] = None
|
kerning: Optional[str] = None
|
||||||
size: Optional[Unit] = None
|
size: Optional[Unit] = None
|
||||||
|
|
||||||
|
map = {
|
||||||
|
"font-family":"family",
|
||||||
|
"font-kerning":"kerning",
|
||||||
|
"font-size":"size"
|
||||||
|
}
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Space(Cluster):
|
class Space(Cluster):
|
||||||
top: Optional[Unit] = None
|
top: Optional[Unit] = None
|
||||||
right: Optional[Unit] = None
|
right: Optional[Unit] = None
|
||||||
bottom: Optional[Unit] = None
|
bottom: Optional[Unit] = None
|
||||||
left: Optional[Unit] = None
|
left: Optional[Unit] = None
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class XForm(Space):
|
class XForm(Space):
|
||||||
width: Optional[Unit] = None
|
width: Optional[Unit] = None
|
||||||
height: Optional[Unit] = None
|
height: Optional[Unit] = None
|
||||||
angle: Optional[float] = None
|
angle: Optional[float] = None
|
||||||
|
|
||||||
@dataclass
|
class Chainer():
|
||||||
class Size():
|
|
||||||
def __init__(self, minWidth:int = 0):
|
def __init__(self) -> None:
|
||||||
|
self.accessed = 0
|
||||||
pass
|
pass
|
||||||
def __getitem__(self, keys:Union[Cluster, Tuple[Cluster, ...]]):
|
|
||||||
self.keys = keys
|
def __getitem__(self, args:Union[Cluster, Tuple[Cluster, ...]]):
|
||||||
return self
|
if isinstance(args, tuple):
|
||||||
def __repr__(self) -> str:
|
children = f'\n'.join(k.render() for k in args)
|
||||||
if isinstance(self.keys, tuple):
|
|
||||||
return f'\n'.join(str(k) for k in self.keys)
|
|
||||||
else:
|
else:
|
||||||
return str(self.keys)
|
children = args.render()
|
||||||
|
if self.accessed:
|
||||||
class Atomic():
|
css_write(f'@media(max-width:{self.accessed}px){{ {children} }}')
|
||||||
def __init__(self, *parts:Cluster):
|
else:
|
||||||
self.output:List[str] = []
|
css_write(children)
|
||||||
for part in parts:
|
self.accessed = 0
|
||||||
self.output.append(f'max-width({part[0]}px)'+"{"+part[1].render()+"}")
|
return self
|
||||||
|
|
||||||
def __getitem__(self, keys:Tuple[int, *tuple[Cluster, ...]]):
|
def __call__(self, key:int):
|
||||||
self.keys = keys
|
self.accessed = key
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
CSS = Chainer()
|
||||||
|
|
||||||
### example use:
|
##########################
|
||||||
print(
|
|
||||||
|
|
||||||
Atomic
|
class _SHEET(type):
|
||||||
(
|
last_accessed:Optional[str] = None
|
||||||
Font( size=PX(18) ),
|
def __getattribute__(cls, name:str):
|
||||||
XForm( left=PX(10) )
|
if name != "__name__" and name != "__module__":
|
||||||
)
|
css_class(f'.{cls.__module__}.{cls.__name__}.{name}')
|
||||||
[
|
return super().__getattribute__(name)
|
||||||
(
|
|
||||||
512,
|
class SHEET(metaclass=_SHEET):
|
||||||
Font( size=PX(22) ),
|
pass
|
||||||
XForm( left=PX(18) )
|
class UserMadeSheet(SHEET):
|
||||||
)
|
Paragraph=CSS[
|
||||||
]
|
Font( size=PX(10) ),
|
||||||
|
](512)[
|
||||||
|
Font( size=PX(18), family="sans" ),
|
||||||
|
](1024)[
|
||||||
|
Font( size=PX(120) ),
|
||||||
|
]
|
||||||
|
|
||||||
|
Anchor=CSS[
|
||||||
|
Font( size=PX(123) )
|
||||||
|
]
|
||||||
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user