I'm currently tackling a project involving Angular Elements. Within this specialized component, my goal is to incorporate SVG.js 3+.
However, due to the necessity of utilizing ViewEncapsulation.ShadowDom
in my component, I am encountering challenges when initializing SVG.js.
The typical procedure for creating an SVG and drawing a rectangle would go something like this:
this.draw = SVG().addTo("#SVGContainer").viewbox(0, 0, 300, 140);
this.draw.rect(100, 100).move(100, 50).fill('#f06')
The issue lies in the fact that
.addTo("#SVGContainer")
can only detect elements that are not within the shadow-root. I conducted tests with both components using shadow-root and those without. As expected, SVG.js functioned properly in the Angular Project without Shadow Dom but failed in the Project integrated with shadow-root.
I am aware that using
container.shadowRoot.querySelector(".test").innerHTML
enables access to shadow elements. However, the .addTo()
method restricts me to passing the ID of the element, thus preventing direct transmission of the DOM element itself.
Due to the mandatory inclusion of ViewEncapsulation.ShadowDom
in my new custom web component, I am left pondering whether it is feasible to pass shadow-dom elements to SVG.js or if this remains an insurmountable obstacle.