fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
3 lines (2 loc) • 1.25 kB
JavaScript
import{svgNS as t}from"./constants.min.mjs";import{getMultipleNodes as e}from"./getMultipleNodes.min.mjs";import{applyViewboxTransform as n}from"./applyViewboxTransform.min.mjs";function r(r){const i=e(r,["use","svg:use"]);let o=0;for(;i.length&&o<i.length;){const e=i[o],s=e.getAttribute("xlink:href")||e.getAttribute("href");if(null===s)return;const l=s.slice(1),m=e.getAttribute("x")||0,u=e.getAttribute("y")||0,f=r.getElementById(l);if(null===f)return;let a=f.cloneNode(!0),c=(a.getAttribute("transform")||"")+" translate("+m+", "+u+")";const d=i.length,g=t;if(n(a),/^svg$/i.test(a.nodeName)){const t=a.ownerDocument.createElementNS(g,"g");for(let e=0,n=a.attributes,r=n.length;e<r;e++){const r=n.item(e);r&&t.setAttributeNS(g,r.nodeName,r.nodeValue)}for(;a.firstChild;)t.appendChild(a.firstChild);a=t}for(let t=0,n=e.attributes,r=n.length;t<r;t++){const e=n.item(t);if(!e)continue;const{nodeName:r,nodeValue:i}=e;"x"!==r&&"y"!==r&&"xlink:href"!==r&&"href"!==r&&("transform"===r?c=i+" "+c:a.setAttribute(r,i))}a.setAttribute("transform",c),a.setAttribute("instantiated_by_use","1"),a.removeAttribute("id");e.parentNode.replaceChild(a,e),i.length===d&&o++}}export{r as parseUseDirectives};
//# sourceMappingURL=parseUseDirectives.min.mjs.map