///|
pub struct CssExportOptions {
selector : String
include_comment : Bool
} derive(Debug, Eq)
///|
pub fn CssExportOptions::default() -> CssExportOptions {
CssExportOptions::{ selector: ":root", include_comment: true }
}
///|
pub fn Palette::to_css(
self : Palette,
options? : CssExportOptions = CssExportOptions::default(),
) -> String {
let lines : Array[String] = []
if options.include_comment {
lines.push("/* Generated by moonbit-brandbook. */")
}
lines.push("\{options.selector} {")
for color in self.colors {
lines.push(" \{color.css_var()}")
}
for gradient in self.gradients {
lines.push(
" --brand-gradient-\{gradient.name}: \{gradient.to_css_value()};",
)
}
lines.push("}")
lines.join("\n")
}
///|
pub fn GradientToken::to_css_value(self : GradientToken) -> String {
"linear-gradient(\{self.angle}deg, \{self.stops.join(", ")})"
}
///|
pub fn Typography::to_css(
self : Typography,
selector? : String = ":root",
) -> String {
let lines : Array[String] = ["\{selector} {"]
for font in self.families {
lines.push(
" --brand-font-\{font.name}: \"\{font.name}\", \{font.fallback};",
)
}
for step in self.scale {
lines.push(" --brand-type-\{step.name}-size: \{step.size_px}px;")
lines.push(
" --brand-type-\{step.name}-line-height: \{step.line_height_px}px;",
)
}
lines.push("}")
lines.join("\n")
}
///|
pub fn BrandBook::to_css(self : BrandBook) -> String {
join_lines([self.palette.to_css(), "", self.typography.to_css()])
}