use super::Span;
use super::value::Dimension;
#[derive(Debug, Clone, PartialEq)]
pub enum TokenType {
Color,
Dimension,
Number,
FontFamily,
FontWeight,
Gradient,
Shadow,
Filter,
Mask,
Unknown(String),
}
impl TokenType {
pub fn from_type_name(s: &str) -> Self {
match s {
"color" => Self::Color,
"dimension" => Self::Dimension,
"number" => Self::Number,
"fontFamily" => Self::FontFamily,
"fontWeight" => Self::FontWeight,
"gradient" => Self::Gradient,
"shadow" => Self::Shadow,
"filter" => Self::Filter,
"mask" => Self::Mask,
other => Self::Unknown(other.to_owned()),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum TokenLiteral {
String(String),
Dimension(Dimension),
Number(f64),
Gradient(GradientLiteral),
Shadow(ShadowLiteral),
Filter(FilterLiteral),
Mask(MaskLiteral),
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum MaskShape {
Rect,
RoundedRect,
Ellipse,
}
impl MaskShape {
pub fn from_shape_name(s: &str) -> Option<Self> {
match s {
"rect" => Some(Self::Rect),
"rounded" => Some(Self::RoundedRect),
"ellipse" => Some(Self::Ellipse),
_ => None,
}
}
pub fn as_shape_name(&self) -> &'static str {
match self {
Self::Rect => "rect",
Self::RoundedRect => "rounded",
Self::Ellipse => "ellipse",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct MaskLiteral {
pub shape: MaskShape,
pub radius: Option<f64>,
pub feather: f64,
pub invert: bool,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FilterKind {
Grayscale,
Invert,
Sepia,
Saturate,
Brightness,
Contrast,
HueRotate,
Duotone,
Noise,
}
impl FilterKind {
pub fn from_op_name(s: &str) -> Option<Self> {
match s {
"grayscale" => Some(Self::Grayscale),
"invert" => Some(Self::Invert),
"sepia" => Some(Self::Sepia),
"saturate" => Some(Self::Saturate),
"brightness" => Some(Self::Brightness),
"contrast" => Some(Self::Contrast),
"hue-rotate" => Some(Self::HueRotate),
"duotone" => Some(Self::Duotone),
"noise" => Some(Self::Noise),
_ => None,
}
}
pub fn as_op_name(&self) -> &'static str {
match self {
Self::Grayscale => "grayscale",
Self::Invert => "invert",
Self::Sepia => "sepia",
Self::Saturate => "saturate",
Self::Brightness => "brightness",
Self::Contrast => "contrast",
Self::HueRotate => "hue-rotate",
Self::Duotone => "duotone",
Self::Noise => "noise",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct FilterLiteral {
pub ops: Vec<FilterOp>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FilterOp {
pub kind: FilterKind,
pub amount: Option<f64>,
pub shadow: Option<String>,
pub highlight: Option<String>,
pub seed: Option<i64>,
pub scale: Option<f64>,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum GradientKind {
#[default]
Linear,
Radial,
}
#[derive(Debug, Clone, PartialEq)]
pub struct GradientLiteral {
pub kind: GradientKind,
pub angle_deg: f64,
pub center_x: Option<f64>,
pub center_y: Option<f64>,
pub radius: Option<f64>,
pub stops: Vec<GradientStopRef>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct GradientStopRef {
pub offset: f64,
pub color_token: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShadowLiteral {
pub layers: Vec<ShadowLayerRef>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShadowLayerRef {
pub dx: f64,
pub dy: f64,
pub blur: f64,
pub color_token: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TokenValue {
Literal(TokenLiteral),
Reference { token_id: String },
}
#[derive(Debug, Clone, PartialEq)]
pub struct Token {
pub id: String,
pub token_type: TokenType,
pub value: TokenValue,
pub source_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TokenBlock {
pub format: String,
pub tokens: Vec<Token>,
}
impl Default for TokenBlock {
fn default() -> Self {
Self {
format: "zenith-token-v1".to_owned(),
tokens: Vec::new(),
}
}
}