@metadev/daga-react 0.0.2 → 0.0.4

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/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react/jsx-runtime"),mi=require("d3"),se=require("rxjs"),R=require("react");function pi(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const $=pi(mi);var p=(s=>(s.Bottom="bottom",s.Left="left",s.Right="right",s.Top="top",s))(p||{}),Pe=(s=>(s.BottomLeft="bottom-left",s.BottomRight="bottom-right",s.TopLeft="top-left",s.TopRight="top-right",s))(Pe||{}),Ce=(s=>(s.Left="left",s.Center="center",s.Right="right",s))(Ce||{}),ze=(s=>(s.Top="top",s.Center="center",s.Bottom="bottom",s))(ze||{});const Ne=s=>[Math.round(s[0]),Math.round(s[1])],le=(s,e,t)=>e<t?e<=s&&s<=t:t<=s&&s<=e,Ut=(s,e,t)=>(s-e[0])/(e[1]-e[0])*(t[1]-t[0])+t[0],Le=(s,e,t,n,l)=>[Ut(s[0],e,n),Ut(s[1],t,l)],Qt=(s,e)=>((s[0]-e[0])**2+(s[1]-e[1])**2)**.5,yi=(s,e)=>(le(s[0][0],e[0][0],e[1][0])||le(s[1][0],e[1][0],e[0][0])||le(e[0][0],s[0][0],s[1][0])||le(e[1][0],s[1][0],s[0][0]))&&(le(s[0][1],e[0][1],e[1][1])||le(s[1][1],e[1][1],e[0][1])||le(e[0][1],s[0][1],s[1][1])||le(e[1][1],s[1][1],s[0][1]));var I=(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))(I||{}),oe=(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))(oe||{}),T=(s=>(s.Drag="drag",s.Start="start",s.End="end",s))(T||{}),st=(s=>(s.Zoom="zoom",s.Start="start",s.End="end",s))(st||{}),ei=(s=>(s.Straight="straight",s.Bezier="bezier",s.Square="square",s))(ei||{}),ti=(s=>(s.Solid="solid",s.Dashed="dashed",s.GappedDashes="gapped-dashes",s.Dotted="dotted",s))(ti||{});const bi=20,vi=(s,e,t,n,l)=>{if(e.length===0)return"";if(e.length===1)return`M ${e[0][0]} ${e[0][1]}`;{l=l||bi;let a="",i,o;switch(s){case"straight":a+=`M ${e[0][0]} ${e[0][1]}`;for(let r=1;r<e.length;++r)a+=` L ${e[r][0]} ${e[r][1]}`;break;case"bezier":i=t,a+=`M ${e[0][0]} ${e[0][1]}`;for(let r=1;r<e.length;++r){if(r+1>=e.length?o=n:Math.abs(e[r][0]-e[r-1][0])<Math.abs(e[r][1]-e[r-1][1])?e[r][1]>e[r-1][1]?o=p.Bottom:o=p.Top:e[r][0]>e[r-1][0]?o=p.Right:o=p.Left,i!==void 0){let d="",u="";const c=(Math.abs(e[r][0]-e[r-1][0])+Math.abs(e[r][1]-e[r-1][1]))/2;switch(i){case p.Bottom:d=`${e[r-1][0]} ${e[r-1][1]+c}`;break;case p.Top:d=`${e[r-1][0]} ${e[r-1][1]-c}`;break;case p.Right:d=`${e[r-1][0]+c} ${e[r-1][1]}`;break;case p.Left:d=`${e[r-1][0]-c} ${e[r-1][1]}`;break}if(o!==void 0){switch(o){case p.Bottom:u=`${e[r][0]} ${e[r][1]+c}`;break;case p.Top:u=`${e[r][0]} ${e[r][1]-c}`;break;case p.Right:u=`${e[r][0]+c} ${e[r][1]}`;break;case p.Left:u=`${e[r][0]-c} ${e[r][1]}`;break}a+=` C ${d} ${u} ${e[r][0]} ${e[r][1]}`}else a+=` Q ${d} ${e[r][0]} ${e[r][1]}`}else if(o!==void 0){let d="";const u=(Math.abs(e[r][0]-e[r-1][0])+Math.abs(e[r][1]-e[r-1][1]))/2;switch(o){case p.Bottom:d=`${e[r][0]} ${e[r][1]+u}`;break;case p.Top:d=`${e[r][0]} ${e[r][1]-u}`;break;case p.Right:d=`${e[r][0]+u} ${e[r][1]}`;break;case p.Left:d=`${e[r][0]-u} ${e[r][1]}`;break}a+=` Q ${d} ${e[r][0]} ${e[r][1]}`}else a+=` L ${e[r][0]} ${e[r][1]}`;i=o}break;case"square":if(a+=`M ${e[0][0]} ${e[0][1]}`,t)switch(t){case p.Bottom:e.splice(1,0,[e[0][0],e[0][1]+l]);break;case p.Top:e.splice(1,0,[e[0][0],e[0][1]-l]);break;case p.Right:e.splice(1,0,[e[0][0]+l,e[0][1]]);break;case p.Left:e.splice(1,0,[e[0][0]-l,e[0][1]]);break}if(n)switch(n){case p.Bottom:e.splice(e.length-1,0,[e[e.length-1][0],e[e.length-1][1]+l]);break;case p.Top:e.splice(e.length-1,0,[e[e.length-1][0],e[e.length-1][1]-l]);break;case p.Right:e.splice(e.length-1,0,[e[e.length-1][0]+l,e[e.length-1][1]]);break;case p.Left:e.splice(e.length-1,0,[e[e.length-1][0]-l,e[e.length-1][1]]);break}for(let r=1;r<e.length;++r)if(i!==void 0)switch(i){case p.Bottom:e[r][1]<e[r-1][1]&&e[r][0]!==e[r-1][0]?(a+=` H ${e[r][0]}`,a+=` V ${e[r][1]}`,i=p.Top):e[r][1]<e[r-1][1]&&e[r][0]===e[r-1][0]?(a+=` H ${e[r][0]+l}`,a+=` V ${e[r][1]}`,a+=` H ${e[r][0]}`,i=p.Left):e[r][1]===e[r-1][1]&&e[r][0]!==e[r-1][0]?(a+=` H ${e[r][0]}`,i=e[r][0]>e[r-1][0]?p.Right:p.Left):e[r][1]>e[r-1][1]&&e[r][0]!==e[r-1][0]?(a+=` H ${e[r][0]}`,a+=` V ${e[r][1]}`):e[r][1]>e[r-1][1]&&e[r][0]===e[r-1][0]&&(a+=` V ${e[r][1]}`);break;case p.Top:e[r][1]>e[r-1][1]&&e[r][0]!==e[r-1][0]?(a+=` H ${e[r][0]}`,a+=` V ${e[r][1]}`,i=p.Bottom):e[r][1]>e[r-1][1]&&e[r][0]===e[r-1][0]?(a+=` H ${e[r][0]-l}`,a+=` V ${e[r][1]}`,a+=` H ${e[r][0]}`,i=p.Right):e[r][1]===e[r-1][1]&&e[r][0]!==e[r-1][0]?(a+=` H ${e[r][0]}`,i=e[r][0]>e[r-1][0]?p.Right:p.Left):e[r][1]<e[r-1][1]&&e[r][0]!==e[r-1][0]?(a+=` H ${e[r][0]}`,a+=` V ${e[r][1]}`):e[r][1]<e[r-1][1]&&e[r][0]===e[r-1][0]&&(a+=` V ${e[r][1]}`);break;case p.Right:e[r][0]<e[r-1][0]&&e[r][1]!==e[r-1][1]?(a+=` V ${e[r][1]}`,a+=` H ${e[r][0]}`,i=p.Left):e[r][0]<e[r-1][0]&&e[r][1]===e[r-1][1]?(a+=` V ${e[r][1]+l}`,a+=` H ${e[r][0]}`,a+=` V ${e[r][1]}`,i=p.Top):e[r][0]===e[r-1][0]&&e[r][1]!==e[r-1][1]?(a+=` V ${e[r][1]}`,i=e[r][1]>e[r-1][1]?p.Bottom:p.Top):e[r][0]>e[r-1][0]&&e[r][1]!==e[r-1][1]?(a+=` V ${e[r][1]}`,a+=` H ${e[r][0]}`):e[r][0]>e[r-1][0]&&e[r][1]===e[r-1][1]&&(a+=` H ${e[r][0]}`);break;case p.Left:e[r][0]>e[r-1][0]&&e[r][1]!==e[r-1][1]?(a+=` V ${e[r][1]}`,a+=` H ${e[r][0]}`,i=p.Right):e[r][0]>e[r-1][0]&&e[r][1]===e[r-1][1]?(a+=` V ${e[r][1]-l}`,a+=` H ${e[r][0]}`,a+=` V ${e[r][1]}`,i=p.Bottom):e[r][0]===e[r-1][0]&&e[r][1]!==e[r-1][1]?(a+=` V ${e[r][1]}`,i=e[r][1]>e[r-1][1]?p.Bottom:p.Top):e[r][0]<e[r-1][0]&&e[r][1]!==e[r-1][1]?(a+=` V ${e[r][1]}`,a+=` H ${e[r][0]}`):e[r][0]<e[r-1][0]&&e[r][1]===e[r-1][1]&&(a+=` H ${e[r][0]}`);break}else e[r][0]!==e[r-1][0]&&(a+=` H ${e[r][0]}`,i=e[r][0]>e[r-1][0]?p.Right:p.Left),e[r][1]!==e[r-1][1]&&(a+=` V ${e[r][1]}`,i=e[r][1]>e[r-1][1]?p.Bottom:p.Top);break}return a}},Ht=(s,e)=>{switch(s){case"dotted":return`${e}`;case"dashed":return`${4*e} ${e}`;case"gapped-dashes":return`${4*e} ${4*e}`;case"solid":default:return"none"}},B=(s,e)=>{const t=s.indexOf(e);return t>=0&&s.splice(t,1),s};var Be=(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))(Be||{});const Ve=(s,e,t,n,l)=>{if(typeof s=="function")return s(e,t,n,l);switch(s){case"ellipse":return ii(e,t,n,l);case"empty":return Ci();case"folder":return wi(e,t,n,l);case"hexagon":return ki(e,t,n,l);case"octagon":return xi(e,t,n,l);case"pill":return Re(e,t,n,l);case"rectangle":return _t(e,t,n,l);case"rhombus":return Si(e,t,n,l);case"rounded-rectangle":return Ii(e,t,n,l);case"sticky-note":return Ai(e,t,n,l);default:return _t(e,t,n,l)}},ii=(s,e,t,n)=>`M ${s+t/2} ${e} A ${t/2} ${n/2} 0 0 0 ${s+t/2} ${e+n} A ${t/2} ${n/2} 0 1 0 ${s+t/2} ${e} Z`,Ci=()=>"Z",wi=(s,e,t,n)=>`M ${s} ${e} L ${s+t/3} ${e} L ${s+t/2} ${e+n/6} L ${s+t} ${e+n/6} L ${s+t} ${e+n} L ${s} ${e+n} Z`,ki=(s,e,t,n)=>`M ${s+t/4} ${e} L ${s+3*t/4} ${e} L ${s+t} ${e+n/2} L ${s+3*t/4} ${e+n} L ${s+t/4} ${e+n} L ${s} ${e+n/2} Z`,xi=(s,e,t,n)=>`M ${s+t/4} ${e} L ${s+3*t/4} ${e} L ${s+t} ${e+n/4} L ${s+t} ${e+3*n/4} L ${s+3*t/4} ${e+n} L ${s+t/4} ${e+n} L ${s} ${e+3*n/4} L ${s} ${e+n/4} L ${s+t/4} ${e} Z`,Re=(s,e,t,n)=>n<t?`M ${s+n/2} ${e} L ${s+t-n/2} ${e} A ${n/2} ${n/2} 0 0 1 ${s+t} ${e+n/2} A ${n/2} ${n/2} 0 0 1 ${s+t-n/2} ${e+n} L ${s+n/2} ${e+n} A ${n/2} ${n/2} 0 0 1 ${s} ${e+n/2} A ${n/2} ${n/2} 0 0 1 ${s+n/2} ${e} Z`:n>t?`M ${s} ${e+t/2} L ${s} ${e+n-t/2} A ${t/2} ${t/2} 0 0 0 ${s+t/2} ${e+n} A ${t/2} ${t/2} 0 0 0 ${s+t} ${e+n-t/2} L ${s+t} ${e+t/2} A ${t/2} ${t/2} 0 0 0 ${s+t/2} ${e} A ${t/2} ${t/2} 0 0 0 ${s} ${e+t/2} Z`:ii(s,e,t,n),_t=(s,e,t,n)=>`M ${s} ${e} L ${s+t} ${e} L ${s+t} ${e+n} L ${s} ${e+n} Z`,Si=(s,e,t,n)=>`M ${s+t/2} ${e} L ${s+t} ${e+n/2} L ${s+t/2} ${e+n} L ${s} ${e+n/2} Z`,Ii=(s,e,t,n)=>`M ${s+t/4} ${e} L ${s+3*t/4} ${e} A ${t/4} ${n/4} 0 0 1 ${s+t} ${e+n/4} L ${s+t} ${e+3*n/4} A ${t/4} ${n/4} 0 0 1 ${s+3*t/4} ${e+n} L ${s+t/4} ${e+n} A ${t/4} ${n/4} 0 0 1 ${s} ${e+3*n/4} L ${s} ${e+n/4} A ${t/4} ${n/4} 0 0 1 ${s+t/4} ${e} Z`,Ai=(s,e,t,n)=>`M ${s} ${e} L ${s+3*t/4} ${e} L ${s+3*t/4} ${e+n/4} L ${s+3*t/4} ${e} L ${s+t} ${e+n/4} L ${s+3*t/4} ${e+n/4} L ${s+t} ${e+n/4} L ${s+t} ${e+n} L ${s} ${e+n} Z`;var E=(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))(E||{});const Ti=s=>Math.max(...s.split(`
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,"&lt;").replace(/>/g,"&gt;").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 y=require("react/jsx-runtime"),Li=require("d3"),we=require("rxjs"),$=require("react");function Ei(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const T=Ei(Li);var k=(i=>(i.Bottom="bottom",i.Left="left",i.Right="right",i.Top="top",i))(k||{}),He=(i=>(i.BottomLeft="bottom-left",i.BottomRight="bottom-right",i.TopLeft="top-left",i.TopRight="top-right",i))(He||{}),Ee=(i=>(i.Left="left",i.Center="center",i.Right="right",i))(Ee||{}),Fe=(i=>(i.Top="top",i.Center="center",i.Bottom="bottom",i))(Fe||{});const Ie=i=>[Math.round(i[0]),Math.round(i[1])],ge=(i,e,t)=>e<t?e<=i&&i<=t:t<=i&&i<=e,Kt=(i,e,t)=>(i-e[0])/(e[1]-e[0])*(t[1]-t[0])+t[0],Be=(i,e,t,o,a)=>[Kt(i[0],e,o),Kt(i[1],t,a)],ri=(i,e)=>((i[0]-e[0])**2+(i[1]-e[1])**2)**.5,Ti=(i,e)=>(ge(i[0][0],e[0][0],e[1][0])||ge(i[1][0],e[1][0],e[0][0])||ge(e[0][0],i[0][0],i[1][0])||ge(e[1][0],i[1][0],i[0][0]))&&(ge(i[0][1],e[0][1],e[1][1])||ge(i[1][1],e[1][1],e[0][1])||ge(e[0][1],i[0][1],i[1][1])||ge(e[1][1],i[1][1],i[0][1]));var I=(i=>(i.Blur="blur",i.Change="change",i.Click="click",i.ContextMenu="contextmenu",i.DoubleClick="dblclick",i.Focus="focus",i.FocusIn="focusin",i.FocusOut="focusout",i.Input="input",i.KeyDown="keydown",i.KeyUp="keyup",i.MouseDown="mousedown",i.MouseEnter="mouseenter",i.MouseLeave="mouseleave",i.MouseMove="mousemove",i.MouseOut="mouseout",i.MouseOver="mouseover",i.MouseUp="mouseup",i.TouchStart="touchstart",i.TouchEnd="touchend",i.Wheel="wheel",i))(I||{}),ee=(i=>(i.Alt="Alt",i.AltGraph="AltGraph",i.ArrowDown="ArrowDown",i.ArrowLeft="ArrowLeft",i.ArrowRight="ArrowRight",i.ArrowUp="ArrowUp",i.Backspace="Backspace",i.Control="Control",i.Delete="Delete",i.End="End",i.Enter="Enter",i.Escape="Escape",i.Home="Home",i.OS="OS",i.PageDown="PageDown",i.PageUp="PageUp",i.Shift="Shift",i.Tab="Tab",i))(ee||{}),E=(i=>(i.Drag="drag",i.Start="start",i.End="end",i))(E||{}),at=(i=>(i.Zoom="zoom",i.Start="start",i.End="end",i))(at||{}),ai=(i=>(i.Straight="straight",i.Bezier="bezier",i.Square="square",i))(ai||{}),li=(i=>(i.Solid="solid",i.Dashed="dashed",i.GappedDashes="gapped-dashes",i.Dotted="dotted",i))(li||{});const $i=20,Mi=(i,e,t,o,a)=>{if(typeof i=="function")return i(e,t,o,a);if(e.length===0)return"";if(e.length===1)return`M ${e[0][0]} ${e[0][1]}`;{a=a||$i;let l="",s,n;switch(i){case"straight":l+=`M ${e[0][0]} ${e[0][1]}`;for(let r=1;r<e.length;++r)l+=` L ${e[r][0]} ${e[r][1]}`;break;case"bezier":s=t,l+=`M ${e[0][0]} ${e[0][1]}`;for(let r=1;r<e.length;++r){if(r+1>=e.length?n=o:Math.abs(e[r][0]-e[r-1][0])<Math.abs(e[r][1]-e[r-1][1])?e[r][1]>e[r-1][1]?n=k.Bottom:n=k.Top:e[r][0]>e[r-1][0]?n=k.Right:n=k.Left,s!==void 0){let d="",c="";const h=(Math.abs(e[r][0]-e[r-1][0])+Math.abs(e[r][1]-e[r-1][1]))/2;switch(s){case k.Bottom:d=`${e[r-1][0]} ${e[r-1][1]+h}`;break;case k.Top:d=`${e[r-1][0]} ${e[r-1][1]-h}`;break;case k.Right:d=`${e[r-1][0]+h} ${e[r-1][1]}`;break;case k.Left:d=`${e[r-1][0]-h} ${e[r-1][1]}`;break}if(n!==void 0){switch(n){case k.Bottom:c=`${e[r][0]} ${e[r][1]+h}`;break;case k.Top:c=`${e[r][0]} ${e[r][1]-h}`;break;case k.Right:c=`${e[r][0]+h} ${e[r][1]}`;break;case k.Left:c=`${e[r][0]-h} ${e[r][1]}`;break}l+=` C ${d} ${c} ${e[r][0]} ${e[r][1]}`}else l+=` Q ${d} ${e[r][0]} ${e[r][1]}`}else if(n!==void 0){let d="";const c=(Math.abs(e[r][0]-e[r-1][0])+Math.abs(e[r][1]-e[r-1][1]))/2;switch(n){case k.Bottom:d=`${e[r][0]} ${e[r][1]+c}`;break;case k.Top:d=`${e[r][0]} ${e[r][1]-c}`;break;case k.Right:d=`${e[r][0]+c} ${e[r][1]}`;break;case k.Left:d=`${e[r][0]-c} ${e[r][1]}`;break}l+=` Q ${d} ${e[r][0]} ${e[r][1]}`}else l+=` L ${e[r][0]} ${e[r][1]}`;s=n}break;case"square":if(l+=`M ${e[0][0]} ${e[0][1]}`,t)switch(t){case k.Bottom:e.splice(1,0,[e[0][0],e[0][1]+a]);break;case k.Top:e.splice(1,0,[e[0][0],e[0][1]-a]);break;case k.Right:e.splice(1,0,[e[0][0]+a,e[0][1]]);break;case k.Left:e.splice(1,0,[e[0][0]-a,e[0][1]]);break}if(o)switch(o){case k.Bottom:e.splice(e.length-1,0,[e[e.length-1][0],e[e.length-1][1]+a]);break;case k.Top:e.splice(e.length-1,0,[e[e.length-1][0],e[e.length-1][1]-a]);break;case k.Right:e.splice(e.length-1,0,[e[e.length-1][0]+a,e[e.length-1][1]]);break;case k.Left:e.splice(e.length-1,0,[e[e.length-1][0]-a,e[e.length-1][1]]);break}for(let r=1;r<e.length;++r)if(s!==void 0)switch(s){case k.Bottom:e[r][1]<e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`,s=k.Top):e[r][1]<e[r-1][1]&&e[r][0]===e[r-1][0]?(l+=` H ${e[r][0]+a}`,l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`,s=k.Left):e[r][1]===e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,s=e[r][0]>e[r-1][0]?k.Right:k.Left):e[r][1]>e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`):e[r][1]>e[r-1][1]&&e[r][0]===e[r-1][0]&&(l+=` V ${e[r][1]}`);break;case k.Top:e[r][1]>e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`,s=k.Bottom):e[r][1]>e[r-1][1]&&e[r][0]===e[r-1][0]?(l+=` H ${e[r][0]-a}`,l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`,s=k.Right):e[r][1]===e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,s=e[r][0]>e[r-1][0]?k.Right:k.Left):e[r][1]<e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`):e[r][1]<e[r-1][1]&&e[r][0]===e[r-1][0]&&(l+=` V ${e[r][1]}`);break;case k.Right:e[r][0]<e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`,s=k.Left):e[r][0]<e[r-1][0]&&e[r][1]===e[r-1][1]?(l+=` V ${e[r][1]+a}`,l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`,s=k.Top):e[r][0]===e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,s=e[r][1]>e[r-1][1]?k.Bottom:k.Top):e[r][0]>e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`):e[r][0]>e[r-1][0]&&e[r][1]===e[r-1][1]&&(l+=` H ${e[r][0]}`);break;case k.Left:e[r][0]>e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`,s=k.Right):e[r][0]>e[r-1][0]&&e[r][1]===e[r-1][1]?(l+=` V ${e[r][1]-a}`,l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`,s=k.Bottom):e[r][0]===e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,s=e[r][1]>e[r-1][1]?k.Bottom:k.Top):e[r][0]<e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`):e[r][0]<e[r-1][0]&&e[r][1]===e[r-1][1]&&(l+=` H ${e[r][0]}`);break}else e[r][0]!==e[r-1][0]&&(l+=` H ${e[r][0]}`,s=e[r][0]>e[r-1][0]?k.Right:k.Left),e[r][1]!==e[r-1][1]&&(l+=` V ${e[r][1]}`,s=e[r][1]>e[r-1][1]?k.Bottom:k.Top);break}return l}},Zt=(i,e)=>{switch(i){case"dotted":return`${e}`;case"dashed":return`${4*e} ${e}`;case"gapped-dashes":return`${4*e} ${4*e}`;case"solid":default:return"none"}},B=(i,e)=>{const t=i.indexOf(e);return t>=0&&i.splice(t,1),i};var Ye=(i=>(i.Ellipse="ellipse",i.Empty="empty",i.Folder="folder",i.Hexagon="hexagon",i.Octagon="octagon",i.Pill="pill",i.Rectangle="rectangle",i.Rhombus="rhombus",i.RoundedRectangle="rounded-rectangle",i.StickyNote="sticky-note",i))(Ye||{});const lt=(i,e,t,o,a)=>{if(typeof i=="function")return i(e,t,o,a);switch(i){case"ellipse":return di(e,t,o,a);case"empty":return Ni();case"folder":return Pi(e,t,o,a);case"hexagon":return zi(e,t,o,a);case"octagon":return Ri(e,t,o,a);case"pill":return Ge(e,t,o,a);case"rectangle":return qt(e,t,o,a);case"rhombus":return Vi(e,t,o,a);case"rounded-rectangle":return ji(e,t,o,a);case"sticky-note":return _i(e,t,o,a);default:return qt(e,t,o,a)}},di=(i,e,t,o)=>`M ${i+t/2} ${e} A ${t/2} ${o/2} 0 0 0 ${i+t/2} ${e+o} A ${t/2} ${o/2} 0 1 0 ${i+t/2} ${e} Z`,Ni=()=>"Z",Pi=(i,e,t,o)=>`M ${i} ${e} L ${i+t/3} ${e} L ${i+t/2} ${e+o/6} L ${i+t} ${e+o/6} L ${i+t} ${e+o} L ${i} ${e+o} Z`,zi=(i,e,t,o)=>`M ${i+t/4} ${e} L ${i+3*t/4} ${e} L ${i+t} ${e+o/2} L ${i+3*t/4} ${e+o} L ${i+t/4} ${e+o} L ${i} ${e+o/2} Z`,Ri=(i,e,t,o)=>`M ${i+t/4} ${e} L ${i+3*t/4} ${e} L ${i+t} ${e+o/4} L ${i+t} ${e+3*o/4} L ${i+3*t/4} ${e+o} L ${i+t/4} ${e+o} L ${i} ${e+3*o/4} L ${i} ${e+o/4} L ${i+t/4} ${e} Z`,Ge=(i,e,t,o)=>o<t?`M ${i+o/2} ${e} L ${i+t-o/2} ${e} A ${o/2} ${o/2} 0 0 1 ${i+t} ${e+o/2} A ${o/2} ${o/2} 0 0 1 ${i+t-o/2} ${e+o} L ${i+o/2} ${e+o} A ${o/2} ${o/2} 0 0 1 ${i} ${e+o/2} A ${o/2} ${o/2} 0 0 1 ${i+o/2} ${e} Z`:o>t?`M ${i} ${e+t/2} L ${i} ${e+o-t/2} A ${t/2} ${t/2} 0 0 0 ${i+t/2} ${e+o} A ${t/2} ${t/2} 0 0 0 ${i+t} ${e+o-t/2} L ${i+t} ${e+t/2} A ${t/2} ${t/2} 0 0 0 ${i+t/2} ${e} A ${t/2} ${t/2} 0 0 0 ${i} ${e+t/2} Z`:di(i,e,t,o),qt=(i,e,t,o)=>`M ${i} ${e} L ${i+t} ${e} L ${i+t} ${e+o} L ${i} ${e+o} Z`,Vi=(i,e,t,o)=>`M ${i+t/2} ${e} L ${i+t} ${e+o/2} L ${i+t/2} ${e+o} L ${i} ${e+o/2} Z`,ji=(i,e,t,o)=>`M ${i+t/4} ${e} L ${i+3*t/4} ${e} A ${t/4} ${o/4} 0 0 1 ${i+t} ${e+o/4} L ${i+t} ${e+3*o/4} A ${t/4} ${o/4} 0 0 1 ${i+3*t/4} ${e+o} L ${i+t/4} ${e+o} A ${t/4} ${o/4} 0 0 1 ${i} ${e+3*o/4} L ${i} ${e+o/4} A ${t/4} ${o/4} 0 0 1 ${i+t/4} ${e} Z`,_i=(i,e,t,o)=>`M ${i} ${e} L ${i+3*t/4} ${e} L ${i+3*t/4} ${e+o/4} L ${i+3*t/4} ${e} L ${i+t} ${e+o/4} L ${i+3*t/4} ${e+o/4} L ${i+t} ${e+o/4} L ${i+t} ${e+o} L ${i} ${e+o} Z`;var M=(i=>(i.AllScroll="all-scroll",i.Auto="auto",i.Crosshair="crosshair",i.EWResize="ew-resize",i.Grab="grab",i.Grabbing="grabbing",i.Move="move",i.NoDrop="no-drop",i.NSResize="ns-resize",i.NotAllowed="not-allowed",i.ZoomIn="zoom-in",i.ZoomOut="zoom-out",i))(M||{});const Oi=i=>Math.max(...i.split(`
2
+ `).map(e=>e.length)),Di=i=>{var e;return((e=i.match(/\n/g))==null?void 0:e.length)||0},K=[];for(let i=0;i<256;++i)K.push((i+256).toString(16).slice(1));function Hi(i,e=0){return(K[i[e+0]]+K[i[e+1]]+K[i[e+2]]+K[i[e+3]]+"-"+K[i[e+4]]+K[i[e+5]]+"-"+K[i[e+6]]+K[i[e+7]]+"-"+K[i[e+8]]+K[i[e+9]]+"-"+K[i[e+10]]+K[i[e+11]]+K[i[e+12]]+K[i[e+13]]+K[i[e+14]]+K[i[e+15]]).toLowerCase()}let et;const Gi=new Uint8Array(16);function Fi(){if(!et){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");et=crypto.getRandomValues.bind(crypto)}return et(Gi)}const Bi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Jt={randomUUID:Bi};function Qt(i,e,t){var a;if(Jt.randomUUID&&!i)return Jt.randomUUID();i=i||{};const o=i.random??((a=i.rng)==null?void 0:a.call(i))??Fi();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Hi(o)}const ie=i=>{const{selected:e,highlighted:t,...o}=i,a=o,l={...a,...e},s={...a,...t},n={...a,...t,...e};return{defaultLook:a,selectedLook:l,highlightedLook:s,selectedAndHighlightedLook:n}};class Xe{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 Me=0;class Se{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 ue extends Xe{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((o,a,l)=>e(o,a,l)&&!o.removed)}filter(e,t=!1){return t?super.filter(e):super.filter((o,a,l)=>e(o,a,l)&&!o.removed)}find(e,t=!1){return t?super.find(e):super.find((o,a,l)=>e(o,a,l)&&!o.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(o=>!o.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(o=>!o.removed))yield t}}function Ae(i,e){return!e||i[0]>e[0]?!0:i[0]===e[0]?i[1]>=e[1]:!1}class Ui{constructor(e,t,o,a,l,s){this.name=e,this.type=t,this.defaultValue=o,this.basic=a,this.editable=l,this.rootAttribute=s,this.options=void 0,this.properties=void 0}}var G=(i=>(i.Boolean="boolean",i.Color="color",i.Date="date",i.Datetime="datetime",i.Number="number",i.Object="object",i.Option="option",i.OptionList="option-list",i.OptionSet="option-set",i.Text="text",i.TextArea="text-area",i.TextList="text-list",i.TextSet="text-set",i.TextMap="text-map",i.Time="time",i.Url="url",i))(G||{});class We{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 be{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 o of e){if(t==null)return;t=t[o]}return t}}setRootElementValue(e,t){if(typeof e=="string"&&(this.rootElement[e]=t),Array.isArray(e)&&e.length>0){let o=this.rootElement;for(let a=0;a<e.length-1;++a){const l=e[a];if(o==null)return;o=o[l]}if(o==null)return;o[e[e.length-1]]=t}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}getValue(e){var a;const t=(a=this.propertySet.getProperty(e))==null?void 0:a.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 o in e)this.propertySet.getProperty(o).type==="object"?t[o]=this.valueSets[o].getValuesForKeys(e[o]):t[o]=this.getValue(o);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 a=this.ownTimestamps[t];a&&(e[t]=a)}return e}hasValue(e){const t=this.getValue(e);return!ei(t)}hasSetValue(e){const t=this.getValue(e),o=this.propertySet.getProperty(e);return o&&o.type==="object"?this.getSubValueSet(e).hasAnySetValue():!ei(t)&&!xe(t,o==null?void 0:o.defaultValue)}hasAnySetValue(){for(const e of this.propertySet.propertyList)if(this.hasSetValue(e.name))return!0;return!1}setValue(e,t){const o=this.propertySet.getProperty(e);if(o){o.type==="object"?this.valueSets[e].setValues(t):(this.values[e]=t,xe(t,o.defaultValue)||this.displayProperty(o));const a=o.rootAttribute;a!=null&&this.setRootElementValue(a,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 o in e)this.propertySet.getProperty(o).type==="object"?this.valueSets[o].overwriteValuesLww(e[o],t):Ae(t,this.ownTimestamps[o])&&(this.setValue(o,e[o]),this.ownTimestamps[o]=t)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const e in this.propertySet.propertyMap){const t=this.propertySet.getProperty(e),o=t.rootAttribute;t.type==="object"?this.valueSets[e]=this.constructSubValueSet(e):this.values[e]=structuredClone(t.defaultValue),o!=null&&(t.defaultValue!==void 0&&!xe(this.values[e],t.defaultValue)?this.setRootElementValue(o,this.values[e]):this.values[e]=this.getRootElementValue(o)),t.basic?this.displayedProperties.push(t):this.hiddenProperties.push(t)}}constructSubValueSet(e){const t=this.propertySet.getProperty(e),o=new We(t.properties),a=new be(o,this.rootElement);return a.overwriteValues(structuredClone(t.defaultValue)),a}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 ei=i=>i==null||i===""||i instanceof Array&&i.length===0||i instanceof Object&&Object.keys(i).length===0,xe=(i,e)=>i===e||JSON.stringify(i)===JSON.stringify(e),ci=(i,e)=>{const t={},o={},a=[];for(const l in i)a.push(l);for(const l in e)l in i||a.push(l);for(const l of a)if(dt(i[l])&&dt(e[l])){const s=ci(i[l],e[l]);Object.keys(s[0]).length>0&&Object.keys(s[1]).length>0&&(t[l]=s[0],o[l]=s[1])}else xe(i[l],e[l])||(t[l]=i[l],o[l]=e[l]);return[t,o]},dt=i=>i!=null&&i.constructor===Object,Yi={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:ai.Straight,style:li.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class hi{constructor(e){const t={...Yi,...e};this.id=t.id,this.name=t.name,this.label=t.label;const o=ie(t.look);if(this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook,t.startMarkerLook!==void 0){const a=ie(t.startMarkerLook);this.defaultStartMarkerLook=a.defaultLook,this.selectedStartMarkerLook=a.selectedLook,this.highlightedStartMarkerLook=a.highlightedLook,this.selectedAndHighlightedStartMarkerLook=a.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(t.endMarkerLook!==void 0){const a=ie(t.endMarkerLook);this.defaultEndMarkerLook=a.defaultLook,this.selectedEndMarkerLook=a.selectedLook,this.highlightedEndMarkerLook=a.highlightedLook,this.selectedAndHighlightedEndMarkerLook=a.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=t.startTypes,this.endTypes=t.endTypes,this.propertySet=new We(t.properties)}canStartFromType(e){return this.startTypes.indexOf(e)>=0}canFinishOnType(e){return this.endTypes.indexOf(e)>=0}}class le extends Se{constructor(e,t,o,a,l){if(e.connections.get(l)!==void 0)throw new Error(`DiagramConnection with id "${l}" already exists`);if(!l)throw new Error("DiagramConnection cannot have an empty or null id");super(e,l),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=t,this.valueSet=new be(t.propertySet,this),this.originalData={},this.setStart(o),this.setEnd(a)}get type(){return this._type}set type(e){var t,o;(o=(t=this.model.canvas)==null?void 0:t.userSelection)==null||o.openInPropertyEditor(void 0),this._type=e,this.valueSet&&(this.valueSet=new be(e.propertySet,this)),this.updateInView()}get typeString(){return this.type.id}set typeString(e){const t=this.model.connections.types.get(e);t&&(this.type=t)}get name(){return this.middleLabel}set name(e){this.middleLabel=e}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(e){if(e){const t=ie(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook!==void 0?this._selectedAndHighlightedStartMarkerLook:this.type.selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook!==void 0?this._selectedStartMarkerLook:this.type.selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook!==void 0?this._highlightedStartMarkerLook:this.type.highlightedStartMarkerLook:this._defaultStartMarkerLook!==void 0?this._defaultStartMarkerLook:this.type.defaultStartMarkerLook}set startMarkerLook(e){if(e){const t=ie(e);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...t.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...t.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...t.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=e,this._selectedStartMarkerLook=e,this._highlightedStartMarkerLook=e,this._selectedAndHighlightedStartMarkerLook=e}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook!==void 0?this._selectedAndHighlightedEndMarkerLook:this.type.selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook!==void 0?this._selectedEndMarkerLook:this.type.selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook!==void 0?this._highlightedEndMarkerLook:this.type.highlightedEndMarkerLook:this._defaultEndMarkerLook!==void 0?this._defaultEndMarkerLook:this.type.defaultEndMarkerLook}set endMarkerLook(e){if(e){const t=ie(e);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...t.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...t.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...t.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=e,this._selectedEndMarkerLook=e,this._highlightedEndMarkerLook=e,this._selectedAndHighlightedEndMarkerLook=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.connectionPoint)||[0,0])):(this.startDirection=e==null?void 0:e.direction,this.startCoords=(e==null?void 0:e.connectionPoint)||[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.connectionPoint)||[0,0])):(this.endDirection=e==null?void 0:e.direction,this.endCoords=(e==null?void 0:e.connectionPoint)||[0,0]),this.updateInView()}tighten(){var e,t;if((e=this.start)!=null&&e.rootElement&&this.end){const o=this.start.rootElement.ports.map(a=>[a,a.distanceTo(this.end.coords)]).sort((a,l)=>a[1]-l[1]).map(a=>a[0]);e:for(const a of o){if(a===this.end||!a.allowsOutgoing)continue e;{for(const l of a.outgoingConnections)if(l!==this&&l.end===this.end)continue e;for(const l of a.incomingConnections)if(l!==this&&l.start===this.end)continue e}if(a===this.start)break e;this.setStart(a);break e}}if((t=this.end)!=null&&t.rootElement&&this.start){const o=this.end.rootElement.ports.map(a=>[a,a.distanceTo(this.start.coords)]).sort((a,l)=>a[1]-l[1]).map(a=>a[0]);e:for(const a of o){if(a===this.start||!a.allowsIncoming)continue e;{for(const l of a.incomingConnections)if(l!==this&&l.start===this.start)continue e;for(const l of a.outgoingConnections)if(l!==this&&l.end===this.start)continue e}if(a===this.end)break e;this.setEnd(a);break e}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Me}}class Xi extends ue{constructor(e){super(),this.types=new Xe,this.model=e}new(e,t,o,a){let l;if(e instanceof hi)l=e;else{const n=this.types.get(e);if(n===void 0)throw new TypeError(`Connection type with id '${e}' could not be found.`);l=n}const s=new le(this.model,l,t,o,a);return super.add(s),s.updateInView(),s.valueSet.resetValues(),s}remove(e){var o,a;const t=this.get(e,!0);t&&(B(((o=t.start)==null?void 0:o.outgoingConnections)||[],t),B(((a=t.end)==null?void 0:a.incomingConnections)||[],t),super.remove(e),t.updateInView())}}const V={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",horizontalAlign:Ee.Center,verticalAlign:Fe.Center,fit:!1};class ce extends Se{constructor(e,t,o,a,l,s,n,r,d,c,h,g,b,f){const m=`${t==null?void 0:t.id}_field`;if(e.fields.get(m)!==void 0)throw new Error("DiagramField for rootElement already exists");super(e,m),this.textTimestamp=null,this.rootElement=t,this.coords=o,this.width=a,this.height=l,this.fontSize=s,this.fontFamily=n,this.color=r,this.selectedColor=d,this.horizontalAlign=c,this.verticalAlign=h,this.defaultText=g,this._text=g,this.editable=b,this.fit=f}get text(){return this._text}set text(e){var t;(e==null||(e==null?void 0: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())||Me}}class Wi extends ue{constructor(e){super(),this.model=e}new(e,t,o,a,l,s,n,r,d,c,h,g,b){const f=new ce(this.model,e,t,n,r,o,a,l,s,d,c,h,g,b);return super.add(f),f.updateInView(),e!==void 0&&(e.label=f),f}remove(e){var o;const t=this.get(e,!0);t&&(((o=t.rootElement)==null?void 0:o.label)!==void 0&&t.rootElement.label===t&&(t.rootElement.label=void 0),super.remove(e),t.updateInView())}}const oe=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?V.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?V.margin:i.margin.length===1||i.margin.length===2?i.margin[0]:(i.margin.length===3,i.margin[2]),q=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?V.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?V.margin:i.margin.length===1?i.margin[0]:i.margin.length===2||i.margin.length===3?i.margin[1]:i.margin[3],de=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?V.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?V.margin:i.margin.length===1?i.margin[0]:(i.margin.length===2||i.margin.length===3,i.margin[1]),X=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?V.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?V.margin:(i.margin.length===1||i.margin.length===2||i.margin.length===3,i.margin[0]),Ne=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?V.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?V.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),Pe=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?V.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?V.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],ze=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?V.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?V.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),Re=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?V.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?V.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),ti=1,ii=1,Ki=1,Zi=1;class qi{constructor(e){this.margin=e.margin||0,this.defaultWidths=e.defaultWidths||null,this.defaultHeights=e.defaultHeights||null,this.minWidths=e.minWidths||null,this.minHeights=e.minHeights||null,this.sections=[];for(const t of e.sections){const o=[];this.sections.push(o);for(const a of t)o.push(new Ji(a))}}}class Ji{constructor(e){this.label=e.label||null,this.ports=e.ports||[],this.priority=e.priority||Me;const t=ie(e.look||ui);this.defaultLook=t.defaultLook,this.selectedLook=t.selectedLook,this.highlightedLook=t.highlightedLook,this.selectedAndHighlightedLook=t.selectedAndHighlightedLook}}class Z extends Se{constructor(e,t,o,a,l,s,n,r){if(e.sections.get(r)!==void 0)throw new Error(`DiagramSection with id "${r}" already exists`);if(!r)throw new Error("DiagramSection cannot have an empty or null id");super(e,r),this.ports=[],this.decorators=[],this.node=t,this.indexXInNode=o,this.indexYInNode=a,this.coords=l,this.width=s,this.height=n}get name(){var e;return((e=this.label)==null?void 0:e.text)||""}set name(e){this.label&&(this.label.text=e)}get look(){var e,t,o,a,l,s,n,r;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:((e=this.type)==null?void 0:e.selectedAndHighlightedLook)||((t=this.node)==null?void 0:t.look):this._selectedLook!==void 0?this._selectedLook:((o=this.type)==null?void 0:o.selectedLook)||((a=this.node)==null?void 0:a.look):this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:((l=this.type)==null?void 0:l.highlightedLook)||((s=this.node)==null?void 0:s.look):this._defaultLook!==void 0?this._defaultLook:((n=this.type)==null?void 0:n.defaultLook)||((r=this.node)==null?void 0:r.look)}set look(e){if(e){const t=ie(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=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()}get type(){var e,t,o,a,l;return(l=(a=(o=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode]}getMinWidth(){var e,t,o,a;return((a=(o=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:o.minWidths)==null?void 0:a[this.indexXInNode])||Ki}getMinHeight(){var e,t,o,a;return((a=(o=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:o.minHeights)==null?void 0:a[this.indexYInNode])||Zi}getPriority(){var e,t,o,a,l,s;return((s=(l=(a=(o=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode])==null?void 0:s.priority)||Me}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const t=this.ports.map(l=>l.distanceTo(e)),o=t.indexOf(Math.min(...t));return this.ports[o]}}}getIncomingConnections(e=!1){const t=[];for(const o of this.ports)for(const a of o.incomingConnections)!e&&a.removed||t.push(a);return t}getOutgoingConnections(e=!1){const t=[];for(const o of this.ports)for(const a of o.outgoingConnections)!e&&a.removed||t.push(a);return t}getConnections(e=!1){const t=[];for(const o of this.ports){for(const a of o.incomingConnections)!e&&a.removed||t.push(a);for(const a of o.outgoingConnections)!e&&a.removed||t.push(a)}return t}move(e){this.setGeometry({coords:e,width:this.width,height:this.height})}stretch(e,t){const o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(e){case k.Left:l=[o[0]-t,o[1]],s=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[0]=l[1]-this.getMinWidth());break;case k.Top:l=[o[0],o[1]],s=[a[0]-t,a[1]],s[1]-s[0]<this.getMinHeight()&&(s[0]=s[1]-this.getMinHeight());break;case k.Right:l=[o[0],o[1]+t],s=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[1]=l[0]+this.getMinWidth());break;case k.Bottom:l=[o[0],o[1]],s=[a[0],a[1]+t],s[1]-s[0]<this.getMinHeight()&&(s[1]=s[0]+this.getMinHeight());break}this.setGeometry({coords:[l[0],s[0]],width:l[1]-l[0],height:s[1]-s[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(e){const t=[this.coords[0],this.coords[0]+this.width],o=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const n of this.ports)n.move(Be(n.coords,t,o,a,l));const s=this.type;this.label&&(this.label.coords=[this.coords[0]+q(s==null?void 0:s.label),this.coords[1]+X(s==null?void 0:s.label)],this.label.width=this.width-q(s==null?void 0:s.label)-de(s==null?void 0:s.label),this.label.height=this.height-X(s==null?void 0:s.label)-oe(s==null?void 0:s.label),this.label.updateInView());for(const n of this.decorators)n.move(Be(n.coords,t,o,a,l));this.getConnections().forEach(n=>n.tighten()),this.updateInView()}}class Qi extends ue{constructor(e){super(),this.model=e}new(e,t,o,a,l,s,n){var h,g,b,f,m,u,v,w,p,S;const r=new Z(this.model,e,t,o,a,l,s,n);super.add(r),r.updateInView(),e.sections.push(r),e.updateInView();const d=(f=(b=(g=(h=e.type.sectionGrid)==null?void 0:h.sections)==null?void 0:g[o])==null?void 0:b[t])==null?void 0:f.ports;if(d&&d.length>0)for(let x=0;x<d.length;++x){const L=d[x],z=this.model.ports.new(L.type!==void 0?this.model.ports.types.get(L.type):void 0,r,[r.coords[0]+(L.coords[0]||0),r.coords[1]+(L.coords[1]||0)],L.connectionPoint!==void 0?[r.coords[0]+(L.connectionPoint[0]||0),r.coords[1]+(L.connectionPoint[1]||0)]:void 0,L==null?void 0:L.direction,`${r.id}_${x}`);if((m=z.type)!=null&&m.label){const N={...V,...(u=z.type)==null?void 0:u.label},H=6*N.fontSize+Pe(N)+ze(N),P=N.fontSize+Re(N)+Ne(N);let R;switch(z.direction){case k.Bottom:case k.Left:case k.Right:R=[z.coords[0]-H/2,z.coords[1]-P-oe(N)];break;case k.Top:R=[z.coords[0]-H/2,z.coords[1]+X(N)];break;default:R=z.coords}this.model.fields.new(z,R,N.fontSize,N.fontFamily,N.color,N.selectedColor,H,P,N.horizontalAlign,N.verticalAlign,"",N.editable,N.fit)}}const c=(S=(p=(w=(v=e.type.sectionGrid)==null?void 0:v.sections)==null?void 0:w[o])==null?void 0:p[t])==null?void 0:S.label;if(c){const x={...V,...c};this.model.fields.new(r,[r.coords[0]+q(x),r.coords[1]+X(x)],x.fontSize,x.fontFamily,x.color,x.selectedColor,r.width-q(x)-de(x),r.height-X(x)-oe(x),x.horizontalAlign,x.verticalAlign,"",x.editable,x.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 ui={lookType:"shaped-look",shape:Ye.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},he={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:Me,properties:[]};class fi{constructor(e){const t={...he,...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=ts(t),this.leftPadding=is(t),this.rightPadding=ss(t),this.topPadding=os(t),this.label=t.label,this.ports=t.ports,this.sectionGrid=t.sectionGrid?new qi(t.sectionGrid):null;const o=ie(t.look);this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook,this.isUnique=t.isUnique,this.canBeParentless=t.canBeParentless,this.childrenTypes=t.childrenTypes,this.priority=t.priority,this.propertySet=new We((e==null?void 0:e.properties)||[])}}class j extends Se{constructor(e,t,o=[0,0],a){if(e.nodes.get(a)!==void 0)throw new Error(`DiagramNode with id "${a}" already exists`);if(!a)throw new Error("DiagramNode cannot have an empty or null id");super(e,a),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=t,this.valueSet=new be(t.propertySet,this),this.originalData={},this.coords=o,this.width=t.defaultWidth,this.height=t.defaultHeight}get type(){return this._type}set type(e){var t,o;(o=(t=this.model.canvas)==null?void 0:t.userSelection)==null||o.openInPropertyEditor(void 0),this._type=e,this.valueSet&&(this.valueSet=new be(e.propertySet,this)),this.updateInView()}get typeString(){return this.type.id}set typeString(e){const t=this.model.nodes.types.get(e);t&&(this.type=t)}get name(){var e;return((e=this.label)==null?void 0:e.text)||""}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(e){if(e){const t=ie(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=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(l=>l.distanceTo(e)),o=t.indexOf(Math.min(...t));return this.ports[o]}}}getIncomingConnections(e=!1){const t=[];for(const o of this.ports)for(const a of o.incomingConnections)!e&&a.removed||t.push(a);return t}getOutgoingConnections(e=!1){const t=[];for(const o of this.ports)for(const a of o.outgoingConnections)!e&&a.removed||t.push(a);return t}getConnections(e=!1){const t=[];for(const o of this.ports){for(const a of o.incomingConnections)!e&&a.removed||t.push(a);for(const a of o.outgoingConnections)!e&&a.removed||t.push(a)}return t}getAdjacentNodes(e=!1){var o,a;const t=[];for(const l of this.ports){for(const s of l.incomingConnections){if(!e&&s.removed)continue;const n=(o=s.start)==null?void 0:o.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}for(const s of l.outgoingConnections){if(!e&&s.removed)continue;const n=(a=s.end)==null?void 0:a.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}}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,o=!1;for(;t!==void 0;){if(t.id===e.id){o=!0;break}t=t.parent}o||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(k.Left,t);const o=this.coords[1]-e.coords[1]+this.type.topPadding;o>=0&&this.stretch(k.Top,o);const a=e.coords[0]+e.width-(this.coords[0]+this.width)+this.type.rightPadding;a>=0&&this.stretch(k.Right,a);const l=e.coords[1]+e.height-(this.coords[1]+this.height)+this.type.bottomPadding;l>=0&&this.stretch(k.Bottom,l),this.parent&&this.parent.fitToChild(this)}move(e){const t=[e[0]-this.coords[0],e[1]-this.coords[1]];for(const o of this.children)o.move([o.coords[0]+t[0],o.coords[1]+t[1]]);for(const o of this.sections)o.move([o.coords[0]+t[0],o.coords[1]+t[1]]);this.setGeometry({coords:e,width:this.width,height:this.height,sections:{},children:{}})}stretch(e,t){const o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(e){case k.Left:l=[o[0]-t,o[1]],s=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[0]=l[1]-this.type.minWidth);break;case k.Top:l=[o[0],o[1]],s=[a[0]-t,a[1]],s[1]-s[0]<this.type.minHeight&&(s[0]=s[1]-this.type.minHeight);break;case k.Right:l=[o[0],o[1]+t],s=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[1]=l[0]+this.type.minWidth);break;case k.Bottom:l=[o[0],o[1]],s=[a[0],a[1]+t],s[1]-s[0]<this.type.minHeight&&(s[1]=s[0]+this.type.minHeight);break}this.setGeometry({coords:[l[0],s[0]],width:l[1]-l[0],height:s[1]-s[0],sections:{},children:{}})}stretchSections(e,t,o,a){let l=Number.NEGATIVE_INFINITY;switch(e){case k.Bottom:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));t<l&&(t=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(e,t):s.indexYInNode>a&&s.move([s.coords[0],s.coords[1]+t]);break;case k.Right:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));t<l&&(t=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(e,t):s.indexXInNode>o&&s.move([s.coords[0]+t,s.coords[1]]);break;case k.Top:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));t<l&&(t=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(e,t):s.indexYInNode<a&&s.move([s.coords[0],s.coords[1]-t]);break;case k.Left:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));t<l&&(t=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(e,t):s.indexXInNode<o&&s.move([s.coords[0]-t,s.coords[1]]);break}this.stretch(e,t)}getGeometry(e){const t={};for(const a of this.sections)t[a.id]=a.getGeometry();const o={};for(const a of this.children)a.id!==e&&(o[a.id]=a.getGeometry(e));return{coords:[...this.coords],width:this.width,height:this.height,sections:t,children:o}}setGeometry(e){this.raise();const t=[this.coords[0],this.coords[0]+this.width],o=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const s of this.children){const n=e.children[s.id];n&&s.setGeometry(n)}for(const s of this.sections){const n=e.sections[s.id];n&&s.setGeometry(n)}for(const s of this.ports)s.move(Be(s.coords,t,o,a,l));this.label&&(this.label.coords=[this.coords[0]+q(this.type.label),this.coords[1]+X(this.type.label)],this.label.width=this.width-q(this.type.label)-de(this.type.label),this.label.height=this.height-X(this.type.label)-oe(this.type.label),this.label.updateInView());for(const s of this.decorators)s.move(Be(s.coords,t,o,a,l));this.getConnections().forEach(s=>s.tighten()),this.updateInView()}}class es extends ue{constructor(e){super(),this.types=new Xe,this.model=e}new(e,t,o){var s,n,r,d,c,h,g;let a;if(e instanceof fi)a=e;else{const b=this.types.get(e);if(b===void 0)throw new TypeError(`Node type with id '${e}' could not be found.`);a=b}const l=new j(this.model,a,t,o);if(super.add(l),l.updateInView(),a.sectionGrid!==null){let b=l.coords[1]+(a.sectionGrid.margin||0);for(let f=0;f<a.sectionGrid.sections.length;++f){let m=l.coords[0]+(a.sectionGrid.margin||0);for(let u=0;u<a.sectionGrid.sections[f].length;++u)this.model.sections.new(l,u,f,[m,b],((s=a.sectionGrid.defaultWidths)==null?void 0:s[u])||ti,((n=a.sectionGrid.defaultHeights)==null?void 0:n[f])||ii,`${l.id}_${f}_${u}`),m+=(((r=a.sectionGrid.defaultWidths)==null?void 0:r[u])||ti)+(a.sectionGrid.margin||0);b+=(((d=a.sectionGrid.defaultHeights)==null?void 0:d[f])||ii)+(a.sectionGrid.margin||0)}}if(a.ports.length>0)for(let b=0;b<a.ports.length;++b){const f=a.ports[b],m=f.type!==void 0?this.model.ports.types.get(f.type):void 0,u=this.model.ports.new(m,l,[l.coords[0]+f.coords[0],l.coords[1]+f.coords[1]],f.connectionPoint!==void 0?[l.coords[0]+(f.connectionPoint[0]||0),l.coords[1]+(f.connectionPoint[1]||0)]:void 0,f.direction,`${l.id}_${b}`);if((c=u.type)!=null&&c.label){const v={...V,...(h=u.type)==null?void 0:h.label},w=6*v.fontSize+Pe(v)+ze(v),p=v.fontSize+Re(v)+Ne(v);let S;switch(u.direction){case k.Bottom:case k.Left:case k.Right:S=[u.coords[0]-w/2,u.coords[1]-p-oe(v)];break;case k.Top:S=[u.coords[0]-w/2,u.coords[1]+X(v)];break;default:S=u.coords}this.model.fields.new(u,S,v.fontSize,v.fontFamily,v.color,v.selectedColor,w,p,v.horizontalAlign,v.verticalAlign,"",v.editable,v.fit)}}if(a.label){const b={...V,...a.label};this.model.fields.new(l,[l.coords[0]+q(b),l.coords[1]+X(b)],b.fontSize,b.fontFamily,b.color,b.selectedColor,l.width-q(b)-de(b),l.height-X(b)-oe(b),b.horizontalAlign,b.verticalAlign,"",b.editable,b.fit)}return l.valueSet.resetValues(),(g=l.model.canvas)==null||g.fitNodeInView(l.id),l}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 o=[];for(const a of this)a.coords[0]<e&&e<a.coords[0]+a.width&&a.coords[1]<t&&t<a.coords[1]+a.height&&o.push(a);return o}}const gi=i=>{for(let e=0;e<i.length;++e)for(let t=0;t<i.length;++t)t!==e&&i[t].isAncestorOf(i[e])&&(i.splice(t,1),--t,e>t&&--e);return i},ts=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?he.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?he.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),is=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?he.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?he.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],ss=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?he.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?he.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),os=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?he.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?he.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),mi={lookType:"shaped-look",shape:Ye.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},De=ie(mi),pi={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:mi};class ns{constructor(e){const t={...pi,...e};this.id=t.id,this.name=t.name,this.label=t.label,this.allowsOutgoing=t.allowsOutgoing,this.allowsIncoming=t.allowsIncoming,this.width=t.width;const o=ie(t.look);this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook}}class ve extends Se{constructor(e,t,o,a,l,s,n){if(e.ports.get(n)!==void 0)throw new Error(`DiagramPort with id "${n}" already exists`);if(!n)throw new Error("DiagramPort cannot have an empty or null id");super(e,n),this.outgoingConnections=[],this.incomingConnections=[],this._type=t,this.rootElement=o,this.coords=a,this.connectionPoint=l||a,this.direction=s}get type(){return this._type}set type(e){this._type=e,this.updateInView()}get typeString(){var e;return(e=this.type)==null?void 0:e.id}set typeString(e){if(e===void 0)this.type=void 0;else{const t=this.model.ports.types.get(e);t&&(this.type=t)}}get allowsOutgoing(){var e,t;return((e=this.type)==null?void 0:e.allowsOutgoing)!==void 0?(t=this.type)==null?void 0:t.allowsOutgoing:!0}get allowsIncoming(){var e,t;return((e=this.type)==null?void 0:e.allowsIncoming)!==void 0?(t=this.type)==null?void 0:t.allowsIncoming:!0}get name(){var e;return((e=this.label)==null?void 0:e.text)||""}set name(e){this.label&&(this.label.text=e)}get look(){var e,t,o,a;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(e=this.type||De)==null?void 0:e.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(t=this.type||De)==null?void 0:t.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(o=this.type||De)==null?void 0:o.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(a=this.type||De)==null?void 0:a.defaultLook}set look(e){if(e){const t=ie(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get width(){var e;return((e=this.type)==null?void 0:e.width)||pi.width}get height(){return this.width}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(),this.label&&this.label.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 j)return this.rootElement;if(this.rootElement instanceof Z)return this.rootElement.node}getPriority(){var e;return((e=this.rootElement)==null?void 0:e.getPriority())||Me}move(e){const t=[e[0]-this.coords[0],e[1]-this.coords[1]];this.coords=e,this.connectionPoint[0]=this.connectionPoint[0]+t[0],this.connectionPoint[1]=this.connectionPoint[1]+t[1];for(const o of this.outgoingConnections)o.setStart(this);for(const o of this.incomingConnections)o.setEnd(this);this.label&&this.label.move([this.label.coords[0]+t[0],this.label.coords[1]+t[1]]),this.updateInView()}distanceTo(e){return ri(this.coords,e)}}class rs extends ue{constructor(e){super(),this.types=new Xe,this.model=e}new(e,t,o,a,l,s){const n=new ve(this.model,e,t,o,a,l,s);return super.add(n),n.updateInView(),t!==void 0&&t.ports.push(n),n}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 j||t.rootElement instanceof Z)&&B(t.rootElement.ports,t),super.remove(e),t.updateInView()}}}class yi{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 o of t.nodes||[])this.importNode(e,o);for(const o of t.connections||[])this.importConnection(e,o);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 a,l,s,n,r,d,c,h,g,b;const o=e.nodes.types.get(t.type);if(o){const f=new j(e,o,t.coords,t.id);if(e.nodes.add(f),f.width=t.width,f.height=t.height,t.label&&o.label){const u={...V,...o.label},v=new ce(e,f,[f.coords[0]+q(u),f.coords[1]+X(u)],f.width-q(u)-de(u),f.height-X(u)-oe(u),u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,"",u.editable,u.fit);v.text=t.label,f.label=v,e.fields.add(v),v.updateInView()}for(const u of t.children||[]){const v=this.importNode(e,u);v!==void 0&&((a=f.children)==null||a.push(v),v.parent=f)}for(const u of t.sections||[]){const v=new Z(e,f,u.indexXInNode,u.indexYInNode,u.coords,u.width,u.height,u.id);if((l=f.sections)==null||l.push(v),e.sections.add(v),u.label&&(d=(r=(n=(s=o.sectionGrid)==null?void 0:s.sections)==null?void 0:n[u.indexYInNode])==null?void 0:r[u.indexXInNode])!=null&&d.label){const p={...V,...(b=(g=(h=(c=o.sectionGrid)==null?void 0:c.sections)==null?void 0:h[u.indexYInNode])==null?void 0:g[u.indexXInNode])==null?void 0:b.label},S=new ce(e,v,[v.coords[0]+q(p),v.coords[1]+X(p)],v.width-q(p)-de(p),v.height-X(p)-oe(p),p.fontSize,p.fontFamily,p.color,p.selectedColor,p.horizontalAlign,p.verticalAlign,"",p.editable,p.fit);S.text=u.label,v.label=S,e.fields.add(S),S.updateInView()}let w=0;for(const p of u.ports||[]){const S=p.type!==void 0?e.ports.types.get(p.type):void 0,x=new ve(e,S,v,p.coords,p.connectionPoint,p.direction,p.id);if(v.ports.push(x),e.ports.add(x),p.label){if(o.ports.length>w&&(S!=null&&S.label)){const L={...V,...S==null?void 0:S.label};let z;switch(x.direction){case k.Top:case k.Left:z=[x.coords[0]-L.fontSize,x.coords[1]-L.fontSize];break;case k.Bottom:z=[x.coords[0]-L.fontSize,x.coords[1]+L.fontSize];break;case k.Right:z=[x.coords[0]+L.fontSize,x.coords[1]-L.fontSize];break;default:z=x.coords}const N=new ce(e,x,z,L.fontSize,L.fontSize,L.fontSize,L.fontFamily,L.color,L.selectedColor,L.horizontalAlign,L.verticalAlign,"",L.editable,L.fit);N.text=p.label,x.label=N,e.fields.add(N),N.updateInView()}++w}p.collabMeta&&(x.selfRemoved=p.collabMeta.selfRemoved,x.selfRemovedTimestamp=p.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(x.label,p.collabMeta.label)),x.updateInView()}u.collabMeta&&(v.selfRemoved=u.collabMeta.selfRemoved,v.selfRemovedTimestamp=u.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(v.label,u.collabMeta.label)),v.updateInView()}let m=0;for(const u of t.ports||[]){const v=u.type!==void 0?e.ports.types.get(u.type):void 0,w=new ve(e,v,f,u.coords,u.connectionPoint,u.direction,u.id);if(f.ports.push(w),e.ports.add(w),u.label){if(o.ports.length>m&&(v!=null&&v.label)){const p={...V,...v==null?void 0:v.label};let S;switch(w.direction){case k.Top:case k.Left:S=[w.coords[0]-p.fontSize,w.coords[1]-p.fontSize];break;case k.Bottom:S=[w.coords[0]-p.fontSize,w.coords[1]+p.fontSize];break;case k.Right:S=[w.coords[0]+p.fontSize,w.coords[1]-p.fontSize];break;default:S=w.coords}const x=new ce(e,w,S,p.fontSize,p.fontSize,p.fontSize,p.fontFamily,p.color,p.selectedColor,p.horizontalAlign,p.verticalAlign,"",p.editable,p.fit);x.text=u.label,w.label=x,e.fields.add(x),x.updateInView()}++m}u.collabMeta&&(w.selfRemoved=u.collabMeta.selfRemoved,w.selfRemovedTimestamp=u.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(w.label,u.collabMeta.label)),w.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.raise(),f}}importConnection(e,t){const o=e.connections.types.get(t.type);if(o){const a=new le(e,o,t.start?e.ports.get(t.start):void 0,t.end?e.ports.get(t.end):void 0,t.id);return e.connections.add(a),a.startLabel=t.startLabel,a.middleLabel=t.middleLabel,a.endLabel=t.endLabel,a.points=t.points,t.data&&a.valueSet.setValues(t.data),t.collabMeta&&(a.selfRemoved=t.collabMeta.selfRemoved,a.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,a.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),a.updateInView(),a.raise(),a}}importLabelCollabMeta(e,t){e&&t&&(e.selfRemoved=t.selfRemoved,e.selfRemovedTimestamp=t.selfRemovedTimestamp,e.textTimestamp=t.textTimestamp)}}class Ke{constructor(e,t,o,a,l,s,n){this.canvas=e,this.id=t,this.typeId=o,this.coords=a,this.parentId=l,this.label=s,this.values=n}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 Ke(e,t.id,t.typeId,t.coords,t.parentId,t.label,t.values)}}class ut{constructor(e,t,o){this.canvas=e,this.to=t,this.timestamp=o}do(){for(const e in this.to){const t=this.canvas.model.nodes.get(e,!0);if(t&&Ae(this.timestamp,t.geometryTimestamp)){const o=this.to[e];t.move([o[0],o[1]]),t.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new ut(e,t.to,t.timestamp)}}class Ve{constructor(e,t,o,a){this.canvas=e,this.nodeIds=t,this.delta=o,this.timestamp=a}do(){var e;for(const t of this.nodeIds){const o=this.canvas.model.nodes.get(t,!0);o&&Ae(this.timestamp,o.geometryTimestamp)&&(o.move([o.coords[0]+this.delta[0],o.coords[1]+this.delta[1]]),(e=o.parent)==null||e.fitToChild(o),o.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(e,t){return new Ve(e,t.nodeIds,t.delta,t.timestamp)}}class te{constructor(e,t,o,a){this.canvas=e,this.nodeId=t,this.to=o,this.timestamp=a}do(){var t,o,a;const e=this.canvas.model.nodes.get(this.nodeId,!0);if(e&&Ae(this.timestamp,e.geometryTimestamp)){e.setGeometry(this.to),(t=e.label)!=null&&t.fit&&this.canvas.fitFieldRootInView(e.label.id);for(const l of e.sections)(o=l.label)!=null&&o.fit&&this.canvas.fitFieldRootInView(l.label.id);(a=e.parent)==null||a.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 te(e,t.nodeId,t.to,t.timestamp)}}class je{constructor(e,t,o,a,l){this.canvas=e,this.childId=t,this.parentId=o,this.childGeometry=a,this.timestamp=l}do(){var o;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)&&Ae(this.timestamp,e.geometryTimestamp)&&((o=e.parent)==null||o.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 je(e,t.childId,t.parentId,t.childGeometry,t.timestamp)}}class Ze{constructor(e,t,o,a,l){this.canvas=e,this.id=t,this.typeId=o,this.startId=a,this.endId=l}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 Ze(e,t.id,t.typeId,t.startId,t.endId)}}class Te{constructor(e,t,o,a){this.canvas=e,this.fieldId=t,this.to=o,this.timestamp=a}do(){const e=this.canvas.model.fields.get(this.fieldId,!0);e&&Ae(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 Te(e,t.fieldId,t.to,t.timestamp)}}class $e{constructor(e,t,o,a){this.canvas=e,this.id=t,this.to=o,this.timestamp=a}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 $e(e,t.id,t.to,t.timestamp)}}class ae{constructor(e,t,o,a,l,s,n,r){this.canvas=e,this.nodeIds=t,this.sectionIds=o,this.portIds=a,this.connectionIds=l,this.fieldIds=s,this.selfRemoved=n,this.timestamp=r}doOne(e){e&&Ae(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 ae(e,t.nodeIds,t.sectionIds,t.portIds,t.connectionIds,t.fieldIds,t.removed,t.timestamp)}}class qe{constructor(e,t,o){this.canvas=e,this.nodes=t,this.connections=o}do(){const e=new yi;this.canvas.userSelection.clear();for(const t of this.nodes){const o=e.importNode(this.canvas.model,t);o&&this.canvas.userSelection.add(o)}for(const t of this.connections){const o=e.importConnection(this.canvas.model,t);o&&this.canvas.userSelection.add(o)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(e,t){return new qe(e,t.nodes,t.connections)}}class as{constructor(e){this.isInRoom=!1,this.canvas=e,this.replicaId=Qt()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+Qt()}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":{Ke.deserialize(this.canvas,e).do();break}case"applyLayout":{ut.deserialize(this.canvas,e).do();break}case"move":{Ve.deserialize(this.canvas,e).do();break}case"setGeometry":{te.deserialize(this.canvas,e).do();break}case"setParent":{je.deserialize(this.canvas,e).do();break}case"addConnection":{Ze.deserialize(this.canvas,e).do();break}case"editField":{Te.deserialize(this.canvas,e).do();break}case"updateValues":{$e.deserialize(this.canvas,e).do();break}case"setSelfRemoved":{ae.deserialize(this.canvas,e).do();break}case"paste":{qe.deserialize(this.canvas,e).do();break}default:console.error("Unknown CollabAction type, skipping:",e)}}}class ls{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 C=(i=>(i.AddConnection="add-connection",i.AddNode="add-node",i.ApplyLayout="apply-layout",i.Clipboard="clipboard",i.ContextMenu="context-menu",i.EditField="edit-field",i.MoveNode="move-node",i.Paste="paste",i.Remove="remove",i.StretchNode="stretch-node",i.StretchSection="stretch-section",i.UpdateValues="update-values",i.Zoom="zoom",i))(C||{});class ds{constructor(e,t,o,a,l,s,n,r,d){this.canvas=e,this.type=t,this.coords=o,this.parentId=a,this.ancestorId=l,this.fromAncestorGeometry=s,this.toAncestorGeometry=n,this.label=r,this.values=d,this.id=this.canvas.collabEngine.freshId()}do(){const e=new Ke(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 te(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 ae(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const o=new te(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return e!==void 0}redo(){const e=this.canvas.model.nodes.get(this.id),t=new ae(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const o=new te(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return e===void 0}}class tt{constructor(e,t,o){this.canvas=e,this.nodeIds=t,this.delta=o}do(){const e=new Ve(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 Ve(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 Y{constructor(e,t,o,a,l,s,n,r){this.canvas=e,this.intent=t,this.nodeId=o,this.from=a,this.to=l,this.ancestorId=s,this.fromAncestorGeometry=n,this.toAncestorGeometry=r}do(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){const t=new te(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 o=new te(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}}return e!==void 0}undo(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){this.to=e.getGeometry();const t=new te(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 o=new te(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}}return e!==void 0}redo(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){this.from=e.getGeometry();const t=new te(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}}class cs{constructor(e,t,o,a,l,s,n,r,d){this.canvas=e,this.childId=t,this.fromParentId=o,this.toParentId=a,this.fromChildGeometry=l,this.toChildGeometry=s,this.ancestorId=n,this.fromAncestorGeometry=r,this.toAncestorGeometry=d}do(){const e=this.canvas.model.nodes.get(this.childId),t=new je(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 o=new te(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return e!==void 0}undo(){const e=this.canvas.model.nodes.get(this.childId),t=new je(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 o=new te(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return e!==void 0}redo(){return this.do()}}class it{constructor(e,t,o,a){this.canvas=e,this.type=t,this.startId=o,this.endId=a,this.id=this.canvas.collabEngine.freshId()}do(){const e=new Ze(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 ae(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 ae(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e===void 0}}class si{constructor(e,t,o,a){this.canvas=e,this.fieldId=t,this.from=o,this.to=a}do(){const e=this.canvas.model.fields.get(this.fieldId),t=new Te(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 Te(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 Te(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}}class hs{constructor(e,t,o,a){this.canvas=e,this.id=t,this.from=o,this.to=a}do(){const e=new $e(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){const e=new $e(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 $e(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 us{constructor(e,t,o,a,l,s){this.canvas=e,this.nodeIds=t,this.sectionIds=o,this.portIds=a,this.connectionIds=l,this.fieldIds=s}do(){const e=this.nodeIds.map(o=>this.canvas.model.nodes.get(o)!==void 0).includes(!0)||this.sectionIds.map(o=>this.canvas.model.sections.get(o)!==void 0).includes(!0)||this.portIds.map(o=>this.canvas.model.ports.get(o)!==void 0).includes(!0)||this.connectionIds.map(o=>this.canvas.model.connections.get(o)!==void 0).includes(!0)||this.fieldIds.map(o=>this.canvas.model.fields.get(o)!==void 0).includes(!0),t=new ae(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(o=>this.canvas.model.nodes.get(o)===void 0).includes(!0)||this.sectionIds.map(o=>this.canvas.model.sections.get(o)===void 0).includes(!0)||this.portIds.map(o=>this.canvas.model.ports.get(o)===void 0).includes(!0)||this.connectionIds.map(o=>this.canvas.model.connections.get(o)===void 0).includes(!0)||this.fieldIds.map(o=>this.canvas.model.fields.get(o)===void 0).includes(!0),t=new ae(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 fs{constructor(e,t,o,a){this.canvas=e,this.nodes=t,this.connections=o,this.coords=a}do(){const e=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const l of this.nodes)l.coords[0]<e[0]&&(e[0]=l.coords[0]),l.coords[1]<e[1]&&(e[1]=l.coords[1]);const t=this.coords!==void 0?[this.coords[0]-e[0],this.coords[1]-e[1]]:void 0,o={};for(const l of this.nodes){const s=l.id,n=this.canvas.collabEngine.freshId();if(o[s]=n,l.id=n,t&&(l.coords=[l.coords[0]+t[0],l.coords[1]+t[1]]),l.sections)for(const r of l.sections){const d=r.id;if(r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),o[d]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]]),r.ports)for(const c of r.ports){const h=c.id;c.id.includes(l.id)?c.id=c.id.replace(l.id,n):c.id=this.canvas.collabEngine.freshId(),o[h]=c.id,t&&(c.coords=[c.coords[0]+t[0],c.coords[1]+t[1]])}}if(l.ports)for(const r of l.ports){const d=r.id;r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),o[d]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]])}}for(const l of this.connections){const s=this.canvas.collabEngine.freshId();if(o[l.id]=s,l.id=s,l.start=o[l.start]||l.start,l.end=o[l.end]||l.end,t)for(let n=0;n<l.points.length;++n)l.points[n]=[l.points[n][0]+t[0],l.points[n][1]+t[1]]}const a=new qe(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(a),!0}undo(){const e=this.nodes.map(o=>this.canvas.model.nodes.get(o.id)!==void 0).includes(!0)||this.connections.map(o=>this.canvas.model.connections.get(o.id)!==void 0).includes(!0),t=new ae(this.canvas,this.nodes.map(o=>o.id),[],[],this.connections.map(o=>o.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){const e=this.nodes.map(o=>this.canvas.model.nodes.get(o.id)===void 0).includes(!0)||this.connections.map(o=>this.canvas.model.connections.get(o.id)===void 0).includes(!0),t=new ae(this.canvas,this.nodes.map(o=>o.id),[],[],this.connections.map(o=>o.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}}class Je{constructor(e){this.type=e,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}class me extends Je{constructor(e,t,o){super(0),this.cause=e,this.target=t,this.coords=o}}class pe extends Je{constructor(e,t,o){super(1),this.cause=e,this.target=t,this.coords=o}}class F extends Je{constructor(e,t){super(2),this.targets=e,this.selected=t}}class se extends Je{constructor(e){super(3),this.target=e}}class gs extends Se{constructor(e,t,o,a,l,s,n,r){if(e.objects.get(r)!==void 0)throw new Error(`DiagramDecorator with id "${r}" already exists`);if(!r)throw new Error("DiagramDecorator cannot have an empty or null id");super(e,r),this.rootElement=t,this.coords=o,this.width=a,this.height=l,this.priority=s,this.html=n}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 ms extends ue{constructor(e){super(),this.model=e}new(e,t,o,a,l,s,n){const r=new gs(this.model,e,t,o,a,l,s,n);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 j||t.rootElement instanceof Z)&&B(t.rootElement.decorators,t),super.remove(e),t.updateInView())}}class ps extends Se{constructor(e,t,o,a,l,s,n){if(e.objects.get(n)!==void 0)throw new Error(`DiagramObject with id "${n}" already exists`);if(!n)throw new Error("DiagramObject cannot have an empty or null id");super(e,n),this.coords=t,this.width=o,this.height=a,this.priority=l,this.html=s}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 ys extends ue{constructor(e){super(),this.model=e}new(e,t,o,a,l,s){const n=new ps(this.model,e,t,o,a,l,s);return super.add(n),n.updateInView(),n}remove(e){const t=this.get(e,!0);t&&(super.remove(e),t.updateInView())}}class bi{constructor(e,t,o,a,l,s=[]){this.nodes=new es(this),this.sections=new Qi(this),this.ports=new rs(this),this.connections=new Xi(this),this.fields=new Wi(this),this.objects=new ys(this),this.decorators=new ms(this),this.canvas=e,this.id=t,this.name=o,this.description=a,this.type=l,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new be(new We(s),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 ye=i=>!!i.button,st=(i,e,t,o,a,l,s,n)=>Mi(i,[e,t],o,a,Math.max(10,s||0,n||0)*l),A=i=>{i?T.select("body").style("cursor",i):T.select("body").style("cursor",M.Auto)},ke=i=>i instanceof j?i:i instanceof Z?i.node||i:i.rootElement instanceof j||i.rootElement instanceof Z||i.rootElement instanceof ve?ke(i.rootElement):i,ot=i=>{i.filter(".shaped-look").append("path"),i.filter(".image-look").append("image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none")},nt=i=>{i.filter(".shaped-look").select("path").attr("d",e=>lt(e.look.shape,0,0,e.width,e.height)).attr("fill",e=>e.look.fillColor).attr("stroke",e=>e.look.borderColor).attr("stroke-width",e=>`${e.look.borderThickness}px`),i.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",e=>e.width).attr("height",e=>e.height).attr("href",e=>e.look.backgroundImage),i.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",e=>e.look.leftMargin).attr("height",e=>e.look.topMargin).attr("href",e=>e.look.backgroundImageTopLeft),i.filter(".stretchable-image-look").select("image.top-image").attr("x",e=>e.look.leftMargin).attr("y",0).attr("width",e=>e.width-e.look.rightMargin-e.look.leftMargin).attr("height",e=>e.look.topMargin).attr("href",e=>e.look.backgroundImageTop),i.filter(".stretchable-image-look").select("image.top-right-image").attr("x",e=>e.width-e.look.rightMargin).attr("y",0).attr("width",e=>e.look.rightMargin).attr("height",e=>e.look.topMargin).attr("href",e=>e.look.backgroundImageTopRight),i.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",e=>e.look.topMargin).attr("width",e=>e.look.leftMargin).attr("height",e=>e.height-e.look.bottomMargin-e.look.topMargin).attr("href",e=>e.look.backgroundImageLeft),i.filter(".stretchable-image-look").select("image.center-image").attr("x",e=>e.look.leftMargin).attr("y",e=>e.look.topMargin).attr("width",e=>e.width-e.look.rightMargin-e.look.leftMargin).attr("height",e=>e.height-e.look.bottomMargin-e.look.topMargin).attr("href",e=>e.look.backgroundImageCenter),i.filter(".stretchable-image-look").select("image.right-image").attr("x",e=>e.width-e.look.rightMargin).attr("y",e=>e.look.topMargin).attr("width",e=>e.look.rightMargin).attr("height",e=>e.height-e.look.bottomMargin-e.look.topMargin).attr("href",e=>e.look.backgroundImageRight),i.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",e=>e.height-e.look.bottomMargin).attr("width",e=>e.look.leftMargin).attr("height",e=>e.look.bottomMargin).attr("href",e=>e.look.backgroundImageBottomLeft),i.filter(".stretchable-image-look").select("image.bottom-image").attr("x",e=>e.look.leftMargin).attr("y",e=>e.height-e.look.bottomMargin).attr("width",e=>e.width-e.look.rightMargin-e.look.leftMargin).attr("height",e=>e.look.bottomMargin).attr("href",e=>e.look.backgroundImageBottom),i.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",e=>e.width-e.look.rightMargin).attr("y",e=>e.height-e.look.bottomMargin).attr("width",e=>e.look.rightMargin).attr("height",e=>e.look.bottomMargin).attr("href",e=>e.look.backgroundImageBottomRight)},ct=96,Q=32,Le=ct+Q,bs=Math.PI/4,vs=100;class ks{constructor(e){this.canvas=e}open(e){this.close();const t=this.canvas.getPointerLocationRelativeToRoot(e),o=this.canvas.getPointerLocationRelativeToCanvas(e),a=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${t[0]-Le}px`).attr("y",`${t[1]-Le}px`).attr("width",`${2*Le}px`).attr("height",`${2*Le}px`).style("pointer-events","none").on(I.ContextMenu,s=>{this.canvas.canUserPerformAction(C.ContextMenu)&&(e.preventDefault(),this.open(s))}).on(I.Click,s=>{s.preventDefault(),this.close()});this.contextMenuContainer=a;const l=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"CUT",imageClass:"daga-cut",onPress:s=>{s.preventDefault(),this.canvas.userSelection.cutToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&l.push({name:"COPY",imageClass:"daga-copy",onPress:s=>{s.preventDefault(),this.canvas.userSelection.copyToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.canUserPerformAction(C.Paste)&&l.push({name:"PASTE",imageClass:"daga-paste",onPress:s=>{s.preventDefault(),this.canvas.userSelection.pasteFromClipboard(this.canvas.getClosestGridPoint(o)),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"DELETE",imageClass:"daga-delete",onPress:s=>{s.preventDefault(),this.canvas.userSelection.removeFromModel(),this.canvas.cancelAllUserActions()}}),l.length===0&&l.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let s=0;s<l.length;++s){const n=l[s],r=n.onPress,d=(s+.5-l.length/2)*bs,c=a.append("xhtml:div").attr("class",`daga-context-menu-button ${n.imageClass}-button${n.onPress!=null?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*Q}px`).style("height",`${2*Q}px`).style("border-radius",`${Q}px`).style("pointer-events","auto").on(I.Click,h=>{r&&r(h)}).on(I.KeyDown,h=>{r&&h.key===ee.Enter&&r(h)});c.append("xhtml:div").style("position","absolute").style("left",`${.75*Q}px`).style("top",`${.5*Q}px`).style("width",`${.5*Q}px`).style("height",`${.5*Q}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass),c.append("xhtml:span").style("position","absolute").style("left",`${.2*Q}px`).style("top",`${1.1*Q}px`).style("text-align","center").style("width",`${1.6*Q}px`).style("height",`${.35*Q}px`).style("margin","0").style("font-size",`${.35*Q}px`).style("font-weight","700").style("user-select","none").text(n.name),c.transition().ease(T.easeLinear).duration(vs).tween("progress",()=>h=>{const g=d*h;return c.style("left",`${Math.sin(g)*ct-Q+Le}px`).style("top",`${-Math.cos(g)*ct-Q+Le}px`)})}}close(){var e;(e=this.contextMenuContainer)==null||e.remove(),this.contextMenuContainer=void 0}}class ws extends ue{constructor(e){super(),this.focus=void 0,this.canvas=e}getFocus(){return this.focus}focusOn(e){this.clear(),this.focus=e,e instanceof ce&&e.rootElement?this.focusOn(e.rootElement):this.add(e)}add(e){if(super.add(e),e instanceof j){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 Z){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 ve?(e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updatePortsInView(e.id)):e instanceof le&&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 xs=1;class vi{export(e,t=!1){const o={name:e.name,type:e.type,typeVersion:xs,createdAt:e.createdAt,updatedAt:e.updatedAt,nodes:[],connections:[],data:e.valueSet.getValues(),...t?{collabMeta:{logicalClock:e.logicalClock,dataTimestamps:e.valueSet.getTimestamps()}}:{}};e.id&&(o.id=e.id),e.description&&(o.description=e.description);for(const a of e.nodes.all(!0))!t&&a.removed||a.parent===void 0&&o.nodes.push(this.exportNode(a,t));for(const a of e.connections.all(!0))!t&&a.removed||o.connections.push(this.exportConnection(a,t));return o}exportNode(e,t=!1){var s,n,r,d,c,h;const o=[];for(const g of e.children)o.push(this.exportNode(g,t));const a=[];for(const g of e.sections){const b=[];for(const f of g.ports)b.push({id:f.id,type:(s=f.type)==null?void 0:s.id,coords:Ie(f.coords),connectionPoint:Ie(f.connectionPoint),direction:f.direction,label:((n=f.label)==null?void 0:n.text)||"",...t?{collabMeta:{removed:f.removed,selfRemoved:f.selfRemoved,selfRemovedTimestamp:f.selfRemovedTimestamp,...this.exportLabelCollabMeta(f)}}:{}});a.push({id:g.id,ports:b,label:((r=g.label)==null?void 0:r.text)||"",indexXInNode:g.indexXInNode,indexYInNode:g.indexYInNode,coords:Ie(g.coords),width:g.width,height:g.height,...t?{collabMeta:{removed:g.removed,selfRemoved:g.selfRemoved,selfRemovedTimestamp:g.selfRemovedTimestamp,...this.exportLabelCollabMeta(g)}}:{}})}const l=[];for(const g of e.ports)l.push({id:g.id,type:(d=g.type)==null?void 0:d.id,coords:Ie(g.coords),connectionPoint:Ie(g.connectionPoint),direction:g.direction,label:((c=g.label)==null?void 0:c.text)||"",...t?{collabMeta:{removed:g.removed,selfRemoved:g.selfRemoved,selfRemovedTimestamp:g.selfRemovedTimestamp,...this.exportLabelCollabMeta(g)}}:{}});return{id:e.id,type:e.type.id,children:o,sections:a,ports:l,label:((h=e.label)==null?void 0:h.text)||"",coords:Ie(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 o,a;return{id:e.id,type:e.type.id,start:((o=e.start)==null?void 0:o.id)||"",end:((a=e.end)==null?void 0:a.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 Cs="Diagram properties";class Ss extends ue{constructor(e){super(),this.canvas=e,this.canvas.propertyEditorChanges$.pipe(we.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(e){if(!this.contains(e.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(e instanceof j||e instanceof le)?this.openInPropertyEditor(e):this.propertyEditorSelection===void 0&&e instanceof Z?this.openInPropertyEditor(e.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(e),e.updateInView(),e instanceof j&&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 j&&t.sections))for(const o of t.sections)super.remove(o.id),o.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 j&&t.move([t.coords[0]+e[0],t.coords[1]+e[1]])}removeFromModel(){if(this.length>0){const e=[],t=[],o=[],a=[],l=[];for(const n of this.all())n instanceof j?e.push(n.id):n instanceof Z?t.push(n.id):n instanceof ve?o.push(n.id):n instanceof le?a.push(n.id):n instanceof ce&&l.push(n.id);const s=new us(this.canvas,e,t,o,a,l);s.do(),this.canvas.actionStack.add(s)}}copyToClipboard(){const e={type:"daga-user-selection",nodes:[],connections:[]},t=new vi;for(const o of this.all())o instanceof j&&e.nodes.push(t.exportNode(o,!1)),o instanceof le&&e.connections.push(t.exportConnection(o,!1));navigator.clipboard.writeText(JSON.stringify(e))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(e){navigator.clipboard.readText().then(t=>{try{const o=JSON.parse(t);if(o.type!=="daga-user-selection")return;const a=new fs(this.canvas,o.nodes,o.connections,e);this.canvas.actionStack.add(a),a.do()}catch{return}})}openInPropertyEditor(e){var a;this.makeUpdateValuesAction();const t=(a=this.canvas.parentComponent)==null?void 0:a.propertyEditor;if(t===void 0)return;const o=e==null?void 0:e.valueSet;o?(this.propertyEditorSelection=e,this.propertyEditorValues=structuredClone(o.getValues()),t&&(e instanceof j||e instanceof le?(e instanceof j?e.name?t.title=`${e.type.name}: ${e.name}`:t.title=e.type.name:e instanceof le&&(t.title=e.type.name),t.valueSet=void 0,t.valueSet=o):(t.title=Cs,t.valueSet=void 0,t.valueSet=o))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,t&&(t.title="",t.valueSet=void 0))}makeUpdateValuesAction(){var n,r;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const e=this.propertyEditorSelection instanceof bi?void 0:this.propertyEditorSelection.id;if(xe(this.propertyEditorValues,(n=this.propertyEditorSelection)==null?void 0:n.valueSet.getValues()))return;const t=this.propertyEditorValues,o=structuredClone((r=this.propertyEditorSelection)==null?void 0:r.valueSet.getValues()),[a,l]=ci(t,o),s=new hs(this.canvas,e,a,l);s.do(),this.canvas.actionStack.add(s),this.propertyEditorValues=o}}const As=12,O=6,Is=25,rt="diagram-connection-unfinished",Ls=100,Ue=class Ue{constructor(e,t){var o,a,l,s,n,r,d,c,h,g,b,f,m,u,v,w,p,S;if(this.backgroundPatternId=`daga-background-pattern-id-${Ue.canvasCount++}`,this.zoomTransform=T.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new we.Subject,this.diagramChange$=new we.Subject,this.diagramEvent$=new we.Subject,this.propertyEditorChanges$=new we.Subject,this.parentComponent=e,this.model=new bi(this,void 0,t.name||"unnamed","",t.type||"",t.properties||[]),this.userSelection=new Ss(this),this.userHighlight=new ws(this),this.contextMenu=new ks(this),this.backgroundColor=((o=t.canvas)==null?void 0:o.backgroundColor)||"#FFFFFF",this.gridSize=((l=(a=t.canvas)==null?void 0:a.grid)==null?void 0:l.enabled)===!1||((s=t.canvas)==null?void 0:s.grid)===void 0?0:Math.abs(((r=(n=t.canvas)==null?void 0:n.grid)==null?void 0:r.spacing)||10),this.gridThickness=Math.abs(((c=(d=t.canvas)==null?void 0:d.grid)==null?void 0:c.thickness)||.05),this.gridColor=((g=(h=t.canvas)==null?void 0:h.grid)==null?void 0:g.color)||"rgba(0, 0, 0, 0.1)",this.snapToGrid=((f=(b=t.canvas)==null?void 0:b.grid)==null?void 0:f.enabled)===!1||((m=t.canvas)==null?void 0:m.grid)===void 0?!1:((v=(u=t.canvas)==null?void 0:u.grid)==null?void 0:v.snap)||!1,this.zoomFactor=((w=t.canvas)==null?void 0:w.zoomFactor)||2,this.panRate=((p=t.canvas)==null?void 0:p.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 ls(this,Is),this.collabEngine=new as(this),t.nodeTypes)for(const x of t.nodeTypes){const L=new fi({...t.nodeTypeDefaults,...x});this.model.nodes.types.add(L)}if(t.portTypes)for(const x of t.portTypes){const L=new ns({...t.portTypeDefaults,...x});this.model.ports.types.add(L)}if(t.connectionTypes){for(const x of t.connectionTypes){const L=new hi({...t.connectionTypeDefaults,...x});this.model.connections.types.add(L)}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,o;this._connectionType=e,(o=(t=this.parentComponent)==null?void 0:t.palette)==null||o.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,o;this.priorityThreshold=e,this.updateModelInView();for(const a of this.model.nodes)this.fitNodeInView(a.id);(o=(t=this.parentComponent)==null?void 0:t.palette)==null||o.refreshPalette()}initView(e){const t=T.select(e);t.html(""),this.diagramRoot=t.append("div").node(),T.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),T.select(this.diagramRoot).on(I.Click,()=>{var s;(s=T.select(this.diagramRoot).node())==null||s.focus()}).on(I.ContextMenu,s=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const n=new pe(s,null);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.contextMenu.open(s))}).on(I.DoubleClick,s=>{const n=new me(s,null);this.diagramEvent$.next(n)}).on(I.KeyDown,s=>{if(!s.ctrlKey&&(s.key===ee.Delete||s.key===ee.Backspace)&&this.canUserPerformAction(C.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),s.ctrlKey&&s.key==="a"){s.preventDefault();for(const n of this.model.nodes)this.userSelection.add(n);for(const n of this.model.connections)this.userSelection.add(n);this.diagramEvent$.next(new F(this.userSelection.all(),!0))}if(s.ctrlKey&&s.key==="i"){s.preventDefault();const n=[],r=[];for(const d of this.model.nodes)this.userSelection.toggle(d),d.selected?n.push(d):r.push(d);for(const d of this.model.connections)this.userSelection.toggle(d),d.selected?n.push(d):r.push(d);n.length>0&&this.diagramEvent$.next(new F(n,!0)),r.length>0&&this.diagramEvent$.next(new F(r,!1))}if(s.ctrlKey&&s.key==="c"&&(s.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),s.ctrlKey&&s.key==="x"&&(s.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),s.ctrlKey&&s.key==="v"){s.preventDefault();const n=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(n[0][0]+n[1][0])/2,(n[0][1]+n[1][1])/2])),this.cancelAllUserActions()}s.ctrlKey&&s.key==="y"&&(s.preventDefault(),this.actionStack.redo()),s.ctrlKey&&s.key==="z"&&(s.preventDefault(),this.actionStack.undo()),s.key==="+"&&(s.preventDefault(),this.zoomBy(this.zoomFactor)),s.key==="-"&&(s.preventDefault(),this.zoomBy(1/this.zoomFactor)),s.key===ee.ArrowLeft&&(s.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),s.key===ee.ArrowRight&&(s.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),s.key===ee.ArrowDown&&(s.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),s.key===ee.ArrowUp&&(s.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const o=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%"),a=o.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,s=>{if(this.unfinishedConnection!==void 0){const n=this.getPointerLocationRelativeToCanvas(s);this.unfinishedConnection.endCoords=n}}).on(I.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new se(null)))}).on(I.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new se(null))),this.contextMenu.close(),this.userSelection.size()>0){const s=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(s,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(T.drag().filter(s=>this.multipleSelectionOn||ye(s)).on(E.Start,s=>{this.startMultipleSelection(s)}).on(E.Drag,s=>{this.continueMultipleSelection(s)}).on(E.End,s=>{this.finishMultipleSelection(s)})).call(this.zoomBehavior=T.zoom().on(at.Zoom,s=>{if(s.sourceEvent){if(!this.canUserPerformAction(C.Zoom)){A(M.NotAllowed);return}s.sourceEvent.type===I.Wheel&&s.sourceEvent.wheelDelta!==void 0?(s.sourceEvent.wheelDelta>0&&A(M.ZoomIn),s.sourceEvent.wheelDelta<0&&A(M.ZoomOut)):s.sourceEvent.type===I.MouseMove&&A(M.AllScroll)}this.zoomTransform=s.transform;const n=s.transform.toString();this.selectCanvasElements().attr("transform",n),T.select(`#${this.backgroundPatternId}`).attr("patternTransform",n),this.contextMenu.close()}).on(at.End,()=>{A()})),l=o.append("defs");if(this.gridSize>0&&isFinite(this.gridSize)){const s=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");s.append("rect").attr("x",0).attr("y",0).attr("width",this.gridSize).attr("height",this.gridSize).attr("fill",this.backgroundColor),s.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})`)}o.append("g").attr("class","daga-canvas-elements")}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(){var e;if(this.model.nodes.length>0){const t=(e=this.selectCanvasView().select("rect").node())==null?void 0:e.getBBox(),o=this.model.nodes.all(),a=Math.min(...o.map(m=>m.coords[0])),l=Math.max(...o.map(m=>m.coords[0]+m.width)),s=(a+l)/2,n=l-a,r=t.width,d=Math.min(...o.map(m=>m.coords[1])),c=Math.max(...o.map(m=>m.coords[1]+m.height)),h=(d+c)/2,g=c-d,b=t.height,f=Math.min(r/n,b/g,1);this.translateTo(s,h),this.zoomTo(f)}}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 o;const e=(o=this.selectSVGElement().node())==null?void 0:o.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 T.pointer(this.getEventHoldingCoordinates(e),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(e){return T.pointer(this.getEventHoldingCoordinates(e),this.selectSVGElement().node())}getPointerLocationRelativeToBody(e){return T.pointer(this.getEventHoldingCoordinates(e),T.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(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("g").attr("id",s=>s.id).attr("class",s=>`diagram-node${s.type.resizableX?" resizable-x":""}${s.type.resizableY?" resizable-y":""} ${s.type.defaultLook.lookType}`);e&&e.length>0&&(t=t.filter(s=>e.includes(s.id)));const l=a.merge(t);o.remove(),a.on(I.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(n)))}).on(I.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(r,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new F([n],n.selected))}).on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(n)),this.userSelection.add(n),this.diagramEvent$.next(new F([n],!0)),this.contextMenu.open(s))}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(s):this.startMovingNode(s,n)}).on(E.Drag,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(s):this.continueMovingNode(s,n)}).on(E.End,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(s):this.finishMovingNode(s,n),this.secondaryButton=!1})),ot(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${O}px`).on(I.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A(M.EWResize)}).on(I.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(A(M.EWResize),this.currentAction=new Y(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(s);n.stretch(k.Left,n.coords[0]-r[0])}}).on(E.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Left,n.coords[0]-r[0]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${O}px`).on(I.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A(M.NSResize)}).on(I.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(A(M.NSResize),this.currentAction=new Y(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(s);n.stretch(k.Top,n.coords[1]-r[1])}}).on(E.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Top,n.coords[1]-r[1]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${O}px`).on(I.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A(M.EWResize)}).on(I.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(A(M.EWResize),this.currentAction=new Y(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(s);n.stretch(k.Right,r[0]-(n.coords[0]+n.width))}}).on(E.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Right,r[0]-(n.coords[0]+n.width)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${O}px`).on(I.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A(M.NSResize)}).on(I.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(A(M.NSResize),this.currentAction=new Y(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(s);n.stretch(k.Bottom,r[1]-(n.coords[1]+n.height))}}).on(E.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Bottom,r[1]-(n.coords[1]+n.height)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),l.attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).attr("opacity",s=>s.removed?.5:1),nt(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",O/2).attr("x2",O/2).attr("y1",0).attr("y2",s=>s.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",s=>s.width).attr("y1",O/2).attr("y2",O/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",s=>s.width-O/2).attr("x2",s=>s.width-O/2).attr("y1",0).attr("y2",s=>s.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",s=>s.width).attr("y1",s=>s.height-O/2).attr("y2",s=>s.height-O/2)}updateSectionsInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("g").attr("id",s=>s.id).attr("class",s=>{var n,r,d,c,h;return`diagram-section${(r=(n=s.node)==null?void 0:n.type)!=null&&r.resizableX?" resizable-x":""}${(c=(d=s.node)==null?void 0:d.type)!=null&&c.resizableY?" resizable-y":""} ${(h=s.look)==null?void 0:h.lookType}`});e&&e.length>0&&(t=t.filter(s=>e.includes(s.id)));const l=a.merge(t);o.remove(),a.on(I.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(n)))}).on(I.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(d,!1))}const r=ke(n);this.userSelection.toggle(r),this.diagramEvent$.next(new F([r],r.selected))}).on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const d=ke(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new se(d)),this.userSelection.add(d),this.diagramEvent$.next(new F([d],!0)),this.contextMenu.open(s)}}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(s);else{const r=n==null?void 0:n.node;r?this.startMovingNode(s,r):A(M.NotAllowed)}}).on(E.Drag,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else{const r=n==null?void 0:n.node;r?this.continueMovingNode(s,r):A(M.NotAllowed)}}).on(E.End,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{const r=n==null?void 0:n.node;r?this.finishMovingNode(s,r):A()}this.secondaryButton=!1})),ot(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${O}px`).on(I.MouseOver,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&A(M.EWResize)}).on(I.MouseOut,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed?(A(M.EWResize),this.currentAction=new Y(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed){const c=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Left,n.coords[0]-c[0],n.indexXInNode,n.indexYInNode)}}).on(E.End,(s,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(c=this.getClosestGridPoint(c)),n.node.stretchSections(k.Left,n.coords[0]-c[0],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${O}px`).on(I.MouseOver,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&A(M.NSResize)}).on(I.MouseOut,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed?(A(M.NSResize),this.currentAction=new Y(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed){const c=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Top,n.coords[1]-c[1],n.indexXInNode,n.indexYInNode)}}).on(E.End,(s,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(c=this.getClosestGridPoint(c)),n.node.stretchSections(k.Top,n.coords[1]-c[1],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${O}px`).on(I.MouseOver,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&A(M.EWResize)}).on(I.MouseOut,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed?(A(M.EWResize),this.currentAction=new Y(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed){const c=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Right,c[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on(E.End,(s,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(c=this.getClosestGridPoint(c)),n.node.stretchSections(k.Right,c[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${O}px`).on(I.MouseOver,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&A(M.NSResize)}).on(I.MouseOut,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed?(A(M.NSResize),this.currentAction=new Y(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed){const c=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Bottom,c[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on(E.End,(s,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(c=this.getClosestGridPoint(c)),n.node.stretchSections(k.Bottom,c[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),l.attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).attr("opacity",s=>s.removed?.5:1),nt(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",O/2).attr("x2",O/2).attr("y1",0).attr("y2",s=>s.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",s=>s.width).attr("y1",O/2).attr("y2",O/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",s=>s.width-O/2).attr("x2",s=>s.width-O/2).attr("y1",0).attr("y2",s=>s.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",s=>s.width).attr("y1",s=>s.height-O/2).attr("y2",s=>s.height-O/2)}updatePortsInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("g").attr("id",s=>s.id).attr("class",s=>`diagram-port ${s.look.lookType}`);e&&e.length>0&&(t=t.filter(s=>e.includes(s.id)));const l=a.merge(t);o.remove(),a.on(I.MouseOver,(s,n)=>{var r,d,c,h,g,b,f,m,u,v,w,p;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(n))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((c=(d=(r=this.unfinishedConnection.start)==null?void 0:r.getNode())==null?void 0:d.type)==null?void 0:c.id)||"")&&((h=this.unfinishedConnection.start)!=null&&h.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((b=(g=n.getNode())==null?void 0:g.type)==null?void 0:b.id)||"")&&n.allowsIncoming||this.unfinishedConnection.type.canStartFromType(((m=(f=n.getNode())==null?void 0:f.type)==null?void 0:m.id)||"")&&n.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(((w=(v=(u=this.unfinishedConnection.start)==null?void 0:u.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&((p=this.unfinishedConnection.start)!=null&&p.allowsIncoming)||A(M.NoDrop))}).on(I.MouseOut,()=>{this.unfinishedConnection&&A(M.Grabbing)}).on(I.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(d,!1))}const r=ke(n);this.userSelection.toggle(r),this.diagramEvent$.next(new F([r],r.selected))}).on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const d=ke(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new se(d)),this.userSelection.add(d),this.diagramEvent$.next(new F([d],!0)),this.contextMenu.open(s)}}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(s):this.canUserPerformAction(C.AddConnection)&&!n.removed?(A(M.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{var r,d,c,h;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else if(this.canUserPerformAction(C.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const g=[s.x,s.y];(c=this.unfinishedConnectionTracer)==null||c.attr("d",st(this.unfinishedConnection.look.shape,this.unfinishedConnection.startCoords,g,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.look.thickness,(r=this.unfinishedConnection.startMarkerLook)==null?void 0:r.width,(d=this.unfinishedConnection.endMarkerLook)==null?void 0:d.width));const b=(h=this.unfinishedConnectionTracer)==null?void 0:h.node();if(b){let f=2;const m=b.getTotalLength();m<f&&(f=0);const u=b.getPointAtLength(m-f);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=g;if(this.updateConnectionsInView(rt),this.model.ports.length>0){const f=this.getPointerLocationRelativeToCanvas(s);let m=Number.POSITIVE_INFINITY,u;for(const v of this.model.ports){const w=v.distanceTo(f);w<m&&(m=w,u=v)}u&&m<Ls?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on(E.End,(s,n)=>{var r;if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{if(this.canUserPerformAction(C.AddConnection)&&!n.removed){(r=this.unfinishedConnectionTracer)==null||r.remove();const d=this.userHighlight.getFocus();if(d instanceof ve)this.finishConnection(d);else if(d instanceof ce&&d.rootElement instanceof ve)this.finishConnection(d.rootElement);else if(d instanceof j||d instanceof Z||d instanceof ce){let c;if(d instanceof j||d instanceof Z)c=d;else if(d.rootElement instanceof j||d.rootElement instanceof Z)c=d.rootElement;else{this.dropConnection();return}const h=c.getClosestPortToPoint([s.x,s.y]);h!==void 0?this.finishConnection(h):this.dropConnection()}else this.dropConnection()}A()}this.secondaryButton=!1})),a.filter(".image-look").append("image"),ot(a),l.attr("transform",s=>`translate(${s.coords[0]-s.width/2},${s.coords[1]-s.width/2})`).attr("opacity",s=>s.removed?.5:1),nt(l)}updateConnectionsInView(...e){const t=this.model.connections.filter(n=>this.priorityThreshold!==void 0?n.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&t.push(this.unfinishedConnection);let o=this.selectCanvasElements().selectAll("g.diagram-connection").data(t,n=>n.id);const a=o.exit(),l=o.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");e&&e.length>0&&(o=o.filter(n=>e.includes(n.id)));const s=l.merge(o);a.remove(),l.on(I.MouseOver,(n,r)=>{r.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new se(r)))}).on(I.Click,(n,r)=>{if(!n.ctrlKey&&!n.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(d,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new F([r],r.selected))}).on(I.ContextMenu,(n,r)=>{if(this.dragging){n.preventDefault(),n.stopPropagation(),this.dragging=!1;return}const d=new pe(n,r);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new se(r)),this.userSelection.add(r),this.diagramEvent$.next(new F([r],!0)),this.contextMenu.open(n))}).on(I.DoubleClick,(n,r)=>{const d=new me(n,r);this.diagramEvent$.next(d)}).call(T.drag().filter(n=>(this.secondaryButton=ye(n),!0)).on(E.Start,n=>{this.startMultipleSelection(n)}).on(E.Drag,n=>{this.continueMultipleSelection(n)}).on(E.End,n=>{this.finishMultipleSelection(n)})),l.append("path").attr("class","diagram-connection-path"),l.append("path").attr("class","diagram-connection-path-box"),l.append("marker").attr("id",n=>`${n.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),l.append("marker").attr("id",n=>`${n.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"),s.attr("opacity",n=>n.removed?.5:1).select("path.diagram-connection-path").attr("d",n=>{var r,d;return st(n.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(d=n.endMarkerLook)==null?void 0:d.width)}).attr("marker-start",n=>`url(#${n.id}-start-marker)`).attr("marker-end",n=>`url(#${n.id}-end-marker)`).attr("stroke",n=>n.look.color).attr("stroke-width",n=>`${n.look.thickness}px`).attr("stroke-dasharray",n=>Zt(n.look.style,n.look.thickness)).attr("fill","none"),s.select("path.diagram-connection-path-box").attr("d",n=>{var r,d;return st(n.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(d=n.endMarkerLook)==null?void 0:d.width)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",n=>`${n.look.thickness+As}px`).attr("stroke-dasharray",n=>Zt(n.look.style,n.look.thickness)).attr("fill","none"),s.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-field");e&&e.length>0&&(t=t.filter(s=>e.includes(s.id)));const l=a.merge(t);o.remove(),a.style("box-sizing","border-box").on(I.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(n)))}).on(I.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(d,!1))}const r=ke(n);this.userSelection.toggle(r),this.diagramEvent$.next(new F([r],r.selected))}).on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const d=ke(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new se(d)),this.userSelection.add(d),this.diagramEvent$.next(new F([d],!0)),this.contextMenu.open(s)}}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.EditField)&&n.editable&&!n.removed&&(this.currentAction=new si(this,n.id,n.text,""),this.createInputField(n.text,n.coords,n.width,n.height,n.fontSize,n.fontFamily||V.fontFamily,d=>{n.text=d},d=>{n.text=d,this.currentAction instanceof si&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof Z&&(r=n.rootElement.node),r?this.startMovingNode(s,r):A(M.NotAllowed)}}).on(E.Drag,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof Z&&(r=n.rootElement.node),r?this.continueMovingNode(s,r):A(M.NotAllowed)}}).on(E.End,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof Z&&(r=n.rootElement.node),r?this.finishMovingNode(s,r):A()}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",s=>`${s.width}px`).attr("height",s=>`${s.height}px`).attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).attr("opacity",s=>s.removed?.5:1).select("div").style("justify-content",s=>s.horizontalAlign===Ee.Center?"center":s.horizontalAlign===Ee.Right?"flex-end":"flex-start").style("align-items",s=>s.verticalAlign===Fe.Center?"center":s.verticalAlign===Fe.Bottom?"end":"start").select("p").style("max-width",s=>s.fit?"default":"100%").style("max-height",s=>s.fit?"default":"100%").style("overflow",s=>s.fit?"default":"hidden").style("text-overflow",s=>s.fit?"default":"ellipsis").style("text-align",s=>s.horizontalAlign===Ee.Center?"center":s.horizontalAlign===Ee.Right?"end":"start").style("font-size",s=>`${s.fontSize}px`).style("font-family",s=>s.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",s=>s.highlighted?600:400).style("color",s=>s.selected?s.selectedColor||"#000000":s.color||"#000000").html(s=>s.text.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br/>"))}updateObjectsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-object");e&&e.length>0&&(t=t.filter(s=>e.includes(s.id))),a.merge(t).attr("width",s=>`${s.width}px`).attr("height",s=>`${s.height}px`).attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).html(s=>s.html),o.remove(),a.on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.contextMenu.open(s))}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,s=>{this.startMultipleSelection(s)}).on(E.Drag,s=>{this.continueMultipleSelection(s)}).on(E.End,s=>{this.finishMultipleSelection(s)}))}updateDecoratorsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-decorator");e&&e.length>0&&(t=t.filter(s=>e.includes(s.id))),a.merge(t).attr("width",s=>`${s.width}px`).attr("height",s=>`${s.height}px`).attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).html(s=>s.html),o.remove(),a.on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.contextMenu.open(s))}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,s=>{this.startMultipleSelection(s)}).on(E.Drag,s=>{this.continueMultipleSelection(s)}).on(E.End,s=>{this.finishMultipleSelection(s)}))}updateConnectionLabelsInView(e){var s,n,r;const t=this.selectCanvasView().select(`g.diagram-connection#${e.id}`),a=t.select("path").node(),l={...V,...e.type.label};if(a){const d=a.getTotalLength();t.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",e.selected?l.selectedColor:l.color).style("font-kerning","none").text(e.startLabel);const c=(s=t.select("g.diagram-connection-start-label text").node())==null?void 0:s.getBoundingClientRect();if(c){const b=e.startLabel?c.width/this.zoomTransform.k+Pe(l)+ze(l):0,f=e.startLabel?c.height/this.zoomTransform.k+Re(l)+Ne(l):0,m=a.getPointAtLength(Math.max(q(l)+b/2,de(l)+b/2,X(l)+f/2,oe(l)+f/2));t.select("g.diagram-connection-start-label path").attr("d",Ge(-b/2,-f/2,b,f)).attr("fill",e.look.color).attr("stroke","none"),t.select("g.diagram-connection-start-label").attr("transform",`translate(${m.x},${m.y})`)}t.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",e.selected?l.selectedColor:l.color).style("font-kerning","none").text(e.middleLabel);const h=(n=t.select("g.diagram-connection-middle-label text").node())==null?void 0:n.getBoundingClientRect();if(h){const b=e.middleLabel?h.width/this.zoomTransform.k+Pe(l)+ze(l):0,f=e.middleLabel?h.height/this.zoomTransform.k+Re(l)+Ne(l):0,m=a.getPointAtLength(d/2);t.select("g.diagram-connection-middle-label path").attr("d",Ge(-b/2,-f/2,b,f)).attr("fill",e.look.color).attr("stroke","none"),t.select("g.diagram-connection-middle-label").attr("transform",`translate(${m.x},${m.y})`)}t.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",e.selected?l.selectedColor:l.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 b=e.endLabel?g.width/this.zoomTransform.k+Pe(l)+ze(l):0,f=e.endLabel?g.height/this.zoomTransform.k+Re(l)+Ne(l):0,m=a.getPointAtLength(d-Math.max(q(l)+b/2,de(l)+b/2,X(l)+f/2,oe(l)+f/2));t.select("g.diagram-connection-end-label path").attr("d",Ge(-b/2,-f/2,b,f)).attr("fill",e.look.color).attr("stroke","none"),t.select("g.diagram-connection-end-label").attr("transform",`translate(${m.x},${m.y})`)}}}updateConnectionMarkersInView(e){const t=this.selectCanvasView().select(`g.diagram-connection#${e.id}`),o=t.select("marker.diagram-connection-start-marker"),a=t.select("marker.diagram-connection-end-marker");e.startMarkerLook!==null?o.attr("orient","auto-start-reverse").attr("markerWidth",e.startMarkerLook.width).attr("markerHeight",e.startMarkerLook.height).attr("refX",e.startMarkerLook.refX).attr("refY",e.startMarkerLook.refY).select("image").attr("href",e.startMarkerLook.image).attr("width",e.startMarkerLook.width).attr("height",e.startMarkerLook.height):o.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),e.endMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",e.endMarkerLook.width).attr("markerHeight",e.endMarkerLook.height).attr("refX",e.endMarkerLook.refX).attr("refY",e.endMarkerLook.refY).select("image").attr("href",e.endMarkerLook.image).attr("width",e.endMarkerLook.width).attr("height",e.endMarkerLook.height):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fitFieldRootInView(e){var o,a,l;const t=this.model.fields.get(e);if(t){if(t.rootElement instanceof j&&t.fit){const s=this.minimumSizeOfField(t);let n=s[0]+q(t.rootElement.type.label)+de(t.rootElement.type.label)-t.rootElement.width,r=s[1]+X(t.rootElement.type.label)+oe(t.rootElement.type.label)-t.rootElement.height;this.snapToGrid&&(n=Math.ceil(n/this.gridSize)*this.gridSize,r=Math.ceil(r/this.gridSize)*this.gridSize),t.rootElement.width+n<t.rootElement.type.minWidth&&(n=t.rootElement.type.minWidth-t.rootElement.width),t.rootElement.height+r<t.rootElement.type.minHeight&&(r=t.rootElement.type.minHeight-t.rootElement.height),t.rootElement.stretch(k.Right,n),t.rootElement.stretch(k.Bottom,r)}if(t.rootElement instanceof Z&&t.fit){const s=this.minimumSizeOfField(t);let n=s[0],r=s[1];for(const g of((o=t.rootElement.node)==null?void 0:o.sections)||[])g.label&&(g.indexXInNode===t.rootElement.indexXInNode&&g.indexYInNode!==t.rootElement.indexYInNode?n=Math.max(n,this.minimumSizeOfField(g.label)[0]):g.indexXInNode!==t.rootElement.indexXInNode&&g.indexYInNode===t.rootElement.indexYInNode&&(r=Math.max(r,this.minimumSizeOfField(g.label)[1])));s[0]<n&&(s[0]=n),s[1]<r&&(s[1]=r);const d=t.rootElement.type;let c=s[0]+q(d==null?void 0:d.label)+de(d==null?void 0:d.label)-t.rootElement.width,h=s[1]+X(d==null?void 0:d.label)+oe(d==null?void 0:d.label)-t.rootElement.height;this.snapToGrid&&(c=Math.ceil(c/this.gridSize)*this.gridSize,h=Math.ceil(h/this.gridSize)*this.gridSize),t.rootElement.width+c<(t.rootElement.getMinWidth()||0)&&(c=(t.rootElement.getMinWidth()||0)-t.rootElement.width),t.rootElement.height+h<(t.rootElement.getMinHeight()||0)&&(h=(t.rootElement.getMinHeight()||0)-t.rootElement.height),(a=t.rootElement.node)==null||a.stretchSections(k.Right,c,t.rootElement.indexXInNode,t.rootElement.indexYInNode),(l=t.rootElement.node)==null||l.stretchSections(k.Bottom,h,t.rootElement.indexXInNode,t.rootElement.indexYInNode)}}}fitNodeInView(e){var o,a;const t=this.model.nodes.get(e);if(t&&t.sections.length>0&&this.priorityThreshold){let l=0,s=0;for(const n of t.sections)if(n.getPriority()>=this.priorityThreshold){const r=n.coords[0]+n.width-t.coords[0],d=n.coords[1]+n.height-t.coords[1];l=Math.max(l,r),s=Math.max(s,d)}l+=((o=t.type.sectionGrid)==null?void 0:o.margin)||0,s+=((a=t.type.sectionGrid)==null?void 0:a.margin)||0,t.stretch(k.Right,l-t.width),t.stretch(k.Bottom,s-t.height)}}selectRoot(){return T.select(this.diagramRoot)}selectSVGElement(){return T.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(e){var t,o,a,l;if(e.allowsOutgoing||e.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(((o=(t=e.getNode())==null?void 0:t.type)==null?void 0:o.id)||"")&&e.allowsOutgoing||this.connectionType.canFinishOnType(((l=(a=e.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&e.allowsIncoming))this.unfinishedConnection=new le(this.model,this.connectionType,e,void 0,rt);else if(this.inferConnectionType){let s=this.model.connections.types.all().find(n=>{var r,d;return e.allowsOutgoing&&n.canStartFromType(((d=(r=e.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")});s===void 0&&(s=this.model.connections.types.all().find(n=>{var r,d;return e.allowsIncoming&&n.canFinishOnType(((d=(r=e.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")})),s!==void 0&&(this.unfinishedConnection=new le(this.model,s,e,void 0,rt))}}}finishConnection(e){var t,o,a,l,s,n,r,d,c,h,g,b,f,m,u,v,w,p,S,x;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0)if(this.unfinishedConnection.start!==e)if(this.unfinishedConnection.type.canStartFromType(((l=(a=(o=(t=this.unfinishedConnection)==null?void 0:t.start)==null?void 0:o.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&((n=(s=this.unfinishedConnection)==null?void 0:s.start)!=null&&n.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((d=(r=e.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")&&e.allowsIncoming){const L=new it(this,this.unfinishedConnection.type,(c=this.unfinishedConnection.start)==null?void 0:c.id,e.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.unfinishedConnection.type.canFinishOnType(((f=(b=(g=(h=this.unfinishedConnection)==null?void 0:h.start)==null?void 0:g.getNode())==null?void 0:b.type)==null?void 0:f.id)||"")&&((u=(m=this.unfinishedConnection)==null?void 0:m.start)!=null&&u.allowsIncoming)&&this.unfinishedConnection.type.canStartFromType(((w=(v=e.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&e.allowsOutgoing){const L=new it(this,this.unfinishedConnection.type,e.id,(p=this.unfinishedConnection.start)==null?void 0:p.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.inferConnectionType){let L=this.model.connections.types.all().find(N=>{var H,P,R,W,_,U,D,J;return N.canStartFromType(((W=(R=(P=(H=this.unfinishedConnection)==null?void 0:H.start)==null?void 0:P.getNode())==null?void 0:R.type)==null?void 0:W.id)||"")&&((U=(_=this.unfinishedConnection)==null?void 0:_.start)==null?void 0:U.allowsOutgoing)&&N.canFinishOnType(((J=(D=e.getNode())==null?void 0:D.type)==null?void 0:J.id)||"")&&e.allowsIncoming}),z=!1;if(L===void 0&&(L=this.model.connections.types.all().find(N=>{var H,P,R,W,_,U,D,J;return N.canFinishOnType(((W=(R=(P=(H=this.unfinishedConnection)==null?void 0:H.start)==null?void 0:P.getNode())==null?void 0:R.type)==null?void 0:W.id)||"")&&((U=(_=this.unfinishedConnection)==null?void 0:_.start)==null?void 0:U.allowsIncoming)&&N.canStartFromType(((J=(D=e.getNode())==null?void 0:D.type)==null?void 0:J.id)||"")&&e.allowsOutgoing}),z=!0),L!==void 0){const N=new it(this,L,z?e.id:(S=this.unfinishedConnection.start)==null?void 0:S.id,z?(x=this.unfinishedConnection.start)==null?void 0:x.id:e.id);this.dropConnection(),N.do(),this.actionStack.add(N)}else this.dropConnection()}else this.dropConnection();else this.dropConnection()}dropConnection(){var e,t,o,a;(e=this.unfinishedConnection)==null||e.setStart(void 0),(t=this.unfinishedConnection)==null||t.setEnd(void 0),(a=(o=this.unfinishedConnection)==null?void 0:o.select())==null||a.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,o,a,l,s,n,r){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${t[0]}px`).attr("y",`${t[1]}px`).attr("width",`${o}px`).attr("height",`${a}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const c=d.append("xhtml:textarea");let h,g;c.text(e).style("box-sizing","border-box").style("width",`${o}px`).style("height",`${a}px`).style("font-size",`${l}px`).style("font-family",s).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===ee.Escape){const m=c.property("value");this.removeInputField(),r&&r(m)}}).on(I.Input,()=>{const f=c.property("value");c.attr("cols",Oi(f)+1),c.attr("rows",Di(f)+1),c.style("width",""),c.style("height",""),h=c.property("scrollWidth")+1,g=c.property("scrollHeight")+1;const m=Math.max(h,o),u=Math.max(g,a);d==null||d.attr("width",`${m}px`),c.style("width",`${m}px`),d==null||d.attr("height",`${u}px`),c.style("height",`${u}px`),n&&n(f)}).on(I.Click,f=>{f.stopPropagation()}).on(I.FocusOut,()=>{const f=c.property("value");this.removeInputField(),r&&r(f)});const b=c.node();b.focus(),b.select()}removeInputField(){var e,t,o;(t=(e=this.inputFieldContainer)==null?void 0:e.select("input"))==null||t.on(I.Blur,null),(o=this.inputFieldContainer)==null||o.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(e){var a,l;const t=(l=(a=e.select())==null?void 0:a.select("p"))==null?void 0:l.node();if(!t)return[0,0];const o=t.getBoundingClientRect();return[o.width/this.zoomTransform.k,o.height/this.zoomTransform.k]}startMovingNode(e,t){if(this.canUserPerformAction(C.MoveNode)&&!t.removed)if(A(M.Grabbing),this.draggingFrom=[e.x,e.y],t.selected&&this.userSelection.count(o=>o instanceof j)>1)this.currentAction=new tt(this,this.userSelection.filter(o=>o instanceof j).map(o=>o.id),t.coords);else{const o=t.getLastAncestor();this.currentAction=new Y(this,C.MoveNode,t.id,t.getGeometry(),t.getGeometry(),o==null?void 0:o.id,o==null?void 0:o.getGeometry(t.id),o==null?void 0:o.getGeometry(t.id))}else A(M.NotAllowed)}continueMovingNode(e,t){if(this.canUserPerformAction(C.MoveNode)&&(this.currentAction instanceof tt||this.currentAction instanceof Y)&&!t.removed){const o=[e.x-t.width/2,e.y-t.height/2];t.selected?this.userSelection.move([o[0]-t.coords[0],o[1]-t.coords[1]]):t.move(o),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(e,t){var o,a,l;if(this.canUserPerformAction(C.MoveNode)&&!t.removed&&(this.draggingFrom[0]!==e.x||this.draggingFrom[1]!==e.y)){let s=[e.x-t.width/2,e.y-t.height/2];if(this.snapToGrid&&(s=this.getClosestGridPoint(s)),this.currentAction instanceof tt){const n=this.currentAction.delta;this.currentAction.delta=[s[0]-n[0],s[1]-n[1]],t.selected?this.userSelection.move([n[0]-t.coords[0],n[1]-t.coords[1]]):t.move(n)}else if(this.currentAction instanceof Y){t.move(s);const r=this.model.nodes.getAtCoordinates(e.x,e.y).filter(h=>h.id!==t.id&&!h.isDescendantOf(t)).filter(h=>h.type.childrenTypes.includes(t.type.id)),d=gi(r),c=d[d.length-1];if(c!==t.parent&&(t.type.canBeParentless||c!==void 0)){const h=c==null?void 0:c.getLastAncestor(),g=this.currentAction.from,b=new cs(this,t.id,(o=t.parent)==null?void 0:o.id,c==null?void 0:c.id,g,t.getGeometry(),h==null?void 0:h.id,h==null?void 0:h.getGeometry(t.id),h==null?void 0:h.getGeometry(t.id));(a=t.parent)==null||a.removeChild(t),c!==void 0&&c.addChild(t),b.toChildGeometry=t.getGeometry(t.id),b.toAncestorGeometry=h==null?void 0:h.getGeometry(t.id),this.currentAction=b}else{const h=t==null?void 0:t.getLastAncestor();this.currentAction.ancestorId=h==null?void 0:h.id,this.currentAction.fromAncestorGeometry=h==null?void 0:h.getGeometry(t.id),(l=t.parent)==null||l.fitToChild(t),this.currentAction.to=t.getGeometry(t.id),this.currentAction.toAncestorGeometry=h==null?void 0:h.getGeometry(t.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}A(),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 o,a,l,s;const t=this.getPointerLocationRelativeToCanvas(e);(this.draggingFrom[0]!==t[0]||this.draggingFrom[1]!==t[1])&&(A(M.Crosshair),(s=(l=(a=(o=this.multipleSelectionContainer)==null?void 0:o.attr("x",Math.min(this.draggingFrom[0],t[0])))==null?void 0:a.attr("y",Math.min(this.draggingFrom[1],t[1])))==null?void 0:l.attr("width",Math.abs(this.draggingFrom[0]-t[0])))==null||s.attr("height",Math.abs(this.draggingFrom[1]-t[1])),this.dragging=!0)}finishMultipleSelection(e){var o;const t=this.getPointerLocationRelativeToCanvas(e);(o=this.multipleSelectionContainer)==null||o.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)Ti([a.coords,[a.coords[0]+a.width,a.coords[1]+a.height]],[this.draggingFrom,t])&&this.userSelection.add(a);this.multipleSelectionOn=!1,this.diagramEvent$.next(new F(this.userSelection.all(),!0)),A()}};Ue.canvasCount=0;let ht=Ue;class ki{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 o=1;;++o){const a=o%2>0?o:-o,l=a>0?1:-1,s=[t[0]+a,t[1]+a];for(let n=t[0];n!==s[0]+l;n+=l)if(t[0]=n,this.get(t)===void 0)return t;for(let n=t[1];n!==s[1]+l;n+=l)if(t[1]=n,this.get(t)===void 0)return t}}}class Es{apply(e){var n;if(e.nodes.length===0)return e;const t=new ki,o=e.nodes.filter(r=>!r.parent);for(;o.length>0;)wi(o[0],t,[0,0],o);const a=Math.max(...e.nodes.map(r=>r.width)),l=Math.max(...e.nodes.map(r=>r.height)),s=(((n=e.canvas)==null?void 0:n.gridSize)||0)*2;for(let r=t.minY();r<=t.maxY();++r)for(let d=t.minX();d<=t.maxX();++d){const c=t.get([d,r]);c!==void 0&&c.move([d*(a+s),r*(l+s)])}return e}}const wi=(i,e,t,o)=>{const a=e.getClosestEmptyCoordinate(t);e.set(a,i),B(o,i);for(const l of i.getAdjacentNodes())o.includes(l)&&wi(l,e,a,o)};class Ts{apply(e){var c;if(e.nodes.length===0)return e;const t=new ki,o=e.nodes.filter(h=>!h.parent),a={},l=o[0];let s=[l];for(a[l.id]=[0,0];o.length>0;){const h=[];for(const g of s){t.set(t.getClosestEmptyCoordinate(a[g.id]),g),B(o,g);const b=g.getAdjacentNodes();for(const f of b)o.includes(f)&&(h.push(f),a[f.id]=a[g.id])}if(h.length>0)s=h;else if(o.length>0){const g=o[0];s=[g],a[g.id]=t.getClosestEmptyCoordinate([0,0])}}const n=Math.max(...e.nodes.map(h=>h.width)),r=Math.max(...e.nodes.map(h=>h.height)),d=(((c=e.canvas)==null?void 0:c.gridSize)||0)*2;for(let h=t.minY();h<=t.maxY();++h)for(let g=t.minX();g<=t.maxX();++g){const b=t.get([g,h]);b!==void 0&&b.move([g*(n+d),h*(r+d)])}return e}}class Qe{apply(e){var n;if(e.nodes.length===0)return e;const t=(((n=e.canvas)==null?void 0:n.gridSize)||0)*2;let o=e.nodes.filter(r=>!r.parent);const a=o[0];B(o,a);const l=[[a]];for(;o.length>0;){const r=l[l.length-1],d=[];for(const c of r){const h=c.getAdjacentNodes();for(const g of h)o.includes(g)&&(B(o,g),d.push(g))}d.length>0?l.push(d):(l.push(o),o=[])}let s=0;for(const r of l){let d=0;for(const h of r)h.move([s,d]),d+=t+h.height;const c=Math.max(...r.map(h=>h.width));s+=t+c}for(const r of e.connections)r.tighten();return e}}class $s{apply(e){var h;if(e.nodes.length===0)return e;new Qe().apply(e);const t=(((h=e.canvas)==null?void 0:h.gridSize)||0)*2,o=.99,a=1,l=.1,s=2e5,n=.5,r=1,d=.002;let c=100;for(;c>a;){c=c*o;const g=[0,0];{for(const b of e.nodes)g[0]=g[0]+b.coords[0]+b.width/2,g[1]=g[1]+b.coords[1]+b.width/2;g[0]=g[0]/e.nodes.length,g[1]=g[1]/e.nodes.length}for(const b of e.nodes){const f=b.getAdjacentNodes();for(const m of e.nodes){const u=[b.coords[0]+b.width/2,b.coords[1]+b.height/2],v=[m.coords[0]+m.width/2,m.coords[1]+m.height/2],w=ri(b.coords,m.coords),p=[m.coords[0],m.coords[1]];if(f.includes(m)&&w>0&&(w>t+(Math.max(b.width,b.height)+Math.max(m.width,m.height))/2?(p[0]=p[0]-(v[0]-u[0])*l,p[1]=p[1]-(v[1]-u[1])*l):(p[0]=p[0]+(v[0]-u[0])*n,p[1]=p[1]+(v[1]-u[1])*n)),w>0){const S=s/(w*w);p[0]=p[0]+S*(v[0]-u[0])/w,p[1]=p[1]+S*(v[1]-u[1])/w}else p[0]=p[0]+r*(Math.random()*2-1),p[1]=p[1]+r*(Math.random()*2-1);p[0]=p[0]-(v[0]-g[0])*d,p[1]=p[1]-(v[1]-g[1])*d,p[0]-m.coords[0]>c?p[0]=m.coords[0]+c:p[0]-m.coords[0]<-c&&(p[0]=m.coords[0]-c),p[1]-m.coords[1]>c?p[1]=m.coords[1]+c:p[1]-m.coords[1]<-c&&(p[1]=m.coords[1]-c),m.move(p)}}}if(e.canvas&&e.canvas.snapToGrid)for(const g of e.nodes){const b=e.canvas.getClosestGridPoint(g.coords);g.move(b)}for(const g of e.connections)g.tighten();return e}}class Ms{apply(e){var l;if(e.nodes.length===0)return e;const t=(((l=e.canvas)==null?void 0:l.gridSize)||0)*2,o=e.nodes.filter(s=>!s.parent);o.sort((s,n)=>n.type.priority-s.type.priority);let a=0;for(const s of o)s.move([a,0]),a+=s.width+t;return e}}class Ns{apply(e){var c;if(e.nodes.length===0)return e;const t=Math.max(...e.nodes.map(h=>h.getPriority())),o=Math.min(...e.nodes.map(h=>h.getPriority()));if(t===o)return new Qe().apply(e),e;const a=(((c=e.canvas)==null?void 0:c.gridSize)||0)*2,l=e.nodes.filter(h=>!h.parent),s=[],n=e.nodes.filter(h=>!h.parent).filter(h=>h.getPriority()>=t),r=[];if(n.length>1){const h=n[0];n.splice(0,1),r.push(h);const g=[h],b=[h];for(;g.length>0;){const f=g[0];g.splice(0,1),n.includes(f)&&(r.push(f),B(n,f));const m=f.getAdjacentNodes();for(const u of m)b.includes(u)||(g.push(u),b.push(u))}for(const f of n)r.push(f)}else r.push(n[0]);for(const h of r)B(l,h),s.push([h]);for(s.push([]),l.sort((h,g)=>g.type.priority-h.type.priority);l.length>0;){const h=l[0];l.splice(0,1);const g=[h],b=[h];let f=!1;for(;g.length>0;){const m=g[0];g.splice(0,1);const u=r.indexOf(m);if(u>=0){s[u].push(h),f=!0;break}else{const v=m.getAdjacentNodes();for(const w of v)b.includes(w)||(g.push(w),b.push(w))}}f||s[s.length-1].push(h)}let d=0;for(let h=0;h<s.length;++h){let g=0;for(let f=0;f<s[h].length;++f){const m=s[h][f];m.move([d,g]),g+=a+m.height}const b=Math.max(...s[h].map(f=>f.width));d+=a+b}for(const h of e.connections)h.tighten();return e}}class Ps{apply(e){var c;if(e.nodes.length===0)return e;const t=Math.max(...e.nodes.map(h=>h.getPriority())),o=Math.min(...e.nodes.map(h=>h.getPriority()));if(t===o)return new Qe().apply(e),e;const a=(((c=e.canvas)==null?void 0:c.gridSize)||0)*2,l=e.nodes.filter(h=>!h.parent).sort((h,g)=>g.getPriority()-h.getPriority()),s=[];for(;l.length>0;){const h=l[0];l.splice(0,1);const g=new ft(void 0,h);xi(g,l),s.push(g)}const n=[];for(const h of s)n.push([h]),Ci(h,n,n.length);const r=Math.max(...e.nodes.map(h=>h.height));let d=0;for(let h=0;h<n.length;++h){let g=0;for(let f=0;f<n[h].length;++f){const m=n[h][f];m.node.move([d,g]),g+=(a+r)*m.countBranchHeight()}const b=Math.max(...n[h].map(f=>f.node.width));d+=a+b}for(const h of e.connections)h.tighten();return e}}const xi=(i,e)=>{for(const t of i.node.getAdjacentNodes().sort((o,a)=>a.getPriority()-o.getPriority())){const o=e.indexOf(t);if(o>=0){e.splice(o,1);const a=i.addBranch(t);xi(a,e)}}},Ci=(i,e,t)=>{if(i.branches.length>0){for(;t>=e.length;)e.push([]);for(const o of i.branches)e[t].push(o),Ci(o,e,t+1)}};class ft{constructor(e,t){this.parent=e,this.branches=[],this.depth=0,this.node=t}addBranch(e){const t=new ft(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 zs{apply(e){var l;if(e.nodes.length===0)return e;const t=(((l=e.canvas)==null?void 0:l.gridSize)||0)*2,o=e.nodes.filter(s=>!s.parent);o.sort((s,n)=>n.type.priority-s.type.priority);let a=0;for(const s of o)s.move([0,a]),a+=s.height+t;return e}}const oi={adjacency:new Es,breadth:new Qe,"breadth-adjacency":new Ts,force:new $s,horizontal:new Ms,priority:new Ns,tree:new Ps,vertical:new zs},Rs=$.createContext({}),Ce=$.createContext({});class Vs{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 gt=({direction:i,collapsableSelector:e,collapsableAdditionalSelector:t,collapsed:o,disabled:a,rule:l,collapsedValue:s,visibleValue:n,onCollapse:r})=>{const[d,c]=$.useState(o),h=()=>{if(!a){const b=!d;c(b),r==null||r(b);let f;if(typeof e=="string")f=T.select(e),t&&(f=f.select(t));else{const m=e;if(!m)throw new Error("collapsableSelector is not a valid ref");f=T.select(m.current),t&&(f=f.select(t))}f.style(l,b?s:n)}},g=()=>{switch(i){case k.Right:return a?"daga-horizontal-none":d?"daga-horizontal-right":"daga-horizontal-left";case k.Bottom:return a?"daga-vertical-none":d?"daga-vertical-down":"daga-vertical-up";case k.Left:return a?"daga-horizontal-none":d?"daga-horizontal-left":"daga-horizontal-right";case k.Top:return a?"daga-vertical-none":d?"daga-vertical-up":"daga-vertical-down"}};return y.jsx("daga-collapse-button",{children:y.jsx("button",{className:`daga-collapse-button daga-${i}`,onClick:h,children:y.jsx("div",{className:g()})})})},js=()=>{const i=$.useContext(Ce),e=$.useRef(null),[t,o]=$.useState([]);we.merge(i.validatorChange$,i.diagramChange$).pipe(we.map(()=>a())).subscribe();const a=()=>{o([]);for(const s of i.validators){const n=s.validate(i.model);o(n)}},l=s=>{var n,r,d,c;if(s.elementId&&(s.propertyNames===void 0||s.propertyNames.length===0)){const h=i.model.nodes.get(s.elementId)||i.model.connections.get(s.elementId);h&&i.userHighlight.add(h)}else if(s.elementId&&s.propertyNames!==void 0&&s.propertyNames.length>0){i.userSelection.openInPropertyEditor(i.model.nodes.get(s.elementId)||i.model.connections.get(s.elementId));const h=i.model.nodes.get(s.elementId)||i.model.connections.get(s.elementId);h&&i.userHighlight.add(h),(r=(n=i.parentComponent)==null?void 0:n.propertyEditor)==null||r.highlightProperty(...s.propertyNames)}else!s.elementId&&s.propertyNames!==void 0&&s.propertyNames.length>0&&(i.userSelection.openInPropertyEditor(),(c=(d=i.parentComponent)==null?void 0:d.propertyEditor)==null||c.highlightProperty(...s.propertyNames))};return y.jsx("daga-errors",{children:y.jsxs("div",{ref:e,className:"daga-errors",children:[t.length===0&&y.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:y.jsx("span",{children:"No errors found"})}),t.length>0&&y.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[y.jsxs("span",{children:[t.length," errors found"]}),y.jsx("div",{className:"daga-collapse-button-container",children:y.jsx(gt,{collapsableSelector:e,collapsableAdditionalSelector:".daga-error-panel",direction:k.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),t.length>0&&y.jsx("div",{className:"daga-error-panel",children:y.jsx("ol",{children:t.map((s,n)=>y.jsx("li",{onClick:()=>l(s),dangerouslySetInnerHTML:{__html:s.message}},n))})})]})})},_s=200,ni=i=>(i||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),Si=({disabled:i,options:e,value:t,onChange:o})=>{const a=$.useRef(null),[l,s]=$.useState("");let n;const[r,d]=$.useState([]),[c,h]=$.useState([]),[g,b]=$.useState([]),[f,m]=$.useState([]),[u,v]=$.useState(!1);$.useEffect(()=>{var P;s(((P=e.find(R=>xe(R.key,t)))==null?void 0:P.label)||"")},[t,e]);const w=P=>{if(!i)switch(P.key){case ee.PageDown:n===void 0?(x(0),z(0)):(x(n+5),z(n)),P.preventDefault();break;case ee.ArrowDown:n===void 0?(x(0),z(0)):(x(n+1),z(n)),P.preventDefault();break;case ee.PageUp:n===void 0?(x(e.length-1),z(e.length-1)):(x(n-5),z(n)),P.preventDefault();break;case ee.ArrowUp:n===void 0?(x(e.length-1),z(e.length-1)):(x(n-1),z(n)),P.preventDefault();break;case ee.Escape:S(),P.preventDefault();break;case ee.Enter:H(e[n||0]),P.preventDefault();break;default:p()}},p=()=>{if(!i){const P=ni(l.trim());d([]),h([]),b([]),m([]);for(const R of e){const _=ni(R.label).indexOf(P);if(_>=0){const U=R.label.substring(0,_),D=R.label.substring(_,_+P.length),J=R.label.substring(_+P.length);d(ne=>[...ne,R]),h(ne=>[...ne,U]),b(ne=>[...ne,D]),m(ne=>[...ne,J])}}v(!0)}},S=()=>{v(!1)},x=P=>{if(!i){if(n=P,P===void 0)return;P<0&&(n=0),P>=e.length&&(n=e.length-1)}},L=()=>{setTimeout(()=>{S()},_s)},z=P=>{var W;const R=(W=a.current)==null?void 0:W.querySelectorAll("li")[P];R&&R.scrollIntoView({block:"center"})},N=()=>{i||(s(""),v(!1),n=void 0)},H=P=>{i||(s(P.label),v(!1),n=void 0,o(P.key))};return y.jsxs("div",{ref:a,className:`daga-autocomplete ${u?"daga-showing-options":""}`,children:[y.jsxs("div",{className:"daga-autocomplete-input",children:[y.jsx("input",{value:l,disabled:i,onKeyUp:w,onFocus:p,onBlur:L,onChange:P=>s(P.target.value)}),l!==""&&y.jsx("button",{className:"daga-clear",onClick:N})]}),y.jsx("div",{className:"daga-autocomplete-options",children:y.jsxs("ul",{className:"daga-autocomplete-option-list",children:[r.length===0&&y.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),r.map((P,R)=>y.jsxs("li",{className:`daga-autocomplete-option ${R===n?"daga-focused":""}`,onMouseMove:()=>x(R),onClick:()=>H(P),children:[y.jsx("span",{children:c[R]}),y.jsx("span",{className:"daga-match",children:g[R]}),y.jsx("span",{children:f[R]})]},R))]})})]})},Os=(i,e)=>{var t;return((t=i.find(o=>o.key===e))==null?void 0:t.label)||`${e}`},Ds=({disabled:i,allowRepeats:e,options:t,value:o,onChange:a})=>{const[l,s]=$.useState(),[n,r]=$.useState([]),[d,c]=$.useState([]);$.useEffect(()=>{const u=o.length===0,v=o.map(w=>Os(t,w));r(v),u&&a(o),m()},[o,t]);const h=u=>{for(const v of o)if(v===u)return!0;return!1},g=u=>{o.length>u&&(o.splice(u,1),r(n.filter((v,w)=>w!==u)),a(o),m())},b=()=>{l!==void 0&&(e||!h(l))&&(a(o.concat(l)),f())},f=()=>{s("")},m=()=>{if(!e){const u=[];for(const v of t)h(v.key)||u.push(v);c(u)}};return y.jsxs("div",{children:[o.map((u,v)=>y.jsxs("div",{className:"daga-value-item-element",children:[y.jsx("span",{className:"daga-input",children:n[v]}),!i&&y.jsx("button",{className:"daga-property-button",onClick:()=>g(v),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},v)),!i&&y.jsxs("div",{className:"daga-value-item-input",children:[y.jsx("div",{className:"daga-input daga-relatively-positioned",children:y.jsx(Si,{disabled:i,options:e?t||[]:d||[],value:l,onChange:s})}),y.jsx("button",{className:"daga-property-button",onClick:b,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Hs=({disabled:i,allowRepeats:e,value:t,onChange:o})=>{const[a,l]=$.useState(""),s=g=>{for(const b of g||[])if(b===g)return!0;return!1},n=g=>{t.length>g&&o(t.filter((b,f)=>f!==g))},r=(g,b,f)=>{const m=t.map((u,v)=>v===b?f==="blur"?g.trim():g:u);o(m)},d=()=>{const g=a.trim();g!==""&&(e||!s(g))&&(o(t.concat(g)),c())},c=()=>{l("")},h=g=>{g.key==="Enter"&&d()};return y.jsxs(y.Fragment,{children:[t.map((g,b)=>y.jsxs("div",{className:"daga-value-item-element",children:[y.jsx("input",{className:"daga-input",disabled:i,value:g,onChange:f=>r(f.target.value,b,"change"),onBlur:f=>r(f.target.value,b,"blur")}),y.jsx("button",{className:"daga-property-button",onClick:()=>n(b),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},b)),!i&&y.jsxs("div",{className:"daga-value-item-input",children:[y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",onKeyUp:h,value:a,onChange:g=>l(g.target.value)}),y.jsx("button",{className:"daga-clear",onClick:c})]}),y.jsx("button",{className:"daga-property-button",onClick:d,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Gs=({disabled:i,value:e,onChange:t})=>{const[o,a]=$.useState(""),[l,s]=$.useState(""),[n,r]=$.useState({}),d=u=>{const v={};Object.keys(e).forEach(w=>{w!==u&&(v[w]=e[w])}),t(v)},c=(u,v,w)=>{const p=w==="blur"?v.trim():v;if(w==="blur"){if(u!==p){const S={};Object.keys(e).forEach(x=>{x===u?S[p]=e[x]:S[x]=e[x]}),t(S),r(x=>{const L={...x};return delete L[u],L})}}else r(S=>({...S,[u]:v}))},h=(u,v,w)=>{const p=w==="blur"?v.trim():v;if(p!==""){const S={};Object.keys(e).forEach(x=>{x===u?S[x]=p:S[x]=e[x]}),t(S)}},g=()=>{const u=o.trim(),v=l.trim();if(u!==""&&v!==""){const w={};Object.keys(e).forEach(p=>{w[p]=e[p]}),w[u]=v,console.log("addToValue",w),t(w),a(""),s("")}},b=()=>{a("")},f=()=>{s("")},m=u=>{u.key==="Enter"&&g()};return y.jsxs("div",{children:[Object.entries(e).map(([u,v],w)=>y.jsxs("div",{className:"daga-value-item-element",children:[y.jsx("input",{id:`key-${w}`,className:"daga-input",type:"text",disabled:i,value:n[u]??u,onChange:p=>c(u,p.target.value,"change"),onBlur:p=>c(u,p.target.value,"blur")}),y.jsx("input",{id:`value-${w}`,className:"daga-input",type:"text",disabled:i,value:v,onChange:p=>h(u,p.target.value,"change"),onBlur:p=>h(u,p.target.value,"blur")}),y.jsx("button",{className:"daga-property-button",onClick:()=>d(u),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},u)),!i&&y.jsxs("div",{className:"daga-value-item-input",children:[y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",value:o,onKeyUp:m,onChange:u=>a(u.target.value),onBlur:u=>c(o,u.target.value,"blur")}),y.jsx("button",{className:"daga-clear",onClick:b})]}),y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",value:l,onKeyUp:m,onChange:u=>s(u.target.value),onBlur:u=>h(o,u.target.value,"blur")}),y.jsx("button",{className:"daga-clear",onClick:f})]}),y.jsx("button",{className:"daga-property-button",onClick:g,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Ai=({valueSet:i,onValueChange:e,depth:t})=>{var r;const a=$.useContext(Ce).canUserPerformAction(C.UpdateValues)&&((r=i==null?void 0:i.rootElement)==null?void 0:r.removed)!==!0,l=d=>"daga-property-name-"+d.replace(/\s/g,""),s=d=>{if(typeof d=="string")return d;if(d==null||isNaN(d.valueOf()))return"";const c=new Date(d),h=c.getTimezoneOffset();return c.setMinutes(c.getMinutes()-h),c.toISOString().substring(0,19)},n=d=>new Date(d);return y.jsx("daga-object-editor",{children:i.displayedProperties.map(d=>y.jsxs("div",{className:`daga-property ${l(d.name)}`,children:[y.jsx("p",{className:"daga-property-name",children:d.name}),d.type===G.Text&&y.jsx("input",{type:"daga-text",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.TextArea&&y.jsx("textarea",{disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Number&&y.jsx("input",{type:"number",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Color&&y.jsx("input",{type:"text",pattern:"#\\d{6}",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Datetime&&y.jsx("input",{type:"datetime-local",disabled:!d.editable||!a,value:s(i==null?void 0:i.getValue(d.name)),onChange:c=>e(d,n(c.target.value))}),d.type===G.Date&&y.jsx("input",{type:"date",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Time&&y.jsx("input",{type:"time",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Url&&y.jsx("input",{type:"url",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Boolean&&y.jsxs("div",{className:"daga-radio",children:[y.jsxs("label",{className:"daga-radio-item daga-radio-start",children:[y.jsx("input",{type:"radio",disabled:!d.editable||!a,name:d.name,value:"false",checked:(i==null?void 0:i.getValue(d.name))===!1,onChange:()=>e(d,!1)}),"No"]}),y.jsxs("label",{className:"daga-radio-item daga-radio-end",children:[y.jsx("input",{type:"radio",disabled:!d.editable||!a,name:d.name,value:"true",checked:(i==null?void 0:i.getValue(d.name))===!0,onChange:()=>e(d,!0)}),"Yes"]})]}),d.type===G.Option&&y.jsx("div",{className:"daga-relatively-positioned",children:y.jsx(Si,{disabled:!d.editable||!a,options:d.options||[],value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c)})}),(d.type===G.OptionList||d.type===G.OptionSet)&&y.jsx(Ds,{disabled:!d.editable||!a,allowRepeats:d.type===G.OptionList,options:d.options||[],value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c)}),(d.type===G.TextList||d.type===G.TextSet)&&y.jsx(Hs,{disabled:!d.editable||!a,allowRepeats:d.type===G.TextList,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c)}),d.type===G.TextMap&&y.jsx(Gs,{disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c)}),d.type===G.Object&&y.jsx("div",{className:"daga-left-bar",children:y.jsx(Ai,{valueSet:i.getSubValueSet(d.name),onValueChange:e,depth:t+1})})]},d.name))})},Ii=({valueSet:i,depth:e})=>{const t=$.useContext(Ce),o=$.useRef(null),a=r=>"daga-property-name-"+r.replace(/\s/g,""),l=()=>{for(const r of(i==null?void 0:i.displayedProperties)||[]){let d=0,c=0,h=0;const g=T.select(o.current).select(`.daga-property.${a(r.name)}.daga-depth-${e}`);g.select("button.daga-move-button").call(T.drag().on(E.Start,b=>{var u;A(M.Grabbing);const f=t.getPointerLocationRelativeToScreen(b);if(f.length<2||isNaN(f[0])||isNaN(f[1]))return;const m=(u=g.node())==null?void 0:u.getBoundingClientRect();d=(m==null?void 0:m.width)||0,c=(m==null?void 0:m.height)||0,g.style("position","fixed").style("left",`${f[0]-d/2}px`).style("top",`${f[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1)}).on(E.Drag,b=>{A(M.Grabbing);const f=t.getPointerLocationRelativeToScreen(b);f.length<2||isNaN(f[0])||isNaN(f[1])||(g.style("position","fixed").style("left",`${f[0]-d/2}px`).style("top",`${f[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1),T.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${e}`).style("visibility","hidden").style("height",0),h=s(f),T.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${e}`).style("visibility","visible").style("height","0.25rem"))}).on(E.End,b=>{var m,u;A(M.Auto),g.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),T.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${e}`).style("visibility","hidden").style("height",0);const f=t.getPointerLocationRelativeToScreen(b);f.length<2||isNaN(f[0])||isNaN(f[1])||(h=s(f),(m=i==null?void 0:i.displayedProperties)==null||m.splice(i.displayedProperties.indexOf(r),1),(u=i==null?void 0:i.displayedProperties)==null||u.splice(h,0,r))}))}},s=r=>{var h;const d=(i==null?void 0:i.propertySet.propertyList)||[],c=[];for(let g=0;g<=d.length;++g){const b=(h=T.select(o.current).select(`.daga-dropbar.daga-index-${g}.daga-depth-${e}`).node())==null?void 0:h.getBoundingClientRect();b&&c.push([b.x+b.width/2,b.y+b.height/2])}if(c.length>0){const g=c.map(f=>((r[0]-f[0])**2+(r[1]-f[1])**2)**.5);return g.indexOf(Math.min(...g))}return 0},n=r=>{var c;if(i===void 0)return;let d;r instanceof Ui?d=r:r instanceof Event?d=i==null?void 0:i.propertySet.getProperty(((c=r.target)==null?void 0:c.value)||""):d=i==null?void 0:i.propertySet.getProperty(r||""),d&&(i==null||i.hideProperty(d)),l()};return y.jsxs("daga-property-settings",{ref:o,children:[y.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${e}`}),i==null?void 0:i.displayedProperties.map((r,d)=>y.jsxs("div",{className:`daga-property-and-dropbar ${a(r.name)} daga-depth-${e}`,children:[y.jsxs("div",{className:`daga-property ${a(r.name)} daga-depth-${e}`,children:[y.jsxs("div",{className:"daga-property-name",children:[y.jsx("span",{children:r.name}),y.jsxs("div",{className:"daga-buttons",children:[y.jsx("button",{className:"daga-property-button daga-move-button",children:y.jsx("div",{className:"daga-icon daga-move-icon"})}),y.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>n(r.name),children:y.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),r.type!==G.Object&&y.jsx("div",{className:"daga-property-value",children:Fs(i==null?void 0:i.getValue(r.name))}),r.type===G.Object&&y.jsx(Ii,{valueSet:i==null?void 0:i.getSubValueSet(r.name),depth:e+1})]}),y.jsx("div",{className:`daga-dropbar daga-index-${d+1} daga-depth-${e}`})]},r.name))]})},Fs=i=>Array.isArray(i)?i.join(", "):dt(i)?Object.entries(i).map(e=>e.map(t=>JSON.stringify(t)).join(": ")).join(", "):i instanceof Date?i.toLocaleString():i==null?"":""+i,Bs=({location:i,direction:e,width:t,title:o,valueSet:a,onValueChange:l})=>{const s=$.useRef(null),[n,r]=$.useState(!1),[d,c]=$.useState(!1),h=()=>T.select(s.current);return $.useEffect(()=>{if(s.current)switch(e){case k.Bottom:case k.Top:h().style("width",t);break;case k.Left:case k.Right:h().style("height",t);break}},[t,e]),y.jsx("daga-property-editor",{children:y.jsxs("div",{ref:s,className:`daga-panel daga-bottom daga-${i} daga-${e}`,children:[y.jsx(gt,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:n,direction:e,collapsableSelector:s,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:r}),a&&a.propertySet&&a.propertySet.hasProperties()&&!n&&y.jsxs("div",{className:"daga-panel-content",children:[o&&y.jsxs("p",{className:"daga-title",children:[o,y.jsx("button",{className:"daga-property-button",onClick:()=>c(!d),children:y.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&y.jsx(Ai,{valueSet:a,onValueChange:l,depth:0}),d&&y.jsx(Ii,{valueSet:a,depth:0})]})]})})},Us=i=>{const e=$.useContext(Ce),[t,o]=$.useState(i.currentPalette||i.palettes[0]),[a,l]=$.useState(0),[s,n]=$.useState(void 0),r=$.useRef(null),d=m=>{if(o(m),c().selectAll("*").remove(),l(e.getPriorityThreshold()||0),m.categories&&h(m.categories),m.templates)for(const u of m.templates)g(u)},c=()=>T.select(r.current).select(".daga-palette-view"),h=m=>{const u=c().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");u.append("option").attr("value","").text("(None selected)");for(const v in m)u.append("option").attr("value",v).text(v);u.on(I.Change,()=>{s&&c().selectAll(".daga-template-container.daga-in-category").remove();const v=u.property("value");n(v);const w=m[v]||[];for(const p of w)g(p,"daga-in-category")}),s&&(u.property("value",s),u.dispatch(I.Change))},g=(m,u)=>{if(m.templateType==="node"){const v=e.model.nodes.types.get(m.type);v?b(v,m,u):console.error(`Could not find a node type called '${m.type}'`)}else if(m.templateType==="connection"){const v=e.model.connections.types.get(m.type);v?f(v,m,u):console.error(`Could not find a connection type called '${m.type}'`)}},b=(m,u,v)=>{if(a!==void 0&&m.priority<a)return;const w=c().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${m.defaultWidth}px`).style("height",`${m.defaultHeight}px`).call(T.drag().on(E.Drag,S=>{if(e.canUserPerformAction(C.AddNode)){const x=e.getPointerLocationRelativeToScreen(S);if(x.length<2||isNaN(x[0])||isNaN(x[1]))return;w.style("position","fixed").style("left",`${x[0]-m.defaultWidth/2}px`).style("top",`${x[1]-m.defaultHeight/2}px`).style("z-index",1)}}).on(E.Start,S=>{if(e.canUserPerformAction(C.AddNode)){A(M.Grabbing);const x=e.getPointerLocationRelativeToScreen(S);if(x.length<2||isNaN(x[0])||isNaN(x[1]))return;w.style("position","fixed").style("left",`${x[0]-m.defaultWidth/2}px`).style("top",`${x[1]-m.defaultHeight/2}px`).style("z-index",1),m.isUnique&&e.model.nodes.find(L=>!L.removed&&L.type.id===m.id)!==void 0&&A(M.NotAllowed)}}).on(E.End,S=>{var x;if(e.canUserPerformAction(C.AddNode)){if(A(M.Auto),w.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),m.isUnique&&e.model.nodes.find(J=>!J.removed&&J.type.id===m.id)!==void 0)return;const L=e.getPointerLocationRelativeToScreen(S);if(L.length<2||isNaN(L[0])||isNaN(L[1]))return;const z=document.elementFromPoint(L[0],L[1]);if(z&&!((x=e.selectCanvasView().node())!=null&&x.contains(z)))return;const N=e.getPointerLocationRelativeToCanvas(S);if(N.length<2||isNaN(N[0])||isNaN(N[1]))return;let H=[N[0]-m.defaultWidth/2,N[1]-m.defaultHeight/2];e.snapToGrid&&(H=e.getClosestGridPoint(H));const R=e.model.nodes.getAtCoordinates(N[0],N[1]).filter(J=>J.type.childrenTypes.includes(m.id)),W=gi(R),_=W[W.length-1];if(!m.canBeParentless&&_===void 0)return;const U=_==null?void 0:_.getLastAncestor(),D=new ds(e,m,H,_==null?void 0:_.id,U==null?void 0:U.id,U==null?void 0:U.getGeometry(),void 0,u.label,u.values);D.do(),e==null||e.actionStack.add(D),A()}})).append("svg").attr("class",`palette-node ${m.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%"),p=u.look||m.defaultLook;switch(p.lookType){case"shaped-look":w.append("path").attr("d",lt(p.shape,0,0,m.defaultWidth,m.defaultHeight)).attr("fill",p.fillColor).attr("stroke",p.borderColor).attr("stroke-width",`${p.borderThickness}px`);break;case"image-look":w.append("image").attr("x",0).attr("y",0).attr("width",m.defaultWidth).attr("height",m.defaultHeight).attr("href",p.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":w.append("image").attr("x",0).attr("y",0).attr("width",p.leftMargin).attr("height",p.topMargin).attr("href",p.backgroundImageTopLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",p.leftMargin).attr("y",0).attr("width",m.defaultWidth-p.rightMargin-p.leftMargin).attr("height",p.topMargin).attr("href",p.backgroundImageTop).attr("preserveAspectRatio","none"),w.append("image").attr("x",m.defaultWidth-p.rightMargin).attr("y",0).attr("width",p.rightMargin).attr("height",p.topMargin).attr("href",p.backgroundImageTopRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",p.topMargin).attr("width",p.leftMargin).attr("height",m.defaultHeight-p.bottomMargin-p.topMargin).attr("href",p.backgroundImageLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",p.leftMargin).attr("y",p.topMargin).attr("width",m.defaultWidth-p.rightMargin-p.leftMargin).attr("height",m.defaultHeight-p.bottomMargin-p.topMargin).attr("href",p.backgroundImageCenter).attr("preserveAspectRatio","none"),w.append("image").attr("x",m.defaultWidth-p.rightMargin).attr("y",p.topMargin).attr("width",p.rightMargin).attr("height",m.defaultHeight-p.bottomMargin-p.topMargin).attr("href",p.backgroundImageRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",m.defaultHeight-p.bottomMargin).attr("width",p.leftMargin).attr("height",p.bottomMargin).attr("href",p.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",p.leftMargin).attr("y",m.defaultHeight-p.bottomMargin).attr("width",m.defaultWidth-p.rightMargin-p.leftMargin).attr("height",p.bottomMargin).attr("href",p.backgroundImageBottom).attr("preserveAspectRatio","none"),w.append("image").attr("x",m.defaultWidth-p.rightMargin).attr("y",m.defaultHeight-p.bottomMargin).attr("width",p.rightMargin).attr("height",p.bottomMargin).attr("href",p.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(u.label){const S={...V,...m.label,...u.labelLook};w.append("text").attr("transform",`translate(${(q(S)+m.defaultWidth)/2},${(X(S)+m.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${S.fontSize}px`).attr("text-anchor","middle").attr("font-family",S.fontFamily).attr("font-weight",400).attr("fill",S.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(u.label)}},f=(m,u,v)=>{const w=c().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${u.width}px`).style("height",`${u.height}px`).append("svg").attr("class",`palette-button ${m.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{e.connectionType=m});w.append("path").attr("d",lt(Ye.Rectangle,0,0,u.width,u.height)).attr("fill",u.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),u.icon!==""&&w.append("image").attr("x",0).attr("y",0).attr("width",u.width).attr("height",u.height).attr("href",u.icon),u.label!==""&&w.append("text").attr("transform",`translate(${u.width/2},${u.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(u.label)};return $.useEffect(()=>{if(d(i.palettes[0]),r.current)switch(i.direction){case k.Bottom:case k.Top:r.current.style.width=i.width;break;case k.Left:case k.Right:r.current.style.height=i.width;break}},[t,i.palettes]),y.jsx("daga-palette",{children:y.jsxs("div",{ref:r,className:`daga-panel daga-${i.location} daga-${i.direction}`,children:[y.jsx(gt,{direction:i.direction,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),y.jsxs("div",{className:"daga-panel-content",children:[i.palettes.length>1&&y.jsx("div",{className:"daga-panel-tabs",children:i.palettes.map(m=>y.jsx("div",{className:`daga-panel-tab ${m===t?"daga-current-tab":""}`,onClick:()=>d(m),children:m.name}))}),y.jsx("div",{className:"daga-palette-view"})]})]})})},Ys=({location:i,direction:e,enableAction:t,enableFilter:o,enableLayout:a,enableSelection:l,enableZoom:s})=>{let n=!1,r=!0,d=!1,c,h,g,b;switch(e){case k.Bottom:c="height",h="scaleY",g="top",b="bottom";break;case k.Top:c="height",h="scaleY",g="bottom",b="top";break;case k.Left:c="width",h="scaleX",g="right",b="left";break;case k.Right:c="width",h="scaleX",g="left",b="right";break}const f=$.useRef(null),m=$.useRef(null),u=$.useRef(null);$.useEffect(()=>{T.select(f.current).style(`margin-${b}`,"-1rem").style(c,"0rem").style("transform",`${h}(0)`).style("transform-origin",g)});const v=async()=>{const D=T.select(f.current);if(!d)if(r){r=!1;const _e=`${4*D.selectChildren().size()}rem`;D.transition().duration(500).ease(T.easeLinear).style(c,_e).style("transform",`${h}(1)`),setTimeout(()=>{d=!1},500)}else r=!0,D.transition().duration(500).ease(T.easeLinear).style(c,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{d=!1},500)},w=$.useContext(Ce),p=()=>{w.zoomBy(w.zoomFactor)},S=()=>{w.zoomBy(1/w.zoomFactor)},x=()=>{w.center()},L=()=>{w.layoutFormat&&w.layoutFormat in oi&&oi[w.layoutFormat].apply(w.model)},z=()=>{n=!n,T.select(u.current).classed("daga-on",n).classed("daga-off",!n);const D=w.getPriorityThresholdOptions();D&&D.length>=2&&w.setPriorityThreshold(D[n?1:0])},N=()=>{w.actionStack.undo()},H=()=>{w.actionStack.redo()},P=()=>{w.userSelection.copyToClipboard()},R=()=>{w.userSelection.cutToClipboard()},W=()=>{w.userSelection.pasteFromClipboard()},_=()=>{w.userSelection.removeFromModel()},U=()=>{w.multipleSelectionOn=!0,T.select(m.current).classed("daga-on",!0).classed("daga-off",!1)};return y.jsx("daga-diagram-buttons",{children:y.jsxs("div",{className:`daga-diagram-buttons daga-${i} daga-${e}`,children:[s&&w.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-zoom-in",onClick:p,children:y.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),s&&w.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-zoom-out",onClick:S,children:y.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),y.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:f,children:[s&&w.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-center",onClick:x,children:y.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),t&&y.jsx("button",{className:"daga-undo",onClick:N,children:y.jsx("span",{className:"daga-tooltip",children:"Undo"})}),t&&y.jsx("button",{className:"daga-redo",onClick:H,children:y.jsx("span",{className:"daga-tooltip",children:"Redo"})}),l&&y.jsx("button",{className:"daga-copy",onClick:P,children:y.jsx("span",{className:"daga-tooltip",children:"Copy"})}),l&&y.jsx("button",{className:"daga-cut",onClick:R,children:y.jsx("span",{className:"daga-tooltip",children:"Cut"})}),l&&y.jsx("button",{className:`daga-multiple-selection ${n?"daga-on":"daga-off"}`,onClick:U,ref:m,children:y.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),l&&y.jsx("button",{className:"daga-paste",onClick:W,children:y.jsx("span",{className:"daga-tooltip",children:"Paste"})}),l&&y.jsx("button",{className:"daga-delete",onClick:_,children:y.jsx("span",{className:"daga-tooltip",children:"Delete"})}),a&&w.layoutFormat&&y.jsx("button",{className:"daga-layout",onClick:L,children:y.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),o&&y.jsx("button",{className:`daga-filter ${n?"daga-on":"daga-off"}`,onClick:z,ref:u,children:y.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),y.jsx("button",{className:"daga-more-options",onClick:v,children:r?y.jsx("span",{className:"daga-tooltip",children:"More options"}):y.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Xs=({config:i,model:e,onCanvasCreated:t,onDiagramEvent:o,onModelChange:a})=>{var z,N,H,P,R,W,_,U,D,J,ne,_e,mt,pt,yt,bt,vt,kt,wt,xt,Ct,St,At,It,Lt,Et,Tt,$t,Mt,Nt,Pt,zt,Rt,Vt,jt,_t,Ot,Dt,Ht,Gt,Ft,Bt,Ut,Yt,Xt;const l=new yi,s=new vi,n=$.useRef(null),r=$.useRef(void 0),d=$.useRef(!1),c=[],[h,g]=$.useState(void 0),[b,f]=$.useState(void 0),m={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")}},v=new Vs(re=>g(re),re=>f(re)),w={diagramButtons:m,palette:u,propertyEditor:v},p=(re=!1)=>((!r.current||re)&&(c.forEach(fe=>fe.unsubscribe()),r.current=new ht(w,i)),r.current),S=p(),x=re=>{S.initView(re),c.push(S.diagramEvent$.subscribe(fe=>{o==null||o(fe)})),c.push(S.diagramChange$.subscribe(()=>{const fe=s.export(S.model);a==null||a(fe)}))};$.useEffect(()=>{n.current&&(d.current||(x(n.current),d.current=!0,t==null||t(S)))},[n.current]),$.useMemo(()=>{n.current&&(p(!0),x(n.current),t==null||t(S))},[i]),$.useEffect(()=>{e&&l.import(S.model,e)},[e]);const L=(re,fe)=>{var Wt;if(b!==void 0&&re.editable&&!xe(b.getValue(re.name),fe)){const Oe=new be(b.propertySet,b.rootElement);Oe.setValues(b.values),Oe.setValue(re.name,fe),v.valueSet=Oe,b.rootElement.valueSet=Oe,(Wt=S.propertyEditorChanges$)==null||Wt.next()}};return y.jsx("daga-diagram",{children:y.jsx(Rs.Provider,{value:i,children:y.jsx(Ce.Provider,{value:S,children:y.jsxs("daga-diagram-editor",{children:[y.jsx("div",{className:"daga-append-to",ref:n}),y.jsxs(Ce.Provider,{value:S,children:[((z=i.components)==null?void 0:z.buttons)!==void 0&&((H=(N=i.components)==null?void 0:N.buttons)==null?void 0:H.enabled)!==!1&&y.jsx(Ys,{location:((R=(P=i.components)==null?void 0:P.buttons)==null?void 0:R.location)||He.BottomRight,direction:((_=(W=i.components)==null?void 0:W.buttons)==null?void 0:_.direction)||k.Top,enableAction:((D=(U=i.components)==null?void 0:U.buttons)==null?void 0:D.enableAction)===!0,enableFilter:((ne=(J=i.components)==null?void 0:J.buttons)==null?void 0:ne.enableFilter)===!0,enableLayout:((mt=(_e=i.components)==null?void 0:_e.buttons)==null?void 0:mt.enableLayout)===!0,enableSelection:((yt=(pt=i.components)==null?void 0:pt.buttons)==null?void 0:yt.enableSelection)===!0,enableZoom:((vt=(bt=i.components)==null?void 0:bt.buttons)==null?void 0:vt.enableZoom)!==!1}),((kt=i.components)==null?void 0:kt.palette)!==void 0&&((xt=(wt=i.components)==null?void 0:wt.palette)==null?void 0:xt.enabled)!==!1&&((St=(Ct=i.components)==null?void 0:Ct.palette)==null?void 0:St.sections)&&(((Lt=(It=(At=i.components)==null?void 0:At.palette)==null?void 0:It.sections)==null?void 0:Lt.length)||0)>0&&y.jsx(Us,{location:((Tt=(Et=i.components)==null?void 0:Et.palette)==null?void 0:Tt.location)||He.TopLeft,direction:((Mt=($t=i.components)==null?void 0:$t.palette)==null?void 0:Mt.direction)||k.Bottom,width:((Pt=(Nt=i.components)==null?void 0:Nt.palette)==null?void 0:Pt.width)||"12rem",palettes:((Rt=(zt=i.components)==null?void 0:zt.palette)==null?void 0:Rt.sections)||[]}),((Vt=i.components)==null?void 0:Vt.propertyEditor)!==void 0&&((_t=(jt=i.components)==null?void 0:jt.propertyEditor)==null?void 0:_t.enabled)!==!1&&y.jsx(Bs,{location:((Dt=(Ot=i.components)==null?void 0:Ot.propertyEditor)==null?void 0:Dt.location)||He.TopRight,direction:((Gt=(Ht=i.components)==null?void 0:Ht.propertyEditor)==null?void 0:Gt.direction)||k.Bottom,width:((Bt=(Ft=i.components)==null?void 0:Ft.propertyEditor)==null?void 0:Bt.width)||"24rem",title:h,valueSet:b,onValueChange:L}),((Ut=i.components)==null?void 0:Ut.errors)!==void 0&&((Xt=(Yt=i.components)==null?void 0:Yt.errors)==null?void 0:Xt.enabled)!==!1&&y.jsx(js,{})]})]})})})})};exports.DagaDiagram=Xs;