def gradient.stops

gralha-svg-render@0.1.0.1 · svg.bend:2146

import gralha-svg-render@0.1.0.1/svg.bend as Svg
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U
import gralha-xml-doc@0.1.0.1/xml.bend as XML
import gralha-css-style@0.1.0.1/css.bend as CSS

2146def gradient.stops(xs: List<&2, XML.Element>, +as: List<&2, XML.Attr>, +previous: F32, +linear: Bool) -> List<&2, Stop>:
2147  match xs:
2148    case Nil{}: Nil{}
2149    case Con{XML.Element{n, attrs, kids, txt}, rest}:
2150      +props = CSS.properties(attrs)
2151      +offset = U.max(previous, U.clamp(U.unit(U.number(XML.attr.get(props, "offset", "0")), 1.0), 0.0, 1.0))
2152      +col = XML.attr.get(props, "stop-color", "black")
2153      +tail = rest
2154      U.branch(List<&2, Stop>, U.string.equal(n, "stop"),
2155        _ => Con{Stop{offset, stop.color(color(U.choose(String, U.string.equal(CSS.css.lower(U.trim.both(col)), "currentcolor"),
2156          XML.attr.get(props, "color", XML.attr.get(as, "color", "black")), col)), U.clamp(U.unit(U.number(XML.attr.get(props, "stop-opacity", "1")), 1.0), 0.0, 1.0), linear)},
2157          gradient.stops(tail, as, offset, linear)}, _ => gradient.stops(tail, as, previous, linear))

Uses (20)

Used by (1)