UNPKG

g2o-svg

Version:
3 lines (2 loc) 4.27 kB
System.register(["g2o"],(function(e){"use strict";var t,n,r,o;return{setters:[function(e){t=e.Commands,n=e.G20,r=e.TreeView,o=e.GraphicsBoard}],execute:function(){e("initBoard",(function(e,t={}){const n=new c(window.document),r=new d;return new o(e,n,r,new y,t)}));class c{doc;constructor(e){this.doc=e}addEventListener(e,t,n){e.addEventListener(t,n)}appendChild(e,t){e.appendChild(t)}getAttribute(e,t){return e.getAttribute(t)}getBoundingClientRect(e){return e.getBoundingClientRect()}getElementById(e){return document.getElementById(e)}isDocumentBody(e){return e===document.body}removeEventListener(e,t,n){e.removeEventListener(t,n)}}function s(e,t){for(;e<0;)e+=t;return e%t}const i=Math.floor;function l(e){return i(1e6*e)/1e6}const u="http://www.w3.org/1999/xlink";function a(e,t){const n=t,r=Object.keys(t);for(let t=0;t<r.length;t++){const o=r[t],c=n[o];/href/.test(r[t])?e.setAttributeNS(u,o,c):e.setAttribute(o,c)}}class d{downcast(e){if(e instanceof SVGElement)return e;throw new Error("element is not an SVGElement")}createSVGElement(e,t={}){return function(e,t={}){const n=document.createElementNS("http://www.w3.org/2000/svg",e);return t&&Object.keys(t).length>0&&a(n,t),n}(e,t)}setAttribute(e,t,n){e.setAttribute(t,n)}setAttributes(e,t){a(e,t)}removeAttribute(e,t){e.removeAttribute(t)}removeAttributes(e,t){m.removeAttributes(e,t)}appendChild(e,t){e.appendChild(t)}removeChild(e,t){e.removeChild(t)}setTextContent(e,t){e.textContent=t}getParentNode(e){return e.parentNode}getLastChild(e){return e.lastChild}getElementDefs(e){return function(e){const t=e.children,n=t.length;for(let e=0;e<n;e++){const n=t.item(e);if(n instanceof SVGDefsElement)return n}throw new Error}(e)}setStyle(e,t,n){e.style[t]=n}}e("SVGViewDOM",d);const m={ns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",createElement:function(e,t={}){const n=document.createElementNS(m.ns,e);return t&&Object.keys(t).length>0&&m.setAttributes(n,t),n},setAttributes:function(e,t){const n=t,r=Object.keys(t);for(let t=0;t<r.length;t++){const o=r[t],c=n[o];/href/.test(r[t])?e.setAttributeNS(m.xlink,o,c):e.setAttribute(o,c)}return this},removeAttributes:function(e,t){if(e){for(const n in t)e.removeAttribute(n);return this}throw new Error("elem MUST be defined.")},path_from_anchors:function(e,r,o,c,i){const[u,a]=function(e){return e.goofy?e.crazy?[(e,t)=>t,(e,t)=>e]:[(e,t)=>e,(e,t)=>t]:e.crazy?[(e,t)=>e,(e,t)=>t]:[(e,t)=>t,(e,t)=>e]}(e),d=c.length,m=d-1;let y,f="";for(let e=0;e<d;e++){const r=c[e],o=c[i?s(e-1,d):Math.max(e-1,0)];let h,x,g,w,p,v,b,E,A,C,S,k,z,V,G,B=l(u(r.x,r.y)),N=l(a(r.x,r.y));switch(r.command){case t.close:h=t.close;break;case t.arc:S=r.rx,k=r.ry,z=r.xAxisRotation,V=r.largeArcFlag,G=r.sweepFlag,h=t.arc+" "+S+" "+k+" "+z+" "+V+" "+G+" "+B+" "+N;break;case t.curve:b=o.controls&&o.controls.b||n.zero,E=r.controls&&r.controls.a||n.zero,o.relative?(g=l(u(b.x+o.x,b.y+o.y)),w=l(a(b.x+o.x,b.y+o.y))):(g=l(u(b.x,b.y)),w=l(a(b.x,b.y))),r.relative?(p=l(u(E.x+r.x,E.y+r.y)),v=l(a(E.x+r.x,E.y+r.y))):(p=l(u(E.x,E.y)),v=l(a(E.x,E.y))),h=(0===e?t.move:t.curve)+" "+g+" "+w+" "+p+" "+v+" "+B+" "+N;break;case t.move:y=r,h=t.move+" "+B+" "+N;break;default:h=r.command+" "+B+" "+N}e>=m&&i&&(r.command===t.curve&&(x=y,A=r.controls&&r.controls.b||r,C=x.controls&&x.controls.a||x,r.relative?(g=l(u(A.x+r.x,A.y+r.y)),w=l(a(A.x+r.x,A.y+r.y))):(g=l(u(A.x,A.y)),w=l(a(A.x,A.y))),x.relative?(p=l(u(C.x+x.x,C.y+x.y)),v=l(a(C.x+x.x,C.y+x.y))):(p=l(u(C.x,C.y)),v=l(a(C.x,C.y))),B=l(u(x.x,x.y)),N=l(a(x.x,x.y)),h+=" C "+g+" "+w+" "+p+" "+v+" "+B+" "+N),r.command!==t.close&&(h+=" Z")),f+=h+" "}return f},getClip:function(e,t,n){let r=t.zzz.svgClipPathElement;return r||(r=t.zzz.svgClipPathElement=e.createSVGElement("clipPath",{"clip-rule":"nonzero"})),null===e.getParentNode(r)&&e.appendChild(e.getElementDefs(n),r),r},defs:{update:function(e,t){if(function(e){return e._flagUpdate}(t)){const n=Array.prototype.slice.call(t.children,0);for(let r=0;r<n.length;r++){const o=n[r],c=o.id,s=`[fill="url(#${c})"],[stroke="url(#${c})"],[clip-path="url(#${c})"]`;e.querySelector(s)||t.removeChild(o)}!function(e,t){e._flagUpdate=t}(t,!1)}}}};class y{constructor(){}createView(e,t){const n=new d;return new r(n,e,t)}}e("SVGViewFactory",y)}}})); //# sourceMappingURL=index.min.js.map