Open nornagon opened 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!
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:
rect
- x
, y
, width
, height
, rx
, ry
circle
- cx
, cy
, r
ellipse
- cx
, cy
, rx
, ry
path
- noneline
- x1
, y1
, x2
, y2
polyline
- nonepolygon
- nonebaseVal
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.
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 :)
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!