UNPKG

jointjs

Version:

JavaScript diagramming library

8 lines (6 loc) 304 kB
/*! JointJS v3.1.1 (2019-10-28) - JavaScript diagramming library This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ if(function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("backbone"),require("lodash"),require("jquery")):"function"==typeof define&&define.amd?define(["exports","backbone","lodash","jquery"],e):e((t=t||self).joint={},t.Backbone,t._,t.$)}(this,function(e,s,n,C){"use strict";var i,h,r,l;s=s&&s.hasOwnProperty("default")?s.default:s,n=n&&n.hasOwnProperty("default")?n.default:n,C=C&&C.hasOwnProperty("default")?C.default:C,Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(t,e){if(null==this)throw new TypeError('"this" is null or not defined');var n=Object(this),i=n.length>>>0;if(0===i)return!1;var r,o,s=0|e,a=Math.max(0<=s?s:i-Math.abs(s),0);for(;a<i;){if((r=n[a])===(o=t)||"number"==typeof r&&"number"==typeof o&&isNaN(r)&&isNaN(o))return!0;a++}return!1}}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),n=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var i=arguments[1],r=0;r<n;){var o=e[r];if(t.call(i,o,r,e))return o;r++}}}),Array.from||(Array.from=(i=Object.prototype.toString,h=function(t){return"function"==typeof t||"[object Function]"===i.call(t)},r=Math.pow(2,53)-1,l=function(t){var e,n=(e=Number(t),isNaN(e)?0:0!==e&&isFinite(e)?(0<e?1:-1)*Math.floor(Math.abs(e)):e);return Math.min(Math.max(n,0),r)},function(t){var e=Object(t);if(null==t)throw new TypeError("Array.from requires an array-like object - not null or undefined");var n,i=1<arguments.length?arguments[1]:void 0;if(void 0!==i){if(!h(i))throw new TypeError("Array.from: when provided, the second argument must be a function");2<arguments.length&&(n=arguments[2])}for(var r,o=l(e.length),s=h(this)?Object(new this(o)):new Array(o),a=0;a<o;)r=e[a],s[a]=i?void 0===n?i(r,a):i.call(n,r,a):r,a+=1;return s.length=o,s})),Array.prototype.findIndex||Object.defineProperty(Array.prototype,"findIndex",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),n=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var i=arguments[1],r=0;r<n;){var o=e[r];if(t.call(i,o,r,e))return r;r++}return-1}}),function(){var t=void 0!==e?e:this,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function h(t){this.message=t}(h.prototype=new Error).name="InvalidCharacterError",t.btoa||(t.btoa=function(t){for(var e,n,i=String(t),r=0,o=a,s="";i.charAt(0|r)||(o="=",r%1);s+=o.charAt(63&e>>8-r%1*8)){if(255<(n=i.charCodeAt(r+=.75)))throw new h("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");e=e<<8|n}return s}),t.atob||(t.atob=function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new h("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,i,r=0,o=0,s="";i=e.charAt(o++);~i&&(n=r%4?64*n+i:i,r++%4)?s+=String.fromCharCode(255&n>>(-2*r&6)):0)i=a.indexOf(i);return s})}(),Number.isFinite=Number.isFinite||function(t){return"number"==typeof t&&isFinite(t)},Number.isNaN=Number.isNaN||function(t){return t!=t},String.prototype.includes||(String.prototype.includes=function(t,e){return"number"!=typeof e&&(e=0),!(e+t.length>this.length)&&-1!==this.indexOf(t,e)}),String.prototype.startsWith||(String.prototype.startsWith=function(t,e){return this.substr(e||0,t.length)===t}),function(){function i(t,e){return this.slice(t,e)}function r(t,e){arguments.length<2&&(e=0);for(var n=0,i=t.length;n<i;++n,++e)this[e]=255&t[n]}function t(t){var e;if("number"==typeof t){e=new Array(t);for(var n=0;n<t;++n)e[n]=0}else e=t.slice(0);return e.subarray=i,(e.buffer=e).byteLength=e.length,e.set=r,"object"==typeof t&&t.buffer&&(e.buffer=t.buffer),e}"undefined"==typeof Uint8Array&&"undefined"!=typeof window&&(window.Uint8Array=t,window.Uint32Array=t,window.Int32Array=t)}(),"undefined"!=typeof XMLHttpRequest&&("response"in XMLHttpRequest.prototype||"mozResponseArrayBuffer"in XMLHttpRequest.prototype||"mozResponse"in XMLHttpRequest.prototype||"responseArrayBuffer"in XMLHttpRequest.prototype||Object.defineProperty(XMLHttpRequest.prototype,"response",{get:function(){return new Uint8Array(new VBArray(this.responseBody).toArray())}}));var o=Math,F=o.abs,u=o.cos,c=o.sin,_=o.sqrt,B=o.min,R=o.max,d=o.atan2,a=o.round,f=o.floor,p=o.PI,T=o.pow,t={curveThroughPoints:function(t){return console.warn("deprecated"),new D(g.throughPoints(t)).serialize()},getCurveControlPoints:function(t){console.warn("deprecated");var e,n=[],i=[],r=t.length-1;if(1==r)return n[0]=new z((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),i[0]=new z(2*n[0].x-t[0].x,2*n[0].y-t[0].y),[n,i];var o=[];for(e=1;e<r-1;e++)o[e]=4*t[e].x+2*t[e+1].x;o[0]=t[0].x+2*t[1].x,o[r-1]=(8*t[r-1].x+t[r].x)/2;var s=this.getFirstControlPoints(o);for(e=1;e<r-1;++e)o[e]=4*t[e].y+2*t[e+1].y;o[0]=t[0].y+2*t[1].y,o[r-1]=(8*t[r-1].y+t[r].y)/2;var a=this.getFirstControlPoints(o);for(e=0;e<r;e++)n.push(new z(s[e],a[e])),e<r-1?i.push(new z(2*t[e+1].x-s[e+1],2*t[e+1].y-a[e+1])):i.push(new z((t[r].x+s[r-1])/2,(t[r].y+a[r-1])/2));return[n,i]},getCurveDivider:function(t,e,n,i){console.warn("deprecated");var r=new g(t,e,n,i);return function(t){var e=r.divide(t);return[{p0:e[0].start,p1:e[0].controlPoint1,p2:e[0].controlPoint2,p3:e[0].end},{p0:e[1].start,p1:e[1].controlPoint1,p2:e[1].controlPoint2,p3:e[1].end}]}},getFirstControlPoints:function(t){console.warn("deprecated");var e=t.length,n=[],i=[],r=2;n[0]=t[0]/r;for(var o=1;o<e;o++)i[o]=1/r,r=(o<e-1?4:3.5)-i[o],n[o]=(t[o]-n[o-1])/r;for(o=1;o<e;o++)n[e-o-1]-=i[e-o]*n[e-o];return n},getInversionSolver:function(t,e,n,i){console.warn("deprecated");var r=new g(t,e,n,i);return function(t){return r.closestPointT(t)}}},g=function(t,e,n,i){return this instanceof g?t instanceof g?new g(t.start,t.controlPoint1,t.controlPoint2,t.end):(this.start=new z(t),this.controlPoint1=new z(e),this.controlPoint2=new z(n),void(this.end=new z(i))):new g(t,e,n,i)};g.throughPoints=function(){function h(t){var e=t.length,n=[],i=[],r=2;n[0]=t[0]/r;for(var o=1;o<e;o++)i[o]=1/r,r=(o<e-1?4:3.5)-i[o],n[o]=(t[o]-n[o-1])/r;for(o=1;o<e;o++)n[e-o-1]-=i[e-o]*n[e-o];return n}return function(t){if(!t||Array.isArray(t)&&t.length<2)throw new Error("At least 2 points are required");for(var e=function(t){var e,n=[],i=[],r=t.length-1;if(1==r)return n[0]=new z((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),i[0]=new z(2*n[0].x-t[0].x,2*n[0].y-t[0].y),[n,i];var o=[];for(e=1;e<r-1;e++)o[e]=4*t[e].x+2*t[e+1].x;o[0]=t[0].x+2*t[1].x,o[r-1]=(8*t[r-1].x+t[r].x)/2;var s=h(o);for(e=1;e<r-1;++e)o[e]=4*t[e].y+2*t[e+1].y;o[0]=t[0].y+2*t[1].y,o[r-1]=(8*t[r-1].y+t[r].y)/2;var a=h(o);for(e=0;e<r;e++)n.push(new z(s[e],a[e])),e<r-1?i.push(new z(2*t[e+1].x-s[e+1],2*t[e+1].y-a[e+1])):i.push(new z((t[r].x+s[r-1])/2,(t[r].y+a[r-1])/2));return[n,i]}(t),n=[],i=e[0].length,r=0;r<i;r++){var o=new z(e[0][r].x,e[0][r].y),s=new z(e[1][r].x,e[1][r].y);n.push(new g(t[r],o,s,t[r+1]))}return n}}(),g.prototype={bbox:function(){for(var t,e,n,i,r,o,s,a,h=this.start,l=this.controlPoint1,u=this.controlPoint2,c=this.end,d=h.x,f=h.y,p=l.x,g=l.y,v=u.x,m=u.y,y=c.x,w=c.y,b=new Array,x=new Array,A=[new Array,new Array],P=0;P<2;++P)if(n=0===P?(e=6*d-12*p+6*v,t=-3*d+9*p-9*v+3*y,3*p-3*d):(e=6*f-12*g+6*m,t=-3*f+9*g-9*m+3*w,3*g-3*f),F(t)<1e-12){if(F(e)<1e-12)continue;0<(i=-n/e)&&i<1&&x.push(i)}else a=_(s=e*e-4*n*t),s<0||(0<(r=(-e+a)/(2*t))&&r<1&&x.push(r),0<(o=(-e-a)/(2*t))&&o<1&&x.push(o));for(var S,k,E,C=x.length,T=C;C--;)k=(S=1-(i=x[C]))*S*S*d+3*S*S*i*p+3*S*i*i*v+i*i*i*y,A[0][C]=k,E=S*S*S*f+3*S*S*i*g+3*S*i*i*m+i*i*i*w,A[1][C]=E,b[C]={X:k,Y:E};x[T]=0,x[T+1]=1,b[T]={X:d,Y:f},b[T+1]={X:y,Y:w},A[0][T]=d,A[1][T]=f,A[0][T+1]=y,A[1][T+1]=w,x.length=T+2,A[0].length=T+2,A[1].length=T+2,b.length=T+2;var L=B.apply(null,A[0]),M=B.apply(null,A[1]),N=R.apply(null,A[0]),V=R.apply(null,A[1]);return new X(L,M,N-L,V-M)},clone:function(){return new g(this.start,this.controlPoint1,this.controlPoint2,this.end)},closestPoint:function(t,e){return this.pointAtT(this.closestPointT(t,e))},closestPointLength:function(t,e){var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,subdivisions:void 0===e.subdivisions?this.getSubdivisions({precision:n}):e.subdivisions};return this.lengthAtT(this.closestPointT(t,i),i)},closestPointNormalizedLength:function(t,e){var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,subdivisions:void 0===e.subdivisions?this.getSubdivisions({precision:n}):e.subdivisions},r=this.closestPointLength(t,i);if(!r)return 0;var o=this.length(i);return 0===o?0:r/o},closestPointT:function(t,e){for(var n,i,r,o,s,a,h,l=void 0===(e=e||{}).precision?this.PRECISION:e.precision,u=void 0===e.subdivisions?this.getSubdivisions({precision:l}):e.subdivisions,c=u.length,d=c?1/c:0,f=0;f<c;f++){var p=u[f],g=p.start.distance(t),v=p.end.distance(t),m=g+v;(!h||m<h)&&(i=f*d,r=(f+1)*d,o=g,s=v,a=(n=p).start.distance(p.end),h=m)}for(var y=T(10,-l);;){var w=o?F(o-s)/o:0,b=s?F(o-s)/s:0;if(w<y||b<y||(!o||o<a*y||(!s||s<a*y)))return o<=s?i:r;var x=n.divide(.5);d/=2;var A=x[0].start.distance(t),P=x[0].end.distance(t),S=A+P,k=x[1].start.distance(t),E=x[1].end.distance(t);s=S<=k+E?(n=x[0],r-=d,o=A,P):(n=x[1],i+=d,o=k,E)}},closestPointTangent:function(t,e){return this.tangentAtT(this.closestPointT(t,e))},containsPoint:function(t,e){return this.toPolyline(e).containsPoint(t)},divideAt:function(t,e){if(t<=0)return this.divideAtT(0);if(1<=t)return this.divideAtT(1);var n=this.tAt(t,e);return this.divideAtT(n)},divideAtLength:function(t,e){var n=this.tAtLength(t,e);return this.divideAtT(n)},divideAtT:function(t){var e=this.start,n=this.controlPoint1,i=this.controlPoint2,r=this.end;if(t<=0)return[new g(e,e,e,e),new g(e,n,i,r)];if(1<=t)return[new g(e,n,i,r),new g(r,r,r,r)];var o=this.getSkeletonPoints(t),s=o.startControlPoint1,a=o.startControlPoint2,h=o.divider,l=o.dividerControlPoint1,u=o.dividerControlPoint2;return[new g(e,s,a,h),new g(h,l,u,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 e=this.start,n=this.controlPoint1,i=this.controlPoint2,r=this.end;if(t<=0)return{startControlPoint1:e.clone(),startControlPoint2:e.clone(),divider:e.clone(),dividerControlPoint1:n.clone(),dividerControlPoint2:i.clone()};if(1<=t)return{startControlPoint1:n.clone(),startControlPoint2:i.clone(),divider:r.clone(),dividerControlPoint1:r.clone(),dividerControlPoint2:r.clone()};var o=new O(e,n).pointAt(t),s=new O(n,i).pointAt(t),a=new O(i,r).pointAt(t),h=new O(o,s).pointAt(t),l=new O(s,a).pointAt(t);return{startControlPoint1:o,startControlPoint2:h,divider:new O(h,l).pointAt(t),dividerControlPoint1:l,dividerControlPoint2:a}},getSubdivisions:function(t){var e=void 0===(t=t||{}).precision?this.PRECISION:t.precision,n=[new g(this.start,this.controlPoint1,this.controlPoint2,this.end)];if(0===e)return n;for(var i=this.endpointDistance(),r=T(10,-e),o=0;;){o+=1;for(var s=[],a=n.length,h=0;h<a;h++){var l=n[h].divide(.5);s.push(l[0],l[1])}for(var u=0,c=s.length,d=0;d<c;d++){u+=s[d].endpointDistance()}if(1<o&&(0!==u?(u-i)/u:0)<r)return s;n=s,i=u}},isDifferentiable:function(){var t=this.start,e=this.controlPoint1,n=this.controlPoint2,i=this.end;return!(t.equals(e)&&e.equals(n)&&n.equals(i))},length:function(t){for(var e=void 0===(t=t||{}).precision?this.PRECISION:t.precision,n=void 0===t.subdivisions?this.getSubdivisions({precision:e}):t.subdivisions,i=0,r=n.length,o=0;o<r;o++){i+=n[o].endpointDistance()}return i},lengthAtT:function(t,e){if(t<=0)return 0;var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision;return this.divide(t)[0].length({precision:n})},pointAt:function(t,e){if(t<=0)return this.start.clone();if(1<=t)return this.end.clone();var n=this.tAt(t,e);return this.pointAtT(n)},pointAtLength:function(t,e){var n=this.tAtLength(t,e);return this.pointAtT(n)},pointAtT:function(t){return t<=0?this.start.clone():1<=t?this.end.clone():this.getSkeletonPoints(t).divider},PRECISION:3,scale:function(t,e,n){return this.start.scale(t,e,n),this.controlPoint1.scale(t,e,n),this.controlPoint2.scale(t,e,n),this.end.scale(t,e,n),this},tangentAt:function(t,e){if(!this.isDifferentiable())return null;t<0?t=0:1<t&&(t=1);var n=this.tAt(t,e);return this.tangentAtT(n)},tangentAtLength:function(t,e){if(!this.isDifferentiable())return null;var n=this.tAtLength(t,e);return this.tangentAtT(n)},tangentAtT:function(t){if(!this.isDifferentiable())return null;t<0?t=0:1<t&&(t=1);var e=this.getSkeletonPoints(t),n=e.startControlPoint2,i=e.dividerControlPoint1,r=e.divider,o=new O(n,i);return o.translate(r.x-n.x,r.y-n.y),o},tAt:function(t,e){if(t<=0)return 0;if(1<=t)return 1;var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,subdivisions:void 0===e.subdivisions?this.getSubdivisions({precision:n}):e.subdivisions},r=this.length(i)*t;return this.tAtLength(r,i)},tAtLength:function(t,e){var n=!0;t<0&&(n=!1,t=-t);for(var i,r,o,s,a,h=void 0===(e=e||{}).precision?this.PRECISION:e.precision,l=void 0===e.subdivisions?this.getSubdivisions({precision:h}):e.subdivisions,u={precision:h,subdivisions:l},c=0,d=l.length,f=1/d,p=0;p<d;p++){var g=n?p:d-1-p,v=l[p],m=v.endpointDistance();if(t<=c+m){i=v,r=g*f,o=(g+1)*f,s=n?t-c:m+c-t,a=n?m+c-t:t-c;break}c+=m}if(!i)return n?1:0;for(var y=this.length(u),w=T(10,-h);;){var b,x;if((0!==y?s/y:0)<w)return r;if((0!==y?a/y:0)<w)return o;var A=i.divide(.5);f/=2;var P=A[0].endpointDistance(),S=A[1].endpointDistance();x=s<=P?(i=A[0],o-=f,P-(b=s)):(i=A[1],r+=f,S-(b=s-P)),s=b,a=x}},toPoints:function(t){for(var e=void 0===(t=t||{}).precision?this.PRECISION:t.precision,n=void 0===t.subdivisions?this.getSubdivisions({precision:e}):t.subdivisions,i=[n[0].start.clone()],r=n.length,o=0;o<r;o++){var s=n[o];i.push(s.end.clone())}return i},toPolyline:function(t){return new L(this.toPoints(t))},toString:function(){return this.start+" "+this.controlPoint1+" "+this.controlPoint2+" "+this.end},translate:function(t,e){return this.start.translate(t,e),this.controlPoint1.translate(t,e),this.controlPoint2.translate(t,e),this.end.translate(t,e),this}},g.prototype.divide=g.prototype.divideAtT;var x=function(t,e,n){return this instanceof x?t instanceof x?new x(new z(t.x,t.y),t.a,t.b):(t=new z(t),this.x=t.x,this.y=t.y,this.a=e,void(this.b=n)):new x(t,e,n)};x.fromRect=function(t){return t=new X(t),new x(t.center(),t.width/2,t.height/2)},x.prototype={bbox:function(){return new X(this.x-this.a,this.y-this.b,2*this.a,2*this.b)},center:function(){return new z(this.x,this.y)},clone:function(){return new x(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,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.a+=2*t,this.b+=2*e,this},intersectionWithLine:function(t){var e=[],n=t.start,i=t.end,r=this.a,o=this.b,s=t.vector(),a=n.difference(new z(this)),h=new z(s.x/(r*r),s.y/(o*o)),l=new z(a.x/(r*r),a.y/(o*o)),u=s.dot(h),c=s.dot(l),d=c*c-u*(a.dot(l)-1);if(d<0)return null;if(0<d){var f=_(d),p=(-c-f)/u,g=(-c+f)/u;if((p<0||1<p)&&(g<0||1<g))return null;0<=p&&p<=1&&e.push(n.lerp(i,p)),0<=g&&g<=1&&e.push(n.lerp(i,g))}else{var v=-c/u;if(!(0<=v&&v<=1))return null;e.push(n.lerp(i,v))}return e},intersectionWithLineFromCenterToPoint:function(t,e){t=new z(t),e&&t.rotate(new z(this.x,this.y),e);var n,i=t.x-this.x,r=t.y-this.y;if(0===i)return n=this.bbox().pointNearestToPoint(t),e?n.rotate(new z(this.x,this.y),-e):n;var o=r/i,s=o*o,a=this.a*this.a,h=this.b*this.b,l=_(1/(1/a+s/h)),u=o*(l=i<0?-l:l);return n=new z(this.x+l,this.y+u),e?n.rotate(new z(this.x,this.y),-e):n},normalizedDistance:function(t){var e=t.x,n=t.y,i=this.a,r=this.b,o=this.x,s=this.y;return(e-o)*(e-o)/(i*i)+(n-s)*(n-s)/(r*r)},tangentTheta:function(t){var e,n,i=t.x,r=t.y,o=this.a,s=this.b,a=this.bbox().center(),h=a.x,l=a.y,u=i>a.x+o/2,c=i<a.x-o/2;return u||c?n=o*o/(i-h)-o*o*(r-l)*((e=i>a.x?r-30:r+30)-l)/(s*s*(i-h))+h:e=s*s/(r-l)-s*s*(i-h)*((n=r>a.y?i+30:i-30)-h)/(o*o*(r-l))+l,new z(n,e).theta(t)},toString:function(){return new z(this.x,this.y).toString()+" "+this.a+" "+this.b}};var O=function(t,e){return this instanceof O?t instanceof O?new O(t.start,t.end):(this.start=new z(t),void(this.end=new z(e))):new O(t,e)};O.prototype={angle:function(){var t=new z(this.start.x+1,this.start.y);return this.start.angleBetween(this.end,t)},bbox:function(){var t=B(this.start.x,this.end.x),e=B(this.start.y,this.end.y),n=R(this.start.x,this.end.x),i=R(this.start.y,this.end.y);return new X(t,e,n-t,i-e)},bearing:function(){var t=A(this.start.y),e=A(this.end.y),n=this.start.x,i=this.end.x,r=A(i-n),o=c(r)*u(e),s=u(t)*c(e)-c(t)*u(e)*u(r),a=y(d(o,s))-22.5;return a<0&&(a+=360),["NE","E","SE","S","SW","W","NW","N"][a=parseInt(a/45)]},clone:function(){return new O(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 e=this.vector().dot(new O(this.start,t).vector()),n=B(1,R(0,e/this.squaredLength()));return n!=n?0:n},closestPointTangent:function(t){return this.tangentAt(this.closestPointNormalizedLength(t))},containsPoint:function(t){var e=this.start,n=this.end;if(0!==e.cross(t,n))return!1;var i=this.length();return!(new O(e,t).length()>i)&&!(new O(t,n).length()>i)},divideAt:function(t){var e=this.pointAt(t);return[new O(this.start,e),new O(e,this.end)]},divideAtLength:function(t){var e=this.pointAtLength(t);return[new O(this.start,e),new O(e,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,e){if(t instanceof O||t instanceof X||t instanceof L||t instanceof x||t instanceof D){var n=t.intersectionWithLine(this,e);return n&&t instanceof O&&(n=n[0]),n}return null},intersectionWithLine:function(t){var e=new z(this.end.x-this.start.x,this.end.y-this.start.y),n=new z(t.end.x-t.start.x,t.end.y-t.start.y),i=e.x*n.y-e.y*n.x,r=new z(t.start.x-this.start.x,t.start.y-this.start.y),o=r.x*n.y-r.y*n.x,s=r.x*e.y-r.y*e.x;if(0===i||o*i<0||s*i<0)return null;if(0<i){if(i<o||i<s)return null}else if(o<i||s<i)return null;return[new z(this.start.x+o*e.x/i,this.start.y+o*e.y/i)]},isDifferentiable:function(){return!this.start.equals(this.end)},length:function(){return _(this.squaredLength())},midpoint:function(){return new z((this.start.x+this.end.x)/2,(this.start.y+this.end.y)/2)},pointAt:function(t){var e=this.start,n=this.end;return t<=0?e.clone():1<=t?n.clone():e.lerp(n,t)},pointAtLength:function(t){var e=this.start,n=this.end,i=!0;t<0&&(i=!1,t=-t);var r=this.length();return r<=t?i?n.clone():e.clone():this.pointAt((i?t:r-t)/r)},pointOffset:function(t){t=new z(t);var e=this.start,n=this.end;return((n.x-e.x)*(t.y-e.y)-(n.y-e.y)*(t.x-e.x))/this.length()},rotate:function(t,e){return this.start.rotate(t,e),this.end.rotate(t,e),this},round:function(t){var e=T(10,t||0);return this.start.x=a(this.start.x*e)/e,this.start.y=a(this.start.y*e)/e,this.end.x=a(this.end.x*e)/e,this.end.y=a(this.end.y*e)/e,this},scale:function(t,e,n){return this.start.scale(t,e,n),this.end.scale(t,e,n),this},setLength:function(t){var e=this.length();if(!e)return this;var n=t/e;return this.scale(n,n,this.start)},squaredLength:function(){var t=this.start.x,e=this.start.y;return(t-=this.end.x)*t+(e-=this.end.y)*e},tangentAt:function(t){if(!this.isDifferentiable())return null;var e=this.start,n=this.end,i=this.pointAt(t),r=new O(e,n);return r.translate(i.x-e.x,i.y-e.y),r},tangentAtLength:function(t){if(!this.isDifferentiable())return null;var e=this.start,n=this.end,i=this.pointAtLength(t),r=new O(e,n);return r.translate(i.x-e.x,i.y-e.y),r},toString:function(){return this.start.toString()+" "+this.end.toString()},translate:function(t,e){return this.start.translate(t,e),this.end.translate(t,e),this},vector:function(){return new z(this.end.x-this.start.x,this.end.y-this.start.y)}},O.prototype.intersection=O.prototype.intersect;var D=function(t){if(!(this instanceof D))return new D(t);if("string"==typeof t)return new D.parse(t);var e,n;if(this.segments=[],t)if(Array.isArray(t)&&0!==t.length)if(n=(t=t.reduce(function(t,e){return t.concat(e)},[])).length,t[0].isSegment)for(e=0;e<n;e++){var i=t[e];this.appendSegment(i)}else{var r=null;for(e=0;e<n;e++){var o=t[e];if(!(o instanceof O||o instanceof g))throw new Error("Cannot construct a path segment from the provided object.");0===e&&this.appendSegment(D.createSegment("M",o.start)),r&&!r.end.equals(o.start)&&this.appendSegment(D.createSegment("M",o.start)),o instanceof O?this.appendSegment(D.createSegment("L",o.end)):o instanceof g&&this.appendSegment(D.createSegment("C",o.controlPoint1,o.controlPoint2,o.end)),r=o}}else if(t.isSegment)this.appendSegment(t);else if(t instanceof O)this.appendSegment(D.createSegment("M",t.start)),this.appendSegment(D.createSegment("L",t.end));else if(t instanceof g)this.appendSegment(D.createSegment("M",t.start)),this.appendSegment(D.createSegment("C",t.controlPoint1,t.controlPoint2,t.end));else{if(!(t instanceof L))throw new Error("Cannot construct a path from the provided object.");if(!t.points||0===t.points.length)return;for(n=t.points.length,e=0;e<n;e++){var s=t.points[e];0===e?this.appendSegment(D.createSegment("M",s)):this.appendSegment(D.createSegment("L",s))}}else;};D.parse=function(t){if(!t)return new D;for(var e=new D,n=t.match(/(?:[a-zA-Z] *)(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)? *,? *)|(?:-?\.\d+ *,? *))+|(?:[a-zA-Z] *)(?! |\d|-|\.)/g),i=n.length,r=0;r<i;r++){var o=n[r].match(/(?:[a-zA-Z])|(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)?))|(?:(?:-?\.\d+))/g),s=D.createSegment.apply(this,o);e.appendSegment(s)}return e},D.createSegment=function(t){var e=arguments;if(!t)throw new Error("Type must be provided.");var n=D.segmentTypes[t];if(!n)throw new Error(t+" is not a recognized path segment type.");for(var i=[],r=arguments.length,o=1;o<r;o++)i.push(e[o]);return E(n,i)},D.prototype={appendSegment:function(t){var e,n=this.segments,i=n.length,r=0!==i?n[i-1]:null;if(Array.isArray(t)){if(!(t=t.reduce(function(t,e){return t.concat(e)},[]))[0].isSegment)throw new Error("Segments required.");for(var o=t.length,s=0;s<o;s++){var a=t[s];e=this.prepareSegment(a,r,null),n.push(e),r=e}}else{if(!t||!t.isSegment)throw new Error("Segment required.");e=this.prepareSegment(t,r,null),n.push(e)}},bbox:function(){var t,e=this.segments,n=e.length;if(0===n)return null;for(var i=0;i<n;i++){var r=e[i];if(r.isVisible){var o=r.bbox();t=t?t.union(o):o}}if(t)return t;var s=e[n-1];return new X(s.end.x,s.end.y,0,0)},clone:function(){for(var t=this.segments,e=t.length,n=new D,i=0;i<e;i++){var r=t[i].clone();n.appendSegment(r)}return n},closestPoint:function(t,e){var n=this.closestPointT(t,e);return n?this.pointAtT(n):null},closestPointLength:function(t,e){var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:n}):e.segmentSubdivisions},r=this.closestPointT(t,i);return r?this.lengthAtT(r,i):0},closestPointNormalizedLength:function(t,e){var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:n}):e.segmentSubdivisions},r=this.closestPointLength(t,i);if(0===r)return 0;var o=this.length(i);return 0===o?0:r/o},closestPointT:function(t,e){var n=this.segments,i=n.length;if(0===i)return null;for(var r,o=void 0===(e=e||{}).precision?this.PRECISION:e.precision,s=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):e.segmentSubdivisions,a=1/0,h=0;h<i;h++){var l=n[h],u=s[h];if(l.isVisible){var c=l.closestPointT(t,{precision:o,subdivisions:u}),d=l.pointAtT(c),f=new O(d,t).squaredLength();f<a&&(r={segmentIndex:h,value:c},a=f)}}return r||{segmentIndex:i-1,value:1}},closestPointTangent:function(t,e){var n=this.segments,i=n.length;if(0===i)return null;for(var r,o=void 0===(e=e||{}).precision?this.PRECISION:e.precision,s=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):e.segmentSubdivisions,a=1/0,h=0;h<i;h++){var l=n[h],u=s[h];if(l.isDifferentiable()){var c=l.closestPointT(t,{precision:o,subdivisions:u}),d=l.pointAtT(c),f=new O(d,t).squaredLength();f<a&&(r=l.tangentAtT(c),a=f)}}return r||null},containsPoint:function(t,e){var n=this.toPolylines(e);if(!n)return!1;for(var i=n.length,r=0,o=0;o<i;o++){n[o].containsPoint(t)&&r++}return r%2==1},divideAt:function(t,e){if(0===this.segments.length)return null;t<0&&(t=0),1<t&&(t=1);var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:n}):e.segmentSubdivisions},r=this.length(i)*t;return this.divideAtLength(r,i)},divideAtLength:function(t,e){var n=this.segments.length;if(0===n)return null;var i=!0;t<0&&(i=!1,t=-t);var r,o,s,a,h,l,u,c=void 0===(e=e||{}).precision?this.PRECISION:e.precision,d=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:c}):e.segmentSubdivisions,f=0;for(r=0;r<n;r++){var p=i?r:n-1-r;o=this.getSegment(p);var g=d[p],v=o.length({precision:c,subdivisions:g});if(o.isDifferentiable()&&(h=o,l=p,t<=f+v)){a=p,s=o.divideAtLength((i?1:-1)*(t-f),{precision:c,subdivisions:g});break}f+=v}if(!h)return null;s||(a=l,u=i?1:0,s=h.divideAtT(u));var m=this.clone();m.replaceSegment(a,s);var y=a,w=a+1,b=a+2;s[0].isDifferentiable()||(m.removeSegment(y),w-=1,b-=1);var x=m.getSegment(w).start;m.insertSegment(w,D.createSegment("M",x)),b+=1,s[1].isDifferentiable()||(m.removeSegment(b-1),b-=1);var A=b-y-1;for(r=b;r<m.segments.length;r++){var P=this.getSegment(r-A);if("Z"===(o=m.getSegment(r)).type&&!P.subpathStartSegment.end.equals(o.subpathStartSegment.end)){var S=D.createSegment("L",P.end);m.replaceSegment(r,S)}}return[new D(m.segments.slice(0,w)),new D(m.segments.slice(w))]},equals:function(t){if(!t)return!1;var e=this.segments,n=t.segments,i=e.length;if(n.length!==i)return!1;for(var r=0;r<i;r++){var o=e[r],s=n[r];if(o.type!==s.type||!o.equals(s))return!1}return!0},getSegment:function(t){var e=this.segments,n=e.length;if(0===n)throw new Error("Path has no segments.");if(t<0&&(t=n+t),n<=t||t<0)throw new Error("Index out of range.");return e[t]},getSegmentSubdivisions:function(t){for(var e=this.segments,n=e.length,i=void 0===(t=t||{}).precision?this.PRECISION:t.precision,r=[],o=0;o<n;o++){var s=e[o].getSubdivisions({precision:i});r.push(s)}return r},insertSegment:function(t,e){var n,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 o=null,s=null;if(0!==r&&(s=1<=t?(o=i[t-1]).nextSegment:i[0]),Array.isArray(e)){if(!(e=e.reduce(function(t,e){return t.concat(e)},[]))[0].isSegment)throw new Error("Segments required.");for(var a=e.length,h=0;h<a;h++){var l=e[h];n=this.prepareSegment(l,o,s),i.splice(t+h,0,n),o=n}}else{if(!e||!e.isSegment)throw new Error("Segment required.");n=this.prepareSegment(e,o,s),i.splice(t,0,n)}},intersectionWithLine:function(t,e){var n=null,i=this.toPolylines(e);if(!i)return null;for(var r=0,o=i.length;r<o;r++){var s=i[r],a=t.intersect(s);a&&(n||(n=[]),Array.isArray(a)?Array.prototype.push.apply(n,a):n.push(a))}return n},isDifferentiable:function(){for(var t=this.segments,e=t.length,n=0;n<e;n++){if(t[n].isDifferentiable())return!0}return!1},isValid:function(){var t=this.segments;return 0===t.length||"M"===t[0].type},length:function(t){var e=this.segments,n=e.length;if(0===n)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,o=0,s=0;s<n;s++){var a=e[s],h=r[s];o+=a.length({subdivisions:h})}return o},lengthAtT:function(t,e){var n=this.segments,i=n.length;if(0===i)return 0;var r=t.segmentIndex;if(r<0)return 0;var o=t.value;i<=r?(r=i-1,o=1):o<0?o=0:1<o&&(o=1);for(var s,a=void 0===(e=e||{}).precision?this.PRECISION:e.precision,h=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:a}):e.segmentSubdivisions,l=0,u=0;u<r;u++){var c=n[u];s=h[u],l+=c.length({precisison:a,subdivisions:s})}return c=n[r],s=h[r],l+=c.lengthAtT(o,{precisison:a,subdivisions:s})},pointAt:function(t,e){if(0===this.segments.length)return null;if(t<=0)return this.start.clone();if(1<=t)return this.end.clone();var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:n}):e.segmentSubdivisions},r=this.length(i)*t;return this.pointAtLength(r,i)},pointAtLength:function(t,e){var n=this.segments,i=n.length;if(0===i)return null;if(0===t)return this.start.clone();var r=!0;t<0&&(r=!1,t=-t);for(var o,s=void 0===(e=e||{}).precision?this.PRECISION:e.precision,a=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:s}):e.segmentSubdivisions,h=0,l=0;l<i;l++){var u=r?l:i-1-l,c=n[u],d=a[u],f=c.length({precision:s,subdivisions:d});if(c.isVisible){if(t<=h+f)return c.pointAtLength((r?1:-1)*(t-h),{precision:s,subdivisions:d});o=c}h+=f}return o?r?o.end:o.start:n[i-1].end.clone()},pointAtT:function(t){var e=this.segments,n=e.length;if(0===n)return null;var i=t.segmentIndex;if(i<0)return e[0].pointAtT(0);if(n<=i)return e[n-1].pointAtT(1);var r=t.value;return r<0?r=0:1<r&&(r=1),e[i].pointAtT(r)},PRECISION:3,prepareSegment:function(t,e,n){t.previousSegment=e,t.nextSegment=n,e&&(e.nextSegment=t),n&&(n.previousSegment=t);var i=t;return t.isSubpathStart&&(t.subpathStartSegment=t,i=n),i&&this.updateSubpathStartSegment(i),t},removeSegment:function(t){var e=this.segments,n=e.length;if(0===n)throw new Error("Path has no segments.");if(t<0&&(t=n+t),n<=t||t<0)throw new Error("Index out of range.");var i=e.splice(t,1)[0],r=i.previousSegment,o=i.nextSegment;r&&(r.nextSegment=o),o&&(o.previousSegment=r),i.isSubpathStart&&o&&this.updateSubpathStartSegment(o)},replaceSegment:function(t,e){var n,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 o=i[t],s=o.previousSegment,a=o.nextSegment,h=o.isSubpathStart;if(Array.isArray(e)){if(!(e=e.reduce(function(t,e){return t.concat(e)},[]))[0].isSegment)throw new Error("Segments required.");i.splice(t,1);for(var l=e.length,u=0;u<l;u++){var c=e[u];n=this.prepareSegment(c,s,a),i.splice(t+u,0,n),s=n,h&&n.isSubpathStart&&(h=!1)}}else{if(!e||!e.isSegment)throw new Error("Segment required.");n=this.prepareSegment(e,s,a),i.splice(t,1,n),h&&n.isSubpathStart&&(h=!1)}h&&a&&this.updateSubpathStartSegment(a)},scale:function(t,e,n){for(var i=this.segments,r=i.length,o=0;o<r;o++){i[o].scale(t,e,n)}return this},segmentAt:function(t,e){var n=this.segmentIndexAt(t,e);return n?this.getSegment(n):null},segmentAtLength:function(t,e){var n=this.segmentIndexAtLength(t,e);return n?this.getSegment(n):null},segmentIndexAt:function(t,e){if(0===this.segments.length)return null;t<0&&(t=0),1<t&&(t=1);var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:n}):e.segmentSubdivisions},r=this.length(i)*t;return this.segmentIndexAtLength(r,i)},segmentIndexAtLength:function(t,e){var n=this.segments,i=n.length;if(0===i)return null;var r=!0;t<0&&(r=!1,t=-t);for(var o=void 0===(e=e||{}).precision?this.PRECISION:e.precision,s=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:o}):e.segmentSubdivisions,a=null,h=0,l=0;l<i;l++){var u=r?l:i-1-l,c=n[u],d=s[u],f=c.length({precision:o,subdivisions:d});if(c.isVisible){if(t<=h+f)return u;a=u}h+=f}return a},serialize:function(){if(!this.isValid())throw new Error("Invalid path segments.");return this.toString()},tangentAt:function(t,e){if(0===this.segments.length)return null;t<0&&(t=0),1<t&&(t=1);var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,segmentSubdivisions:void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:n}):e.segmentSubdivisions},r=this.length(i)*t;return this.tangentAtLength(r,i)},tangentAtLength:function(t,e){var n=this.segments,i=n.length;if(0===i)return null;var r=!0;t<0&&(r=!1,t=-t);for(var o,s=void 0===(e=e||{}).precision?this.PRECISION:e.precision,a=void 0===e.segmentSubdivisions?this.getSegmentSubdivisions({precision:s}):e.segmentSubdivisions,h=0,l=0;l<i;l++){var u=r?l:i-1-l,c=n[u],d=a[u],f=c.length({precision:s,subdivisions:d});if(c.isDifferentiable()){if(t<=h+f)return c.tangentAtLength((r?1:-1)*(t-h),{precision:s,subdivisions:d});o=c}h+=f}if(o){var p=r?1:0;return o.tangentAtT(p)}return null},tangentAtT:function(t){var e=this.segments,n=e.length;if(0===n)return null;var i=t.segmentIndex;if(i<0)return e[0].tangentAtT(0);if(n<=i)return e[n-1].tangentAtT(1);var r=t.value;return r<0?r=0:1<r&&(r=1),e[i].tangentAtT(r)},toPoints:function(t){var e=this.segments,n=e.length;if(0===n)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,o=[],s=[],a=0;a<n;a++){var h=e[a];if(h.isVisible){var l=r[a];if(0<l.length){var u=l.map(function(t){return t.start});Array.prototype.push.apply(s,u)}else s.push(h.start)}else 0<s.length&&(s.push(e[a-1].end),o.push(s),s=[])}return 0<s.length&&(s.push(this.end),o.push(s)),o},toPolylines:function(t){var e=[],n=this.toPoints(t);if(!n)return null;for(var i=0,r=n.length;i<r;i++)e.push(new L(n[i]));return e},toString:function(){for(var t=this.segments,e=t.length,n="",i=0;i<e;i++){n+=t[i].serialize()+" "}return n.trim()},translate:function(t,e){for(var n=this.segments,i=n.length,r=0;r<i;r++){n[r].translate(t,e)}return this},updateSubpathStartSegment:function(t){for(var e=t.previousSegment;t&&!t.isSubpathStart;)t.subpathStartSegment=e?e.subpathStartSegment:null,t=(e=t).nextSegment}},Object.defineProperty(D.prototype,"start",{configurable:!0,enumerable:!0,get:function(){var t=this.segments,e=t.length;if(0===e)return null;for(var n=0;n<e;n++){var i=t[n];if(i.isVisible)return i.start}return t[e-1].end}}),Object.defineProperty(D.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.segments,e=t.length;if(0===e)return null;for(var n=e-1;0<=n;n--){var i=t[n];if(i.isVisible)return i.end}return t[e-1].end}});var z=function(t,e){if(!(this instanceof z))return new z(t,e);if("string"==typeof t){var n=t.split(-1===t.indexOf("@")?" ":"@");t=parseFloat(n[0]),e=parseFloat(n[1])}else Object(t)===t&&(e=t.y,t=t.x);this.x=void 0===t?0:t,this.y=void 0===e?0:e};z.fromPolar=function(t,e,n){n=n&&new z(n)||new z(0,0);var i=F(t*u(e)),r=F(t*c(e)),o=b(y(e));return o<90?r=-r:o<180?(i=-i,r=-r):o<270&&(i=-i),new z(n.x+i,n.y+r)},z.random=function(t,e,n,i){return new z(m(t,e),m(n,i))},z.prototype={chooseClosest:function(t){var e=t.length;if(1===e)return new z(t[0]);for(var n=null,i=1/0,r=0;r<e;r++){var o=new z(t[r]),s=this.squaredDistance(o);s<i&&(n=o,i=s)}return n},adhereToRect:function(t){return t.containsPoint(this)||(this.x=B(R(this.x,t.x),t.x+t.width),this.y=B(R(this.y,t.y),t.y+t.height)),this},angleBetween:function(t,e){var n=this.equals(t)||this.equals(e)?NaN:this.theta(e)-this.theta(t);return n<0&&(n+=360),n},bearing:function(t){return new O(this,t).bearing()},changeInAngle:function(t,e,n){return this.clone().offset(-t,-e).theta(n)-this.theta(n)},clone:function(){return new z(this)},cross:function(t,e){return t&&e?(e.x-this.x)*(t.y-this.y)-(e.y-this.y)*(t.x-this.x):NaN},difference:function(t,e){return Object(t)===t&&(e=t.y,t=t.x),new z(this.x-(t||0),this.y-(e||0))},distance:function(t){return new O(this,t).length()},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,e){var n=this.x,i=this.y;return new z((1-e)*n+e*t.x,(1-e)*i+e*t.y)},magnitude:function(){return _(this.x*this.x+this.y*this.y)||.01},manhattanDistance:function(t){return F(t.x-this.x)+F(t.y-this.y)},move:function(t,e){var n=A(new z(t).theta(this));return this.offset(u(n)*e,-c(n)*e)},normalize:function(t){var e=(t||1)/this.magnitude();return this.scale(e,e)},offset:function(t,e){return Object(t)===t&&(e=t.y,t=t.x),this.x+=t||0,this.y+=e||0,this},reflection:function(t){return new z(t).move(this,this.distance(t))},rotate:function(t,e){t=t||new z(0,0),e=A(b(-e));var n=u(e),i=c(e),r=n*(this.x-t.x)-i*(this.y-t.y)+t.x,o=i*(this.x-t.x)+n*(this.y-t.y)+t.y;return this.x=r,this.y=o,this},round:function(t){var e=T(10,t||0);return this.x=a(this.x*e)/e,this.y=a(this.y*e)/e,this},scale:function(t,e,n){return n=n&&new z(n)||new z(0,0),this.x=n.x+t*(this.x-n.x),this.y=n.y+e*(this.y-n.y),this},snapToGrid:function(t,e){return this.x=v(this.x,t),this.y=v(this.y,e||t),this},squaredDistance:function(t){return new O(this,t).squaredLength()},theta:function(t){var e=-((t=new z(t)).y-this.y),n=t.x-this.x,i=d(e,n);return i<0&&(i=2*p+i),180*i/p},toJSON:function(){return{x:this.x,y:this.y}},toPolar:function(t){t=t&&new z(t)||new z(0,0);var e=this.x,n=this.y;return this.x=_((e-t.x)*(e-t.x)+(n-t.y)*(n-t.y)),this.y=A(t.theta(new z(e,n))),this},toString:function(){return this.x+"@"+this.y},update:function(t,e){return this.x=t||0,this.y=e||0,this},vectorAngle:function(t){return new z(0,0).angleBetween(this,t)}},z.prototype.translate=z.prototype.offset;var L=function(t){return this instanceof L?"string"==typeof t?new L.parse(t):void(this.points=Array.isArray(t)?t.map(z):[]):new L(t)};L.parse=function(t){if(""===(t=t.trim()))return new L;for(var e=[],n=t.split(/\s*,\s*|\s+/),i=n.length,r=0;r<i;r+=2)e.push({x:+n[r],y:+n[r+1]});return new L(e)},L.prototype={bbox:function(){var t=1/0,e=-1/0,n=1/0,i=-1/0,r=this.points,o=r.length;if(0===o)return null;for(var s=0;s<o;s++){var a=r[s],h=a.x,l=a.y;h<t&&(t=h),e<h&&(e=h),l<n&&(n=l),i<l&&(i=l)}return new X(t,n,e-t,i-n)},clone:function(){var t=this.points,e=t.length;if(0===e)return new L;for(var n=[],i=0;i<e;i++){var r=t[i].clone();n.push(r)}return new L(n)},closestPoint:function(t){var e=this.closestPointLength(t);return this.pointAtLength(e)},closestPointLength:function(t){var e,n=this.points,i=n.length;if(0===i)return 0;if(1===i)return 0;for(var r=1/0,o=0,s=i-1,a=0;a<s;a++){var h=new O(n[a],n[a+1]),l=h.length(),u=h.closestPointNormalizedLength(t),c=h.pointAt(u).squaredDistance(t);c<r&&(r=c,e=o+u*l),o+=l}return e},closestPointNormalizedLength:function(t){var e=this.closestPointLength(t);if(0===e)return 0;var n=this.length();return 0===n?0:e/n},closestPointTangent:function(t){var e=this.closestPointLength(t);return this.tangentAtLength(e)},containsPoint:function(t){var e=this.points,n=e.length;if(0===n)return!1;for(var i=t.x,r=t.y,o=n-1,s=0,a=0;s<n;s++){var h=e[o],l=e[s];if(t.equals(h))return!0;var u=new O(h,l);if(u.containsPoint(t))return!0;if(r<=h.y&&r>l.y||r>h.y&&r<=l.y){var c=h.x-i>l.x-i?h.x-i:l.x-i;if(0<=c){var d=new z(i+c,r),f=new O(t,d);u.intersect(f)&&a++}}o=s}return a%2==1},convexHull:function(){var t,e,n,i=this.points,r=i.length;if(0===r)return new L;for(t=0;t<r;t++)void 0===n?n=i[t]:i[t].y<n.y?n=i[t]:i[t].y===n.y&&i[t].x>n.x&&(n=i[t]);var o=[];for(t=0;t<r;t++){var s=n.theta(i[t]);0===s&&(s=360);var a=[i[t],t,s];o.push(a)}if(o.sort(function(t,e){var n=t[2]-e[2];return 0===n&&(n=e[1]-t[1]),n}),2<o.length){var h=o[o.length-1];o.unshift(h)}for(var l,u,c,d,f,p,g,v={},m=[];0!==o.length;)if(u=(l=o.pop())[0],!v.hasOwnProperty(l[0]+"@@"+l[1]))for(var y=!1;!y;)if(m.length<2)m.push(l),y=!0;else{d=(c=m.pop())[0];var w=(p=(f=m.pop())[0]).cross(d,u);if(w<0)m.push(f),m.push(c),m.push(l),y=!0;else if(0===w){var b=d.angleBetween(p,u);F(b-180)<1e-10?(v[c[0]+"@@"+c[1]]=d,m.push(f)):d.equals(u)||p.equals(d)?(v[c[0]+"@@"+c[1]]=d,m.push(f)):F((b+1)%360-1)<1e-10&&(m.push(f),o.push(c))}else v[c[0]+"@@"+c[1]]=d,m.push(f)}2<m.length&&m.pop();var x=-1;for(e=m.length,t=0;t<e;t++){var A=m[t][1];(void 0===g||A<g)&&(g=A,x=t)}var P=[];if(0<x){var S=m.slice(x),k=m.slice(0,x);P=S.concat(k)}else P=m;var E=[];for(e=P.length,t=0;t<e;t++)E.push(P[t][0]);return new L(E)},equals:function(t){if(!t)return!1;var e=this.points,n=t.points,i=e.length;if(n.length!==i)return!1;for(var r=0;r<i;r++){var o=e[r],s=t.points[r];if(!o.equals(s))return!1}return!0},intersectionWithLine:function(t){for(var e=new O(t),n=[],i=this.points,r=0,o=i.length-1;r<o;r++){var s=i[r],a=i[r+1],h=new O(s,a),l=e.intersectionWithLine(h);l&&n.push(l[0])}return 0<n.length?n:null},isDifferentiable:function(){var t=this.points,e=t.length;if(0===e)return!1;for(var n=e-1,i=0;i<n;i++){var r=t[i],o=t[i+1];if(new O(r,o).isDifferentiable())return!0}return!1},length:function(){var t=this.points,e=t.length;if(0===e)return 0;for(var n=0,i=e-1,r=0;r<i;r++)n+=t[r].distance(t[r+1]);return n},pointAt:function(t){var e=this.points,n=e.length;if(0===n)return null;if(1===n)return e[0].clone();if(t<=0)return e[0].clone();if(1<=t)return e[n-1].clone();var i=this.length()*t;return this.pointAtLength(i)},pointAtLength:function(t){var e=this.points,n=e.length;if(0===n)return null;if(1===n)return e[0].clone();var i=!0;t<0&&(i=!1,t=-t);for(var r=0,o=n-1,s=0;s<o;s++){var a=i?s:o-1-s,h=e[a],l=e[a+1],u=new O(h,l),c=h.distance(l);if(t<=r+c)return u.pointAtLength((i?1:-1)*(t-r));r+=c}return(i?e[n-1]:e[0]).clone()},scale:function(t,e,n){var i=this.points,r=i.length;if(0===r)return this;for(var o=0;o<r;o++)i[o].scale(t,e,n);return this},simplify:function(t){void 0===t&&(t={});var e=this.points;if(e.length<3)return this;for(var n=t.threshold||0,i=0;e[i+2];){var r=i+1,o=i+2,s=e[i],a=e[r],h=e[o];new O(s,h).closestPoint(a).distance(a)<=n?e.splice(r,1):i+=1}return this},tangentAt:function(t){var e=this.points.length;if(0===e)return null;if(1===e)return null;t<0&&(t=0),1<t&&(t=1);var n=this.length()*t;return this.tangentAtLength(n)},tangentAtLength:function(t){var e=this.points,n=e.length;if(0===n)return null;if(1===n)return null;var i,r=!0;t<0&&(r=!1,t=-t);for(var o=0,s=n-1,a=0;a<s;a++){var h=r?a:s-1-a,l=e[h],u=e[h+1],c=new O(l,u),d=l.distance(u);if(c.isDifferentiable()){if(t<=o+d)return c.tangentAtLength((r?1:-1)*(t-o));i=c}o+=d}if(i){var f=r?1:0;return i.tangentAt(f)}return null},toString:function(){return this.points+""},translate:function(t,e){var n=this.points,i=n.length;if(0===i)return this;for(var r=0;r<i;r++)n[r].translate(t,e);return this},serialize:function(){var t=this.points,e=t.length;if(0===e)return"";for(var n="",i=0;i<e;i++){var r=t[i];n+=r.x+","+r.y+" "}return n.trim()}},Object.defineProperty(L.prototype,"start",{configurable:!0,enumerable:!0,get:function(){return 0===this.points.length?null:this.points[0]}}),Object.defineProperty(L.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.points.length;return 0===t?null:this.points[t-1]}});var X=function(t,e,n,i){if(!(this instanceof X))return new X(t,e,n,i);Object(t)===t&&(e=t.y,n=t.width,i=t.height,t=t.x),this.x=void 0===t?0:t,this.y=void 0===e?0:e,this.width=void 0===n?0:n,this.height=void 0===i?0:i};X.fromEllipse=function(t){return t=new x(t),new X(t.x-t.a,t.y-t.b,2*t.a,2*t.b)},X.prototype={bbox:function(t){if(!t)return this.clone();var e=A(t),n=F(c(e)),i=F(u(e)),r=this.width*i+this.height*n,o=this.width*n+this.height*i;return new X(this.x+(this.width-r)/2,this.y+(this.height-o)/2,r,o)},bottomLeft:function(){return new z(this.x,this.y+this.height)},bottomLine:function(){return new O(this.bottomLeft(),this.bottomRight())},bottomMiddle:function(){return new z(this.x+this.width/2,this.y+this.height)},center:function(){return new z(this.x+this.width/2,this.y+this.height/2)},clone:function(){return new X(this)},containsPoint:function(t){return(t=new z(t)).x>=this.x&&t.x<=this.x+this.width&&t.y>=this.y&&t.y<=this.y+this.height},containsRect:function(t){var e=new X(this).normalize(),n=new X(t).normalize(),i=e.width,r=e.height,o=n.width,s=n.height;if(!(i&&r&&o&&s))return!1;var a=e.x,h=e.y,l=n.x,u=n.y;return o+=l,i+=a,s+=u,r+=h,a<=l&&o<=i&&h<=u&&s<=r},corner:function(){return new z(this.x+this.width,this.y+this.height)},equals:function(t){var e=new X(this).normalize(),n=new X(t).normalize();return e.x===n.x&&e.y===n.y&&e.width===n.width&&e.height===n.height},inflate:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.x-=t,this.y-=e,this.width+=2*t,this.height+=2*e,this},intersect:function(t){var e=this.origin(),n=this.corner(),i=t.origin(),r=t.corner();if(r.x<=e.x||r.y<=e.y||i.x>=n.x||i.y>=n.y)return null;var o=R(e.x,i.x),s=R(e.y,i.y);return new X(o,s,B(n.x,r.x)-o,B(n.y,r.y)-s)},intersectionWithLine:function(t){var e,n,i=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],r=[],o=[],s=i.length;for(n=0;n<s;n++)null!==(e=t.intersect(i[n]))&&o.indexOf(e.toString())<0&&(r.push(e),o.push(e.toString()));return 0<r.length?r:null},intersectionWithLineFromCenterToPoint:function(t,e){t=new z(t);var n,i=new z(this.x+this.width/2,this.y+this.height/2);e&&t.rotate(i,e);for(var r=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],o=new O(i,t),s=r.length-1;0<=s;--s){var a=r[s].intersection(o);if(null!==a){n=a;break}}return n&&e&&n.rotate(i,-e),n},leftLine:function(){return new O(this.topLeft(),this.bottomLeft())},leftMiddle:function(){return new z(this.x,this.y+this.height/2)},maxRectScaleToFit:function(t,e){var n,i,r,o,s,a,h,l;t=new X(t),e||(e=t.center());var u=e.x,c=e.y;n=i=r=o=s=a=h=l=1/0;var d=t.topLeft();d.x<u&&(n=(this.x-u)/(d.x-u)),d.y<c&&(s=(this.y-c)/(d.y-c));var f=t.bottomRight();f.x>u&&(i=(this.x+this.width-u)/(f.x-u)),f.y>c&&(a=(this.y+this.height-c)/(f.y-c));var p=t.topRight();p.x>u&&(r=(this.x+this.width-u)/(p.x-u)),p.y<c&&(h=(this.y-c)/(p.y-c));var g=t.bottomLeft();return g.x<u&&(o=(this.x-u)/(g.x-u)),g.y>c&&(l=(this.y+this.height-c)/(g.y-c)),{sx:B(n,i,r,o),sy:B(s,a,h,l)}},maxRectUniformScaleToFit:function(t,e){var n=this.maxRectScaleToFit(t,e);return B(n.sx,n.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,e=this.y,n=this.width,i=this.height;return this.width<0&&(t=this.x+this.width,n=-this.width),this.height<0&&(e=this.y+this.height,i=-this.height),this.x=t,this.y=e,this.width=n,this.height=i,this},offset:function(t,e){return z.prototype.offset.call(this,t,e)},origin:function(){return new z(this.x,this.y)},pointNearestToPoint:function(t){if(t=new z(t),this.containsPoint(t))switch(this.sideNearestToPoint(t)){case"right":return new z(this.x+this.width,t.y);case"left":return new z(this.x,t.y);case"bottom":return new z(t.x,this.y+this.height);case"top":return new z(t.x,this.y)}return t.adhereToRect(this)},rightLine:function(){return new O(this.topRight(),this.bottomRight())},rightMiddle:function(){return new z(this.x+this.width,this.y+this.height/2)},round:function(t){var e=T(10,t||0);return this.x=a(this.x*e)/e,this.y=a(this.y*e)/e,this.width=a(this.width*e)/e,this.height=a(this.height*e)/e,this},scale:function(t,e,n){return n=this.origin().scale(t,e,n),this.x=n.x,this.y=n.y,this.width*=t,this.height*=e,this},sideNearestToPoint:function(t){var e=(t=new z(t)).x-this.x,n=this.x+this.width-t.x,i=t.y-this.y,r=e,o="left";return n<r&&(r=n,o="right"),i<r&&(r=i,o="top"),this.y+this.height-t.y<r&&(o="bottom"),o},snapToGrid:function(t,e){var n=this.origin().snapToGrid(t,e),i=this.corner().snapToGrid(t,e);return this.x=n.x,this.y=n.y,this.width=i.x-n.x,this.height=i.y-n.y,this},toJSON:function(){return{x:this.x,y:this.y,width:this.width,height:this.height}},topLine:function(){return new O(this.topLeft(),this.topRight())},topMiddle:function(){return new z(this.x+this.width/2,this.y)},topRight:function(){return new z(this.x+this.width,this.y)},toString:function(){return this.origin().toString()+" "+this.corner().toString()},union:function(t){var e=new X(t),n=this.x,i=this.y,r=this.width,o=this.height,s=e.x,a=e.y,h=e.width,l=e.height,u=e.x=B(n,s),c=e.y=B(i,a);return e.width=R(n+r,s+h)-u,e.height=R(i+o,a+l)-c,e}},X.prototype.bottomRight=X.prototype.corner,X.prototype.topLeft=X.prototype.origin,X.prototype.translate=X.prototype.offset;var b=function(t){return t%360+(t<0?360:0)},v=function(t,e){return e*a(t/e)},y=function(t){return 180*t/p%360},A=function(t,e){return(t=(e=e||!1)?t:t%360)*p/180},m=function(t,e){if(void 0===e)e=void 0===t?1:t,t=0;else if(e<t){var n=t;t=e,e=n}return f(o.random()*(e-t+1)+t)},w=x,P=O,S=z,k=X;function E(t,e){return e.unshift(null),new(Function.prototype.bind.apply(t,e))}function M(t){var e,n,i=arguments,r=[];for(n=arguments.length,e=1;e<n;e++)r.push(i[e]);if(!t)throw new Error("Missing a parent object.");var o=Object.create(t);for(n=r.length,e=0;e<n;e++){var s,a,h=r[e];for(a in h)h.hasOwnProperty(a)&&(delete o[a],s=Object.getOwnPropertyDescriptor(h,a),Object.defineProperty(o,a,s))}return o}var N={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 functi