118 lines
2.9 KiB
Python
118 lines
2.9 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
主题配置模型
|
||
|
|
"""
|
||
|
|
|
||
|
|
from dataclasses import dataclass, field
|
||
|
|
from typing import Tuple, Dict, List
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
def hex_to_rgb(hex_color: str) -> Tuple[int, int, int]:
|
||
|
|
"""十六进制颜色转 RGB"""
|
||
|
|
hex_color = hex_color.lstrip('#')
|
||
|
|
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class Theme:
|
||
|
|
"""
|
||
|
|
主题配置模型
|
||
|
|
|
||
|
|
Attributes:
|
||
|
|
name: 主题名称
|
||
|
|
primary: 主色 (hex)
|
||
|
|
secondary: 次要色 (hex)
|
||
|
|
accent: 强调色 (hex)
|
||
|
|
text: 浅色文字 (hex)
|
||
|
|
text_dark: 深色文字 (hex)
|
||
|
|
gradient: 渐变色 [起始色, 结束色]
|
||
|
|
"""
|
||
|
|
name: str
|
||
|
|
primary: str
|
||
|
|
secondary: str
|
||
|
|
accent: str
|
||
|
|
text: str = "#FFFFFF"
|
||
|
|
text_dark: str = "#333333"
|
||
|
|
gradient: List[str] = field(default_factory=lambda: ["#FFFFFF", "#EEEEEE"])
|
||
|
|
|
||
|
|
@property
|
||
|
|
def primary_rgb(self) -> Tuple[int, int, int]:
|
||
|
|
return hex_to_rgb(self.primary)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def secondary_rgb(self) -> Tuple[int, int, int]:
|
||
|
|
return hex_to_rgb(self.secondary)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def accent_rgb(self) -> Tuple[int, int, int]:
|
||
|
|
return hex_to_rgb(self.accent)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def text_rgb(self) -> Tuple[int, int, int]:
|
||
|
|
return hex_to_rgb(self.text)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def text_dark_rgb(self) -> Tuple[int, int, int]:
|
||
|
|
return hex_to_rgb(self.text_dark)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def gradient_rgb(self) -> List[Tuple[int, int, int]]:
|
||
|
|
return [hex_to_rgb(c) for c in self.gradient]
|
||
|
|
|
||
|
|
|
||
|
|
# 预定义主题 - 小红书风格
|
||
|
|
THEMES: Dict[str, Theme] = {
|
||
|
|
"ocean": Theme(
|
||
|
|
name="深青海洋",
|
||
|
|
primary="#4A8B8B",
|
||
|
|
secondary="#E8F4F4",
|
||
|
|
accent="#E8956C",
|
||
|
|
text="#FFFFFF",
|
||
|
|
text_dark="#2D5555",
|
||
|
|
gradient=["#8BC4C4", "#4A8B8B"],
|
||
|
|
),
|
||
|
|
"sunset": Theme(
|
||
|
|
name="日落暖橙",
|
||
|
|
primary="#D66853",
|
||
|
|
secondary="#FFF5E6",
|
||
|
|
accent="#6BA08A",
|
||
|
|
text="#FFFFFF",
|
||
|
|
text_dark="#4A3328",
|
||
|
|
gradient=["#F5D5A8", "#D66853"],
|
||
|
|
),
|
||
|
|
"peach": Theme(
|
||
|
|
name="蜜桃粉",
|
||
|
|
primary="#D4918A",
|
||
|
|
secondary="#FFF8F5",
|
||
|
|
accent="#B85A54",
|
||
|
|
text="#FFFFFF",
|
||
|
|
text_dark="#5A3D3D",
|
||
|
|
gradient=["#F8D8D4", "#D4918A"],
|
||
|
|
),
|
||
|
|
"mint": Theme(
|
||
|
|
name="薄荷绿",
|
||
|
|
primary="#6A9B88",
|
||
|
|
secondary="#F0F8F4",
|
||
|
|
accent="#D4A05A",
|
||
|
|
text="#FFFFFF",
|
||
|
|
text_dark="#3A5548",
|
||
|
|
gradient=["#B8D8C8", "#6A9B88"],
|
||
|
|
),
|
||
|
|
"latte": Theme(
|
||
|
|
name="拿铁咖啡",
|
||
|
|
primary="#8B7355",
|
||
|
|
secondary="#FAF6F0",
|
||
|
|
accent="#B8956A",
|
||
|
|
text="#FFFFFF",
|
||
|
|
text_dark="#4A3D30",
|
||
|
|
gradient=["#D8C8B0", "#8B7355"],
|
||
|
|
),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def get_theme(name: str) -> Theme:
|
||
|
|
"""获取主题,如果不存在则返回默认主题"""
|
||
|
|
return THEMES.get(name, THEMES["ocean"])
|