UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

3 lines (2 loc) 1.39 kB
import{svgNS as t}from"./constants.min.mjs";import{getMultipleNodes as e}from"./getMultipleNodes.min.mjs";import{applyViewboxTransform as n}from"./applyViewboxTransform.min.mjs";import{parseStyleString as r}from"./parseStyleString.min.mjs";function o(o){const s=e(o,["use","svg:use"]),i=["x","y","xlink:href","href","transform"];for(const e of s){const s=e.attributes,a={};for(const t of s)t.value&&(a[t.name]=t.value);const f=(a["xlink:href"]||a.href||"").slice(1);if(""===f)return;const m=o.getElementById(f);if(null===m)return;let c=m.cloneNode(!0);const l=c.attributes,u={};for(const t of l)t.value&&(u[t.name]=t.value);const{x:p=0,y:b=0,transform:d=""}=a,j=`${d} ${u.transform||""} translate(${p}, ${b})`;if(n(c),/^svg$/i.test(c.nodeName)){const e=c.ownerDocument.createElementNS(t,"g");Object.entries(u).forEach(n=>{let[r,o]=n;return e.setAttributeNS(t,r,o)}),e.append(...c.childNodes),c=e}for(const t of s){if(!t)continue;const{name:e,value:n}=t;if(!i.includes(e))if("style"===e){const t={};r(n,t),Object.entries(u).forEach(e=>{let[n,r]=e;t[n]=r}),r(u.style||"",t);const o=Object.entries(t).map(t=>t.join(":")).join(";");c.setAttribute(e,o)}else!u[e]&&c.setAttribute(e,n)}c.setAttribute("transform",j),c.setAttribute("instantiated_by_use","1"),c.removeAttribute("id"),e.parentNode.replaceChild(c,e)}}export{o as parseUseDirectives}; //# sourceMappingURL=parseUseDirectives.min.mjs.map