jointjs
Version:
JavaScript diagramming library
8 lines (6 loc) • 94.3 kB
JavaScript
/*! JointJS v3.7.7 (2023-11-07) - JavaScript diagramming library
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
if(function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).V=n()}(this,function(){"use strict";var e=Math.round,r=Math.floor,i=Math.PI,h=function(t){return t%360+(t<0?360:0)},s=function(t,n){return n*e(t/n)},c=function(t){return 180*t/i%360},l=function(t,n){return(t=(n=n||!1)?t:t%360)*i/180},o=function(t,n){if(void 0===n)n=void 0===t?1:t,t=0;else if(n<t){var e=t;t=n,n=e}return r(Math.random()*(n-t+1)+t)},f=Math.cos,d=Math.sin,g=Math.atan2,n=function(t,n){var e=l(t.y),r=l(n.y),i=t.x,s=n.x,o=l(s-i),a=d(o)*f(r),h=f(e)*d(r)-d(e)*f(r)*f(o),u=c(g(a,h))-22.5;return u<0&&(u+=360),["NE","E","SE","S","SW","W","NW","N"][u=parseInt(u/45)]},a=function(t,n){var e=t.x,r=t.y;return(e-=n.x)*e+(r-=n.y)*r},u=function(t,n){return Math.sqrt(a(t,n))},v={Point:1,Line:2,Ellipse:3,Rect:4,Polyline:5,Polygon:6,Curve:7,Path:8},p=Math.abs,m=Math.cos,y=Math.sin,x=Math.sqrt,w=Math.min,b=Math.max,S=Math.atan2,P=Math.round,A=Math.pow,T=Math.PI,L=function(t,n){if(!(this instanceof L))return new L(t,n);if("string"==typeof t){var e=t.split(-1===t.indexOf("@")?" ":"@");t=parseFloat(e[0]),n=parseFloat(e[1])}else Object(t)===t&&(n=t.y,t=t.x);this.x=void 0===t?0:t,this.y=void 0===n?0:n};L.fromPolar=function(t,n,e){e=new L(e);var r=p(t*m(n)),i=p(t*y(n)),s=h(c(n));return s<90?i=-i:s<180?(r=-r,i=-i):s<270&&(r=-r),new L(e.x+r,e.y+i)},L.random=function(t,n,e,r){return new L(o(t,n),o(e,r))},L.prototype={type:v.Point,chooseClosest:function(t){var n=t.length;if(1===n)return new L(t[0]);for(var e=null,r=1/0,i=0;i<n;i++){var s=new L(t[i]),o=this.squaredDistance(s);o<r&&(e=s,r=o)}return e},adhereToRect:function(t){return t.containsPoint(this)||(this.x=w(b(this.x,t.x),t.x+t.width),this.y=w(b(this.y,t.y),t.y+t.height)),this},angleBetween:function(t,n){var e=this.equals(t)||this.equals(n)?NaN:this.theta(n)-this.theta(t);return e<0&&(e+=360),e},bearing:function(t){return n(this,t)},changeInAngle:function(t,n,e){return this.clone().offset(-t,-n).theta(e)-this.theta(e)},clone:function(){return new L(this)},cross:function(t,n){return t&&n?(n.x-this.x)*(t.y-this.y)-(n.y-this.y)*(t.x-this.x):NaN},difference:function(t,n){return Object(t)===t&&(n=t.y,t=t.x),new L(this.x-(t||0),this.y-(n||0))},distance:function(t){return u(this,t)},dot:function(t){return t?this.x*t.x+this.y*t.y:NaN},equals:function(t){return!!t&&this.x===t.x&&this.y===t.y},lerp:function(t,n){var e=this.x,r=this.y;return new L((1-n)*e+n*t.x,(1-n)*r+n*t.y)},magnitude:function(){return x(this.x*this.x+this.y*this.y)||.01},manhattanDistance:function(t){return p(t.x-this.x)+p(t.y-this.y)},move:function(t,n){var e=l(new L(t).theta(this));return this.offset(m(e)*n,-y(e)*n)},normalize:function(t){var n=(t||1)/this.magnitude();return this.scale(n,n)},offset:function(t,n){return Object(t)===t&&(n=t.y,t=t.x),this.x+=t||0,this.y+=n||0,this},reflection:function(t){return new L(t).move(this,this.distance(t))},rotate:function(t,n){if(0===n)return this;t=t||new L(0,0),n=l(h(-n));var e=m(n),r=y(n),i=e*(this.x-t.x)-r*(this.y-t.y)+t.x,s=r*(this.x-t.x)+e*(this.y-t.y)+t.y;return this.x=i,this.y=s,this},round:function(t){var n=1;if(t)switch(t){case 1:n=10;break;case 2:n=100;break;case 3:n=1e3;break;default:n=A(10,t)}return this.x=P(this.x*n)/n,this.y=P(this.y*n)/n,this},scale:function(t,n,e){return e=e&&new L(e)||new L(0,0),this.x=e.x+t*(this.x-e.x),this.y=e.y+n*(this.y-e.y),this},snapToGrid:function(t,n){return this.x=s(this.x,t),this.y=s(this.y,n||t),this},squaredDistance:function(t){return a(this,t)},theta:function(t){var n=-((t=new L(t)).y-this.y),e=t.x-this.x,r=S(n,e);return r<0&&(r=2*T+r),180*r/T},toJSON:function(){return{x:this.x,y:this.y}},toPolar:function(t){t=t&&new L(t)||new L(0,0);var n=this.x,e=this.y;return this.x=x((n-t.x)*(n-t.x)+(e-t.y)*(e-t.y)),this.y=l(t.theta(new L(n,e))),this},toString:function(){return this.x+"@"+this.y},serialize:function(){return this.x+","+this.y},update:function(t,n){return Object(t)===t&&(n=t.y,t=t.x),this.x=t||0,this.y=n||0,this},vectorAngle:function(t){return new L(0,0).angleBetween(this,t)}},L.prototype.translate=L.prototype.offset;var t=L,E=Math.max,C=Math.min,N=function(t,n){return this instanceof N?t instanceof N?new N(t.start,t.end):(this.start=new L(t),void(this.end=new L(n))):new N(t,n)};N.prototype={type:v.Line,angle:function(){var t=new L(this.start.x+1,this.start.y);return this.start.angleBetween(this.end,t)},bbox:function(){var t=C(this.start.x,this.end.x),n=C(this.start.y,this.end.y),e=E(this.start.x,this.end.x),r=E(this.start.y,this.end.y);return new B(t,n,e-t,r-n)},bearing:function(){return n(this.start,this.end)},clone:function(){return new N(this.start,this.end)},closestPoint:function(t){return this.pointAt(this.closestPointNormalizedLength(t))},closestPointLength:function(t){return this.closestPointNormalizedLength(t)*this.length()},closestPointNormalizedLength:function(t){var n=this.vector().dot(new N(this.start,t).vector()),e=C(1,E(0,n/this.squaredLength()));return e!=e?0:e},closestPointTangent:function(t){return this.tangentAt(this.closestPointNormalizedLength(t))},containsPoint:function(t){var n=this.start,e=this.end;if(0!==n.cross(t,e))return!1;var r=this.length();return!(new N(n,t).length()>r)&&!(new N(t,e).length()>r)},divideAt:function(t){var n=this.pointAt(t);return[new N(this.start,n),new N(n,this.end)]},divideAtLength:function(t){var n=this.pointAtLength(t);return[new N(this.start,n),new N(n,this.end)]},equals:function(t){return!!t&&this.start.x===t.start.x&&this.start.y===t.start.y&&this.end.x===t.end.x&&this.end.y===t.end.y},intersect:function(t,n){if(t&&t.intersectionWithLine){var e=t.intersectionWithLine(this,n);return e&&t instanceof N&&(e=e[0]),e}return null},intersectionWithLine:function(t){var n=new L(this.end.x-this.start.x,this.end.y-this.start.y),e=new L(t.end.x-t.start.x,t.end.y-t.start.y),r=n.x*e.y-n.y*e.x,i=new L(t.start.x-this.start.x,t.start.y-this.start.y),s=i.x*e.y-i.y*e.x,o=i.x*n.y-i.y*n.x;if(0===r||s*r<0||o*r<0)return null;if(0<r){if(r<s||r<o)return null}else if(s<r||o<r)return null;return[new L(this.start.x+s*n.x/r,this.start.y+s*n.y/r)]},isDifferentiable:function(){return!this.start.equals(this.end)},length:function(){return u(this.start,this.end)},midpoint:function(){return new L((this.start.x+this.end.x)/2,(this.start.y+this.end.y)/2)},parallel:function(t){var n=this.clone();if(!this.isDifferentiable())return n;var e=n.start,r=n.end,i=e.clone().rotate(r,270),s=r.clone().rotate(e,90);return e.move(s,t),r.move(i,t),n},pointAt:function(t){var n=this.start,e=this.end;return t<=0?n.clone():1<=t?e.clone():n.lerp(e,t)},pointAtLength:function(t){var n=this.start,e=this.end,r=!0;t<0&&(r=!1,t=-t);var i=this.length();return i<=t?r?e.clone():n.clone():this.pointAt((r?t:i-t)/i)},pointOffset:function(t){t=new L(t);var n=this.start,e=this.end;return((e.x-n.x)*(t.y-n.y)-(e.y-n.y)*(t.x-n.x))/this.length()},rotate:function(t,n){return this.start.rotate(t,n),this.end.rotate(t,n),this},round:function(t){return this.start.round(t),this.end.round(t),this},scale:function(t,n,e){return this.start.scale(t,n,e),this.end.scale(t,n,e),this},setLength:function(t){var n=this.length();if(!n)return this;var e=t/n;return this.scale(e,e,this.start)},squaredLength:function(){return a(this.start,this.end)},tangentAt:function(t){if(!this.isDifferentiable())return null;var n=this.start,e=this.end,r=this.pointAt(t),i=new N(n,e);return i.translate(r.x-n.x,r.y-n.y),i},tangentAtLength:function(t){if(!this.isDifferentiable())return null;var n=this.start,e=this.end,r=this.pointAtLength(t),i=new N(n,e);return i.translate(r.x-n.x,r.y-n.y),i},toString:function(){return this.start.toString()+" "+this.end.toString()},serialize:function(){return this.start.serialize()+" "+this.end.serialize()},translate:function(t,n){return this.start.translate(t,n),this.end.translate(t,n),this},vector:function(){return new L(this.end.x-this.start.x,this.end.y-this.start.y)}},N.prototype.intersection=N.prototype.intersect;var I=N,M=Math.sqrt,R=Math.round,O=Math.pow,D=function(t,n,e){return this instanceof D?t instanceof D?new D(new L(t.x,t.y),t.a,t.b):(t=new L(t),this.x=t.x,this.y=t.y,this.a=n,void(this.b=e)):new D(t,n,e)};D.fromRect=function(t){return t=new B(t),new D(t.center(),t.width/2,t.height/2)},D.prototype={type:v.Ellipse,bbox:function(){return new B(this.x-this.a,this.y-this.b,2*this.a,2*this.b)},center:function(){return new L(this.x,this.y)},clone:function(){return new D(this)},containsPoint:function(t){return this.normalizedDistance(t)<=1},equals:function(t){return!!t&&t.x===this.x&&t.y===this.y&&t.a===this.a&&t.b===this.b},inflate:function(t,n){return void 0===t&&(t=0),void 0===n&&(n=t),this.a+=2*t,this.b+=2*n,this},intersectionWithLine:function(t){var n=[],e=t.start,r=t.end,i=this.a,s=this.b,o=t.vector(),a=e.difference(new L(this)),h=new L(o.x/(i*i),o.y/(s*s)),u=new L(a.x/(i*i),a.y/(s*s)),c=o.dot(h),l=o.dot(u),f=l*l-c*(a.dot(u)-1);if(f<0)return null;if(0<f){var d=M(f),g=(-l-d)/c,v=(-l+d)/c;if((g<0||1<g)&&(v<0||1<v))return null;0<=g&&g<=1&&n.push(e.lerp(r,g)),0<=v&&v<=1&&n.push(e.lerp(r,v))}else{var p=-l/c;if(!(0<=p&&p<=1))return null;n.push(e.lerp(r,p))}return n},intersectionWithLineFromCenterToPoint:function(t,n){t=new L(t),n&&t.rotate(new L(this.x,this.y),n);var e,r=t.x-this.x,i=t.y-this.y;if(0===r)return e=this.bbox().pointNearestToPoint(t),n?e.rotate(new L(this.x,this.y),-n):e;var s=i/r,o=s*s,a=this.a*this.a,h=this.b*this.b,u=M(1/(1/a+o/h)),c=s*(u=r<0?-u:u);return e=new L(this.x+u,this.y+c),n?e.rotate(new L(this.x,this.y),-n):e},normalizedDistance:function(t){var n=t.x,e=t.y,r=this.a,i=this.b,s=this.x,o=this.y;return(n-s)*(n-s)/(r*r)+(e-o)*(e-o)/(i*i)},round:function(t){var n=1;if(t)switch(t){case 1:n=10;break;case 2:n=100;break;case 3:n=1e3;break;default:n=O(10,t)}return this.x=R(this.x*n)/n,this.y=R(this.y*n)/n,this.a=R(this.a*n)/n,this.b=R(this.b*n)/n,this},tangentTheta:function(t){var n,e,r=t.x,i=t.y,s=this.a,o=this.b,a=this.bbox().center(),h=a.x,u=a.y,c=r>a.x+s/2,l=r<a.x-s/2;return c||l?e=s*s/(r-h)-s*s*(i-u)*((n=r>a.x?i-30:i+30)-u)/(o*o*(r-h))+h:n=o*o/(i-u)-o*o*(r-h)*((e=i>a.y?r+30:r-30)-h)/(s*s*(i-u))+u,new L(e,n).theta(t)},toString:function(){return new L(this.x,this.y).toString()+" "+this.a+" "+this.b}};var F=D,q=Math.abs,k=Math.cos,V=Math.sin,z=Math.min,j=Math.max,G=Math.round,W=Math.pow,B=function(t,n,e,r){if(!(this instanceof B))return new B(t,n,e,r);Object(t)===t&&(n=t.y,e=t.width,r=t.height,t=t.x),this.x=void 0===t?0:t,this.y=void 0===n?0:n,this.width=void 0===e?0:e,this.height=void 0===r?0:r};B.fromEllipse=function(t){return t=new D(t),new B(t.x-t.a,t.y-t.b,2*t.a,2*t.b)},B.fromPointUnion=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];if(0===t.length)return null;var e,r,i,s,o=new L;e=r=1/0,i=s=-1/0;for(var a=0;a<t.length;a++){o.update(t[a]);var h=o.x,u=o.y;h<e&&(e=h),i<h&&(i=h),u<r&&(r=u),s<u&&(s=u)}return new B(e,r,i-e,s-r)},B.fromRectUnion=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];if(0===t.length)return null;var e,r,i,s,o=new B;e=r=1/0,i=s=-1/0;for(var a=0;a<t.length;a++){o.update(t[a]);var h=o.x,u=o.y,c=h+o.width,l=u+o.height;h<e&&(e=h),i<c&&(i=c),u<r&&(r=u),s<l&&(s=l)}return new B(e,r,i-e,s-r)},B.prototype={type:v.Rect,bbox:function(t){return this.clone().rotateAroundCenter(t)},rotateAroundCenter:function(t){if(!t)return this;var n=this.width,e=this.height,r=l(t),i=q(V(r)),s=q(k(r)),o=n*s+e*i,a=n*i+e*s;return this.x+=(n-o)/2,this.y+=(e-a)/2,this.width=o,this.height=a,this},bottomLeft:function(){return new L(this.x,this.y+this.height)},bottomLine:function(){return new N(this.bottomLeft(),this.bottomRight())},bottomMiddle:function(){return new L(this.x+this.width/2,this.y+this.height)},center:function(){return new L(this.x+this.width/2,this.y+this.height/2)},clone:function(){return new B(this)},containsPoint:function(t){return t instanceof L||(t=new L(t)),t.x>=this.x&&t.x<=this.x+this.width&&t.y>=this.y&&t.y<=this.y+this.height},containsRect:function(t){var n=new B(this).normalize(),e=new B(t).normalize(),r=n.width,i=n.height,s=e.width,o=e.height;if(!(r&&i&&s&&o))return!1;var a=n.x,h=n.y,u=e.x,c=e.y;return s+=u,r+=a,o+=c,i+=h,a<=u&&s<=r&&h<=c&&o<=i},corner:function(){return new L(this.x+this.width,this.y+this.height)},equals:function(t){var n=new B(this).normalize(),e=new B(t).normalize();return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height},inflate:function(t,n){return void 0===t&&(t=0),void 0===n&&(n=t),this.x-=t,this.y-=n,this.width+=2*t,this.height+=2*n,this},intersect:function(t){var n=this.origin(),e=this.corner(),r=t.origin(),i=t.corner();if(i.x<=n.x||i.y<=n.y||r.x>=e.x||r.y>=e.y)return null;var s=j(n.x,r.x),o=j(n.y,r.y);return new B(s,o,z(e.x,i.x)-s,z(e.y,i.y)-o)},intersectionWithLine:function(t){var n,e,r=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],i=[],s=[],o=r.length;for(e=0;e<o;e++)null!==(n=t.intersect(r[e]))&&s.indexOf(n.toString())<0&&(i.push(n),s.push(n.toString()));return 0<i.length?i:null},intersectionWithLineFromCenterToPoint:function(t,n){t=new L(t);var e,r=new L(this.x+this.width/2,this.y+this.height/2);n&&t.rotate(r,n);for(var i=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],s=new N(r,t),o=i.length-1;0<=o;--o){var a=i[o].intersection(s);if(null!==a){e=a;break}}return e&&n&&e.rotate(r,-n),e},leftLine:function(){return new N(this.topLeft(),this.bottomLeft())},leftMiddle:function(){return new L(this.x,this.y+this.height/2)},maxRectScaleToFit:function(t,n){var e,r,i,s,o,a,h,u;t=new B(t),n||(n=t.center());var c=n.x,l=n.y;e=r=i=s=o=a=h=u=1/0;var f=t.topLeft();f.x<c&&(e=(this.x-c)/(f.x-c)),f.y<l&&(o=(this.y-l)/(f.y-l));var d=t.bottomRight();d.x>c&&(r=(this.x+this.width-c)/(d.x-c)),d.y>l&&(a=(this.y+this.height-l)/(d.y-l));var g=t.topRight();g.x>c&&(i=(this.x+this.width-c)/(g.x-c)),g.y<l&&(h=(this.y-l)/(g.y-l));var v=t.bottomLeft();return v.x<c&&(s=(this.x-c)/(v.x-c)),v.y>l&&(u=(this.y+this.height-l)/(v.y-l)),{sx:z(e,r,i,s),sy:z(o,a,h,u)}},maxRectUniformScaleToFit:function(t,n){var e=this.maxRectScaleToFit(t,n);return z(e.sx,e.sy)},moveAndExpand:function(t){return this.x+=t.x||0,this.y+=t.y||0,this.width+=t.width||0,this.height+=t.height||0,this},normalize:function(){var t=this.x,n=this.y,e=this.width,r=this.height;return this.width<0&&(t=this.x+this.width,e=-this.width),this.height<0&&(n=this.y+this.height,r=-this.height),this.x=t,this.y=n,this.width=e,this.height=r,this},offset:function(t,n){return L.prototype.offset.call(this,t,n)},origin:function(){return new L(this.x,this.y)},pointNearestToPoint:function(t){if(t=new L(t),this.containsPoint(t))switch(this.sideNearestToPoint(t)){case"right":return new L(this.x+this.width,t.y);case"left":return new L(this.x,t.y);case"bottom":return new L(t.x,this.y+this.height);case"top":return new L(t.x,this.y)}return t.adhereToRect(this)},rightLine:function(){return new N(this.topRight(),this.bottomRight())},rightMiddle:function(){return new L(this.x+this.width,this.y+this.height/2)},round:function(t){var n=1;if(t)switch(t){case 1:n=10;break;case 2:n=100;break;case 3:n=1e3;break;default:n=W(10,t)}return this.x=G(this.x*n)/n,this.y=G(this.y*n)/n,this.width=G(this.width*n)/n,this.height=G(this.height*n)/n,this},scale:function(t,n,e){return e=this.origin().scale(t,n,e),this.x=e.x,this.y=e.y,this.width*=t,this.height*=n,this},sideNearestToPoint:function(t){var n=(t=new L(t)).x-this.x,e=this.x+this.width-t.x,r=t.y-this.y,i=n,s="left";return e<i&&(i=e,s="right"),r<i&&(i=r,s="top"),this.y+this.height-t.y<i&&(s="bottom"),s},snapToGrid:function(t,n){var e=this.origin().snapToGrid(t,n),r=this.corner().snapToGrid(t,n);return this.x=e.x,this.y=e.y,this.width=r.x-e.x,this.height=r.y-e.y,this},toJSON:function(){return{x:this.x,y:this.y,width:this.width,height:this.height}},topLine:function(){return new N(this.topLeft(),this.topRight())},topMiddle:function(){return new L(this.x+this.width/2,this.y)},topRight:function(){return new L(this.x+this.width,this.y)},toString:function(){return this.origin().toString()+" "+this.corner().toString()},union:function(t){return B.fromRectUnion(this,t)},update:function(t,n,e,r){return Object(t)===t&&(n=t.y,e=t.width,r=t.height,t=t.x),this.x=t||0,this.y=n||0,this.width=e||0,this.height=r||0,this}},B.prototype.bottomRight=B.prototype.corner,B.prototype.topLeft=B.prototype.origin,B.prototype.translate=B.prototype.offset;var U=B;function H(t){var n=t.trim();if(""===n)return[];for(var e=[],r=n.split(/\b\s*,\s*|,\s*|\s+/),i=r.length,s=0;s<i;s+=2)e.push({x:+r[s],y:+r[s+1]});return e}function Z(t){var n=t.length;if(0===n)return[];for(var e=[],r=0;r<n;r++){var i=t[r].clone();e.push(i)}return e}function Y(t){var n,e,r,i=Math.abs,s=t.length;if(0===s)return[];for(n=0;n<s;n++)void 0===r?r=t[n]:t[n].y<r.y?r=t[n]:t[n].y===r.y&&t[n].x>r.x&&(r=t[n]);var o=[];for(n=0;n<s;n++){var a=r.theta(t[n]);0===a&&(a=360);var h=[t[n],n,a];o.push(h)}if(o.sort(function(t,n){var e=t[2]-n[2];return 0===e&&(e=n[1]-t[1]),e}),2<o.length){var u=o[o.length-1];o.unshift(u)}for(var c,l,f,d,g,v,p,m={},y=[];0!==o.length;)if(l=(c=o.pop())[0],!m.hasOwnProperty(c[0]+"@@"+c[1]))for(var x=!1;!x;)if(y.length<2)y.push(c),x=!0;else{d=(f=y.pop())[0];var w=(v=(g=y.pop())[0]).cross(d,l);if(w<0)y.push(g),y.push(f),y.push(c),x=!0;else if(0===w){var b=d.angleBetween(v,l);i(b-180)<1e-10?(m[f[0]+"@@"+f[1]]=d,y.push(g)):d.equals(l)||v.equals(d)?(m[f[0]+"@@"+f[1]]=d,y.push(g)):i((b+1)%360-1)<1e-10&&(y.push(g),o.push(f))}else m[f[0]+"@@"+f[1]]=d,y.push(g)}2<y.length&&y.pop();var S=-1;for(e=y.length,n=0;n<e;n++){var P=y[n][1];(void 0===p||P<p)&&(p=P,S=n)}var A=[];if(0<S){var T=y.slice(S),L=y.slice(0,S);A=T.concat(L)}else A=y;var E=[];for(e=A.length,n=0;n<e;n++)E.push(A[n][0]);return E}var X=function(t){return this instanceof X?"string"==typeof t?new X.parse(t):void(this.points=Array.isArray(t)?t.map(L):[]):new X(t)};X.parse=function(t){return new X(H(t))},X.fromRect=function(t){return new X([t.topLeft(),t.topRight(),t.bottomRight(),t.bottomLeft(),t.topLeft()])},X.prototype={type:v.Polyline,bbox:function(){var t=1/0,n=-1/0,e=1/0,r=-1/0,i=this.points,s=i.length;if(0===s)return null;for(var o=0;o<s;o++){var a=i[o],h=a.x,u=a.y;h<t&&(t=h),n<h&&(n=h),u<e&&(e=u),r<u&&(r=u)}return new B(t,e,n-t,r-e)},clone:function(){return new X(Z(this.points))},closestPoint:function(t){var n=this.closestPointLength(t);return this.pointAtLength(n)},closestPointLength:function(t){var n,e=this.lengthPoints(),r=e.length;if(0===r)return 0;if(1===r)return 0;for(var i=1/0,s=0,o=r-1,a=0;a<o;a++){var h=new N(e[a],e[a+1]),u=h.length(),c=h.closestPointNormalizedLength(t),l=h.pointAt(c).squaredDistance(t);l<i&&(i=l,n=s+c*u),s+=u}return n},closestPointNormalizedLength:function(t){var n=this.closestPointLength(t);if(0===n)return 0;var e=this.length();return 0===e?0:n/e},closestPointTangent:function(t){var n=this.closestPointLength(t);return this.tangentAtLength(n)},containsPoint:function(t){var n=this.points,e=n.length;if(0===e)return!1;for(var r=t.x,i=t.y,s=e-1,o=0,a=0,h=new N,u=new N,c=new L;o<e;o++){var l=n[s],f=n[o];if(t.equals(l))return!0;if(h.start=l,h.end=f,h.containsPoint(t))return!0;if(i<=l.y&&i>f.y||i>l.y&&i<=f.y){var d=l.x-r>f.x-r?l.x-r:f.x-r;0<=d&&(c.x=r+d,c.y=i,u.start=t,u.end=c,h.intersect(u)&&a++)}s=o}return a%2==1},close:function(){var t=this.start,n=this.end,e=this.points;return t&&n&&!t.equals(n)&&e.push(t.clone()),this},lengthPoints:function(){return this.points},convexHull:function(){return new X(Y(this.points))},equals:function(t){if(!t)return!1;var n=this.points,e=t.points,r=n.length;if(e.length!==r)return!1;for(var i=0;i<r;i++){var s=n[i],o=t.points[i];if(!s.equals(o))return!1}return!0},intersectionWithLine:function(t){for(var n=new N(t),e=[],r=this.lengthPoints(),i=new N,s=0,o=r.length-1;s<o;s++){i.start=r[s],i.end=r[s+1];var a=n.intersectionWithLine(i);a&&e.push(a[0])}return 0<e.length?e:null},isDifferentiable:function(){var t=this.points,n=t.length;if(0===n)return!1;for(var e=new N,r=n-1,i=0;i<r;i++)if(e.start=t[i],e.end=t[i+1],e.isDifferentiable())return!0;return!1},length:function(){var t=this.lengthPoints(),n=t.length;if(0===n)return 0;for(var e=0,r=n-1,i=0;i<r;i++)e+=t[i].distance(t[i+1]);return e},pointAt:function(t){var n=this.lengthPoints(),e=n.length;if(0===e)return null;if(1===e)return n[0].clone();if(t<=0)return n[0].clone();if(1<=t)return n[e-1].clone();var r=this.length()*t;return this.pointAtLength(r)},pointAtLength:function(t){var n=this.lengthPoints(),e=n.length;if(0===e)return null;if(1===e)return n[0].clone();var r=!0;t<0&&(r=!1,t=-t);for(var i=0,s=e-1,o=0;o<s;o++){var a=r?o:s-1-o,h=n[a],u=n[a+1],c=new N(h,u),l=h.distance(u);if(t<=i+l)return c.pointAtLength((r?1:-1)*(t-i));i+=l}return(r?n[e-1]:n[0]).clone()},round:function(t){for(var n=this.points,e=n.length,r=0;r<e;r++)n[r].round(t);return this},scale:function(t,n,e){for(var r=this.points,i=r.length,s=0;s<i;s++)r[s].scale(t,n,e);return this},simplify:function(t){void 0===t&&(t={});var n=this.points;if(n.length<3)return this;for(var e=t.threshold||1e-10,r=0;n[r+2];){var i=r+1,s=r+2,o=n[r],a=n[i],h=n[s];new N(o,h).closestPoint(a).distance(a)<=e?n.splice(i,1):r+=1}return this},tangentAt:function(t){var n=this.lengthPoints().length;if(0===n)return null;if(1===n)return null;t<0&&(t=0),1<t&&(t=1);var e=this.length()*t;return this.tangentAtLength(e)},tangentAtLength:function(t){var n=this.lengthPoints(),e=n.length;if(0===e)return null;if(1===e)return null;var r,i=!0;t<0&&(i=!1,t=-t);for(var s=0,o=e-1,a=0;a<o;a++){var h=i?a:o-1-a,u=n[h],c=n[h+1],l=new N(u,c),f=u.distance(c);if(l.isDifferentiable()){if(t<=s+f)return l.tangentAtLength((i?1:-1)*(t-s));r=l}s+=f}if(r){var d=i?1:0;return r.tangentAt(d)}return null},toString:function(){return this.points+""},translate:function(t,n){for(var e=this.points,r=e.length,i=0;i<r;i++)e[i].translate(t,n);return this},serialize:function(){var t=this.points,n=t.length;if(0===n)return"";for(var e="",r=0;r<n;r++){var i=t[r];e+=i.x+","+i.y+" "}return e.trim()}},Object.defineProperty(X.prototype,"start",{configurable:!0,enumerable:!0,get:function(){return 0===this.points.length?null:this.points[0]}}),Object.defineProperty(X.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.points.length;return 0===t?null:this.points[t-1]}});var J=Math.abs,K=Math.sqrt,Q=Math.min,$=Math.max,_=Math.pow,tt=function(t,n,e,r){return this instanceof tt?t instanceof tt?new tt(t.start,t.controlPoint1,t.controlPoint2,t.end):(this.start=new L(t),this.controlPoint1=new L(n),this.controlPoint2=new L(e),void(this.end=new L(r))):new tt(t,n,e,r)};function nt(t){var n,e,r=arguments,i=[];for(e=arguments.length,n=1;n<e;n++)i.push(r[n]);if(!t)throw new Error("Missing a parent object.");var s=Object.create(t);for(e=i.length,n=0;n<e;n++){var o,a,h=i[n];for(a in h)h.hasOwnProperty(a)&&(delete s[a],o=Object.getOwnPropertyDescriptor(h,a),Object.defineProperty(s,a,o))}return s}tt.throughPoints=function(){function h(t){var n=t.length,e=[],r=[],i=2;e[0]=t[0]/i;for(var s=1;s<n;s++)r[s]=1/i,i=(s<n-1?4:3.5)-r[s],e[s]=(t[s]-e[s-1])/i;for(s=1;s<n;s++)e[n-s-1]-=r[n-s]*e[n-s];return e}return function(t){if(!t||Array.isArray(t)&&t.length<2)throw new Error("At least 2 points are required");for(var n=function(t){var n,e=[],r=[],i=t.length-1;if(1==i)return e[0]=new L((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),r[0]=new L(2*e[0].x-t[0].x,2*e[0].y-t[0].y),[e,r];var s=[];for(n=1;n<i-1;n++)s[n]=4*t[n].x+2*t[n+1].x;s[0]=t[0].x+2*t[1].x,s[i-1]=(8*t[i-1].x+t[i].x)/2;var o=h(s);for(n=1;n<i-1;++n)s[n]=4*t[n].y+2*t[n+1].y;s[0]=t[0].y+2*t[1].y,s[i-1]=(8*t[i-1].y+t[i].y)/2;var a=h(s);for(n=0;n<i;n++)e.push(new L(o[n],a[n])),n<i-1?r.push(new L(2*t[n+1].x-o[n+1],2*t[n+1].y-a[n+1])):r.push(new L((t[i].x+o[i-1])/2,(t[i].y+a[i-1])/2));return[e,r]}(t),e=[],r=n[0].length,i=0;i<r;i++){var s=new L(n[0][i].x,n[0][i].y),o=new L(n[1][i].x,n[1][i].y);e.push(new tt(t[i],s,o,t[i+1]))}return e}}(),tt.prototype={type:v.Curve,bbox:function(){for(var t,n,e,r,i,s,o,a,h=this.start,u=this.controlPoint1,c=this.controlPoint2,l=this.end,f=h.x,d=h.y,g=u.x,v=u.y,p=c.x,m=c.y,y=l.x,x=l.y,w=new Array,b=new Array,S=[new Array,new Array],P=0;P<2;++P)if(e=0===P?(n=6*f-12*g+6*p,t=-3*f+9*g-9*p+3*y,3*g-3*f):(n=6*d-12*v+6*m,t=-3*d+9*v-9*m+3*x,3*v-3*d),J(t)<1e-12){if(J(n)<1e-12)continue;0<(r=-e/n)&&r<1&&b.push(r)}else a=K(o=n*n-4*e*t),o<0||(0<(i=(-n+a)/(2*t))&&i<1&&b.push(i),0<(s=(-n-a)/(2*t))&&s<1&&b.push(s));for(var A,T,L,E=b.length,C=E;E--;)T=(A=1-(r=b[E]))*A*A*f+3*A*A*r*g+3*A*r*r*p+r*r*r*y,S[0][E]=T,L=A*A*A*d+3*A*A*r*v+3*A*r*r*m+r*r*r*x,S[1][E]=L,w[E]={X:T,Y:L};b[C]=0,b[C+1]=1,w[C]={X:f,Y:d},w[C+1]={X:y,Y:x},S[0][C]=f,S[1][C]=d,S[0][C+1]=y,S[1][C+1]=x,b.length=C+2,S[0].length=C+2,S[1].length=C+2,w.length=C+2;var N=Q.apply(null,S[0]),I=Q.apply(null,S[1]),M=$.apply(null,S[0]),R=$.apply(null,S[1]);return new B(N,I,M-N,R-I)},clone:function(){return new tt(this.start,this.controlPoint1,this.controlPoint2,this.end)},closestPoint:function(t,n){return this.pointAtT(this.closestPointT(t,n))},closestPointLength:function(t,n){var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,r={precision:e,subdivisions:void 0===n.subdivisions?this.getSubdivisions({precision:e}):n.subdivisions};return this.lengthAtT(this.closestPointT(t,r),r)},closestPointNormalizedLength:function(t,n){var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,r={precision:e,subdivisions:void 0===n.subdivisions?this.getSubdivisions({precision:e}):n.subdivisions},i=this.closestPointLength(t,r);if(!i)return 0;var s=this.length(r);return 0===s?0:i/s},closestPointT:function(t,n){for(var e,r,i,s,o,a,h,u=void 0===(n=n||{}).precision?this.PRECISION:n.precision,c=void 0===n.subdivisions?this.getSubdivisions({precision:u}):n.subdivisions,l=c.length,f=l?1/l:0,d=0;d<l;d++){var g=c[d],v=g.start.distance(t),p=g.end.distance(t),m=v+p;(!h||m<h)&&(r=d*f,i=(d+1)*f,s=v,o=p,a=(e=g).start.distance(g.end),h=m)}for(var y=_(10,-u);;){var x=s?J(s-o)/s:0,w=o?J(s-o)/o:0;if(x<y||w<y||(!s||s<a*y||(!o||o<a*y)))return s<=o?r:i;var b=e.divide(.5);f/=2;var S=b[0].start.distance(t),P=b[0].end.distance(t),A=S+P,T=b[1].start.distance(t),L=b[1].end.distance(t);o=A<=T+L?(e=b[0],i-=f,s=S,P):(e=b[1],r+=f,s=T,L)}},closestPointTangent:function(t,n){return this.tangentAtT(this.closestPointT(t,n))},containsPoint:function(t,n){return this.toPolyline(n).containsPoint(t)},divideAt:function(t,n){if(t<=0)return this.divideAtT(0);if(1<=t)return this.divideAtT(1);var e=this.tAt(t,n);return this.divideAtT(e)},divideAtLength:function(t,n){var e=this.tAtLength(t,n);return this.divideAtT(e)},divideAtT:function(t){var n=this.start,e=this.controlPoint1,r=this.controlPoint2,i=this.end;if(t<=0)return[new tt(n,n,n,n),new tt(n,e,r,i)];if(1<=t)return[new tt(n,e,r,i),new tt(i,i,i,i)];var s=this.getSkeletonPoints(t),o=s.startControlPoint1,a=s.startControlPoint2,h=s.divider,u=s.dividerControlPoint1,c=s.dividerControlPoint2;return[new tt(n,o,a,h),new tt(h,u,c,i)]},endpointDistance:function(){return this.start.distance(this.end)},equals:function(t){return!!t&&this.start.x===t.start.x&&this.start.y===t.start.y&&this.controlPoint1.x===t.controlPoint1.x&&this.controlPoint1.y===t.controlPoint1.y&&this.controlPoint2.x===t.controlPoint2.x&&this.controlPoint2.y===t.controlPoint2.y&&this.end.x===t.end.x&&this.end.y===t.end.y},getSkeletonPoints:function(t){var n=this.start,e=this.controlPoint1,r=this.controlPoint2,i=this.end;if(t<=0)return{startControlPoint1:n.clone(),startControlPoint2:n.clone(),divider:n.clone(),dividerControlPoint1:e.clone(),dividerControlPoint2:r.clone()};if(1<=t)return{startControlPoint1:e.clone(),startControlPoint2:r.clone(),divider:i.clone(),dividerControlPoint1:i.clone(),dividerControlPoint2:i.clone()};var s=new N(n,e).pointAt(t),o=new N(e,r).pointAt(t),a=new N(r,i).pointAt(t),h=new N(s,o).pointAt(t),u=new N(o,a).pointAt(t);return{startControlPoint1:s,startControlPoint2:h,divider:new N(h,u).pointAt(t),dividerControlPoint1:u,dividerControlPoint2:a}},getSubdivisions:function(t){var n=void 0===(t=t||{}).precision?this.PRECISION:t.precision,e=this.start,r=this.controlPoint1,i=this.controlPoint2,s=this.end,o=[new tt(e,r,i,s)];if(0===n)return o;if(!this.isDifferentiable())return o;var a=this.endpointDistance(),h=_(10,-n),u=2;0===r.cross(e,s)&&0===i.cross(e,s)&&(u=2*n);for(var c=0;;){c+=1;for(var l=[],f=o.length,d=0;d<f;d++){var g=o[d].divide(.5);l.push(g[0],g[1])}for(var v=0,p=l.length,m=0;m<p;m++){v+=l[m].endpointDistance()}if(u<=c)if((0!==v?(v-a)/v:0)<h)return l;o=l,a=v}},isDifferentiable:function(){var t=this.start,n=this.controlPoint1,e=this.controlPoint2,r=this.end;return!(t.equals(n)&&n.equals(e)&&e.equals(r))},length:function(t){for(var n=void 0===(t=t||{}).precision?this.PRECISION:t.precision,e=void 0===t.subdivisions?this.getSubdivisions({precision:n}):t.subdivisions,r=0,i=e.length,s=0;s<i;s++){r+=e[s].endpointDistance()}return r},lengthAtT:function(t,n){if(t<=0)return 0;var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision;return this.divide(t)[0].length({precision:e})},pointAt:function(t,n){if(t<=0)return this.start.clone();if(1<=t)return this.end.clone();var e=this.tAt(t,n);return this.pointAtT(e)},pointAtLength:function(t,n){var e=this.tAtLength(t,n);return this.pointAtT(e)},pointAtT:function(t){return t<=0?this.start.clone():1<=t?this.end.clone():this.getSkeletonPoints(t).divider},PRECISION:3,round:function(t){return this.start.round(t),this.controlPoint1.round(t),this.controlPoint2.round(t),this.end.round(t),this},scale:function(t,n,e){return this.start.scale(t,n,e),this.controlPoint1.scale(t,n,e),this.controlPoint2.scale(t,n,e),this.end.scale(t,n,e),this},tangentAt:function(t,n){if(!this.isDifferentiable())return null;t<0?t=0:1<t&&(t=1);var e=this.tAt(t,n);return this.tangentAtT(e)},tangentAtLength:function(t,n){if(!this.isDifferentiable())return null;var e=this.tAtLength(t,n);return this.tangentAtT(e)},tangentAtT:function(t){if(!this.isDifferentiable())return null;t<0?t=0:1<t&&(t=1);var n=this.getSkeletonPoints(t),e=n.startControlPoint2,r=n.dividerControlPoint1,i=n.divider,s=new N(e,r);return s.translate(i.x-e.x,i.y-e.y),s},tAt:function(t,n){if(t<=0)return 0;if(1<=t)return 1;var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,r={precision:e,subdivisions:void 0===n.subdivisions?this.getSubdivisions({precision:e}):n.subdivisions},i=this.length(r)*t;return this.tAtLength(i,r)},tAtLength:function(t,n){var e=!0;t<0&&(e=!1,t=-t);for(var r,i,s,o,a,h=void 0===(n=n||{}).precision?this.PRECISION:n.precision,u=void 0===n.subdivisions?this.getSubdivisions({precision:h}):n.subdivisions,c={precision:h,subdivisions:u},l=0,f=u.length,d=1/f,g=0;g<f;g++){var v=e?g:f-1-g,p=u[g],m=p.endpointDistance();if(t<=l+m){r=p,i=v*d,s=(v+1)*d,o=e?t-l:m+l-t,a=e?m+l-t:t-l;break}l+=m}if(!r)return e?1:0;for(var y=this.length(c),x=_(10,-h);;){var w,b;if((0!==y?o/y:0)<x)return i;if((0!==y?a/y:0)<x)return s;var S=r.divide(.5);d/=2;var P=S[0].endpointDistance(),A=S[1].endpointDistance();b=o<=P?(r=S[0],s-=d,P-(w=o)):(r=S[1],i+=d,A-(w=o-P)),o=w,a=b}},toPoints:function(t){for(var n=void 0===(t=t||{}).precision?this.PRECISION:t.precision,e=void 0===t.subdivisions?this.getSubdivisions({precision:n}):t.subdivisions,r=[e[0].start.clone()],i=e.length,s=0;s<i;s++){var o=e[s];r.push(o.end.clone())}return r},toPolyline:function(t){return new X(this.toPoints(t))},toString:function(){return this.start+" "+this.controlPoint1+" "+this.controlPoint2+" "+this.end},translate:function(t,n){return this.start.translate(t,n),this.controlPoint1.translate(t,n),this.controlPoint2.translate(t,n),this.end.translate(t,n),this}},tt.prototype.divide=tt.prototype.divideAtT;var et=function(t){if(!(this instanceof et))return new et(t);if("string"==typeof t)return new et.parse(t);var n,e;if(this.segments=[],t)if(Array.isArray(t)&&0!==t.length)if(e=(t=t.reduce(function(t,n){return t.concat(n)},[])).length,t[0].isSegment)for(n=0;n<e;n++){var r=t[n];this.appendSegment(r)}else{var i=null;for(n=0;n<e;n++){var s=t[n];if(!(s instanceof N||s instanceof tt))throw new Error("Cannot construct a path segment from the provided object.");0===n&&this.appendSegment(et.createSegment("M",s.start)),i&&!i.end.equals(s.start)&&this.appendSegment(et.createSegment("M",s.start)),s instanceof N?this.appendSegment(et.createSegment("L",s.end)):s instanceof tt&&this.appendSegment(et.createSegment("C",s.controlPoint1,s.controlPoint2,s.end)),i=s}}else if(t.isSegment)this.appendSegment(t);else if(t instanceof N)this.appendSegment(et.createSegment("M",t.start)),this.appendSegment(et.createSegment("L",t.end));else if(t instanceof tt)this.appendSegment(et.createSegment("M",t.start)),this.appendSegment(et.createSegment("C",t.controlPoint1,t.controlPoint2,t.end));else{if(!(t instanceof X))throw new Error("Cannot construct a path from the provided object.");if(!t.points||0===t.points.length)return;for(e=t.points.length,n=0;n<e;n++){var o=t.points[n];0===n?this.appendSegment(et.createSegment("M",o)):this.appendSegment(et.createSegment("L",o))}}else;};function rt(t,n){return n.unshift(null),new(Function.prototype.bind.apply(t,n))}et.parse=function(t){if(!t)return new et;for(var n=new et,e=t.match(/(?:[a-zA-Z] *)(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)? *,? *)|(?:-?\.\d+ *,? *))+|(?:[a-zA-Z] *)(?! |\d|-|\.)/g),r=e.length,i=0;i<r;i++){var s=e[i].match(/(?:[a-zA-Z])|(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)?))|(?:(?:-?\.\d+))/g),o=et.createSegment.apply(this,s);n.appendSegment(o)}return n},et.createSegment=function(t){var n=arguments;if(!t)throw new Error("Type must be provided.");var e=et.segmentTypes[t];if(!e)throw new Error(t+" is not a recognized path segment type.");for(var r=[],i=arguments.length,s=1;s<i;s++)r.push(n[s]);return rt(e,r)},et.prototype={type:v.Path,appendSegment:function(t){var n,e=this.segments,r=e.length,i=0!==r?e[r-1]:null;if(Array.isArray(t)){if(!(t=t.reduce(function(t,n){return t.concat(n)},[]))[0].isSegment)throw new Error("Segments required.");for(var s=t.length,o=0;o<s;o++){var a=t[o];n=this.prepareSegment(a,i,null),e.push(n),i=n}}else{if(!t||!t.isSegment)throw new Error("Segment required.");n=this.prepareSegment(t,i,null),e.push(n)}},bbox:function(){var t,n=this.segments,e=n.length;if(0===e)return null;for(var r=0;r<e;r++){var i=n[r];if(i.isVisible){var s=i.bbox();t=t?t.union(s):s}}if(t)return t;var o=n[e-1];return new B(o.end.x,o.end.y,0,0)},clone:function(){for(var t=this.segments,n=t.length,e=new et,r=0;r<n;r++){var i=t[r].clone();e.appendSegment(i)}return e},closestPoint:function(t,n){var e=this.closestPointT(t,n);return e?this.pointAtT(e):null},closestPointLength:function(t,n){var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,r={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},i=this.closestPointT(t,r);return i?this.lengthAtT(i,r):0},closestPointNormalizedLength:function(t,n){var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,r={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},i=this.closestPointLength(t,r);if(0===i)return 0;var s=this.length(r);return 0===s?0:i/s},closestPointT:function(t,n){var e=this.segments,r=e.length;if(0===r)return null;for(var i,s=void 0===(n=n||{}).precision?this.PRECISION:n.precision,o=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:s}):n.segmentSubdivisions,a=1/0,h=0;h<r;h++){var u=e[h],c=o[h];if(u.isVisible){var l=u.closestPointT(t,{precision:s,subdivisions:c}),f=u.pointAtT(l),d=new N(f,t).squaredLength();d<a&&(i={segmentIndex:h,value:l},a=d)}}return i||{segmentIndex:r-1,value:1}},closestPointTangent:function(t,n){var e=this.segments,r=e.length;if(0===r)return null;for(var i,s=void 0===(n=n||{}).precision?this.PRECISION:n.precision,o=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:s}):n.segmentSubdivisions,a=1/0,h=0;h<r;h++){var u=e[h],c=o[h];if(u.isDifferentiable()){var l=u.closestPointT(t,{precision:s,subdivisions:c}),f=u.pointAtT(l),d=new N(f,t).squaredLength();d<a&&(i=u.tangentAtT(l),a=d)}}return i||null},containsPoint:function(t,n){var e=this.toPolylines(n);if(!e)return!1;for(var r=e.length,i=0,s=0;s<r;s++){e[s].containsPoint(t)&&i++}return i%2==1},divideAt:function(t,n){if(0===this.segments.length)return null;t<0&&(t=0),1<t&&(t=1);var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,r={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},i=this.length(r)*t;return this.divideAtLength(i,r)},divideAtLength:function(t,n){var e=this.segments.length;if(0===e)return null;var r=!0;t<0&&(r=!1,t=-t);var i,s,o,a,h,u,c,l=void 0===(n=n||{}).precision?this.PRECISION:n.precision,f=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:l}):n.segmentSubdivisions,d=0;for(i=0;i<e;i++){var g=r?i:e-1-i;s=this.getSegment(g);var v=f[g],p=s.length({precision:l,subdivisions:v});if(s.isDifferentiable()&&(h=s,u=g,t<=d+p)){a=g,o=s.divideAtLength((r?1:-1)*(t-d),{precision:l,subdivisions:v});break}d+=p}if(!h)return null;o||(a=u,c=r?1:0,o=h.divideAtT(c));var m=this.clone();m.replaceSegment(a,o);var y=a,x=a+1,w=a+2;o[0].isDifferentiable()||(m.removeSegment(y),x-=1,w-=1);var b=m.getSegment(x).start;m.insertSegment(x,et.createSegment("M",b)),w+=1,o[1].isDifferentiable()||(m.removeSegment(w-1),w-=1);var S=w-y-1;for(i=w;i<m.segments.length;i++){var P=this.getSegment(i-S);if("Z"===(s=m.getSegment(i)).type&&!P.subpathStartSegment.end.equals(s.subpathStartSegment.end)){var A=et.createSegment("L",P.end);m.replaceSegment(i,A)}}return[new et(m.segments.slice(0,x)),new et(m.segments.slice(x))]},equals:function(t){if(!t)return!1;var n=this.segments,e=t.segments,r=n.length;if(e.length!==r)return!1;for(var i=0;i<r;i++){var s=n[i],o=e[i];if(s.type!==o.type||!s.equals(o))return!1}return!0},getSegment:function(t){var n=this.segments,e=n.length;if(0===e)throw new Error("Path has no segments.");if(t<0&&(t=e+t),e<=t||t<0)throw new Error("Index out of range.");return n[t]},getSegmentSubdivisions:function(t){for(var n=this.segments,e=n.length,r=void 0===(t=t||{}).precision?this.PRECISION:t.precision,i=[],s=0;s<e;s++){var o=n[s].getSubdivisions({precision:r});i.push(o)}return i},getSubpaths:function(){for(var t=this.clone().validate().segments,n=t.length,e=[],r=0;r<n;r++){var i=t[r];i.isSubpathStart?e.push(new et(i)):e[e.length-1].appendSegment(i)}return e},insertSegment:function(t,n){var e,r=this.segments,i=r.length;if(t<0&&(t=i+t+1),i<t||t<0)throw new Error("Index out of range.");var s=null,o=null;if(0!==i&&(o=1<=t?(s=r[t-1]).nextSegment:r[0]),Array.isArray(n)){if(!(n=n.reduce(function(t,n){return t.concat(n)},[]))[0].isSegment)throw new Error("Segments required.");for(var a=n.length,h=0;h<a;h++){var u=n[h];e=this.prepareSegment(u,s,o),r.splice(t+h,0,e),s=e}}else{if(!n||!n.isSegment)throw new Error("Segment required.");e=this.prepareSegment(n,s,o),r.splice(t,0,e)}},intersectionWithLine:function(t,n){var e=null,r=this.toPolylines(n);if(!r)return null;for(var i=0,s=r.length;i<s;i++){var o=r[i],a=t.intersect(o);a&&(e||(e=[]),Array.isArray(a)?Array.prototype.push.apply(e,a):e.push(a))}return e},isDifferentiable:function(){for(var t=this.segments,n=t.length,e=0;e<n;e++){if(t[e].isDifferentiable())return!0}return!1},isValid:function(){var t=this.segments;return 0===t.length||"M"===t[0].type},length:function(t){var n=this.segments,e=n.length;if(0===e)return 0;for(var r=void 0===(t=t||{}).precision?this.PRECISION:t.precision,i=void 0===t.segmentSubdivisions?this.getSegmentSubdivisions({precision:r}):t.segmentSubdivisions,s=0,o=0;o<e;o++){var a=n[o],h=i[o];s+=a.length({subdivisions:h})}return s},lengthAtT:function(t,n){var e=this.segments,r=e.length;if(0===r)return 0;var i=t.segmentIndex;if(i<0)return 0;var s=t.value;r<=i?(i=r-1,s=1):s<0?s=0:1<s&&(s=1);for(var o,a=void 0===(n=n||{}).precision?this.PRECISION:n.precision,h=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:a}):n.segmentSubdivisions,u=0,c=0;c<i;c++){var l=e[c];o=h[c],u+=l.length({precisison:a,subdivisions:o})}return l=e[i],o=h[i],u+=l.lengthAtT(s,{precisison:a,subdivisions:o})},pointAt:function(t,n){if(0===this.segments.length)return null;if(t<=0)return this.start.clone();if(1<=t)return this.end.clone();var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,r={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},i=this.length(r)*t;return this.pointAtLength(i,r)},pointAtLength:function(t,n){var e=this.segments,r=e.length;if(0===r)return null;if(0===t)return this.start.clone();var i=!0;t<0&&(i=!1,t=-t);for(var s,o=void 0===(n=n||{}).precision?this.PRECISION:n.precision,a=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):n.segmentSubdivisions,h=0,u=0;u<r;u++){var c=i?u:r-1-u,l=e[c],f=a[c],d=l.length({precision:o,subdivisions:f});if(l.isVisible){if(t<=h+d)return l.pointAtLength((i?1:-1)*(t-h),{precision:o,subdivisions:f});s=l}h+=d}return s?i?s.end:s.start:e[r-1].end.clone()},pointAtT:function(t){var n=this.segments,e=n.length;if(0===e)return null;var r=t.segmentIndex;if(r<0)return n[0].pointAtT(0);if(e<=r)return n[e-1].pointAtT(1);var i=t.value;return i<0?i=0:1<i&&(i=1),n[r].pointAtT(i)},PRECISION:3,prepareSegment:function(t,n,e){t.previousSegment=n,t.nextSegment=e,n&&(n.nextSegment=t),e&&(e.previousSegment=t);var r=t;return t.isSubpathStart&&(t.subpathStartSegment=t,r=e),r&&this.updateSubpathStartSegment(r),t},removeSegment:function(t){var n=this.segments,e=n.length;if(0===e)throw new Error("Path has no segments.");if(t<0&&(t=e+t),e<=t||t<0)throw new Error("Index out of range.");var r=n.splice(t,1)[0],i=r.previousSegment,s=r.nextSegment;i&&(i.nextSegment=s),s&&(s.previousSegment=i),r.isSubpathStart&&s&&this.updateSubpathStartSegment(s)},replaceSegment:function(t,n){var e,r=this.segments,i=r.length;if(0===i)throw new Error("Path has no segments.");if(t<0&&(t=i+t),i<=t||t<0)throw new Error("Index out of range.");var s=r[t],o=s.previousSegment,a=s.nextSegment,h=s.isSubpathStart;if(Array.isArray(n)){if(!(n=n.reduce(function(t,n){return t.concat(n)},[]))[0].isSegment)throw new Error("Segments required.");r.splice(t,1);for(var u=n.length,c=0;c<u;c++){var l=n[c];e=this.prepareSegment(l,o,a),r.splice(t+c,0,e),o=e,h&&e.isSubpathStart&&(h=!1)}}else{if(!n||!n.isSegment)throw new Error("Segment required.");e=this.prepareSegment(n,o,a),r.splice(t,1,e),h&&e.isSubpathStart&&(h=!1)}h&&a&&this.updateSubpathStartSegment(a)},round:function(t){for(var n=this.segments,e=n.length,r=0;r<e;r++){n[r].round(t)}return this},scale:function(t,n,e){for(var r=this.segments,i=r.length,s=0;s<i;s++){r[s].scale(t,n,e)}return this},segmentAt:function(t,n){var e=this.segmentIndexAt(t,n);return e?this.getSegment(e):null},segmentAtLength:function(t,n){var e=this.segmentIndexAtLength(t,n);return e?this.getSegment(e):null},segmentIndexAt:function(t,n){if(0===this.segments.length)return null;t<0&&(t=0),1<t&&(t=1);var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,r={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},i=this.length(r)*t;return this.segmentIndexAtLength(i,r)},segmentIndexAtLength:function(t,n){var e=this.segments,r=e.length;if(0===r)return null;var i=!0;t<0&&(i=!1,t=-t);for(var s=void 0===(n=n||{}).precision?this.PRECISION:n.precision,o=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:s}):n.segmentSubdivisions,a=null,h=0,u=0;u<r;u++){var c=i?u:r-1-u,l=e[c],f=o[c],d=l.length({precision:s,subdivisions:f});if(l.isVisible){if(t<=h+d)return c;a=c}h+=d}return a},serialize:function(){if(!this.isValid())throw new Error("Invalid path segments.");return this.toString()},tangentAt:function(t,n){if(0===this.segments.length)return null;t<0&&(t=0),1<t&&(t=1);var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,r={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},i=this.length(r)*t;return this.tangentAtLength(i,r)},tangentAtLength:function(t,n){var e=this.segments,r=e.length;if(0===r)return null;var i=!0;t<0&&(i=!1,t=-t);for(var s,o=void 0===(n=n||{}).precision?this.PRECISION:n.precision,a=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):n.segmentSubdivisions,h=0,u=0;u<r;u++){var c=i?u:r-1-u,l=e[c],f=a[c],d=l.length({precision:o,subdivisions:f});if(l.isDifferentiable()){if(t<=h+d)return l.tangentAtLength((i?1:-1)*(t-h),{precision:o,subdivisions:f});s=l}h+=d}if(s){var g=i?1:0;return s.tangentAtT(g)}return null},tangentAtT:function(t){var n=this.segments,e=n.length;if(0===e)return null;var r=t.segmentIndex;if(r<0)return n[0].tangentAtT(0);if(e<=r)return n[e-1].tangentAtT(1);var i=t.value;return i<0?i=0:1<i&&(i=1),n[r].tangentAtT(i)},toPoints:function(t){var n=this.segments,e=n.length;if(0===e)return null;for(var r=void 0===(t=t||{}).precision?this.PRECISION:t.precision,i=void 0===t.segmentSubdivisions?this.getSegmentSubdivisions({precision:r}):t.segmentSubdivisions,s=[],o=[],a=0;a<e;a++){var h=n[a];if(h.isVisible){var u=i[a];if(0<u.length){var c=u.map(function(t){return t.start});Array.prototype.push.apply(o,c)}else o.push(h.start)}else 0<o.length&&(o.push(n[a-1].end),s.push(o),o=[])}return 0<o.length&&(o.push(this.end),s.push(o)),s},toPolylines:function(t){var n=[],e=this.toPoints(t);if(!e)return null;for(var r=0,i=e.length;r<i;r++)n.push(new X(e[r]));return n},toString:function(){for(var t=this.segments,n=t.length,e="",r=0;r<n;r++){e+=t[r].serialize()+" "}return e.trim()},translate:function(t,n){for(var e=this.segments,r=e.length,i=0;i<r;i++){e[i].translate(t,n)}return this},updateSubpathStartSegment:function(t){for(var n=t.previousSegment;t&&!t.isSubpathStart;)t.subpathStartSegment=n?n.subpathStartSegment:null,t=(n=t).nextSegment},validate:function(){return this.isValid()||this.insertSegment(0,et.createSegment("M",0,0)),this}},Object.defineProperty(et.prototype,"start",{configurable:!0,enumerable:!0,get:function(){var t=this.segments,n=t.length;if(0===n)return null;for(var e=0;e<n;e++){var r=t[e];if(r.isVisible)return r.start}return t[n-1].end}}),Object.defineProperty(et.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.segments,n=t.length;if(0===n)return null;for(var e=n-1;0<=e;e--){var r=t[e];if(r.isVisible)return r.end}return t[n-1].end}});var it={bbox:function(){throw new Error("Declaration missing for virtual function.")},clone:function(){throw new Error("Declaration missing for virtual function.")},closestPoint:function(){throw new Error("Declaration missing for virtual function.")},closestPointLength:function(){throw new Error("Declaration missing for virtual function.")},closestPointNormalizedLength:function(){throw new Error("Declaration missing for virtual function.")},closestPointT:function(t){if(this.closestPointNormalizedLength)return this.closestPointNormalizedLength(t);throw new Error("Neither closestPointT() nor closestPointNormalizedLength() function is implemented.")},closestPointTangent:function(){throw new Error("Declaration missing for virtual function.")},divideAt:function(){throw new Error("Declaration missing for virtual function.")},divideAtLength:function(){throw new Error("Declaration missing for virtual function.")},divideAtT:function(t){if(this.divideAt)return this.divideAt(t);throw new Error("Neither divideAtT() nor divideAt() function is implemented.")},equals:function(){throw new Error("Declaration missing for virtual function.")},getSubdivisions:function(){throw new Error("Declaration missing for virtual function.")},isDifferentiable:function(){throw new Error("Declaration missing for virtual function.")},isSegment:!0,isSubpathStart:!1,isVisible:!0,length:function(){throw new Error("Declaration missing for virtual function.")},lengthAtT:function(t){if(t<=0)return 0;var n=this.length();return 1<=t?n:n*t},nextSegment:null,pointAt:function(){throw new Error("Declaration missing for virtual function.")},pointAtLength:function(){throw new Error("Declaration missing for virtual function.")},pointAtT:function(t){if(this.pointAt)return this.pointAt(t);throw new Error("Neither pointAtT() nor pointAt() function is implemented.")},previousSegment:null,round:function(){throw new Error("Declaration missing for virtual function.")},subpathStartSegment:null,scale:function(){throw new Error("Declaration missing for virtual function.")},serialize:function(){throw new Error("Declaration missing for virtual function.")},tangentAt:function(){throw new Error("Declaration missing for virtual function.")},tangentAtLength:function(){throw new Error("Declaration missing for virtual function.")},tangentAtT:function(t){if(this.tangentAt)return this.tangentAt(t);throw new Error("Neither tangentAtT() nor tangentAt() function is implemented.")},toString:function(){throw new Error("Declaration missing for virtual function.")},translate:function(){throw new Error("Declaration missing for virtual function.")}};Object.defineProperty(it,"end",{configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(it,"start",{configurable:!0,enumerable:!0,get:function(){if(!this.previousSegment)throw new Error("Missing previous segment. (This segment cannot be the first segment of a path; OR segment has not yet been added to a path.)");return this.previousSegment.end}}),Object.defineProperty(it,"type",{configurable:!0,enumerable:!0,get:function(){throw new Error("Bad segment declaration. No type specified.")}});var st=function(){for(var t,n,e=arguments,r=[],i=arguments.length,s=0;s<i;s++)r.push(e[s]);if(!(this instanceof st))return rt(st,r);if(0===i)throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates (none provided).");if(r[0]instanceof N){if(1===i)return this.end=r[0].end