UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

2 lines 72.3 kB
module.exports=function(t){function e(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return t[i].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}({0:function(t,e,n){t.exports=n(892)},3:function(t,e){t.exports=function(){throw Error("define cannot be used indirect")}},881:function(t,e){t.exports=require("../../kendo.data")},882:function(t,e){t.exports=require("../../kendo.dataviz.core")},883:function(t,e){t.exports=require("../../kendo.dataviz.themes")},892:function(t,e,n){var i,o,s;!function(r,define){o=[n(881),n(894),n(895),n(896),n(897),n(893),n(882),n(883),n(898),n(899),n(900)],i=r,s="function"==typeof i?i.apply(e,o):i,!(void 0!==s&&(t.exports=s))}(function(){!function(t,e){function n(t){var e=t.originalEvent,n=0;return e.wheelDelta?(n=-e.wheelDelta/40,n=n>0?Ct.ceil(n):Ct.floor(n)):e.detail&&(n=e.detail),n}function i(t){return t.options.name.toLowerCase()===Pt.toLowerCase()}function o(t,e){var n,o,s,r,a=Ht;for(s=0;s<e.length;s++)o=e[s],i(o)||(r=t.distanceTo(o.position()),r<a&&(a=r,n=o));return n}function s(t,e){var n,i,o,s=[],r=t.drawingContainer().children,a=r.length;for(n=0;n<e.length;n++)for(i=e[n],o=0;o<a;o++)if(r[o]==i.drawingContainer()){s.push(o);break}return s}function r(t){var e={};return t=t||{},mt(t.text)&&null!==t.text&&(e.text=t.text),mt(t.x)&&null!==t.x&&(e.x=t.x),mt(t.y)&&null!==t.y&&(e.y=t.y),mt(t.width)&&null!==t.width&&(e.width=t.width),mt(t.height)&&null!==t.height&&(e.height=t.height),mt(t.type)&&null!==t.type&&(e.type=t.type),e}function a(t){var e={};return t=t||{},mt(t.text)&&null!==t.text&&(e.content=t.text),mt(t.type)&&null!==t.type&&(e.type=t.type),mt(t.from)&&null!==t.from&&(e.from=t.from),mt(t.fromConnector)&&null!==t.fromConnector&&(e.fromConnector=t.fromConnector),mt(t.fromX)&&null!==t.fromX&&(e.fromX=t.fromX),mt(t.fromY)&&null!==t.fromY&&(e.fromY=t.fromY),mt(t.to)&&null!==t.to&&(e.to=t.to),mt(t.toConnector)&&null!==t.toConnector&&(e.toConnector=t.toConnector),mt(t.toX)&&null!==t.toX&&(e.toX=t.toX),mt(t.toY)&&null!==t.toY&&(e.toY=t.toY),e}function h(e,n){var i,o=this.dataSource.reader.model;o&&(i=o.fn.fields.text?"text":o.idField,t("<input name='"+n.field+"' />").appendTo(e).kendoDropDownList({dataValueField:o.idField,dataTextField:i,dataSource:this.dataSource.data().toJSON(),optionLabel:" ",valuePrimitive:!0}))}function c(t){this.dataItem=t,this.callbacks=[]}function d(){this.items={}}function u(t){var e=t;return t instanceof kendo.data.Model&&(e=t.toJSON(),e[t.idField]=t._defaultId),e}function l(t){var e,n,i=[],o=[];for(n=0;n<t.length;n++)e=t[n],e instanceof C?o.push(e):i.push(e);return{shapes:o,connections:i}}function p(t,e){return t.reader.model?new t.reader.model(e):new kendo.data.ObservableObject(e)}function f(t,e){mt(e[t])&&e.set(t,null)}function _(t,e,n){var i,o;for(o=0;o<n.length;o++)i=n[o],e&&!mt(e[i])&&(e[i]=t[i])}function m(t){var e=t.drawingContainer().clippedBBox(null);0===e.origin.x&&0===e.origin.y||t.position(-e.origin.x,-e.origin.y)}function g(t){t.preventDefault()}var v,w,y,C,b,S,x,k,T,D,I,M,B=kendo.dataviz,E=kendo.drawing,R=kendo.geometry,P=B.diagram,O=kendo.ui.Widget,z=kendo.Class,A=t.proxy,L=kendo.deepExtend,H=kendo._outerWidth,V=kendo._outerHeight,U=t.extend,F=kendo.data.HierarchicalDataSource,N=P.Canvas,X=P.Group,q=P.Rectangle,Y=P.Circle,G=P.CompositeTransform,J=P.Rect,W=P.Path,K=P.DeleteShapeUnit,Z=P.DeleteConnectionUnit,Q=P.TextBlock,j=P.Image,$=P.Point,tt=P.Intersect,et=P.ConnectionEditAdorner,nt=P.UndoRedoService,it=P.ToolService,ot=P.Selector,st=P.ResizingAdorner,rt=P.ConnectorsAdorner,at=P.Cursors,ht=P.Utils,ct=kendo.Observable,dt=P.ToBackUnit,ut=P.ToFrontUnit,lt=P.PolylineRouter,pt=P.CascadingRouter,ft=ht.isUndefined,_t=ht.isDefined,mt=E.util.defined,gt=t.isArray,vt=kendo.isFunction,wt=ht.isString,yt=t.isPlainObject,Ct=Math,bt=".kendoDiagram",St="cascading",xt="itemBoundsChange",kt="change",Tt="click",Dt="drag",It="dragEnd",Mt="dragStart",Bt="mouseEnter",Et="mouseLeave",Rt="error",Pt="Auto",Ot="Top",zt="Right",At="Left",Lt="Bottom",Ht=9007199254740992,Vt="select",Ut="itemRotate",Ft="pan",Nt="zoomStart",Xt="zoomEnd",qt="none",Yt=600,Gt=600,Jt="rectangle",Wt=100,Kt=100,Zt=20,Qt=20,jt=0,$t="Yellow",te=Number.MAX_VALUE,ee=-Number.MAX_VALUE,ne="absolute",ie="transformed",oe="rotated",se="transparent",re="width",ae="height",he="x",ce="y",de="DOMMouseScroll"+bt+" mousewheel"+bt,ue=.05,le=5,pe='<a class="k-button k-button-icontext #=className#" href="\\#"><span class="#=iconClass# #=imageClass#"></span>#=text#</a>',fe=5;P.DefaultConnectors=[{name:Ot},{name:Lt},{name:At},{name:zt},{name:Pt,position:function(t){return t.getPosition("center")}}],v={cancel:{text:"Cancel",imageClass:"k-i-cancel",className:"k-diagram-cancel",iconClass:"k-icon"},update:{text:"Update",imageClass:"k-i-checkmark",className:"k-diagram-update",iconClass:"k-icon"}},P.shapeDefaults=function(t){var e={type:Jt,path:"",autoSize:!0,visual:null,x:jt,y:jt,minWidth:Zt,minHeight:Qt,width:Wt,height:Kt,hover:{},editable:{connect:!0,tools:[]},connectors:P.DefaultConnectors,rotation:{angle:0}};return ht.simpleExtend(e,t),e},w=ct.extend({init:function(t){var e=this;e.dataItem=(t||{}).dataItem,ct.fn.init.call(e),e.options=L({id:P.randomId()},e.options,t),e.isSelected=!1,e.visual=new X({id:e.options.id,autoSize:e.options.autoSize}),e.id=e.options.id,e._template()},options:{hover:{},cursor:at.grip,content:{align:"center middle"},selectable:!0,serializable:!0,enable:!0},_getCursor:function(t){return this.adorner?this.adorner._getCursor(t):this.options.cursor},visible:function(t){return ft(t)?this.visual.visible():(this.visual.visible(t),e)},bounds:function(){},refresh:function(){this.visual.redraw()},position:function(t){this.options.x=t.x,this.options.y=t.y,this.visual.position(t)},toString:function(){return this.options.id},serialize:function(){var t=L({},{options:this.options});return this.dataItem&&(t.dataItem=""+this.dataItem),t},_content:function(t){var n,i,o;return t!==e&&(n=this.options,P.Utils.isString(t)?n.content.text=t:L(n.content,t),i=n.content,o=this._contentVisual,o?this._updateContentVisual(i):this._createContentVisual(i)),this.options.content.text},_createContentVisual:function(t){t.text&&(this._contentVisual=new Q(t),this._contentVisual._includeInBBox=!1,this.visual.append(this._contentVisual))},_updateContentVisual:function(t){this._contentVisual.redraw(t)},_hitTest:function(t){var e=this.bounds();return this.visible()&&e.contains(t)&&this.options.enable},_template:function(){var t,e,n=this;n.options.content.template&&(t=n.dataItem||{},e=kendo.template(n.options.content.template,{paramName:"dataItem"}),n.options.content.text=e(t))},_canSelect:function(){return this.options.selectable!==!1},toJSON:function(){return{id:this.options.id}}}),y=z.extend({init:function(t,e){this.options=L({},this.options,e),this.connections=[],this.shape=t},options:{width:7,height:7,fill:{color:$t},hover:{}},position:function(){return this.options.position?this.options.position(this.shape):this.shape.getPosition(this.options.name)},toJSON:function(){return{shapeId:""+this.shape,connector:this.options.name}}}),y.parse=function(t,e){var n,i,o=e.split(":"),s=o[0],r=o[1]||Pt;for(n=0;n<t.shapes.length;n++)if(i=t.shapes[n],i.options.id==s)return i.getConnector(r.trim())},C=w.extend({init:function(t,e){var n=this;w.fn.init.call(n,t),this.diagram=e,this.updateOptionsFromModel(),t=n.options,n.connectors=[],n.type=t.type,n.createShapeVisual(),n.updateBounds(),n.content(n.content()),n._createConnectors()},options:P.shapeDefaults(),_setOptionsFromModel:function(t){var e=r(t||this.dataItem);this.options=L({},this.options,e),this.redrawVisual()},updateOptionsFromModel:function(t,e){var n,i;this.diagram&&this.diagram._isEditable&&(n=r(t||this.dataItem),t&&e?B.inArray(e,["x","y","width","height"])?(i=this.bounds(),i[e]=t[e],this.bounds(i)):(this.options.visual?this._redrawVisual():n.type&&(this.options=L({},this.options,n),this._redrawVisual()),this.options.content&&(this._template(),this.content(this.options.content))):this.options=L({},this.options,n))},_redrawVisual:function(){this.visual.clear(),this._contentVisual=null,this.options.dataItem=this.dataItem,this.createShapeVisual(),this.updateBounds()},redrawVisual:function(){this._redrawVisual(),this.options.content&&(this._template(),this.content(this.options.content))},updateModel:function(t){var e,n,i=this.diagram;i&&i._isEditable&&(e=this._bounds,n=this.dataItem,n&&(i._suspendModelRefresh(),mt(n.x)&&e.x!==n.x&&n.set("x",e.x),mt(n.y)&&e.y!==n.y&&n.set("y",e.y),mt(n.width)&&e.width!==n.width&&n.set("width",e.width),mt(n.height)&&e.height!==n.height&&n.set("height",e.height),this.dataItem=n,i._resumeModelRefresh(),t&&i._syncShapeChanges()))},updateBounds:function(){var t=this.visual._measure(!0),e=this.options;this.bounds(new J(e.x,e.y,t.width,t.height)),this._rotate(),this._alignContent()},content:function(t){var e=this._content(t);return this._alignContent(),e},_alignContent:function(){var t,e,n,i,o,s=this.options.content||{},r=this._contentVisual;r&&s.align&&(t=this.visual._measure(),e=new P.RectAlign(t),n=r.drawingElement.bbox(null),i=new J(0,0,n.width(),n.height()),o=e.align(i,s.align),r.position(o.topLeft()))},_createConnectors:function(){var t,e,n=this.options,i=n.connectors.length,o=n.connectorDefaults;for(e=0;e<i;e++)t=new y(this,L({},o,n.connectors[e])),this.connectors.push(t)},bounds:function(t){var e,n;if(t)if(wt(t))switch(t){case ie:e=this._transformedBounds();break;case ne:e=this._transformedBounds(),n=this.diagram._pan,e.x+=n.x,e.y+=n.y;break;case oe:e=this._rotatedBounds();break;default:e=this._bounds}else this._setBounds(t),this._triggerBoundsChange(),this.diagram&&this.diagram._layouting||this.refreshConnections();else e=this._bounds;return e},_setBounds:function(t){var e=this.options,n=t.topLeft(),i=e.x=n.x,o=e.y=n.y,s=e.width=Ct.max(t.width,e.minWidth),r=e.height=Ct.max(t.height,e.minHeight);this._bounds=new J(i,o,s,r),this.visual.redraw({x:i,y:o,width:s,height:r})},position:function(t){return t?(this.bounds(new J(t.x,t.y,this._bounds.width,this._bounds.height)),e):this._bounds.topLeft()},clone:function(){var t=this.serialize();return t.options.id=P.randomId(),this.diagram&&this.diagram._isEditable&&mt(this.dataItem)&&(t.options.dataItem=u(this.dataItem)),new C(t.options)},select:function(t){var e,n,i=this.diagram;if(ft(t)&&(t=!0),this._canSelect()&&this.isSelected!=t)return e=[],n=[],this.isSelected=t,this.isSelected?(i._selectedItems.push(this),e.push(this)):(ht.remove(i._selectedItems,this),n.push(this)),i._internalSelection||i._selectionChanged(e,n),!0},rotate:function(t,n,i){var o,s,r,a,h=this.visual.rotate();return t!==e&&(i!==!1&&this.diagram&&this.diagram.undoRedoService&&t!==h.angle&&this.diagram.undoRedoService.add(new P.RotateUnit(this.diagram._resizingAdorner,[this],[h.angle]),!1),o=this.bounds(),s=new $(o.width/2,o.height/2),n&&(r=t-h.angle,a=o.center().rotate(n,360-r).minus(s),this._rotationOffset=this._rotationOffset.plus(a.minus(o.topLeft())),this.position(a)),this.visual.rotate(t,s),this.options.rotation.angle=t,this.diagram&&this.diagram._connectorsAdorner&&this.diagram._connectorsAdorner.refresh(),this.refreshConnections(),this.diagram&&this.diagram.trigger(Ut,{item:this})),h},connections:function(t){var e,n,i,o,s,r,a,h=[];for(e=0;e<this.connectors.length;e++)for(s=this.connectors[e],o=s.connections,n=0,o;n<o.length;n++)i=o[n],"out"==t?(r=i.source(),r.shape&&r.shape==this&&h.push(i)):"in"==t?(a=i.target(),a.shape&&a.shape==this&&h.push(i)):h.push(i);return h},refreshConnections:function(){t.each(this.connections(),function(){this.refresh()})},getConnector:function(t){var e,n;if(!wt(t))return t instanceof $?o(t,this.connectors):this.connectors.length?this.connectors[0]:null;for(t=t.toLocaleLowerCase(),e=0;e<this.connectors.length;e++)if(n=this.connectors[e],n.options.name.toLocaleLowerCase()==t)return n},getPosition:function(t){var e=this.bounds(),n=t.charAt(0).toLowerCase()+t.slice(1);return vt(e[n])?this._transformPoint(e[n]()):e.center()},redraw:function(t){var e,n;t&&(e=this.options,this.shapeVisual.redraw(this._visualOptions(t)),this._diffNumericOptions(t,[re,ae,he,ce])&&(this.bounds(new J(e.x,e.y,e.width,e.height)),n=!0),t.connectors&&(e.connectors=t.connectors,this._updateConnectors()),e=L(e,t),(t.rotation||n)&&this._rotate(),e.content&&this.content(e.content))},_updateConnectors:function(){var t,e,n,i,o=this.connections();for(this.connectors=[],this._createConnectors(),i=0;i<o.length;i++)t=o[i],e=t.source(),n=t.target(),e.shape&&e.shape===this?t.source(this.getConnector(e.options.name)||null):n.shape&&n.shape===this&&t.target(this.getConnector(n.options.name)||null),t.updateModel()},_diffNumericOptions:P.diffNumericOptions,_visualOptions:function(t){return{data:t.path,source:t.source,hover:t.hover,fill:t.fill,stroke:t.stroke}},_triggerBoundsChange:function(){this.diagram&&this.diagram.trigger(xt,{item:this,bounds:this._bounds.clone()})},_transformPoint:function(t){var e=this.rotate(),n=this.bounds(),i=n.topLeft();return e.angle&&t.rotate(e.center().plus(i),360-e.angle),t},_transformedBounds:function(){var t=this.bounds(),e=t.topLeft(),n=t.bottomRight();return J.fromPoints(this.diagram.modelToView(e),this.diagram.modelToView(n))},_rotatedBounds:function(){var t=this.bounds().rotatedBounds(this.rotate().angle),e=t.topLeft(),n=t.bottomRight();return J.fromPoints(e,n)},_rotate:function(){var t=this.options.rotation;t&&t.angle&&this.rotate(t.angle),this._rotationOffset=new $},_hover:function(t){var e=this.options,n=e.hover,i=e.stroke,o=e.fill;t&&_t(n.stroke)&&(i=L({},i,n.stroke)),t&&_t(n.fill)&&(o=n.fill),this.shapeVisual.redraw({stroke:i,fill:o}),e.editable&&e.editable.connect&&this.diagram._showConnectors(this,t)},_hitTest:function(t){if(this.visible()){var e,n=this.bounds(),i=this.rotate().angle;if(t.isEmpty&&!t.isEmpty())return tt.rects(t,n,i?i:0);if(e=t.clone().rotate(n.center(),i),n.contains(e))return this}},toJSON:function(){return{shapeId:this.options.id}},createShapeVisual:function(){var t,e=this.options,n=this._visualOptions(e),i=e.visual,o=(e.type+"").toLocaleLowerCase();n.width=e.width,n.height=e.height,vt(i)?t=i.call(this,e):n.data?(t=new W(n),m(t)):t="rectangle"==o?new q(n):"circle"==o?new Y(n):"text"==o?new Q(n):"image"==o?new j(n):new W(n),this.shapeVisual=t,this.visual.append(this.shapeVisual)}}),b=w.extend({init:function(t,e,n){var i=this;w.fn.init.call(i,n),this.updateOptionsFromModel(),this._initRouter(),i.path=new P.Polyline(i.options),i.path.fill(se),i.visual.append(i.path),i._sourcePoint=i._targetPoint=new $,i._setSource(t),i._setTarget(e),i.content(i.options.content),i.definers=[],mt(n)&&n.points&&i.points(n.points)},options:{hover:{stroke:{}},startCap:qt,endCap:qt,points:[],selectable:!0,fromConnector:Pt,toConnector:Pt},_setOptionsFromModel:function(t){this.updateOptionsFromModel(t||this.dataItem)},updateOptionsFromModel:function(t){var e,n,i,o;this.diagram&&this.diagram._isEditable&&(e=this.diagram._dataMap,n=a(t||this.dataItem),t?(mt(n.from)?(i=e[n.from],i&&mt(n.fromConnector)&&(i=i.getConnector(n.fromConnector)),this.source(i)):mt(n.fromX)&&mt(n.fromY)&&this.source(new $(n.fromX,n.fromY)),mt(n.to)?(o=e[n.to],o&&mt(n.toConnector)&&(o=o.getConnector(n.toConnector)),this.target(o)):mt(n.toX)&&mt(n.toY)&&this.target(new $(n.toX,n.toY)),mt(n.type)&&this.type()!==n.type&&(this.points([]),this.type(n.type)),this.dataItem=t,this._template(),this.redraw(this.options)):this.options=L({},n,this.options))},updateModel:function(t){if(this.diagram&&this.diagram._isEditable&&this.diagram.connectionsDataSource){var e=this.diagram.connectionsDataSource.getByUid(this.dataItem.uid);e&&(this.diagram._suspendModelRefresh(),mt(this.options.fromX)&&null!==this.options.fromX?(f("from",e),f("fromConnector",e),e.set("fromX",this.options.fromX),e.set("fromY",this.options.fromY)):(e.set("from",this.options.from),mt(e.fromConnector)&&e.set("fromConnector",this.sourceConnector?this.sourceConnector.options.name:null),f("fromX",e),f("fromY",e)),mt(this.options.toX)&&null!==this.options.toX?(f("to",e),f("toConnector",e),e.set("toX",this.options.toX),e.set("toY",this.options.toY)):(e.set("to",this.options.to),mt(e.toConnector)&&e.set("toConnector",this.targetConnector?this.targetConnector.options.name:null),f("toX",e),f("toY",e)),mt(this.options.type)&&mt(e.type)&&e.set("type",this.options.type),this.dataItem=e,this.diagram._resumeModelRefresh(),t&&this.diagram._syncConnectionChanges())}},sourcePoint:function(){return this._resolvedSourceConnector?this._resolvedSourceConnector.position():this._sourcePoint},_setSource:function(t){var n,i=t instanceof C,o=this.options.fromConnector||Pt;i&&!t.getConnector(o)||(t!==e&&(this.from=t),this._removeFromSourceConnector(),null===t?this.sourceConnector&&(this._sourcePoint=(this._resolvedSourceConnector||this.sourceConnector).position(),this._clearSourceConnector(),this._setFromOptions(null,this._sourcePoint)):t instanceof y?(n=t.shape.dataItem,n&&this._setFromOptions(n.id),this.sourceConnector=t,this.sourceConnector.connections.push(this)):t instanceof $?(this._setFromOptions(null,t),this._sourcePoint=t,this.sourceConnector&&this._clearSourceConnector()):i&&(n=t.dataItem,n&&this._setFromOptions(n.id),this.sourceConnector=t.getConnector(o),this.sourceConnector.connections.push(this)))},source:function(t,e){return _t(t)&&(e&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new P.ConnectionEditUnit(this,t)),this._setSource(t),this.refresh()),this.sourceConnector?this.sourceConnector:this._sourcePoint},_setFromOptions:function(t,e){this.options.from=t,e?(this.options.fromX=e.x,this.options.fromY=e.y):(this.options.fromX=null,this.options.fromY=null)},sourceDefiner:function(t){if(!t)return this._sourceDefiner||(this._sourceDefiner=new P.PathDefiner(this.sourcePoint(),null,null)),this._sourceDefiner;if(!(t instanceof P.PathDefiner))throw"The sourceDefiner needs to be a PathDefiner.";t.left=null,this._sourceDefiner=t,this.source(t.point)},targetPoint:function(){return this._resolvedTargetConnector?this._resolvedTargetConnector.position():this._targetPoint},_setTarget:function(t){var n,i=t instanceof C,o=this.options.toConnector||Pt;i&&!t.getConnector(o)||(t!==e&&(this.to=t),this._removeFromTargetConnector(),null===t?this.targetConnector&&(this._targetPoint=(this._resolvedTargetConnector||this.targetConnector).position(),this._clearTargetConnector(),this._setToOptions(null,this._targetPoint)):t instanceof y?(n=t.shape.dataItem,n&&this._setToOptions(n.id),this.targetConnector=t,this.targetConnector.connections.push(this)):t instanceof $?(this._setToOptions(null,t),this._targetPoint=t,this.targetConnector&&this._clearTargetConnector()):i&&(n=t.dataItem,n&&this._setToOptions(n.id),this.targetConnector=t.getConnector(o),this.targetConnector.connections.push(this)))},target:function(t,n){return _t(t)&&(n&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new P.ConnectionEditUnit(this,e,t)),this._setTarget(t),this.refresh()),this.targetConnector?this.targetConnector:this._targetPoint},_setToOptions:function(t,e){this.options.to=t,e?(this.options.toX=e.x,this.options.toY=e.y):(this.options.toX=null,this.options.toY=null)},targetDefiner:function(t){if(!t)return this._targetDefiner||(this._targetDefiner=new P.PathDefiner(this.targetPoint(),null,null)),this._targetDefiner;if(!(t instanceof P.PathDefiner))throw"The sourceDefiner needs to be a PathDefiner.";t.right=null,this._targetDefiner=t,this.target(t.point)},_updateConnectors:function(){this._updateConnector(this.source(),"source"),this._updateConnector(this.target(),"target")},_updateConnector:function(t,e){var n,i,o,s,r=this,a=r.diagram;t instanceof y&&!a.getShapeById(t.shape.id)?(n=t.shape.dataItem,i=t.options.name,o=function(){var o=a._dataMap[n.id];t=o.getConnector(i),r[e](t,!1),r.updateModel()},a._dataMap[n.id]?o():(s=a._inactiveShapeItems.getByUid(n.uid),s&&a._deferredConnectionUpdates.push(s.onActivate(o)))):r[e](t,!1)},content:function(t){var e=this._content(t);return mt(t)&&this._alignContent(),e},_createContentVisual:function(t){var e;return vt(t.visual)?e=t.visual.call(this,t):t.text&&(e=new Q(t)),e&&(this._contentVisual=e,e._includeInBBox=!1,this.visual.append(e)),e},_updateContentVisual:function(t){vt(t.visual)?(this.visual.remove(this._contentVisual),this._createContentVisual(t)):this._contentVisual.redraw(t)},_alignContent:function(){var t,e,n,i,o,s,r,a,h,c,d,u,l,p,f,_;if(this._contentVisual){for(t=fe,e=this.allPoints(),n=Ct.floor(e.length/2),i=n-1;i>0&&e[i].equals(e[n]);)i--,n++;o=e[n],s=e[i],r=this._contentVisual._measure(),a=r.width,h=r.height,c=e.length%2===0,d=s.distanceTo(o),c&&e.length>2&&d>0&&(s.y===o.y&&d<a||s.x===o.x&&d<h)&&(c=!1,t=0),c?(l=E.util.deg(Ct.atan2(o.y-s.y,o.x-s.x)),u=new $((o.x-s.x)/2+s.x,(o.y-s.y)/2+s.y),90===Ct.abs(l)?(u.x+=t,u.y-=h/2):l%180===0?(u.x-=a/2,u.y-=h+t):l<-90||0<l&&l<90?u.y-=h:(l<0||l>90)&&(u.x-=a,u.y-=h)):(p=Ct.floor(e.length/2),u=e[p].clone(),s=e[p-1],o=e[p+1],f=s.x<=u.x&&o.x<=u.x?t:-r.width-t,_=s.y<=u.y&&o.y<=u.y?t:-r.height-t,u.x+=f,u.y+=_),this._contentVisual.position(u)}},select:function(t){var n,i,o=this.diagram;if(this._canSelect()&&this.isSelected!==t)return this.isSelected=t,n=[],i=[],this.isSelected?(this.adorner=new et(this,this.options.selection),o._adorn(this.adorner,!0),o._selectedItems.push(this),n.push(this)):this.adorner&&(o._adorn(this.adorner,!1),ht.remove(o._selectedItems,this),this.adorner=e,i.push(this)),this.adorner&&this.adorner.refresh(),o._internalSelection||o._selectionChanged(n,i),!0},bounds:function(t){return!t||wt(t)?this._bounds:(this._bounds=t,e)},type:function(t){var n=this.options;return t?(t!==n.type&&(n.type=t,this._initRouter(),this.refresh()),e):n.type},_initRouter:function(){var t=(this.options.type||"").toLowerCase();this._router=t==St?new pt(this):new lt(this)},points:function(t){var e,n,i,o;if(!t){if(i=[],_t(this.definers))for(o=0;o<this.definers.length;o++)i.push(this.definers[o].point);return i}for(this.definers=[],e=0;e<t.length;e++)if(n=t[e],n instanceof P.Point)this.definers.push(new P.PathDefiner(n));else{if(!n.hasOwnProperty("x")||!n.hasOwnProperty("y"))throw"A Connection point needs to be a Point or an object with x and y properties.";this.definers.push(new P.PathDefiner(new $(n.x,n.y)))}},allPoints:function(){var t,e=[this.sourcePoint()];if(this.definers)for(t=0;t<this.definers.length;t++)e.push(this.definers[t].point);return e.push(this.targetPoint()),e},refresh:function(){this._resolveConnectors(),this._refreshPath(),this._alignContent(),this.adorner&&this.adorner.refresh()},_resolveConnectors:function(){var t,e,n,s,r=this,a=r.source(),h=r.target();a instanceof $?t=a:a instanceof y&&(n=i(a)?a.shape.connectors:[a]),h instanceof $?e=h:h instanceof y&&(s=i(h)?h.shape.connectors:[h]),t?s&&(r._resolvedTargetConnector=o(t,s)):n&&(e?r._resolvedSourceConnector=o(e,n):s&&this._resolveAutoConnectors(n,s))},_resolveAutoConnectors:function(t,e){var n,o,s,r,a,h,c,d,u,l,p,f=Ht,_=Ht;for(u=0;u<t.length;u++)if(c=t[u],!i(c))for(s=c.position(),l=0;l<e.length;l++)d=e[l],i(d)||(r=d.position(),p=Ct.round(s.distanceTo(r)),p<f&&this.diagram&&this._testRoutePoints(s,r,c,d)&&(f=p,n=c,o=d),p<_&&(a=c,h=d,_=p));n&&(a=n,h=o),this._resolvedSourceConnector=a,this._resolvedTargetConnector=h},_testRoutePoints:function(t,e,n,i){var o,s,r,a,h,c,d=this._router,u=!0;if(d instanceof pt)for(o=d.routePoints(t,e,n,i),h=this._getRouteExclude(t,e,n.shape,i.shape),o.unshift(t),o.push(e),c=1;c<o.length;c++)if(s=o[c-1],r=o[c],a=new J(Ct.min(s.x,r.x),Ct.min(s.y,r.y),Ct.abs(s.x-r.x),Ct.abs(s.y-r.y)),a.width>0&&(a.x++,a.width-=2),a.height>0&&(a.y++,a.height-=2),!a.isEmpty()&&this.diagram._shapesQuadTree.hitTestRect(a,h)){u=!1;break}return u},_getRouteExclude:function(t,e,n,i){var o=[];return this._isPointInsideShape(t,n)&&o.push(n),this._isPointInsideShape(e,i)&&o.push(i),o},_isPointInsideShape:function(t,e){var n,i,o,s=e.bounds(),r=e.rotate().angle,a=s.x,h=s.y;return n=t.clone().rotate(s.center(),r),i=n.x,o=n.y,i>a&&i<a+s.width&&o>h&&o<h+s.height},redraw:function(t){if(t){this.options=L({},this.options,t);var e=this.options.points;mt(e)&&e.length>0&&(this.points(e),this._refreshPath()),(t&&t.content||t.text)&&this.content(t.content),this.path.redraw({fill:t.fill,stroke:t.stroke,startCap:t.startCap,endCap:t.endCap})}},clone:function(){var t=this.serialize();return this.diagram&&this.diagram._isEditable&&mt(this.dataItem)&&(t.options.dataItem=u(this.dataItem)),new b(this.from,this.to,t.options)},serialize:function(){var t=this.from.toJSON?this.from.toJSON:""+this.from,e=this.to.toJSON?this.to.toJSON:""+this.to,n=L({},{options:this.options,from:t,to:e});return mt(this.dataItem)&&(n.dataItem=""+this.dataItem),n.options.points=this.points(),n},_hitTest:function(t){if(this.visible()){var e=new $(t.x,t.y),n=this.sourcePoint(),i=this.targetPoint();if(t.isEmpty&&!t.isEmpty()&&t.contains(n)&&t.contains(i))return this;if(this._router.hitTest(e))return this}},_hover:function(t){var e=(this.options.stroke||{}).color;t&&_t(this.options.hover.stroke.color)&&(e=this.options.hover.stroke.color),this.path.redraw({stroke:{color:e}})},_refreshPath:function(){mt(this.path)&&(this._drawPath(),this.bounds(this._router.getBounds()))},_drawPath:function(){var t,e,n;this._router&&this._router.route(),t=this.sourcePoint(),e=this.targetPoint(),n=this.points(),this.path.redraw({points:[t].concat(n,[e])})},_clearSourceConnector:function(){this.sourceConnector=e,this._resolvedSourceConnector=e},_clearTargetConnector:function(){this.targetConnector=e,this._resolvedTargetConnector=e},_removeFromSourceConnector:function(){this.sourceConnector&&ht.remove(this.sourceConnector.connections,this)},_removeFromTargetConnector:function(){this.targetConnector&&ht.remove(this.targetConnector.connections,this)},toJSON:function(){var t,e,n,i=this;return i.from&&i.from.toJSON?t=i.from.toJSON():(n=i._sourcePoint,t={x:n.x,y:n.y}),i.to&&i.to.toJSON?e=i.to.toJSON():(n=i._targetPoint,e={x:n.x,y:n.y}),{from:t,to:e}}}),S=O.extend({init:function(t,e){var n=this;kendo.destroy(t),O.fn.init.call(n,t,e),n._initTheme(),n._initElements(),n._extendLayoutOptions(n.options),n._initDefaults(e),n._interactionDefaults(),n._initCanvas(),n.mainLayer=new X({id:"main-layer"}),n.canvas.append(n.mainLayer),n._shapesQuadTree=new M(n),n._pan=new $,n._adorners=[],n.adornerLayer=new X({id:"adorner-layer"}),n.canvas.append(n.adornerLayer),n._createHandlers(),n._initialize(),n._resizingAdorner=new st(n,{editable:n.options.editable}),n._connectorsAdorner=new rt(n),n._adorn(n._resizingAdorner,!0),n._adorn(n._connectorsAdorner,!0),n.selector=new ot(n),n._clipboard=[],n.pauseMouseHandlers=!1,n._fetchFreshData(),n._createGlobalToolBar(),n._createOptionElements(),n.zoom(n.options.zoom),n.canvas.draw()},options:{name:"Diagram",theme:"default",layout:"",zoomRate:.1,zoom:1,zoomMin:0,zoomMax:2,dataSource:{},draggable:!0,template:"",autoBind:!0,editable:{rotate:{},resize:{},text:!0,tools:[],drag:{snap:{size:10,angle:10}},remove:!0},pannable:{},selectable:{key:"none"},tooltip:{enabled:!0,format:"{0}"},copy:{enabled:!0,offsetX:20,offsetY:20},shapeDefaults:P.shapeDefaults({undoable:!0}),connectionDefaults:{editable:{tools:[]},type:St},shapes:[],connections:[]},events:[Xt,Nt,Ft,Vt,Ut,xt,kt,Tt,Bt,Et,"toolBarClick","save","cancel","edit","remove","add","dataBound",Mt,Dt,It],items:function(){return t()},_createGlobalToolBar:function(){var t,e=this.options.editable;e&&(t=e.tools,!this._isEditable||t===!1||t&&0!==t.length||(t=["createShape","undo","redo","rotateClockwise","rotateAnticlockwise"]),t&&t.length&&(this.toolBar=new x(this,{tools:t||{},click:A(this._toolBarClick,this),modal:!1}),this.toolBar.element.css({textAlign:"left"}),this.element.prepend(this.toolBar.element),this._resize()))},createShape:function(){var t,e,n,i,o,s;(this.editor&&this.editor.end()||!this.editor)&&(t=this.dataSource,e=t.view()||[],n=e.length,i=p(t,{}),o=this._createShape(i,{}),this.trigger("add",{shape:o})||(t.insert(n,i),s=this._inactiveShapeItems.getByUid(i.uid),s.element=o,this.edit(o)))},_createShape:function(t,e){e=L({},this.options.shapeDefaults,e),e.dataItem=t;var n=new C(e,this);return n},createConnection:function(){var t,e,n,i,o;(this.editor&&this.editor.end()||!this.editor)&&(t=this.connectionsDataSource,e=t.view()||[],n=e.length,i=p(t,{}),o=this._createConnection(i),this.trigger("add",{connection:o})||(this._connectionsDataMap[i.uid]=o,t.insert(n,i),this.addConnection(o,!1),this.edit(o)))},_createConnection:function(t,e,n){var i,o=L({},this.options.connectionDefaults);return o.dataItem=t,i=new b(e||new $,n||new $,o)},editModel:function(t,e){var n,i,o,s;if(this.cancelEdit(),o=this.options.editable,"shape"==e)n=o.shapeEditors,i=o.shapeTemplate;else{if("connection"!=e)return;s=A(h,this),n=L({},{from:s,to:s},o.connectionEditors),i=o.connectionTemplate}this.editor=new T(this.element,{update:A(this._update,this),cancel:A(this._cancel,this),model:t,type:e,target:this,editors:n,template:i}),this.trigger("edit",this._editArgs())},edit:function(t){if(t.dataItem){var e=t instanceof C?"shape":"connection";this.editModel(t.dataItem,e)}},cancelEdit:function(){this.editor&&(this._getEditDataSource().cancelChanges(this.editor.model),this._destroyEditor())},saveEdit:function(){this.editor&&this.editor.end()&&!this.trigger("save",this._editArgs())&&this._getEditDataSource().sync()},_update:function(){this.editor&&this.editor.end()&&!this.trigger("save",this._editArgs())&&(this._getEditDataSource().sync(),this._destroyEditor())},_cancel:function(){var t,e;this.editor&&!this.trigger("cancel",this._editArgs())&&(t=this.editor.model,this._getEditDataSource().cancelChanges(t),e=this._connectionsDataMap[t.uid]||this._dataMap[t.id],e&&e._setOptionsFromModel(t),this._destroyEditor())},_getEditDataSource:function(){return"shape"===this.editor.options.type?this.dataSource:this.connectionsDataSource},_editArgs:function(){var t={container:this.editor.wrapper};return t[this.editor.options.type]=this.editor.model,t},_destroyEditor:function(){this.editor&&(this.editor.close(),this.editor=null)},_initElements:function(){this.wrapper=this.element.empty().css("position","relative").attr("tabindex",0).addClass("k-widget k-diagram"),this.scrollable=t("<div />").appendTo(this.element)},_initDefaults:function(t){var e=this.options,n=e.editable,i=e.shapeDefaults,o=e.connectionDefaults,s=(t||{}).shapeDefaults;n===!1?(i.editable=!1,o.editable=!1):(_(n,i.editable,["drag","remove","connect"]),_(n,o.editable,["drag","remove"])),s&&s.connectors&&(e.shapeDefaults.connectors=s.connectors)},_interactionDefaults:function(){var t=this.options,e=t.selectable,n=t.pannable,i=kendo.support.mobileOS;e&&!mt(e.multiple)&&(t.selectable=L({multiple:!i},t.selectable)),n&&!mt(n.key)&&(t.pannable=L({key:i?"none":"ctrl"},t.pannable))},_initCanvas:function(){var e=t("<div class='k-layer'></div>").appendTo(this.scrollable)[0],n=this.viewport();this.canvas=new N(e,{width:n.width||Yt,height:n.height||Gt})},_createHandlers:function(){var t=this,e=t.element;e.on(de,A(t._wheel,t)).on("keydown"+bt,A(t._keydown,t)),t._userEvents=new kendo.UserEvents(this.scrollable,{multiTouch:!0,fastTap:!0,tap:A(t._tap,t),start:A(t._dragStart,t),move:A(t._drag,t),end:A(t._dragEnd,t),gesturestart:A(t._gestureStart,t),gesturechange:A(t._gestureChange,t),gestureend:A(t._gestureEnd,t),doubleTap:A(t._doubleTap,t),supportDoubleTap:!0}),t.toolService=new it(t),this.scrollable.on("mouseover"+bt,A(t._mouseover,t)).on("mouseout"+bt,A(t._mouseout,t)).on("mousemove"+bt,A(t._mouseMove,t)).on("mousedown"+bt,A(t._mouseDown,t)).on("mouseup"+bt,A(t._mouseUp,t)),this._syncHandler=A(t._syncChanges,t),t._resizeHandler=A(t.resize,t,!1),kendo.onResize(t._resizeHandler),this.bind(Nt,A(t._destroyToolBar,t)),this.bind(Ft,A(t._destroyToolBar,t))},_dragStart:function(t){var e,n;this._pauseMouseHandlers=!0,e=this._eventPositions(t,!0),n=t.event,this.toolService.start(e,this._meta(n))&&(this._destroyToolBar(),n.preventDefault())},_drag:function(t){var e=this._eventPositions(t),n=t.event;this.toolService.move(e,this._meta(n))&&n.preventDefault(); },_dragEnd:function(t){var e,n;this._pauseMouseHandlers=!1,e=this._eventPositions(t),n=t.event,this.toolService.end(e,this._meta(n))&&(this._createToolBar(),n.preventDefault())},_mouseMove:function(t){if(!this._pauseMouseHandlers){var e=this._eventPositions(t);this.toolService._updateHoveredItem(e),this.toolService._updateCursor(e)}},_mouseDown:function(){this._pauseMouseHandlers=!0},_mouseUp:function(){this._pauseMouseHandlers=!1},_tap:function(t){var e,n,i,o=this.toolService,s=this.options.selectable,r=this._eventPositions(t),a=this.focus();o._updateHoveredItem(r),o.hoveredItem?(e=o.hoveredItem,this.trigger("click",{item:e,point:r,meta:this._meta(t.event)}),s&&e.options.selectable!==!1&&(n=s.multiple!==!1,i=kendo.support.mobileOS||this._meta(t.event).ctrlKey,e.isSelected?i?(this._destroyToolBar(),e.select(!1)):this._createToolBar(a):(this._destroyToolBar(),this.select(e,{addToSelection:n&&i}),this._createToolBar(a)))):s&&(this._destroyToolBar(),this.deselect())},_keydown:function(t){this.toolService.keyDown(t.keyCode,this._meta(t))&&t.preventDefault()},_wheel:function(t){var e=n(t),i=this._eventPositions(t),o=L(this._meta(t),{delta:e});this.toolService.wheel(i,o)&&t.preventDefault()},_meta:function(t){return{ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,shiftKey:t.shiftKey,type:t.type}},_eventPositions:function(t,e){var n,i,o;return t.touch?(i=e?"startLocation":"location",n=new $(t.x[i],t.y[i])):(o=t.originalEvent,n=new $(o.pageX,o.pageY)),this.documentToModel(n)},_gestureStart:function(t){var e,n;this._destroyToolBar(),this.scroller.disable(),e=this.documentToModel(new $(t.center.x,t.center.y)),n={point:e,zoom:this.zoom()},this.trigger(Nt,n)||(this._gesture=t,this._initialCenter=e)},_gestureChange:function(t){var e,n,i=this._gesture,o=this._initialCenter,s=this.documentToView(new $(t.center.x,t.center.y)),r=t.distance/i.distance,a=this._zoom,h=!1;Ct.abs(r-1)>=ue&&(this._zoom=a=this._getValidZoom(a*r),this.options.zoom=a,this._gesture=t,h=!0),e=o.times(a),n=s.minus(e),(h||this._pan.distanceTo(n)>=le)&&(this._panTransform(n),this._updateAdorners()),t.preventDefault()},_doubleTap:function(t){var e=this,n=this._eventPositions(t),i=e.options,o=i.zoomRate,s=e.zoom()+o,r=this._meta(t),a={point:n,meta:r,zoom:s};e.trigger(Nt,a)||(s=kendo.dataviz.round(Math.max(i.zoomMin,Math.min(i.zoomMax,s)),2),a.zoom=s,e.zoom(s,a),e.trigger(Xt,a))},_gestureEnd:function(){this.options.pannable!==!1&&this.scroller.enable(),this.trigger(Xt,{point:this._initialCenter,zoom:this.zoom()})},_resize:function(){var t=this.viewport();this.canvas&&this.canvas.size(t),this.scrollable&&this.toolBar&&this.scrollable.height(t.height)},_mouseover:function(t){var e=t.target._kendoNode;e&&e.srcElement._hover&&e.srcElement._hover(!0,e.srcElement)},_mouseout:function(t){var e=t.target._kendoNode;e&&e.srcElement._hover&&e.srcElement._hover(!1,e.srcElement)},_initTheme:function(){var t,e=this,n=((e.options||{}).theme||"").toLowerCase(),i=B.ui.themes||{};t=B.SASS_THEMES.indexOf(n)!=-1?B.autoTheme().diagram:(i[n]||{}).diagram,e.options=L({},t,e.options),e.options.editable===!0&&L(e.options,{editable:(t||{}).editable})},_createOptionElements:function(){var t=this.options,e=t.shapes.length;e&&this._createShapes(),t.connections.length&&this._createConnections(),e&&t.layout&&this.layout(t.layout)},_createShapes:function(){var t,e,n=this,i=n.options,o=i.shapes;for(e=0;e<o.length;e++)t=o[e],n.addShape(t)},_createConnections:function(){var t,e,n,i,o=this,s=o.options,r=s.connectionDefaults,a=s.connections;for(i=0;i<a.length;i++)t=a[i],e=o._findConnectionTarget(t.from),n=o._findConnectionTarget(t.to),o.connect(e,n,L({},r,t))},_findConnectionTarget:function(t){var e,n,i;return t=t||{},e=this,n=wt(t)?t:t.shapeId||t.id,n?(i=e.getShapeById(n),t.connector&&(i=i.getConnector(t.connector))):i=new $(t.x||0,t.y||0),i},destroy:function(){var t=this;O.fn.destroy.call(t),this._userEvents&&this._userEvents.destroy(),kendo.unbindResize(t._resizeHandler),t.clear(),t.element.off(bt),t.scroller.wrapper.off(bt),t.canvas.destroy(!0),t.canvas=e,t._destroyEditor(),t.destroyScroller(),t._destroyGlobalToolBar(),t._destroyToolBar()},destroyScroller:function(){var t=this.scroller;t&&(t.destroy(),t.element.remove(),this.scroller=null)},save:function(){var t,e,n,i={shapes:[],connections:[]};for(t=0;t<this.shapes.length;t++)n=this.shapes[t],n.options.serializable&&i.shapes.push(n.options);for(t=0;t<this.connections.length;t++)e=this.connections[t],i.connections.push(L({},e.options,e.toJSON()));return i},focus:function(){if(!this.element.is(kendo._activeElement())){var t,e=this.element,n=e[0],i=[],o=[],s=document.documentElement;do n=n.parentNode,n.scrollHeight>n.clientHeight&&(i.push(n),o.push(n.scrollTop));while(n!=s);for(e.focus(),t=0;t<i.length;t++)i[t].scrollTop=o[t];return!0}},load:function(t){this.clear(),this.setOptions(t),this._createShapes(),this._createConnections()},setOptions:function(t){L(this.options,t)},clear:function(){var t=this;t.select(!1),t.mainLayer.clear(),t._shapesQuadTree.clear(),t._initialize()},connect:function(t,e,n){var i,o;return this.connectionsDataSource&&this._isEditable?(o=this.connectionsDataSource.add({}),i=this._connectionsDataMap[o.uid],i.source(t),i.target(e),i.redraw(n),i.updateModel()):(i=new b(t,e,L({},this.options.connectionDefaults,n)),this.addConnection(i)),i},connected:function(t,e){var n,i;for(n=0;n<this.connections.length;n++)if(i=this.connections[n],i.from==t&&i.to==e)return!0;return!1},addConnection:function(t,e){return e!==!1&&this.undoRedoService.add(new P.AddConnectionUnit(t,this),!1),t.diagram=this,t._setOptionsFromModel(),t.refresh(),this.mainLayer.append(t.visual),this.connections.push(t),this.trigger(kt,{added:[t],removed:[]}),t},_addConnection:function(t,e){var n,i=this.connectionsDataSource;if(i&&this._isEditable){if(n=p(i,u(t.dataItem)),t.dataItem=n,t.updateModel(),!this.trigger("add",{connection:t}))return this._connectionsDataMap[n.uid]=t,i.add(n),this.addConnection(t,e),t._updateConnectors(),t}else if(!this.trigger("add",{connection:t}))return this.addConnection(t,e),t._updateConnectors(),t},addShape:function(t,e){var n,i=this.options.shapeDefaults;if(t instanceof C)n=t;else{if(t instanceof kendo.Class)return;i=L({},i,t||{}),n=new C(i,this)}return e!==!1&&this.undoRedoService.add(new P.AddShapeUnit(n,this),!1),this.shapes.push(n),n.diagram!==this&&(this._shapesQuadTree.insert(n),n.diagram=this),this.mainLayer.append(n.visual),this.trigger(kt,{added:[n],removed:[]}),n},_addShape:function(t,e){var n,i,o=this,s=o.dataSource;if(s&&this._isEditable){if(n=p(s,u(t.dataItem)),t.dataItem=n,t.updateModel(),!this.trigger("add",{shape:t}))return this.dataSource.add(n),i=this._inactiveShapeItems.getByUid(n.uid),i.element=t,i.undoable=e,t}else if(!this.trigger("add",{shape:t}))return this.addShape(t,e)},remove:function(t,e){var n,i,o,s;for(t=gt(t)?t.slice(0):[t],n=l(t),i=n.shapes,o=n.connections,mt(e)||(e=!0),e&&this.undoRedoService.begin(),this._suspendModelRefresh(),s=i.length-1;s>=0;s--)this._removeItem(i[s],e,o);for(s=o.length-1;s>=0;s--)this._removeItem(o[s],e);this._resumeModelRefresh(),e&&this.undoRedoService.commit(!1),this.trigger(kt,{added:[],removed:t})},_removeShapeDataItem:function(t){this._isEditable&&(this.dataSource.remove(t.dataItem),delete this._dataMap[t.dataItem.id])},_removeConnectionDataItem:function(t){this._isEditable&&(this.connectionsDataSource.remove(t.dataItem),delete this._connectionsDataMap[t.dataItem.uid])},_triggerRemove:function(t){var e,n,i,o,s=[];for(o=0;o<t.length;o++)e=t[o],i=e.options.editable,n=e instanceof C?{shape:e}:{connection:e},i&&i.remove!==!1&&!this.trigger("remove",n)&&s.push(e);return s},undo:function(){this.undoRedoService.undo()},redo:function(){this.undoRedoService.redo()},select:function(t,e){if(!_t(t))return this._selectedItems;e=L({addToSelection:!1},e);var n,i,o=e.addToSelection,s=[],r=[];for(o||this.deselect(),this._internalSelection=!0,t instanceof Array?s=t:t instanceof w&&(s=[t]),n=0;n<s.length;n++)i=s[n],i.select(!0)&&r.push(i);this._selectionChanged(r,[]),this._internalSelection=!1},selectAll:function(){this.select(this.shapes.concat(this.connections))},selectArea:function(t){var e,n,i,o;if(this._internalSelection=!0,o=[],t instanceof J)for(n=this.shapes.concat(this.connections),e=0;e<n.length;e++)i=n[e],t&&!i._hitTest(t)||!i.options.enable||i.select(!0)&&o.push(i);this._selectionChanged(o,[]),this._internalSelection=!1},deselect:function(t){this._internalSelection=!0;var e,n,i=[],o=[];for(t instanceof Array?o=t:t instanceof w?o.push(t):_t(t)||(o=this._selectedItems.slice(0)),n=0;n<o.length;n++)e=o[n],e.select(!1)&&i.push(e);this._selectionChanged([],i),this._internalSelection=!1},toFront:function(t,e){var n,i,o;t||(t=this._selectedItems.slice()),n=this._getDiagramItems(t),!mt(e)||e?(i=s(this.mainLayer,n.visuals),o=new ut(this,t,i),this.undoRedoService.add(o)):(this.mainLayer.toFront(n.visuals),this._fixOrdering(n,!0))},toBack:function(t,e){var n,i,o;t||(t=this._selectedItems.slice()),n=this._getDiagramItems(t),!mt(e)||e?(i=s(this.mainLayer,n.visuals),o=new dt(this,t,i),this.undoRedoService.add(o)):(this.mainLayer.toBack(n.visuals),this._fixOrdering(n,!1))},bringIntoView:function(t,e){var n,i,o,s,r=this.viewport(),a=new P.RectAlign(r);0!==r.width&&0!==r.height&&(e=L({animate:!1,align:"center middle"},e),"none"==e.align&&(e.align="center middle"),t instanceof w?i=t.bounds(ie):gt(t)?i=this.boundingBox(t):t instanceof J&&(i=t.clone()),o=i.clone(),i.zoom(this._zoom),(i.width>r.width||i.height>r.height)&&(this._zoom=this._getValidZoom(Ct.min(r.width/o.width,r.height/o.height)),i=o.clone().zoom(this._zoom)),this._zoomMainLayer(),n=i.clone(),a.align(i,e.align),s=i.topLeft().minus(n.topLeft()),this.pan(s.times(-1),e.animate))},alignShapes:function(t){var e,n,i,o,s,r,a;if(ft(t)&&(t="Left"),e=this.select(),0!==e.length){switch(t.toLowerCase()){case"left":case"top":n=te;break;case"right":case"bottom":n=ee}for(o=0;o<e.length;o++)if(i=e[o],i instanceof C)switch(t.toLowerCase()){case"left":n=Ct.min(n,i.options.x);break;case"top":n=Ct.min(n,i.options.y);break;case"right":n=Ct.max(n,i.options.x);break;case"bottom":n=Ct.max(n,i.options.y)}for(s=[],r=[],o=0;o<e.length;o++)if(i=e[o],i instanceof C)switch(r.push(i),s.push(i.bounds()),t.toLowerCase()){case"left":case"right":i.position(new $(n,i.options.y));break;case"top":case"bottom":i.position(new $(i.options.x,n))}a=new P.TransformUnit(r,s),this.undoRedoService.add(a,!1)}},zoom:function(t,e){var n,i,o,s;return t&&(n=e?e.point:new P.Point(0,0),t=this._zoom=this._getValidZoom(t),ft(n)||(n=new P.Point(Ct.round(n.x),Ct.round(n.y)),i=n.times(t),o=this.modelToView(n),s=o.minus(i),this._storePan(new P.Point(Ct.round(s.x),Ct.round(s.y)))),e&&(e.zoom=t),this._panTransform(),this.canvas.surface.hideTooltip(),this._updateAdorners()),this._zoom},_getPan:function(t){var e=this.canvas;return e.translate||(t=t.plus(this._pan)),t},pan:function(t,n){var i,o;return t instanceof $?(i=this,o=i.scroller,t=i._getPan(t),t=t.times(-1),n?o.animatedScrollTo(t.x,t.y,function(){i._updateAdorners()}):(o.scrollTo(t.x,t.y),i._updateAdorners()),e):this._pan.times(-1)},viewport:function(){var t=this.element,e=t.width(),n=t.height();return this.toolBar&&(n-=V(this.toolBar.element)),new J(0,0,e,n)},copy:function(){var t,e;if(this.options.copy.enabled)for(this._clipboard=[],this._copyOffset=1,t=0;t<this._selectedItems.length;t++)e=this._selectedItems[t],this._clipboard.push(e)},cut:function(){var t,e;if(this.options.copy.enabled){for(this._clipboard=[],this._copyOffset=0,t=0;t<this._selectedItems.length;t++)e=this._selectedItems[t],this._clipboard.push(e);this.remove(this._clipboard,!0)}},paste:function(){var t,e,n,i,o,s,r,a;if(this._clipboard.length>0){for(i={},o=l(this._clipboard),s=o.connections,r=o.shapes,a={x:this._copyOffset*this.options.copy.offsetX,y:this._copyOffset*this.options.copy.offsetY},this.deselect(),n=0;n<r.length;n++)t=r[n],e=t.clone(),i[t.id]=e,e.position(new $(t.options.x+a.x,t.options.y+a.y)),e.diagram=this,e=this._addShape(e),e&&e.select();for(n=0;n<s.length;n++)t=s[n],e=this._addConnection(t.clone()),e&&(this._updateCopiedConnection(e,t,"source",i,a),this._updateCopiedConnection(e,t,"target",i,a),e.select(!0),e.updateModel());this._syncChanges(),this._copyOffset+=1}},_updateCopiedConnection:function(t,e,n,i,o){var s,r,a,h=e[n](),c=this;h instanceof y&&i[h.shape.id]?(a=i[h.shape.id],c.getShapeById(a.id)?t[n](a.getConnector(h.options.name)):(r=c._inactiveShapeItems.getByUid(a.dataItem.uid),r&&(s=function(e){a=c._dataMap[e.id],t[n](a.getConnector(h.options.name)),t.updateModel()},c._deferredConnectionUpdates.push(r.onActivate(s))))):t[n](new $(e[n+"Point"]().x+o.x,e[n+"Point"]().y+o.y))},boundingBox:function(t,e){var n,i,o,s=J.empty(),r=_t(t)?this._getDiagramItems(t):{shapes:this.shapes};if(r.shapes.length>0)for(i=r.shapes[0],s=i.bounds(oe),o=1;o<r.shapes.length;o++)i=r.shapes[o],n=i.bounds(oe),e===!0&&(n.x-=i._rotationOffset.x,n.y-=i._rotationOffset.y),s=s.union(n);return s},_containerOffset:function(){var t=this.element.offset();return this.toolBar&&(t.top+=V(this.toolBar.element)),t},documentToView:function(t){var e=this._containerOffset();return new $(t.x-e.left,t.y-e.top)},viewToDocument:function(t){var e=this._containerOffset();return new $(t.x+e.left,t.y+e.top)},viewToModel:function(t){return this._transformWithMatrix(t,this._matrixInvert)},modelToView:function(t){return this._transformWithMatrix(t,this._matrix)},modelToLayer:function(t){return this._transformWithMatrix(t,this._layerMatrix)},layerToModel:function(t){return this._transformWithMatrix(t,this._layerMatrixInvert)},documentToModel:function(t){var e=this.documentToView(t);return this.canvas.translate||(e.x=e.x+this.scroller.scrollLeft,e.y=e.y+this.scroller.scrollTop),this.viewToModel(e)},modelToDocument:function(t){return this.viewToDocument(this.modelToView(t))},_transformWithMatrix:function(t,e){var n,i,o=t;return t instanceof $?e&&(o=e.apply(t)):(n=this._transformWithMatrix(t.topLeft(),e),i=this._transformWithMatrix(t.bottomRight(),e),o=J.fromPoints(n,i)),o},setDataSource:function(t){this.options.dataSource=t,this._dataSource(),this.options.autoBind&&this.dataSource.fetch()},setConnectionsDataSource:function(t){this.options.connectionsDataSource=t,this._connectionDataSource(),this.options.autoBind&&this.connectionsDataSource.fetch()},layout:function(t){var e,n,i,o,s;switch(this._layouting=!0,ft(t)&&(t=this.options.layout),e=ft(t)||ft(t.type)?"Tree":t.type,e.toLowerCase()){case"tree":n=new P.TreeLayout(this);break;case"layered":n=new P.LayeredLayout(this);break;case"forcedirected":case"force":case"spring":case"springembedder":n=new P.SpringLayout(this);break;default:throw"Layout algorithm '"+e+"' is not supported."}i=new P.LayoutState(this),o=n.layout(t),o&&(s=new P.LayoutUndoUnit(i,o,t?t.animate:null),this.undoRedoService.add(s)),this._layouting=!1,this._redrawConnections()},getShapeById:function(t){var e;return(e=ht.first(this.shapes,function(e){return e.visual.id===t}))?e:e=ht.first(this.connections,function(e){return e.visual.id===t})},getShapeByModelId:function(t){var e;return e=this._isEditable?this._dataMap[t]:ht.first(this.shapes,function(e){return(e.dataItem||{}).id===t})},getShapeByModelUid:function(t){var e;return e=this._isEditable?ht.first(this.shapes,function(e){return(e.dataItem||{}).uid===t}):this._dataMap[t]},getConnectionByModelId:function(t){var e;return this.connectionsDataSource&&(e=ht.first(this.connections,function(e){return(e.dataItem||{}).id===t})),e},getConnectionByModelUid:function(t){var e;return this.connectionsDataSource&&(e=this._connectionsDataMap[t]),e},_extendLayoutOptions:function(t){t.layout&&(t.layout=L({},P.LayoutBase.fn.defaultOptions||{},t.layout))},_selectionChanged:function(t,e){(t.length||e.length)&&this.trigger(Vt,{selected:t,deselected:e})},_getValidZoom:function(t){return Ct.min(Ct.max(t,this.options.zoomMin),this.options.zoomMax)},_panTransform:function(t){var e=this,n=t||e._pan;e.canvas.translate?(e.scroller.scrollTo(n.x,n.y),e._zoomMainLayer()):(e._storePan(n),e._transformMainLayer())},_finishPan:function(){this.trigger(Ft,{total:this._pan,delta:Number.NaN})},_storePan:function(t){this._pan=t,this._storeViewMatrix()},_zoomMainLayer:function(){var t=this._zoom,e=new G(0,0,t,t);e.render(this.mainLayer),this._storeLayerMatrix(e),this._storeViewMatrix()},_transformMainLayer:function(){var t=this._pan,e=this._zoom,n=new G(t.x,t.y,e,e);n.render(this.mainLayer),this._storeLayerMatrix(n),this._storeViewMatrix()},_storeLayerMatrix:function(t){this._layerMatrix=t.toMatrix(),this._layerMatrixInvert=t.invert().toMatrix()},_storeViewMatrix:function(){var t=this._pan,e=this._zoom,n=new G(t.x,t.y,e,e);this._matrix=n.toMatrix(),this._matrixInvert=n.invert().toMatrix()},_toIndex:function(t,e){var n=this._getDiagramItems(t);this.mainLayer.toIndex(n.visuals,e),this._fixOrdering(n,!1)},_fixOrdering:function(t,e){var n,i,o=e?this.shapes.length-1:0,s=e?this.connections.length-1:0;for(n=0;n<t.shapes.length;n++)i=t.shapes[n],ht.remove(this.shapes,i),ht.insert(this.shapes,i,o);for(n=0;n<t.cons.length;n++)i=t.cons[n],ht.remove(this.connections,i),ht.insert(this.connections,i,s)},_getDiagramItems:function(t){var e,n,i={},o=t;for(i.visuals=[],i.shapes=[],i.cons=[],t?gt(t)||(o=[t]):o=this._selectedItems.slice(),e=0;e<o.length;e++)n=o[e],n instanceof C?(i.shapes.push(n),i.visuals.push(n.visual)):n instanceof b&&(i.cons.push(n),i.visuals.push(n.visual));return i},_removeItem:function(t,e,n){t.select(!1),t instanceof C?(this._removeShapeDataItem(t),this._removeShape(t,e,n)):t instanceof b&&(this._removeConnectionDataItem(t),this._removeConnection(t,e)),this.mainLayer.remove(t.visual)},_removeShape:function(t,e,n){var i,o,s,r,a=[],h=[];for(this.toolService._removeHover(),e&&this.undoRedoService.addCompositeItem(new K(t)),ht.remove(this.shapes,t),this._shapesQuadTree.remove(t),i=0;i<t.connectors.length;i++)for(s=t.connectors[i],r=0;r<s.connections.length;r++)o=s.connections[r],n&&B.i