svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
10.95k stars 1.07k forks source link

Color-names are not applied after animation #1270

Closed chaitanyasunkara closed 2 years ago

chaitanyasunkara commented 2 years ago

Bug report

Fiddle

this fiddle

Screen Shot 2022-04-12 at 2 48 40 AM

Explanation

saivan commented 2 years ago

This is definitely not a bug. The css colors are supported by modern browsers, but not natively supported in SVGjs. You can certainly write a plugin to add support for them if you'd like to but it shouldn't be included in the core.

For starters, you can't animate between the strings 'red' and 'green' in any reasonable way. We would need to maintain a mapping with all of those names in them. Instead you should use:

canvas.rect(100, 100).attr({ fill: 'rgb(255, 0, 0)' })

Or you can use our awesome color module to define your colours however you'd like. But internally, to be able to animate the string 'red', we'd need to convert it to an rgb tuple.

If you really want this functionality, you can just use this

https://stackoverflow.com/questions/1573053/javascript-function-to-convert-color-names-to-hex-codes

But I think that native support for these colors isn't something we'd add to the library