svgdom icon indicating copy to clipboard operation
svgdom copied to clipboard

baseVal not supported

Open nornagon opened this issue 7 years ago • 3 comments

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!

nornagon avatar Mar 12 '19 21:03 nornagon

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!

Fuzzyma avatar Mar 13 '19 05:03 Fuzzyma

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 - none
  • line - x1, y1, x2, y2
  • polyline - none
  • polygon - none

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.

nornagon avatar Mar 15 '19 05:03 nornagon

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 :)

Fuzzyma avatar Mar 15 '19 12:03 Fuzzyma