@metadev/daga-react 1.0.0 → 4.1.0

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