-
Notifications
You must be signed in to change notification settings - Fork 378
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
Adding support for ShadowDOM features in SVG #942
Comments
I presume it is a sh*load of Namespace issues. It looks like Vue has a ApplyNS function; no experience with it. I have faked "slots" with: <div>
<svg>
<circle cx="50%" cy="50%" r="35%" fill="yellow" slot="content"></circle>
<circle cx="50%" cy="50%" r="15%" fill="green" slot="content"></circle>
</svg>
</div>
<script>
const host = document.querySelector('div');
const root = host.attachShadow({mode:'open'});
root.innerHTML = `
<svg viewBox="0 0 100 100">
<rect width="100%" height="100%" fill="blue"/>
<slot name="content"/>
</svg>`;
root.querySelectorAll('slot').forEach(shadowSlot => {
let name = shadowSlot.getAttribute("name");
let slotFragment = new DocumentFragment();
slotFragment.append(...host.querySelectorAll(`[slot="${name}"]`));
shadowSlot.replaceWith(slotFragment);
});
</script> See: https://jsfiddle.net/WebComponents/d7xp5noq/ But since it moves lightDOM content it certainly is not a Polyfill. For Web Component users that In the <pie-chart> Web Component I did for Dev.to <pie-chart>
<slice size="90" stroke="green">HTML</slice>
<slice size="1" stroke="red">JavaScript</slice>
<slice size="9" stroke="blue">CSS</slice>
</pie-chart> This is code end-users understand; |
this seems to be related: #6226 Anyway, the response I've got is:
|
I dislike the namespace stuff. If only svg were merely a subset of html. It currently hampers the dev experience. A No way to fix it? (Although that would be a whole other discussion.) |
I think at least something like the following, f.e. distributing SVG content to a slot element inside SVG markup, should be possible:
codepen example
Although the composition actually works (notice in the element inspector in Chrome that the
SVGRectElement
<rect>
instance is in fact composed to the<svg>
element, and the<slot>
that is inside of the<svg>
element does have the<rect>
as anassignedNode
. However the rectangle does not appear on screen, although the composition mechanics are in place and functioning.The ability to compose non-HTMLElement elements like this would be nice. Non-web-component frameworks don't have this limitation when composing from a higher tree to a lower tree.
What's the plan for composition with SVG?
The text was updated successfully, but these errors were encountered: