svgdotjs / svgdom

Straightforward DOM implementation to make SVG.js run headless on Node.js
MIT License
274 stars 54 forks source link

baseVal not supported #32

Open nornagon opened 5 years ago

nornagon commented 5 years ago

I'm using path-data-polyfill, which uses baseVal to get x/y/width/height/etc. values from <rect>, <ellipse>, etc. elements. It would be great to implement this in svgdom!

Fuzzyma commented 5 years ago

Unfortunately that's not as easy as it sounds. You basically need to intercept all access to the node to return the correct attribute. Feel free to open a PR to implement this feature!

nornagon commented 5 years ago

It looks like HTMLLinkElement exposes some direct properties, could baseVal be handled in a similar manner?

The properties for which baseVal works are quite limited and well-defined per element type, at least for shapes:

baseVal is useful for parsing SVG lengths, as in <rect width="10cm" height="10cm"/>. getAttribute works fine for the raw value but it would be great if svgdom could handle the lengths.

Fuzzyma commented 5 years ago

There is more. Everything in svg is animatable. Everything which is animatable has baseVal and animVal properties. For e.g. polygon you have points with a pointlist which of it also has x and y. I think its not as easy as you think it is. But if you want enhance a special bit of svgdom you are welcome to do so. If you only need some properties, just add them :)