-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoint.core.min.js
More file actions
15 lines (8 loc) · 297 KB
/
joint.core.min.js
File metadata and controls
15 lines (8 loc) · 297 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*! Rappid v3.1.1 - HTML5 Diagramming Framework - TRIAL VERSION
Copyright (c) 2015 client IO
2020-06-11
This Source Code Form is subject to the terms of the Rappid Trial License
, v. 2.0. If a copy of the Rappid License was not distributed with this
file, You can obtain one at http://jointjs.com/license/rappid_v2.txt
or from the Rappid archive as was distributed by client IO. See the LICENSE file.*/
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 function.")},divideAt:function(){throw new Error("Declaration missing for virtual function.")},divideAtLength:function(){throw new Error("Declaration missing for virtual function.")},divideAtT:function(t){if(this.divideAt)return this.divideAt(t);throw new Error("Neither divideAtT() nor divideAt() function is implemented.")},equals:function(){throw new Error("Declaration missing for virtual function.")},getSubdivisions:function(){throw new Error("Declaration missing for virtual function.")},isDifferentiable:function(){throw new Error("Declaration missing for virtual function.")},isSegment:!0,isSubpathStart:!1,isVisible:!0,length:function(){throw new Error("Declaration missing for virtual function.")},lengthAtT:function(t){if(t<=0)return 0;var e=this.length();return 1<=t?e:e*t},nextSegment:null,pointAt:function(){throw new Error("Declaration missing for virtual function.")},pointAtLength:function(){throw new Error("Declaration missing for virtual function.")},pointAtT:function(t){if(this.pointAt)return this.pointAt(t);throw new Error("Neither pointAtT() nor pointAt() function is implemented.")},previousSegment:null,subpathStartSegment:null,scale:function(){throw new Error("Declaration missing for virtual function.")},serialize:function(){throw new Error("Declaration missing for virtual function.")},tangentAt:function(){throw new Error("Declaration missing for virtual function.")},tangentAtLength:function(){throw new Error("Declaration missing for virtual function.")},tangentAtT:function(t){if(this.tangentAt)return this.tangentAt(t);throw new Error("Neither tangentAtT() nor tangentAt() function is implemented.")},toString:function(){throw new Error("Declaration missing for virtual function.")},translate:function(){throw new Error("Declaration missing for virtual function.")}};Object.defineProperty(N,"end",{configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(N,"start",{configurable:!0,enumerable:!0,get:function(){if(!this.previousSegment)throw new Error("Missing previous segment. (This segment cannot be the first segment of a path; OR segment has not yet been added to a path.)");return this.previousSegment.end}}),Object.defineProperty(N,"type",{configurable:!0,enumerable:!0,get:function(){throw new Error("Bad segment declaration. No type specified.")}});var V=function(){for(var t,e,n=arguments,i=[],r=arguments.length,o=0;o<r;o++)i.push(n[o]);if(!(this instanceof V))return E(V,i);if(0===r)throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates (none provided).");if(i[0]instanceof O){if(1===r)return this.end=i[0].end.clone(),this;throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates ("+r+" lines provided).")}if("string"==typeof i[0]||"number"==typeof i[0]){if(2===r)return this.end=new z(+i[0],+i[1]),this;if(r<2)throw new Error("Lineto constructor expects a line, 1 point, or 2 coordinates ("+r+" coordinates provided).");var s;for(t=[],o=0;o<r;o+=2)s=i.slice(o,o+2),t.push(E(V,s));return t}if(1===r)return this.end=new z(i[0]),this;for(t=[],o=0;o<r;o+=1)e=i[o],t.push(new V(e));return t},I={clone:function(){return new V(this.end)},divideAt:function(t){var e=new O(this.start,this.end).divideAt(t);return[new V(e[0]),new V(e[1])]},divideAtLength:function(t){var e=new O(this.start,this.end).divideAtLength(t);return[new V(e[0]),new V(e[1])]},getSubdivisions:function(){return[]},isDifferentiable:function(){return!!this.previousSegment&&!this.start.equals(this.end)},scale:function(t,e,n){return this.end.scale(t,e,n),this},serialize:function(){var t=this.end;return this.type+" "+t.x+" "+t.y},toString:function(){return this.type+" "+this.start+" "+this.end},translate:function(t,e){return this.end.translate(t,e),this}};Object.defineProperty(I,"type",{configurable:!0,enumerable:!0,value:"L"}),V.prototype=M(N,O.prototype,I);var j=function(){for(var t,e,n=arguments,i=[],r=arguments.length,o=0;o<r;o++)i.push(n[o]);if(!(this instanceof j))return E(j,i);if(0===r)throw new Error("Curveto constructor expects a curve, 3 points, or 6 coordinates (none provided).");if(i[0]instanceof g){if(1===r)return this.controlPoint1=i[0].controlPoint1.clone(),this.controlPoint2=i[0].controlPoint2.clone(),this.end=i[0].end.clone(),this;throw new Error("Curveto constructor expects a curve, 3 points, or 6 coordinates ("+r+" curves provided).")}if("string"==typeof i[0]||"number"==typeof i[0]){if(6===r)return this.controlPoint1=new z(+i[0],+i[1]),this.controlPoint2=new z(+i[2],+i[3]),this.end=new z(+i[4],+i[5]),this;if(r<6)throw new Error("Curveto constructor expects a curve, 3 points, or 6 coordinates ("+r+" coordinates provided).");var s;for(t=[],o=0;o<r;o+=6)s=i.slice(o,o+6),t.push(E(j,s));return t}if(3===r)return this.controlPoint1=new z(i[0]),this.controlPoint2=new z(i[1]),this.end=new z(i[2]),this;if(r<3)throw new Error("Curveto constructor expects a curve, 3 points, or 6 coordinates ("+r+" points provided).");for(t=[],o=0;o<r;o+=3)e=i.slice(o,o+3),t.push(E(j,e));return t},G={clone:function(){return new j(this.controlPoint1,this.controlPoint2,this.end)},divideAt:function(t,e){var n=new g(this.start,this.controlPoint1,this.controlPoint2,this.end).divideAt(t,e);return[new j(n[0]),new j(n[1])]},divideAtLength:function(t,e){var n=new g(this.start,this.controlPoint1,this.controlPoint2,this.end).divideAtLength(t,e);return[new j(n[0]),new j(n[1])]},divideAtT:function(t){var e=new g(this.start,this.controlPoint1,this.controlPoint2,this.end).divideAtT(t);return[new j(e[0]),new j(e[1])]},isDifferentiable:function(){if(!this.previousSegment)return!1;var t=this.start,e=this.controlPoint1,n=this.controlPoint2,i=this.end;return!(t.equals(e)&&e.equals(n)&&n.equals(i))},scale:function(t,e,n){return this.controlPoint1.scale(t,e,n),this.controlPoint2.scale(t,e,n),this.end.scale(t,e,n),this},serialize:function(){var t=this.controlPoint1,e=this.controlPoint2,n=this.end;return this.type+" "+t.x+" "+t.y+" "+e.x+" "+e.y+" "+n.x+" "+n.y},toString:function(){return this.type+" "+this.start+" "+this.controlPoint1+" "+this.controlPoint2+" "+this.end},translate:function(t,e){return this.controlPoint1.translate(t,e),this.controlPoint2.translate(t,e),this.end.translate(t,e),this}};Object.defineProperty(G,"type",{configurable:!0,enumerable:!0,value:"C"}),j.prototype=M(N,g.prototype,G);var U=function(){for(var t,e,n=arguments,i=[],r=arguments.length,o=0;o<r;o++)i.push(n[o]);if(!(this instanceof U))return E(U,i);if(0===r)throw new Error("Moveto constructor expects a line, a curve, 1 point, or 2 coordinates (none provided).");if(i[0]instanceof O){if(1===r)return this.end=i[0].end.clone(),this;throw new Error("Moveto constructor expects a line, a curve, 1 point, or 2 coordinates ("+r+" lines provided).")}if(i[0]instanceof g){if(1===r)return this.end=i[0].end.clone(),this;throw new Error("Moveto constructor expects a line, a curve, 1 point, or 2 coordinates ("+r+" curves provided).")}if("string"==typeof i[0]||"number"==typeof i[0]){if(2===r)return this.end=new z(+i[0],+i[1]),this;if(r<2)throw new Error("Moveto constructor expects a line, a curve, 1 point, or 2 coordinates ("+r+" coordinates provided).");var s;for(t=[],o=0;o<r;o+=2)s=i.slice(o,o+2),0===o?t.push(E(U,s)):t.push(E(V,s));return t}if(1===r)return this.end=new z(i[0]),this;for(t=[],o=0;o<r;o+=1)e=i[o],0===o?t.push(new U(e)):t.push(new V(e));return t},q={bbox:function(){return null},clone:function(){return new U(this.end)},closestPoint:function(){return this.end.clone()},closestPointNormalizedLength:function(){return 0},closestPointLength:function(){return 0},closestPointT:function(){return 1},closestPointTangent:function(){return null},divideAt:function(){return[this.clone(),this.clone()]},divideAtLength:function(){return[this.clone(),this.clone()]},equals:function(t){return this.end.equals(t.end)},getSubdivisions:function(){return[]},isDifferentiable:function(){return!1},isSubpathStart:!0,isVisible:!1,length:function(){return 0},lengthAtT:function(){return 0},pointAt:function(){return this.end.clone()},pointAtLength:function(){return this.end.clone()},pointAtT:function(){return this.end.clone()},scale:function(t,e,n){return this.end.scale(t,e,n),this},serialize:function(){var t=this.end;return this.type+" "+t.x+" "+t.y},tangentAt:function(){return null},tangentAtLength:function(){return null},tangentAtT:function(){return null},toString:function(){return this.type+" "+this.end},translate:function(t,e){return this.end.translate(t,e),this}};Object.defineProperty(q,"start",{configurable:!0,enumerable:!0,get:function(){throw new Error("Illegal access. Moveto segments should not need a start property.")}}),Object.defineProperty(q,"type",{configurable:!0,enumerable:!0,value:"M"}),U.prototype=M(N,q);var H=function(){for(var t=arguments,e=[],n=arguments.length,i=0;i<n;i++)e.push(t[i]);if(!(this instanceof H))return E(H,e);if(0<n)throw new Error("Closepath constructor expects no arguments.");return this},$={clone:function(){return new H},divideAt:function(t){var e=new O(this.start,this.end).divideAt(t);return[e[1].isDifferentiable()?new V(e[0]):this.clone(),new V(e[1])]},divideAtLength:function(t){var e=new O(this.start,this.end).divideAtLength(t);return[e[1].isDifferentiable()?new V(e[0]):this.clone(),new V(e[1])]},getSubdivisions:function(){return[]},isDifferentiable:function(){return!(!this.previousSegment||!this.subpathStartSegment)&&!this.start.equals(this.end)},scale:function(){return this},serialize:function(){return this.type},toString:function(){return this.type+" "+this.start+" "+this.end},translate:function(){return this}};Object.defineProperty($,"end",{configurable:!0,enumerable:!0,get:function(){if(!this.subpathStartSegment)throw new Error("Missing subpath start segment. (This segment needs a subpath start segment (e.g. Moveto); OR segment has not yet been added to a path.)");return this.subpathStartSegment.end}}),Object.defineProperty($,"type",{configurable:!0,enumerable:!0,value:"Z"}),H.prototype=M(N,O.prototype,$);var Y=D.segmentTypes={L:V,C:j,M:U,Z:H,z:H};D.regexSupportedData=new RegExp("^[\\s\\d"+Object.keys(Y).join("")+",.]*$"),D.isDataSupported=function(t){return"string"==typeof t&&this.regexSupportedData.test(t)};var W,Z,J={bezier:t,Curve:g,Ellipse:x,Line:O,Path:D,Point:z,Polyline:L,Rect:X,scale:{linear:function(t,e,n){var i=t[1]-t[0],r=e[1]-e[0];return(n-t[0])/i*r+e[0]||0}},normalizeAngle:b,snapToGrid:v,toDeg:y,toRad:A,random:m,ellipse:w,line:P,point:S,rect:k},K=function(){if(!("object"==typeof window&&!(!window.SVGAngle&&!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1"))))return function(){throw new Error("SVG is required to use Vectorizer.")};var M={svg:"http://www.w3.org/2000/svg",xmlns:"http://www.w3.org/2000/xmlns/",xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xhtml:"http://www.w3.org/1999/xhtml"},t=Math,g=t.PI,o=t.atan2,s=t.sqrt,c=t.min,d=t.max,v=t.cos,m=t.sin,N=function(t,e,n){if(!(this instanceof N))return N.apply(Object.create(N.prototype),arguments);if(t){if(N.isV(t)&&(t=t.node),e=e||{},N.isString(t)){if("svg"===t.toLowerCase())t=N.createSvgDocument();else if("<"===t[0]){var i=N.createSvgDocument(t);if(1<i.childNodes.length){var r,o,s=[];for(r=0,o=i.childNodes.length;r<o;r++){var a=i.childNodes[r];s.push(new N(document.importNode(a,!0)))}return s}t=document.importNode(i.firstChild,!0)}else t=document.createElementNS(M.svg,t);N.ensureId(t)}return this.node=t,this.setAttributes(e),n&&this.append(n),this}},e=N.prototype;function V(t,e,n){n||(n={});for(var i=n.includeAnnotationIndices,r=n.eol,o=n.lineHeight,s=n.baseSize,a=0,h={},l=e.length-1,u=0;u<=l;u++){var c=e[u],d=null;if(N.isObject(c)){var f=c.attrs,p=N("tspan",f),g=p.node,v=c.t;r&&u===l&&(v+=r),g.textContent=v;var m=f.class;m&&p.addClass(m),i&&p.attr("annotations",c.annotations),void 0===(d=parseFloat(f["font-size"]))&&(d=s),d&&a<d&&(a=d)}else r&&u===l&&(c+=r),g=document.createTextNode(c||" "),s&&a<s&&(a=s);t.appendChild(g)}return a&&(h.maxFontSize=a),o?h.lineHeight=o:a&&(h.lineHeight=1.2*a),h}Object.defineProperty(e,"id",{enumerable:!0,get:function(){return this.node.id},set:function(t){this.node.id=t}}),e.getTransformToElement=function(t){var e=this.node;if(N.isSVGGraphicsElement(t)&&N.isSVGGraphicsElement(e)){var n=N.toNode(t).getScreenCTM(),i=e.getScreenCTM();if(n&&i)return n.inverse().multiply(i)}return N.createSVGMatrix()},e.transform=function(t,e){var n=this.node;if(N.isUndefined(t))return N.transformStringToMatrix(this.attr("transform"));if(e&&e.absolute)return this.attr("transform",N.matrixToTransformString(t));var i=N.createSVGTransform(t);return n.transform.baseVal.appendItem(i),this},e.translate=function(t,e,n){n=n||{},e=e||0;var i=this.attr("transform")||"",r=N.parseTransformString(i);if(i=r.value,N.isUndefined(t))return r.translate;i=i.replace(/translate\([^)]*\)/g,"").trim();var o="translate("+(n.absolute?t:r.translate.tx+t)+","+(n.absolute?e:r.translate.ty+e)+")";return this.attr("transform",(o+" "+i).trim()),this},e.rotate=function(t,e,n,i){i=i||{};var r=this.attr("transform")||"",o=N.parseTransformString(r);if(r=o.value,N.isUndefined(t))return o.rotate;r=r.replace(/rotate\([^)]*\)/g,"").trim(),t%=360;var s="rotate("+(i.absolute?t:o.rotate.angle+t)+(void 0!==e&&void 0!==n?","+e+","+n:"")+")";return this.attr("transform",(r+" "+s).trim()),this},e.scale=function(t,e){e=N.isUndefined(e)?t:e;var n=this.attr("transform")||"",i=N.parseTransformString(n);if(n=i.value,N.isUndefined(t))return i.scale;n=n.replace(/scale\([^)]*\)/g,"").trim();var r="scale("+t+","+e+")";return this.attr("transform",(n+" "+r).trim()),this},e.bbox=function(t,e){var n,i=this.node,r=i.ownerSVGElement;if(!r)return new X(0,0,0,0);try{n=i.getBBox()}catch(t){n={x:i.clientLeft,y:i.clientTop,width:i.clientWidth,height:i.clientHeight}}if(t)return new X(n);var o=this.getTransformToElement(e||r);return N.transformRect(n,o)},e.getBBox=function(t){var e,n={},i=this.node;if(!i.ownerSVGElement||!N.isSVGGraphicsElement(i))return new X(0,0,0,0);if(t&&(t.target&&(n.target=N.toNode(t.target)),t.recursive&&(n.recursive=t.recursive)),n.recursive){var r=this.children(),o=r.length;if(0===o)return this.getBBox({target:n.target,recursive:!1});n.target||(n.target=this);for(var s=0;s<o;s++){var a,h=r[s];a=0===h.children().length?h.getBBox({target:n.target,recursive:!1}):h.getBBox({target:n.target,recursive:!0}),e=e?e.union(a):a}return e}try{e=i.getBBox()}catch(t){e={x:i.clientLeft,y:i.clientTop,width:i.clientWidth,height:i.clientHeight}}if(n.target){var l=this.getTransformToElement(n.target);return N.transformRect(e,l)}return new X(e)};var F=/em$/;function _(t,e){var n=parseFloat(t);return F.test(t)?n*e:n}e.text=function(t,e){if(t&&"string"!=typeof t)throw new Error("Vectorizer: text() expects the first argument to be a string.");t=N.sanitizeText(t),e||(e={});var n=e.displayEmpty,i=e.eol,r=e.textPath,o=e.textVerticalAnchor,s="middle"===o||"bottom"===o||"top"===o,a=e.x;void 0===a&&(a=this.attr("x")||0);var h=e.includeAnnotationIndices,l=e.annotations;l&&!N.isArray(l)&&(l=[l]);var u=e.lineHeight,c="auto"===u,d=c?"1.5em":u||"1em";this.empty(),this.attr({"xml:space":"preserve",display:t||n?null:"none"});var f=parseFloat(this.attr("font-size"));f||(f=16,(s||l)&&this.attr("font-size",f));var p,g=document;p=r?("string"==typeof r&&(r={d:r}),function(t,e){t||(t={});var n=N("textPath"),i=t.d;if(i&&void 0===t["xlink:href"]){var r=N("path").attr("d",i).appendTo(e.defs());n.attr("xlink:href","#"+r.id)}return N.isObject(t)&&n.attr(t),n.node}(r,this)):g.createDocumentFragment();for(var v,m=0,y=t.split("\n"),w=[],b=0,x=y.length-1;b<=x;b++){var A,P=d,S="v-line",k=g.createElementNS(M.svg,"tspan"),E=y[b];if(E)if(l){var C=(A=V(k,N.annotateString(E,l,{offset:-m,includeAnnotationIndices:h}),{includeAnnotationIndices:h,eol:b!==x&&i,lineHeight:c?null:d,baseSize:f})).lineHeight;C&&c&&0!==b&&(P=C),0===b&&(v=.8*A.maxFontSize)}else i&&b!==x&&(E+=i),k.textContent=E;else{k.textContent="-",S+=" v-empty-line";var T=k.style;T.fillOpacity=0,T.strokeOpacity=0,l&&(A={})}A&&w.push(A),0<b&&k.setAttribute("dy",P),(0<b||r)&&k.setAttribute("x",a),k.className.baseVal=S,p.appendChild(k),m+=E.length+1}if(s)if(l)P=function(t,e,n,i){if(!Array.isArray(e))return 0;var r=e.length;if(!r)return 0;for(var o=e[0],s=_(o.maxFontSize,n)||n,a=0,h=_(i,n),l=1;l<r;l++)a+=_((o=e[l]).lineHeight,n)||h;var u,c=_(o.maxFontSize,n)||n;switch(t){case"middle":u=s/2-.15*c-a/2;break;case"bottom":u=-.25*c-a;break;default:case"top":u=.8*s}return u}(o,w,f,d);else if("top"===o)P="0.8em";else{var L;switch(0<x?(L=parseFloat(d)||1,L*=x,F.test(d)||(L/=f)):L=0,o){case"middle":P=.3-L/2+"em";break;case"bottom":P=-L-.3+"em"}}else 0===o?P="0em":o?P=o:(P=0,null===this.attr("y")&&this.attr("y",v||"0.8em"));return p.firstChild.setAttribute("dy",P),this.append(p),this},e.removeAttr=function(t){var e=N.qualifyAttr(t),n=this.node;return e.ns?n.hasAttributeNS(e.ns,e.local)&&n.removeAttributeNS(e.ns,e.local):n.hasAttribute(t)&&n.removeAttribute(t),this},e.attr=function(t,e){if(N.isUndefined(t)){for(var n=this.node.attributes,i={},r=0;r<n.length;r++)i[n[r].name]=n[r].value;return i}if(N.isString(t)&&N.isUndefined(e))return this.node.getAttribute(t);if("object"==typeof t)for(var o in t)t.hasOwnProperty(o)&&this.setAttribute(o,t[o]);else this.setAttribute(t,e);return this},e.normalizePath=function(){return"PATH"===this.tagName()&&this.attr("d",N.normalizePathData(this.attr("d"))),this},e.remove=function(){return this.node.parentNode&&this.node.parentNode.removeChild(this.node),this},e.empty=function(){for(;this.node.firstChild;)this.node.removeChild(this.node.firstChild);return this},e.setAttributes=function(t){for(var e in t)t.hasOwnProperty(e)&&this.setAttribute(e,t[e]);return this},e.append=function(t){N.isArray(t)||(t=[t]);for(var e=0,n=t.length;e<n;e++)this.node.appendChild(N.toNode(t[e]));return this},e.prepend=function(t){var e=this.node.firstChild;return e?N(e).before(t):this.append(t)},e.before=function(t){var e=this.node,n=e.parentNode;if(n){N.isArray(t)||(t=[t]);for(var i=0,r=t.length;i<r;i++)n.insertBefore(N.toNode(t[i]),e)}return this},e.appendTo=function(t){return N.toNode(t).appendChild(this.node),this},e.svg=function(){return this.node instanceof window.SVGSVGElement?this:N(this.node.ownerSVGElement)},e.tagName=function(){return this.node.tagName.toUpperCase()},e.defs=function(){var t=this.svg()||this,e=t.node.getElementsByTagName("defs")[0];return e?N(e):N("defs").appendTo(t)},e.clone=function(){var t=N(this.node.cloneNode(!0));return t.node.id=N.uniqueId(),t},e.findOne=function(t){var e=this.node.querySelector(t);return e?N(e):void 0},e.find=function(t){var e=[],n=this.node.querySelectorAll(t);if(n)for(var i=0;i<n.length;i++)e.push(N(n[i]));return e},e.children=function(){for(var t=this.node.childNodes,e=[],n=0;n<t.length;n++){1===t[n].nodeType&&e.push(N(t[n]))}return e},e.index=function(){for(var t=0,e=this.node.previousSibling;e;)1===e.nodeType&&t++,e=e.previousSibling;return t},e.findParentByClass=function(t,e){for(var n=this.node.ownerSVGElement,i=this.node.parentNode;i&&i!==e&&i!==n;){var r=N(i);if(r.hasClass(t))return r;i=i.parentNode}return null},e.contains=function(t){var e=this.node,n=N.toNode(t),i=n&&n.parentNode;return e===i||!!(i&&1===i.nodeType&&16&e.compareDocumentPosition(i))},e.toLocalPoint=function(t,e){var n=this.svg().node,i=n.createSVGPoint();i.x=t,i.y=e;try{var r=i.matrixTransform(n.getScreenCTM().inverse()),o=this.getTransformToElement(n).inverse()}catch(t){return i}return r.matrixTransform(o)},e.translateCenterToPoint=function(t){var e=this.getBBox({target:this.svg()}).center();return this.translate(t.x-e.x,t.y-e.y),this},e.translateAndAutoOrient=function(t,e,n){t=new z(t),e=new z(e),n||(n=this.svg());var i=this.scale();this.attr("transform","");var r=this.getBBox({target:n}).scale(i.sx,i.sy),o=N.createSVGTransform();o.setTranslate(-r.x-r.width/2,-r.y-r.height/2);var s=N.createSVGTransform(),a=t.angleBetween(e,t.clone().offset(1,0));a&&s.setRotate(a,0,0);var h=N.createSVGTransform(),l=t.clone().move(e,r.width/2);h.setTranslate(2*t.x-l.x,2*t.y-l.y);var u=this.getTransformToElement(n),c=N.createSVGTransform();return c.setMatrix(h.matrix.multiply(s.matrix.multiply(o.matrix.multiply(u.scale(i.sx,i.sy))))),this.attr("transform",N.matrixToTransformString(c.matrix)),this},e.animateAlongPath=function(t,e){e=N.toNode(e);var n=N.ensureId(e),i=N("animateMotion",t),r=N("mpath",{"xlink:href":"#"+n});i.append(r),this.append(i);try{i.node.beginElement()}catch(t){if("fake"===document.documentElement.getAttribute("smiling")){var o=i.node;o.animators=[];var s=o.getAttribute("id");s&&(id2anim[s]=o);for(var a=getTargets(o),h=0,l=a.length;h<l;h++){var u=a[h],c=new Animator(o,u,h);animators.push(c),(o.animators[h]=c).register()}}}return this},e.hasClass=function(t){return new RegExp("(\\s|^)"+t+"(\\s|$)").test(this.node.getAttribute("class"))},e.addClass=function(t){if(t&&!this.hasClass(t)){var e=this.node.getAttribute("class")||"";this.node.setAttribute("class",(e+" "+t).trim())}return this},e.removeClass=function(t){if(t&&this.hasClass(t)){var e=this.node.getAttribute("class").replace(new RegExp("(\\s|^)"+t+"(\\s|$)","g"),"$2");this.node.setAttribute("class",e)}return this},e.toggleClass=function(t,e){return(N.isUndefined(e)?this.hasClass(t):!e)?this.removeClass(t):this.addClass(t),this},e.sample=function(t){t=t||1;for(var e,n=this.node,i=n.getTotalLength(),r=[],o=0;o<i;)e=n.getPointAtLength(o),r.push({x:e.x,y:e.y,distance:o}),o+=t;return r},e.convertToPath=function(){var t=N("path");t.attr(this.attr());var e=this.convertToPathData();return e&&t.attr("d",e),t},e.convertToPathData=function(){var t=this.tagName();switch(t){case"PATH":return this.attr("d");case"LINE":return N.convertLineToPathData(this.node);case"POLYGON":return N.convertPolygonToPathData(this.node);case"POLYLINE":return N.convertPolylineToPathData(this.node);case"ELLIPSE":return N.convertEllipseToPathData(this.node);case"CIRCLE":return N.convertCircleToPathData(this.node);case"RECT":return N.convertRectToPathData(this.node)}throw new Error(t+" cannot be converted to PATH.")},N.prototype.toGeometryShape=function(){var t,e,n,i,r,o,s,a,h,l,u,c,d,f,p;switch(this.tagName()){case"RECT":return t=parseFloat(this.attr("x"))||0,e=parseFloat(this.attr("y"))||0,n=parseFloat(this.attr("width"))||0,i=parseFloat(this.attr("height"))||0,new X(t,e,n,i);case"CIRCLE":return r=parseFloat(this.attr("cx"))||0,o=parseFloat(this.attr("cy"))||0,s=parseFloat(this.attr("r"))||0,new x({x:r,y:o},s,s);case"ELLIPSE":return r=parseFloat(this.attr("cx"))||0,o=parseFloat(this.attr("cy"))||0,a=parseFloat(this.attr("rx"))||0,h=parseFloat(this.attr("ry"))||0,new x({x:r,y:o},a,h);case"POLYLINE":return l=N.getPointsFromSvgNode(this),new L(l);case"POLYGON":return 1<(l=N.getPointsFromSvgNode(this)).length&&l.push(l[0]),new L(l);case"PATH":return u=this.attr("d"),D.isDataSupported(u)||(u=N.normalizePathData(u)),new D(u);case"LINE":return c=parseFloat(this.attr("x1"))||0,f=parseFloat(this.attr("y1"))||0,d=parseFloat(this.attr("x2"))||0,p=parseFloat(this.attr("y2"))||0,new O({x:c,y:f},{x:d,y:p})}return this.getBBox()},e.findIntersection=function(t,e){var n=this.svg().node;e=e||n;var i=this.getBBox({target:e}),r=i.center();if(i.intersectionWithLineFromCenterToPoint(t)){var o,s=this.tagName();if("RECT"===s){var a=new X(parseFloat(this.attr("x")||0),parseFloat(this.attr("y")||0),parseFloat(this.attr("width")),parseFloat(this.attr("height"))),h=this.getTransformToElement(e),l=N.decomposeMatrix(h),u=n.createSVGTransform();u.setRotate(-l.rotation,r.x,r.y);var c=N.transformRect(a,u.matrix.multiply(h));o=new X(c).intersectionWithLineFromCenterToPoint(t,l.rotation)}else if("PATH"===s||"POLYGON"===s||"POLYLINE"===s||"CIRCLE"===s||"ELLIPSE"===s){var d,f,p,g,v,m=("PATH"===s?this:this.convertToPath()).sample(),y=1/0,w=[];for(d=0;d<m.length;d++)f=m[d],p=(p=N.createSVGPoint(f.x,f.y)).matrixTransform(this.getTransformToElement(e)),(v=(f=new z(p)).distance(r)+(g=1.1*f.distance(t)))<y?(y=v,w=[{sample:f,refDistance:g}]):v<y+1&&w.push({sample:f,refDistance:g});w.sort(function(t,e){return t.refDistance-e.refDistance}),w[0]&&(o=w[0].sample)}return o}},e.setAttribute=function(t,e){var n=this.node;if(null===e)return this.removeAttr(t),this;var i=N.qualifyAttr(t);return i.ns?n.setAttributeNS(i.ns,t,e):"id"===t?n.id=e:n.setAttribute(t,e),this},N.createSvgDocument=function(t){if(t){var e='<svg xmlns="'+M.svg+'" xmlns:xlink="'+M.xlink+'" version="1.1">'+t+"</svg>";return N.parseXML(e,{async:!1}).documentElement}var n=document.createElementNS(M.svg,"svg");return n.setAttributeNS(M.xmlns,"xmlns:xlink",M.xlink),n.setAttribute("version","1.1"),n},N.idCounter=0,N.uniqueId=function(){return"v-"+ ++N.idCounter},N.toNode=function(t){return N.isV(t)?t.node:t.nodeName&&t||t[0]},N.ensureId=function(t){return(t=N.toNode(t)).id||(t.id=N.uniqueId())},N.sanitizeText=function(t){return(t||"").replace(/ /g," ")},N.isUndefined=function(t){return void 0===t},N.isString=function(t){return"string"==typeof t},N.isObject=function(t){return t&&"object"==typeof t},N.isArray=Array.isArray,N.parseXML=function(t,e){var n;e=e||{};try{var i=new DOMParser;N.isUndefined(e.async)||(i.async=e.async),n=i.parseFromString(t,"text/xml")}catch(t){n=void 0}if(!n||n.getElementsByTagName("parsererror").length)throw new Error("Invalid XML: "+t);return n},N.qualifyAttr=function(t){if(-1===t.indexOf(":"))return{ns:null,local:t};var e=t.split(":");return{ns:M[e[0]],local:e[1]}},N.transformRegex=/(\w+)\(([^,)]+),?([^)]+)?\)/gi,N.transformSeparatorRegex=/[ ,]+/,N.transformationListRegex=/^(\w+)\((.*)\)/,N.transformStringToMatrix=function(t){var e=N.createSVGMatrix(),n=t&&t.match(N.transformRegex);if(!n)return e;for(var i=0,r=n.length;i<r;i++){var o=n[i].match(N.transformationListRegex);if(o){var s,a,h,l,u,c=N.createSVGMatrix(),d=o[2].split(N.transformSeparatorRegex);switch(o[1].toLowerCase()){case"scale":s=parseFloat(d[0]),a=void 0===d[1]?s:parseFloat(d[1]),c=c.scaleNonUniform(s,a);break;case"translate":h=parseFloat(d[0]),l=parseFloat(d[1]),c=c.translate(h,l);break;case"rotate":u=parseFloat(d[0]),h=parseFloat(d[1])||0,l=parseFloat(d[2])||0,c=0!==h||0!==l?c.translate(h,l).rotate(u).translate(-h,-l):c.rotate(u);break;case"skewx":u=parseFloat(d[0]),c=c.skewX(u);break;case"skewy":u=parseFloat(d[0]),c=c.skewY(u);break;case"matrix":c.a=parseFloat(d[0]),c.b=parseFloat(d[1]),c.c=parseFloat(d[2]),c.d=parseFloat(d[3]),c.e=parseFloat(d[4]),c.f=parseFloat(d[5]);break;default:continue}e=e.multiply(c)}}return e},N.matrixToTransformString=function(t){return t||(t=!0),"matrix("+(void 0!==t.a?t.a:1)+","+(void 0!==t.b?t.b:0)+","+(void 0!==t.c?t.c:0)+","+(void 0!==t.d?t.d:1)+","+(void 0!==t.e?t.e:0)+","+(void 0!==t.f?t.f:0)+")"},N.parseTransformString=function(t){var e,n,i;if(t){var r=N.transformSeparatorRegex;if(0<=t.trim().indexOf("matrix")){var o=N.transformStringToMatrix(t),s=N.decomposeMatrix(o);e=[s.translateX,s.translateY],i=[s.scaleX,s.scaleY],n=[s.rotation];var a=[];0===e[0]&&0===e[1]||a.push("translate("+e+")"),1===i[0]&&1===i[1]||a.push("scale("+i+")"),0!==n[0]&&a.push("rotate("+n+")"),t=a.join(" ")}else{var h=t.match(/translate\((.*?)\)/);h&&(e=h[1].split(r));var l=t.match(/rotate\((.*?)\)/);l&&(n=l[1].split(r));var u=t.match(/scale\((.*?)\)/);u&&(i=u[1].split(r))}}var c=i&&i[0]?parseFloat(i[0]):1;return{value:t,translate:{tx:e&&e[0]?parseInt(e[0],10):0,ty:e&&e[1]?parseInt(e[1],10):0},rotate:{angle:n&&n[0]?parseInt(n[0],10):0,cx:n&&n[1]?parseInt(n[1],10):void 0,cy:n&&n[2]?parseInt(n[2],10):void 0},scale:{sx:c,sy:i&&i[1]?parseFloat(i[1]):c}}},N.deltaTransformPoint=function(t,e){return{x:e.x*t.a+e.y*t.c+0,y:e.x*t.b+e.y*t.d+0}},N.decomposeMatrix=function(t){var e=N.deltaTransformPoint(t,{x:0,y:1}),n=N.deltaTransformPoint(t,{x:1,y:0}),i=180/g*o(e.y,e.x)-90,r=180/g*o(n.y,n.x);return{translateX:t.e,translateY:t.f,scaleX:s(t.a*t.a+t.b*t.b),scaleY:s(t.c*t.c+t.d*t.d),skewX:i,skewY:r,rotation:i}},N.matrixToScale=function(t){var e,n,i,r;return t?(e=N.isUndefined(t.a)?1:t.a,r=N.isUndefined(t.d)?1:t.d,n=t.b,i=t.c):e=r=1,{sx:n?s(e*e+n*n):e,sy:i?s(i*i+r*r):r}},N.matrixToRotate=function(t){var e={x:0,y:1};return t&&(e=N.deltaTransformPoint(t,e)),{angle:b(y(o(e.y,e.x))-90)}},N.matrixToTranslate=function(t){return{tx:t&&t.e||0,ty:t&&t.f||0}},N.isV=function(t){return t instanceof N},N.isVElement=N.isV,N.isSVGGraphicsElement=function(t){return!!t&&((t=N.toNode(t))instanceof SVGElement&&"function"==typeof t.getScreenCTM)};var f=N("svg").node;return N.createSVGMatrix=function(t){var e=f.createSVGMatrix();for(var n in t)e[n]=t[n];return e},N.createSVGTransform=function(t){return N.isUndefined(t)?f.createSVGTransform():(t instanceof SVGMatrix||(t=N.createSVGMatrix(t)),f.createSVGTransformFromMatrix(t))},N.createSVGPoint=function(t,e){var n=f.createSVGPoint();return n.x=t,n.y=e,n},N.transformRect=function(t,e){var n=f.createSVGPoint();n.x=t.x,n.y=t.y;var i=n.matrixTransform(e);n.x=t.x+t.width,n.y=t.y;var r=n.matrixTransform(e);n.x=t.x+t.width,n.y=t.y+t.height;var o=n.matrixTransform(e);n.x=t.x,n.y=t.y+t.height;var s=n.matrixTransform(e),a=c(i.x,r.x,o.x,s.x),h=d(i.x,r.x,o.x,s.x),l=c(i.y,r.y,o.y,s.y),u=d(i.y,r.y,o.y,s.y);return new X(a,l,h-a,u-l)},N.transformPoint=function(t,e){return new z(N.createSVGPoint(t.x,t.y).matrixTransform(e))},N.transformLine=function(t,e){return new O(N.transformPoint(t.start,e),N.transformPoint(t.end,e))},N.transformPolyline=function(t,e){var n=t instanceof L?t.points:t;N.isArray(n)||(n=[]);for(var i=[],r=0,o=n.length;r<o;r++)i[r]=N.transformPoint(n[r],e);return new L(i)},N.styleToObject=function(t){for(var e={},n=t.split(";"),i=0;i<n.length;i++){var r=n[i].split("=");e[r[0].trim()]=r[1].trim()}return e},N.createSlicePathData=function(t,e,n,i){var r=2*g-1e-6,o=t,s=e,a=n,h=i,l=(h<a&&(l=a,a=h,h=l),h-a),u=l<g?"0":"1",c=v(a),d=m(a),f=v(h),p=m(h);return r<=l?o?"M0,"+s+"A"+s+","+s+" 0 1,1 0,"+-s+"A"+s+","+s+" 0 1,1 0,"+s+"M0,"+o+"A"+o+","+o+" 0 1,0 0,"+-o+"A"+o+","+o+" 0 1,0 0,"+o+"Z":"M0,"+s+"A"+s+","+s+" 0 1,1 0,"+-s+"A"+s+","+s+" 0 1,1 0,"+s+"Z":o?"M"+s*c+","+s*d+"A"+s+","+s+" 0 "+u+",1 "+s*f+","+s*p+"L"+o*f+","+o*p+"A"+o+","+o+" 0 "+u+",0 "+o*c+","+o*d+"Z":"M"+s*c+","+s*d+"A"+s+","+s+" 0 "+u+",1 "+s*f+","+s*p+"L0,0Z"},N.mergeAttrs=function(t,e){for(var n in e)"class"===n?t[n]=t[n]?t[n]+" "+e[n]:e[n]:"style"===n?N.isObject(t[n])&&N.isObject(e[n])?t[n]=N.mergeAttrs(t[n],e[n]):N.isObject(t[n])?t[n]=N.mergeAttrs(t[n],N.styleToObject(e[n])):N.isObject(e[n])?t[n]=N.mergeAttrs(N.styleToObject(t[n]),e[n]):t[n]=N.mergeAttrs(N.styleToObject(t[n]),N.styleToObject(e[n])):t[n]=e[n];return t},N.annotateString=function(t,e,n){e=e||[];for(var i,r,o,s=(n=n||{}).offset||0,a=[],h=[],l=0;l<t.length;l++){r=h[l]=t[l];for(var u=0;u<e.length;u++){var c=e[u],d=c.start+s,f=c.end+s;d<=l&&l<f&&(N.isObject(r)?r.attrs=N.mergeAttrs(N.mergeAttrs({},r.attrs),c.attrs):r=h[l]={t:t[l],attrs:c.attrs},n.includeAnnotationIndices&&(r.annotations||(r.annotations=[])).push(u))}(o=h[l-1])?N.isObject(r)&&N.isObject(o)?JSON.stringify(r.attrs)===JSON.stringify(o.attrs)?i.t+=r.t:(a.push(i),i=r):i=N.isObject(r)?(a.push(i),r):N.isObject(o)?(a.push(i),r):(i||"")+r:i=r}return i&&a.push(i),a},N.findAnnotationsAtIndex=function(t,e){var n=[];return t&&t.forEach(function(t){t.start<e&&e<=t.end&&n.push(t)}),n},N.findAnnotationsBetweenIndexes=function(t,e,n){var i=[];return t&&t.forEach(function(t){(e>=t.start&&e<t.end||n>t.start&&n<=t.end||t.start>=e&&t.end<n)&&i.push(t)}),i},N.shiftAnnotations=function(t,e,n){return t&&t.forEach(function(t){t.start<e&&t.end>=e?t.end+=n:t.start>=e&&(t.start+=n,t.end+=n)}),t},N.convertLineToPathData=function(t){return["M",(t=N(t)).attr("x1"),t.attr("y1"),"L",t.attr("x2"),t.attr("y2")].join(" ")},N.convertPolygonToPathData=function(t){var e=N.getPointsFromSvgNode(t);return 0===e.length?null:N.svgPointsToPath(e)+" Z"},N.convertPolylineToPathData=function(t){var e=N.getPointsFromSvgNode(t);return 0===e.length?null:N.svgPointsToPath(e)},N.svgPointsToPath=function(t){for(var e=0,n=t.length;e<n;e++)t[e]=t[e].x+" "+t[e].y;return"M "+t.join(" L")},N.getPointsFromSvgNode=function(t){var e=[],n=(t=N.toNode(t)).points;if(n)for(var i=0,r=n.numberOfItems;i<r;i++)e.push(n.getItem(i));return e},N.KAPPA=.551784,N.convertCircleToPathData=function(t){t=N(t);var e=parseFloat(t.attr("cx"))||0,n=parseFloat(t.attr("cy"))||0,i=parseFloat(t.attr("r")),r=i*N.KAPPA;return["M",e,n-i,"C",e+r,n-i,e+i,n-r,e+i,n,"C",e+i,n+r,e+r,n+i,e,n+i,"C",e-r,n+i,e-i,n+r,e-i,n,"C",e-i,n-r,e-r,n-i,e,n-i,"Z"].join(" ")},N.convertEllipseToPathData=function(t){t=N(t);var e=parseFloat(t.attr("cx"))||0,n=parseFloat(t.attr("cy"))||0,i=parseFloat(t.attr("rx")),r=parseFloat(t.attr("ry"))||i,o=i*N.KAPPA,s=r*N.KAPPA;return["M",e,n-r,"C",e+o,n-r,e+i,n-s,e+i,n,"C",e+i,n+s,e+o,n+r,e,n+r,"C",e-o,n+r,e-i,n+s,e-i,n,"C",e-i,n-s,e-o,n-r,e,n-r,"Z"].join(" ")},N.convertRectToPathData=function(t){return t=N(t),N.rectToPath({x:parseFloat(t.attr("x"))||0,y:parseFloat(t.attr("y"))||0,width:parseFloat(t.attr("width"))||0,height:parseFloat(t.attr("height"))||0,rx:parseFloat(t.attr("rx"))||0,ry:parseFloat(t.attr("ry"))||0})},N.rectToPath=function(t){var e=t.x,n=t.y,i=t.width,r=t.height,o=c(t.rx||t["top-rx"]||0,i/2),s=c(t.rx||t["bottom-rx"]||0,i/2),a=c(t.ry||t["top-ry"]||0,r/2),h=c(t.ry||t["bottom-ry"]||0,r/2);return(o||s||a||h?["M",e,n+a,"v",r-a-h,"a",s,h,0,0,0,s,h,"h",i-2*s,"a",s,h,0,0,0,s,-h,"v",-(r-h-a),"a",o,a,0,0,0,-o,-a,"h",-(i-2*o),"a",o,a,0,0,0,-o,a,"Z"]:["M",e,n,"H",e+i,"V",n+r,"H",e,"V",n,"Z"]).join(" ")},N.normalizePathData=function(){var t="\t\n\v\f\r \u2028\u2029",g=new RegExp("([a-z])["+t+",]*((-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?["+t+"]*,?["+t+"]*)+)","ig"),v=new RegExp("(-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?)["+t+"]*,?["+t+"]*","ig"),e=Math,U=e.PI,q=e.sin,H=e.cos,$=e.tan,Y=e.asin,X=e.sqrt,W=e.abs;function d(t,e,n,i,r,o){return[1/3*t+2/3*n,1/3*e+2/3*i,1/3*r+2/3*n,1/3*o+2/3*i,r,o]}function Z(t,e,n){return{x:t*H(n)-e*q(n),y:t*q(n)+e*H(n)}}function f(t){if(Array.isArray(t)&&Array.isArray(t&&t[0])||(t=function(t){if(!t)return null;var o={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},s=[];return String(t).replace(g,function(t,e,n){var i=[],r=e.toLowerCase();for(n.replace(v,function(t,e){e&&i.push(+e)}),"m"===r&&2<i.length&&(s.push([e].concat(i.splice(0,2))),r="l",e="m"===e?"l":"L");i.length>=o[r]&&(s.push([e].concat(i.splice(0,o[r]))),o[r]););}),s}(t)),!t||!t.length)return[["M",0,0]];for(var e,n=[],i=0,r=0,o=0,s=0,a=t.length,h=0;h<a;h++){var l=[];n.push(l);var u,c,d=t[h];if((e=d[0])!=e.toUpperCase())switch(l[0]=e.toUpperCase(),l[0]){case"A":l[1]=d[1],l[2]=d[2],l[3]=d[3],l[4]=d[4],l[5]=d[5],l[6]=+d[6]+i,l[7]=+d[7]+r;break;case"V":l[1]=+d[1]+r;break;case"H":l[1]=+d[1]+i;break;case"M":for(o=+d[1]+i,s=+d[2]+r,u=d.length,c=1;c<u;c++)l[c]=+d[c]+(c%2?i:r);break;default:for(u=d.length,c=1;c<u;c++)l[c]=+d[c]+(c%2?i:r)}else for(var f=d.length,p=0;p<f;p++)l[p]=d[p];switch(l[0]){case"Z":i=+o,r=+s;break;case"H":i=l[1];break;case"V":r=l[1];break;case"M":o=l[l.length-2],s=l[l.length-1],i=l[l.length-2],r=l[l.length-1];break;default:i=l[l.length-2],r=l[l.length-1]}}return n}function n(t){var i=f(t),e={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null};function n(t,e,n){var i,r;if(!t)return["C",e.x,e.y,e.x,e.y,e.x,e.y];switch(t[0]in{T:1,Q:1}||(e.qx=null,e.qy=null),t[0]){case"M":e.X=t[1],e.Y=t[2];break;case"A":t=0===parseFloat(t[1])||0===parseFloat(t[2])?["L",t[6],t[7]]:["C"].concat(function t(e,n,i,r,o,s,a,h,l,u){var c,d=120*U/180,f=U/180*(+o||0),p=[];if(u)P=u[0],S=u[1],x=u[2],A=u[3];else{e=(c=Z(e,n,-f)).x,n=c.y;var g=(e-(h=(c=Z(h,l,-f)).x))/2,v=(n-(l=c.y))/2,m=g*g/(i*i)+v*v/(r*r);1<m&&(i*=m=X(m),r*=m);var y=i*i,w=r*r,b=(s==a?-1:1)*X(W((y*w-y*v*v-w*g*g)/(y*v*v+w*g*g))),x=b*i*v/r+(e+h)/2,A=b*-r*g/i+(n+l)/2,P=Y(((n-A)/r).toFixed(9)),S=Y(((l-A)/r).toFixed(9));(P=e<x?U-P:P)<0&&(P=2*U+P),(S=h<x?U-S:S)<0&&(S=2*U+S),a&&S<P&&(P-=2*U),!a&&P<S&&(S-=2*U)}var k=S-P;if(W(k)>d){var E=S,C=h,T=l;p=t(h=x+i*H(S=P+d*(a&&P<S?1:-1)),l=A+r*q(S),i,r,o,0,a,C,T,[S,E,x,A])}k=S-P;var L=H(P),M=q(P),N=H(S),V=q(S),F=$(k/4),_=4/3*(i*F),B=4/3*(r*F),R=[e,n],O=[e+_*M,n-B*L],D=[h+_*V,l-B*N],z=[h,l];if(O[0]=2*R[0]-O[0],O[1]=2*R[1]-O[1],u)return[O,D,z].concat(p);for(var I=[],j=(p=[O,D,z].concat(p).join().split(",")).length,G=0;G<j;G++)I[G]=G%2?Z(p[G-1],p[G],f).y:Z(p[G],p[G+1],f).x;return I}.apply(0,[e.x,e.y].concat(t.slice(1))));break;case"S":r="C"===n||"S"===n?(i=2*e.x-e.bx,2*e.y-e.by):(i=e.x,e.y),t=["C",i,r].concat(t.slice(1));break;case"T":e.qy="Q"===n||"T"===n?(e.qx=2*e.x-e.qx,2*e.y-e.qy):(e.qx=e.x,e.y),t=["C"].concat(d(e.x,e.y,e.qx,e.qy,t[1],t[2]));break;case"Q":e.qx=t[1],e.qy=t[2],t=["C"].concat(d(e.x,e.y,t[1],t[2],t[3],t[4]));break;case"H":t=["L"].concat(t[1],e.y);break;case"V":t=["L"].concat(e.x,t[1])}return t}function r(t,e){if(7<t[e].length){t[e].shift();for(var n=t[e];n.length;)o[e]="A",t.splice(e++,0,["C"].concat(n.splice(0,6)));t.splice(e,1),h=i.length}}for(var o=[],s="",a="",h=i.length,l=0;l<h;l++){i[l]&&(s=i[l][0]),"C"!==s&&(o[l]=s,0<l&&(a=o[l-1])),i[l]=n(i[l],e,a),"A"!==o[l]&&"C"===s&&(o[l]="C"),r(i,l);var u=i[l],c=u.length;e.x=u[c-2],e.y=u[c-1],e.bx=parseFloat(u[c-4])||e.x,e.by=parseFloat(u[c-3])||e.y}return i[0][0]&&"M"===i[0][0]||i.unshift(["M",0,0]),i}return function(t){return n(t).join(",").split(",").join(" ")}}(),N.namespace=M,N.g=J,N}(),Q={useCSSSelectors:!0,classNamePrefix:"joint-",defaultTheme:"default"},tt=function(t){return t?t.toString().split(" ").map(function(t){return t.substr(0,Q.classNamePrefix.length)!==Q.classNamePrefix&&(t=Q.classNamePrefix+t),t}).join(" "):t},et=function(t){return t?t.toString().split(" ").map(function(t){return t.substr(0,Q.classNamePrefix.length)===Q.classNamePrefix&&(t=t.substr(Q.classNamePrefix.length)),t}).join(" "):t},nt=function(t,e){for(var n={},i={},r=K.namespace.svg,o=e||r,s=document.createDocumentFragment(),a=[t,s,o];0<a.length;){o=a.pop();for(var h=a.pop(),l=a.pop(),u=0,c=l.length;u<c;u++){var d=l[u];if(!d.hasOwnProperty("tagName"))throw new Error("json-dom-parser: missing tagName");var f=d.tagName;d.hasOwnProperty("namespaceURI")&&(o=d.namespaceURI);var p=document.createElementNS(o,f),g=o===r,v=g?K:C,m=d.attributes;m&&v(p).attr(m);var y=d.style;if(y&&C(p).css(y),d.hasOwnProperty("className")){var w=d.className;g?p.className.baseVal=w:p.className=w}if(d.hasOwnProperty("textContent")&&(p.textContent=d.textContent),d.hasOwnProperty("selector")){var b=d.selector;if(n[b])throw new Error("json-dom-parser: selector must be unique");v(n[b]=p).attr("joint-selector",b)}if(d.hasOwnProperty("groupSelector")){var x=d.groupSelector;Array.isArray(x)||(x=[x]);for(var A=0,P=x.length;A<P;A++){var S=x[A],k=i[S];k||(k=i[S]=[]),k.push(p)}}h.appendChild(p);var E=d.children;Array.isArray(E)&&a.push(E,p,o)}}return{fragment:s,selectors:n,groupSelectors:i}},it=function(t){var e=0;if(0===t.length)return e;for(var n=0;n<t.length;n++){e=(e<<5)-e+t.charCodeAt(n),e&=e}return e},rt=function(t,e,n){for(var i,r=Array.isArray(e)?e:e.split(n||"/"),o=0,s=r.length;o<s;){if(i=r[o++],!(Object(t)===t&&i in t))return;t=t[i]}return t},ot=function(t,e,n,i){for(var r=Array.isArray(e)?e:e.split(i||"/"),o=t,s=0,a=r.length;s<a-1;s++)o=o[r[s]]||(o[r[s]]={});return o[r[a-1]]=n,t},st=function(t,e,n){n||(n="/");var i=Array.isArray(e)?e.slice():e.split(n),r=i.pop();if(0<i.length){var o=rt(t,i,n);o&&delete o[r]}else delete t[r];return t},at=function(t,e,n){e=e||"/";var i={};for(var r in t)if(t.hasOwnProperty(r)){var o="object"==typeof t[r];if(o&&n&&n(t[r])&&(o=!1),o){var s=at(t[r],e,n);for(var a in s)s.hasOwnProperty(a)&&(i[r+e+a]=s[a])}else i[r]=t[r]}return i},ht=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})},lt=function(t){return lt.id=lt.id||1,t.id=void 0===t.id?"j_"+lt.id++:t.id,t.id},ut=function(t){return t.replace(/[A-Z]/g,"-$&").toLowerCase()},ct=function(t){var e=t,n=t.originalEvent&&t.originalEvent.changedTouches&&t.originalEvent.changedTouches[0];if(n){for(var i in t)void 0===n[i]&&(n[i]=t[i]);e=n}var r=e.target;if(r){var o=r.correspondingUseElement;o&&(e.target=o)}return e},dt=function(){var r;if("undefined"!=typeof window&&(r=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame),!r){var o=0;r=function(t){var e=(new Date).getTime(),n=Math.max(0,16-(e-o)),i=setTimeout(function(){t(e+n)},n);return o=e+n,i}}return function(t,e){for(var n=[],i=arguments.length-2;0<i--;)n[i]=arguments[i+2];return r(void 0!==e?t.bind.apply(t,[e].concat(n)):t)}}(),ft=((Z="undefined"!=typeof window)&&(W=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.msCancelAnimationFrame||window.msCancelRequestAnimationFrame||window.oCancelAnimationFrame||window.oCancelRequestAnimationFrame||window.mozCancelAnimationFrame||window.mozCancelRequestAnimationFrame),W=W||clearTimeout,Z?W.bind(window):W),pt=function(t){return ue(t)&&"%"===t.slice(-1)},gt=function(t,e){var n=parseFloat(t);if(Number.isNaN(n))return null;var i,r={};if(r.value=n,null==e)i="[A-Za-z]*";else if(Array.isArray(e)){if(0===e.length)return null;i=e.join("|")}else ue(e)&&(i=e);var o,s=(o=new RegExp("(?:\\d+(?:\\.\\d+)*)("+i+")$").exec(t))?o[1]:null;return null===s?null:(r.unit=s,r)},vt=function(t,e,n,i){i=i||{},n=n||{};var r=e.width,o=e.height,s=i.svgDocument||K("svg").node,a=K("tspan").node,h=K("text").attr(n).append(a).node,l=document.createTextNode("");h.style.opacity=0,h.style.display="block",a.style.display="block",a.appendChild(l),s.appendChild(h),i.svgDocument||document.body.appendChild(s);for(var u,c,d,f=i.separator||" ",p=i.eol||"\n",g=i.hyphen?new RegExp(i.hyphen):/[^\w\d]/,v=t.split(f),m=[],y=[],w=0,b=0,x=v.length;w<x;w++){var A=v[w];if(A)if(p&&0<=A.indexOf(p))if(1<A.length){for(var P=A.split(p),S=0,k=P.length-1;S<k;S++)P.splice(2*S+1,0,p);Array.prototype.splice.apply(v,[w,1].concat(P)),w--,x+=P.length-1}else b++;else{if(l.data=y[b]?y[b]+" "+A:A,a.getComputedTextLength()<=r)y[b]=l.data,(u||c)&&(m[b++]=!0,c=u=0);else{if(!y[b]||u){var E=!!u;if(u=A.length-1,E||!u){if(!u){if(!y[b]){y=[];break}v.splice(w,2,A+v[w+1]),x--,m[b++]=!0,w--;continue}v[w]=A.substring(0,u),v[w+1]=A.substring(u)+v[w+1]}else{if(c)v.splice(w,2,v[w]+v[w+1]),c=0;else{var C=A.search(g);-1<C&&C!==A.length-1&&0!==C&&(c=C+1,u=0),v.splice(w,1,A.substring(0,c||u),A.substring(c||u)),x++}b&&!m[b-1]&&b--}w--;continue}b++,w--}if(void 0!==o){var T;if(void 0===d)d=(T="auto"===n.lineHeight?{value:1.5,unit:"em"}:gt(n.lineHeight,["em"])||{value:1,unit:"em"}).value,"em"===T.unit&&(d*=h.getBBox().height);if(d*y.length>o){var L=Math.floor(o/d)-1;y.splice(L+1);var M=i.ellipsis;if(!M||L<0)break;"string"!=typeof M&&(M="…");var N,V,F=y[L],_=F.length;do{if(V=F[_],N=F.substring(0,_),V?V.match(f)&&(N+=V):N+="string"==typeof f?f:" ",N+=M,l.data=N,a.getComputedTextLength()<=r){y[L]=N;break}_--}while(0<=_);break}}}}return i.svgDocument?s.removeChild(h):document.body.removeChild(s),y.join(p)},mt=function(t){var e=C(C.parseHTML("<div>"+t+"</div>",null,!1));return e.find("*").each(function(){var n=this;C.each(n.attributes,function(){var t=this.name,e=this.value;0!==t.indexOf("on")&&0!==e.indexOf("javascript:")||C(n).removeAttr(t)})}),e.html()},yt=function(t,e){if(window.navigator.msSaveBlob)window.navigator.msSaveBlob(t,e);else{var n=window.URL.createObjectURL(t),i=document.createElement("a");i.href=n,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),window.URL.revokeObjectURL(n)}},wt=function(t){t=t.replace(/\s/g,"");var e,n=(t=decodeURIComponent(t)).indexOf(","),i=t.slice(0,n),r=i.split(":")[1].split(";")[0],o=t.slice(n+1);e=0<=i.indexOf("base64")?atob(o):unescape(encodeURIComponent(o));for(var s=new Uint8Array(e.length),a=0;a<e.length;a++)s[a]=e.charCodeAt(a);return new Blob([s],{type:r})},bt=function(t,e){var n=C(t),i=n.map(function(){var t=this.parentNode,e=t.insertBefore(document.createTextNode(""),this.nextSibling);return function(){if(t===this)throw new Error("You can't sort elements if any one is a descendant of another.");t.insertBefore(this,e),t.removeChild(e)}});return Array.prototype.sort.call(n,e).each(function(t){i[t].call(this)})},xt=function(t){if(Object(t)===t)return e=n=i=r=0,isFinite(t.vertical)&&(e=i=+t.vertical),isFinite(t.horizontal)&&(n=r=+t.horizontal),isFinite(t.top)&&(e=+t.top),isFinite(t.right)&&(n=+t.right),isFinite(t.bottom)&&(i=+t.bottom),isFinite(t.left)&&(r=+t.left),{top:e,right:n,bottom:i,left:r};var e,n,i,r,o=0;return isFinite(t)&&(o=+t),{top:o,right:o,bottom:o,left:o}},At={linear:function(t){return t},quad:function(t){return t*t},cubic:function(t){return t*t*t},inout:function(t){if(t<=0)return 0;if(1<=t)return 1;var e=t*t,n=e*t;return 4*(t<.5?n:3*(t-e)+n-.75)},exponential:function(t){return Math.pow(2,10*(t-1))},bounce:function(t){for(var e=0,n=1;;e+=n,n/=2)if((7-4*e)/11<=t){var i=(11-6*e-11*t)/4;return-i*i+n*n}},reverse:function(e){return function(t){return 1-e(1-t)}},reflect:function(e){return function(t){return.5*(t<.5?e(2*t):2-e(2-2*t))}},clamp:function(n,i,r){return i=i||0,r=r||1,function(t){var e=n(t);return e<i?i:r<e?r:e}},back:function(e){return e||(e=1.70158),function(t){return t*t*((e+1)*t-e)}},elastic:function(e){return e||(e=1.5),function(t){return Math.pow(2,10*(t-1))*Math.cos(20*Math.PI*e/3*t)}}},Pt={number:function(e,t){var n=t-e;return function(t){return e+n*t}},object:function(r,o){var s=Object.keys(r);return function(t){var e,n,i={};for(e=s.length-1;-1!=e;e--)i[n=s[e]]=r[n]+(o[n]-r[n])*t;return i}},hexColor:function(t,e){var n=parseInt(t.slice(1),16),i=parseInt(e.slice(1),16),r=255&n,o=(255&i)-r,s=65280&n,a=(65280&i)-s,h=16711680&n,l=(16711680&i)-h;return function(t){return"#"+(1<<24|r+o*t&255|s+a*t&65280|h+l*t&16711680).toString(16).slice(1)}},unit:function(e,t){var n=/(-?[0-9]*.[0-9]*)(px|em|cm|mm|in|pt|pc|%)/,i=n.exec(e),r=n.exec(t),o=r[1].indexOf("."),s=0<o?r[1].length-o-1:0;e=+i[1];var a=+r[1]-e,h=i[2];return function(t){return(e+a*t).toFixed(s)+h}}},St={outline:function(t){var e=Number.isFinite(t.margin)?t.margin:2,n=Number.isFinite(t.width)?t.width:1;return Et('<filter><feFlood flood-color="${color}" flood-opacity="${opacity}" result="colored"/><feMorphology in="SourceAlpha" result="morphedOuter" operator="dilate" radius="${outerRadius}" /><feMorphology in="SourceAlpha" result="morphedInner" operator="dilate" radius="${innerRadius}" /><feComposite result="morphedOuterColored" in="colored" in2="morphedOuter" operator="in"/><feComposite operator="xor" in="morphedOuterColored" in2="morphedInner" result="outline"/><feMerge><feMergeNode in="outline"/><feMergeNode in="SourceGraphic"/></feMerge></filter>')({color:t.color||"blue",opacity:Number.isFinite(t.opacity)?t.opacity:1,outerRadius:e+n,innerRadius:e})},highlight:function(t){return Et('<filter><feFlood flood-color="${color}" flood-opacity="${opacity}" result="colored"/><feMorphology result="morphed" in="SourceGraphic" operator="dilate" radius="${width}"/><feComposite result="composed" in="colored" in2="morphed" operator="in"/><feGaussianBlur result="blured" in="composed" stdDeviation="${blur}"/><feBlend in="SourceGraphic" in2="blured" mode="normal"/></filter>')({color:t.color||"red",width:Number.isFinite(t.width)?t.width:1,blur:Number.isFinite(t.blur)?t.blur:0,opacity:Number.isFinite(t.opacity)?t.opacity:1})},blur:function(t){var e=Number.isFinite(t.x)?t.x:2;return Et('<filter><feGaussianBlur stdDeviation="${stdDeviation}"/></filter>')({stdDeviation:Number.isFinite(t.y)?[e,t.y]:e})},dropShadow:function(t){var e="SVGFEDropShadowElement"in window?'<filter><feDropShadow stdDeviation="${blur}" dx="${dx}" dy="${dy}" flood-color="${color}" flood-opacity="${opacity}"/></filter>':'<filter><feGaussianBlur in="SourceAlpha" stdDeviation="${blur}"/><feOffset dx="${dx}" dy="${dy}" result="offsetblur"/><feFlood flood-color="${color}"/><feComposite in2="offsetblur" operator="in"/><feComponentTransfer><feFuncA type="linear" slope="${opacity}"/></feComponentTransfer><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter>';return Et(e)({dx:t.dx||0,dy:t.dy||0,opacity:Number.isFinite(t.opacity)?t.opacity:1,color:t.color||"black",blur:Number.isFinite(t.blur)?t.blur:4})},grayscale:function(t){var e=Number.isFinite(t.amount)?t.amount:1;return Et('<filter><feColorMatrix type="matrix" values="${a} ${b} ${c} 0 0 ${d} ${e} ${f} 0 0 ${g} ${b} ${h} 0 0 0 0 0 1 0"/></filter>')({a:.2126+.7874*(1-e),b:.7152-.7152*(1-e),c:.0722-.0722*(1-e),d:.2126-.2126*(1-e),e:.7152+.2848*(1-e),f:.0722-.0722*(1-e),g:.2126-.2126*(1-e),h:.0722+.9278*(1-e)})},sepia:function(t){var e=Number.isFinite(t.amount)?t.amount:1;return Et('<filter><feColorMatrix type="matrix" values="${a} ${b} ${c} 0 0 ${d} ${e} ${f} 0 0 ${g} ${h} ${i} 0 0 0 0 0 1 0"/></filter>')({a:.393+.607*(1-e),b:.769-.769*(1-e),c:.189-.189*(1-e),d:.349-.349*(1-e),e:.686+.314*(1-e),f:.168-.168*(1-e),g:.272-.272*(1-e),h:.534-.534*(1-e),i:.131+.869*(1-e)})},saturate:function(t){var e=Number.isFinite(t.amount)?t.amount:1;return Et('<filter><feColorMatrix type="saturate" values="${amount}"/></filter>')({amount:1-e})},hueRotate:function(t){return Et('<filter><feColorMatrix type="hueRotate" values="${angle}"/></filter>')({angle:t.angle||0})},invert:function(t){var e=Number.isFinite(t.amount)?t.amount:1;return Et('<filter><feComponentTransfer><feFuncR type="table" tableValues="${amount} ${amount2}"/><feFuncG type="table" tableValues="${amount} ${amount2}"/><feFuncB type="table" tableValues="${amount} ${amount2}"/></feComponentTransfer></filter>')({amount:e,amount2:1-e})},brightness:function(t){return Et('<filter><feComponentTransfer><feFuncR type="linear" slope="${amount}"/><feFuncG type="linear" slope="${amount}"/><feFuncB type="linear" slope="${amount}"/></feComponentTransfer></filter>')({amount:Number.isFinite(t.amount)?t.amount:1})},contrast:function(t){var e=Number.isFinite(t.amount)?t.amount:1;return Et('<filter><feComponentTransfer><feFuncR type="linear" slope="${amount}" intercept="${amount2}"/><feFuncG type="linear" slope="${amount}" intercept="${amount2}"/><feFuncB type="linear" slope="${amount}" intercept="${amount2}"/></feComponentTransfer></filter>')({amount:e,amount2:.5-e/2})}},kt={number:function(t,e,o){o=o||{currency:["$",""],decimal:".",thousands:",",grouping:[3]};var n=/(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i.exec(t),i=n[1]||" ",r=n[2]||">",s=n[3]||"",a=n[4]||"",h=n[5],l=+n[6],u=n[7],c=n[8],d=n[9],f=1,p="",g="",v=!1;switch(c&&(c=+c.substring(1)),(h||"0"===i&&"="===r)&&(h=i="0",r="=",u&&(l-=Math.floor((l-1)/4))),d){case"n":u=!0,d="g";break;case"%":f=100,g="%",d="f";break;case"p":f=100,g="%",d="r";break;case"b":case"o":case"x":case"X":"#"===a&&(p="0"+d.toLowerCase());break;case"c":case"d":v=!0,c=0;break;case"s":f=-1,d="r"}"$"===a&&(p=o.currency[0],g=o.currency[1]),"r"!=d||c||(d="g"),null!=c&&("g"==d?c=Math.max(1,Math.min(21,c)):"e"!=d&&"f"!=d||(c=Math.max(0,Math.min(20,c))));var m=h&&u;if(v&&e%1)return"";var y=e<0||0===e&&1/e<0?(e=-e,"-"):s,w=g;if(f<0){var b=this.prefix(e,c);e=b.scale(e),w=b.symbol+g}else e*=f;var x=(e=this.convert(d,e,c)).lastIndexOf("."),A=x<0?e:e.substring(0,x),P=x<0?"":o.decimal+e.substring(x+1);function S(t){for(var e=t.length,n=[],i=0,r=o.grouping[0];0<e&&0<r;)n.push(t.substring(e-=r,e+r)),r=o.grouping[i=(i+1)%o.grouping.length];return n.reverse().join(o.thousands)}!h&&u&&o.grouping&&(A=S(A));var k=p.length+A.length+P.length+(m?0:y.length),E=k<l?new Array(k=l-k+1).join(i):"";return m&&(A=S(E+A)),y+=p,e=A+P,("<"===r?y+e+E:">"===r?E+y+e:"^"===r?E.substring(0,k>>=1)+y+e+E.substring(k):y+(m?e:E+e))+w},string:function(t,e){for(var n,i="{",r=!1,o=[];-1!==(n=t.indexOf(i));){var s,a,h;if(s=t.slice(0,n),r){h=(a=s.split(":")).shift().split("."),s=e;for(var l=0;l<h.length;l++)s=s[h[l]];a.length&&(s=this.number(a,s))}o.push(s),t=t.slice(n+1),i=(r=!r)?"}":"{"}return o.push(t),o.join("")},convert:function(t,e,n){switch(t){case"b":return e.toString(2);case"c":return String.fromCharCode(e);case"o":return e.toString(8);case"x":return e.toString(16);case"X":return e.toString(16).toUpperCase();case"g":return e.toPrecision(n);case"e":return e.toExponential(n);case"f":return e.toFixed(n);case"r":return(e=this.round(e,this.precision(e,n))).toFixed(Math.max(0,Math.min(20,this.precision(e*(1+1e-15),n))));default:return e+""}},round:function(t,e){return e?Math.round(t*(e=Math.pow(10,e)))/e:Math.round(t)},precision:function(t,e){return e-(t?Math.ceil(Math.log(t)/Math.LN10):1)},prefix:function(t,e){var n=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"].map(function(t,e){var n=Math.pow(10,3*Math.abs(8-e));return{scale:8<e?function(t){return t/n}:function(t){return t*n},symbol:t}}),i=0;return t&&(t<0&&(t*=-1),e&&(t=this.round(t,this.precision(t,e))),i=1+Math.floor(1e-12+Math.log(t)/Math.LN10),i=Math.max(-24,Math.min(24,3*Math.floor((i<=0?i+1:i-1)/3)))),n[8+i/3]}},Et=function(t){var e=/<%= ([^ ]+) %>|\$\{ ?([^{} ]+) ?\}|\{\{([^{} ]+)\}\}/g;return function(i){return i=i||{},t.replace(e,function(t){for(var e=Array.from(arguments).slice(1,4).find(function(t){return!!t}).split("."),n=i[e.shift()];void 0!==n&&e.length;)n=n[e.shift()];return void 0!==n?n:""})}},Ct=n.assign,Tt=n.defaults,Lt=Ct,Mt=n.defaultsDeep,Nt=n.assign,Vt=n.defaults,Ft=n.defaultsDeep,_t=n.invokeMap||n.invoke,Bt=n.sortedIndexBy||n.sortedIndex,Rt=n.uniqBy||n.uniq,Ot=n.clone,Dt=n.cloneDeep,zt=n.isEmpty,It=n.isEqual,jt=n.isFunction,Gt=n.isPlainObject,Ut=n.toArray,qt=n.debounce,Ht=n.groupBy,$t=n.sortBy,Yt=n.flattenDeep,Xt=n.without,Wt=n.difference,Zt=n.intersection,Jt=n.union,Kt=n.has,Qt=n.result,te=n.omit,ee=n.pick,ne=n.bindAll,ie=n.forIn,re=n.camelCase,oe=n.uniqueId,se=function(){if(n.mergeWith){var t=Array.from(arguments),e=t[t.length-1],i=jt(e)?e:ce;return t.push(function(t,e){var n=i(t,e);return void 0!==n?n:Array.isArray(t)&&!Array.isArray(e)?e:void 0}),n.mergeWith.apply(this,t)}return n.merge.apply(this,arguments)},ae=function(t){var e=Object.prototype.toString;return!0===t||!1===t||!!t&&"object"==typeof t&&"[object Boolean]"===e.call(t)},he=function(t){return!!t&&("object"==typeof t||"function"==typeof t)},le=function(t){var e=Object.prototype.toString;return"number"==typeof t||!!t&&"object"==typeof t&&"[object Number]"===e.call(t)},ue=function(t){var e=Object.prototype.toString;return"string"==typeof t||!!t&&"object"==typeof t&&"[object String]"===e.call(t)},ce=function(){};function de(t){t=Rt(t);var s=Ut(t).reduce(function(t,e){return t[e.id]=e.clone(),t},{});return Ut(t).forEach(function(t){var e=s[t.id];if(e.isLink()){var n=e.source(),i=e.target();n.id&&s[n.id]&&e.prop("source/id",s[n.id].id),i.id&&s[i.id]&&e.prop("target/id",s[i.id].id)}var r=t.get("parent");r&&s[r]&&e.set("parent",s[r].id);var o=Ut(t.get("embeds")).reduce(function(t,e){return s[e]&&t.push(s[e].id),t},[]);zt(o)||e.set("embeds",o)}),s}function fe(o,s){return function(t,e){var n=pt(t);t=parseFloat(t),n&&(t/=100);var i={};if(isFinite(t)){var r=n||0<=t&&t<=1?t*e[s]:Math.max(t+e[s],0);i[o]=r}return i}}function pe(s,a,h){return function(t,e){var n,i=pt(t);if(t=parseFloat(t),i&&(t/=100),isFinite(t)){var r=e[h]();n=i||0<t&&t<1?r[s]+e[a]*t:r[s]+t}var o=z();return o[s]=n||0,o}}function ge(r,o,s){return function(t,e){var n;n="middle"===t?e[o]/2:t===s?e[o]:isFinite(t)?-1<t&&t<1?-e[o]*t:-t:pt(t)?e[o]*parseFloat(t)/100:0;var i=z();return i[r]=-(e[r]+n),i}}function ve(f,t){var p="joint-shape",g=t&&t.resetOffset;return function(t,e,n){var i=C(n),r=i.data(p);if(!r||r.value!==t){var o=f(t);r={value:t,shape:o,shapeBBox:o.bbox()},i.data(p,r)}var s=r.shape.clone(),a=r.shapeBBox.clone(),h=a.origin(),l=e.origin();a.x=l.x,a.y=l.y;var u=e.maxRectScaleToFit(a,l),c=0===a.width||0===e.width?1:u.sx,d=0===a.height||0===e.height?1:u.sy;return s.scale(c,d,h),g&&s.translate(-h.x,-h.y),s}}function me(t){var i=ve(function(t){return new D(K.normalizePathData(t))},t);return function(t,e,n){return{d:i(t,e,n).serialize()}}}function ye(t){var i=ve(L,t);return function(t,e,n){return{points:i(t,e,n).serialize()}}}function we(r,o){var s=new z(1,0);return function(t){var e,n,i=this[r](t);return i?(n=o.rotate?i.vector().vectorAngle(s):0,e=i.start):(e=this.path.start,n=0),0===n?{transform:"translate("+e.x+","+e.y+")"}:{transform:"translate("+e.x+","+e.y+") rotate("+n+")"}}}function be(t,e,n){return void 0!==n.text}function xe(){return this.model.isLink()}function Ae(t){var e={},n=t.stroke;"string"==typeof n&&(e.stroke=n,e.fill=n);var i=t.strokeOpacity;return void 0===i&&(i=t["stroke-opacity"]),void 0===i&&(i=t.opacity),void 0!==i&&(e["stroke-opacity"]=i,e["fill-opacity"]=i),e}var Pe,Se,ke={xlinkHref:{set:"xlink:href"},xlinkShow:{set:"xlink:show"},xlinkRole:{set:"xlink:role"},xlinkType:{set:"xlink:type"},xlinkArcrole:{set:"xlink:arcrole"},xlinkTitle:{set:"xlink:title"},xlinkActuate:{set:"xlink:actuate"},xmlSpace:{set:"xml:space"},xmlBase:{set:"xml:base"},xmlLang:{set:"xml:lang"},preserveAspectRatio:{set:"preserveAspectRatio"},requiredExtension:{set:"requiredExtension"},requiredFeatures:{set:"requiredFeatures"},systemLanguage:{set:"systemLanguage"},externalResourcesRequired:{set:"externalResourceRequired"},filter:{qualify:Gt,set:function(t){return"url(#"+this.paper.defineFilter(t)+")"}},fill:{qualify:Gt,set:function(t){return"url(#"+this.paper.defineGradient(t)+")"}},stroke:{qualify:Gt,set:function(t){return"url(#"+this.paper.defineGradient(t)+")"}},sourceMarker:{qualify:Gt,set:function(t,e,n,i){return t=Nt(Ae(i),t),{"marker-start":"url(#"+this.paper.defineMarker(t)+")"}}},targetMarker:{qualify:Gt,set:function(t,e,n,i){return t=Nt(Ae(i),{transform:"rotate(180)"},t),{"marker-end":"url(#"+this.paper.defineMarker(t)+")"}}},vertexMarker:{qualify:Gt,set:function(t,e,n,i){return t=Nt(Ae(i),t),{"marker-mid":"url(#"+this.paper.defineMarker(t)+")"}}},text:{qualify:function(t,e,n){return!n.textWrap||!Gt(n.textWrap)},set:function(t,e,n,i){var r=C(n),o="joint-text",s=r.data(o),a=ee(i,"lineHeight","annotations","textPath","x","textVerticalAnchor","eol","displayEmpty"),h=a.fontSize=i["font-size"]||i.fontSize,l=JSON.stringify([t,a]);if(void 0===s||s!==l){h&&n.setAttribute("font-size",h);var u=a.textPath;if(he(u)){var c=u.selector;if("string"==typeof c){var d=this.findBySelector(c)[0];d instanceof SVGPathElement&&(a.textPath=Nt({"xlink:href":"#"+d.id},u))}}K(n).text(""+t,a),r.data(o,l)}}},textWrap:{qualify:Gt,set:function(t,e,n,i){var r=t.width||0;pt(r)?e.width*=parseFloat(r)/100:r<=0?e.width+=r:e.width=r;var o,s=t.height||0;pt(s)?e.height*=parseFloat(s)/100:s<=0?e.height+=s:e.height=s;var a=t.text;void 0===a&&(a=i.text),o=void 0!==a?vt(""+a,e,{"font-weight":i["font-weight"]||i.fontWeight,"font-size":i["font-size"]||i.fontSize,"font-family":i["font-family"]||i.fontFamily,lineHeight:i.lineHeight},{svgDocument:this.paper.svg,ellipsis:t.ellipsis,hyphen:t.hyphen}):"",ke.text.set.call(this,o,e,n,i)}},title:{qualify:function(t,e){return e instanceof SVGElement},set:function(t,e,n){var i=C(n),r="joint-title",o=i.data(r);if(void 0===o||o!==t){i.data(r,t);var s=n.firstChild;if(s&&"TITLE"===s.tagName.toUpperCase())s.textContent=t;else{var a=document.createElementNS(n.namespaceURI,"title");a.textContent=t,n.insertBefore(a,s)}}}},lineHeight:{qualify:be},textVerticalAnchor:{qualify:be},textPath:{qualify:be},annotations:{qualify:be},eol:{qualify:be},displayEmpty:{qualify:be},port:{set:function(t){return null===t||void 0===t.id?t:t.id}},style:{qualify:Gt,set:function(t,e,n){C(n).css(t)}},html:{set:function(t,e,n){C(n).html(t+"")}},ref:{},refX:{position:pe("x","width","origin")},refY:{position:pe("y","height","origin")},refDx:{position:pe("x","width","corner")},refDy:{position:pe("y","height","corner")},refWidth:{set:fe("width","width")},refHeight:{set:fe("height","height")},refRx:{set:fe("rx","width")},refRy:{set:fe("ry","height")},refRInscribed:{set:(Pe=fe("r","width"),Se=fe("r","height"),function(t,e){return(e.height>e.width?Pe:Se)(t,e)})},refRCircumscribed:{set:function(t,e){var n=pt(t);t=parseFloat(t),n&&(t/=100);var i,r=Math.sqrt(e.height*e.height+e.width*e.width);return isFinite(t)&&(i=n||0<=t&&t<=1?t*r:Math.max(t+r,0)),{r:i}}},refCx:{set:fe("cx","width")},refCy:{set:fe("cy","height")},xAlignment:{offset:ge("x","width","right")},yAlignment:{offset:ge("y","height","bottom")},resetOffset:{offset:function(t,e){return t?{x:-e.x,y:-e.y}:{x:0,y:0}}},refDResetOffset:{set:me({resetOffset:!0})},refDKeepOffset:{set:me({resetOffset:!1})},refPointsResetOffset:{set:ye({resetOffset:!0})},refPointsKeepOffset:{set:ye({resetOffset:!1})},connection:{qualify:xe,set:function(t){var e,n=t.stubs;if(void 0===n&&(n=0),isFinite(n)&&0!==n){var i;i=n<0?(this.getConnectionLength()+n)/2:n;var r=this.getConnection(),o=r.divideAtLength(i),s=r.divideAtLength(-i);o&&s&&(e=o[0].serialize()+" "+s[1].serialize())}return{d:e||this.getSerializedConnection()}}},atConnectionLengthKeepGradient:{qualify:xe,set:we("getTangentAtLength",{rotate:!0})},atConnectionLengthIgnoreGradient:{qualify:xe,set:we("getTangentAtLength",{rotate:!1})},atConnectionRatioKeepGradient:{qualify:xe,set:we("getTangentAtRatio",{rotate:!0})},atConnectionRatioIgnoreGradient:{qualify:xe,set:we("getTangentAtRatio",{rotate:!1})}};ke.refR=ke.refRInscribed,ke.refD=ke.refDResetOffset,ke.refPoints=ke.refPointsResetOffset,ke.atConnectionLength=ke.atConnectionLengthKeepGradient,ke.atConnectionRatio=ke.atConnectionRatioKeepGradient,ke.refX2=ke.refX,ke.refY2=ke.refY,ke.refWidth2=ke.refWidth,ke.refHeight2=ke.refHeight,ke["ref-x"]=ke.refX,ke["ref-y"]=ke.refY,ke["ref-dy"]=ke.refDy,ke["ref-dx"]=ke.refDx,ke["ref-width"]=ke.refWidth,ke["ref-height"]=ke.refHeight,ke["x-alignment"]=ke.xAlignment,ke["y-alignment"]=ke.yAlignment;var Ee=ke,Ce=s.Model.extend({constructor:function(t,e){var n,i=t||{};this.cid=oe("c"),this.attributes={},e&&e.collection&&(this.collection=e.collection),e&&e.parse&&(i=this.parse(i,e)||{}),(n=Qt(this,"defaults"))&&(i=se({},n,i)),this.set(i,e),this.changed={},this.initialize.apply(this,arguments)},translate:function(t,e,n){throw new Error("Must define a translate() method.")},toJSON:function(){var e=this.constructor.prototype.defaults.attrs||{},t=this.attributes.attrs,o={};ie(t,function(t,i){var r=e[i];ie(t,function(t,n){he(t)&&!Array.isArray(t)?ie(t,function(t,e){r&&r[n]&&It(r[n][e],t)||(o[i]=o[i]||{},(o[i][n]||(o[i][n]={}))[e]=t)}):r&&It(r[n],t)||(o[i]=o[i]||{},o[i][n]=t)})});var n=Dt(te(this.attributes,"attrs"));return n.attrs=o,n},initialize:function(t){t&&t.id||this.set("id",this.generateId(),{silent:!0}),this._transitionIds={},this.processPorts(),this.on("change:attrs",this.processPorts,this)},generateId:function(){return ht()},processPorts:function(){var t=this.ports,n={};ie(this.get("attrs"),function(t,e){t&&t.port&&(void 0!==t.port.id?n[t.port.id]=t.port:n[t.port]={id:t.port})});var i={};(ie(t,function(t,e){n[e]||(i[e]=!0)}),this.graph&&!zt(i))&&(this.graph.getConnectedLinks(this,{inbound:!0}).forEach(function(t){i[t.get("target").port]&&t.remove()}),this.graph.getConnectedLinks(this,{outbound:!0}).forEach(function(t){i[t.get("source").port]&&t.remove()}));this.ports=n},remove:function(t){t=t||{};var e=this.graph;if(!e)return this.collection&&this.collection.remove(this,t),this;e.startBatch("remove");var n=this.getParentCell();n&&n.unembed(this);for(var i=this.getEmbeddedCells(),r=0,o=i.length;r<o;r++){var s=i[r];s&&s.remove(t)}return this.trigger("remove",this,e.attributes.cells,t),e.stopBatch("remove"),this},toFront:function(n){var t=this.graph;if(t){n=n||{};var e,i=t.maxZIndex();n.deep?(e=this.getEmbeddedCells({deep:!0,breadthFirst:!0})).unshift(this):e=[this],i=i-e.length+1;var r=t.get("cells"),o=r.indexOf(this)!==r.length-e.length;o||(o=e.some(function(t,e){return t.get("z")!==i+e})),o&&(this.startBatch("to-front"),i+=e.length,e.forEach(function(t,e){t.set("z",i+e,n)}),this.stopBatch("to-front"))}return this},toBack:function(n){var t=this.graph;if(t){n=n||{};var e,i=t.minZIndex();n.deep?(e=this.getEmbeddedCells({deep:!0,breadthFirst:!0})).unshift(this):e=[this];var r=0!==t.get("cells").indexOf(this);r||(r=e.some(function(t,e){return t.get("z")!==i+e})),r&&(this.startBatch("to-back"),i-=e.length,e.forEach(function(t,e){t.set("z",i+e,n)}),this.stopBatch("to-back"))}return this},parent:function(t,e){return void 0===t?this.get("parent"):this.set("parent",t,e)},embed:function(t,e){if(this===t||this.isEmbeddedIn(t))throw new Error("Recursive embedding not allowed.");this.startBatch("embed");var n=Nt([],this.get("embeds"));return n[t.isLink()?"unshift":"push"](t.id),t.parent(this.id,e),this.set("embeds",Rt(n),e),this.stopBatch("embed"),this},unembed:function(t,e){return this.startBatch("unembed"),t.unset("parent",e),this.set("embeds",Xt(this.get("embeds"),t.id),e),this.stopBatch("unembed"),this},getParentCell:function(){var t=this.parent(),e=this.graph;return t&&e&&e.getCell(t)||null},getAncestors:function(){var t=[];if(!this.graph)return t;for(var e=this.getParentCell();e;)t.push(e),e=e.getParentCell();return t},getEmbeddedCells:function(e){if(e=e||{},this.graph){var n;if(e.deep)if(e.breadthFirst){n=[];for(var t=this.getEmbeddedCells();0<t.length;){var i=t.shift();n.push(i),t.push.apply(t,i.getEmbeddedCells())}}else(n=this.getEmbeddedCells()).forEach(function(t){n.push.apply(n,t.getEmbeddedCells(e))});else n=Ut(this.get("embeds")).map(this.graph.getCell,this.graph);return n}return[]},isEmbeddedIn:function(t,e){var n=ue(t)?t:t.id,i=this.parent();if(e=Vt({deep:!0},e),this.graph&&e.deep){for(;i;){if(i===n)return!0;i=this.graph.getCell(i).parent()}return!1}return i===n},isEmbedded:function(){return!!this.parent()},clone:function(t){if((t=t||{}).deep)return Ut(de([this].concat(this.getEmbeddedCells({deep:!0}))));var e=s.Model.prototype.clone.apply(this,arguments);return e.set("id",this.generateId()),e.unset("embeds"),e.unset("parent"),e},prop:function(t,e,n){var i=ue(t);if(i||Array.isArray(t)){if(1<arguments.length){var r,o,s=(o=i?(r=t).split("/"):(r=t.join("/"),t.slice()))[0],a=o.length;if((n=n||{}).propertyPath=r,n.propertyValue=e,n.propertyPathArray=o,1===a)return this.set(s,e,n);for(var h={},l=h,u=s,c=1;c<a;c++){var d=o[c],f=Number.isFinite(i?Number(d):d);l=l[u]=f?[]:{},u=d}h=ot(h,o,e,"/");var p=se({},this.attributes);n.rewrite&&st(p,r,"/");var g=se(p,h);return this.set(s,g[s],n)}return rt(this.attributes,t,"/")}return this.set(se({},this.attributes,t),e)},removeProp:function(t,e){e=e||{};var n=Array.isArray(t)?t:t.split("/"),i=n[0];if("attrs"===i&&(e.dirty=!0),1===n.length)return this.unset(t,e);var r=n.slice(1),o=Dt(this.get(i));return st(o,r,"/"),this.set(i,o,e)},attr:function(t,e,n){var i=Array.from(arguments);return 0===i.length?this.get("attrs"):(Array.isArray(t)?i[0]=["attrs"].concat(t):ue(t)?i[0]="attrs/"+t:i[0]={attrs:t},this.prop.apply(this,i))},removeAttr:function(t,e){return Array.isArray(t)?this.removeProp(["attrs"].concat(t)):this.removeProp("attrs/"+t,e)},transition:function(r,e,o,n){n=n||"/",o=Nt({duration:100,delay:10,timingFunction:At.linear,valueFunction:Pt.number},o);var s,a=0,h=function(t){var e,n,i;(n=(t-=a=a||t)/o.duration)<1?this._transitionIds[r]=e=dt(h):(n=1,delete this._transitionIds[r]),i=s(o.timingFunction(n)),o.transitionId=e,this.prop(r,i,o),e||this.trigger("transition:end",this,r)}.bind(this),t=function(t){this.stopTransitions(r),s=o.valueFunction(rt(this.attributes,r,n),e),this._transitionIds[r]=dt(t),this.trigger("transition:start",this,r)}.bind(this);return setTimeout(t,o.delay,h)},getTransitions:function(){return Object.keys(this._transitionIds)},stopTransitions:function(t,e){e=e||"/";var n=t&&t.split(e);return Object.keys(this._transitionIds).filter(n&&function(t){return It(n,t.split(e).slice(0,n.length))}).forEach(function(t){ft(this._transitionIds[t]),delete this._transitionIds[t],this.trigger("transition:end",this,t)},this),this},addTo:function(t,e){return t.addCell(this,e),this},findView:function(t){return t.findViewByModel(this)},isElement:function(){return!1},isLink:function(){return!1},startBatch:function(t,e){return this.graph&&this.graph.startBatch(t,Nt({},e,{cell:this})),this},stopBatch:function(t,e){return this.graph&&this.graph.stopBatch(t,Nt({},e,{cell:this})),this},getChangeFlag:function(t){var e=0;if(!t)return e;for(var n in t)t.hasOwnProperty(n)&&this.hasChanged(n)&&(e|=t[n]);return e},angle:function(){return 0},position:function(){return new z(0,0)},getPointFromConnectedLink:function(){return new z},getBBox:function(){return new X(0,0,0,0)}},{getAttributeDefinition:function(t){var e=this.attributes,n=Ee;return e&&e[t]||n[t]},define:function(t,e,n,i){n=Nt({defaults:Ft({type:t},e,this.prototype.defaults)},n);var r=this.extend(n,i);return"undefined"!=typeof joint&&Kt(joint,"shapes")&&ot(joint.shapes,t,r,"."),r}}),Te=function(e,t,n){if(ue(n)){if(!Le[n])throw new Error('Unknown wrapper: "'+n+'"');n=Le[n]}if(!jt(n))throw new Error("Wrapper must be a function.");Ut(t).forEach(function(t){e[t]=n(e[t])})},Le={cells:function(r){return function(){var t=Array.from(arguments),e=t.length,n=0<e&&t[0]||[],i=1<e&&t[e-1]||{};return Array.isArray(n)||(i instanceof Ce?n=t:n instanceof Ce&&(1<t.length&&t.pop(),n=t)),i instanceof Ce&&(i={}),r.call(this,n,i)}}},Me={wrapWith:Te,wrappers:Le,addClassNamePrefix:tt,removeClassNamePrefix:et,parseDOMJSON:nt,hashCode:it,getByPath:rt,setByPath:ot,unsetByPath:st,flattenObject:at,uuid:ht,guid:lt,toKebabCase:ut,normalizeEvent:ct,nextFrame:dt,cancelFrame:ft,shapePerimeterConnectionPoint:function(t,e,n,i){var r,o;if(!n){var s=e.$(".scalable")[0],a=e.$(".rotatable")[0];s&&s.firstChild?n=s.firstChild:a&&a.firstChild&&(n=a.firstChild)}return n?(o=K(n).findIntersection(i,t.paper.cells))||(r=K(n).getBBox({target:t.paper.cells})):o=(r=e.model.getBBox()).intersectionWithLineFromCenterToPoint(i),o||r.center()},isPercentage:pt,parseCssNumeric:gt,breakText:vt,sanitizeHTML:mt,downloadBlob:yt,downloadDataUri:function(t,e){var n=wt(t);yt(n,e)},dataUriToBlob:wt,imageToDataUri:function(r,t){if(!r||"data:"===r.substr(0,"data:".length))return setTimeout(function(){t(null,r)},0);var e=new XMLHttpRequest;e.open("GET",r,!0),e.addEventListener("error",function(){t(new Error("Failed to load image "+r))}),e.responseType=window.FileReader?"blob":"arraybuffer",e.addEventListener("load",function(){window.FileReader?function(t,n){if(200===t.status){var e=new FileReader;e.onload=function(t){var e=t.target.result;n(null,e)},e.onerror=function(){n(new Error("Failed to load image "+r))},e.readAsDataURL(t.response)}else n(new Error("Failed to load image "+r))}(e,t):function(t,e){if(200===t.status){var n=new Uint8Array(t.response),i=r.split(".").pop()||"png";e(null,"data:image/"+({svg:"svg+xml"}[i]||i)+";base64,"+btoa(function(t){for(var e=[],n=0;n<t.length;n+=32768)e.push(String.fromCharCode.apply(null,t.subarray(n,n+32768)));return e.join("")}(n)))}else e(new Error("Failed to load image "+r))}(e,t)}),e.send()},getElementBBox:function(t){var e=C(t);if(0===e.length)throw new Error("Element not found");var n=e[0],i=n.ownerDocument,r=n.getBoundingClientRect(),o=0,s=0;if(n.ownerSVGElement){var a=K(n),h=a.getBBox({target:a.svg()});o=r.width-h.width,s=r.height-h.height}return{x:r.left+window.pageXOffset-i.documentElement.offsetLeft+o/2,y:r.top+window.pageYOffset-i.documentElement.offsetTop+s/2,width:r.width-o,height:r.height-s}},sortElements:bt,setAttributesBySelector:function(t,e){var i=C(t);ie(e,function(t,e){var n=i.find(e).addBack().filter(e);Kt(t,"class")&&(n.addClass(t.class),t=te(t,"class")),n.attr(t)})},normalizeSides:xt,timing:At,interpolate:Pt,filter:St,format:kt,template:Et,toggleFullScreen:function(t){var e=window.top.document;function n(t,e){for(var n=["webkit","moz","ms","o",""],i=0;i<n.length;i++){var r=n[i],o=r?r+e:e.substr(0,1).toLowerCase()+e.substr(1);if(void 0!==t[o])return jt(t[o])?t[o]():t[o]}}t=t||e.body,n(e,"FullscreenElement")||n(e,"FullScreenElement")?n(e,"ExitFullscreen")||n(e,"CancelFullScreen"):n(t,"RequestFullscreen")||n(t,"RequestFullScreen")},mixin:Ct,supplement:Tt,deepMixin:Lt,deepSupplement:Mt,assign:Nt,defaults:Vt,defaultsDeep:Ft,invoke:_t,sortedIndex:Bt,uniq:Rt,clone:Ot,cloneDeep:Dt,isEmpty:zt,isEqual:It,isFunction:jt,isPlainObject:Gt,toArray:Ut,debounce:qt,groupBy:Ht,sortBy:$t,flattenDeep:Yt,without:Xt,difference:Wt,intersection:Zt,union:Jt,has:Kt,result:Qt,omit:te,pick:ee,bindAll:ne,forIn:ie,camelCase:re,uniqueId:oe,merge:se,isBoolean:ae,isObject:he,isNumber:le,isString:ue,noop:ce,cloneCells:de};function Ne(t,e,n){var i=t.toJSON();return i.angle=e||0,Vt({},n,i)}function Ve(t,e,n){return t.map(function(t,e,n){var i=this.pointAt((e+.5)/n.length);return(t.dx||t.dy)&&i.offset(t.dx||0,t.dy||0),Ne(i.round(),0,t)},P(e,n))}function Fe(t,e,s,a){var h=e.center(),l=e.width/e.height,u=e.topMiddle(),c=x.fromRect(e);return t.map(function(t,e,n){var i=s+a(e,n.length),r=u.clone().rotate(h,-i).scale(l,1,h),o=t.compensateRotation?-c.tangentTheta(r):0;return(t.dx||t.dy)&&r.offset(t.dx||0,t.dy||0),t.dr&&r.move(h,t.dr),Ne(r.round(),o,t)})}function _e(t,e){var n=e.x;ue(n)&&(n=parseFloat(n)/100*t.width);var i=e.y;return ue(i)&&(i=parseFloat(i)/100*t.height),S(n||0,i||0)}var Be={absolute:function(t,e,n){return t.map(_e.bind(null,e))},fn:function(t,e,n){return n.fn(t,e,n)},line:function(t,e,n){return Ve(t,_e(e,n.start||e.origin()),_e(e,n.end||e.corner()))},left:function(t,e,n){return Ve(t,e.origin(),e.bottomLeft())},right:function(t,e,n){return Ve(t,e.topRight(),e.corner())},top:function(t,e,n){return Ve(t,e.origin(),e.topRight())},bottom:function(t,e,n){return Ve(t,e.bottomLeft(),e.corner())},ellipseSpread:function(t,e,n){var i=n.startAngle||0,r=n.step||360/t.length;return Fe(t,e,i,function(t){return t*r})},ellipse:function(t,e,n){var i=n.startAngle||0,r=n.step||20;return Fe(t,e,i,function(t,e){return(t+.5-e/2)*r})}};function Re(t,e){return Ft({},t,e,{x:0,y:0,angle:0,attrs:{".":{y:"0","text-anchor":"start"}}})}function Oe(t,e,n,i){i=Vt({},i,{offset:15});var r,o,s,a,h=e.center().theta(t),l=De(e),u=i.offset,c=0;a=h<l[1]||h>l[2]?(s=".3em",r=u,o=0,"start"):h<l[0]?(s="0",r=0,o=-u,n?(c=-90,"start"):"middle"):h<l[3]?(s=".3em",r=-u,o=0,"end"):(s=".6em",r=0,o=u,n?(c=90,"start"):"middle");var d=Math.round;return Re({x:d(r),y:d(o),angle:c,attrs:{".":{y:s,"text-anchor":a}}})}function De(t){var e=t.center(),n=e.theta(t.origin()),i=e.theta(t.bottomLeft()),r=e.theta(t.corner());return[n,e.theta(t.topRight()),r,i]}function ze(t,e,n,i){var r,o,s,a,h=e.center().theta(t),l=(i=Vt({},i,{offset:15})).offset,u=0,c=De(e);a=h<c[1]||h>c[2]?(s=".3em",r=-l,o=0,"end"):h<c[0]?(s=".6em",r=0,o=l,n?(u=90,"start"):"middle"):h<c[3]?(s=".3em",r=l,o=0,"start"):(s="0em",r=0,o=-l,n?(u=-90,"start"):"middle");var d=Math.round;return Re({x:d(r),y:d(o),angle:u,attrs:{".":{y:s,"text-anchor":a}}})}function Ie(t,e,n){n=Vt({},n,{offset:20});var i,r=S(0,0),o=-t.theta(r),s=o,a=t.clone().move(r,n.offset).difference(t).round(),h=".3em";(o+90)%180==0?(i=e?"end":"middle",e||-270!==o||(h="0em")):-270<o&&o<-90?(i="start",s=o-180):i="end";var l=Math.round;return Re({x:l(a.x),y:l(a.y),angle:e?s:0,attrs:{".":{y:h,"text-anchor":i}}})}var je={manual:function(t,e,n){return Re(n,e)},left:function(t,e,n){return Re(n,{x:-15,attrs:{".":{y:".3em","text-anchor":"end"}}})},right:function(t,e,n){return Re(n,{x:15,attrs:{".":{y:".3em","text-anchor":"start"}}})},top:function(t,e,n){return Re(n,{y:-15,attrs:{".":{"text-anchor":"middle"}}})},bottom:function(t,e,n){return Re(n,{y:15,attrs:{".":{y:".6em","text-anchor":"middle"}}})},outsideOriented:function(t,e,n){return Oe(t,e,!0,n)},outside:function(t,e,n){return Oe(t,e,!1,n)},insideOriented:function(t,e,n){return ze(t,e,!0,n)},inside:function(t,e,n){return ze(t,e,!1,n)},radial:function(t,e,n){return Ie(t.difference(e.center()),!1,n)},radialOriented:function(t,e,n){return Ie(t.difference(e.center()),!0,n)}},Ge=function(t){var e=Dt(t)||{};this.ports=[],this.groups={},this.portLayoutNamespace=Be,this.portLabelLayoutNamespace=je,this._init(e)};Ge.prototype={getPorts:function(){return this.ports},getGroup:function(t){return this.groups[t]||{}},getPortsByGroup:function(e){return this.ports.filter(function(t){return t.group===e})},getGroupPortsMetrics:function(t,r){var e=this.getGroup(t),n=this.getPortsByGroup(t),i=e.position||{},o=i.name,s=this.portLayoutNamespace;s[o]||(o="left");var a=i.args||{},h=n.map(function(t){return t&&t.position&&t.position.args}),l=s[o](h,r,a),u={ports:n,result:[]};return Ut(l).reduce(function(t,e,n){var i=t.ports[n];return t.result.push({portId:i.id,portTransformation:e,labelTransformation:this._getPortLabelLayout(i,z(e),r),portAttrs:i.attrs,portSize:i.size,labelSize:i.label.size}),t}.bind(this),u),u.result},_getPortLabelLayout:function(t,e,n){var i=this.portLabelLayoutNamespace,r=t.label.position.name||"left";return i[r]?i[r](e,n,t.label.position.args):null},_init:function(t){if(he(t.groups))for(var e=Object.keys(t.groups),n=0,i=e.length;n<i;n++){var r=e[n];this.groups[r]=this._evaluateGroup(t.groups[r])}for(var o=Ut(t.items),s=0,a=o.length;s<a;s++)this.ports.push(this._evaluatePort(o[s]))},_evaluateGroup:function(t){return se(t,{position:this._getPosition(t.position,!0),label:this._getLabel(t,!0)})},_evaluatePort:function(t){var e=Nt({},t),n=this.getGroup(t.group);return e.markup=e.markup||n.markup,e.attrs=se({},n.attrs,e.attrs),e.position=this._createPositionNode(n,e),e.label=se({},n.label,this._getLabel(e)),e.z=this._getZIndex(n,e),e.size=Nt({},n.size,e.size),e},_getZIndex:function(t,e){return le(e.z)?e.z:le(t.z)||"auto"===t.z?t.z:"auto"},_createPositionNode:function(t,e){return se({name:"left",args:{}},t.position,{args:e.args})},_getPosition:function(t,e){var n,i={};jt(t)?(n="fn",i.fn=t):ue(t)?n=t:void 0===t?n=e?"left":null:Array.isArray(t)?(n="absolute",i.x=t[0],i.y=t[1]):he(t)&&(n=t.name,Nt(i,t.args));var r={args:i};return n&&(r.name=n),r},_getLabel:function(t,e){var n=t.label||{},i=n;return i.position=this._getPosition(n.position,e),i}};var Ue={_initializePorts:function(){this._createPortData(),this.on("change:ports",function(){this._processRemovedPort(),this._createPortData()},this)},_processRemovedPort:function(){var t=this.get("ports")||{},e={};Ut(t.items).forEach(function(t){e[t.id]=!0});var n=this.previous("ports")||{},i={};Ut(n.items).forEach(function(t){e[t.id]||(i[t.id]=!0)});var r=this.graph;r&&!zt(i)&&(r.getConnectedLinks(this,{inbound:!0}).forEach(function(t){i[t.get("target").port]&&t.remove()}),r.getConnectedLinks(this,{outbound:!0}).forEach(function(t){i[t.get("source").port]&&t.remove()}))},hasPorts:function(){var t=this.prop("ports/items");return Array.isArray(t)&&0<t.length},hasPort:function(t){return-1!==this.getPortIndex(t)},getPorts:function(){return Dt(this.prop("ports/items"))||[]},getPort:function(e){return Dt(Ut(this.prop("ports/items")).find(function(t){return t.id&&t.id===e}))},getPortsPositions:function(t){return this._portSettingsData.getGroupPortsMetrics(t,X(this.size())).reduce(function(t,e){var n=e.portTransformation;return t[e.portId]={x:n.x,y:n.y,angle:n.angle},t},{})},getPortIndex:function(t){var e=he(t)?t.id:t;return this._isValidPortId(e)?Ut(this.prop("ports/items")).findIndex(function(t){return t.id===e}):-1},addPort:function(t,e){if(!he(t)||Array.isArray(t))throw new Error("Element: addPort requires an object.");var n=Nt([],this.prop("ports/items"));return n.push(t),this.prop("ports/items",n,e),this},portProp:function(t,e,n,i){var r=this.getPortIndex(t);if(-1===r)throw new Error("Element: unable to find port with id "+t);var o=Array.prototype.slice.call(arguments,1);return Array.isArray(e)?o[0]=["ports","items",r].concat(e):ue(e)?o[0]=["ports/items/",r,"/",e].join(""):(o=["ports/items/"+r],Gt(e)&&(o.push(e),o.push(n))),this.prop.apply(this,o)},_validatePorts:function(){var t=this.get("ports")||{},e=[],n=Ut((t=t||{}).items);return n.forEach(function(t){"object"!=typeof t&&e.push("Element: invalid port ",t),this._isValidPortId(t.id)||(t.id=this.generatePortId())},this),Rt(n,"id").length!==n.length&&e.push("Element: found id duplicities in ports."),e},generatePortId:function(){return this.generateId()},_isValidPortId:function(t){return null!=t&&!he(t)},addPorts:function(t,e){return t.length&&this.prop("ports/items",Nt([],this.prop("ports/items")).concat(t),e),this},removePort:function(t,e){var n=e||{},i=Nt([],this.prop("ports/items")),r=this.getPortIndex(t);return-1!==r&&(i.splice(r,1),n.rewrite=!0,this.prop("ports/items",i,n)),this},removePorts:function(t,e){var n;if(Array.isArray(t)){if(n=e||{},t.length){n.rewrite=!0;var i=Nt([],this.prop("ports/items")).filter(function(n){return!t.some(function(t){var e=he(t)?t.id:t;return n.id===e})});this.prop("ports/items",i,n)}}else(n=t||{}).rewrite=!0,this.prop("ports/items",[],n);return this},_createPortData:function(){var t,e=this._validatePorts();if(0<e.length)throw this.set("ports",this.previous("ports")),new Error(e.join(" "));this._portSettingsData&&(t=this._portSettingsData.getPorts()),this._portSettingsData=new Ge(this.get("ports"));var n=this._portSettingsData.getPorts();if(t){var i=n.filter(function(e){if(!t.find(function(t){return t.id===e.id}))return e}),r=t.filter(function(e){if(!n.find(function(t){return t.id===e.id}))return e});0<r.length&&this.trigger("ports:remove",this,r),0<i.length&&this.trigger("ports:add",this,i)}}},qe={portContainerMarkup:"g",portMarkup:[{tagName:"circle",selector:"circle",attributes:{r:10,fill:"#FFFFFF",stroke:"#000000"}}],portLabelMarkup:[{tagName:"text",selector:"text",attributes:{fill:"#000000"}}],_portElementsCache:null,_initializePorts:function(){this._cleanPortsCache()},_refreshPorts:function(){this._removePorts(),this._cleanPortsCache(),this._renderPorts()},_cleanPortsCache:function(){this._portElementsCache={}},_renderPorts:function(){for(var n=[],i=this._getContainerElement(),t=0,e=i.node.childNodes.length;t<e;t++)n.push(i.node.childNodes[t]);var r=Ht(this.model._portSettingsData.getPorts(),"z");Ut(r.auto).forEach(function(t){var e=this._getPortElement(t);i.append(e),n.push(e)},this);for(var o=Object.keys(r),s=0;s<o.length;s++){var a=o[s];if("auto"!==a){var h=parseInt(a,10);this._appendPorts(r[a],h,n)}}this._updatePorts()},_getContainerElement:function(){return this.rotatableNode||this.vel},_appendPorts:function(t,e,n){var i=this._getContainerElement(),r=Ut(t).map(this._getPortElement,this);n[e]||e<0?K(n[Math.max(e,0)]).before(r):i.append(r)},_getPortElement:function(t){return this._portElementsCache[t.id]?this._portElementsCache[t.id].portElement:this._createPortElement(t)},findPortNode:function(t,e){var n=this._portElementsCache[t];if(!n)return null;var i=n.portContentElement.node,r=n.portContentSelectors;return this.findBySelector(e,i,r)[0]},_updatePorts:function(){this._updatePortGroup(void 0),Object.keys(this.model._portSettingsData.groups).forEach(this._updatePortGroup,this)},_removePorts:function(){_t(this._portElementsCache,"portElement.remove")},_createPortElement:function(t){var e,n,i,r=K(this.portContainerMarkup).addClass("joint-port"),o=this._getPortMarkup(t);if(Array.isArray(o)){var s=this.parseDOMJSON(o,r.node),a=s.fragment;e=1<a.childNodes.length?K("g").append(a):K(a.firstChild),i=s.selectors}else e=K(o),Array.isArray(e)&&(e=K("g").append(e));if(!e)throw new Error("ElementView: Invalid port markup.");e.attr({port:t.id,"port-group":t.group});var h,l,u=this._getPortLabelMarkup(t.label);if(Array.isArray(u)){var c=this.parseDOMJSON(u,r.node),d=c.fragment;n=1<d.childNodes.length?K("g").append(d):K(d.firstChild),h=c.selectors}else n=K(u),Array.isArray(n)&&(n=K("g").append(n));if(!n)throw new Error("ElementView: Invalid port label markup.");if(i&&h){for(var f in h)if(i[f]&&f!==this.selector)throw new Error("ElementView: selectors within port must be unique.");l=Nt({},i,h)}else l=i||h;return r.append([e.addClass("joint-port-body"),n.addClass("joint-port-label")]),this._portElementsCache[t.id]={portElement:r,portLabelElement:n,portSelectors:l,portLabelSelectors:h,portContentElement:e,portContentSelectors:i},r},_updatePortGroup:function(t){for(var e=X(this.model.size()),n=this.model._portSettingsData.getGroupPortsMetrics(t,e),i=0,r=n.length;i<r;i++){var o=n[i],s=o.portId,a=this._portElementsCache[s]||{},h=o.portTransformation;this.applyPortTransform(a.portElement,h),this.updateDOMSubtreeAttributes(a.portElement.node,o.portAttrs,{rootBBox:new X(o.portSize),selectors:a.portSelectors});var l=o.labelTransformation;l&&(this.applyPortTransform(a.portLabelElement,l,-h.angle||0),this.updateDOMSubtreeAttributes(a.portLabelElement.node,l.attrs,{rootBBox:new X(o.labelSize),selectors:a.portLabelSelectors}))}},applyPortTransform:function(t,e,n){var i=K.createSVGMatrix().rotate(n||0).translate(e.x||0,e.y||0).rotate(e.angle||0);t.transform(i,{absolute:!0})},_getPortMarkup:function(t){return t.markup||this.model.get("portMarkup")||this.model.portMarkup||this.portMarkup},_getPortLabelMarkup:function(t){return t.markup||this.model.get("portLabelMarkup")||this.model.portLabelMarkup||this.portLabelMarkup}},He=Ce.extend({defaults:{position:{x:0,y:0},size:{width:1,height:1},angle:0},initialize:function(){this._initializePorts(),Ce.prototype.initialize.apply(this,arguments)},_initializePorts:function(){},_refreshPorts:function(){},isElement:function(){return!0},position:function(t,e,n){var i=le(e);if((n=(i?n:t)||{}).parentRelative){if(!this.graph)throw new Error("Element must be part of a graph.");var r=this.getParentCell(),o=r&&!r.isLink()?r.get("position"):{x:0,y:0}}if(i){if(n.parentRelative&&(t+=o.x,e+=o.y),n.deep){var s=this.get("position");this.translate(t-s.x,e-s.y,n)}else this.set("position",{x:t,y:e},n);return this}var a=z(this.get("position"));return n.parentRelative?a.difference(o):a},translate:function(t,e,n){if(e=e||0,0===(t=t||0)&&0===e)return this;(n=n||{}).translateBy=n.translateBy||this.id;var i=this.get("position")||{x:0,y:0};if(n.restrictedArea&&n.translateBy===this.id){var r=this.getBBox({deep:!0}),o=n.restrictedArea,s=i.x-r.x,a=i.y-r.y,h=Math.max(o.x+s,Math.min(o.x+o.width+s-r.width,i.x+t)),l=Math.max(o.y+a,Math.min(o.y+o.height+a-r.height,i.y+e));t=h-i.x,e=l-i.y}var u={x:i.x+t,y:i.y+e};return n.tx=t,n.ty=e,n.transition?(he(n.transition)||(n.transition={}),this.transition("position",u,Nt({},n.transition,{valueFunction:Pt.object})),_t(this.getEmbeddedCells(),"translate",t,e,n)):(this.startBatch("translate",n),this.set("position",u,n),_t(this.getEmbeddedCells(),"translate",t,e,n),this.stopBatch("translate",n)),this},size:function(t,e,n){var i=this.get("size");return void 0===t?{width:i.width,height:i.height}:(he(t)&&(n=e,e=le(t.height)?t.height:i.height,t=le(t.width)?t.width:i.width),this.resize(t,e,n))},resize:function(t,e,n){if(n=n||{},this.startBatch("resize",n),n.direction){var i=this.get("size");switch(n.direction){case"left":case"right":e=i.height;break;case"top":case"bottom":t=i.width}var r=b(this.get("angle")||0),o={"top-right":0,right:0,"top-left":1,top:1,"bottom-left":2,left:2,"bottom-right":3,bottom:3}[n.direction];n.absolute&&(o+=Math.floor((r+45)/90),o%=4);var s=this.getBBox(),a=s[["bottomLeft","corner","topRight","origin"][o]](),h=z(a).rotate(s.center(),-r),l=Math.sqrt(t*t+e*e)/2,u=o*Math.PI/2;u+=Math.atan(o%2==0?e/t:t/e),u-=A(r);var c=z.fromPolar(l,u,h),d=z(c).offset(t/-2,e/-2);this.set("size",{width:t,height:e},n),this.position(d.x,d.y,n)}else this.set("size",{width:t,height:e},n);return this.stopBatch("resize",n),this},scale:function(t,e,n,i){var r=this.getBBox().scale(t,e,n);return this.startBatch("scale",i),this.position(r.x,r.y,i),this.resize(r.width,r.height,i),this.stopBatch("scale"),this},fitEmbeds:function(t){void 0===t&&(t={});var e=this.graph;if(!e)throw new Error("Element must be part of a graph.");var n=this.getEmbeddedCells().filter(function(t){return t.isElement()});if(0===n.length)return this;this.startBatch("fit-embeds",t),t.deep&&_t(n,"fitEmbeds",t);var i=xt(t.padding),r=i.left,o=i.right,s=i.top,a=i.bottom,h=e.getCellsBBox(n),l=h.x,u=h.y,c=h.width,d=h.height;return l-=r,u-=s,c+=r+o,d+=a+s,this.set({position:{x:l,y:u},size:{width:c,height:d}},t),this.stopBatch("fit-embeds"),this},rotate:function(t,e,n,i){if(n){var r=this.getBBox().center(),o=this.get("size"),s=this.get("position");r.rotate(n,this.get("angle")-t);var a=r.x-o.width/2-s.x,h=r.y-o.height/2-s.y;this.startBatch("rotate",{angle:t,absolute:e,origin:n}),this.position(s.x+a,s.y+h,i),this.rotate(t,e,null,i),this.stopBatch("rotate")}else this.set("angle",e?t:(this.get("angle")+t)%360,i);return this},angle:function(){return b(this.get("angle")||0)},getBBox:function(t){if((t=t||{}).deep&&this.graph){var e=this.getEmbeddedCells({deep:!0,breadthFirst:!0});return e.push(this),this.graph.getCellsBBox(e)}var n=this.get("position"),i=this.get("size");return new X(n.x,n.y,i.width,i.height)},getPointFromConnectedLink:function(t,e){var n=this.getBBox(),i=n.center(),r=t.get(e);if(!r)return i;var o=r.port;if(!o)return i;var s=this.portProp(o,["group"]),a=this.getPortsPositions(s),h=new z(a[o]).offset(n.origin()),l=this.angle();return l&&h.rotate(i,-l),h}});Nt(He.prototype,Ue);var $e={},Ye=s.View.extend({options:{},theme:null,themeClassNamePrefix:tt("theme-"),requireSetThemeOverride:!1,defaultTheme:Q.defaultTheme,children:null,childNodes:null,UPDATE_PRIORITY:2,constructor:function(t){this.requireSetThemeOverride=t&&!!t.theme,this.options=Nt({},this.options,t),s.View.call(this,t)},initialize:function(){($e[this.cid]=this).setTheme(this.options.theme||this.defaultTheme),this.init()},unmount:function(){this.svgElement?this.vel.remove():this.$el.remove()},renderChildren:function(t){if(t||(t=Qt(this,"children")),t){var e=this.svgElement,n=K.namespace[e?"svg":"xhtml"],i=nt(t,n);(e?this.vel:this.$el).empty().append(i.fragment),this.childNodes=i.selectors}return this},findAttribute:function(t,e){for(var n=e;n&&1===n.nodeType;){var i=n.getAttribute(t);if(i)return i;if(n===this.el)return null;n=n.parentNode}return null},_ensureElement:function(){if(this.el)this.setElement(Qt(this,"el"));else{var t=Qt(this,"tagName"),e=Nt({},Qt(this,"attributes")),n=Nt({},Qt(this,"style"));this.id&&(e.id=Qt(this,"id")),this.setElement(this._createElement(t)),this._setAttributes(e),this._setStyle(n)}this._ensureElClassName()},_setAttributes:function(t){this.svgElement?this.vel.attr(t):this.$el.attr(t)},_setStyle:function(t){this.$el.css(t)},_createElement:function(t){return this.svgElement?document.createElementNS(K.namespace.svg,t):document.createElement(t)},_setElement:function(t){this.$el=t instanceof s.$?t:s.$(t),this.el=this.$el[0],this.svgElement&&(this.vel=K(this.el))},_ensureElClassName:function(){var t=Qt(this,"className");if(t){var e=tt(t);this.svgElement?this.vel.removeClass(t).addClass(e):this.$el.removeClass(t).addClass(e)}},init:function(){},onRender:function(){},confirmUpdate:function(){return 0},setTheme:function(t,e){return e=e||{},this.theme&&this.requireSetThemeOverride&&!e.override||(this.removeThemeClassName(),this.addThemeClassName(t),this.onSetTheme(this.theme,t),this.theme=t),this},addThemeClassName:function(t){t=t||this.theme;var e=this.themeClassNamePrefix+t;return this.svgElement?this.vel.addClass(e):this.$el.addClass(e),this},removeThemeClassName:function(t){t=t||this.theme;var e=this.themeClassNamePrefix+t;return this.svgElement?this.vel.removeClass(e):this.$el.removeClass(e),this},onSetTheme:function(t,e){},remove:function(){return this.onRemove(),this.undelegateDocumentEvents(),$e[this.cid]=null,s.View.prototype.remove.apply(this,arguments),this},onRemove:function(){},getEventNamespace:function(){return".joint-event-ns-"+this.cid},delegateElementEvents:function(t,e,n){if(!e)return this;n||(n={});var i=this.getEventNamespace();for(var r in e){var o=e[r];"function"!=typeof o&&(o=this[o]),o&&C(t).on(r+i,n,o.bind(this))}return this},undelegateElementEvents:function(t){return C(t).off(this.getEventNamespace()),this},delegateDocumentEvents:function(t,e){return t||(t=Qt(this,"documentEvents")),this.delegateElementEvents(document,t,e)},undelegateDocumentEvents:function(){return this.undelegateElementEvents(document)},eventData:function(t,e){if(!t)throw new Error("eventData(): event object required.");var n=t.data,i="__"+this.cid+"__";return void 0===e?n&&n[i]||{}:(n||(n=t.data={}),n[i]||(n[i]={}),Nt(n[i],e),this)},stopPropagation:function(t){return this.eventData(t,{propagationStopped:!0}),this},isPropagationStopped:function(t){return!!this.eventData(t).propagationStopped}},{extend:function(){var t=Array.from(arguments),e=t[0]&&Nt({},t[0])||{},n=t[1]&&Nt({},t[1])||{},i=e.render||this.prototype&&this.prototype.render||null;return e.render=function(){return"function"==typeof i&&i.apply(this,arguments),this.render.__render__===i&&this.onRender(),this},e.render.__render__=i,s.View.extend.call(this,e,n)}}),Xe={views:$e,View:Ye},We=Ye.extend({tagName:"g",svgElement:!0,selector:"root",metrics:null,className:function(){var i=["cell"],t=this.model.get("type");return t&&t.toLowerCase().split(".").forEach(function(t,e,n){i.push("type-"+n.slice(0,e+1).join("-"))}),i.join(" ")},_presentationAttributes:null,_flags:null,setFlags:function(){var t,e,n,i={},r={},o=0,s=this.presentationAttributes;for(var a in s)if(s.hasOwnProperty(a)){var h=s[a];for(Array.isArray(h)||(h=[h]),t=0,e=h.length;t<e;t++){var l=i[n=h[t]];l||(l=i[n]=1<<o++),r[a]|=l}}var u=this.initFlag;for(Array.isArray(u)||(u=[u]),t=0,e=u.length;t<e;t++)i[n=u[t]]||(i[n]=1<<o++);if(25<o)throw new Error("dia.CellView: Maximum number of flags exceeded.");this._flags=i,this._presentationAttributes=r},hasFlag:function(t,e){return t&this.getFlag(e)},removeFlag:function(t,e){return t^t&this.getFlag(e)},getFlag:function(t){var e=this._flags;if(!e)return 0;var n=0;if(Array.isArray(t))for(var i=0,r=t.length;i<r;i++)n|=e[t[i]];else n|=e[t];return n},attributes:function(){var t=this.model;return{"model-id":t.id,"data-type":t.attributes.type}},constructor:function(t){t.id=t.id||lt(this),Ye.call(this,t)},initialize:function(){this.setFlags(),Ye.prototype.initialize.apply(this,arguments),this.cleanNodesCache(),this.$el.data("view",this),this.startListening()},startListening:function(){this.listenTo(this.model,"change",this.onAttributesChange)},onAttributesChange:function(t,e){var n=t.getChangeFlag(this._presentationAttributes);if(!e.updateHandled&&n){e.dirty&&this.hasFlag(n,"UPDATE")&&(n|=this.getFlag("RENDER")),e.tool&&(e.async=!1);var i=this.paper;i&&i.requestViewUpdate(this,n,this.UPDATE_PRIORITY,e)}},parseDOMJSON:function(t,e){var n=nt(t),i=n.selectors,r=n.groupSelectors;for(var o in r){if(i[o])throw new Error("dia.CellView: ambiguous group selector");i[o]=r[o]}if(e){var s=this.selector;if(i[s])throw new Error("dia.CellView: ambiguous root selector.");i[s]=e}return{fragment:n.fragment,selectors:i}},can:function(t){var e=jt(this.options.interactive)?this.options.interactive(this):this.options.interactive;return he(e)&&!1!==e[t]||ae(e)&&!1!==e},findBySelector:function(t,e,n){if(e||(e=this.el),n||(n=this.selectors),!t||"."===t)return[e];if(n){var i=n[t];if(i)return Array.isArray(i)?i:[i]}return Q.useCSSSelectors?C(e).find(t).toArray():[]},notify:function(t){if(this.paper){var e=Array.prototype.slice.call(arguments,1);this.trigger.apply(this,[t].concat(e)),this.paper.trigger.apply(this.paper,[t,this].concat(e))}},getBBox:function(t){var e;if(t&&t.useModelGeometry){var n=this.model;e=n.getBBox().bbox(n.angle())}else e=this.getNodeBBox(this.el);return this.paper.localToPaperRect(e)},getNodeBBox:function(t){var e=this.getNodeBoundingRect(t),n=this.getNodeMatrix(t),i=this.getRootTranslateMatrix(),r=this.getRootRotateMatrix();return K.transformRect(e,i.multiply(r).multiply(n))},getNodeUnrotatedBBox:function(t){var e=this.getNodeBoundingRect(t),n=this.getNodeMatrix(t),i=this.getRootTranslateMatrix();return K.transformRect(e,i.multiply(n))},getRootTranslateMatrix:function(){var t=this.model.position();return K.createSVGMatrix().translate(t.x,t.y)},getRootRotateMatrix:function(){var t=K.createSVGMatrix(),e=this.model,n=e.angle();if(n){var i=e.getBBox(),r=i.width/2,o=i.height/2;t=t.translate(r,o).rotate(n).translate(-r,-o)}return t},highlight:function(t,e){return t=t&&this.$(t)[0]||this.el,(e=e||{}).partial=t!==this.el,this.notify("cell:highlight",t,e),this},unhighlight:function(t,e){return t=t&&this.$(t)[0]||this.el,(e=e||{}).partial=t!=this.el,this.notify("cell:unhighlight",t,e),this},findMagnet:function(t){var e=this.$(t),n=this.$el;0===e.length&&(e=n);do{var i=e.attr("magnet");if((i||e.is(n))&&"false"!==i)return e[0];e=e.parent()}while(0<e.length)},getSelector:function(t,e){var n;if(t===this.el)return"string"==typeof e&&(n="> "+e),n;if(t){var i=K(t).index()+1;n=t.tagName+":nth-child("+i+")",e&&(n+=" > "+e),n=this.getSelector(t.parentNode,n)}return n},getLinkEnd:function(t,e,n,i,r){var o=this.model,s=o.id,a=this.findAttribute("port",t),h=t.getAttribute("joint-selector"),l={id:s};null!=h&&(l.magnet=h),null!=a?(l.port=a,o.hasPort(a)||h||(l.selector=this.getSelector(t))):null==h&&this.el!==t&&(l.selector=this.getSelector(t));var u=this.paper,c=u.options.connectionStrategy;if("function"==typeof c){var d=c.call(u,l,this,t,new z(e,n),i,r,u);d&&(l=d)}return l},getMagnetFromLinkEnd:function(t){var e=this.el,n=t.port,i=t.magnet,r=this.model;return null!=n&&r.isElement()&&r.hasPort(n)?this.findPortNode(n,i)||e:(i||(i=t.selector),i||null==n||(i='[port="'+n+'"]'),this.findBySelector(i,e,this.selectors)[0])},getAttributeDefinition:function(t){return this.model.constructor.getAttributeDefinition(t)},setNodeAttributes:function(t,e){zt(e)||(t instanceof SVGElement?K(t).attr(e):C(t).attr(e))},processNodeAttributes:function(t,e){var n,i,r,o,s,a,h,l,u,c=[];for(n in e)e.hasOwnProperty(n)&&(i=e[n],!(r=this.getAttributeDefinition(n))||jt(r.qualify)&&!r.qualify.call(this,i,t,e)?(a||(a={}),a[ut(n)]=i):(ue(r.set)&&(a||(a={}),a[r.set]=i),null!==i&&c.push(n,r)));for(o=0,s=c.length;o<s;o+=2)n=c[o],r=c[o+1],i=e[n],jt(r.set)&&(h||(h={}),h[n]=i),jt(r.position)&&(l||(l={}),l[n]=i),jt(r.offset)&&(u||(u={}),u[n]=i);return{raw:e,normal:a,set:h,position:l,offset:u}},updateRelativeAttributes:function(t,e,n,i){var r,o;i||(i={});var s=e.raw||{},a=e.normal||{},h=e.set,l=e.position,u=e.offset;for(r in h){o=h[r];var c=this.getAttributeDefinition(r).set.call(this,o,n.clone(),t,s);he(c)?Nt(a,c):void 0!==c&&(a[r]=c)}if(t instanceof HTMLElement)this.setNodeAttributes(t,a);else{var d,f,p,g=a.transform,v=K.transformStringToMatrix(g),m=z(v.e,v.f);if(g&&(a=te(a,"transform"),v.e=v.f=0),l||u){var y=this.getNodeScale(t,i.scalableNode);d=y.sx,f=y.sy}var w=!1;for(r in l)o=l[r],(p=this.getAttributeDefinition(r).position.call(this,o,n.clone(),t,s))&&(m.offset(z(p).scale(d,f)),w||(w=!0));this.setNodeAttributes(t,a);var b=!1;if(u){var x=this.getNodeBoundingRect(t);if(0<x.width&&0<x.height){var A=K.transformRect(x,v).scale(1/d,1/f);for(r in u)o=u[r],(p=this.getAttributeDefinition(r).offset.call(this,o,A,t,s))&&(m.offset(z(p).scale(d,f)),b||(b=!0))}}(void 0!==g||w||b)&&(m.round(1),v.e=m.x,v.f=m.y,t.setAttribute("transform",K.matrixToTransformString(v)))}},getNodeScale:function(t,e){var n,i;if(e&&e.contains(t)){var r=e.scale();n=1/r.sx,i=1/r.sy}else i=n=1;return{sx:n,sy:i}},cleanNodesCache:function(){this.metrics={}},nodeCache:function(t){var e=this.metrics;if(!e)return{};var n=K.ensureId(t),i=e[n];return i||(i=e[n]={}),i},getNodeData:function(t){var e=this.nodeCache(t);return e.data||(e.data={}),e.data},getNodeBoundingRect:function(t){var e=this.nodeCache(t);return void 0===e.boundingRect&&(e.boundingRect=K(t).getBBox()),new X(e.boundingRect)},getNodeMatrix:function(t){var e=this.nodeCache(t);if(void 0===e.magnetMatrix){var n=this.rotatableNode||this.el;e.magnetMatrix=K(t).getTransformToElement(n)}return K.createSVGMatrix(e.magnetMatrix)},getNodeShape:function(t){var e=this.nodeCache(t);return void 0===e.geometryShape&&(e.geometryShape=K(t).toGeometryShape()),e.geometryShape.clone()},isNodeConnection:function(t){return this.model.isLink()&&(!t||t===this.el)},findNodesAttributes:function(t,e,n,i){var r,o,s,a,h={},l=[];for(var u in t)if(t.hasOwnProperty(u)&&(s=t[u],Gt(s))){var c=n[u]=this.findBySelector(u,e,i);for(r=0,o=c.length;r<o;r++){var d=c[r];a=K.ensureId(d);var f=i&&i[u]===d,p=h[a];if(p){p.array||(l.push(a),p.array=!0,p.attributes=[p.attributes],p.selectedLength=[p.selectedLength]);var g=p.attributes,v=p.selectedLength;if(f)g.unshift(s),v.unshift(-1);else{var m=Bt(v,o);g.splice(m,0,s),v.splice(m,0,o)}}else h[a]={attributes:s,selectedLength:f?-1:o,node:d,array:!1}}}for(r=0,o=l.length;r<o;r++)(s=h[a=l[r]]).attributes=se.apply(void 0,[{}].concat(s.attributes.reverse()));return h},getEventTarget:function(t,e){void 0===e&&(e={});var n=t.target,i=t.type,r=t.clientX;void 0===r&&(r=0);var o=t.clientY;return void 0===o&&(o=0),e.fromPoint||"touchmove"===i||"touchend"===i?document.elementFromPoint(r,o):n},updateDOMSubtreeAttributes:function(t,e,n){n||(n={}),n.rootBBox||(n.rootBBox=X()),n.selectors||(n.selectors=this.selectors);var i,r,o,s,a,h,l={},u={},c=[],d=n.roAttributes,f=this.findNodesAttributes(d||e,t,l,n.selectors),p=d?this.findNodesAttributes(e,t,l,n.selectors):f;for(var g in f)if(o=(s=f[g]).attributes,r=s.node,(a=this.processNodeAttributes(r,o)).set||a.position||a.offset){var v,m=p[g]&&p[g].attributes,y=m&&void 0===o.ref?m.ref:o.ref;if(y){if(!(v=(l[y]||this.findBySelector(y,t,n.selectors))[0]))throw new Error('dia.ElementView: "'+y+'" reference does not exist.')}else v=null;i={node:r,refNode:v,processedAttributes:a,allAttributes:m};var w=c.findIndex(function(t){return t.refNode===r});-1<w?c.splice(w,0,i):c.push(i)}else this.setNodeAttributes(r,a.normal);for(var b=0,x=c.length;b<x;b++){i=c[b],r=i.node,v=i.refNode;var A=K(n.rotatableNode),P=v?K.ensureId(v):"",S=!!A&&!!v&&A.contains(v),k=u[P];if(!k){var E=S?A:t;k=u[P]=v?K(v).getBBox({target:E}):n.rootBBox}d?(a=this.processNodeAttributes(r,i.allAttributes),this.mergeProcessedAttributes(a,i.processedAttributes)):a=i.processedAttributes;var C=k;S&&!A.contains(r)&&(h||(h=K.transformStringToMatrix(A.attr("transform"))),C=K.transformRect(k,h)),this.updateRelativeAttributes(r,a,C,n)}},mergeProcessedAttributes:function(t,e){t.set||(t.set={}),t.position||(t.position={}),t.offset||(t.offset={}),Nt(t.set,e.set),Nt(t.position,e.position),Nt(t.offset,e.offset);var n=t.normal&&t.normal.transform;void 0!==n&&e.normal&&(e.normal.transform=n),t.normal=e.normal},onRemove:function(){this.removeTools()},_toolsView:null,hasTools:function(t){var e=this._toolsView;return!!e&&(!t||e.getName()===t)},addTools:function(t){return this.removeTools(),t&&((this._toolsView=t).configure({relatedView:this}),t.listenTo(this.paper,"tools:event",this.onToolEvent.bind(this)),t.mount()),this},updateTools:function(t){var e=this._toolsView;return e&&e.update(t),this},removeTools:function(){var t=this._toolsView;return t&&(t.remove(),this._toolsView=null),this},hideTools:function(){var t=this._toolsView;return t&&t.hide(),this},showTools:function(){var t=this._toolsView;return t&&t.show(),this},onToolEvent:function(t){switch(t){case"remove":this.removeTools();break;case"hide":this.hideTools();break;case"show":this.showTools()}},pointerdblclick:function(t,e,n){this.notify("cell:pointerdblclick",t,e,n)},pointerclick:function(t,e,n){this.notify("cell:pointerclick",t,e,n)},contextmenu:function(t,e,n){this.notify("cell:contextmenu",t,e,n)},pointerdown:function(t,e,n){this.model.graph&&(this.model.startBatch("pointer"),this._graph=this.model.graph),this.notify("cell:pointerdown",t,e,n)},pointermove:function(t,e,n){this.notify("cell:pointermove",t,e,n)},pointerup:function(t,e,n){this.notify("cell:pointerup",t,e,n),this._graph&&(this._graph.stopBatch("pointer",{cell:this.model}),delete this._graph)},mouseover:function(t){this.notify("cell:mouseover",t)},mouseout:function(t){this.notify("cell:mouseout",t)},mouseenter:function(t){this.notify("cell:mouseenter",t)},mouseleave:function(t){this.notify("cell:mouseleave",t)},mousewheel:function(t,e,n,i){this.notify("cell:mousewheel",t,e,n,i)},onevent:function(t,e,n,i){this.notify(e,t,n,i)},onmagnet:function(){},magnetpointerdblclick:function(){},magnetcontextmenu:function(){},checkMouseleave:function(t){var e=this.paper;e.isAsync()&&e.dumpView(this);var n=this.getEventTarget(t,{fromPoint:!0}),i=e.findView(n);i!==this&&(this.mouseleave(t),i&&i.mouseenter(t))},setInteractivity:function(t){this.options.interactive=t}},{addPresentationAttributes:function(t){return se({},this.prototype.presentationAttributes,t,function(t,e){if(t&&e)return"string"==typeof t&&(t=[t]),"string"==typeof e&&(e=[e]),Array.isArray(t)&&Array.isArray(e)?Rt(t.concat(e)):void 0})}}),Ze=We.extend({_removePorts:function(){},_renderPorts:function(){},className:function(){var t=We.prototype.className.apply(this).split(" ");return t.push("element"),t.join(" ")},initialize:function(){We.prototype.initialize.apply(this,arguments),this._initializePorts()},presentationAttributes:{attrs:["UPDATE"],position:["TRANSLATE","TOOLS"],size:["RESIZE","PORTS","TOOLS"],angle:["ROTATE","TOOLS"],markup:["RENDER"],ports:["PORTS"]},initFlag:["RENDER"],UPDATE_PRIORITY:0,confirmUpdate:function(t,e){var n=Q.useCSSSelectors;return this.hasFlag(t,"PORTS")&&(this._removePorts(),this._cleanPortsCache()),this.hasFlag(t,"RENDER")?(this.render(),this.updateTools(e),t=this.removeFlag(t,["RENDER","UPDATE","RESIZE","TRANSLATE","ROTATE","PORTS"])):(this.hasFlag(t,"RESIZE")&&(this.resize(e),t=this.removeFlag(t,["RESIZE","UPDATE"])),this.hasFlag(t,"UPDATE")&&(this.update(this.model,null,e),t=this.removeFlag(t,"UPDATE"),n&&(t=this.removeFlag(t,"PORTS"))),this.hasFlag(t,"TRANSLATE")&&(this.translate(),t=this.removeFlag(t,"TRANSLATE")),this.hasFlag(t,"ROTATE")&&(this.rotate(),t=this.removeFlag(t,"ROTATE")),this.hasFlag(t,"PORTS")&&(this._renderPorts(),t=this.removeFlag(t,"PORTS"))),this.hasFlag(t,"TOOLS")&&(this.updateTools(e),t=this.removeFlag(t,"TOOLS")),t},_initializePorts:function(){},update:function(t,e){this.cleanNodesCache();var n=Q.useCSSSelectors;n&&this._removePorts();var i=this.model,r=i.attr();this.updateDOMSubtreeAttributes(this.el,r,{rootBBox:new X(i.size()),selectors:this.selectors,scalableNode:this.scalableNode,rotatableNode:this.rotatableNode,roAttributes:e===r?null:e}),n&&this._renderPorts()},rotatableSelector:"rotatable",scalableSelector:"scalable",scalableNode:null,rotatableNode:null,renderMarkup:function(){var t=this.model,e=t.get("markup")||t.markup;if(!e)throw new Error("dia.ElementView: markup required");if(Array.isArray(e))return this.renderJSONMarkup(e);if("string"==typeof e)return this.renderStringMarkup(e);throw new Error("dia.ElementView: invalid markup")},renderJSONMarkup:function(t){var e=this.parseDOMJSON(t,this.el),n=this.selectors=e.selectors;this.rotatableNode=K(n[this.rotatableSelector])||null,this.scalableNode=K(n[this.scalableSelector])||null,this.vel.append(e.fragment)},renderStringMarkup:function(t){var e=this.vel;e.append(K(t)),this.rotatableNode=e.findOne(".rotatable"),this.scalableNode=e.findOne(".scalable"),(this.selectors={})[this.selector]=this.el},render:function(){return this.vel.empty(),this.renderMarkup(),this.scalableNode&&this.update(),this.resize(),this.rotatableNode?(this.rotate(),this.translate()):this.updateTransformation(),Q.useCSSSelectors||this._renderPorts(),this},resize:function(t){if(this.scalableNode)return this.sgResize(t);this.model.attributes.angle&&this.rotate(),this.update()},translate:function(){if(this.rotatableNode)return this.rgTranslate();this.updateTransformation()},rotate:function(){if(this.rotatableNode)return this.rgRotate(),void this.update();this.updateTransformation()},updateTransformation:function(){var t=this.getTranslateString(),e=this.getRotateString();e&&(t+=" "+e),this.vel.attr("transform",t)},getTranslateString:function(){var t=this.model.attributes.position;return"translate("+t.x+","+t.y+")"},getRotateString:function(){var t=this.model.attributes,e=t.angle;if(!e)return null;var n=t.size;return"rotate("+e+","+n.width/2+","+n.height/2+")"},rgRotate:function(){this.rotatableNode.attr("transform",this.getRotateString())},rgTranslate:function(){this.vel.attr("transform",this.getTranslateString())},sgResize:function(t){var e=this.model,n=e.angle(),i=e.size(),r=this.scalableNode,o=!1;0<r.node.getElementsByTagName("path").length&&(o=!0);var s=r.getBBox({recursive:o}),a=i.width/(s.width||1),h=i.height/(s.height||1);r.attr("transform","scale("+a+","+h+")");var l=this.rotatableNode,u=l&&l.attr("transform");if(u){l.attr("transform",u+" rotate("+-n+","+i.width/2+","+i.height/2+")");var c=r.getBBox({target:this.paper.cells});e.set("position",{x:c.x,y:c.y},Nt({updateHandled:!0},t)),this.translate(),this.rotate()}this.update()},prepareEmbedding:function(t){t||(t={});var e=t.model||this.model,n=(t.paper||this.paper).model;e.startBatch("to-front"),e.toFront({deep:!0,ui:!0});var i=n.getElements().reduce(function(t,e){return Math.max(t,e.attributes.z||0)},0);n.getConnectedLinks(e,{deep:!0,includeEnclosed:!0}).forEach(function(t){t.attributes.z<=i&&t.set("z",i+1,{ui:!0})}),e.stopBatch("to-front");var r=e.parent();r&&n.getCell(r).unembed(e,{ui:!0})},processEmbedding:function(t){t||(t={});var e=t.model||this.model,n=t.paper||this.paper,i=n.options,r=[];jt(i.findParentBy)?r=Ut(i.findParentBy.call(n.model,this)).filter(function(t){return t instanceof Ce&&this.model.id!==t.id&&!t.isEmbeddedIn(this.model)}.bind(this)):r=n.model.findModelsUnderElement(e,{searchBy:i.findParentBy});i.frontParentOnly&&(r=r.slice(-1));for(var o=null,s=t.candidateEmbedView,a=r.length-1;0<=a;a--){var h=r[a];if(s&&s.model.id==h.id){o=s;break}var l=h.findView(n);if(i.validateEmbedding.call(n,this,l)){o=l;break}}o&&o!=s&&(this.clearEmbedding(t),t.candidateEmbedView=o.highlight(null,{embedding:!0})),!o&&s&&this.clearEmbedding(t)},clearEmbedding:function(t){t||(t={});var e=t.candidateEmbedView;e&&(e.unhighlight(null,{embedding:!0}),t.candidateEmbedView=null)},finalizeEmbedding:function(t){t||(t={});var e=t.candidateEmbedView,n=t.model||this.model,i=t.paper||this.paper;e&&(e.model.embed(n,{ui:!0}),e.unhighlight(null,{embedding:!0}),t.candidateEmbedView=null),_t(i.model.getConnectedLinks(n,{deep:!0}),"reparent",{ui:!0})},getDelegatedView:function(){for(var t=this,e=t.model,n=t.paper;t&&!e.isLink();){if(!e.isEmbedded()||t.can("stopDelegation"))return t;e=e.getParentCell(),t=n.findViewByModel(e)}return null},notifyPointerdown:function(t,e,n){We.prototype.pointerdown.call(this,t,e,n),this.notify("element:pointerdown",t,e,n)},notifyPointermove:function(t,e,n){We.prototype.pointermove.call(this,t,e,n),this.notify("element:pointermove",t,e,n)},notifyPointerup:function(t,e,n){this.notify("element:pointerup",t,e,n),We.prototype.pointerup.call(this,t,e,n)},pointerdblclick:function(t,e,n){We.prototype.pointerdblclick.apply(this,arguments),this.notify("element:pointerdblclick",t,e,n)},pointerclick:function(t,e,n){We.prototype.pointerclick.apply(this,arguments),this.notify("element:pointerclick",t,e,n)},contextmenu:function(t,e,n){We.prototype.contextmenu.apply(this,arguments),this.notify("element:contextmenu",t,e,n)},pointerdown:function(t,e,n){this.isPropagationStopped(t)||(this.notifyPointerdown(t,e,n),this.dragStart(t,e,n))},pointermove:function(t,e,n){var i=this.eventData(t);switch(i.action){case"magnet":this.dragMagnet(t,e,n);break;case"move":(i.delegatedView||this).drag(t,e,n);default:this.notifyPointermove(t,e,n)}this.eventData(t,i)},pointerup:function(t,e,n){var i=this.eventData(t);switch(i.action){case"magnet":this.dragMagnetEnd(t,e,n);break;case"move":(i.delegatedView||this).dragEnd(t,e,n);default:this.notifyPointerup(t,e,n)}var r=i.targetMagnet;r&&this.magnetpointerclick(t,r,e,n),this.checkMouseleave(t)},mouseover:function(t){We.prototype.mouseover.apply(this,arguments),this.notify("element:mouseover",t)},mouseout:function(t){We.prototype.mouseout.apply(this,arguments),this.notify("element:mouseout",t)},mouseenter:function(t){We.prototype.mouseenter.apply(this,arguments),this.notify("element:mouseenter",t)},mouseleave:function(t){We.prototype.mouseleave.apply(this,arguments),this.notify("element:mouseleave",t)},mousewheel:function(t,e,n,i){We.prototype.mousewheel.apply(this,arguments),this.notify("element:mousewheel",t,e,n,i)},onmagnet:function(t,e,n){this.dragMagnetStart(t,e,n)},magnetpointerdblclick:function(t,e,n,i){this.notify("element:magnet:pointerdblclick",t,e,n,i)},magnetcontextmenu:function(t,e,n,i){this.notify("element:magnet:contextmenu",t,e,n,i)},dragStart:function(t,e,n){var i=this.getDelegatedView();i&&i.can("elementMove")&&(this.eventData(t,{action:"move",delegatedView:i}),i.eventData(t,{pointerOffset:i.model.position().difference(e,n),restrictedArea:this.paper.getRestrictedArea(i)}))},dragMagnetStart:function(t,e,n){if(this.can("addLinkFromMagnet")){var i=t.currentTarget,r=this.paper;this.eventData(t,{targetMagnet:i}),t.stopPropagation(),r.options.validateMagnet(this,i,t)?(r.options.magnetThreshold<=0&&this.dragLinkStart(t,i,e,n),this.eventData(t,{action:"magnet"}),this.stopPropagation(t)):this.pointerdown(t,e,n),r.delegateDragEvents(this,t.data)}},dragLinkStart:function(t,e,n,i){this.model.startBatch("add-link");var r=this.addLinkFromMagnet(e,n,i);r.notifyPointerdown(t,n,i),r.eventData(t,r.startArrowheadMove("target",{whenNotAllowed:"remove"})),this.eventData(t,{linkView:r})},addLinkFromMagnet:function(t,e,n){var i=this.paper,r=i.model,o=i.getDefaultLink(this,t);return o.set({source:this.getLinkEnd(t,e,n,o,"source"),target:{x:e,y:n}}).addTo(r,{async:!1,ui:!0}),o.findView(i)},drag:function(t,e,n){var i=this.paper,r=i.options.gridSize,o=this.model,s=this.eventData(t),a=s.pointerOffset,h=s.restrictedArea,l=s.embedding,u=v(e+a.x,r),c=v(n+a.y,r);o.position(u,c,{restrictedArea:h,deep:!0,ui:!0}),i.options.embeddingMode&&(l||(this.prepareEmbedding(s),l=!0),this.processEmbedding(s)),this.eventData(t,{embedding:l})},dragMagnet:function(t,e,n){var i=this.eventData(t),r=i.linkView;if(r)r.pointermove(t,e,n);else{var o=this.paper,s=o.options.magnetThreshold,a=this.getEventTarget(t),h=i.targetMagnet;if("onleave"===s){if(h===a||K(h).contains(a))return}else if(o.eventData(t).mousemoved<=s)return;this.dragLinkStart(t,h,e,n)}},dragEnd:function(t,e,n){var i=this.eventData(t);i.embedding&&this.finalizeEmbedding(i)},dragMagnetEnd:function(t,e,n){var i=this.eventData(t).linkView;i&&(i.pointerup(t,e,n),this.model.stopBatch("add-link"))},magnetpointerclick:function(t,e,n,i){var r=this.paper;r.eventData(t).mousemoved>r.options.clickThreshold||this.notify("element:magnet:pointerclick",t,e,n,i)}});Nt(Ze.prototype,qe);var Je={_results:{},_tests:{svgforeignobject:function(){return!!document.createElementNS&&/SVGForeignObject/.test({}.toString.call(document.createElementNS("http://www.w3.org/2000/svg","foreignObject")))}},addTest:function(t,e){return this._tests[t]=e},test:function(t){var e=this._tests[t];if(!e)throw new Error('Test not defined ("'+t+'"). Use `joint.env.addTest(name, fn) to add a new test.`');var n=this._results[t];if(void 0!==n)return n;try{n=e()}catch(t){n=!1}return this._results[t]=n}},Ke=He.define("basic.Generic",{attrs:{".":{fill:"#ffffff",stroke:"none"}}}),Qe=Ke.define("basic.Rect",{attrs:{rect:{fill:"#ffffff",stroke:"#000000",width:100,height:60},text:{fill:"#000000",text:"","font-size":14,"ref-x":.5,"ref-y":.5,"text-anchor":"middle","y-alignment":"middle","font-family":"Arial, helvetica, sans-serif"}}},{markup:'<g class="rotatable"><g class="scalable"><rect/></g><text/></g>'}),tn=Ze.extend({presentationAttributes:Ze.addPresentationAttributes({attrs:["SCALE"]}),confirmUpdate:function(){var t=Ze.prototype.confirmUpdate.apply(this,arguments);return this.hasFlag(t,"SCALE")&&(this.resize(),t=this.removeFlag(t,"SCALE")),t}}),en=Ke.define("basic.Text",{attrs:{text:{"font-size":18,fill:"#000000"}}},{markup:'<g class="rotatable"><g class="scalable"><text/></g></g>'}),nn=Ke.define("basic.Circle",{size:{width:60,height:60},attrs:{circle:{fill:"#ffffff",stroke:"#000000",r:30,cx:30,cy:30},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-y":.5,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},{markup:'<g class="rotatable"><g class="scalable"><circle/></g><text/></g>'}),rn=Ke.define("basic.Ellipse",{size:{width:60,height:40},attrs:{ellipse:{fill:"#ffffff",stroke:"#000000",rx:30,ry:20,cx:30,cy:20},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-y":.5,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},{markup:'<g class="rotatable"><g class="scalable"><ellipse/></g><text/></g>'}),on=Ke.define("basic.Polygon",{size:{width:60,height:40},attrs:{polygon:{fill:"#ffffff",stroke:"#000000"},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-dy":20,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},{markup:'<g class="rotatable"><g class="scalable"><polygon/></g><text/></g>'}),sn=Ke.define("basic.Polyline",{size:{width:60,height:40},attrs:{polyline:{fill:"#ffffff",stroke:"#000000"},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-dy":20,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},{markup:'<g class="rotatable"><g class="scalable"><polyline/></g><text/></g>'}),an=Ke.define("basic.Image",{attrs:{text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-dy":20,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},{markup:'<g class="rotatable"><g class="scalable"><image/></g><text/></g>'}),hn=Ke.define("basic.Path",{size:{width:60,height:60},attrs:{path:{fill:"#ffffff",stroke:"#000000"},text:{"font-size":14,text:"","text-anchor":"middle",ref:"path","ref-x":.5,"ref-dy":10,fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},{markup:'<g class="rotatable"><g class="scalable"><path/></g><text/></g>'}),ln=hn.define("basic.Rhombus",{attrs:{path:{d:"M 30 0 L 60 30 30 60 0 30 z"},text:{"ref-y":.5,"ref-dy":null,"y-alignment":"middle"}}}),un=Je.test("svgforeignobject"),cn=Ke.define("basic.TextBlock",{attrs:{rect:{fill:"#ffffff",stroke:"#000000",width:80,height:100},text:{fill:"#000000","font-size":14,"font-family":"Arial, helvetica, sans-serif"},".content":{text:"","ref-x":.5,"ref-y":.5,"y-alignment":"middle","x-alignment":"middle"}},content:""},{markup:['<g class="rotatable">','<g class="scalable"><rect/></g>',un?'<foreignObject class="fobj"><body xmlns="http://www.w3.org/1999/xhtml"><div class="content"/></body></foreignObject>':'<text class="content"/>',"</g>"].join(""),initialize:function(){this.listenTo(this,"change:size",this.updateSize),this.listenTo(this,"change:content",this.updateContent),this.updateSize(this,this.get("size")),this.updateContent(this,this.get("content")),Ke.prototype.initialize.apply(this,arguments)},updateSize:function(t,e){this.attr({".fobj":Nt({},e),div:{style:Nt({},e)}})},updateContent:function(t,e){un?this.attr({".content":{html:mt(e)}}):this.attr({".content":{text:e}})},setForeignObjectSize:function(){this.updateSize.apply(this,arguments)},setDivContent:function(){this.updateContent.apply(this,arguments)}}),dn=Ze.extend({presentationAttributes:un?Ze.prototype.presentationAttributes:Ze.addPresentationAttributes({content:["CONTENT"],size:["CONTENT"]}),initFlag:["RENDER","CONTENT"],confirmUpdate:function(){var t=Ze.prototype.confirmUpdate.apply(this,arguments);return this.hasFlag(t,"CONTENT")&&(this.updateContent(this.model),t=this.removeFlag(t,"CONTENT")),t},update:function(t,e){var n=this.model;if(un)Ze.prototype.update.call(this,n,e);else{var i=te(e||n.get("attrs"),".content");Ze.prototype.update.call(this,n,i),e&&!Kt(e,".content")||this.updateContent(n,e)}},updateContent:function(t,e){var n=se({},(e||t.get("attrs"))[".content"]);n=te(n,"text");var i=vt(t.get("content"),t.get("size"),n,{svgDocument:this.paper.svg}),r=ot({},".content",n,"/");r[".content"].text=i,Ze.prototype.update.call(this,t,r)}}),fn={Generic:Ke,Rect:Qe,TextView:tn,Text:en,Circle:nn,Ellipse:rn,Polygon:on,Polyline:sn,Image:an,Path:hn,Rhombus:ln,TextBlock:cn,TextBlockView:dn},pn=Ce.extend({markup:['<path class="connection" stroke="black" d="M 0 0 0 0"/>','<path class="marker-source" fill="black" stroke="black" d="M 0 0 0 0"/>','<path class="marker-target" fill="black" stroke="black" d="M 0 0 0 0"/>','<path class="connection-wrap" d="M 0 0 0 0"/>','<g class="labels"/>','<g class="marker-vertices"/>','<g class="marker-arrowheads"/>','<g class="link-tools"/>'].join(""),toolMarkup:['<g class="link-tool">','<g class="tool-remove" event="remove">','<circle r="11" />','<path transform="scale(.8) translate(-16, -16)" d="M24.778,21.419 19.276,15.917 24.777,10.415 21.949,7.585 16.447,13.087 10.945,7.585 8.117,10.415 13.618,15.917 8.116,21.419 10.946,24.248 16.447,18.746 21.948,24.248z" />',"<title>Remove link.</title>","</g>",'<g class="tool-options" event="link:options">','<circle r="11" transform="translate(25)"/>','<path fill="white" transform="scale(.55) translate(29, -16)" d="M31.229,17.736c0.064-0.571,0.104-1.148,0.104-1.736s-0.04-1.166-0.104-1.737l-4.377-1.557c-0.218-0.716-0.504-1.401-0.851-2.05l1.993-4.192c-0.725-0.91-1.549-1.734-2.458-2.459l-4.193,1.994c-0.647-0.347-1.334-0.632-2.049-0.849l-1.558-4.378C17.165,0.708,16.588,0.667,16,0.667s-1.166,0.041-1.737,0.105L12.707,5.15c-0.716,0.217-1.401,0.502-2.05,0.849L6.464,4.005C5.554,4.73,4.73,5.554,4.005,6.464l1.994,4.192c-0.347,0.648-0.632,1.334-0.849,2.05l-4.378,1.557C0.708,14.834,0.667,15.412,0.667,16s0.041,1.165,0.105,1.736l4.378,1.558c0.217,0.715,0.502,1.401,0.849,2.049l-1.994,4.193c0.725,0.909,1.549,1.733,2.459,2.458l4.192-1.993c0.648,0.347,1.334,0.633,2.05,0.851l1.557,4.377c0.571,0.064,1.148,0.104,1.737,0.104c0.588,0,1.165-0.04,1.736-0.104l1.558-4.377c0.715-0.218,1.399-0.504,2.049-0.851l4.193,1.993c0.909-0.725,1.733-1.549,2.458-2.458l-1.993-4.193c0.347-0.647,0.633-1.334,0.851-2.049L31.229,17.736zM16,20.871c-2.69,0-4.872-2.182-4.872-4.871c0-2.69,2.182-4.872,4.872-4.872c2.689,0,4.871,2.182,4.871,4.872C20.871,18.689,18.689,20.871,16,20.871z"/>',"<title>Link options.</title>","</g>","</g>"].join(""),doubleToolMarkup:void 0,vertexMarkup:['<g class="marker-vertex-group" transform="translate(<%= x %>, <%= y %>)">','<circle class="marker-vertex" idx="<%= idx %>" r="10" />','<path class="marker-vertex-remove-area" idx="<%= idx %>" d="M16,5.333c-7.732,0-14,4.701-14,10.5c0,1.982,0.741,3.833,2.016,5.414L2,25.667l5.613-1.441c2.339,1.317,5.237,2.107,8.387,2.107c7.732,0,14-4.701,14-10.5C30,10.034,23.732,5.333,16,5.333z" transform="translate(5, -33)"/>','<path class="marker-vertex-remove" idx="<%= idx %>" transform="scale(.8) translate(9.5, -37)" d="M24.778,21.419 19.276,15.917 24.777,10.415 21.949,7.585 16.447,13.087 10.945,7.585 8.117,10.415 13.618,15.917 8.116,21.419 10.946,24.248 16.447,18.746 21.948,24.248z">',"<title>Remove vertex.</title>","</path>","</g>"].join(""),arrowheadMarkup:['<g class="marker-arrowhead-group marker-arrowhead-group-<%= end %>">','<path class="marker-arrowhead" end="<%= end %>" d="M 26 0 L 0 13 L 26 26 z" />',"</g>"].join(""),defaultLabel:void 0,labelMarkup:void 0,_builtins:{defaultLabel:{markup:[{tagName:"rect",selector:"rect"},{tagName:"text",selector:"text"}],attrs:{text:{fill:"#000000",fontSize:14,textAnchor:"middle",yAlignment:"middle",pointerEvents:"none"},rect:{ref:"text",fill:"#ffffff",rx:3,ry:3,refWidth:1,refHeight:1,refX:0,refY:0}},position:{distance:.5}}},defaults:{type:"link",source:{},target:{}},isLink:function(){return!0},disconnect:function(t){return this.set({source:{x:0,y:0},target:{x:0,y:0}},t)},source:function(t,e,n){return void 0===t?Ot(this.get("source")):(r=t instanceof Ce?((i=Ot(e)||{}).id=t.id,n):Gt(t)?(i=t,e):((i=Ot(e)||{}).x=t.x,i.y=t.y,n),this.set("source",i,r));var i,r},target:function(t,e,n){return void 0===t?Ot(this.get("target")):(r=t instanceof Ce?((i=Ot(e)||{}).id=t.id,n):Gt(t)?(i=t,e):((i=Ot(e)||{}).x=t.x,i.y=t.y,n),this.set("target",i,r));var i,r},router:function(t,e,n){if(void 0===t){var i=this.get("router");return i?"object"==typeof i?Ot(i):i:this.get("manhattan")?{name:"orthogonal"}:null}var r="object"==typeof t||"function"==typeof t,o=r?t:{name:t,args:e},s=r?e:n;return this.set("router",o,s)},connector:function(t,e,n){if(void 0===t){var i=this.get("connector");return i?"object"==typeof i?Ot(i):i:this.get("smooth")?{name:"smooth"}:null}var r="object"==typeof t||"function"==typeof t,o=r?t:{name:t,args:e},s=r?e:n;return this.set("connector",o,s)},label:function(t,e,n){var i=this.labels();return(t=isFinite(t)&&null!==t?0|t:0)<0&&(t=i.length+t),arguments.length<=1?this.prop(["labels",t]):this.prop(["labels",t],e,n)},labels:function(t,e){return 0===arguments.length?(t=this.get("labels"),Array.isArray(t)?t.slice():[]):(Array.isArray(t)||(t=[]),this.set("labels",t,e))},insertLabel:function(t,e,n){if(!e)throw new Error("dia.Link: no label provided");var i=this.labels(),r=i.length;return(t=isFinite(t)&&null!==t?0|t:r)<0&&(t=r+t+1),i.splice(t,0,e),this.labels(i,n)},appendLabel:function(t,e){return this.insertLabel(-1,t,e)},removeLabel:function(t,e){var n=this.labels();return t=isFinite(t)&&null!==t?0|t:-1,n.splice(t,1),this.labels(n,e)},vertex:function(t,e,n){var i=this.vertices();if((t=isFinite(t)&&null!==t?0|t:0)<0&&(t=i.length+t),arguments.length<=1)return this.prop(["vertices",t]);var r=this._normalizeVertex(e);return this.prop(["vertices",t],r,n)},vertices:function(t,e){if(0===arguments.length)return t=this.get("vertices"),Array.isArray(t)?t.slice():[];Array.isArray(t)||(t=[]);for(var n=[],i=0;i<t.length;i++){var r=t[i],o=this._normalizeVertex(r);n.push(o)}return this.set("vertices",n,e)},insertVertex:function(t,e,n){if(!e)throw new Error("dia.Link: no vertex provided");var i=this.vertices(),r=i.length;(t=isFinite(t)&&null!==t?0|t:r)<0&&(t=r+t+1);var o=this._normalizeVertex(e);return i.splice(t,0,o),this.vertices(i,n)},removeVertex:function(t,e){var n=this.vertices();return t=isFinite(t)&&null!==t?0|t:-1,n.splice(t,1),this.vertices(n,e)},_normalizeVertex:function(t){return!Gt(t)?{x:t.x,y:t.y}:t},translate:function(e,n,t){return(t=t||{}).translateBy=t.translateBy||this.id,t.tx=e,t.ty=n,this.applyToPoints(function(t){return{x:(t.x||0)+e,y:(t.y||0)+n}},t)},scale:function(e,n,i,t){return this.applyToPoints(function(t){return z(t).scale(e,n,i).toJSON()},t)},applyToPoints:function(t,e){if(!jt(t))throw new TypeError("dia.Link: applyToPoints expects its first parameter to be a function.");var n={},i=this.attributes,r=i.source,o=i.target;r.id||(n.source=t(r)),o.id||(n.target=t(o));var s=this.vertices();return 0<s.length&&(n.vertices=s.map(t)),this.set(n,e)},getSourcePoint:function(){var t=this.getSourceCell();return t?t.getPointFromConnectedLink(this,"source"):new z(this.source())},getTargetPoint:function(){var t=this.getTargetCell();return t?t.getPointFromConnectedLink(this,"target"):new z(this.target())},getPointFromConnectedLink:function(){return this.getPolyline().pointAt(.5)},getPolyline:function(){var t=[this.getSourcePoint(),this.getTargetPoint()],e=this.vertices();return 0<e.length&&Array.prototype.push.apply(t,e.map(z)),new L(t)},getBBox:function(){return this.getPolyline().bbox()},reparent:function(t){var e;if(this.graph){var n=this.getSourceElement(),i=this.getTargetElement(),r=this.getParentCell();n&&i&&(e=n===i||n.isEmbeddedIn(i)?i:i.isEmbeddedIn(n)?n:this.graph.getCommonAncestor(n,i)),!r||e&&e.id===r.id||r.unembed(this,t),e&&e.embed(this,t)}return e},hasLoop:function(t){t=t||{};var e=this.attributes,n=e.source,i=e.target,r=n.id,o=i.id;if(!r||!o)return!1;var s=r===o;if(!s&&t.deep&&this.graph){var a=this.getSourceCell(),h=this.getTargetCell();s=a.isEmbeddedIn(h)||h.isEmbeddedIn(a)}return s},getSourceCell:function(){var t=this.graph,e=this.attributes.source;return e&&e.id&&t&&t.getCell(e.id)||null},getSourceElement:function(){var t=this,e={};do{if(e[t.id])return null;e[t.id]=!0,t=t.getSourceCell()}while(t&&t.isLink());return t},getTargetCell:function(){var t=this.graph,e=this.attributes.target;return e&&e.id&&t&&t.getCell(e.id)||null},getTargetElement:function(){var t=this,e={};do{if(e[t.id])return null;e[t.id]=!0,t=t.getTargetCell()}while(t&&t.isLink());return t},getRelationshipAncestor:function(){var t;if(this.graph){var e=[this,this.getSourceElement(),this.getTargetElement()].filter(function(t){return!!t});t=this.graph.getCommonAncestor.apply(this.graph,e)}return t||null},isRelationshipEmbeddedIn:function(t){var e=ue(t)||le(t)?t:t.id,n=this.getRelationshipAncestor();return!!n&&(n.id===e||n.isEmbeddedIn(e))},_getDefaultLabel:function(){var t=this.get("defaultLabel")||this.defaultLabel||{},e={};return e.markup=t.markup||this.get("labelMarkup")||this.labelMarkup,e.position=t.position,e.attrs=t.attrs,e.size=t.size,e}},{endsEqual:function(t,e){var n=t.port===e.port||!t.port&&!e.port;return t.id===e.id&&n}}),gn=He.define("standard.Rectangle",{attrs:{body:{refWidth:"100%",refHeight:"100%",strokeWidth:2,stroke:"#000000",fill:"#FFFFFF"},label:{textVerticalAnchor:"middle",textAnchor:"middle",refX:"50%",refY:"50%",fontSize:14,fill:"#333333"}}},{markup:[{tagName:"rect",selector:"body"},{tagName:"text",selector:"label"}]}),vn=He.define("standard.Circle",{attrs:{body:{refCx:"50%",refCy:"50%",refR:"50%",strokeWidth:2,stroke:"#333333",fill:"#FFFFFF"},label:{textVerticalAnchor:"middle",textAnchor:"middle",refX:"50%",refY:"50%",fontSize:14,fill:"#333333"}}},{markup:[{tagName:"circle",selector:"body"},{tagName:"text",selector:"label"}]}),mn=He.define("standard.Ellipse",{attrs:{body:{refCx:"50%",refCy:"50%",refRx:"50%",refRy:"50%",strokeWidth:2,stroke:"#333333",fill:"#FFFFFF"},label:{textVerticalAnchor:"middle",textAnchor:"middle",refX:"50%",refY:"50%",fontSize:14,fill:"#333333"}}},{markup:[{tagName:"ellipse",selector:"body"},{tagName:"text",selector:"label"}]}),yn=He.define("standard.Path",{attrs:{body:{refD:"M 0 0 L 10 0 10 10 0 10 Z",strokeWidth:2,stroke:"#333333",fill:"#FFFFFF"},label:{textVerticalAnchor:"middle",textAnchor:"middle",refX:"50%",refY:"50%",fontSize:14,fill:"#333333"}}},{markup:[{tagName:"path",selector:"body"},{tagName:"text",selector:"label"}]}),wn=He.define("standard.Polygon",{attrs:{body:{refPoints:"0 0 10 0 10 10 0 10",strokeWidth:2,stroke:"#333333",fill:"#FFFFFF"},label:{textVerticalAnchor:"middle",textAnchor:"middle",refX:"50%",refY:"50%",fontSize:14,fill:"#333333"}}},{markup:[{tagName:"polygon",selector:"body"},{tagName:"text",selector:"label"}]}),bn=He.define("standard.Polyline",{attrs:{body:{refPoints:"0 0 10 0 10 10 0 10 0 0",strokeWidth:2,stroke:"#333333",fill:"#FFFFFF"},label:{textVerticalAnchor:"middle",textAnchor:"middle",refX:"50%",refY:"50%",fontSize:14,fill:"#333333"}}},{markup:[{tagName:"polyline",selector:"body"},{tagName:"text",selector:"label"}]}),xn=He.define("standard.Image",{attrs:{image:{refWidth:"100%",refHeight:"100%"},label:{textVerticalAnchor:"top",textAnchor:"middle",refX:"50%",refY:"100%",refY2:10,fontSize:14,fill:"#333333"}}},{markup:[{tagName:"image",selector:"image"},{tagName:"text",selector:"label"}]}),An=He.define("standard.BorderedImage",{attrs:{border:{refWidth:"100%",refHeight:"100%",stroke:"#333333",strokeWidth:2},background:{refWidth:-1,refHeight:-1,x:.5,y:.5,fill:"#FFFFFF"},image:{refWidth:-1,refHeight:-1,x:.5,y:.5},label:{textVerticalAnchor:"top",textAnchor:"middle",refX:"50%",refY:"100%",refY2:10,fontSize:14,fill:"#333333"}}},{markup:[{tagName:"rect",selector:"background",attributes:{stroke:"none"}},{tagName:"image",selector:"image"},{tagName:"rect",selector:"border",attributes:{fill:"none"}},{tagName:"text",selector:"label"}]}),Pn=He.define("standard.EmbeddedImage",{attrs:{body:{refWidth:"100%",refHeight:"100%",stroke:"#333333",fill:"#FFFFFF",strokeWidth:2},image:{refWidth:"30%",refHeight:-20,x:10,y:10,preserveAspectRatio:"xMidYMin"},label:{textVerticalAnchor:"top",textAnchor:"left",refX:"30%",refX2:20,refY:10,fontSize:14,fill:"#333333"}}},{markup:[{tagName:"rect",selector:"body"},{tagName:"image",selector:"image"},{tagName:"text",selector:"label"}]}),Sn=He.define("standard.InscribedImage",{attrs:{border:{refRx:"50%",refRy:"50%",refCx:"50%",refCy:"50%",stroke:"#333333",strokeWidth:2},background:{refRx:"50%",refRy:"50%",refCx:"50%",refCy:"50%",fill:"#FFFFFF"},image:{refWidth:"68%",refHeight:"68%",refX:"16%",refY:"16%",preserveAspectRatio:"xMidYMid"},label:{textVerticalAnchor:"top",textAnchor:"middle",refX:"50%",refY:"100%",refY2:10,fontSize:14,fill:"#333333"}}},{markup:[{tagName:"ellipse",selector:"background"},{tagName:"image",selector:"image"},{tagName:"ellipse",selector:"border",attributes:{fill:"none"}},{tagName:"text",selector:"label"}]}),kn=He.define("standard.HeaderedRectangle",{attrs:{body:{refWidth:"100%",refHeight:"100%",strokeWidth:2,stroke:"#000000",fill:"#FFFFFF"},header:{refWidth:"100%",height:30,strokeWidth:2,stroke:"#000000",fill:"#FFFFFF"},headerText:{textVerticalAnchor:"middle",textAnchor:"middle",refX:"50%",refY:15,fontSize:16,fill:"#333333"},bodyText:{textVerticalAnchor:"middle",textAnchor:"middle",refX:"50%",refY:"50%",refY2:15,fontSize:14,fill:"#333333"}}},{markup:[{tagName:"rect",selector:"body"},{tagName:"rect",selector:"header"},{tagName:"text",selector:"headerText"},{tagName:"text",selector:"bodyText"}]}),En=He.define("standard.Cylinder",{attrs:{body:{lateralArea:10,fill:"#FFFFFF",stroke:"#333333",strokeWidth:2},top:{refCx:"50%",cy:10,refRx:"50%",ry:10,fill:"#FFFFFF",stroke:"#333333",strokeWidth:2},label:{textVerticalAnchor:"middle",textAnchor:"middle",refX:"50%",refY:"100%",refY2:15,fontSize:14,fill:"#333333"}}},{markup:[{tagName:"path",selector:"body"},{tagName:"ellipse",selector:"top"},{tagName:"text",selector:"label"}],topRy:function(t,e){if(void 0===t)return this.attr("body/lateralArea");var n={lateralArea:t},i=pt(t)?{refCy:t,refRy:t,cy:null,ry:null}:{refCy:null,refRy:null,cy:t,ry:t};return this.attr({body:n,top:i},e)}},{attributes:{lateralArea:{set:function(t,e){var n=pt(t);n&&(t=parseFloat(t)/100);var i=e.x,r=e.y,o=e.width,s=e.height,a=o/2,h=n?s*t:t,l=K.KAPPA,u=l*a,c=l*(n?s*t:t),d=i+o/2,f=i+o,p=r+h,g=p-h,v=r+s-h,m=r+s;return{d:["M",i,p,"L",i,v,"C",i,v+c,d-u,m,d,m,"C",d+u,m,f,v+c,f,v,"L",f,p,"C",f,p-c,d+u,g,d,g,"C",d-u,g,i,p-c,i,p,"Z"].join(" ")}}}}}),Cn=Je.test("svgforeignobject")?{tagName:"foreignObject",selector:"foreignObject",attributes:{overflow:"hidden"},children:[{tagName:"div",namespaceURI:"http://www.w3.org/1999/xhtml",selector:"label",style:{width:"100%",height:"100%",position:"static",backgroundColor:"transparent",textAlign:"center",margin:0,padding:"0px 5px",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center"}}]}:{tagName:"text",selector:"label",attributes:{"text-anchor":"middle"}},Tn={Rectangle:gn,Circle:vn,Ellipse:mn,Path:yn,Polygon:wn,Polyline:bn,Image:xn,BorderedImage:An,EmbeddedImage:Pn,InscribedImage:Sn,HeaderedRectangle:kn,Cylinder:En,TextBlock:He.define("standard.TextBlock",{attrs:{body:{refWidth:"100%",refHeight:"100%",stroke:"#333333",fill:"#ffffff",strokeWidth:2},foreignObject:{refWidth:"100%",refHeight:"100%"},label:{style:{fontSize:14}}}},{markup:[{tagName:"rect",selector:"body"},Cn]},{attributes:{text:{set:function(t,e,n,i){if(!(n instanceof HTMLElement)){var r=i.style||{},o={text:t,width:-5,height:"100%"},s=Nt({textVerticalAnchor:"middle"},r);return Ee.textWrap.set.call(this,o,e,n,s),{fill:r.color||null}}n.textContent=t},position:function(t,e,n){if(n instanceof SVGElement)return e.center()}}}}),Link:pn.define("standard.Link",{attrs:{line:{connection:!0,stroke:"#333333",strokeWidth:2,strokeLinejoin:"round",targetMarker:{type:"path",d:"M 10 -5 0 0 10 5 z"}},wrapper:{connection:!0,strokeWidth:10,strokeLinejoin:"round"}}},{markup:[{tagName:"path",selector:"wrapper",attributes:{fill:"none",cursor:"pointer",stroke:"transparent","stroke-linecap":"round"}},{tagName:"path",selector:"line",attributes:{fill:"none","pointer-events":"none"}}]}),DoubleLink:pn.define("standard.DoubleLink",{attrs:{line:{connection:!0,stroke:"#DDDDDD",strokeWidth:4,strokeLinejoin:"round",targetMarker:{type:"path",stroke:"#000000",d:"M 10 -3 10 -10 -2 0 10 10 10 3"}},outline:{connection:!0,stroke:"#000000",strokeWidth:6,strokeLinejoin:"round"}}},{markup:[{tagName:"path",selector:"outline",attributes:{fill:"none"}},{tagName:"path",selector:"line",attributes:{fill:"none"}}]}),ShadowLink:pn.define("standard.ShadowLink",{attrs:{line:{connection:!0,stroke:"#FF0000",strokeWidth:20,strokeLinejoin:"round",targetMarker:{type:"path",stroke:"none",d:"M 0 -10 -10 0 0 10 z"},sourceMarker:{type:"path",stroke:"none",d:"M -10 -10 0 0 -10 10 0 10 0 -10 z"}},shadow:{connection:!0,refX:3,refY:6,stroke:"#000000",strokeOpacity:.2,strokeWidth:20,strokeLinejoin:"round",targetMarker:{type:"path",d:"M 0 -10 -10 0 0 10 z",stroke:"none"},sourceMarker:{type:"path",stroke:"none",d:"M -10 -10 0 0 -10 10 0 10 0 -10 z"}}}},{markup:[{tagName:"path",selector:"shadow",attributes:{fill:"none"}},{tagName:"path",selector:"line",attributes:{fill:"none"}}]})},Ln=["arc","gap","cubic"],Mn=["smooth"],Nn=1/3,Vn=2/3;function Fn(t,e,n){var r=[].concat(t,n,e);return r.reduce(function(t,e,n){var i=r[n+1];return null!=i&&(t[n]=P(e,i)),t},[])}function _n(){for(var t=this._jumpOverUpdateList,e=0;e<t.length;e++)t[e].update()}function Bn(t,e){return P(t,e).squaredLength()}function Rn(C,T,L,M){var N,V=new D;return N=D.createSegment("M",C[0].start),V.appendSegment(N),Ut(C).forEach(function(t,e){if(t.isJump){var n,i,r,o;if("arc"===L){n=-90,i=t.start.difference(t.end);var s=Number(i.x<0||0===i.x&&i.y<0);s&&(n+=180);var a,h=t.midpoint(),l=new O(h,t.end).rotate(h,n);r=(a=new O(t.start,h)).pointAt(2/3).rotate(t.start,n),o=l.pointAt(1/3).rotate(l.end,-n),N=D.createSegment("C",r,o,l.end),V.appendSegment(N),a=new O(h,t.end),r=l.pointAt(1/3).rotate(l.end,n),o=a.pointAt(1/3).rotate(t.end,-n),N=D.createSegment("C",r,o,t.end),V.appendSegment(N)}else if("gap"===L)N=D.createSegment("M",t.end),V.appendSegment(N);else if("cubic"===L){n=t.start.theta(t.end);var u=.6*T,c=1.35*T;i=t.start.difference(t.end),(s=Number(i.x<0||0===i.x&&i.y<0))&&(c*=-1),r=z(t.start.x+u,t.start.y+c).rotate(t.start,n),o=z(t.end.x-u,t.end.y+c).rotate(t.end,n),N=D.createSegment("C",r,o,t.end),V.appendSegment(N)}}else{var d=C[e+1];0==M||!d||d.isJump?(N=D.createSegment("L",t.end),V.appendSegment(N)):(f=M,p=V,g=t.end,v=t.start,m=d.end,w=g.distance(v)/2,b=g.distance(m)/2,x=-Math.min(f,w),A=-Math.min(f,b),P=g.clone().move(v,x).round(),S=g.clone().move(m,A).round(),k=new z(Nn*P.x+Vn*g.x,Vn*g.y+Nn*P.y),E=new z(Nn*S.x+Vn*g.x,Vn*g.y+Nn*S.y),y=D.createSegment("L",P),p.appendSegment(y),y=D.createSegment("C",k,E,S),p.appendSegment(y))}var f,p,g,v,m,y,w,b,x,A,P,S,k,E}),V}var On={jumpover:function(t,e,n,i){var r,o;null==(o=(r=this).paper._jumpOverUpdateList)&&(o=r.paper._jumpOverUpdateList=[],r.paper.on("cell:pointerup",_n),r.paper.model.on("reset",function(){o=r.paper._jumpOverUpdateList=[]})),o.indexOf(r)<0&&(o.push(r),r.listenToOnce(r.model,"change:connector remove",function(){o.splice(o.indexOf(r),1)}));var s=i.raw,a=i.size||5,h=i.jump&&(""+i.jump).toLowerCase(),l=i.radius||0,u=i.ignoreConnectors||Mn;-1===Ln.indexOf(h)&&(h=Ln[0]);var c=this.paper,d=c.model.getLinks();if(1===d.length)return Rn(Fn(t,e,n),a,h,l);var f=this.model,p=d.indexOf(f),g=c.options.defaultConnector||{},v=d.filter(function(t,e){var n=t.get("connector")||g;return!(Ut(u).includes(n.name)||p<e&&"jumpover"===n.name)}),m=v.map(function(t){return c.findViewByModel(t)}),y=Fn(t,e,n),w=m.map(function(t){return null==t?[]:t===this?y:Fn(t.sourcePoint,t.targetPoint,t.route)},this),b=Rn(y.reduce(function(t,s){var l,u,c,e=v.reduce(function(t,e,n){if(e!==f){var i=(r=s,o=w[n],Ut(o).reduce(function(t,e){var n=r.intersection(e);return n&&t.push(n),t},[]));t.push.apply(t,i)}var r,o;return t},[]).sort(function(t,e){return Bn(s.start,t)-Bn(s.start,e)});return 0<e.length?t.push.apply(t,(l=s,c=a,(u=e).reduce(function(t,e,n){if(!0===e.skip)return t;var i=t.pop()||l,r=S(e).move(i.start,-c),o=S(e).move(i.start,+c),s=u[n+1];if(null!=s){var a=o.distance(s);a<=c&&(o=s.move(i.start,a),s.skip=!0)}else if(r.distance(i.end)<2*c+1)return t.push(i),t;if(o.distance(i.start)<2*c+1)return t.push(i),t;var h=P(r,o);return h.isJump=!0,t.push(P(i.start,r),h,P(o,i.end)),t},[]))):t.push(s),t},[]),a,h,l);return s?b:b.serialize()},normal:function(t,e,n,i){var r=i&&i.raw,o=[t].concat(n).concat([e]),s=new L(o),a=new D(s);return r?a:a.serialize()},rounded:function(t,e,n,i){i||(i={});var r,o=i.radius||10,s=i.raw,a=new D;r=D.createSegment("M",t),a.appendSegment(r);for(var h,l,u,c,d,f,p,g,v,m,y,w=0,b=n.length;w<b;w++)h=new z(n[w]),l=n[w-1]||t,u=n[w+1]||e,c=d||h.distance(l)/2,d=h.distance(u)/2,f=-Math.min(o,c),p=-Math.min(o,d),g=h.clone().move(l,f).round(),v=h.clone().move(u,p).round(),m=new z(1/3*g.x+2/3*h.x,2/3*h.y+1/3*g.y),y=new z(1/3*v.x+2/3*h.x,2/3*h.y+1/3*v.y),r=D.createSegment("L",g),a.appendSegment(r),r=D.createSegment("C",m,y,v),a.appendSegment(r);return r=D.createSegment("L",e),a.appendSegment(r),s?a:a.serialize()},smooth:function(t,e,n,i){var r,o=i&&i.raw;if(n&&0!==n.length){var s=[t].concat(n).concat([e]),a=g.throughPoints(s);r=new D(a)}else{var h;if(r=new D,h=D.createSegment("M",t),r.appendSegment(h),Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)){var l=(t.x+e.x)/2;h=D.createSegment("C",l,t.y,l,e.y,e.x,e.y),r.appendSegment(h)}else{var u=(t.y+e.y)/2;h=D.createSegment("C",t.x,u,e.x,u,e.x,e.y),r.appendSegment(h)}}return o?r:r.serialize()}},Dn={stroke:{defaultOptions:{padding:3,rx:0,ry:0,attrs:{"stroke-width":3,stroke:"#FEB663"}},_views:{},getHighlighterId:function(t,e){return t.id+JSON.stringify(e)},removeHighlighter:function(t){this._views[t]&&(this._views[t].remove(),this._views[t]=null)},highlight:function(t,e,n){var i=this.getHighlighterId(e,n);if(!this._views[i]){var r,o=Vt(n||{},this.defaultOptions),s=K(e);try{var a=s.convertToPathData()}catch(t){r=s.bbox(!0),a=K.rectToPath(Nt({},o,r))}var h=K("path").attr({d:a,"pointer-events":"none","vector-effect":"non-scaling-stroke",fill:"none"}).attr(o.attrs);if(t.isNodeConnection(e))h.attr("d",t.getSerializedConnection());else{var l=s.getTransformToElement(t.el),u=o.padding;if(u){r||(r=s.bbox(!0));var c=r.x+r.width/2,d=r.y+r.height/2;r=K.transformRect(r,l);var f=Math.max(r.width,1),p=Math.max(r.height,1),g=(f+u)/f,v=(p+u)/p,m=K.createSVGMatrix({a:g,b:0,c:0,d:v,e:c-g*c,f:d-v*d});l=l.multiply(m)}h.transform(l)}var y=this._views[i]=new Ye({svgElement:!0,className:"highlight-stroke",el:h.node}),w=this.removeHighlighter.bind(this,i),b=t.model;y.listenTo(b,"remove",w),y.listenTo(b.graph,"reset",w),t.vel.append(h)}},unhighlight:function(t,e,n){this.removeHighlighter(this.getHighlighterId(e,n))}},opacity:{highlight:function(t,e){K(e).addClass(tt("highlight-opacity"))},unhighlight:function(t,e){K(e).removeClass(tt("highlight-opacity"))}},addClass:{className:tt("highlighted"),highlight:function(t,e,n){var i=(n||{}).className||this.className;K(e).addClass(i)},unhighlight:function(t,e,n){var i=(n||{}).className||this.className;K(e).removeClass(i)}}};function zn(t,e,n){if(!isFinite(n))return t;var i=t.distance(e);return 0===n&&0<i?t:t.move(e,-Math.min(n,i-1))}function In(t){var e=t.getAttribute("stroke-width");return null===e?0:parseFloat(e)||0}function jn(t,e,n,i){var r=e.getNodeBBox(n);i.stroke&&r.inflate(In(n)/2);var o=t.intersect(r);return zn(o?t.start.chooseClosest(o):t.end,t.start,i.offset)}var Gn="segmentSubdivisons",Un="shapeBBox";var qn={anchor:function(t,e,n,i){return zn(t.end,t.start,i.offset)},bbox:jn,rectangle:function(t,e,n,i){var r=e.model.angle();if(0===r)return jn(t,e,n,i);var o=e.getNodeUnrotatedBBox(n);i.stroke&&o.inflate(In(n)/2);var s=o.center(),a=t.clone().rotate(s,r),h=a.setLength(1e6).intersect(o);return zn(h?a.start.chooseClosest(h).rotate(s,-r):t.end,t.start,i.offset)},boundary:function(t,e,n,i){var r,o,s=i.selector,a=t.end;if(r="string"==typeof s?e.findBySelector(s)[0]:Array.isArray(s)?rt(n,s):function(t){if(!t)return null;var e=t;do{var n=e.tagName;if("string"!=typeof n)return null;if("G"===(n=n.toUpperCase()))e=e.firstElementChild;else{if("TITLE"!==n)break;e=e.nextElementSibling}}while(e);return e}(n),!K.isSVGGraphicsElement(r)){if(r===n||!K.isSVGGraphicsElement(n))return a;r=n}var h,l=e.getNodeShape(r),u=e.getNodeMatrix(r),c=e.getRootTranslateMatrix(),d=e.getRootRotateMatrix(),f=c.multiply(d).multiply(u),p=f.inverse(),g=K.transformLine(t,p),v=g.start.clone(),m=e.getNodeData(r);if(!1===i.insideout&&(m[Un]||(m[Un]=l.bbox()),m[Un].containsPoint(v)))return a;if(l instanceof D){var y=i.precision||2;m[Gn]||(m[Gn]=l.getSegmentSubdivisions({precision:y})),h={precision:y,segmentSubdivisions:m[Gn]}}!0===i.extrapolate&&g.setLength(1e6),(o=g.intersect(l,h))?K.isArray(o)&&(o=v.chooseClosest(o)):!0===i.sticky&&(o=l instanceof X?l.pointNearestToPoint(v):l instanceof x?l.intersectionWithLineFromCenterToPoint(v):l.closestPoint(v,h));var w=o?K.transformPoint(o,f):a,b=i.offset||0;return i.stroke&&(b+=In(r)/2),zn(w,t.start,b)}};function Hn(t,e){return 0===e?"0%":Math.round(t/e*100)+"%"}function $n(r){return function(t,e,n,i){return(e.isNodeConnection(n)?Xn:Yn)(r,t,e,n,i)}}function Yn(t,e,n,i,r){var o=n.model.angle(),s=n.getNodeUnrotatedBBox(i),a=n.model.getBBox().center();r.rotate(a,o);var h=r.x-s.x,l=r.y-s.y;return t&&(h=Hn(h,s.width),l=Hn(l,s.height)),e.anchor={name:"topLeft",args:{dx:h,dy:l,rotate:!0}},e}function Xn(t,e,n,i,r){var o=n.getConnection();if(!o)return e;var s=o.closestPointLength(r);if(t){var a=o.length();e.anchor={name:"connectionRatio",args:{ratio:s/a}}}else e.anchor={name:"connectionLength",args:{length:s}};return e}var Wn=ce,Zn=$n(!1),Jn=$n(!0),Kn={useDefaults:Wn,pinAbsolute:Zn,pinRelative:Jn},Qn={N:"S",S:"N",E:"W",W:"E"},ti={N:-Math.PI/2*3,S:-Math.PI/2,E:0,W:Math.PI};function ei(t,e,n){var i=new z(t.x,e.y);return n.containsPoint(i)&&(i=new z(e.x,t.y)),i}function ni(t,e){return t["W"===e||"E"===e?"width":"height"]}function ii(t,e){return t.x===e.x?t.y>e.y?"N":"S":t.y===e.y?t.x>e.x?"W":"E":null}function ri(t){return new X(t.x,t.y,0,0)}function oi(t){var e=xt(t.padding||t.elementPadding||20);return{x:-e.left,y:-e.top,width:e.left+e.right,height:e.top+e.bottom}}function si(t,e){return t.sourceBBox.clone().moveAndExpand(oi(e))}function ai(t,e){return t.targetBBox.clone().moveAndExpand(oi(e))}function hi(t,e,n){var i=new z(t.x,e.y),r=new z(e.x,t.y),o=ii(t,i),s=ii(t,r),a=Qn[n],h=o===n||o!==a&&(s===a||s!==n)?i:r;return{points:[h],direction:ii(h,e)}}function li(t,e,n){var i=ei(t,e,n);return{points:[i],direction:ii(i,e)}}function ui(e,t,n,i){var r,o={},s=[new z(e.x,t.y),new z(t.x,e.y)],a=s.filter(function(t){return!n.containsPoint(t)}),h=a.filter(function(t){return ii(t,e)!==i});if(0<h.length)r=(r=h.filter(function(t){return ii(e,t)===i}).pop())||h[0],o.points=[r],o.direction=ii(r,t);else{r=Wt(s,a)[0];var l=new z(t).move(r,-ni(n,i)/2),u=ei(l,e,n);o.points=[u,l],o.direction=ii(l,t)}return o}function ci(t,e,n,i){var r=li(e,t,i),o=r.points[0];if(n.containsPoint(o)){var s=(r=li(t,e,n)).points[0];if(i.containsPoint(s)){var a=new z(t).move(s,-ni(n,ii(t,s))/2),h=new z(e).move(o,-ni(i,ii(e,o))/2),l=new O(a,h).midpoint(),u=li(t,l,n),c=hi(l,e,u.direction);r.points=[u.points[0],c.points[0]],r.direction=c.direction}}return r}function di(t,e,n,i,r){var o,s,a,h={},l=n.union(i).inflate(1),u=l.center().distance(e)>l.center().distance(t),c=u?e:t,d=u?t:e;return s=ei(o=r?(o=z.fromPolar(l.width+l.height,ti[r],c),l.pointNearestToPoint(o).move(o,-1)):l.pointNearestToPoint(c).move(c,1),d,l),o.round().equals(s.round())?(s=z.fromPolar(l.width+l.height,A(o.theta(c))+Math.PI/2,d),a=ei(o,s=l.pointNearestToPoint(s).move(d,1).round(),l),h.points=u?[s,a,o]:[o,a,s]):h.points=u?[s,o]:[o,s],h.direction=ii(u?o:s,e),h}function fi(t,e,n){var i,r,o,s,a,h=si(n,e),l=ai(n,e),u=(r=e,(i=n).sourceAnchor?i.sourceAnchor:si(i,r).center()),c=(s=e,(o=n).targetAnchor?o.targetAnchor:ai(o,s).center());h=h.union(ri(u)),l=l.union(ri(c)),(t=Ut(t).map(z)).unshift(u),t.push(c);for(var d=[],f=0,p=t.length-1;f<p;f++){var g=null,v=t[f],m=t[f+1],y=!!ii(v,m);if(0===f)f+1===p?h.intersect(l.clone().inflate(1))?g=di(v,m,h,l):y||(g=ci(v,m,h,l)):h.containsPoint(m)?g=di(v,m,h,ri(m).moveAndExpand(oi(e))):y||(g=li(v,m,h));else if(f+1===p){var w=y&&ii(m,v)===a;l.containsPoint(v)||w?g=di(v,m,ri(v).moveAndExpand(oi(e)),l,a):y||(g=ui(v,m,l,a))}else y||(g=hi(v,m,a));a=g?(Array.prototype.push.apply(d,g.points),g.direction):ii(v,m),f+1<p&&d.push(m)}return d}var pi={step:10,maximumLoops:2e3,precision:1,maxAllowedDirectionChange:90,perpendicular:!0,excludeEnds:[],excludeTypes:["basic.Text"],startDirections:["top","right","bottom","left"],endDirections:["top","right","bottom","left"],directionMap:{top:{x:0,y:-1},right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0}},cost:function(){return this.step},directions:function(){var t=this.step,e=this.cost();return[{offsetX:t,offsetY:0,cost:e},{offsetX:0,offsetY:t,cost:e},{offsetX:-t,offsetY:0,cost:e},{offsetX:0,offsetY:-t,cost:e}]},penalties:function(){return{0:0,45:this.step/2,90:this.step/2}},paddingBox:function(){var t=this.step;return{x:-t,y:-t,width:2*t,height:2*t}},fallbackRouter:function(t,e,n){if(!jt(fi))throw new Error("Manhattan requires the orthogonal router as default fallback.");return fi(t,Nt({},pi,e),n)},fallbackRoute:function(t,e,n){return null},draggingRoute:null};function gi(t){this.map={},this.options=t,this.mapGridSize=100}function vi(){this.items=[],this.hash={},this.values={},this.OPEN=1,this.CLOSE=2}function mi(t,e){return e&&e.paddingBox?t.sourceBBox.clone().moveAndExpand(e.paddingBox):t.sourceBBox.clone()}function yi(t,e){return e&&e.paddingBox?t.targetBBox.clone().moveAndExpand(e.paddingBox):t.targetBBox.clone()}function wi(t,e){return t.sourceAnchor?t.sourceAnchor:mi(t,e).center()}function bi(t,e,n,i,r){var o,s,a,h,l,u,c,d,f,p,g=360/n,v=t.theta((o=t,s=e,a=i,h=r.step,l=s.x-o.x,u=s.y-o.y,c=l/a.x,d=u/a.y,f=c*h,p=d*h,new z(o.x+f,o.y+p))),m=b(v+g/2);return g*Math.floor(m/g)}function xi(t,e){var n=Math.abs(t-e);return 180<n?360-n:n}function Ai(t,e){if(!t)return e;var n=Math.abs(t),i=Math.round(n/e);return i?e+(n-i*e)/i:n}function Pi(t,e){return t.round(e)}function Si(t,e,n){return Pi((i=t.clone(),o=(r=e).source,s=v(i.x-o.x,r.x)+o.x,a=v(i.y-o.y,r.y)+o.y,new z(s,a)),n);var i,r,o,s,a}function ki(t){return t.clone().toString()}function Ei(t){return new z(0===t.x?0:Math.abs(t.x)/t.x,0===t.y?0:Math.abs(t.y)/t.y)}function Ci(t,e,n,i,r,o,s){for(var a,h=[],l=Ei(r.difference(n)),u=ki(n),c=t[u];c;){var d=Ei((a=e[u]).difference(c));d.equals(l)||(h.unshift(a),l=d),c=t[u=ki(c)]}var f=e[u];return Ei(f.difference(i)).equals(l)||h.unshift(f),h}function Ti(t,e){for(var n=1/0,i=0,r=e.length;i<r;i++){var o=t.manhattanDistance(e[i]);o<n&&(n=o)}return n}function Li(d,f,t,p,e){var g=e.precision,v=e.directionMap,m=d.difference(f.center()),n=he(v)?Object.keys(v):[],y=Ut(t),i=n.reduce(function(t,e){if(y.includes(e)){for(var n,i=v[e],r=new z(d.x+i.x*(Math.abs(m.x)+f.width),d.y+i.y*(Math.abs(m.y)+f.height)),o=new O(d,r).intersect(f)||[],s=o.length,a=null,h=0;h<s;h++){var l=o[h],u=d.squaredDistance(l);(void 0===n||n<u)&&(n=u,a=l)}if(a){var c=Si(a,p,g);f.containsPoint(c)&&(c=Si(c.offset(i.x*p.x,i.y*p.y),p,g)),t.push(c)}}return t},[]);return f.containsPoint(d)||i.push(Si(d,p,g)),i}function Mi(t,e,n,i){var r,o,s,a,h=i.precision;r=Pi(t instanceof X?wi(this,i).clone():t.clone(),h),o=Pi(e instanceof X?(s=this,a=i,s.targetAnchor?s.targetAnchor:yi(s,a).center()).clone():e.clone(),h);var l,u,c,d,f,p,g,v,m,y,w=(l=i.step,c=o,{source:(u=r).clone(),x:Ai(c.x-u.x,l),y:Ai(c.y-u.y,l)});if(p=t instanceof X?Li(d=r,t,i.startDirections,w,i):[d=r],g=e instanceof X?Li(f=o,e,i.endDirections,w,i):[f=o],p=p.filter(n.isPointAccessible,n),g=g.filter(n.isPointAccessible,n),0<p.length&&0<g.length){for(var b=new vi,x={},A={},P={},S=0,k=p.length;S<k;S++){var E=p[S],C=ki(E);b.add(C,Ti(E,g)),x[C]=E,P[C]=0}var T,L,M=i.previousDirectionAngle,N=void 0===M,V=i.directions;v=w,y=(m=i).step,Ut(m.directions).forEach(function(t){t.gridOffsetX=t.offsetX/y*v.x,t.gridOffsetY=t.offsetY/y*v.y});for(var F=V.length,_=Ut(g).reduce(function(t,e){var n=ki(e);return t.push(n),t},[]),B=i.maximumLoops;!b.isEmpty()&&0<B;){var R,O=b.pop(),D=x[O],z=A[O],I=P[O],j=void 0===z,G=D.equals(d);R=j?N?G?null:bi(d,D,F,w,i):M:bi(z,D,F,w,i);var U=It(p,g);if(!(j&&U)&&0<=_.indexOf(O))return i.previousDirectionAngle=R,Ci(A,x,D,d,f);for(S=0;S<F;S++){var q=(T=V[S]).angle;if(L=xi(R,q),N&&G||!(L>i.maxAllowedDirectionChange)){var H=Si(D.clone().offset(T.gridOffsetX,T.gridOffsetY),w,h),$=ki(H);if(!b.isClose($)&&n.isPointAccessible(H)){if(0<=_.indexOf($))if(!H.equals(f))if(xi(q,bi(H,f,F,w,i))>i.maxAllowedDirectionChange)continue;var Y=I+T.cost+(G?0:i.penalties[L]);(!b.isOpen($)||Y<P[$])&&(x[$]=H,A[$]=D,P[$]=Y,b.add($,Y+Ti(H,g)))}}}B--}}return i.fallbackRoute.call(this,d,f,i)}function Ni(t,e,n){!function(t){if(t.directions=Qt(t,"directions"),t.penalties=Qt(t,"penalties"),t.paddingBox=Qt(t,"paddingBox"),t.padding=Qt(t,"padding"),t.padding){var e=xt(t.padding);t.paddingBox={x:-e.left,y:-e.top,width:e.left+e.right,height:e.top+e.bottom}}Ut(t.directions).forEach(function(t){var e=new z(0,0),n=new z(t.offsetX,t.offsetY);t.angle=b(e.theta(n))})}(e),n.options.perpendicular=!!e.perpendicular;for(var i,r,o=mi(n,e),s=yi(n,e),a=wi(n,e),h=new gi(e).build(n.paper.model,n.model),l=Ut(t).map(z),u=[],c=a,d=0,f=l.length;d<=f;d++){var p=null;if(r=i||o,!(i=l[d]))if(i=s,(!n.model.get("source").id||!n.model.get("target").id)&&jt(e.draggingRoute)){var g=r===o?a:r,v=i.origin();p=e.draggingRoute.call(n,g,v,e)}if(null===(p=p||Mi.call(n,r,i,h,e)))return e.fallbackRouter(t,e,n);var m=p[0];m&&m.equals(c)&&p.shift(),c=p[p.length-1]||c,Array.prototype.push.apply(u,p)}return u}gi.prototype.build=function(r,o){var c=this.options,d=Ut(c.excludeEnds).reduce(function(t,e){var n=o.get(e);if(n){var i=r.getCell(n.id);i&&t.push(i)}return t},[]),f=[],t=r.getCell(o.get("source").id);t&&(f=Jt(f,t.getAncestors().map(function(t){return t.id})));var e=r.getCell(o.get("target").id);e&&(f=Jt(f,e.getAncestors().map(function(t){return t.id})));var p=this.mapGridSize;return r.getElements().reduce(function(t,e){var n=Ut(c.excludeTypes).includes(e.get("type")),i=d.find(function(t){return t.id===e.id}),r=f.includes(e.id);if(!(n||i||r))for(var o=e.getBBox().moveAndExpand(c.paddingBox),s=o.origin().snapToGrid(p),a=o.corner().snapToGrid(p),h=s.x;h<=a.x;h+=p)for(var l=s.y;l<=a.y;l+=p){var u=h+"@"+l;t[u]=t[u]||[],t[u].push(o)}return t},this.map),this},gi.prototype.isPointAccessible=function(e){var t=e.clone().snapToGrid(this.mapGridSize).toString();return Ut(this.map[t]).every(function(t){return!t.containsPoint(e)})},vi.prototype.add=function(t,e){this.hash[t]?this.items.splice(this.items.indexOf(t),1):this.hash[t]=this.OPEN,this.values[t]=e;var n=Bt(this.items,t,function(t){return this.values[t]}.bind(this));this.items.splice(n,0,t)},vi.prototype.remove=function(t){this.hash[t]=this.CLOSE},vi.prototype.isOpen=function(t){return this.hash[t]===this.OPEN},vi.prototype.isClose=function(t){return this.hash[t]===this.CLOSE},vi.prototype.isEmpty=function(){return 0===this.items.length},vi.prototype.pop=function(){var t=this.items.shift();return this.remove(t),t};var Vi=function(t,e,n){return Ni(t,Nt({},pi,e),n)},Fi={maxAllowedDirectionChange:45,diagonalCost:function(){var t=this.step;return Math.ceil(Math.sqrt(t*t<<1))},directions:function(){var t=this.step,e=this.cost(),n=this.diagonalCost();return[{offsetX:t,offsetY:0,cost:e},{offsetX:t,offsetY:t,cost:n},{offsetX:0,offsetY:t,cost:e},{offsetX:-t,offsetY:t,cost:n},{offsetX:-t,offsetY:0,cost:e},{offsetX:-t,offsetY:-t,cost:n},{offsetX:0,offsetY:-t,cost:e},{offsetX:t,offsetY:-t,cost:n}]},fallbackRoute:function(t,e,n){var i=t.theta(e),r=[],o={x:e.x,y:t.y},s={x:t.x,y:e.y};if(90<i%180){var a=o;o=s,s=a}var h=i%90<45?o:s,l=new O(t,h),u=90*Math.ceil(i/90),c=z.fromPolar(l.squaredLength(),A(u+135),h),d=new O(e,c),f=l.intersection(d),p=f||e,g=f?p:t,v=360/n.directions.length,m=g.theta(e),y=b(m+v/2),w=v*Math.floor(y/v);return n.previousDirectionAngle=w,p&&r.push(p.round()),r.push(e),r}},_i={normal:function(t,e,n){return t},oneSide:function(t,e,n){var i,r,o,s=e.side||"bottom",a=xt(e.padding||40),h=n.sourceBBox,l=n.targetBBox,u=h.center(),c=l.center();switch(s){case"bottom":o=1,i="y",r="height";break;case"top":o=-1,i="y",r="height";break;case"left":o=-1,i="x",r="width";break;case"right":o=1,i="x",r="width";break;default:throw new Error("Router: invalid side")}return u[i]+=o*(h[r]/2+a[s]),c[i]+=o*(l[r]/2+a[s]),0<o*(u[i]-c[i])?c[i]=u[i]:u[i]=c[i],[u].concat(t,c)},orthogonal:fi,manhattan:Vi,metro:function(t,e,n){if(!jt(Vi))throw new Error("Metro requires the manhattan router.");return Vi(t,Nt({},Fi,e),n)}};function Bi(s){return function(t,e,n,i){if(n instanceof Element){var r,o=this.paper.findView(n);if(o)if(o.isNodeConnection(n))r=Ri(o,"fixedAt"in i?i.fixedAt:"50%");else r=o.getNodeBBox(n).center();else r=new z;return s.call(this,t,e,r,i)}return s.apply(this,arguments)}}function Ri(t,e){var n=parseFloat(e);return pt(e)?t.getPointAtRatio(n/100):t.getPointAtLength(n)}var Oi=Bi(function(t,e,n,i){var r=t.getConnection(),o=t.getConnectionSubdivisions(),s=new O(n.clone().offset(0,1e6),n.clone().offset(0,-1e6)),a=new O(n.clone().offset(1e6,0),n.clone().offset(-1e6,0)),h=s.intersect(r,{segmentSubdivisions:o}),l=a.intersect(r,{segmentSubdivisions:o}),u=[];return h&&Array.prototype.push.apply(u,h),l&&Array.prototype.push.apply(u,l),0<u.length?n.chooseClosest(u):"fallbackAt"in i?Ri(t,i.fallbackAt):Di(t,e,n,i)}),Di=Bi(function(t,e,n,i){var r=t.getClosestPoint(n);return r||new z}),zi={resolveRef:Bi,connectionRatio:function(t,e,n,i){var r="ratio"in i?i.ratio:.5;return t.getPointAtRatio(r)},connectionLength:function(t,e,n,i){var r="length"in i?i.length:20;return t.getPointAtLength(r)},connectionPerpendicular:Oi,connectionClosest:Di};function Ii(c){return function(t,e,n,i){var r=!!i.rotate,o=r?t.getNodeUnrotatedBBox(e):t.getNodeBBox(e),s=o[c](),a=i.dx;if(a){var h=pt(a);a=parseFloat(a),isFinite(a)&&(h&&(a/=100,a*=o.width),s.x+=a)}var l=i.dy;if(l){var u=pt(l);l=parseFloat(l),isFinite(l)&&(u&&(l/=100,l*=o.height),s.y+=l)}return r?s.rotate(t.model.getBBox().center(),-t.model.angle()):s}}var ji={center:Ii("center"),top:Ii("topMiddle"),bottom:Ii("bottomMiddle"),left:Ii("leftMiddle"),right:Ii("rightMiddle"),topLeft:Ii("origin"),topRight:Ii("topRight"),bottomLeft:Ii("bottomLeft"),bottomRight:Ii("corner"),perpendicular:Bi(function(t,e,n,i){var r=t.model.angle(),o=t.getNodeBBox(e),s=o.center(),a=o.origin(),h=o.corner(),l=i.padding;if(isFinite(l)||(l=0),a.y+l<=n.y&&n.y<=h.y-l){var u=n.y-s.y;s.x+=0===r||180===r?0:1*u/Math.tan(A(r)),s.y+=u}else if(a.x+l<=n.x&&n.x<=h.x-l){var c=n.x-s.x;s.y+=90===r||270===r?0:c*Math.tan(A(r)),s.x+=c}return s}),midSide:Bi(function(t,e,n,i){var r,o,s,a=!!i.rotate;a?(r=t.getNodeUnrotatedBBox(e),s=t.model.getBBox().center(),o=t.model.angle()):r=t.getNodeBBox(e);var h,l=i.padding;switch(isFinite(l)&&r.inflate(l),a&&n.rotate(s,o),r.sideNearestToPoint(n)){case"left":h=r.leftMiddle();break;case"right":h=r.rightMiddle();break;case"top":h=r.topMiddle();break;case"bottom":h=r.bottomMiddle()}return a?h.rotate(s,-o):h}),modelCenter:function(t,e,n,i,r){return t.model.getPointFromConnectedLink(this.model,r).offset(i.dx,i.dy)}},Gi=s.Collection.extend({initialize:function(t,e){e.cellNamespace?this.cellNamespace=e.cellNamespace:this.cellNamespace="undefined"!=typeof joint&&Kt(joint,"shapes")?joint.shapes:null,this.graph=e.graph},model:function(t,e){var n=e.collection,i=n.cellNamespace,r=new("link"===t.type?pn:rt(i,t.type,".")||He)(t,e);return e.dry||(r.graph=n.graph),r},comparator:function(t){return t.get("z")||0}}),Ui=s.Model.extend({_batches:{},initialize:function(t,e){var n=new Gi([],{model:(e=e||{}).cellModel,cellNamespace:e.cellNamespace,graph:this});s.Model.prototype.set.call(this,"cells",n),n.on("all",this.trigger,this),this.on("change:z",this._sortOnChangeZ,this),this._out={},this._in={},this._nodes={},this._edges={},n.on("add",this._restructureOnAdd,this),n.on("remove",this._restructureOnRemove,this),n.on("reset",this._restructureOnReset,this),n.on("change:source",this._restructureOnChangeSource,this),n.on("change:target",this._restructureOnChangeTarget,this),n.on("remove",this._removeCell,this)},_sortOnChangeZ:function(){this.get("cells").sort()},_restructureOnAdd:function(t){if(t.isLink()){this._edges[t.id]=!0;var e=t.attributes,n=e.source,i=e.target;n.id&&((this._out[n.id]||(this._out[n.id]={}))[t.id]=!0),i.id&&((this._in[i.id]||(this._in[i.id]={}))[t.id]=!0)}else this._nodes[t.id]=!0},_restructureOnRemove:function(t){if(t.isLink()){delete this._edges[t.id];var e=t.attributes,n=e.source,i=e.target;n.id&&this._out[n.id]&&this._out[n.id][t.id]&&delete this._out[n.id][t.id],i.id&&this._in[i.id]&&this._in[i.id][t.id]&&delete this._in[i.id][t.id]}else delete this._nodes[t.id]},_restructureOnReset:function(t){t=t.models,this._out={},this._in={},this._nodes={},this._edges={},t.forEach(this._restructureOnAdd,this)},_restructureOnChangeSource:function(t){var e=t.previous("source");e.id&&this._out[e.id]&&delete this._out[e.id][t.id];var n=t.attributes.source;n.id&&((this._out[n.id]||(this._out[n.id]={}))[t.id]=!0)},_restructureOnChangeTarget:function(t){var e=t.previous("target");e.id&&this._in[e.id]&&delete this._in[e.id][t.id];var n=t.get("target");n.id&&((this._in[n.id]||(this._in[n.id]={}))[t.id]=!0)},getOutboundEdges:function(t){return this._out&&this._out[t]||{}},getInboundEdges:function(t){return this._in&&this._in[t]||{}},toJSON:function(){var t=s.Model.prototype.toJSON.apply(this,arguments);return t.cells=this.get("cells").toJSON(),t},fromJSON:function(t,e){if(!t.cells)throw new Error("Graph JSON must contain cells array.");return this.set(t,e)},set:function(t,e,n){var i;return"object"==typeof t?(i=t,n=e):(i={})[t]=e,i.hasOwnProperty("cells")&&(this.resetCells(i.cells,n),i=te(i,"cells")),s.Model.prototype.set.call(this,i,n)},clear:function(t){t=Nt({},t,{clear:!0});var e=this.get("cells");if(0===e.length)return this;this.startBatch("clear",t);for(var n=e.sortBy(function(t){return t.isLink()?1:2});n.shift().remove(t),0<n.length;);return this.stopBatch("clear"),this},_prepareCell:function(t,e){var n;if(t instanceof s.Model?(n=t.attributes,t.graph||e&&e.dry||(t.graph=this)):n=t,!ue(n.type))throw new TypeError("dia.Graph: cell type must be a string.");return t},minZIndex:function(){var t=this.get("cells").first();return t&&t.get("z")||0},maxZIndex:function(){var t=this.get("cells").last();return t&&t.get("z")||0},addCell:function(t,e){return Array.isArray(t)?this.addCells(t,e):(t instanceof s.Model?t.has("z")||t.set("z",this.maxZIndex()+1):void 0===t.z&&(t.z=this.maxZIndex()+1),this.get("cells").add(this._prepareCell(t,e),e||{}),this)},addCells:function(t,e){return 0===t.length||(t=Yt(t),e.maxPosition=e.position=t.length-1,this.startBatch("add",e),t.forEach(function(t){this.addCell(t,e),e.position--},this),this.stopBatch("add",e)),this},resetCells:function(t,e){var n=Ut(t).map(function(t){return this._prepareCell(t,e)},this);return this.get("cells").reset(n,e),this},removeCells:function(t,e){return t.length&&(this.startBatch("remove"),_t(t,"remove",e),this.stopBatch("remove")),this},_removeCell:function(t,e,n){(n=n||{}).clear||(n.disconnectLinks?this.disconnectLinks(t,n):this.removeLinks(t,n)),this.get("cells").remove(t,{silent:!0}),t.graph===this&&(t.graph=null)},getCell:function(t){return this.get("cells").get(t)},getCells:function(){return this.get("cells").toArray()},getElements:function(){return Object.keys(this._nodes).map(this.getCell,this)},getLinks:function(){return Object.keys(this._edges).map(this.getCell,this)},getFirstCell:function(){return this.get("cells").first()},getLastCell:function(){return this.get("cells").last()},getConnectedLinks:function(t,a){var r=(a=a||{}).indirect,o=a.inbound,s=a.outbound;void 0===o&&void 0===s&&(o=s=!0);var h=[],l={};function u(i,t){if(ie(i.getOutboundEdges(t.id),function(t,e){if(!l[e]){var n=i.getCell(e);h.push(n),l[e]=!0,r&&(o&&c(i,n),s&&u(i,n))}}.bind(i)),r&&t.isLink()){var e=t.getTargetCell();e&&e.isLink()&&(l[e.id]||(h.push(e),u(i,e)))}}function c(i,t){if(ie(i.getInboundEdges(t.id),function(t,e){if(!l[e]){var n=i.getCell(e);h.push(n),l[e]=!0,r&&(o&&c(i,n),s&&u(i,n))}}.bind(i)),r&&t.isLink()){var e=t.getSourceCell();e&&e.isLink()&&(l[e.id]||(h.push(e),c(i,e)))}}if(s&&u(this,t),o&&c(this,t),a.deep){var e=t.getEmbeddedCells({deep:!0}),d={};e.forEach(function(t){t.isElement()&&(d[t.id]=!0)}),e.forEach(function(t){t.isLink()||(s&&ie(this.getOutboundEdges(t.id),function(t,e){if(!l[e]){var n=this.getCell(e).attributes,i=n.source,r=n.target,o=i.id,s=r.id;if(!a.includeEnclosed&&o&&d[o]&&s&&d[s])return;h.push(this.getCell(e)),l[e]=!0}}.bind(this)),o&&ie(this.getInboundEdges(t.id),function(t,e){if(!l[e]){var n=this.getCell(e).attributes,i=n.source,r=n.target,o=i.id,s=r.id;if(!a.includeEnclosed&&o&&d[o]&&s&&d[s])return;h.push(this.getCell(e)),l[e]=!0}}.bind(this)))},this)}return h},getNeighbors:function(h,l){l||(l={});var u=l.inbound,c=l.outbound;void 0===u&&void 0===c&&(u=c=!0);var t=this.getConnectedLinks(h,l).reduce(function(t,e){var n=e.attributes,i=n.source,r=n.target,o=e.hasLoop(l);if(u&&Kt(i,"id")&&!t[i.id]){var s=this.getCell(i.id);s.isElement()&&(!o&&(!s||s===h||l.deep&&s.isEmbeddedIn(h))||(t[i.id]=s))}if(c&&Kt(r,"id")&&!t[r.id]){var a=this.getCell(r.id);a.isElement()&&(!o&&(!a||a===h||l.deep&&a.isEmbeddedIn(h))||(t[r.id]=a))}return t}.bind(this),{});if(h.isLink()){if(u){var e=h.getSourceCell();e&&e.isElement()&&!t[e.id]&&(t[e.id]=e)}if(c){var n=h.getTargetCell();n&&n.isElement()&&!t[n.id]&&(t[n.id]=n)}}return Ut(t)},getCommonAncestor:function(){var t=Array.from(arguments).map(function(t){for(var e=[],n=t.get("parent");n;)e.push(n),n=this.getCell(n).get("parent");return e},this);t=t.sort(function(t,e){return t.length-e.length});var e=Ut(t.shift()).find(function(e){return t.every(function(t){return t.includes(e)})});return this.getCell(e)},getSuccessors:function(e,t){t=t||{};var n=[];return this.search(e,function(t){t!==e&&n.push(t)},Nt({},t,{outbound:!0})),n},cloneCells:de,cloneSubgraph:function(t,e){var n=this.getSubgraph(t,e);return this.cloneCells(n)},getSubgraph:function(t,e){e=e||{};var s=[],a={},h=[],n=[];return Ut(t).forEach(function(t){(a[t.id]||(s.push(t),(a[t.id]=t).isLink()?n.push(t):h.push(t)),e.deep)&&t.getEmbeddedCells({deep:!0}).forEach(function(t){a[t.id]||(s.push(t),(a[t.id]=t).isLink()?n.push(t):h.push(t))})}),n.forEach(function(t){var e=t.attributes,n=e.source,i=e.target;if(n.id&&!a[n.id]){var r=this.getCell(n.id);s.push(r),a[r.id]=r,h.push(r)}if(i.id&&!a[i.id]){var o=this.getCell(i.id);s.push(this.getCell(i.id)),a[o.id]=o,h.push(o)}},this),h.forEach(function(t){this.getConnectedLinks(t,e).forEach(function(t){var e=t.attributes,n=e.source,i=e.target;!a[t.id]&&n.id&&a[n.id]&&i.id&&a[i.id]&&(s.push(t),a[t.id]=t)})},this),s},getPredecessors:function(e,t){t=t||{};var n=[];return this.search(e,function(t){t!==e&&n.push(t)},Nt({},t,{inbound:!0})),n},search:function(t,e,n){(n=n||{}).breadthFirst?this.bfs(t,e,n):this.dfs(t,e,n)},bfs:function(t,e,n){void 0===n&&(n={});var i={},r={},o=[];for(o.push(t),r[t.id]=0;0<o.length;){var s=o.shift();if(!i[s.id]&&!(i[s.id]=!0)!==e.call(this,s,r[s.id]))for(var a=this.getNeighbors(s,n),h=0,l=a.length;h<l;h++){var u=a[h];r[u.id]=r[s.id]+1,o.push(u)}}},dfs:function(t,e,n){void 0===n&&(n={});var i={},r={},o=[];for(o.push(t),r[t.id]=0;0<o.length;){var s=o.pop();if(!i[s.id]&&!(i[s.id]=!0)!==e.call(this,s,r[s.id]))for(var a=this.getNeighbors(s,n),h=o.length,l=0,u=a.length;l<u;l++){var c=a[l];r[c.id]=r[s.id]+1,o.splice(h,0,c)}}},getSources:function(){var n=[];return ie(this._nodes,function(t,e){this._in[e]&&!zt(this._in[e])||n.push(this.getCell(e))}.bind(this)),n},getSinks:function(){var n=[];return ie(this._nodes,function(t,e){this._out[e]&&!zt(this._out[e])||n.push(this.getCell(e))}.bind(this)),n},isSource:function(t){return!this._in[t.id]||zt(this._in[t.id])},isSink:function(t){return!this._out[t.id]||zt(this._out[t.id])},isSuccessor:function(e,n){var i=!1;return this.search(e,function(t){if(t===n&&t!==e)return!(i=!0)},{outbound:!0}),i},isPredecessor:function(e,n){var i=!1;return this.search(e,function(t){if(t===n&&t!==e)return!(i=!0)},{inbound:!0}),i},isNeighbor:function(t,r,e){var o=(e=e||{}).inbound,s=e.outbound;void 0===o&&void 0===s&&(o=s=!0);var a=!1;return this.getConnectedLinks(t,e).forEach(function(t){var e=t.attributes,n=e.source,i=e.target;return o&&Kt(n,"id")&&n.id===r.id?!(a=!0):s&&Kt(i,"id")&&i.id===r.id?!(a=!0):void 0}),a},disconnectLinks:function(e,n){this.getConnectedLinks(e).forEach(function(t){t.set(t.attributes.source.id===e.id?"source":"target",{x:0,y:0},n)})},removeLinks:function(t,e){_t(this.getConnectedLinks(t),"remove",e)},findModelsFromPoint:function(e){return this.getElements().filter(function(t){return t.getBBox().containsPoint(e)})},findModelsInArea:function(e,t){e=k(e);var n=(t=Vt(t||{},{strict:!1})).strict?"containsRect":"intersect";return this.getElements().filter(function(t){return e[n](t.getBBox())})},findModelsUnderElement:function(e,t){t=Vt(t||{},{searchBy:"bbox"});var n=e.getBBox();return("bbox"===t.searchBy?this.findModelsInArea(n):this.findModelsFromPoint(n[t.searchBy]())).filter(function(t){return e.id!==t.id&&!t.isEmbeddedIn(e)})},getBBox:function(){return this.getCellsBBox(this.getCells())},getCellsBBox:function(t,r){return r||(r={}),Ut(t).reduce(function(t,e){var n=e.getBBox(r);if(!n)return t;var i=e.angle();return i&&(n=n.bbox(i)),t?t.union(n):n},null)},translate:function(t,e,n){var i=this.getCells().filter(function(t){return!t.isEmbedded()});return _t(i,"translate",t,e,n),this},resize:function(t,e,n){return this.resizeCells(t,e,this.getCells(),n)},resizeCells:function(t,e,n,i){var r=this.getCellsBBox(n);if(r){var o=Math.max(t/r.width,0),s=Math.max(e/r.height,0);_t(n,"scale",o,s,r.origin(),i)}return this},startBatch:function(t,e){return e=e||{},this._batches[t]=(this._batches[t]||0)+1,this.trigger("batch:start",Nt({},e,{batchName:t}))},stopBatch:function(t,e){return e=e||{},this._batches[t]=(this._batches[t]||0)-1,this.trigger("batch:stop",Nt({},e,{batchName:t}))},hasActiveBatch:function(t){var e=this._batches;return(0===arguments.length?Ut(e):Array.isArray(t)?t:[t]).some(function(t){return 0<e[t]})}},{validations:{multiLinks:function(t,e){var n=e.attributes,r=n.source,o=n.target;if(r.id&&o.id){var i=e.getSourceCell();if(i)if(1<t.getConnectedLinks(i,{outbound:!0}).filter(function(t){var e=t.attributes,n=e.source,i=e.target;return n&&n.id===r.id&&(!n.port||n.port===r.port)&&i&&i.id===o.id&&(!i.port||i.port===o.port)}).length)return!1}return!0},linkPinning:function(t,e){var n=e.attributes,i=n.source,r=n.target;return i.id&&r.id}}});Te(Ui.prototype,["resetCells","addCells","removeCells"],Le.cells);var qi=We.extend({className:function(){var t=We.prototype.className.apply(this).split(" ");return t.push("link"),t.join(" ")},options:{shortLinkLength:105,doubleLinkTools:!1,longLinkLength:155,linkToolsOffset:40,doubleLinkToolsOffset:65,sampleInterval:50},_labelCache:null,_labelSelectors:null,_markerCache:null,_V:null,_dragData:null,metrics:null,decimalsRounding:2,initialize:function(){We.prototype.initialize.apply(this,arguments),this._labelCache={},this._labelSelectors={},this._markerCache={},this._V={},this.metrics={}},presentationAttributes:{markup:["RENDER"],attrs:["UPDATE"],router:["UPDATE"],connector:["UPDATE"],smooth:["UPDATE"],manhattan:["UPDATE"],toolMarkup:["TOOLS"],labels:["LABELS"],labelMarkup:["LABELS"],vertices:["VERTICES","UPDATE"],vertexMarkup:["VERTICES"],source:["SOURCE","UPDATE"],target:["TARGET","UPDATE"]},initFlag:["RENDER","SOURCE","TARGET"],UPDATE_PRIORITY:1,confirmUpdate:function(t,e){if(e||(e={}),this.hasFlag(t,"SOURCE")){if(!this.updateEndProperties("source"))return t;t=this.removeFlag(t,"SOURCE")}if(this.hasFlag(t,"TARGET")){if(!this.updateEndProperties("target"))return t;t=this.removeFlag(t,"TARGET")}var n=this.paper,i=this.sourceView,r=this.targetView;if(n&&(i&&!n.isViewMounted(i)||r&&!n.isViewMounted(r)))return t;if(this.hasFlag(t,"RENDER"))return this.render(),t=this.removeFlag(t,["RENDER","UPDATE","VERTICES","TOOLS","LABELS"]);this.hasFlag(t,"VERTICES")&&(this.renderVertexMarkers(),t=this.removeFlag(t,"VERTICES"));var o=this.model,s=o.attributes;return this.hasFlag(t,"UPDATE")&&(this.update(o,null,e),t=this.removeFlag(t,"UPDATE")),this.hasFlag(t,"LABELS")&&(this.onLabelsChange(o,s.labels,e),t=this.removeFlag(t,"LABELS")),this.hasFlag(t,"TOOLS")&&(this.renderTools().updateToolsPosition(),t=this.removeFlag(t,"TOOLS")),t},isLabelsRenderRequired:function(t){void 0===t&&(t={});var e=this.model.previous("labels");if(!e)return!0;if("propertyPathArray"in t&&"propertyValue"in t){var n=t.propertyPathArray||[],i=n.length;if(1<i)if(!!e[n[1]]){if(2===i)return"markup"in Object(t.propertyValue);if("markup"!==n[2])return!1}}return!0},onLabelsChange:function(t,e,n){this.isLabelsRenderRequired(n)?this.renderLabels():this.updateLabels(),this.updateLabelPositions()},render:function(){return this.vel.empty(),this._V={},this.renderMarkup(),this.renderLabels(),this.update(),this},renderMarkup:function(){var t=this.model,e=t.get("markup")||t.markup;if(!e)throw new Error("dia.LinkView: markup required");if(Array.isArray(e))return this.renderJSONMarkup(e);if("string"==typeof e)return this.renderStringMarkup(e);throw new Error("dia.LinkView: invalid markup")},renderJSONMarkup:function(t){var e=this.parseDOMJSON(t,this.el);this.selectors=e.selectors,this.vel.append(e.fragment)},renderStringMarkup:function(t){var e=K(t);Array.isArray(e)||(e=[e]);for(var n=this._V,i=0,r=e.length;i<r;i++){var o=e[i],s=o.attr("class");s&&(s=et(s),n[C.camelCase(s)]=o)}this.renderTools(),this.renderVertexMarkers(),this.renderArrowheadMarkers(),this.vel.append(e)},_getLabelMarkup:function(t){if(t){if(Array.isArray(t))return this.parseDOMJSON(t,null);if("string"==typeof t)return this._getLabelStringMarkup(t);throw new Error("dia.linkView: invalid label markup")}},_getLabelStringMarkup:function(t){var e=K(t),n=document.createDocumentFragment();if(Array.isArray(e))for(var i=0,r=e.length;i<r;i++){var o=e[i].node;n.appendChild(o)}else n.appendChild(e.node);return{fragment:n,selectors:{}}},_normalizeLabelMarkup:function(t){if(t){var e,n=t.fragment;if(!(t.fragment instanceof DocumentFragment&&t.fragment.hasChildNodes()))throw new Error("dia.LinkView: invalid label markup.");var i=n.childNodes;return(e=1<i.length||"G"!==i[0].nodeName.toUpperCase()?K("g").append(n):K(i[0])).addClass("label"),{node:e.node,selectors:t.selectors}}},renderLabels:function(){var t=this._V,e=t.labels,n=this._labelCache={},i=this._labelSelectors={},r=this.model,o=r.attributes.labels||[],s=o.length;if(0===s)return e&&e.remove(),this;e?e.empty():e=t.labels=K("g").addClass("labels");for(var a=e.node,h=0;h<s;h++){var l,u,c=o[h],d=this._normalizeLabelMarkup(this._getLabelMarkup(c.markup));if(d)l=d.node,u=d.selectors;else{var f=r._builtins.defaultLabel,p=this._normalizeLabelMarkup(this._getLabelMarkup(f.markup)),g=r._getDefaultLabel(),v=this._normalizeLabelMarkup(this._getLabelMarkup(g.markup))||p;l=v.node,u=v.selectors}l.setAttribute("label-idx",h),a.appendChild(l),n[h]=l;var m=this.selector;if(u[m])throw new Error("dia.LinkView: ambiguous label root selector.");u[m]=l,i[h]=u}return a.parentNode||this.el.appendChild(a),this.updateLabels(),this},_mergeLabelAttrs:function(t,e,n,i){return null===e?null:void 0!==e?t?se({},n,e):se({},i,n,e):null===n?null:void 0!==n?t?n:se({},i,n):t?void 0:i},updateLabels:function(){if(!this._V.labels)return this;for(var t=this.model,e=t.get("labels")||[],n=this.can("labelMove"),i=t._builtins.defaultLabel.attrs,r=t._getDefaultLabel(),o=r.markup,s=r.attrs,a=0,h=e.length;a<h;a++){var l=this._labelCache[a];l.setAttribute("cursor",n?"move":"default");var u=this._labelSelectors[a],c=e[a],d=c.markup,f=c.attrs,p=this._mergeLabelAttrs(d||o,f,s,i);this.updateDOMSubtreeAttributes(l,p,{rootBBox:new X(c.size),selectors:u})}return this},renderTools:function(){if(!this._V.linkTools)return this;var t,e=C(this._V.linkTools.node).empty(),n=Et(this.model.get("toolMarkup")||this.model.toolMarkup),i=K(n());(e.append(i.node),this._toolCache=i,this.options.doubleLinkTools)&&(t=this.model.get("doubleToolMarkup")||this.model.doubleToolMarkup?(n=Et(this.model.get("doubleToolMarkup")||this.model.doubleToolMarkup),K(n())):i.clone(),e.append(t.node),this._tool2Cache=t);return this},renderVertexMarkers:function(){if(!this._V.markerVertices)return this;var n=C(this._V.markerVertices.node).empty(),i=Et(this.model.get("vertexMarkup")||this.model.vertexMarkup);return this.model.vertices().forEach(function(t,e){n.append(K(i(Nt({idx:e},t))).node)}),this},renderArrowheadMarkers:function(){if(!this._V.markerArrowheads)return this;var t=C(this._V.markerArrowheads.node);t.empty();var e=Et(this.model.get("arrowheadMarkup")||this.model.arrowheadMarkup);return this._V.sourceArrowhead=K(e({end:"source"})),this._V.targetArrowhead=K(e({end:"target"})),t.append(this._V.sourceArrowhead.node,this._V.targetArrowhead.node),this},update:function(t,e,n){return n||(n={}),this.cleanNodesCache(),this.updateConnection(n),this.updateDOMSubtreeAttributes(this.el,this.model.attr(),{selectors:this.selectors}),this.updateDefaultConnectionPath(),this.updateLabelPositions(),this.updateToolsPosition(),this.updateArrowheadMarkers(),this.updateTools(n),this.options.perpendicular=null,this},removeRedundantLinearVertices:function(t){var e=this.model,n=e.vertices(),i=[this.sourceAnchor].concat(n,[this.targetAnchor]),r=i.length,o=new L(i);o.simplify({threshold:.001});var s=o.points.map(function(t){return t.toJSON()}),a=s.length;return r===a?0:(e.vertices(s.slice(1,a-1),t),r-a)},updateDefaultConnectionPath:function(){var t=this._V;t.connection&&t.connection.attr("d",this.getSerializedConnection()),t.connectionWrap&&t.connectionWrap.attr("d",this.getSerializedConnection()),t.markerSource&&t.markerTarget&&this._translateAndAutoOrientArrows(t.markerSource,t.markerTarget)},getEndView:function(t){switch(t){case"source":return this.sourceView||null;case"target":return this.targetView||null;default:throw new Error("dia.LinkView: type parameter required.")}},getEndAnchor:function(t){switch(t){case"source":return new z(this.sourceAnchor);case"target":return new z(this.targetAnchor);default:throw new Error("dia.LinkView: type parameter required.")}},getEndMagnet:function(t){switch(t){case"source":var e=this.sourceView;if(!e)break;return this.sourceMagnet||e.el;case"target":var n=this.targetView;if(!n)break;return this.targetMagnet||n.el;default:throw new Error("dia.LinkView: type parameter required.")}return null},updateConnection:function(t){t=t||{};var e,n,i=this.model;if(t.translateBy&&i.isRelationshipEmbeddedIn(t.translateBy)){var r=t.tx||0,o=t.ty||0;e=new L(this.route).translate(r,o).points,this._translateConnectionPoints(r,o),(n=this.path).translate(r,o)}else{var s=i.vertices(),a=this.findAnchors(s),h=this.sourceAnchor=a.source,l=this.targetAnchor=a.target;e=this.findRoute(s,t);var u=this.findConnectionPoints(e,h,l),c=this.sourcePoint=u.source,d=this.targetPoint=u.target,f=this.findMarkerPoints(e,c,d);n=this.findPath(e,f.source||c,f.target||d)}this.route=e,this.path=n,this.metrics={}},findMarkerPoints:function(t,e,n){var i,r,o=t[0],s=t[t.length-1],a=this._markerCache;return this._V.markerSource&&(a.sourceBBox=a.sourceBBox||this._V.markerSource.getBBox(),i=z(e).move(o||n,a.sourceBBox.width*this._V.markerSource.scale().sx*-1).round()),this._V.markerTarget&&(a.targetBBox=a.targetBBox||this._V.markerTarget.getBBox(),r=z(n).move(s||e,a.targetBBox.width*this._V.markerTarget.scale().sx*-1).round()),a.sourcePoint=i||e.clone(),a.targetPoint=r||n.clone(),{source:i,target:r}},findAnchorsOrdered:function(t,e,n,i){var r,o,s,a,h=this.model,l=h.get(t),u=h.get(n),c=this.getEndView(t),d=this.getEndView(n),f=this.getEndMagnet(t),p=this.getEndMagnet(n);r=c?(s=e?new z(e):d?p:new z(u),this.getAnchor(l.anchor,c,f,s,t)):new z(l),o=d?(a=new z(i||r),this.getAnchor(u.anchor,d,p,a,n)):new z(u);var g={};return g[t]=r,g[n]=o,g},findAnchors:function(t){var e=this.model,n=t[0],i=t[t.length-1];return e.target().priority&&!e.source().priority?this.findAnchorsOrdered("target",i,"source",n):this.findAnchorsOrdered("source",n,"target",i)},findConnectionPoints:function(t,e,n){var i,r,o,s,a=t[0],h=t[t.length-1],l=this.model,u=l.get("source"),c=l.get("target"),d=this.sourceView,f=this.targetView,p=this.paper.options;if(d&&!d.isNodeConnection(this.sourceMagnet)){i=this.sourceMagnet||d.el;var g=u.connectionPoint||p.defaultConnectionPoint,v=new O(a||n,e);o=this.getConnectionPoint(g,d,i,v,"source")}else o=e;if(f&&!f.isNodeConnection(this.targetMagnet)){r=this.targetMagnet||f.el;var m=c.connectionPoint||p.defaultConnectionPoint,y=new O(h||e,n);s=this.getConnectionPoint(m,f,r,y,"target")}else s=n;return{source:o,target:s}},getAnchor:function(t,e,n,i,r){var o,s=e.isNodeConnection(n),a=this.paper.options;if(t||(t=s?a.defaultLinkAnchor:a.perpendicularLinks||this.options.perpendicular?{name:"perpendicular"}:a.defaultAnchor),!t)throw new Error("Anchor required.");if("function"==typeof t)o=t;else{var h=t.name;if("function"!=typeof(o=a[s?"linkAnchorNamespace":"anchorNamespace"][h]))throw new Error("Unknown anchor: "+h)}var l=o.call(this,e,n,i,t.args||{},r,this);return l?l.round(this.decimalsRounding):new z},getConnectionPoint:function(t,e,n,i,r){var o,s,a=i.end,h=this.paper.options;if("function"==typeof h.linkConnectionPoint){var l=n===e.el?void 0:n;if(o=h.linkConnectionPoint(this,e,l,i.start,r))return o}if(!t)return a;if("function"==typeof t)s=t;else{var u=t.name;if("function"!=typeof(s=h.connectionPointNamespace[u]))throw new Error("Unknown connection point: "+u)}return(o=s.call(this,i,e,n,t.args||{},r,this))?o.round(this.decimalsRounding):a},_translateConnectionPoints:function(t,e){var n=this._markerCache;n.sourcePoint.offset(t,e),n.targetPoint.offset(t,e),this.sourcePoint.offset(t,e),this.targetPoint.offset(t,e),this.sourceAnchor.offset(t,e),this.targetAnchor.offset(t,e)},_normalizeLabelPosition:function(t){return"number"==typeof t?{distance:t,offset:null,angle:0,args:null}:t},updateLabelPositions:function(){if(!this._V.labels)return this;if(!this.path)return this;var t=this.model,e=t.get("labels")||[];if(!e.length)return this;for(var n=t._builtins.defaultLabel.position,i=t._getDefaultLabel(),r=this._normalizeLabelPosition(i.position),o=se({},n,r),s=0,a=e.length;s<a;s++){var h=e[s],l=this._normalizeLabelPosition(h.position),u=se({},o,l),c=this._getLabelTransformationMatrix(u);this._labelCache[s].setAttribute("transform",K.matrixToTransformString(c))}return this},updateToolsPosition:function(){if(!this._V.linkTools)return this;var t="",e=this.options.linkToolsOffset,n=this.getConnectionLength();if(!Number.isNaN(n)){n<this.options.shortLinkLength&&(t="scale(.5)",e/=2);var i=this.getPointAtLength(e);if(this._toolCache.attr("transform","translate("+i.x+", "+i.y+") "+t),this.options.doubleLinkTools&&n>=this.options.longLinkLength){var r=this.options.doubleLinkToolsOffset||e;i=this.getPointAtLength(n-r),this._tool2Cache.attr("transform","translate("+i.x+", "+i.y+") "+t),this._tool2Cache.attr("visibility","visible")}else this.options.doubleLinkTools&&this._tool2Cache.attr("visibility","hidden")}return this},updateArrowheadMarkers:function(){if(!this._V.markerArrowheads)return this;if("none"===C.css(this._V.markerArrowheads.node,"display"))return this;var t=this.getConnectionLength()<this.options.shortLinkLength?.5:1;return this._V.sourceArrowhead.scale(t),this._V.targetArrowhead.scale(t),this._translateAndAutoOrientArrows(this._V.sourceArrowhead,this._V.targetArrowhead),this},updateEndProperties:function(t){var e=this.model,n=this.paper,i=t+"View",r=e.get(t),o=r&&r.id;if(!o)return this[i]=null,this.updateEndMagnet(t),!0;var s=n.getModelById(o);if(!s)throw new Error("LinkView: invalid "+t+" cell.");var a=s.findView(n);return!!a&&(this[i]=a,this.updateEndMagnet(t),!0)},updateEndMagnet:function(t){var e=t+"Magnet",n=this.getEndView(t);if(n){var i=n.getMagnetFromLinkEnd(this.model.get(t));i===n.el&&(i=null),this[e]=i}else this[e]=null},_translateAndAutoOrientArrows:function(t,e){var n=Ut(this.route);t&&t.translateAndAutoOrient(this.sourcePoint,n[0]||this.targetPoint,this.paper.cells),e&&e.translateAndAutoOrient(this.targetPoint,n[n.length-1]||this.sourcePoint,this.paper.cells)},_getLabelPositionAngle:function(t){return(this.model.label(t).position||{}).angle||0},_getLabelPositionArgs:function(t){return(this.model.label(t).position||{}).args},_getDefaultLabelPositionArgs:function(){return(this.model._getDefaultLabel().position||{}).args},_mergeLabelPositionArgs:function(t,e){return null===t?null:void 0===t?null===e?null:e:se({},e,t)},addLabel:function(t,e,n,i){var r,o,s,a=0;s="number"!=typeof t?(r=t.x,o=t.y,"number"==typeof e?(a=e,n):e):(r=t,o=e,"number"==typeof n?(a=n,i):n);var h=this._getDefaultLabelPositionArgs(),l=s,u=this._mergeLabelPositionArgs(l,h),c={position:this.getLabelPosition(r,o,a,u)};return this.model.insertLabel(-1,c,s),-1},addVertex:function(t,e,n){var i="number"!=typeof t,r=i?t.x:t,o=i?t.y:e,s=i?e:n,a={x:r,y:o},h=this.getVertexIndex(r,o);return this.model.insertVertex(h,a,s),h},sendToken:function(t,e,n){var i,r,o;o=he(e)?(i=e.duration,r="reverse"===e.direction,e.connection):(i=e,r=!1,null);var s={dur:(i=i||1e3)+"ms",repeatCount:1,calcMode:"linear",fill:"freeze"};r&&(s.keyPoints="1;0",s.keyTimes="0;1");var a,h,l,u=K(t);if("string"==typeof o)a=this.findBySelector(o,this.el,this.selectors)[0];else{var c=this._V;a=c.connection?c.connection.node:this.el.querySelector("path")}if(!(a instanceof SVGPathElement))throw new Error("dia.LinkView: token animation requires a valid connection path.");u.appendTo(this.paper.cells).animateAlongPath(s,a),setTimeout((h=u,l=n,function(){h.remove(),"function"==typeof l&&l()}),i)},findRoute:function(t){t||(t=[]);var e=_i,n=this.model.router(),i=this.paper.options.defaultRouter;if(!n){if(!i)return t.map(z);n=i}var r=jt(n)?n:e[n.name];if(!jt(r))throw new Error('dia.LinkView: unknown router: "'+n.name+'".');var o=n.args||{},s=r.call(this,t,o,this);return s||t.map(z)},findPath:function(t,e,n){var i=On,r=this.model.connector(),o=this.paper.options.defaultConnector;r||(r=o||{});var s=jt(r)?r:i[r.name];if(!jt(s))throw new Error('dia.LinkView: unknown connector: "'+r.name+'".');var a=Ot(r.args||{});a.raw=!0;var h=s.call(this,e,n,t,a,this);return"string"==typeof h&&(h=new D(K.normalizePathData(h))),h},getConnection:function(){var t=this.path;return t?t.clone():null},getSerializedConnection:function(){var t=this.path;if(!t)return null;var e=this.metrics;if(e.hasOwnProperty("data"))return e.data;var n=t.serialize();return e.data=n},getConnectionSubdivisions:function(){var t=this.path;if(!t)return null;var e=this.metrics;if(e.hasOwnProperty("segmentSubdivisions"))return e.segmentSubdivisions;var n=t.getSegmentSubdivisions();return e.segmentSubdivisions=n},getConnectionLength:function(){var t=this.path;if(!t)return 0;var e=this.metrics;if(e.hasOwnProperty("length"))return e.length;var n=t.length({segmentSubdivisions:this.getConnectionSubdivisions()});return e.length=n},getPointAtLength:function(t){var e=this.path;return e?e.pointAtLength(t,{segmentSubdivisions:this.getConnectionSubdivisions()}):null},getPointAtRatio:function(t){var e=this.path;return e?(pt(t)&&(t=parseFloat(t)/100),e.pointAt(t,{segmentSubdivisions:this.getConnectionSubdivisions()})):null},getTangentAtLength:function(t){var e=this.path;return e?e.tangentAtLength(t,{segmentSubdivisions:this.getConnectionSubdivisions()}):null},getTangentAtRatio:function(t){var e=this.path;return e?e.tangentAt(t,{segmentSubdivisions:this.getConnectionSubdivisions()}):null},getClosestPoint:function(t){var e=this.path;return e?e.closestPoint(t,{segmentSubdivisions:this.getConnectionSubdivisions()}):null},getClosestPointLength:function(t){var e=this.path;return e?e.closestPointLength(t,{segmentSubdivisions:this.getConnectionSubdivisions()}):null},getClosestPointRatio:function(t){var e=this.path;return e?e.closestPointNormalizedLength(t,{segmentSubdivisions:this.getConnectionSubdivisions()}):null},getLabelPosition:function(t,e,n,i){var r,o={},s=0;(r="number"==typeof n?(s=n,i):n)&&(o.args=r);var a,h,l=!(r&&r.absoluteDistance),u=r&&r.absoluteDistance&&r.reverseDistance,c=r&&r.absoluteOffset,d=this.path,f={segmentSubdivisions:this.getConnectionSubdivisions()},p=new z(t,e),g=d.closestPointT(p,f),v=d.lengthAtT(g,f);if(l&&(v=v/this.getConnectionLength()||0),u&&(v=-1*(this.getConnectionLength()-v)||1),o.distance=v,c||(a=d.tangentAtT(g)),a)h=a.pointOffset(p);else{var m=d.pointAtT(g),y=p.difference(m);h={x:y.x,y:y.y}}return o.offset=h,o.angle=s,o},_getLabelTransformationMatrix:function(t){var e,n=0,i={};if("number"==typeof t)e=t;else{if("number"!=typeof t.distance)throw new Error("dia.LinkView: invalid label position distance.");i=t.args||{},e=t.distance,n=t.angle||0}var r=0<e&&e<=1,o=0,s={x:0,y:0};if(t.offset){var a=t.offset;"number"==typeof a&&(o=a),a.x&&(s.x=a.x),a.y&&(s.y=a.y)}var h,l=0!==s.x||0!==s.y||0===o,u=i.keepGradient,c=i.ensureLegibility,d=this.path,f={segmentSubdivisions:this.getConnectionSubdivisions()},p=r?e*this.getConnectionLength():e,g=d.tangentAtLength(p,f),v=n;if(g){if(l)(h=g.start).offset(s);else{var m=g.clone();m.rotate(g.start,-90),m.setLength(o),h=m.end}u&&(v=g.angle()+n,c&&(v=b((v+90)%180-90)))}else h=d.start,l&&h.offset(s);return K.createSVGMatrix().translate(h.x,h.y).rotate(v)},getLabelCoordinates:function(t){var e=this._getLabelTransformationMatrix(t);return new z(e.e,e.f)},getVertexIndex:function(t,e){for(var n=this.model.vertices(),i=this.getClosestPointLength(new z(t,e)),r=0,o=n.length;r<o;r++){var s=n[r];if(i<this.getClosestPointLength(s))break}return r},notifyPointerdown:function(t,e,n){We.prototype.pointerdown.call(this,t,e,n),this.notify("link:pointerdown",t,e,n)},notifyPointermove:function(t,e,n){We.prototype.pointermove.call(this,t,e,n),this.notify("link:pointermove",t,e,n)},notifyPointerup:function(t,e,n){this.notify("link:pointerup",t,e,n),We.prototype.pointerup.call(this,t,e,n)},pointerdblclick:function(t,e,n){We.prototype.pointerdblclick.apply(this,arguments),this.notify("link:pointerdblclick",t,e,n)},pointerclick:function(t,e,n){We.prototype.pointerclick.apply(this,arguments),this.notify("link:pointerclick",t,e,n)},contextmenu:function(t,e,n){We.prototype.contextmenu.apply(this,arguments),this.notify("link:contextmenu",t,e,n)},pointerdown:function(t,e,n){switch(this.notifyPointerdown(t,e,n),t.target.getAttribute("class")){case"marker-vertex":return void this.dragVertexStart(t,e,n);case"marker-vertex-remove":case"marker-vertex-remove-area":return void this.dragVertexRemoveStart(t,e,n);case"marker-arrowhead":return void this.dragArrowheadStart(t,e,n);case"connection":case"connection-wrap":return void this.dragConnectionStart(t,e,n);case"marker-source":case"marker-target":return}this.dragStart(t,e,n)},pointermove:function(t,e,n){var i=this._dragData;switch(i&&this.eventData(t,i),this.eventData(t).action){case"vertex-move":this.dragVertex(t,e,n);break;case"label-move":this.dragLabel(t,e,n);break;case"arrowhead-move":this.dragArrowhead(t,e,n);break;case"move":this.drag(t,e,n)}i&&Nt(i,this.eventData(t)),this.notifyPointermove(t,e,n)},pointerup:function(t,e,n){var i=this._dragData;switch(i&&(this.eventData(t,i),this._dragData=null),this.eventData(t).action){case"vertex-move":this.dragVertexEnd(t,e,n);break;case"label-move":this.dragLabelEnd(t,e,n);break;case"arrowhead-move":this.dragArrowheadEnd(t,e,n);break;case"move":this.dragEnd(t,e,n)}this.notifyPointerup(t,e,n),this.checkMouseleave(t)},mouseover:function(t){We.prototype.mouseover.apply(this,arguments),this.notify("link:mouseover",t)},mouseout:function(t){We.prototype.mouseout.apply(this,arguments),this.notify("link:mouseout",t)},mouseenter:function(t){We.prototype.mouseenter.apply(this,arguments),this.notify("link:mouseenter",t)},mouseleave:function(t){We.prototype.mouseleave.apply(this,arguments),this.notify("link:mouseleave",t)},mousewheel:function(t,e,n,i){We.prototype.mousewheel.apply(this,arguments),this.notify("link:mousewheel",t,e,n,i)},onevent:function(t,e,n,i){if(K(t.target).findParentByClass("link-tool",this.el)){if(t.stopPropagation(),this.can("useLinkTools")){if("remove"===e)return void this.model.remove({ui:!0});this.notify(e,t,n,i)}this.notifyPointerdown(t,n,i)}else We.prototype.onevent.apply(this,arguments)},onlabel:function(t,e,n){this.notifyPointerdown(t,e,n),this.dragLabelStart(t,e,n),this.eventData(t).stopPropagation&&t.stopPropagation()},dragConnectionStart:function(t,e,n){if(this.can("vertexAdd")){var i=this.addVertex({x:e,y:n},{ui:!0});this.eventData(t,{action:"vertex-move",vertexIdx:i})}},dragLabelStart:function(t,e,n){if(this.can("labelMove")){var i=t.currentTarget,r=parseInt(i.getAttribute("label-idx"),10),o=this._getLabelPositionAngle(r),s=this._getLabelPositionArgs(r),a=this._getDefaultLabelPositionArgs(),h=this._mergeLabelPositionArgs(s,a);this.eventData(t,{action:"label-move",labelIdx:r,positionAngle:o,positionArgs:h,stopPropagation:!0})}else this.eventData(t,{stopPropagation:!0});this.paper.delegateDragEvents(this,t.data)},dragVertexStart:function(t,e,n){if(this.can("vertexMove")){var i=t.target,r=parseInt(i.getAttribute("idx"),10);this.eventData(t,{action:"vertex-move",vertexIdx:r})}},dragVertexRemoveStart:function(t,e,n){if(this.can("vertexRemove")){var i=t.target,r=parseInt(i.getAttribute("idx"),10);this.model.removeVertex(r)}},dragArrowheadStart:function(t,e,n){if(this.can("arrowheadMove")){var i=t.target.getAttribute("end"),r=this.startArrowheadMove(i,{ignoreBackwardsCompatibility:!0});this.eventData(t,r)}},dragStart:function(t,e,n){this.can("linkMove")&&this.eventData(t,{action:"move",dx:e,dy:n})},dragLabel:function(t,e,n){var i=this.eventData(t),r={position:this.getLabelPosition(e,n,i.positionAngle,i.positionArgs)};this.model.label(i.labelIdx,r)},dragVertex:function(t,e,n){var i=this.eventData(t);this.model.vertex(i.vertexIdx,{x:e,y:n},{ui:!0})},dragArrowhead:function(t,e,n){var i=this.eventData(t);this.paper.options.snapLinks?this._snapArrowhead(e,n,i):this._connectArrowhead(this.getEventTarget(t),e,n,i)},drag:function(t,e,n){var i=this.eventData(t);this.model.translate(e-i.dx,n-i.dy,{ui:!0}),this.eventData(t,{dx:e,dy:n})},dragLabelEnd:function(){},dragVertexEnd:function(){},dragArrowheadEnd:function(t,e,n){var i=this.eventData(t),r=this.paper;r.options.snapLinks?this._snapArrowheadEnd(i):this._connectArrowheadEnd(i,e,n),r.linkAllowed(this)?(this._finishEmbedding(i),this._notifyConnectEvent(i,t)):this._disallow(i),this._afterArrowheadMove(i)},dragEnd:function(){},_disallow:function(t){switch(t.whenNotAllowed){case"remove":this.model.remove({ui:!0});break;case"revert":default:this.model.set(t.arrowhead,t.initialEnd,{ui:!0})}},_finishEmbedding:function(t){this.paper.options.embeddingMode&&this.model.reparent()&&(t.z=null)},_notifyConnectEvent:function(t,e){var n=t.arrowhead,i=t.initialEnd,r=this.model.prop(n);if(r&&!pn.endsEqual(i,r)){var o=this.paper;i.id&&this.notify("link:disconnect",e,o.findViewByModel(i.id),t.initialMagnet,n),r.id&&this.notify("link:connect",e,o.findViewByModel(r.id),t.magnetUnderPointer,n)}},_snapArrowhead:function(t,e,r){var o,s=this.paper.options.snapLinks.radius||50,n=this.paper.findViewsInArea({x:t-s,y:e-s,width:2*s,height:2*s}),i=r.closestView||null,a=r.closestMagnet||null;r.closestView=r.closestMagnet=null;var h,l=Number.MAX_VALUE,u=z(t,e),c=this.paper;n.forEach(function(i){"false"!==i.el.getAttribute("magnet")&&(o=i.model.getBBox().center().distance(u))<s&&o<l&&(a===i.el||c.options.validateConnection.apply(c,r.validateConnectionArgs(i,null)))&&(l=o,r.closestView=i,r.closestMagnet=i.el),i.$("[magnet]").each(function(t,e){var n=i.getNodeBBox(e);(o=u.distance({x:n.x+n.width/2,y:n.y+n.height/2}))<s&&o<l&&(a===e||c.options.validateConnection.apply(c,r.validateConnectionArgs(i,e)))&&(l=o,r.closestView=i,r.closestMagnet=e)}.bind(this))},this);var d=r.closestView,f=r.closestMagnet,p=r.arrowhead,g=a!==f;if(i&&g&&i.unhighlight(a,{connecting:!0,snapping:!0}),d){if(!g)return;d.highlight(f,{connecting:!0,snapping:!0}),h=d.getLinkEnd(f,t,e,this.model,p)}else h={x:t,y:e};this.model.set(p,h||{x:t,y:e},{ui:!0})},_snapArrowheadEnd:function(t){var e=t.closestView,n=t.closestMagnet;e&&n&&(e.unhighlight(n,{connecting:!0,snapping:!0}),t.magnetUnderPointer=e.findMagnet(n)),t.closestView=t.closestMagnet=null},_connectArrowhead:function(t,e,n,i){i.eventTarget!==t&&(i.magnetUnderPointer&&i.viewUnderPointer.unhighlight(i.magnetUnderPointer,{connecting:!0}),i.viewUnderPointer=this.paper.findView(t),i.viewUnderPointer?(i.magnetUnderPointer=i.viewUnderPointer.findMagnet(t),i.magnetUnderPointer&&this.paper.options.validateConnection.apply(this.paper,i.validateConnectionArgs(i.viewUnderPointer,i.magnetUnderPointer))?i.magnetUnderPointer&&i.viewUnderPointer.highlight(i.magnetUnderPointer,{connecting:!0}):i.magnetUnderPointer=null):i.magnetUnderPointer=null),i.eventTarget=t,this.model.set(i.arrowhead,{x:e,y:n},{ui:!0})},_connectArrowheadEnd:function(t,e,n){var i=t.viewUnderPointer,r=t.magnetUnderPointer;if(r&&i){i.unhighlight(r,{connecting:!0});var o=t.arrowhead,s=i.getLinkEnd(r,e,n,this.model,o);this.model.set(o,s,{ui:!0})}},_beforeArrowheadMove:function(t){t.z=this.model.get("z"),this.model.toFront();var e=this.el.style;t.pointerEvents=e.pointerEvents,e.pointerEvents="none",this.paper.options.markAvailable&&this._markAvailableMagnets(t)},_afterArrowheadMove:function(t){null!==t.z&&(this.model.set("z",t.z,{ui:!0}),t.z=null),this.el.style.pointerEvents=t.pointerEvents,this.paper.options.markAvailable&&this._unmarkAvailableMagnets(t)},_createValidateConnectionArgs:function(t){var e,n=[];n[4]=t,n[5]=this;var i=0,r=0;e="source"===t?(i=2,"target"):(r=2,"source");var o=this.model.get(e);if(o.id){var s=n[i]=this.paper.findViewByModel(o.id),a=s.getMagnetFromLinkEnd(o);a===s.el&&(a=void 0),n[i+1]=a}return function(t,e){return n[r]=t,n[r+1]=t.el===e?void 0:e,n}},_markAvailableMagnets:function(t){function e(t,e){var n=t.paper;return n.options.validateConnection.apply(n,this.validateConnectionArgs(t,e))}var n=this.paper,i=n.model.getCells();t.marked={};for(var r=0,o=i.length;r<o;r++){var s=i[r].findView(n);if(s){var a=Array.prototype.slice.call(s.el.querySelectorAll("[magnet]"));"false"!==s.el.getAttribute("magnet")&&a.push(s.el);var h=a.filter(e.bind(t,s));if(0<h.length){for(var l=0,u=h.length;l<u;l++)s.highlight(h[l],{magnetAvailability:!0});s.highlight(null,{elementAvailability:!0}),t.marked[s.model.id]=h}}}},_unmarkAvailableMagnets:function(t){for(var e,n,i=Object.keys(t.marked),r=0,o=i.length;r<o;r++){e=i[r],n=t.marked[e];var s=this.paper.findViewByModel(e);if(s){for(var a=0,h=n.length;a<h;a++)s.unhighlight(n[a],{magnetAvailability:!0});s.unhighlight(null,{elementAvailability:!0})}}t.marked=null},startArrowheadMove:function(t,e){e||(e={});var n={action:"arrowhead-move",arrowhead:t,whenNotAllowed:e.whenNotAllowed||"revert",initialMagnet:this[t+"Magnet"]||(this[t+"View"]?this[t+"View"].el:null),initialEnd:Ot(this.model.get(t)),validateConnectionArgs:this._createValidateConnectionArgs(t)};return this._beforeArrowheadMove(n),!0!==e.ignoreBackwardsCompatibility&&(this._dragData=n),n}});Object.defineProperty(qi.prototype,"sourceBBox",{enumerable:!0,get:function(){var t=this.sourceView;if(!t){var e=this.model.source();return new X(e.x,e.y)}var n=this.sourceMagnet;return t.isNodeConnection(n)?new X(this.sourceAnchor):t.getNodeBBox(n||t.el)}}),Object.defineProperty(qi.prototype,"targetBBox",{enumerable:!0,get:function(){var t=this.targetView;if(!t){var e=this.model.target();return new X(e.x,e.y)}var n=this.targetMagnet;return t.isNodeConnection(n)?new X(this.targetAnchor):t.getNodeBBox(n||t.el)}});var Hi={NONE:"sorting-none",APPROX:"sorting-approximate",EXACT:"sorting-exact"},$i=1<<30,Yi=1<<29,Xi=Ye.extend({className:"paper",options:{width:800,height:600,origin:{x:0,y:0},gridSize:1,drawGrid:!1,background:!1,perpendicularLinks:!1,elementView:Ze,linkView:qi,snapLinks:!1,multiLinks:!0,guard:function(t,e){return!1},highlighting:{default:{name:"stroke",options:{padding:3}},magnetAvailability:{name:"addClass",options:{className:"available-magnet"}},elementAvailability:{name:"addClass",options:{className:"available-cell"}}},preventContextMenu:!0,preventDefaultBlankAction:!0,restrictTranslate:!1,markAvailable:!1,defaultLink:new pn,defaultConnector:{name:"normal"},defaultRouter:{name:"normal"},defaultAnchor:{name:"center"},defaultLinkAnchor:{name:"connectionRatio"},defaultConnectionPoint:{name:"bbox"},connectionStrategy:null,validateMagnet:function(t,e,n){return"passive"!==e.getAttribute("magnet")},validateConnection:function(t,e,n,i,r,o){return("target"===r?n:t)instanceof Ze},embeddingMode:!1,validateEmbedding:function(t,e){return!0},findParentBy:"bbox",frontParentOnly:!0,interactive:{labelMove:!1},linkPinning:!0,allowLink:null,clickThreshold:0,moveThreshold:0,magnetThreshold:0,sorting:Hi.EXACT,frozen:!1,onViewUpdate:function(t,e,n,i){e&$i||n.mounting||i.requestConnectedLinksUpdate(t,n)},onViewPostponed:function(t,e){return this.forcePostponedViewUpdate(t,e)},viewport:null,cellViewNamespace:null,highlighterNamespace:Dn,anchorNamespace:ji,linkAnchorNamespace:zi,connectionPointNamespace:qn},events:{dblclick:"pointerdblclick",contextmenu:"contextmenu",mousedown:"pointerdown",touchstart:"pointerdown",mouseover:"mouseover",mouseout:"mouseout",mouseenter:"mouseenter",mouseleave:"mouseleave",mousewheel:"mousewheel",DOMMouseScroll:"mousewheel","mouseenter .joint-cell":"mouseenter","mouseleave .joint-cell":"mouseleave","mouseenter .joint-tools":"mouseenter","mouseleave .joint-tools":"mouseleave","mousedown .joint-cell [event]":"onevent","touchstart .joint-cell [event]":"onevent","mousedown .joint-cell [magnet]":"onmagnet","touchstart .joint-cell [magnet]":"onmagnet","dblclick .joint-cell [magnet]":"magnetpointerdblclick","contextmenu .joint-cell [magnet]":"magnetcontextmenu","mousedown .joint-link .label":"onlabel","touchstart .joint-link .label":"onlabel","dragstart .joint-cell image":"onImageDragStart"},documentEvents:{mousemove:"pointermove",touchmove:"pointermove",mouseup:"pointerup",touchend:"pointerup",touchcancel:"pointerup"},svg:null,viewport:null,defs:null,tools:null,$background:null,layers:null,$grid:null,$document:null,_highlights:null,_zPivots:null,_viewportMatrix:null,_viewportTransformString:null,_updates:null,SORT_DELAYING_BATCHES:["add","to-front","to-back"],UPDATE_DELAYING_BATCHES:["translate"],MIN_SCALE:1e-6,init:function(){var t=this.options,e=this.el;t.cellViewNamespace||(t.cellViewNamespace="undefined"!=typeof joint&&Kt(joint,"shapes")?joint.shapes:null);var n=this.model=t.model||new Ui;this.setGrid(t.drawGrid),this.cloneOptions(),this.render(),this.setDimensions(),this.startListening(),this._views={},this._zPivots={},this.$document=C(e.ownerDocument),this._highlights={},this.resetViews(n.attributes.cells.models),!this.isFrozen()&&this.isAsync()&&this.updateViewsAsync()},_resetUpdates:function(){return this._updates={id:null,priorities:[{},{},{}],unmountedCids:[],mountedCids:[],unmounted:{},mounted:{},count:0,keyFrozen:!1,freezeKey:null,sort:!1}},startListening:function(){var t=this.model;this.listenTo(t,"add",this.onCellAdded).listenTo(t,"remove",this.onCellRemoved).listenTo(t,"change",this.onCellChange).listenTo(t,"reset",this.onGraphReset).listenTo(t,"sort",this.onGraphSort).listenTo(t,"batch:stop",this.onGraphBatchStop),this.on("cell:highlight",this.onCellHighlight).on("cell:unhighlight",this.onCellUnhighlight).on("scale translate",this.update)},onCellAdded:function(t,e,n){var i=n.position;this.isAsync()||!le(i)?this.renderView(t,n):(n.maxPosition===i&&this.freeze({key:"addCells"}),this.renderView(t,n),0===i&&this.unfreeze({key:"addCells"}))},onCellRemoved:function(t,e,n){var i=this.findViewByModel(t);i&&this.requestViewUpdate(i,Yi,i.UPDATE_PRIORITY,n)},onCellChange:function(t,e){if(t!==this.model.attributes.cells&&t.hasChanged("z")&&this.options.sorting===Hi.APPROX){var n=this.findViewByModel(t);n&&this.requestViewUpdate(n,$i,n.UPDATE_PRIORITY,e)}},onGraphReset:function(t,e){this.removeZPivots(),this.resetViews(t.models,e)},onGraphSort:function(){this.model.hasActiveBatch(this.SORT_DELAYING_BATCHES)||this.sortViews()},onGraphBatchStop:function(t){if(!this.isFrozen()){var e=t&&t.batchName,n=this.model;if(!this.isAsync()){var i=this.UPDATE_DELAYING_BATCHES;i.includes(e)&&!n.hasActiveBatch(i)&&this.updateViews(t)}var r=this.SORT_DELAYING_BATCHES;r.includes(e)&&!n.hasActiveBatch(r)&&this.sortViews()}},cloneOptions:function(){var t=this.options;t.origin=Nt({},t.origin),t.defaultConnector=Nt({},t.defaultConnector),t.highlighting=Ft({},t.highlighting,this.constructor.prototype.options.highlighting),!t.cellViewNamespace&&"undefined"!=typeof joint&&Kt(joint,"shapes")&&(t.cellViewNamespace=joint.shapes)},children:function(){var t=K.namespace;return[{namespaceURI:t.xhtml,tagName:"div",className:tt("paper-background"),selector:"background"},{namespaceURI:t.xhtml,tagName:"div",className:tt("paper-grid"),selector:"grid"},{namespaceURI:t.svg,tagName:"svg",attributes:{width:"100%",height:"100%","xmlns:xlink":t.xlink},selector:"svg",children:[{tagName:"defs",selector:"defs"},{tagName:"g",className:tt("layers"),selector:"layers",children:[{tagName:"g",className:tt("cells-layer viewport"),selector:"cells"},{tagName:"g",className:tt("tools-layer"),selector:"tools"}]}]}]},render:function(){this.renderChildren();var t=this.childNodes,e=this.options,n=t.svg,i=t.cells,r=t.defs,o=t.tools,s=t.layers,a=t.background,h=t.grid;return this.svg=n,this.defs=r,this.tools=o,this.cells=i,this.layers=s,this.$background=C(a),this.$grid=C(h),K.ensureId(n),this.viewport=i,e.background&&this.drawBackground(e.background),e.drawGrid&&this.drawGrid(),this},update:function(){return this.options.drawGrid&&this.drawGrid(),this._background&&this.updateBackgroundImage(this._background),this},matrix:function(t){var e=this.layers;if(void 0===t){var n=e.getAttribute("transform");return(this._viewportTransformString||null)===n?t=this._viewportMatrix:(t=e.getCTM(),this._viewportMatrix=t,this._viewportTransformString=n),K.createSVGMatrix(t)}t=K.createSVGMatrix(t);var i=K.matrixToTransformString(t);return e.setAttribute("transform",i),this._viewportMatrix=t,this._viewportTransformString=e.getAttribute("transform"),this},clientMatrix:function(){return K.createSVGMatrix(this.cells.getScreenCTM())},requestConnectedLinksUpdate:function(t,e){if(t instanceof We)for(var n=t.model,i=this.model.getConnectedLinks(n),r=0,o=i.length;r<o;r++){var s=i[r],a=this.findViewByModel(s);if(a){var h=["UPDATE"];s.getTargetCell()===n&&h.push("TARGET"),s.getSourceCell()===n&&h.push("SOURCE"),this.scheduleViewUpdate(a,a.getFlag(h),a.UPDATE_PRIORITY,e)}}},forcePostponedViewUpdate:function(t,e){if(!(t&&t instanceof We))return!1;var n=t.model;if(n.isElement())return!1;if(0==(e&t.getFlag(["SOURCE","TARGET"]))){var i=0,r=this.findViewByModel(n.getSourceCell());r&&!this.isViewMounted(r)&&(i=this.dumpView(r),t.updateEndMagnet("source"));var o=0,s=this.findViewByModel(n.getTargetCell());if(s&&!this.isViewMounted(s)&&(o=this.dumpView(s),t.updateEndMagnet("target")),0===i&&0===o)return!!this.dumpView(t)}return!1},requestViewUpdate:function(t,e,n,i){i||(i={}),this.scheduleViewUpdate(t,e,n,i);var r=this.isAsync();if(!(this.isFrozen()||r&&!1!==i.async||this.model.hasActiveBatch(this.UPDATE_DELAYING_BATCHES))){var o=this.updateViews(i);r&&this.trigger("render:done",o,i)}},scheduleViewUpdate:function(t,e,n,i){var r=this._updates,o=r.priorities[n];o||(o=r.priorities[n]={});var s=o[t.cid]||0;if((s&e)!==e){s||r.count++,e&Yi&&s&$i?o[t.cid]^=$i:e&$i&&s&Yi&&(o[t.cid]^=Yi),o[t.cid]|=e;var a=this.options.onViewUpdate;"function"==typeof a&&a.call(this,t,e,i||{},this)}},dumpViewUpdate:function(t){if(!t)return 0;var e=this._updates,n=t.cid,i=e.priorities[t.UPDATE_PRIORITY],r=this.registerMountedView(t)|i[n];return delete i[n],r},dumpView:function(t,e){var n=this.dumpViewUpdate(t);return n?this.updateView(t,n,e):0},updateView:function(t,e,n){if(!t)return 0;if(t instanceof We){if(e&Yi)return this.removeView(t.model),0;e&$i&&(this.insertView(t),e^=$i)}return e?t.confirmUpdate(e,n||{}):0},requireView:function(t,e){var n=this.findViewByModel(t);return n?(this.dumpView(n,e),n):null},registerUnmountedView:function(t){var e=t.cid,n=this._updates;if(e in n.unmounted)return 0;var i=n.unmounted[e]|=$i;return n.unmountedCids.push(e),delete n.mounted[e],i},registerMountedView:function(t){var e=t.cid,n=this._updates;if(e in n.mounted)return 0;n.mounted[e]=!0,n.mountedCids.push(e);var i=n.unmounted[e]||0;return delete n.unmounted[e],i},isViewMounted:function(t){return!!t&&t.cid in this._updates.mounted},dumpViews:function(t){var e=Vt({},t,{viewport:null});this.checkViewport(e),this.updateViews(e)},updateViews:function(t){for(var e,n=0,i=0,r=2;i++,n+=(e=this.updateViewsBatch(t)).updated,r=Math.min(e.priority,r),!e.empty;);return{updated:n,batches:i,priority:r}},updateViewsAsync:function(t,e){t||(t={}),e||(e={processed:0,priority:2});var n=this._updates,i=n.id;if(i){ft(i);var r=this.updateViewsBatch(t),o=Vt({},t,{mountBatchSize:1e3-r.mounted,unmountBatchSize:1e3-r.unmounted}),s=this.checkViewport(o),a=s.unmounted,h=s.mounted,l=e.processed,u=n.count;0<r.updated&&(l+=r.updated+r.unmounted,r.processed=l,e.priority=Math.min(r.priority,e.priority),r.empty&&0===h?(r.unmounted+=a,r.mounted+=h,r.priority=e.priority,this.trigger("render:done",r,t),e.processed=0,n.count=0):e.processed=l);var c=t.progress;if(u&&"function"==typeof c&&c.call(this,r.empty,l,u,r,this),n.id!==i)return}n.id=dt(this.updateViewsAsync,this,t,e)},updateViewsBatch:function(t){t||(t={});var e=t.batchSize||1/0,n=this._updates,i=0,r=0,o=0,s=0,a=2,h=!0,l=this.options,u=n.priorities,c="viewport"in t?t.viewport:l.viewport;"function"!=typeof c&&(c=null);var d=l.onViewPostponed;"function"!=typeof d&&(d=null);t:for(var f=0,p=u.length;f<p;f++){var g=u[f];for(var v in g){if(e<=i){h=!1;break t}var m=$e[v];if(m){var y=g[v];if(0==(y&Yi)){var w=v in n.unmounted;if(c&&!c.call(this,m,w,this)){w||(this.registerUnmountedView(m),m.unmount()),n.unmounted[v]|=y,delete g[v],o++;continue}w&&(y|=$i,s++),y|=this.registerMountedView(m)}var b=this.updateView(m,y,t);0<b&&(g[v]=b,!d||!d.call(this,m,b,this)||g[v])?(r++,h=!1):(f<a&&(a=f),i++,delete g[v])}else delete g[v]}}return{priority:a,updated:i,postponed:r,unmounted:o,mounted:s,empty:h}},getUnmountedViews:function(){for(var t=this._updates,e=Object.keys(t.unmounted),n=e.length,i=new Array(n),r=0;r<n;r++)i[r]=$e[e[r]];return i},getMountedViews:function(){for(var t=this._updates,e=Object.keys(t.mounted),n=e.length,i=new Array(n),r=0;r<n;r++)i[r]=$e[e[r]];return i},checkUnmountedViews:function(t,e){e||(e={});var n=0;"function"!=typeof t&&(t=null);for(var i=("mountBatchSize"in e?e.mountBatchSize:1/0),r=this._updates,o=r.unmountedCids,s=r.unmounted,a=0,h=Math.min(o.length,i);a<h;a++){var l=o[a];if(l in s){var u=$e[l];if(u)if(!t||t.call(this,u,!1,this)){n++;var c=this.registerMountedView(u);c&&this.scheduleViewUpdate(u,c,u.UPDATE_PRIORITY,{mounting:!0})}else o.push(l)}}return o.splice(0,a),n},checkMountedViews:function(t,e){e||(e={});var n=0;if("function"!=typeof t)return n;for(var i=("unmountBatchSize"in e?e.unmountBatchSize:1/0),r=this._updates,o=r.mountedCids,s=r.mounted,a=0,h=Math.min(o.length,i);a<h;a++){var l=o[a];if(l in s){var u=$e[l];if(u)if(t.call(this,u,!0,this))o.push(l);else n++,this.registerUnmountedView(u)&&u.unmount()}}return o.splice(0,a),n},checkViewport:function(t){var e=Vt({},t,{mountBatchSize:1/0,unmountBatchSize:1/0}),n="viewport"in e?e.viewport:this.options.viewport,i=this.checkMountedViews(n,e);if(0<i){var r=this._updates.unmountedCids;e.mountBatchSize=Math.min(r.length-i,e.mountBatchSize)}return{mounted:this.checkUnmountedViews(n,e),unmounted:i}},freeze:function(t){t||(t={});var e=this._updates,n=t.key,i=this.options.frozen,r=e.freezeKey;if(n&&n!==r){if(i&&r)return;e.freezeKey=n,e.keyFrozen=i}this.options.frozen=!0;var o=e.id;e.id=null,this.isAsync()&&o&&ft(o)},unfreeze:function(t){t||(t={});var e=this._updates,n=t.key,i=e.freezeKey;n&&i&&n!==i||(e.freezeKey=null,n&&n===i&&e.keyFrozen||(this.isAsync()?(this.freeze(),this.updateViewsAsync(t)):this.updateViews(t),this.options.frozen=e.keyFrozen=!1,e.sort&&(this.sortViews(),e.sort=!1)))},isAsync:function(){return!!this.options.async},isFrozen:function(){return!!this.options.frozen},isExactSorting:function(){return this.options.sorting===Hi.EXACT},onRemove:function(){this.freeze(),this.removeViews()},getComputedSize:function(){var t=this.options,e=t.width,n=t.height;return le(e)||(e=this.el.clientWidth),le(n)||(n=this.el.clientHeight),{width:e,height:n}},setDimensions:function(t,e){var n=this.options,i=void 0===t?n.width:t,r=void 0===e?n.height:e;this.options.width=i,this.options.height=r,le(i)&&(i=Math.round(i)),le(r)&&(r=Math.round(r)),this.$el.css({width:null===i?"":i,height:null===r?"":r});var o=this.getComputedSize();this.trigger("resize",o.width,o.height)},setOrigin:function(t,e){return this.translate(t||0,e||0,{absolute:!0})},fitToContent:function(t,e,n,i){n=he(t)?(t=(i=t).gridWidth||1,e=i.gridHeight||1,i.padding||0):(i||(i={}),t=t||1,e=e||1,n||0),n=xt(n);var r="contentArea"in i?new X(i.contentArea):this.getContentArea(i),o=this.scale(),s=this.translate(),a=o.sx,h=o.sy;r.x*=a,r.y*=h,r.width*=a,r.height*=h;var l=Math.max(Math.ceil((r.width+r.x)/t),1)*t,u=Math.max(Math.ceil((r.height+r.y)/e),1)*e,c=0,d=0;("negative"==i.allowNewOrigin&&r.x<0||"positive"==i.allowNewOrigin&&0<=r.x||"any"==i.allowNewOrigin)&&(c=Math.ceil(-r.x/t)*t,l+=c+=n.left),("negative"==i.allowNewOrigin&&r.y<0||"positive"==i.allowNewOrigin&&0<=r.y||"any"==i.allowNewOrigin)&&(d=Math.ceil(-r.y/e)*e,u+=d+=n.top),l+=n.right,u+=n.bottom,l=Math.max(l,i.minWidth||0),u=Math.max(u,i.minHeight||0),l=Math.min(l,i.maxWidth||Number.MAX_VALUE),u=Math.min(u,i.maxHeight||Number.MAX_VALUE);var f=this.getComputedSize(),p=l!=f.width||u!=f.height;return(c!=s.tx||d!=s.ty)&&this.translate(c,d),p&&this.setDimensions(l,u),new X(-c/a,-d/h,l/a,u/h)},scaleContentToFit:function(t){var e,n;if(t||(t={}),"contentArea"in t){var i=t.contentArea;e=this.localToPaperRect(i),n=new z(i)}else e=this.getContentBBox(t),n=this.paperToLocalPoint(e);if(e.width&&e.height){Vt(t,{padding:0,preserveAspectRatio:!0,scaleGrid:null,minScale:0,maxScale:Number.MAX_VALUE});var r,o=t.padding,s=t.minScaleX||t.minScale,a=t.maxScaleX||t.maxScale,h=t.minScaleY||t.minScale,l=t.maxScaleY||t.maxScale;if(t.fittingBBox)r=t.fittingBBox;else{var u=this.translate(),c=this.getComputedSize();r={x:u.tx,y:u.ty,width:c.width,height:c.height}}r=new X(r).inflate(-o);var d=this.scale(),f=r.width/e.width*d.sx,p=r.height/e.height*d.sy;if(t.preserveAspectRatio&&(f=p=Math.min(f,p)),t.scaleGrid){var g=t.scaleGrid;f=g*Math.floor(f/g),p=g*Math.floor(p/g)}f=Math.min(a,Math.max(s,f)),p=Math.min(l,Math.max(h,p));var v=this.options.origin,m=r.x-n.x*f-v.x,y=r.y-n.y*p-v.y;this.scale(f,p),this.translate(m,y)}},getContentArea:function(t){return t&&t.useModelGeometry?this.model.getBBox()||new X:K(this.cells).getBBox()},getContentBBox:function(t){return this.localToPaperRect(this.getContentArea(t))},getArea:function(){return this.paperToLocalRect(this.getComputedSize())},getRestrictedArea:function(){return jt(this.options.restrictTranslate)?this.options.restrictTranslate.apply(this,arguments):!0===this.options.restrictTranslate?this.getArea():this.options.restrictTranslate||null},createViewForModel:function(t){var e,n,i=this.options.cellViewNamespace,r=t.get("type")+"View",o=rt(i,r,".");return n=t.isLink()?(e=this.options.linkView,qi):(e=this.options.elementView,Ze),new(e.prototype instanceof s.View?o||e:e.call(this,t)||o||n)({model:t,interactive:this.options.interactive})},removeView:function(t){var e=t.id,n=this._views,i=this._updates,r=n[e];if(r){var o=r.cid,s=i.mounted,a=i.unmounted;r.remove(),delete n[e],delete s[o],delete a[o]}return r},renderView:function(t,e){var n,i,r=t.id,o=this._views;return i=r in o?(n=o[r],$i):((n=o[t.id]=this.createViewForModel(t)).paper=this).registerUnmountedView(n)|n.getFlag(n.initFlag),this.requestViewUpdate(n,i,n.UPDATE_PRIORITY,e),n},onImageDragStart:function(){return!1},resetViews:function(t,e){e||(e={}),t||(t=[]),this._resetUpdates(),this.removeViews(),this.freeze({key:"reset"});for(var n=0,i=t.length;n<i;n++)this.renderView(t[n],e);this.unfreeze({key:"reset"}),this.sortViews()},removeViews:function(){_t(this._views,"remove"),this._views={}},sortViews:function(){this.isExactSorting()&&(this.isFrozen()?this._updates.sort=!0:this.sortViewsExact())},sortViewsExact:function(){var t=C(this.cells).children("[model-id]"),s=this.model.get("cells");bt(t,function(t,e){var n=s.get(t.getAttribute("model-id")),i=s.get(e.getAttribute("model-id")),r=n.attributes.z||0,o=i.attributes.z||0;return r===o?0:r<o?-1:1})},insertView:function(t){var e=this.cells;switch(this.options.sorting){case Hi.APPROX:var n=t.model.get("z"),i=this.addZPivot(n);e.insertBefore(t.el,i);break;case Hi.EXACT:default:e.appendChild(t.el)}},addZPivot:function(t){(t=+t)||(t=0);var e=this._zPivots,n=e[t];if(n)return n;n=e[t]=document.createComment("z-index:"+(t+1));var i=-1/0;for(var r in e)(r=+r)<t&&i<r&&(i=r);var o=this.cells;if(i!==-1/0){var s=e[i];o.insertBefore(n,s.nextSibling)}else o.insertBefore(n,o.firstChild);return n},removeZPivots:function(){var t=this._zPivots,e=this.viewport;for(var n in t)e.removeChild(t[n]);this._zPivots={}},scale:function(t,e,n,i){if(void 0===t)return K.matrixToScale(this.matrix());void 0===e&&(e=t),void 0===n&&(i=n=0);var r=this.translate();if(n||i||r.tx||r.ty){var o=r.tx-n*(t-1),s=r.ty-i*(e-1);this.translate(o,s)}t=Math.max(t||0,this.MIN_SCALE),e=Math.max(e||0,this.MIN_SCALE);var a=this.matrix();return a.a=t,a.d=e,this.matrix(a),this.trigger("scale",t,e,n,i),this},rotate:function(t,e,n){if(void 0===t)return K.matrixToRotate(this.matrix());if(void 0===e){var i=this.cells.getBBox();e=i.width/2,n=i.height/2}var r=this.matrix().translate(e,n).rotate(t).translate(-e,-n);return this.matrix(r),this},translate:function(t,e){if(void 0===t)return K.matrixToTranslate(this.matrix());var n=this.matrix();n.e=t||0,n.f=e||0,this.matrix(n);var i=this.translate(),r=this.options.origin;return r.x=i.tx,r.y=i.ty,this.trigger("translate",i.tx,i.ty),this.options.drawGrid&&this.drawGrid(),this},findView:function(t){var e=ue(t)?this.cells.querySelector(t):t instanceof C?t[0]:t,n=this.findAttribute("model-id",e);if(n)return this._views[n]},findViewByModel:function(t){var e=ue(t)||le(t)?t:t&&t.id;return this._views[e]},findViewsFromPoint:function(e){return e=new z(e),this.model.getElements().map(this.findViewByModel,this).filter(function(t){return t&&t.vel.getBBox({target:this.cells}).containsPoint(e)},this)},findViewsInArea:function(e,t){t=Vt(t||{},{strict:!1}),e=new X(e);var n=this.model.getElements().map(this.findViewByModel,this),i=t.strict?"containsRect":"intersect";return n.filter(function(t){return t&&e[i](t.vel.getBBox({target:this.cells}))},this)},removeTools:function(){return this.dispatchToolsEvent("remove"),this},hideTools:function(){return this.dispatchToolsEvent("hide"),this},showTools:function(){return this.dispatchToolsEvent("show"),this},dispatchToolsEvent:function(t){for(var e,n=[],i=arguments.length-1;0<i--;)n[i]=arguments[i+1];"string"==typeof t&&(e=this).trigger.apply(e,["tools:event",t].concat(n))},getModelById:function(t){return this.model.getCell(t)},snapToGrid:function(t,e){return this.clientToLocalPoint(t,e).snapToGrid(this.options.gridSize)},localToPaperPoint:function(t,e){var n=new z(t,e);return K.transformPoint(n,this.matrix())},localToPaperRect:function(t,e,n,i){var r=new X(t,e,n,i);return K.transformRect(r,this.matrix())},paperToLocalPoint:function(t,e){var n=new z(t,e);return K.transformPoint(n,this.matrix().inverse())},paperToLocalRect:function(t,e,n,i){var r=new X(t,e,n,i);return K.transformRect(r,this.matrix().inverse())},localToClientPoint:function(t,e){var n=new z(t,e);return K.transformPoint(n,this.clientMatrix())},localToClientRect:function(t,e,n,i){var r=new X(t,e,n,i);return K.transformRect(r,this.clientMatrix())},clientToLocalPoint:function(t,e){var n=new z(t,e);return K.transformPoint(n,this.clientMatrix().inverse())},clientToLocalRect:function(t,e,n,i){var r=new X(t,e,n,i);return K.transformRect(r,this.clientMatrix().inverse())},localToPagePoint:function(t,e){return this.localToPaperPoint(t,e).offset(this.pageOffset())},localToPageRect:function(t,e,n,i){return this.localToPaperRect(t,e,n,i).offset(this.pageOffset())},pageToLocalPoint:function(t,e){var n=new z(t,e).difference(this.pageOffset());return this.paperToLocalPoint(n)},pageToLocalRect:function(t,e,n,i){var r=this.pageOffset(),o=new X(t,e,n,i);return o.x-=r.x,o.y-=r.y,this.paperToLocalRect(o)},clientOffset:function(){var t=this.svg.getBoundingClientRect();return new z(t.left,t.top)},pageOffset:function(){return this.clientOffset().offset(window.scrollX,window.scrollY)},linkAllowed:function(t){if(!(t instanceof qi))throw new Error("Must provide a linkView.");var e=t.model,n=this.options,i=this.model,r=i.constructor.validations;return!(!n.multiLinks&&!r.multiLinks.call(this,i,e))&&(!(!n.linkPinning&&!r.linkPinning.call(this,i,e))&&!("function"==typeof n.allowLink&&!n.allowLink.call(this,t,this)))},getDefaultLink:function(t,e){return jt(this.options.defaultLink)?this.options.defaultLink.call(this,t,e):this.options.defaultLink.clone()},resolveHighlighter:function(e){var t=(e=e||{}).highlighter,n=this.options;if(void 0===t){var i=["embedding","connecting","magnetAvailability","elementAvailability"].find(function(t){return!!e[t]});t=i&&n.highlighting[i]||n.highlighting.default}if(!t)return!1;ue(t)&&(t={name:t});var r=t.name,o=n.highlighterNamespace[r];if(!o)throw new Error('Unknown highlighter ("'+r+'")');if("function"!=typeof o.highlight)throw new Error('Highlighter ("'+r+'") is missing required highlight() method');if("function"!=typeof o.unhighlight)throw new Error('Highlighter ("'+r+'") is missing required unhighlight() method');return{highlighter:o,options:t.options||{},name:r}},onCellHighlight:function(t,e,n){if(n=this.resolveHighlighter(n)){e.id||(e.id=K.uniqueId());var i=n.name+e.id+JSON.stringify(n.options);if(!this._highlights[i]){var r=n.highlighter;r.highlight(t,e,Nt({},n.options)),this._highlights[i]={cellView:t,magnetEl:e,opt:n.options,highlighter:r}}}},onCellUnhighlight:function(t,e,n){if(n=this.resolveHighlighter(n)){var i=n.name+e.id+JSON.stringify(n.options),r=this._highlights[i];r&&(r.highlighter.unhighlight(r.cellView,r.magnetEl,r.opt),this._highlights[i]=null)}},pointerdblclick:function(t){t.preventDefault(),t=ct(t);var e=this.findView(t.target);if(!this.guard(t,e)){var n=this.snapToGrid(t.clientX,t.clientY);e?e.pointerdblclick(t,n.x,n.y):this.trigger("blank:pointerdblclick",t,n.x,n.y)}},pointerclick:function(t){if(this.eventData(t).mousemoved<=this.options.clickThreshold){t=ct(t);var e=this.findView(t.target);if(this.guard(t,e))return;var n=this.snapToGrid(t.clientX,t.clientY);e?e.pointerclick(t,n.x,n.y):this.trigger("blank:pointerclick",t,n.x,n.y)}},contextmenu:function(t){this.options.preventContextMenu&&t.preventDefault(),t=ct(t);var e=this.findView(t.target);if(!this.guard(t,e)){var n=this.snapToGrid(t.clientX,t.clientY);e?e.contextmenu(t,n.x,n.y):this.trigger("blank:contextmenu",t,n.x,n.y)}},pointerdown:function(t){t=ct(t);var e=this.findView(t.target);if(!this.guard(t,e)){var n=this.snapToGrid(t.clientX,t.clientY);e?(t.preventDefault(),e.pointerdown(t,n.x,n.y)):(this.options.preventDefaultBlankAction&&t.preventDefault(),this.trigger("blank:pointerdown",t,n.x,n.y)),this.delegateDragEvents(e,t.data)}},pointermove:function(t){var e=this.eventData(t);if(e.mousemoved||(e.mousemoved=0),!(++e.mousemoved<=this.options.moveThreshold)){t=ct(t);var n=this.snapToGrid(t.clientX,t.clientY),i=e.sourceView;i?i.pointermove(t,n.x,n.y):this.trigger("blank:pointermove",t,n.x,n.y),this.eventData(t,e)}},pointerup:function(t){this.undelegateDocumentEvents();var e=ct(t),n=this.snapToGrid(e.clientX,e.clientY),i=this.eventData(t).sourceView;i?i.pointerup(e,n.x,n.y):this.trigger("blank:pointerup",e,n.x,n.y),e.isPropagationStopped()||this.pointerclick(C.Event(t,{type:"click",data:t.data})),t.stopImmediatePropagation(),this.delegateEvents()},mouseover:function(t){t=ct(t);var e=this.findView(t.target);if(!this.guard(t,e))if(e)e.mouseover(t);else{if(this.el===t.target)return;this.trigger("blank:mouseover",t)}},mouseout:function(t){t=ct(t);var e=this.findView(t.target);if(!this.guard(t,e))if(e)e.mouseout(t);else{if(this.el===t.target)return;this.trigger("blank:mouseout",t)}},mouseenter:function(t){t=ct(t);var e=this.findView(t.target);if(!this.guard(t,e)){var n=this.findView(t.relatedTarget);if(e){if(n===e)return;e.mouseenter(t)}else{if(n)return;this.trigger("paper:mouseenter",t)}}},mouseleave:function(t){t=ct(t);var e=this.findView(t.target);if(!this.guard(t,e)){var n=this.findView(t.relatedTarget);if(e){if(n===e)return;e.mouseleave(t)}else{if(n)return;this.trigger("paper:mouseleave",t)}}},mousewheel:function(t){t=ct(t);var e=this.findView(t.target);if(!this.guard(t,e)){var n=t.originalEvent,i=this.snapToGrid(n.clientX,n.clientY),r=Math.max(-1,Math.min(1,n.wheelDelta||-n.detail));e?e.mousewheel(t,i.x,i.y,r):this.trigger("blank:mousewheel",t,i.x,i.y,r)}},onevent:function(t){var e=t.currentTarget,n=e.getAttribute("event");if(n){var i=this.findView(e);if(i){if(t=ct(t),this.guard(t,i))return;var r=this.snapToGrid(t.clientX,t.clientY);i.onevent(t,n,r.x,r.y)}}},magnetEvent:function(t,e){var n=t.currentTarget;if(n.getAttribute("magnet")){var i=this.findView(n);if(i){if(t=ct(t),this.guard(t,i))return;var r=this.snapToGrid(t.clientX,t.clientY);e.call(this,i,t,n,r.x,r.y)}}},onmagnet:function(t){this.magnetEvent(t,function(t,e,n,i,r){t.onmagnet(e,i,r)})},magnetpointerdblclick:function(t){this.magnetEvent(t,function(t,e,n,i,r){t.magnetpointerdblclick(e,n,i,r)})},magnetcontextmenu:function(t){this.options.preventContextMenu&&t.preventDefault(),this.magnetEvent(t,function(t,e,n,i,r){t.magnetcontextmenu(e,n,i,r)})},onlabel:function(t){var e=t.currentTarget,n=this.findView(e);if(n){if(t=ct(t),this.guard(t,n))return;var i=this.snapToGrid(t.clientX,t.clientY);n.onlabel(t,i.x,i.y)}},getPointerArgs:function(t){var e=ct(t),n=this.snapToGrid(e.clientX,e.clientY);return[e,n.x,n.y]},delegateDragEvents:function(t,e){e||(e={}),this.eventData({data:e},{sourceView:t||null,mousemoved:0}),this.delegateDocumentEvents(null,e),this.undelegateEvents()},guard:function(t,e){return"mousedown"===t.type&&2===t.button||(!(!this.options.guard||!this.options.guard(t,e))||(t.data&&void 0!==t.data.guarded?t.data.guarded:!(e&&e.model&&e.model instanceof Ce)&&(this.svg!==t.target&&this.el!==t.target&&!C.contains(this.svg,t.target))))},setGridSize:function(t){return this.options.gridSize=t,this.options.drawGrid&&this.drawGrid(),this},clearGrid:function(){return this.$grid&&this.$grid.css("backgroundImage","none"),this},_getGridRefs:function(){return this._gridCache||(this._gridCache={root:K("svg",{width:"100%",height:"100%"},K("defs")),patterns:{},add:function(t,e){K(this.root.node.childNodes[0]).append(e),this.patterns[t]=e,this.root.append(K("rect",{width:"100%",height:"100%",fill:"url(#"+t+")"}))},get:function(t){return this.patterns[t]},exist:function(t){return void 0!==this.patterns[t]}}),this._gridCache},setGrid:function(t){return this.clearGrid(),this._gridCache=null,this._gridSettings=[],(Array.isArray(t)?t:[t||{}]).forEach(function(t){this._gridSettings.push.apply(this._gridSettings,this._resolveDrawGridOption(t))},this),this},_resolveDrawGridOption:function(t){var e=this.constructor.gridPatterns;if(ue(t)&&Array.isArray(e[t]))return e[t].map(function(t){return Nt({},t)});var n=t||{args:[{}]},i=Array.isArray(n),r=n.name;if(i||r||n.markup||(r="dot"),r&&Array.isArray(e[r])){var o=e[r].map(function(t){return Nt({},t)}),s=Array.isArray(n.args)?n.args:[n.args||{}];Vt(s[0],te(t,"args"));for(var a=0;a<s.length;a++)o[a]&&Nt(o[a],s[a]);return o}return i?n:[n]},drawGrid:function(t){var a=this.options.gridSize;if(a<=1)return this.clearGrid();var h=Array.isArray(t)?t:[t],l=this.matrix(),u=this._getGridRefs();this._gridSettings.forEach(function(t,e){var n="pattern_"+e,i=se(t,h[e],{sx:l.a||1,sy:l.d||1,ox:l.e||0,oy:l.f||0});i.width=a*(l.a||1)*(i.scaleFactor||1),i.height=a*(l.d||1)*(i.scaleFactor||1),u.exist(n)||u.add(n,K("pattern",{id:n,patternUnits:"userSpaceOnUse"},K(i.markup)));var r=u.get(n);jt(i.update)&&i.update(r.node.childNodes[0],i);var o=i.ox%i.width;o<0&&(o+=i.width);var s=i.oy%i.height;s<0&&(s+=i.height),r.attr({x:o,y:s,width:i.width,height:i.height})});var e=(new XMLSerializer).serializeToString(u.root.node);return e="url(data:image/svg+xml;base64,"+btoa(e)+")",this.$grid.css("backgroundImage",e),this},updateBackgroundImage:function(t){var e=(t=t||{}).position||"center",n=t.size||"auto auto",i=this.scale(),r=this.translate();he(e)&&(e=r.tx+i.sx*(e.x||0)+"px "+(r.ty+i.sy*(e.y||0))+"px");he(n)&&(n=(n=new X(n).scale(i.sx,i.sy)).width+"px "+n.height+"px"),this.$background.css({backgroundSize:n,backgroundPosition:e})},drawBackgroundImage:function(t,e){if(t instanceof HTMLImageElement){var n,i=(e=e||{}).size,r=e.repeat||"no-repeat",o=e.opacity||1,s=Math.abs(e.quality)||1,a=this.constructor.backgroundPatterns[re(r)];if(jt(a)){t.width*=s,t.height*=s;var h=a(t,e);if(!(h instanceof HTMLCanvasElement))throw new Error("dia.Paper: background pattern must return an HTML Canvas instance");n=h.toDataURL("image/png"),r="repeat",he(i)?(i.width*=h.width/t.width,i.height*=h.height/t.height):void 0===i&&(e.size={width:h.width/s,height:h.height/s})}else n=t.src,void 0===i&&(e.size={width:t.width,height:t.height});this.$background.css({opacity:o,backgroundRepeat:r,backgroundImage:"url("+n+")"}),this.updateBackgroundImage(e)}else this.$background.css("backgroundImage","")},updateBackgroundColor:function(t){this.$el.css("backgroundColor",t||"")},drawBackground:function(t){if(t=t||{},this.updateBackgroundColor(t.color),t.image){t=this._background=Dt(t);var e=document.createElement("img");e.onload=this.drawBackgroundImage.bind(this,e,t),e.src=t.image}else this.drawBackgroundImage(null),this._background=null;return this},setInteractivity:function(t){this.options.interactive=t,_t(this._views,"setInteractivity",t)},isDefined:function(t){return!!this.svg.getElementById(t)},defineFilter:function(t){if(!he(t))throw new TypeError("dia.Paper: defineFilter() requires 1. argument to be an object.");var e=t.id,n=t.name;if(e||(e=n+this.svg.id+it(JSON.stringify(t))),!this.isDefined(e)){var i=St,r=i[n]&&i[n](t.args||{});if(!r)throw new Error("Non-existing filter "+n);var o=Nt({filterUnits:"objectBoundingBox",x:-1,y:-1,width:3,height:3},t.attrs,{id:e});K(r,o).appendTo(this.defs)}return e},defineGradient:function(t){if(!he(t))throw new TypeError("dia.Paper: defineGradient() requires 1. argument to be an object.");var e=t.id,n=t.type,i=t.stops;if(e||(e=n+this.svg.id+it(JSON.stringify(t))),!this.isDefined(e)){var r=Et('<stop offset="${offset}" stop-color="${color}" stop-opacity="${opacity}"/>'),o=["<"+n+">",Ut(i).map(function(t){return r({offset:t.offset,color:t.color,opacity:Number.isFinite(t.opacity)?t.opacity:1})}).join(""),"</"+n+">"].join(""),s=Nt({id:e},t.attrs);K(o,s).appendTo(this.defs)}return e},defineMarker:function(t){if(!he(t))throw new TypeError("dia.Paper: defineMarker() requires 1. argument to be an object.");var e=t.id;if(e||(e=this.svg.id+it(JSON.stringify(t))),!this.isDefined(e)){var n=te(t,"type","userSpaceOnUse");K("marker",{id:e,orient:"auto",overflow:"visible",markerUnits:t.markerUnits||"userSpaceOnUse"},[K(t.type||"path",n)]).appendTo(this.defs)}return e}},{sorting:Hi,backgroundPatterns:{flipXy:function(t){var e=document.createElement("canvas"),n=t.width,i=t.height;e.width=2*n,e.height=2*i;var r=e.getContext("2d");return r.drawImage(t,0,0,n,i),r.setTransform(-1,0,0,-1,e.width,e.height),r.drawImage(t,0,0,n,i),r.setTransform(-1,0,0,1,e.width,0),r.drawImage(t,0,0,n,i),r.setTransform(1,0,0,-1,0,e.height),r.drawImage(t,0,0,n,i),e},flipX:function(t){var e=document.createElement("canvas"),n=t.width,i=t.height;e.width=2*n,e.height=i;var r=e.getContext("2d");return r.drawImage(t,0,0,n,i),r.translate(2*n,0),r.scale(-1,1),r.drawImage(t,0,0,n,i),e},flipY:function(t){var e=document.createElement("canvas"),n=t.width,i=t.height;e.width=n,e.height=2*i;var r=e.getContext("2d");return r.drawImage(t,0,0,n,i),r.translate(0,2*i),r.scale(1,-1),r.drawImage(t,0,0,n,i),e},watermark:function(t,e){e=e||{};var n=t.width,i=t.height,r=document.createElement("canvas");r.width=3*n,r.height=3*i;for(var o=r.getContext("2d"),s=le(e.watermarkAngle)?-e.watermarkAngle:-20,a=A(s),h=r.width/4,l=r.height/4,u=0;u<4;u++)for(var c=0;c<4;c++)0<(u+c)%2&&(o.setTransform(1,0,0,1,(2*u-1)*h,(2*c-1)*l),o.rotate(a),o.drawImage(t,-n/2,-i/2,n,i));return r}},gridPatterns:{dot:[{color:"#AAAAAA",thickness:1,markup:"rect",update:function(t,e){K(t).attr({width:e.thickness*e.sx,height:e.thickness*e.sy,fill:e.color})}}],fixedDot:[{color:"#AAAAAA",thickness:1,markup:"rect",update:function(t,e){var n=e.sx<=1?e.thickness*e.sx:e.thickness;K(t).attr({width:n,height:n,fill:e.color})}}],mesh:[{color:"#AAAAAA",thickness:1,markup:"path",update:function(t,e){var n,i=e.width,r=e.height,o=e.thickness;n=0<=i-o&&0<=r-o?["M",i,0,"H0 M0 0 V0",r].join(" "):"M 0 0 0 0",K(t).attr({d:n,stroke:e.color,"stroke-width":e.thickness})}}],doubleMesh:[{color:"#AAAAAA",thickness:1,markup:"path",update:function(t,e){var n,i=e.width,r=e.height,o=e.thickness;n=0<=i-o&&0<=r-o?["M",i,0,"H0 M0 0 V0",r].join(" "):"M 0 0 0 0",K(t).attr({d:n,stroke:e.color,"stroke-width":e.thickness})}},{color:"#000000",thickness:3,scaleFactor:4,markup:"path",update:function(t,e){var n,i=e.width,r=e.height,o=e.thickness;n=0<=i-o&&0<=r-o?["M",i,0,"H0 M0 0 V0",r].join(" "):"M 0 0 0 0",K(t).attr({d:n,stroke:e.color,"stroke-width":e.thickness})}}]}}),Wi=Ye.extend({name:null,tagName:"g",className:"tool",svgElement:!0,_visible:!0,init:function(){var t=this.name;t&&this.vel.attr("data-tool-name",t)},configure:function(t,e){return this.relatedView=t,this.paper=t.paper,this.parentView=e,this.simulateRelatedView(this.el),this.delegateEvents(),this},simulateRelatedView:function(t){t&&t.setAttribute("model-id",this.relatedView.model.id)},getName:function(){return this.name},show:function(){this.el.style.display="",this._visible=!0},hide:function(){this.el.style.display="none",this._visible=!1},isVisible:function(){return!!this._visible},focus:function(){var t=this.options.focusOpacity;isFinite(t)&&(this.el.style.opacity=t),this.parentView.focusTool(this)},blur:function(){this.el.style.opacity="",this.parentView.blurTool(this)},update:function(){},guard:function(t){var e=this.paper,n=this.relatedView;return!e||!n||e.guard(t,n)}}),Zi=Ye.extend({tagName:"g",className:"tools",svgElement:!0,tools:null,options:{tools:null,relatedView:null,name:null,component:!1},configure:function(t){var e=(t=Nt(this.options,t)).tools;if(!Array.isArray(e))return this;var n=t.relatedView;if(!(n instanceof We))return this;for(var i=this.tools=[],r=0,o=e.length;r<o;r++){var s=e[r];s instanceof Wi&&(s.configure(n,this),s.render(),this.vel.append(s.el),i.push(s))}return this},getName:function(){return this.options.name},update:function(t){t||(t={});var e=this.tools;if(e){for(var n=0,i=e.length;n<i;n++){var r=e[n];t.tool!==r.cid&&r.isVisible()&&r.update()}return this}},focusTool:function(t){var e=this.tools;if(!e)return this;for(var n=0,i=e.length;n<i;n++){var r=e[n];t===r?r.show():r.hide()}return this},blurTool:function(t){var e=this.tools;if(!e)return this;for(var n=0,i=e.length;n<i;n++){var r=e[n];r===t||r.isVisible()||(r.show(),r.update())}return this},hide:function(){return this.focusTool(null)},show:function(){return this.blurTool(null)},onRemove:function(){var t=this.tools;if(!t)return this;for(var e=0,n=t.length;e<n;e++)t[e].remove();this.tools=null},mount:function(){var t=this.options,e=t.relatedView;e&&(t.component?e.el:e.paper.tools).appendChild(this.el);return this}}),Ji={ElementView:Ze,Graph:Ui,Cell:Ce,CellView:We,Element:He,attributes:Ee,Link:pn,LinkView:qi,Paper:Xi,ToolView:Wi,ToolsView:Zi};function Ki(t,e,n){return Jn.call(this.paper,{},e,n,t,this.model).anchor}function Qi(t,e){var n=t.model;return e?n.getBBox():n.isLink()?t.getConnection().bbox():t.getNodeUnrotatedBBox(t.el)}var tr=Ye.extend({tagName:"circle",svgElement:!0,className:"marker-vertex",events:{mousedown:"onPointerDown",touchstart:"onPointerDown",dblclick:"onDoubleClick"},documentEvents:{mousemove:"onPointerMove",touchmove:"onPointerMove",mouseup:"onPointerUp",touchend:"onPointerUp",touchcancel:"onPointerUp"},attributes:{r:6,fill:"#33334F",stroke:"#FFFFFF","stroke-width":2,cursor:"move"},position:function(t,e){this.vel.attr({cx:t,cy:e})},onPointerDown:function(t){this.options.guard(t)||(t.stopPropagation(),t.preventDefault(),this.options.paper.undelegateEvents(),this.delegateDocumentEvents(null,t.data),this.trigger("will-change",this,t))},onPointerMove:function(t){this.trigger("changing",this,t)},onDoubleClick:function(t){this.trigger("remove",this,t)},onPointerUp:function(t){this.trigger("changed",this,t),this.undelegateDocumentEvents(),this.options.paper.delegateEvents()}}),er=Wi.extend({name:"vertices",options:{handleClass:tr,snapRadius:20,redundancyRemoval:!0,vertexAdding:!0,stopPropagation:!0},children:[{tagName:"path",selector:"connection",className:"joint-vertices-path",attributes:{fill:"none",stroke:"transparent","stroke-width":10,cursor:"cell"}}],handles:null,events:{"mousedown .joint-vertices-path":"onPathPointerDown","touchstart .joint-vertices-path":"onPathPointerDown"},onRender:function(){return this.options.vertexAdding&&(this.renderChildren(),this.updatePath()),this.resetHandles(),this.renderHandles(),this},update:function(){return this.relatedView.model.vertices().length===this.handles.length?this.updateHandles():(this.resetHandles(),this.renderHandles()),this.options.vertexAdding&&this.updatePath(),this},resetHandles:function(){var t=this.handles;if(this.handles=[],this.stopListening(),Array.isArray(t))for(var e=0,n=t.length;e<n;e++)t[e].remove()},renderHandles:function(){for(var e=this,t=this.relatedView.model.vertices(),n=0,i=t.length;n<i;n++){var r=t[n],o=new this.options.handleClass({index:n,paper:this.paper,guard:function(t){return e.guard(t)}});o.render(),o.position(r.x,r.y),this.simulateRelatedView(o.el),o.vel.appendTo(this.el),this.handles.push(o),this.startHandleListening(o)}},updateHandles:function(){for(var t=this.relatedView.model.vertices(),e=0,n=t.length;e<n;e++){var i=t[e],r=this.handles[e];if(!r)return;r.position(i.x,i.y)}},updatePath:function(){var t=this.childNodes.connection;t&&t.setAttribute("d",this.relatedView.getSerializedConnection())},startHandleListening:function(t){var e=this.relatedView;e.can("vertexMove")&&(this.listenTo(t,"will-change",this.onHandleWillChange),this.listenTo(t,"changing",this.onHandleChanging),this.listenTo(t,"changed",this.onHandleChanged)),e.can("vertexRemove")&&this.listenTo(t,"remove",this.onHandleRemove)},getNeighborPoints:function(t){var e=this.relatedView,n=e.model.vertices(),i=0<t?n[t-1]:e.sourceAnchor,r=t<n.length-1?n[t+1]:e.targetAnchor;return{prev:new z(i),next:new z(r)}},onHandleWillChange:function(t,e){this.focus();var n=this.relatedView,i=this.options;n.model.startBatch("vertex-move",{ui:!0,tool:this.cid}),i.stopPropagation||n.notifyPointerdown.apply(n,n.paper.getPointerArgs(e))},onHandleChanging:function(t,e){var n=this.options,i=this.relatedView,r=t.options.index,o=i.paper.getPointerArgs(e),s=o[0],a=o[1],h=o[2],l={x:a,y:h};this.snapVertex(l,r),i.model.vertex(r,l,{ui:!0,tool:this.cid}),t.position(l.x,l.y),n.stopPropagation||i.notifyPointermove(s,a,h)},onHandleChanged:function(t,e){var n=this.options,i=this.relatedView;if(n.vertexAdding&&this.updatePath(),n.redundancyRemoval){i.removeRedundantLinearVertices({ui:!0,tool:this.cid})&&this.render(),this.blur(),i.model.stopBatch("vertex-move",{ui:!0,tool:this.cid}),this.eventData(e).vertexAdded&&i.model.stopBatch("vertex-add",{ui:!0,tool:this.cid});var r=i.paper.getPointerArgs(e),o=r[0],s=r[1],a=r[2];n.stopPropagation||i.notifyPointerup(o,s,a),i.checkMouseleave(o)}},snapVertex:function(t,e){var n=this.options.snapRadius;if(0<n){var i=this.getNeighborPoints(e),r=i.prev,o=i.next;Math.abs(t.x-r.x)<n?t.x=r.x:Math.abs(t.x-o.x)<n&&(t.x=o.x),Math.abs(t.y-r.y)<n?t.y=i.prev.y:Math.abs(t.y-o.y)<n&&(t.y=o.y)}},onHandleRemove:function(t,e){var n=t.options.index,i=this.relatedView;i.model.removeVertex(n,{ui:!0}),this.options.vertexAdding&&this.updatePath(),i.checkMouseleave(ct(e))},onPathPointerDown:function(t){if(!this.guard(t)){t.stopPropagation(),t.preventDefault();var e=ct(t),n=this.paper.snapToGrid(e.clientX,e.clientY).toJSON(),i=this.relatedView;i.model.startBatch("vertex-add",{ui:!0,tool:this.cid});var r=i.getVertexIndex(n.x,n.y);this.snapVertex(n,r),i.model.insertVertex(r,n,{ui:!0,tool:this.cid}),this.render();var o=this.handles[r];this.eventData(e,{vertexAdded:!0}),o.onPointerDown(e)}},onRemove:function(){this.resetHandles()}},{VertexHandle:tr}),nr=Ye.extend({tagName:"g",svgElement:!0,className:"marker-segment",events:{mousedown:"onPointerDown",touchstart:"onPointerDown"},documentEvents:{mousemove:"onPointerMove",touchmove:"onPointerMove",mouseup:"onPointerUp",touchend:"onPointerUp",touchcancel:"onPointerUp"},children:[{tagName:"line",selector:"line",attributes:{stroke:"#33334F","stroke-width":2,fill:"none","pointer-events":"none"}},{tagName:"rect",selector:"handle",attributes:{width:20,height:8,x:-10,y:-4,rx:4,ry:4,fill:"#33334F",stroke:"#FFFFFF","stroke-width":2}}],onRender:function(){this.renderChildren()},position:function(t,e,n,i){var r=K.createSVGMatrix().translate(t,e).rotate(n),o=this.childNodes.handle;o.setAttribute("transform",K.matrixToTransformString(r)),o.setAttribute("cursor",n%180==0?"row-resize":"col-resize");var s=i.getClosestPoint(new z(t,e)),a=this.childNodes.line;a.setAttribute("x1",t),a.setAttribute("y1",e),a.setAttribute("x2",s.x),a.setAttribute("y2",s.y)},onPointerDown:function(t){this.options.guard(t)||(this.trigger("change:start",this,t),t.stopPropagation(),t.preventDefault(),this.options.paper.undelegateEvents(),this.delegateDocumentEvents(null,t.data))},onPointerMove:function(t){this.trigger("changing",this,t)},onPointerUp:function(t){this.undelegateDocumentEvents(),this.options.paper.delegateEvents(),this.trigger("change:end",this,t)},show:function(){this.el.style.display=""},hide:function(){this.el.style.display="none"}}),ir=Wi.extend({name:"segments",precision:.5,options:{handleClass:nr,segmentLengthThreshold:40,redundancyRemoval:!0,anchor:Ki,snapRadius:10,snapHandle:!0},handles:null,onRender:function(){this.resetHandles();var t=this.relatedView,e=t.model.vertices();e.unshift(t.sourcePoint),e.push(t.targetPoint);for(var n=0,i=e.length;n<i-1;n++){var r=e[n],o=e[n+1],s=this.renderHandle(r,o);this.simulateRelatedView(s.el),this.handles.push(s),s.options.index=n}return this},renderHandle:function(t,e){var n=this,i=new this.options.handleClass({paper:this.paper,guard:function(t){return n.guard(t)}});return i.render(),this.updateHandle(i,t,e),i.vel.appendTo(this.el),this.startHandleListening(i),i},update:function(){return this.render(),this},startHandleListening:function(t){this.listenTo(t,"change:start",this.onHandleChangeStart),this.listenTo(t,"changing",this.onHandleChanging),this.listenTo(t,"change:end",this.onHandleChangeEnd)},resetHandles:function(){var t=this.handles;if(this.handles=[],this.stopListening(),Array.isArray(t))for(var e=0,n=t.length;e<n;e++)t[e].remove()},shiftHandleIndexes:function(t){for(var e=this.handles,n=0,i=e.length;n<i;n++)e[n].options.index+=t},resetAnchor:function(t,e){var n=this.relatedView.model;e?n.prop([t,"anchor"],e,{rewrite:!0,ui:!0,tool:this.cid}):n.removeProp([t,"anchor"],{ui:!0,tool:this.cid})},snapHandle:function(t,e,n){var i=t.options.index,r=this.relatedView.model.vertices(),o=t.options.axis,s=r[i-2]||n.sourceAnchor,a=r[i+1]||n.targetAnchor,h=this.options.snapRadius;return Math.abs(e[o]-s[o])<h?e[o]=s[o]:Math.abs(e[o]-a[o])<h&&(e[o]=a[o]),e},onHandleChanging:function(t,e){var n=this.eventData(e),i=this.relatedView,r=i.paper,o=t.options.index-1,s=ct(e),a=r.snapToGrid(s.clientX,s.clientY),h=this.snapHandle(t,a.clone(),n),l=t.options.axis,u=this.options.snapHandle?0:a[l]-h[l],c=i.model,d=Dt(c.vertices()),f=d[o],p=d[o+1],g=this.options.anchor;"function"!=typeof g&&(g=null);var v=i.sourceView,m=i.sourceBBox,y=!1,w=!1;if(f?0===o?m.containsPoint(f)?(d.shift(),this.shiftHandleIndexes(-1),y=!0):(f[l]=h[l],w=!0):f[l]=h[l]:((f=i.sourceAnchor.toJSON())[l]=h[l],m.containsPoint(f)?(f[l]=h[l],y=!0):(d.unshift(f),this.shiftHandleIndexes(1),w=!0)),g&&v){if(y){var b=n.sourceAnchor.clone();b[l]=h[l];var x=g.call(i,b,v,i.sourceMagnet||v.el,"source",i);this.resetAnchor("source",x)}w&&this.resetAnchor("source",n.sourceAnchorDef)}var A=i.targetView,P=i.targetBBox,S=!1,k=!1;if(p?o===d.length-2?P.containsPoint(p)?(d.pop(),S=!0):(p[l]=h[l],k=!0):p[l]=h[l]:((p=i.targetAnchor.toJSON())[l]=h[l],P.containsPoint(p)?S=!0:(d.push(p),k=!0)),g&&A){if(S){var E=n.targetAnchor.clone();E[l]=h[l];var C=g.call(i,E,A,i.targetMagnet||A.el,"target",i);this.resetAnchor("target",C)}k&&this.resetAnchor("target",n.targetAnchorDef)}c.vertices(d,{ui:!0,tool:this.cid}),this.updateHandle(t,f,p,u)},onHandleChangeStart:function(t,e){var n=t.options.index,i=this.handles;if(Array.isArray(i)){for(var r=0,o=i.length;r<o;r++)r!==n&&i[r].hide();this.focus();var s=this.relatedView,a=s.model;this.eventData(e,{sourceAnchor:s.sourceAnchor.clone(),targetAnchor:s.targetAnchor.clone(),sourceAnchorDef:Ot(a.prop(["source","anchor"])),targetAnchorDef:Ot(a.prop(["target","anchor"]))}),s.model.startBatch("segment-move",{ui:!0,tool:this.cid})}},onHandleChangeEnd:function(t,e){var n=this.relatedView;this.options.redundancyRemoval&&n.removeRedundantLinearVertices({ui:!0,tool:this.cid}),this.render(),this.blur(),n.model.stopBatch("segment-move",{ui:!0,tool:this.cid}),n.checkMouseleave(ct(e))},updateHandle:function(t,e,n,i){var r=Math.abs(e.x-n.x)<this.precision,o=Math.abs(e.y-n.y)<this.precision;if(r||o){var s=new O(e,n);if(s.length()<this.options.segmentLengthThreshold)t.hide();else{var a=s.midpoint(),h=r?"x":"y";a[h]+=i||0;var l=s.vector().vectorAngle(new z(1,0));t.position(a.x,a.y,l,this.relatedView),t.show(),t.options.axis=h}}else t.hide()},onRemove:function(){this.resetHandles()}},{SegmentHandle:nr}),rr=Wi.extend({tagName:"path",xAxisVector:new z(1,0),events:{mousedown:"onPointerDown",touchstart:"onPointerDown"},documentEvents:{mousemove:"onPointerMove",touchmove:"onPointerMove",mouseup:"onPointerUp",touchend:"onPointerUp",touchcancel:"onPointerUp"},onRender:function(){this.update()},update:function(){var t,e,n=this.ratio,i=this.relatedView,r=i.getTangentAtRatio(n);if(e=r?(t=r.start,r.vector().vectorAngle(this.xAxisVector)||0):(t=i.getPointAtRatio(n),0),!t)return this;var o=K.createSVGMatrix().translate(t.x,t.y).rotate(e);return this.vel.transform(o,{absolute:!0}),this},onPointerDown:function(t){if(!this.guard(t)){t.stopPropagation(),t.preventDefault();var e=this.relatedView;e.model.startBatch("arrowhead-move",{ui:!0,tool:this.cid}),e.can("arrowheadMove")&&(e.startArrowheadMove(this.arrowheadType),this.delegateDocumentEvents(),e.paper.undelegateEvents()),this.focus(),this.el.style.pointerEvents="none"}},onPointerMove:function(t){var e=ct(t),n=this.paper.snapToGrid(e.clientX,e.clientY);this.relatedView.pointermove(e,n.x,n.y)},onPointerUp:function(t){this.undelegateDocumentEvents();var e=this.relatedView,n=e.paper,i=ct(t),r=n.snapToGrid(i.clientX,i.clientY);e.pointerup(i,r.x,r.y),n.delegateEvents(),this.blur(),this.el.style.pointerEvents="",e.model.stopBatch("arrowhead-move",{ui:!0,tool:this.cid})}}),or=rr.extend({name:"target-arrowhead",ratio:1,arrowheadType:"target",attributes:{d:"M -10 -8 10 0 -10 8 Z",fill:"#33334F",stroke:"#FFFFFF","stroke-width":2,cursor:"move",class:"target-arrowhead"}}),sr=rr.extend({name:"source-arrowhead",ratio:0,arrowheadType:"source",attributes:{d:"M 10 -8 -10 0 10 8 Z",fill:"#33334F",stroke:"#FFFFFF","stroke-width":2,cursor:"move",class:"source-arrowhead"}}),ar=Wi.extend({name:"button",events:{mousedown:"onPointerDown",touchstart:"onPointerDown"},options:{distance:0,offset:0,rotate:!1},onRender:function(){this.renderChildren(this.options.markup),this.update()},update:function(){return this.position(),this},position:function(){var t=this.relatedView,e=this.vel,n=t.model.isLink()?this.getLinkMatrix():this.getElementMatrix();e.transform(n,{absolute:!0})},getElementMatrix:function(){var t=this.relatedView,e=this.options,n=e.x;void 0===n&&(n=0);var i=e.y;void 0===i&&(i=0);var r=e.offset;void 0===r&&(r={});var o=e.useModelGeometry,s=e.rotate,a=Qi(t,o),h=t.model.angle();s||(a=a.bbox(h));var l=r.x;void 0===l&&(l=0);var u=r.y;void 0===u&&(u=0),pt(n)&&(n=parseFloat(n)/100*a.width),pt(i)&&(i=parseFloat(i)/100*a.height);var c=K.createSVGMatrix().translate(a.x+a.width/2,a.y+a.height/2);return s&&(c=c.rotate(h)),c=c.translate(n+l-a.width/2,i+u-a.height/2)},getLinkMatrix:function(){var t=this.relatedView,e=this.options,n=e.offset;void 0===n&&(n=0);var i=e.distance;void 0===i&&(i=0);var r,o,s,a=e.rotate;s=(r=pt(i)?t.getTangentAtRatio(parseFloat(i)/100):t.getTangentAtLength(i))?(o=r.start,r.vector().vectorAngle(new z(1,0))||0):(o=t.getConnection().start,0);var h=K.createSVGMatrix().translate(o.x,o.y).rotate(s).translate(0,n);return a||(h=h.rotate(-s)),h},onPointerDown:function(t){if(!this.guard(t)){t.stopPropagation(),t.preventDefault();var e=this.options.action;"function"==typeof e&&e.call(this.relatedView,t,this.relatedView,this)}}}),hr=ar.extend({children:[{tagName:"circle",selector:"button",attributes:{r:7,fill:"#FF1D00",cursor:"pointer"}},{tagName:"path",selector:"icon",attributes:{d:"M -3 -3 3 3 M -3 3 3 -3",fill:"none",stroke:"#FFFFFF","stroke-width":2,"pointer-events":"none"}}],options:{distance:60,offset:0,action:function(t,e,n){e.model.remove({ui:!0,tool:n.cid})}}}),lr=Wi.extend({name:"boundary",tagName:"rect",options:{padding:10,useModelGeometry:!1},attributes:{fill:"none",stroke:"#33334F","stroke-width":.5,"stroke-dasharray":"5, 5","pointer-events":"none"},onRender:function(){this.update()},update:function(){var t=this.relatedView,e=this.options,n=this.vel,i=e.useModelGeometry,r=e.rotate,o=xt(e.padding),s=Qi(t,i).moveAndExpand({x:-o.left,y:-o.top,width:o.left+o.right,height:o.top+o.bottom}),a=t.model;if(a.isElement()){var h=a.angle();if(h)if(r){var l=a.getBBox().center();n.rotate(h,l.x,l.y,{absolute:!0})}else s=s.bbox(h)}return n.attr(s.toJSON()),this}}),ur=Wi.extend({tagName:"g",type:null,children:[{tagName:"circle",selector:"anchor",attributes:{cursor:"pointer"}},{tagName:"rect",selector:"area",attributes:{"pointer-events":"none",fill:"none",stroke:"#33334F","stroke-dasharray":"2,4",rx:5,ry:5}}],events:{mousedown:"onPointerDown",touchstart:"onPointerDown",dblclick:"onPointerDblClick"},documentEvents:{mousemove:"onPointerMove",touchmove:"onPointerMove",mouseup:"onPointerUp",touchend:"onPointerUp",touchcancel:"onPointerUp"},options:{snap:function(t,e,n,i,r,o){var s=o.options.snapRadius,a="source"===i,h=a?0:-1,l=this.model.vertex(h)||this.getEndAnchor(a?"target":"source");return l&&(Math.abs(l.x-t.x)<s&&(t.x=l.x),Math.abs(l.y-t.y)<s&&(t.y=l.y)),t},anchor:Ki,customAnchorAttributes:{"stroke-width":4,stroke:"#33334F",fill:"#FFFFFF",r:5},defaultAnchorAttributes:{"stroke-width":2,stroke:"#FFFFFF",fill:"#33334F",r:6},areaPadding:6,snapRadius:10,restrictArea:!0,redundancyRemoval:!0},onRender:function(){this.renderChildren(),this.toggleArea(!1),this.update()},update:function(){var t=this.type,e=this.relatedView.getEndView(t);return this.el.style.display=e?(this.updateAnchor(),this.updateArea(),""):"none",this},updateAnchor:function(){var t=this.childNodes;if(t){var e=t.anchor;if(e){var n=this.relatedView,i=this.type,r=n.getEndAnchor(i),o=this.options,s=n.model.prop([i,"anchor"]);e.setAttribute("transform","translate("+r.x+","+r.y+")");var a=s?o.customAnchorAttributes:o.defaultAnchorAttributes;for(var h in a)e.setAttribute(h,a[h])}}},updateArea:function(){var t=this.childNodes;if(t){var e=t.area;if(e){var n,i,r,o=this.relatedView,s=this.type,a=o.getEndView(s),h=a.model,l=o.getEndMagnet(s),u=this.options.areaPadding;isFinite(u)||(u=0),a.isNodeConnection(l)?(i=0,r=(n=a.getBBox()).center()):(n=a.getNodeUnrotatedBBox(l),i=h.angle(),r=n.center(),i&&r.rotate(h.getBBox().center(),-i)),n.inflate(u),e.setAttribute("x",-n.width/2),e.setAttribute("y",-n.height/2),e.setAttribute("width",n.width),e.setAttribute("height",n.height),e.setAttribute("transform","translate("+r.x+","+r.y+") rotate("+i+")")}}},toggleArea:function(t){this.childNodes.area.style.display=t?"":"none"},onPointerDown:function(t){this.guard(t)||(t.stopPropagation(),t.preventDefault(),this.paper.undelegateEvents(),this.delegateDocumentEvents(),this.focus(),this.toggleArea(this.options.restrictArea),this.relatedView.model.startBatch("anchor-move",{ui:!0,tool:this.cid}))},resetAnchor:function(t){var e=this.type,n=this.relatedView.model;t?n.prop([e,"anchor"],t,{rewrite:!0,ui:!0,tool:this.cid}):n.removeProp([e,"anchor"],{ui:!0,tool:this.cid})},onPointerMove:function(t){var e,n=this.relatedView,i=this.type,r=n.getEndView(i),o=r.model,s=n.getEndMagnet(i),a=ct(t),h=this.paper.clientToLocalPoint(a.clientX,a.clientY),l=this.options.snap;if("function"==typeof l&&(h=l.call(n,h,r,s,i,n,this),h=new z(h)),this.options.restrictArea)if(r.isNodeConnection(s)){var u=r.getClosestPoint(h);u&&(h=u)}else{var c=r.getNodeUnrotatedBBox(s),d=o.angle(),f=o.getBBox().center(),p=h.clone().rotate(f,d);c.containsPoint(p)||(h=c.pointNearestToPoint(p).rotate(f,-d))}var g=this.options.anchor;"function"==typeof g&&(e=g.call(n,h,r,s,i,n)),this.resetAnchor(e),this.update()},onPointerUp:function(t){this.paper.delegateEvents(),this.undelegateDocumentEvents(),this.blur(),this.toggleArea(!1);var e=this.relatedView;this.options.redundancyRemoval&&e.removeRedundantLinearVertices({ui:!0,tool:this.cid}),e.model.stopBatch("anchor-move",{ui:!0,tool:this.cid})},onPointerDblClick:function(){this.resetAnchor(),this.update()}}),cr={Vertices:er,Segments:ir,SourceArrowhead:sr,TargetArrowhead:or,SourceAnchor:ur.extend({name:"source-anchor",type:"source"}),TargetAnchor:ur.extend({name:"target-anchor",type:"target"}),Button:ar,Remove:hr,Boundary:lr},dr={Button:ar,Remove:hr,Boundary:lr},fr=K,pr={PortLabel:je,Port:Be},gr={basic:fn,standard:Tn};e.V=K,e.Vectorizer=fr,e.anchors=ji,e.config=Q,e.connectionPoints=qn,e.connectionStrategies=Kn,e.connectors=On,e.dia=Ji,e.elementTools=dr,e.env=Je,e.format={},e.g=J,e.highlighters=Dn,e.layout=pr,e.linkAnchors=zi,e.linkTools=cr,e.mvc=Xe,e.routers=_i,e.setTheme=function(t,e){_t($e,"setTheme",t,e=e||{}),Ye.prototype.defaultTheme=t},e.shapes=gr,e.ui={},e.util=Me,e.version="3.1.1",Object.defineProperty(e,"__esModule",{value:!0})}),"undefined"!=typeof joint)var g=joint.g,V=joint.V,Vectorizer=joint.V;