UNPKG

@joint/core

Version:

JavaScript diagramming library

8 lines (6 loc) 64.3 kB
/*! JointJS v4.1.3 (2025-02-04) - 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/. */ ((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){let{round:M,floor:W,PI:j}=Math;function r(t){return t%360+(t<0?360:0)}function e(t,n){return n*M(t/n)}function s(t){return 180*t/j%360}function o(t,n){return(t=(n=n||!1)?t:t%360)*j/180}function h(t,n){var e;return void 0===n?(n=void 0===t?1:t,t=0):n<t&&(e=t,t=n,n=e),W(Math.random()*(n-t+1)+t)}function k(t,n){var e=o(t.y),i=o(n.y),t=t.x,n=n.x,n=o(n-t),t=Z(n)*u(i),e=u(e)*Z(i)-Z(e)*u(i)*u(n);return(i=s(B(t,e))-22.5)<0&&(i+=360),["NE","E","SE","S","SW","W","NW","N"][i=parseInt(i/45)]}function V(t,n){var e=t.x,t=t.y;return(e-=n.x)*e+(t-=n.y)*t}function F(t,n){return Math.sqrt(V(t,n))}function d(t,n){if(!(this instanceof d))return new d(t,n);var e;"string"==typeof t?(e=t.split(-1===t.indexOf("@")?" ":"@"),t=parseFloat(e[0]),n=parseFloat(e[1])):Object(t)===t&&(n=t.y,t=t.x),this.x=void 0===t?0:t,this.y=void 0===n?0:n}let{cos:u,sin:Z,atan2:B}=Math,a={Point:1,Line:2,Ellipse:3,Rect:4,Polyline:5,Polygon:6,Curve:7,Path:8},{abs:c,cos:G,sin:U,sqrt:X,min:Y,max:$,atan2:H,round:J,pow:_,PI:K}=Math;d.fromPolar=function(t,n,e){e=new d(e);var i=c(t*G(n)),t=c(t*U(n)),n=r(s(n));return n<90?t=-t:n<180?(i=-i,t=-t):n<270&&(i=-i),new d(e.x+i,e.y+t)},d.random=function(t,n,e,i){return new d(h(t,n),h(e,i))},d.prototype={type:a.Point,chooseClosest:function(t){var n=t.length;if(1===n)return new d(t[0]);for(var e=null,i=1/0,r=0;r<n;r++){var s=new d(t[r]),o=this.squaredDistance(s);o<i&&(e=s,i=o)}return e},adhereToRect:function(t){return t.containsPoint(this)||(this.x=Y($(this.x,t.x),t.x+t.width),this.y=Y($(this.y,t.y),t.y+t.height)),this},angleBetween:function(t,n){n=this.equals(t)||this.equals(n)?NaN:this.theta(n)-this.theta(t);return n<0&&(n+=360),n},bearing:function(t){return k(this,t)},changeInAngle:function(t,n,e){return this.clone().offset(-t,-n).theta(e)-this.theta(e)},clone:function(){return new d(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 d(this.x-(t||0),this.y-(n||0))},distance:function(t){return F(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 d((1-n)*e+n*t.x,(1-n)*i+n*t.y)},magnitude:function(){return X(this.x*this.x+this.y*this.y)||.01},manhattanDistance:function(t){return c(t.x-this.x)+c(t.y-this.y)},move:function(t,n){t=o(new d(t).theta(this));return this.offset(G(t)*n,-U(t)*n)},normalize:function(t){t=(t||1)/this.magnitude();return this.scale(t,t)},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 d(t).move(this,this.distance(t))},rotate:function(t,n){var e,i;return 0!==n&&(t=t||new d(0,0),n=o(r(-n)),e=G(n),n=U(n),i=e*(this.x-t.x)-n*(this.y-t.y)+t.x,n=n*(this.x-t.x)+e*(this.y-t.y)+t.y,this.x=i,this.y=n),this},round:function(t){let n=1;if(t)switch(t){case 1:n=10;break;case 2:n=100;break;case 3:n=1e3;break;default:n=_(10,t)}return this.x=J(this.x*n)/n,this.y=J(this.y*n)/n,this},scale:function(t,n,e){return e=e&&new d(e)||new d(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=e(this.x,t),this.y=e(this.y,n||t),this},squaredDistance:function(t){return V(this,t)},theta:function(t){var n=-((t=new d(t)).y-this.y),t=t.x-this.x,n=H(n,t);return 180*(n=n<0?2*K+n:n)/K},toJSON:function(){return{x:this.x,y:this.y}},toPolar:function(t){t=t&&new d(t)||new d(0,0);var n=this.x,e=this.y;return this.x=X((n-t.x)*(n-t.x)+(e-t.y)*(e-t.y)),this.y=o(t.theta(new d(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 d(0,0).angleBetween(this,t)}},d.prototype.translate=d.prototype.offset;var Q=d;let{max:tt,min:nt}=Math,g=function(t,n){return this instanceof g?t instanceof g?new g(t.start,t.end):(this.start=new d(t),void(this.end=new d(n))):new g(t,n)};g.prototype={type:a.Line,angle:function(){var t=new d(this.start.x+1,this.start.y);return this.start.angleBetween(this.end,t)},bbox:function(){var t=nt(this.start.x,this.end.x),n=nt(this.start.y,this.end.y),e=tt(this.start.x,this.end.x),i=tt(this.start.y,this.end.y);return new A(t,n,e-t,i-n)},bearing:function(){return k(this.start,this.end)},clone:function(){return new g(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){t=this.vector().dot(new g(this.start,t).vector()),t=nt(1,tt(0,t/this.squaredLength()));return t!=t?0:t},closestPointTangent:function(t){return this.tangentAt(this.closestPointNormalizedLength(t))},containsPoint:function(t){var n,e=this.start,i=this.end;return 0===e.cross(t,i)&&(n=this.length(),!(new g(e,t).length()>n||new g(t,i).length()>n))},divideAt:function(t){t=this.pointAt(t);return[new g(this.start,t),new g(t,this.end)]},divideAtLength:function(t){t=this.pointAtLength(t);return[new g(this.start,t),new g(t,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){return t&&t.intersectionWithLine?(n=t.intersectionWithLine(this,n))&&t instanceof g?n[0]:n:null},intersectionWithLine:function(t){var n=new d(this.end.x-this.start.x,this.end.y-this.start.y),e=new d(t.end.x-t.start.x,t.end.y-t.start.y),i=n.x*e.y-n.y*e.x,t=new d(t.start.x-this.start.x,t.start.y-this.start.y),e=t.x*e.y-t.y*e.x,t=t.x*n.y-t.y*n.x;if(0==i||e*i<0||t*i<0)return null;if(0<i){if(i<e||i<t)return null}else if(e<i||t<i)return null;return[new d(this.start.x+e*n.x/i,this.start.y+e*n.y/i)]},isDifferentiable:function(){return!this.start.equals(this.end)},length:function(){return F(this.start,this.end)},midpoint:function(){return new d((this.start.x+this.end.x)/2,(this.start.y+this.end.y)/2)},parallel:function(t){var n,e,i,r,s=this.clone();return this.isDifferentiable()&&({start:n,end:e}=s,i=n.clone().rotate(e,270),r=e.clone().rotate(n,90),n.move(r,t),e.move(i,t)),s},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,r=(t<0&&(i=!1,t=-t),this.length());return r<=t?(i?e:n).clone():this.pointAt((i?t:r-t)/r)},pointOffset:function(t){t=new d(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();return n?this.scale(t=t/n,t,this.start):this},squaredLength:function(){return V(this.start,this.end)},tangentAt:function(t){var n,e;return this.isDifferentiable()?(n=this.start,e=this.end,t=this.pointAt(t),(e=new g(n,e)).translate(t.x-n.x,t.y-n.y),e):null},tangentAtLength:function(t){var n,e;return this.isDifferentiable()?(n=this.start,e=this.end,t=this.pointAtLength(t),(e=new g(n,e)).translate(t.x-n.x,t.y-n.y),e):null},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 d(this.end.x-this.start.x,this.end.y-this.start.y)}},g.prototype.intersection=g.prototype.intersect;var et=g;function i(t,n,e){return this instanceof i?t instanceof i?new i(new d(t.x,t.y),t.a,t.b):(t=new d(t),this.x=t.x,this.y=t.y,this.a=n,void(this.b=e)):new i(t,n,e)}let{sqrt:it,round:l,pow:rt}=Math;i.fromRect=function(t){return t=new A(t),new i(t.center(),t.width/2,t.height/2)},i.prototype={type:a.Ellipse,bbox:function(){return new A(this.x-this.a,this.y-this.b,2*this.a,2*this.b)},center:function(){return new d(this.x,this.y)},clone:function(){return new i(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,t=t.vector(),o=e.difference(new d(this)),h=new d(t.x/(r*r),t.y/(s*s)),r=new d(o.x/(r*r),o.y/(s*s)),s=t.dot(h),h=t.dot(r),t=h*h-s*(o.dot(r)-1);if(t<0)return null;if(0<t){o=it(t),r=(-h-o)/s,t=(-h+o)/s;if((r<0||1<r)&&(t<0||1<t))return null;0<=r&&r<=1&&n.push(e.lerp(i,r)),0<=t&&t<=1&&n.push(e.lerp(i,t))}else{o=-h/s;if(!(0<=o&&o<=1))return null;n.push(e.lerp(i,o))}return n},intersectionWithLineFromCenterToPoint:function(t,n){t=new d(t),n&&t.rotate(new d(this.x,this.y),n);var e,i,r,s=t.x-this.x,o=t.y-this.y;return r=0==s?this.bbox().pointNearestToPoint(t):(o=(t=o/s)*t,i=this.a*this.a,e=this.b*this.b,i=it(1/(1/i+o/e)),o=t*(i=s<0?-i:i),new d(this.x+i,this.y+o)),n?r.rotate(new d(this.x,this.y),-n):r},normalizedDistance:function(t){var n=t.x,t=t.y,e=this.a,i=this.b,r=this.x,s=this.y;return(n-r)*(n-r)/(e*e)+(t-s)*(t-s)/(i*i)},round:function(t){let n=1;if(t)switch(t){case 1:n=10;break;case 2:n=100;break;case 3:n=1e3;break;default:n=rt(10,t)}return this.x=l(this.x*n)/n,this.y=l(this.y*n)/n,this.a=l(this.a*n)/n,this.b=l(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;return h.x+s/2<i||i<h.x-s/2?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 d(e,n).theta(t)},toString:function(){return new d(this.x,this.y).toString()+" "+this.a+" "+this.b}};var st=i;let{abs:ot,cos:ht,sin:ut,min:f,max:at,round:p,pow:ct}=Math,A=function(t,n,e,i){if(!(this instanceof A))return new A(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};A.fromEllipse=function(t){return t=new i(t),new A(t.x-t.a,t.y-t.b,2*t.a,2*t.b)},A.fromPointUnion=function(){if(0===arguments.length)return null;var n=new d;let e,i,r,s;e=i=1/0,r=s=-1/0;for(let t=0;t<arguments.length;t++){n.update(t<0||arguments.length<=t?void 0:arguments[t]);var o=n.x,h=n.y;o<e&&(e=o),o>r&&(r=o),h<i&&(i=h),h>s&&(s=h)}return new A(e,i,r-e,s-i)},A.fromRectUnion=function(){if(0===arguments.length)return null;var n=new A;let e,i,r,s;e=i=1/0,r=s=-1/0;for(let t=0;t<arguments.length;t++){n.update(t<0||arguments.length<=t?void 0:arguments[t]);var o=n.x,h=n.y,u=o+n.width,a=h+n.height;o<e&&(e=o),u>r&&(r=u),h<i&&(i=h),a>s&&(s=a)}return new A(e,i,r-e,s-i)},A.prototype={type:a.Rect,bbox:function(t){return this.clone().rotateAroundCenter(t)},rotateAroundCenter:function(t){var n,e,i,r;return t&&({width:i,height:n}=this,t=o(t),r=i*(e=ot(ut(t)))+n*(t=ot(ht(t))),this.x+=(i-(i=i*t+n*e))/2,this.y+=(n-r)/2,this.width=i,this.height=r),this},bottomLeft:function(){return new d(this.x,this.y+this.height)},bottomLine:function(){return new g(this.bottomLeft(),this.bottomRight())},bottomMiddle:function(){return new d(this.x+this.width/2,this.y+this.height)},center:function(){return new d(this.x+this.width/2,this.y+this.height/2)},clone:function(){return new A(this)},containsPoint:function(t,n){let e,i;return t&&"string"!=typeof t?{x:e=0,y:i=0}=t:{x:e,y:i}=new d(t),n&&n.strict?e>this.x&&e<this.x+this.width&&i>this.y&&i<this.y+this.height:e>=this.x&&e<=this.x+this.width&&i>=this.y&&i<=this.y+this.height},containsRect:function(t){var n,e,i=new A(this).normalize(),t=new A(t).normalize(),r=i.width,s=i.height,o=t.width,h=t.height;return!!(r&&s&&o&&h)&&(n=i.x,i=i.y,o+=e=t.x,r+=n,h+=t=t.y,s+=i,n<=e)&&o<=r&&i<=t&&h<=s},corner:function(){return new d(this.x+this.width,this.y+this.height)},equals:function(t){var n=new A(this).normalize(),t=new A(t).normalize();return n.x===t.x&&n.y===t.y&&n.width===t.width&&n.height===t.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,e=this.origin(),i=this.corner(),r=t.origin(),t=t.corner();return t.x<=e.x||t.y<=e.y||r.x>=i.x||r.y>=i.y?null:(n=at(e.x,r.x),e=at(e.y,r.y),new A(n,e,f(i.x,t.x)-n,f(i.y,t.y)-e))},intersectionWithLine:function(t){for(var n,e=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],i=[],r=[],s=e.length,o=0;o<s;o++)null!==(n=t.intersect(e[o]))&&r.indexOf(n.toString())<0&&(i.push(n),r.push(n.toString()));return 0<i.length?i:null},intersectionWithLineFromCenterToPoint:function(t,n){t=new d(t);for(var e,i=new d(this.x+this.width/2,this.y+this.height/2),r=(n&&t.rotate(i,n),[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()]),s=new g(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 g(this.topLeft(),this.bottomLeft())},leftMiddle:function(){return new d(this.x,this.y+this.height/2)},maxRectScaleToFit:function(t,n){t=new A(t);var e,i,r,s,o,h,u,a=(n=n||t.center()).x,n=n.y,c=e=i=r=s=o=h=u=1/0,l=t.topLeft(),l=(l.x<a&&(c=(this.x-a)/(l.x-a)),l.y<n&&(s=(this.y-n)/(l.y-n)),t.bottomRight()),l=(l.x>a&&(e=(this.x+this.width-a)/(l.x-a)),n<l.y&&(o=(this.y+this.height-n)/(l.y-n)),t.topRight()),l=(l.x>a&&(i=(this.x+this.width-a)/(l.x-a)),l.y<n&&(h=(this.y-n)/(l.y-n)),t.bottomLeft());return l.x<a&&(r=(this.x-a)/(l.x-a)),n<l.y&&(u=(this.y+this.height-n)/(l.y-n)),{sx:f(c,e,i,r),sy:f(s,o,h,u)}},maxRectUniformScaleToFit:function(t,n){t=this.maxRectScaleToFit(t,n);return f(t.sx,t.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 d.prototype.offset.call(this,t,n)},origin:function(){return new d(this.x,this.y)},pointNearestToPoint:function(t){if(t=new d(t),this.containsPoint(t))switch(this.sideNearestToPoint(t)){case"right":return new d(this.x+this.width,t.y);case"left":return new d(this.x,t.y);case"bottom":return new d(t.x,this.y+this.height);case"top":return new d(t.x,this.y)}return t.adhereToRect(this)},rightLine:function(){return new g(this.topRight(),this.bottomRight())},rightMiddle:function(){return new d(this.x+this.width,this.y+this.height/2)},round:function(t){let n=1;if(t)switch(t){case 1:n=10;break;case 2:n=100;break;case 3:n=1e3;break;default:n=ct(10,t)}return this.x=p(this.x*n)/n,this.y=p(this.y*n)/n,this.width=p(this.width*n)/n,this.height=p(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 d(t)).x-this.x,e=this.x+this.width-t.x,i=t.y-this.y,r="left";return e<n&&(n=e,r="right"),i<n&&(n=i,r="top"),r=this.y+this.height-t.y<n?"bottom":r},snapToGrid:function(t,n){var e=this.origin().snapToGrid(t,n),t=this.corner().snapToGrid(t,n);return this.x=e.x,this.y=e.y,this.width=t.x-e.x,this.height=t.y-e.y,this},toJSON:function(){return{x:this.x,y:this.y,width:this.width,height:this.height}},topLine:function(){return new g(this.topLeft(),this.topRight())},topMiddle:function(){return new d(this.x+this.width/2,this.y)},topRight:function(){return new d(this.x+this.width,this.y)},toString:function(){return this.origin().toString()+" "+this.corner().toString()},union:function(t){return A.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}},A.prototype.bottomRight=A.prototype.corner,A.prototype.topLeft=A.prototype.origin,A.prototype.translate=A.prototype.offset;var lt=A;function ft(t){t=t.trim();if(""===t)return[];var n=[],e=t.split(/\b\s*,\s*|,\s*|\s+/),i=e.length;for(let t=0;t<i;t+=2)n.push({x:+e[t],y:+e[t+1]});return n}function dt(n){var e=n.length;if(0===e)return[];var i=[];for(let t=0;t<e;t++){var r=n[t].clone();i.push(r)}return i}function gt(t){var n,e=Math.abs,i=t.length;if(0===i)return[];for(s=0;s<i;s++)(void 0===n||t[s].y<n.y||t[s].y===n.y&&t[s].x>n.x)&&(n=t[s]);for(var r=[],s=0;s<i;s++){var o=n.theta(t[s]),o=(0===o&&(o=360),[t[s],s,o]);r.push(o)}r.sort(function(t,n){var e=t[2]-n[2];return e=0===e?n[1]-t[1]:e}),2<r.length&&r.unshift(r[r.length-1]);for(var h,u,a,c={},l=[];0!==r.length;)if(u=(h=r.pop())[0],!c.hasOwnProperty(h[0]+"@@"+h[1]))for(var f,d,g,p,v,y=!1;!y;)l.length<2?(l.push(h),y=!0):(d=(f=l.pop())[0],(v=(p=(g=l.pop())[0]).cross(d,u))<0?(l.push(g),l.push(f),l.push(h),y=!0):0!==v||e((v=d.angleBetween(p,u))-180)<1e-10||d.equals(u)||p.equals(d)?(c[f[0]+"@@"+f[1]]=d,l.push(g)):e((v+1)%360-1)<1e-10&&(l.push(g),r.push(f)));2<l.length&&l.pop();var w=-1,m=l.length;for(s=0;s<m;s++){var x=l[s][1];(void 0===a||x<a)&&(a=x,w=s)}var b,S,P=[],A=[];for(m=(P=0<w?(b=l.slice(w),S=l.slice(0,w),b.concat(S)):l).length,s=0;s<m;s++)A.push(P[s][0]);return A}function v(t){return this instanceof v?"string"==typeof t?new v.parse(t):void(this.points=Array.isArray(t)?t.map(d):[]):new v(t)}function y(t,n,e,i){return this instanceof y?t instanceof y?new y(t.start,t.controlPoint1,t.controlPoint2,t.end):(this.start=new d(t),this.controlPoint1=new d(n),this.controlPoint2=new d(e),void(this.end=new d(i))):new y(t,n,e,i)}v.parse=function(t){return new v(ft(t))},v.fromRect=function(t){return new v([t.topLeft(),t.topRight(),t.bottomRight(),t.bottomLeft(),t.topLeft()])},v.prototype={type:a.Polyline,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,h=h.y;u<t&&(t=u),n<u&&(n=u),h<e&&(e=h),i<h&&(i=h)}return new A(t,e,n-t,i-e)},clone:function(){return new v(dt(this.points))},closestPoint:function(t){t=this.closestPointLength(t);return this.pointAtLength(t)},closestPointLength:function(t){var n,e=this.lengthPoints(),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 g(e[h],e[h+1]),a=u.length(),c=u.closestPointNormalizedLength(t),u=u.pointAt(c).squaredDistance(t);u<r&&(r=u,n=s+c*a),s+=a}return n},closestPointNormalizedLength:function(t){var n,t=this.closestPointLength(t);return 0===t||0===(n=this.length())?0:t/n},closestPointTangent:function(t){t=this.closestPointLength(t);return this.tangentAtLength(t)},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,u=new g,a=new g,c=new d;o<e;o++){var l=n[s],f=n[o];if(t.equals(l))return!0;if(u.start=l,u.end=f,u.containsPoint(t))return!0;(r<=l.y&&r>f.y||r>l.y&&r<=f.y)&&0<=(l=l.x-i>f.x-i?l.x-i:f.x-i)&&(c.x=i+l,c.y=r,a.start=t,a.end=c,u.intersect(a))&&h++,s=o}return h%2==1},close:function(){var{start:t,end:n,points:e}=this;return t&&n&&!t.equals(n)&&e.push(t.clone()),this},lengthPoints:function(){return this.points},convexHull:function(){return new v(gt(this.points))},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 g(t),e=[],i=this.lengthPoints(),r=new g,s=0,o=i.length-1;s<o;s++){r.start=i[s],r.end=i[s+1];var h=n.intersectionWithLine(r);h&&e.push(h[0])}return 0<e.length?e:null},isDifferentiable:function(){var t=this.points,n=t.length;if(0!==n)for(var e=new g,i=n-1,r=0;r<i;r++)if(e.start=t[r],e.end=t[r+1],e.isDifferentiable())return!0;return!1},length:function(){var t=this.lengthPoints(),n=t.length;if(0===n)return 0;for(var e=0,i=n-1,r=0;r<i;r++)e+=t[r].distance(t[r+1]);return e},pointAt:function(t){var n=this.lengthPoints(),e=n.length;return 0===e?null:1===e||t<=0?n[0].clone():1<=t?n[e-1].clone():(n=this.length(),this.pointAtLength(n*t))},pointAtLength:function(t){var n=this.lengthPoints(),e=n.length;if(0===e)return null;if(1===e)return n[0].clone();for(var i=!0,r=(t<0&&(i=!1,t=-t),0),s=e-1,o=0;o<s;o++){var h=i?o:s-1-o,u=n[h],h=n[h+1],a=new g(u,h),u=u.distance(h);if(t<=r+u)return a.pointAtLength((i?1:-1)*(t-r));r+=u}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(){var n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=this.points;if(!(e.length<3)){var i=n.threshold||1e-10;let t=0;for(;e[t+2];){var r=t,s=t+1,o=t+2,r=e[r],h=e[s],o=e[o];new g(r,o).closestPoint(h).distance(h)<=i?e.splice(s,1):t+=1}}return this},tangentAt:function(t){var n=this.lengthPoints().length;if(0===n)return null;if(1===n)return null;1<(t=t<0?0:t)&&(t=1);n=this.length();return this.tangentAtLength(n*t)},tangentAtLength:function(t){var n=this.lengthPoints(),e=n.length;if(0===e)return null;if(1===e)return null;for(var i,r=!0,s=(t<0&&(r=!1,t=-t),0),o=e-1,h=0;h<o;h++){var u=r?h:o-1-h,a=n[u],u=n[u+1],c=new g(a,u),a=a.distance(u);if(c.isDifferentiable()){if(t<=s+a)return c.tangentAtLength((r?1:-1)*(t-s));i=c}s+=a}return i?i.tangentAt(r?1:0):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(v.prototype,"start",{configurable:!0,enumerable:!0,get:function(){return 0===this.points.length?null:this.points[0]}}),Object.defineProperty(v.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.points.length;return 0===t?null:this.points[t-1]}});let{abs:L,sqrt:pt,min:vt,max:yt,pow:wt}=Math;function mt(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,e[s]=(t[s]-e[s-1])/(r=(s<n-1?4:3.5)-i[s]);for(s=1;s<n;s++)e[n-s-1]-=i[n-s]*e[n-s];return e}function n(t){for(var n=[],e=arguments.length,i=1;i<e;i++)n.push(arguments[i]);if(!t)throw new Error("Missing a parent object.");var r=Object.create(t);for(e=n.length,i=0;i<e;i++){var s,o,h=n[i];for(o in h)h.hasOwnProperty(o)&&(delete r[o],s=Object.getOwnPropertyDescriptor(h,o),Object.defineProperty(r,o,s))}return r}y.throughPoints=function(t){if(!t||Array.isArray(t)&&t.length<2)throw new Error("At least 2 points are required");for(var n=(t=>{var n=[],e=[],i=t.length-1;if(1==i)n[0]=new d((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),e[0]=new d(2*n[0].x-t[0].x,2*n[0].y-t[0].y);else{for(var r=[],s=1;s<i-1;s++)r[s]=4*t[s].x+2*t[s+1].x;r[0]=t[0].x+2*t[1].x,r[i-1]=(8*t[i-1].x+t[i].x)/2;var o=mt(r);for(s=1;s<i-1;++s)r[s]=4*t[s].y+2*t[s+1].y;r[0]=t[0].y+2*t[1].y,r[i-1]=(8*t[i-1].y+t[i].y)/2;var h=mt(r);for(s=0;s<i;s++)n.push(new d(o[s],h[s])),e.push(s<i-1?new d(2*t[s+1].x-o[s+1],2*t[s+1].y-h[s+1]):new d((t[i].x+o[i-1])/2,(t[i].y+h[i-1])/2))}return[n,e]})(t),e=[],i=n[0].length,r=0;r<i;r++){var s=new d(n[0][r].x,n[0][r].y),o=new d(n[1][r].x,n[1][r].y);e.push(new y(t[r],s,o,t[r+1]))}return e},y.prototype={type:a.Curve,bbox:function(){for(var t,n,e,i,r,s=this.start,o=this.controlPoint1,h=this.controlPoint2,u=this.end,a=s.x,c=s.y,l=o.x,f=o.y,d=h.x,g=h.y,p=u.x,v=u.y,y=new Array,w=new Array,m=[new Array,new Array],x=0;x<2;++x)i=0===x?(n=6*a-12*l+6*d,t=-3*a+9*l-9*d+3*p,3*l-3*a):(n=6*c-12*f+6*g,t=-3*c+9*f-9*g+3*v,3*f-3*c),L(t)<1e-12?L(n)<1e-12||0<(e=-i/n)&&e<1&&w.push(e):(i=n*n-4*i*t,r=pt(i),i<0||(0<(i=(-n+r)/(2*t))&&i<1&&w.push(i),0<(i=(-n-r)/(2*t))&&i<1&&w.push(i)));for(var b,S,P=w.length,s=P;P--;)e=w[P],m[0][P]=b=(S=1-e)*S*S*a+3*S*S*e*l+3*S*e*e*d+e*e*e*p,m[1][P]=S=S*S*S*c+3*S*S*e*f+3*S*e*e*g+e*e*e*v,y[P]={X:b,Y:S};w[s]=0,w[s+1]=1,y[s]={X:a,Y:c},y[s+1]={X:p,Y:v},m[0][s]=a,m[1][s]=c,m[0][s+1]=p,m[1][s+1]=v,w.length=s+2,m[0].length=s+2,m[1].length=s+2,y.length=s+2;o=vt.apply(null,m[0]),h=vt.apply(null,m[1]),u=yt.apply(null,m[0]),s=yt.apply(null,m[1]);return new A(o,h,u-o,s-h)},clone:function(){return new y(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,e={precision:e,subdivisions:void 0===n.subdivisions?this.getSubdivisions({precision:e}):n.subdivisions};return this.lengthAtT(this.closestPointT(t,e),e)},closestPointNormalizedLength:function(t,n){var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,e={precision:e,subdivisions:void 0===n.subdivisions?this.getSubdivisions({precision:e}):n.subdivisions},n=this.closestPointLength(t,e);return!n||0===(t=this.length(e))?0:n/t},closestPointT:function(t,n){for(var e,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=a.length,l=c?1/c:0,f=0;f<c;f++){var d=a[f],g=d.start.distance(t),p=d.end.distance(t),v=g+p;(!h||v<h)&&(i=f*l,r=(f+1)*l,s=g,A=p,o=(e=d).start.distance(d.end),h=v)}for(var y=wt(10,-u);;){var w=s?L(s-A)/s:0,m=A?L(s-A)/A:0;if(w<y||m<y||(!s||s<o*y||(!A||A<o*y)))return s<=A?i:r;var w=e.divide(.5),m=(l/=2,w[0].start.distance(t)),x=w[0].end.distance(t),b=m+x,S=w[1].start.distance(t),P=w[1].end.distance(t),A=b<=S+P?(e=w[0],r-=l,s=m,x):(e=w[1],i+=l,s=S,P)}},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){return t<=0?this.divideAtT(0):1<=t?this.divideAtT(1):(t=this.tAt(t,n),this.divideAtT(t))},divideAtLength:function(t,n){t=this.tAtLength(t,n);return this.divideAtT(t)},divideAtT:function(t){var n,e,i=this.start,r=this.controlPoint1,s=this.controlPoint2,o=this.end;return t<=0?[new y(i,i,i,i),new y(i,r,s,o)]:1<=t?[new y(i,r,s,o),new y(o,o,o,o)]:(s=(r=this.getSkeletonPoints(t)).startControlPoint1,t=r.startControlPoint2,n=r.divider,e=r.dividerControlPoint1,r=r.dividerControlPoint2,[new y(i,s,t,n),new y(n,e,r,o)])},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;return t<=0?{startControlPoint1:n.clone(),startControlPoint2:n.clone(),divider:n.clone(),dividerControlPoint1:e.clone(),dividerControlPoint2:i.clone()}:1<=t?{startControlPoint1:e.clone(),startControlPoint2:i.clone(),divider:r.clone(),dividerControlPoint1:r.clone(),dividerControlPoint2:r.clone()}:(n=new g(n,e).pointAt(t),e=new g(e,i).pointAt(t),i=new g(i,r).pointAt(t),r=new g(n,e).pointAt(t),e=new g(e,i).pointAt(t),{startControlPoint1:n,startControlPoint2:r,divider:new g(r,e).pointAt(t),dividerControlPoint1:e,dividerControlPoint2:i})},getSubdivisions:function(t){var t=void 0===(t=t||{}).precision?this.PRECISION:t.precision,n=this.start,e=this.controlPoint1,i=this.controlPoint2,r=this.end,s=[new y(n,e,i,r)];if(0===t)return s;if(!this.isDifferentiable())return s;for(var o=this.endpointDistance(),h=wt(10,-t),u=2,a=(0===e.cross(n,r)&&0===i.cross(n,r)&&(u=2*t),0);;){a+=1;for(var c=[],l=s.length,f=0;f<l;f++){var d=s[f].divide(.5);c.push(d[0],d[1])}for(var g=0,p=c.length,v=0;v<p;v++)g+=c[v].endpointDistance();if(u<=a)if((0!==g?(g-o)/g:0)<h)return c;s=c,o=g}},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){return t<=0?0:(n=void 0===(n=n||{}).precision?this.PRECISION:n.precision,this.divide(t)[0].length({precision:n}))},pointAt:function(t,n){return t<=0?this.start.clone():1<=t?this.end.clone():(t=this.tAt(t,n),this.pointAtT(t))},pointAtLength:function(t,n){t=this.tAtLength(t,n);return this.pointAtT(t)},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);t=this.tAt(t,n);return this.tangentAtT(t)},tangentAtLength:function(t,n){return this.isDifferentiable()?(t=this.tAtLength(t,n),this.tangentAtT(t)):null},tangentAtT:function(t){if(!this.isDifferentiable())return null;t<0?t=0:1<t&&(t=1);var t=this.getSkeletonPoints(t),n=t.startControlPoint2,e=t.dividerControlPoint1,t=t.divider,e=new g(n,e);return e.translate(t.x-n.x,t.y-n.y),e},tAt:function(t,n){var e;return t<=0?0:1<=t?1:(e={precision:e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,subdivisions:void 0===n.subdivisions?this.getSubdivisions({precision:e}):n.subdivisions},n=this.length(e),this.tAtLength(n*t,e))},tAtLength:function(t,n){for(var e,i,r,s=!0,o=(t<0&&(s=!1,t=-t),void 0===(n=n||{}).precision?this.PRECISION:n.precision),h=void 0===n.subdivisions?this.getSubdivisions({precision:o}):n.subdivisions,n={precision:o,subdivisions:h},u=0,a=h.length,c=1/a,l=0;l<a;l++){var f=s?l:a-1-l,d=h[l],g=d.endpointDistance();if(t<=u+g){e=d,i=f*c,r=(f+1)*c,b=s?t-u:g+u-t,S=s?g+u-t:t-u;break}u+=g}if(!e)return s?1:0;for(var p=this.length(n),v=wt(10,-o);;){var y,w=0!==p?b/p:0;if(w<v)return i;if((0!==p?S/p:0)<v)return r;var w=e.divide(.5),m=(c/=2,w[0].endpointDistance()),x=w[1].endpointDistance(),w=b<=m?(e=w[0],r-=c,m-(y=b)):(e=w[1],i+=c,x-(y=b-m)),b=y,S=w}},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 v(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}},y.prototype.divide=y.prototype.divideAtT;function S(t){if(!(this instanceof S))return new S(t);if("string"==typeof t)return new S.parse(t);var n;if(this.segments=[],t)if(Array.isArray(t)&&0!==t.length)if(n=(t=t.reduce(function(t,n){return t.concat(n)},[])).length,t[0].isSegment)for(r=0;r<n;r++){var e=t[r];this.appendSegment(e)}else for(var i=null,r=0;r<n;r++){var s=t[r];if(!(s instanceof g||s instanceof y))throw new Error("Cannot construct a path segment from the provided object.");0===r&&this.appendSegment(S.createSegment("M",s.start)),i&&!i.end.equals(s.start)&&this.appendSegment(S.createSegment("M",s.start)),s instanceof g?this.appendSegment(S.createSegment("L",s.end)):s instanceof y&&this.appendSegment(S.createSegment("C",s.controlPoint1,s.controlPoint2,s.end)),i=s}else if(t.isSegment)this.appendSegment(t);else if(t instanceof g)this.appendSegment(S.createSegment("M",t.start)),this.appendSegment(S.createSegment("L",t.end));else if(t instanceof y)this.appendSegment(S.createSegment("M",t.start)),this.appendSegment(S.createSegment("C",t.controlPoint1,t.controlPoint2,t.end));else{if(!(t instanceof v))throw new Error("Cannot construct a path from the provided object.");if(t.points&&0!==t.points.length)for(n=t.points.length,r=0;r<n;r++){var o=t.points[r];0===r?this.appendSegment(S.createSegment("M",o)):this.appendSegment(S.createSegment("L",o))}}}function w(t,n){return n.unshift(null),new(Function.prototype.bind.apply(t,n))}S.parse=function(t){if(!t)return new S;for(var n=new S,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),s=S.createSegment.apply(this,s);n.appendSegment(s)}return n},S.createSegment=function(t){if(!t)throw new Error("Type must be provided.");var n=S.segmentTypes[t];if(!n)throw new Error(t+" is not a recognized path segment type.");for(var e=[],i=arguments.length,r=1;r<i;r++)e.push(arguments[r]);return w(n,e)},S.prototype={type:a.Path,appendSegment:function(t){var n=this.segments,e=n.length,i=0!==e?n[e-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 r=t.length,s=0;s<r;s++){var o=t[s],h=this.prepareSegment(o,i,null);n.push(h),i=h}}else{if(!t||!t.isSegment)throw new Error("Segment required.");h=this.prepareSegment(t,i,null),n.push(h)}},bbox:function(){var t=this.segments,n=t.length;if(0===n)return null;for(var e,i=0;i<n;i++){var r,s=t[i];s.isVisible&&(s=s.bbox(),r=r?r.union(s):s)}return r||(e=t[n-1],new A(e.end.x,e.end.y,0,0))},clone:function(){for(var t=this.segments,n=t.length,e=new S,i=0;i<n;i++){var r=t[i].clone();e.appendSegment(r)}return e},closestPoint:function(t,n){t=this.closestPointT(t,n);return t?this.pointAtT(t):null},closestPointLength:function(t,n){var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,e={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},n=this.closestPointT(t,e);return n?this.lengthAtT(n,e):0},closestPointNormalizedLength:function(t,n){var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,e={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},n=this.closestPointLength(t,e);return 0===n||0===(t=this.length(e))?0:n/t},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];a.isVisible&&(c=a.closestPointT(t,{precision:s,subdivisions:c}),a=a.pointAtT(c),(a=new g(a,t).squaredLength())<h)&&(r={segmentIndex:u,value:c},h=a)}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,c=e[u],l=o[u];c.isDifferentiable()&&(l=c.closestPointT(t,{precision:s,subdivisions:l}),a=c.pointAtT(l),(a=new g(a,t).squaredLength())<h)&&(r=c.tangentAtT(l),h=a)}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;1<(t=t<0?0:t)&&(t=1);var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,e={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},n=this.length(e);return this.divideAtLength(n*t,e)},divideAtLength:function(t,n){var e=this.segments.length;if(0===e)return null;for(var i,r,s,o,h=!0,u=(t<0&&(h=!1,t=-t),void 0===(n=n||{}).precision?this.PRECISION:n.precision),a=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:u}):n.segmentSubdivisions,c=0,l=0;l<e;l++){var f=h?l:e-1-l,d=this.getSegment(f),g=a[f],p=d.length({precision:u,subdivisions:g});if(d.isDifferentiable()&&(s=d,o=f,t<=c+p)){r=f,i=d.divideAtLength((h?1:-1)*(t-c),{precision:u,subdivisions:g});break}c+=p}if(!s)return null;i||(r=o,i=s.divideAtT(h?1:0));var v=this.clone(),n=(v.replaceSegment(r,i),r),y=r+1,w=r+2,m=(i[0].isDifferentiable()||(v.removeSegment(n),--y,--w),v.getSegment(y).start),x=(v.insertSegment(y,S.createSegment("M",m)),w+=1,i[1].isDifferentiable()||(v.removeSegment(w-1),--w),w-n-1);for(l=w;l<v.segments.length;l++){var b=this.getSegment(l-x);"Z"!==(d=v.getSegment(l)).type||b.subpathStartSegment.end.equals(d.subpathStartSegment.end)||(b=S.createSegment("L",b.end),v.replaceSegment(l,b))}return[new S(v.segments.slice(0,y)),new S(v.segments.slice(y))]},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(e<=(t=t<0?e+t: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(){var n=this.clone().validate().segments,e=n.length,i=[];for(let t=0;t<e;t++){var r=n[t];r.isSubpathStart?i.push(new S(r)):i[i.length-1].appendSegment(r)}return i},insertSegment:function(t,n){var e=this.segments,i=e.length;if(i<(t=t<0?i+t+1:t)||t<0)throw new Error("Index out of range.");var r=null,s=null;if(0!==i&&(s=1<=t?(r=e[t-1]).nextSegment:e[0]),Array.isArray(n)){if(!(n=n.reduce(function(t,n){return t.concat(n)},[]))[0].isSegment)throw new Error("Segments required.");for(var o=n.length,h=0;h<o;h++){var u=n[h],a=this.prepareSegment(u,r,s);e.splice(t+h,0,a),r=a}}else{if(!n||!n.isSegment)throw new Error("Segment required.");a=this.prepareSegment(n,r,s),e.splice(t,0,a)}},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],o=t.intersect(o);o&&(e=e||[],Array.isArray(o)?Array.prototype.push.apply(e,o):e.push(o))}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;for(var t=t.value,s=(i<=r?(r=i-1,t=1):t<0?t=0:1<t&&(t=1),void 0===(n=n||{}).precision?this.PRECISION:n.precision),o=void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:s}):n.segmentSubdivisions,h=0,u=0;u<r;u++){var a=e[u],c=o[u];h+=a.length({precisison:s,subdivisions:c})}return c=o[r],h+=(a=e[r]).lengthAtT(t,{precisison:s,subdivisions:c})},pointAt:function(t,n){var e;return 0===this.segments.length?null:t<=0?this.start.clone():1<=t?this.end.clone():(e={precision:e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},n=this.length(e),this.pointAtLength(n*t,e))},pointAtLength:function(t,n){var e=this.segments,i=e.length;if(0===i)return null;if(0===t)return this.start.clone();for(var r,s=!0,o=(t<0&&(s=!1,t=-t),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=s?a:i-1-a,l=e[c],c=h[c],f=l.length({precision:o,subdivisions:c});if(l.isVisible){if(t<=u+f)return l.pointAtLength((s?1:-1)*(t-u),{precision:o,subdivisions:c});r=l}u+=f}return r?s?r.end:r.start:e[i-1].end.clone()},pointAtT:function(t){var n,e=this.segments,i=e.length;return 0===i?null:(n=t.segmentIndex)<0?e[0].pointAtT(0):i<=n?e[i-1].pointAtT(1):((i=t.value)<0?i=0:1<i&&(i=1),e[n].pointAtT(i))},PRECISION:3,prepareSegment:function(t,n,e){t.previousSegment=n,t.nextSegment=e,n&&(n.nextSegment=t),e&&(e.previousSegment=t);n=t;return t.isSubpathStart&&(t.subpathStartSegment=t,n=e),n&&this.updateSubpathStartSegment(n),t},removeSegment:function(t){var n=this.segments,e=n.length;if(0===e)throw new Error("Path has no segments.");if(e<=(t=t<0?e+t:t)||t<0)throw new Error("Index out of range.");e=n.splice(t,1)[0],n=e.previousSegment,t=e.nextSegment;n&&(n.nextSegment=t),t&&(t.previousSegment=n),e.isSubpathStart&&t&&this.updateSubpathStartSegment(t)},replaceSegment:function(t,n){var e=this.segments,i=e.length;if(0===i)throw new Error("Path has no segments.");if(i<=(t=t<0?i+t:t)||t<0)throw new Error("Index out of range.");var i=e[t],r=i.previousSegment,s=i.nextSegment,o=i.isSubpathStart;if(Array.isArray(n)){if(!(n=n.reduce(function(t,n){return t.concat(n)},[]))[0].isSegment)throw new Error("Segments required.");e.splice(t,1);for(var h=n.length,u=0;u<h;u++){var a=n[u],c=this.prepareSegment(a,r,s);e.splice(t+u,0,c),r=c,o&&c.isSubpathStart&&(o=!1)}}else{if(!n||!n.isSegment)throw new Error("Segment required.");c=this.prepareSegment(n,r,s),e.splice(t,1,c),o&&c.isSubpathStart&&(o=!1)}o&&s&&this.updateSubpathStartSegment(s)},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){t=this.segmentIndexAt(t,n);return t?this.getSegment(t):null},segmentAtLength:function(t,n){t=this.segmentIndexAtLength(t,n);return t?this.getSegment(t):null},segmentIndexAt:function(t,n){if(0===this.segments.length)return null;1<(t=t<0?0:t)&&(t=1);var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,e={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},n=this.length(e);return this.segmentIndexAtLength(n*t,e)},segmentIndexAtLength:function(t,n){var e=this.segments,i=e.length;if(0===i)return null;for(var r=!0,s=(t<0&&(r=!1,t=-t),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],f=l.length({precision:s,subdivisions:f});if(l.isVisible){if(t<=u+f)return c;h=c}u+=f}return h},serialize:function(){if(this.isValid())return this.toString();throw new Error("Invalid path segments.")},tangentAt:function(t,n){if(0===this.segments.length)return null;1<(t=t<0?0:t)&&(t=1);var e=void 0===(n=n||{}).precision?this.PRECISION:n.precision,e={precision:e,segmentSubdivisions:void 0===n.segmentSubdivisions?this.getSegmentSubdivisions({precision:e}):n.segmentSubdivisions},n=this.length(e);return this.tangentAtLength(n*t,e)},tangentAtLength:function(t,n){var e=this.segments,i=e.length;if(0===i)return null;for(var r,s=!0,o=(t<0&&(s=!1,t=-t),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=s?a:i-1-a,l=e[c],c=h[c],f=l.length({precision:o,subdivisions:c});if(l.isDifferentiable()){if(t<=u+f)return l.tangentAtLength((s?1:-1)*(t-u),{precision:o,subdivisions:c});r=l}u+=f}return r?r.tangentAtT(s?1:0):null},tangentAtT:function(t){var n,e=this.segments,i=e.length;return 0===i?null:(n=t.segmentIndex)<0?e[0].tangentAtT(0):i<=n?e[i-1].tangentAtT(1):((i=t.value)<0?i=0:1<i&&(i=1),e[n].tangentAtT(i))},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,a=n[h];a.isVisible?0<(u=r[h]).length?(u=u.map(function(t){return t.start}),Array.prototype.push.apply(o,u)):o.push(a.start):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 v(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,S.createSegment("M",0,0)),this}},Object.defineProperty(S.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(S.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}});function m(){for(var t=[],n=arguments.length,e=0;e<n;e++)t.push(arguments[e]);if(!(this instanceof m))return w(m,t);if(0===n)throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates (none provided).");if(t[0]instanceof g){if(1===n)return this.end=t[0].end.clone(),this;throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates ("+n+" lines provided).")}if("string"==typeof t[0]||"number"==typeof t[0]){if(2===n)return this.end=new d(+t[0],+t[1]),this;if(n<2)throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates ("+n+" coordinates provided).");for(var i,r=[],e=0;e<n;e+=2)i=t.slice(e,e+2),r.push(w(m,i))}else{if(1===n)return this.end=new d(t[0]),this;for(r=[],e=0;e<n;e+=1)r.push(new m(t[e]))}return r}function x(){for(var t,n=[],e=arguments.length,i=0;i<e;i++)n.push(arguments[i]);if(!(this instanceof x))return w(x,n);if(0===e)throw new Error("Curveto constructor expects a curve, 3 points, or 6 coordinates (none provided).");if(n[0]instanceof y){if(1===e)return this.controlPoint1=n[0].controlPoint1.clone(),this.controlPoint2=n[0].controlPoint2.clone(),this.end=n[0].end.clone(),this;throw new Error("Curveto constructor expects a curve, 3 points, or 6 coordinates ("+e+" curves provided).")}if("string"==typeof n[0]||"number"==typeof n[0]){if(6===e)return this.controlPoint1=new d(+n[0],+n[1]),this.controlPoint2=new d(+n[2],+n[3]),this.end=new d(+n[4],+n[5]),this;if(e<6)throw new Error("Curveto constructor expects a curve, 3 points, or 6 coordinates ("+e+" coordinates provided).");for(var r,s=[],i=0;i<e;i+=6)r=n.slice(i,i+6),s.push(w(x,r))}else{if(3===e)return this.controlPoint1=new d(n[0]),this.controlPoint2=new d(n[1]),this.end=new d(n[2]),this;if(e<3)throw new Error("Curveto constructor expects a curve, 3 points, or 6 coordinates ("+e+" points provided).");for(s=[],i=0;i<e;i+=3)t=n.slice(i,i+3),s.push(w(x,t))}return s}function b(){for(var t,n=[],e=arguments.length,i=0;i<e;i++)n.push(arguments[i]);if(!(this instanceof b))return w(b,n);if(0===e)throw new Error("Moveto constructor expects a line, a curve, 1 point, or 2 coordinates (none provided).");if(n[0]instanceof g){if(1===e)return this.end=n[0].end.clone(),this;throw new Error("Moveto constructor expects a line, a curve, 1 point, or 2 coordinates ("+e+" lines provided).")}if(n[0]instanceof y){if(1===e)return this.end=n[0].end.clone(),this;throw new Error("Moveto constructor expects a line, a curve, 1 point, or 2 coordinates ("+e+" curves provided).")}if("string"==typeof n[0]||"number"==typeof n[0]){if(2===e)return this.end=new d(+n[0],+n[1]),this;if(e<2)throw new Error("Moveto constructor expects a line, a curve, 1 point, or 2 coordinates ("+e+" coordinates provided).");for(var r,s=[],i=0;i<e;i+=2)r=n.slice(i,i+2),0===i?s.push(w(b,r)):s.push(w(m,r))}else{if(1===e)return this.end=new d(n[0]),this;for(s=[],i=0;i<e;i+=1)t=n[i],0===i?s.push(new b(t)):s.push(new m(t))}return s}function P(){for(var t=[],n=arguments.length,e=0;e<n;e++)t.push(arguments[e]);if(!(this instanceof P))return w(P,t);if(0<n)throw new Error("Closepath constructor expects no arguments.");return this}var E={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