UNPKG

jointjs

Version:

JavaScript diagramming library

8 lines (6 loc) 58.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/. */ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).g={})}(this,function(t){"use strict";var e=Math.round,i=Math.floor,r=Math.PI,o=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},h=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),h=d(o)*f(i),u=f(e)*d(i)-d(e)*f(i)*f(o),a=c(g(h,u))-22.5;return a<0&&(a+=360),["NE","E","SE","S","SW","W","NW","N"][a=parseInt(a/45)]},u=function(t,n){var e=t.x,i=t.y;return(e-=n.x)*e+(i-=n.y)*i},a=function(t,n){return Math.sqrt(u(t,n))},v=Math.abs,p=Math.cos,w=Math.sin,y=Math.sqrt,m=Math.min,x=Math.max,b=Math.atan2,S=Math.round,P=Math.pow,A=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 i=v(t*p(n)),r=v(t*w(n)),s=o(c(n));return s<90?r=-r:s<180?(i=-i,r=-r):s<270&&(i=-i),new L(e.x+i,e.y+r)},L.random=function(t,n,e,i){return new L(h(t,n),h(e,i))},L.prototype={chooseClosest:function(t){var n=t.length;if(1===n)return new L(t[0]);for(var e=null,i=1/0,r=0;r<n;r++){var s=new L(t[r]),o=this.squaredDistance(s);o<i&&(e=s,i=o)}return e},adhereToRect:function(t){return t.containsPoint(this)||(this.x=m(x(this.x,t.x),t.x+t.width),this.y=m(x(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 a(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 L((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 L(t).theta(this));return this.offset(p(e)*n,-w(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(o(-n));var e=p(n),i=w(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 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 u(this,t)},theta:function(t){var n=-((t=new L(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 L(t)||new L(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 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 E=L,T=Math.max,I=Math.min,C=function(t,n){return this instanceof C?t instanceof C?new C(t.start,t.end):(this.start=new L(t),void(this.end=new L(n))):new C(t,n)};C.prototype={angle:function(){var t=new L(this.start.x+1,this.start.y);return this.start.angleBetween(this.end,t)},bbox:function(){var t=I(this.start.x,this.end.x),n=I(this.start.y,this.end.y),e=T(this.start.x,this.end.x),i=T(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=I(1,T(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 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),i=n.x*e.y-n.y*e.x,r=new L(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 L(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 a(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,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 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 u(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 L(this.end.x-this.start.x,this.end.y-this.start.y)}},C.prototype.intersection=C.prototype.intersect;var D=C,O=Math.sqrt,M=Math.round,N=Math.pow,R=function(t,n,e){return this instanceof R?t instanceof R?new R(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 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 L(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(),h=e.difference(new L(this)),u=new L(o.x/(r*r),o.y/(s*s)),a=new L(h.x/(r*r),h.y/(s*s)),c=o.dot(u),l=o.dot(a),f=l*l-c*(h.dot(a)-1);if(f<0)return null;if(0<f){var d=O(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 L(t),n&&t.rotate(new L(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 L(this.x,this.y),-n):e;var s=r/i,o=s*s,h=this.a*this.a,u=this.b*this.b,a=O(1/(1/h+o/u)),c=s*(a=i<0?-a:a);return e=new L(this.x+a,this.y+c),n?e.rotate(new L(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=N(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,h=this.bbox().center(),u=h.x,a=h.y,c=i>h.x+s/2,l=i<h.x-s/2;return c||l?e=s*s/(i-u)-s*s*(r-a)*((n=i>h.x?r-30:r+30)-a)/(o*o*(i-u))+u:n=o*o/(r-a)-o*o*(i-u)*((e=r>h.y?i+30:i-30)-u)/(s*s*(r-a))+a,new L(e,n).theta(t)},toString:function(){return new L(this.x,this.y).toString()+" "+this.a+" "+this.b}};var q=R,z=Math.abs,j=Math.cos,k=Math.sin,W=Math.min,V=Math.max,F=Math.round,Z=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 L;e=i=1/0,r=s=-1/0;for(var h=0;h<t.length;h++){o.update(t[h]);var u=o.x,a=o.y;u<e&&(e=u),r<u&&(r=u),a<i&&(i=a),s<a&&(s=a)}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 h=0;h<t.length;h++){o.update(t[h]);var u=o.x,a=o.y,c=u+o.width,l=a+o.height;u<e&&(e=u),r<c&&(r=c),a<i&&(i=a),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=z(k(n)),i=z(j(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 L(this.x,this.y+this.height)},bottomLine:function(){return new C(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=new L(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 h=n.x,u=n.y,a=e.x,c=e.y;return s+=a,i+=h,o+=c,r+=u,h<=a&&s<=i&&u<=c&&o<=r},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(),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=V(n.x,i.x),o=V(n.y,i.y);return new B(s,o,W(e.x,r.x)-s,W(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 L(t);var e,i=new L(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 h=r[o].intersection(s);if(null!==h){e=h;break}}return e&&n&&e.rotate(i,-n),e},leftLine:function(){return new C(this.topLeft(),this.bottomLeft())},leftMiddle:function(){return new L(this.x,this.y+this.height/2)},maxRectScaleToFit:function(t,n){var e,i,r,s,o,h,u,a;t=new B(t),n||(n=t.center());var c=n.x,l=n.y;e=i=r=s=o=h=u=a=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&&(h=(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&&(u=(this.y-l)/(g.y-l));var v=t.bottomLeft();return v.x<c&&(s=(this.x-c)/(v.x-c)),v.y>l&&(a=(this.y+this.height-l)/(v.y-l)),{sx:W(e,i,r,s),sy:W(o,h,u,a)}},maxRectUniformScaleToFit:function(t,n){var e=this.maxRectScaleToFit(t,n);return W(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 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 C(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=Z(10,t)}return this.x=F(this.x*n)/n,this.y=F(this.y*n)/n,this.width=F(this.width*n)/n,this.height=F(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,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 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,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 G=B,U=Math.abs,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){if(""===(t=t.trim()))return new X;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 X(n)},X.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 h=r[o],u=h.x,a=h.y;u<t&&(t=u),n<u&&(n=u),a<e&&(e=a),i<a&&(i=a)}return new B(t,e,n-t,i-e)},clone:function(){var t=this.points,n=t.length;if(0===n)return new X;for(var e=[],i=0;i<n;i++){var r=t[i].clone();e.push(r)}return new X(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,h=0;h<o;h++){var u=new C(e[h],e[h+1]),a=u.length(),c=u.closestPointNormalizedLength(t),l=u.pointAt(c).squaredDistance(t);l<r&&(r=l,n=s+c*a),s+=a}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,h=0;o<e;o++){var u=n[s],a=n[o];if(t.equals(u))return!0;var c=new C(u,a);if(c.containsPoint(t))return!0;if(r<=u.y&&r>a.y||r>u.y&&r<=a.y){var l=u.x-i>a.x-i?u.x-i:a.x-i;if(0<=l){var f=new L(i+l,r),d=new C(t,f);c.intersect(d)&&h++}}s=o}return h%2==1},convexHull:function(){var t,n,e,i=this.points,r=i.length;if(0===r)return new X;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 h=[i[t],t,o];s.push(h)}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 u=s[s.length-1];s.unshift(u)}for(var a,c,l,f,d,g,v,p={},w=[];0!==s.length;)if(c=(a=s.pop())[0],!p.hasOwnProperty(a[0]+"@@"+a[1]))for(var y=!1;!y;)if(w.length<2)w.push(a),y=!0;else{f=(l=w.pop())[0];var m=(g=(d=w.pop())[0]).cross(f,c);if(m<0)w.push(d),w.push(l),w.push(a),y=!0;else if(0===m){var x=f.angleBetween(g,c);U(x-180)<1e-10?(p[l[0]+"@@"+l[1]]=f,w.push(d)):f.equals(c)||g.equals(f)?(p[l[0]+"@@"+l[1]]=f,w.push(d)):U((x+1)%360-1)<1e-10&&(w.push(d),s.push(l))}else p[l[0]+"@@"+l[1]]=f,w.push(d)}2<w.length&&w.pop();var b=-1;for(n=w.length,t=0;t<n;t++){var S=w[t][1];(void 0===v||S<v)&&(v=S,b=t)}var P=[];if(0<b){var A=w.slice(b),L=w.slice(0,b);P=A.concat(L)}else P=w;var E=[];for(n=P.length,t=0;t<n;t++)E.push(P[t][0]);return new X(E)},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],h=i[r+1],u=new C(o,h),a=n.intersectionWithLine(u);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=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 h=i?o:s-1-o,u=n[h],a=n[h+1],c=new C(u,a),l=u.distance(a);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],h=n[r],u=n[s];new C(o,u).closestPoint(h).distance(h)<=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,h=0;h<o;h++){var u=r?h:o-1-h,a=n[u],c=n[u+1],l=new C(a,c),f=a.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(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 Y=Math.abs,J=Math.sqrt,_=Math.min,H=Math.max,$=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 L(t),this.controlPoint1=new L(n),this.controlPoint2=new L(e),void(this.end=new L(i))):new K(t,n,e,i)};K.throughPoints=function(){function u(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 L((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),i[0]=new L(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=u(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 h=u(s);for(n=0;n<r;n++)e.push(new L(o[n],h[n])),n<r-1?i.push(new L(2*t[n+1].x-o[n+1],2*t[n+1].y-h[n+1])):i.push(new L((t[r].x+o[r-1])/2,(t[r].y+h[r-1])/2));return[e,i]}(t),e=[],i=n[0].length,r=0;r<i;r++){var s=new L(n[0][r].x,n[0][r].y),o=new L(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,h,u=this.start,a=this.controlPoint1,c=this.controlPoint2,l=this.end,f=u.x,d=u.y,g=a.x,v=a.y,p=c.x,w=c.y,y=l.x,m=l.y,x=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*w,t=-3*d+9*v-9*w+3*m,3*v-3*d),Y(t)<1e-12){if(Y(n)<1e-12)continue;0<(i=-e/n)&&i<1&&b.push(i)}else h=J(o=n*n-4*e*t),o<0||(0<(r=(-n+h)/(2*t))&&r<1&&b.push(r),0<(s=(-n-h)/(2*t))&&s<1&&b.push(s));for(var A,L,E,T=b.length,I=T;T--;)L=(A=1-(i=b[T]))*A*A*f+3*A*A*i*g+3*A*i*i*p+i*i*i*y,S[0][T]=L,E=A*A*A*d+3*A*A*i*v+3*A*i*i*w+i*i*i*m,S[1][T]=E,x[T]={X:L,Y:E};b[I]=0,b[I+1]=1,x[I]={X:f,Y:d},x[I+1]={X:y,Y:m},S[0][I]=f,S[1][I]=d,S[0][I+1]=y,S[1][I+1]=m,b.length=I+2,S[0].length=I+2,S[1].length=I+2,x.length=I+2;var C=_.apply(null,S[0]),D=_.apply(null,S[1]),O=H.apply(null,S[0]),M=H.apply(null,S[1]);return new B(C,D,O-C,M-D)},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,h,u,a=void 0===(n=n||{}).precision?this.PRECISION:n.precision,c=void 0===n.subdivisions?this.getSubdivisions({precision:a}):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),w=v+p;(!u||w<u)&&(i=d*f,r=(d+1)*f,s=v,o=p,h=(e=g).start.distance(g.end),u=w)}for(var y=$(10,-a);;){var m=s?Y(s-o)/s:0,x=o?Y(s-o)/o:0;if(m<y||x<y||(!s||s<h*y||(!o||o<h*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,L=b[1].start.distance(t),E=b[1].end.distance(t);o=A<=L+E?(e=b[0],r-=f,s=S,P):(e=b[1],i+=f,s=L,E)}},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,h=s.startControlPoint2,u=s.divider,a=s.dividerControlPoint1,c=s.dividerControlPoint2;return[new K(n,o,h,u),new K(u,a,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),h=new C(i,r).pointAt(t),u=new C(s,o).pointAt(t),a=new C(o,h).pointAt(t);return{startControlPoint1:s,startControlPoint2:u,divider:new C(u,a).pointAt(t),dividerControlPoint1:a,dividerControlPoint2:h}},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=$(10,-n),s=0;;){s+=1;for(var o=[],h=e.length,u=0;u<h;u++){var a=e[u].divide(.5);o.push(a[0],a[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,h,u=void 0===(n=n||{}).precision?this.PRECISION:n.precision,a=void 0===n.subdivisions?this.getSubdivisions({precision:u}):n.subdivisions,c={precision:u,subdivisions:a},l=0,f=a.length,d=1/f,g=0;g<f;g++){var v=e?g:f-1-g,p=a[g],w=p.endpointDistance();if(t<=l+w){i=p,r=v*d,s=(v+1)*d,o=e?t-l:w+l-t,h=e?w+l-t:t-l;break}l+=w}if(!i)return e?1:0;for(var y=this.length(c),m=$(10,-u);;){var x,b;if((0!==y?o/y:0)<m)return r;if((0!==y?h/y:0)<m)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-(x=o)):(i=S[1],r+=d,A-(x=o-P)),o=x,h=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 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}},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 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(Q.createSegment("M",o)):this.appendSegment(Q.createSegment("L",o))}}else;};function tt(t,n){return n.unshift(null),new(Function.prototype.bind.apply(t,n))}function nt(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,h,u=r[n];for(h in u)u.hasOwnProperty(h)&&(delete s[h],o=Object.getOwnPropertyDescriptor(u,h),Object.defineProperty(s,h,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 tt(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 h=t[o];n=this.prepareSegment(h,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,h=1/0,u=0;u<i;u++){var a=e[u],c=o[u];if(a.isVisible){var l=a.closestPointT(t,{precision:s,subdivisions:c}),f=a.pointAtT(l),d=new C(f,t).squaredLength();d<h&&(r={segmentIndex:u,value:l},h=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,h=1/0,u=0;u<i;u++){var a=e[u],c=o[u];if(a.isDifferentiable()){var l=a.closestPointT(t,{precision:s,subdivisions:c}),f=a.pointAtT(l),d=new C(f,t).squaredLength();d<h&&(r=a.tangentAtT(l),h=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,h,u,a,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()&&(u=s,a=g,t<=d+p)){h=g,o=s.divideAtLength((i?1:-1)*(t-d),{precision:l,subdivisions:v});break}d+=p}if(!u)return null;o||(h=a,c=i?1:0,o=u.divideAtT(c));var w=this.clone();w.replaceSegment(h,o);var y=h,m=h+1,x=h+2;o[0].isDifferentiable()||(w.removeSegment(y),m-=1,x-=1);var b=w.getSegment(m).start;w.insertSegment(m,Q.createSegment("M",b)),x+=1,o[1].isDifferentiable()||(w.removeSegment(x-1),x-=1);var S=x-y-1;for(r=x;r<w.segments.length;r++){var P=this.getSegment(r-S);if("Z"===(s=w.getSegment(r)).type&&!P.subpathStartSegment.end.equals(s.subpathStartSegment.end)){var A=Q.createSegment("L",P.end);w.replaceSegment(r,A)}}return[new Q(w.segments.slice(0,m)),new Q(w.segments.slice(m))]},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 h=n.length,u=0;u<h;u++){var a=n[u];e=this.prepareSegment(a,s,o),i.splice(t+u,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],h=t.intersect(o);h&&(e||(e=[]),Array.isArray(h)?Array.prototype.push.apply(e,h):e.push(h))}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 h=n[o],u=r[o];s+=h.length({subdivisions:u})}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,h=void 0===(n=n||{}).precision?this.PRECISION:n.precision,u=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:h}):n.segmentSubdivisions,a=0,c=0;c<r;c++){var l=e[c];o=u[c],a+=l.length({precisison:h,subdivisions:o})}return l=e[r],o=u[r],a+=l.lengthAtT(s,{precisison:h,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,h=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):n.segmentSubdivisions,u=0,a=0;a<i;a++){var c=r?a:i-1-a,l=e[c],f=h[c],d=l.length({precision:o,subdivisions:f});if(l.isVisible){if(t<=u+d)return l.pointAtLength((r?1:-1)*(t-u),{precision:o,subdivisions:f});s=l}u+=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,h=s.nextSegment,u=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 a=n.length,c=0;c<a;c++){var l=n[c];e=this.prepareSegment(l,o,h),i.splice(t+c,0,e),o=e,u&&e.isSubpathStart&&(u=!1)}}else{if(!n||!n.isSegment)throw new Error("Segment required.");e=this.prepareSegment(n,o,h),i.splice(t,1,e),u&&e.isSubpathStart&&(u=!1)}u&&h&&this.updateSubpathStartSegment(h)},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,h=null,u=0,a=0;a<i;a++){var c=r?a:i-1-a,l=e[c],f=o[c],d=l.length({precision:s,subdivisions:f});if(l.isVisible){if(t<=u+d)return c;h=c}u+=d}return h},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,h=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):n.segmentSubdivisions,u=0,a=0;a<i;a++){var c=r?a:i-1-a,l=e[c],f=h[c],d=l.length({precision:o,subdivisions:f});if(l.isDifferentiable()){if(t<=u+d)return l.tangentAtLength((r?1:-1)*(t-u),{precision:o,subdivisions:f});s=l}u+=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=[],h=0;h<e;h++){var u=n[h];if(u.isVisible){var a=r[h];if(0<a.length){var c=a.map(function(t){return t.start});Array.prototype.push.apply(o,c)}else o.push(u.start)}else 0<o.length&&(o.push(n[h-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 X(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 et={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(et,"end",{configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(et,"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(et,"type",{configurable:!0,enumerable:!0,get:function(){throw new Error("Bad segment declaration. No type specified.")}});var it=function(){for(var t,n,e=arguments,i=[],r=arguments.length,s=0;s<r;s++)i.push(e[s]);if(!(this instanceof it))return tt(it,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 L(+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(tt(it,o));return t}if(1===r)return this.end=new L(i[0]),this;for(t=[],s=0;s<r;s+=1)n=i[s],t.push(new it(n));return t},rt={clone:function(){return new it(this.end)},divideAt:function(t){var n=new C(this.start,this.end).divideAt(t);return[new it(n[0]),new it(n[1])]},divideAtLength:function(t){var n=new C(this.start,this.end).divideAtLength(t);return[new it(n[0]),new it(n[1])]},getSubdivisions:function(){return[]},isDifferentiable:functio