1 |
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.TinySVG={})}(this,function(e){"use strict";function r(e,t){if(e.ownerDocument!==t.ownerDocument)try{return t.ownerDocument.importNode(e,!0)}catch(e){}return e}function a(e,t){return t.appendChild(r(e,t))}var o=2,s={"alignment-baseline":1,"baseline-shift":1,clip:1,"clip-path":1,"clip-rule":1,color:1,"color-interpolation":1,"color-interpolation-filters":1,"color-profile":1,"color-rendering":1,cursor:1,direction:1,display:1,"dominant-baseline":1,"enable-background":1,fill:1,"fill-opacity":1,"fill-rule":1,filter:1,"flood-color":1,"flood-opacity":1,font:1,"font-family":1,"font-size":o,"font-size-adjust":1,"font-stretch":1,"font-style":1,"font-variant":1,"font-weight":1,"glyph-orientation-horizontal":1,"glyph-orientation-vertical":1,"image-rendering":1,kerning:1,"letter-spacing":1,"lighting-color":1,marker:1,"marker-end":1,"marker-mid":1,"marker-start":1,mask:1,opacity:1,overflow:1,"pointer-events":1,"shape-rendering":1,"stop-color":1,"stop-opacity":1,stroke:1,"stroke-dasharray":1,"stroke-dashoffset":1,"stroke-linecap":1,"stroke-linejoin":1,"stroke-miterlimit":1,"stroke-opacity":1,"stroke-width":o,"text-anchor":1,"text-decoration":1,"text-rendering":1,"unicode-bidi":1,visibility:1,"word-spacing":1,"writing-mode":1};function c(e,t,r){var n=t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),i=s[n];i?(i===o&&"number"==typeof r&&(r=String(r)+"px"),e.style[n]=r):e.setAttributeNS(null,t,r)}function n(e,t,r){if("string"==typeof t){if(void 0===r)return n=e,s[i=t]?n.style[i]:n.getAttributeNS(null,i);c(e,t,r)}else!function(e,t){var r,n,i=Object.keys(t);for(r=0;n=i[r];r++)c(e,n,t[n])}(e,t);var n,i;return e}function i(e,t){if(e.indexOf)return e.indexOf(t);for(var r=0;r<e.length;++r)if(e[r]===t)return r;return-1}var t=/\s+/,l=Object.prototype.toString;function u(e){return void 0!==e}function f(e){if(!e||!e.nodeType)throw new Error("A DOM element reference is required");this.el=e,this.list=e.classList}function h(e){var t=e.parentNode;return t&&t.removeChild(e),e}function p(e){for(var t;t=e.firstChild;)h(t);return e}f.prototype.add=function(e){if(this.list)return this.list.add(e),this;var t=this.array();return~i(t,e)||t.push(e),u(this.el.className.baseVal)?this.el.className.baseVal=t.join(" "):this.el.className=t.join(" "),this},f.prototype.remove=function(e){if("[object RegExp]"===l.call(e))return this.removeMatching(e);if(this.list)return this.list.remove(e),this;var t=this.array(),r=i(t,e);return~r&&t.splice(r,1),this.el.className.baseVal=t.join(" "),this},f.prototype.removeMatching=function(e){for(var t=this.array(),r=0;r<t.length;r++)e.test(t[r])&&this.remove(t[r]);return this},f.prototype.toggle=function(e,t){return this.list?u(t)?t!==this.list.toggle(e,t)&&this.list.toggle(e):this.list.toggle(e):u(t)?t?this.add(e):this.remove(e):this.has(e)?this.remove(e):this.add(e),this},f.prototype.array=function(){var e=(this.el.getAttribute("class")||"").replace(/^\s+|\s+$/g,"").split(t);return""===e[0]&&e.shift(),e},f.prototype.has=f.prototype.contains=function(e){return this.list?this.list.contains(e):!!~i(this.array(),e)};var d={svg:"http://www.w3.org/2000/svg"},m='<svg xmlns="'+d.svg+'"';function g(e){var t=!1;"<svg"===e.substring(0,4)?-1===e.indexOf(d.svg)&&(e=m+e.substring(4)):(e=m+">"+e+"</svg>",t=!0);var r,n,i=(r=e,(n=new DOMParser).async=!1,n.parseFromString(r,"text/xml"));if(!t)return i;for(var o=document.createDocumentFragment(),a=i.firstChild;a.firstChild;)o.appendChild(a.firstChild);return o}function v(e,t){var r;return r="<"===e.charAt(0)?(r=g(e).firstChild,document.importNode(r,!0)):document.createElementNS(d.svg,e),t&&n(r,t),r}var y=v("svg");function b(e,t){var r,n,i=Object.keys(t);for(r=0;n=i[r];r++)e[n]=t[n];return e}var w=/([&<>]{1})/g,x=/([\n\r"]{1})/g,k={"&":"&","<":"<",">":">",'"':"'"};function N(e,t){return e.replace(t,function(e,t){return k[t]||t})}function S(e,t){var r,n,i,o,a;switch(e.nodeType){case 3:t.push(N(e.textContent,w));break;case 1:if(t.push("<",e.tagName),e.hasAttributes())for(r=0,n=(i=e.attributes).length;r<n;++r)o=i.item(r),t.push(" ",o.name,'="',N(o.value,x),'"');if(e.hasChildNodes()){for(t.push(">"),r=0,n=(a=e.childNodes).length;r<n;++r)S(a.item(r),t);t.push("</",e.tagName,">")}else t.push("/>");break;case 8:t.push("\x3c!--",N(e.nodeValue,w),"--\x3e");break;case 4:t.push("<![CDATA[",e.nodeValue,"]]>");break;default:throw new Error("unable to handle node "+e.nodeType)}return t}function C(e,t){var r=g(t);if(p(e),t){"#document-fragment"!==r.nodeName&&(r=r.documentElement);for(var n,i=(n=r.childNodes,Array.prototype.slice.call(n)),o=0;o<i.length;o++)a(i[o],e)}}function V(e,t){return t.insertBefore(r(e,t),t.firstChild||null)}e.append=function(e,t){return a(t,e),e},e.appendTo=a,e.attr=n,e.classes=function(e){return new f(e)},e.clear=p,e.clone=function(e){return e.cloneNode(!0)},e.create=v,e.innerSVG=function(e,t){if(void 0===t)return function(e){for(var t=e.firstChild,r=[];t;)S(t,r),t=t.nextSibling;return r.join("")}(e);try{C(e,t)}catch(e){throw new Error("error parsing SVG: "+e.message)}return e},e.prepend=function(e,t){return V(t,e),e},e.prependTo=V,e.remove=h,e.replace=function(e,t){return e.parentNode.replaceChild(r(t,e),e),t},e.transform=function(e,t){var r=e.transform.baseVal;return t&&(Array.isArray(t)||(t=[t]),function(e,t){var r,n,i,o;for(e.clear(),r=0;n=t[r];r++)e.appendItem((i=e,(o=n)instanceof SVGMatrix?i.createSVGTransformFromMatrix(o):o))}(r,t)),r.consolidate()},e.on=function(e,t,r,n){e.addEventListener(t,r,n)},e.off=function(e,t,r,n){e.removeEventListener(t,r,n)},e.createPoint=function(e,t){var r=y.createSVGPoint();switch(arguments.length){case 0:return r;case 2:e={x:e,y:t}}return b(r,e)},e.createMatrix=function(e,t,r,n,i,o){var a=y.createSVGMatrix();switch(arguments.length){case 0:return a;case 1:return b(a,e);case 6:return b(a,{a:e,b:t,c:r,d:n,e:i,f:o})}},e.createTransform=function(e){return e?y.createSVGTransformFromMatrix(e):y.createSVGTransform()},e.select=function(e,t){return e.querySelector(t)},e.selectAll=function(e,t){var r=e.querySelectorAll(t);return[].map.call(r,function(e){return e})},Object.defineProperty(e,"__esModule",{value:!0})});
|