SVG support (Namespace Element support) #27
Replies: 8 comments 20 replies
-
Perhaps ship with a Line 49 in 3f98060 |
Beta Was this translation helpful? Give feedback.
-
Yes. SVG support can be considered. I'm not familiar with native API for creating SVG elements. Could you please share a piece of code with native API and I will think through how to extend VanJS to support it. |
Beta Was this translation helpful? Give feedback.
-
I got curious and looked up how SolidJS implemented their SVG support. SolidJS internalsThey use a constant for the namespace string Exhaustive list of valid SVG elementsTo make the difference between HTML and SVG elements invisible to the user they maintain an exhaustive list of SVG/HTML element names, which they import from a third-party package maintained by the SolidJS creator, I'm not suggesting we follow in SolidJS's footsteps, too much memory overhead. I'd like to point out my latest proposal contains no breaking changes since |
Beta Was this translation helpful? Give feedback.
-
How about we remove a layer of indirection in the spirit of the current Van API? const { div } = van.tags
const { svg, circle } = van.svgs Just a thought, easier to remember I think, and is less code than my previous idea. |
Beta Was this translation helpful? Give feedback.
-
@Tao-VanJS what do I need to do next to get SVG support over the line? |
Beta Was this translation helpful? Give feedback.
-
FYI, SVG (and MathML or other HTML elements with |
Beta Was this translation helpful? Give feedback.
-
Is there a way to read SVG or raw HTML tags without having to convert it to a function? |
Beta Was this translation helpful? Give feedback.
-
@Ashvith10 You might want to give this a try? For now npm install vite-plugin-vanjs-svg |
Beta Was this translation helpful? Give feedback.
-
SVG has a slightly different DOM API for element creation than ordinary DOM elements. Referred to as "namespace" elements in the spec (https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS)
I noticed while trying to add icons to an app using VanJS that the element in the devtools
<svg width="100" ...><circle cx="50" ...></circle></svg>
while visually identical to the namespace element didn't render on my page.Would it be possible to add support for SVG in VanJS without sacrificing the amazing developer experience?
Either switch to
createElementNS
for known namespace tags, e.g.path, p, circle
etc. or allow users to opt-in somehow?Beta Was this translation helpful? Give feedback.
All reactions