UNPKG

jointjs

Version:

JavaScript diagramming library

8 lines (6 loc) 85.8 kB
/*! JointJS v3.4.4 (2021-09-27) - 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,i=Math.floor,r=Math.PI,a=function(t){return t%360+(t<0?360:0)},s=function(t,n){return n*e(t/n)},c=function(t){return 180*t/r%360},l=function(t,n){return(t=(n=n||!1)?t:t%360)*r/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 i(Math.random()*(n-t+1)+t)},f=Math.cos,d=Math.sin,g=Math.atan2,n=function(t,n){var e=l(t.y),i=l(n.y),r=t.x,s=n.x,o=l(s-r),a=d(o)*f(i),h=f(e)*d(i)-d(e)*f(i)*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)]},h=function(t,n){var e=t.x,i=t.y;return(e-=n.x)*e+(i-=n.y)*i},u=function(t,n){return Math.sqrt(h(t,n))},v=Math.abs,p=Math.cos,m=Math.sin,y=Math.sqrt,x=Math.min,w=Math.max,b=Math.atan2,S=Math.round,P=Math.pow,A=Math.PI,T=function(t,n){if(!(this instanceof T))return new T(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};T.fromPolar=function(t,n,e){e=new T(e);var i=v(t*p(n)),r=v(t*m(n)),s=a(c(n));return s<90?r=-r:s<180?(i=-i,r=-r):s<270&&(i=-i),new T(e.x+i,e.y+r)},T.random=function(t,n,e,i){return new T(o(t,n),o(e,i))},T.prototype={chooseClosest:function(t){var n=t.length;if(1===n)return new T(t[0]);for(var e=null,i=1/0,r=0;r<n;r++){var s=new T(t[r]),o=this.squaredDistance(s);o<i&&(e=s,i=o)}return e},adhereToRect:function(t){return t.containsPoint(this)||(this.x=x(w(this.x,t.x),t.x+t.width),this.y=x(w(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 T(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 T(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,i=this.y;return new T((1-n)*e+n*t.x,(1-n)*i+n*t.y)},magnitude:function(){return y(this.x*this.x+this.y*this.y)||.01},manhattanDistance:function(t){return v(t.x-this.x)+v(t.y-this.y)},move:function(t,n){var e=l(new T(t).theta(this));return this.offset(p(e)*n,-m(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 T(t).move(this,this.distance(t))},rotate:function(t,n){if(0===n)return this;t=t||new T(0,0),n=l(a(-n));var e=p(n),i=m(n),r=e*(this.x-t.x)-i*(this.y-t.y)+t.x,s=i*(this.x-t.x)+e*(this.y-t.y)+t.y;return this.x=r,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=P(10,t)}return this.x=S(this.x*n)/n,this.y=S(this.y*n)/n,this},scale:function(t,n,e){return e=e&&new T(e)||new T(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 h(this,t)},theta:function(t){var n=-((t=new T(t)).y-this.y),e=t.x-this.x,i=b(n,e);return i<0&&(i=2*A+i),180*i/A},toJSON:function(){return{x:this.x,y:this.y}},toPolar:function(t){t=t&&new T(t)||new T(0,0);var n=this.x,e=this.y;return this.x=y((n-t.x)*(n-t.x)+(e-t.y)*(e-t.y)),this.y=l(t.theta(new T(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 T(0,0).angleBetween(this,t)}},T.prototype.translate=T.prototype.offset;var t=T,L=Math.max,E=Math.min,C=function(t,n){return this instanceof C?t instanceof C?new C(t.start,t.end):(this.start=new T(t),void(this.end=new T(n))):new C(t,n)};C.prototype={angle:function(){var t=new T(this.start.x+1,this.start.y);return this.start.angleBetween(this.end,t)},bbox:function(){var t=E(this.start.x,this.end.x),n=E(this.start.y,this.end.y),e=L(this.start.x,this.end.x),i=L(this.start.y,this.end.y);return new B(t,n,e-t,i-n)},bearing:function(){return n(this.start,this.end)},clone:function(){return new C(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 C(this.start,t).vector()),e=E(1,L(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 i=this.length();return!(new C(n,t).length()>i)&&!(new C(t,e).length()>i)},divideAt:function(t){var n=this.pointAt(t);return[new C(this.start,n),new C(n,this.end)]},divideAtLength:function(t){var n=this.pointAtLength(t);return[new C(this.start,n),new C(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 C&&(e=e[0]),e}return null},intersectionWithLine:function(t){var n=new T(this.end.x-this.start.x,this.end.y-this.start.y),e=new T(t.end.x-t.start.x,t.end.y-t.start.y),i=n.x*e.y-n.y*e.x,r=new T(t.start.x-this.start.x,t.start.y-this.start.y),s=r.x*e.y-r.y*e.x,o=r.x*n.y-r.y*n.x;if(0===i||s*i<0||o*i<0)return null;if(0<i){if(i<s||i<o)return null}else if(s<i||o<i)return null;return[new T(this.start.x+s*n.x/i,this.start.y+s*n.y/i)]},isDifferentiable:function(){return!this.start.equals(this.end)},length:function(){return u(this.start,this.end)},midpoint:function(){return new T((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,i=n.end,r=e.clone().rotate(i,270),s=i.clone().rotate(e,90);return e.move(s,t),i.move(r,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,i=!0;t<0&&(i=!1,t=-t);var r=this.length();return r<=t?i?e.clone():n.clone():this.pointAt((i?t:r-t)/r)},pointOffset:function(t){t=new T(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 h(this.start,this.end)},tangentAt:function(t){if(!this.isDifferentiable())return null;var n=this.start,e=this.end,i=this.pointAt(t),r=new C(n,e);return r.translate(i.x-n.x,i.y-n.y),r},tangentAtLength:function(t){if(!this.isDifferentiable())return null;var n=this.start,e=this.end,i=this.pointAtLength(t),r=new C(n,e);return r.translate(i.x-n.x,i.y-n.y),r},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 T(this.end.x-this.start.x,this.end.y-this.start.y)}},C.prototype.intersection=C.prototype.intersect;var N=C,I=Math.sqrt,M=Math.round,O=Math.pow,R=function(t,n,e){return this instanceof R?t instanceof R?new R(new T(t.x,t.y),t.a,t.b):(t=new T(t),this.x=t.x,this.y=t.y,this.a=n,void(this.b=e)):new R(t,n,e)};R.fromRect=function(t){return t=new B(t),new R(t.center(),t.width/2,t.height/2)},R.prototype={bbox:function(){return new B(this.x-this.a,this.y-this.b,2*this.a,2*this.b)},center:function(){return new T(this.x,this.y)},clone:function(){return new R(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,i=t.end,r=this.a,s=this.b,o=t.vector(),a=e.difference(new T(this)),h=new T(o.x/(r*r),o.y/(s*s)),u=new T(a.x/(r*r),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=I(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(i,g)),0<=v&&v<=1&&n.push(e.lerp(i,v))}else{var p=-l/c;if(!(0<=p&&p<=1))return null;n.push(e.lerp(i,p))}return n},intersectionWithLineFromCenterToPoint:function(t,n){t=new T(t),n&&t.rotate(new T(this.x,this.y),n);var e,i=t.x-this.x,r=t.y-this.y;if(0===i)return e=this.bbox().pointNearestToPoint(t),n?e.rotate(new T(this.x,this.y),-n):e;var s=r/i,o=s*s,a=this.a*this.a,h=this.b*this.b,u=I(1/(1/a+o/h)),c=s*(u=i<0?-u:u);return e=new T(this.x+u,this.y+c),n?e.rotate(new T(this.x,this.y),-n):e},normalizedDistance:function(t){var n=t.x,e=t.y,i=this.a,r=this.b,s=this.x,o=this.y;return(n-s)*(n-s)/(i*i)+(e-o)*(e-o)/(r*r)},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=M(this.x*n)/n,this.y=M(this.y*n)/n,this.a=M(this.a*n)/n,this.b=M(this.b*n)/n,this},tangentTheta:function(t){var n,e,i=t.x,r=t.y,s=this.a,o=this.b,a=this.bbox().center(),h=a.x,u=a.y,c=i>a.x+s/2,l=i<a.x-s/2;return c||l?e=s*s/(i-h)-s*s*(r-u)*((n=i>a.x?r-30:r+30)-u)/(o*o*(i-h))+h:n=o*o/(r-u)-o*o*(i-h)*((e=r>a.y?i+30:i-30)-h)/(s*s*(r-u))+u,new T(e,n).theta(t)},toString:function(){return new T(this.x,this.y).toString()+" "+this.a+" "+this.b}};var D=R,F=Math.abs,q=Math.cos,V=Math.sin,z=Math.min,j=Math.max,k=Math.round,G=Math.pow,B=function(t,n,e,i){if(!(this instanceof B))return new B(t,n,e,i);Object(t)===t&&(n=t.y,e=t.width,i=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===i?0:i};B.fromEllipse=function(t){return t=new R(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,i,r,s,o=new T;e=i=1/0,r=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),r<h&&(r=h),u<i&&(i=u),s<u&&(s=u)}return new B(e,i,r-e,s-i)},B.fromRectUnion=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];if(0===t.length)return null;var e,i,r,s,o=new B;e=i=1/0,r=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),r<c&&(r=c),u<i&&(i=u),s<l&&(s=l)}return new B(e,i,r-e,s-i)},B.prototype={bbox:function(t){if(!t)return this.clone();var n=l(t),e=F(V(n)),i=F(q(n)),r=this.width*i+this.height*e,s=this.width*e+this.height*i;return new B(this.x+(this.width-r)/2,this.y+(this.height-s)/2,r,s)},bottomLeft:function(){return new T(this.x,this.y+this.height)},bottomLine:function(){return new C(this.bottomLeft(),this.bottomRight())},bottomMiddle:function(){return new T(this.x+this.width/2,this.y+this.height)},center:function(){return new T(this.x+this.width/2,this.y+this.height/2)},clone:function(){return new B(this)},containsPoint:function(t){return(t=new 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(),i=n.width,r=n.height,s=e.width,o=e.height;if(!(i&&r&&s&&o))return!1;var a=n.x,h=n.y,u=e.x,c=e.y;return s+=u,i+=a,o+=c,r+=h,a<=u&&s<=i&&h<=c&&o<=r},corner:function(){return new T(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(),i=t.origin(),r=t.corner();if(r.x<=n.x||r.y<=n.y||i.x>=e.x||i.y>=e.y)return null;var s=j(n.x,i.x),o=j(n.y,i.y);return new B(s,o,z(e.x,r.x)-s,z(e.y,r.y)-o)},intersectionWithLine:function(t){var n,e,i=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],r=[],s=[],o=i.length;for(e=0;e<o;e++)null!==(n=t.intersect(i[e]))&&s.indexOf(n.toString())<0&&(r.push(n),s.push(n.toString()));return 0<r.length?r:null},intersectionWithLineFromCenterToPoint:function(t,n){t=new T(t);var e,i=new T(this.x+this.width/2,this.y+this.height/2);n&&t.rotate(i,n);for(var r=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],s=new C(i,t),o=r.length-1;0<=o;--o){var a=r[o].intersection(s);if(null!==a){e=a;break}}return e&&n&&e.rotate(i,-n),e},leftLine:function(){return new C(this.topLeft(),this.bottomLeft())},leftMiddle:function(){return new T(this.x,this.y+this.height/2)},maxRectScaleToFit:function(t,n){var e,i,r,s,o,a,h,u;t=new B(t),n||(n=t.center());var c=n.x,l=n.y;e=i=r=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&&(i=(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&&(r=(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,i,r,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,i=this.height;return this.width<0&&(t=this.x+this.width,e=-this.width),this.height<0&&(n=this.y+this.height,i=-this.height),this.x=t,this.y=n,this.width=e,this.height=i,this},offset:function(t,n){return T.prototype.offset.call(this,t,n)},origin:function(){return new T(this.x,this.y)},pointNearestToPoint:function(t){if(t=new T(t),this.containsPoint(t))switch(this.sideNearestToPoint(t)){case"right":return new T(this.x+this.width,t.y);case"left":return new T(this.x,t.y);case"bottom":return new T(t.x,this.y+this.height);case"top":return new T(t.x,this.y)}return t.adhereToRect(this)},rightLine:function(){return new C(this.topRight(),this.bottomRight())},rightMiddle:function(){return new T(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=G(10,t)}return this.x=k(this.x*n)/n,this.y=k(this.y*n)/n,this.width=k(this.width*n)/n,this.height=k(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 T(t)).x-this.x,e=this.x+this.width-t.x,i=t.y-this.y,r=n,s="left";return e<r&&(r=e,s="right"),i<r&&(r=i,s="top"),this.y+this.height-t.y<r&&(s="bottom"),s},snapToGrid:function(t,n){var e=this.origin().snapToGrid(t,n),i=this.corner().snapToGrid(t,n);return this.x=e.x,this.y=e.y,this.width=i.x-e.x,this.height=i.y-e.y,this},toJSON:function(){return{x:this.x,y:this.y,width:this.width,height:this.height}},topLine:function(){return new C(this.topLeft(),this.topRight())},topMiddle:function(){return new T(this.x+this.width/2,this.y)},topRight:function(){return new T(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,i){return Object(t)===t&&(n=t.y,e=t.width,i=t.height,t=t.x),this.x=t||0,this.y=n||0,this.width=e||0,this.height=i||0,this}},B.prototype.bottomRight=B.prototype.corner,B.prototype.topLeft=B.prototype.origin,B.prototype.translate=B.prototype.offset;var H=B,U=Math.abs,W=function(t){return this instanceof W?"string"==typeof t?new W.parse(t):void(this.points=Array.isArray(t)?t.map(T):[]):new W(t)};W.parse=function(t){if(""===(t=t.trim()))return new W;for(var n=[],e=t.split(/\s*,\s*|\s+/),i=e.length,r=0;r<i;r+=2)n.push({x:+e[r],y:+e[r+1]});return new W(n)},W.prototype={bbox:function(){var t=1/0,n=-1/0,e=1/0,i=-1/0,r=this.points,s=r.length;if(0===s)return null;for(var o=0;o<s;o++){var a=r[o],h=a.x,u=a.y;h<t&&(t=h),n<h&&(n=h),u<e&&(e=u),i<u&&(i=u)}return new B(t,e,n-t,i-e)},clone:function(){var t=this.points,n=t.length;if(0===n)return new W;for(var e=[],i=0;i<n;i++){var r=t[i].clone();e.push(r)}return new W(e)},closestPoint:function(t){var n=this.closestPointLength(t);return this.pointAtLength(n)},closestPointLength:function(t){var n,e=this.points,i=e.length;if(0===i)return 0;if(1===i)return 0;for(var r=1/0,s=0,o=i-1,a=0;a<o;a++){var h=new C(e[a],e[a+1]),u=h.length(),c=h.closestPointNormalizedLength(t),l=h.pointAt(c).squaredDistance(t);l<r&&(r=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 i=t.x,r=t.y,s=e-1,o=0,a=0;o<e;o++){var h=n[s],u=n[o];if(t.equals(h))return!0;var c=new C(h,u);if(c.containsPoint(t))return!0;if(r<=h.y&&r>u.y||r>h.y&&r<=u.y){var l=h.x-i>u.x-i?h.x-i:u.x-i;if(0<=l){var f=new T(i+l,r),d=new C(t,f);c.intersect(d)&&a++}}s=o}return a%2==1},convexHull:function(){var t,n,e,i=this.points,r=i.length;if(0===r)return new W;for(t=0;t<r;t++)void 0===e?e=i[t]:i[t].y<e.y?e=i[t]:i[t].y===e.y&&i[t].x>e.x&&(e=i[t]);var s=[];for(t=0;t<r;t++){var o=e.theta(i[t]);0===o&&(o=360);var a=[i[t],t,o];s.push(a)}if(s.sort(function(t,n){var e=t[2]-n[2];return 0===e&&(e=n[1]-t[1]),e}),2<s.length){var h=s[s.length-1];s.unshift(h)}for(var u,c,l,f,d,g,v,p={},m=[];0!==s.length;)if(c=(u=s.pop())[0],!p.hasOwnProperty(u[0]+"@@"+u[1]))for(var y=!1;!y;)if(m.length<2)m.push(u),y=!0;else{f=(l=m.pop())[0];var x=(g=(d=m.pop())[0]).cross(f,c);if(x<0)m.push(d),m.push(l),m.push(u),y=!0;else if(0===x){var w=f.angleBetween(g,c);U(w-180)<1e-10?(p[l[0]+"@@"+l[1]]=f,m.push(d)):f.equals(c)||g.equals(f)?(p[l[0]+"@@"+l[1]]=f,m.push(d)):U((w+1)%360-1)<1e-10&&(m.push(d),s.push(l))}else p[l[0]+"@@"+l[1]]=f,m.push(d)}2<m.length&&m.pop();var b=-1;for(n=m.length,t=0;t<n;t++){var S=m[t][1];(void 0===v||S<v)&&(v=S,b=t)}var P=[];if(0<b){var A=m.slice(b),T=m.slice(0,b);P=A.concat(T)}else P=m;var L=[];for(n=P.length,t=0;t<n;t++)L.push(P[t][0]);return new W(L)},equals:function(t){if(!t)return!1;var n=this.points,e=t.points,i=n.length;if(e.length!==i)return!1;for(var r=0;r<i;r++){var s=n[r],o=t.points[r];if(!s.equals(o))return!1}return!0},intersectionWithLine:function(t){for(var n=new C(t),e=[],i=this.points,r=0,s=i.length-1;r<s;r++){var o=i[r],a=i[r+1],h=new C(o,a),u=n.intersectionWithLine(h);u&&e.push(u[0])}return 0<e.length?e:null},isDifferentiable:function(){var t=this.points,n=t.length;if(0===n)return!1;for(var e=n-1,i=0;i<e;i++){var r=t[i],s=t[i+1];if(new C(r,s).isDifferentiable())return!0}return!1},length:function(){var t=this.points,n=t.length;if(0===n)return 0;for(var e=0,i=n-1,r=0;r<i;r++)e+=t[r].distance(t[r+1]);return e},pointAt:function(t){var n=this.points,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 i=this.length()*t;return this.pointAtLength(i)},pointAtLength:function(t){var n=this.points,e=n.length;if(0===e)return null;if(1===e)return n[0].clone();var i=!0;t<0&&(i=!1,t=-t);for(var r=0,s=e-1,o=0;o<s;o++){var a=i?o:s-1-o,h=n[a],u=n[a+1],c=new C(h,u),l=h.distance(u);if(t<=r+l)return c.pointAtLength((i?1:-1)*(t-r));r+=l}return(i?n[e-1]:n[0]).clone()},round:function(t){for(var n=this.points,e=n.length,i=0;i<e;i++)n[i].round(t);return this},scale:function(t,n,e){for(var i=this.points,r=i.length,s=0;s<r;s++)i[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||0,i=0;n[i+2];){var r=i+1,s=i+2,o=n[i],a=n[r],h=n[s];new C(o,h).closestPoint(a).distance(a)<=e?n.splice(r,1):i+=1}return this},tangentAt:function(t){var n=this.points.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.points,e=n.length;if(0===e)return null;if(1===e)return null;var i,r=!0;t<0&&(r=!1,t=-t);for(var s=0,o=e-1,a=0;a<o;a++){var h=r?a:o-1-a,u=n[h],c=n[h+1],l=new C(u,c),f=u.distance(c);if(l.isDifferentiable()){if(t<=s+f)return l.tangentAtLength((r?1:-1)*(t-s));i=l}s+=f}if(i){var d=r?1:0;return i.tangentAt(d)}return null},toString:function(){return this.points+""},translate:function(t,n){for(var e=this.points,i=e.length,r=0;r<i;r++)e[r].translate(t,n);return this},serialize:function(){var t=this.points,n=t.length;if(0===n)return"";for(var e="",i=0;i<n;i++){var r=t[i];e+=r.x+","+r.y+" "}return e.trim()}},Object.defineProperty(W.prototype,"start",{configurable:!0,enumerable:!0,get:function(){return 0===this.points.length?null:this.points[0]}}),Object.defineProperty(W.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.points.length;return 0===t?null:this.points[t-1]}});var Y=Math.abs,Z=Math.sqrt,X=Math.min,$=Math.max,J=Math.pow,K=function(t,n,e,i){return this instanceof K?t instanceof K?new K(t.start,t.controlPoint1,t.controlPoint2,t.end):(this.start=new T(t),this.controlPoint1=new T(n),this.controlPoint2=new T(e),void(this.end=new T(i))):new K(t,n,e,i)};K.throughPoints=function(){function h(t){var n=t.length,e=[],i=[],r=2;e[0]=t[0]/r;for(var s=1;s<n;s++)i[s]=1/r,r=(s<n-1?4:3.5)-i[s],e[s]=(t[s]-e[s-1])/r;for(s=1;s<n;s++)e[n-s-1]-=i[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=[],i=[],r=t.length-1;if(1==r)return e[0]=new T((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),i[0]=new T(2*e[0].x-t[0].x,2*e[0].y-t[0].y),[e,i];var s=[];for(n=1;n<r-1;n++)s[n]=4*t[n].x+2*t[n+1].x;s[0]=t[0].x+2*t[1].x,s[r-1]=(8*t[r-1].x+t[r].x)/2;var o=h(s);for(n=1;n<r-1;++n)s[n]=4*t[n].y+2*t[n+1].y;s[0]=t[0].y+2*t[1].y,s[r-1]=(8*t[r-1].y+t[r].y)/2;var a=h(s);for(n=0;n<r;n++)e.push(new T(o[n],a[n])),n<r-1?i.push(new T(2*t[n+1].x-o[n+1],2*t[n+1].y-a[n+1])):i.push(new T((t[r].x+o[r-1])/2,(t[r].y+a[r-1])/2));return[e,i]}(t),e=[],i=n[0].length,r=0;r<i;r++){var s=new T(n[0][r].x,n[0][r].y),o=new T(n[1][r].x,n[1][r].y);e.push(new K(t[r],s,o,t[r+1]))}return e}}(),K.prototype={bbox:function(){for(var t,n,e,i,r,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),Y(t)<1e-12){if(Y(n)<1e-12)continue;0<(i=-e/n)&&i<1&&b.push(i)}else a=Z(o=n*n-4*e*t),o<0||(0<(r=(-n+a)/(2*t))&&r<1&&b.push(r),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-(i=b[E]))*A*A*f+3*A*A*i*g+3*A*i*i*p+i*i*i*y,S[0][E]=T,L=A*A*A*d+3*A*A*i*v+3*A*i*i*m+i*i*i*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=X.apply(null,S[0]),I=X.apply(null,S[1]),M=$.apply(null,S[0]),O=$.apply(null,S[1]);return new B(N,I,M-N,O-I)},clone:function(){return new K(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,i={precision:e,subdivisions:void 0===n.subdivisions?this.getSubdivisions({precision:e}):n.subdivisions};return this.lengthAtT(this.closestPointT(t,i),i)},closestPointNormalizedLength:function(t,n){var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,i={precision:e,subdivisions:void 0===n.subdivisions?this.getSubdivisions({precision:e}):n.subdivisions},r=this.closestPointLength(t,i);if(!r)return 0;var s=this.length(i);return 0===s?0:r/s},closestPointT:function(t,n){for(var e,i,r,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)&&(i=d*f,r=(d+1)*f,s=v,o=p,a=(e=g).start.distance(g.end),h=m)}for(var y=J(10,-u);;){var x=s?Y(s-o)/s:0,w=o?Y(s-o)/o:0;if(x<y||w<y||(!s||s<a*y||(!o||o<a*y)))return s<=o?i:r;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],r-=f,s=S,P):(e=b[1],i+=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,i=this.controlPoint2,r=this.end;if(t<=0)return[new K(n,n,n,n),new K(n,e,i,r)];if(1<=t)return[new K(n,e,i,r),new K(r,r,r,r)];var s=this.getSkeletonPoints(t),o=s.startControlPoint1,a=s.startControlPoint2,h=s.divider,u=s.dividerControlPoint1,c=s.dividerControlPoint2;return[new K(n,o,a,h),new K(h,u,c,r)]},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,i=this.controlPoint2,r=this.end;if(t<=0)return{startControlPoint1:n.clone(),startControlPoint2:n.clone(),divider:n.clone(),dividerControlPoint1:e.clone(),dividerControlPoint2:i.clone()};if(1<=t)return{startControlPoint1:e.clone(),startControlPoint2:i.clone(),divider:r.clone(),dividerControlPoint1:r.clone(),dividerControlPoint2:r.clone()};var s=new C(n,e).pointAt(t),o=new C(e,i).pointAt(t),a=new C(i,r).pointAt(t),h=new C(s,o).pointAt(t),u=new C(o,a).pointAt(t);return{startControlPoint1:s,startControlPoint2:h,divider:new C(h,u).pointAt(t),dividerControlPoint1:u,dividerControlPoint2:a}},getSubdivisions:function(t){var n=void 0===(t=t||{}).precision?this.PRECISION:t.precision,e=[new K(this.start,this.controlPoint1,this.controlPoint2,this.end)];if(0===n)return e;for(var i=this.endpointDistance(),r=J(10,-n),s=0;;){s+=1;for(var o=[],a=e.length,h=0;h<a;h++){var u=e[h].divide(.5);o.push(u[0],u[1])}for(var c=0,l=o.length,f=0;f<l;f++){c+=o[f].endpointDistance()}if(1<s&&(0!==c?(c-i)/c:0)<r)return o;e=o,i=c}},isDifferentiable:function(){var t=this.start,n=this.controlPoint1,e=this.controlPoint2,i=this.end;return!(t.equals(n)&&n.equals(e)&&e.equals(i))},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,i=0,r=e.length,s=0;s<r;s++){i+=e[s].endpointDistance()}return i},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,i=n.dividerControlPoint1,r=n.divider,s=new C(e,i);return s.translate(r.x-e.x,r.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,i={precision:e,subdivisions:void 0===n.subdivisions?this.getSubdivisions({precision:e}):n.subdivisions},r=this.length(i)*t;return this.tAtLength(r,i)},tAtLength:function(t,n){var e=!0;t<0&&(e=!1,t=-t);for(var i,r,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){i=p,r=v*d,s=(v+1)*d,o=e?t-l:m+l-t,a=e?m+l-t:t-l;break}l+=m}if(!i)return e?1:0;for(var y=this.length(c),x=J(10,-h);;){var w,b;if((0!==y?o/y:0)<x)return r;if((0!==y?a/y:0)<x)return s;var S=i.divide(.5);d/=2;var P=S[0].endpointDistance(),A=S[1].endpointDistance();b=o<=P?(i=S[0],s-=d,P-(w=o)):(i=S[1],r+=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,i=[e[0].start.clone()],r=e.length,s=0;s<r;s++){var o=e[s];i.push(o.end.clone())}return i},toPolyline:function(t){return new W(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}},K.prototype.divide=K.prototype.divideAtT;var Q=function(t){if(!(this instanceof Q))return new Q(t);if("string"==typeof t)return new Q.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 i=t[n];this.appendSegment(i)}else{var r=null;for(n=0;n<e;n++){var s=t[n];if(!(s instanceof C||s instanceof K))throw new Error("Cannot construct a path segment from the provided object.");0===n&&this.appendSegment(Q.createSegment("M",s.start)),r&&!r.end.equals(s.start)&&this.appendSegment(Q.createSegment("M",s.start)),s instanceof C?this.appendSegment(Q.createSegment("L",s.end)):s instanceof K&&this.appendSegment(Q.createSegment("C",s.controlPoint1,s.controlPoint2,s.end)),r=s}}else if(t.isSegment)this.appendSegment(t);else if(t instanceof C)this.appendSegment(Q.createSegment("M",t.start)),this.appendSegment(Q.createSegment("L",t.end));else if(t instanceof K)this.appendSegment(Q.createSegment("M",t.start)),this.appendSegment(Q.createSegment("C",t.controlPoint1,t.controlPoint2,t.end));else{if(!(t instanceof W))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(Q.createSegment("M",o)):this.appendSegment(Q.createSegment("L",o))}}else;};function _(t,n){return n.unshift(null),new(Function.prototype.bind.apply(t,n))}function tt(t){var n,e,i=arguments,r=[];for(e=arguments.length,n=1;n<e;n++)r.push(i[n]);if(!t)throw new Error("Missing a parent object.");var s=Object.create(t);for(e=r.length,n=0;n<e;n++){var o,a,h=r[n];for(a in h)h.hasOwnProperty(a)&&(delete s[a],o=Object.getOwnPropertyDescriptor(h,a),Object.defineProperty(s,a,o))}return s}Q.parse=function(t){if(!t)return new Q;for(var n=new Q,e=t.match(/(?:[a-zA-Z] *)(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)? *,? *)|(?:-?\.\d+ *,? *))+|(?:[a-zA-Z] *)(?! |\d|-|\.)/g),i=e.length,r=0;r<i;r++){var s=e[r].match(/(?:[a-zA-Z])|(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)?))|(?:(?:-?\.\d+))/g),o=Q.createSegment.apply(this,s);n.appendSegment(o)}return n},Q.createSegment=function(t){var n=arguments;if(!t)throw new Error("Type must be provided.");var e=Q.segmentTypes[t];if(!e)throw new Error(t+" is not a recognized path segment type.");for(var i=[],r=arguments.length,s=1;s<r;s++)i.push(n[s]);return _(e,i)},Q.prototype={appendSegment:function(t){var n,e=this.segments,i=e.length,r=0!==i?e[i-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,r,null),e.push(n),r=n}}else{if(!t||!t.isSegment)throw new Error("Segment required.");n=this.prepareSegment(t,r,null),e.push(n)}},bbox:function(){var t,n=this.segments,e=n.length;if(0===e)return null;for(var i=0;i<e;i++){var r=n[i];if(r.isVisible){var s=r.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 Q,i=0;i<n;i++){var r=t[i].clone();e.appendSegment(r)}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,i={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},r=this.closestPointT(t,i);return r?this.lengthAtT(r,i):0},closestPointNormalizedLength:function(t,n){var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,i={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},r=this.closestPointLength(t,i);if(0===r)return 0;var s=this.length(i);return 0===s?0:r/s},closestPointT:function(t,n){var e=this.segments,i=e.length;if(0===i)return null;for(var r,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<i;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 C(f,t).squaredLength();d<a&&(r={segmentIndex:h,value:l},a=d)}}return r||{segmentIndex:i-1,value:1}},closestPointTangent:function(t,n){var e=this.segments,i=e.length;if(0===i)return null;for(var r,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<i;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 C(f,t).squaredLength();d<a&&(r=u.tangentAtT(l),a=d)}}return r||null},containsPoint:function(t,n){var e=this.toPolylines(n);if(!e)return!1;for(var i=e.length,r=0,s=0;s<i;s++){e[s].containsPoint(t)&&r++}return r%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,i={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},r=this.length(i)*t;return this.divideAtLength(r,i)},divideAtLength:function(t,n){var e=this.segments.length;if(0===e)return null;var i=!0;t<0&&(i=!1,t=-t);var r,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(r=0;r<e;r++){var g=i?r:e-1-r;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((i?1:-1)*(t-d),{precision:l,subdivisions:v});break}d+=p}if(!h)return null;o||(a=u,c=i?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,Q.createSegment("M",b)),w+=1,o[1].isDifferentiable()||(m.removeSegment(w-1),w-=1);var S=w-y-1;for(r=w;r<m.segments.length;r++){var P=this.getSegment(r-S);if("Z"===(s=m.getSegment(r)).type&&!P.subpathStartSegment.end.equals(s.subpathStartSegment.end)){var A=Q.createSegment("L",P.end);m.replaceSegment(r,A)}}return[new Q(m.segments.slice(0,x)),new Q(m.segments.slice(x))]},equals:function(t){if(!t)return!1;var n=this.segments,e=t.segments,i=n.length;if(e.length!==i)return!1;for(var r=0;r<i;r++){var s=n[r],o=e[r];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,i=void 0===(t=t||{}).precision?this.PRECISION:t.precision,r=[],s=0;s<e;s++){var o=n[s].getSubdivisions({precision:i});r.push(o)}return r},getSubpaths:function(){for(var t=this.clone().validate().segments,n=t.length,e=[],i=0;i<n;i++){var r=t[i];r.isSubpathStart?e.push(new Q(r)):e[e.length-1].appendSegment(r)}return e},insertSegment:function(t,n){var e,i=this.segments,r=i.length;if(t<0&&(t=r+t+1),r<t||t<0)throw new Error("Index out of range.");var s=null,o=null;if(0!==r&&(o=1<=t?(s=i[t-1]).nextSegment:i[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),i.splice(t+h,0,e),s=e}}else{if(!n||!n.isSegment)throw new Error("Segment required.");e=this.prepareSegment(n,s,o),i.splice(t,0,e)}},intersectionWithLine:function(t,n){var e=null,i=this.toPolylines(n);if(!i)return null;for(var r=0,s=i.length;r<s;r++){var o=i[r],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 i=void 0===(t=t||{}).precision?this.PRECISION:t.precision,r=void 0===t.segmentSubdivisions?this.getSegmentSubdivisions({precision:i}):t.segmentSubdivisions,s=0,o=0;o<e;o++){var a=n[o],h=r[o];s+=a.length({subdivisions:h})}return s},lengthAtT:function(t,n){var e=this.segments,i=e.length;if(0===i)return 0;var r=t.segmentIndex;if(r<0)return 0;var s=t.value;i<=r?(r=i-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<r;c++){var l=e[c];o=h[c],u+=l.length({precisison:a,subdivisions:o})}return l=e[r],o=h[r],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,i={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},r=this.length(i)*t;return this.pointAtLength(r,i)},pointAtLength:function(t,n){var e=this.segments,i=e.length;if(0===i)return null;if(0===t)return this.start.clone();var r=!0;t<0&&(r=!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<i;u++){var c=r?u:i-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((r?1:-1)*(t-h),{precision:o,subdivisions:f});s=l}h+=d}return s?r?s.end:s.start:e[i-1].end.clone()},pointAtT:function(t){var n=this.segments,e=n.length;if(0===e)return null;var i=t.segmentIndex;if(i<0)return n[0].pointAtT(0);if(e<=i)return n[e-1].pointAtT(1);var r=t.value;return r<0?r=0:1<r&&(r=1),n[i].pointAtT(r)},PRECISION:3,prepareSegment:function(t,n,e){t.previousSegment=n,t.nextSegment=e,n&&(n.nextSegment=t),e&&(e.previousSegment=t);var i=t;return t.isSubpathStart&&(t.subpathStartSegment=t,i=e),i&&this.updateSubpathStartSegment(i),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 i=n.splice(t,1)[0],r=i.previousSegment,s=i.nextSegment;r&&(r.nextSegment=s),s&&(s.previousSegment=r),i.isSubpathStart&&s&&this.updateSubpathStartSegment(s)},replaceSegment:function(t,n){var e,i=this.segments,r=i.length;if(0===r)throw new Error("Path has no segments.");if(t<0&&(t=r+t),r<=t||t<0)throw new Error("Index out of range.");var s=i[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.");i.splice(t,1);for(var u=n.length,c=0;c<u;c++){var l=n[c];e=this.prepareSegment(l,o,a),i.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),i.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,i=0;i<e;i++){n[i].round(t)}return this},scale:function(t,n,e){for(var i=this.segments,r=i.length,s=0;s<r;s++){i[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,i={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},r=this.length(i)*t;return this.segmentIndexAtLength(r,i)},segmentIndexAtLength:function(t,n){var e=this.segments,i=e.length;if(0===i)return null;var r=!0;t<0&&(r=!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<i;u++){var c=r?u:i-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,i={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},r=this.length(i)*t;return this.tangentAtLength(r,i)},tangentAtLength:function(t,n){var e=this.segments,i=e.length;if(0===i)return null;var r=!0;t<0&&(r=!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<i;u++){var c=r?u:i-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((r?1:-1)*(t-h),{precision:o,subdivisions:f});s=l}h+=d}if(s){var g=r?1:0;return s.tangentAtT(g)}return null},tangentAtT:function(t){var n=this.segments,e=n.length;if(0===e)return null;var i=t.segmentIndex;if(i<0)return n[0].tangentAtT(0);if(e<=i)return n[e-1].tangentAtT(1);var r=t.value;return r<0?r=0:1<r&&(r=1),n[i].tangentAtT(r)},toPoints:function(t){var n=this.segments,e=n.length;if(0===e)return null;for(var i=void 0===(t=t||{}).precision?this.PRECISION:t.precision,r=void 0===t.segmentSubdivisions?this.getSegmentSubdivisions({precision:i}):t.segmentSubdivisions,s=[],o=[],a=0;a<e;a++){var h=n[a];if(h.isVisible){var u=r[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 i=0,r=e.length;i<r;i++)n.push(new W(e[i]));return n},toString:function(){for(var t=this.segments,n=t.length,e="",i=0;i<n;i++){e+=t[i].serialize()+" "}return e.trim()},translate:function(t,n){for(var e=this.segments,i=e.length,r=0;r<i;r++){e[r].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,Q.createSegment("M",0,0)),this}},Object.defineProperty(Q.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 i=t[e];if(i.isVisible)return i.start}return t[n-1].end}}),Object.defineProperty(Q.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 i=t[e];if(i.isVisible)return i.end}return t[n-1].end}});var nt={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(nt,"end",{configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(nt,"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(nt,"type",{configurable:!0,enumerable:!0,get:function(){throw new Error("Bad segment declaration. No type specified.")}});var et=function(){for(var t,n,e=arguments,i=[],r=arguments.length,s=0;s<r;s++)i.push(e[s]);if(!(this instanceof et))return _(et,i);if(0===r)throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates (none provided).");if(i[0]instanceof C){if(1===r)return this.end=i[0].end.clone(),this;throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates ("+r+" lines provided).")}if("string"==typeof i[0]||"number"==typeof i[0]){if(2===r)return this.end=new T(+i[0],+i[1]),this;if(r<2)throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates ("+r+" coordinates provided).");var o;for(t=[],s=0;s<r;s+=2)o=i.slice(s,s+2),t.push(_(et,o));return t}if(1===r)return this.end=new T(i[0]),this;for(t=[],s=0;s<r;s+=1)n=i[s],t.push(new et(n));return t},it={clone:function(){return new et(this.end)},divideAt:function(t){var n=new C(this.start,this.end).divideAt(t);return[new et(n[0]),new et(n[1])]},divideAtLength:function(t){var n=new C(this.start,this.end).divideAtLength(t);return[new et(n[0]),new et(n[1])]},getSubdivisions:function(){return[]},isDifferentiable:function(){retur