substrate/src/svg/styles.gleam
Lily Rose ff704930c8
Some checks failed
test / test (push) Has been cancelled
Refactor style logic
2025-07-28 18:45:10 +10:00

53 lines
1.1 KiB
Gleam

import gleam/list
import gleam/option.{type Option, None, Some}
import gleam/string
pub type PaintComponent {
FillComponent
StrokeComponent
MarkerComponent
}
pub type PaintOrder =
List(PaintComponent)
pub fn paint_order_to_string(value: PaintOrder) -> String {
value
|> list.map(fn(comp) {
case comp {
FillComponent -> "fill"
StrokeComponent -> "stroke"
MarkerComponent -> "marker"
}
})
|> string.join(" ")
}
pub type Styles {
Styles(
fill: Option(String),
stroke: Option(String),
stroke_width: Option(Float),
paint_order: Option(List(PaintComponent)),
)
}
pub fn new() {
Styles(fill: None, stroke: None, stroke_width: None, paint_order: None)
}
pub fn with_fill(styles: Styles, fill: String) {
Styles(..styles, fill: Some(fill))
}
pub fn with_stroke(styles: Styles, stroke: String) {
Styles(..styles, stroke: Some(stroke))
}
pub fn with_stroke_width(styles: Styles, stroke_width: Float) {
Styles(..styles, stroke_width: Some(stroke_width))
}
pub fn with_paint_order(styles: Styles, paint_order: PaintOrder) {
Styles(..styles, paint_order: Some(paint_order))
}