Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVGDOM implementation (uncomplete) #1445

Closed
wants to merge 7 commits into from
Closed

Conversation

Fuzzyma
Copy link

@Fuzzyma Fuzzyma commented Apr 10, 2016

jsdom does not implement SVG elements atm. I would like to change that and thats why I try to kickoff the implementation here.

Its my first day contributing to jsdom so I am sure I did some mistakes. Please correct me whenever you spot something odd.
I will add commits to this PR whenever I finished an element.

The first commit only adds the SVGElement as basic implementation.

This PR is related to #1423

@domenic
Copy link
Member

domenic commented Apr 10, 2016

Thanks, this is very much appreciated! I'll try to review and see why Travis is failing.

@@ -0,0 +1,6 @@
interface SVGElement : Element {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the interface from https://svgwg.org/svg2-draft/types.html#InterfaceSVGElement instead, commenting out the things that are not implemented yet? Also add a comment at the top of the file like // https://svgwg.org/svg2-draft/types.html#InterfaceSVGElement, and don't forget a newline at the end of the file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will do. However: May I ask why these interfaces are that different?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes are mostly additive. I believe there is a general desire to make SVG elements more like HTML elements where possible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What to do with the interfaces which are no longer present in the draft you linked (e.g. SVGStylable)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can be omitted. Apparently the SVG working group thinks removing them is an acceptable change for SVG2: https://svgwg.org/svg2-draft/changes.html#types

@domenic
Copy link
Member

domenic commented Apr 10, 2016

Travis is failing because some lint errors.

This will also need some tests before it can be merged. See https://github.com/tmpvar/jsdom/blob/master/Contributing.md#web-platform-feature-tests

@Fuzzyma
Copy link
Author

Fuzzyma commented Apr 10, 2016

Yes, I saw the errors. I forgot a semicolon somewhere.
I will add tests as soon as I understand how that works.
Thanks for reviewing!

@Fuzzyma
Copy link
Author

Fuzzyma commented Apr 11, 2016

I could need a bit help with these tests.
I dont know where to start and especially where to place my tests.

@domenic
Copy link
Member

domenic commented Apr 11, 2016

You can place them in a new subdirectory of https://github.com/tmpvar/jsdom/tree/master/test/web-platform-tests/to-upstream called "svg".

@Fuzzyma
Copy link
Author

Fuzzyma commented Apr 12, 2016

How can I test objects which have no constructor?
In this case I want to write tests for the interface SVGStringList.
The normal conctructor cant be used (illegal constructor). So how to do that?

@domenic
Copy link
Member

domenic commented Apr 12, 2016

Well, are there any APIs that return a SVGStringList on the platform? If so, use them. If not, then there's no reason to add SVGStringList :).

@Fuzzyma
Copy link
Author

Fuzzyma commented Apr 12, 2016

Well yes. SVGTests returns a stringlist (SVGGraphics implements SVGTests). But I feel uncomfortable using such a long way to get to the strings instead of just testing them straight forward

@domenic
Copy link
Member

domenic commented Apr 12, 2016

Nah, it's fine :)

@Fuzzyma
Copy link
Author

Fuzzyma commented Apr 12, 2016

This is from the specs about requiredExtensions:

If the attribute is not present, then it implicitly evaluates to "true". If a null string or empty string value is given to attribute ‘requiredExtensions’, the attribute evaluates to "false".

https://svgwg.org/svg2-draft/struct.html#RequiredExtensionsAttribute

I checked. In FF an empty Stringlist is returned. No false and no true. I am not sure which is the correct behavior.

PS: Sorry for bothering you with that :D

@domenic
Copy link
Member

domenic commented Apr 12, 2016

No problem! I think the confusion there is that it is talking about the requiredExtensions content attribute, i.e. the thing in the SVG markup itself: requiredExtensions="". The requiredExtensions IDL attribute is defined here: https://svgwg.org/svg2-draft/types.html#__svg__SVGTests__requiredExtensions

This gets kind of complicated, and needs the rules in https://svgwg.org/svg2-draft/types.html#TermReflect :-/.

@domenic
Copy link
Member

domenic commented Apr 12, 2016

The "evaluates to true/false" bit is presumably about how other parts in the spec will say something like "if the requiredExtensions attribute for this evaluates to true", which is a spec-ese way of saying "if all the required extensions are supported." I think.

@Fuzzyma
Copy link
Author

Fuzzyma commented Apr 13, 2016

I read through this and I think I understand it. However one question remains: how does the Object knows which attribute it is reflecting. Same goes for readonly. How does e.g. a list knows if it should be readonly?

@Sebmaster
Copy link
Member

How does e.g. a list knows if it should be readonly?

It doesn't need to. readonly doesn't mean you can't modify the list, it means you can't modify the reference to the list as in:

obj.list = new List(); // illegal
obj.list.clear(); // totally fine

The webidl2js layer ensures that readonly are enforced automatically, so you won't have to explicitly pay attention to that.

@Fuzzyma
Copy link
Author

Fuzzyma commented Apr 13, 2016

That makes totally sense. Thanks.
Left is the question about the reflectable List. Is this also covered from the layer?

@Sebmaster
Copy link
Member

Do you mean how we know which properties are also reflected as attributes?

That's sadly not in the webidl language, but rather hidden in the spec language, so actual reading required 😕

Chromium/WebKit has their own proprietary attribute extension which introduces [Reflect] as an extra argument into webidl as you can see here. This argument is also supported by webidl2js, so with some creative merging of the spec IDL, spec language and chromium idl, this is also taken care of mostly.

@Fuzzyma
Copy link
Author

Fuzzyma commented Apr 13, 2016

no. I know that the specs lay out which attributes have to be reflected.
I will try an exampel:
The attribute requiredExtensions has to be reflected. It is a StringList so adding one item to the list whould also add one Extension to the requiredExtensions attribute and the other way round.
My question is where i implement this behavior. The List is aware of beeing edited (insertItemBefore, removeItem... called) but it has no knowledge about which attribute it is representing. So where is the logic placed for actual updating the dom?

@edemaine
Copy link

Hi folks! I'm very interested in getting this patch into jsdom, so that I can use svg.js to build SVG in Node (see svgdotjs/svg.js#464 as well as this article). Anything I can do to help? More test writing or are there other issues?

@Fuzzyma
Copy link
Author

Fuzzyma commented Jul 28, 2016

hey edemaine, I actually felt a bit lost in this huge specifications with all this reflection stuff. However - feel free to add your knowledge here. I would be really happy about that!

@domenic
Copy link
Member

domenic commented Jul 28, 2016

I think the main things left to do for landing this initial patch are:

  • Make sure it conforms to the SVG2 spec. (See above discussions about attribute reflection and things that have been removed above.)
  • Add to-upstream tests for every new piece of code, in web platform tests format. See Contributing.md for more details.

Feel free also to implement a subset, e.g. a basic SVGSVGElement class in a single patch, instead of @Fuzzyma's SVGTests and SVGStringList. That might be an easier patch to land.

@edemaine
Copy link

edemaine commented Aug 5, 2016

OK, I finally read through this discussion. Fuzzyma's main question seems to be how to make something like elt.requiredExtensions.appendItem('extension') tell elt to update its requiredExtensions. I don't quite understand the issue in this case, because elt.requiredExtensions presumably is just a pointer to a single SVGStringList object, so changing that object will affect elt (and it's not like we're actually rendering SVG so there's no UI to update in this case). So my sense is that reflection is "free" as far as dom.js is concerned. (If this were an issue, we could subclass SVGStringList to store the element it belongs to and pass updates along... but this doesn't seem necessary.) Am I missing something?

Also, I'm a little new to Github -- is the proper way to extend a pull request to clone the new repository, make my own commits, and then submit another pull request?

@domenic
Copy link
Member

domenic commented Aug 6, 2016

Also, I'm a little new to Github -- is the proper way to extend a pull request to clone the new repository, make my own commits, and then submit another pull request?

Yeah, that sounds good.

Don't take this to serious. I guess it has some major flaws
@tsiege
Copy link

tsiege commented Dec 20, 2016

Hello! I'm currently working on a project that I'd prefer to use jsdom over phantomjs for. What's the status on this PR/what could I do to help move it along?

@edemaine
Copy link

Sorry, I haven't had time to look more / work on this yet. But looks like @Fuzzyma has had some time to write additional tests. Perhaps he could report on what still remains?

@tsiege
Copy link

tsiege commented Dec 20, 2016

@edemaine no worries. It looks like @nhunzaker is also working on this now. Maybe we could all figure out an MVP for this PR since the W3 spec for SVGs is huge and divide up the work? I'm particularly interesting in seeing #getBBox get implemented which relies on SVGRect, but some of the other classes that were started in here would be nice as well.

CC @Fuzzyma @domenic @Sebmaster

@nhunzaker
Copy link

Digging more into this, I think figuring out a baseline to unblock all of our specific desires is a great starting point.

I simply want SVGElement to be defined on the global namespace with basic DOM operations. However I'd be happy to help collaborate on other pieces.

@Fuzzyma
Copy link
Author

Fuzzyma commented Dec 21, 2016

As far as I can remember my code, the "SVGElement is defined" goal was already achieved^^

@edemaine
Copy link

@nhunzaker Agreed, it'd be nice to release this in pieces, if possible. Personally, I just want enough for svg.js to run, which I think is very little. Then we can break up the remaining work by sections of the SVG DOM spec.

@graingert
Copy link

@Fuzzyma can you mark this is fixing #2001 ?

@Fuzzyma
Copy link
Author

Fuzzyma commented Oct 10, 2017

Might fix #2001

PS: I am not sure if that is the right way :D

@TimothyGu
Copy link
Member

I'm working on creating a cleaned-up version of the SVG-support PRs. Hopefully will finish today!

domenic pushed a commit to TimothyGu/jsdom that referenced this pull request Nov 10, 2017
Closes jsdom#1445 by superceding it; also supercedes jsdom#1946.

Fixes jsdom#1423. Fixes jsdom#1528. Fixes jsdom#1938. Fixes jsdom#2001.

Includes only the <svg> element, but this brings along with it the following interfaces:

* SVGElement
* SVGGraphicsElement
* SVGSVGElement
* SVGTests
* SVGAnimatedString
* SVGNumber
* SVGStringList
@domenic domenic closed this in e2ea031 Nov 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants