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

[Suggestion] Add constants for SVG, and MathML namespaces #6711

Closed
Jamesernator opened this issue May 23, 2021 · 4 comments
Closed

[Suggestion] Add constants for SVG, and MathML namespaces #6711

Jamesernator opened this issue May 23, 2021 · 4 comments

Comments

@Jamesernator
Copy link

Jamesernator commented May 23, 2021

Not sure if HTML or DOM spec is better for this, but I've put it here as SVG/MathML integration is primarily specced in HTML.

Currently when dealing with SVG and MathML in the DOM one needs to use .createElementNS, however it's often a bit of a pain to remember the exact url for these namespaces, and what often winds up happening is a bunch of these constants wind up floating around everywhere.

As both of these namespaces have behaviour within browsers, it would be nice to expose them as constants so that they can be referred to in a more uniform way.

Given that both elements and attributes can have namespaces, I'd imagine putting these constants on Node e.g.:

const rect = document.createElementNS(Node.SVG_NS, "rect");
const attr = document.createAttributeNS(Node.SVG_NS, "x");

const msub = document.createElementNS(Node.MATH_NS, "msub");
const mathVariant = document.createAttributeNS(Node.MATH_NS, "mathvariant");

Open Question: Also add constant for HTML namespace for consistency? (Any others?)

@annevk
Copy link
Member

annevk commented May 25, 2021

See whatwg/dom#311. At this point I would rather pursue new creation APIs that simplify this somewhat. There's also no precedence for using constants for strings that I know of, the strings themselves are the constant.

@domenic
Copy link
Member

domenic commented May 25, 2021

Indeed, exposing the constants seems like a really indirect way of accomplishing the use case here (remember step 1).

@Jamesernator
Copy link
Author

Indeed, exposing the constants seems like a really indirect way of accomplishing the use case here (remember step 1).

This is fair, the main use case I was thinking was "I need a way to more easily get these namespace strings" (hence constants really being the solution). But yes better creation APIs would make more sense as the use case is wider in particular I would say the problem is: "mathml/svg elements are currently more cumbersome to construct in comparison to html ones".

In this regard it might be covered more by this issue on DOM. That issue doesn't cover mathml/svg specifically, but I'd imagine whatever solution could be adapted to have entrypoints for MathML/SVG as well.

@annevk
Copy link
Member

annevk commented Jun 12, 2021

Indeed, let's dupe it into that for now.

@annevk annevk closed this as completed Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants