dnfield / vector_graphics

BSD 3-Clause "New" or "Revised" License
95 stars 49 forks source link

runtime themeing of colors #119

Open jonahwilliams opened 2 years ago

jonahwilliams commented 2 years ago

I've spoken to several client teams that use some combination of SVG parsing and the SVG theme API to provide dynamic colors to an SVG. We should support a compile time option for this, perhaps accepting a map of identifier -> color in the VectorGraphic constructor.

TBD: how should we indicate dynamic color in the SVG?

dnfield commented 2 years ago

I think part of this would be needing to make currentColor work.

Do you have some examples of what you'd like to support?

And is this runtime or compiletime support?

jonahwilliams commented 2 years ago

Does currentColor work with more than one color? It would have to be runtime support, but implemented so that the compiler didn't optimize these colors out

dnfield commented 2 years ago

No, currentColor is just one color and a hard coded string in the doc.

Every time I've come up against this problem it hasn't been clear to me how to do it in an abstract way short of just offering color filtering. I vaguely remember considering some kind of Map<Color, Color> solution, but also being worried it'd get hard to reason about when tranparency/gradients/overlapping colors get involved.

jonahwilliams commented 2 years ago

Yeah, if you have a dynamic color you basically can't do any optimizations/folding with it. I think that could still work, but we'd also still need a way to declare it, and I wonder if we could just steal use css classes or ids?

dnfield commented 2 years ago

It'd help to have some examples of what the internal customers are currently doing and what they expect to achieve.