-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlengthy-svg.min.js
1 lines (1 loc) · 1.25 KB
/
lengthy-svg.min.js
1
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Lengthy=e()}(this,function(){"use strict";function t(t){return o(t).map(function(t,e){var n=i(t);return t.classList.add("lengthy"),t.style.setProperty("--path-length",n),{el:t,length:n}})}function e(t){return void 0!==(t=t||0).value?t.value:t.baseVal?e(t.baseVal):t}function n(t,e,n,r){var i=t-n,o=e-r;return Math.sqrt(i*i+o*o)}function r(t,e){return Math.PI*(3*(t+e)-Math.sqrt((3*t+e)*(t+3*e)))}function i(t){if(!t)return!1;if(t.getTotalLength)return t.getTotalLength();if(t instanceof SVGUseElement)return i(document.querySelector(e(t.href)));if(t.width||t.height||t.rx||t.ry){var o=e(t.width),u=e(t.height),a=e(t.rx),f=e(t.ry);return o||u?2*(o+u-2*((a=Math.min(a,o/2))+(f=Math.min(f,u/2))))+(a||f?r(a,f):0):r(a,f)}if(t.x1)return n(e(t.x1),e(t.y1),e(t.x2),e(t.y2));if(t.r)return 2*Math.PI*e(t.r);if(t.points){for(var l=t.getAttribute("points").split(/[\s,]+/),h=0,s=0,c=l.length-2;s<c;s+=2)h+=n(l[s],l[s+1],l[s+2],l[s+3]);return t instanceof SVGPolygonElement&&(h+=n(l[s],l[s+1],l[0],l[1])),h}return!1}function o(t,e){return Array.prototype.slice.call(t.nodeName?[t]:t[0].nodeName?t:document.querySelectorAll(t),0)}return t.getLength=i,t.$=o,t});