@metadev/daga-react 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +45 -1
- package/index.js +2 -2
- package/index.mjs +2623 -2483
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`).map(e=>e.length)),$i=s=>{var e;return((e=s.match(/\n/g))==null?void 0:e.length)||0},O=[];for(let s=0;s<256;++s)O.push((s+256).toString(16).slice(1));function Ei(s,e=0){return(O[s[e+0]]+O[s[e+1]]+O[s[e+2]]+O[s[e+3]]+"-"+O[s[e+4]]+O[s[e+5]]+"-"+O[s[e+6]]+O[s[e+7]]+"-"+O[s[e+8]]+O[s[e+9]]+"-"+O[s[e+10]]+O[s[e+11]]+O[s[e+12]]+O[s[e+13]]+O[s[e+14]]+O[s[e+15]]).toLowerCase()}let We;const Mi=new Uint8Array(16);function Ni(){if(!We){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");We=crypto.getRandomValues.bind(crypto)}return We(Mi)}const Pi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Yt={randomUUID:Pi};function Xt(s,e,t){var l;if(Yt.randomUUID&&!s)return Yt.randomUUID();s=s||{};const n=s.random??((l=s.rng)==null?void 0:l.call(s))??Ni();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ei(n)}class lt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(e){this.entityMap[e.id]===void 0&&(this.entityMap[e.id]=e,this.entities.push(e))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(e){return this.entityMap[e]!==void 0}count(e){return this.entities.filter(e).length}filter(e){return this.entities.filter(e)}find(e){return this.entities.find(e)}get(e){return this.entityMap[e]}map(e){return this.entities.map(e)}remove(e){const t=this.get(e);t!==void 0&&(delete this.entityMap[e],B(this.entities,t))}size(){return this.entities.length}*[Symbol.iterator](){for(const e of this.entities)yield e}}const $e=0;class ye{constructor(e,t){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=e,this._id=t}get id(){return this._id}get highlighted(){var e,t;return((t=(e=this.model.canvas)==null?void 0:e.userHighlight)==null?void 0:t.contains(this.id))||!1}get selected(){var e,t;return((t=(e=this.model.canvas)==null?void 0:e.userSelection)==null?void 0:t.contains(this.id))||!1}select(){var e,t;return(t=(e=this.model.canvas)==null?void 0:e.selectCanvasView())==null?void 0:t.select(`g#${this.id}`)}}class ae extends lt{all(e=!1){return e?super.all():super.filter(t=>!t.removed)}contains(e,t=!1){return t?super.contains(e):super.contains(e)&&!this.entityMap[e].removed}count(e,t=!1){return t?super.count(e):super.count((n,l,a)=>e(n,l,a)&&!n.removed)}filter(e,t=!1){return t?super.filter(e):super.filter((n,l,a)=>e(n,l,a)&&!n.removed)}find(e,t=!1){return t?super.find(e):super.find((n,l,a)=>e(n,l,a)&&!n.removed)}get(e,t=!1){return t?super.get(e):this.contains(e)?super.get(e):void 0}map(e,t=!1){return t?super.map(e):super.filter(n=>!n.removed).map(e)}remove(e){const t=this.get(e,!0);t!==void 0&&(delete this.entityMap[e],B(this.entities,t))}size(e=!1){return e?super.size():super.filter(t=>!t.removed).length}*[Symbol.iterator](e=!1){if(e)for(const t of this.entities)yield t;else for(const t of this.entities.filter(n=>!n.removed))yield t}}function be(s,e){return!e||s[0]>e[0]?!0:s[0]===e[0]?s[1]>=e[1]:!1}class Ri{constructor(e,t,n,l,a,i){this.name=e,this.type=t,this.defaultValue=n,this.basic=l,this.editable=a,this.rootAttribute=i,this.options=void 0,this.properties=void 0}}var Se=(s=>(s.Boolean="boolean",s.Color="color",s.Date="date",s.Datetime="datetime",s.Number="number",s.Object="object",s.Option="option",s.OptionList="option-list",s.OptionSet="option-set",s.Text="text",s.TextArea="text-area",s.TextList="text-list",s.TextSet="text-set",s.TextMap="text-map",s.Time="time",s.Url="url",s))(Se||{});class Fe{constructor(e=[]){this.propertyList=e,this.propertyMap={};for(const t of this.propertyList)this.propertyMap[t.name]=t}getProperty(e){return this.propertyMap[e]}hasProperty(e){return this.propertyMap[e]!==void 0}hasProperties(){return this.propertyList.length>0}}class xe{constructor(e,t){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=e,this.rootElement=t,this.resetValues()}getRootElementValue(e){if(typeof e=="string")return this.rootElement[e];if(Array.isArray(e)&&e.length>0){let t=this.rootElement;for(const n of e){if(t==null)return;t=t[n]}return t}}setRootElementValue(e,t){if(typeof e=="string"&&(this.rootElement[e]=t),Array.isArray(e)&&e.length>0){let n=this.rootElement;for(let l=0;l<e.length-1;++l){const a=e[l];if(n==null)return;n=n[a]}if(n==null)return;n[e[e.length-1]]=t}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}getValue(e){var l;const t=(l=this.propertySet.getProperty(e))==null?void 0:l.rootAttribute;return t!=null&&(this.values[e]=this.getRootElementValue(t)),this.propertySet.getProperty(e).type==="object"?this.valueSets[e].getValues():this.values[e]}getValues(){const e={};for(const t in this.propertySet.propertyMap)this.propertySet.getProperty(t).type==="object"?e[t]=this.valueSets[t].getValues():e[t]=this.getValue(t);return e}getValuesForKeys(e){const t={};for(const n in e)this.propertySet.getProperty(n).type==="object"?t[n]=this.valueSets[n].getValuesForKeys(e[n]):t[n]=this.getValue(n);return t}getTimestamps(){const e={};for(const t in this.propertySet.propertyMap)if(this.propertySet.getProperty(t).type==="object")e[t]=this.valueSets[t].getTimestamps();else{const l=this.ownTimestamps[t];l&&(e[t]=l)}return e}hasValue(e){const t=this.getValue(e);return!Wt(t)}hasSetValue(e){const t=this.getValue(e),n=this.propertySet.getProperty(e);return n&&n.type==="object"?this.getSubValueSet(e).hasAnySetValue():!Wt(t)&&!Ie(t,n==null?void 0:n.defaultValue)}hasAnySetValue(){for(const e of this.propertySet.propertyList)if(this.hasSetValue(e.name))return!0;return!1}setValue(e,t){const n=this.propertySet.getProperty(e);if(n){n.type==="object"?this.valueSets[e].setValues(t):(this.values[e]=t,Ie(t,n.defaultValue)||this.displayProperty(n));const l=n.rootAttribute;l!=null&&this.setRootElementValue(l,t)}}setValues(e){this.resetValues();for(const t in e)this.propertySet.getProperty(t).type==="object"?this.valueSets[t].setValues(e[t]):this.setValue(t,e[t])}setTimestamps(e){this.ownTimestamps={};for(const t in e)this.propertySet.getProperty(t).type==="object"?this.valueSets[t].setTimestamps(e[t]):this.ownTimestamps[t]=e[t]}overwriteValues(e){for(const t in e)this.propertySet.getProperty(t).type==="object"?this.valueSets[t].overwriteValues(e[t]):this.setValue(t,e[t])}overwriteValuesLww(e,t){for(const n in e)this.propertySet.getProperty(n).type==="object"?this.valueSets[n].overwriteValuesLww(e[n],t):be(t,this.ownTimestamps[n])&&(this.setValue(n,e[n]),this.ownTimestamps[n]=t)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const e in this.propertySet.propertyMap){const t=this.propertySet.getProperty(e),n=t.rootAttribute;t.type==="object"?this.valueSets[e]=this.constructSubValueSet(e):this.values[e]=structuredClone(t.defaultValue),n!=null&&(t.defaultValue!==void 0?this.setRootElementValue(n,this.values[e]):this.values[e]=this.getRootElementValue(n)),t.basic?this.displayedProperties.push(t):this.hiddenProperties.push(t)}}constructSubValueSet(e){const t=this.propertySet.getProperty(e),n=new Fe(t.properties),l=new xe(n,this.rootElement);return l.overwriteValues(structuredClone(t.defaultValue)),l}getSubValueSet(e){return this.valueSets[e]}displayProperty(e){this.displayedProperties.includes(e)||(this.displayedProperties.push(e),B(this.hiddenProperties,e))}hideProperty(e){this.hiddenProperties.includes(e)||(this.hiddenProperties.push(e),B(this.displayedProperties,e))}}const Wt=s=>s==null||s===""||s instanceof Array&&s.length===0||s instanceof Object&&Object.keys(s).length===0,Ie=(s,e)=>s===e||JSON.stringify(s)===JSON.stringify(e),oi=(s,e)=>{const t={},n={},l=[];for(const a in s)l.push(a);for(const a in e)a in s||l.push(a);for(const a of l)if(nt(s[a])&&nt(e[a])){const i=oi(s[a],e[a]);Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(t[a]=i[0],n[a]=i[1])}else Ie(s[a],e[a])||(t[a]=s[a],n[a]=e[a]);return[t,n]},nt=s=>s!=null&&s.constructor===Object,zi={name:"",width:1,shape:ei.Straight,style:ti.Solid,label:null,defaultStartMarkerLook:null,defaultEndMarkerLook:null,startTypes:[],endTypes:[],color:"#000000",selectedColor:"#000000",properties:[]};class si{constructor(e){const t={...zi,...e};this.id=t.id,this.name=t.name,this.width=t.width,this.shape=t.shape,this.style=t.style,this.label=t.label,this.defaultStartMarkerLook=t.defaultStartMarkerLook,this.defaultEndMarkerLook=t.defaultEndMarkerLook,this.startTypes=t.startTypes,this.endTypes=t.endTypes,this.color=t.color,this.selectedColor=t.selectedColor,this.propertySet=new Fe(t.properties)}canStartFromType(e){return this.startTypes.indexOf(e)>=0}canFinishOnType(e){return this.endTypes.indexOf(e)>=0}}class ee extends ye{constructor(e,t,n,l,a){if(e.connections.get(a)!==void 0)throw new Error(`DiagramConnection with id "${a}" already exists`);super(e,a),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this.type=t,this.valueSet=new xe(t.propertySet,this),this.originalData={},this.startMarkerLook=t.defaultStartMarkerLook,this.endMarkerLook=t.defaultEndMarkerLook,this.setStart(n),this.setEnd(l)}get name(){return this.middleLabel}set name(e){this.middleLabel=e}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updateConnectionsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise()}setStart(e){this.start!==e?(this.start!==void 0&&B(this.start.outgoingConnections,this),this.start=e,e!==void 0&&(e.outgoingConnections.push(this),this.startDirection=e==null?void 0:e.direction,this.startCoords=(e==null?void 0:e.coords)||[0,0])):(this.startDirection=e==null?void 0:e.direction,this.startCoords=(e==null?void 0:e.coords)||[0,0]),this.updateInView()}setEnd(e){this.end!==e?(this.end!==void 0&&B(this.end.incomingConnections,this),this.end=e,e!==void 0&&(e.incomingConnections.push(this),this.endDirection=e==null?void 0:e.direction,this.endCoords=(e==null?void 0:e.coords)||[0,0])):(this.endDirection=e==null?void 0:e.direction,this.endCoords=(e==null?void 0:e.coords)||[0,0]),this.updateInView()}tighten(){var e,t;if((e=this.start)!=null&&e.rootElement&&this.end){const n=this.start.rootElement.ports.map(l=>[l,l.distanceTo(this.end.coords)]).sort((l,a)=>l[1]-a[1]).map(l=>l[0]);e:for(const l of n){if(l===this.end)continue e;{for(const a of l.outgoingConnections)if(a!==this&&a.end===this.end)continue e;for(const a of l.incomingConnections)if(a!==this&&a.start===this.end)continue e}if(l===this.start)break e;this.setStart(l);break e}}if((t=this.end)!=null&&t.rootElement&&this.start){const n=this.end.rootElement.ports.map(l=>[l,l.distanceTo(this.start.coords)]).sort((l,a)=>l[1]-a[1]).map(l=>l[0]);e:for(const l of n){if(l===this.start)continue e;{for(const a of l.incomingConnections)if(a!==this&&a.start===this.start)continue e;for(const a of l.outgoingConnections)if(a!==this&&a.end===this.start)continue e}if(l===this.end)break e;this.setEnd(l);break e}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():$e}}class Li extends ae{constructor(e){super(),this.types=new lt,this.model=e}new(e,t,n,l){let a;if(e instanceof si)a=e;else{const o=this.types.get(e);if(o===void 0)throw new TypeError(`Connection type with id '${e}' could not be found.`);a=o}const i=new ee(this.model,a,t,n,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(e){var n,l;const t=this.get(e,!0);t&&(B(((n=t.start)==null?void 0:n.outgoingConnections)||[],t),B(((l=t.end)==null?void 0:l.incomingConnections)||[],t),super.remove(e),t.updateInView())}}const z={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",horizontalAlign:Ce.Center,verticalAlign:ze.Center,fit:!1};class ne extends ye{constructor(e,t,n,l,a,i,o,r,d,u,c,g,y,f){const h=`${t==null?void 0:t.id}_field`;if(e.fields.get(h)!==void 0)throw new Error("DiagramField for rootElement already exists");super(e,h),this.textTimestamp=null,this.rootElement=t,this.coords=n,this.width=l,this.height=a,this.fontSize=i,this.fontFamily=o,this.color=r,this.selectedColor=d,this.horizontalAlign=u,this.verticalAlign=c,this.defaultText=g,this._text=g,this.editable=y,this.fit=f}get text(){return this._text}set text(e){var t;e.trim()===""&&(e=this.defaultText),this._text=e,this.updateInView(),this.fit&&((t=this.model.canvas)==null||t.fitFieldRootInView(this.id))}select(){var e,t;return(t=(e=this.model.canvas)==null?void 0:e.selectCanvasView())==null?void 0:t.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updateFieldsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){var e;return((e=this.rootElement)==null?void 0:e.getPriority())||$e}}class Vi extends ae{constructor(e){super(),this.model=e}new(e,t,n,l,a,i,o,r,d,u,c,g,y){const f=new ne(this.model,e,t,o,r,n,l,a,i,d,u,c,g,y);return super.add(f),f.updateInView(),e!==void 0&&(e.label=f),f}remove(e){var n;const t=this.get(e,!0);t&&(((n=t.rootElement)==null?void 0:n.label)!==void 0&&t.rootElement.label===t&&(t.rootElement.label=void 0),super.remove(e),t.updateInView())}}const te=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),U=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],ie=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:s.margin.length===1?s.margin[0]:(s.margin.length===2||s.margin.length===3,s.margin[1]),H=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Ze=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Ke=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],qe=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Je=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Di={lookType:"shaped-look",shape:Be.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",selectedFillColor:"#FFFFFF",selectedBorderColor:"#000000"},Bi={label:null,ports:[],look:Di,priority:$e},Zt=1,Kt=1,Fi=1,ji=1;class G extends ye{constructor(e,t,n,l,a,i,o,r){if(e.sections.get(r)!==void 0)throw new Error(`DiagramSection with id "${r}" already exists`);super(e,r),this.ports=[],this.decorators=[],this.node=t,this.indexXInNode=n,this.indexYInNode=l,this.coords=a,this.width=i,this.height=o}get name(){var e;return((e=this.label)==null?void 0:e.text)||""}set name(e){this.label&&(this.label.text=e)}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updateSectionsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise()}getConfig(){var e,t,n,l,a;return(a=(l=(n=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:n.sections)==null?void 0:l[this.indexYInNode])==null?void 0:a[this.indexXInNode]}getMinWidth(){var e,t,n,l;return((l=(n=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:n.minWidths)==null?void 0:l[this.indexXInNode])||Fi}getMinHeight(){var e,t,n,l;return((l=(n=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:n.minHeights)==null?void 0:l[this.indexYInNode])||ji}getPriority(){var e,t,n,l,a,i;return((i=(a=(l=(n=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:n.sections)==null?void 0:l[this.indexYInNode])==null?void 0:a[this.indexXInNode])==null?void 0:i.priority)||Bi.priority}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const t=this.ports.map(a=>a.distanceTo(e)),n=t.indexOf(Math.min(...t));return this.ports[n]}}}getIncomingConnections(e=!1){const t=[];for(const n of this.ports)for(const l of n.incomingConnections)!e&&l.removed||t.push(l);return t}getOutgoingConnections(e=!1){const t=[];for(const n of this.ports)for(const l of n.outgoingConnections)!e&&l.removed||t.push(l);return t}getConnections(e=!1){const t=[];for(const n of this.ports){for(const l of n.incomingConnections)!e&&l.removed||t.push(l);for(const l of n.outgoingConnections)!e&&l.removed||t.push(l)}return t}move(e){this.setGeometry({coords:e,width:this.width,height:this.height})}stretch(e,t){const n=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let a,i;switch(e){case p.Left:a=[n[0]-t,n[1]],i=[l[0],l[1]],a[1]-a[0]<this.getMinWidth()&&(a[0]=a[1]-this.getMinWidth());break;case p.Top:a=[n[0],n[1]],i=[l[0]-t,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case p.Right:a=[n[0],n[1]+t],i=[l[0],l[1]],a[1]-a[0]<this.getMinWidth()&&(a[1]=a[0]+this.getMinWidth());break;case p.Bottom:a=[n[0],n[1]],i=[l[0],l[1]+t],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[a[0],i[0]],width:a[1]-a[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(e){var i,o,r,d,u,c;const t=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;const l=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];for(const g of this.ports)g.move(Le(g.coords,t,n,l,a));this.label&&(this.label.coords=[this.coords[0]+U((i=this.getConfig())==null?void 0:i.label),this.coords[1]+H((o=this.getConfig())==null?void 0:o.label)],this.label.width=this.width-U((r=this.getConfig())==null?void 0:r.label)-ie((d=this.getConfig())==null?void 0:d.label),this.label.height=this.height-H((u=this.getConfig())==null?void 0:u.label)-te((c=this.getConfig())==null?void 0:c.label),this.label.updateInView());for(const g of this.decorators)g.move(Le(g.coords,t,n,l,a));this.getConnections().forEach(g=>g.tighten()),this.updateInView()}}class Oi extends ae{constructor(e){super(),this.model=e}new(e,t,n,l,a,i,o){var c,g,y,f,h,m,b,v,C,S;const r=new G(this.model,e,t,n,l,a,i,o);super.add(r),r.updateInView(),e.sections.push(r),e.updateInView();const d=(f=(y=(g=(c=e.type.sectionGrid)==null?void 0:c.sections)==null?void 0:g[n])==null?void 0:y[t])==null?void 0:f.ports;if(d&&d.length>0)for(let A=0;A<d.length;++A){const M=d[A],N=this.model.ports.new(r,[r.coords[0]+(((h=M==null?void 0:M.coords)==null?void 0:h[0])||0),r.coords[1]+(((m=M==null?void 0:M.coords)==null?void 0:m[1])||0)],M==null?void 0:M.direction,`${r.id}_${A}`);if(M.label){const P={...z,...M.label};let j;switch(N.direction){case p.Top:case p.Left:j=[N.coords[0]-P.fontSize,N.coords[1]-P.fontSize];break;case p.Bottom:j=[N.coords[0]-P.fontSize,N.coords[1]+P.fontSize];break;case p.Right:j=[N.coords[0]+P.fontSize,N.coords[1]-P.fontSize];break;default:j=N.coords}this.model.fields.new(N,j,P.fontSize,P.fontFamily,P.color,P.selectedColor,P.fontSize,P.fontSize,P.horizontalAlign,P.verticalAlign,"",P.editable,P.fit)}}const u=(S=(C=(v=(b=e.type.sectionGrid)==null?void 0:b.sections)==null?void 0:v[n])==null?void 0:C[t])==null?void 0:S.label;if(u){const A={...z,...u};this.model.fields.new(r,[r.coords[0]+U(A),r.coords[1]+H(A)],A.fontSize,A.fontFamily,A.color,A.selectedColor,r.width-U(A)-ie(A),r.height-H(A)-te(A),A.horizontalAlign,A.verticalAlign,"",A.editable,A.fit)}return r}remove(e){const t=this.get(e,!0);if(t){for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);t.label&&this.model.fields.remove(t.label.id),t.node&&B(t.node.sections,t),super.remove(e),t.updateInView()}}}const Gi={lookType:"shaped-look",shape:Be.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",selectedFillColor:"#FFFFFF",selectedBorderColor:"#000000"},re={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],sectionGrid:null,look:Gi,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:$e,properties:[]};class ni{constructor(e){const t={...re,...e};this.id=t.id,this.name=t.name,this.defaultWidth=t.defaultWidth,this.defaultHeight=t.defaultHeight,this.minWidth=t.minWidth,this.minHeight=t.minHeight,this.resizableX=t.resizableX,this.resizableY=t.resizableY,this.bottomPadding=Hi(t),this.leftPadding=_i(t),this.rightPadding=Yi(t),this.topPadding=Xi(t),this.label=t.label,this.ports=t.ports,this.sectionGrid=t.sectionGrid,this.look=t.look,this.isUnique=t.isUnique,this.canBeParentless=t.canBeParentless,this.childrenTypes=t.childrenTypes,this.priority=t.priority,this.propertySet=new Fe((e==null?void 0:e.properties)||[])}}class L extends ye{constructor(e,t,n=[0,0],l){if(e.nodes.get(l)!==void 0)throw new Error(`DiagramNode with id "${l}" already exists`);super(e,l),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this.type=t,this.valueSet=new xe(t.propertySet,this),this.originalData={},this.coords=n,this.width=t.defaultWidth,this.height=t.defaultHeight}get name(){var e;return((e=this.label)==null?void 0:e.text)||""}set name(e){this.label&&(this.label.text=e)}get removed(){return this.selfRemoved}updateInView(){var e;(e=this.model.canvas)==null||e.updateNodesInView(this.id)}raise(){var e;(e=this.select())==null||e.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.sections)t.raise();for(const t of this.decorators)t.raise();for(const t of this.children)t.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const t=this.ports.map(a=>a.distanceTo(e)),n=t.indexOf(Math.min(...t));return this.ports[n]}}}getIncomingConnections(e=!1){const t=[];for(const n of this.ports)for(const l of n.incomingConnections)!e&&l.removed||t.push(l);return t}getOutgoingConnections(e=!1){const t=[];for(const n of this.ports)for(const l of n.outgoingConnections)!e&&l.removed||t.push(l);return t}getConnections(e=!1){const t=[];for(const n of this.ports){for(const l of n.incomingConnections)!e&&l.removed||t.push(l);for(const l of n.outgoingConnections)!e&&l.removed||t.push(l)}return t}getAdjacentNodes(e=!1){var n,l;const t=[];for(const a of this.ports){for(const i of a.incomingConnections){if(!e&&i.removed)continue;const o=(n=i.start)==null?void 0:n.getNode();if(o){if(!e&&o.removed)continue;t.push(o)}}for(const i of a.outgoingConnections){if(!e&&i.removed)continue;const o=(l=i.end)==null?void 0:l.getNode();if(o){if(!e&&o.removed)continue;t.push(o)}}}return t}getLastAncestor(){let e=this;for(;e.parent!==void 0;)e=e==null?void 0:e.parent;return e}isAncestorOf(e){let t=e;for(;t!==void 0;){if(this.id===t.id)return!0;t=t.parent}return!1}isDescendantOf(e){return e.isAncestorOf(this)}addChild(e){if(e.id===this.id)return;let t=this.parent,n=!1;for(;t!==void 0;){if(t.id===e.id){n=!0;break}t=t.parent}n||this.children.indexOf(e)>=0||(this.fitToChild(e),this.children.push(e),e.parent=this,e.raise())}removeChild(e){B(this.children,e),e.parent=void 0}fitToChild(e){const t=this.coords[0]-e.coords[0]+this.type.leftPadding;t>=0&&this.stretch(p.Left,t);const n=this.coords[1]-e.coords[1]+this.type.topPadding;n>=0&&this.stretch(p.Top,n);const l=e.coords[0]+e.width-(this.coords[0]+this.width)+this.type.rightPadding;l>=0&&this.stretch(p.Right,l);const a=e.coords[1]+e.height-(this.coords[1]+this.height)+this.type.bottomPadding;a>=0&&this.stretch(p.Bottom,a),this.parent&&this.parent.fitToChild(this)}move(e){const t=[e[0]-this.coords[0],e[1]-this.coords[1]];for(const n of this.children)n.move([n.coords[0]+t[0],n.coords[1]+t[1]]);for(const n of this.sections)n.move([n.coords[0]+t[0],n.coords[1]+t[1]]);this.setGeometry({coords:e,width:this.width,height:this.height,sections:{},children:{}})}stretch(e,t){const n=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let a,i;switch(e){case p.Left:a=[n[0]-t,n[1]],i=[l[0],l[1]],a[1]-a[0]<this.type.minWidth&&(a[0]=a[1]-this.type.minWidth);break;case p.Top:a=[n[0],n[1]],i=[l[0]-t,l[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case p.Right:a=[n[0],n[1]+t],i=[l[0],l[1]],a[1]-a[0]<this.type.minWidth&&(a[1]=a[0]+this.type.minWidth);break;case p.Bottom:a=[n[0],n[1]],i=[l[0],l[1]+t],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[a[0],i[0]],width:a[1]-a[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(e,t,n,l){let a=Number.NEGATIVE_INFINITY;switch(e){case p.Bottom:for(const i of this.sections)i.indexYInNode===l&&(a=Math.max(a,i.getMinHeight()-i.height));t<a&&(t=a);for(const i of this.sections)i.indexYInNode===l?i.stretch(e,t):i.indexYInNode>l&&i.move([i.coords[0],i.coords[1]+t]);break;case p.Right:for(const i of this.sections)i.indexXInNode===n&&(a=Math.max(a,i.getMinWidth()-i.width));t<a&&(t=a);for(const i of this.sections)i.indexXInNode===n?i.stretch(e,t):i.indexXInNode>n&&i.move([i.coords[0]+t,i.coords[1]]);break;case p.Top:for(const i of this.sections)i.indexYInNode===l&&(a=Math.max(a,i.getMinHeight()-i.height));t<a&&(t=a);for(const i of this.sections)i.indexYInNode===l?i.stretch(e,t):i.indexYInNode<l&&i.move([i.coords[0],i.coords[1]-t]);break;case p.Left:for(const i of this.sections)i.indexXInNode===n&&(a=Math.max(a,i.getMinWidth()-i.width));t<a&&(t=a);for(const i of this.sections)i.indexXInNode===n?i.stretch(e,t):i.indexXInNode<n&&i.move([i.coords[0]-t,i.coords[1]]);break}this.stretch(e,t)}getGeometry(e){const t={};for(const l of this.sections)t[l.id]=l.getGeometry();const n={};for(const l of this.children)l.id!==e&&(n[l.id]=l.getGeometry(e));return{coords:[...this.coords],width:this.width,height:this.height,sections:t,children:n}}setGeometry(e){this.raise();const t=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;const l=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const o=e.children[i.id];o&&i.setGeometry(o)}for(const i of this.sections){const o=e.sections[i.id];o&&i.setGeometry(o)}for(const i of this.ports)i.move(Le(i.coords,t,n,l,a));this.label&&(this.label.coords=[this.coords[0]+U(this.type.label),this.coords[1]+H(this.type.label)],this.label.width=this.width-U(this.type.label)-ie(this.type.label),this.label.height=this.height-H(this.type.label)-te(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Le(i.coords,t,n,l,a));this.getConnections().forEach(i=>i.tighten()),this.updateInView()}}class Ui extends ae{constructor(e){super(),this.types=new lt,this.model=e}new(e,t,n){var i,o,r,d,u;let l;if(e instanceof ni)l=e;else{const c=this.types.get(e);if(c===void 0)throw new TypeError(`Node type with id '${e}' could not be found.`);l=c}const a=new L(this.model,l,t,n);if(super.add(a),a.updateInView(),l.sectionGrid!==null){let c=a.coords[1]+(l.sectionGrid.margin||0);for(let g=0;g<l.sectionGrid.sections.length;++g){let y=a.coords[0]+(l.sectionGrid.margin||0);for(let f=0;f<l.sectionGrid.sections[g].length;++f)this.model.sections.new(a,f,g,[y,c],((i=l.sectionGrid.defaultWidths)==null?void 0:i[f])||Zt,((o=l.sectionGrid.defaultHeights)==null?void 0:o[g])||Kt,`${a.id}_${g}_${f}`),y+=(((r=l.sectionGrid.defaultWidths)==null?void 0:r[f])||Zt)+(l.sectionGrid.margin||0);c+=(((d=l.sectionGrid.defaultHeights)==null?void 0:d[g])||Kt)+(l.sectionGrid.margin||0)}}if(l.ports.length>0)for(let c=0;c<l.ports.length;++c){const g=l.ports[c],y=this.model.ports.new(a,[a.coords[0]+g.coords[0],a.coords[1]+g.coords[1]],g.direction,`${a.id}_${c}`);if(g.label){const f={...z,...g.label};let h;switch(y.direction){case p.Top:case p.Left:h=[y.coords[0]-f.fontSize,y.coords[1]-f.fontSize];break;case p.Bottom:h=[y.coords[0]-f.fontSize,y.coords[1]+f.fontSize];break;case p.Right:h=[y.coords[0]+f.fontSize,y.coords[1]-f.fontSize];break;default:h=y.coords}this.model.fields.new(y,h,f.fontSize,f.fontFamily,f.color,f.selectedColor,f.fontSize,f.fontSize,f.horizontalAlign,f.verticalAlign,"",f.editable,f.fit)}}if(l.label){const c={...z,...l.label};this.model.fields.new(a,[a.coords[0]+U(c),a.coords[1]+H(c)],c.fontSize,c.fontFamily,c.color,c.selectedColor,a.width-U(c)-ie(c),a.height-H(c)-te(c),c.horizontalAlign,c.verticalAlign,"",c.editable,c.fit)}return a.valueSet.resetValues(),(u=a.model.canvas)==null||u.fitNodeInView(a.id),a}remove(e){const t=this.get(e,!0);if(t){for(t.parent&&B(t.parent.children,t);t.children.length>0;)this.model.nodes.remove(t.children[0].id);for(;t.sections.length>0;)this.model.sections.remove(t.sections[0].id);for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);for(;t.decorators.length>0;)this.model.decorators.remove(t.decorators[0].id);t.label&&this.model.fields.remove(t.label.id),super.remove(e),t.updateInView()}}getAtCoordinates(e,t){const n=[];for(const l of this)l.coords[0]<e&&e<l.coords[0]+l.width&&l.coords[1]<t&&t<l.coords[1]+l.height&&n.push(l);return n}}const ri=s=>{for(let e=0;e<s.length;++e)for(let t=0;t<s.length;++t)t!==e&&s[t].isAncestorOf(s[e])&&(s.splice(t,1),--t,e>t&&--e);return s},Hi=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?re.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?re.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),_i=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?re.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?re.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],Yi=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?re.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?re.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Xi=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?re.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?re.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Qe={radius:12,highlightedColor:"cyan",selectedColor:"violet"};class ue extends ye{constructor(e,t,n,l,a){if(e.ports.get(a)!==void 0)throw new Error(`DiagramPort with id "${a}" already exists`);super(e,a),this.outgoingConnections=[],this.incomingConnections=[],this.rootElement=t,this.coords=n,this.direction=l}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updatePortsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise();for(const t of this.incomingConnections)t.raise();for(const t of this.outgoingConnections)t.raise()}startConnection(e){this.outgoingConnections.push(e)}finishConnection(e){this.incomingConnections.push(e)}getNode(){if(this.rootElement instanceof L)return this.rootElement;if(this.rootElement instanceof G)return this.rootElement.node}getPriority(){var e;return((e=this.rootElement)==null?void 0:e.getPriority())||$e}move(e){const t=[e[0]-this.coords[0],e[1]-this.coords[1]];this.coords=e;for(const n of this.outgoingConnections)n.setStart(this);for(const n of this.incomingConnections)n.setEnd(this);this.label&&this.label.move([this.label.coords[0]+t[0],this.label.coords[1]+t[1]]),this.updateInView()}distanceTo(e){return Qt(this.coords,e)}}class Wi extends ae{constructor(e){super(),this.model=e}new(e,t,n,l){const a=new ue(this.model,e,t,n,l);return super.add(a),a.updateInView(),e!==void 0&&e.ports.push(a),a}remove(e){const t=this.get(e,!0);if(t){for(;t.outgoingConnections.length>0;)this.model.connections.remove(t.outgoingConnections[0].id);for(;t.incomingConnections.length>0;)this.model.connections.remove(t.incomingConnections[0].id);t.label&&this.model.fields.remove(t.label.id),(t.rootElement instanceof L||t.rootElement instanceof G)&&B(t.rootElement.ports,t),super.remove(e),t.updateInView()}}}class ai{import(e,t){e.clear(),t.id&&(e.id=t.id),e.name=t.name,e.description=t.description,e.type=t.type,e.createdAt=new Date(t.createdAt),e.updatedAt=new Date(t.updatedAt);for(const n of t.nodes||[])this.importNode(e,n);for(const n of t.connections||[])this.importConnection(e,n);return t.data&&e.valueSet.setValues(t.data),t.collabMeta&&(e.logicalClock=t.collabMeta.logicalClock,e.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),e}importNode(e,t){var l,a,i,o,r,d,u,c,g,y;const n=e.nodes.types.get(t.type);if(n){const f=new L(e,n,t.coords,t.id);if(e.nodes.add(f),f.width=t.width,f.height=t.height,t.label&&n.label){const m={...z,...n.label},b=new ne(e,f,[f.coords[0]+U(m),f.coords[1]+H(m)],f.width-U(m)-ie(m),f.height-H(m)-te(m),m.fontSize,m.fontFamily,m.color,m.selectedColor,m.horizontalAlign,m.verticalAlign,"",m.editable,m.fit);b.text=t.label,f.label=b,e.fields.add(b),b.updateInView()}for(const m of t.children||[]){const b=this.importNode(e,m);b!==void 0&&((l=f.children)==null||l.push(b),b.parent=f)}for(const m of t.sections||[]){const b=new G(e,f,m.indexXInNode,m.indexYInNode,m.coords,m.width,m.height,m.id);if((a=f.sections)==null||a.push(b),e.sections.add(b),m.label&&(d=(r=(o=(i=n.sectionGrid)==null?void 0:i.sections)==null?void 0:o[m.indexYInNode])==null?void 0:r[m.indexXInNode])!=null&&d.label){const C={...z,...(y=(g=(c=(u=n.sectionGrid)==null?void 0:u.sections)==null?void 0:c[m.indexYInNode])==null?void 0:g[m.indexXInNode])==null?void 0:y.label},S=new ne(e,b,[b.coords[0]+U(C),b.coords[1]+H(C)],b.width-U(C)-ie(C),b.height-H(C)-te(C),C.fontSize,C.fontFamily,C.color,C.selectedColor,C.horizontalAlign,C.verticalAlign,"",C.editable,C.fit);S.text=m.label,b.label=S,e.fields.add(S),S.updateInView()}let v=0;for(const C of m.ports||[]){const S=new ue(e,b,C.coords,C.direction,C.id);if(b.ports.push(S),e.ports.add(S),C.label){if(n.ports.length>v&&n.ports[v].label){const A={...z,...n.ports[v].label};let M;switch(S.direction){case p.Top:case p.Left:M=[S.coords[0]-A.fontSize,S.coords[1]-A.fontSize];break;case p.Bottom:M=[S.coords[0]-A.fontSize,S.coords[1]+A.fontSize];break;case p.Right:M=[S.coords[0]+A.fontSize,S.coords[1]-A.fontSize];break;default:M=S.coords}const N=new ne(e,S,M,A.fontSize,A.fontSize,A.fontSize,A.fontFamily,A.color,A.selectedColor,A.horizontalAlign,A.verticalAlign,"",A.editable,A.fit);N.text=C.label,S.label=N,e.fields.add(N),N.updateInView()}++v}C.collabMeta&&(S.selfRemoved=C.collabMeta.selfRemoved,S.selfRemovedTimestamp=C.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(S.label,C.collabMeta.label)),S.updateInView()}m.collabMeta&&(b.selfRemoved=m.collabMeta.selfRemoved,b.selfRemovedTimestamp=m.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(b.label,m.collabMeta.label)),b.updateInView()}let h=0;for(const m of t.ports||[]){const b=new ue(e,f,m.coords,m.direction,m.id);if(f.ports.push(b),e.ports.add(b),m.label){if(n.ports.length>h&&n.ports[h].label){const v={...z,...n.ports[h].label};let C;switch(b.direction){case p.Top:case p.Left:C=[b.coords[0]-v.fontSize,b.coords[1]-v.fontSize];break;case p.Bottom:C=[b.coords[0]-v.fontSize,b.coords[1]+v.fontSize];break;case p.Right:C=[b.coords[0]+v.fontSize,b.coords[1]-v.fontSize];break;default:C=b.coords}const S=new ne(e,b,C,v.fontSize,v.fontSize,v.fontSize,v.fontFamily,v.color,v.selectedColor,v.horizontalAlign,v.verticalAlign,"",v.editable,v.fit);S.text=m.label,b.label=S,e.fields.add(S),S.updateInView()}++h}m.collabMeta&&(b.selfRemoved=m.collabMeta.selfRemoved,b.selfRemovedTimestamp=m.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(b.label,m.collabMeta.label)),b.updateInView()}return t.data&&f.valueSet.setValues(t.data),t.collabMeta&&(f.selfRemoved=t.collabMeta.selfRemoved,f.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,f.geometryTimestamp=t.collabMeta.geometryTimestamp,this.importLabelCollabMeta(f.label,t.collabMeta.label),f.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),f.updateInView(),f}}importConnection(e,t){const n=e.connections.types.get(t.type);if(n){const l=new ee(e,n,t.start?e.ports.get(t.start):void 0,t.end?e.ports.get(t.end):void 0,t.id);return e.connections.add(l),l.startLabel=t.startLabel,l.middleLabel=t.middleLabel,l.endLabel=t.endLabel,l.points=t.points,t.data&&l.valueSet.setValues(t.data),t.collabMeta&&(l.selfRemoved=t.collabMeta.selfRemoved,l.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,l.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),l.updateInView(),l}}importLabelCollabMeta(e,t){e&&t&&(e.selfRemoved=t.selfRemoved,e.selfRemovedTimestamp=t.selfRemovedTimestamp,e.textTimestamp=t.textTimestamp)}}class je{constructor(e,t,n,l,a,i,o){this.canvas=e,this.id=t,this.typeId=n,this.coords=l,this.parentId=a,this.label=i,this.values=o}do(){var t;const e=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&((t=this.canvas.model.nodes.get(this.parentId))==null||t.addChild(e)),this.values!==void 0&&e.valueSet.setValues(structuredClone({...e.valueSet.getValues(),...this.values})),e.label&&(e.label.text=this.label||"")}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(e,t){return new je(e,t.id,t.typeId,t.coords,t.parentId,t.label,t.values)}}class dt{constructor(e,t,n){this.canvas=e,this.to=t,this.timestamp=n}do(){for(const e in this.to){const t=this.canvas.model.nodes.get(e,!0);if(t&&be(this.timestamp,t.geometryTimestamp)){const n=this.to[e];t.move([n[0],n[1]]),t.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new dt(e,t.to,t.timestamp)}}class Ae{constructor(e,t,n,l){this.canvas=e,this.nodeIds=t,this.delta=n,this.timestamp=l}do(){var e;for(const t of this.nodeIds){const n=this.canvas.model.nodes.get(t,!0);n&&be(this.timestamp,n.geometryTimestamp)&&(n.move([n.coords[0]+this.delta[0],n.coords[1]+this.delta[1]]),(e=n.parent)==null||e.fitToChild(n),n.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(e,t){return new Ae(e,t.nodeIds,t.delta,t.timestamp)}}class X{constructor(e,t,n,l){this.canvas=e,this.nodeId=t,this.to=n,this.timestamp=l}do(){var t,n,l;const e=this.canvas.model.nodes.get(this.nodeId,!0);if(e&&be(this.timestamp,e.geometryTimestamp)){e.setGeometry(this.to),(t=e.label)!=null&&t.fit&&this.canvas.fitFieldRootInView(e.label.id);for(const a of e.sections)(n=a.label)!=null&&n.fit&&this.canvas.fitFieldRootInView(a.label.id);(l=e.parent)==null||l.fitToChild(e),e.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new X(e,t.nodeId,t.to,t.timestamp)}}class Te{constructor(e,t,n,l,a){this.canvas=e,this.childId=t,this.parentId=n,this.childGeometry=l,this.timestamp=a}do(){var n;const e=this.canvas.model.nodes.get(this.childId,!0),t=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;e&&(this.parentId===void 0||t)&&be(this.timestamp,e.geometryTimestamp)&&((n=e.parent)==null||n.removeChild(e),e.setGeometry(this.childGeometry),t==null||t.addChild(e))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(e,t){return new Te(e,t.childId,t.parentId,t.childGeometry,t.timestamp)}}class Oe{constructor(e,t,n,l,a){this.canvas=e,this.id=t,this.typeId=n,this.startId=l,this.endId=a}do(){const e=this.canvas.model.ports.get(this.startId,!0),t=this.canvas.model.ports.get(this.endId,!0);e&&t&&this.canvas.model.connections.new(this.typeId,e,t,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(e,t){return new Oe(e,t.id,t.typeId,t.startId,t.endId)}}class we{constructor(e,t,n,l){this.canvas=e,this.fieldId=t,this.to=n,this.timestamp=l}do(){const e=this.canvas.model.fields.get(this.fieldId,!0);e&&be(this.timestamp,e.textTimestamp)&&(e.text=this.to,e.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new we(e,t.fieldId,t.to,t.timestamp)}}class ke{constructor(e,t,n,l){this.canvas=e,this.id=t,this.to=n,this.timestamp=l}getValueSet(){var e;return this.id===void 0?this.canvas.model.valueSet:(e=this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))==null?void 0:e.valueSet}do(){var e;(e=this.getValueSet())==null||e.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new ke(e,t.id,t.to,t.timestamp)}}class Q{constructor(e,t,n,l,a,i,o,r){this.canvas=e,this.nodeIds=t,this.sectionIds=n,this.portIds=l,this.connectionIds=a,this.fieldIds=i,this.selfRemoved=o,this.timestamp=r}doOne(e){e&&be(this.timestamp,e.selfRemovedTimestamp)&&(e.selfRemoved=this.selfRemoved,e.selfRemovedTimestamp=this.timestamp)}do(){for(const e of this.nodeIds)this.doOne(this.canvas.model.nodes.get(e,!0));for(const e of this.sectionIds)this.doOne(this.canvas.model.sections.get(e,!0));for(const e of this.portIds)this.doOne(this.canvas.model.ports.get(e,!0));for(const e of this.connectionIds)this.doOne(this.canvas.model.connections.get(e,!0));for(const e of this.fieldIds)this.doOne(this.canvas.model.fields.get(e,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(e,t){return new Q(e,t.nodeIds,t.sectionIds,t.portIds,t.connectionIds,t.fieldIds,t.removed,t.timestamp)}}class Ge{constructor(e,t,n){this.canvas=e,this.nodes=t,this.connections=n}do(){const e=new ai;this.canvas.userSelection.clear();for(const t of this.nodes){const n=e.importNode(this.canvas.model,t);n&&this.canvas.userSelection.add(n)}for(const t of this.connections){const n=e.importConnection(this.canvas.model,t);n&&this.canvas.userSelection.add(n)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(e,t){return new Ge(e,t.nodes,t.connections)}}class Zi{constructor(e){this.isInRoom=!1,this.canvas=e,this.replicaId=Xt()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+Xt()}doCollaboratively(e){if(e.do(),this.onSend){const t=e.serialize();this.onSend(t)}}receive(e){switch("timestamp"in e&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,e.timestamp[0])),e.type){case"addNode":{je.deserialize(this.canvas,e).do();break}case"applyLayout":{dt.deserialize(this.canvas,e).do();break}case"move":{Ae.deserialize(this.canvas,e).do();break}case"setGeometry":{X.deserialize(this.canvas,e).do();break}case"setParent":{Te.deserialize(this.canvas,e).do();break}case"addConnection":{Oe.deserialize(this.canvas,e).do();break}case"editField":{we.deserialize(this.canvas,e).do();break}case"updateValues":{ke.deserialize(this.canvas,e).do();break}case"setSelfRemoved":{Q.deserialize(this.canvas,e).do();break}case"paste":{Ge.deserialize(this.canvas,e).do();break}default:console.error("Unknown CollabAction type, skipping:",e)}}}class Ki{constructor(e,t){this.canvas=e,this.maximum=t,this.history=[],this.index=0}add(e){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(e)):(this.history.push(e),++this.index),this.canvas.diagramChange$.next({action:e,method:0})}undo(){let e;if(this.index>0){let t;do--this.index,e=this.history[this.index],t=e.undo();while(!t&&this.index>0)}this.canvas.diagramChange$.next({action:e,method:1})}redo(){let e;if(this.index<this.history.length){let t;do e=this.history[this.index],t=e.redo(),++this.index;while(!t&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:e,method:2})}}var k=(s=>(s.AddConnection="add-connection",s.AddNode="add-node",s.ApplyLayout="apply-layout",s.Clipboard="clipboard",s.ContextMenu="context-menu",s.EditField="edit-field",s.MoveNode="move-node",s.Paste="paste",s.Remove="remove",s.StretchNode="stretch-node",s.StretchSection="stretch-section",s.UpdateValues="update-values",s.Zoom="zoom",s))(k||{});class qi{constructor(e,t,n,l,a,i,o,r,d){this.canvas=e,this.type=t,this.coords=n,this.parentId=l,this.ancestorId=a,this.fromAncestorGeometry=i,this.toAncestorGeometry=o,this.label=r,this.values=d,this.id=this.canvas.collabEngine.freshId()}do(){const e=new je(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const t=new X(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return!0}undo(){const e=this.canvas.model.nodes.get(this.id),t=new Q(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const n=new X(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return e!==void 0}redo(){const e=this.canvas.model.nodes.get(this.id),t=new Q(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const n=new X(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return e===void 0}}class et{constructor(e,t,n){this.canvas=e,this.nodeIds=t,this.delta=n}do(){const e=new Ae(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(t=>this.canvas.model.nodes.get(t)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const e=new Ae(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(t=>this.canvas.model.nodes.get(t)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class F{constructor(e,t,n,l,a,i,o,r){this.canvas=e,this.intent=t,this.nodeId=n,this.from=l,this.to=a,this.ancestorId=i,this.fromAncestorGeometry=o,this.toAncestorGeometry=r}do(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){const t=new X(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const n=new X(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}}return e!==void 0}undo(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){this.to=e.getGeometry();const t=new X(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const n=new X(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}}return e!==void 0}redo(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){this.from=e.getGeometry();const t=new X(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}}class Ji{constructor(e,t,n,l,a,i,o,r,d){this.canvas=e,this.childId=t,this.fromParentId=n,this.toParentId=l,this.fromChildGeometry=a,this.toChildGeometry=i,this.ancestorId=o,this.fromAncestorGeometry=r,this.toAncestorGeometry=d}do(){const e=this.canvas.model.nodes.get(this.childId),t=new Te(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const n=new X(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return e!==void 0}undo(){const e=this.canvas.model.nodes.get(this.childId),t=new Te(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const n=new X(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return e!==void 0}redo(){return this.do()}}class tt{constructor(e,t,n,l){this.canvas=e,this.type=t,this.startId=n,this.endId=l,this.id=this.canvas.collabEngine.freshId()}do(){const e=new Oe(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){const e=this.canvas.model.connections.get(this.id),t=new Q(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}redo(){const e=this.canvas.model.connections.get(this.id),t=new Q(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e===void 0}}class qt{constructor(e,t,n,l){this.canvas=e,this.fieldId=t,this.from=n,this.to=l}do(){const e=this.canvas.model.fields.get(this.fieldId),t=new we(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}undo(){const e=this.canvas.model.fields.get(this.fieldId);if(e){this.to=e.text;const t=new we(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}redo(){const e=this.canvas.model.fields.get(this.fieldId);if(e){this.from=e.text;const t=new we(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}}class Qi{constructor(e,t,n,l){this.canvas=e,this.id=t,this.from=n,this.to=l}do(){const e=new ke(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){const e=new ke(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.to=t.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}redo(){const e=new ke(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.from=t.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}}class eo{constructor(e,t,n,l,a,i){this.canvas=e,this.nodeIds=t,this.sectionIds=n,this.portIds=l,this.connectionIds=a,this.fieldIds=i}do(){const e=this.nodeIds.map(n=>this.canvas.model.nodes.get(n)!==void 0).includes(!0)||this.sectionIds.map(n=>this.canvas.model.sections.get(n)!==void 0).includes(!0)||this.portIds.map(n=>this.canvas.model.ports.get(n)!==void 0).includes(!0)||this.connectionIds.map(n=>this.canvas.model.connections.get(n)!==void 0).includes(!0)||this.fieldIds.map(n=>this.canvas.model.fields.get(n)!==void 0).includes(!0),t=new Q(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}undo(){const e=this.nodeIds.map(n=>this.canvas.model.nodes.get(n)===void 0).includes(!0)||this.sectionIds.map(n=>this.canvas.model.sections.get(n)===void 0).includes(!0)||this.portIds.map(n=>this.canvas.model.ports.get(n)===void 0).includes(!0)||this.connectionIds.map(n=>this.canvas.model.connections.get(n)===void 0).includes(!0)||this.fieldIds.map(n=>this.canvas.model.fields.get(n)===void 0).includes(!0),t=new Q(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){return this.do()}}class to{constructor(e,t,n,l){this.canvas=e,this.nodes=t,this.connections=n,this.coords=l}do(){const e=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const a of this.nodes)a.coords[0]<e[0]&&(e[0]=a.coords[0]),a.coords[1]<e[1]&&(e[1]=a.coords[1]);const t=this.coords!==void 0?[this.coords[0]-e[0],this.coords[1]-e[1]]:void 0,n={};for(const a of this.nodes){const i=a.id,o=this.canvas.collabEngine.freshId();if(n[i]=o,a.id=o,t&&(a.coords=[a.coords[0]+t[0],a.coords[1]+t[1]]),a.sections)for(const r of a.sections){const d=r.id;if(r.id.includes(a.id)?r.id=r.id.replace(a.id,o):r.id=this.canvas.collabEngine.freshId(),n[d]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]]),r.ports)for(const u of r.ports){const c=u.id;u.id.includes(a.id)?u.id=u.id.replace(a.id,o):u.id=this.canvas.collabEngine.freshId(),n[c]=u.id,t&&(u.coords=[u.coords[0]+t[0],u.coords[1]+t[1]])}}if(a.ports)for(const r of a.ports){const d=r.id;r.id.includes(a.id)?r.id=r.id.replace(a.id,o):r.id=this.canvas.collabEngine.freshId(),n[d]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]])}}for(const a of this.connections){const i=this.canvas.collabEngine.freshId();if(n[a.id]=i,a.id=i,a.start=n[a.start]||a.start,a.end=n[a.end]||a.end,t)for(let o=0;o<a.points.length;++o)a.points[o]=[a.points[o][0]+t[0],a.points[o][1]+t[1]]}const l=new Ge(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(l),!0}undo(){const e=this.nodes.map(n=>this.canvas.model.nodes.get(n.id)!==void 0).includes(!0)||this.connections.map(n=>this.canvas.model.connections.get(n.id)!==void 0).includes(!0),t=new Q(this.canvas,this.nodes.map(n=>n.id),[],[],this.connections.map(n=>n.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){const e=this.nodes.map(n=>this.canvas.model.nodes.get(n.id)===void 0).includes(!0)||this.connections.map(n=>this.canvas.model.connections.get(n.id)===void 0).includes(!0),t=new Q(this.canvas,this.nodes.map(n=>n.id),[],[],this.connections.map(n=>n.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}}class Ue{constructor(e){this.type=e,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}class de extends Ue{constructor(e,t,n){super(0),this.cause=e,this.target=t,this.coords=n}}class ce extends Ue{constructor(e,t,n){super(1),this.cause=e,this.target=t,this.coords=n}}class D extends Ue{constructor(e,t){super(2),this.targets=e,this.selected=t}}class K extends Ue{constructor(e){super(3),this.target=e}}class io extends ye{constructor(e,t,n,l,a,i,o,r){if(e.objects.get(r)!==void 0)throw new Error(`DiagramObject with id "${r}" already exists`);super(e,r),this.rootElement=t,this.coords=n,this.width=l,this.height=a,this.priority=i,this.html=o}select(){var e,t;return(t=(e=this.model.canvas)==null?void 0:e.selectCanvasView())==null?void 0:t.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updateDecoratorsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}}class oo extends ae{constructor(e){super(),this.model=e}new(e,t,n,l,a,i,o){const r=new io(this.model,e,t,n,l,a,i,o);return super.add(r),r.updateInView(),e!==void 0&&e.decorators.push(r),r}remove(e){const t=this.get(e,!0);t&&((t.rootElement instanceof L||t.rootElement instanceof G)&&B(t.rootElement.decorators,t),super.remove(e),t.updateInView())}}class so extends ye{constructor(e,t,n,l,a,i,o){if(e.objects.get(o)!==void 0)throw new Error(`DiagramObject with id "${o}" already exists`);super(e,o),this.coords=t,this.width=n,this.height=l,this.priority=a,this.html=i}select(){var e,t;return(t=(e=this.model.canvas)==null?void 0:e.selectCanvasView())==null?void 0:t.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved}updateInView(){var e;(e=this.model.canvas)==null||e.updateObjectsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}}class no extends ae{constructor(e){super(),this.model=e}new(e,t,n,l,a,i){const o=new so(this.model,e,t,n,l,a,i);return super.add(o),o.updateInView(),o}remove(e){const t=this.get(e,!0);t&&(super.remove(e),t.updateInView())}}class li{constructor(e,t,n,l,a,i=[]){this.nodes=new Ui(this),this.sections=new Oi(this),this.ports=new Wi(this),this.connections=new Li(this),this.fields=new Vi(this),this.objects=new no(this),this.decorators=new oo(this),this.canvas=e,this.id=t,this.name=n,this.description=l,this.type=a,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new xe(new Fe(i),this)}clear(){var e,t;(e=this.canvas)==null||e.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),(t=this.canvas)==null||t.updateModelInView()}}const rt=96,Y=32,ve=rt+Y,ro=Math.PI/4,ao=100;class lo{constructor(e){this.canvas=e}open(e){this.close();const t=this.canvas.getPointerLocationRelativeToRoot(e),n=this.canvas.getPointerLocationRelativeToCanvas(e),l=this.canvas.selectRoot().append("foreignObject").attr("class","daga-context-menu").attr("x",`${t[0]-ve}px`).attr("y",`${t[1]-ve}px`).attr("width",`${2*ve}px`).attr("height",`${2*ve}px`).style("pointer-events","none").on(I.ContextMenu,i=>{this.canvas.canUserPerformAction(k.ContextMenu)&&(e.preventDefault(),this.open(i))}).on(I.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=l;const a=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&this.canvas.canUserPerformAction(k.Remove)&&a.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.preventDefault(),this.canvas.userSelection.cutToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&a.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.preventDefault(),this.canvas.userSelection.copyToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.canUserPerformAction(k.Paste)&&a.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.preventDefault(),this.canvas.userSelection.pasteFromClipboard(this.canvas.getClosestGridPoint(n)),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Remove)&&a.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.preventDefault(),this.canvas.userSelection.removeFromModel(),this.canvas.cancelAllUserActions()}}),a.length===0&&a.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<a.length;++i){const o=a[i],r=o.onPress,d=(i+.5-a.length/2)*ro,u=l.append("xhtml:div").attr("class",`daga-context-menu-button ${o.imageClass}-button${o.onPress!=null?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*Y}px`).style("height",`${2*Y}px`).style("border-radius",`${Y}px`).style("pointer-events","auto").on(I.Click,c=>{r&&r(c)}).on(I.KeyDown,c=>{r&&c.key===oe.Enter&&r(c)});u.append("xhtml:div").style("position","absolute").style("left",`${.75*Y}px`).style("top",`${.5*Y}px`).style("width",`${.5*Y}px`).style("height",`${.5*Y}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",o.imageClass),u.append("xhtml:span").style("position","absolute").style("left",`${.2*Y}px`).style("top",`${1.1*Y}px`).style("text-align","center").style("width",`${1.6*Y}px`).style("height",`${.35*Y}px`).style("margin","0").style("font-size",`${.35*Y}px`).style("font-weight","700").style("user-select","none").text(o.name),u.transition().ease($.easeLinear).duration(ao).tween("progress",()=>c=>{const g=d*c;return u.style("left",`${Math.sin(g)*rt-Y+ve}px`).style("top",`${-Math.cos(g)*rt-Y+ve}px`)})}}close(){var e;(e=this.contextMenuContainer)==null||e.remove(),this.contextMenuContainer=void 0}}class co extends ae{constructor(e){super(),this.focus=void 0,this.canvas=e}getFocus(){return this.focus}focusOn(e){this.clear(),this.focus=e,e instanceof ne&&e.rootElement?this.focusOn(e.rootElement):this.add(e)}add(e){if(super.add(e),e instanceof L){for(const t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateNodesInView(e.id)}else if(e instanceof G){for(const t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}else e instanceof ue?(e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updatePortsInView(e.id)):e instanceof ee&&this.canvas.updateConnectionsInView(e.id)}clear(){for(;this.entities.length>0;){const e=this.entities[0];this.remove(e.id),e.updateInView()}this.focus=void 0}}const ho=1;class di{export(e,t=!1){const n={name:e.name,type:e.type,typeVersion:ho,createdAt:e.createdAt,updatedAt:e.updatedAt,nodes:[],connections:[],data:e.valueSet.getValues(),...t?{collabMeta:{logicalClock:e.logicalClock,dataTimestamps:e.valueSet.getTimestamps()}}:{}};e.id&&(n.id=e.id),e.description&&(n.description=e.description);for(const l of e.nodes.all(!0))!t&&l.removed||l.parent===void 0&&n.nodes.push(this.exportNode(l,t));for(const l of e.connections.all(!0))!t&&l.removed||n.connections.push(this.exportConnection(l,t));return n}exportNode(e,t=!1){var i,o,r,d;const n=[];for(const u of e.children)n.push(this.exportNode(u,t));const l=[];for(const u of e.sections){const c=[];for(const g of u.ports)c.push({id:g.id,coords:Ne(g.coords),direction:g.direction,label:((i=g.label)==null?void 0:i.text)||"",...t?{collabMeta:{removed:g.removed,selfRemoved:g.selfRemoved,selfRemovedTimestamp:g.selfRemovedTimestamp,...this.exportLabelCollabMeta(g)}}:{}});l.push({id:u.id,ports:c,label:((o=u.label)==null?void 0:o.text)||"",indexXInNode:u.indexXInNode,indexYInNode:u.indexYInNode,coords:Ne(u.coords),width:u.width,height:u.height,...t?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}})}const a=[];for(const u of e.ports)a.push({id:u.id,coords:Ne(u.coords),direction:u.direction,label:((r=u.label)==null?void 0:r.text)||"",...t?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}});return{id:e.id,type:e.type.id,children:n,sections:l,ports:a,label:((d=e.label)==null?void 0:d.text)||"",coords:Ne(e.coords),width:e.width,height:e.height,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,geometryTimestamp:e.geometryTimestamp,dataTimestamps:e.valueSet.getTimestamps(),...this.exportLabelCollabMeta(e)}}:{}}}exportConnection(e,t=!1){var n,l;return{id:e.id,type:e.type.id,start:((n=e.start)==null?void 0:n.id)||"",end:((l=e.end)==null?void 0:l.id)||"",startLabel:e.startLabel,middleLabel:e.middleLabel,endLabel:e.endLabel,points:e.points,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,dataTimestamps:e.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:e}){return e?{label:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,textTimestamp:e.textTimestamp}}:{}}}const uo="Diagram properties";class fo extends ae{constructor(e){super(),this.canvas=e,this.canvas.propertyEditorChanges$.pipe(se.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(e){if(!this.contains(e.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(e instanceof L||e instanceof ee)?this.openInPropertyEditor(e):this.propertyEditorSelection===void 0&&e instanceof G?this.openInPropertyEditor(e.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(e),e.updateInView(),e instanceof L&&e.sections))for(const t of e.sections)super.add(t),t.updateInView()}remove(e){const t=this.get(e);if(t&&(this.propertyEditorSelection===t&&this.openInPropertyEditor(void 0),super.remove(e),t.updateInView(),t instanceof L&&t.sections))for(const n of t.sections)super.remove(n.id),n.updateInView()}toggle(e){this.contains(e.id)?this.remove(e.id):this.add(e)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const e=this.entities[0];super.remove(e.id),e.updateInView()}}move(e){for(const t of this.all())t instanceof L&&t.move([t.coords[0]+e[0],t.coords[1]+e[1]])}removeFromModel(){if(this.length>0){const e=[],t=[],n=[],l=[],a=[];for(const o of this.all())o instanceof L?e.push(o.id):o instanceof G?t.push(o.id):o instanceof ue?n.push(o.id):o instanceof ee?l.push(o.id):o instanceof ne&&a.push(o.id);const i=new eo(this.canvas,e,t,n,l,a);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const e={type:"daga-user-selection",nodes:[],connections:[]},t=new di;for(const n of this.all())n instanceof L&&e.nodes.push(t.exportNode(n,!1)),n instanceof ee&&e.connections.push(t.exportConnection(n,!1));navigator.clipboard.writeText(JSON.stringify(e))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(e){navigator.clipboard.readText().then(t=>{try{const n=JSON.parse(t);if(n.type!=="daga-user-selection")return;const l=new to(this.canvas,n.nodes,n.connections,e);this.canvas.actionStack.add(l),l.do()}catch{return}})}openInPropertyEditor(e){var l;this.makeUpdateValuesAction();const t=(l=this.canvas.parentComponent)==null?void 0:l.propertyEditor;if(t===void 0)return;const n=e==null?void 0:e.valueSet;n?(this.propertyEditorSelection=e,this.propertyEditorValues=structuredClone(n.getValues()),t&&(e instanceof L||e instanceof ee?(e instanceof L?e.name?t.title=`${e.type.name}: ${e.name}`:t.title=e.type.name:e instanceof ee&&(t.title=e.type.name),t.valueSet=void 0,t.valueSet=n):(t.title=uo,t.valueSet=void 0,t.valueSet=n))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,t&&(t.title="",t.valueSet=void 0))}makeUpdateValuesAction(){var o,r;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const e=this.propertyEditorSelection instanceof li?void 0:this.propertyEditorSelection.id;if(Ie(this.propertyEditorValues,(o=this.propertyEditorSelection)==null?void 0:o.valueSet.getValues()))return;const t=this.propertyEditorValues,n=structuredClone((r=this.propertyEditorSelection)==null?void 0:r.valueSet.getValues()),[l,a]=oi(t,n),i=new Qi(this.canvas,e,l,a);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=n}}const go=12,V=6,mo=25,it="diagram-connection-unfinished",po=100,De=class De{constructor(e,t){var n,l,a,i,o,r,d,u,c,g,y,f,h,m,b,v,C,S;if(this.backgroundPatternId=`daga-background-pattern-id-${De.canvasCount++}`,this.zoomTransform=$.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.viewInitialized$=new se.Subject,this.validatorChange$=new se.Subject,this.diagramChange$=new se.Subject,this.diagramEvent$=new se.Subject,this.propertyEditorChanges$=new se.Subject,this.parentComponent=e,this.model=new li(this,void 0,t.name||"unnamed","",t.type||"",t.properties||[]),this.userSelection=new fo(this),this.userHighlight=new co(this),this.contextMenu=new lo(this),this.backgroundColor=((n=t.canvas)==null?void 0:n.backgroundColor)||"#FFFFFF",this.gridSize=((a=(l=t.canvas)==null?void 0:l.grid)==null?void 0:a.enabled)===!1||((i=t.canvas)==null?void 0:i.grid)===void 0?0:Math.abs(((r=(o=t.canvas)==null?void 0:o.grid)==null?void 0:r.spacing)||10),this.gridThickness=Math.abs(((u=(d=t.canvas)==null?void 0:d.grid)==null?void 0:u.thickness)||.05),this.gridColor=((g=(c=t.canvas)==null?void 0:c.grid)==null?void 0:g.color)||"rgba(0, 0, 0, 0.1)",this.snapToGrid=((f=(y=t.canvas)==null?void 0:y.grid)==null?void 0:f.enabled)===!1||((h=t.canvas)==null?void 0:h.grid)===void 0?!1:((b=(m=t.canvas)==null?void 0:m.grid)==null?void 0:b.snap)||!1,this.zoomFactor=((v=t.canvas)==null?void 0:v.zoomFactor)||2,this.panRate=((C=t.canvas)==null?void 0:C.panRate)||100,this.inferConnectionType=t.inferConnectionType||!1,this.multipleSelectionOn=!1,this.priorityThresholds=((S=t.canvas)==null?void 0:S.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=t.layoutFormat,this.userActions=t.userActions||{},this.validators=[],this.actionStack=new Ki(this,mo),this.collabEngine=new Zi(this),t.nodeTypes)for(const A of t.nodeTypes){const M=new ni({...t.nodeTypeDefaults,...A});this.model.nodes.types.add(M)}if(t.connectionTypes){for(const A of t.connectionTypes){const M=new si({...t.connectionTypeDefaults,...A});this.model.connections.types.add(M)}this._connectionType=t.defaultConnection!==void 0?this.model.connections.types.get(t.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(e){var t,n;this._connectionType=e,(n=(t=this.parentComponent)==null?void 0:t.palette)==null||n.refreshPalette()}addValidator(e){this.validators.push(e),this.validatorChange$.next()}removeValidator(e){B(this.validators,e),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(e){var t,n;this.priorityThreshold=e,this.updateModelInView();for(const l of this.model.nodes)this.fitNodeInView(l.id);(n=(t=this.parentComponent)==null?void 0:t.palette)==null||n.refreshPalette()}initView(e){this.diagramRoot=$.select(e).append("div").node(),$.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),$.select(this.diagramRoot).on(I.Click,()=>{var a;(a=$.select(this.diagramRoot).node())==null||a.focus()}).on(I.ContextMenu,a=>{if(this.dragging){a.preventDefault(),a.stopPropagation(),this.dragging=!1;return}const i=new ce(a,null);this.diagramEvent$.next(i),!i.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(a.preventDefault(),this.contextMenu.open(a))}).on(I.DoubleClick,a=>{const i=new de(a,null);this.diagramEvent$.next(i)}).on(I.KeyDown,a=>{if(!a.ctrlKey&&(a.key===oe.Delete||a.key===oe.Backspace)&&this.canUserPerformAction(k.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="a"){a.preventDefault();for(const i of this.model.nodes)this.userSelection.add(i);for(const i of this.model.connections)this.userSelection.add(i);this.diagramEvent$.next(new D(this.userSelection.all(),!0))}if(a.ctrlKey&&a.key==="i"){a.preventDefault();const i=[],o=[];for(const r of this.model.nodes)this.userSelection.toggle(r),r.selected?i.push(r):o.push(r);for(const r of this.model.connections)this.userSelection.toggle(r),r.selected?i.push(r):o.push(r);i.length>0&&this.diagramEvent$.next(new D(i,!0)),o.length>0&&this.diagramEvent$.next(new D(o,!1))}if(a.ctrlKey&&a.key==="c"&&(a.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="x"&&(a.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="v"){a.preventDefault();const i=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(i[0][0]+i[1][0])/2,(i[0][1]+i[1][1])/2])),this.cancelAllUserActions()}a.ctrlKey&&a.key==="y"&&(a.preventDefault(),this.actionStack.redo()),a.ctrlKey&&a.key==="z"&&(a.preventDefault(),this.actionStack.undo()),a.key==="+"&&(a.preventDefault(),this.zoomBy(this.zoomFactor)),a.key==="-"&&(a.preventDefault(),this.zoomBy(1/this.zoomFactor)),a.key===oe.ArrowLeft&&(a.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),a.key===oe.ArrowRight&&(a.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),a.key===oe.ArrowDown&&(a.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),a.key===oe.ArrowUp&&(a.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const t=this.selectRoot().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%"),n=t.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(I.MouseMove,a=>{if(this.unfinishedConnection!==void 0){const i=this.getPointerLocationRelativeToCanvas(a);this.unfinishedConnection.endCoords=i}}).on(I.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new K(null)))}).on(I.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new K(null))),this.contextMenu.close(),this.userSelection.size()>0){const a=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(a,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call($.drag().filter(a=>this.multipleSelectionOn||he(a)).on(T.Start,a=>{this.startMultipleSelection(a)}).on(T.Drag,a=>{this.continueMultipleSelection(a)}).on(T.End,a=>{this.finishMultipleSelection(a)})).call(this.zoomBehavior=$.zoom().on(st.Zoom,a=>{if(a.sourceEvent){if(!this.canUserPerformAction(k.Zoom)){x(E.NotAllowed);return}a.sourceEvent.type===I.Wheel&&a.sourceEvent.wheelDelta!==void 0?(a.sourceEvent.wheelDelta>0&&x(E.ZoomIn),a.sourceEvent.wheelDelta<0&&x(E.ZoomOut)):a.sourceEvent.type===I.MouseMove&&x(E.AllScroll)}this.zoomTransform=a.transform;const i=a.transform.toString();this.selectCanvasElements().attr("transform",i),$.select(`#${this.backgroundPatternId}`).attr("patternTransform",i),this.contextMenu.close()}).on(st.End,()=>{x()})),l=t.append("defs");if(this.gridSize>0&&isFinite(this.gridSize)){const a=l.append("pattern").attr("id",this.backgroundPatternId).attr("x",-this.gridSize/2).attr("y",-this.gridSize/2).attr("width",this.gridSize).attr("height",this.gridSize).attr("patternUnits","userSpaceOnUse");a.append("rect").attr("x",0).attr("y",0).attr("width",this.gridSize).attr("height",this.gridSize).attr("fill",this.backgroundColor),a.append("circle").attr("cx",this.gridSize/2).attr("cy",this.gridSize/2).attr("r",this.gridSize*this.gridThickness).attr("fill",this.gridColor),n.attr("fill",`url(#${this.backgroundPatternId})`)}t.append("g").attr("class","daga-canvas-elements"),this.viewInitialized$.next()}zoomBy(e){isNaN(e)||this.zoomBehavior.scaleBy(this.selectCanvasView().select("rect"),e)}zoomTo(e){isNaN(e)||this.zoomBehavior.scaleTo(this.selectCanvasView().select("rect"),e)}translateBy(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateBy(this.selectCanvasView().select("rect"),e,t)}translateTo(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateTo(this.selectCanvasView().select("rect"),e,t)}center(){if(this.model.nodes.length>0){const e=this.selectCanvasView().select("rect").node().getBBox(),t=this.model.nodes.all(),n=Math.min(...t.map(f=>f.coords[0])),l=Math.max(...t.map(f=>f.coords[0]+f.width)),a=(n+l)/2,i=l-n,o=e.width,r=Math.min(...t.map(f=>f.coords[1])),d=Math.max(...t.map(f=>f.coords[1]+f.height)),u=(r+d)/2,c=d-r,g=e.height,y=Math.min(o/i,g/c,1);this.translateTo(a,u),this.zoomTo(y)}}getClosestGridPoint(e){return this.gridSize===0||!isFinite(this.gridSize)?e:[Math.round(e[0]/this.gridSize)*this.gridSize,Math.round(e[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){var n;const e=(n=this.selectRoot().node())==null?void 0:n.getBoundingClientRect(),t=[(e==null?void 0:e.width)||0,(e==null?void 0:e.height)||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(t[0]-this.zoomTransform.x)/this.zoomTransform.k,(t[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(e){if(e.type==="drag"||e.type==="start"||e.type==="end"){const t=e.sourceEvent;if(t&&(t.type==="touchmove"||t.type==="touchstart"||t.type==="touchend"))return e.sourceEvent.touches[0]||e.sourceEvent.changedTouches[0]}return e}getPointerLocationRelativeToCanvas(e){return $.pointer(this.getEventHoldingCoordinates(e),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(e){return $.pointer(this.getEventHoldingCoordinates(e),this.selectRoot().node())}getPointerLocationRelativeToBody(e){return $.pointer(this.getEventHoldingCoordinates(e),$.select("body").node())}getPointerLocationRelativeToScreen(e){const t=this.getPointerLocationRelativeToBody(e);return[t[0]-window.scrollX,t[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=t.exit(),l=t.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.look.lookType}`);e&&e.length>0&&(t=t.filter(i=>e.includes(i.id)));const a=l.merge(t);n.remove(),l.on(I.MouseOver,(i,o)=>{this.dragging||(this.userHighlight.focusOn(o),this.diagramEvent$.next(new K(o)))}).on(I.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(r,!1))}this.userSelection.toggle(o),this.diagramEvent$.next(new D([o],o.selected))}).on(I.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ce(i,o);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(o),this.diagramEvent$.next(new K(o)),this.userSelection.add(o),this.diagramEvent$.next(new D([o],!0)),this.contextMenu.open(i))}).on(I.DoubleClick,(i,o)=>{const r=new de(i,o);this.diagramEvent$.next(r)}).call($.drag().filter(i=>(this.secondaryButton=he(i),!0)).on(T.Start,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,o)}).on(T.Drag,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,o)}).on(T.End,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,o),this.secondaryButton=!1})),l.filter(".shaped-look").append("path"),l.filter(".image-look").append("image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none"),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(I.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x(E.EWResize)}).on(I.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x()}).call($.drag().on(T.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed?(x(E.EWResize),this.currentAction=new F(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(E.NotAllowed)}).on(T.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed){const r=this.getPointerLocationRelativeToCanvas(i);o.stretch(p.Left,o.coords[0]-r[0])}}).on(T.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&this.currentAction instanceof F&&this.currentAction.intent===k.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),o.stretch(p.Left,o.coords[0]-r[0]),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(I.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x(E.NSResize)}).on(I.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x()}).call($.drag().on(T.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed?(x(E.NSResize),this.currentAction=new F(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(E.NotAllowed)}).on(T.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed){const r=this.getPointerLocationRelativeToCanvas(i);o.stretch(p.Top,o.coords[1]-r[1])}}).on(T.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&this.currentAction instanceof F&&this.currentAction.intent===k.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),o.stretch(p.Top,o.coords[1]-r[1]),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(I.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x(E.EWResize)}).on(I.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x()}).call($.drag().on(T.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed?(x(E.EWResize),this.currentAction=new F(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(E.NotAllowed)}).on(T.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed){const r=this.getPointerLocationRelativeToCanvas(i);o.stretch(p.Right,r[0]-(o.coords[0]+o.width))}}).on(T.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&this.currentAction instanceof F&&this.currentAction.intent===k.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),o.stretch(p.Right,r[0]-(o.coords[0]+o.width)),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(I.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x(E.NSResize)}).on(I.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x()}).call($.drag().on(T.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed?(x(E.NSResize),this.currentAction=new F(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(E.NotAllowed)}).on(T.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed){const r=this.getPointerLocationRelativeToCanvas(i);o.stretch(p.Bottom,r[1]-(o.coords[1]+o.height))}}).on(T.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&this.currentAction instanceof F&&this.currentAction.intent===k.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),o.stretch(p.Bottom,r[1]-(o.coords[1]+o.height)),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),a.filter(".shaped-look").select("path").attr("d",i=>Ve(i.type.look.shape,0,0,i.width,i.height)).attr("fill",i=>i.selected?i.type.look.selectedFillColor:i.type.look.fillColor).attr("stroke",i=>i.selected?i.type.look.selectedBorderColor:i.type.look.borderColor).attr("stroke-width",i=>`${i.highlighted?3:1}px`),a.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",i=>i.width).attr("height",i=>i.height).attr("href",i=>i.selected?i.type.look.selectedBackgroundImage:i.type.look.backgroundImage),a.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTopLeft:i.type.look.backgroundImageTopLeft),a.filter(".stretchable-image-look").select("image.top-image").attr("x",i=>i.type.look.leftMargin).attr("y",0).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTop:i.type.look.backgroundImageTop),a.filter(".stretchable-image-look").select("image.top-right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",0).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTopRight:i.type.look.backgroundImageTopRight),a.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageLeft:i.type.look.backgroundImageLeft),a.filter(".stretchable-image-look").select("image.center-image").attr("x",i=>i.type.look.leftMargin).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageCenter:i.type.look.backgroundImageCenter),a.filter(".stretchable-image-look").select("image.right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageRight:i.type.look.backgroundImageRight),a.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottomLeft:i.type.look.backgroundImageBottomLeft),a.filter(".stretchable-image-look").select("image.bottom-image").attr("x",i=>i.type.look.leftMargin).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottom:i.type.look.backgroundImageBottom),a.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottomRight:i.type.look.backgroundImageBottomRight),a.filter(".resizable-x").select("line.left-resizer").attr("x1",V/2).attr("x2",V/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",V/2).attr("y2",V/2),a.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-V/2).attr("x2",i=>i.width-V/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-V/2).attr("y2",i=>i.height-V/2)}updateSectionsInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=t.exit(),l=t.enter().append("g").attr("id",i=>i.id).attr("class",i=>{var o,r,d,u,c,g;return`diagram-section${(r=(o=i.node)==null?void 0:o.type)!=null&&r.resizableX?" resizable-x":""}${(u=(d=i.node)==null?void 0:d.type)!=null&&u.resizableY?" resizable-y":""} ${(g=(c=i.getConfig())==null?void 0:c.look)==null?void 0:g.lookType}`});e&&e.length>0&&(t=t.filter(i=>e.includes(i.id)));const a=l.merge(t);n.remove(),l.on(I.MouseOver,(i,o)=>{this.dragging||(this.userHighlight.focusOn(o),this.diagramEvent$.next(new K(o)))}).on(I.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(d,!1))}const r=me(o);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(I.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ce(i,o);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=me(o);this.userHighlight.focusOn(d),this.diagramEvent$.next(new K(d)),this.userSelection.add(d),this.diagramEvent$.next(new D([d],!0)),this.contextMenu.open(i)}}).on(I.DoubleClick,(i,o)=>{const r=new de(i,o);this.diagramEvent$.next(r)}).call($.drag().filter(i=>(this.secondaryButton=he(i),!0)).on(T.Start,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const r=o==null?void 0:o.node;r?this.startMovingNode(i,r):x(E.NotAllowed)}}).on(T.Drag,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const r=o==null?void 0:o.node;r?this.continueMovingNode(i,r):x(E.NotAllowed)}}).on(T.End,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const r=o==null?void 0:o.node;r?this.finishMovingNode(i,r):x()}this.secondaryButton=!1})),l.filter(".shaped-look").append("path"),l.filter(".image-look").append("image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),l.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none"),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(I.MouseOver,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed&&x(E.EWResize)}).on(I.MouseOut,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed&&x()}).call($.drag().on(T.Start,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed?(x(E.EWResize),this.currentAction=new F(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(E.NotAllowed)}).on(T.Drag,(i,o)=>{var r,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed){const u=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(p.Left,o.coords[0]-u[0],o.indexXInNode,o.indexYInNode)}}).on(T.End,(i,o)=>{var r,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed&&this.currentAction instanceof F&&this.currentAction.intent===k.StretchSection){let u=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(u=this.getClosestGridPoint(u)),o.node.stretchSections(p.Left,o.coords[0]-u[0],o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(I.MouseOver,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed&&x(E.NSResize)}).on(I.MouseOut,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed&&x()}).call($.drag().on(T.Start,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed?(x(E.NSResize),this.currentAction=new F(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(E.NotAllowed)}).on(T.Drag,(i,o)=>{var r,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed){const u=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(p.Top,o.coords[1]-u[1],o.indexXInNode,o.indexYInNode)}}).on(T.End,(i,o)=>{var r,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed&&this.currentAction instanceof F&&this.currentAction.intent===k.StretchSection){let u=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(u=this.getClosestGridPoint(u)),o.node.stretchSections(p.Top,o.coords[1]-u[1],o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(I.MouseOver,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed&&x(E.EWResize)}).on(I.MouseOut,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed&&x()}).call($.drag().on(T.Start,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed?(x(E.EWResize),this.currentAction=new F(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(E.NotAllowed)}).on(T.Drag,(i,o)=>{var r,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed){const u=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(p.Right,u[0]-(o.coords[0]+o.width),o.indexXInNode,o.indexYInNode)}}).on(T.End,(i,o)=>{var r,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableX)&&!o.removed&&this.currentAction instanceof F&&this.currentAction.intent===k.StretchSection){let u=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(u=this.getClosestGridPoint(u)),o.node.stretchSections(p.Right,u[0]-(o.coords[0]+o.width),o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(I.MouseOver,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed&&x(E.NSResize)}).on(I.MouseOut,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed&&x()}).call($.drag().on(T.Start,(i,o)=>{var r,d;this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed?(x(E.NSResize),this.currentAction=new F(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(E.NotAllowed)}).on(T.Drag,(i,o)=>{var r,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed){const u=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(p.Bottom,u[1]-(o.coords[1]+o.height),o.indexXInNode,o.indexYInNode)}}).on(T.End,(i,o)=>{var r,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(r=o.node)==null?void 0:r.type)!=null&&d.resizableY)&&!o.removed&&this.currentAction instanceof F&&this.currentAction.intent===k.StretchSection){let u=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(u=this.getClosestGridPoint(u)),o.node.stretchSections(p.Bottom,u[1]-(o.coords[1]+o.height),o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),a.filter(".shaped-look").select("path").attr("d",i=>{var o;return Ve(((o=i.getConfig())==null?void 0:o.look).shape,0,0,i.width,i.height)}).attr("fill",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedFillColor:((r=i.getConfig())==null?void 0:r.look).fillColor}).attr("stroke",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBorderColor:((r=i.getConfig())==null?void 0:r.look).borderColor}).attr("stroke-width",i=>`${i.highlighted?3:1}px`),a.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",i=>i.width).attr("height",i=>i.height).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImage:((r=i.getConfig())==null?void 0:r.look).backgroundImage}),a.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageTopLeft:((r=i.getConfig())==null?void 0:r.look).backgroundImageTopLeft}),a.filter(".stretchable-image-look").select("image.top-image").attr("x",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("y",0).attr("width",i=>{var o,r;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin-((r=i.getConfig())==null?void 0:r.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageTop:((r=i.getConfig())==null?void 0:r.look).backgroundImageTop}),a.filter(".stretchable-image-look").select("image.top-right-image").attr("x",i=>{var o;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("y",0).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageTopRight:((r=i.getConfig())==null?void 0:r.look).backgroundImageTopRight}),a.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("height",i=>{var o,r;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin-((r=i.getConfig())==null?void 0:r.look).topMargin}).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageLeft:((r=i.getConfig())==null?void 0:r.look).backgroundImageLeft}),a.filter(".stretchable-image-look").select("image.center-image").attr("x",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("y",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("width",i=>{var o,r;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin-((r=i.getConfig())==null?void 0:r.look).leftMargin}).attr("height",i=>{var o,r;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin-((r=i.getConfig())==null?void 0:r.look).topMargin}).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageCenter:((r=i.getConfig())==null?void 0:r.look).backgroundImageCenter}),a.filter(".stretchable-image-look").select("image.right-image").attr("x",i=>{var o;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("y",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("height",i=>{var o,r;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin-((r=i.getConfig())==null?void 0:r.look).topMargin}).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageRight:((r=i.getConfig())==null?void 0:r.look).backgroundImageRight}),a.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",i=>{var o;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageBottomLeft:((r=i.getConfig())==null?void 0:r.look).backgroundImageBottomLeft}),a.filter(".stretchable-image-look").select("image.bottom-image").attr("x",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("y",i=>{var o;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("width",i=>{var o,r;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin-((r=i.getConfig())==null?void 0:r.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageBottom:((r=i.getConfig())==null?void 0:r.look).backgroundImageBottom}),a.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",i=>{var o;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("y",i=>{var o;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("href",i=>{var o,r;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageBottomRight:((r=i.getConfig())==null?void 0:r.look).backgroundImageBottomRight}),a.filter(".resizable-x").select("line.left-resizer").attr("x1",V/2).attr("x2",V/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",V/2).attr("y2",V/2),a.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-V/2).attr("x2",i=>i.width-V/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-V/2).attr("y2",i=>i.height-V/2)}updatePortsInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=t.exit(),l=t.enter().append("g").attr("id",i=>i.id).attr("class","diagram-port");e&&e.length>0&&(t=t.filter(i=>e.includes(i.id)));const a=l.merge(t);n.remove(),l.on(I.MouseOver,(i,o)=>{var r,d,u,c,g,y,f,h,m,b;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(o),this.diagramEvent$.next(new K(o))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((u=(d=(r=this.unfinishedConnection.start)==null?void 0:r.getNode())==null?void 0:d.type)==null?void 0:u.id)||"")&&this.unfinishedConnection.type.canFinishOnType(((g=(c=o.getNode())==null?void 0:c.type)==null?void 0:g.id)||"")||this.unfinishedConnection.type.canStartFromType(((f=(y=o.getNode())==null?void 0:y.type)==null?void 0:f.id)||"")&&this.unfinishedConnection.type.canFinishOnType(((b=(m=(h=this.unfinishedConnection.start)==null?void 0:h.getNode())==null?void 0:m.type)==null?void 0:b.id)||"")||x(E.NoDrop))}).on(I.MouseOut,()=>{this.unfinishedConnection&&x(E.Grabbing)}).on(I.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(d,!1))}const r=me(o);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(I.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ce(i,o);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=me(o);this.userHighlight.focusOn(d),this.diagramEvent$.next(new K(d)),this.userSelection.add(d),this.diagramEvent$.next(new D([d],!0)),this.contextMenu.open(i)}}).on(I.DoubleClick,(i,o)=>{const r=new de(i,o);this.diagramEvent$.next(r)}).call($.drag().filter(i=>(this.secondaryButton=he(i),!0)).on(T.Start,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(k.AddConnection)&&!o.removed?(x(E.Grabbing),this.startConnection(o),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):x(E.NotAllowed)}).on(T.Drag,(i,o)=>{var r,d,u,c;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(k.AddConnection)&&!o.removed&&this.unfinishedConnection!==void 0){const g=[i.x,i.y];(u=this.unfinishedConnectionTracer)==null||u.attr("d",ot(this.unfinishedConnection.type.shape,this.unfinishedConnection.startCoords,g,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.width,(r=this.unfinishedConnection.startMarkerLook)==null?void 0:r.markerWidth,(d=this.unfinishedConnection.endMarkerLook)==null?void 0:d.markerWidth));const y=(c=this.unfinishedConnectionTracer)==null?void 0:c.node();if(y){let f=2;const h=y.getTotalLength();h<f&&(f=0);const m=y.getPointAtLength(h-f);this.unfinishedConnection.endCoords=[m.x,m.y]}else this.unfinishedConnection.endCoords=g;if(this.updateConnectionsInView(it),this.model.ports.length>0){const f=this.getPointerLocationRelativeToCanvas(i);let h=Number.POSITIVE_INFINITY,m;for(const b of this.model.ports){const v=b.distanceTo(f);v<h&&(h=v,m=b)}m&&h<po?this.userHighlight.focusOn(m):this.userHighlight.clear()}}}).on(T.End,(i,o)=>{var r;if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(k.AddConnection)&&!o.removed){(r=this.unfinishedConnectionTracer)==null||r.remove();const d=this.userHighlight.getFocus();if(d instanceof ue)this.finishConnection(d);else if(d instanceof ne&&d.rootElement instanceof ue)this.finishConnection(d.rootElement);else if(d instanceof L||d instanceof G||d instanceof ne){let u;if(d instanceof L||d instanceof G)u=d;else if(d.rootElement instanceof L||d.rootElement instanceof G)u=d.rootElement;else{this.dropConnection();return}const c=u.getClosestPortToPoint([i.x,i.y]);c!==void 0?this.finishConnection(c):this.dropConnection()}else this.dropConnection()}x()}this.secondaryButton=!1})),l.append("circle"),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("circle").attr("cx",0).attr("cy",0).attr("r",Qe.radius).attr("fill",i=>i.selected?Qe.selectedColor:Qe.highlightedColor).attr("opacity",i=>i.highlighted||i.selected?.5:0)}updateConnectionsInView(...e){const t=this.model.connections.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&t.push(this.unfinishedConnection);let n=this.selectCanvasElements().selectAll("g.diagram-connection").data(t,o=>o.id);const l=n.exit(),a=n.enter().append("g").attr("id",o=>o.id).attr("class","diagram-connection");e&&e.length>0&&(n=n.filter(o=>e.includes(o.id)));const i=a.merge(n);l.remove(),a.on(I.MouseOver,(o,r)=>{r.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new K(r)))}).on(I.Click,(o,r)=>{if(!o.ctrlKey&&!o.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(d,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(I.ContextMenu,(o,r)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const d=new ce(o,r);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(o.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new K(r)),this.userSelection.add(r),this.diagramEvent$.next(new D([r],!0)),this.contextMenu.open(o))}).on(I.DoubleClick,(o,r)=>{const d=new de(o,r);this.diagramEvent$.next(d)}).call($.drag().filter(o=>(this.secondaryButton=he(o),!0)).on(T.Start,o=>{this.startMultipleSelection(o)}).on(T.Drag,o=>{this.continueMultipleSelection(o)}).on(T.End,o=>{this.finishMultipleSelection(o)})),a.append("path").attr("class","diagram-connection-path"),a.append("path").attr("class","diagram-connection-path-box"),a.append("marker").attr("id",o=>`${o.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),a.append("marker").attr("id",o=>`${o.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),a.append("g").attr("class","diagram-connection-start-label"),a.select("g.diagram-connection-start-label").append("path"),a.select("g.diagram-connection-start-label").append("text").style("user-select","none"),a.append("g").attr("class","diagram-connection-middle-label"),a.select("g.diagram-connection-middle-label").append("path"),a.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),a.append("g").attr("class","diagram-connection-end-label"),a.select("g.diagram-connection-end-label").append("path"),a.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",o=>o.removed?.5:1).select("path.diagram-connection-path").attr("d",o=>{var r,d;return ot(o.type.shape,o.startCoords,o.endCoords,o.startDirection,o.endDirection,o.type.width,(r=o.startMarkerLook)==null?void 0:r.markerWidth,(d=o.endMarkerLook)==null?void 0:d.markerWidth)}).attr("marker-start",o=>`url(#${o.id}-start-marker)`).attr("marker-end",o=>`url(#${o.id}-end-marker)`).attr("stroke",o=>o.selected?o.type.selectedColor:o.type.color).attr("stroke-width",o=>`${o.highlighted?o.type.width+1:o.type.width}px`).attr("stroke-dasharray",o=>Ht(o.type.style,o.type.width)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",o=>{var r,d;return ot(o.type.shape,o.startCoords,o.endCoords,o.startDirection,o.endDirection,o.type.width,(r=o.startMarkerLook)==null?void 0:r.markerWidth,(d=o.endMarkerLook)==null?void 0:d.markerWidth)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",o=>`${o.type.width+go}px`).attr("stroke-dasharray",o=>Ht(o.type.style,o.type.width)).attr("fill","none"),i.data().forEach(o=>{this.updateConnectionLabelsInView(o),this.updateConnectionMarkersInView(o)})}updateFieldsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=t.exit(),l=t.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-field");e&&e.length>0&&(t=t.filter(i=>e.includes(i.id)));const a=l.merge(t);n.remove(),l.style("box-sizing","border-box").on(I.MouseOver,(i,o)=>{this.dragging||(this.userHighlight.focusOn(o),this.diagramEvent$.next(new K(o)))}).on(I.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(d,!1))}const r=me(o);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(I.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ce(i,o);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=me(o);this.userHighlight.focusOn(d),this.diagramEvent$.next(new K(d)),this.userSelection.add(d),this.diagramEvent$.next(new D([d],!0)),this.contextMenu.open(i)}}).on(I.DoubleClick,(i,o)=>{const r=new de(i,o);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.EditField)&&o.editable&&!o.removed&&(this.currentAction=new qt(this,o.id,o.text,""),this.createInputField(o.text,o.coords,o.width,o.height,o.fontSize,o.fontFamily||z.fontFamily,d=>{o.text=d},d=>{o.text=d,this.currentAction instanceof qt&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call($.drag().filter(i=>(this.secondaryButton=he(i),!0)).on(T.Start,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let r;o.rootElement instanceof L?r=o.rootElement:o.rootElement instanceof G&&(r=o.rootElement.node),r?this.startMovingNode(i,r):x(E.NotAllowed)}}).on(T.Drag,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let r;o.rootElement instanceof L?r=o.rootElement:o.rootElement instanceof G&&(r=o.rootElement.node),r?this.continueMovingNode(i,r):x(E.NotAllowed)}}).on(T.End,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let r;o.rootElement instanceof L?r=o.rootElement:o.rootElement instanceof G&&(r=o.rootElement.node),r?this.finishMovingNode(i,r):x()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),a.attr("x",0).attr("y",0).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("div").style("justify-content",i=>i.horizontalAlign===Ce.Center?"center":i.horizontalAlign===Ce.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===ze.Center?"center":i.verticalAlign===ze.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":"100%").style("max-height",i=>i.fit?"default":"100%").style("overflow",i=>i.fit?"default":"hidden").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===Ce.Center?"center":i.horizontalAlign===Ce.Right?"end":"start").style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"))}updateObjectsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=t.exit(),l=t.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-object");e&&e.length>0&&(t=t.filter(i=>e.includes(i.id))),l.merge(t).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),n.remove(),l.on(I.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ce(i,o);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(I.DoubleClick,(i,o)=>{const r=new de(i,o);this.diagramEvent$.next(r)}).call($.drag().filter(i=>(this.secondaryButton=he(i),!0)).on(T.Start,i=>{this.startMultipleSelection(i)}).on(T.Drag,i=>{this.continueMultipleSelection(i)}).on(T.End,i=>{this.finishMultipleSelection(i)}))}updateDecoratorsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=t.exit(),l=t.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-decorator");e&&e.length>0&&(t=t.filter(i=>e.includes(i.id))),l.merge(t).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),n.remove(),l.on(I.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ce(i,o);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(I.DoubleClick,(i,o)=>{const r=new de(i,o);this.diagramEvent$.next(r)}).call($.drag().filter(i=>(this.secondaryButton=he(i),!0)).on(T.Start,i=>{this.startMultipleSelection(i)}).on(T.Drag,i=>{this.continueMultipleSelection(i)}).on(T.End,i=>{this.finishMultipleSelection(i)}))}updateConnectionLabelsInView(e){var i,o,r;const t=this.selectCanvasView().select(`g.diagram-connection#${e.id}`),l=t.select("path").node(),a={...z,...e.type.label};if(l){const d=l.getTotalLength();t.select("g.diagram-connection-start-label text").attr("x",0).attr("y",a.fontSize/3).attr("text-anchor","middle").attr("font-family",a.fontFamily).attr("font-size",a.fontSize).attr("fill",e.selected?a.selectedColor:a.color).style("font-kerning","none").text(e.startLabel);const u=(i=t.select("g.diagram-connection-start-label text").node())==null?void 0:i.getBoundingClientRect();if(u){const y=e.startLabel?u.width/this.zoomTransform.k+Ke(a)+qe(a):0,f=e.startLabel?u.height/this.zoomTransform.k+Je(a)+Ze(a):0,h=l.getPointAtLength(Math.max(U(a)+y/2,ie(a)+y/2,H(a)+f/2,te(a)+f/2));t.select("g.diagram-connection-start-label path").attr("d",Re(-y/2,-f/2,y,f)).attr("fill",e.selected?e.type.selectedColor:e.type.color).attr("stroke","none"),t.select("g.diagram-connection-start-label").attr("transform",`translate(${h.x},${h.y})`)}t.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",a.fontSize/3).attr("text-anchor","middle").attr("font-family",a.fontFamily).attr("font-size",a.fontSize).attr("fill",e.selected?a.selectedColor:a.color).style("font-kerning","none").text(e.middleLabel);const c=(o=t.select("g.diagram-connection-middle-label text").node())==null?void 0:o.getBoundingClientRect();if(c){const y=e.middleLabel?c.width/this.zoomTransform.k+Ke(a)+qe(a):0,f=e.middleLabel?c.height/this.zoomTransform.k+Je(a)+Ze(a):0,h=l.getPointAtLength(d/2);t.select("g.diagram-connection-middle-label path").attr("d",Re(-y/2,-f/2,y,f)).attr("fill",e.selected?e.type.selectedColor:e.type.color).attr("stroke","none"),t.select("g.diagram-connection-middle-label").attr("transform",`translate(${h.x},${h.y})`)}t.select("g.diagram-connection-end-label text").attr("x",0).attr("y",a.fontSize/3).attr("text-anchor","middle").attr("font-family",a.fontFamily).attr("font-size",a.fontSize).attr("fill",e.selected?a.selectedColor:a.color).style("font-kerning","none").text(e.endLabel);const g=(r=t.select("g.diagram-connection-end-label text").node())==null?void 0:r.getBoundingClientRect();if(g){const y=e.endLabel?g.width/this.zoomTransform.k+Ke(a)+qe(a):0,f=e.endLabel?g.height/this.zoomTransform.k+Je(a)+Ze(a):0,h=l.getPointAtLength(d-Math.max(U(a)+y/2,ie(a)+y/2,H(a)+f/2,te(a)+f/2));t.select("g.diagram-connection-end-label path").attr("d",Re(-y/2,-f/2,y,f)).attr("fill",e.selected?e.type.selectedColor:e.type.color).attr("stroke","none"),t.select("g.diagram-connection-end-label").attr("transform",`translate(${h.x},${h.y})`)}}}updateConnectionMarkersInView(e){const t=this.selectCanvasView().select(`g.diagram-connection#${e.id}`),n=t.select("marker.diagram-connection-start-marker"),l=t.select("marker.diagram-connection-end-marker");e.startMarkerLook!==null?n.attr("orient","auto-start-reverse").attr("markerWidth",e.startMarkerLook.markerWidth).attr("markerHeight",e.startMarkerLook.markerHeight).attr("refX",e.startMarkerLook.markerRefX).attr("refY",e.startMarkerLook.markerRefY).select("image").attr("href",e.selected?e.startMarkerLook.selectedImage:e.startMarkerLook.image).attr("width",e.startMarkerLook.markerWidth).attr("height",e.startMarkerLook.markerHeight):n.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),e.endMarkerLook!==null?l.attr("orient","auto-start-reverse").attr("markerWidth",e.endMarkerLook.markerWidth).attr("markerHeight",e.endMarkerLook.markerHeight).attr("refX",e.endMarkerLook.markerRefX).attr("refY",e.endMarkerLook.markerRefY).select("image").attr("href",e.selected?e.endMarkerLook.selectedImage:e.endMarkerLook.image).attr("width",e.endMarkerLook.markerWidth).attr("height",e.endMarkerLook.markerHeight):l.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fitFieldRootInView(e){var n,l,a,i,o,r,d,u,c,g,y;const t=this.model.fields.get(e);if(t){if(t.rootElement instanceof L&&t.fit){const f=this.minimumSizeOfField(t);let h=f[0]+U(t.rootElement.type.label)+ie(t.rootElement.type.label)-t.rootElement.width,m=f[1]+H(t.rootElement.type.label)+te(t.rootElement.type.label)-t.rootElement.height;this.snapToGrid&&(h=Math.ceil(h/this.gridSize)*this.gridSize,m=Math.ceil(m/this.gridSize)*this.gridSize),t.rootElement.width+h<t.rootElement.type.minWidth&&(h=t.rootElement.type.minWidth-t.rootElement.width),t.rootElement.height+m<t.rootElement.type.minHeight&&(m=t.rootElement.type.minHeight-t.rootElement.height),t.rootElement.stretch(p.Right,h),t.rootElement.stretch(p.Bottom,m)}if(t.rootElement instanceof G&&t.fit){const f=this.minimumSizeOfField(t);let h=f[0],m=f[1];for(const C of((n=t.rootElement.node)==null?void 0:n.sections)||[])C.label&&(C.indexXInNode===t.rootElement.indexXInNode&&C.indexYInNode!==t.rootElement.indexYInNode?h=Math.max(h,this.minimumSizeOfField(C.label)[0]):C.indexXInNode!==t.rootElement.indexXInNode&&C.indexYInNode===t.rootElement.indexYInNode&&(m=Math.max(m,this.minimumSizeOfField(C.label)[1])));f[0]<h&&(f[0]=h),f[1]<m&&(f[1]=m);let b=f[0]+U((a=(l=t.rootElement)==null?void 0:l.getConfig())==null?void 0:a.label)+ie((o=(i=t.rootElement)==null?void 0:i.getConfig())==null?void 0:o.label)-t.rootElement.width,v=f[1]+H((d=(r=t.rootElement)==null?void 0:r.getConfig())==null?void 0:d.label)+te((c=(u=t.rootElement)==null?void 0:u.getConfig())==null?void 0:c.label)-t.rootElement.height;this.snapToGrid&&(b=Math.ceil(b/this.gridSize)*this.gridSize,v=Math.ceil(v/this.gridSize)*this.gridSize),t.rootElement.width+b<(t.rootElement.getMinWidth()||0)&&(b=(t.rootElement.getMinWidth()||0)-t.rootElement.width),t.rootElement.height+v<(t.rootElement.getMinHeight()||0)&&(v=(t.rootElement.getMinHeight()||0)-t.rootElement.height),(g=t.rootElement.node)==null||g.stretchSections(p.Right,b,t.rootElement.indexXInNode,t.rootElement.indexYInNode),(y=t.rootElement.node)==null||y.stretchSections(p.Bottom,v,t.rootElement.indexXInNode,t.rootElement.indexYInNode)}}}fitNodeInView(e){var n,l;const t=this.model.nodes.get(e);if(t&&t.sections.length>0&&this.priorityThreshold){let a=0,i=0;for(const o of t.sections)if(o.getPriority()>=this.priorityThreshold){const r=o.coords[0]+o.width-t.coords[0],d=o.coords[1]+o.height-t.coords[1];a=Math.max(a,r),i=Math.max(i,d)}a+=((n=t.type.sectionGrid)==null?void 0:n.margin)||0,i+=((l=t.type.sectionGrid)==null?void 0:l.margin)||0,t.stretch(p.Right,a-t.width),t.stretch(p.Bottom,i-t.height)}}selectRoot(){return $.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectRoot().select(".daga-canvas-view")}selectCanvasElements(){return this.selectRoot().select(".daga-canvas-elements")}startConnection(e){var t,n,l,a;if(this.connectionType&&(this.connectionType.canStartFromType(((n=(t=e.getNode())==null?void 0:t.type)==null?void 0:n.id)||"")||this.connectionType.canFinishOnType(((a=(l=e.getNode())==null?void 0:l.type)==null?void 0:a.id)||"")))this.unfinishedConnection=new ee(this.model,this.connectionType,e,void 0,it);else if(this.inferConnectionType){let i=this.model.connections.types.all().find(o=>{var r,d;return o.canStartFromType(((d=(r=e.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")});i===void 0&&(i=this.model.connections.types.all().find(o=>{var r,d;return o.canFinishOnType(((d=(r=e.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")})),i!==void 0&&(this.unfinishedConnection=new ee(this.model,i,e,void 0,it))}}finishConnection(e){var t,n,l,a,i,o,r,d,u,c,g,y,f,h,m,b;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0)if(this.unfinishedConnection.start!==e)if(this.unfinishedConnection.type.canStartFromType(((a=(l=(n=(t=this.unfinishedConnection)==null?void 0:t.start)==null?void 0:n.getNode())==null?void 0:l.type)==null?void 0:a.id)||"")&&this.unfinishedConnection.type.canFinishOnType(((o=(i=e.getNode())==null?void 0:i.type)==null?void 0:o.id)||"")){const v=new tt(this,this.unfinishedConnection.type,(r=this.unfinishedConnection.start)==null?void 0:r.id,e.id);this.dropConnection(),v.do(),this.actionStack.add(v)}else if(this.unfinishedConnection.type.canFinishOnType(((g=(c=(u=(d=this.unfinishedConnection)==null?void 0:d.start)==null?void 0:u.getNode())==null?void 0:c.type)==null?void 0:g.id)||"")&&this.unfinishedConnection.type.canStartFromType(((f=(y=e.getNode())==null?void 0:y.type)==null?void 0:f.id)||"")){const v=new tt(this,this.unfinishedConnection.type,e.id,(h=this.unfinishedConnection.start)==null?void 0:h.id);this.dropConnection(),v.do(),this.actionStack.add(v)}else if(this.inferConnectionType){let v=this.model.connections.types.all().find(S=>{var A,M,N,P,j,W;return S.canStartFromType(((P=(N=(M=(A=this.unfinishedConnection)==null?void 0:A.start)==null?void 0:M.getNode())==null?void 0:N.type)==null?void 0:P.id)||"")&&S.canFinishOnType(((W=(j=e.getNode())==null?void 0:j.type)==null?void 0:W.id)||"")}),C=!1;if(v===void 0&&(v=this.model.connections.types.all().find(S=>{var A,M,N,P,j,W;return S.canFinishOnType(((P=(N=(M=(A=this.unfinishedConnection)==null?void 0:A.start)==null?void 0:M.getNode())==null?void 0:N.type)==null?void 0:P.id)||"")&&S.canStartFromType(((W=(j=e.getNode())==null?void 0:j.type)==null?void 0:W.id)||"")}),C=!0),v!==void 0){const S=new tt(this,v,C?e.id:(m=this.unfinishedConnection.start)==null?void 0:m.id,C?(b=this.unfinishedConnection.start)==null?void 0:b.id:e.id);this.dropConnection(),S.do(),this.actionStack.add(S)}else this.dropConnection()}else this.dropConnection();else this.dropConnection()}dropConnection(){var e,t,n,l;(e=this.unfinishedConnection)==null||e.setStart(void 0),(t=this.unfinishedConnection)==null||t.setEnd(void 0),(l=(n=this.unfinishedConnection)==null?void 0:n.select())==null||l.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(e){return this.userActions[e]!==!1}createInputField(e,t,n,l,a,i,o,r){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${t[0]}px`).attr("y",`${t[1]}px`).attr("width",`${n}px`).attr("height",`${l}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const u=d.append("xhtml:textarea");let c,g;u.text(e).style("box-sizing","border-box").style("width",`${n}px`).style("height",`${l}px`).style("font-size",`${a}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(I.KeyDown,f=>{f.stopPropagation()}).on(I.KeyUp,f=>{if(f.stopPropagation(),f.key===oe.Escape){const h=u.property("value");this.removeInputField(),r&&r(h)}}).on(I.Input,()=>{const f=u.property("value");u.attr("cols",Ti(f)+1),u.attr("rows",$i(f)+1),u.style("width",""),u.style("height",""),c=u.property("scrollWidth")+1,g=u.property("scrollHeight")+1;const h=Math.max(c,n),m=Math.max(g,l);d==null||d.attr("width",`${h}px`),u.style("width",`${h}px`),d==null||d.attr("height",`${m}px`),u.style("height",`${m}px`),o&&o(f)}).on(I.Click,f=>{f.stopPropagation()}).on(I.FocusOut,()=>{const f=u.property("value");this.removeInputField(),r&&r(f)});const y=u.node();y.focus(),y.select()}removeInputField(){var e,t,n;(t=(e=this.inputFieldContainer)==null?void 0:e.select("input"))==null||t.on(I.Blur,null),(n=this.inputFieldContainer)==null||n.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(e){var l,a;const t=(a=(l=e.select())==null?void 0:l.select("p"))==null?void 0:a.node();if(!t)return[0,0];const n=t.getBoundingClientRect();return[n.width/this.zoomTransform.k,n.height/this.zoomTransform.k]}startMovingNode(e,t){if(this.canUserPerformAction(k.MoveNode)&&!t.removed)if(x(E.Grabbing),this.draggingFrom=[e.x,e.y],t.selected&&this.userSelection.count(n=>n instanceof L)>1)this.currentAction=new et(this,this.userSelection.filter(n=>n instanceof L).map(n=>n.id),t.coords);else{const n=t.getLastAncestor();this.currentAction=new F(this,k.MoveNode,t.id,t.getGeometry(),t.getGeometry(),n==null?void 0:n.id,n==null?void 0:n.getGeometry(t.id),n==null?void 0:n.getGeometry(t.id))}else x(E.NotAllowed)}continueMovingNode(e,t){if(this.canUserPerformAction(k.MoveNode)&&(this.currentAction instanceof et||this.currentAction instanceof F)&&!t.removed){const n=[e.x-t.width/2,e.y-t.height/2];t.selected?this.userSelection.move([n[0]-t.coords[0],n[1]-t.coords[1]]):t.move(n),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(e,t){var n,l,a;if(this.canUserPerformAction(k.MoveNode)&&!t.removed&&(this.draggingFrom[0]!==e.x||this.draggingFrom[1]!==e.y)){let i=[e.x-t.width/2,e.y-t.height/2];if(this.snapToGrid&&(i=this.getClosestGridPoint(i)),this.currentAction instanceof et){const o=this.currentAction.delta;this.currentAction.delta=[i[0]-o[0],i[1]-o[1]],t.selected?this.userSelection.move([o[0]-t.coords[0],o[1]-t.coords[1]]):t.move(o)}else if(this.currentAction instanceof F){t.move(i);const r=this.model.nodes.getAtCoordinates(e.x,e.y).filter(c=>c.id!==t.id&&!c.isDescendantOf(t)).filter(c=>c.type.childrenTypes.includes(t.type.id)),d=ri(r),u=d[d.length-1];if(u!==t.parent&&(t.type.canBeParentless||u!==void 0)){const c=u==null?void 0:u.getLastAncestor(),g=this.currentAction.from,y=new Ji(this,t.id,(n=t.parent)==null?void 0:n.id,u==null?void 0:u.id,g,t.getGeometry(),c==null?void 0:c.id,c==null?void 0:c.getGeometry(t.id),c==null?void 0:c.getGeometry(t.id));(l=t.parent)==null||l.removeChild(t),u!==void 0&&u.addChild(t),y.toChildGeometry=t.getGeometry(t.id),y.toAncestorGeometry=c==null?void 0:c.getGeometry(t.id),this.currentAction=y}else{const c=t==null?void 0:t.getLastAncestor();this.currentAction.ancestorId=c==null?void 0:c.id,this.currentAction.fromAncestorGeometry=c==null?void 0:c.getGeometry(t.id),(a=t.parent)==null||a.fitToChild(t),this.currentAction.to=t.getGeometry(t.id),this.currentAction.toAncestorGeometry=c==null?void 0:c.getGeometry(t.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}x(),this.dragging=!1}startMultipleSelection(e){this.draggingFrom=this.getPointerLocationRelativeToCanvas(e),this.multipleSelectionContainer=this.selectCanvasElements().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(e){var n,l,a,i;const t=this.getPointerLocationRelativeToCanvas(e);(this.draggingFrom[0]!==t[0]||this.draggingFrom[1]!==t[1])&&(x(E.Crosshair),(i=(a=(l=(n=this.multipleSelectionContainer)==null?void 0:n.attr("x",Math.min(this.draggingFrom[0],t[0])))==null?void 0:l.attr("y",Math.min(this.draggingFrom[1],t[1])))==null?void 0:a.attr("width",Math.abs(this.draggingFrom[0]-t[0])))==null||i.attr("height",Math.abs(this.draggingFrom[1]-t[1])),this.dragging=!0)}finishMultipleSelection(e){var n;const t=this.getPointerLocationRelativeToCanvas(e);(n=this.multipleSelectionContainer)==null||n.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const l of this.model.nodes)yi([l.coords,[l.coords[0]+l.width,l.coords[1]+l.height]],[this.draggingFrom,t])&&this.userSelection.add(l);this.multipleSelectionOn=!1,this.diagramEvent$.next(new D(this.userSelection.all(),!0)),x()}};De.canvasCount=0;let at=De;const he=s=>!!s.button,ot=(s,e,t,n,l,a,i,o)=>vi(s,[e,t],n,l,Math.max(10,i||0,o||0)*a),x=s=>{s?$.select("body").style("cursor",s):$.select("body").style("cursor",E.Auto)},me=s=>s instanceof L?s:s instanceof G?s.node||s:s.rootElement instanceof L||s.rootElement instanceof G||s.rootElement instanceof ue?me(s.rootElement):s;class ci{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const e of this.grid)e.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const e of this.grid)e.push(void 0)}addRowTop(){const e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.splice(0,0,e),this.offsetY=this.offsetY+1}addRowBottom(){const e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.push(e)}get(e){if(this.grid[e[1]+this.offsetY])return this.grid[e[1]+this.offsetY][e[0]+this.offsetX]}set(e,t){for(;e[0]<-this.offsetX;)this.addColumnLeft();for(;e[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;e[1]<-this.offsetY;)this.addRowTop();for(;e[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[e[1]+this.offsetY][e[0]+this.offsetX]=t}getClosestEmptyCoordinate(e){if(this.get(e)===void 0)return e;const t=[...e];for(let n=1;;++n){const l=n%2>0?n:-n,a=l>0?1:-1,i=[t[0]+l,t[1]+l];for(let o=t[0];o!==i[0]+a;o+=a)if(t[0]=o,this.get(t)===void 0)return t;for(let o=t[1];o!==i[1]+a;o+=a)if(t[1]=o,this.get(t)===void 0)return t}}}class yo{apply(e){var o;if(e.nodes.length===0)return e;const t=new ci,n=e.nodes.filter(r=>!r.parent);for(;n.length>0;)hi(n[0],t,[0,0],n);const l=Math.max(...e.nodes.map(r=>r.width)),a=Math.max(...e.nodes.map(r=>r.height)),i=(((o=e.canvas)==null?void 0:o.gridSize)||0)*2;for(let r=t.minY();r<=t.maxY();++r)for(let d=t.minX();d<=t.maxX();++d){const u=t.get([d,r]);u!==void 0&&u.move([d*(l+i),r*(a+i)])}return e}}const hi=(s,e,t,n)=>{const l=e.getClosestEmptyCoordinate(t);e.set(l,s),B(n,s);for(const a of s.getAdjacentNodes())n.includes(a)&&hi(a,e,l,n)};class bo{apply(e){var u;if(e.nodes.length===0)return e;const t=new ci,n=e.nodes.filter(c=>!c.parent),l={},a=n[0];let i=[a];for(l[a.id]=[0,0];n.length>0;){const c=[];for(const g of i){t.set(t.getClosestEmptyCoordinate(l[g.id]),g),B(n,g);const y=g.getAdjacentNodes();for(const f of y)n.includes(f)&&(c.push(f),l[f.id]=l[g.id])}if(c.length>0)i=c;else if(n.length>0){const g=n[0];i=[g],l[g.id]=t.getClosestEmptyCoordinate([0,0])}}const o=Math.max(...e.nodes.map(c=>c.width)),r=Math.max(...e.nodes.map(c=>c.height)),d=(((u=e.canvas)==null?void 0:u.gridSize)||0)*2;for(let c=t.minY();c<=t.maxY();++c)for(let g=t.minX();g<=t.maxX();++g){const y=t.get([g,c]);y!==void 0&&y.move([g*(o+d),c*(r+d)])}return e}}class He{apply(e){var o;if(e.nodes.length===0)return e;const t=(((o=e.canvas)==null?void 0:o.gridSize)||0)*2;let n=e.nodes.filter(r=>!r.parent);const l=n[0];B(n,l);const a=[[l]];for(;n.length>0;){const r=a[a.length-1],d=[];for(const u of r){const c=u.getAdjacentNodes();for(const g of c)n.includes(g)&&(B(n,g),d.push(g))}d.length>0?a.push(d):(a.push(n),n=[])}let i=0;for(const r of a){let d=0;for(const c of r)c.move([i,d]),d+=t+c.height;const u=Math.max(...r.map(c=>c.width));i+=t+u}for(const r of e.connections)r.tighten();return e}}class vo{apply(e){var c;if(e.nodes.length===0)return e;new He().apply(e);const t=(((c=e.canvas)==null?void 0:c.gridSize)||0)*2,n=.99,l=1,a=.1,i=2e5,o=.5,r=1,d=.002;let u=100;for(;u>l;){u=u*n;const g=[0,0];{for(const y of e.nodes)g[0]=g[0]+y.coords[0]+y.width/2,g[1]=g[1]+y.coords[1]+y.width/2;g[0]=g[0]/e.nodes.length,g[1]=g[1]/e.nodes.length}for(const y of e.nodes){const f=y.getAdjacentNodes();for(const h of e.nodes){const m=[y.coords[0]+y.width/2,y.coords[1]+y.height/2],b=[h.coords[0]+h.width/2,h.coords[1]+h.height/2],v=Qt(y.coords,h.coords),C=[h.coords[0],h.coords[1]];if(f.includes(h)&&v>0&&(v>t+(Math.max(y.width,y.height)+Math.max(h.width,h.height))/2?(C[0]=C[0]-(b[0]-m[0])*a,C[1]=C[1]-(b[1]-m[1])*a):(C[0]=C[0]+(b[0]-m[0])*o,C[1]=C[1]+(b[1]-m[1])*o)),v>0){const S=i/(v*v);C[0]=C[0]+S*(b[0]-m[0])/v,C[1]=C[1]+S*(b[1]-m[1])/v}else C[0]=C[0]+r*(Math.random()*2-1),C[1]=C[1]+r*(Math.random()*2-1);C[0]=C[0]-(b[0]-g[0])*d,C[1]=C[1]-(b[1]-g[1])*d,C[0]-h.coords[0]>u?C[0]=h.coords[0]+u:C[0]-h.coords[0]<-u&&(C[0]=h.coords[0]-u),C[1]-h.coords[1]>u?C[1]=h.coords[1]+u:C[1]-h.coords[1]<-u&&(C[1]=h.coords[1]-u),h.move(C)}}}if(e.canvas&&e.canvas.snapToGrid)for(const g of e.nodes){const y=e.canvas.getClosestGridPoint(g.coords);g.move(y)}for(const g of e.connections)g.tighten();return e}}class Co{apply(e){var a;if(e.nodes.length===0)return e;const t=(((a=e.canvas)==null?void 0:a.gridSize)||0)*2,n=e.nodes.filter(i=>!i.parent);n.sort((i,o)=>o.type.priority-i.type.priority);let l=0;for(const i of n)i.move([l,0]),l+=i.width+t;return e}}class wo{apply(e){var u;if(e.nodes.length===0)return e;const t=Math.max(...e.nodes.map(c=>c.getPriority())),n=Math.min(...e.nodes.map(c=>c.getPriority()));if(t===n)return new He().apply(e),e;const l=(((u=e.canvas)==null?void 0:u.gridSize)||0)*2,a=e.nodes.filter(c=>!c.parent),i=[],o=e.nodes.filter(c=>!c.parent).filter(c=>c.getPriority()>=t),r=[];if(o.length>1){const c=o[0];o.splice(0,1),r.push(c);const g=[c],y=[c];for(;g.length>0;){const f=g[0];g.splice(0,1),o.includes(f)&&(r.push(f),B(o,f));const h=f.getAdjacentNodes();for(const m of h)y.includes(m)||(g.push(m),y.push(m))}for(const f of o)r.push(f)}else r.push(o[0]);for(const c of r)B(a,c),i.push([c]);for(i.push([]),a.sort((c,g)=>g.type.priority-c.type.priority);a.length>0;){const c=a[0];a.splice(0,1);const g=[c],y=[c];let f=!1;for(;g.length>0;){const h=g[0];g.splice(0,1);const m=r.indexOf(h);if(m>=0){i[m].push(c),f=!0;break}else{const b=h.getAdjacentNodes();for(const v of b)y.includes(v)||(g.push(v),y.push(v))}}f||i[i.length-1].push(c)}let d=0;for(let c=0;c<i.length;++c){let g=0;for(let f=0;f<i[c].length;++f){const h=i[c][f];h.move([d,g]),g+=l+h.height}const y=Math.max(...i[c].map(f=>f.width));d+=l+y}for(const c of e.connections)c.tighten();return e}}class ko{apply(e){var u;if(e.nodes.length===0)return e;const t=Math.max(...e.nodes.map(c=>c.getPriority())),n=Math.min(...e.nodes.map(c=>c.getPriority()));if(t===n)return new He().apply(e),e;const l=(((u=e.canvas)==null?void 0:u.gridSize)||0)*2,a=e.nodes.filter(c=>!c.parent).sort((c,g)=>g.getPriority()-c.getPriority()),i=[];for(;a.length>0;){const c=a[0];a.splice(0,1);const g=new ct(void 0,c);ui(g,a),i.push(g)}const o=[];for(const c of i)o.push([c]),fi(c,o,o.length);const r=Math.max(...e.nodes.map(c=>c.height));let d=0;for(let c=0;c<o.length;++c){let g=0;for(let f=0;f<o[c].length;++f){const h=o[c][f];h.node.move([d,g]),g+=(l+r)*h.countBranchHeight()}const y=Math.max(...o[c].map(f=>f.node.width));d+=l+y}for(const c of e.connections)c.tighten();return e}}const ui=(s,e)=>{for(const t of s.node.getAdjacentNodes().sort((n,l)=>l.getPriority()-n.getPriority())){const n=e.indexOf(t);if(n>=0){e.splice(n,1);const l=s.addBranch(t);ui(l,e)}}},fi=(s,e,t)=>{if(s.branches.length>0){for(;t>=e.length;)e.push([]);for(const n of s.branches)e[t].push(n),fi(n,e,t+1)}};class ct{constructor(e,t){this.parent=e,this.branches=[],this.depth=0,this.node=t}addBranch(e){const t=new ct(this,e);return t.depth=this.depth+1,this.branches.push(t),t}countBranchHeight(){if(this.branches.length<=0)return 1;{let e=0;for(const t of this.branches)e+=t.countBranchHeight();return e}}}class xo{apply(e){var a;if(e.nodes.length===0)return e;const t=(((a=e.canvas)==null?void 0:a.gridSize)||0)*2,n=e.nodes.filter(i=>!i.parent);n.sort((i,o)=>o.type.priority-i.type.priority);let l=0;for(const i of n)i.move([0,l]),l+=i.height+t;return e}}const Jt={adjacency:new yo,breadth:new He,"breadth-adjacency":new bo,force:new vo,horizontal:new Co,priority:new wo,tree:new ko,vertical:new xo},So=R.createContext({}),pe=R.createContext({});class Io{constructor(e,t){this.onTitleChange=e,this.onValueSetChange=t}get title(){return this._title}set title(e){this._title=e,this.onTitleChange(e)}get valueSet(){return this._valueSet}set valueSet(e){this._valueSet=e,this.onValueSetChange(e)}highlightProperty(...e){console.log("highlightProperty",e)}}const ht=({direction:s,collapsableSelector:e,collapsableAdditionalSelector:t,collapsed:n,disabled:l,rule:a,collapsedValue:i,visibleValue:o,onCollapse:r})=>{const[d,u]=R.useState(n),c=()=>{if(!l){const y=!d;u(y),r==null||r(y);let f;if(typeof e=="string")f=$.select(e),t&&(f=f.select(t));else{const h=e;if(!h)throw new Error("collapsableSelector is not a valid ref");f=$.select(h.current),t&&(f=f.select(t))}f.style(a,y?i:o)}},g=()=>{switch(s){case p.Right:return l?"daga-horizontal-none":d?"daga-horizontal-right":"daga-horizontal-left";case p.Bottom:return l?"daga-vertical-none":d?"daga-vertical-down":"daga-vertical-up";case p.Left:return l?"daga-horizontal-none":d?"daga-horizontal-left":"daga-horizontal-right";case p.Top:return l?"daga-vertical-none":d?"daga-vertical-up":"daga-vertical-down"}};return w.jsx("daga-collapse-button",{children:w.jsx("button",{className:`daga-collapse-button daga-${s}`,onClick:c,children:w.jsx("div",{className:g()})})})},Ao=()=>{const s=R.useContext(pe),e=R.useRef(null),[t,n]=R.useState([]);se.merge(s.validatorChange$,s.diagramChange$).pipe(se.delay(1),se.map(()=>l())).subscribe();const l=()=>{n([]);for(const i of s.validators){const o=i.validate(s.model);n(o)}},a=i=>{var o,r,d,u;if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const c=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);c&&s.userHighlight.add(c)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){s.userSelection.openInPropertyEditor(s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId));const c=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);c&&s.userHighlight.add(c),(r=(o=s.parentComponent)==null?void 0:o.propertyEditor)==null||r.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(s.userSelection.openInPropertyEditor(),(u=(d=s.parentComponent)==null?void 0:d.propertyEditor)==null||u.highlightProperty(...i.propertyNames))};return w.jsx("daga-errors",{children:w.jsxs("div",{ref:e,className:"daga-errors",children:[t.length===0&&w.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:w.jsx("span",{children:"No errors found"})}),t.length>0&&w.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[w.jsxs("span",{children:[t.length," errors found"]}),w.jsx("div",{className:"daga-collapse-button-container",children:w.jsx(ht,{collapsableSelector:e,collapsableAdditionalSelector:".daga-error-panel",direction:p.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),t.length>0&&w.jsx("div",{className:"daga-error-panel",children:w.jsx("ol",{children:t.map((i,o)=>w.jsx("li",{onClick:()=>a(i),dangerouslySetInnerHTML:{__html:i.message}},o))})})]})})},To=({valueSet:s,onValueChange:e})=>{var i;const[t]=R.useState((s==null?void 0:s.displayedProperties)||[]),l=R.useContext(pe).canUserPerformAction(k.UpdateValues)&&((i=s==null?void 0:s.rootElement)==null?void 0:i.removed)!==!0,a=o=>"daga-property-name-"+o.replace(/\s/g,"");return w.jsx("daga-object-editor",{children:t.map(o=>w.jsxs("div",{className:`daga-property ${a(o.name)}`,children:[w.jsx("p",{className:"daga-property-name",children:o.name}),o.type===Se.Text&&w.jsx("input",{type:"daga-text",disabled:!o.editable||!l,value:s==null?void 0:s.getValue(o.name),onChange:r=>e(o,r.target.value)}),o.type===Se.TextArea&&w.jsx("textarea",{disabled:!o.editable||!l,value:s==null?void 0:s.getValue(o.name),onChange:r=>e(o,r.target.value)})]},o.name))})},gi=({valueSet:s,depth:e})=>{const t=R.useContext(pe),n=R.useRef(null),l=d=>"daga-property-name-"+d.replace(/\s/g,""),a=()=>{for(const d of(s==null?void 0:s.displayedProperties)||[]){let u=0,c=0,g=0;const y=$.select(n.current).select(`.daga-property.${l(d.name)}.daga-depth-${e}`);y.select("button.daga-move-button").call($.drag().on(T.Start,f=>{var b;x(E.Grabbing);const h=t.getPointerLocationRelativeToScreen(f);if(h.length<2||isNaN(h[0])||isNaN(h[1]))return;const m=(b=y.node())==null?void 0:b.getBoundingClientRect();u=(m==null?void 0:m.width)||0,c=(m==null?void 0:m.height)||0,y.style("position","fixed").style("left",`${h[0]-u/2}px`).style("top",`${h[1]-c/2}px`).style("width",`${u}px`).style("height",`${c}px`).style("z-index",1)}).on(T.Drag,f=>{x(E.Grabbing);const h=t.getPointerLocationRelativeToScreen(f);h.length<2||isNaN(h[0])||isNaN(h[1])||(y.style("position","fixed").style("left",`${h[0]-u/2}px`).style("top",`${h[1]-c/2}px`).style("width",`${u}px`).style("height",`${c}px`).style("z-index",1),$.select(n.current).select(`.daga-dropbar.daga-index-${g}.daga-depth-${e}`).style("visibility","hidden").style("height",0),g=i(h),$.select(n.current).select(`.daga-dropbar.daga-index-${g}.daga-depth-${e}`).style("visibility","visible").style("height","0.25rem"))}).on(T.End,f=>{var m,b;x(E.Auto),y.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),$.select(n.current).select(`.daga-dropbar.daga-index-${g}.daga-depth-${e}`).style("visibility","hidden").style("height",0);const h=t.getPointerLocationRelativeToScreen(f);h.length<2||isNaN(h[0])||isNaN(h[1])||(g=i(h),(m=s==null?void 0:s.displayedProperties)==null||m.splice(s.displayedProperties.indexOf(d),1),(b=s==null?void 0:s.displayedProperties)==null||b.splice(g,0,d))}))}},i=d=>{var g;const u=(s==null?void 0:s.propertySet.propertyList)||[],c=[];for(let y=0;y<=u.length;++y){const f=(g=$.select(n.current).select(`.daga-dropbar.daga-index-${y}.daga-depth-${e}`).node())==null?void 0:g.getBoundingClientRect();f&&c.push([f.x+f.width/2,f.y+f.height/2])}if(c.length>0){const y=c.map(h=>((d[0]-h[0])**2+(d[1]-h[1])**2)**.5);return y.indexOf(Math.min(...y))}return 0},o=d=>{var c;if(s===void 0)return;let u;d instanceof Ri?u=d:d instanceof Event?u=s==null?void 0:s.propertySet.getProperty(((c=d.target)==null?void 0:c.value)||""):u=s==null?void 0:s.propertySet.getProperty(d||""),u&&(s==null||s.hideProperty(u)),a()},r=d=>Array.isArray(d)?d.join(", "):nt(d)?Object.entries(d).map(u=>u.map(c=>JSON.stringify(c)).join(": ")).join(", "):d instanceof Date?d.toLocaleString():d==null?"":""+d;return w.jsxs("daga-property-settings",{ref:n,children:[w.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${e}`}),s==null?void 0:s.displayedProperties.map((d,u)=>w.jsxs("div",{className:`daga-property-and-dropbar ${l(d.name)} daga-depth-${e}`,children:[w.jsxs("div",{className:`daga-property ${l(d.name)} daga-depth-${e}`,children:[w.jsxs("div",{className:"daga-property-name",children:[w.jsx("span",{children:d.name}),w.jsxs("div",{className:"daga-buttons",children:[w.jsx("button",{className:"daga-property-button daga-move-button",children:w.jsx("div",{className:"daga-icon daga-move-icon"})}),w.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>o(d.name),children:w.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),d.type!==Se.Object&&w.jsx("div",{className:"daga-property-value",children:r(s==null?void 0:s.getValue(d.name))}),d.type===Se.Object&&w.jsx(gi,{valueSet:s==null?void 0:s.getSubValueSet(d.name),depth:e+1})]}),w.jsx("div",{className:`daga-dropbar daga-index-${u+1} daga-depth-${e}`})]},d.name))]})},$o=({location:s,direction:e,width:t,title:n,valueSet:l,onValueChange:a})=>{const i=R.useRef(null),[o,r]=R.useState(!1),[d,u]=R.useState(!1),c=()=>$.select(i.current);return R.useEffect(()=>{if(i.current)switch(e){case p.Bottom:case p.Top:c().style("width",t);break;case p.Left:case p.Right:c().style("height",t);break}},[t,e]),w.jsx("daga-property-editor",{children:w.jsxs("div",{ref:i,className:`daga-panel daga-bottom daga-${s} daga-${e}`,children:[w.jsx(ht,{disabled:!l||!l.propertySet||!l.propertySet.hasProperties(),collapsed:o,direction:e,collapsableSelector:i,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:r}),l&&l.propertySet&&l.propertySet.hasProperties()&&!o&&w.jsxs("div",{className:"daga-panel-content",children:[n&&w.jsxs("p",{className:"daga-title",children:[n,w.jsx("button",{className:"daga-property-button",onClick:()=>u(!d),children:w.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&w.jsx(To,{valueSet:l,onValueChange:a}),d&&w.jsx(gi,{valueSet:l,depth:0})]})]})})},Eo=s=>{const e=R.useContext(pe),[t,n]=R.useState(s.currentPalette||s.palettes[0]),[l,a]=R.useState(0),[i,o]=R.useState(void 0),r=R.useRef(null),d=h=>{if(n(h),u().selectAll("*").remove(),a(e.getPriorityThreshold()||0),h.categories&&c(h.categories),h.templates)for(const m of h.templates)g(m)},u=()=>$.select(r.current).select(".daga-palette-view"),c=h=>{const m=u().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");m.append("option").attr("value","").text("(None selected)");for(const b in h)m.append("option").attr("value",b).text(b);m.on(I.Change,()=>{i&&u().selectAll(".daga-template-container.daga-in-category").remove();const b=m.property("value");o(b);const v=h[b]||[];for(const C of v)g(C,"daga-in-category")}),i&&(m.property("value",i),m.dispatch(I.Change))},g=(h,m)=>{if(h.templateType==="node"){const b=e.model.nodes.types.get(h.type);b?y(b,h,m):console.error(`Could not find a node type called '${h.type}'`)}else if(h.templateType==="connection"){const b=e.model.connections.types.get(h.type);b?f(b,h,m):console.error(`Could not find a connection type called '${h.type}'`)}},y=(h,m,b)=>{if(l!==void 0&&h.priority<l)return;const v=u().append("div").attr("class",`daga-template-container ${b!==void 0?b:""}`).style("width",`${h.defaultWidth}px`).style("height",`${h.defaultHeight}px`).call($.drag().on(T.Drag,C=>{if(e.canUserPerformAction(k.AddNode)){const S=e.getPointerLocationRelativeToScreen(C);if(S.length<2||isNaN(S[0])||isNaN(S[1]))return;v.style("position","fixed").style("left",`${S[0]-h.defaultWidth/2}px`).style("top",`${S[1]-h.defaultHeight/2}px`).style("z-index",1)}}).on(T.Start,C=>{if(e.canUserPerformAction(k.AddNode)){x(E.Grabbing);const S=e.getPointerLocationRelativeToScreen(C);if(S.length<2||isNaN(S[0])||isNaN(S[1]))return;v.style("position","fixed").style("left",`${S[0]-h.defaultWidth/2}px`).style("top",`${S[1]-h.defaultHeight/2}px`).style("z-index",1),h.isUnique&&e.model.nodes.find(A=>!A.removed&&A.type.id===h.id)!==void 0&&x(E.NotAllowed)}}).on(T.End,C=>{var S;if(e.canUserPerformAction(k.AddNode)){if(x(E.Auto),v.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),h.isUnique&&e.model.nodes.find(_=>!_.removed&&_.type.id===h.id)!==void 0)return;const A=e.getPointerLocationRelativeToScreen(C);if(A.length<2||isNaN(A[0])||isNaN(A[1]))return;const M=document.elementFromPoint(A[0],A[1]);if(M&&!((S=e.selectCanvasView().node())!=null&&S.contains(M)))return;const N=e.getPointerLocationRelativeToCanvas(C);if(N.length<2||isNaN(N[0])||isNaN(N[1]))return;let P=[N[0]-h.defaultWidth/2,N[1]-h.defaultHeight/2];e.snapToGrid&&(P=e.getClosestGridPoint(P));const W=e.model.nodes.getAtCoordinates(N[0],N[1]).filter(_=>_.type.childrenTypes.includes(h.id)),fe=ri(W),Z=fe[fe.length-1];if(!h.canBeParentless&&Z===void 0)return;const q=Z==null?void 0:Z.getLastAncestor(),ge=new qi(e,h,P,Z==null?void 0:Z.id,q==null?void 0:q.id,q==null?void 0:q.getGeometry(),void 0,m.label,m.values);ge.do(),e==null||e.actionStack.add(ge),x()}})).append("svg").attr("class",`palette-node ${h.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%");switch(h.look.lookType){case"shaped-look":v.append("path").attr("d",Ve(h.look.shape,0,0,h.defaultWidth,h.defaultHeight)).attr("fill",h.look.fillColor).attr("stroke",h.look.borderColor).attr("stroke-width","1px");break;case"image-look":v.append("image").attr("x",0).attr("y",0).attr("width",h.defaultWidth).attr("height",h.defaultHeight).attr("href",h.look.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":v.append("image").attr("x",0).attr("y",0).attr("width",h.look.leftMargin).attr("height",h.look.topMargin).attr("href",h.look.backgroundImageTopLeft).attr("preserveAspectRatio","none"),v.append("image").attr("x",h.look.leftMargin).attr("y",0).attr("width",h.defaultWidth-h.look.rightMargin-h.look.leftMargin).attr("height",h.look.topMargin).attr("href",h.look.backgroundImageTop).attr("preserveAspectRatio","none"),v.append("image").attr("x",h.defaultWidth-h.look.rightMargin).attr("y",0).attr("width",h.look.rightMargin).attr("height",h.look.topMargin).attr("href",h.look.backgroundImageTopRight).attr("preserveAspectRatio","none"),v.append("image").attr("x",0).attr("y",h.look.topMargin).attr("width",h.look.leftMargin).attr("height",h.defaultHeight-h.look.bottomMargin-h.look.topMargin).attr("href",h.look.backgroundImageLeft).attr("preserveAspectRatio","none"),v.append("image").attr("x",h.look.leftMargin).attr("y",h.look.topMargin).attr("width",h.defaultWidth-h.look.rightMargin-h.look.leftMargin).attr("height",h.defaultHeight-h.look.bottomMargin-h.look.topMargin).attr("href",h.look.backgroundImageCenter).attr("preserveAspectRatio","none"),v.append("image").attr("x",h.defaultWidth-h.look.rightMargin).attr("y",h.look.topMargin).attr("width",h.look.rightMargin).attr("height",h.defaultHeight-h.look.bottomMargin-h.look.topMargin).attr("href",h.look.backgroundImageRight).attr("preserveAspectRatio","none"),v.append("image").attr("x",0).attr("y",h.defaultHeight-h.look.bottomMargin).attr("width",h.look.leftMargin).attr("height",h.look.bottomMargin).attr("href",h.look.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),v.append("image").attr("x",h.look.leftMargin).attr("y",h.defaultHeight-h.look.bottomMargin).attr("width",h.defaultWidth-h.look.rightMargin-h.look.leftMargin).attr("height",h.look.bottomMargin).attr("href",h.look.backgroundImageBottom).attr("preserveAspectRatio","none"),v.append("image").attr("x",h.defaultWidth-h.look.rightMargin).attr("y",h.defaultHeight-h.look.bottomMargin).attr("width",h.look.rightMargin).attr("height",h.look.bottomMargin).attr("href",h.look.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(m.label){const C={...z,...h.label,...m.labelLook};v.append("text").attr("transform",`translate(${(U(C)+h.defaultWidth)/2},${(H(C)+h.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${C.fontSize}px`).attr("text-anchor","middle").attr("font-family",C.fontFamily).attr("font-weight",400).attr("fill",C.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(m.label)}},f=(h,m,b)=>{const v=u().append("div").attr("class",`daga-template-container ${b!==void 0?b:""}`).style("width",`${m.width}px`).style("height",`${m.height}px`).append("svg").attr("class",`palette-button ${h.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{e.connectionType=h});v.append("path").attr("d",Ve(Be.Rectangle,0,0,m.width,m.height)).attr("fill",m.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),m.icon!==""&&v.append("image").attr("x",0).attr("y",0).attr("width",m.width).attr("height",m.height).attr("href",m.icon),m.label!==""&&v.append("text").attr("transform",`translate(${m.width/2},${m.height/2+5})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(m.label)};return R.useEffect(()=>{if(n(t||s.palettes[0]),d(t),r.current)switch(s.direction){case p.Bottom:case p.Top:r.current.style.width=s.width;break;case p.Left:case p.Right:r.current.style.height=s.width;break}},[t,s.palettes]),w.jsx("daga-palette",{children:w.jsxs("div",{ref:r,className:`daga-panel daga-${s.location} daga-${s.direction}`,children:[w.jsx(ht,{direction:s.direction,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),w.jsxs("div",{className:"daga-panel-content",children:[s.palettes.length>1&&w.jsx("div",{className:"daga-panel-tabs",children:s.palettes.map(h=>w.jsx("div",{className:`daga-panel-tab ${h===t?"daga-current-tab":""}`,onClick:()=>d(h),children:h.name}))}),w.jsx("div",{className:"daga-palette-view"})]})]})})},Mo=({location:s,direction:e,enableAction:t,enableFilter:n,enableLayout:l,enableSelection:a,enableZoom:i})=>{let o=!1,r=!0,d=!1,u,c,g,y;switch(e){case p.Bottom:u="height",c="scaleY",g="top",y="bottom";break;case p.Top:u="height",c="scaleY",g="bottom",y="top";break;case p.Left:u="width",c="scaleX",g="right",y="left";break;case p.Right:u="width",c="scaleX",g="left",y="right";break}const f=R.useRef(null),h=R.useRef(null),m=R.useRef(null);R.useEffect(()=>{$.select(f.current).style(`margin-${y}`,"-1rem").style(u,"0rem").style("transform",`${c}(0)`).style("transform-origin",g)});const b=async()=>{const _=$.select(f.current);if(!d)if(r){r=!1;const Ee=`${4*_.selectChildren().size()}rem`;_.transition().duration(500).ease($.easeLinear).style(u,Ee).style("transform",`${c}(1)`),setTimeout(()=>{d=!1},500)}else r=!0,_.transition().duration(500).ease($.easeLinear).style(u,"0rem").style("transform",`${c}(0)`),setTimeout(()=>{d=!1},500)},v=R.useContext(pe),C=()=>{v.zoomBy(v.zoomFactor)},S=()=>{v.zoomBy(1/v.zoomFactor)},A=()=>{v.center()},M=()=>{v.layoutFormat&&v.layoutFormat in Jt&&Jt[v.layoutFormat].apply(v.model)},N=()=>{o=!o,$.select(m.current).classed("daga-on",o).classed("daga-off",!o);const _=v.getPriorityThresholdOptions();_&&_.length>=2&&v.setPriorityThreshold(_[o?1:0])},P=()=>{v.actionStack.undo()},j=()=>{v.actionStack.redo()},W=()=>{v.userSelection.copyToClipboard()},fe=()=>{v.userSelection.cutToClipboard()},Z=()=>{v.userSelection.pasteFromClipboard()},q=()=>{v.userSelection.removeFromModel()},ge=()=>{v.multipleSelectionOn=!0,$.select(h.current).classed("daga-on",!0).classed("daga-off",!1)};return w.jsx("daga-diagram-buttons",{children:w.jsxs("div",{className:`daga-diagram-buttons daga-${s} daga-${e}`,children:[i&&v.canUserPerformAction(k.Zoom)&&w.jsx("button",{className:"daga-zoom-in",onClick:C,children:w.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&v.canUserPerformAction(k.Zoom)&&w.jsx("button",{className:"daga-zoom-out",onClick:S,children:w.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),w.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:f,children:[i&&v.canUserPerformAction(k.Zoom)&&w.jsx("button",{className:"daga-center",onClick:A,children:w.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),t&&w.jsx("button",{className:"daga-undo",onClick:P,children:w.jsx("span",{className:"daga-tooltip",children:"Undo"})}),t&&w.jsx("button",{className:"daga-redo",onClick:j,children:w.jsx("span",{className:"daga-tooltip",children:"Redo"})}),a&&w.jsx("button",{className:"daga-copy",onClick:W,children:w.jsx("span",{className:"daga-tooltip",children:"Copy"})}),a&&w.jsx("button",{className:"daga-cut",onClick:fe,children:w.jsx("span",{className:"daga-tooltip",children:"Cut"})}),a&&w.jsx("button",{className:`daga-multiple-selection ${o?"daga-on":"daga-off"}`,onClick:ge,ref:h,children:w.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),a&&w.jsx("button",{className:"daga-paste",onClick:Z,children:w.jsx("span",{className:"daga-tooltip",children:"Paste"})}),a&&w.jsx("button",{className:"daga-delete",onClick:q,children:w.jsx("span",{className:"daga-tooltip",children:"Delete"})}),l&&v.layoutFormat&&w.jsx("button",{className:"daga-layout",onClick:M,children:w.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),n&&w.jsx("button",{className:`daga-filter ${o?"daga-on":"daga-off"}`,onClick:N,ref:m,children:w.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),w.jsx("button",{className:"daga-more-options",onClick:b,children:r?w.jsx("span",{className:"daga-tooltip",children:"More options"}):w.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},No=({config:s,model:e,onCanvasCreated:t,onDiagramEvent:n,onModelChange:l})=>{var S,A,M,N,P,j,W,fe,Z,q,ge,_,_e,Ye,Ee,ut,ft,gt,mt,pt,yt,bt,vt,Ct,wt,kt,xt,St,It,At,Tt,$t,Et,Mt,Nt,Pt,Rt,zt,Lt,Vt,Dt,Bt,Ft,jt,Ot;const a=new ai,i=new di,o=R.useRef(null),r=R.useRef(!1),[d,u]=R.useState(void 0),[c,g]=R.useState(void 0),y={zoomIn:()=>{console.log("zoomIn")},zoomOut:()=>{console.log("zoomOut")},center:()=>{console.log("center")},layout:()=>{console.log("layout")},filter:()=>{console.log("filter")},undo:()=>{console.log("undo")},redo:()=>{console.log("redo")}},f={refreshPalette:()=>{console.log("refreshPalette")}},h=new Io(J=>u(J),J=>g(J)),m={diagramButtons:y,palette:f,propertyEditor:h},b=new at(m,s);R.useEffect(()=>{e&&a.import(b.model,e)},[e]),b.diagramChange$.subscribe(()=>{const J=i.export(b.model);l==null||l(J)});const v=J=>{b.initView(J),b.diagramEvent$.subscribe(Me=>{n==null||n(Me)})};R.useEffect(()=>{o.current&&(r.current||(v(o.current),r.current=!0,t==null||t(b)))},[o.current]);const C=(J,Me)=>{var Gt;if(c!==void 0&&J.editable&&!Ie(c.getValue(J.name),Me)){const Xe=new xe(c.propertySet,c.rootElement);Xe.setValues(c.values),Xe.setValue(J.name,Me),h.valueSet=Xe,(Gt=b.propertyEditorChanges$)==null||Gt.next()}};return w.jsx("daga-diagram",{children:w.jsx(So.Provider,{value:s,children:w.jsx(pe.Provider,{value:b,children:w.jsxs("daga-diagram-editor",{children:[w.jsx("div",{className:"daga-append-to",ref:o}),w.jsxs(pe.Provider,{value:b,children:[((S=s.components)==null?void 0:S.buttons)!==void 0&&((M=(A=s.components)==null?void 0:A.buttons)==null?void 0:M.enabled)!==!1&&w.jsx(Mo,{location:((P=(N=s.components)==null?void 0:N.buttons)==null?void 0:P.location)||Pe.BottomRight,direction:((W=(j=s.components)==null?void 0:j.buttons)==null?void 0:W.direction)||p.Top,enableAction:((Z=(fe=s.components)==null?void 0:fe.buttons)==null?void 0:Z.enableAction)===!0,enableFilter:((ge=(q=s.components)==null?void 0:q.buttons)==null?void 0:ge.enableFilter)===!0,enableLayout:((_e=(_=s.components)==null?void 0:_.buttons)==null?void 0:_e.enableLayout)===!0,enableSelection:((Ee=(Ye=s.components)==null?void 0:Ye.buttons)==null?void 0:Ee.enableSelection)===!0,enableZoom:((ft=(ut=s.components)==null?void 0:ut.buttons)==null?void 0:ft.enableZoom)!==!1}),((gt=s.components)==null?void 0:gt.palette)!==void 0&&((pt=(mt=s.components)==null?void 0:mt.palette)==null?void 0:pt.enabled)!==!1&&((bt=(yt=s.components)==null?void 0:yt.palette)==null?void 0:bt.sections)&&(((wt=(Ct=(vt=s.components)==null?void 0:vt.palette)==null?void 0:Ct.sections)==null?void 0:wt.length)||0)>0&&w.jsx(Eo,{location:((xt=(kt=s.components)==null?void 0:kt.palette)==null?void 0:xt.location)||Pe.TopLeft,direction:((It=(St=s.components)==null?void 0:St.palette)==null?void 0:It.direction)||p.Bottom,width:((Tt=(At=s.components)==null?void 0:At.palette)==null?void 0:Tt.width)||"12rem",palettes:((Et=($t=s.components)==null?void 0:$t.palette)==null?void 0:Et.sections)||[]}),((Mt=s.components)==null?void 0:Mt.propertyEditor)!==void 0&&((Pt=(Nt=s.components)==null?void 0:Nt.propertyEditor)==null?void 0:Pt.enabled)!==!1&&w.jsx($o,{location:((zt=(Rt=s.components)==null?void 0:Rt.propertyEditor)==null?void 0:zt.location)||Pe.TopRight,direction:((Vt=(Lt=s.components)==null?void 0:Lt.propertyEditor)==null?void 0:Vt.direction)||p.Bottom,width:((Bt=(Dt=s.components)==null?void 0:Dt.propertyEditor)==null?void 0:Bt.width)||"24rem",title:d,valueSet:c,onValueChange:C}),((Ft=s.components)==null?void 0:Ft.errors)!==void 0&&((Ot=(jt=s.components)==null?void 0:jt.errors)==null?void 0:Ot.enabled)!==!1&&w.jsx(Ao,{})]})]})})})})};exports.DagaDiagram=No;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react/jsx-runtime"),pi=require("d3"),yt=require("rxjs"),R=require("react");function yi(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const r=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const E=yi(pi);var y=(s=>(s.Bottom="bottom",s.Left="left",s.Right="right",s.Top="top",s))(y||{}),Ot=(s=>(s.BottomLeft="bottom-left",s.BottomRight="bottom-right",s.TopLeft="top-left",s.TopRight="top-right",s))(Ot||{}),xt=(s=>(s.Left="left",s.Center="center",s.Right="right",s))(xt||{}),Bt=(s=>(s.Top="top",s.Center="center",s.Bottom="bottom",s))(Bt||{});const Ct=s=>[Math.round(s[0]),Math.round(s[1])],ht=(s,t,e)=>t<e?t<=s&&s<=e:e<=s&&s<=t,Ge=(s,t,e)=>(s-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Ft=(s,t,e,r,a)=>[Ge(s[0],t,r),Ge(s[1],e,a)],Qe=(s,t)=>((s[0]-t[0])**2+(s[1]-t[1])**2)**.5,bi=(s,t)=>(ht(s[0][0],t[0][0],t[1][0])||ht(s[1][0],t[1][0],t[0][0])||ht(t[0][0],s[0][0],s[1][0])||ht(t[1][0],s[1][0],s[0][0]))&&(ht(s[0][1],t[0][1],t[1][1])||ht(s[1][1],t[1][1],t[0][1])||ht(t[0][1],s[0][1],s[1][1])||ht(t[1][1],s[1][1],s[0][1]));var S=(s=>(s.Blur="blur",s.Change="change",s.Click="click",s.ContextMenu="contextmenu",s.DoubleClick="dblclick",s.Focus="focus",s.FocusIn="focusin",s.FocusOut="focusout",s.Input="input",s.KeyDown="keydown",s.KeyUp="keyup",s.MouseDown="mousedown",s.MouseEnter="mouseenter",s.MouseLeave="mouseleave",s.MouseMove="mousemove",s.MouseOut="mouseout",s.MouseOver="mouseover",s.MouseUp="mouseup",s.TouchStart="touchstart",s.TouchEnd="touchend",s.Wheel="wheel",s))(S||{}),at=(s=>(s.Alt="Alt",s.AltGraph="AltGraph",s.ArrowDown="ArrowDown",s.ArrowLeft="ArrowLeft",s.ArrowRight="ArrowRight",s.ArrowUp="ArrowUp",s.Backspace="Backspace",s.Control="Control",s.Delete="Delete",s.End="End",s.Enter="Enter",s.Escape="Escape",s.Home="Home",s.OS="OS",s.PageDown="PageDown",s.PageUp="PageUp",s.Shift="Shift",s.Tab="Tab",s))(at||{}),A=(s=>(s.Drag="drag",s.Start="start",s.End="end",s))(A||{}),se=(s=>(s.Zoom="zoom",s.Start="start",s.End="end",s))(se||{}),ti=(s=>(s.Straight="straight",s.Bezier="bezier",s.Square="square",s))(ti||{}),ei=(s=>(s.Solid="solid",s.Dashed="dashed",s.GappedDashes="gapped-dashes",s.Dotted="dotted",s))(ei||{});const vi=20,wi=(s,t,e,r,a)=>{if(typeof s=="function")return s(t,e,r,a);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{a=a||vi;let l="",i,o;switch(s){case"straight":l+=`M ${t[0][0]} ${t[0][1]}`;for(let n=1;n<t.length;++n)l+=` L ${t[n][0]} ${t[n][1]}`;break;case"bezier":i=e,l+=`M ${t[0][0]} ${t[0][1]}`;for(let n=1;n<t.length;++n){if(n+1>=t.length?o=r:Math.abs(t[n][0]-t[n-1][0])<Math.abs(t[n][1]-t[n-1][1])?t[n][1]>t[n-1][1]?o=y.Bottom:o=y.Top:t[n][0]>t[n-1][0]?o=y.Right:o=y.Left,i!==void 0){let d="",g="";const h=(Math.abs(t[n][0]-t[n-1][0])+Math.abs(t[n][1]-t[n-1][1]))/2;switch(i){case y.Bottom:d=`${t[n-1][0]} ${t[n-1][1]+h}`;break;case y.Top:d=`${t[n-1][0]} ${t[n-1][1]-h}`;break;case y.Right:d=`${t[n-1][0]+h} ${t[n-1][1]}`;break;case y.Left:d=`${t[n-1][0]-h} ${t[n-1][1]}`;break}if(o!==void 0){switch(o){case y.Bottom:g=`${t[n][0]} ${t[n][1]+h}`;break;case y.Top:g=`${t[n][0]} ${t[n][1]-h}`;break;case y.Right:g=`${t[n][0]+h} ${t[n][1]}`;break;case y.Left:g=`${t[n][0]-h} ${t[n][1]}`;break}l+=` C ${d} ${g} ${t[n][0]} ${t[n][1]}`}else l+=` Q ${d} ${t[n][0]} ${t[n][1]}`}else if(o!==void 0){let d="";const g=(Math.abs(t[n][0]-t[n-1][0])+Math.abs(t[n][1]-t[n-1][1]))/2;switch(o){case y.Bottom:d=`${t[n][0]} ${t[n][1]+g}`;break;case y.Top:d=`${t[n][0]} ${t[n][1]-g}`;break;case y.Right:d=`${t[n][0]+g} ${t[n][1]}`;break;case y.Left:d=`${t[n][0]-g} ${t[n][1]}`;break}l+=` Q ${d} ${t[n][0]} ${t[n][1]}`}else l+=` L ${t[n][0]} ${t[n][1]}`;i=o}break;case"square":if(l+=`M ${t[0][0]} ${t[0][1]}`,e)switch(e){case y.Bottom:t.splice(1,0,[t[0][0],t[0][1]+a]);break;case y.Top:t.splice(1,0,[t[0][0],t[0][1]-a]);break;case y.Right:t.splice(1,0,[t[0][0]+a,t[0][1]]);break;case y.Left:t.splice(1,0,[t[0][0]-a,t[0][1]]);break}if(r)switch(r){case y.Bottom:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]+a]);break;case y.Top:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]-a]);break;case y.Right:t.splice(t.length-1,0,[t[t.length-1][0]+a,t[t.length-1][1]]);break;case y.Left:t.splice(t.length-1,0,[t[t.length-1][0]-a,t[t.length-1][1]]);break}for(let n=1;n<t.length;++n)if(i!==void 0)switch(i){case y.Bottom:t[n][1]<t[n-1][1]&&t[n][0]!==t[n-1][0]?(l+=` H ${t[n][0]}`,l+=` V ${t[n][1]}`,i=y.Top):t[n][1]<t[n-1][1]&&t[n][0]===t[n-1][0]?(l+=` H ${t[n][0]+a}`,l+=` V ${t[n][1]}`,l+=` H ${t[n][0]}`,i=y.Left):t[n][1]===t[n-1][1]&&t[n][0]!==t[n-1][0]?(l+=` H ${t[n][0]}`,i=t[n][0]>t[n-1][0]?y.Right:y.Left):t[n][1]>t[n-1][1]&&t[n][0]!==t[n-1][0]?(l+=` H ${t[n][0]}`,l+=` V ${t[n][1]}`):t[n][1]>t[n-1][1]&&t[n][0]===t[n-1][0]&&(l+=` V ${t[n][1]}`);break;case y.Top:t[n][1]>t[n-1][1]&&t[n][0]!==t[n-1][0]?(l+=` H ${t[n][0]}`,l+=` V ${t[n][1]}`,i=y.Bottom):t[n][1]>t[n-1][1]&&t[n][0]===t[n-1][0]?(l+=` H ${t[n][0]-a}`,l+=` V ${t[n][1]}`,l+=` H ${t[n][0]}`,i=y.Right):t[n][1]===t[n-1][1]&&t[n][0]!==t[n-1][0]?(l+=` H ${t[n][0]}`,i=t[n][0]>t[n-1][0]?y.Right:y.Left):t[n][1]<t[n-1][1]&&t[n][0]!==t[n-1][0]?(l+=` H ${t[n][0]}`,l+=` V ${t[n][1]}`):t[n][1]<t[n-1][1]&&t[n][0]===t[n-1][0]&&(l+=` V ${t[n][1]}`);break;case y.Right:t[n][0]<t[n-1][0]&&t[n][1]!==t[n-1][1]?(l+=` V ${t[n][1]}`,l+=` H ${t[n][0]}`,i=y.Left):t[n][0]<t[n-1][0]&&t[n][1]===t[n-1][1]?(l+=` V ${t[n][1]+a}`,l+=` H ${t[n][0]}`,l+=` V ${t[n][1]}`,i=y.Top):t[n][0]===t[n-1][0]&&t[n][1]!==t[n-1][1]?(l+=` V ${t[n][1]}`,i=t[n][1]>t[n-1][1]?y.Bottom:y.Top):t[n][0]>t[n-1][0]&&t[n][1]!==t[n-1][1]?(l+=` V ${t[n][1]}`,l+=` H ${t[n][0]}`):t[n][0]>t[n-1][0]&&t[n][1]===t[n-1][1]&&(l+=` H ${t[n][0]}`);break;case y.Left:t[n][0]>t[n-1][0]&&t[n][1]!==t[n-1][1]?(l+=` V ${t[n][1]}`,l+=` H ${t[n][0]}`,i=y.Right):t[n][0]>t[n-1][0]&&t[n][1]===t[n-1][1]?(l+=` V ${t[n][1]-a}`,l+=` H ${t[n][0]}`,l+=` V ${t[n][1]}`,i=y.Bottom):t[n][0]===t[n-1][0]&&t[n][1]!==t[n-1][1]?(l+=` V ${t[n][1]}`,i=t[n][1]>t[n-1][1]?y.Bottom:y.Top):t[n][0]<t[n-1][0]&&t[n][1]!==t[n-1][1]?(l+=` V ${t[n][1]}`,l+=` H ${t[n][0]}`):t[n][0]<t[n-1][0]&&t[n][1]===t[n-1][1]&&(l+=` H ${t[n][0]}`);break}else t[n][0]!==t[n-1][0]&&(l+=` H ${t[n][0]}`,i=t[n][0]>t[n-1][0]?y.Right:y.Left),t[n][1]!==t[n-1][1]&&(l+=` V ${t[n][1]}`,i=t[n][1]>t[n-1][1]?y.Bottom:y.Top);break}return l}},Ue=(s,t)=>{switch(s){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},j=(s,t)=>{const e=s.indexOf(t);return e>=0&&s.splice(e,1),s};var Ht=(s=>(s.Ellipse="ellipse",s.Empty="empty",s.Folder="folder",s.Hexagon="hexagon",s.Octagon="octagon",s.Pill="pill",s.Rectangle="rectangle",s.Rhombus="rhombus",s.RoundedRectangle="rounded-rectangle",s.StickyNote="sticky-note",s))(Ht||{});const Gt=(s,t,e,r,a)=>{if(typeof s=="function")return s(t,e,r,a);switch(s){case"ellipse":return ii(t,e,r,a);case"empty":return Ci();case"folder":return ki(t,e,r,a);case"hexagon":return xi(t,e,r,a);case"octagon":return Ii(t,e,r,a);case"pill":return jt(t,e,r,a);case"rectangle":return He(t,e,r,a);case"rhombus":return Si(t,e,r,a);case"rounded-rectangle":return Ai(t,e,r,a);case"sticky-note":return Ti(t,e,r,a);default:return He(t,e,r,a)}},ii=(s,t,e,r)=>`M ${s+e/2} ${t} A ${e/2} ${r/2} 0 0 0 ${s+e/2} ${t+r} A ${e/2} ${r/2} 0 1 0 ${s+e/2} ${t} Z`,Ci=()=>"Z",ki=(s,t,e,r)=>`M ${s} ${t} L ${s+e/3} ${t} L ${s+e/2} ${t+r/6} L ${s+e} ${t+r/6} L ${s+e} ${t+r} L ${s} ${t+r} Z`,xi=(s,t,e,r)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+r/2} L ${s+3*e/4} ${t+r} L ${s+e/4} ${t+r} L ${s} ${t+r/2} Z`,Ii=(s,t,e,r)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+r/4} L ${s+e} ${t+3*r/4} L ${s+3*e/4} ${t+r} L ${s+e/4} ${t+r} L ${s} ${t+3*r/4} L ${s} ${t+r/4} L ${s+e/4} ${t} Z`,jt=(s,t,e,r)=>r<e?`M ${s+r/2} ${t} L ${s+e-r/2} ${t} A ${r/2} ${r/2} 0 0 1 ${s+e} ${t+r/2} A ${r/2} ${r/2} 0 0 1 ${s+e-r/2} ${t+r} L ${s+r/2} ${t+r} A ${r/2} ${r/2} 0 0 1 ${s} ${t+r/2} A ${r/2} ${r/2} 0 0 1 ${s+r/2} ${t} Z`:r>e?`M ${s} ${t+e/2} L ${s} ${t+r-e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t+r} A ${e/2} ${e/2} 0 0 0 ${s+e} ${t+r-e/2} L ${s+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${s} ${t+e/2} Z`:ii(s,t,e,r),He=(s,t,e,r)=>`M ${s} ${t} L ${s+e} ${t} L ${s+e} ${t+r} L ${s} ${t+r} Z`,Si=(s,t,e,r)=>`M ${s+e/2} ${t} L ${s+e} ${t+r/2} L ${s+e/2} ${t+r} L ${s} ${t+r/2} Z`,Ai=(s,t,e,r)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} A ${e/4} ${r/4} 0 0 1 ${s+e} ${t+r/4} L ${s+e} ${t+3*r/4} A ${e/4} ${r/4} 0 0 1 ${s+3*e/4} ${t+r} L ${s+e/4} ${t+r} A ${e/4} ${r/4} 0 0 1 ${s} ${t+3*r/4} L ${s} ${t+r/4} A ${e/4} ${r/4} 0 0 1 ${s+e/4} ${t} Z`,Ti=(s,t,e,r)=>`M ${s} ${t} L ${s+3*e/4} ${t} L ${s+3*e/4} ${t+r/4} L ${s+3*e/4} ${t} L ${s+e} ${t+r/4} L ${s+3*e/4} ${t+r/4} L ${s+e} ${t+r/4} L ${s+e} ${t+r} L ${s} ${t+r} Z`;var M=(s=>(s.AllScroll="all-scroll",s.Auto="auto",s.Crosshair="crosshair",s.EWResize="ew-resize",s.Grab="grab",s.Grabbing="grabbing",s.Move="move",s.NoDrop="no-drop",s.NSResize="ns-resize",s.NotAllowed="not-allowed",s.ZoomIn="zoom-in",s.ZoomOut="zoom-out",s))(M||{});const $i=s=>Math.max(...s.split(`
|
|
2
|
+
`).map(t=>t.length)),Ei=s=>{var t;return((t=s.match(/\n/g))==null?void 0:t.length)||0},_=[];for(let s=0;s<256;++s)_.push((s+256).toString(16).slice(1));function Mi(s,t=0){return(_[s[t+0]]+_[s[t+1]]+_[s[t+2]]+_[s[t+3]]+"-"+_[s[t+4]]+_[s[t+5]]+"-"+_[s[t+6]]+_[s[t+7]]+"-"+_[s[t+8]]+_[s[t+9]]+"-"+_[s[t+10]]+_[s[t+11]]+_[s[t+12]]+_[s[t+13]]+_[s[t+14]]+_[s[t+15]]).toLowerCase()}let Qt;const Pi=new Uint8Array(16);function Ni(){if(!Qt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Qt=crypto.getRandomValues.bind(crypto)}return Qt(Pi)}const Ri=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),_e={randomUUID:Ri};function Ye(s,t,e){var a;if(_e.randomUUID&&!s)return _e.randomUUID();s=s||{};const r=s.random??((a=s.rng)==null?void 0:a.call(s))??Ni();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=r[6]&15|64,r[8]=r[8]&63|128,Mi(r)}class _t{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],j(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const zt=0;class vt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userHighlight)==null?void 0:e.contains(this.id))||!1}get selected(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userSelection)==null?void 0:e.contains(this.id))||!1}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`g#${this.id}`)}}class ct extends _t{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((r,a,l)=>t(r,a,l)&&!r.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((r,a,l)=>t(r,a,l)&&!r.removed)}find(t,e=!1){return e?super.find(t):super.find((r,a,l)=>t(r,a,l)&&!r.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(r=>!r.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],j(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(r=>!r.removed))yield e}}function wt(s,t){return!t||s[0]>t[0]?!0:s[0]===t[0]?s[1]>=t[1]:!1}class zi{constructor(t,e,r,a,l,i){this.name=t,this.type=e,this.defaultValue=r,this.basic=a,this.editable=l,this.rootAttribute=i,this.options=void 0,this.properties=void 0}}var tt=(s=>(s.Boolean="boolean",s.Color="color",s.Date="date",s.Datetime="datetime",s.Number="number",s.Object="object",s.Option="option",s.OptionList="option-list",s.OptionSet="option-set",s.Text="text",s.TextArea="text-area",s.TextList="text-list",s.TextSet="text-set",s.TextMap="text-map",s.Time="time",s.Url="url",s))(tt||{});class Yt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}class At{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const r of t){if(e==null)return;e=e[r]}return e}}setRootElementValue(t,e){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let r=this.rootElement;for(let a=0;a<t.length-1;++a){const l=t[a];if(r==null)return;r=r[l]}if(r==null)return;r[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}getValue(t){var a;const e=(a=this.propertySet.getProperty(t))==null?void 0:a.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type==="object"?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type==="object"?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const r in t)this.propertySet.getProperty(r).type==="object"?e[r]=this.valueSets[r].getValuesForKeys(t[r]):e[r]=this.getValue(r);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type==="object")t[e]=this.valueSets[e].getTimestamps();else{const a=this.ownTimestamps[e];a&&(t[e]=a)}return t}hasValue(t){const e=this.getValue(t);return!Xe(e)}hasSetValue(t){const e=this.getValue(t),r=this.propertySet.getProperty(t);return r&&r.type==="object"?this.getSubValueSet(t).hasAnySetValue():!Xe(e)&&!Pt(e,r==null?void 0:r.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const r=this.propertySet.getProperty(t);if(r){r.type==="object"?this.valueSets[t].setValues(e):(this.values[t]=e,Pt(e,r.defaultValue)||this.displayProperty(r));const a=r.rootAttribute;a!=null&&this.setRootElementValue(a,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type==="object"?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type==="object"?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type==="object"?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const r in t)this.propertySet.getProperty(r).type==="object"?this.valueSets[r].overwriteValuesLww(t[r],e):wt(e,this.ownTimestamps[r])&&(this.setValue(r,t[r]),this.ownTimestamps[r]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),r=e.rootAttribute;e.type==="object"?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),r!=null&&(e.defaultValue!==void 0?this.setRootElementValue(r,this.values[t]):this.values[t]=this.getRootElementValue(r)),e.basic?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),r=new Yt(e.properties),a=new At(r,this.rootElement);return a.overwriteValues(structuredClone(e.defaultValue)),a}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),j(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),j(this.displayedProperties,t))}}const Xe=s=>s==null||s===""||s instanceof Array&&s.length===0||s instanceof Object&&Object.keys(s).length===0,Pt=(s,t)=>s===t||JSON.stringify(s)===JSON.stringify(t),oi=(s,t)=>{const e={},r={},a=[];for(const l in s)a.push(l);for(const l in t)l in s||a.push(l);for(const l of a)if(ne(s[l])&&ne(t[l])){const i=oi(s[l],t[l]);Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(e[l]=i[0],r[l]=i[1])}else Pt(s[l],t[l])||(e[l]=s[l],r[l]=t[l]);return[e,r]},ne=s=>s!=null&&s.constructor===Object,Li={name:"",width:1,shape:ti.Straight,style:ei.Solid,label:null,defaultStartMarkerLook:null,defaultEndMarkerLook:null,startTypes:[],endTypes:[],color:"#000000",selectedColor:"#000000",properties:[]};class si{constructor(t){const e={...Li,...t};this.id=e.id,this.name=e.name,this.width=e.width,this.shape=e.shape,this.style=e.style,this.label=e.label,this.defaultStartMarkerLook=e.defaultStartMarkerLook,this.defaultEndMarkerLook=e.defaultEndMarkerLook,this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.color=e.color,this.selectedColor=e.selectedColor,this.propertySet=new Yt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class st extends vt{constructor(t,e,r,a,l){if(t.connections.get(l)!==void 0)throw new Error(`DiagramConnection with id "${l}" already exists`);super(t,l),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this.type=e,this.valueSet=new At(e.propertySet,this),this.originalData={},this.startMarkerLook=e.defaultStartMarkerLook,this.endMarkerLook=e.defaultEndMarkerLook,this.setStart(r),this.setEnd(a)}get name(){return this.middleLabel}set name(t){this.middleLabel=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateConnectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}setStart(t){this.start!==t?(this.start!==void 0&&j(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&j(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}tighten(){var t,e;if((t=this.start)!=null&&t.rootElement&&this.end){const r=this.start.rootElement.ports.map(a=>[a,a.distanceTo(this.end.coords)]).sort((a,l)=>a[1]-l[1]).map(a=>a[0]);t:for(const a of r){if(a===this.end||!a.allowsOutgoing)continue t;{for(const l of a.outgoingConnections)if(l!==this&&l.end===this.end)continue t;for(const l of a.incomingConnections)if(l!==this&&l.start===this.end)continue t}if(a===this.start)break t;this.setStart(a);break t}}if((e=this.end)!=null&&e.rootElement&&this.start){const r=this.end.rootElement.ports.map(a=>[a,a.distanceTo(this.start.coords)]).sort((a,l)=>a[1]-l[1]).map(a=>a[0]);t:for(const a of r){if(a===this.start||!a.allowsIncoming)continue t;{for(const l of a.incomingConnections)if(l!==this&&l.start===this.start)continue t;for(const l of a.outgoingConnections)if(l!==this&&l.end===this.start)continue t}if(a===this.end)break t;this.setEnd(a);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():zt}}class Vi extends ct{constructor(t){super(),this.types=new _t,this.model=t}new(t,e,r,a){let l;if(t instanceof si)l=t;else{const o=this.types.get(t);if(o===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);l=o}const i=new st(this.model,l,e,r,a);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){var r,a;const e=this.get(t,!0);e&&(j(((r=e.start)==null?void 0:r.outgoingConnections)||[],e),j(((a=e.end)==null?void 0:a.incomingConnections)||[],e),super.remove(t),e.updateInView())}}const z={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",horizontalAlign:xt.Center,verticalAlign:Bt.Center,fit:!1};class lt extends vt{constructor(t,e,r,a,l,i,o,n,d,g,h,m,p,u){const c=`${e==null?void 0:e.id}_field`;if(t.fields.get(c)!==void 0)throw new Error("DiagramField for rootElement already exists");super(t,c),this.textTimestamp=null,this.rootElement=e,this.coords=r,this.width=a,this.height=l,this.fontSize=i,this.fontFamily=o,this.color=n,this.selectedColor=d,this.horizontalAlign=g,this.verticalAlign=h,this.defaultText=m,this._text=m,this.editable=p,this.fit=u}get text(){return this._text}set text(t){var e;(t==null||(t==null?void 0:t.trim())==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&((e=this.model.canvas)==null||e.fitFieldRootInView(this.id))}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateFieldsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||zt}}class Di extends ct{constructor(t){super(),this.model=t}new(t,e,r,a,l,i,o,n,d,g,h,m,p){const u=new lt(this.model,t,e,o,n,r,a,l,i,d,g,h,m,p);return super.add(u),u.updateInView(),t!==void 0&&(t.label=u),u}remove(t){var r;const e=this.get(t,!0);e&&(((r=e.rootElement)==null?void 0:r.label)!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const et=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),X=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],nt=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:s.margin.length===1?s.margin[0]:(s.margin.length===2||s.margin.length===3,s.margin[1]),F=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Tt=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),$t=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],Et=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Mt=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Oi={lookType:"shaped-look",shape:Ht.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",selectedFillColor:"#FFFFFF",selectedBorderColor:"#000000"},ji={label:null,ports:[],look:Oi,priority:zt},We=1,Ze=1,Bi=1,Fi=1;class Y extends vt{constructor(t,e,r,a,l,i,o,n){if(t.sections.get(n)!==void 0)throw new Error(`DiagramSection with id "${n}" already exists`);super(t,n),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=r,this.indexYInNode=a,this.coords=l,this.width=i,this.height=o}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateSectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise()}getConfig(){var t,e,r,a,l;return(l=(a=(r=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:r.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode]}getMinWidth(){var t,e,r,a;return((a=(r=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:r.minWidths)==null?void 0:a[this.indexXInNode])||Bi}getMinHeight(){var t,e,r,a;return((a=(r=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:r.minHeights)==null?void 0:a[this.indexYInNode])||Fi}getPriority(){var t,e,r,a,l,i;return((i=(l=(a=(r=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:r.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode])==null?void 0:i.priority)||ji.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),r=e.indexOf(Math.min(...e));return this.ports[r]}}}getIncomingConnections(t=!1){const e=[];for(const r of this.ports)for(const a of r.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const r of this.ports)for(const a of r.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const r of this.ports){for(const a of r.incomingConnections)!t&&a.removed||e.push(a);for(const a of r.outgoingConnections)!t&&a.removed||e.push(a)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const r=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,i;switch(t){case y.Left:l=[r[0]-e,r[1]],i=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[0]=l[1]-this.getMinWidth());break;case y.Top:l=[r[0],r[1]],i=[a[0]-e,a[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case y.Right:l=[r[0],r[1]+e],i=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[1]=l[0]+this.getMinWidth());break;case y.Bottom:l=[r[0],r[1]],i=[a[0],a[1]+e],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[l[0],i[0]],width:l[1]-l[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){var i,o,n,d,g,h;const e=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const m of this.ports)m.move(Ft(m.coords,e,r,a,l));this.label&&(this.label.coords=[this.coords[0]+X((i=this.getConfig())==null?void 0:i.label),this.coords[1]+F((o=this.getConfig())==null?void 0:o.label)],this.label.width=this.width-X((n=this.getConfig())==null?void 0:n.label)-nt((d=this.getConfig())==null?void 0:d.label),this.label.height=this.height-F((g=this.getConfig())==null?void 0:g.label)-et((h=this.getConfig())==null?void 0:h.label),this.label.updateInView());for(const m of this.decorators)m.move(Ft(m.coords,e,r,a,l));this.getConnections().forEach(m=>m.tighten()),this.updateInView()}}class Gi extends ct{constructor(t){super(),this.model=t}new(t,e,r,a,l,i,o){var h,m,p,u,c,f,v,w,b,$;const n=new Y(this.model,t,e,r,a,l,i,o);super.add(n),n.updateInView(),t.sections.push(n),t.updateInView();const d=(u=(p=(m=(h=t.type.sectionGrid)==null?void 0:h.sections)==null?void 0:m[r])==null?void 0:p[e])==null?void 0:u.ports;if(d&&d.length>0)for(let I=0;I<d.length;++I){const T=d[I],N=this.model.ports.new(T.type!==void 0?this.model.ports.types.get(T.type):void 0,n,[n.coords[0]+(T.coords[0]||0),n.coords[1]+(T.coords[1]||0)],T.connectionPoint!==void 0?[n.coords[0]+(T.connectionPoint[0]||0),n.coords[1]+(T.connectionPoint[1]||0)]:void 0,T==null?void 0:T.direction,`${n.id}_${I}`);if((c=N.type)!=null&&c.label){const P={...z,...(f=N.type)==null?void 0:f.label},W=6*P.fontSize+$t(P)+Et(P),Z=P.fontSize+Mt(P)+Tt(P);let G;switch(N.direction){case y.Bottom:case y.Left:case y.Right:G=[N.coords[0]-W/2,N.coords[1]-Z-et(P)];break;case y.Top:G=[N.coords[0]-W/2,N.coords[1]+F(P)];break;default:G=N.coords}this.model.fields.new(N,G,P.fontSize,P.fontFamily,P.color,P.selectedColor,W,Z,P.horizontalAlign,P.verticalAlign,"",P.editable,P.fit)}}const g=($=(b=(w=(v=t.type.sectionGrid)==null?void 0:v.sections)==null?void 0:w[r])==null?void 0:b[e])==null?void 0:$.label;if(g){const I={...z,...g};this.model.fields.new(n,[n.coords[0]+X(I),n.coords[1]+F(I)],I.fontSize,I.fontFamily,I.color,I.selectedColor,n.width-X(I)-nt(I),n.height-F(I)-et(I),I.horizontalAlign,I.verticalAlign,"",I.editable,I.fit)}return n}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&j(e.node.sections,e),super.remove(t),e.updateInView()}}}const Ui={lookType:"shaped-look",shape:Ht.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",selectedFillColor:"#FFFFFF",selectedBorderColor:"#000000"},dt={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],sectionGrid:null,look:Ui,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:zt,properties:[]};class ni{constructor(t){const e={...dt,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.bottomPadding=_i(e),this.leftPadding=Yi(e),this.rightPadding=Xi(e),this.topPadding=Wi(e),this.label=e.label,this.ports=e.ports,this.sectionGrid=e.sectionGrid,this.look=e.look,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new Yt((t==null?void 0:t.properties)||[])}}class L extends vt{constructor(t,e,r=[0,0],a){if(t.nodes.get(a)!==void 0)throw new Error(`DiagramNode with id "${a}" already exists`);super(t,a),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this.type=e,this.valueSet=new At(e.propertySet,this),this.originalData={},this.coords=r,this.width=e.defaultWidth,this.height=e.defaultHeight}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateNodesInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.sections)e.raise();for(const e of this.decorators)e.raise();for(const e of this.children)e.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),r=e.indexOf(Math.min(...e));return this.ports[r]}}}getIncomingConnections(t=!1){const e=[];for(const r of this.ports)for(const a of r.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const r of this.ports)for(const a of r.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const r of this.ports){for(const a of r.incomingConnections)!t&&a.removed||e.push(a);for(const a of r.outgoingConnections)!t&&a.removed||e.push(a)}return e}getAdjacentNodes(t=!1){var r,a;const e=[];for(const l of this.ports){for(const i of l.incomingConnections){if(!t&&i.removed)continue;const o=(r=i.start)==null?void 0:r.getNode();if(o){if(!t&&o.removed)continue;e.push(o)}}for(const i of l.outgoingConnections){if(!t&&i.removed)continue;const o=(a=i.end)==null?void 0:a.getNode();if(o){if(!t&&o.removed)continue;e.push(o)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t==null?void 0:t.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,r=!1;for(;e!==void 0;){if(e.id===t.id){r=!0;break}e=e.parent}r||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){j(this.children,t),t.parent=void 0}fitToChild(t){const e=this.coords[0]-t.coords[0]+this.type.leftPadding;e>=0&&this.stretch(y.Left,e);const r=this.coords[1]-t.coords[1]+this.type.topPadding;r>=0&&this.stretch(y.Top,r);const a=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;a>=0&&this.stretch(y.Right,a);const l=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;l>=0&&this.stretch(y.Bottom,l),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const r of this.children)r.move([r.coords[0]+e[0],r.coords[1]+e[1]]);for(const r of this.sections)r.move([r.coords[0]+e[0],r.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const r=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,i;switch(t){case y.Left:l=[r[0]-e,r[1]],i=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[0]=l[1]-this.type.minWidth);break;case y.Top:l=[r[0],r[1]],i=[a[0]-e,a[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case y.Right:l=[r[0],r[1]+e],i=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[1]=l[0]+this.type.minWidth);break;case y.Bottom:l=[r[0],r[1]],i=[a[0],a[1]+e],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[l[0],i[0]],width:l[1]-l[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,r,a){let l=Number.NEGATIVE_INFINITY;switch(t){case y.Bottom:for(const i of this.sections)i.indexYInNode===a&&(l=Math.max(l,i.getMinHeight()-i.height));e<l&&(e=l);for(const i of this.sections)i.indexYInNode===a?i.stretch(t,e):i.indexYInNode>a&&i.move([i.coords[0],i.coords[1]+e]);break;case y.Right:for(const i of this.sections)i.indexXInNode===r&&(l=Math.max(l,i.getMinWidth()-i.width));e<l&&(e=l);for(const i of this.sections)i.indexXInNode===r?i.stretch(t,e):i.indexXInNode>r&&i.move([i.coords[0]+e,i.coords[1]]);break;case y.Top:for(const i of this.sections)i.indexYInNode===a&&(l=Math.max(l,i.getMinHeight()-i.height));e<l&&(e=l);for(const i of this.sections)i.indexYInNode===a?i.stretch(t,e):i.indexYInNode<a&&i.move([i.coords[0],i.coords[1]-e]);break;case y.Left:for(const i of this.sections)i.indexXInNode===r&&(l=Math.max(l,i.getMinWidth()-i.width));e<l&&(e=l);for(const i of this.sections)i.indexXInNode===r?i.stretch(t,e):i.indexXInNode<r&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const a of this.sections)e[a.id]=a.getGeometry();const r={};for(const a of this.children)a.id!==t&&(r[a.id]=a.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:r}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const o=t.children[i.id];o&&i.setGeometry(o)}for(const i of this.sections){const o=t.sections[i.id];o&&i.setGeometry(o)}for(const i of this.ports)i.move(Ft(i.coords,e,r,a,l));this.label&&(this.label.coords=[this.coords[0]+X(this.type.label),this.coords[1]+F(this.type.label)],this.label.width=this.width-X(this.type.label)-nt(this.type.label),this.label.height=this.height-F(this.type.label)-et(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Ft(i.coords,e,r,a,l));this.getConnections().forEach(i=>i.tighten()),this.updateInView()}}class Hi extends ct{constructor(t){super(),this.types=new _t,this.model=t}new(t,e,r){var i,o,n,d,g,h,m;let a;if(t instanceof ni)a=t;else{const p=this.types.get(t);if(p===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);a=p}const l=new L(this.model,a,e,r);if(super.add(l),l.updateInView(),a.sectionGrid!==null){let p=l.coords[1]+(a.sectionGrid.margin||0);for(let u=0;u<a.sectionGrid.sections.length;++u){let c=l.coords[0]+(a.sectionGrid.margin||0);for(let f=0;f<a.sectionGrid.sections[u].length;++f)this.model.sections.new(l,f,u,[c,p],((i=a.sectionGrid.defaultWidths)==null?void 0:i[f])||We,((o=a.sectionGrid.defaultHeights)==null?void 0:o[u])||Ze,`${l.id}_${u}_${f}`),c+=(((n=a.sectionGrid.defaultWidths)==null?void 0:n[f])||We)+(a.sectionGrid.margin||0);p+=(((d=a.sectionGrid.defaultHeights)==null?void 0:d[u])||Ze)+(a.sectionGrid.margin||0)}}if(a.ports.length>0)for(let p=0;p<a.ports.length;++p){const u=a.ports[p],c=this.model.ports.new(u.type!==void 0?this.model.ports.types.get(u.type):void 0,l,[l.coords[0]+u.coords[0],l.coords[1]+u.coords[1]],u.connectionPoint!==void 0?[l.coords[0]+(u.connectionPoint[0]||0),l.coords[1]+(u.connectionPoint[1]||0)]:void 0,u.direction,`${l.id}_${p}`);if((g=c.type)!=null&&g.label){const f={...z,...(h=c.type)==null?void 0:h.label},v=6*f.fontSize+$t(f)+Et(f),w=f.fontSize+Mt(f)+Tt(f);let b;switch(c.direction){case y.Bottom:case y.Left:case y.Right:b=[c.coords[0]-v/2,c.coords[1]-w-et(f)];break;case y.Top:b=[c.coords[0]-v/2,c.coords[1]+F(f)];break;default:b=c.coords}this.model.fields.new(c,b,f.fontSize,f.fontFamily,f.color,f.selectedColor,v,w,f.horizontalAlign,f.verticalAlign,"",f.editable,f.fit)}}if(a.label){const p={...z,...a.label};this.model.fields.new(l,[l.coords[0]+X(p),l.coords[1]+F(p)],p.fontSize,p.fontFamily,p.color,p.selectedColor,l.width-X(p)-nt(p),l.height-F(p)-et(p),p.horizontalAlign,p.verticalAlign,"",p.editable,p.fit)}return l.valueSet.resetValues(),(m=l.model.canvas)==null||m.fitNodeInView(l.id),l}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&j(e.parent.children,e);e.children.length>0;)this.model.nodes.remove(e.children[0].id);for(;e.sections.length>0;)this.model.sections.remove(e.sections[0].id);for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);for(;e.decorators.length>0;)this.model.decorators.remove(e.decorators[0].id);e.label&&this.model.fields.remove(e.label.id),super.remove(t),e.updateInView()}}getAtCoordinates(t,e){const r=[];for(const a of this)a.coords[0]<t&&t<a.coords[0]+a.width&&a.coords[1]<e&&e<a.coords[1]+a.height&&r.push(a);return r}}const ri=s=>{for(let t=0;t<s.length;++t)for(let e=0;e<s.length;++e)e!==t&&s[e].isAncestorOf(s[t])&&(s.splice(e,1),--e,t>e&&--t);return s},_i=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Yi=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],Xi=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Wi=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Ke={highlightedColor:"cyan",selectedColor:"violet"},ai={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24};class Zi{constructor(t){const e={...ai,...t};this.id=e.id,this.name=e.name,this.label=e.label,this.allowsOutgoing=e.allowsOutgoing,this.allowsIncoming=e.allowsIncoming,this.width=e.width,this.look=e.look}}class mt extends vt{constructor(t,e,r,a,l,i,o){if(t.ports.get(o)!==void 0)throw new Error(`DiagramPort with id "${o}" already exists`);super(t,o),this.outgoingConnections=[],this.incomingConnections=[],this.type=e,this.rootElement=r,this.coords=a,this.connectionPoint=l||a,this.direction=i}get allowsOutgoing(){var t,e;return((t=this.type)==null?void 0:t.allowsOutgoing)!==void 0?(e=this.type)==null?void 0:e.allowsOutgoing:!0}get allowsIncoming(){var t,e;return((t=this.type)==null?void 0:t.allowsIncoming)!==void 0?(e=this.type)==null?void 0:e.allowsIncoming:!0}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updatePortsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.incomingConnections)e.raise();for(const e of this.outgoingConnections)e.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof L)return this.rootElement;if(this.rootElement instanceof Y)return this.rootElement.node}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||zt}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];this.coords=t,this.connectionPoint[0]=this.connectionPoint[0]+e[0],this.connectionPoint[1]=this.connectionPoint[1]+e[1];for(const r of this.outgoingConnections)r.setStart(this);for(const r of this.incomingConnections)r.setEnd(this);this.label&&this.label.move([this.label.coords[0]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return Qe(this.coords,t)}}class Ki extends ct{constructor(t){super(),this.types=new _t,this.model=t}new(t,e,r,a,l,i){const o=new mt(this.model,t,e,r,a,l,i);return super.add(o),o.updateInView(),e!==void 0&&e.ports.push(o),o}remove(t){const e=this.get(t,!0);if(e){for(;e.outgoingConnections.length>0;)this.model.connections.remove(e.outgoingConnections[0].id);for(;e.incomingConnections.length>0;)this.model.connections.remove(e.incomingConnections[0].id);e.label&&this.model.fields.remove(e.label.id),(e.rootElement instanceof L||e.rootElement instanceof Y)&&j(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class li{import(t,e){t.clear(),e.id&&(t.id=e.id),t.name=e.name,t.description=e.description,t.type=e.type,t.createdAt=new Date(e.createdAt),t.updatedAt=new Date(e.updatedAt);for(const r of e.nodes||[])this.importNode(t,r);for(const r of e.connections||[])this.importConnection(t,r);return e.data&&t.valueSet.setValues(e.data),e.collabMeta&&(t.logicalClock=e.collabMeta.logicalClock,t.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),t}importNode(t,e){var a,l,i,o,n,d,g,h,m,p;const r=t.nodes.types.get(e.type);if(r){const u=new L(t,r,e.coords,e.id);if(t.nodes.add(u),u.width=e.width,u.height=e.height,e.label&&r.label){const f={...z,...r.label},v=new lt(t,u,[u.coords[0]+X(f),u.coords[1]+F(f)],u.width-X(f)-nt(f),u.height-F(f)-et(f),f.fontSize,f.fontFamily,f.color,f.selectedColor,f.horizontalAlign,f.verticalAlign,"",f.editable,f.fit);v.text=e.label,u.label=v,t.fields.add(v),v.updateInView()}for(const f of e.children||[]){const v=this.importNode(t,f);v!==void 0&&((a=u.children)==null||a.push(v),v.parent=u)}for(const f of e.sections||[]){const v=new Y(t,u,f.indexXInNode,f.indexYInNode,f.coords,f.width,f.height,f.id);if((l=u.sections)==null||l.push(v),t.sections.add(v),f.label&&(d=(n=(o=(i=r.sectionGrid)==null?void 0:i.sections)==null?void 0:o[f.indexYInNode])==null?void 0:n[f.indexXInNode])!=null&&d.label){const b={...z,...(p=(m=(h=(g=r.sectionGrid)==null?void 0:g.sections)==null?void 0:h[f.indexYInNode])==null?void 0:m[f.indexXInNode])==null?void 0:p.label},$=new lt(t,v,[v.coords[0]+X(b),v.coords[1]+F(b)],v.width-X(b)-nt(b),v.height-F(b)-et(b),b.fontSize,b.fontFamily,b.color,b.selectedColor,b.horizontalAlign,b.verticalAlign,"",b.editable,b.fit);$.text=f.label,v.label=$,t.fields.add($),$.updateInView()}let w=0;for(const b of f.ports||[]){const $=b.type!==void 0?t.ports.types.get(b.type):void 0,I=new mt(t,$,v,b.coords,b.connectionPoint,b.direction,b.id);if(v.ports.push(I),t.ports.add(I),b.label){if(r.ports.length>w&&($!=null&&$.label)){const T={...z,...$==null?void 0:$.label};let N;switch(I.direction){case y.Top:case y.Left:N=[I.coords[0]-T.fontSize,I.coords[1]-T.fontSize];break;case y.Bottom:N=[I.coords[0]-T.fontSize,I.coords[1]+T.fontSize];break;case y.Right:N=[I.coords[0]+T.fontSize,I.coords[1]-T.fontSize];break;default:N=I.coords}const P=new lt(t,I,N,T.fontSize,T.fontSize,T.fontSize,T.fontFamily,T.color,T.selectedColor,T.horizontalAlign,T.verticalAlign,"",T.editable,T.fit);P.text=b.label,I.label=P,t.fields.add(P),P.updateInView()}++w}b.collabMeta&&(I.selfRemoved=b.collabMeta.selfRemoved,I.selfRemovedTimestamp=b.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(I.label,b.collabMeta.label)),I.updateInView()}f.collabMeta&&(v.selfRemoved=f.collabMeta.selfRemoved,v.selfRemovedTimestamp=f.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(v.label,f.collabMeta.label)),v.updateInView()}let c=0;for(const f of e.ports||[]){const v=f.type!==void 0?t.ports.types.get(f.type):void 0,w=new mt(t,v,u,f.coords,f.connectionPoint,f.direction,f.id);if(u.ports.push(w),t.ports.add(w),f.label){if(r.ports.length>c&&(v!=null&&v.label)){const b={...z,...v==null?void 0:v.label};let $;switch(w.direction){case y.Top:case y.Left:$=[w.coords[0]-b.fontSize,w.coords[1]-b.fontSize];break;case y.Bottom:$=[w.coords[0]-b.fontSize,w.coords[1]+b.fontSize];break;case y.Right:$=[w.coords[0]+b.fontSize,w.coords[1]-b.fontSize];break;default:$=w.coords}const I=new lt(t,w,$,b.fontSize,b.fontSize,b.fontSize,b.fontFamily,b.color,b.selectedColor,b.horizontalAlign,b.verticalAlign,"",b.editable,b.fit);I.text=f.label,w.label=I,t.fields.add(I),I.updateInView()}++c}f.collabMeta&&(w.selfRemoved=f.collabMeta.selfRemoved,w.selfRemovedTimestamp=f.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(w.label,f.collabMeta.label)),w.updateInView()}return e.data&&u.valueSet.setValues(e.data),e.collabMeta&&(u.selfRemoved=e.collabMeta.selfRemoved,u.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,u.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(u.label,e.collabMeta.label),u.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),u.updateInView(),u.raise(),u}}importConnection(t,e){const r=t.connections.types.get(e.type);if(r){const a=new st(t,r,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(a),a.startLabel=e.startLabel,a.middleLabel=e.middleLabel,a.endLabel=e.endLabel,a.points=e.points,e.data&&a.valueSet.setValues(e.data),e.collabMeta&&(a.selfRemoved=e.collabMeta.selfRemoved,a.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,a.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),a.updateInView(),a.raise(),a}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class Xt{constructor(t,e,r,a,l,i,o){this.canvas=t,this.id=e,this.typeId=r,this.coords=a,this.parentId=l,this.label=i,this.values=o}do(){var e;const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&((e=this.canvas.model.nodes.get(this.parentId))==null||e.addChild(t)),this.values!==void 0&&t.valueSet.setValues(structuredClone({...t.valueSet.getValues(),...this.values})),t.label&&(t.label.text=this.label||"")}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new Xt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class le{constructor(t,e,r){this.canvas=t,this.to=e,this.timestamp=r}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&wt(this.timestamp,e.geometryTimestamp)){const r=this.to[t];e.move([r[0],r[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new le(t,e.to,e.timestamp)}}class Nt{constructor(t,e,r,a){this.canvas=t,this.nodeIds=e,this.delta=r,this.timestamp=a}do(){var t;for(const e of this.nodeIds){const r=this.canvas.model.nodes.get(e,!0);r&&wt(this.timestamp,r.geometryTimestamp)&&(r.move([r.coords[0]+this.delta[0],r.coords[1]+this.delta[1]]),(t=r.parent)==null||t.fitToChild(r),r.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new Nt(t,e.nodeIds,e.delta,e.timestamp)}}class J{constructor(t,e,r,a){this.canvas=t,this.nodeId=e,this.to=r,this.timestamp=a}do(){var e,r,a;const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&wt(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),(e=t.label)!=null&&e.fit&&this.canvas.fitFieldRootInView(t.label.id);for(const l of t.sections)(r=l.label)!=null&&r.fit&&this.canvas.fitFieldRootInView(l.label.id);(a=t.parent)==null||a.fitToChild(t),t.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new J(t,e.nodeId,e.to,e.timestamp)}}class Rt{constructor(t,e,r,a,l){this.canvas=t,this.childId=e,this.parentId=r,this.childGeometry=a,this.timestamp=l}do(){var r;const t=this.canvas.model.nodes.get(this.childId,!0),e=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;t&&(this.parentId===void 0||e)&&wt(this.timestamp,t.geometryTimestamp)&&((r=t.parent)==null||r.removeChild(t),t.setGeometry(this.childGeometry),e==null||e.addChild(t))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,e){return new Rt(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class Wt{constructor(t,e,r,a,l){this.canvas=t,this.id=e,this.typeId=r,this.startId=a,this.endId=l}do(){const t=this.canvas.model.ports.get(this.startId,!0),e=this.canvas.model.ports.get(this.endId,!0);t&&e&&this.canvas.model.connections.new(this.typeId,t,e,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,e){return new Wt(t,e.id,e.typeId,e.startId,e.endId)}}class It{constructor(t,e,r,a){this.canvas=t,this.fieldId=e,this.to=r,this.timestamp=a}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&wt(this.timestamp,t.textTimestamp)&&(t.text=this.to,t.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new It(t,e.fieldId,e.to,e.timestamp)}}class St{constructor(t,e,r,a){this.canvas=t,this.id=e,this.to=r,this.timestamp=a}getValueSet(){var t;return this.id===void 0?this.canvas.model.valueSet:(t=this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))==null?void 0:t.valueSet}do(){var t;(t=this.getValueSet())==null||t.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new St(t,e.id,e.to,e.timestamp)}}class ot{constructor(t,e,r,a,l,i,o,n){this.canvas=t,this.nodeIds=e,this.sectionIds=r,this.portIds=a,this.connectionIds=l,this.fieldIds=i,this.selfRemoved=o,this.timestamp=n}doOne(t){t&&wt(this.timestamp,t.selfRemovedTimestamp)&&(t.selfRemoved=this.selfRemoved,t.selfRemovedTimestamp=this.timestamp)}do(){for(const t of this.nodeIds)this.doOne(this.canvas.model.nodes.get(t,!0));for(const t of this.sectionIds)this.doOne(this.canvas.model.sections.get(t,!0));for(const t of this.portIds)this.doOne(this.canvas.model.ports.get(t,!0));for(const t of this.connectionIds)this.doOne(this.canvas.model.connections.get(t,!0));for(const t of this.fieldIds)this.doOne(this.canvas.model.fields.get(t,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,e){return new ot(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class Zt{constructor(t,e,r){this.canvas=t,this.nodes=e,this.connections=r}do(){const t=new li;this.canvas.userSelection.clear();for(const e of this.nodes){const r=t.importNode(this.canvas.model,e);r&&this.canvas.userSelection.add(r)}for(const e of this.connections){const r=t.importConnection(this.canvas.model,e);r&&this.canvas.userSelection.add(r)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new Zt(t,e.nodes,e.connections)}}class qi{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=Ye()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+Ye()}doCollaboratively(t){if(t.do(),this.onSend){const e=t.serialize();this.onSend(e)}}receive(t){switch("timestamp"in t&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,t.timestamp[0])),t.type){case"addNode":{Xt.deserialize(this.canvas,t).do();break}case"applyLayout":{le.deserialize(this.canvas,t).do();break}case"move":{Nt.deserialize(this.canvas,t).do();break}case"setGeometry":{J.deserialize(this.canvas,t).do();break}case"setParent":{Rt.deserialize(this.canvas,t).do();break}case"addConnection":{Wt.deserialize(this.canvas,t).do();break}case"editField":{It.deserialize(this.canvas,t).do();break}case"updateValues":{St.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{ot.deserialize(this.canvas,t).do();break}case"paste":{Zt.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class Ji{constructor(t,e){this.canvas=t,this.maximum=e,this.history=[],this.index=0}add(t){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(t)):(this.history.push(t),++this.index),this.canvas.diagramChange$.next({action:t,method:0})}undo(){let t;if(this.index>0){let e;do--this.index,t=this.history[this.index],e=t.undo();while(!e&&this.index>0)}this.canvas.diagramChange$.next({action:t,method:1})}redo(){let t;if(this.index<this.history.length){let e;do t=this.history[this.index],e=t.redo(),++this.index;while(!e&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:t,method:2})}}var k=(s=>(s.AddConnection="add-connection",s.AddNode="add-node",s.ApplyLayout="apply-layout",s.Clipboard="clipboard",s.ContextMenu="context-menu",s.EditField="edit-field",s.MoveNode="move-node",s.Paste="paste",s.Remove="remove",s.StretchNode="stretch-node",s.StretchSection="stretch-section",s.UpdateValues="update-values",s.Zoom="zoom",s))(k||{});class Qi{constructor(t,e,r,a,l,i,o,n,d){this.canvas=t,this.type=e,this.coords=r,this.parentId=a,this.ancestorId=l,this.fromAncestorGeometry=i,this.toAncestorGeometry=o,this.label=n,this.values=d,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Xt(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const e=new J(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){const t=this.canvas.model.nodes.get(this.id),e=new ot(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const r=new J(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new ot(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const r=new J(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}return t===void 0}}class te{constructor(t,e,r){this.canvas=t,this.nodeIds=e,this.delta=r}do(){const t=new Nt(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const t=new Nt(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class B{constructor(t,e,r,a,l,i,o,n){this.canvas=t,this.intent=e,this.nodeId=r,this.from=a,this.to=l,this.ancestorId=i,this.fromAncestorGeometry=o,this.toAncestorGeometry=n}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new J(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const r=new J(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new J(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const r=new J(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new J(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class to{constructor(t,e,r,a,l,i,o,n,d){this.canvas=t,this.childId=e,this.fromParentId=r,this.toParentId=a,this.fromChildGeometry=l,this.toChildGeometry=i,this.ancestorId=o,this.fromAncestorGeometry=n,this.toAncestorGeometry=d}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Rt(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const r=new J(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Rt(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const r=new J(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}return t!==void 0}redo(){return this.do()}}class ee{constructor(t,e,r,a){this.canvas=t,this.type=e,this.startId=r,this.endId=a,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Wt(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=this.canvas.model.connections.get(this.id),e=new ot(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}redo(){const t=this.canvas.model.connections.get(this.id),e=new ot(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class qe{constructor(t,e,r,a){this.canvas=t,this.fieldId=e,this.from=r,this.to=a}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new It(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}undo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.to=t.text;const e=new It(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}redo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.from=t.text;const e=new It(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class eo{constructor(t,e,r,a){this.canvas=t,this.id=e,this.from=r,this.to=a}do(){const t=new St(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new St(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.to=e.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}redo(){const t=new St(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.from=e.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}}class io{constructor(t,e,r,a,l,i){this.canvas=t,this.nodeIds=e,this.sectionIds=r,this.portIds=a,this.connectionIds=l,this.fieldIds=i}do(){const t=this.nodeIds.map(r=>this.canvas.model.nodes.get(r)!==void 0).includes(!0)||this.sectionIds.map(r=>this.canvas.model.sections.get(r)!==void 0).includes(!0)||this.portIds.map(r=>this.canvas.model.ports.get(r)!==void 0).includes(!0)||this.connectionIds.map(r=>this.canvas.model.connections.get(r)!==void 0).includes(!0)||this.fieldIds.map(r=>this.canvas.model.fields.get(r)!==void 0).includes(!0),e=new ot(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}undo(){const t=this.nodeIds.map(r=>this.canvas.model.nodes.get(r)===void 0).includes(!0)||this.sectionIds.map(r=>this.canvas.model.sections.get(r)===void 0).includes(!0)||this.portIds.map(r=>this.canvas.model.ports.get(r)===void 0).includes(!0)||this.connectionIds.map(r=>this.canvas.model.connections.get(r)===void 0).includes(!0)||this.fieldIds.map(r=>this.canvas.model.fields.get(r)===void 0).includes(!0),e=new ot(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){return this.do()}}class oo{constructor(t,e,r,a){this.canvas=t,this.nodes=e,this.connections=r,this.coords=a}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const l of this.nodes)l.coords[0]<t[0]&&(t[0]=l.coords[0]),l.coords[1]<t[1]&&(t[1]=l.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,r={};for(const l of this.nodes){const i=l.id,o=this.canvas.collabEngine.freshId();if(r[i]=o,l.id=o,e&&(l.coords=[l.coords[0]+e[0],l.coords[1]+e[1]]),l.sections)for(const n of l.sections){const d=n.id;if(n.id.includes(l.id)?n.id=n.id.replace(l.id,o):n.id=this.canvas.collabEngine.freshId(),r[d]=n.id,e&&(n.coords=[n.coords[0]+e[0],n.coords[1]+e[1]]),n.ports)for(const g of n.ports){const h=g.id;g.id.includes(l.id)?g.id=g.id.replace(l.id,o):g.id=this.canvas.collabEngine.freshId(),r[h]=g.id,e&&(g.coords=[g.coords[0]+e[0],g.coords[1]+e[1]])}}if(l.ports)for(const n of l.ports){const d=n.id;n.id.includes(l.id)?n.id=n.id.replace(l.id,o):n.id=this.canvas.collabEngine.freshId(),r[d]=n.id,e&&(n.coords=[n.coords[0]+e[0],n.coords[1]+e[1]])}}for(const l of this.connections){const i=this.canvas.collabEngine.freshId();if(r[l.id]=i,l.id=i,l.start=r[l.start]||l.start,l.end=r[l.end]||l.end,e)for(let o=0;o<l.points.length;++o)l.points[o]=[l.points[o][0]+e[0],l.points[o][1]+e[1]]}const a=new Zt(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(a),!0}undo(){const t=this.nodes.map(r=>this.canvas.model.nodes.get(r.id)!==void 0).includes(!0)||this.connections.map(r=>this.canvas.model.connections.get(r.id)!==void 0).includes(!0),e=new ot(this.canvas,this.nodes.map(r=>r.id),[],[],this.connections.map(r=>r.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=this.nodes.map(r=>this.canvas.model.nodes.get(r.id)===void 0).includes(!0)||this.connections.map(r=>this.canvas.model.connections.get(r.id)===void 0).includes(!0),e=new ot(this.canvas,this.nodes.map(r=>r.id),[],[],this.connections.map(r=>r.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class Kt{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}class gt extends Kt{constructor(t,e,r){super(0),this.cause=t,this.target=e,this.coords=r}}class ut extends Kt{constructor(t,e,r){super(1),this.cause=t,this.target=e,this.coords=r}}class O extends Kt{constructor(t,e){super(2),this.targets=t,this.selected=e}}class Q extends Kt{constructor(t){super(3),this.target=t}}class so extends vt{constructor(t,e,r,a,l,i,o,n){if(t.objects.get(n)!==void 0)throw new Error(`DiagramObject with id "${n}" already exists`);super(t,n),this.rootElement=e,this.coords=r,this.width=a,this.height=l,this.priority=i,this.html=o}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateDecoratorsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class no extends ct{constructor(t){super(),this.model=t}new(t,e,r,a,l,i,o){const n=new so(this.model,t,e,r,a,l,i,o);return super.add(n),n.updateInView(),t!==void 0&&t.decorators.push(n),n}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof L||e.rootElement instanceof Y)&&j(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class ro extends vt{constructor(t,e,r,a,l,i,o){if(t.objects.get(o)!==void 0)throw new Error(`DiagramObject with id "${o}" already exists`);super(t,o),this.coords=e,this.width=r,this.height=a,this.priority=l,this.html=i}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateObjectsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class ao extends ct{constructor(t){super(),this.model=t}new(t,e,r,a,l,i){const o=new ro(this.model,t,e,r,a,l,i);return super.add(o),o.updateInView(),o}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class di{constructor(t,e,r,a,l,i=[]){this.nodes=new Hi(this),this.sections=new Gi(this),this.ports=new Ki(this),this.connections=new Vi(this),this.fields=new Di(this),this.objects=new ao(this),this.decorators=new no(this),this.canvas=t,this.id=e,this.name=r,this.description=a,this.type=l,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new At(new Yt(i),this)}clear(){var t,e;(t=this.canvas)==null||t.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),(e=this.canvas)==null||e.updateModelInView()}}const re=96,K=32,kt=re+K,lo=Math.PI/4,co=100;class ho{constructor(t){this.canvas=t}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),r=this.canvas.getPointerLocationRelativeToCanvas(t),a=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-kt}px`).attr("y",`${e[1]-kt}px`).attr("width",`${2*kt}px`).attr("height",`${2*kt}px`).style("pointer-events","none").on(S.ContextMenu,i=>{this.canvas.canUserPerformAction(k.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(S.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=a;const l=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&this.canvas.canUserPerformAction(k.Remove)&&l.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.preventDefault(),this.canvas.userSelection.cutToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&l.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.preventDefault(),this.canvas.userSelection.copyToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.canUserPerformAction(k.Paste)&&l.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.preventDefault(),this.canvas.userSelection.pasteFromClipboard(this.canvas.getClosestGridPoint(r)),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Remove)&&l.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.preventDefault(),this.canvas.userSelection.removeFromModel(),this.canvas.cancelAllUserActions()}}),l.length===0&&l.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<l.length;++i){const o=l[i],n=o.onPress,d=(i+.5-l.length/2)*lo,g=a.append("xhtml:div").attr("class",`daga-context-menu-button ${o.imageClass}-button${o.onPress!=null?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*K}px`).style("height",`${2*K}px`).style("border-radius",`${K}px`).style("pointer-events","auto").on(S.Click,h=>{n&&n(h)}).on(S.KeyDown,h=>{n&&h.key===at.Enter&&n(h)});g.append("xhtml:div").style("position","absolute").style("left",`${.75*K}px`).style("top",`${.5*K}px`).style("width",`${.5*K}px`).style("height",`${.5*K}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",o.imageClass),g.append("xhtml:span").style("position","absolute").style("left",`${.2*K}px`).style("top",`${1.1*K}px`).style("text-align","center").style("width",`${1.6*K}px`).style("height",`${.35*K}px`).style("margin","0").style("font-size",`${.35*K}px`).style("font-weight","700").style("user-select","none").text(o.name),g.transition().ease(E.easeLinear).duration(co).tween("progress",()=>h=>{const m=d*h;return g.style("left",`${Math.sin(m)*re-K+kt}px`).style("top",`${-Math.cos(m)*re-K+kt}px`)})}}close(){var t;(t=this.contextMenuContainer)==null||t.remove(),this.contextMenuContainer=void 0}}class go extends ct{constructor(t){super(),this.focus=void 0,this.canvas=t}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,t instanceof lt&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof L){for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateNodesInView(t.id)}else if(t instanceof Y){for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}else t instanceof mt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof st&&this.canvas.updateConnectionsInView(t.id)}clear(){for(;this.entities.length>0;){const t=this.entities[0];this.remove(t.id),t.updateInView()}this.focus=void 0}}const uo=1;class ci{export(t,e=!1){const r={name:t.name,type:t.type,typeVersion:uo,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(r.id=t.id),t.description&&(r.description=t.description);for(const a of t.nodes.all(!0))!e&&a.removed||a.parent===void 0&&r.nodes.push(this.exportNode(a,e));for(const a of t.connections.all(!0))!e&&a.removed||r.connections.push(this.exportConnection(a,e));return r}exportNode(t,e=!1){var i,o,n,d,g,h;const r=[];for(const m of t.children)r.push(this.exportNode(m,e));const a=[];for(const m of t.sections){const p=[];for(const u of m.ports)p.push({id:u.id,type:(i=u.type)==null?void 0:i.id,coords:Ct(u.coords),connectionPoint:Ct(u.connectionPoint),direction:u.direction,label:((o=u.label)==null?void 0:o.text)||"",...e?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}});a.push({id:m.id,ports:p,label:((n=m.label)==null?void 0:n.text)||"",indexXInNode:m.indexXInNode,indexYInNode:m.indexYInNode,coords:Ct(m.coords),width:m.width,height:m.height,...e?{collabMeta:{removed:m.removed,selfRemoved:m.selfRemoved,selfRemovedTimestamp:m.selfRemovedTimestamp,...this.exportLabelCollabMeta(m)}}:{}})}const l=[];for(const m of t.ports)l.push({id:m.id,type:(d=m.type)==null?void 0:d.id,coords:Ct(m.coords),connectionPoint:Ct(m.connectionPoint),direction:m.direction,label:((g=m.label)==null?void 0:g.text)||"",...e?{collabMeta:{removed:m.removed,selfRemoved:m.selfRemoved,selfRemovedTimestamp:m.selfRemovedTimestamp,...this.exportLabelCollabMeta(m)}}:{}});return{id:t.id,type:t.type.id,children:r,sections:a,ports:l,label:((h=t.label)==null?void 0:h.text)||"",coords:Ct(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){var r,a;return{id:t.id,type:t.type.id,start:((r=t.start)==null?void 0:r.id)||"",end:((a=t.end)==null?void 0:a.id)||"",startLabel:t.startLabel,middleLabel:t.middleLabel,endLabel:t.endLabel,points:t.points,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,dataTimestamps:t.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:t}){return t?{label:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,textTimestamp:t.textTimestamp}}:{}}}const fo="Diagram properties";class mo extends ct{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(yt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof L||t instanceof st)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof Y?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof L&&t.sections))for(const e of t.sections)super.add(e),e.updateInView()}remove(t){const e=this.get(t);if(e&&(this.propertyEditorSelection===e&&this.openInPropertyEditor(void 0),super.remove(t),e.updateInView(),e instanceof L&&e.sections))for(const r of e.sections)super.remove(r.id),r.updateInView()}toggle(t){this.contains(t.id)?this.remove(t.id):this.add(t)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const t=this.entities[0];super.remove(t.id),t.updateInView()}}move(t){for(const e of this.all())e instanceof L&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],r=[],a=[],l=[];for(const o of this.all())o instanceof L?t.push(o.id):o instanceof Y?e.push(o.id):o instanceof mt?r.push(o.id):o instanceof st?a.push(o.id):o instanceof lt&&l.push(o.id);const i=new io(this.canvas,t,e,r,a,l);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new ci;for(const r of this.all())r instanceof L&&t.nodes.push(e.exportNode(r,!1)),r instanceof st&&t.connections.push(e.exportConnection(r,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const r=JSON.parse(e);if(r.type!=="daga-user-selection")return;const a=new oo(this.canvas,r.nodes,r.connections,t);this.canvas.actionStack.add(a),a.do()}catch{return}})}openInPropertyEditor(t){var a;this.makeUpdateValuesAction();const e=(a=this.canvas.parentComponent)==null?void 0:a.propertyEditor;if(e===void 0)return;const r=t==null?void 0:t.valueSet;r?(this.propertyEditorSelection=t,this.propertyEditorValues=structuredClone(r.getValues()),e&&(t instanceof L||t instanceof st?(t instanceof L?t.name?e.title=`${t.type.name}: ${t.name}`:e.title=t.type.name:t instanceof st&&(e.title=t.type.name),e.valueSet=void 0,e.valueSet=r):(e.title=fo,e.valueSet=void 0,e.valueSet=r))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,e&&(e.title="",e.valueSet=void 0))}makeUpdateValuesAction(){var o,n;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof di?void 0:this.propertyEditorSelection.id;if(Pt(this.propertyEditorValues,(o=this.propertyEditorSelection)==null?void 0:o.valueSet.getValues()))return;const e=this.propertyEditorValues,r=structuredClone((n=this.propertyEditorSelection)==null?void 0:n.valueSet.getValues()),[a,l]=oi(e,r),i=new eo(this.canvas,t,a,l);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=r}}const po=12,V=6,yo=25,ie="diagram-connection-unfinished",bo=100,Ut=class Ut{constructor(t,e){var r,a,l,i,o,n,d,g,h,m,p,u,c,f,v,w,b,$;if(this.backgroundPatternId=`daga-background-pattern-id-${Ut.canvasCount++}`,this.zoomTransform=E.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new yt.Subject,this.diagramChange$=new yt.Subject,this.diagramEvent$=new yt.Subject,this.propertyEditorChanges$=new yt.Subject,this.parentComponent=t,this.model=new di(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new mo(this),this.userHighlight=new go(this),this.contextMenu=new ho(this),this.backgroundColor=((r=e.canvas)==null?void 0:r.backgroundColor)||"#FFFFFF",this.gridSize=((l=(a=e.canvas)==null?void 0:a.grid)==null?void 0:l.enabled)===!1||((i=e.canvas)==null?void 0:i.grid)===void 0?0:Math.abs(((n=(o=e.canvas)==null?void 0:o.grid)==null?void 0:n.spacing)||10),this.gridThickness=Math.abs(((g=(d=e.canvas)==null?void 0:d.grid)==null?void 0:g.thickness)||.05),this.gridColor=((m=(h=e.canvas)==null?void 0:h.grid)==null?void 0:m.color)||"rgba(0, 0, 0, 0.1)",this.snapToGrid=((u=(p=e.canvas)==null?void 0:p.grid)==null?void 0:u.enabled)===!1||((c=e.canvas)==null?void 0:c.grid)===void 0?!1:((v=(f=e.canvas)==null?void 0:f.grid)==null?void 0:v.snap)||!1,this.zoomFactor=((w=e.canvas)==null?void 0:w.zoomFactor)||2,this.panRate=((b=e.canvas)==null?void 0:b.panRate)||100,this.inferConnectionType=e.inferConnectionType||!1,this.multipleSelectionOn=!1,this.priorityThresholds=(($=e.canvas)==null?void 0:$.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new Ji(this,yo),this.collabEngine=new qi(this),e.nodeTypes)for(const I of e.nodeTypes){const T=new ni({...e.nodeTypeDefaults,...I});this.model.nodes.types.add(T)}if(e.portTypes)for(const I of e.portTypes){const T=new Zi({...e.portTypeDefaults,...I});this.model.ports.types.add(T)}if(e.connectionTypes){for(const I of e.connectionTypes){const T=new si({...e.connectionTypeDefaults,...I});this.model.connections.types.add(T)}this._connectionType=e.defaultConnection!==void 0?this.model.connections.types.get(e.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){var e,r;this._connectionType=t,(r=(e=this.parentComponent)==null?void 0:e.palette)==null||r.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){j(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){var e,r;this.priorityThreshold=t,this.updateModelInView();for(const a of this.model.nodes)this.fitNodeInView(a.id);(r=(e=this.parentComponent)==null?void 0:e.palette)==null||r.refreshPalette()}initView(t){const e=E.select(t);e.html(""),this.diagramRoot=e.append("div").node(),E.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),E.select(this.diagramRoot).on(S.Click,()=>{var i;(i=E.select(this.diagramRoot).node())==null||i.focus()}).on(S.ContextMenu,i=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,null);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(S.DoubleClick,i=>{const o=new gt(i,null);this.diagramEvent$.next(o)}).on(S.KeyDown,i=>{if(!i.ctrlKey&&(i.key===at.Delete||i.key===at.Backspace)&&this.canUserPerformAction(k.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),i.ctrlKey&&i.key==="a"){i.preventDefault();for(const o of this.model.nodes)this.userSelection.add(o);for(const o of this.model.connections)this.userSelection.add(o);this.diagramEvent$.next(new O(this.userSelection.all(),!0))}if(i.ctrlKey&&i.key==="i"){i.preventDefault();const o=[],n=[];for(const d of this.model.nodes)this.userSelection.toggle(d),d.selected?o.push(d):n.push(d);for(const d of this.model.connections)this.userSelection.toggle(d),d.selected?o.push(d):n.push(d);o.length>0&&this.diagramEvent$.next(new O(o,!0)),n.length>0&&this.diagramEvent$.next(new O(n,!1))}if(i.ctrlKey&&i.key==="c"&&(i.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),i.ctrlKey&&i.key==="x"&&(i.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),i.ctrlKey&&i.key==="v"){i.preventDefault();const o=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(o[0][0]+o[1][0])/2,(o[0][1]+o[1][1])/2])),this.cancelAllUserActions()}i.ctrlKey&&i.key==="y"&&(i.preventDefault(),this.actionStack.redo()),i.ctrlKey&&i.key==="z"&&(i.preventDefault(),this.actionStack.undo()),i.key==="+"&&(i.preventDefault(),this.zoomBy(this.zoomFactor)),i.key==="-"&&(i.preventDefault(),this.zoomBy(1/this.zoomFactor)),i.key===at.ArrowLeft&&(i.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),i.key===at.ArrowRight&&(i.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),i.key===at.ArrowDown&&(i.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),i.key===at.ArrowUp&&(i.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const r=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%"),a=r.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(S.MouseMove,i=>{if(this.unfinishedConnection!==void 0){const o=this.getPointerLocationRelativeToCanvas(i);this.unfinishedConnection.endCoords=o}}).on(S.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null)))}).on(S.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null))),this.contextMenu.close(),this.userSelection.size()>0){const i=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(i,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(E.drag().filter(i=>this.multipleSelectionOn||ft(i)).on(A.Start,i=>{this.startMultipleSelection(i)}).on(A.Drag,i=>{this.continueMultipleSelection(i)}).on(A.End,i=>{this.finishMultipleSelection(i)})).call(this.zoomBehavior=E.zoom().on(se.Zoom,i=>{if(i.sourceEvent){if(!this.canUserPerformAction(k.Zoom)){x(M.NotAllowed);return}i.sourceEvent.type===S.Wheel&&i.sourceEvent.wheelDelta!==void 0?(i.sourceEvent.wheelDelta>0&&x(M.ZoomIn),i.sourceEvent.wheelDelta<0&&x(M.ZoomOut)):i.sourceEvent.type===S.MouseMove&&x(M.AllScroll)}this.zoomTransform=i.transform;const o=i.transform.toString();this.selectCanvasElements().attr("transform",o),E.select(`#${this.backgroundPatternId}`).attr("patternTransform",o),this.contextMenu.close()}).on(se.End,()=>{x()})),l=r.append("defs");if(this.gridSize>0&&isFinite(this.gridSize)){const i=l.append("pattern").attr("id",this.backgroundPatternId).attr("x",-this.gridSize/2).attr("y",-this.gridSize/2).attr("width",this.gridSize).attr("height",this.gridSize).attr("patternUnits","userSpaceOnUse");i.append("rect").attr("x",0).attr("y",0).attr("width",this.gridSize).attr("height",this.gridSize).attr("fill",this.backgroundColor),i.append("circle").attr("cx",this.gridSize/2).attr("cy",this.gridSize/2).attr("r",this.gridSize*this.gridThickness).attr("fill",this.gridColor),a.attr("fill",`url(#${this.backgroundPatternId})`)}r.append("g").attr("class","daga-canvas-elements")}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView().select("rect"),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView().select("rect"),t)}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView().select("rect"),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView().select("rect"),t,e)}center(){var t;if(this.model.nodes.length>0){const e=(t=this.selectCanvasView().select("rect").node())==null?void 0:t.getBBox(),r=this.model.nodes.all(),a=Math.min(...r.map(c=>c.coords[0])),l=Math.max(...r.map(c=>c.coords[0]+c.width)),i=(a+l)/2,o=l-a,n=e.width,d=Math.min(...r.map(c=>c.coords[1])),g=Math.max(...r.map(c=>c.coords[1]+c.height)),h=(d+g)/2,m=g-d,p=e.height,u=Math.min(n/o,p/m,1);this.translateTo(i,h),this.zoomTo(u)}}getClosestGridPoint(t){return this.gridSize===0||!isFinite(this.gridSize)?t:[Math.round(t[0]/this.gridSize)*this.gridSize,Math.round(t[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){var r;const t=(r=this.selectSVGElement().node())==null?void 0:r.getBoundingClientRect(),e=[(t==null?void 0:t.width)||0,(t==null?void 0:t.height)||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return E.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return E.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return E.pointer(this.getEventHoldingCoordinates(t),E.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.look.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const l=a.merge(e);r.remove(),a.on(S.MouseOver,(i,o)=>{this.dragging||(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)))}).on(S.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const n=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(n,!1))}this.userSelection.toggle(o),this.diagramEvent$.next(new O([o],o.selected))}).on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)),this.userSelection.add(o),this.diagramEvent$.next(new O([o],!0)),this.contextMenu.open(i))}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,o)}).on(A.Drag,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,o)}).on(A.End,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,o),this.secondaryButton=!1})),a.filter(".shaped-look").append("path"),a.filter(".image-look").append("image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none"),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x(M.EWResize)}).on(S.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed?(x(M.EWResize),this.currentAction=new B(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed){const n=this.getPointerLocationRelativeToCanvas(i);o.stretch(y.Left,o.coords[0]-n[0])}}).on(A.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchNode){let n=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(n=this.getClosestGridPoint(n)),o.stretch(y.Left,o.coords[0]-n[0]),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x(M.NSResize)}).on(S.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed?(x(M.NSResize),this.currentAction=new B(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed){const n=this.getPointerLocationRelativeToCanvas(i);o.stretch(y.Top,o.coords[1]-n[1])}}).on(A.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchNode){let n=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(n=this.getClosestGridPoint(n)),o.stretch(y.Top,o.coords[1]-n[1]),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x(M.EWResize)}).on(S.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed?(x(M.EWResize),this.currentAction=new B(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed){const n=this.getPointerLocationRelativeToCanvas(i);o.stretch(y.Right,n[0]-(o.coords[0]+o.width))}}).on(A.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchNode){let n=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(n=this.getClosestGridPoint(n)),o.stretch(y.Right,n[0]-(o.coords[0]+o.width)),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x(M.NSResize)}).on(S.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed?(x(M.NSResize),this.currentAction=new B(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed){const n=this.getPointerLocationRelativeToCanvas(i);o.stretch(y.Bottom,n[1]-(o.coords[1]+o.height))}}).on(A.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchNode){let n=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(n=this.getClosestGridPoint(n)),o.stretch(y.Bottom,n[1]-(o.coords[1]+o.height)),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),l.filter(".shaped-look").select("path").attr("d",i=>Gt(i.type.look.shape,0,0,i.width,i.height)).attr("fill",i=>i.selected?i.type.look.selectedFillColor:i.type.look.fillColor).attr("stroke",i=>i.selected?i.type.look.selectedBorderColor:i.type.look.borderColor).attr("stroke-width",i=>`${i.highlighted?3:1}px`),l.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",i=>i.width).attr("height",i=>i.height).attr("href",i=>i.selected?i.type.look.selectedBackgroundImage:i.type.look.backgroundImage),l.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTopLeft:i.type.look.backgroundImageTopLeft),l.filter(".stretchable-image-look").select("image.top-image").attr("x",i=>i.type.look.leftMargin).attr("y",0).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTop:i.type.look.backgroundImageTop),l.filter(".stretchable-image-look").select("image.top-right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",0).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTopRight:i.type.look.backgroundImageTopRight),l.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageLeft:i.type.look.backgroundImageLeft),l.filter(".stretchable-image-look").select("image.center-image").attr("x",i=>i.type.look.leftMargin).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageCenter:i.type.look.backgroundImageCenter),l.filter(".stretchable-image-look").select("image.right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageRight:i.type.look.backgroundImageRight),l.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottomLeft:i.type.look.backgroundImageBottomLeft),l.filter(".stretchable-image-look").select("image.bottom-image").attr("x",i=>i.type.look.leftMargin).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottom:i.type.look.backgroundImageBottom),l.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottomRight:i.type.look.backgroundImageBottomRight),l.filter(".resizable-x").select("line.left-resizer").attr("x1",V/2).attr("x2",V/2).attr("y1",0).attr("y2",i=>i.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",V/2).attr("y2",V/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-V/2).attr("x2",i=>i.width-V/2).attr("y1",0).attr("y2",i=>i.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-V/2).attr("y2",i=>i.height-V/2)}updateSectionsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>{var o,n,d,g,h,m;return`diagram-section${(n=(o=i.node)==null?void 0:o.type)!=null&&n.resizableX?" resizable-x":""}${(g=(d=i.node)==null?void 0:d.type)!=null&&g.resizableY?" resizable-y":""} ${(m=(h=i.getConfig())==null?void 0:h.look)==null?void 0:m.lookType}`});t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const l=a.merge(e);r.remove(),a.on(S.MouseOver,(i,o)=>{this.dragging||(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)))}).on(S.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(d,!1))}const n=pt(o);this.userSelection.toggle(n),this.diagramEvent$.next(new O([n],n.selected))}).on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=pt(o);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new O([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const n=o==null?void 0:o.node;n?this.startMovingNode(i,n):x(M.NotAllowed)}}).on(A.Drag,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const n=o==null?void 0:o.node;n?this.continueMovingNode(i,n):x(M.NotAllowed)}}).on(A.End,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const n=o==null?void 0:o.node;n?this.finishMovingNode(i,n):x()}this.secondaryButton=!1})),a.filter(".shaped-look").append("path"),a.filter(".image-look").append("image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none"),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&x(M.EWResize)}).on(S.MouseOut,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed?(x(M.EWResize),this.currentAction=new B(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed){const g=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(y.Left,o.coords[0]-g[0],o.indexXInNode,o.indexYInNode)}}).on(A.End,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchSection){let g=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(g=this.getClosestGridPoint(g)),o.node.stretchSections(y.Left,o.coords[0]-g[0],o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&x(M.NSResize)}).on(S.MouseOut,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed?(x(M.NSResize),this.currentAction=new B(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed){const g=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(y.Top,o.coords[1]-g[1],o.indexXInNode,o.indexYInNode)}}).on(A.End,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchSection){let g=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(g=this.getClosestGridPoint(g)),o.node.stretchSections(y.Top,o.coords[1]-g[1],o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&x(M.EWResize)}).on(S.MouseOut,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed?(x(M.EWResize),this.currentAction=new B(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed){const g=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(y.Right,g[0]-(o.coords[0]+o.width),o.indexXInNode,o.indexYInNode)}}).on(A.End,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchSection){let g=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(g=this.getClosestGridPoint(g)),o.node.stretchSections(y.Right,g[0]-(o.coords[0]+o.width),o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&x(M.NSResize)}).on(S.MouseOut,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed?(x(M.NSResize),this.currentAction=new B(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed){const g=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(y.Bottom,g[1]-(o.coords[1]+o.height),o.indexXInNode,o.indexYInNode)}}).on(A.End,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchSection){let g=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(g=this.getClosestGridPoint(g)),o.node.stretchSections(y.Bottom,g[1]-(o.coords[1]+o.height),o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),l.filter(".shaped-look").select("path").attr("d",i=>{var o;return Gt(((o=i.getConfig())==null?void 0:o.look).shape,0,0,i.width,i.height)}).attr("fill",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedFillColor:((n=i.getConfig())==null?void 0:n.look).fillColor}).attr("stroke",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBorderColor:((n=i.getConfig())==null?void 0:n.look).borderColor}).attr("stroke-width",i=>`${i.highlighted?3:1}px`),l.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",i=>i.width).attr("height",i=>i.height).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImage:((n=i.getConfig())==null?void 0:n.look).backgroundImage}),l.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageTopLeft:((n=i.getConfig())==null?void 0:n.look).backgroundImageTopLeft}),l.filter(".stretchable-image-look").select("image.top-image").attr("x",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("y",0).attr("width",i=>{var o,n;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin-((n=i.getConfig())==null?void 0:n.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageTop:((n=i.getConfig())==null?void 0:n.look).backgroundImageTop}),l.filter(".stretchable-image-look").select("image.top-right-image").attr("x",i=>{var o;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("y",0).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageTopRight:((n=i.getConfig())==null?void 0:n.look).backgroundImageTopRight}),l.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("height",i=>{var o,n;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin-((n=i.getConfig())==null?void 0:n.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageLeft:((n=i.getConfig())==null?void 0:n.look).backgroundImageLeft}),l.filter(".stretchable-image-look").select("image.center-image").attr("x",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("y",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("width",i=>{var o,n;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin-((n=i.getConfig())==null?void 0:n.look).leftMargin}).attr("height",i=>{var o,n;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin-((n=i.getConfig())==null?void 0:n.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageCenter:((n=i.getConfig())==null?void 0:n.look).backgroundImageCenter}),l.filter(".stretchable-image-look").select("image.right-image").attr("x",i=>{var o;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("y",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("height",i=>{var o,n;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin-((n=i.getConfig())==null?void 0:n.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageRight:((n=i.getConfig())==null?void 0:n.look).backgroundImageRight}),l.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",i=>{var o;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageBottomLeft:((n=i.getConfig())==null?void 0:n.look).backgroundImageBottomLeft}),l.filter(".stretchable-image-look").select("image.bottom-image").attr("x",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("y",i=>{var o;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("width",i=>{var o,n;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin-((n=i.getConfig())==null?void 0:n.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageBottom:((n=i.getConfig())==null?void 0:n.look).backgroundImageBottom}),l.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",i=>{var o;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("y",i=>{var o;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageBottomRight:((n=i.getConfig())==null?void 0:n.look).backgroundImageBottomRight}),l.filter(".resizable-x").select("line.left-resizer").attr("x1",V/2).attr("x2",V/2).attr("y1",0).attr("y2",i=>i.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",V/2).attr("y2",V/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-V/2).attr("x2",i=>i.width-V/2).attr("y1",0).attr("y2",i=>i.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-V/2).attr("y2",i=>i.height-V/2)}updatePortsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>{var o,n;return`diagram-port ${((n=(o=i.type)==null?void 0:o.look)==null?void 0:n.lookType)||"default"}`});t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const l=a.merge(e);r.remove(),a.on(S.MouseOver,(i,o)=>{var n,d,g,h,m,p,u,c,f,v,w,b;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((g=(d=(n=this.unfinishedConnection.start)==null?void 0:n.getNode())==null?void 0:d.type)==null?void 0:g.id)||"")&&((h=this.unfinishedConnection.start)!=null&&h.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((p=(m=o.getNode())==null?void 0:m.type)==null?void 0:p.id)||"")&&o.allowsIncoming||this.unfinishedConnection.type.canStartFromType(((c=(u=o.getNode())==null?void 0:u.type)==null?void 0:c.id)||"")&&o.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(((w=(v=(f=this.unfinishedConnection.start)==null?void 0:f.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&((b=this.unfinishedConnection.start)!=null&&b.allowsIncoming)||x(M.NoDrop))}).on(S.MouseOut,()=>{this.unfinishedConnection&&x(M.Grabbing)}).on(S.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(d,!1))}const n=pt(o);this.userSelection.toggle(n),this.diagramEvent$.next(new O([n],n.selected))}).on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=pt(o);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new O([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(k.AddConnection)&&!o.removed?(x(M.Grabbing),this.startConnection(o),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d,g,h;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(k.AddConnection)&&!o.removed&&this.unfinishedConnection!==void 0){const m=[i.x,i.y];(g=this.unfinishedConnectionTracer)==null||g.attr("d",oe(this.unfinishedConnection.type.shape,this.unfinishedConnection.startCoords,m,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.width,(n=this.unfinishedConnection.startMarkerLook)==null?void 0:n.markerWidth,(d=this.unfinishedConnection.endMarkerLook)==null?void 0:d.markerWidth));const p=(h=this.unfinishedConnectionTracer)==null?void 0:h.node();if(p){let u=2;const c=p.getTotalLength();c<u&&(u=0);const f=p.getPointAtLength(c-u);this.unfinishedConnection.endCoords=[f.x,f.y]}else this.unfinishedConnection.endCoords=m;if(this.updateConnectionsInView(ie),this.model.ports.length>0){const u=this.getPointerLocationRelativeToCanvas(i);let c=Number.POSITIVE_INFINITY,f;for(const v of this.model.ports){const w=v.distanceTo(u);w<c&&(c=w,f=v)}f&&c<bo?this.userHighlight.focusOn(f):this.userHighlight.clear()}}}).on(A.End,(i,o)=>{var n;if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(k.AddConnection)&&!o.removed){(n=this.unfinishedConnectionTracer)==null||n.remove();const d=this.userHighlight.getFocus();if(d instanceof mt)this.finishConnection(d);else if(d instanceof lt&&d.rootElement instanceof mt)this.finishConnection(d.rootElement);else if(d instanceof L||d instanceof Y||d instanceof lt){let g;if(d instanceof L||d instanceof Y)g=d;else if(d.rootElement instanceof L||d.rootElement instanceof Y)g=d.rootElement;else{this.dropConnection();return}const h=g.getClosestPortToPoint([i.x,i.y]);h!==void 0?this.finishConnection(h):this.dropConnection()}else this.dropConnection()}x()}this.secondaryButton=!1})),a.filter(".default").append("circle"),a.filter(".image-look").append("image"),l.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),l.filter(".default").select("circle").attr("cx",0).attr("cy",0).attr("r",ai.width/2).attr("fill",i=>i.selected?Ke.selectedColor:Ke.highlightedColor).attr("opacity",i=>i.highlighted||i.selected?.5:0),l.filter(".image-look").select("image").attr("x",i=>-i.type.width/2).attr("y",i=>-i.type.width/2).attr("width",i=>i.type.width).attr("height",i=>i.type.width).attr("href",i=>{var o,n;return i.selected?((o=i.type)==null?void 0:o.look).selectedBackgroundImage:((n=i.type)==null?void 0:n.look).backgroundImage})}updateConnectionsInView(...t){const e=this.model.connections.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let r=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,o=>o.id);const a=r.exit(),l=r.enter().append("g").attr("id",o=>o.id).attr("class","diagram-connection");t&&t.length>0&&(r=r.filter(o=>t.includes(o.id)));const i=l.merge(r);a.remove(),l.on(S.MouseOver,(o,n)=>{n.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(d,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new O([n],n.selected))}).on(S.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const d=new ut(o,n);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(o.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)),this.userSelection.add(n),this.diagramEvent$.next(new O([n],!0)),this.contextMenu.open(o))}).on(S.DoubleClick,(o,n)=>{const d=new gt(o,n);this.diagramEvent$.next(d)}).call(E.drag().filter(o=>(this.secondaryButton=ft(o),!0)).on(A.Start,o=>{this.startMultipleSelection(o)}).on(A.Drag,o=>{this.continueMultipleSelection(o)}).on(A.End,o=>{this.finishMultipleSelection(o)})),l.append("path").attr("class","diagram-connection-path"),l.append("path").attr("class","diagram-connection-path-box"),l.append("marker").attr("id",o=>`${o.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),l.append("marker").attr("id",o=>`${o.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),l.append("g").attr("class","diagram-connection-start-label"),l.select("g.diagram-connection-start-label").append("path"),l.select("g.diagram-connection-start-label").append("text").style("user-select","none"),l.append("g").attr("class","diagram-connection-middle-label"),l.select("g.diagram-connection-middle-label").append("path"),l.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),l.append("g").attr("class","diagram-connection-end-label"),l.select("g.diagram-connection-end-label").append("path"),l.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",o=>o.removed?.5:1).select("path.diagram-connection-path").attr("d",o=>{var n,d;return oe(o.type.shape,o.startCoords,o.endCoords,o.startDirection,o.endDirection,o.type.width,(n=o.startMarkerLook)==null?void 0:n.markerWidth,(d=o.endMarkerLook)==null?void 0:d.markerWidth)}).attr("marker-start",o=>`url(#${o.id}-start-marker)`).attr("marker-end",o=>`url(#${o.id}-end-marker)`).attr("stroke",o=>o.selected?o.type.selectedColor:o.type.color).attr("stroke-width",o=>`${o.highlighted?o.type.width+1:o.type.width}px`).attr("stroke-dasharray",o=>Ue(o.type.style,o.type.width)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",o=>{var n,d;return oe(o.type.shape,o.startCoords,o.endCoords,o.startDirection,o.endDirection,o.type.width,(n=o.startMarkerLook)==null?void 0:n.markerWidth,(d=o.endMarkerLook)==null?void 0:d.markerWidth)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",o=>`${o.type.width+po}px`).attr("stroke-dasharray",o=>Ue(o.type.style,o.type.width)).attr("fill","none"),i.data().forEach(o=>{this.updateConnectionLabelsInView(o),this.updateConnectionMarkersInView(o)})}updateFieldsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const l=a.merge(e);r.remove(),a.style("box-sizing","border-box").on(S.MouseOver,(i,o)=>{this.dragging||(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)))}).on(S.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(d,!1))}const n=pt(o);this.userSelection.toggle(n),this.diagramEvent$.next(new O([n],n.selected))}).on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=pt(o);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new O([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.EditField)&&o.editable&&!o.removed&&(this.currentAction=new qe(this,o.id,o.text,""),this.createInputField(o.text,o.coords,o.width,o.height,o.fontSize,o.fontFamily||z.fontFamily,d=>{o.text=d},d=>{o.text=d,this.currentAction instanceof qe&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let n;o.rootElement instanceof L?n=o.rootElement:o.rootElement instanceof Y&&(n=o.rootElement.node),n?this.startMovingNode(i,n):x(M.NotAllowed)}}).on(A.Drag,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let n;o.rootElement instanceof L?n=o.rootElement:o.rootElement instanceof Y&&(n=o.rootElement.node),n?this.continueMovingNode(i,n):x(M.NotAllowed)}}).on(A.End,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let n;o.rootElement instanceof L?n=o.rootElement:o.rootElement instanceof Y&&(n=o.rootElement.node),n?this.finishMovingNode(i,n):x()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),l.attr("x",0).attr("y",0).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("div").style("justify-content",i=>i.horizontalAlign===xt.Center?"center":i.horizontalAlign===xt.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Bt.Center?"center":i.verticalAlign===Bt.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":"100%").style("max-height",i=>i.fit?"default":"100%").style("overflow",i=>i.fit?"default":"hidden").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===xt.Center?"center":i.horizontalAlign===xt.Right?"end":"start").style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"))}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),a.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),r.remove(),a.on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,i=>{this.startMultipleSelection(i)}).on(A.Drag,i=>{this.continueMultipleSelection(i)}).on(A.End,i=>{this.finishMultipleSelection(i)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),a.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),r.remove(),a.on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,i=>{this.startMultipleSelection(i)}).on(A.Drag,i=>{this.continueMultipleSelection(i)}).on(A.End,i=>{this.finishMultipleSelection(i)}))}updateConnectionLabelsInView(t){var i,o,n;const e=this.selectCanvasView().select(`g.diagram-connection#${t.id}`),a=e.select("path").node(),l={...z,...t.type.label};if(a){const d=a.getTotalLength();e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.startLabel);const g=(i=e.select("g.diagram-connection-start-label text").node())==null?void 0:i.getBoundingClientRect();if(g){const p=t.startLabel?g.width/this.zoomTransform.k+$t(l)+Et(l):0,u=t.startLabel?g.height/this.zoomTransform.k+Mt(l)+Tt(l):0,c=a.getPointAtLength(Math.max(X(l)+p/2,nt(l)+p/2,F(l)+u/2,et(l)+u/2));e.select("g.diagram-connection-start-label path").attr("d",jt(-p/2,-u/2,p,u)).attr("fill",t.selected?t.type.selectedColor:t.type.color).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${c.x},${c.y})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.middleLabel);const h=(o=e.select("g.diagram-connection-middle-label text").node())==null?void 0:o.getBoundingClientRect();if(h){const p=t.middleLabel?h.width/this.zoomTransform.k+$t(l)+Et(l):0,u=t.middleLabel?h.height/this.zoomTransform.k+Mt(l)+Tt(l):0,c=a.getPointAtLength(d/2);e.select("g.diagram-connection-middle-label path").attr("d",jt(-p/2,-u/2,p,u)).attr("fill",t.selected?t.type.selectedColor:t.type.color).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${c.x},${c.y})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.endLabel);const m=(n=e.select("g.diagram-connection-end-label text").node())==null?void 0:n.getBoundingClientRect();if(m){const p=t.endLabel?m.width/this.zoomTransform.k+$t(l)+Et(l):0,u=t.endLabel?m.height/this.zoomTransform.k+Mt(l)+Tt(l):0,c=a.getPointAtLength(d-Math.max(X(l)+p/2,nt(l)+p/2,F(l)+u/2,et(l)+u/2));e.select("g.diagram-connection-end-label path").attr("d",jt(-p/2,-u/2,p,u)).attr("fill",t.selected?t.type.selectedColor:t.type.color).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${c.x},${c.y})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`g.diagram-connection#${t.id}`),r=e.select("marker.diagram-connection-start-marker"),a=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?r.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.markerWidth).attr("markerHeight",t.startMarkerLook.markerHeight).attr("refX",t.startMarkerLook.markerRefX).attr("refY",t.startMarkerLook.markerRefY).select("image").attr("href",t.selected?t.startMarkerLook.selectedImage:t.startMarkerLook.image).attr("width",t.startMarkerLook.markerWidth).attr("height",t.startMarkerLook.markerHeight):r.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.markerWidth).attr("markerHeight",t.endMarkerLook.markerHeight).attr("refX",t.endMarkerLook.markerRefX).attr("refY",t.endMarkerLook.markerRefY).select("image").attr("href",t.selected?t.endMarkerLook.selectedImage:t.endMarkerLook.image).attr("width",t.endMarkerLook.markerWidth).attr("height",t.endMarkerLook.markerHeight):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fitFieldRootInView(t){var r,a,l,i,o,n,d,g,h,m,p;const e=this.model.fields.get(t);if(e){if(e.rootElement instanceof L&&e.fit){const u=this.minimumSizeOfField(e);let c=u[0]+X(e.rootElement.type.label)+nt(e.rootElement.type.label)-e.rootElement.width,f=u[1]+F(e.rootElement.type.label)+et(e.rootElement.type.label)-e.rootElement.height;this.snapToGrid&&(c=Math.ceil(c/this.gridSize)*this.gridSize,f=Math.ceil(f/this.gridSize)*this.gridSize),e.rootElement.width+c<e.rootElement.type.minWidth&&(c=e.rootElement.type.minWidth-e.rootElement.width),e.rootElement.height+f<e.rootElement.type.minHeight&&(f=e.rootElement.type.minHeight-e.rootElement.height),e.rootElement.stretch(y.Right,c),e.rootElement.stretch(y.Bottom,f)}if(e.rootElement instanceof Y&&e.fit){const u=this.minimumSizeOfField(e);let c=u[0],f=u[1];for(const b of((r=e.rootElement.node)==null?void 0:r.sections)||[])b.label&&(b.indexXInNode===e.rootElement.indexXInNode&&b.indexYInNode!==e.rootElement.indexYInNode?c=Math.max(c,this.minimumSizeOfField(b.label)[0]):b.indexXInNode!==e.rootElement.indexXInNode&&b.indexYInNode===e.rootElement.indexYInNode&&(f=Math.max(f,this.minimumSizeOfField(b.label)[1])));u[0]<c&&(u[0]=c),u[1]<f&&(u[1]=f);let v=u[0]+X((l=(a=e.rootElement)==null?void 0:a.getConfig())==null?void 0:l.label)+nt((o=(i=e.rootElement)==null?void 0:i.getConfig())==null?void 0:o.label)-e.rootElement.width,w=u[1]+F((d=(n=e.rootElement)==null?void 0:n.getConfig())==null?void 0:d.label)+et((h=(g=e.rootElement)==null?void 0:g.getConfig())==null?void 0:h.label)-e.rootElement.height;this.snapToGrid&&(v=Math.ceil(v/this.gridSize)*this.gridSize,w=Math.ceil(w/this.gridSize)*this.gridSize),e.rootElement.width+v<(e.rootElement.getMinWidth()||0)&&(v=(e.rootElement.getMinWidth()||0)-e.rootElement.width),e.rootElement.height+w<(e.rootElement.getMinHeight()||0)&&(w=(e.rootElement.getMinHeight()||0)-e.rootElement.height),(m=e.rootElement.node)==null||m.stretchSections(y.Right,v,e.rootElement.indexXInNode,e.rootElement.indexYInNode),(p=e.rootElement.node)==null||p.stretchSections(y.Bottom,w,e.rootElement.indexXInNode,e.rootElement.indexYInNode)}}}fitNodeInView(t){var r,a;const e=this.model.nodes.get(t);if(e&&e.sections.length>0&&this.priorityThreshold){let l=0,i=0;for(const o of e.sections)if(o.getPriority()>=this.priorityThreshold){const n=o.coords[0]+o.width-e.coords[0],d=o.coords[1]+o.height-e.coords[1];l=Math.max(l,n),i=Math.max(i,d)}l+=((r=e.type.sectionGrid)==null?void 0:r.margin)||0,i+=((a=e.type.sectionGrid)==null?void 0:a.margin)||0,e.stretch(y.Right,l-e.width),e.stretch(y.Bottom,i-e.height)}}selectRoot(){return E.select(this.diagramRoot)}selectSVGElement(){return E.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){var e,r,a,l;if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(((r=(e=t.getNode())==null?void 0:e.type)==null?void 0:r.id)||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(((l=(a=t.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&t.allowsIncoming))this.unfinishedConnection=new st(this.model,this.connectionType,t,void 0,ie);else if(this.inferConnectionType){let i=this.model.connections.types.all().find(o=>{var n,d;return t.allowsOutgoing&&o.canStartFromType(((d=(n=t.getNode())==null?void 0:n.type)==null?void 0:d.id)||"")});i===void 0&&(i=this.model.connections.types.all().find(o=>{var n,d;return t.allowsIncoming&&o.canFinishOnType(((d=(n=t.getNode())==null?void 0:n.type)==null?void 0:d.id)||"")})),i!==void 0&&(this.unfinishedConnection=new st(this.model,i,t,void 0,ie))}}}finishConnection(t){var e,r,a,l,i,o,n,d,g,h,m,p,u,c,f,v,w,b,$,I;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0)if(this.unfinishedConnection.start!==t)if(this.unfinishedConnection.type.canStartFromType(((l=(a=(r=(e=this.unfinishedConnection)==null?void 0:e.start)==null?void 0:r.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&((o=(i=this.unfinishedConnection)==null?void 0:i.start)!=null&&o.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((d=(n=t.getNode())==null?void 0:n.type)==null?void 0:d.id)||"")&&t.allowsIncoming){const T=new ee(this,this.unfinishedConnection.type,(g=this.unfinishedConnection.start)==null?void 0:g.id,t.id);this.dropConnection(),T.do(),this.actionStack.add(T)}else if(this.unfinishedConnection.type.canFinishOnType(((u=(p=(m=(h=this.unfinishedConnection)==null?void 0:h.start)==null?void 0:m.getNode())==null?void 0:p.type)==null?void 0:u.id)||"")&&((f=(c=this.unfinishedConnection)==null?void 0:c.start)!=null&&f.allowsIncoming)&&this.unfinishedConnection.type.canStartFromType(((w=(v=t.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&t.allowsOutgoing){const T=new ee(this,this.unfinishedConnection.type,t.id,(b=this.unfinishedConnection.start)==null?void 0:b.id);this.dropConnection(),T.do(),this.actionStack.add(T)}else if(this.inferConnectionType){let T=this.model.connections.types.all().find(P=>{var W,Z,G,U,H,q,D,rt;return P.canStartFromType(((U=(G=(Z=(W=this.unfinishedConnection)==null?void 0:W.start)==null?void 0:Z.getNode())==null?void 0:G.type)==null?void 0:U.id)||"")&&((q=(H=this.unfinishedConnection)==null?void 0:H.start)==null?void 0:q.allowsOutgoing)&&P.canFinishOnType(((rt=(D=t.getNode())==null?void 0:D.type)==null?void 0:rt.id)||"")&&t.allowsIncoming}),N=!1;if(T===void 0&&(T=this.model.connections.types.all().find(P=>{var W,Z,G,U,H,q,D,rt;return P.canFinishOnType(((U=(G=(Z=(W=this.unfinishedConnection)==null?void 0:W.start)==null?void 0:Z.getNode())==null?void 0:G.type)==null?void 0:U.id)||"")&&((q=(H=this.unfinishedConnection)==null?void 0:H.start)==null?void 0:q.allowsIncoming)&&P.canStartFromType(((rt=(D=t.getNode())==null?void 0:D.type)==null?void 0:rt.id)||"")&&t.allowsOutgoing}),N=!0),T!==void 0){const P=new ee(this,T,N?t.id:($=this.unfinishedConnection.start)==null?void 0:$.id,N?(I=this.unfinishedConnection.start)==null?void 0:I.id:t.id);this.dropConnection(),P.do(),this.actionStack.add(P)}else this.dropConnection()}else this.dropConnection();else this.dropConnection()}dropConnection(){var t,e,r,a;(t=this.unfinishedConnection)==null||t.setStart(void 0),(e=this.unfinishedConnection)==null||e.setEnd(void 0),(a=(r=this.unfinishedConnection)==null?void 0:r.select())==null||a.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(t){return this.userActions[t]!==!1}createInputField(t,e,r,a,l,i,o,n){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${r}px`).attr("height",`${a}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const g=d.append("xhtml:textarea");let h,m;g.text(t).style("box-sizing","border-box").style("width",`${r}px`).style("height",`${a}px`).style("font-size",`${l}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(S.KeyDown,u=>{u.stopPropagation()}).on(S.KeyUp,u=>{if(u.stopPropagation(),u.key===at.Escape){const c=g.property("value");this.removeInputField(),n&&n(c)}}).on(S.Input,()=>{const u=g.property("value");g.attr("cols",$i(u)+1),g.attr("rows",Ei(u)+1),g.style("width",""),g.style("height",""),h=g.property("scrollWidth")+1,m=g.property("scrollHeight")+1;const c=Math.max(h,r),f=Math.max(m,a);d==null||d.attr("width",`${c}px`),g.style("width",`${c}px`),d==null||d.attr("height",`${f}px`),g.style("height",`${f}px`),o&&o(u)}).on(S.Click,u=>{u.stopPropagation()}).on(S.FocusOut,()=>{const u=g.property("value");this.removeInputField(),n&&n(u)});const p=g.node();p.focus(),p.select()}removeInputField(){var t,e,r;(e=(t=this.inputFieldContainer)==null?void 0:t.select("input"))==null||e.on(S.Blur,null),(r=this.inputFieldContainer)==null||r.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){var a,l;const e=(l=(a=t.select())==null?void 0:a.select("p"))==null?void 0:l.node();if(!e)return[0,0];const r=e.getBoundingClientRect();return[r.width/this.zoomTransform.k,r.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed)if(x(M.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(r=>r instanceof L)>1)this.currentAction=new te(this,this.userSelection.filter(r=>r instanceof L).map(r=>r.id),e.coords);else{const r=e.getLastAncestor();this.currentAction=new B(this,k.MoveNode,e.id,e.getGeometry(),e.getGeometry(),r==null?void 0:r.id,r==null?void 0:r.getGeometry(e.id),r==null?void 0:r.getGeometry(e.id))}else x(M.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&(this.currentAction instanceof te||this.currentAction instanceof B)&&!e.removed){const r=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([r[0]-e.coords[0],r[1]-e.coords[1]]):e.move(r),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){var r,a,l;if(this.canUserPerformAction(k.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let i=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(i=this.getClosestGridPoint(i)),this.currentAction instanceof te){const o=this.currentAction.delta;this.currentAction.delta=[i[0]-o[0],i[1]-o[1]],e.selected?this.userSelection.move([o[0]-e.coords[0],o[1]-e.coords[1]]):e.move(o)}else if(this.currentAction instanceof B){e.move(i);const n=this.model.nodes.getAtCoordinates(t.x,t.y).filter(h=>h.id!==e.id&&!h.isDescendantOf(e)).filter(h=>h.type.childrenTypes.includes(e.type.id)),d=ri(n),g=d[d.length-1];if(g!==e.parent&&(e.type.canBeParentless||g!==void 0)){const h=g==null?void 0:g.getLastAncestor(),m=this.currentAction.from,p=new to(this,e.id,(r=e.parent)==null?void 0:r.id,g==null?void 0:g.id,m,e.getGeometry(),h==null?void 0:h.id,h==null?void 0:h.getGeometry(e.id),h==null?void 0:h.getGeometry(e.id));(a=e.parent)==null||a.removeChild(e),g!==void 0&&g.addChild(e),p.toChildGeometry=e.getGeometry(e.id),p.toAncestorGeometry=h==null?void 0:h.getGeometry(e.id),this.currentAction=p}else{const h=e==null?void 0:e.getLastAncestor();this.currentAction.ancestorId=h==null?void 0:h.id,this.currentAction.fromAncestorGeometry=h==null?void 0:h.getGeometry(e.id),(l=e.parent)==null||l.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=h==null?void 0:h.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}x(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectCanvasElements().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){var r,a,l,i;const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(x(M.Crosshair),(i=(l=(a=(r=this.multipleSelectionContainer)==null?void 0:r.attr("x",Math.min(this.draggingFrom[0],e[0])))==null?void 0:a.attr("y",Math.min(this.draggingFrom[1],e[1])))==null?void 0:l.attr("width",Math.abs(this.draggingFrom[0]-e[0])))==null||i.attr("height",Math.abs(this.draggingFrom[1]-e[1])),this.dragging=!0)}finishMultipleSelection(t){var r;const e=this.getPointerLocationRelativeToCanvas(t);(r=this.multipleSelectionContainer)==null||r.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)bi([a.coords,[a.coords[0]+a.width,a.coords[1]+a.height]],[this.draggingFrom,e])&&this.userSelection.add(a);this.multipleSelectionOn=!1,this.diagramEvent$.next(new O(this.userSelection.all(),!0)),x()}};Ut.canvasCount=0;let ae=Ut;const ft=s=>!!s.button,oe=(s,t,e,r,a,l,i,o)=>wi(s,[t,e],r,a,Math.max(10,i||0,o||0)*l),x=s=>{s?E.select("body").style("cursor",s):E.select("body").style("cursor",M.Auto)},pt=s=>s instanceof L?s:s instanceof Y?s.node||s:s.rootElement instanceof L||s.rootElement instanceof Y||s.rootElement instanceof mt?pt(s.rootElement):s;class hi{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const t of this.grid)t.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const t of this.grid)t.push(void 0)}addRowTop(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.splice(0,0,t),this.offsetY=this.offsetY+1}addRowBottom(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.push(t)}get(t){if(this.grid[t[1]+this.offsetY])return this.grid[t[1]+this.offsetY][t[0]+this.offsetX]}set(t,e){for(;t[0]<-this.offsetX;)this.addColumnLeft();for(;t[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;t[1]<-this.offsetY;)this.addRowTop();for(;t[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[t[1]+this.offsetY][t[0]+this.offsetX]=e}getClosestEmptyCoordinate(t){if(this.get(t)===void 0)return t;const e=[...t];for(let r=1;;++r){const a=r%2>0?r:-r,l=a>0?1:-1,i=[e[0]+a,e[1]+a];for(let o=e[0];o!==i[0]+l;o+=l)if(e[0]=o,this.get(e)===void 0)return e;for(let o=e[1];o!==i[1]+l;o+=l)if(e[1]=o,this.get(e)===void 0)return e}}}class vo{apply(t){var o;if(t.nodes.length===0)return t;const e=new hi,r=t.nodes.filter(n=>!n.parent);for(;r.length>0;)gi(r[0],e,[0,0],r);const a=Math.max(...t.nodes.map(n=>n.width)),l=Math.max(...t.nodes.map(n=>n.height)),i=(((o=t.canvas)==null?void 0:o.gridSize)||0)*2;for(let n=e.minY();n<=e.maxY();++n)for(let d=e.minX();d<=e.maxX();++d){const g=e.get([d,n]);g!==void 0&&g.move([d*(a+i),n*(l+i)])}return t}}const gi=(s,t,e,r)=>{const a=t.getClosestEmptyCoordinate(e);t.set(a,s),j(r,s);for(const l of s.getAdjacentNodes())r.includes(l)&&gi(l,t,a,r)};class wo{apply(t){var g;if(t.nodes.length===0)return t;const e=new hi,r=t.nodes.filter(h=>!h.parent),a={},l=r[0];let i=[l];for(a[l.id]=[0,0];r.length>0;){const h=[];for(const m of i){e.set(e.getClosestEmptyCoordinate(a[m.id]),m),j(r,m);const p=m.getAdjacentNodes();for(const u of p)r.includes(u)&&(h.push(u),a[u.id]=a[m.id])}if(h.length>0)i=h;else if(r.length>0){const m=r[0];i=[m],a[m.id]=e.getClosestEmptyCoordinate([0,0])}}const o=Math.max(...t.nodes.map(h=>h.width)),n=Math.max(...t.nodes.map(h=>h.height)),d=(((g=t.canvas)==null?void 0:g.gridSize)||0)*2;for(let h=e.minY();h<=e.maxY();++h)for(let m=e.minX();m<=e.maxX();++m){const p=e.get([m,h]);p!==void 0&&p.move([m*(o+d),h*(n+d)])}return t}}class qt{apply(t){var o;if(t.nodes.length===0)return t;const e=(((o=t.canvas)==null?void 0:o.gridSize)||0)*2;let r=t.nodes.filter(n=>!n.parent);const a=r[0];j(r,a);const l=[[a]];for(;r.length>0;){const n=l[l.length-1],d=[];for(const g of n){const h=g.getAdjacentNodes();for(const m of h)r.includes(m)&&(j(r,m),d.push(m))}d.length>0?l.push(d):(l.push(r),r=[])}let i=0;for(const n of l){let d=0;for(const h of n)h.move([i,d]),d+=e+h.height;const g=Math.max(...n.map(h=>h.width));i+=e+g}for(const n of t.connections)n.tighten();return t}}class Co{apply(t){var h;if(t.nodes.length===0)return t;new qt().apply(t);const e=(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,r=.99,a=1,l=.1,i=2e5,o=.5,n=1,d=.002;let g=100;for(;g>a;){g=g*r;const m=[0,0];{for(const p of t.nodes)m[0]=m[0]+p.coords[0]+p.width/2,m[1]=m[1]+p.coords[1]+p.width/2;m[0]=m[0]/t.nodes.length,m[1]=m[1]/t.nodes.length}for(const p of t.nodes){const u=p.getAdjacentNodes();for(const c of t.nodes){const f=[p.coords[0]+p.width/2,p.coords[1]+p.height/2],v=[c.coords[0]+c.width/2,c.coords[1]+c.height/2],w=Qe(p.coords,c.coords),b=[c.coords[0],c.coords[1]];if(u.includes(c)&&w>0&&(w>e+(Math.max(p.width,p.height)+Math.max(c.width,c.height))/2?(b[0]=b[0]-(v[0]-f[0])*l,b[1]=b[1]-(v[1]-f[1])*l):(b[0]=b[0]+(v[0]-f[0])*o,b[1]=b[1]+(v[1]-f[1])*o)),w>0){const $=i/(w*w);b[0]=b[0]+$*(v[0]-f[0])/w,b[1]=b[1]+$*(v[1]-f[1])/w}else b[0]=b[0]+n*(Math.random()*2-1),b[1]=b[1]+n*(Math.random()*2-1);b[0]=b[0]-(v[0]-m[0])*d,b[1]=b[1]-(v[1]-m[1])*d,b[0]-c.coords[0]>g?b[0]=c.coords[0]+g:b[0]-c.coords[0]<-g&&(b[0]=c.coords[0]-g),b[1]-c.coords[1]>g?b[1]=c.coords[1]+g:b[1]-c.coords[1]<-g&&(b[1]=c.coords[1]-g),c.move(b)}}}if(t.canvas&&t.canvas.snapToGrid)for(const m of t.nodes){const p=t.canvas.getClosestGridPoint(m.coords);m.move(p)}for(const m of t.connections)m.tighten();return t}}class ko{apply(t){var l;if(t.nodes.length===0)return t;const e=(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,r=t.nodes.filter(i=>!i.parent);r.sort((i,o)=>o.type.priority-i.type.priority);let a=0;for(const i of r)i.move([a,0]),a+=i.width+e;return t}}class xo{apply(t){var g;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(h=>h.getPriority())),r=Math.min(...t.nodes.map(h=>h.getPriority()));if(e===r)return new qt().apply(t),t;const a=(((g=t.canvas)==null?void 0:g.gridSize)||0)*2,l=t.nodes.filter(h=>!h.parent),i=[],o=t.nodes.filter(h=>!h.parent).filter(h=>h.getPriority()>=e),n=[];if(o.length>1){const h=o[0];o.splice(0,1),n.push(h);const m=[h],p=[h];for(;m.length>0;){const u=m[0];m.splice(0,1),o.includes(u)&&(n.push(u),j(o,u));const c=u.getAdjacentNodes();for(const f of c)p.includes(f)||(m.push(f),p.push(f))}for(const u of o)n.push(u)}else n.push(o[0]);for(const h of n)j(l,h),i.push([h]);for(i.push([]),l.sort((h,m)=>m.type.priority-h.type.priority);l.length>0;){const h=l[0];l.splice(0,1);const m=[h],p=[h];let u=!1;for(;m.length>0;){const c=m[0];m.splice(0,1);const f=n.indexOf(c);if(f>=0){i[f].push(h),u=!0;break}else{const v=c.getAdjacentNodes();for(const w of v)p.includes(w)||(m.push(w),p.push(w))}}u||i[i.length-1].push(h)}let d=0;for(let h=0;h<i.length;++h){let m=0;for(let u=0;u<i[h].length;++u){const c=i[h][u];c.move([d,m]),m+=a+c.height}const p=Math.max(...i[h].map(u=>u.width));d+=a+p}for(const h of t.connections)h.tighten();return t}}class Io{apply(t){var g;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(h=>h.getPriority())),r=Math.min(...t.nodes.map(h=>h.getPriority()));if(e===r)return new qt().apply(t),t;const a=(((g=t.canvas)==null?void 0:g.gridSize)||0)*2,l=t.nodes.filter(h=>!h.parent).sort((h,m)=>m.getPriority()-h.getPriority()),i=[];for(;l.length>0;){const h=l[0];l.splice(0,1);const m=new de(void 0,h);ui(m,l),i.push(m)}const o=[];for(const h of i)o.push([h]),fi(h,o,o.length);const n=Math.max(...t.nodes.map(h=>h.height));let d=0;for(let h=0;h<o.length;++h){let m=0;for(let u=0;u<o[h].length;++u){const c=o[h][u];c.node.move([d,m]),m+=(a+n)*c.countBranchHeight()}const p=Math.max(...o[h].map(u=>u.node.width));d+=a+p}for(const h of t.connections)h.tighten();return t}}const ui=(s,t)=>{for(const e of s.node.getAdjacentNodes().sort((r,a)=>a.getPriority()-r.getPriority())){const r=t.indexOf(e);if(r>=0){t.splice(r,1);const a=s.addBranch(e);ui(a,t)}}},fi=(s,t,e)=>{if(s.branches.length>0){for(;e>=t.length;)t.push([]);for(const r of s.branches)t[e].push(r),fi(r,t,e+1)}};class de{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new de(this,t);return e.depth=this.depth+1,this.branches.push(e),e}countBranchHeight(){if(this.branches.length<=0)return 1;{let t=0;for(const e of this.branches)t+=e.countBranchHeight();return t}}}class So{apply(t){var l;if(t.nodes.length===0)return t;const e=(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,r=t.nodes.filter(i=>!i.parent);r.sort((i,o)=>o.type.priority-i.type.priority);let a=0;for(const i of r)i.move([0,a]),a+=i.height+e;return t}}const Je={adjacency:new vo,breadth:new qt,"breadth-adjacency":new wo,force:new Co,horizontal:new ko,priority:new xo,tree:new Io,vertical:new So},Ao=R.createContext({}),bt=R.createContext({});class To{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){console.log("highlightProperty",t)}}const ce=({direction:s,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:r,disabled:a,rule:l,collapsedValue:i,visibleValue:o,onCollapse:n})=>{const[d,g]=R.useState(r),h=()=>{if(!a){const p=!d;g(p),n==null||n(p);let u;if(typeof t=="string")u=E.select(t),e&&(u=u.select(e));else{const c=t;if(!c)throw new Error("collapsableSelector is not a valid ref");u=E.select(c.current),e&&(u=u.select(e))}u.style(l,p?i:o)}},m=()=>{switch(s){case y.Right:return a?"daga-horizontal-none":d?"daga-horizontal-right":"daga-horizontal-left";case y.Bottom:return a?"daga-vertical-none":d?"daga-vertical-down":"daga-vertical-up";case y.Left:return a?"daga-horizontal-none":d?"daga-horizontal-left":"daga-horizontal-right";case y.Top:return a?"daga-vertical-none":d?"daga-vertical-up":"daga-vertical-down"}};return C.jsx("daga-collapse-button",{children:C.jsx("button",{className:`daga-collapse-button daga-${s}`,onClick:h,children:C.jsx("div",{className:m()})})})},$o=()=>{const s=R.useContext(bt),t=R.useRef(null),[e,r]=R.useState([]);yt.merge(s.validatorChange$,s.diagramChange$).pipe(yt.map(()=>a())).subscribe();const a=()=>{r([]);for(const i of s.validators){const o=i.validate(s.model);r(o)}},l=i=>{var o,n,d,g;if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const h=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);h&&s.userHighlight.add(h)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){s.userSelection.openInPropertyEditor(s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId));const h=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);h&&s.userHighlight.add(h),(n=(o=s.parentComponent)==null?void 0:o.propertyEditor)==null||n.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(s.userSelection.openInPropertyEditor(),(g=(d=s.parentComponent)==null?void 0:d.propertyEditor)==null||g.highlightProperty(...i.propertyNames))};return C.jsx("daga-errors",{children:C.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&C.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:C.jsx("span",{children:"No errors found"})}),e.length>0&&C.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[C.jsxs("span",{children:[e.length," errors found"]}),C.jsx("div",{className:"daga-collapse-button-container",children:C.jsx(ce,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:y.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&C.jsx("div",{className:"daga-error-panel",children:C.jsx("ol",{children:e.map((i,o)=>C.jsx("li",{onClick:()=>l(i),dangerouslySetInnerHTML:{__html:i.message}},o))})})]})})},Eo=({valueSet:s,onValueChange:t})=>{var o;const r=R.useContext(bt).canUserPerformAction(k.UpdateValues)&&((o=s==null?void 0:s.rootElement)==null?void 0:o.removed)!==!0,a=n=>"daga-property-name-"+n.replace(/\s/g,""),l=n=>{if(typeof n=="string")return n;if(n==null||isNaN(n.valueOf()))return"";const d=new Date(n),g=d.getTimezoneOffset();return d.setMinutes(d.getMinutes()-g),d.toISOString().substring(0,19)},i=n=>new Date(n);return C.jsx("daga-object-editor",{children:s.displayedProperties.map(n=>C.jsxs("div",{className:`daga-property ${a(n.name)}`,children:[C.jsx("p",{className:"daga-property-name",children:n.name}),n.type===tt.Text&&C.jsx("input",{type:"daga-text",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.TextArea&&C.jsx("textarea",{disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Number&&C.jsx("input",{type:"number",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Color&&C.jsx("input",{type:"text",pattern:"#\\d{6}",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Datetime&&C.jsx("input",{type:"datetime-local",disabled:!n.editable||!r,value:l(s==null?void 0:s.getValue(n.name)),onChange:d=>t(n,i(d.target.value))}),n.type===tt.Date&&C.jsx("input",{type:"date",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Time&&C.jsx("input",{type:"time",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Url&&C.jsx("input",{type:"url",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Boolean&&C.jsxs("div",{className:"daga-radio",children:[C.jsxs("label",{className:"daga-radio-item daga-radio-start",children:[C.jsx("input",{type:"radio",disabled:!n.editable||!r,name:n.name,value:"false",checked:(s==null?void 0:s.getValue(n.name))===!1,onChange:()=>t(n,!1)}),"No"]}),C.jsxs("label",{className:"daga-radio-item daga-radio-end",children:[C.jsx("input",{type:"radio",disabled:!n.editable||!r,name:n.name,value:"true",checked:(s==null?void 0:s.getValue(n.name))===!0,onChange:()=>t(n,!0)}),"Yes"]})]})]},n.name))})},mi=({valueSet:s,depth:t})=>{const e=R.useContext(bt),r=R.useRef(null),a=d=>"daga-property-name-"+d.replace(/\s/g,""),l=()=>{for(const d of(s==null?void 0:s.displayedProperties)||[]){let g=0,h=0,m=0;const p=E.select(r.current).select(`.daga-property.${a(d.name)}.daga-depth-${t}`);p.select("button.daga-move-button").call(E.drag().on(A.Start,u=>{var v;x(M.Grabbing);const c=e.getPointerLocationRelativeToScreen(u);if(c.length<2||isNaN(c[0])||isNaN(c[1]))return;const f=(v=p.node())==null?void 0:v.getBoundingClientRect();g=(f==null?void 0:f.width)||0,h=(f==null?void 0:f.height)||0,p.style("position","fixed").style("left",`${c[0]-g/2}px`).style("top",`${c[1]-h/2}px`).style("width",`${g}px`).style("height",`${h}px`).style("z-index",1)}).on(A.Drag,u=>{x(M.Grabbing);const c=e.getPointerLocationRelativeToScreen(u);c.length<2||isNaN(c[0])||isNaN(c[1])||(p.style("position","fixed").style("left",`${c[0]-g/2}px`).style("top",`${c[1]-h/2}px`).style("width",`${g}px`).style("height",`${h}px`).style("z-index",1),E.select(r.current).select(`.daga-dropbar.daga-index-${m}.daga-depth-${t}`).style("visibility","hidden").style("height",0),m=i(c),E.select(r.current).select(`.daga-dropbar.daga-index-${m}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on(A.End,u=>{var f,v;x(M.Auto),p.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),E.select(r.current).select(`.daga-dropbar.daga-index-${m}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const c=e.getPointerLocationRelativeToScreen(u);c.length<2||isNaN(c[0])||isNaN(c[1])||(m=i(c),(f=s==null?void 0:s.displayedProperties)==null||f.splice(s.displayedProperties.indexOf(d),1),(v=s==null?void 0:s.displayedProperties)==null||v.splice(m,0,d))}))}},i=d=>{var m;const g=(s==null?void 0:s.propertySet.propertyList)||[],h=[];for(let p=0;p<=g.length;++p){const u=(m=E.select(r.current).select(`.daga-dropbar.daga-index-${p}.daga-depth-${t}`).node())==null?void 0:m.getBoundingClientRect();u&&h.push([u.x+u.width/2,u.y+u.height/2])}if(h.length>0){const p=h.map(c=>((d[0]-c[0])**2+(d[1]-c[1])**2)**.5);return p.indexOf(Math.min(...p))}return 0},o=d=>{var h;if(s===void 0)return;let g;d instanceof zi?g=d:d instanceof Event?g=s==null?void 0:s.propertySet.getProperty(((h=d.target)==null?void 0:h.value)||""):g=s==null?void 0:s.propertySet.getProperty(d||""),g&&(s==null||s.hideProperty(g)),l()},n=d=>Array.isArray(d)?d.join(", "):ne(d)?Object.entries(d).map(g=>g.map(h=>JSON.stringify(h)).join(": ")).join(", "):d instanceof Date?d.toLocaleString():d==null?"":""+d;return C.jsxs("daga-property-settings",{ref:r,children:[C.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),s==null?void 0:s.displayedProperties.map((d,g)=>C.jsxs("div",{className:`daga-property-and-dropbar ${a(d.name)} daga-depth-${t}`,children:[C.jsxs("div",{className:`daga-property ${a(d.name)} daga-depth-${t}`,children:[C.jsxs("div",{className:"daga-property-name",children:[C.jsx("span",{children:d.name}),C.jsxs("div",{className:"daga-buttons",children:[C.jsx("button",{className:"daga-property-button daga-move-button",children:C.jsx("div",{className:"daga-icon daga-move-icon"})}),C.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>o(d.name),children:C.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),d.type!==tt.Object&&C.jsx("div",{className:"daga-property-value",children:n(s==null?void 0:s.getValue(d.name))}),d.type===tt.Object&&C.jsx(mi,{valueSet:s==null?void 0:s.getSubValueSet(d.name),depth:t+1})]}),C.jsx("div",{className:`daga-dropbar daga-index-${g+1} daga-depth-${t}`})]},d.name))]})},Mo=({location:s,direction:t,width:e,title:r,valueSet:a,onValueChange:l})=>{const i=R.useRef(null),[o,n]=R.useState(!1),[d,g]=R.useState(!1),h=()=>E.select(i.current);return R.useEffect(()=>{if(i.current)switch(t){case y.Bottom:case y.Top:h().style("width",e);break;case y.Left:case y.Right:h().style("height",e);break}},[e,t]),C.jsx("daga-property-editor",{children:C.jsxs("div",{ref:i,className:`daga-panel daga-bottom daga-${s} daga-${t}`,children:[C.jsx(ce,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:o,direction:t,collapsableSelector:i,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:n}),a&&a.propertySet&&a.propertySet.hasProperties()&&!o&&C.jsxs("div",{className:"daga-panel-content",children:[r&&C.jsxs("p",{className:"daga-title",children:[r,C.jsx("button",{className:"daga-property-button",onClick:()=>g(!d),children:C.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&C.jsx(Eo,{valueSet:a,onValueChange:l}),d&&C.jsx(mi,{valueSet:a,depth:0})]})]})})},Po=s=>{const t=R.useContext(bt),[e,r]=R.useState(s.currentPalette||s.palettes[0]),[a,l]=R.useState(0),[i,o]=R.useState(void 0),n=R.useRef(null),d=c=>{if(r(c),g().selectAll("*").remove(),l(t.getPriorityThreshold()||0),c.categories&&h(c.categories),c.templates)for(const f of c.templates)m(f)},g=()=>E.select(n.current).select(".daga-palette-view"),h=c=>{const f=g().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");f.append("option").attr("value","").text("(None selected)");for(const v in c)f.append("option").attr("value",v).text(v);f.on(S.Change,()=>{i&&g().selectAll(".daga-template-container.daga-in-category").remove();const v=f.property("value");o(v);const w=c[v]||[];for(const b of w)m(b,"daga-in-category")}),i&&(f.property("value",i),f.dispatch(S.Change))},m=(c,f)=>{if(c.templateType==="node"){const v=t.model.nodes.types.get(c.type);v?p(v,c,f):console.error(`Could not find a node type called '${c.type}'`)}else if(c.templateType==="connection"){const v=t.model.connections.types.get(c.type);v?u(v,c,f):console.error(`Could not find a connection type called '${c.type}'`)}},p=(c,f,v)=>{if(a!==void 0&&c.priority<a)return;const w=g().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${c.defaultWidth}px`).style("height",`${c.defaultHeight}px`).call(E.drag().on(A.Drag,b=>{if(t.canUserPerformAction(k.AddNode)){const $=t.getPointerLocationRelativeToScreen(b);if($.length<2||isNaN($[0])||isNaN($[1]))return;w.style("position","fixed").style("left",`${$[0]-c.defaultWidth/2}px`).style("top",`${$[1]-c.defaultHeight/2}px`).style("z-index",1)}}).on(A.Start,b=>{if(t.canUserPerformAction(k.AddNode)){x(M.Grabbing);const $=t.getPointerLocationRelativeToScreen(b);if($.length<2||isNaN($[0])||isNaN($[1]))return;w.style("position","fixed").style("left",`${$[0]-c.defaultWidth/2}px`).style("top",`${$[1]-c.defaultHeight/2}px`).style("z-index",1),c.isUnique&&t.model.nodes.find(I=>!I.removed&&I.type.id===c.id)!==void 0&&x(M.NotAllowed)}}).on(A.End,b=>{var $;if(t.canUserPerformAction(k.AddNode)){if(x(M.Auto),w.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),c.isUnique&&t.model.nodes.find(D=>!D.removed&&D.type.id===c.id)!==void 0)return;const I=t.getPointerLocationRelativeToScreen(b);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;const T=document.elementFromPoint(I[0],I[1]);if(T&&!(($=t.selectCanvasView().node())!=null&&$.contains(T)))return;const N=t.getPointerLocationRelativeToCanvas(b);if(N.length<2||isNaN(N[0])||isNaN(N[1]))return;let P=[N[0]-c.defaultWidth/2,N[1]-c.defaultHeight/2];t.snapToGrid&&(P=t.getClosestGridPoint(P));const Z=t.model.nodes.getAtCoordinates(N[0],N[1]).filter(D=>D.type.childrenTypes.includes(c.id)),G=ri(Z),U=G[G.length-1];if(!c.canBeParentless&&U===void 0)return;const H=U==null?void 0:U.getLastAncestor(),q=new Qi(t,c,P,U==null?void 0:U.id,H==null?void 0:H.id,H==null?void 0:H.getGeometry(),void 0,f.label,f.values);q.do(),t==null||t.actionStack.add(q),x()}})).append("svg").attr("class",`palette-node ${c.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%");switch(c.look.lookType){case"shaped-look":w.append("path").attr("d",Gt(c.look.shape,0,0,c.defaultWidth,c.defaultHeight)).attr("fill",c.look.fillColor).attr("stroke",c.look.borderColor).attr("stroke-width","1px");break;case"image-look":w.append("image").attr("x",0).attr("y",0).attr("width",c.defaultWidth).attr("height",c.defaultHeight).attr("href",c.look.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":w.append("image").attr("x",0).attr("y",0).attr("width",c.look.leftMargin).attr("height",c.look.topMargin).attr("href",c.look.backgroundImageTopLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.look.leftMargin).attr("y",0).attr("width",c.defaultWidth-c.look.rightMargin-c.look.leftMargin).attr("height",c.look.topMargin).attr("href",c.look.backgroundImageTop).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.defaultWidth-c.look.rightMargin).attr("y",0).attr("width",c.look.rightMargin).attr("height",c.look.topMargin).attr("href",c.look.backgroundImageTopRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",c.look.topMargin).attr("width",c.look.leftMargin).attr("height",c.defaultHeight-c.look.bottomMargin-c.look.topMargin).attr("href",c.look.backgroundImageLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.look.leftMargin).attr("y",c.look.topMargin).attr("width",c.defaultWidth-c.look.rightMargin-c.look.leftMargin).attr("height",c.defaultHeight-c.look.bottomMargin-c.look.topMargin).attr("href",c.look.backgroundImageCenter).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.defaultWidth-c.look.rightMargin).attr("y",c.look.topMargin).attr("width",c.look.rightMargin).attr("height",c.defaultHeight-c.look.bottomMargin-c.look.topMargin).attr("href",c.look.backgroundImageRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",c.defaultHeight-c.look.bottomMargin).attr("width",c.look.leftMargin).attr("height",c.look.bottomMargin).attr("href",c.look.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.look.leftMargin).attr("y",c.defaultHeight-c.look.bottomMargin).attr("width",c.defaultWidth-c.look.rightMargin-c.look.leftMargin).attr("height",c.look.bottomMargin).attr("href",c.look.backgroundImageBottom).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.defaultWidth-c.look.rightMargin).attr("y",c.defaultHeight-c.look.bottomMargin).attr("width",c.look.rightMargin).attr("height",c.look.bottomMargin).attr("href",c.look.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(f.label){const b={...z,...c.label,...f.labelLook};w.append("text").attr("transform",`translate(${(X(b)+c.defaultWidth)/2},${(F(b)+c.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${b.fontSize}px`).attr("text-anchor","middle").attr("font-family",b.fontFamily).attr("font-weight",400).attr("fill",b.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(f.label)}},u=(c,f,v)=>{const w=g().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${f.width}px`).style("height",`${f.height}px`).append("svg").attr("class",`palette-button ${c.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=c});w.append("path").attr("d",Gt(Ht.Rectangle,0,0,f.width,f.height)).attr("fill",f.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),f.icon!==""&&w.append("image").attr("x",0).attr("y",0).attr("width",f.width).attr("height",f.height).attr("href",f.icon),f.label!==""&&w.append("text").attr("transform",`translate(${f.width/2},${f.height/2+5})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(f.label)};return R.useEffect(()=>{if(r(e||s.palettes[0]),d(e),n.current)switch(s.direction){case y.Bottom:case y.Top:n.current.style.width=s.width;break;case y.Left:case y.Right:n.current.style.height=s.width;break}},[e,s.palettes]),C.jsx("daga-palette",{children:C.jsxs("div",{ref:n,className:`daga-panel daga-${s.location} daga-${s.direction}`,children:[C.jsx(ce,{direction:s.direction,collapsableSelector:n,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),C.jsxs("div",{className:"daga-panel-content",children:[s.palettes.length>1&&C.jsx("div",{className:"daga-panel-tabs",children:s.palettes.map(c=>C.jsx("div",{className:`daga-panel-tab ${c===e?"daga-current-tab":""}`,onClick:()=>d(c),children:c.name}))}),C.jsx("div",{className:"daga-palette-view"})]})]})})},No=({location:s,direction:t,enableAction:e,enableFilter:r,enableLayout:a,enableSelection:l,enableZoom:i})=>{let o=!1,n=!0,d=!1,g,h,m,p;switch(t){case y.Bottom:g="height",h="scaleY",m="top",p="bottom";break;case y.Top:g="height",h="scaleY",m="bottom",p="top";break;case y.Left:g="width",h="scaleX",m="right",p="left";break;case y.Right:g="width",h="scaleX",m="left",p="right";break}const u=R.useRef(null),c=R.useRef(null),f=R.useRef(null);R.useEffect(()=>{E.select(u.current).style(`margin-${p}`,"-1rem").style(g,"0rem").style("transform",`${h}(0)`).style("transform-origin",m)});const v=async()=>{const D=E.select(u.current);if(!d)if(n){n=!1;const Lt=`${4*D.selectChildren().size()}rem`;D.transition().duration(500).ease(E.easeLinear).style(g,Lt).style("transform",`${h}(1)`),setTimeout(()=>{d=!1},500)}else n=!0,D.transition().duration(500).ease(E.easeLinear).style(g,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{d=!1},500)},w=R.useContext(bt),b=()=>{w.zoomBy(w.zoomFactor)},$=()=>{w.zoomBy(1/w.zoomFactor)},I=()=>{w.center()},T=()=>{w.layoutFormat&&w.layoutFormat in Je&&Je[w.layoutFormat].apply(w.model)},N=()=>{o=!o,E.select(f.current).classed("daga-on",o).classed("daga-off",!o);const D=w.getPriorityThresholdOptions();D&&D.length>=2&&w.setPriorityThreshold(D[o?1:0])},P=()=>{w.actionStack.undo()},W=()=>{w.actionStack.redo()},Z=()=>{w.userSelection.copyToClipboard()},G=()=>{w.userSelection.cutToClipboard()},U=()=>{w.userSelection.pasteFromClipboard()},H=()=>{w.userSelection.removeFromModel()},q=()=>{w.multipleSelectionOn=!0,E.select(c.current).classed("daga-on",!0).classed("daga-off",!1)};return C.jsx("daga-diagram-buttons",{children:C.jsxs("div",{className:`daga-diagram-buttons daga-${s} daga-${t}`,children:[i&&w.canUserPerformAction(k.Zoom)&&C.jsx("button",{className:"daga-zoom-in",onClick:b,children:C.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&w.canUserPerformAction(k.Zoom)&&C.jsx("button",{className:"daga-zoom-out",onClick:$,children:C.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),C.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:u,children:[i&&w.canUserPerformAction(k.Zoom)&&C.jsx("button",{className:"daga-center",onClick:I,children:C.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&C.jsx("button",{className:"daga-undo",onClick:P,children:C.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&C.jsx("button",{className:"daga-redo",onClick:W,children:C.jsx("span",{className:"daga-tooltip",children:"Redo"})}),l&&C.jsx("button",{className:"daga-copy",onClick:Z,children:C.jsx("span",{className:"daga-tooltip",children:"Copy"})}),l&&C.jsx("button",{className:"daga-cut",onClick:G,children:C.jsx("span",{className:"daga-tooltip",children:"Cut"})}),l&&C.jsx("button",{className:`daga-multiple-selection ${o?"daga-on":"daga-off"}`,onClick:q,ref:c,children:C.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),l&&C.jsx("button",{className:"daga-paste",onClick:U,children:C.jsx("span",{className:"daga-tooltip",children:"Paste"})}),l&&C.jsx("button",{className:"daga-delete",onClick:H,children:C.jsx("span",{className:"daga-tooltip",children:"Delete"})}),a&&w.layoutFormat&&C.jsx("button",{className:"daga-layout",onClick:T,children:C.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),r&&C.jsx("button",{className:`daga-filter ${o?"daga-on":"daga-off"}`,onClick:N,ref:f,children:C.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),C.jsx("button",{className:"daga-more-options",onClick:v,children:n?C.jsx("span",{className:"daga-tooltip",children:"More options"}):C.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Ro=({config:s,model:t,onCanvasCreated:e,onDiagramEvent:r,onModelChange:a})=>{var $,I,T,N,P,W,Z,G,U,H,q,D,rt,Jt,Lt,he,ge,ue,fe,me,pe,ye,be,ve,we,Ce,ke,xe,Ie,Se,Ae,Te,$e,Ee,Me,Pe,Ne,Re,ze,Le,Ve,De,Oe,je,Be;const l=new li,i=new ci,o=R.useRef(null),n=R.useRef(!1),[d,g]=R.useState(void 0),[h,m]=R.useState(void 0),p={zoomIn:()=>{console.log("zoomIn")},zoomOut:()=>{console.log("zoomOut")},center:()=>{console.log("center")},layout:()=>{console.log("layout")},filter:()=>{console.log("filter")},undo:()=>{console.log("undo")},redo:()=>{console.log("redo")}},u={refreshPalette:()=>{console.log("refreshPalette")}},c=new To(it=>g(it),it=>m(it)),f={diagramButtons:p,palette:u,propertyEditor:c},v=new ae(f,s);R.useEffect(()=>{t&&l.import(v.model,t)},[t]),v.diagramChange$.subscribe(()=>{const it=i.export(v.model);a==null||a(it)});const w=it=>{v.initView(it),v.diagramEvent$.subscribe(Vt=>{r==null||r(Vt)})};R.useEffect(()=>{o.current&&(n.current||(w(o.current),n.current=!0,e==null||e(v)))},[o.current]);const b=(it,Vt)=>{var Fe;if(h!==void 0&&it.editable&&!Pt(h.getValue(it.name),Vt)){const Dt=new At(h.propertySet,h.rootElement);Dt.setValues(h.values),Dt.setValue(it.name,Vt),c.valueSet=Dt,h.rootElement.valueSet=Dt,(Fe=v.propertyEditorChanges$)==null||Fe.next()}};return C.jsx("daga-diagram",{children:C.jsx(Ao.Provider,{value:s,children:C.jsx(bt.Provider,{value:v,children:C.jsxs("daga-diagram-editor",{children:[C.jsx("div",{className:"daga-append-to",ref:o}),C.jsxs(bt.Provider,{value:v,children:[(($=s.components)==null?void 0:$.buttons)!==void 0&&((T=(I=s.components)==null?void 0:I.buttons)==null?void 0:T.enabled)!==!1&&C.jsx(No,{location:((P=(N=s.components)==null?void 0:N.buttons)==null?void 0:P.location)||Ot.BottomRight,direction:((Z=(W=s.components)==null?void 0:W.buttons)==null?void 0:Z.direction)||y.Top,enableAction:((U=(G=s.components)==null?void 0:G.buttons)==null?void 0:U.enableAction)===!0,enableFilter:((q=(H=s.components)==null?void 0:H.buttons)==null?void 0:q.enableFilter)===!0,enableLayout:((rt=(D=s.components)==null?void 0:D.buttons)==null?void 0:rt.enableLayout)===!0,enableSelection:((Lt=(Jt=s.components)==null?void 0:Jt.buttons)==null?void 0:Lt.enableSelection)===!0,enableZoom:((ge=(he=s.components)==null?void 0:he.buttons)==null?void 0:ge.enableZoom)!==!1}),((ue=s.components)==null?void 0:ue.palette)!==void 0&&((me=(fe=s.components)==null?void 0:fe.palette)==null?void 0:me.enabled)!==!1&&((ye=(pe=s.components)==null?void 0:pe.palette)==null?void 0:ye.sections)&&(((we=(ve=(be=s.components)==null?void 0:be.palette)==null?void 0:ve.sections)==null?void 0:we.length)||0)>0&&C.jsx(Po,{location:((ke=(Ce=s.components)==null?void 0:Ce.palette)==null?void 0:ke.location)||Ot.TopLeft,direction:((Ie=(xe=s.components)==null?void 0:xe.palette)==null?void 0:Ie.direction)||y.Bottom,width:((Ae=(Se=s.components)==null?void 0:Se.palette)==null?void 0:Ae.width)||"12rem",palettes:(($e=(Te=s.components)==null?void 0:Te.palette)==null?void 0:$e.sections)||[]}),((Ee=s.components)==null?void 0:Ee.propertyEditor)!==void 0&&((Pe=(Me=s.components)==null?void 0:Me.propertyEditor)==null?void 0:Pe.enabled)!==!1&&C.jsx(Mo,{location:((Re=(Ne=s.components)==null?void 0:Ne.propertyEditor)==null?void 0:Re.location)||Ot.TopRight,direction:((Le=(ze=s.components)==null?void 0:ze.propertyEditor)==null?void 0:Le.direction)||y.Bottom,width:((De=(Ve=s.components)==null?void 0:Ve.propertyEditor)==null?void 0:De.width)||"24rem",title:d,valueSet:h,onValueChange:b}),((Oe=s.components)==null?void 0:Oe.errors)!==void 0&&((Be=(je=s.components)==null?void 0:je.errors)==null?void 0:Be.enabled)!==!1&&C.jsx($o,{})]})]})})})})};exports.DagaDiagram=Ro;
|