@metadev/daga-react 4.2.2 → 4.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/Changelog.md +14 -1
  2. package/index.js +2 -2
  3. package/index.mjs +2785 -2661
  4. package/package.json +2 -2
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),zi=require("d3"),It=require("rxjs"),z=require("react");function Ri(i){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const e in i)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>i[e]})}}return t.default=i,Object.freeze(t)}const N=Ri(zi);var b=(i=>(i.Bottom="bottom",i.Left="left",i.Right="right",i.Top="top",i))(b||{}),Bt=(i=>(i.BottomLeft="bottom-left",i.BottomRight="bottom-right",i.TopLeft="top-left",i.TopRight="top-right",i))(Bt||{}),Mt=(i=>(i.Left="left",i.Center="center",i.Right="right",i))(Mt||{}),Yt=(i=>(i.Top="top",i.Center="center",i.Bottom="bottom",i))(Yt||{});const Lt=i=>[Math.round(i[0]),Math.round(i[1])],vt=(i,t,e)=>t<e?t<=i&&i<=e:e<=i&&i<=t,Je=(i,t,e)=>(i-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Xt=(i,t,e,s,r,l,o)=>{const n=(()=>{switch(l){case"start":return s[0]+(i[0]-t[0]);case"end":return s[1]-(t[1]-i[0]);case"middle":{const c=(t[0]+t[1])/2,h=(s[0]+s[1])/2,d=t[1]-t[0],u=s[1]-s[0],p=(i[0]-c)/d;return h+p*u}case"floating":default:return Je(i[0],t,s)}})(),a=(()=>{switch(o){case"start":return r[0]+(i[1]-e[0]);case"end":return r[1]-(e[1]-i[1]);case"middle":{const c=(e[0]+e[1])/2,h=(r[0]+r[1])/2,d=e[1]-e[0],u=r[1]-r[0],p=(i[1]-c)/d;return h+p*u}case"floating":default:return Je(i[1],e,r)}})();return[n,a]},hi=(i,t)=>((i[0]-t[0])**2+(i[1]-t[1])**2)**.5,Vi=(i,t)=>(vt(i[0][0],t[0][0],t[1][0])||vt(i[1][0],t[1][0],t[0][0])||vt(t[0][0],i[0][0],i[1][0])||vt(t[1][0],i[1][0],i[0][0]))&&(vt(i[0][1],t[0][1],t[1][1])||vt(i[1][1],t[1][1],t[0][1])||vt(t[0][1],i[0][1],i[1][1])||vt(t[1][1],i[1][1],i[0][1]));var A=(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))(A||{}),tt=(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))(tt||{}),$=(i=>(i.Drag="drag",i.Start="start",i.End="end",i))($||{}),he=(i=>(i.Zoom="zoom",i.Start="start",i.End="end",i))(he||{});const ge=i=>i.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var gi=(i=>(i.Straight="straight",i.Bezier="bezier",i.Square="square",i))(gi||{}),ui=(i=>(i.Solid="solid",i.Dashed="dashed",i.GappedDashes="gapped-dashes",i.Dotted="dotted",i))(ui||{});const _i=20,ji=(i,t,e,s,r)=>{if(typeof i=="function")return i(t,e,s,r);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{r=r||_i;let l="",o,n;switch(i){case"straight":l+=`M ${t[0][0]} ${t[0][1]}`;for(let a=1;a<t.length;++a)l+=` L ${t[a][0]} ${t[a][1]}`;break;case"bezier":o=e,l+=`M ${t[0][0]} ${t[0][1]}`;for(let a=1;a<t.length;++a){if(a+1>=t.length?n=s:Math.abs(t[a][0]-t[a-1][0])<Math.abs(t[a][1]-t[a-1][1])?t[a][1]>t[a-1][1]?n=b.Bottom:n=b.Top:t[a][0]>t[a-1][0]?n=b.Right:n=b.Left,o!==void 0){let c="",h="";const d=(Math.abs(t[a][0]-t[a-1][0])+Math.abs(t[a][1]-t[a-1][1]))/2;switch(o){case b.Bottom:c=`${t[a-1][0]} ${t[a-1][1]+d}`;break;case b.Top:c=`${t[a-1][0]} ${t[a-1][1]-d}`;break;case b.Right:c=`${t[a-1][0]+d} ${t[a-1][1]}`;break;case b.Left:c=`${t[a-1][0]-d} ${t[a-1][1]}`;break}if(n!==void 0){switch(n){case b.Bottom:h=`${t[a][0]} ${t[a][1]+d}`;break;case b.Top:h=`${t[a][0]} ${t[a][1]-d}`;break;case b.Right:h=`${t[a][0]+d} ${t[a][1]}`;break;case b.Left:h=`${t[a][0]-d} ${t[a][1]}`;break}l+=` C ${c} ${h} ${t[a][0]} ${t[a][1]}`}else l+=` Q ${c} ${t[a][0]} ${t[a][1]}`}else if(n!==void 0){let c="";const h=(Math.abs(t[a][0]-t[a-1][0])+Math.abs(t[a][1]-t[a-1][1]))/2;switch(n){case b.Bottom:c=`${t[a][0]} ${t[a][1]+h}`;break;case b.Top:c=`${t[a][0]} ${t[a][1]-h}`;break;case b.Right:c=`${t[a][0]+h} ${t[a][1]}`;break;case b.Left:c=`${t[a][0]-h} ${t[a][1]}`;break}l+=` Q ${c} ${t[a][0]} ${t[a][1]}`}else l+=` L ${t[a][0]} ${t[a][1]}`;o=n}break;case"square":if(l+=`M ${t[0][0]} ${t[0][1]}`,e)switch(e){case b.Bottom:t.splice(1,0,[t[0][0],t[0][1]+r]);break;case b.Top:t.splice(1,0,[t[0][0],t[0][1]-r]);break;case b.Right:t.splice(1,0,[t[0][0]+r,t[0][1]]);break;case b.Left:t.splice(1,0,[t[0][0]-r,t[0][1]]);break}if(s)switch(s){case b.Bottom:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]+r]);break;case b.Top:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]-r]);break;case b.Right:t.splice(t.length-1,0,[t[t.length-1][0]+r,t[t.length-1][1]]);break;case b.Left:t.splice(t.length-1,0,[t[t.length-1][0]-r,t[t.length-1][1]]);break}for(let a=1;a<t.length;++a)if(o!==void 0)switch(o){case b.Bottom:t[a][1]<t[a-1][1]&&t[a][0]!==t[a-1][0]?(l+=` H ${t[a][0]}`,l+=` V ${t[a][1]}`,o=b.Top):t[a][1]<t[a-1][1]&&t[a][0]===t[a-1][0]?(l+=` H ${t[a][0]+r}`,l+=` V ${t[a][1]}`,l+=` H ${t[a][0]}`,o=b.Left):t[a][1]===t[a-1][1]&&t[a][0]!==t[a-1][0]?(l+=` H ${t[a][0]}`,o=t[a][0]>t[a-1][0]?b.Right:b.Left):t[a][1]>t[a-1][1]&&t[a][0]!==t[a-1][0]?(l+=` H ${t[a][0]}`,l+=` V ${t[a][1]}`):t[a][1]>t[a-1][1]&&t[a][0]===t[a-1][0]&&(l+=` V ${t[a][1]}`);break;case b.Top:t[a][1]>t[a-1][1]&&t[a][0]!==t[a-1][0]?(l+=` H ${t[a][0]}`,l+=` V ${t[a][1]}`,o=b.Bottom):t[a][1]>t[a-1][1]&&t[a][0]===t[a-1][0]?(l+=` H ${t[a][0]-r}`,l+=` V ${t[a][1]}`,l+=` H ${t[a][0]}`,o=b.Right):t[a][1]===t[a-1][1]&&t[a][0]!==t[a-1][0]?(l+=` H ${t[a][0]}`,o=t[a][0]>t[a-1][0]?b.Right:b.Left):t[a][1]<t[a-1][1]&&t[a][0]!==t[a-1][0]?(l+=` H ${t[a][0]}`,l+=` V ${t[a][1]}`):t[a][1]<t[a-1][1]&&t[a][0]===t[a-1][0]&&(l+=` V ${t[a][1]}`);break;case b.Right:t[a][0]<t[a-1][0]&&t[a][1]!==t[a-1][1]?(l+=` V ${t[a][1]}`,l+=` H ${t[a][0]}`,o=b.Left):t[a][0]<t[a-1][0]&&t[a][1]===t[a-1][1]?(l+=` V ${t[a][1]+r}`,l+=` H ${t[a][0]}`,l+=` V ${t[a][1]}`,o=b.Top):t[a][0]===t[a-1][0]&&t[a][1]!==t[a-1][1]?(l+=` V ${t[a][1]}`,o=t[a][1]>t[a-1][1]?b.Bottom:b.Top):t[a][0]>t[a-1][0]&&t[a][1]!==t[a-1][1]?(l+=` V ${t[a][1]}`,l+=` H ${t[a][0]}`):t[a][0]>t[a-1][0]&&t[a][1]===t[a-1][1]&&(l+=` H ${t[a][0]}`);break;case b.Left:t[a][0]>t[a-1][0]&&t[a][1]!==t[a-1][1]?(l+=` V ${t[a][1]}`,l+=` H ${t[a][0]}`,o=b.Right):t[a][0]>t[a-1][0]&&t[a][1]===t[a-1][1]?(l+=` V ${t[a][1]-r}`,l+=` H ${t[a][0]}`,l+=` V ${t[a][1]}`,o=b.Bottom):t[a][0]===t[a-1][0]&&t[a][1]!==t[a-1][1]?(l+=` V ${t[a][1]}`,o=t[a][1]>t[a-1][1]?b.Bottom:b.Top):t[a][0]<t[a-1][0]&&t[a][1]!==t[a-1][1]?(l+=` V ${t[a][1]}`,l+=` H ${t[a][0]}`):t[a][0]<t[a-1][0]&&t[a][1]===t[a-1][1]&&(l+=` H ${t[a][0]}`);break}else t[a][0]!==t[a-1][0]&&(l+=` H ${t[a][0]}`,o=t[a][0]>t[a-1][0]?b.Right:b.Left),t[a][1]!==t[a-1][1]&&(l+=` V ${t[a][1]}`,o=t[a][1]>t[a-1][1]?b.Bottom:b.Top);break}return l}},Qe=(i,t)=>{switch(i){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},Y=(i,t)=>{const e=i.indexOf(t);return e>=0&&i.splice(e,1),i};var Zt=(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))(Zt||{});const ue=(i,t,e,s,r)=>{if(typeof i=="function")return i(t,e,s,r);switch(i){case"ellipse":return mi(t,e,s,r);case"empty":return Oi();case"folder":return Di(t,e,s,r);case"hexagon":return Hi(t,e,s,r);case"octagon":return Gi(t,e,s,r);case"pill":return Ut(t,e,s,r);case"rectangle":return ti(t,e,s,r);case"rhombus":return Fi(t,e,s,r);case"rounded-rectangle":return Bi(t,e,s,r);case"sticky-note":return Ui(t,e,s,r);default:return ti(t,e,s,r)}},mi=(i,t,e,s)=>`M ${i+e/2} ${t} A ${e/2} ${s/2} 0 0 0 ${i+e/2} ${t+s} A ${e/2} ${s/2} 0 1 0 ${i+e/2} ${t} Z`,Oi=()=>"Z",Di=(i,t,e,s)=>`M ${i} ${t} L ${i+e/3} ${t} L ${i+e/2} ${t+s/6} L ${i+e} ${t+s/6} L ${i+e} ${t+s} L ${i} ${t+s} Z`,Hi=(i,t,e,s)=>`M ${i+e/4} ${t} L ${i+3*e/4} ${t} L ${i+e} ${t+s/2} L ${i+3*e/4} ${t+s} L ${i+e/4} ${t+s} L ${i} ${t+s/2} Z`,Gi=(i,t,e,s)=>`M ${i+e/4} ${t} L ${i+3*e/4} ${t} L ${i+e} ${t+s/4} L ${i+e} ${t+3*s/4} L ${i+3*e/4} ${t+s} L ${i+e/4} ${t+s} L ${i} ${t+3*s/4} L ${i} ${t+s/4} L ${i+e/4} ${t} Z`,Ut=(i,t,e,s)=>s<e?`M ${i+s/2} ${t} L ${i+e-s/2} ${t} A ${s/2} ${s/2} 0 0 1 ${i+e} ${t+s/2} A ${s/2} ${s/2} 0 0 1 ${i+e-s/2} ${t+s} L ${i+s/2} ${t+s} A ${s/2} ${s/2} 0 0 1 ${i} ${t+s/2} A ${s/2} ${s/2} 0 0 1 ${i+s/2} ${t} Z`:s>e?`M ${i} ${t+e/2} L ${i} ${t+s-e/2} A ${e/2} ${e/2} 0 0 0 ${i+e/2} ${t+s} A ${e/2} ${e/2} 0 0 0 ${i+e} ${t+s-e/2} L ${i+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${i+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${i} ${t+e/2} Z`:mi(i,t,e,s),ti=(i,t,e,s)=>`M ${i} ${t} L ${i+e} ${t} L ${i+e} ${t+s} L ${i} ${t+s} Z`,Fi=(i,t,e,s)=>`M ${i+e/2} ${t} L ${i+e} ${t+s/2} L ${i+e/2} ${t+s} L ${i} ${t+s/2} Z`,Bi=(i,t,e,s)=>`M ${i+e/4} ${t} L ${i+3*e/4} ${t} A ${e/4} ${s/4} 0 0 1 ${i+e} ${t+s/4} L ${i+e} ${t+3*s/4} A ${e/4} ${s/4} 0 0 1 ${i+3*e/4} ${t+s} L ${i+e/4} ${t+s} A ${e/4} ${s/4} 0 0 1 ${i} ${t+3*s/4} L ${i} ${t+s/4} A ${e/4} ${s/4} 0 0 1 ${i+e/4} ${t} Z`,Ui=(i,t,e,s)=>`M ${i} ${t} L ${i+3*e/4} ${t} L ${i+3*e/4} ${t+s/4} L ${i+3*e/4} ${t} L ${i+e} ${t+s/4} L ${i+3*e/4} ${t+s/4} L ${i+e} ${t+s/4} L ${i+e} ${t+s} L ${i} ${t+s} Z`;var P=(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))(P||{});const Yi=i=>Math.max(...i.split(`
2
- `).map(t=>t.length)),Xi=i=>{var t;return((t=i.match(/\n/g))==null?void 0:t.length)||0},q=[];for(let i=0;i<256;++i)q.push((i+256).toString(16).slice(1));function Wi(i,t=0){return(q[i[t+0]]+q[i[t+1]]+q[i[t+2]]+q[i[t+3]]+"-"+q[i[t+4]]+q[i[t+5]]+"-"+q[i[t+6]]+q[i[t+7]]+"-"+q[i[t+8]]+q[i[t+9]]+"-"+q[i[t+10]]+q[i[t+11]]+q[i[t+12]]+q[i[t+13]]+q[i[t+14]]+q[i[t+15]]).toLowerCase()}let se;const Zi=new Uint8Array(16);function Ki(){if(!se){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");se=crypto.getRandomValues.bind(crypto)}return se(Zi)}const qi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ei={randomUUID:qi};function ii(i,t,e){var r;if(ei.randomUUID&&!i)return ei.randomUUID();i=i||{};const s=i.random??((r=i.rng)==null?void 0:r.call(i))??Ki();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,Wi(s)}const nt=i=>{const{selected:t,highlighted:e,...s}=i,r=s,l={...r,...t},o={...r,...e},n={...r,...e,...t};return{defaultLook:r,selectedLook:l,highlightedLook:o,selectedAndHighlightedLook:n}};class Kt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],Y(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const zt=0;class Tt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userHighlight)==null?void 0:e.contains(this.id))||!1}get selected(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userSelection)==null?void 0:e.contains(this.id))||!1}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`[id='${ge(this.id)}']`)}}class pt extends Kt{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((s,r,l)=>t(s,r,l)&&!s.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((s,r,l)=>t(s,r,l)&&!s.removed)}find(t,e=!1){return e?super.find(t):super.find((s,r,l)=>t(s,r,l)&&!s.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(s=>!s.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],Y(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(s=>!s.removed))yield e}}class Ji{constructor(t,e,s,r,l,o){this.name=t,this.type=e,this.defaultValue=s,this.basic=r,this.editable=l,this.rootAttribute=o,this.options=void 0,this.properties=void 0}}var _=(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))(_||{});class qt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}function St(i,t){return!t||i[0]>t[0]?!0:i[0]===t[0]?i[1]>=t[1]:!1}const oi=i=>i==null||i===""||i instanceof Array&&i.length===0||i instanceof Object&&Object.keys(i).length===0,At=(i,t)=>i===t||JSON.stringify(i)===JSON.stringify(t),fi=(i,t,e)=>{const s={},r={};for(const l in e.propertySet.propertyMap)if(e.propertySet.propertyMap[l].type===_.Object){const o=fi(i[l],t[l],e.getSubValueSet(l));Object.keys(o[0]).length>0&&Object.keys(o[1]).length>0&&(s[l]=o[0],r[l]=o[1])}else At(i[l],t[l])||(s[l]=i[l],r[l]=t[l]);return[s,r]},Qi=i=>i!=null&&i.constructor===Object;class wt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const s of t){if(e==null)return;e=e[s]}return e}}setRootElementValue(t,e){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let s=this.rootElement;for(let r=0;r<t.length-1;++r){const l=t[r];if(s==null)return;s=s[l]}if(s==null)return;s[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}getValue(t){var r;const e=(r=this.propertySet.getProperty(t))==null?void 0:r.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===_.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===_.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const s in t)this.propertySet.getProperty(s).type===_.Object?e[s]=this.valueSets[s].getValuesForKeys(t[s]):e[s]=this.getValue(s);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===_.Object)t[e]=this.valueSets[e].getTimestamps();else{const r=this.ownTimestamps[e];r&&(t[e]=r)}return t}hasValue(t){const e=this.getValue(t);return!oi(e)}hasSetValue(t){const e=this.getValue(t),s=this.propertySet.getProperty(t);return s&&s.type===_.Object?this.getSubValueSet(t).hasAnySetValue():!oi(e)&&!At(e,s==null?void 0:s.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const s=this.propertySet.getProperty(t);if(s){s.type===_.Object?this.valueSets[t].setValues(e):(this.values[t]=e,At(e,s.defaultValue)||this.displayProperty(s));const r=s.rootAttribute;r!=null&&this.setRootElementValue(r,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const s in t)this.propertySet.getProperty(s).type===_.Object?this.valueSets[s].overwriteValuesLww(t[s],e):St(e,this.ownTimestamps[s])&&(this.setValue(s,t[s]),this.ownTimestamps[s]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),s=e.rootAttribute;e.type===_.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),s!=null&&e.defaultValue!==void 0&&!At(this.getRootElementValue(s),e.defaultValue)&&this.setRootElementValue(s,this.values[t]),e.basic?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),s=new qt(e.properties),r=new wt(s,this.rootElement);return r.overwriteValues(structuredClone(e.defaultValue)),r}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),Y(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),Y(this.displayedProperties,t))}}const to={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:gi.Straight,style:ui.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class pi{constructor(t){const e={...to,...t};this.id=e.id,this.name=e.name,this.label=e.label;const s=nt(e.look);if(this.defaultLook=s.defaultLook,this.selectedLook=s.selectedLook,this.highlightedLook=s.highlightedLook,this.selectedAndHighlightedLook=s.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const r=nt(e.startMarkerLook);this.defaultStartMarkerLook=r.defaultLook,this.selectedStartMarkerLook=r.selectedLook,this.highlightedStartMarkerLook=r.highlightedLook,this.selectedAndHighlightedStartMarkerLook=r.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const r=nt(e.endMarkerLook);this.defaultEndMarkerLook=r.defaultLook,this.selectedEndMarkerLook=r.selectedLook,this.highlightedEndMarkerLook=r.highlightedLook,this.selectedAndHighlightedEndMarkerLook=r.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.propertySet=new qt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class dt extends Tt{constructor(t,e,s,r,l){if(t.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(t,l),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new wt(e.propertySet,this),this.originalData={},this.setStart(s),this.setEnd(r)}get type(){return this._type}set type(t){var e,s;t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new wt(t.propertySet,this)),(s=(e=this.model.canvas)==null?void 0:e.userSelection)==null||s.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.connections.types.get(t);e&&(this.type=e)}}get name(){return this.middleLabel}set name(t){this.middleLabel=t}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(t){if(t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}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(t){if(t){const e=nt(t);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...e.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...e.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...e.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=t,this._selectedStartMarkerLook=t,this._highlightedStartMarkerLook=t,this._selectedAndHighlightedStartMarkerLook=t}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(t){if(t){const e=nt(t);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...e.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...e.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...e.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=t,this._selectedEndMarkerLook=t,this._highlightedEndMarkerLook=t,this._selectedAndHighlightedEndMarkerLook=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateConnectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}setStart(t){this.start!==t?(this.start!==void 0&&Y(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&Y(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}tighten(){var t,e;if((t=this.start)!=null&&t.rootElement&&this.end){const s=this.start.rootElement.ports.map(r=>[r,r.distanceTo(this.end.coords)]).sort((r,l)=>r[1]-l[1]).map(r=>r[0]);t:for(const r of s){if(r===this.end||!r.allowsOutgoing)continue t;{for(const l of r.outgoingConnections)if(l!==this&&l.end===this.end)continue t;for(const l of r.incomingConnections)if(l!==this&&l.start===this.end)continue t}if(r===this.start)break t;this.setStart(r);break t}}if((e=this.end)!=null&&e.rootElement&&this.start){const s=this.end.rootElement.ports.map(r=>[r,r.distanceTo(this.start.coords)]).sort((r,l)=>r[1]-l[1]).map(r=>r[0]);t:for(const r of s){if(r===this.start||!r.allowsIncoming)continue t;{for(const l of r.incomingConnections)if(l!==this&&l.start===this.start)continue t;for(const l of r.outgoingConnections)if(l!==this&&l.end===this.start)continue t}if(r===this.end)break t;this.setEnd(r);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():zt}}class eo extends pt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,s,r){let l;if(t instanceof pi)l=t;else{const n=this.types.get(t);if(n===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);l=n}const o=new dt(this.model,l,e,s,r);return super.add(o),o.updateInView(),o.valueSet.resetValues(),o}remove(t){var s,r;const e=this.get(t,!0);e&&(Y(((s=e.start)==null?void 0:s.outgoingConnections)||[],e),Y(((r=e.end)==null?void 0:r.incomingConnections)||[],e),super.remove(t),e.updateInView())}}const O={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",horizontalAlign:Mt.Center,verticalAlign:Yt.Center,orientation:b.Top,fit:!1,shrink:!0};class mt extends Tt{constructor(t,e,s,r,l,o,n,a,c,h,d,u,p,m,f,g){const y=`${e==null?void 0:e.id}_field`;if(t.fields.get(y)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,y),this.textTimestamp=null,this.rootElement=e,this.coords=s,this.width=r,this.height=l,this.fontSize=o,this.fontFamily=n,this.color=a,this.selectedColor=c,this.horizontalAlign=h,this.verticalAlign=d,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case b.Top:this.orientation=0;break;case b.Right:this.orientation=90;break;case b.Bottom:this.orientation=180;break;case b.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=p,this._text=p,this.editable=m,this.fit=f,this.shrink=g}get text(){return this._text}set text(t){var e;(t==null||(t==null?void 0:t.trim())==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&((e=this.model.canvas)==null||e.fitFieldRootInView(this.id,this.shrink))}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateFieldsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||zt}}class io extends pt{constructor(t){super(),this.model=t}new(t,e,s,r,l,o,n,a,c,h,d,u,p,m,f){const g=new mt(this.model,t,e,n,a,s,r,l,o,c,h,d,u,p,m,f);return super.add(g),g.updateInView(),t!==void 0&&(t.label=g),g}remove(t){var s;const e=this.get(t,!0);e&&(((s=e.rootElement)==null?void 0:s.label)!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const ot=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?O.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?O.margin:i.margin.length===1||i.margin.length===2?i.margin[0]:(i.margin.length===3,i.margin[2]),Z=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?O.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?O.margin:i.margin.length===1?i.margin[0]:i.margin.length===2||i.margin.length===3?i.margin[1]:i.margin[3],at=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?O.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?O.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?O.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?O.margin:(i.margin.length===1||i.margin.length===2||i.margin.length===3,i.margin[0]),_t=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?O.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?O.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),jt=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?O.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?O.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],Ot=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?O.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?O.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),Dt=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?O.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?O.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),si=1,ni=1,oo=1,so=1;class no{constructor(t){this.margin=t.margin||0,this.defaultWidths=t.defaultWidths||null,this.defaultHeights=t.defaultHeights||null,this.minWidths=t.minWidths||null,this.minHeights=t.minHeights||null,this.sections=[];for(const e of t.sections){const s=[];this.sections.push(s);for(const r of e)s.push(new ro(r))}}}class ro{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||zt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=nt(t.look||vi);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class B extends Tt{constructor(t,e,s,r,l,o,n,a){if(t.sections.get(a)!==void 0)throw new Error(`DiagramSection with id "${a}" already exists`);if(!a)throw new Error("DiagramSection cannot have an empty or null id");super(t,a),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=s,this.indexYInNode=r,this.coords=l,this.width=o,this.height=n}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){var t,e,s,r,l,o,n,a;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:((t=this.type)==null?void 0:t.selectedAndHighlightedLook)||((e=this.node)==null?void 0:e.look):this._selectedLook!==void 0?this._selectedLook:((s=this.type)==null?void 0:s.selectedLook)||((r=this.node)==null?void 0:r.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)||((a=this.node)==null?void 0:a.look)}set look(t){if(t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateSectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise()}get type(){var t,e,s,r,l;return(l=(r=(s=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:s.sections)==null?void 0:r[this.indexYInNode])==null?void 0:l[this.indexXInNode]}getMinWidth(){var t,e,s,r;return((r=(s=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:s.minWidths)==null?void 0:r[this.indexXInNode])||oo}getMinHeight(){var t,e,s,r;return((r=(s=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:s.minHeights)==null?void 0:r[this.indexYInNode])||so}getPriority(){var t,e,s,r,l,o;return((o=(l=(r=(s=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:s.sections)==null?void 0:r[this.indexYInNode])==null?void 0:l[this.indexXInNode])==null?void 0:o.priority)||zt}getResizableX(){var e,s;const t=this.type;return(t==null?void 0:t.resizableX)!==void 0?t.resizableX:((s=(e=this.node)==null?void 0:e.type)==null?void 0:s.resizableX)||!1}getResizableY(){var e,s;const t=this.type;return(t==null?void 0:t.resizableY)!==void 0?t.resizableY:((s=(e=this.node)==null?void 0:e.type)==null?void 0:s.resizableY)||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),s=e.indexOf(Math.min(...e));return this.ports[s]}}}getIncomingConnections(t=!1){const e=[];for(const s of this.ports)for(const r of s.incomingConnections)!t&&r.removed||e.push(r);return e}getOutgoingConnections(t=!1){const e=[];for(const s of this.ports)for(const r of s.outgoingConnections)!t&&r.removed||e.push(r);return e}getConnections(t=!1){const e=[];for(const s of this.ports){for(const r of s.incomingConnections)!t&&r.removed||e.push(r);for(const r of s.outgoingConnections)!t&&r.removed||e.push(r)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const s=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];let l,o;switch(t){case b.Left:l=[s[0]-e,s[1]],o=[r[0],r[1]],l[1]-l[0]<this.getMinWidth()&&(l[0]=l[1]-this.getMinWidth());break;case b.Top:l=[s[0],s[1]],o=[r[0]-e,r[1]],o[1]-o[0]<this.getMinHeight()&&(o[0]=o[1]-this.getMinHeight());break;case b.Right:l=[s[0],s[1]+e],o=[r[0],r[1]],l[1]-l[0]<this.getMinWidth()&&(l[1]=l[0]+this.getMinWidth());break;case b.Bottom:l=[s[0],s[1]],o=[r[0],r[1]+e],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(t){const e=[this.coords[0],this.coords[0]+this.width],s=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const r=[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(Xt(n.coords,e,s,r,l,n.anchorPointX,n.anchorPointY));const o=this.type;this.label&&(this.label.coords=[this.coords[0]+Z(o==null?void 0:o.label),this.coords[1]+U(o==null?void 0:o.label)],this.label.width=this.width-Z(o==null?void 0:o.label)-at(o==null?void 0:o.label),this.label.height=this.height-U(o==null?void 0:o.label)-ot(o==null?void 0:o.label),this.label.updateInView());for(const n of this.decorators)n.move(Xt(n.coords,e,s,r,l,n.anchorPointX,n.anchorPointY));this.getConnections().forEach(n=>n.tighten()),this.updateInView()}}class ao extends pt{constructor(t){super(),this.model=t}new(t,e,s,r,l,o,n){var d,u,p,m,f,g,y,w,k,E;const a=new B(this.model,t,e,s,r,l,o,n);super.add(a),a.updateInView(),t.sections.push(a),t.updateInView();const c=(m=(p=(u=(d=t.type.sectionGrid)==null?void 0:d.sections)==null?void 0:u[s])==null?void 0:p[e])==null?void 0:m.ports;if(c&&c.length>0)for(let C=0;C<c.length;++C){const T=c[C],M=this.model.ports.new(T.type!==void 0?this.model.ports.types.get(T.type):void 0,a,[a.coords[0]+(T.coords[0]||0),a.coords[1]+(T.coords[1]||0)],T.connectionPoint!==void 0?[a.coords[0]+(T.connectionPoint[0]||0),a.coords[1]+(T.connectionPoint[1]||0)]:void 0,T==null?void 0:T.direction,`${a.id}_${C}`,T.anchorPointX||"floating",T.anchorPointY||"floating");if((f=M.type)!=null&&f.label){const x={...O,...(g=M.type)==null?void 0:g.label},R=6*x.fontSize+jt(x)+Ot(x),L=x.fontSize+Dt(x)+_t(x);let V;switch(M.direction){case b.Bottom:case b.Left:case b.Right:V=[M.coords[0]-R/2,M.coords[1]-L-ot(x)];break;case b.Top:V=[M.coords[0]-R/2,M.coords[1]+U(x)];break;default:V=M.coords}this.model.fields.new(M,V,x.fontSize,x.fontFamily,x.color,x.selectedColor,R,L,x.horizontalAlign,x.verticalAlign,x.orientation,"",x.editable,x.fit,x.shrink)}}const h=(E=(k=(w=(y=t.type.sectionGrid)==null?void 0:y.sections)==null?void 0:w[s])==null?void 0:k[e])==null?void 0:E.label;if(h){const C={...O,...h};this.model.fields.new(a,[a.coords[0]+Z(C),a.coords[1]+U(C)],C.fontSize,C.fontFamily,C.color,C.selectedColor,a.width-Z(C)-at(C),a.height-U(C)-ot(C),C.horizontalAlign,C.verticalAlign,C.orientation,"",C.editable,C.fit,C.shrink)}return a}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&Y(e.node.sections,e),super.remove(t),e.updateInView()}}}const vi={lookType:"shaped-look",shape:Zt.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},ft={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:vi,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:zt,properties:[]};class yi{constructor(t){const e={...ft,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.bottomPadding=co(e),this.leftPadding=ho(e),this.rightPadding=go(e),this.topPadding=uo(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new no(e.sectionGrid):null;const s=nt(e.look);this.defaultLook=s.defaultLook,this.selectedLook=s.selectedLook,this.highlightedLook=s.highlightedLook,this.selectedAndHighlightedLook=s.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new qt((t==null?void 0:t.properties)||[])}}class j extends Tt{constructor(t,e,s=[0,0],r){if(t.nodes.get(r)!==void 0)throw new Error(`DiagramNode with id "${r}" already exists`);if(!r)throw new Error("DiagramNode cannot have an empty or null id");super(t,r),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new wt(e.propertySet,this),this.originalData={},this.coords=s,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){var e,s;t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new wt(t.propertySet,this)),(s=(e=this.model.canvas)==null?void 0:e.userSelection)==null||s.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.nodes.types.get(t);e&&(this.type=e)}}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}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(t){if(t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateNodesInView(this.id)}raise(){var t;(t=this.select())==null||t.raise();for(const e of this.sections)e.raise();this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise();for(const e of this.children)e.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),s=e.indexOf(Math.min(...e));return this.ports[s]}}}getIncomingConnections(t=!1){const e=[];for(const s of this.ports)for(const r of s.incomingConnections)!t&&r.removed||e.push(r);return e}getOutgoingConnections(t=!1){const e=[];for(const s of this.ports)for(const r of s.outgoingConnections)!t&&r.removed||e.push(r);return e}getConnections(t=!1){const e=[];for(const s of this.ports){for(const r of s.incomingConnections)!t&&r.removed||e.push(r);for(const r of s.outgoingConnections)!t&&r.removed||e.push(r)}return e}getAdjacentNodes(t=!1){var s,r;const e=[];for(const l of this.ports){for(const o of l.incomingConnections){if(!t&&o.removed)continue;const n=(s=o.start)==null?void 0:s.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}for(const o of l.outgoingConnections){if(!t&&o.removed)continue;const n=(r=o.end)==null?void 0:r.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t==null?void 0:t.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,s=!1;for(;e!==void 0;){if(e.id===t.id){s=!0;break}e=e.parent}s||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){Y(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(a=>a.indexXInNode)),s=Math.max(...this.sections.map(a=>a.indexYInNode)),r=this.coords[0]-t.coords[0]+this.type.leftPadding;r>=0&&(this.sections.length>0?this.stretchSections(b.Left,r,e,s):this.stretch(b.Left,r));const l=this.coords[1]-t.coords[1]+this.type.topPadding;l>=0&&(this.sections.length>0?this.stretchSections(b.Top,l,e,s):this.stretch(b.Top,l));const o=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;o>=0&&(this.sections.length>0?this.stretchSections(b.Right,o,e,s):this.stretch(b.Right,o));const n=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;n>=0&&(this.sections.length>0?this.stretchSections(b.Bottom,n,e,s):this.stretch(b.Bottom,n)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const s of this.children)s.move([s.coords[0]+e[0],s.coords[1]+e[1]]);for(const s of this.sections)s.move([s.coords[0]+e[0],s.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const s=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];let l,o;switch(t){case b.Left:l=[s[0]-e,s[1]],o=[r[0],r[1]],l[1]-l[0]<this.type.minWidth&&(l[0]=l[1]-this.type.minWidth);break;case b.Top:l=[s[0],s[1]],o=[r[0]-e,r[1]],o[1]-o[0]<this.type.minHeight&&(o[0]=o[1]-this.type.minHeight);break;case b.Right:l=[s[0],s[1]+e],o=[r[0],r[1]],l[1]-l[0]<this.type.minWidth&&(l[1]=l[0]+this.type.minWidth);break;case b.Bottom:l=[s[0],s[1]],o=[r[0],r[1]+e],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(t,e,s,r){let l=Number.NEGATIVE_INFINITY;switch(t){case b.Bottom:for(const o of this.sections)o.indexYInNode===r&&(l=Math.max(l,o.getMinHeight()-o.height));e<l&&(e=l);for(const o of this.sections)o.indexYInNode===r?o.stretch(t,e):o.indexYInNode>r&&o.move([o.coords[0],o.coords[1]+e]);break;case b.Right:for(const o of this.sections)o.indexXInNode===s&&(l=Math.max(l,o.getMinWidth()-o.width));e<l&&(e=l);for(const o of this.sections)o.indexXInNode===s?o.stretch(t,e):o.indexXInNode>s&&o.move([o.coords[0]+e,o.coords[1]]);break;case b.Top:for(const o of this.sections)o.indexYInNode===r&&(l=Math.max(l,o.getMinHeight()-o.height));e<l&&(e=l);for(const o of this.sections)o.indexYInNode===r?o.stretch(t,e):o.indexYInNode<r&&o.move([o.coords[0],o.coords[1]-e]);break;case b.Left:for(const o of this.sections)o.indexXInNode===s&&(l=Math.max(l,o.getMinWidth()-o.width));e<l&&(e=l);for(const o of this.sections)o.indexXInNode===s?o.stretch(t,e):o.indexXInNode<s&&o.move([o.coords[0]-e,o.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const r of this.sections)e[r.id]=r.getGeometry();const s={};for(const r of this.children)r.id!==t&&(s[r.id]=r.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:s}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],s=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const r=[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=t.children[o.id];n&&o.setGeometry(n)}for(const o of this.sections){const n=t.sections[o.id];n&&o.setGeometry(n)}for(const o of this.ports)o.move(Xt(o.coords,e,s,r,l,o.anchorPointX,o.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+Z(this.type.label),this.coords[1]+U(this.type.label)],this.label.width=this.width-Z(this.type.label)-at(this.type.label),this.label.height=this.height-U(this.type.label)-ot(this.type.label),this.label.updateInView());for(const o of this.decorators)o.move(Xt(o.coords,e,s,r,l,o.anchorPointX,o.anchorPointY));this.getConnections().forEach(o=>o.tighten()),this.updateInView()}removeSectionColumn(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let s=0;const r=[...this.sections];for(const o of r)o.indexYInNode===t&&(s=Math.max(s,o.width),this.model.sections.remove(o.id));for(const o of r)o.indexYInNode>t&&(--o.indexYInNode,o.move([o.coords[0]-s-e,o.coords[1]]));this.stretch(b.Right,-e-s)}removeSectionRow(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let s=0;const r=[...this.sections];for(const o of r)o.indexXInNode===t&&(s=Math.max(s,o.height),this.model.sections.remove(o.id));for(const o of r)o.indexYInNode>t&&(--o.indexXInNode,o.move([o.coords[0],o.coords[1]-s-e]));this.stretch(b.Bottom,-e-s)}copySectionColumn(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let s=0;const r=[...this.sections];for(const o of r)if(o.indexXInNode===t){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+e,o.coords[1]],o.width,o.height,`${o.id}_copy_${n}_${o.indexYInNode}`)}for(const o of r)o.indexXInNode>t&&(++o.indexXInNode,o.move([o.coords[0]+s+e,o.coords[1]]));this.stretch(b.Right,e+s)}copySectionRow(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let s=0;const r=[...this.sections];for(const o of r)if(o.indexYInNode===t){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+e],o.width,o.height,`${o.id}_copy_${o.indexXInNode}_${n}`)}for(const o of r)o.indexYInNode>t&&(++o.indexYInNode,o.move([o.coords[0],o.coords[1]+s+e]));this.stretch(b.Bottom,e+s)}}class lo extends pt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,s){var o,n,a,c,h,d,u;let r;if(t instanceof yi)r=t;else{const p=this.types.get(t);if(p===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);r=p}const l=new j(this.model,r,e,s);if(super.add(l),l.updateInView(),r.sectionGrid!==null){let p=l.coords[1]+(r.sectionGrid.margin||0);for(let m=0;m<r.sectionGrid.sections.length;++m){let f=l.coords[0]+(r.sectionGrid.margin||0);for(let g=0;g<r.sectionGrid.sections[m].length;++g)this.model.sections.new(l,g,m,[f,p],((o=r.sectionGrid.defaultWidths)==null?void 0:o[g])||si,((n=r.sectionGrid.defaultHeights)==null?void 0:n[m])||ni,`${l.id}_${m}_${g}`),f+=(((a=r.sectionGrid.defaultWidths)==null?void 0:a[g])||si)+(r.sectionGrid.margin||0);p+=(((c=r.sectionGrid.defaultHeights)==null?void 0:c[m])||ni)+(r.sectionGrid.margin||0)}}if(r.ports.length>0)for(let p=0;p<r.ports.length;++p){const m=r.ports[p],f=m.type!==void 0?this.model.ports.types.get(m.type):void 0,g=this.model.ports.new(f,l,[l.coords[0]+m.coords[0],l.coords[1]+m.coords[1]],m.connectionPoint!==void 0?[l.coords[0]+(m.connectionPoint[0]||0),l.coords[1]+(m.connectionPoint[1]||0)]:void 0,m.direction,`${l.id}_port_${p}`,m.anchorPointX||"floating",m.anchorPointY||"floating");if((h=g.type)!=null&&h.label){const y={...O,...(d=g.type)==null?void 0:d.label},w=6*y.fontSize+jt(y)+Ot(y),k=y.fontSize+Dt(y)+_t(y);let E;switch(g.direction){case b.Bottom:case b.Left:case b.Right:E=[g.coords[0]-w/2,g.coords[1]-k-ot(y)];break;case b.Top:E=[g.coords[0]-w/2,g.coords[1]+U(y)];break;default:E=g.coords}this.model.fields.new(g,E,y.fontSize,y.fontFamily,y.color,y.selectedColor,w,k,y.horizontalAlign,y.verticalAlign,y.orientation,"",y.editable,y.fit,y.shrink)}}if(r.label){const p={...O,...r.label};this.model.fields.new(l,[l.coords[0]+Z(p),l.coords[1]+U(p)],p.fontSize,p.fontFamily,p.color,p.selectedColor,l.width-Z(p)-at(p),l.height-U(p)-ot(p),p.horizontalAlign,p.verticalAlign,p.orientation,"",p.editable,p.fit,p.shrink)}if(r.decorators.length>0)for(let p=0;p<r.decorators.length;++p){const m=r.decorators[p];this.model.decorators.new(l,[l.coords[0]+m.coords[0],l.coords[1]+m.coords[1]],m.width,m.height,l.getPriority(),m.html,`${l.id}_decorator_${p}`,m.anchorPointX||"floating",m.anchorPointY||"floating")}return l.valueSet.resetValues(),(u=l.model.canvas)==null||u.fitNodeInView(l.id),l}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&Y(e.parent.children,e);e.children.length>0;)this.model.nodes.remove(e.children[0].id);for(;e.sections.length>0;)this.model.sections.remove(e.sections[0].id);for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);for(;e.decorators.length>0;)this.model.decorators.remove(e.decorators[0].id);e.label&&this.model.fields.remove(e.label.id),super.remove(t),e.updateInView()}}getAtCoordinates(t,e){const s=[];for(const r of this)r.coords[0]<t&&t<r.coords[0]+r.width&&r.coords[1]<e&&e<r.coords[1]+r.height&&s.push(r);return s}}const bi=i=>{for(let t=0;t<i.length;++t)for(let e=0;e<i.length;++e)e!==t&&i[e].isAncestorOf(i[t])&&(i.splice(e,1),--e,t>e&&--t);return i},co=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?ft.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?ft.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),ho=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?ft.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?ft.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],go=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?ft.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?ft.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?ft.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?ft.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),ki={lookType:"shaped-look",shape:Zt.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Ft=nt(ki),wi={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:ki};class mo{constructor(t){const e={...wi,...t};this.id=e.id,this.name=e.name,this.label=e.label,this.allowsOutgoing=e.allowsOutgoing,this.allowsIncoming=e.allowsIncoming,this.width=e.width;const s=nt(e.look);this.defaultLook=s.defaultLook,this.selectedLook=s.selectedLook,this.highlightedLook=s.highlightedLook,this.selectedAndHighlightedLook=s.selectedAndHighlightedLook}}class xt extends Tt{constructor(t,e,s,r,l,o,n,a="floating",c="floating"){if(t.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(t,n),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=s,this.coords=r,this.connectionPoint=l||r,this.direction=o,this.anchorPointX=a,this.anchorPointY=c}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.updateInView())}get typeString(){var t;return(t=this.type)==null?void 0:t.id}set typeString(t){var e;if(t!==((e=this.type)==null?void 0:e.id))if(t===void 0)this.type=void 0;else{const s=this.model.ports.types.get(t);s&&(this.type=s)}}get allowsOutgoing(){var t,e;return((t=this.type)==null?void 0:t.allowsOutgoing)!==void 0?(e=this.type)==null?void 0:e.allowsOutgoing:!0}get allowsIncoming(){var t,e;return((t=this.type)==null?void 0:t.allowsIncoming)!==void 0?(e=this.type)==null?void 0:e.allowsIncoming:!0}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){var t,e,s,r;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(t=this.type||Ft)==null?void 0:t.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(e=this.type||Ft)==null?void 0:e.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(s=this.type||Ft)==null?void 0:s.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(r=this.type||Ft)==null?void 0:r.defaultLook}set look(t){if(t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get width(){var t;return((t=this.type)==null?void 0:t.width)||wi.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updatePortsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.incomingConnections)e.raise();for(const e of this.outgoingConnections)e.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof j)return this.rootElement;if(this.rootElement instanceof B)return this.rootElement.node}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||zt}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];this.coords=t,this.connectionPoint[0]=this.connectionPoint[0]+e[0],this.connectionPoint[1]=this.connectionPoint[1]+e[1];for(const 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]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return hi(this.coords,t)}}class fo extends pt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,s,r,l,o,n="floating",a="floating"){const c=new xt(this.model,t,e,s,r,l,o,n,a);return super.add(c),c.updateInView(),e!==void 0&&e.ports.push(c),c}remove(t){const e=this.get(t,!0);if(e){for(;e.outgoingConnections.length>0;)this.model.connections.remove(e.outgoingConnections[0].id);for(;e.incomingConnections.length>0;)this.model.connections.remove(e.incomingConnections[0].id);e.label&&this.model.fields.remove(e.label.id),(e.rootElement instanceof j||e.rootElement instanceof B)&&Y(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class xi{import(t,e){t.clear(),e.id&&(t.id=e.id),t.name=e.name,t.description=e.description,t.type=e.type,t.createdAt=new Date(e.createdAt),t.updatedAt=new Date(e.updatedAt);for(const s of e.nodes||[])this.importNode(t,s);for(const s of e.connections||[])this.importConnection(t,s);return e.data&&t.valueSet.setValues(e.data),e.collabMeta&&(t.logicalClock=e.collabMeta.logicalClock,t.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),t}importNode(t,e){var r,l,o,n,a,c,h,d,u,p;const s=t.nodes.types.get(e.type);if(s){const m=new j(t,s,e.coords,e.id);if(t.nodes.add(m),m.width=e.width,m.height=e.height,e.label){if(s.decorators)for(let g=0;g<s.decorators.length;++g){const y=s.decorators[g];t.decorators.new(m,[m.coords[0]+y.coords[0],m.coords[1]+y.coords[1]],y.width,y.height,m.getPriority(),y.html,`${m.id}_decorator_${g}`)}if(s.label){const g={...O,...s.label},y=new mt(t,m,[m.coords[0]+Z(g),m.coords[1]+U(g)],m.width-Z(g)-at(g),m.height-U(g)-ot(g),g.fontSize,g.fontFamily,g.color,g.selectedColor,g.horizontalAlign,g.verticalAlign,g.orientation,"",g.editable,g.fit,g.shrink);y.text=e.label,m.label=y,t.fields.add(y),y.updateInView()}}for(const g of e.children||[]){const y=this.importNode(t,g);y!==void 0&&((r=m.children)==null||r.push(y),y.parent=m)}for(const g of e.sections||[]){const y=new B(t,m,g.indexXInNode,g.indexYInNode,g.coords,g.width,g.height,g.id);if((l=m.sections)==null||l.push(y),t.sections.add(y),g.label&&(c=(a=(n=(o=s.sectionGrid)==null?void 0:o.sections)==null?void 0:n[g.indexYInNode])==null?void 0:a[g.indexXInNode])!=null&&c.label){const k={...O,...(p=(u=(d=(h=s.sectionGrid)==null?void 0:h.sections)==null?void 0:d[g.indexYInNode])==null?void 0:u[g.indexXInNode])==null?void 0:p.label},E=new mt(t,y,[y.coords[0]+Z(k),y.coords[1]+U(k)],y.width-Z(k)-at(k),y.height-U(k)-ot(k),k.fontSize,k.fontFamily,k.color,k.selectedColor,k.horizontalAlign,k.verticalAlign,k.orientation,"",k.editable,k.fit,k.shrink);E.text=g.label,y.label=E,t.fields.add(E),E.updateInView()}let w=0;for(const k of g.ports||[]){const E=k.type!==void 0?t.ports.types.get(k.type):void 0,C=new xt(t,E,y,k.coords,k.connectionPoint,k.direction,k.id);if(y.ports.push(C),t.ports.add(C),k.label){if(s.ports.length>w&&(E!=null&&E.label)){const T={...O,...E==null?void 0:E.label};let M;switch(C.direction){case b.Top:case b.Left:M=[C.coords[0]-T.fontSize,C.coords[1]-T.fontSize];break;case b.Bottom:M=[C.coords[0]-T.fontSize,C.coords[1]+T.fontSize];break;case b.Right:M=[C.coords[0]+T.fontSize,C.coords[1]-T.fontSize];break;default:M=C.coords}const x=new mt(t,C,M,T.fontSize,T.fontSize,T.fontSize,T.fontFamily,T.color,T.selectedColor,T.horizontalAlign,T.verticalAlign,T.orientation,"",T.editable,T.fit,T.shrink);x.text=k.label,C.label=x,t.fields.add(x),x.updateInView()}++w}k.collabMeta&&(C.selfRemoved=k.collabMeta.selfRemoved,C.selfRemovedTimestamp=k.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(C.label,k.collabMeta.label)),C.updateInView()}g.collabMeta&&(y.selfRemoved=g.collabMeta.selfRemoved,y.selfRemovedTimestamp=g.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(y.label,g.collabMeta.label)),y.updateInView()}let f=0;for(const g of e.ports||[]){const y=g.type!==void 0?t.ports.types.get(g.type):void 0,w=new xt(t,y,m,g.coords,g.connectionPoint,g.direction,g.id);if(m.ports.push(w),t.ports.add(w),g.label){if(s.ports.length>f&&(y!=null&&y.label)){const k={...O,...y==null?void 0:y.label};let E;switch(w.direction){case b.Top:case b.Left:E=[w.coords[0]-k.fontSize,w.coords[1]-k.fontSize];break;case b.Bottom:E=[w.coords[0]-k.fontSize,w.coords[1]+k.fontSize];break;case b.Right:E=[w.coords[0]+k.fontSize,w.coords[1]-k.fontSize];break;default:E=w.coords}const C=new mt(t,w,E,k.fontSize,k.fontSize,k.fontSize,k.fontFamily,k.color,k.selectedColor,k.horizontalAlign,k.verticalAlign,k.orientation,"",k.editable,k.fit,k.shrink);C.text=g.label,w.label=C,t.fields.add(C),C.updateInView()}++f}g.collabMeta&&(w.selfRemoved=g.collabMeta.selfRemoved,w.selfRemovedTimestamp=g.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(w.label,g.collabMeta.label)),w.updateInView()}return e.data&&m.valueSet.setValues(e.data),e.collabMeta&&(m.selfRemoved=e.collabMeta.selfRemoved,m.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,m.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(m.label,e.collabMeta.label),m.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),m.updateInView(),m.raise(),m}}importConnection(t,e){const s=t.connections.types.get(e.type);if(s){const r=new dt(t,s,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(r),r.startLabel=e.startLabel,r.middleLabel=e.middleLabel,r.endLabel=e.endLabel,r.points=e.points,e.data&&r.valueSet.setValues(e.data),e.collabMeta&&(r.selfRemoved=e.collabMeta.selfRemoved,r.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,r.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),r.updateInView(),r.raise(),r}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class Jt{constructor(t,e,s,r,l,o,n){this.canvas=t,this.id=e,this.typeId=s,this.coords=r,this.parentId=l,this.label=o,this.values=n}do(){var e;const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&((e=this.canvas.model.nodes.get(this.parentId))==null||e.addChild(t)),t.label&&(t.label.text=this.label||""),this.values!==void 0?t.valueSet.setValues(structuredClone({...t.valueSet.getValues(),...this.values})):t.valueSet.resetValues()}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new Jt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class pe{constructor(t,e,s,r,l,o,n){this.canvas=t,this.nodeId=e,this.copyColumnIndex=s,this.copyRowIndex=r,this.removeColumnIndex=l,this.removeRowIndex=o,this.timestamp=n}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&St(this.timestamp,t.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&t.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&t.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&t.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&t.removeSectionRow(this.removeRowIndex),t.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(t,e){return new pe(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class ve{constructor(t,e,s){this.canvas=t,this.to=e,this.timestamp=s}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&St(this.timestamp,e.geometryTimestamp)){const s=this.to[t];e.move([s[0],s[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new ve(t,e.to,e.timestamp)}}class Ht{constructor(t,e,s,r){this.canvas=t,this.nodeIds=e,this.delta=s,this.timestamp=r}do(){var t;for(const e of this.nodeIds){const s=this.canvas.model.nodes.get(e,!0);s&&St(this.timestamp,s.geometryTimestamp)&&(s.move([s.coords[0]+this.delta[0],s.coords[1]+this.delta[1]]),(t=s.parent)==null||t.fitToChild(s),s.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new Ht(t,e.nodeIds,e.delta,e.timestamp)}}class st{constructor(t,e,s,r){this.canvas=t,this.nodeId=e,this.to=s,this.timestamp=r}do(){var e,s,r;const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&St(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),(e=t.label)!=null&&e.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);for(const l of t.sections)(s=l.label)!=null&&s.fit&&this.canvas.fitFieldRootInView(l.label.id,l.label.shrink);(r=t.parent)==null||r.fitToChild(t),t.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new st(t,e.nodeId,e.to,e.timestamp)}}class Gt{constructor(t,e,s,r,l){this.canvas=t,this.childId=e,this.parentId=s,this.childGeometry=r,this.timestamp=l}do(){var s;const t=this.canvas.model.nodes.get(this.childId,!0),e=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;t&&(this.parentId===void 0||e)&&St(this.timestamp,t.geometryTimestamp)&&((s=t.parent)==null||s.removeChild(t),t.setGeometry(this.childGeometry),e==null||e.addChild(t))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,e){return new Gt(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class Qt{constructor(t,e,s,r,l){this.canvas=t,this.id=e,this.typeId=s,this.startId=r,this.endId=l}do(){const t=this.canvas.model.ports.get(this.startId,!0),e=this.canvas.model.ports.get(this.endId,!0);t&&e&&this.canvas.model.connections.new(this.typeId,t,e,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,e){return new Qt(t,e.id,e.typeId,e.startId,e.endId)}}class Nt{constructor(t,e,s,r){this.canvas=t,this.fieldId=e,this.to=s,this.timestamp=r}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&St(this.timestamp,t.textTimestamp)&&(t.text=this.to,t.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Nt(t,e.fieldId,e.to,e.timestamp)}}class Pt{constructor(t,e,s,r){this.canvas=t,this.id=e,this.to=s,this.timestamp=r}getValueSet(){var t;return this.id===void 0?this.canvas.model.valueSet:(t=this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))==null?void 0:t.valueSet}do(){var t;(t=this.getValueSet())==null||t.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Pt(t,e.id,e.to,e.timestamp)}}class lt{constructor(t,e,s,r,l,o,n,a){this.canvas=t,this.nodeIds=e,this.sectionIds=s,this.portIds=r,this.connectionIds=l,this.fieldIds=o,this.selfRemoved=n,this.timestamp=a}doOne(t){t&&St(this.timestamp,t.selfRemovedTimestamp)&&(t.selfRemoved=this.selfRemoved,t.selfRemovedTimestamp=this.timestamp)}do(){for(const t of this.nodeIds)this.doOne(this.canvas.model.nodes.get(t,!0));for(const t of this.sectionIds)this.doOne(this.canvas.model.sections.get(t,!0));for(const t of this.portIds)this.doOne(this.canvas.model.ports.get(t,!0));for(const t of this.connectionIds)this.doOne(this.canvas.model.connections.get(t,!0));for(const t of this.fieldIds)this.doOne(this.canvas.model.fields.get(t,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,e){return new lt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class te{constructor(t,e,s){this.canvas=t,this.nodes=e,this.connections=s}do(){const t=new xi;this.canvas.userSelection.clear();for(const e of this.nodes){const s=t.importNode(this.canvas.model,e);s&&this.canvas.userSelection.add(s)}for(const e of this.connections){const s=t.importConnection(this.canvas.model,e);s&&this.canvas.userSelection.add(s)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new te(t,e.nodes,e.connections)}}class po{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=ii()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+ii()}doCollaboratively(t){if(t.do(),this.onSend){const e=t.serialize();this.onSend(e)}}receive(t){switch("timestamp"in t&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,t.timestamp[0])),t.type){case"addNode":{Jt.deserialize(this.canvas,t).do();break}case"addSection":{pe.deserialize(this.canvas,t).do();break}case"applyLayout":{ve.deserialize(this.canvas,t).do();break}case"move":{Ht.deserialize(this.canvas,t).do();break}case"setGeometry":{st.deserialize(this.canvas,t).do();break}case"setParent":{Gt.deserialize(this.canvas,t).do();break}case"addConnection":{Qt.deserialize(this.canvas,t).do();break}case"editField":{Nt.deserialize(this.canvas,t).do();break}case"updateValues":{Pt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{lt.deserialize(this.canvas,t).do();break}case"paste":{te.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class vo{constructor(t,e){this.canvas=t,this.maximum=e,this.history=[],this.index=0}add(t){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(t)):(this.history.push(t),++this.index),this.canvas.diagramChange$.next({action:t,method:0})}undo(){let t;if(this.index>0){let e;do--this.index,t=this.history[this.index],e=t.undo();while(!e&&this.index>0)}this.canvas.diagramChange$.next({action:t,method:1})}redo(){let t;if(this.index<this.history.length){let e;do t=this.history[this.index],e=t.redo(),++this.index;while(!e&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:t,method:2})}}var S=(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))(S||{});class yo{constructor(t,e,s,r,l,o,n,a,c){this.canvas=t,this.type=e,this.coords=s,this.parentId=r,this.ancestorId=l,this.fromAncestorGeometry=o,this.toAncestorGeometry=n,this.label=a,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Jt(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const e=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){const t=this.canvas.model.nodes.get(this.id),e=new lt(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new lt(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return t===void 0}}class ne{constructor(t,e,s){this.canvas=t,this.nodeIds=e,this.delta=s}do(){const t=new Ht(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const t=new Ht(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class X{constructor(t,e,s,r,l,o,n,a){this.canvas=t,this.intent=e,this.nodeId=s,this.from=r,this.to=l,this.ancestorId=o,this.fromAncestorGeometry=n,this.toAncestorGeometry=a}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class bo{constructor(t,e,s,r,l,o,n,a,c){this.canvas=t,this.childId=e,this.fromParentId=s,this.toParentId=r,this.fromChildGeometry=l,this.toChildGeometry=o,this.ancestorId=n,this.fromAncestorGeometry=a,this.toAncestorGeometry=c}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return t!==void 0}redo(){return this.do()}}class re{constructor(t,e,s,r){this.canvas=t,this.type=e,this.startId=s,this.endId=r,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Qt(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=this.canvas.model.connections.get(this.id),e=new lt(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}redo(){const t=this.canvas.model.connections.get(this.id),e=new lt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class ri{constructor(t,e,s,r){this.canvas=t,this.fieldId=e,this.from=s,this.to=r}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new Nt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}undo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.to=t.text;const e=new Nt(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}redo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.from=t.text;const e=new Nt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class ko{constructor(t,e,s,r){this.canvas=t,this.id=e,this.from=s,this.to=r}do(){const t=new Pt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Pt(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.to=e.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}redo(){const t=new Pt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.from=e.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}}class wo{constructor(t,e,s,r,l,o){this.canvas=t,this.nodeIds=e,this.sectionIds=s,this.portIds=r,this.connectionIds=l,this.fieldIds=o}do(){const t=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),e=new lt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}undo(){const t=this.nodeIds.map(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),e=new lt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){return this.do()}}class xo{constructor(t,e,s,r){this.canvas=t,this.nodes=e,this.connections=s,this.coords=r}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const l of this.nodes)l.coords[0]<t[0]&&(t[0]=l.coords[0]),l.coords[1]<t[1]&&(t[1]=l.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,s={};for(const l of this.nodes){const o=l.id,n=this.canvas.collabEngine.freshId();if(s[o]=n,l.id=n,e&&(l.coords=[l.coords[0]+e[0],l.coords[1]+e[1]]),l.sections)for(const a of l.sections){const c=a.id;if(a.id.includes(l.id)?a.id=a.id.replace(l.id,n):a.id=this.canvas.collabEngine.freshId(),s[c]=a.id,e&&(a.coords=[a.coords[0]+e[0],a.coords[1]+e[1]]),a.ports)for(const h of a.ports){const d=h.id;h.id.includes(l.id)?h.id=h.id.replace(l.id,n):h.id=this.canvas.collabEngine.freshId(),s[d]=h.id,e&&(h.coords=[h.coords[0]+e[0],h.coords[1]+e[1]])}}if(l.ports)for(const a of l.ports){const c=a.id;a.id.includes(l.id)?a.id=a.id.replace(l.id,n):a.id=this.canvas.collabEngine.freshId(),s[c]=a.id,e&&(a.coords=[a.coords[0]+e[0],a.coords[1]+e[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,e)for(let n=0;n<l.points.length;++n)l.points[n]=[l.points[n][0]+e[0],l.points[n][1]+e[1]]}const r=new te(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(r),!0}undo(){const t=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),e=new lt(this.canvas,this.nodes.map(s=>s.id),[],[],this.connections.map(s=>s.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=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),e=new lt(this.canvas,this.nodes.map(s=>s.id),[],[],this.connections.map(s=>s.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class ee{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Si=(i=>(i[i.DoubleClick=0]="DoubleClick",i[i.SecondaryClick=1]="SecondaryClick",i[i.Selection=2]="Selection",i[i.Highlight=3]="Highlight",i))(Si||{});class yt extends ee{constructor(t,e,s){super(0),this.cause=t,this.target=e,this.coords=s}}class bt extends ee{constructor(t,e,s){super(1),this.cause=t,this.target=e,this.coords=s}}class G extends ee{constructor(t,e){super(2),this.targets=t,this.selected=e}}class it extends ee{constructor(t){super(3),this.target=t}}class Ci extends Tt{constructor(t,e,s,r,l,o,n,a,c="floating",h="floating"){if(t.objects.get(a)!==void 0)throw new Error(`DiagramDecorator with id "${a}" already exists`);if(!a)throw new Error("DiagramDecorator cannot have an empty or null id");super(t,a),this.rootElement=e,this.coords=s,this.width=r,this.height=l,this.priority=o,this.html=n,this.anchorPointX=c,this.anchorPointY=h}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateDecoratorsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class So extends pt{constructor(t){super(),this.model=t}new(t,e,s,r,l,o,n,a="floating",c="floating"){const h=new Ci(this.model,t,e,s,r,l,o,n,a,c);return super.add(h),h.updateInView(),t!==void 0&&t.decorators.push(h),h}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof j||e.rootElement instanceof B)&&Y(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Co extends Tt{constructor(t,e,s,r,l,o,n){if(t.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(t,n),this.coords=e,this.width=s,this.height=r,this.priority=l,this.html=o}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateObjectsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Io extends pt{constructor(t){super(),this.model=t}new(t,e,s,r,l,o){const n=new Co(this.model,t,e,s,r,l,o);return super.add(n),n.updateInView(),n}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Ii{constructor(t,e,s,r,l,o=[]){this.nodes=new lo(this),this.sections=new ao(this),this.ports=new fo(this),this.connections=new eo(this),this.fields=new io(this),this.objects=new Io(this),this.decorators=new So(this),this.canvas=t,this.id=e,this.name=s,this.description=r,this.type=l,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new wt(new qt(o),this)}clear(){var t,e;(t=this.canvas)==null||t.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),(e=this.canvas)==null||e.updateModelInView()}}const kt=i=>!!i.button,ae=(i,t,e,s,r,l,o,n)=>ji(i,[t,e],s,r,Math.max(10,o||0,n||0)*l),I=i=>{i?N.select("body").style("cursor",i):N.select("body").style("cursor",P.Auto)},ut=i=>i instanceof j?i:i instanceof B?i.node||i:i.rootElement instanceof j||i.rootElement instanceof B||i.rootElement instanceof xt?ut(i.rootElement):i,le=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")},ce=i=>{i.filter(".shaped-look").select("path").attr("d",t=>ue(t.look.shape,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor).attr("stroke",t=>t.look.borderColor).attr("stroke-width",t=>`${t.look.borderThickness}px`),i.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",t=>t.width).attr("height",t=>t.height).attr("href",t=>t.look.backgroundImage),i.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopLeft),i.filter(".stretchable-image-look").select("image.top-image").attr("x",t=>t.look.leftMargin).attr("y",0).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTop),i.filter(".stretchable-image-look").select("image.top-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",0).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopRight),i.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageLeft),i.filter(".stretchable-image-look").select("image.center-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageCenter),i.filter(".stretchable-image-look").select("image.right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageRight),i.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomLeft),i.filter(".stretchable-image-look").select("image.bottom-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottom),i.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomRight)},Vt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Ao=(i,t,e)=>{const s=t.append("defs");if(i.gridSize>0&&isFinite(i.gridSize)){const r=s.append("pattern").attr("id",e).attr("x",-i.gridSize/2).attr("y",-i.gridSize/2).attr("width",i.gridSize).attr("height",i.gridSize).attr("patternUnits","userSpaceOnUse");switch(r.append("rect").attr("x",0).attr("y",0).attr("width",i.gridSize).attr("height",i.gridSize).attr("fill",i.backgroundColor),i.gridStyle){case"dots":r.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":r.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),r.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),r.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}t.select("rect").attr("fill",`url(#${e})`)}},me=96,W=32,$t=me+W,Eo=Math.PI/4,To=100,ai={customButtons:[]};class Lo{constructor(t,e){this.canvas=t,this.config=e||ai}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),s=this.canvas.getPointerLocationRelativeToCanvas(t),r=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-$t}px`).attr("y",`${e[1]-$t}px`).attr("width",`${2*$t}px`).attr("height",`${2*$t}px`).style("pointer-events","none").on(A.ContextMenu,o=>{this.canvas.canUserPerformAction(S.ContextMenu)&&(t.preventDefault(),this.open(o))}).on(A.Click,o=>{o.preventDefault(),this.close()});this.contextMenuContainer=r;const l=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(S.Clipboard)&&this.canvas.canUserPerformAction(S.Remove)&&l.push({name:"CUT",imageClass:"daga-cut",onPress:o=>{o.userSelection.cutToClipboard(),o.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(S.Clipboard)&&l.push({name:"COPY",imageClass:"daga-copy",onPress:o=>{o.userSelection.copyToClipboard(),o.cancelAllUserActions()}}),this.canvas.canUserPerformAction(S.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(S.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],a=n.onPress,c=(o+.5-l.length/2)*Eo,h=r.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*W}px`).style("height",`${2*W}px`).style("border-radius",`${W}px`).style("pointer-events","auto").on(A.Click,d=>{a&&(d.preventDefault(),a(this.canvas))}).on(A.KeyDown,d=>{a&&d.key===tt.Enter&&(d.preventDefault(),a(this.canvas))});n.imageClass!==void 0?h.append("xhtml:div").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass):n.image!==void 0&&h.append("xhtml:img").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).attr("src",n.image),h.append("xhtml:span").style("position","absolute").style("left",`${.2*W}px`).style("top",`${1.1*W}px`).style("text-align","center").style("width",`${1.6*W}px`).style("height",`${.35*W}px`).style("margin","0").style("font-size",`${.35*W}px`).style("font-weight","700").style("user-select","none").text(n.name),h.transition().ease(N.easeLinear).duration(To).tween("progress",()=>d=>{const u=c*d;return h.style("left",`${Math.sin(u)*me-W+$t}px`).style("top",`${-Math.cos(u)*me-W+$t}px`)})}}close(){var t;(t=this.contextMenuContainer)==null||t.remove(),this.contextMenuContainer=void 0}}class $o extends pt{constructor(t){super(),this.focus=void 0,this.canvas=t}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,(t instanceof mt||t instanceof Ci)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof j){for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateNodesInView(t.id)}else if(t instanceof B){for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}else t instanceof xt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof dt&&this.canvas.updateConnectionsInView(t.id)}clear(){for(;this.entities.length>0;){const t=this.entities[0];this.remove(t.id),t.updateInView()}this.focus=void 0}}const Mo=1;class Ai{export(t,e=!1){const s={name:t.name,type:t.type,typeVersion:Mo,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(s.id=t.id),t.description&&(s.description=t.description);for(const r of t.nodes.all(!0))!e&&r.removed||r.parent===void 0&&s.nodes.push(this.exportNode(r,e));for(const r of t.connections.all(!0))!e&&r.removed||s.connections.push(this.exportConnection(r,e));return s}exportNode(t,e=!1){var o,n,a,c,h,d;const s=[];for(const u of t.children)s.push(this.exportNode(u,e));const r=[];for(const u of t.sections){const p=[];for(const m of u.ports)p.push({id:m.id,type:(o=m.type)==null?void 0:o.id,coords:Lt(m.coords),connectionPoint:Lt(m.connectionPoint),direction:m.direction,label:((n=m.label)==null?void 0:n.text)||"",...e?{collabMeta:{removed:m.removed,selfRemoved:m.selfRemoved,selfRemovedTimestamp:m.selfRemovedTimestamp,...this.exportLabelCollabMeta(m)}}:{}});r.push({id:u.id,ports:p,label:((a=u.label)==null?void 0:a.text)||"",indexXInNode:u.indexXInNode,indexYInNode:u.indexYInNode,coords:Lt(u.coords),width:u.width,height:u.height,...e?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}})}const l=[];for(const u of t.ports)l.push({id:u.id,type:(c=u.type)==null?void 0:c.id,coords:Lt(u.coords),connectionPoint:Lt(u.connectionPoint),direction:u.direction,label:((h=u.label)==null?void 0:h.text)||"",...e?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}});return{id:t.id,type:t.type.id,children:s,sections:r,ports:l,label:((d=t.label)==null?void 0:d.text)||"",coords:Lt(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){var s,r;return{id:t.id,type:t.type.id,start:((s=t.start)==null?void 0:s.id)||"",end:((r=t.end)==null?void 0:r.id)||"",startLabel:t.startLabel,middleLabel:t.middleLabel,endLabel:t.endLabel,points:t.points,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,dataTimestamps:t.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:t}){return t?{label:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,textTimestamp:t.textTimestamp}}:{}}}const No="Diagram properties";class Po extends pt{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(It.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof j||t instanceof dt)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof B?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof j&&t.sections))for(const e of t.sections)super.add(e),e.updateInView()}remove(t){const e=this.get(t);if(e&&(this.propertyEditorSelection===e&&this.openInPropertyEditor(void 0),super.remove(t),e.updateInView(),e instanceof j&&e.sections))for(const s of e.sections)super.remove(s.id),s.updateInView()}toggle(t){this.contains(t.id)?this.remove(t.id):this.add(t)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const t=this.entities[0];super.remove(t.id),t.updateInView()}}move(t){for(const e of this.all())e instanceof j&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],s=[],r=[],l=[];for(const n of this.all())n instanceof j?t.push(n.id):n instanceof B?e.push(n.id):n instanceof xt?s.push(n.id):n instanceof dt?r.push(n.id):n instanceof mt&&l.push(n.id);const o=new wo(this.canvas,t,e,s,r,l);o.do(),this.canvas.actionStack.add(o)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Ai;for(const s of this.all())s instanceof j&&t.nodes.push(e.exportNode(s,!1)),s instanceof dt&&t.connections.push(e.exportConnection(s,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const s=JSON.parse(e);if(s.type!=="daga-user-selection")return;const r=new xo(this.canvas,s.nodes,s.connections,t);this.canvas.actionStack.add(r),r.do()}catch{return}})}openInPropertyEditor(t,e=!0){var l;e&&this.makeUpdateValuesAction();const s=(l=this.canvas.parentComponent)==null?void 0:l.propertyEditor;if(s===void 0)return;const r=t==null?void 0:t.valueSet;r?(this.propertyEditorSelection=t,e&&(this.propertyEditorValues=structuredClone(r.getValues())),s&&(t instanceof j||t instanceof dt?(t instanceof j?t.name?s.title=`${t.type.name}: ${t.name}`:s.title=t.type.name:t instanceof dt&&(s.title=t.type.name),s.valueSet=void 0,s.valueSet=r):(s.title=No,s.valueSet=void 0,s.valueSet=r))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,s&&(s.title="",s.valueSet=void 0))}makeUpdateValuesAction(){var n,a,c;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof Ii?void 0:this.propertyEditorSelection.id;if(At(this.propertyEditorValues,(n=this.propertyEditorSelection)==null?void 0:n.valueSet.getValues()))return;const e=this.propertyEditorValues,s=structuredClone((a=this.propertyEditorSelection)==null?void 0:a.valueSet.getValues()),[r,l]=fi(e,s,(c=this.propertyEditorSelection)==null?void 0:c.valueSet),o=new ko(this.canvas,t,r,l);o.do(),this.canvas.actionStack.add(o),this.propertyEditorValues=s}}const zo=i=>i*Math.PI/180,li=(i,t,e)=>{const s=zo(e),r=Math.sin(s),l=Math.cos(s),o=(Math.abs(i*l)-Math.abs(t*r))/(l*l-r*r),n=(Math.abs(i*r)-Math.abs(t*l))/(r*r-l*l);return[o,n]},Ro=12,H=6,Vo=25,de="diagram-connection-unfinished",_o=100,Wt=class Wt{constructor(t,e){var s,r,l,o,n,a,c,h,d,u,p,m,f,g,y,w,k,E,C,T,M;if(this.backgroundPatternId=`daga-background-pattern-id-${Wt.canvasCount++}`,this.zoomTransform=N.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new It.Subject,this.diagramChange$=new It.Subject,this.diagramEvent$=new It.Subject,this.propertyEditorChanges$=new It.Subject,this.parentComponent=t,this.model=new Ii(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new Po(this),this.userHighlight=new $o(this),this.contextMenu=new Lo(this,(s=e.canvas)==null?void 0:s.contextMenu),this.backgroundColor=((r=e.canvas)==null?void 0:r.backgroundColor)||"#FFFFFF",this.gridStyle=((o=(l=e.canvas)==null?void 0:l.grid)==null?void 0:o.style)??Vt.style,this.gridSize=((a=(n=e.canvas)==null?void 0:n.grid)==null?void 0:a.enabled)===!1||((c=e.canvas)==null?void 0:c.grid)===void 0?0:Math.abs(((d=(h=e.canvas)==null?void 0:h.grid)==null?void 0:d.spacing)||Vt.spacing),this.gridThickness=Math.abs(((p=(u=e.canvas)==null?void 0:u.grid)==null?void 0:p.thickness)||Vt.thickness),this.gridColor=((f=(m=e.canvas)==null?void 0:m.grid)==null?void 0:f.color)||Vt.color,this.snapToGrid=((y=(g=e.canvas)==null?void 0:g.grid)==null?void 0:y.enabled)===!1||((w=e.canvas)==null?void 0:w.grid)===void 0?!1:((E=(k=e.canvas)==null?void 0:k.grid)==null?void 0:E.snap)||Vt.snap,this.zoomFactor=((C=e.canvas)==null?void 0:C.zoomFactor)||2,this.panRate=((T=e.canvas)==null?void 0:T.panRate)||100,this.inferConnectionType=e.inferConnectionType||!1,this.multipleSelectionOn=!1,this.priorityThresholds=((M=e.canvas)==null?void 0:M.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new vo(this,Vo),this.collabEngine=new po(this),e.nodeTypes)for(const x of e.nodeTypes){const R=new yi({...e.nodeTypeDefaults,...x});this.model.nodes.types.add(R)}if(e.portTypes)for(const x of e.portTypes){const R=new mo({...e.portTypeDefaults,...x});this.model.ports.types.add(R)}if(e.connectionTypes){for(const x of e.connectionTypes){const R=new pi({...e.connectionTypeDefaults,...x});this.model.connections.types.add(R)}this._connectionType=e.defaultConnection!==void 0?this.model.connections.types.get(e.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){var e,s;this._connectionType=t,(s=(e=this.parentComponent)==null?void 0:e.palette)==null||s.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){Y(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){var e,s;this.priorityThreshold=t,this.updateModelInView();for(const r of this.model.nodes)this.fitNodeInView(r.id);(s=(e=this.parentComponent)==null?void 0:e.palette)==null||s.refreshPalette()}initView(t){const e=N.select(t);e.html(""),this.diagramRoot=e.append("div").node(),N.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),N.select(this.diagramRoot).on(A.Click,()=>{var r;(r=N.select(this.diagramRoot).node())==null||r.focus()}).on(A.ContextMenu,r=>{if(this.dragging){r.preventDefault(),r.stopPropagation(),this.dragging=!1;return}const l=new bt(r,null);this.diagramEvent$.next(l),!l.defaultPrevented&&this.canUserPerformAction(S.ContextMenu)&&(r.preventDefault(),this.contextMenu.open(r))}).on(A.DoubleClick,r=>{const l=new yt(r,null);this.diagramEvent$.next(l)}).on(A.KeyDown,r=>{if(!r.ctrlKey&&(r.key===tt.Delete||r.key===tt.Backspace)&&this.canUserPerformAction(S.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),r.ctrlKey&&r.key==="a"){r.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(r.ctrlKey&&r.key==="i"){r.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(r.ctrlKey&&r.key==="c"&&this.canUserPerformAction(S.Clipboard)&&(r.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),r.ctrlKey&&r.key==="x"&&this.canUserPerformAction(S.Clipboard)&&this.canUserPerformAction(S.Remove)&&(r.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),r.ctrlKey&&r.key==="v"&&this.canUserPerformAction(S.Paste)){r.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()}r.ctrlKey&&r.key==="y"&&(r.preventDefault(),this.actionStack.redo()),r.ctrlKey&&r.key==="z"&&(r.preventDefault(),this.actionStack.undo()),r.key==="+"&&this.canUserPerformAction(S.Zoom)&&(r.preventDefault(),this.zoomBy(this.zoomFactor)),r.key==="-"&&this.canUserPerformAction(S.Zoom)&&(r.preventDefault(),this.zoomBy(1/this.zoomFactor)),r.key===tt.ArrowLeft&&this.canUserPerformAction(S.Zoom)&&(r.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),r.key===tt.ArrowRight&&this.canUserPerformAction(S.Zoom)&&(r.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),r.key===tt.ArrowDown&&this.canUserPerformAction(S.Zoom)&&(r.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),r.key===tt.ArrowUp&&this.canUserPerformAction(S.Zoom)&&(r.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.call(this.zoomBehavior=N.zoom().filter(r=>r.type!==A.DoubleClick).on(he.Zoom,r=>{if(r.sourceEvent){if(!this.canUserPerformAction(S.Zoom)){I(P.NotAllowed);return}r.sourceEvent.type===A.Wheel&&r.sourceEvent.wheelDelta!==void 0?(r.sourceEvent.wheelDelta>0&&I(P.ZoomIn),r.sourceEvent.wheelDelta<0&&I(P.ZoomOut)):r.sourceEvent.type===A.MouseMove&&I(P.AllScroll)}this.zoomTransform=r.transform;const l=r.transform.toString();this.selectCanvasElements().attr("transform",l),N.select(`#${this.backgroundPatternId}`).attr("patternTransform",l),this.contextMenu.close()}).on(he.End,()=>{I()})),s.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(A.MouseMove,r=>{if(this.unfinishedConnection!==void 0){const l=this.getPointerLocationRelativeToCanvas(r);this.unfinishedConnection.endCoords=l}}).on(A.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new it(null)))}).on(A.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new it(null))),this.contextMenu.close(),this.userSelection.size()>0){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(r,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(N.drag().filter(r=>this.multipleSelectionOn||kt(r)).on($.Start,r=>{this.startMultipleSelection(r)}).on($.Drag,r=>{this.continueMultipleSelection(r)}).on($.End,r=>{this.finishMultipleSelection(r)})),Ao(this,s,this.backgroundPatternId),s.append("g").attr("class","daga-canvas-elements")}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView(),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView(),t)}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView(),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView(),t,e)}center(){var t;if(this.model.nodes.length>0){const e=(t=this.selectCanvasView().select("rect").node())==null?void 0:t.getBBox(),s=this.model.nodes.all(),r=Math.min(...s.map(f=>f.coords[0])),l=Math.max(...s.map(f=>f.coords[0]+f.width)),o=(r+l)/2,n=l-r,a=e.width,c=Math.min(...s.map(f=>f.coords[1])),h=Math.max(...s.map(f=>f.coords[1]+f.height)),d=(c+h)/2,u=h-c,p=e.height,m=Math.min(a/n,p/u,1);this.translateTo(o,d),this.zoomTo(m)}}getClosestGridPoint(t){return this.gridSize===0||!isFinite(this.gridSize)?t:[Math.round(t[0]/this.gridSize)*this.gridSize,Math.round(t[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){var s;const t=(s=this.selectSVGElement().node())==null?void 0:s.getBoundingClientRect(),e=[(t==null?void 0:t.width)||0,(t==null?void 0:t.height)||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return N.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return N.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return N.pointer(this.getEventHoldingCoordinates(t),N.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=e.exit(),r=e.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}`);t&&t.length>0&&(e=e.filter(o=>t.includes(o.id)));const l=r.merge(e);s.remove(),r.on(A.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(A.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const a=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(a,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new G([n],n.selected))}).on(A.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const a=new bt(o,n);this.diagramEvent$.next(a),!a.defaultPrevented&&this.canUserPerformAction(S.ContextMenu)&&(o.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)),this.userSelection.add(n),this.diagramEvent$.next(new G([n],!0)),this.contextMenu.open(o))}).on(A.DoubleClick,(o,n)=>{const a=new yt(o,n);this.diagramEvent$.next(a)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(o):this.startMovingNode(o,n)}).on($.Drag,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(o):this.continueMovingNode(o,n)}).on($.End,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(o):this.finishMovingNode(o,n),this.secondaryButton=!1})),le(r),r.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(A.MouseOver,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed&&I(P.EWResize)}).on(A.MouseOut,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed?(I(P.EWResize),this.currentAction=new X(this,S.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed){const a=this.getPointerLocationRelativeToCanvas(o);n.stretch(b.Left,n.coords[0]-a[0])}}).on($.End,(o,n)=>{if(this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===S.StretchNode){let a=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(a=this.getClosestGridPoint(a)),n.stretch(b.Left,n.coords[0]-a[0]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),r.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(A.MouseOver,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed&&I(P.NSResize)}).on(A.MouseOut,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed?(I(P.NSResize),this.currentAction=new X(this,S.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed){const a=this.getPointerLocationRelativeToCanvas(o);n.stretch(b.Top,n.coords[1]-a[1])}}).on($.End,(o,n)=>{if(this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===S.StretchNode){let a=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(a=this.getClosestGridPoint(a)),n.stretch(b.Top,n.coords[1]-a[1]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),r.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(A.MouseOver,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed&&I(P.EWResize)}).on(A.MouseOut,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed?(I(P.EWResize),this.currentAction=new X(this,S.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed){const a=this.getPointerLocationRelativeToCanvas(o);n.stretch(b.Right,a[0]-(n.coords[0]+n.width))}}).on($.End,(o,n)=>{if(this.canUserPerformAction(S.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===S.StretchNode){let a=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(a=this.getClosestGridPoint(a)),n.stretch(b.Right,a[0]-(n.coords[0]+n.width)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),r.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(A.MouseOver,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed&&I(P.NSResize)}).on(A.MouseOut,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed?(I(P.NSResize),this.currentAction=new X(this,S.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed){const a=this.getPointerLocationRelativeToCanvas(o);n.stretch(b.Bottom,a[1]-(n.coords[1]+n.height))}}).on($.End,(o,n)=>{if(this.canUserPerformAction(S.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===S.StretchNode){let a=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(a=this.getClosestGridPoint(a)),n.stretch(b.Bottom,a[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),ce(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(...t){let e=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=e.exit(),r=e.enter().append("g").attr("id",o=>o.id).attr("class",o=>{var n;return`diagram-section${o.getResizableX()?" resizable-x":""}${o.getResizableY()?" resizable-y":""} ${(n=o.look)==null?void 0:n.lookType}`});t&&t.length>0&&(e=e.filter(o=>t.includes(o.id)));const l=r.merge(e);s.remove(),r.on(A.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(A.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}const a=ut(n);this.userSelection.toggle(a),this.diagramEvent$.next(new G([a],a.selected))}).on(A.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const a=new bt(o,n);if(this.diagramEvent$.next(a),!a.defaultPrevented&&this.canUserPerformAction(S.ContextMenu)){o.preventDefault();const c=ut(n);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(o)}}).on(A.DoubleClick,(o,n)=>{const a=new yt(o,n);this.diagramEvent$.next(a)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(o);else{const a=n==null?void 0:n.node;a?this.startMovingNode(o,a):I(P.NotAllowed)}}).on($.Drag,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else{const a=n==null?void 0:n.node;a?this.continueMovingNode(o,a):I(P.NotAllowed)}}).on($.End,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{const a=n==null?void 0:n.node;a?this.finishMovingNode(o,a):I()}this.secondaryButton=!1})),le(r),r.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(A.MouseOver,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&I(P.EWResize)}).on(A.MouseOut,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(I(P.EWResize),this.currentAction=new X(this,S.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const a=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(b.Left,n.coords[0]-a[0],n.indexXInNode,n.indexYInNode)}}).on($.End,(o,n)=>{if(this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===S.StretchSection&&n.node){let a=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(a=this.getClosestGridPoint(a)),n.node.stretchSections(b.Left,n.coords[0]-a[0],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),r.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(A.MouseOver,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&I(P.NSResize)}).on(A.MouseOut,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(I(P.NSResize),this.currentAction=new X(this,S.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const a=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(b.Top,n.coords[1]-a[1],n.indexXInNode,n.indexYInNode)}}).on($.End,(o,n)=>{if(this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===S.StretchSection&&n.node){let a=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(a=this.getClosestGridPoint(a)),n.node.stretchSections(b.Top,n.coords[1]-a[1],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),r.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(A.MouseOver,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&I(P.EWResize)}).on(A.MouseOut,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(I(P.EWResize),this.currentAction=new X(this,S.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const a=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(b.Right,a[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on($.End,(o,n)=>{if(this.canUserPerformAction(S.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===S.StretchSection&&n.node){let a=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(a=this.getClosestGridPoint(a)),n.node.stretchSections(b.Right,a[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()})),r.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(A.MouseOver,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&I(P.NSResize)}).on(A.MouseOut,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(I(P.NSResize),this.currentAction=new X(this,S.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const a=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(b.Bottom,a[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on($.End,(o,n)=>{if(this.canUserPerformAction(S.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===S.StretchSection&&n.node){let a=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(a=this.getClosestGridPoint(a)),n.node.stretchSections(b.Bottom,a[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),ce(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(...t){let e=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=e.exit(),r=e.enter().append("g").attr("id",o=>o.id).attr("class",o=>`diagram-port ${o.look.lookType}`);t&&t.length>0&&(e=e.filter(o=>t.includes(o.id)));const l=r.merge(e);s.remove(),r.on(A.MouseOver,(o,n)=>{var a,c,h,d,u,p,m,f,g,y,w,k;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((h=(c=(a=this.unfinishedConnection.start)==null?void 0:a.getNode())==null?void 0:c.type)==null?void 0:h.id)||"")&&((d=this.unfinishedConnection.start)!=null&&d.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((p=(u=n.getNode())==null?void 0:u.type)==null?void 0:p.id)||"")&&n.allowsIncoming||this.unfinishedConnection.type.canStartFromType(((f=(m=n.getNode())==null?void 0:m.type)==null?void 0:f.id)||"")&&n.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(((w=(y=(g=this.unfinishedConnection.start)==null?void 0:g.getNode())==null?void 0:y.type)==null?void 0:w.id)||"")&&((k=this.unfinishedConnection.start)!=null&&k.allowsIncoming)||I(P.NoDrop))}).on(A.MouseOut,()=>{this.unfinishedConnection&&I(P.Grabbing)}).on(A.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}const a=ut(n);this.userSelection.toggle(a),this.diagramEvent$.next(new G([a],a.selected))}).on(A.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const a=new bt(o,n);if(this.diagramEvent$.next(a),!a.defaultPrevented&&this.canUserPerformAction(S.ContextMenu)){o.preventDefault();const c=ut(n);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(o)}}).on(A.DoubleClick,(o,n)=>{const a=new yt(o,n);this.diagramEvent$.next(a)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(o):this.canUserPerformAction(S.AddConnection)&&!n.removed?(I(P.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):I(P.NotAllowed)}).on($.Drag,(o,n)=>{var a,c,h,d;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else if(this.canUserPerformAction(S.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const u=[o.x,o.y];(h=this.unfinishedConnectionTracer)==null||h.attr("d",ae(this.unfinishedConnection.look.shape,this.unfinishedConnection.startCoords,u,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.look.thickness,(a=this.unfinishedConnection.startMarkerLook)==null?void 0:a.width,(c=this.unfinishedConnection.endMarkerLook)==null?void 0:c.width));const p=(d=this.unfinishedConnectionTracer)==null?void 0:d.node();if(p){let m=2;const f=p.getTotalLength();f<m&&(m=0);const g=p.getPointAtLength(f-m);this.unfinishedConnection.endCoords=[g.x,g.y]}else this.unfinishedConnection.endCoords=u;if(this.updateConnectionsInView(de),this.model.ports.length>0){const m=this.getPointerLocationRelativeToCanvas(o);let f=Number.POSITIVE_INFINITY,g;for(const y of this.model.ports){const w=y.distanceTo(m);w<f&&(f=w,g=y)}g&&f<_o?this.userHighlight.focusOn(g):this.userHighlight.clear()}}}).on($.End,(o,n)=>{var a;if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{if(this.canUserPerformAction(S.AddConnection)&&!n.removed){(a=this.unfinishedConnectionTracer)==null||a.remove();const c=this.userHighlight.getFocus();if(c instanceof xt)this.finishConnection(c);else if(c instanceof mt&&c.rootElement instanceof xt)this.finishConnection(c.rootElement);else if(c instanceof j||c instanceof B||c instanceof mt){let h;if(c instanceof j||c instanceof B)h=c;else if(c.rootElement instanceof j||c.rootElement instanceof B)h=c.rootElement;else{this.dropConnection();return}const d=h.getClosestPortToPoint([o.x,o.y]);d!==void 0?this.finishConnection(d):this.dropConnection()}else this.dropConnection()}I()}this.secondaryButton=!1})),r.filter(".image-look").append("image"),le(r),l.attr("transform",o=>`translate(${o.coords[0]-o.width/2},${o.coords[1]-o.width/2})`).attr("opacity",o=>o.removed?.5:1),ce(l)}updateConnectionsInView(...t){const e=this.model.connections.filter(n=>this.priorityThreshold!==void 0?n.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let s=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,n=>n.id);const r=s.exit(),l=s.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");t&&t.length>0&&(s=s.filter(n=>t.includes(n.id)));const o=l.merge(s);r.remove(),l.on(A.MouseOver,(n,a)=>{a.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(a),this.diagramEvent$.next(new it(a)))}).on(A.Click,(n,a)=>{if(!n.ctrlKey&&!n.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}this.userSelection.toggle(a),this.diagramEvent$.next(new G([a],a.selected))}).on(A.ContextMenu,(n,a)=>{if(this.dragging){n.preventDefault(),n.stopPropagation(),this.dragging=!1;return}const c=new bt(n,a);this.diagramEvent$.next(c),!c.defaultPrevented&&this.canUserPerformAction(S.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(a),this.diagramEvent$.next(new it(a)),this.userSelection.add(a),this.diagramEvent$.next(new G([a],!0)),this.contextMenu.open(n))}).on(A.DoubleClick,(n,a)=>{const c=new yt(n,a);this.diagramEvent$.next(c)}).call(N.drag().filter(n=>(this.secondaryButton=kt(n),!0)).on($.Start,n=>{this.startMultipleSelection(n)}).on($.Drag,n=>{this.continueMultipleSelection(n)}).on($.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 a,c;return ae(n.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness,(a=n.startMarkerLook)==null?void 0:a.width,(c=n.endMarkerLook)==null?void 0:c.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=>Qe(n.look.style,n.look.thickness)).attr("fill","none"),o.select("path.diagram-connection-path-box").attr("d",n=>{var a,c;return ae(n.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness,(a=n.startMarkerLook)==null?void 0:a.width,(c=n.endMarkerLook)==null?void 0:c.width)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",n=>`${n.look.thickness+Ro}px`).attr("stroke-dasharray",n=>Qe(n.look.style,n.look.thickness)).attr("fill","none"),o.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...t){let e=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=e.exit(),r=e.enter().append("foreignObject").attr("id",o=>o.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(o=>t.includes(o.id)));const l=r.merge(e);s.remove(),r.style("box-sizing","border-box").on(A.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(A.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}const a=ut(n);this.userSelection.toggle(a),this.diagramEvent$.next(new G([a],a.selected))}).on(A.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const a=new bt(o,n);if(this.diagramEvent$.next(a),!a.defaultPrevented&&this.canUserPerformAction(S.ContextMenu)){o.preventDefault();const c=ut(n);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(o)}}).on(A.DoubleClick,(o,n)=>{const a=new yt(o,n);this.diagramEvent$.next(a),!a.defaultPrevented&&this.canUserPerformAction(S.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||O.fontFamily,n.orientation,c=>{},c=>{n.text=c,this.currentAction instanceof ri&&(this.currentAction.to=c,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(o);else{let a;n.rootElement instanceof j?a=n.rootElement:n.rootElement instanceof B&&(a=n.rootElement.node),a?this.startMovingNode(o,a):I(P.NotAllowed)}}).on($.Drag,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else{let a;n.rootElement instanceof j?a=n.rootElement:n.rootElement instanceof B&&(a=n.rootElement.node),a?this.continueMovingNode(o,a):I(P.NotAllowed)}}).on($.End,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{let a;n.rootElement instanceof j?a=n.rootElement:n.rootElement instanceof B&&(a=n.rootElement.node),a?this.finishMovingNode(o,a):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===Mt.Center?"center":o.horizontalAlign===Mt.Right?"flex-end":"flex-start").style("align-items",o=>o.verticalAlign===Yt.Center?"center":o.verticalAlign===Yt.Bottom?"end":"start").select("p").style("max-width",o=>o.fit?"default":`${li(o.width,o.height,o.orientation)[0]}px`).style("max-height",o=>o.fit?"default":`${li(o.width,o.height,o.orientation)[1]}px`).style("overflow",o=>o.fit?"default":"clip").style("text-overflow",o=>o.fit?"default":"ellipsis").style("text-align",o=>o.horizontalAlign===Mt.Center?"center":o.horizontalAlign===Mt.Right?"end":"start").style("transform",o=>`rotate(${o.orientation}deg)`).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(...t){let e=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=e.exit(),r=e.enter().append("foreignObject").attr("id",o=>o.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(o=>t.includes(o.id))),r.merge(e).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(),r.on(A.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const a=new bt(o,n);this.diagramEvent$.next(a),!a.defaultPrevented&&this.canUserPerformAction(S.ContextMenu)&&(o.preventDefault(),this.contextMenu.open(o))}).on(A.DoubleClick,(o,n)=>{const a=new yt(o,n);this.diagramEvent$.next(a)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,o=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(o)}).on($.Drag,o=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(o)}).on($.End,o=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(o)}))}updateDecoratorsInView(...t){let e=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=e.exit(),r=e.enter().append("foreignObject").attr("id",o=>o.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(o=>t.includes(o.id))),r.merge(e).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(),r.on(A.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(A.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const a=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(a,!1))}if(n.rootElement){const a=ut(n.rootElement);this.userSelection.toggle(a),this.diagramEvent$.next(new G([a],a.selected))}}).on(A.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const a=new bt(o,n);if(this.diagramEvent$.next(a),!a.defaultPrevented&&this.canUserPerformAction(S.ContextMenu)&&n.rootElement){o.preventDefault();const c=ut(n.rootElement);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(o)}}).on(A.DoubleClick,(o,n)=>{const a=new yt(o,n);this.diagramEvent$.next(a)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(o);else{let a;n.rootElement instanceof j?a=n.rootElement:n.rootElement instanceof B&&(a=n.rootElement.node),a?this.startMovingNode(o,a):I(P.NotAllowed)}}).on($.Drag,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else{let a;n.rootElement instanceof j?a=n.rootElement:n.rootElement instanceof B&&(a=n.rootElement.node),a?this.continueMovingNode(o,a):I(P.NotAllowed)}}).on($.End,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{let a;n.rootElement instanceof j?a=n.rootElement:n.rootElement instanceof B&&(a=n.rootElement.node),a?this.finishMovingNode(o,a):I()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){var o,n,a;const e=this.selectCanvasView().select(`[id='${ge(t.id)}']`),r=e.select("path").node(),l={...O,...t.type.label};if(r){const c=r.getTotalLength();e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.startLabel);const h=(o=e.select("g.diagram-connection-start-label text").node())==null?void 0:o.getBoundingClientRect();if(h){const p=t.startLabel?h.width/this.zoomTransform.k+jt(l)+Ot(l):0,m=t.startLabel?h.height/this.zoomTransform.k+Dt(l)+_t(l):0,f=r.getPointAtLength(Math.max(Z(l)+p/2,at(l)+p/2,U(l)+m/2,ot(l)+m/2));e.select("g.diagram-connection-start-label path").attr("d",Ut(-p/2,-m/2,p,m)).attr("fill",t.look.color).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${f.x},${f.y})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.middleLabel);const d=(n=e.select("g.diagram-connection-middle-label text").node())==null?void 0:n.getBoundingClientRect();if(d){const p=t.middleLabel?d.width/this.zoomTransform.k+jt(l)+Ot(l):0,m=t.middleLabel?d.height/this.zoomTransform.k+Dt(l)+_t(l):0,f=r.getPointAtLength(c/2);e.select("g.diagram-connection-middle-label path").attr("d",Ut(-p/2,-m/2,p,m)).attr("fill",t.look.color).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${f.x},${f.y})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.endLabel);const u=(a=e.select("g.diagram-connection-end-label text").node())==null?void 0:a.getBoundingClientRect();if(u){const p=t.endLabel?u.width/this.zoomTransform.k+jt(l)+Ot(l):0,m=t.endLabel?u.height/this.zoomTransform.k+Dt(l)+_t(l):0,f=r.getPointAtLength(c-Math.max(Z(l)+p/2,at(l)+p/2,U(l)+m/2,ot(l)+m/2));e.select("g.diagram-connection-end-label path").attr("d",Ut(-p/2,-m/2,p,m)).attr("fill",t.look.color).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${f.x},${f.y})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${ge(t.id)}']`),s=e.select("marker.diagram-connection-start-marker"),r=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?s.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.width).attr("markerHeight",t.startMarkerLook.height).attr("refX",t.startMarkerLook.refX).attr("refY",t.startMarkerLook.refY).select("image").attr("href",t.startMarkerLook.image).attr("width",t.startMarkerLook.width).attr("height",t.startMarkerLook.height):s.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?r.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.width).attr("markerHeight",t.endMarkerLook.height).attr("refX",t.endMarkerLook.refX).attr("refY",t.endMarkerLook.refY).select("image").attr("href",t.endMarkerLook.image).attr("width",t.endMarkerLook.width).attr("height",t.endMarkerLook.height):r.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){var s,r,l,o;const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof j||e.rootElement instanceof B){const n=this.minimumSizeOfField(e),a=n[0]+Z((s=e.rootElement.type)==null?void 0:s.label)+at((r=e.rootElement.type)==null?void 0:r.label)-e.rootElement.width,c=n[1]+U((l=e.rootElement.type)==null?void 0:l.label)+ot((o=e.rootElement.type)==null?void 0:o.label)-e.rootElement.height;return a<=0&&c<=0}return!0}fitFieldRootInView(t,e=!0){var r,l,o;const s=this.model.fields.get(t);if(s){if(s.rootElement instanceof j){const n=this.minimumSizeOfField(s);let a=n[0]+Z(s.rootElement.type.label)+at(s.rootElement.type.label)-s.rootElement.width,c=n[1]+U(s.rootElement.type.label)+ot(s.rootElement.type.label)-s.rootElement.height;this.snapToGrid&&(a=Math.ceil(a/this.gridSize)*this.gridSize,c=Math.ceil(c/this.gridSize)*this.gridSize),s.rootElement.width+a<s.rootElement.type.minWidth&&(a=s.rootElement.type.minWidth-s.rootElement.width),s.rootElement.height+c<s.rootElement.type.minHeight&&(c=s.rootElement.type.minHeight-s.rootElement.height),(e!==!1||a>0)&&s.rootElement.stretch(b.Right,a),(e!==!1||c>0)&&s.rootElement.stretch(b.Bottom,c)}if(s.rootElement instanceof B){const n=this.minimumSizeOfField(s);let a=n[0],c=n[1];for(const p of((r=s.rootElement.node)==null?void 0:r.sections)||[])p.label&&(p.indexXInNode===s.rootElement.indexXInNode&&p.indexYInNode!==s.rootElement.indexYInNode?a=Math.max(a,this.minimumSizeOfField(p.label)[0]):p.indexXInNode!==s.rootElement.indexXInNode&&p.indexYInNode===s.rootElement.indexYInNode&&(c=Math.max(c,this.minimumSizeOfField(p.label)[1])));n[0]<a&&(n[0]=a),n[1]<c&&(n[1]=c);const h=s.rootElement.type;let d=n[0]+Z(h==null?void 0:h.label)+at(h==null?void 0:h.label)-s.rootElement.width,u=n[1]+U(h==null?void 0:h.label)+ot(h==null?void 0:h.label)-s.rootElement.height;this.snapToGrid&&(d=Math.ceil(d/this.gridSize)*this.gridSize,u=Math.ceil(u/this.gridSize)*this.gridSize),s.rootElement.width+d<(s.rootElement.getMinWidth()||0)&&(d=(s.rootElement.getMinWidth()||0)-s.rootElement.width),s.rootElement.height+u<(s.rootElement.getMinHeight()||0)&&(u=(s.rootElement.getMinHeight()||0)-s.rootElement.height),(e||d>0)&&((l=s.rootElement.node)==null||l.stretchSections(b.Right,d,s.rootElement.indexXInNode,s.rootElement.indexYInNode)),(e||u>0)&&((o=s.rootElement.node)==null||o.stretchSections(b.Bottom,u,s.rootElement.indexXInNode,s.rootElement.indexYInNode))}}}fitNodeInView(t,e=!0){var r,l;const s=this.model.nodes.get(t);if(s&&s.sections.length>0&&this.priorityThreshold){let o=0,n=0;for(const a of s.sections)if(a.getPriority()>=this.priorityThreshold){const c=a.coords[0]+a.width-s.coords[0],h=a.coords[1]+a.height-s.coords[1];o=Math.max(o,c),n=Math.max(n,h)}o+=((r=s.type.sectionGrid)==null?void 0:r.margin)||0,n+=((l=s.type.sectionGrid)==null?void 0:l.margin)||0,(e||o>s.width)&&s.stretch(b.Right,o-s.width),(e||n>s.height)&&s.stretch(b.Bottom,n-s.height)}}selectRoot(){return N.select(this.diagramRoot)}selectSVGElement(){return N.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){var e,s,r,l;if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(((s=(e=t.getNode())==null?void 0:e.type)==null?void 0:s.id)||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(((l=(r=t.getNode())==null?void 0:r.type)==null?void 0:l.id)||"")&&t.allowsIncoming))this.unfinishedConnection=new dt(this.model,this.connectionType,t,void 0,de);else if(this.inferConnectionType){let o=this.model.connections.types.all().find(n=>{var a,c;return t.allowsOutgoing&&n.canStartFromType(((c=(a=t.getNode())==null?void 0:a.type)==null?void 0:c.id)||"")});o===void 0&&(o=this.model.connections.types.all().find(n=>{var a,c;return t.allowsIncoming&&n.canFinishOnType(((c=(a=t.getNode())==null?void 0:a.type)==null?void 0:c.id)||"")})),o!==void 0&&(this.unfinishedConnection=new dt(this.model,o,t,void 0,de))}}}finishConnection(t){var e,s,r,l,o,n,a,c,h,d,u,p,m,f,g,y,w,k,E,C;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0)if(this.unfinishedConnection.start!==t)if(this.unfinishedConnection.type.canStartFromType(((l=(r=(s=(e=this.unfinishedConnection)==null?void 0:e.start)==null?void 0:s.getNode())==null?void 0:r.type)==null?void 0:l.id)||"")&&((n=(o=this.unfinishedConnection)==null?void 0:o.start)!=null&&n.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((c=(a=t.getNode())==null?void 0:a.type)==null?void 0:c.id)||"")&&t.allowsIncoming){const T=new re(this,this.unfinishedConnection.type,(h=this.unfinishedConnection.start)==null?void 0:h.id,t.id);this.dropConnection(),T.do(),this.actionStack.add(T)}else if(this.unfinishedConnection.type.canFinishOnType(((m=(p=(u=(d=this.unfinishedConnection)==null?void 0:d.start)==null?void 0:u.getNode())==null?void 0:p.type)==null?void 0:m.id)||"")&&((g=(f=this.unfinishedConnection)==null?void 0:f.start)!=null&&g.allowsIncoming)&&this.unfinishedConnection.type.canStartFromType(((w=(y=t.getNode())==null?void 0:y.type)==null?void 0:w.id)||"")&&t.allowsOutgoing){const T=new re(this,this.unfinishedConnection.type,t.id,(k=this.unfinishedConnection.start)==null?void 0:k.id);this.dropConnection(),T.do(),this.actionStack.add(T)}else if(this.inferConnectionType){let T=this.model.connections.types.all().find(x=>{var R,L,V,K,D,J,F,Q;return x.canStartFromType(((K=(V=(L=(R=this.unfinishedConnection)==null?void 0:R.start)==null?void 0:L.getNode())==null?void 0:V.type)==null?void 0:K.id)||"")&&((J=(D=this.unfinishedConnection)==null?void 0:D.start)==null?void 0:J.allowsOutgoing)&&x.canFinishOnType(((Q=(F=t.getNode())==null?void 0:F.type)==null?void 0:Q.id)||"")&&t.allowsIncoming}),M=!1;if(T===void 0&&(T=this.model.connections.types.all().find(x=>{var R,L,V,K,D,J,F,Q;return x.canFinishOnType(((K=(V=(L=(R=this.unfinishedConnection)==null?void 0:R.start)==null?void 0:L.getNode())==null?void 0:V.type)==null?void 0:K.id)||"")&&((J=(D=this.unfinishedConnection)==null?void 0:D.start)==null?void 0:J.allowsIncoming)&&x.canStartFromType(((Q=(F=t.getNode())==null?void 0:F.type)==null?void 0:Q.id)||"")&&t.allowsOutgoing}),M=!0),T!==void 0){const x=new re(this,T,M?t.id:(E=this.unfinishedConnection.start)==null?void 0:E.id,M?(C=this.unfinishedConnection.start)==null?void 0:C.id:t.id);this.dropConnection(),x.do(),this.actionStack.add(x)}else this.dropConnection()}else this.dropConnection();else this.dropConnection()}dropConnection(){var t,e,s,r;(t=this.unfinishedConnection)==null||t.setStart(void 0),(e=this.unfinishedConnection)==null||e.setEnd(void 0),(r=(s=this.unfinishedConnection)==null?void 0:s.select())==null||r.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(t){return this.userActions[t]!==!1}createInputField(t,e,s,r,l,o,n,a,c){this.removeInputField();const h=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${s}px`).attr("height",`${r}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=h;const d=h.append("xhtml:textarea");let u,p;d.text(t).style("box-sizing","border-box").style("width",`${s}px`).style("height",`${r}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(A.KeyDown,f=>{f.stopPropagation()}).on(A.KeyUp,f=>{if(f.stopPropagation(),f.key===tt.Escape){const g=d.property("value");this.removeInputField(),c&&c(g)}}).on(A.Input,()=>{const f=d.property("value");d.attr("cols",Yi(f)+1),d.attr("rows",Xi(f)+1),d.style("width",""),d.style("height",""),u=d.property("scrollWidth")+1,p=d.property("scrollHeight")+1;const g=Math.max(u,s),y=Math.max(p,r);h==null||h.attr("width",`${g}px`),d.style("width",`${g}px`),h==null||h.attr("height",`${y}px`),d.style("height",`${y}px`),a&&a(f)}).on(A.Click,f=>{f.stopPropagation()}).on(A.FocusOut,()=>{const f=d.property("value");this.removeInputField(),c&&c(f)});const m=d.node();m.focus(),m.select()}removeInputField(){var t,e,s;(e=(t=this.inputFieldContainer)==null?void 0:t.select("input"))==null||e.on(A.Blur,null),(s=this.inputFieldContainer)==null||s.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){var r,l;const e=(l=(r=t.select())==null?void 0:r.select("p"))==null?void 0:l.node();if(!e)return[0,0];const s=e.getBoundingClientRect();return[s.width/this.zoomTransform.k,s.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(S.MoveNode)&&!e.removed)if(I(P.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(s=>s instanceof j)>1)this.currentAction=new ne(this,this.userSelection.filter(s=>s instanceof j).map(s=>s.id),e.coords);else{const s=e.getLastAncestor();this.currentAction=new X(this,S.MoveNode,e.id,e.getGeometry(),e.getGeometry(),s==null?void 0:s.id,s==null?void 0:s.getGeometry(e.id),s==null?void 0:s.getGeometry(e.id))}else I(P.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(S.MoveNode)&&(this.currentAction instanceof ne||this.currentAction instanceof X)&&!e.removed){const s=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([s[0]-e.coords[0],s[1]-e.coords[1]]):e.move(s),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){var s,r,l;if(this.canUserPerformAction(S.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let o=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(o=this.getClosestGridPoint(o)),this.currentAction instanceof ne){const n=this.currentAction.delta;this.currentAction.delta=[o[0]-n[0],o[1]-n[1]],e.selected?this.userSelection.move([n[0]-e.coords[0],n[1]-e.coords[1]]):e.move(n)}else if(this.currentAction instanceof X){e.move(o);const a=this.model.nodes.getAtCoordinates(t.x,t.y).filter(d=>d.id!==e.id&&!d.isDescendantOf(e)).filter(d=>d.type.childrenTypes.includes(e.type.id)),c=bi(a),h=c[c.length-1];if(h!==e.parent&&(e.type.canBeParentless||h!==void 0)){const d=h==null?void 0:h.getLastAncestor(),u=this.currentAction.from,p=new bo(this,e.id,(s=e.parent)==null?void 0:s.id,h==null?void 0:h.id,u,e.getGeometry(),d==null?void 0:d.id,d==null?void 0:d.getGeometry(e.id),d==null?void 0:d.getGeometry(e.id));(r=e.parent)==null||r.removeChild(e),h!==void 0&&h.addChild(e),p.toChildGeometry=e.getGeometry(e.id),p.toAncestorGeometry=d==null?void 0:d.getGeometry(e.id),this.currentAction=p}else{const d=e==null?void 0:e.getLastAncestor();this.currentAction.ancestorId=d==null?void 0:d.id,this.currentAction.fromAncestorGeometry=d==null?void 0:d.getGeometry(e.id),(l=e.parent)==null||l.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=d==null?void 0:d.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}I(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectSVGElement().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){var s,r,l,o;const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(I(P.Crosshair),(o=(l=(r=(s=this.multipleSelectionContainer)==null?void 0:s.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x))==null?void 0:r.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y))==null?void 0:l.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k))==null||o.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){var s;const e=this.getPointerLocationRelativeToCanvas(t);(s=this.multipleSelectionContainer)==null||s.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const r of this.model.nodes)Vi([r.coords,[r.coords[0]+r.width,r.coords[1]+r.height]],[this.draggingFrom,e])&&this.userSelection.add(r);this.multipleSelectionOn=!1,this.diagramEvent$.next(new G(this.userSelection.all(),!0)),I()}};Wt.canvasCount=0;let fe=Wt;class Ei{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const t of this.grid)t.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const t of this.grid)t.push(void 0)}addRowTop(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.splice(0,0,t),this.offsetY=this.offsetY+1}addRowBottom(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.push(t)}get(t){if(this.grid[t[1]+this.offsetY])return this.grid[t[1]+this.offsetY][t[0]+this.offsetX]}set(t,e){for(;t[0]<-this.offsetX;)this.addColumnLeft();for(;t[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;t[1]<-this.offsetY;)this.addRowTop();for(;t[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[t[1]+this.offsetY][t[0]+this.offsetX]=e}getClosestEmptyCoordinate(t){if(this.get(t)===void 0)return t;const e=[...t];for(let s=1;;++s){const r=s%2>0?s:-s,l=r>0?1:-1,o=[e[0]+r,e[1]+r];for(let n=e[0];n!==o[0]+l;n+=l)if(e[0]=n,this.get(e)===void 0)return e;for(let n=e[1];n!==o[1]+l;n+=l)if(e[1]=n,this.get(e)===void 0)return e}}}class jo{constructor(t){this.gapSize=t}apply(t){var n;if(t.nodes.length===0)return t;const e=new Ei,s=t.nodes.filter(a=>!a.parent);for(;s.length>0;)Ti(s[0],e,[0,0],s);const r=Math.max(...t.nodes.map(a=>a.width)),l=Math.max(...t.nodes.map(a=>a.height)),o=this.gapSize!==void 0?this.gapSize:(((n=t.canvas)==null?void 0:n.gridSize)||0)*2;for(let a=e.minY();a<=e.maxY();++a)for(let c=e.minX();c<=e.maxX();++c){const h=e.get([c,a]);h!==void 0&&h.move([c*(r+o),a*(l+o)])}return t}}const Ti=(i,t,e,s)=>{const r=t.getClosestEmptyCoordinate(e);t.set(r,i),Y(s,i);for(const l of i.getAdjacentNodes())s.includes(l)&&Ti(l,t,r,s)};class Oo{constructor(t){this.gapSize=t}apply(t){var h;if(t.nodes.length===0)return t;const e=new Ei,s=t.nodes.filter(d=>!d.parent),r={},l=s[0];let o=[l];for(r[l.id]=[0,0];s.length>0;){const d=[];for(const u of o){e.set(e.getClosestEmptyCoordinate(r[u.id]),u),Y(s,u);const p=u.getAdjacentNodes();for(const m of p)s.includes(m)&&(d.push(m),r[m.id]=r[u.id])}if(d.length>0)o=d;else if(s.length>0){const u=s[0];o=[u],r[u.id]=e.getClosestEmptyCoordinate([0,0])}}const n=Math.max(...t.nodes.map(d=>d.width)),a=Math.max(...t.nodes.map(d=>d.height)),c=this.gapSize!==void 0?this.gapSize:(((h=t.canvas)==null?void 0:h.gridSize)||0)*2;for(let d=e.minY();d<=e.maxY();++d)for(let u=e.minX();u<=e.maxX();++u){const p=e.get([u,d]);p!==void 0&&p.move([u*(n+c),d*(a+c)])}return t}}class ie{constructor(t){this.gapSize=t}apply(t){var n;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((n=t.canvas)==null?void 0:n.gridSize)||0)*2;let s=t.nodes.filter(a=>!a.parent);const r=s[0];Y(s,r);const l=[[r]];for(;s.length>0;){const a=l[l.length-1],c=[];for(const h of a){const d=h.getAdjacentNodes();for(const u of d)s.includes(u)&&(Y(s,u),c.push(u))}c.length>0?l.push(c):(l.push(s),s=[])}let o=0;for(const a of l){let c=0;for(const d of a)d.move([o,c]),c+=e+d.height;const h=Math.max(...a.map(d=>d.width));o+=e+h}for(const a of t.connections)a.tighten();return t}}class Do{constructor(t){this.gapSize=t}apply(t){var d;if(t.nodes.length===0)return t;new ie(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(((d=t.canvas)==null?void 0:d.gridSize)||0)*2,s=.99,r=1,l=.1,o=2e5,n=.5,a=1,c=.002;let h=100;for(;h>r;){h=h*s;const u=[0,0];{for(const p of t.nodes)u[0]=u[0]+p.coords[0]+p.width/2,u[1]=u[1]+p.coords[1]+p.width/2;u[0]=u[0]/t.nodes.length,u[1]=u[1]/t.nodes.length}for(const p of t.nodes){const m=p.getAdjacentNodes();for(const f of t.nodes){const g=[p.coords[0]+p.width/2,p.coords[1]+p.height/2],y=[f.coords[0]+f.width/2,f.coords[1]+f.height/2],w=hi(p.coords,f.coords),k=[f.coords[0],f.coords[1]];if(m.includes(f)&&w>0&&(w>e+(Math.max(p.width,p.height)+Math.max(f.width,f.height))/2?(k[0]=k[0]-(y[0]-g[0])*l,k[1]=k[1]-(y[1]-g[1])*l):(k[0]=k[0]+(y[0]-g[0])*n,k[1]=k[1]+(y[1]-g[1])*n)),w>0){const E=o/(w*w);k[0]=k[0]+E*(y[0]-g[0])/w,k[1]=k[1]+E*(y[1]-g[1])/w}else k[0]=k[0]+a*(Math.random()*2-1),k[1]=k[1]+a*(Math.random()*2-1);k[0]=k[0]-(y[0]-u[0])*c,k[1]=k[1]-(y[1]-u[1])*c,k[0]-f.coords[0]>h?k[0]=f.coords[0]+h:k[0]-f.coords[0]<-h&&(k[0]=f.coords[0]-h),k[1]-f.coords[1]>h?k[1]=f.coords[1]+h:k[1]-f.coords[1]<-h&&(k[1]=f.coords[1]-h),f.move(k)}}}if(t.canvas&&t.canvas.snapToGrid)for(const u of t.nodes){const p=t.canvas.getClosestGridPoint(u.coords);u.move(p)}for(const u of t.connections)u.tighten();return t}}class Ho{constructor(t){this.gapSize=t}apply(t){var l;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,s=t.nodes.filter(o=>!o.parent);s.sort((o,n)=>n.type.priority-o.type.priority);let r=0;for(const o of s)o.move([r,0]),r+=o.width+e;return t}}class Go{constructor(t){this.gapSize=t}apply(t){var h;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),s=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===s)return new ie(this.gapSize).apply(t),t;const r=this.gapSize!==void 0?this.gapSize:(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,l=t.nodes.filter(d=>!d.parent),o=[],n=t.nodes.filter(d=>!d.parent).filter(d=>d.getPriority()>=e),a=[];if(n.length>1){const d=n[0];n.splice(0,1),a.push(d);const u=[d],p=[d];for(;u.length>0;){const m=u[0];u.splice(0,1),n.includes(m)&&(a.push(m),Y(n,m));const f=m.getAdjacentNodes();for(const g of f)p.includes(g)||(u.push(g),p.push(g))}for(const m of n)a.push(m)}else a.push(n[0]);for(const d of a)Y(l,d),o.push([d]);for(o.push([]),l.sort((d,u)=>u.type.priority-d.type.priority);l.length>0;){const d=l[0];l.splice(0,1);const u=[d],p=[d];let m=!1;for(;u.length>0;){const f=u[0];u.splice(0,1);const g=a.indexOf(f);if(g>=0){o[g].push(d),m=!0;break}else{const y=f.getAdjacentNodes();for(const w of y)p.includes(w)||(u.push(w),p.push(w))}}m||o[o.length-1].push(d)}let c=0;for(let d=0;d<o.length;++d){let u=0;for(let m=0;m<o[d].length;++m){const f=o[d][m];f.move([c,u]),u+=r+f.height}const p=Math.max(...o[d].map(m=>m.width));c+=r+p}for(const d of t.connections)d.tighten();return t}}class Fo{constructor(t){this.gapSize=t}apply(t){var h;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),s=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===s)return new ie(this.gapSize).apply(t),t;const r=this.gapSize!==void 0?this.gapSize:(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,l=t.nodes.filter(d=>!d.parent).sort((d,u)=>u.getPriority()-d.getPriority()),o=[];for(;l.length>0;){const d=l[0];l.splice(0,1);const u=new ye(void 0,d);Li(u,l),o.push(u)}const n=[];for(const d of o)n.push([d]),$i(d,n,n.length);const a=Math.max(...t.nodes.map(d=>d.height));let c=0;for(let d=0;d<n.length;++d){let u=0;for(let m=0;m<n[d].length;++m){const f=n[d][m];f.node.move([c,u]),u+=(r+a)*f.countBranchHeight()}const p=Math.max(...n[d].map(m=>m.node.width));c+=r+p}for(const d of t.connections)d.tighten();return t}}const Li=(i,t)=>{for(const e of i.node.getAdjacentNodes().sort((s,r)=>r.getPriority()-s.getPriority())){const s=t.indexOf(e);if(s>=0){t.splice(s,1);const r=i.addBranch(e);Li(r,t)}}},$i=(i,t,e)=>{if(i.branches.length>0){for(;e>=t.length;)t.push([]);for(const s of i.branches)t[e].push(s),$i(s,t,e+1)}};class ye{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new ye(this,t);return e.depth=this.depth+1,this.branches.push(e),e}countBranchHeight(){if(this.branches.length<=0)return 1;{let t=0;for(const e of this.branches)t+=e.countBranchHeight();return t}}}class Bo{constructor(t){this.gapSize=t}apply(t){var l;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,s=t.nodes.filter(o=>!o.parent);s.sort((o,n)=>n.type.priority-o.type.priority);let r=0;for(const o of s)o.move([0,r]),r+=o.height+e;return t}}const ci={adjacency:new jo,breadth:new ie,"breadth-adjacency":new Oo,force:new Do,horizontal:new Ho,priority:new Go,tree:new Fo,vertical:new Bo},Uo=z.createContext({}),Et=z.createContext({});class Yo{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){}}const be=({direction:i,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:s,disabled:r,rule:l,collapsedValue:o,visibleValue:n,onCollapse:a})=>{const[c,h]=z.useState(s),d=()=>{if(!r){const p=!c;h(p),a==null||a(p);let m;if(typeof t=="string")m=N.select(t),e&&(m=m.select(e));else{const f=t;if(!f)throw new Error("collapsableSelector is not a valid ref");m=N.select(f.current),e&&(m=m.select(e))}m.style(l,p?o:n)}},u=()=>{switch(i){case b.Right:return r?"daga-horizontal-none":c?"daga-horizontal-right":"daga-horizontal-left";case b.Bottom:return r?"daga-vertical-none":c?"daga-vertical-down":"daga-vertical-up";case b.Left:return r?"daga-horizontal-none":c?"daga-horizontal-left":"daga-horizontal-right";case b.Top:return r?"daga-vertical-none":c?"daga-vertical-up":"daga-vertical-down"}};return v.jsx("daga-collapse-button",{children:v.jsx("button",{className:`daga-collapse-button daga-${i}`,onClick:d,children:v.jsx("div",{className:u()})})})},Xo=()=>{const i=z.useContext(Et),t=z.useRef(null),[e,s]=z.useState([]);It.merge(i.validatorChange$,i.diagramChange$).pipe(It.map(()=>r())).subscribe();const r=()=>{s([]);for(const o of i.validators){const n=o.validate(i.model);s(n)}},l=o=>{var n,a,c,h;if(o.elementId&&(o.propertyNames===void 0||o.propertyNames.length===0)){const d=i.model.nodes.get(o.elementId)||i.model.connections.get(o.elementId);d&&i.userHighlight.add(d)}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 d=i.model.nodes.get(o.elementId)||i.model.connections.get(o.elementId);d&&i.userHighlight.add(d),(a=(n=i.parentComponent)==null?void 0:n.propertyEditor)==null||a.highlightProperty(...o.propertyNames)}else!o.elementId&&o.propertyNames!==void 0&&o.propertyNames.length>0&&(i.userSelection.openInPropertyEditor(),(h=(c=i.parentComponent)==null?void 0:c.propertyEditor)==null||h.highlightProperty(...o.propertyNames))};return v.jsx("daga-errors",{children:v.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&v.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:v.jsx("span",{children:"No errors found"})}),e.length>0&&v.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[v.jsxs("span",{children:[e.length," errors found"]}),v.jsx("div",{className:"daga-collapse-button-container",children:v.jsx(be,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:b.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&v.jsx("div",{className:"daga-error-panel",children:v.jsx("ol",{children:e.map((o,n)=>v.jsx("li",{onClick:()=>l(o),dangerouslySetInnerHTML:{__html:o.message}},n))})})]})})},Wo=200,di=i=>(i||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),Mi=({disabled:i,options:t,value:e,onChange:s})=>{const r=z.useRef(null),[l,o]=z.useState("");let n;const[a,c]=z.useState([]),[h,d]=z.useState([]),[u,p]=z.useState([]),[m,f]=z.useState([]),[g,y]=z.useState(!1);z.useEffect(()=>{var L;o(((L=t.find(V=>At(V.key,e)))==null?void 0:L.label)||"")},[e,t]);const w=L=>{if(!i)switch(L.key){case tt.PageDown:n===void 0?(C(0),M(0)):(C(n+5),M(n)),L.preventDefault();break;case tt.ArrowDown:n===void 0?(C(0),M(0)):(C(n+1),M(n)),L.preventDefault();break;case tt.PageUp:n===void 0?(C(t.length-1),M(t.length-1)):(C(n-5),M(n)),L.preventDefault();break;case tt.ArrowUp:n===void 0?(C(t.length-1),M(t.length-1)):(C(n-1),M(n)),L.preventDefault();break;case tt.Escape:E(),L.preventDefault();break;case tt.Enter:R(t[n||0]),L.preventDefault();break;default:k()}},k=()=>{if(!i){const L=di(l.trim());c([]),d([]),p([]),f([]);for(const V of t){const D=di(V.label).indexOf(L);if(D>=0){const J=V.label.substring(0,D),F=V.label.substring(D,D+L.length),Q=V.label.substring(D+L.length);c(et=>[...et,V]),d(et=>[...et,J]),p(et=>[...et,F]),f(et=>[...et,Q])}}y(!0)}},E=()=>{y(!1)},C=L=>{if(!i){if(n=L,L===void 0)return;L<0&&(n=0),L>=t.length&&(n=t.length-1)}},T=()=>{setTimeout(()=>{E()},Wo)},M=L=>{var K;const V=(K=r.current)==null?void 0:K.querySelectorAll("li")[L];V&&V.scrollIntoView({block:"center"})},x=()=>{i||(o(""),y(!1),n=void 0)},R=L=>{i||(o(L.label),y(!1),n=void 0,s(L.key))};return v.jsxs("div",{ref:r,className:`daga-autocomplete ${g?"daga-showing-options":""}`,children:[v.jsxs("div",{className:"daga-autocomplete-input",children:[v.jsx("input",{value:l,disabled:i,onKeyUp:w,onFocus:k,onBlur:T,onChange:L=>o(L.target.value)}),l!==""&&v.jsx("button",{className:"daga-clear",onClick:x})]}),v.jsx("div",{className:"daga-autocomplete-options",children:v.jsxs("ul",{className:"daga-autocomplete-option-list",children:[a.length===0&&v.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),a.map((L,V)=>v.jsxs("li",{className:`daga-autocomplete-option ${V===n?"daga-focused":""}`,onMouseMove:()=>C(V),onClick:()=>R(L),children:[v.jsx("span",{children:h[V]}),v.jsx("span",{className:"daga-match",children:u[V]}),v.jsx("span",{children:m[V]})]},V))]})})]})},Zo=(i,t)=>{var e;return((e=i.find(s=>s.key===t))==null?void 0:e.label)||`${t}`},Ko=({disabled:i,allowRepeats:t,options:e,value:s,onChange:r})=>{const[l,o]=z.useState(),[n,a]=z.useState([]),[c,h]=z.useState([]);z.useEffect(()=>{const g=s.length===0,y=s.map(w=>Zo(e,w));a(y),g&&r(s),f()},[s,e]);const d=g=>{for(const y of s)if(y===g)return!0;return!1},u=g=>{s.length>g&&(s.splice(g,1),a(n.filter((y,w)=>w!==g)),r(s),f())},p=()=>{l!==void 0&&(t||!d(l))&&(r(s.concat(l)),m())},m=()=>{o("")},f=()=>{if(!t){const g=[];for(const y of e)d(y.key)||g.push(y);h(g)}};return v.jsxs("div",{children:[s.map((g,y)=>v.jsxs("div",{className:"daga-value-item-element",children:[v.jsx("span",{className:"daga-input",children:n[y]}),!i&&v.jsx("button",{className:"daga-property-button",onClick:()=>u(y),children:v.jsx("div",{className:"daga-icon daga-close-icon"})})]},y)),!i&&v.jsxs("div",{className:"daga-value-item-input",children:[v.jsx("div",{className:"daga-input daga-relatively-positioned",children:v.jsx(Mi,{disabled:i,options:t?e||[]:c||[],value:l,onChange:o})}),v.jsx("button",{className:"daga-property-button",onClick:p,children:v.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},qo=({disabled:i,allowRepeats:t,value:e,onChange:s})=>{const[r,l]=z.useState(""),o=u=>{for(const p of u||[])if(p===u)return!0;return!1},n=u=>{e.length>u&&s(e.filter((p,m)=>m!==u))},a=(u,p,m)=>{const f=e.map((g,y)=>y===p?m==="blur"?u.trim():u:g);s(f)},c=()=>{const u=r.trim();u!==""&&(t||!o(u))&&(s(e.concat(u)),h())},h=()=>{l("")},d=u=>{u.key==="Enter"&&c()};return v.jsxs(v.Fragment,{children:[e.map((u,p)=>v.jsxs("div",{className:"daga-value-item-element",children:[v.jsx("input",{className:"daga-input",disabled:i,value:u,onChange:m=>a(m.target.value,p,"change"),onBlur:m=>a(m.target.value,p,"blur")}),v.jsx("button",{className:"daga-property-button",onClick:()=>n(p),children:v.jsx("div",{className:"daga-icon daga-close-icon"})})]},p)),!i&&v.jsxs("div",{className:"daga-value-item-input",children:[v.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[v.jsx("input",{type:"text",onKeyUp:d,value:r,onChange:u=>l(u.target.value)}),v.jsx("button",{className:"daga-clear",onClick:h})]}),v.jsx("button",{className:"daga-property-button",onClick:c,children:v.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Jo=({disabled:i,value:t,onChange:e})=>{const[s,r]=z.useState(""),[l,o]=z.useState(""),[n,a]=z.useState({}),c=g=>{const y={};Object.keys(t).forEach(w=>{w!==g&&(y[w]=t[w])}),e(y)},h=(g,y,w)=>{const k=w==="blur"?y.trim():y;if(w==="blur"){if(g!==k){const E={};Object.keys(t).forEach(C=>{C===g?E[k]=t[C]:E[C]=t[C]}),e(E),a(C=>{const T={...C};return delete T[g],T})}}else a(E=>({...E,[g]:y}))},d=(g,y,w)=>{const k=w==="blur"?y.trim():y;if(k!==""){const E={};Object.keys(t).forEach(C=>{C===g?E[C]=k:E[C]=t[C]}),e(E)}},u=()=>{const g=s.trim(),y=l.trim();if(g!==""&&y!==""){const w={};Object.keys(t).forEach(k=>{w[k]=t[k]}),w[g]=y,e(w),r(""),o("")}},p=()=>{r("")},m=()=>{o("")},f=g=>{g.key==="Enter"&&u()};return v.jsxs("div",{children:[Object.entries(t).map(([g,y],w)=>v.jsxs("div",{className:"daga-value-item-element",children:[v.jsx("input",{id:`key-${w}`,className:"daga-input",type:"text",disabled:i,value:n[g]??g,onChange:k=>h(g,k.target.value,"change"),onBlur:k=>h(g,k.target.value,"blur")}),v.jsx("input",{id:`value-${w}`,className:"daga-input",type:"text",disabled:i,value:y,onChange:k=>d(g,k.target.value,"change"),onBlur:k=>d(g,k.target.value,"blur")}),v.jsx("button",{className:"daga-property-button",onClick:()=>c(g),children:v.jsx("div",{className:"daga-icon daga-close-icon"})})]},g)),!i&&v.jsxs("div",{className:"daga-value-item-input",children:[v.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[v.jsx("input",{type:"text",value:s,onKeyUp:f,onChange:g=>r(g.target.value),onBlur:g=>h(s,g.target.value,"blur")}),v.jsx("button",{className:"daga-clear",onClick:p})]}),v.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[v.jsx("input",{type:"text",value:l,onKeyUp:f,onChange:g=>o(g.target.value),onBlur:g=>d(s,g.target.value,"blur")}),v.jsx("button",{className:"daga-clear",onClick:m})]}),v.jsx("button",{className:"daga-property-button",onClick:u,children:v.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Ni=({valueSet:i,onValueChange:t,depth:e})=>{var a;const r=z.useContext(Et).canUserPerformAction(S.UpdateValues)&&((a=i==null?void 0:i.rootElement)==null?void 0:a.removed)!==!0,l=c=>"daga-property-name-"+c.replace(/\s/g,""),o=c=>{if(typeof c=="string")return c;if(c==null||isNaN(c.valueOf()))return"";const h=new Date(c),d=h.getTimezoneOffset();return h.setMinutes(h.getMinutes()-d),h.toISOString().substring(0,19)},n=c=>new Date(c);return v.jsx("daga-object-editor",{children:i.displayedProperties.map(c=>v.jsxs("div",{className:`daga-property ${l(c.name)}`,children:[v.jsx("p",{className:"daga-property-name",children:c.name}),c.type===_.Text&&v.jsx("input",{type:"daga-text",disabled:!c.editable||!r,value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h.target.value)}),c.type===_.TextArea&&v.jsx("textarea",{disabled:!c.editable||!r,value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h.target.value)}),c.type===_.Number&&v.jsx("input",{type:"number",disabled:!c.editable||!r,value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h.target.value)}),c.type===_.Color&&v.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:!c.editable||!r,value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h.target.value)}),c.type===_.Datetime&&v.jsx("input",{type:"datetime-local",disabled:!c.editable||!r,value:o(i==null?void 0:i.getValue(c.name)),onChange:h=>t(i,c,n(h.target.value))}),c.type===_.Date&&v.jsx("input",{type:"date",disabled:!c.editable||!r,value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h.target.value)}),c.type===_.Time&&v.jsx("input",{type:"time",disabled:!c.editable||!r,value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h.target.value)}),c.type===_.Url&&v.jsx("input",{type:"url",disabled:!c.editable||!r,value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h.target.value)}),c.type===_.Boolean&&v.jsxs("div",{className:"daga-radio",children:[v.jsxs("label",{className:"daga-radio-item daga-radio-start"+((i==null?void 0:i.getValue(c.name))===!1?" daga-checked":""),children:[v.jsx("input",{type:"radio",disabled:!c.editable||!r,name:c.name,value:"false",checked:(i==null?void 0:i.getValue(c.name))===!1,onChange:()=>t(i,c,!1)}),"No"]}),v.jsxs("label",{className:"daga-radio-item daga-radio-end"+((i==null?void 0:i.getValue(c.name))===!0?" daga-checked":""),children:[v.jsx("input",{type:"radio",disabled:!c.editable||!r,name:c.name,value:"true",checked:(i==null?void 0:i.getValue(c.name))===!0,onChange:()=>t(i,c,!0)}),"Yes"]})]}),c.type===_.Option&&v.jsx("div",{className:"daga-relatively-positioned",children:v.jsx(Mi,{disabled:!c.editable||!r,options:c.options||[],value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h)})}),(c.type===_.OptionList||c.type===_.OptionSet)&&v.jsx(Ko,{disabled:!c.editable||!r,allowRepeats:c.type===_.OptionList,options:c.options||[],value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h)}),(c.type===_.TextList||c.type===_.TextSet)&&v.jsx(qo,{disabled:!c.editable||!r,allowRepeats:c.type===_.TextList,value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h)}),c.type===_.TextMap&&v.jsx(Jo,{disabled:!c.editable||!r,value:i==null?void 0:i.getValue(c.name),onChange:h=>t(i,c,h)}),c.type===_.Object&&v.jsx("div",{className:"daga-left-bar",children:v.jsx(Ni,{valueSet:i.getSubValueSet(c.name),onValueChange:t,depth:e+1})})]},c.name))})},Pi=({valueSet:i,depth:t})=>{const e=z.useContext(Et),s=z.useRef(null),r=a=>"daga-property-name-"+a.replace(/\s/g,""),l=()=>{for(const a of(i==null?void 0:i.displayedProperties)||[]){let c=0,h=0,d=0;const u=N.select(s.current).select(`.daga-property.${r(a.name)}.daga-depth-${t}`);u.select("button.daga-move-button").call(N.drag().on($.Start,p=>{var g;I(P.Grabbing);const m=e.getPointerLocationRelativeToScreen(p);if(m.length<2||isNaN(m[0])||isNaN(m[1]))return;const f=(g=u.node())==null?void 0:g.getBoundingClientRect();c=(f==null?void 0:f.width)||0,h=(f==null?void 0:f.height)||0,u.style("position","fixed").style("left",`${m[0]-c/2}px`).style("top",`${m[1]-h/2}px`).style("width",`${c}px`).style("height",`${h}px`).style("z-index",1)}).on($.Drag,p=>{I(P.Grabbing);const m=e.getPointerLocationRelativeToScreen(p);m.length<2||isNaN(m[0])||isNaN(m[1])||(u.style("position","fixed").style("left",`${m[0]-c/2}px`).style("top",`${m[1]-h/2}px`).style("width",`${c}px`).style("height",`${h}px`).style("z-index",1),N.select(s.current).select(`.daga-dropbar.daga-index-${d}.daga-depth-${t}`).style("visibility","hidden").style("height",0),d=o(m),N.select(s.current).select(`.daga-dropbar.daga-index-${d}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on($.End,p=>{var f,g;I(P.Auto),u.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),N.select(s.current).select(`.daga-dropbar.daga-index-${d}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const m=e.getPointerLocationRelativeToScreen(p);m.length<2||isNaN(m[0])||isNaN(m[1])||(d=o(m),(f=i==null?void 0:i.displayedProperties)==null||f.splice(i.displayedProperties.indexOf(a),1),(g=i==null?void 0:i.displayedProperties)==null||g.splice(d,0,a))}))}},o=a=>{var d;const c=(i==null?void 0:i.propertySet.propertyList)||[],h=[];for(let u=0;u<=c.length;++u){const p=(d=N.select(s.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).node())==null?void 0:d.getBoundingClientRect();p&&h.push([p.x+p.width/2,p.y+p.height/2])}if(h.length>0){const u=h.map(m=>((a[0]-m[0])**2+(a[1]-m[1])**2)**.5);return u.indexOf(Math.min(...u))}return 0},n=a=>{var h;if(i===void 0)return;let c;a instanceof Ji?c=a:a instanceof Event?c=i==null?void 0:i.propertySet.getProperty(((h=a.target)==null?void 0:h.value)||""):c=i==null?void 0:i.propertySet.getProperty(a||""),c&&(i==null||i.hideProperty(c)),l()};return v.jsxs("daga-property-settings",{ref:s,children:[v.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),i==null?void 0:i.displayedProperties.map((a,c)=>v.jsxs("div",{className:`daga-property-and-dropbar ${r(a.name)} daga-depth-${t}`,children:[v.jsxs("div",{className:`daga-property ${r(a.name)} daga-depth-${t}`,children:[v.jsxs("div",{className:"daga-property-name",children:[v.jsx("span",{children:a.name}),v.jsxs("div",{className:"daga-buttons",children:[v.jsx("button",{className:"daga-property-button daga-move-button",children:v.jsx("div",{className:"daga-icon daga-move-icon"})}),v.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>n(a.name),children:v.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),a.type!==_.Object&&v.jsx("div",{className:"daga-property-value",children:Qo(i==null?void 0:i.getValue(a.name))}),a.type===_.Object&&v.jsx(Pi,{valueSet:i==null?void 0:i.getSubValueSet(a.name),depth:t+1})]}),v.jsx("div",{className:`daga-dropbar daga-index-${c+1} daga-depth-${t}`})]},a.name))]})},Qo=i=>Array.isArray(i)?i.join(", "):Qi(i)?Object.entries(i).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):i instanceof Date?i.toLocaleString():i==null?"":""+i,ts=({location:i,direction:t,width:e,title:s,valueSet:r,onValueChange:l})=>{const o=z.useRef(null),[n,a]=z.useState(!1),[c,h]=z.useState(!1),d=()=>N.select(o.current);return z.useEffect(()=>{if(o.current)switch(t){case b.Bottom:case b.Top:d().style("width",e);break;case b.Left:case b.Right:d().style("height",e);break}},[e,t]),v.jsx("daga-property-editor",{children:v.jsxs("div",{ref:o,className:`daga-panel daga-bottom daga-${i} daga-${t}`,children:[v.jsx(be,{disabled:!r||!r.propertySet||!r.propertySet.hasProperties(),collapsed:n,direction:t,collapsableSelector:o,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:a}),r&&r.propertySet&&r.propertySet.hasProperties()&&!n&&v.jsxs("div",{className:"daga-panel-content",children:[s&&v.jsxs("p",{className:"daga-title",children:[s,v.jsx("button",{className:"daga-property-button",onClick:()=>h(!c),children:v.jsx("div",{className:`daga-icon daga-settings-icon ${c?"daga-unrotate":"daga-rotate"}`})})]}),!c&&v.jsx(Ni,{valueSet:r,onValueChange:l,depth:0}),c&&v.jsx(Pi,{valueSet:r,depth:0})]})]})})},es=6,is=i=>{const t=z.useContext(Et),[e,s]=z.useState(i.currentPalette||i.palettes[0]),[r,l]=z.useState(0),[o,n]=z.useState(void 0),a=z.useRef(null),c=f=>{if(s(f),h().selectAll("*").remove(),l(t.getPriorityThreshold()||0),f.categories&&d(f.categories),f.templates)for(const g of f.templates)u(g)},h=()=>N.select(a.current).select(".daga-palette-view"),d=f=>{const g=h().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");g.append("option").attr("value","").text("(None selected)");for(const y in f)g.append("option").attr("value",y).text(y);g.on(A.Change,()=>{o&&h().selectAll(".daga-template-container.daga-in-category").remove();const y=g.property("value");n(y);const w=f[y]||[];for(const k of w)u(k,"daga-in-category")}),o&&(g.property("value",o),g.dispatch(A.Change))},u=(f,g)=>{if(f.templateType==="node"){const y=t.model.nodes.types.get(f.type);y?p(y,f,g):console.error(`Could not find a node type called '${f.type}'`)}else if(f.templateType==="connection"){const y=t.model.connections.types.get(f.type);y?m(y,f,g):console.error(`Could not find a connection type called '${f.type}'`)}},p=(f,g,y)=>{if(r!==void 0&&f.priority<r)return;const w=f.defaultLook.lookType==="shaped-look"?f.defaultLook.borderThickness:0,k=f.defaultHeight+w,E=f.defaultWidth+w,C=g.height||k,T=g.width||E,M=h().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${T}px`).style("height",`${C}px`).call(N.drag().on($.Drag,R=>{if(t.canUserPerformAction(S.AddNode)){const L=t.getPointerLocationRelativeToScreen(R);if(L.length<2||isNaN(L[0])||isNaN(L[1]))return;M.style("position","fixed").style("left",`${L[0]-T}px`).style("top",`${L[1]-C}px`).style("z-index",1)}}).on($.Start,R=>{if(t.canUserPerformAction(S.AddNode)){I(P.Grabbing);const L=t.getPointerLocationRelativeToScreen(R);if(L.length<2||isNaN(L[0])||isNaN(L[1]))return;M.style("position","fixed").style("left",`${L[0]-T}px`).style("top",`${L[1]-C}px`).style("z-index",1),f.isUnique&&t.model.nodes.find(V=>!V.removed&&V.type.id===f.id)!==void 0&&I(P.NotAllowed)}}).on($.End,R=>{var L;if(t.canUserPerformAction(S.AddNode)){if(I(P.Auto),M.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),f.isUnique&&t.model.nodes.find(Ct=>!Ct.removed&&Ct.type.id===f.id)!==void 0)return;const V=t.getPointerLocationRelativeToScreen(R);if(V.length<2||isNaN(V[0])||isNaN(V[1]))return;const K=document.elementFromPoint(V[0],V[1]);if(K&&!((L=t.selectCanvasView().node())!=null&&L.contains(K)))return;const D=t.getPointerLocationRelativeToCanvas(R);if(D.length<2||isNaN(D[0])||isNaN(D[1]))return;let J=[D[0]-f.defaultWidth/2,D[1]-f.defaultHeight/2];t.snapToGrid&&(J=t.getClosestGridPoint(J));const Q=t.model.nodes.getAtCoordinates(D[0],D[1]).filter(Ct=>Ct.type.childrenTypes.includes(f.id)),et=bi(Q),rt=et[et.length-1];if(!f.canBeParentless&&rt===void 0)return;const ht=rt==null?void 0:rt.getLastAncestor(),Rt=new yo(t,f,J,rt==null?void 0:rt.id,ht==null?void 0:ht.id,ht==null?void 0:ht.getGeometry(),void 0,g.label,g.values);Rt.do(),t==null||t.actionStack.add(Rt),I()}})).append("svg").attr("class",`palette-node ${f.id}`).attr("viewBox",`0 0 ${E} ${k}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${T}px`).style("height",`${C}px`),x=g.look||f.defaultLook;switch(x.lookType){case"shaped-look":M.append("path").attr("d",ue(x.shape,x.borderThickness/2,x.borderThickness/2,f.defaultWidth,f.defaultHeight)).attr("fill",x.fillColor).attr("stroke",x.borderColor).attr("stroke-width",`${x.borderThickness}px`);break;case"image-look":M.append("image").attr("x",0).attr("y",0).attr("width",f.defaultWidth).attr("height",f.defaultHeight).attr("href",x.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":M.append("image").attr("x",0).attr("y",0).attr("width",x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",0).attr("width",f.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTop).attr("preserveAspectRatio","none"),M.append("image").attr("x",f.defaultWidth-x.rightMargin).attr("y",0).attr("width",x.rightMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",x.topMargin).attr("width",x.leftMargin).attr("height",f.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",x.topMargin).attr("width",f.defaultWidth-x.rightMargin-x.leftMargin).attr("height",f.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageCenter).attr("preserveAspectRatio","none"),M.append("image").attr("x",f.defaultWidth-x.rightMargin).attr("y",x.topMargin).attr("width",x.rightMargin).attr("height",f.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",f.defaultHeight-x.bottomMargin).attr("width",x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",f.defaultHeight-x.bottomMargin).attr("width",f.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottom).attr("preserveAspectRatio","none"),M.append("image").attr("x",f.defaultWidth-x.rightMargin).attr("y",f.defaultHeight-x.bottomMargin).attr("width",x.rightMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(g.look===void 0){if(f.decorators)for(const R of f.decorators)M.append("foreignObject").attr("width",`${R.width}px`).attr("height",`${R.height}px`).attr("transform",`translate(${R.coords[0]},${R.coords[1]})`).html(R.html);if(g.label){const R={...O,...f.label,...g.labelLook};M.append("text").attr("transform",`translate(${(Z(R)+f.defaultWidth)/2},${(U(R)+f.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${R.fontSize}px`).attr("text-anchor","middle").attr("font-family",R.fontFamily).attr("font-weight",400).attr("fill",R.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(g.label)}}},m=(f,g,y)=>{const w=h().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${g.width}px`).style("height",`${g.height}px`).append("svg").attr("class",`palette-button ${f.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=f});w.append("path").attr("d",ue(Zt.Rectangle,0,0,g.width,g.height)).attr("fill",g.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),g.icon!==""&&w.append("image").attr("x",0).attr("y",0).attr("width",g.width).attr("height",g.height).attr("href",g.icon),g.label!==""&&w.append("text").attr("transform",`translate(${g.width/2},${g.height/2+es})`).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(g.label)};return z.useEffect(()=>{if(c(i.palettes[0]),a.current)switch(i.direction){case b.Bottom:case b.Top:a.current.style.width=i.width;break;case b.Left:case b.Right:a.current.style.height=i.width;break}},[e,i.palettes]),v.jsx("daga-palette",{children:v.jsxs("div",{ref:a,className:`daga-panel daga-${i.location} daga-${i.direction}`,children:[v.jsx(be,{direction:i.direction,collapsableSelector:a,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),v.jsxs("div",{className:"daga-panel-content",children:[i.palettes.length>1&&v.jsx("div",{className:"daga-panel-tabs",children:i.palettes.map(f=>v.jsx("div",{className:`daga-panel-tab ${f===e?"daga-current-tab":""}`,onClick:()=>c(f),children:f.name}))}),v.jsx("div",{className:"daga-palette-view"})]})]})})},os=({location:i,direction:t,enableAction:e,enableFilter:s,enableLayout:r,enableSelection:l,enableZoom:o})=>{let n=!1,a=!0,c=!1,h,d,u,p;switch(t){case b.Bottom:h="height",d="scaleY",u="top",p="bottom";break;case b.Top:h="height",d="scaleY",u="bottom",p="top";break;case b.Left:h="width",d="scaleX",u="right",p="left";break;case b.Right:h="width",d="scaleX",u="left",p="right";break}const m=z.useRef(null),f=z.useRef(null),g=z.useRef(null);z.useEffect(()=>{N.select(m.current).style(`margin-${p}`,"-1rem").style(h,"0rem").style("transform",`${d}(0)`).style("transform-origin",u)});const y=async()=>{const F=N.select(m.current);if(!c)if(a){a=!1;const rt=`${4*F.selectChildren().size()}rem`;F.transition().duration(500).ease(N.easeLinear).style(h,rt).style("transform",`${d}(1)`),setTimeout(()=>{c=!1},500)}else a=!0,F.transition().duration(500).ease(N.easeLinear).style(h,"0rem").style("transform",`${d}(0)`),setTimeout(()=>{c=!1},500)},w=z.useContext(Et),k=()=>{w.zoomBy(w.zoomFactor)},E=()=>{w.zoomBy(1/w.zoomFactor)},C=()=>{w.center()},T=()=>{w.layoutFormat&&w.layoutFormat in ci&&ci[w.layoutFormat].apply(w.model)},M=()=>{n=!n,N.select(g.current).classed("daga-on",n).classed("daga-off",!n);const F=w.getPriorityThresholdOptions();F&&F.length>=2&&w.setPriorityThreshold(F[n?1:0])},x=()=>{w.actionStack.undo()},R=()=>{w.actionStack.redo()},L=()=>{w.userSelection.copyToClipboard()},V=()=>{w.userSelection.cutToClipboard()},K=()=>{w.userSelection.pasteFromClipboard()},D=()=>{w.userSelection.removeFromModel()},J=()=>{w.multipleSelectionOn=!0,N.select(f.current).classed("daga-on",!0).classed("daga-off",!1);const F=w.diagramEvent$.subscribe(Q=>{Q.type===Si.Selection&&(N.select(f.current).classed("daga-on",!1).classed("daga-off",!0),F.unsubscribe())})};return v.jsx("daga-diagram-buttons",{children:v.jsxs("div",{className:`daga-diagram-buttons daga-${i} daga-${t}`,children:[o&&w.canUserPerformAction(S.Zoom)&&v.jsx("button",{className:"daga-zoom-in",onClick:k,children:v.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),o&&w.canUserPerformAction(S.Zoom)&&v.jsx("button",{className:"daga-zoom-out",onClick:E,children:v.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),v.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:m,children:[o&&w.canUserPerformAction(S.Zoom)&&v.jsx("button",{className:"daga-center",onClick:C,children:v.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&v.jsx("button",{className:"daga-undo",onClick:x,children:v.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&v.jsx("button",{className:"daga-redo",onClick:R,children:v.jsx("span",{className:"daga-tooltip",children:"Redo"})}),l&&v.jsx("button",{className:"daga-copy",onClick:L,children:v.jsx("span",{className:"daga-tooltip",children:"Copy"})}),l&&v.jsx("button",{className:"daga-cut",onClick:V,children:v.jsx("span",{className:"daga-tooltip",children:"Cut"})}),l&&v.jsx("button",{className:`daga-multiple-selection ${n?"daga-on":"daga-off"}`,onClick:J,ref:f,children:v.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),l&&v.jsx("button",{className:"daga-paste",onClick:K,children:v.jsx("span",{className:"daga-tooltip",children:"Paste"})}),l&&v.jsx("button",{className:"daga-delete",onClick:D,children:v.jsx("span",{className:"daga-tooltip",children:"Delete"})}),r&&w.layoutFormat&&v.jsx("button",{className:"daga-layout",onClick:T,children:v.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),s&&v.jsx("button",{className:`daga-filter ${n?"daga-on":"daga-off"}`,onClick:M,ref:g,children:v.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),v.jsx("button",{className:"daga-more-options",onClick:y,children:a?v.jsx("span",{className:"daga-tooltip",children:"More options"}):v.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},ss=({config:i,model:t,onCanvasCreated:e,onDiagramEvent:s,onModelChange:r})=>{var M,x,R,L,V,K,D,J,F,Q,et,rt,ht,Rt,Ct,ke,we,xe,Se,Ce,Ie,Ae,Ee,Te,Le,$e,Me,Ne,Pe,ze,Re,Ve,_e,je,Oe,De,He,Ge,Fe,Be,Ue,Ye,Xe,We,Ze;const l=new xi,o=new Ai,n=z.useRef(null),a=z.useRef(void 0),c=z.useRef(!1),h=[],[d,u]=z.useState(void 0),[p,m]=z.useState(void 0),f={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},g={refreshPalette:()=>{}},y=new Yo(ct=>u(ct),ct=>m(ct)),w={diagramButtons:f,palette:g,propertyEditor:y},k=(ct=!1)=>((!a.current||ct)&&(h.forEach(gt=>gt.unsubscribe()),a.current=new fe(w,i)),a.current),E=k(),C=ct=>{E.initView(ct),h.push(E.diagramEvent$.subscribe(gt=>{s==null||s(gt)})),h.push(E.diagramChange$.subscribe(()=>{const gt=o.export(E.model);r==null||r(gt)}))};z.useEffect(()=>{n.current&&(c.current||(C(n.current),c.current=!0,e==null||e(E)))},[n.current]),z.useMemo(()=>{n.current&&(k(!0),C(n.current),e==null||e(E))},[i]),z.useEffect(()=>{t&&l.import(E.model,t)},[t]);const T=(ct,gt,Ke)=>{var qe;if(p!==void 0&&gt.editable&&!At(ct.getValue(gt.name),Ke)){ct.setValue(gt.name,Ke);const oe=new wt(p.propertySet,p.rootElement);oe.setValues(p.getValues()),y.valueSet=oe,p.rootElement.valueSet=oe,(qe=E.propertyEditorChanges$)==null||qe.next()}};return v.jsx("daga-diagram",{children:v.jsx(Uo.Provider,{value:i,children:v.jsx(Et.Provider,{value:E,children:v.jsxs("daga-diagram-editor",{children:[v.jsx("div",{className:"daga-append-to",ref:n}),v.jsxs(Et.Provider,{value:E,children:[((M=i.components)==null?void 0:M.buttons)!==void 0&&((R=(x=i.components)==null?void 0:x.buttons)==null?void 0:R.enabled)!==!1&&v.jsx(os,{location:((V=(L=i.components)==null?void 0:L.buttons)==null?void 0:V.location)||Bt.BottomRight,direction:((D=(K=i.components)==null?void 0:K.buttons)==null?void 0:D.direction)||b.Top,enableAction:((F=(J=i.components)==null?void 0:J.buttons)==null?void 0:F.enableAction)!==!1,enableFilter:((et=(Q=i.components)==null?void 0:Q.buttons)==null?void 0:et.enableFilter)===!0,enableLayout:((ht=(rt=i.components)==null?void 0:rt.buttons)==null?void 0:ht.enableLayout)===!0,enableSelection:((Ct=(Rt=i.components)==null?void 0:Rt.buttons)==null?void 0:Ct.enableSelection)!==!1,enableZoom:((we=(ke=i.components)==null?void 0:ke.buttons)==null?void 0:we.enableZoom)!==!1}),((xe=i.components)==null?void 0:xe.palette)!==void 0&&((Ce=(Se=i.components)==null?void 0:Se.palette)==null?void 0:Ce.enabled)!==!1&&((Ae=(Ie=i.components)==null?void 0:Ie.palette)==null?void 0:Ae.sections)&&(((Le=(Te=(Ee=i.components)==null?void 0:Ee.palette)==null?void 0:Te.sections)==null?void 0:Le.length)||0)>0&&v.jsx(is,{location:((Me=($e=i.components)==null?void 0:$e.palette)==null?void 0:Me.location)||Bt.TopLeft,direction:((Pe=(Ne=i.components)==null?void 0:Ne.palette)==null?void 0:Pe.direction)||b.Bottom,width:((Re=(ze=i.components)==null?void 0:ze.palette)==null?void 0:Re.width)||"12rem",palettes:((_e=(Ve=i.components)==null?void 0:Ve.palette)==null?void 0:_e.sections)||[]}),((je=i.components)==null?void 0:je.propertyEditor)!==void 0&&((De=(Oe=i.components)==null?void 0:Oe.propertyEditor)==null?void 0:De.enabled)!==!1&&v.jsx(ts,{location:((Ge=(He=i.components)==null?void 0:He.propertyEditor)==null?void 0:Ge.location)||Bt.TopRight,direction:((Be=(Fe=i.components)==null?void 0:Fe.propertyEditor)==null?void 0:Be.direction)||b.Bottom,width:((Ye=(Ue=i.components)==null?void 0:Ue.propertyEditor)==null?void 0:Ye.width)||"24rem",title:d,valueSet:p,onValueChange:T}),((Xe=i.components)==null?void 0:Xe.errors)!==void 0&&((Ze=(We=i.components)==null?void 0:We.errors)==null?void 0:Ze.enabled)!==!1&&v.jsx(Xo,{})]})]})})})})};exports.DagaDiagram=ss;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),Vi=require("d3"),At=require("rxjs"),z=require("react");function _i(i){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const e in i)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>i[e]})}}return t.default=i,Object.freeze(t)}const N=_i(Vi);var k=(i=>(i.Bottom="bottom",i.Left="left",i.Right="right",i.Top="top",i))(k||{}),Xt=(i=>(i.BottomLeft="bottom-left",i.BottomRight="bottom-right",i.TopLeft="top-left",i.TopRight="top-right",i))(Xt||{}),Nt=(i=>(i.Left="left",i.Center="center",i.Right="right",i))(Nt||{}),Zt=(i=>(i.Top="top",i.Center="center",i.Bottom="bottom",i))(Zt||{});const $t=i=>[Math.round(i[0]),Math.round(i[1])],yt=(i,t,e)=>t<e?t<=i&&i<=e:e<=i&&i<=t,ii=(i,t,e)=>(i-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Kt=(i,t,e,o,a,l,s)=>{const n=(()=>{switch(l){case"start":return o[0]+(i[0]-t[0]);case"end":return o[1]-(t[1]-i[0]);case"middle":{const c=(t[0]+t[1])/2,d=(o[0]+o[1])/2,h=t[1]-t[0],u=o[1]-o[0],p=(i[0]-c)/h;return d+p*u}case"floating":default:return ii(i[0],t,o)}})(),r=(()=>{switch(s){case"start":return a[0]+(i[1]-e[0]);case"end":return a[1]-(e[1]-i[1]);case"middle":{const c=(e[0]+e[1])/2,d=(a[0]+a[1])/2,h=e[1]-e[0],u=a[1]-a[0],p=(i[1]-c)/h;return d+p*u}case"floating":default:return ii(i[1],e,a)}})();return[n,r]},fi=(i,t)=>((i[0]-t[0])**2+(i[1]-t[1])**2)**.5,ji=(i,t)=>(yt(i[0][0],t[0][0],t[1][0])||yt(i[1][0],t[1][0],t[0][0])||yt(t[0][0],i[0][0],i[1][0])||yt(t[1][0],i[1][0],i[0][0]))&&(yt(i[0][1],t[0][1],t[1][1])||yt(i[1][1],t[1][1],t[0][1])||yt(t[0][1],i[0][1],i[1][1])||yt(t[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||{}),et=(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))(et||{}),M=(i=>(i.Drag="drag",i.Start="start",i.End="end",i))(M||{}),ue=(i=>(i.Zoom="zoom",i.Start="start",i.End="end",i))(ue||{});const fe=i=>i.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var mi=(i=>(i.Straight="straight",i.Bezier="bezier",i.Square="square",i))(mi||{}),be=(i=>(i.Solid="solid",i.Dashed="dashed",i.GappedDashes="gapped-dashes",i.Dotted="dotted",i))(be||{});const Oi=20,Di=(i,t,e,o,a)=>{if(typeof i=="function")return i(t,e,o,a);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{a=a||Oi;let l="",s,n;switch(i){case"straight":l+=`M ${t[0][0]} ${t[0][1]}`;for(let r=1;r<t.length;++r)l+=` L ${t[r][0]} ${t[r][1]}`;break;case"bezier":s=e,l+=`M ${t[0][0]} ${t[0][1]}`;for(let r=1;r<t.length;++r){if(r+1>=t.length?n=o:Math.abs(t[r][0]-t[r-1][0])<Math.abs(t[r][1]-t[r-1][1])?t[r][1]>t[r-1][1]?n=k.Bottom:n=k.Top:t[r][0]>t[r-1][0]?n=k.Right:n=k.Left,s!==void 0){let c="",d="";const h=(Math.abs(t[r][0]-t[r-1][0])+Math.abs(t[r][1]-t[r-1][1]))/2;switch(s){case k.Bottom:c=`${t[r-1][0]} ${t[r-1][1]+h}`;break;case k.Top:c=`${t[r-1][0]} ${t[r-1][1]-h}`;break;case k.Right:c=`${t[r-1][0]+h} ${t[r-1][1]}`;break;case k.Left:c=`${t[r-1][0]-h} ${t[r-1][1]}`;break}if(n!==void 0){switch(n){case k.Bottom:d=`${t[r][0]} ${t[r][1]+h}`;break;case k.Top:d=`${t[r][0]} ${t[r][1]-h}`;break;case k.Right:d=`${t[r][0]+h} ${t[r][1]}`;break;case k.Left:d=`${t[r][0]-h} ${t[r][1]}`;break}l+=` C ${c} ${d} ${t[r][0]} ${t[r][1]}`}else l+=` Q ${c} ${t[r][0]} ${t[r][1]}`}else if(n!==void 0){let c="";const d=(Math.abs(t[r][0]-t[r-1][0])+Math.abs(t[r][1]-t[r-1][1]))/2;switch(n){case k.Bottom:c=`${t[r][0]} ${t[r][1]+d}`;break;case k.Top:c=`${t[r][0]} ${t[r][1]-d}`;break;case k.Right:c=`${t[r][0]+d} ${t[r][1]}`;break;case k.Left:c=`${t[r][0]-d} ${t[r][1]}`;break}l+=` Q ${c} ${t[r][0]} ${t[r][1]}`}else l+=` L ${t[r][0]} ${t[r][1]}`;s=n}break;case"square":if(l+=`M ${t[0][0]} ${t[0][1]}`,e)switch(e){case k.Bottom:t.splice(1,0,[t[0][0],t[0][1]+a]);break;case k.Top:t.splice(1,0,[t[0][0],t[0][1]-a]);break;case k.Right:t.splice(1,0,[t[0][0]+a,t[0][1]]);break;case k.Left:t.splice(1,0,[t[0][0]-a,t[0][1]]);break}if(o)switch(o){case k.Bottom:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]+a]);break;case k.Top:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]-a]);break;case k.Right:t.splice(t.length-1,0,[t[t.length-1][0]+a,t[t.length-1][1]]);break;case k.Left:t.splice(t.length-1,0,[t[t.length-1][0]-a,t[t.length-1][1]]);break}for(let r=1;r<t.length;++r)if(s!==void 0)switch(s){case k.Bottom:t[r][1]<t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`,s=k.Top):t[r][1]<t[r-1][1]&&t[r][0]===t[r-1][0]?(l+=` H ${t[r][0]+a}`,l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`,s=k.Left):t[r][1]===t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,s=t[r][0]>t[r-1][0]?k.Right:k.Left):t[r][1]>t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`):t[r][1]>t[r-1][1]&&t[r][0]===t[r-1][0]&&(l+=` V ${t[r][1]}`);break;case k.Top:t[r][1]>t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`,s=k.Bottom):t[r][1]>t[r-1][1]&&t[r][0]===t[r-1][0]?(l+=` H ${t[r][0]-a}`,l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`,s=k.Right):t[r][1]===t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,s=t[r][0]>t[r-1][0]?k.Right:k.Left):t[r][1]<t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`):t[r][1]<t[r-1][1]&&t[r][0]===t[r-1][0]&&(l+=` V ${t[r][1]}`);break;case k.Right:t[r][0]<t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`,s=k.Left):t[r][0]<t[r-1][0]&&t[r][1]===t[r-1][1]?(l+=` V ${t[r][1]+a}`,l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`,s=k.Top):t[r][0]===t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,s=t[r][1]>t[r-1][1]?k.Bottom:k.Top):t[r][0]>t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`):t[r][0]>t[r-1][0]&&t[r][1]===t[r-1][1]&&(l+=` H ${t[r][0]}`);break;case k.Left:t[r][0]>t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`,s=k.Right):t[r][0]>t[r-1][0]&&t[r][1]===t[r-1][1]?(l+=` V ${t[r][1]-a}`,l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`,s=k.Bottom):t[r][0]===t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,s=t[r][1]>t[r-1][1]?k.Bottom:k.Top):t[r][0]<t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`):t[r][0]<t[r-1][0]&&t[r][1]===t[r-1][1]&&(l+=` H ${t[r][0]}`);break}else t[r][0]!==t[r-1][0]&&(l+=` H ${t[r][0]}`,s=t[r][0]>t[r-1][0]?k.Right:k.Left),t[r][1]!==t[r-1][1]&&(l+=` V ${t[r][1]}`,s=t[r][1]>t[r-1][1]?k.Bottom:k.Top);break}return l}},me=(i,t)=>{switch(i){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},Z=(i,t)=>{const e=i.indexOf(t);return e>=0&&i.splice(e,1),i};var Rt=(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))(Rt||{});const pe=(i,t,e,o,a)=>{if(typeof i=="function")return i(t,e,o,a);switch(i){case"ellipse":return pi(t,e,o,a);case"empty":return Fi();case"folder":return Hi(t,e,o,a);case"hexagon":return Gi(t,e,o,a);case"octagon":return Bi(t,e,o,a);case"pill":return Wt(t,e,o,a);case"rectangle":return oi(t,e,o,a);case"rhombus":return Ui(t,e,o,a);case"rounded-rectangle":return Yi(t,e,o,a);case"sticky-note":return Xi(t,e,o,a);default:return oi(t,e,o,a)}},pi=(i,t,e,o)=>`M ${i+e/2} ${t} A ${e/2} ${o/2} 0 0 0 ${i+e/2} ${t+o} A ${e/2} ${o/2} 0 1 0 ${i+e/2} ${t} Z`,Fi=()=>"Z",Hi=(i,t,e,o)=>`M ${i} ${t} L ${i+e/3} ${t} L ${i+e/2} ${t+o/6} L ${i+e} ${t+o/6} L ${i+e} ${t+o} L ${i} ${t+o} Z`,Gi=(i,t,e,o)=>`M ${i+e/4} ${t} L ${i+3*e/4} ${t} L ${i+e} ${t+o/2} L ${i+3*e/4} ${t+o} L ${i+e/4} ${t+o} L ${i} ${t+o/2} Z`,Bi=(i,t,e,o)=>`M ${i+e/4} ${t} L ${i+3*e/4} ${t} L ${i+e} ${t+o/4} L ${i+e} ${t+3*o/4} L ${i+3*e/4} ${t+o} L ${i+e/4} ${t+o} L ${i} ${t+3*o/4} L ${i} ${t+o/4} L ${i+e/4} ${t} Z`,Wt=(i,t,e,o)=>o<e?`M ${i+o/2} ${t} L ${i+e-o/2} ${t} A ${o/2} ${o/2} 0 0 1 ${i+e} ${t+o/2} A ${o/2} ${o/2} 0 0 1 ${i+e-o/2} ${t+o} L ${i+o/2} ${t+o} A ${o/2} ${o/2} 0 0 1 ${i} ${t+o/2} A ${o/2} ${o/2} 0 0 1 ${i+o/2} ${t} Z`:o>e?`M ${i} ${t+e/2} L ${i} ${t+o-e/2} A ${e/2} ${e/2} 0 0 0 ${i+e/2} ${t+o} A ${e/2} ${e/2} 0 0 0 ${i+e} ${t+o-e/2} L ${i+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${i+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${i} ${t+e/2} Z`:pi(i,t,e,o),oi=(i,t,e,o)=>`M ${i} ${t} L ${i+e} ${t} L ${i+e} ${t+o} L ${i} ${t+o} Z`,Ui=(i,t,e,o)=>`M ${i+e/2} ${t} L ${i+e} ${t+o/2} L ${i+e/2} ${t+o} L ${i} ${t+o/2} Z`,Yi=(i,t,e,o)=>`M ${i+e/4} ${t} L ${i+3*e/4} ${t} A ${e/4} ${o/4} 0 0 1 ${i+e} ${t+o/4} L ${i+e} ${t+3*o/4} A ${e/4} ${o/4} 0 0 1 ${i+3*e/4} ${t+o} L ${i+e/4} ${t+o} A ${e/4} ${o/4} 0 0 1 ${i} ${t+3*o/4} L ${i} ${t+o/4} A ${e/4} ${o/4} 0 0 1 ${i+e/4} ${t} Z`,Xi=(i,t,e,o)=>`M ${i} ${t} L ${i+3*e/4} ${t} L ${i+3*e/4} ${t+o/4} L ${i+3*e/4} ${t} L ${i+e} ${t+o/4} L ${i+3*e/4} ${t+o/4} L ${i+e} ${t+o/4} L ${i+e} ${t+o} L ${i} ${t+o} Z`;var P=(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))(P||{});const Wi=i=>Math.max(...i.split(`
2
+ `).map(t=>t.length)),Zi=i=>{var t;return((t=i.match(/\n/g))==null?void 0:t.length)||0},tt=[];for(let i=0;i<256;++i)tt.push((i+256).toString(16).slice(1));function Ki(i,t=0){return(tt[i[t+0]]+tt[i[t+1]]+tt[i[t+2]]+tt[i[t+3]]+"-"+tt[i[t+4]]+tt[i[t+5]]+"-"+tt[i[t+6]]+tt[i[t+7]]+"-"+tt[i[t+8]]+tt[i[t+9]]+"-"+tt[i[t+10]]+tt[i[t+11]]+tt[i[t+12]]+tt[i[t+13]]+tt[i[t+14]]+tt[i[t+15]]).toLowerCase()}let re;const qi=new Uint8Array(16);function Ji(){if(!re){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");re=crypto.getRandomValues.bind(crypto)}return re(qi)}const Qi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),si={randomUUID:Qi};function ni(i,t,e){var a;if(si.randomUUID&&!i)return si.randomUUID();i=i||{};const o=i.random??((a=i.rng)==null?void 0:a.call(i))??Ji();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,Ki(o)}const rt=i=>{const{selected:t,highlighted:e,...o}=i,a=o,l={...a,...t},s={...a,...e},n={...a,...e,...t};return{defaultLook:a,selectedLook:l,highlightedLook:s,selectedAndHighlightedLook:n}};class Jt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],Z(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Vt=0;class Tt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userHighlight)==null?void 0:e.contains(this.id))||!1}get selected(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userSelection)==null?void 0:e.contains(this.id))||!1}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`[id='${fe(this.id)}']`)}}class vt extends Jt{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((o,a,l)=>t(o,a,l)&&!o.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((o,a,l)=>t(o,a,l)&&!o.removed)}find(t,e=!1){return e?super.find(t):super.find((o,a,l)=>t(o,a,l)&&!o.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(o=>!o.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],Z(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(o=>!o.removed))yield e}}class to{constructor(t,e,o,a,l,s,n){this.name=t,this.label=e,this.type=o,this.defaultValue=a,this.basic=l,this.editable=s,this.rootAttribute=n,this.options=void 0,this.properties=void 0}}var _=(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))(_||{});class Qt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}function St(i,t){return!t||i[0]>t[0]?!0:i[0]===t[0]?i[1]>=t[1]:!1}const ri=i=>i==null||i===""||i instanceof Array&&i.length===0||i instanceof Object&&Object.keys(i).length===0,Et=(i,t)=>i===t||JSON.stringify(i)===JSON.stringify(t),vi=(i,t,e)=>{const o={},a={};for(const l in e.propertySet.propertyMap)if(e.propertySet.propertyMap[l].type===_.Object){const s=vi(i[l],t[l],e.getSubValueSet(l));Object.keys(s[0]).length>0&&Object.keys(s[1]).length>0&&(o[l]=s[0],a[l]=s[1])}else Et(i[l],t[l])||(o[l]=i[l],a[l]=t[l]);return[o,a]},eo=i=>i!=null&&i.constructor===Object;class xt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const o of t){if(e==null)return;e=e[o]}return e}}setRootElementValue(t,e){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let o=this.rootElement;for(let a=0;a<t.length-1;++a){const l=t[a];if(o==null)return;o=o[l]}if(o==null)return;o[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}getValue(t){var a;const e=(a=this.propertySet.getProperty(t))==null?void 0:a.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===_.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===_.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const o in t)this.propertySet.getProperty(o).type===_.Object?e[o]=this.valueSets[o].getValuesForKeys(t[o]):e[o]=this.getValue(o);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===_.Object)t[e]=this.valueSets[e].getTimestamps();else{const a=this.ownTimestamps[e];a&&(t[e]=a)}return t}hasValue(t){const e=this.getValue(t);return!ri(e)}hasSetValue(t){const e=this.getValue(t),o=this.propertySet.getProperty(t);return o&&o.type===_.Object?this.getSubValueSet(t).hasAnySetValue():!ri(e)&&!Et(e,o==null?void 0:o.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const o=this.propertySet.getProperty(t);if(o){o.type===_.Object?this.valueSets[t].setValues(e):(this.values[t]=e,Et(e,o.defaultValue)||this.displayProperty(o));const a=o.rootAttribute;a!=null&&this.setRootElementValue(a,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const o in t)this.propertySet.getProperty(o).type===_.Object?this.valueSets[o].overwriteValuesLww(t[o],e):St(e,this.ownTimestamps[o])&&(this.setValue(o,t[o]),this.ownTimestamps[o]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),o=e.rootAttribute;e.type===_.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),o!=null&&e.defaultValue!==void 0&&!Et(this.getRootElementValue(o),e.defaultValue)&&this.setRootElementValue(o,this.values[t]),e.basic!==!1?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),o=new Qt(e.properties),a=new xt(o,this.rootElement);return a.overwriteValues(structuredClone(e.defaultValue)),a}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),Z(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),Z(this.displayedProperties,t))}}const ot={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:mi.Straight,style:be.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class yi{constructor(t){const e={...ot,...t};this.id=e.id,this.name=e.name,this.label=e.label;const o=rt(e.look);if(this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const a=rt(e.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(e.endMarkerLook!==void 0){const a=rt(e.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=e.startTypes,this.endTypes=e.endTypes,this.propertySet=new Qt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class ht extends Tt{constructor(t,e,o,a,l){if(t.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(t,l),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new xt(e.propertySet,this),this.originalData={},this.setStart(o),this.setEnd(a)}get type(){return this._type}set type(t){var e,o;t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new xt(t.propertySet,this)),(o=(e=this.model.canvas)==null?void 0:e.userSelection)==null||o.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.connections.types.get(t);e&&(this.type=e)}}get name(){return this.middleLabel}set name(t){this.middleLabel=t}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(t){if(t){const e=rt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}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(t){if(t){const e=rt(t);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...e.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...e.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...e.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=t,this._selectedStartMarkerLook=t,this._highlightedStartMarkerLook=t,this._selectedAndHighlightedStartMarkerLook=t}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(t){if(t){const e=rt(t);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...e.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...e.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...e.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=t,this._selectedEndMarkerLook=t,this._highlightedEndMarkerLook=t,this._selectedAndHighlightedEndMarkerLook=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateConnectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}setStart(t){this.start!==t?(this.start!==void 0&&Z(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&Z(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}tighten(){var a,l,s,n,r;const t=((a=this.model.canvas)==null?void 0:a.allowConnectionLoops)||!1,e=((l=this.model.canvas)==null?void 0:l.allowSharingPorts)!==!1,o=((s=this.model.canvas)==null?void 0:s.allowSharingBothPorts)||!1;if((n=this.start)!=null&&n.rootElement&&this.end){const c=this.start.rootElement.ports.map(d=>[d,d.distanceTo(this.end.coords)]).sort((d,h)=>d[1]-h[1]).map(d=>d[0]);t:for(const d of c){if(!t&&d===this.end||!d.allowsOutgoing||!e&&(d.incomingConnections.length===1&&d.incomingConnections[0]!==this||d.incomingConnections.length>1||d.outgoingConnections.length===1&&d.outgoingConnections[0]!==this||d.outgoingConnections.length>1))continue t;if(!o){for(const h of d.outgoingConnections)if(h!==this&&h.end===this.end)continue t;for(const h of d.incomingConnections)if(h!==this&&h.start===this.end)continue t}if(d===this.start)break t;this.setStart(d);break t}}if((r=this.end)!=null&&r.rootElement&&this.start){const c=this.end.rootElement.ports.map(d=>[d,d.distanceTo(this.start.coords)]).sort((d,h)=>d[1]-h[1]).map(d=>d[0]);t:for(const d of c){if(!t&&d===this.start||!d.allowsIncoming||!e&&(d.outgoingConnections.length===1&&d.outgoingConnections[0]!==this||d.outgoingConnections.length>1||d.incomingConnections.length===1&&d.incomingConnections[0]!==this||d.incomingConnections.length>1))continue t;if(!o){for(const h of d.incomingConnections)if(h!==this&&h.start===this.start)continue t;for(const h of d.outgoingConnections)if(h!==this&&h.end===this.start)continue t}if(d===this.end)break t;this.setEnd(d);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Vt}}class io extends vt{constructor(t){super(),this.types=new Jt,this.model=t}new(t,e,o,a){let l;if(t instanceof yi)l=t;else{const n=this.types.get(t);if(n===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);l=n}const s=new ht(this.model,l,e,o,a);return super.add(s),s.updateInView(),s.valueSet.resetValues(),s}remove(t){var o,a;const e=this.get(t,!0);e&&(Z(((o=e.start)==null?void 0:o.outgoingConnections)||[],e),Z(((a=e.end)==null?void 0:a.incomingConnections)||[],e),super.remove(t),e.updateInView())}}const D={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:Nt.Center,verticalAlign:Zt.Center,orientation:k.Top,fit:!1,shrink:!0};class mt extends Tt{constructor(t,e,o,a,l,s,n,r,c,d,h,u,p,m,f,g){const y=`${e==null?void 0:e.id}_field`;if(t.fields.get(y)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,y),this.textTimestamp=null,this.rootElement=e,this.coords=o,this.width=a,this.height=l,this.fontSize=s,this.fontFamily=n,this.color=r,this.selectedColor=c,this.horizontalAlign=d,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case k.Top:this.orientation=0;break;case k.Right:this.orientation=90;break;case k.Bottom:this.orientation=180;break;case k.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=p,this._text=p,this.editable=m,this.fit=f,this.shrink=g}get text(){return this._text}set text(t){var e;(t==null||(t==null?void 0:t.trim())==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&((e=this.model.canvas)==null||e.fitFieldRootInView(this.id,this.shrink))}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateFieldsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||Vt}}class oo extends vt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s,n,r,c,d,h,u,p,m,f){const g=new mt(this.model,t,e,n,r,o,a,l,s,c,d,h,u,p,m,f);return super.add(g),g.updateInView(),t!==void 0&&(t.label=g),g}remove(t){var o;const e=this.get(t,!0);e&&(((o=e.rootElement)==null?void 0:o.label)!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const st=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]),Q=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],lt=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]),W=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]),Dt=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]),Ft=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],Ht=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]),Gt=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]),ai=1,li=1,so=1,no=1;class ro{constructor(t){this.margin=t.margin||0,this.defaultWidths=t.defaultWidths||null,this.defaultHeights=t.defaultHeights||null,this.minWidths=t.minWidths||null,this.minHeights=t.minHeights||null,this.sections=[];for(const e of t.sections){const o=[];this.sections.push(o);for(const a of e)o.push(new ao(a))}}}class ao{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||Vt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=rt(t.look||bi);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class U extends Tt{constructor(t,e,o,a,l,s,n,r){if(t.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(t,r),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=o,this.indexYInNode=a,this.coords=l,this.width=s,this.height=n}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){var t,e,o,a,l,s,n,r;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:((t=this.type)==null?void 0:t.selectedAndHighlightedLook)||((e=this.node)==null?void 0:e.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(t){if(t){const e=rt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateSectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise()}get type(){var t,e,o,a,l;return(l=(a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode]}getMinWidth(){var t,e,o,a;return((a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.minWidths)==null?void 0:a[this.indexXInNode])||so}getMinHeight(){var t,e,o,a;return((a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.minHeights)==null?void 0:a[this.indexYInNode])||no}getPriority(){var t,e,o,a,l,s;return((s=(l=(a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode])==null?void 0:s.priority)||Vt}getResizableX(){var e,o;const t=this.type;return(t==null?void 0:t.resizableX)!==void 0?t.resizableX:((o=(e=this.node)==null?void 0:e.type)==null?void 0:o.resizableX)||!1}getResizableY(){var e,o;const t=this.type;return(t==null?void 0:t.resizableY)!==void 0?t.resizableY:((o=(e=this.node)==null?void 0:e.type)==null?void 0:o.resizableY)||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),o=e.indexOf(Math.min(...e));return this.ports[o]}}}getIncomingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const o of this.ports){for(const a of o.incomingConnections)!t&&a.removed||e.push(a);for(const a of o.outgoingConnections)!t&&a.removed||e.push(a)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(t){case k.Left:l=[o[0]-e,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]-e,a[1]],s[1]-s[0]<this.getMinHeight()&&(s[0]=s[1]-this.getMinHeight());break;case k.Right:l=[o[0],o[1]+e],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]+e],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(t){var n;const e=[this.coords[0],this.coords[0]+this.width],o=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const r of this.ports)r.move(Kt(r.coords,e,o,a,l,r.anchorPointX,r.anchorPointY));const s=this.type;this.label&&(this.label.coords=[this.coords[0]+Q(s==null?void 0:s.label),this.coords[1]+W(s==null?void 0:s.label)],this.label.width=this.width-Q(s==null?void 0:s.label)-lt(s==null?void 0:s.label),this.label.height=this.height-W(s==null?void 0:s.label)-st(s==null?void 0:s.label),this.label.updateInView());for(const r of this.decorators)r.move(Kt(r.coords,e,o,a,l,r.anchorPointX,r.anchorPointY));((n=this.model.canvas)==null?void 0:n.autoTightenConnections)!==!1&&this.getConnections().forEach(r=>r.tighten()),this.updateInView()}}class lo extends vt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s,n){var h,u,p,m,f,g,y,w,b,I;const r=new U(this.model,t,e,o,a,l,s,n);super.add(r),r.updateInView(),t.sections.push(r),t.updateInView();const c=(m=(p=(u=(h=t.type.sectionGrid)==null?void 0:h.sections)==null?void 0:u[o])==null?void 0:p[e])==null?void 0:m.ports;if(c&&c.length>0)for(let S=0;S<c.length;++S){const L=c[S],$=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}_${S}`,L.anchorPointX||"floating",L.anchorPointY||"floating");if((f=$.type)!=null&&f.label){const x={...D,...(g=$.type)==null?void 0:g.label},V=6*x.fontSize+Ft(x)+Ht(x),T=x.fontSize+Gt(x)+Dt(x);let R;switch($.direction){case k.Bottom:case k.Left:case k.Right:R=[$.coords[0]-V/2,$.coords[1]-T-st(x)];break;case k.Top:R=[$.coords[0]-V/2,$.coords[1]+W(x)];break;default:R=$.coords}this.model.fields.new($,R,x.fontSize,x.fontFamily,x.color,x.selectedColor,V,T,x.horizontalAlign,x.verticalAlign,x.orientation,"",x.editable,x.fit,x.shrink)}}const d=(I=(b=(w=(y=t.type.sectionGrid)==null?void 0:y.sections)==null?void 0:w[o])==null?void 0:b[e])==null?void 0:I.label;if(d){const S={...D,...d};this.model.fields.new(r,[r.coords[0]+Q(S),r.coords[1]+W(S)],S.fontSize,S.fontFamily,S.color,S.selectedColor,r.width-Q(S)-lt(S),r.height-W(S)-st(S),S.horizontalAlign,S.verticalAlign,S.orientation,"",S.editable,S.fit,S.shrink)}return r}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&Z(e.node.sections,e),super.remove(t),e.updateInView()}}}const bi={lookType:"shaped-look",shape:Rt.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},pt={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:bi,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Vt,properties:[]};class ki{constructor(t){const e={...pt,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.bottomPadding=ho(e),this.leftPadding=go(e),this.rightPadding=uo(e),this.topPadding=fo(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new ro(e.sectionGrid):null;const o=rt(e.look);this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new Qt((t==null?void 0:t.properties)||[])}}class j extends Tt{constructor(t,e,o=[0,0],a){if(t.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(t,a),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new xt(e.propertySet,this),this.originalData={},this.coords=o,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){var e,o;t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new xt(t.propertySet,this)),(o=(e=this.model.canvas)==null?void 0:e.userSelection)==null||o.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.nodes.types.get(t);e&&(this.type=e)}}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}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(t){if(t){const e=rt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateNodesInView(this.id)}raise(){var t;(t=this.select())==null||t.raise();for(const e of this.sections)e.raise();this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise();for(const e of this.children)e.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),o=e.indexOf(Math.min(...e));return this.ports[o]}}}getIncomingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const o of this.ports){for(const a of o.incomingConnections)!t&&a.removed||e.push(a);for(const a of o.outgoingConnections)!t&&a.removed||e.push(a)}return e}getAdjacentNodes(t=!1){var o,a;const e=[];for(const l of this.ports){for(const s of l.incomingConnections){if(!t&&s.removed)continue;const n=(o=s.start)==null?void 0:o.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}for(const s of l.outgoingConnections){if(!t&&s.removed)continue;const n=(a=s.end)==null?void 0:a.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t==null?void 0:t.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,o=!1;for(;e!==void 0;){if(e.id===t.id){o=!0;break}e=e.parent}o||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){Z(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(r=>r.indexXInNode)),o=Math.max(...this.sections.map(r=>r.indexYInNode)),a=this.coords[0]-t.coords[0]+this.type.leftPadding;a>=0&&(this.sections.length>0?this.stretchSections(k.Left,a,e,o):this.stretch(k.Left,a));const l=this.coords[1]-t.coords[1]+this.type.topPadding;l>=0&&(this.sections.length>0?this.stretchSections(k.Top,l,e,o):this.stretch(k.Top,l));const s=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;s>=0&&(this.sections.length>0?this.stretchSections(k.Right,s,e,o):this.stretch(k.Right,s));const n=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;n>=0&&(this.sections.length>0?this.stretchSections(k.Bottom,n,e,o):this.stretch(k.Bottom,n)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const o of this.children)o.move([o.coords[0]+e[0],o.coords[1]+e[1]]);for(const o of this.sections)o.move([o.coords[0]+e[0],o.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(t){case k.Left:l=[o[0]-e,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]-e,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]+e],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]+e],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(t,e,o,a){let l=Number.NEGATIVE_INFINITY;switch(t){case k.Bottom:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));e<l&&(e=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(t,e):s.indexYInNode>a&&s.move([s.coords[0],s.coords[1]+e]);break;case k.Right:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));e<l&&(e=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(t,e):s.indexXInNode>o&&s.move([s.coords[0]+e,s.coords[1]]);break;case k.Top:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));e<l&&(e=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(t,e):s.indexYInNode<a&&s.move([s.coords[0],s.coords[1]-e]);break;case k.Left:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));e<l&&(e=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(t,e):s.indexXInNode<o&&s.move([s.coords[0]-e,s.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const a of this.sections)e[a.id]=a.getGeometry();const o={};for(const a of this.children)a.id!==t&&(o[a.id]=a.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:o}}setGeometry(t){var s;this.raise();const e=[this.coords[0],this.coords[0]+this.width],o=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const n of this.children){const r=t.children[n.id];r&&n.setGeometry(r)}for(const n of this.sections){const r=t.sections[n.id];r&&n.setGeometry(r)}for(const n of this.ports)n.move(Kt(n.coords,e,o,a,l,n.anchorPointX,n.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+Q(this.type.label),this.coords[1]+W(this.type.label)],this.label.width=this.width-Q(this.type.label)-lt(this.type.label),this.label.height=this.height-W(this.type.label)-st(this.type.label),this.label.updateInView());for(const n of this.decorators)n.move(Kt(n.coords,e,o,a,l,n.anchorPointX,n.anchorPointY));((s=this.model.canvas)==null?void 0:s.autoTightenConnections)!==!1&&this.getConnections().forEach(n=>n.tighten()),this.updateInView()}removeSectionColumn(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)s.indexYInNode===t&&(o=Math.max(o,s.width),this.model.sections.remove(s.id));for(const s of a)s.indexYInNode>t&&(--s.indexYInNode,s.move([s.coords[0]-o-e,s.coords[1]]));this.stretch(k.Right,-e-o)}removeSectionRow(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)s.indexXInNode===t&&(o=Math.max(o,s.height),this.model.sections.remove(s.id));for(const s of a)s.indexYInNode>t&&(--s.indexXInNode,s.move([s.coords[0],s.coords[1]-o-e]));this.stretch(k.Bottom,-e-o)}copySectionColumn(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)if(s.indexXInNode===t){o=Math.max(o,s.width);let n=s.indexXInNode+1;for(;this.model.sections.get(`${s.id}_copy_${n}_${s.indexYInNode}`,!0)!==void 0;)++n;this.model.sections.new(this,s.indexXInNode+1,s.indexYInNode,[s.coords[0]+s.width+e,s.coords[1]],s.width,s.height,`${s.id}_copy_${n}_${s.indexYInNode}`)}for(const s of a)s.indexXInNode>t&&(++s.indexXInNode,s.move([s.coords[0]+o+e,s.coords[1]]));this.stretch(k.Right,e+o)}copySectionRow(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)if(s.indexYInNode===t){o=Math.max(o,s.height);let n=s.indexYInNode+1;for(;this.model.sections.get(`${s.id}_copy_${s.indexXInNode}_${n}`,!0)!==void 0;)++n;this.model.sections.new(this,s.indexXInNode,s.indexYInNode+1,[s.coords[0],s.coords[1]+s.height+e],s.width,s.height,`${s.id}_copy_${s.indexXInNode}_${n}`)}for(const s of a)s.indexYInNode>t&&(++s.indexYInNode,s.move([s.coords[0],s.coords[1]+o+e]));this.stretch(k.Bottom,e+o)}}class co extends vt{constructor(t){super(),this.types=new Jt,this.model=t}new(t,e,o){var s,n,r,c,d,h,u;let a;if(t instanceof ki)a=t;else{const p=this.types.get(t);if(p===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);a=p}const l=new j(this.model,a,e,o);if(super.add(l),l.updateInView(),a.sectionGrid!==null){let p=l.coords[1]+(a.sectionGrid.margin||0);for(let m=0;m<a.sectionGrid.sections.length;++m){let f=l.coords[0]+(a.sectionGrid.margin||0);for(let g=0;g<a.sectionGrid.sections[m].length;++g)this.model.sections.new(l,g,m,[f,p],((s=a.sectionGrid.defaultWidths)==null?void 0:s[g])||ai,((n=a.sectionGrid.defaultHeights)==null?void 0:n[m])||li,`${l.id}_${m}_${g}`),f+=(((r=a.sectionGrid.defaultWidths)==null?void 0:r[g])||ai)+(a.sectionGrid.margin||0);p+=(((c=a.sectionGrid.defaultHeights)==null?void 0:c[m])||li)+(a.sectionGrid.margin||0)}}if(a.ports.length>0)for(let p=0;p<a.ports.length;++p){const m=a.ports[p],f=m.type!==void 0?this.model.ports.types.get(m.type):void 0,g=this.model.ports.new(f,l,[l.coords[0]+m.coords[0],l.coords[1]+m.coords[1]],m.connectionPoint!==void 0?[l.coords[0]+(m.connectionPoint[0]||0),l.coords[1]+(m.connectionPoint[1]||0)]:void 0,m.direction,`${l.id}_port_${p}`,m.anchorPointX||"floating",m.anchorPointY||"floating");if((d=g.type)!=null&&d.label){const y={...D,...(h=g.type)==null?void 0:h.label},w=6*y.fontSize+Ft(y)+Ht(y),b=y.fontSize+Gt(y)+Dt(y);let I;switch(g.direction){case k.Bottom:case k.Left:case k.Right:I=[g.coords[0]-w/2,g.coords[1]-b-st(y)];break;case k.Top:I=[g.coords[0]-w/2,g.coords[1]+W(y)];break;default:I=g.coords}this.model.fields.new(g,I,y.fontSize,y.fontFamily,y.color,y.selectedColor,w,b,y.horizontalAlign,y.verticalAlign,y.orientation,"",y.editable,y.fit,y.shrink)}}if(a.label){const p={...D,...a.label};this.model.fields.new(l,[l.coords[0]+Q(p),l.coords[1]+W(p)],p.fontSize,p.fontFamily,p.color,p.selectedColor,l.width-Q(p)-lt(p),l.height-W(p)-st(p),p.horizontalAlign,p.verticalAlign,p.orientation,"",p.editable,p.fit,p.shrink)}if(a.decorators.length>0)for(let p=0;p<a.decorators.length;++p){const m=a.decorators[p];this.model.decorators.new(l,[l.coords[0]+m.coords[0],l.coords[1]+m.coords[1]],m.width,m.height,l.getPriority(),m.html,`${l.id}_decorator_${p}`,m.anchorPointX||"floating",m.anchorPointY||"floating")}return l.valueSet.resetValues(),(u=l.model.canvas)==null||u.fitNodeInView(l.id),l}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&Z(e.parent.children,e);e.children.length>0;)this.model.nodes.remove(e.children[0].id);for(;e.sections.length>0;)this.model.sections.remove(e.sections[0].id);for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);for(;e.decorators.length>0;)this.model.decorators.remove(e.decorators[0].id);e.label&&this.model.fields.remove(e.label.id),super.remove(t),e.updateInView()}}getAtCoordinates(t,e){const o=[];for(const a of this)a.coords[0]<t&&t<a.coords[0]+a.width&&a.coords[1]<e&&e<a.coords[1]+a.height&&o.push(a);return o}}const wi=i=>{for(let t=0;t<i.length;++t)for(let e=0;e<i.length;++e)e!==t&&i[e].isAncestorOf(i[t])&&(i.splice(e,1),--e,t>e&&--t);return i},ho=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?pt.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?pt.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),go=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?pt.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?pt.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],uo=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?pt.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?pt.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),fo=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?pt.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?pt.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),xi={lookType:"shaped-look",shape:Rt.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Yt=rt(xi),Ci={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:xi};class mo{constructor(t){const e={...Ci,...t};this.id=e.id,this.name=e.name,this.label=e.label,this.allowsOutgoing=e.allowsOutgoing,this.allowsIncoming=e.allowsIncoming,this.width=e.width;const o=rt(e.look);this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook}}class Ct extends Tt{constructor(t,e,o,a,l,s,n,r="floating",c="floating"){if(t.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(t,n),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=o,this.coords=a,this.connectionPoint=l||a,this.direction=s,this.anchorPointX=r,this.anchorPointY=c}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.updateInView())}get typeString(){var t;return(t=this.type)==null?void 0:t.id}set typeString(t){var e;if(t!==((e=this.type)==null?void 0:e.id))if(t===void 0)this.type=void 0;else{const o=this.model.ports.types.get(t);o&&(this.type=o)}}get allowsOutgoing(){var t,e;return((t=this.type)==null?void 0:t.allowsOutgoing)!==void 0?(e=this.type)==null?void 0:e.allowsOutgoing:!0}get allowsIncoming(){var t,e;return((t=this.type)==null?void 0:t.allowsIncoming)!==void 0?(e=this.type)==null?void 0:e.allowsIncoming:!0}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){var t,e,o,a;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(t=this.type||Yt)==null?void 0:t.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(e=this.type||Yt)==null?void 0:e.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(o=this.type||Yt)==null?void 0:o.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(a=this.type||Yt)==null?void 0:a.defaultLook}set look(t){if(t){const e=rt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get width(){var t;return((t=this.type)==null?void 0:t.width)||Ci.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updatePortsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.incomingConnections)e.raise();for(const e of this.outgoingConnections)e.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof j)return this.rootElement;if(this.rootElement instanceof U)return this.rootElement.node}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||Vt}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];this.coords=t,this.connectionPoint[0]=this.connectionPoint[0]+e[0],this.connectionPoint[1]=this.connectionPoint[1]+e[1];for(const 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]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return fi(this.coords,t)}}class po extends vt{constructor(t){super(),this.types=new Jt,this.model=t}new(t,e,o,a,l,s,n="floating",r="floating"){const c=new Ct(this.model,t,e,o,a,l,s,n,r);return super.add(c),c.updateInView(),e!==void 0&&e.ports.push(c),c}remove(t){const e=this.get(t,!0);if(e){for(;e.outgoingConnections.length>0;)this.model.connections.remove(e.outgoingConnections[0].id);for(;e.incomingConnections.length>0;)this.model.connections.remove(e.incomingConnections[0].id);e.label&&this.model.fields.remove(e.label.id),(e.rootElement instanceof j||e.rootElement instanceof U)&&Z(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class Si{import(t,e){t.clear(),e.id&&(t.id=e.id),t.name=e.name,t.description=e.description,t.type=e.type,t.createdAt=new Date(e.createdAt),t.updatedAt=new Date(e.updatedAt);for(const o of e.nodes||[])this.importNode(t,o);for(const o of e.connections||[])this.importConnection(t,o);return e.data&&t.valueSet.setValues(e.data),e.collabMeta&&(t.logicalClock=e.collabMeta.logicalClock,t.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),t}importNode(t,e){var a,l,s,n,r,c,d,h,u,p;const o=t.nodes.types.get(e.type);if(o){const m=new j(t,o,e.coords,e.id);if(t.nodes.add(m),m.width=e.width,m.height=e.height,e.label){if(o.decorators)for(let g=0;g<o.decorators.length;++g){const y=o.decorators[g];t.decorators.new(m,[m.coords[0]+y.coords[0],m.coords[1]+y.coords[1]],y.width,y.height,m.getPriority(),y.html,`${m.id}_decorator_${g}`)}if(o.label){const g={...D,...o.label},y=new mt(t,m,[m.coords[0]+Q(g),m.coords[1]+W(g)],m.width-Q(g)-lt(g),m.height-W(g)-st(g),g.fontSize,g.fontFamily,g.color,g.selectedColor,g.horizontalAlign,g.verticalAlign,g.orientation,"",g.editable,g.fit,g.shrink);y.text=e.label,m.label=y,t.fields.add(y),y.updateInView()}}for(const g of e.children||[]){const y=this.importNode(t,g);y!==void 0&&((a=m.children)==null||a.push(y),y.parent=m)}for(const g of e.sections||[]){const y=new U(t,m,g.indexXInNode,g.indexYInNode,g.coords,g.width,g.height,g.id);if((l=m.sections)==null||l.push(y),t.sections.add(y),g.label&&(c=(r=(n=(s=o.sectionGrid)==null?void 0:s.sections)==null?void 0:n[g.indexYInNode])==null?void 0:r[g.indexXInNode])!=null&&c.label){const b={...D,...(p=(u=(h=(d=o.sectionGrid)==null?void 0:d.sections)==null?void 0:h[g.indexYInNode])==null?void 0:u[g.indexXInNode])==null?void 0:p.label},I=new mt(t,y,[y.coords[0]+Q(b),y.coords[1]+W(b)],y.width-Q(b)-lt(b),y.height-W(b)-st(b),b.fontSize,b.fontFamily,b.color,b.selectedColor,b.horizontalAlign,b.verticalAlign,b.orientation,"",b.editable,b.fit,b.shrink);I.text=g.label,y.label=I,t.fields.add(I),I.updateInView()}let w=0;for(const b of g.ports||[]){const I=b.type!==void 0?t.ports.types.get(b.type):void 0,S=new Ct(t,I,y,b.coords,b.connectionPoint,b.direction,b.id);if(y.ports.push(S),t.ports.add(S),b.label){if(o.ports.length>w&&(I!=null&&I.label)){const L={...D,...I==null?void 0:I.label};let $;switch(S.direction){case k.Top:case k.Left:$=[S.coords[0]-L.fontSize,S.coords[1]-L.fontSize];break;case k.Bottom:$=[S.coords[0]-L.fontSize,S.coords[1]+L.fontSize];break;case k.Right:$=[S.coords[0]+L.fontSize,S.coords[1]-L.fontSize];break;default:$=S.coords}const x=new mt(t,S,$,L.fontSize,L.fontSize,L.fontSize,L.fontFamily,L.color,L.selectedColor,L.horizontalAlign,L.verticalAlign,L.orientation,"",L.editable,L.fit,L.shrink);x.text=b.label,S.label=x,t.fields.add(x),x.updateInView()}++w}b.collabMeta&&(S.selfRemoved=b.collabMeta.selfRemoved,S.selfRemovedTimestamp=b.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(S.label,b.collabMeta.label)),S.updateInView()}g.collabMeta&&(y.selfRemoved=g.collabMeta.selfRemoved,y.selfRemovedTimestamp=g.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(y.label,g.collabMeta.label)),y.updateInView()}let f=0;for(const g of e.ports||[]){const y=g.type!==void 0?t.ports.types.get(g.type):void 0,w=new Ct(t,y,m,g.coords,g.connectionPoint,g.direction,g.id);if(m.ports.push(w),t.ports.add(w),g.label){if(o.ports.length>f&&(y!=null&&y.label)){const b={...D,...y==null?void 0:y.label};let I;switch(w.direction){case k.Top:case k.Left:I=[w.coords[0]-b.fontSize,w.coords[1]-b.fontSize];break;case k.Bottom:I=[w.coords[0]-b.fontSize,w.coords[1]+b.fontSize];break;case k.Right:I=[w.coords[0]+b.fontSize,w.coords[1]-b.fontSize];break;default:I=w.coords}const S=new mt(t,w,I,b.fontSize,b.fontSize,b.fontSize,b.fontFamily,b.color,b.selectedColor,b.horizontalAlign,b.verticalAlign,b.orientation,"",b.editable,b.fit,b.shrink);S.text=g.label,w.label=S,t.fields.add(S),S.updateInView()}++f}g.collabMeta&&(w.selfRemoved=g.collabMeta.selfRemoved,w.selfRemovedTimestamp=g.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(w.label,g.collabMeta.label)),w.updateInView()}return e.data&&m.valueSet.setValues(e.data),e.collabMeta&&(m.selfRemoved=e.collabMeta.selfRemoved,m.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,m.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(m.label,e.collabMeta.label),m.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),m.updateInView(),m.raise(),m}}importConnection(t,e){const o=t.connections.types.get(e.type);if(o){const a=new ht(t,o,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(a),a.startLabel=e.startLabel,a.middleLabel=e.middleLabel,a.endLabel=e.endLabel,a.points=e.points,e.data&&a.valueSet.setValues(e.data),e.collabMeta&&(a.selfRemoved=e.collabMeta.selfRemoved,a.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,a.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),a.updateInView(),a.raise(),a}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class te{constructor(t,e,o,a,l,s,n){this.canvas=t,this.id=e,this.typeId=o,this.coords=a,this.parentId=l,this.label=s,this.values=n}do(){var e;const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&((e=this.canvas.model.nodes.get(this.parentId))==null||e.addChild(t)),t.label&&(t.label.text=this.label||""),this.values!==void 0?t.valueSet.setValues(structuredClone({...t.valueSet.getValues(),...this.values})):t.valueSet.resetValues()}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new te(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class ke{constructor(t,e,o,a,l,s,n){this.canvas=t,this.nodeId=e,this.copyColumnIndex=o,this.copyRowIndex=a,this.removeColumnIndex=l,this.removeRowIndex=s,this.timestamp=n}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&St(this.timestamp,t.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&t.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&t.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&t.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&t.removeSectionRow(this.removeRowIndex),t.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(t,e){return new ke(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class we{constructor(t,e,o){this.canvas=t,this.to=e,this.timestamp=o}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&St(this.timestamp,e.geometryTimestamp)){const o=this.to[t];e.move([o[0],o[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new we(t,e.to,e.timestamp)}}class Bt{constructor(t,e,o,a){this.canvas=t,this.nodeIds=e,this.delta=o,this.timestamp=a}do(){var t;for(const e of this.nodeIds){const o=this.canvas.model.nodes.get(e,!0);o&&St(this.timestamp,o.geometryTimestamp)&&(o.move([o.coords[0]+this.delta[0],o.coords[1]+this.delta[1]]),(t=o.parent)==null||t.fitToChild(o),o.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new Bt(t,e.nodeIds,e.delta,e.timestamp)}}class nt{constructor(t,e,o,a){this.canvas=t,this.nodeId=e,this.to=o,this.timestamp=a}do(){var e,o,a;const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&St(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),(e=t.label)!=null&&e.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);for(const l of t.sections)(o=l.label)!=null&&o.fit&&this.canvas.fitFieldRootInView(l.label.id,l.label.shrink);(a=t.parent)==null||a.fitToChild(t),t.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new nt(t,e.nodeId,e.to,e.timestamp)}}class Ut{constructor(t,e,o,a,l){this.canvas=t,this.childId=e,this.parentId=o,this.childGeometry=a,this.timestamp=l}do(){var o;const t=this.canvas.model.nodes.get(this.childId,!0),e=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;t&&(this.parentId===void 0||e)&&St(this.timestamp,t.geometryTimestamp)&&((o=t.parent)==null||o.removeChild(t),t.setGeometry(this.childGeometry),e==null||e.addChild(t))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,e){return new Ut(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class ee{constructor(t,e,o,a,l){this.canvas=t,this.id=e,this.typeId=o,this.startId=a,this.endId=l}do(){const t=this.canvas.model.ports.get(this.startId,!0),e=this.canvas.model.ports.get(this.endId,!0);t&&e&&this.canvas.model.connections.new(this.typeId,t,e,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,e){return new ee(t,e.id,e.typeId,e.startId,e.endId)}}class Pt{constructor(t,e,o,a){this.canvas=t,this.fieldId=e,this.to=o,this.timestamp=a}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&St(this.timestamp,t.textTimestamp)&&(t.text=this.to,t.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Pt(t,e.fieldId,e.to,e.timestamp)}}class zt{constructor(t,e,o,a){this.canvas=t,this.id=e,this.to=o,this.timestamp=a}getValueSet(){var t;return this.id===void 0?this.canvas.model.valueSet:(t=this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))==null?void 0:t.valueSet}do(){var t;(t=this.getValueSet())==null||t.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new zt(t,e.id,e.to,e.timestamp)}}class ct{constructor(t,e,o,a,l,s,n,r){this.canvas=t,this.nodeIds=e,this.sectionIds=o,this.portIds=a,this.connectionIds=l,this.fieldIds=s,this.selfRemoved=n,this.timestamp=r}doOne(t){t&&St(this.timestamp,t.selfRemovedTimestamp)&&(t.selfRemoved=this.selfRemoved,t.selfRemovedTimestamp=this.timestamp)}do(){for(const t of this.nodeIds)this.doOne(this.canvas.model.nodes.get(t,!0));for(const t of this.sectionIds)this.doOne(this.canvas.model.sections.get(t,!0));for(const t of this.portIds)this.doOne(this.canvas.model.ports.get(t,!0));for(const t of this.connectionIds)this.doOne(this.canvas.model.connections.get(t,!0));for(const t of this.fieldIds)this.doOne(this.canvas.model.fields.get(t,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,e){return new ct(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class ie{constructor(t,e,o){this.canvas=t,this.nodes=e,this.connections=o}do(){const t=new Si;this.canvas.userSelection.clear();for(const e of this.nodes){const o=t.importNode(this.canvas.model,e);o&&this.canvas.userSelection.add(o)}for(const e of this.connections){const o=t.importConnection(this.canvas.model,e);o&&this.canvas.userSelection.add(o)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new ie(t,e.nodes,e.connections)}}class vo{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=ni()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+ni()}doCollaboratively(t){if(t.do(),this.onSend){const e=t.serialize();this.onSend(e)}}receive(t){switch("timestamp"in t&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,t.timestamp[0])),t.type){case"addNode":{te.deserialize(this.canvas,t).do();break}case"addSection":{ke.deserialize(this.canvas,t).do();break}case"applyLayout":{we.deserialize(this.canvas,t).do();break}case"move":{Bt.deserialize(this.canvas,t).do();break}case"setGeometry":{nt.deserialize(this.canvas,t).do();break}case"setParent":{Ut.deserialize(this.canvas,t).do();break}case"addConnection":{ee.deserialize(this.canvas,t).do();break}case"editField":{Pt.deserialize(this.canvas,t).do();break}case"updateValues":{zt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{ct.deserialize(this.canvas,t).do();break}case"paste":{ie.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class yo{constructor(t,e){this.canvas=t,this.maximum=e,this.history=[],this.index=0}add(t){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(t)):(this.history.push(t),++this.index),this.canvas.diagramChange$.next({action:t,method:0})}undo(){let t;if(this.index>0){let e;do--this.index,t=this.history[this.index],e=t.undo();while(!e&&this.index>0)}this.canvas.diagramChange$.next({action:t,method:1})}redo(){let t;if(this.index<this.history.length){let e;do t=this.history[this.index],e=t.redo(),++this.index;while(!e&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:t,method:2})}}var 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 bo{constructor(t,e,o,a,l,s,n,r,c){this.canvas=t,this.type=e,this.coords=o,this.parentId=a,this.ancestorId=l,this.fromAncestorGeometry=s,this.toAncestorGeometry=n,this.label=r,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){const t=new te(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const e=new nt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){const t=this.canvas.model.nodes.get(this.id),e=new ct(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const o=new nt(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new ct(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const o=new nt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t===void 0}}class ae{constructor(t,e,o){this.canvas=t,this.nodeIds=e,this.delta=o}do(){const t=new Bt(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const t=new Bt(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class q{constructor(t,e,o,a,l,s,n,r){this.canvas=t,this.intent=e,this.nodeId=o,this.from=a,this.to=l,this.ancestorId=s,this.fromAncestorGeometry=n,this.toAncestorGeometry=r}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new nt(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const o=new nt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new nt(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const o=new nt(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new nt(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class ko{constructor(t,e,o,a,l,s,n,r,c){this.canvas=t,this.childId=e,this.fromParentId=o,this.toParentId=a,this.fromChildGeometry=l,this.toChildGeometry=s,this.ancestorId=n,this.fromAncestorGeometry=r,this.toAncestorGeometry=c}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Ut(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const o=new nt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Ut(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const o=new nt(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t!==void 0}redo(){return this.do()}}class le{constructor(t,e,o,a){this.canvas=t,this.type=e,this.startId=o,this.endId=a,this.id=this.canvas.collabEngine.freshId()}do(){const t=new ee(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=this.canvas.model.connections.get(this.id),e=new ct(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}redo(){const t=this.canvas.model.connections.get(this.id),e=new ct(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class ci{constructor(t,e,o,a){this.canvas=t,this.fieldId=e,this.from=o,this.to=a}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new Pt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}undo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.to=t.text;const e=new Pt(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}redo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.from=t.text;const e=new Pt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class wo{constructor(t,e,o,a){this.canvas=t,this.id=e,this.from=o,this.to=a}do(){const t=new zt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new zt(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.to=e.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}redo(){const t=new zt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.from=e.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}}class xo{constructor(t,e,o,a,l,s){this.canvas=t,this.nodeIds=e,this.sectionIds=o,this.portIds=a,this.connectionIds=l,this.fieldIds=s}do(){const t=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),e=new ct(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}undo(){const t=this.nodeIds.map(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),e=new ct(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){return this.do()}}class Co{constructor(t,e,o,a){this.canvas=t,this.nodes=e,this.connections=o,this.coords=a}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const l of this.nodes)l.coords[0]<t[0]&&(t[0]=l.coords[0]),l.coords[1]<t[1]&&(t[1]=l.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,o={};for(const l of this.nodes){const s=l.id,n=this.canvas.collabEngine.freshId();if(o[s]=n,l.id=n,e&&(l.coords=[l.coords[0]+e[0],l.coords[1]+e[1]]),l.sections)for(const r of l.sections){const c=r.id;if(r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),o[c]=r.id,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]]),r.ports)for(const d of r.ports){const h=d.id;d.id.includes(l.id)?d.id=d.id.replace(l.id,n):d.id=this.canvas.collabEngine.freshId(),o[h]=d.id,e&&(d.coords=[d.coords[0]+e[0],d.coords[1]+e[1]])}}if(l.ports)for(const r of l.ports){const c=r.id;r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),o[c]=r.id,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[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,e)for(let n=0;n<l.points.length;++n)l.points[n]=[l.points[n][0]+e[0],l.points[n][1]+e[1]]}const a=new ie(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(a),!0}undo(){const t=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),e=new ct(this.canvas,this.nodes.map(o=>o.id),[],[],this.connections.map(o=>o.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=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),e=new ct(this.canvas,this.nodes.map(o=>o.id),[],[],this.connections.map(o=>o.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class oe{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Ii=(i=>(i[i.DoubleClick=0]="DoubleClick",i[i.SecondaryClick=1]="SecondaryClick",i[i.Selection=2]="Selection",i[i.Highlight=3]="Highlight",i))(Ii||{});class bt extends oe{constructor(t,e,o){super(0),this.cause=t,this.target=e,this.coords=o}}class kt extends oe{constructor(t,e,o){super(1),this.cause=t,this.target=e,this.coords=o}}class G extends oe{constructor(t,e){super(2),this.targets=t,this.selected=e}}class it extends oe{constructor(t){super(3),this.target=t}}class Ai extends Tt{constructor(t,e,o,a,l,s,n,r,c="floating",d="floating"){if(t.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(t,r),this.rootElement=e,this.coords=o,this.width=a,this.height=l,this.priority=s,this.html=n,this.anchorPointX=c,this.anchorPointY=d}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateDecoratorsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class So extends vt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s,n,r="floating",c="floating"){const d=new Ai(this.model,t,e,o,a,l,s,n,r,c);return super.add(d),d.updateInView(),t!==void 0&&t.decorators.push(d),d}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof j||e.rootElement instanceof U)&&Z(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Io extends Tt{constructor(t,e,o,a,l,s,n){if(t.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(t,n),this.coords=e,this.width=o,this.height=a,this.priority=l,this.html=s}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateObjectsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Ao extends vt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s){const n=new Io(this.model,t,e,o,a,l,s);return super.add(n),n.updateInView(),n}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Ei{constructor(t,e,o,a,l,s=[]){this.nodes=new co(this),this.sections=new lo(this),this.ports=new po(this),this.connections=new io(this),this.fields=new oo(this),this.objects=new Ao(this),this.decorators=new So(this),this.canvas=t,this.id=e,this.name=o,this.description=a,this.type=l,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new xt(new Qt(s),this)}clear(){var t,e;(t=this.canvas)==null||t.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),(e=this.canvas)==null||e.updateModelInView()}}const wt=i=>!!i.button,ce=(i,t,e,o,a,l,s,n)=>Di(i,[t,e],o,a,Math.max(10,s||0,n||0)*l),A=i=>{i?N.select("body").style("cursor",i):N.select("body").style("cursor",P.Auto)},ft=i=>i instanceof j?i:i instanceof U?i.node||i:i.rootElement instanceof j||i.rootElement instanceof U||i.rootElement instanceof Ct?ft(i.rootElement):i,de=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")},jt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:be.Solid},he=i=>{i.filter(".shaped-look").select("path").attr("d",t=>pe(t.look.shape||Rt.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||jt.fillColor).attr("stroke",t=>t.look.borderColor||jt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||jt.borderThickness}px`).attr("stroke-dasharray",t=>me(t.look.borderStyle||jt.borderStyle,t.look.borderThickness||jt.borderThickness)),i.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",t=>t.width).attr("height",t=>t.height).attr("href",t=>t.look.backgroundImage),i.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopLeft),i.filter(".stretchable-image-look").select("image.top-image").attr("x",t=>t.look.leftMargin).attr("y",0).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTop),i.filter(".stretchable-image-look").select("image.top-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",0).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopRight),i.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageLeft),i.filter(".stretchable-image-look").select("image.center-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageCenter),i.filter(".stretchable-image-look").select("image.right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageRight),i.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomLeft),i.filter(".stretchable-image-look").select("image.bottom-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottom),i.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomRight)},Ot={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Eo=(i,t,e)=>{const o=t.append("defs");if(i.gridSize>0&&isFinite(i.gridSize)){const a=o.append("pattern").attr("id",e).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}t.select("rect").attr("fill",`url(#${e})`)}},ve=96,J=32,Mt=ve+J,Lo=Math.PI/4,To=100,di={customButtons:[]};class $o{constructor(t,e){this.canvas=t,this.config=e||di}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),o=this.canvas.getPointerLocationRelativeToCanvas(t),a=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-Mt}px`).attr("y",`${e[1]-Mt}px`).attr("width",`${2*Mt}px`).attr("height",`${2*Mt}px`).style("pointer-events","none").on(E.ContextMenu,s=>{this.canvas.canUserPerformAction(C.ContextMenu)&&(t.preventDefault(),this.open(s))}).on(E.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.userSelection.cutToClipboard(),s.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&l.push({name:"COPY",imageClass:"daga-copy",onPress:s=>{s.userSelection.copyToClipboard(),s.cancelAllUserActions()}}),this.canvas.canUserPerformAction(C.Paste)&&l.push({name:"PASTE",imageClass:"daga-paste",onPress:s=>{s.userSelection.pasteFromClipboard(s.getClosestGridPoint(o)),s.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"DELETE",imageClass:"daga-delete",onPress:s=>{s.userSelection.removeFromModel(),s.cancelAllUserActions()}});for(const s of this.config.customButtons||di.customButtons)(s.condition===void 0||s.condition(this.canvas))&&l.push(s);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,c=(s+.5-l.length/2)*Lo,d=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*J}px`).style("height",`${2*J}px`).style("border-radius",`${J}px`).style("pointer-events","auto").on(E.Click,h=>{r&&(h.preventDefault(),r(this.canvas))}).on(E.KeyDown,h=>{r&&h.key===et.Enter&&(h.preventDefault(),r(this.canvas))});n.imageClass!==void 0?d.append("xhtml:div").style("position","absolute").style("left",`${.75*J}px`).style("top",`${.5*J}px`).style("width",`${.5*J}px`).style("height",`${.5*J}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass):n.image!==void 0&&d.append("xhtml:img").style("position","absolute").style("left",`${.75*J}px`).style("top",`${.5*J}px`).style("width",`${.5*J}px`).style("height",`${.5*J}px`).attr("src",n.image),d.append("xhtml:span").style("position","absolute").style("left",`${.2*J}px`).style("top",`${1.1*J}px`).style("text-align","center").style("width",`${1.6*J}px`).style("height",`${.35*J}px`).style("margin","0").style("font-size",`${.35*J}px`).style("font-weight","700").style("user-select","none").text(n.name),d.transition().ease(N.easeLinear).duration(To).tween("progress",()=>h=>{const u=c*h;return d.style("left",`${Math.sin(u)*ve-J+Mt}px`).style("top",`${-Math.cos(u)*ve-J+Mt}px`)})}}close(){var t;(t=this.contextMenuContainer)==null||t.remove(),this.contextMenuContainer=void 0}}class Mo extends vt{constructor(t,e=!0){super(),this.focus=void 0,this.canvas=t,this.highlightSections=e}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,(t instanceof mt||t instanceof Ai)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof j){if(!this.highlightSections)for(const e of t.sections){super.add(e);for(const o of e.ports)super.add(o),this.canvas.updatePortsInView(o.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateNodesInView(t.id)}else if(t instanceof U)if(!this.highlightSections&&t.node)this.add(t.node);else{for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}else t instanceof Ct?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof ht&&this.canvas.updateConnectionsInView(t.id)}clear(){for(;this.entities.length>0;){const t=this.entities[0];this.remove(t.id),t.updateInView()}this.focus=void 0}}const No=1;class Li{export(t,e=!1){const o={name:t.name,type:t.type,typeVersion:No,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(o.id=t.id),t.description&&(o.description=t.description);for(const a of t.nodes.all(!0))!e&&a.removed||a.parent===void 0&&o.nodes.push(this.exportNode(a,e));for(const a of t.connections.all(!0))!e&&a.removed||o.connections.push(this.exportConnection(a,e));return o}exportNode(t,e=!1){var s,n,r,c,d,h;const o=[];for(const u of t.children)o.push(this.exportNode(u,e));const a=[];for(const u of t.sections){const p=[];for(const m of u.ports)p.push({id:m.id,type:(s=m.type)==null?void 0:s.id,coords:$t(m.coords),connectionPoint:$t(m.connectionPoint),direction:m.direction,label:((n=m.label)==null?void 0:n.text)||"",...e?{collabMeta:{removed:m.removed,selfRemoved:m.selfRemoved,selfRemovedTimestamp:m.selfRemovedTimestamp,...this.exportLabelCollabMeta(m)}}:{}});a.push({id:u.id,ports:p,label:((r=u.label)==null?void 0:r.text)||"",indexXInNode:u.indexXInNode,indexYInNode:u.indexYInNode,coords:$t(u.coords),width:u.width,height:u.height,...e?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}})}const l=[];for(const u of t.ports)l.push({id:u.id,type:(c=u.type)==null?void 0:c.id,coords:$t(u.coords),connectionPoint:$t(u.connectionPoint),direction:u.direction,label:((d=u.label)==null?void 0:d.text)||"",...e?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}});return{id:t.id,type:t.type.id,children:o,sections:a,ports:l,label:((h=t.label)==null?void 0:h.text)||"",coords:$t(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){var o,a;return{id:t.id,type:t.type.id,start:((o=t.start)==null?void 0:o.id)||"",end:((a=t.end)==null?void 0:a.id)||"",startLabel:t.startLabel,middleLabel:t.middleLabel,endLabel:t.endLabel,points:t.points,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,dataTimestamps:t.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:t}){return t?{label:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,textTimestamp:t.textTimestamp}}:{}}}const Po="Diagram properties";class zo extends vt{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(At.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof j||t instanceof ht)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof U?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof j&&t.sections))for(const e of t.sections)super.add(e),e.updateInView()}remove(t){const e=this.get(t);if(e&&(this.propertyEditorSelection===e&&this.openInPropertyEditor(void 0),super.remove(t),e.updateInView(),e instanceof j&&e.sections))for(const o of e.sections)super.remove(o.id),o.updateInView()}toggle(t){this.contains(t.id)?this.remove(t.id):this.add(t)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const t=this.entities[0];super.remove(t.id),t.updateInView()}}move(t){for(const e of this.all())e instanceof j&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],o=[],a=[],l=[];for(const n of this.all())n instanceof j?t.push(n.id):n instanceof U?e.push(n.id):n instanceof Ct?o.push(n.id):n instanceof ht?a.push(n.id):n instanceof mt&&l.push(n.id);const s=new xo(this.canvas,t,e,o,a,l);s.do(),this.canvas.actionStack.add(s)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Li;for(const o of this.all())o instanceof j&&t.nodes.push(e.exportNode(o,!1)),o instanceof ht&&t.connections.push(e.exportConnection(o,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const o=JSON.parse(e);if(o.type!=="daga-user-selection")return;const a=new Co(this.canvas,o.nodes,o.connections,t);this.canvas.actionStack.add(a),a.do()}catch{return}})}openInPropertyEditor(t,e=!0){var l;e&&this.makeUpdateValuesAction();const o=(l=this.canvas.parentComponent)==null?void 0:l.propertyEditor;if(o===void 0)return;const a=t==null?void 0:t.valueSet;a?(this.propertyEditorSelection=t,e&&(this.propertyEditorValues=structuredClone(a.getValues())),o&&(t instanceof j||t instanceof ht?(t instanceof j?t.name?o.title=`${t.type.name}: ${t.name}`:o.title=t.type.name:t instanceof ht&&(o.title=t.type.name),o.valueSet=void 0,o.valueSet=a):(o.title=Po,o.valueSet=void 0,o.valueSet=a))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,o&&(o.title="",o.valueSet=void 0))}makeUpdateValuesAction(){var n,r,c;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof Ei?void 0:this.propertyEditorSelection.id;if(Et(this.propertyEditorValues,(n=this.propertyEditorSelection)==null?void 0:n.valueSet.getValues()))return;const e=this.propertyEditorValues,o=structuredClone((r=this.propertyEditorSelection)==null?void 0:r.valueSet.getValues()),[a,l]=vi(e,o,(c=this.propertyEditorSelection)==null?void 0:c.valueSet),s=new wo(this.canvas,t,a,l);s.do(),this.canvas.actionStack.add(s),this.propertyEditorValues=o}}const Ro=i=>i*Math.PI/180,hi=(i,t,e)=>{const o=Ro(e),a=Math.sin(o),l=Math.cos(o),s=(Math.abs(i*l)-Math.abs(t*a))/(l*l-a*a),n=(Math.abs(i*a)-Math.abs(t*l))/(a*a-l*l);return[s,n]},Vo=12,H=6,_o=25,ge="diagram-connection-unfinished",qt=class qt{constructor(t,e){var o,a,l,s,n,r,c,d,h,u,p,m,f,g,y,w,b,I,S,L,$,x,V,T,R,Y,O,K,F;if(this.backgroundPatternId=`daga-background-pattern-id-${qt.canvasCount++}`,this.zoomTransform=N.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new At.Subject,this.diagramChange$=new At.Subject,this.diagramEvent$=new At.Subject,this.propertyEditorChanges$=new At.Subject,this.parentComponent=t,this.model=new Ei(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new zo(this),this.userHighlight=new Mo(this,((o=e.canvas)==null?void 0:o.highlightSections)!==!1),this.contextMenu=new $o(this,(a=e.canvas)==null?void 0:a.contextMenu),this.backgroundColor=((l=e.canvas)==null?void 0:l.backgroundColor)||"#FFFFFF",this.gridStyle=((n=(s=e.canvas)==null?void 0:s.grid)==null?void 0:n.style)??Ot.style,this.gridSize=((c=(r=e.canvas)==null?void 0:r.grid)==null?void 0:c.enabled)===!1||((d=e.canvas)==null?void 0:d.grid)===void 0?0:Math.abs(((u=(h=e.canvas)==null?void 0:h.grid)==null?void 0:u.spacing)||Ot.spacing),this.gridThickness=Math.abs(((m=(p=e.canvas)==null?void 0:p.grid)==null?void 0:m.thickness)||Ot.thickness),this.gridColor=((g=(f=e.canvas)==null?void 0:f.grid)==null?void 0:g.color)||Ot.color,this.snapToGrid=((w=(y=e.canvas)==null?void 0:y.grid)==null?void 0:w.enabled)===!1||((b=e.canvas)==null?void 0:b.grid)===void 0?!1:((S=(I=e.canvas)==null?void 0:I.grid)==null?void 0:S.snap)||Ot.snap,this.zoomFactor=((L=e.canvas)==null?void 0:L.zoomFactor)||2,this.panRate=(($=e.canvas)==null?void 0:$.panRate)||100,this.inferConnectionType=((x=e.connectionSettings)==null?void 0:x.inferConnectionType)||!1,this.autoTightenConnections=((V=e.connectionSettings)==null?void 0:V.autoTighten)!==!1,this.allowConnectionLoops=((T=e.connectionSettings)==null?void 0:T.allowLoops)||!1,this.allowSharingPorts=((R=e.connectionSettings)==null?void 0:R.sharePorts)!==!1,this.allowSharingBothPorts=((Y=e.connectionSettings)==null?void 0:Y.shareBothPorts)||!1,this.portHighlightRadius=((O=e.connectionSettings)==null?void 0:O.portHighlightRadius)||100,this.multipleSelectionOn=!1,this.priorityThresholds=((K=e.canvas)==null?void 0:K.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new yo(this,_o),this.collabEngine=new vo(this),e.nodeTypes)for(const B of e.nodeTypes){const X=new ki({...e.nodeTypeDefaults,...B});this.model.nodes.types.add(X)}if(e.portTypes)for(const B of e.portTypes){const X=new mo({...e.portTypeDefaults,...B});this.model.ports.types.add(X)}if(e.connectionTypes){for(const B of e.connectionTypes){const X=new yi({...e.connectionTypeDefaults,...B});this.model.connections.types.add(X)}this._connectionType=((F=e==null?void 0:e.connectionSettings)==null?void 0:F.defaultConnection)!==void 0?this.model.connections.types.get(e.connectionSettings.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){var e,o;this._connectionType=t,(o=(e=this.parentComponent)==null?void 0:e.palette)==null||o.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){Z(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){var e,o;this.priorityThreshold=t,this.updateModelInView();for(const a of this.model.nodes)this.fitNodeInView(a.id);(o=(e=this.parentComponent)==null?void 0:e.palette)==null||o.refreshPalette()}initView(t){const e=N.select(t);e.html(""),this.diagramRoot=e.append("div").node(),N.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),N.select(this.diagramRoot).on(E.Click,()=>{var a;(a=N.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 kt(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 bt(a,null);this.diagramEvent$.next(l)}).on(E.KeyDown,a=>{if(!a.ctrlKey&&(a.key===et.Delete||a.key===et.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=[],s=[];for(const n of this.model.nodes)this.userSelection.toggle(n),n.selected?l.push(n):s.push(n);for(const n of this.model.connections)this.userSelection.toggle(n),n.selected?l.push(n):s.push(n);l.length>0&&this.diagramEvent$.next(new G(l,!0)),s.length>0&&this.diagramEvent$.next(new G(s,!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===et.ArrowLeft&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),a.key===et.ArrowRight&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),a.key===et.ArrowDown&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),a.key===et.ArrowUp&&this.canUserPerformAction(C.Zoom)&&(a.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%");o.call(this.zoomBehavior=N.zoom().filter(a=>a.type!==E.DoubleClick).on(ue.Zoom,a=>{if(a.sourceEvent){if(!this.canUserPerformAction(C.Zoom)){A(P.NotAllowed);return}a.sourceEvent.type===E.Wheel&&a.sourceEvent.wheelDelta!==void 0?(a.sourceEvent.wheelDelta>0&&A(P.ZoomIn),a.sourceEvent.wheelDelta<0&&A(P.ZoomOut)):a.sourceEvent.type===E.MouseMove&&A(P.AllScroll)}this.zoomTransform=a.transform;const l=a.transform.toString();this.selectCanvasElements().attr("transform",l),N.select(`#${this.backgroundPatternId}`).attr("patternTransform",l),this.contextMenu.close()}).on(ue.End,()=>{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(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 it(null)))}).on(E.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new it(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(N.drag().filter(a=>this.multipleSelectionOn||wt(a)).on(M.Start,a=>{this.startMultipleSelection(a)}).on(M.Drag,a=>{this.continueMultipleSelection(a)}).on(M.End,a=>{this.finishMultipleSelection(a)})),Eo(this,o,this.backgroundPatternId),o.append("g").attr("class","daga-canvas-elements")}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView(),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView(),t)}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView(),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView(),t,e)}center(){var t;if(this.model.nodes.length>0){const e=(t=this.selectCanvasView().select("rect").node())==null?void 0:t.getBBox(),o=this.model.nodes.all(),a=Math.min(...o.map(f=>f.coords[0])),l=Math.max(...o.map(f=>f.coords[0]+f.width)),s=(a+l)/2,n=l-a,r=e.width,c=Math.min(...o.map(f=>f.coords[1])),d=Math.max(...o.map(f=>f.coords[1]+f.height)),h=(c+d)/2,u=d-c,p=e.height,m=Math.min(r/n,p/u,1);this.translateTo(s,h),this.zoomTo(m)}}getClosestGridPoint(t){return this.gridSize===0||!isFinite(this.gridSize)?t:[Math.round(t[0]/this.gridSize)*this.gridSize,Math.round(t[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){var o;const t=(o=this.selectSVGElement().node())==null?void 0:o.getBoundingClientRect(),e=[(t==null?void 0:t.width)||0,(t==null?void 0:t.height)||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return N.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return N.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return N.pointer(this.getEventHoldingCoordinates(t),N.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=e.exit(),a=e.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}`);t&&t.length>0&&(e=e.filter(s=>t.includes(s.id)));const l=a.merge(e);o.remove(),a.on(E.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.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,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)),this.userSelection.add(n),this.diagramEvent$.next(new G([n],!0)),this.contextMenu.open(s))}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(s):this.startMovingNode(s,n)}).on(M.Drag,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(s):this.continueMovingNode(s,n)}).on(M.End,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(s):this.finishMovingNode(s,n),this.secondaryButton=!1})),de(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A(P.EWResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(A(P.EWResize),this.currentAction=new q(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(P.NotAllowed)}).on(M.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(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof q&&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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A(P.NSResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(A(P.NSResize),this.currentAction=new q(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(P.NotAllowed)}).on(M.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(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof q&&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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A(P.EWResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(A(P.EWResize),this.currentAction=new q(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(P.NotAllowed)}).on(M.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(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof q&&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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A(P.NSResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(A(P.NSResize),this.currentAction=new q(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(P.NotAllowed)}).on(M.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(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof q&&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),he(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/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",H/2).attr("y2",H/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",s=>s.width-H/2).attr("x2",s=>s.width-H/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-H/2).attr("y2",s=>s.height-H/2)}updateSectionsInView(...t){let e=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=e.exit(),a=e.enter().append("g").attr("id",s=>s.id).attr("class",s=>{var n;return`diagram-section${s.getResizableX()?" resizable-x":""}${s.getResizableY()?" resizable-y":""} ${(n=s.look)==null?void 0:n.lookType}`});t&&t.length>0&&(e=e.filter(s=>t.includes(s.id)));const l=a.merge(e);o.remove(),a.on(E.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}const r=ft(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const c=ft(n);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(s)}}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.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(P.NotAllowed)}}).on(M.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(P.NotAllowed)}}).on(M.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})),de(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&A(P.EWResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(A(P.EWResize),this.currentAction=new q(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const r=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Left,n.coords[0]-r[0],n.indexXInNode,n.indexYInNode)}}).on(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof q&&this.currentAction.intent===C.StretchSection&&n.node){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.node.stretchSections(k.Left,n.coords[0]-r[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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&A(P.NSResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(A(P.NSResize),this.currentAction=new q(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const r=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Top,n.coords[1]-r[1],n.indexXInNode,n.indexYInNode)}}).on(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof q&&this.currentAction.intent===C.StretchSection&&n.node){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.node.stretchSections(k.Top,n.coords[1]-r[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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&A(P.EWResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(A(P.EWResize),this.currentAction=new q(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const r=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Right,r[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof q&&this.currentAction.intent===C.StretchSection&&n.node){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.node.stretchSections(k.Right,r[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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&A(P.NSResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(A(P.NSResize),this.currentAction=new q(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const r=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Bottom,r[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof q&&this.currentAction.intent===C.StretchSection&&n.node){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.node.stretchSections(k.Bottom,r[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),he(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/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",H/2).attr("y2",H/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",s=>s.width-H/2).attr("x2",s=>s.width-H/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-H/2).attr("y2",s=>s.height-H/2)}updatePortsInView(...t){let e=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=e.exit(),a=e.enter().append("g").attr("id",s=>s.id).attr("class",s=>`diagram-port ${s.look.lookType}`);t&&t.length>0&&(e=e.filter(s=>t.includes(s.id)));const l=a.merge(e);o.remove(),a.on(E.MouseOver,(s,n)=>{var r,c,d,h,u,p,m,f,g,y,w,b;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((d=(c=(r=this.unfinishedConnection.start)==null?void 0:r.getNode())==null?void 0:c.type)==null?void 0:d.id)||"")&&((h=this.unfinishedConnection.start)!=null&&h.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((p=(u=n.getNode())==null?void 0:u.type)==null?void 0:p.id)||"")&&n.allowsIncoming||this.unfinishedConnection.type.canStartFromType(((f=(m=n.getNode())==null?void 0:m.type)==null?void 0:f.id)||"")&&n.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(((w=(y=(g=this.unfinishedConnection.start)==null?void 0:g.getNode())==null?void 0:y.type)==null?void 0:w.id)||"")&&((b=this.unfinishedConnection.start)!=null&&b.allowsIncoming)||A(P.NoDrop))}).on(E.MouseOut,()=>{this.unfinishedConnection&&A(P.Grabbing)}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}const r=ft(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const c=ft(n);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(s)}}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(s):this.canUserPerformAction(C.AddConnection)&&(this.allowSharingPorts||n.incomingConnections.length===0&&n.outgoingConnections.length===0)&&!n.removed?(A(P.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{var r,c,d,h;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else if(this.canUserPerformAction(C.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const u=[s.x,s.y];(d=this.unfinishedConnectionTracer)==null||d.attr("d",ce(this.unfinishedConnection.look.shape||ot.look.shape,this.unfinishedConnection.startCoords,u,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.look.thickness||ot.look.thickness,(r=this.unfinishedConnection.startMarkerLook)==null?void 0:r.width,(c=this.unfinishedConnection.endMarkerLook)==null?void 0:c.width));const p=(h=this.unfinishedConnectionTracer)==null?void 0:h.node();if(p){let m=2;const f=p.getTotalLength();f<m&&(m=0);const g=p.getPointAtLength(f-m);this.unfinishedConnection.endCoords=[g.x,g.y]}else this.unfinishedConnection.endCoords=u;if(this.updateConnectionsInView(ge),this.model.ports.length>0){const m=this.getPointerLocationRelativeToCanvas(s);let f=Number.POSITIVE_INFINITY,g;for(const y of this.model.ports){const w=y.distanceTo(m);w<f&&(f=w,g=y)}g&&f<this.portHighlightRadius?this.userHighlight.focusOn(g):this.userHighlight.clear()}}}).on(M.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 c=this.userHighlight.getFocus();if(c instanceof Ct)this.finishConnection(c);else if(c instanceof mt&&c.rootElement instanceof Ct)this.finishConnection(c.rootElement);else if(c instanceof j||c instanceof U||c instanceof mt){let d;if(c instanceof j||c instanceof U)d=c;else if(c.rootElement instanceof j||c.rootElement instanceof U)d=c.rootElement;else{this.dropConnection();return}const h=d.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"),de(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),he(l)}updateConnectionsInView(...t){const e=this.model.connections.filter(n=>this.priorityThreshold!==void 0?n.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let o=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,n=>n.id);const a=o.exit(),l=o.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");t&&t.length>0&&(o=o.filter(n=>t.includes(n.id)));const s=l.merge(o);a.remove(),l.on(E.MouseOver,(n,r)=>{r.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new it(r)))}).on(E.Click,(n,r)=>{if(!n.ctrlKey&&!n.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!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 c=new kt(n,r);this.diagramEvent$.next(c),!c.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new it(r)),this.userSelection.add(r),this.diagramEvent$.next(new G([r],!0)),this.contextMenu.open(n))}).on(E.DoubleClick,(n,r)=>{const c=new bt(n,r);this.diagramEvent$.next(c)}).call(N.drag().filter(n=>(this.secondaryButton=wt(n),!0)).on(M.Start,n=>{this.startMultipleSelection(n)}).on(M.Drag,n=>{this.continueMultipleSelection(n)}).on(M.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,c;return ce(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness||ot.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(c=n.endMarkerLook)==null?void 0:c.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||ot.look.color).attr("stroke-width",n=>`${n.look.thickness}px`).attr("stroke-dasharray",n=>me(n.look.style||ot.look.style,n.look.thickness||ot.look.thickness)).attr("fill","none"),s.select("path.diagram-connection-path-box").attr("d",n=>{var r,c;return ce(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness||ot.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(c=n.endMarkerLook)==null?void 0:c.width)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",n=>`${(n.look.thickness||ot.look.thickness)+Vo}px`).attr("stroke-dasharray",n=>me(n.look.style||ot.look.style,n.look.thickness||ot.look.thickness)).attr("fill","none"),s.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...t){let e=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=e.exit(),a=e.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(s=>t.includes(s.id)));const l=a.merge(e);o.remove(),a.style("box-sizing","border-box").on(E.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}const r=ft(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const c=ft(n);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(s)}}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.EditField)&&n.editable&&!n.removed&&(this.currentAction=new ci(this,n.id,n.text,""),this.createInputField(n.text,n.coords,n.width,n.height,n.fontSize,n.fontFamily||D.fontFamily,n.orientation,c=>{},c=>{n.text=c,this.currentAction instanceof ci&&(this.currentAction.to=c,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.startMovingNode(s,r):A(P.NotAllowed)}}).on(M.Drag,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.continueMovingNode(s,r):A(P.NotAllowed)}}).on(M.End,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(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===Nt.Center?"center":s.horizontalAlign===Nt.Right?"flex-end":"flex-start").style("align-items",s=>s.verticalAlign===Zt.Center?"center":s.verticalAlign===Zt.Bottom?"end":"start").select("p").style("max-width",s=>s.fit?"default":`${hi(s.width,s.height,s.orientation)[0]}px`).style("max-height",s=>s.fit?"default":`${hi(s.width,s.height,s.orientation)[1]}px`).style("overflow",s=>s.fit?"default":"clip").style("text-overflow",s=>s.fit?"default":"ellipsis").style("text-align",s=>s.horizontalAlign===Nt.Center?"center":s.horizontalAlign===Nt.Right?"end":"start").style("transform",s=>`rotate(${s.orientation}deg)`).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(...t){let e=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=e.exit(),a=e.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(s=>t.includes(s.id))),a.merge(e).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(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.contextMenu.open(s))}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,s=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(s)}).on(M.Drag,s=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(s)}).on(M.End,s=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(s)}))}updateDecoratorsInView(...t){let e=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=e.exit(),a=e.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(s=>t.includes(s.id))),a.merge(e).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(E.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(r,!1))}if(n.rootElement){const r=ft(n.rootElement);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}}).on(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&n.rootElement){s.preventDefault();const c=ft(n.rootElement);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(s)}}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.startMovingNode(s,r):A(P.NotAllowed)}}).on(M.Drag,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.continueMovingNode(s,r):A(P.NotAllowed)}}).on(M.End,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.finishMovingNode(s,r):A()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){var s,n,r;const e=this.selectCanvasView().select(`[id='${fe(t.id)}']`),a=e.select("path").node(),l={...D,...t.type.label};if(a){const c=a.getTotalLength();let d=0,h=0,u=0,p=0,m=0,f=0;if(l.backgroundColor==="#00000000"){const b=t.endCoords[0]-t.startCoords[0],I=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case k.Top:d=b>=0?1:-1,u=d,m=d,h=-1;break;case k.Bottom:d=b>=0?1:-1,u=d,m=d,h=1;break;case k.Left:d=-1,h=I>0?1:-1,p=h,f=h;break;case k.Right:d=1,h=I>0?1:-1,p=h,f=h;break;default:d=1,u=d,m=d,h=-1,p=h,f=h}switch(t.endDirection){case k.Top:m=b>=0?1:-1,u=m,f=1;break;case k.Bottom:m=b>=0?1:-1,u=m,f=-1;break;case k.Left:m=-1,f=I>0?1:-1,p=f;break;case k.Right:m=1,f=I>0?1:-1,p=f;break;default:m=1,u=m,f=-1,p=f}}e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.startLabel);const g=(s=e.select("g.diagram-connection-start-label text").node())==null?void 0:s.getBoundingClientRect();if(g){const b=t.startLabel?g.width/this.zoomTransform.k+Ft(l)+Ht(l):0,I=t.startLabel?g.height/this.zoomTransform.k+Gt(l)+Dt(l):0,S=a.getPointAtLength(Math.max(Q(l)+b/2,lt(l)+b/2,W(l)+I/2,st(l)+I/2));e.select("g.diagram-connection-start-label path").attr("d",Wt(-b/2,-I/2,b,I)).attr("fill",l.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${S.x+d*b},${S.y+h*I})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.middleLabel);const y=(n=e.select("g.diagram-connection-middle-label text").node())==null?void 0:n.getBoundingClientRect();if(y){const b=t.middleLabel?y.width/this.zoomTransform.k+Ft(l)+Ht(l):0,I=t.middleLabel?y.height/this.zoomTransform.k+Gt(l)+Dt(l):0,S=a.getPointAtLength(c/2);e.select("g.diagram-connection-middle-label path").attr("d",Wt(-b/2,-I/2,b,I)).attr("fill",l.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${S.x+u*b},${S.y+p*I})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.endLabel);const w=(r=e.select("g.diagram-connection-end-label text").node())==null?void 0:r.getBoundingClientRect();if(w){const b=t.endLabel?w.width/this.zoomTransform.k+Ft(l)+Ht(l):0,I=t.endLabel?w.height/this.zoomTransform.k+Gt(l)+Dt(l):0,S=a.getPointAtLength(c-Math.max(Q(l)+b/2,lt(l)+b/2,W(l)+I/2,st(l)+I/2));e.select("g.diagram-connection-end-label path").attr("d",Wt(-b/2,-I/2,b,I)).attr("fill",l.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${S.x+m*b},${S.y+f*I})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${fe(t.id)}']`),o=e.select("marker.diagram-connection-start-marker"),a=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?o.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.width).attr("markerHeight",t.startMarkerLook.height).attr("refX",t.startMarkerLook.refX).attr("refY",t.startMarkerLook.refY).select("image").attr("href",t.startMarkerLook.image).attr("width",t.startMarkerLook.width).attr("height",t.startMarkerLook.height):o.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.width).attr("markerHeight",t.endMarkerLook.height).attr("refX",t.endMarkerLook.refX).attr("refY",t.endMarkerLook.refY).select("image").attr("href",t.endMarkerLook.image).attr("width",t.endMarkerLook.width).attr("height",t.endMarkerLook.height):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){var o,a,l,s;const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof j||e.rootElement instanceof U){const n=this.minimumSizeOfField(e),r=n[0]+Q((o=e.rootElement.type)==null?void 0:o.label)+lt((a=e.rootElement.type)==null?void 0:a.label)-e.rootElement.width,c=n[1]+W((l=e.rootElement.type)==null?void 0:l.label)+st((s=e.rootElement.type)==null?void 0:s.label)-e.rootElement.height;return r<=0&&c<=0}return!0}fitFieldRootInView(t,e=!0){var a,l,s;const o=this.model.fields.get(t);if(o){if(o.rootElement instanceof j){const n=this.minimumSizeOfField(o);let r=n[0]+Q(o.rootElement.type.label)+lt(o.rootElement.type.label)-o.rootElement.width,c=n[1]+W(o.rootElement.type.label)+st(o.rootElement.type.label)-o.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,c=Math.ceil(c/this.gridSize)*this.gridSize),o.rootElement.width+r<o.rootElement.type.minWidth&&(r=o.rootElement.type.minWidth-o.rootElement.width),o.rootElement.height+c<o.rootElement.type.minHeight&&(c=o.rootElement.type.minHeight-o.rootElement.height),(e!==!1||r>0)&&o.rootElement.stretch(k.Right,r),(e!==!1||c>0)&&o.rootElement.stretch(k.Bottom,c)}if(o.rootElement instanceof U){const n=this.minimumSizeOfField(o);let r=n[0],c=n[1];for(const p of((a=o.rootElement.node)==null?void 0:a.sections)||[])p.label&&(p.indexXInNode===o.rootElement.indexXInNode&&p.indexYInNode!==o.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(p.label)[0]):p.indexXInNode!==o.rootElement.indexXInNode&&p.indexYInNode===o.rootElement.indexYInNode&&(c=Math.max(c,this.minimumSizeOfField(p.label)[1])));n[0]<r&&(n[0]=r),n[1]<c&&(n[1]=c);const d=o.rootElement.type;let h=n[0]+Q(d==null?void 0:d.label)+lt(d==null?void 0:d.label)-o.rootElement.width,u=n[1]+W(d==null?void 0:d.label)+st(d==null?void 0:d.label)-o.rootElement.height;this.snapToGrid&&(h=Math.ceil(h/this.gridSize)*this.gridSize,u=Math.ceil(u/this.gridSize)*this.gridSize),o.rootElement.width+h<(o.rootElement.getMinWidth()||0)&&(h=(o.rootElement.getMinWidth()||0)-o.rootElement.width),o.rootElement.height+u<(o.rootElement.getMinHeight()||0)&&(u=(o.rootElement.getMinHeight()||0)-o.rootElement.height),(e||h>0)&&((l=o.rootElement.node)==null||l.stretchSections(k.Right,h,o.rootElement.indexXInNode,o.rootElement.indexYInNode)),(e||u>0)&&((s=o.rootElement.node)==null||s.stretchSections(k.Bottom,u,o.rootElement.indexXInNode,o.rootElement.indexYInNode))}}}fitNodeInView(t,e=!0){var a,l;const o=this.model.nodes.get(t);if(o&&o.sections.length>0&&this.priorityThreshold){let s=0,n=0;for(const r of o.sections)if(r.getPriority()>=this.priorityThreshold){const c=r.coords[0]+r.width-o.coords[0],d=r.coords[1]+r.height-o.coords[1];s=Math.max(s,c),n=Math.max(n,d)}s+=((a=o.type.sectionGrid)==null?void 0:a.margin)||0,n+=((l=o.type.sectionGrid)==null?void 0:l.margin)||0,(e||s>o.width)&&o.stretch(k.Right,s-o.width),(e||n>o.height)&&o.stretch(k.Bottom,n-o.height)}}selectRoot(){return N.select(this.diagramRoot)}selectSVGElement(){return N.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){var e,o,a,l;if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(((o=(e=t.getNode())==null?void 0:e.type)==null?void 0:o.id)||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(((l=(a=t.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&t.allowsIncoming))this.unfinishedConnection=new ht(this.model,this.connectionType,t,void 0,ge);else if(this.inferConnectionType){let s=this.model.connections.types.all().find(n=>{var r,c;return t.allowsOutgoing&&n.canStartFromType(((c=(r=t.getNode())==null?void 0:r.type)==null?void 0:c.id)||"")});s===void 0&&(s=this.model.connections.types.all().find(n=>{var r,c;return t.allowsIncoming&&n.canFinishOnType(((c=(r=t.getNode())==null?void 0:r.type)==null?void 0:c.id)||"")})),s!==void 0&&(this.unfinishedConnection=new ht(this.model,s,t,void 0,ge))}}}finishConnection(t){var e,o,a,l,s,n,r,c,d,h,u,p,m,f,g,y,w,b,I,S;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0){if(!this.allowConnectionLoops&&this.unfinishedConnection.start===t){this.dropConnection();return}if(!this.allowSharingPorts&&(t.incomingConnections.length>0||t.outgoingConnections.length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(L=>{var $,x;return L.start===(($=this.unfinishedConnection)==null?void 0:$.start)&&L.end===t||L.end===((x=this.unfinishedConnection)==null?void 0:x.start)&&L.start===t})!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(((l=(a=(o=(e=this.unfinishedConnection)==null?void 0:e.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(((c=(r=t.getNode())==null?void 0:r.type)==null?void 0:c.id)||"")&&t.allowsIncoming){const L=new le(this,this.unfinishedConnection.type,(d=this.unfinishedConnection.start)==null?void 0:d.id,t.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.unfinishedConnection.type.canFinishOnType(((m=(p=(u=(h=this.unfinishedConnection)==null?void 0:h.start)==null?void 0:u.getNode())==null?void 0:p.type)==null?void 0:m.id)||"")&&((g=(f=this.unfinishedConnection)==null?void 0:f.start)!=null&&g.allowsIncoming)&&this.unfinishedConnection.type.canStartFromType(((w=(y=t.getNode())==null?void 0:y.type)==null?void 0:w.id)||"")&&t.allowsOutgoing){const L=new le(this,this.unfinishedConnection.type,t.id,(b=this.unfinishedConnection.start)==null?void 0:b.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.inferConnectionType){let L=this.model.connections.types.all().find(x=>{var V,T,R,Y,O,K,F,B;return x.canStartFromType(((Y=(R=(T=(V=this.unfinishedConnection)==null?void 0:V.start)==null?void 0:T.getNode())==null?void 0:R.type)==null?void 0:Y.id)||"")&&((K=(O=this.unfinishedConnection)==null?void 0:O.start)==null?void 0:K.allowsOutgoing)&&x.canFinishOnType(((B=(F=t.getNode())==null?void 0:F.type)==null?void 0:B.id)||"")&&t.allowsIncoming}),$=!1;if(L===void 0&&(L=this.model.connections.types.all().find(x=>{var V,T,R,Y,O,K,F,B;return x.canFinishOnType(((Y=(R=(T=(V=this.unfinishedConnection)==null?void 0:V.start)==null?void 0:T.getNode())==null?void 0:R.type)==null?void 0:Y.id)||"")&&((K=(O=this.unfinishedConnection)==null?void 0:O.start)==null?void 0:K.allowsIncoming)&&x.canStartFromType(((B=(F=t.getNode())==null?void 0:F.type)==null?void 0:B.id)||"")&&t.allowsOutgoing}),$=!0),L!==void 0){const x=new le(this,L,$?t.id:(I=this.unfinishedConnection.start)==null?void 0:I.id,$?(S=this.unfinishedConnection.start)==null?void 0:S.id:t.id);this.dropConnection(),x.do(),this.actionStack.add(x)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){var t,e,o,a;(t=this.unfinishedConnection)==null||t.setStart(void 0),(e=this.unfinishedConnection)==null||e.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(t){return this.userActions[t]!==!1}createInputField(t,e,o,a,l,s,n,r,c){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${o}px`).attr("height",`${a}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const h=d.append("xhtml:textarea");let u,p;h.text(t).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(E.KeyDown,f=>{f.stopPropagation()}).on(E.KeyUp,f=>{if(f.stopPropagation(),f.key===et.Escape){const g=h.property("value");this.removeInputField(),c&&c(g)}}).on(E.Input,()=>{const f=h.property("value");h.attr("cols",Wi(f)+1),h.attr("rows",Zi(f)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,p=h.property("scrollHeight")+1;const g=Math.max(u,o),y=Math.max(p,a);d==null||d.attr("width",`${g}px`),h.style("width",`${g}px`),d==null||d.attr("height",`${y}px`),h.style("height",`${y}px`),r&&r(f)}).on(E.Click,f=>{f.stopPropagation()}).on(E.FocusOut,()=>{const f=h.property("value");this.removeInputField(),c&&c(f)});const m=h.node();m.focus(),m.select()}removeInputField(){var t,e,o;(e=(t=this.inputFieldContainer)==null?void 0:t.select("input"))==null||e.on(E.Blur,null),(o=this.inputFieldContainer)==null||o.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){var a,l;const e=(l=(a=t.select())==null?void 0:a.select("p"))==null?void 0:l.node();if(!e)return[0,0];const o=e.getBoundingClientRect();return[o.width/this.zoomTransform.k,o.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(C.MoveNode)&&!e.removed)if(A(P.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(o=>o instanceof j)>1)this.currentAction=new ae(this,this.userSelection.filter(o=>o instanceof j).map(o=>o.id),e.coords);else{const o=e.getLastAncestor();this.currentAction=new q(this,C.MoveNode,e.id,e.getGeometry(),e.getGeometry(),o==null?void 0:o.id,o==null?void 0:o.getGeometry(e.id),o==null?void 0:o.getGeometry(e.id))}else A(P.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(C.MoveNode)&&(this.currentAction instanceof ae||this.currentAction instanceof q)&&!e.removed){const o=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([o[0]-e.coords[0],o[1]-e.coords[1]]):e.move(o),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){var o,a,l;if(this.canUserPerformAction(C.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let s=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(s=this.getClosestGridPoint(s)),this.currentAction instanceof ae){const n=this.currentAction.delta;this.currentAction.delta=[s[0]-n[0],s[1]-n[1]],e.selected?this.userSelection.move([n[0]-e.coords[0],n[1]-e.coords[1]]):e.move(n)}else if(this.currentAction instanceof q){e.move(s);const r=this.model.nodes.getAtCoordinates(t.x,t.y).filter(h=>h.id!==e.id&&!h.isDescendantOf(e)).filter(h=>h.type.childrenTypes.includes(e.type.id)),c=wi(r),d=c[c.length-1];if(d!==e.parent&&(e.type.canBeParentless||d!==void 0)){const h=d==null?void 0:d.getLastAncestor(),u=this.currentAction.from,p=new ko(this,e.id,(o=e.parent)==null?void 0:o.id,d==null?void 0:d.id,u,e.getGeometry(),h==null?void 0:h.id,h==null?void 0:h.getGeometry(e.id),h==null?void 0:h.getGeometry(e.id));(a=e.parent)==null||a.removeChild(e),d!==void 0&&d.addChild(e),p.toChildGeometry=e.getGeometry(e.id),p.toAncestorGeometry=h==null?void 0:h.getGeometry(e.id),this.currentAction=p}else{const h=e==null?void 0:e.getLastAncestor();this.currentAction.ancestorId=h==null?void 0:h.id,this.currentAction.fromAncestorGeometry=h==null?void 0:h.getGeometry(e.id),(l=e.parent)==null||l.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=h==null?void 0:h.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}A(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectSVGElement().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){var o,a,l,s;const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(A(P.Crosshair),(s=(l=(a=(o=this.multipleSelectionContainer)==null?void 0:o.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x))==null?void 0:a.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y))==null?void 0:l.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k))==null||s.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){var o;const e=this.getPointerLocationRelativeToCanvas(t);(o=this.multipleSelectionContainer)==null||o.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)ji([a.coords,[a.coords[0]+a.width,a.coords[1]+a.height]],[this.draggingFrom,e])&&this.userSelection.add(a);this.multipleSelectionOn=!1,this.diagramEvent$.next(new G(this.userSelection.all(),!0)),A()}};qt.canvasCount=0;let ye=qt;class Ti{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const t of this.grid)t.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const t of this.grid)t.push(void 0)}addRowTop(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.splice(0,0,t),this.offsetY=this.offsetY+1}addRowBottom(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.push(t)}get(t){if(this.grid[t[1]+this.offsetY])return this.grid[t[1]+this.offsetY][t[0]+this.offsetX]}set(t,e){for(;t[0]<-this.offsetX;)this.addColumnLeft();for(;t[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;t[1]<-this.offsetY;)this.addRowTop();for(;t[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[t[1]+this.offsetY][t[0]+this.offsetX]=e}getClosestEmptyCoordinate(t){if(this.get(t)===void 0)return t;const e=[...t];for(let o=1;;++o){const a=o%2>0?o:-o,l=a>0?1:-1,s=[e[0]+a,e[1]+a];for(let n=e[0];n!==s[0]+l;n+=l)if(e[0]=n,this.get(e)===void 0)return e;for(let n=e[1];n!==s[1]+l;n+=l)if(e[1]=n,this.get(e)===void 0)return e}}}class jo{constructor(t){this.gapSize=t}apply(t){var n;if(t.nodes.length===0)return t;const e=new Ti,o=t.nodes.filter(r=>!r.parent);for(;o.length>0;)$i(o[0],e,[0,0],o);const a=Math.max(...t.nodes.map(r=>r.width)),l=Math.max(...t.nodes.map(r=>r.height)),s=this.gapSize!==void 0?this.gapSize:(((n=t.canvas)==null?void 0:n.gridSize)||0)*2;for(let r=e.minY();r<=e.maxY();++r)for(let c=e.minX();c<=e.maxX();++c){const d=e.get([c,r]);d!==void 0&&d.move([c*(a+s),r*(l+s)])}return t}}const $i=(i,t,e,o)=>{const a=t.getClosestEmptyCoordinate(e);t.set(a,i),Z(o,i);for(const l of i.getAdjacentNodes())o.includes(l)&&$i(l,t,a,o)};class Oo{constructor(t){this.gapSize=t}apply(t){var d;if(t.nodes.length===0)return t;const e=new Ti,o=t.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 u of s){e.set(e.getClosestEmptyCoordinate(a[u.id]),u),Z(o,u);const p=u.getAdjacentNodes();for(const m of p)o.includes(m)&&(h.push(m),a[m.id]=a[u.id])}if(h.length>0)s=h;else if(o.length>0){const u=o[0];s=[u],a[u.id]=e.getClosestEmptyCoordinate([0,0])}}const n=Math.max(...t.nodes.map(h=>h.width)),r=Math.max(...t.nodes.map(h=>h.height)),c=this.gapSize!==void 0?this.gapSize:(((d=t.canvas)==null?void 0:d.gridSize)||0)*2;for(let h=e.minY();h<=e.maxY();++h)for(let u=e.minX();u<=e.maxX();++u){const p=e.get([u,h]);p!==void 0&&p.move([u*(n+c),h*(r+c)])}return t}}class se{constructor(t){this.gapSize=t}apply(t){var n;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((n=t.canvas)==null?void 0:n.gridSize)||0)*2;let o=t.nodes.filter(r=>!r.parent);const a=o[0];Z(o,a);const l=[[a]];for(;o.length>0;){const r=l[l.length-1],c=[];for(const d of r){const h=d.getAdjacentNodes();for(const u of h)o.includes(u)&&(Z(o,u),c.push(u))}c.length>0?l.push(c):(l.push(o),o=[])}let s=0;for(const r of l){let c=0;for(const h of r)h.move([s,c]),c+=e+h.height;const d=Math.max(...r.map(h=>h.width));s+=e+d}for(const r of t.connections)r.tighten();return t}}class Do{constructor(t){this.gapSize=t}apply(t){var h;if(t.nodes.length===0)return t;new se(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,o=.99,a=1,l=.1,s=2e5,n=.5,r=1,c=.002;let d=100;for(;d>a;){d=d*o;const u=[0,0];{for(const p of t.nodes)u[0]=u[0]+p.coords[0]+p.width/2,u[1]=u[1]+p.coords[1]+p.width/2;u[0]=u[0]/t.nodes.length,u[1]=u[1]/t.nodes.length}for(const p of t.nodes){const m=p.getAdjacentNodes();for(const f of t.nodes){const g=[p.coords[0]+p.width/2,p.coords[1]+p.height/2],y=[f.coords[0]+f.width/2,f.coords[1]+f.height/2],w=fi(p.coords,f.coords),b=[f.coords[0],f.coords[1]];if(m.includes(f)&&w>0&&(w>e+(Math.max(p.width,p.height)+Math.max(f.width,f.height))/2?(b[0]=b[0]-(y[0]-g[0])*l,b[1]=b[1]-(y[1]-g[1])*l):(b[0]=b[0]+(y[0]-g[0])*n,b[1]=b[1]+(y[1]-g[1])*n)),w>0){const I=s/(w*w);b[0]=b[0]+I*(y[0]-g[0])/w,b[1]=b[1]+I*(y[1]-g[1])/w}else b[0]=b[0]+r*(Math.random()*2-1),b[1]=b[1]+r*(Math.random()*2-1);b[0]=b[0]-(y[0]-u[0])*c,b[1]=b[1]-(y[1]-u[1])*c,b[0]-f.coords[0]>d?b[0]=f.coords[0]+d:b[0]-f.coords[0]<-d&&(b[0]=f.coords[0]-d),b[1]-f.coords[1]>d?b[1]=f.coords[1]+d:b[1]-f.coords[1]<-d&&(b[1]=f.coords[1]-d),f.move(b)}}}if(t.canvas&&t.canvas.snapToGrid)for(const u of t.nodes){const p=t.canvas.getClosestGridPoint(u.coords);u.move(p)}for(const u of t.connections)u.tighten();return t}}class Fo{constructor(t){this.gapSize=t}apply(t){var l;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,o=t.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+e;return t}}class Ho{constructor(t){this.gapSize=t}apply(t){var d;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(h=>h.getPriority())),o=Math.min(...t.nodes.map(h=>h.getPriority()));if(e===o)return new se(this.gapSize).apply(t),t;const a=this.gapSize!==void 0?this.gapSize:(((d=t.canvas)==null?void 0:d.gridSize)||0)*2,l=t.nodes.filter(h=>!h.parent),s=[],n=t.nodes.filter(h=>!h.parent).filter(h=>h.getPriority()>=e),r=[];if(n.length>1){const h=n[0];n.splice(0,1),r.push(h);const u=[h],p=[h];for(;u.length>0;){const m=u[0];u.splice(0,1),n.includes(m)&&(r.push(m),Z(n,m));const f=m.getAdjacentNodes();for(const g of f)p.includes(g)||(u.push(g),p.push(g))}for(const m of n)r.push(m)}else r.push(n[0]);for(const h of r)Z(l,h),s.push([h]);for(s.push([]),l.sort((h,u)=>u.type.priority-h.type.priority);l.length>0;){const h=l[0];l.splice(0,1);const u=[h],p=[h];let m=!1;for(;u.length>0;){const f=u[0];u.splice(0,1);const g=r.indexOf(f);if(g>=0){s[g].push(h),m=!0;break}else{const y=f.getAdjacentNodes();for(const w of y)p.includes(w)||(u.push(w),p.push(w))}}m||s[s.length-1].push(h)}let c=0;for(let h=0;h<s.length;++h){let u=0;for(let m=0;m<s[h].length;++m){const f=s[h][m];f.move([c,u]),u+=a+f.height}const p=Math.max(...s[h].map(m=>m.width));c+=a+p}for(const h of t.connections)h.tighten();return t}}class Go{constructor(t){this.gapSize=t}apply(t){var d;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(h=>h.getPriority())),o=Math.min(...t.nodes.map(h=>h.getPriority()));if(e===o)return new se(this.gapSize).apply(t),t;const a=this.gapSize!==void 0?this.gapSize:(((d=t.canvas)==null?void 0:d.gridSize)||0)*2,l=t.nodes.filter(h=>!h.parent).sort((h,u)=>u.getPriority()-h.getPriority()),s=[];for(;l.length>0;){const h=l[0];l.splice(0,1);const u=new xe(void 0,h);Mi(u,l),s.push(u)}const n=[];for(const h of s)n.push([h]),Ni(h,n,n.length);const r=Math.max(...t.nodes.map(h=>h.height));let c=0;for(let h=0;h<n.length;++h){let u=0;for(let m=0;m<n[h].length;++m){const f=n[h][m];f.node.move([c,u]),u+=(a+r)*f.countBranchHeight()}const p=Math.max(...n[h].map(m=>m.node.width));c+=a+p}for(const h of t.connections)h.tighten();return t}}const Mi=(i,t)=>{for(const e of i.node.getAdjacentNodes().sort((o,a)=>a.getPriority()-o.getPriority())){const o=t.indexOf(e);if(o>=0){t.splice(o,1);const a=i.addBranch(e);Mi(a,t)}}},Ni=(i,t,e)=>{if(i.branches.length>0){for(;e>=t.length;)t.push([]);for(const o of i.branches)t[e].push(o),Ni(o,t,e+1)}};class xe{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new xe(this,t);return e.depth=this.depth+1,this.branches.push(e),e}countBranchHeight(){if(this.branches.length<=0)return 1;{let t=0;for(const e of this.branches)t+=e.countBranchHeight();return t}}}class Bo{constructor(t){this.gapSize=t}apply(t){var l;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,o=t.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+e;return t}}const gi={adjacency:new jo,breadth:new se,"breadth-adjacency":new Oo,force:new Do,horizontal:new Fo,priority:new Ho,tree:new Go,vertical:new Bo},Uo=z.createContext({}),Lt=z.createContext({});class Yo{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){}}const Ce=({direction:i,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:o,disabled:a,rule:l,collapsedValue:s,visibleValue:n,onCollapse:r})=>{const[c,d]=z.useState(o),h=()=>{if(!a){const p=!c;d(p),r==null||r(p);let m;if(typeof t=="string")m=N.select(t),e&&(m=m.select(e));else{const f=t;if(!f)throw new Error("collapsableSelector is not a valid ref");m=N.select(f.current),e&&(m=m.select(e))}m.style(l,p?s:n)}},u=()=>{switch(i){case k.Right:return a?"daga-horizontal-none":c?"daga-horizontal-right":"daga-horizontal-left";case k.Bottom:return a?"daga-vertical-none":c?"daga-vertical-down":"daga-vertical-up";case k.Left:return a?"daga-horizontal-none":c?"daga-horizontal-left":"daga-horizontal-right";case k.Top:return a?"daga-vertical-none":c?"daga-vertical-up":"daga-vertical-down"}};return v.jsx("daga-collapse-button",{children:v.jsx("button",{className:`daga-collapse-button daga-${i}`,onClick:h,children:v.jsx("div",{className:u()})})})},Xo=()=>{const i=z.useContext(Lt),t=z.useRef(null),[e,o]=z.useState([]);At.merge(i.validatorChange$,i.diagramChange$).pipe(At.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,c,d;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(),(d=(c=i.parentComponent)==null?void 0:c.propertyEditor)==null||d.highlightProperty(...s.propertyNames))};return v.jsx("daga-errors",{children:v.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&v.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:v.jsx("span",{children:"No errors found"})}),e.length>0&&v.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[v.jsxs("span",{children:[e.length," errors found"]}),v.jsx("div",{className:"daga-collapse-button-container",children:v.jsx(Ce,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:k.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&v.jsx("div",{className:"daga-error-panel",children:v.jsx("ol",{children:e.map((s,n)=>v.jsx("li",{onClick:()=>l(s),dangerouslySetInnerHTML:{__html:s.message}},n))})})]})})},Wo=200,ui=i=>(i||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),Pi=({disabled:i,options:t,value:e,onChange:o})=>{const a=z.useRef(null),[l,s]=z.useState("");let n;const[r,c]=z.useState([]),[d,h]=z.useState([]),[u,p]=z.useState([]),[m,f]=z.useState([]),[g,y]=z.useState(!1);z.useEffect(()=>{var T;s(((T=t.find(R=>Et(R.key,e)))==null?void 0:T.label)||"")},[e,t]);const w=T=>{if(!i)switch(T.key){case et.PageDown:n===void 0?(S(0),$(0)):(S(n+5),$(n)),T.preventDefault();break;case et.ArrowDown:n===void 0?(S(0),$(0)):(S(n+1),$(n)),T.preventDefault();break;case et.PageUp:n===void 0?(S(t.length-1),$(t.length-1)):(S(n-5),$(n)),T.preventDefault();break;case et.ArrowUp:n===void 0?(S(t.length-1),$(t.length-1)):(S(n-1),$(n)),T.preventDefault();break;case et.Escape:I(),T.preventDefault();break;case et.Enter:V(t[n||0]),T.preventDefault();break;default:b()}},b=()=>{if(!i){const T=ui(l.trim());c([]),h([]),p([]),f([]);for(const R of t){const O=ui(R.label).indexOf(T);if(O>=0){const K=R.label.substring(0,O),F=R.label.substring(O,O+T.length),B=R.label.substring(O+T.length);c(X=>[...X,R]),h(X=>[...X,K]),p(X=>[...X,F]),f(X=>[...X,B])}}y(!0)}},I=()=>{y(!1)},S=T=>{if(!i){if(n=T,T===void 0)return;T<0&&(n=0),T>=t.length&&(n=t.length-1)}},L=()=>{setTimeout(()=>{I()},Wo)},$=T=>{var Y;const R=(Y=a.current)==null?void 0:Y.querySelectorAll("li")[T];R&&R.scrollIntoView({block:"center"})},x=()=>{i||(s(""),y(!1),n=void 0)},V=T=>{i||(s(T.label),y(!1),n=void 0,o(T.key))};return v.jsxs("div",{ref:a,className:`daga-autocomplete ${g?"daga-showing-options":""}`,children:[v.jsxs("div",{className:"daga-autocomplete-input",children:[v.jsx("input",{value:l,disabled:i,onKeyUp:w,onFocus:b,onBlur:L,onChange:T=>s(T.target.value)}),l!==""&&v.jsx("button",{className:"daga-clear",onClick:x})]}),v.jsx("div",{className:"daga-autocomplete-options",children:v.jsxs("ul",{className:"daga-autocomplete-option-list",children:[r.length===0&&v.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),r.map((T,R)=>v.jsxs("li",{className:`daga-autocomplete-option ${R===n?"daga-focused":""}`,onMouseMove:()=>S(R),onClick:()=>V(T),children:[v.jsx("span",{children:d[R]}),v.jsx("span",{className:"daga-match",children:u[R]}),v.jsx("span",{children:m[R]})]},R))]})})]})},Zo=(i,t)=>{var e;return((e=i.find(o=>o.key===t))==null?void 0:e.label)||`${t}`},Ko=({disabled:i,allowRepeats:t,options:e,value:o,onChange:a})=>{const[l,s]=z.useState(),[n,r]=z.useState([]),[c,d]=z.useState([]);z.useEffect(()=>{const g=o.length===0,y=o.map(w=>Zo(e,w));r(y),g&&a(o),f()},[o,e]);const h=g=>{for(const y of o)if(y===g)return!0;return!1},u=g=>{o.length>g&&(o.splice(g,1),r(n.filter((y,w)=>w!==g)),a(o),f())},p=()=>{l!==void 0&&(t||!h(l))&&(a(o.concat(l)),m())},m=()=>{s("")},f=()=>{if(!t){const g=[];for(const y of e)h(y.key)||g.push(y);d(g)}};return v.jsxs("div",{children:[o.map((g,y)=>v.jsxs("div",{className:"daga-value-item-element",children:[v.jsx("span",{className:"daga-input",children:n[y]}),!i&&v.jsx("button",{className:"daga-property-button",onClick:()=>u(y),children:v.jsx("div",{className:"daga-icon daga-close-icon"})})]},y)),!i&&v.jsxs("div",{className:"daga-value-item-input",children:[v.jsx("div",{className:"daga-input daga-relatively-positioned",children:v.jsx(Pi,{disabled:i,options:t?e||[]:c||[],value:l,onChange:s})}),v.jsx("button",{className:"daga-property-button",onClick:p,children:v.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},qo=({disabled:i,allowRepeats:t,value:e,onChange:o})=>{const[a,l]=z.useState(""),s=u=>{for(const p of u||[])if(p===u)return!0;return!1},n=u=>{e.length>u&&o(e.filter((p,m)=>m!==u))},r=(u,p,m)=>{const f=e.map((g,y)=>y===p?m==="blur"?u.trim():u:g);o(f)},c=()=>{const u=a.trim();u!==""&&(t||!s(u))&&(o(e.concat(u)),d())},d=()=>{l("")},h=u=>{u.key==="Enter"&&c()};return v.jsxs(v.Fragment,{children:[e.map((u,p)=>v.jsxs("div",{className:"daga-value-item-element",children:[v.jsx("input",{className:"daga-input",disabled:i,value:u,onChange:m=>r(m.target.value,p,"change"),onBlur:m=>r(m.target.value,p,"blur")}),v.jsx("button",{className:"daga-property-button",onClick:()=>n(p),children:v.jsx("div",{className:"daga-icon daga-close-icon"})})]},p)),!i&&v.jsxs("div",{className:"daga-value-item-input",children:[v.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[v.jsx("input",{type:"text",onKeyUp:h,value:a,onChange:u=>l(u.target.value)}),v.jsx("button",{className:"daga-clear",onClick:d})]}),v.jsx("button",{className:"daga-property-button",onClick:c,children:v.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Jo=({disabled:i,value:t,onChange:e})=>{const[o,a]=z.useState(""),[l,s]=z.useState(""),[n,r]=z.useState({}),c=g=>{const y={};Object.keys(t).forEach(w=>{w!==g&&(y[w]=t[w])}),e(y)},d=(g,y,w)=>{const b=w==="blur"?y.trim():y;if(w==="blur"){if(g!==b){const I={};Object.keys(t).forEach(S=>{S===g?I[b]=t[S]:I[S]=t[S]}),e(I),r(S=>{const L={...S};return delete L[g],L})}}else r(I=>({...I,[g]:y}))},h=(g,y,w)=>{const b=w==="blur"?y.trim():y;if(b!==""){const I={};Object.keys(t).forEach(S=>{S===g?I[S]=b:I[S]=t[S]}),e(I)}},u=()=>{const g=o.trim(),y=l.trim();if(g!==""&&y!==""){const w={};Object.keys(t).forEach(b=>{w[b]=t[b]}),w[g]=y,e(w),a(""),s("")}},p=()=>{a("")},m=()=>{s("")},f=g=>{g.key==="Enter"&&u()};return v.jsxs("div",{children:[Object.entries(t).map(([g,y],w)=>v.jsxs("div",{className:"daga-value-item-element",children:[v.jsx("input",{id:`key-${w}`,className:"daga-input",type:"text",disabled:i,value:n[g]??g,onChange:b=>d(g,b.target.value,"change"),onBlur:b=>d(g,b.target.value,"blur")}),v.jsx("input",{id:`value-${w}`,className:"daga-input",type:"text",disabled:i,value:y,onChange:b=>h(g,b.target.value,"change"),onBlur:b=>h(g,b.target.value,"blur")}),v.jsx("button",{className:"daga-property-button",onClick:()=>c(g),children:v.jsx("div",{className:"daga-icon daga-close-icon"})})]},g)),!i&&v.jsxs("div",{className:"daga-value-item-input",children:[v.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[v.jsx("input",{type:"text",value:o,onKeyUp:f,onChange:g=>a(g.target.value),onBlur:g=>d(o,g.target.value,"blur")}),v.jsx("button",{className:"daga-clear",onClick:p})]}),v.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[v.jsx("input",{type:"text",value:l,onKeyUp:f,onChange:g=>s(g.target.value),onBlur:g=>h(o,g.target.value,"blur")}),v.jsx("button",{className:"daga-clear",onClick:m})]}),v.jsx("button",{className:"daga-property-button",onClick:u,children:v.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},zi=({valueSet:i,onValueChange:t,depth:e})=>{var r;const a=z.useContext(Lt).canUserPerformAction(C.UpdateValues)&&((r=i==null?void 0:i.rootElement)==null?void 0:r.removed)!==!0,l=c=>"daga-property-name-"+c.replace(/\s/g,""),s=c=>{if(typeof c=="string")return c;if(c==null||isNaN(c.valueOf()))return"";const d=new Date(c),h=d.getTimezoneOffset();return d.setMinutes(d.getMinutes()-h),d.toISOString().substring(0,19)},n=c=>new Date(c);return v.jsx("daga-object-editor",{children:i.displayedProperties.map(c=>v.jsxs("div",{className:`daga-property ${l(c.name)}`,children:[v.jsx("p",{className:"daga-property-name",children:c.label||c.name}),c.type===_.Text&&v.jsx("input",{type:"daga-text",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.TextArea&&v.jsx("textarea",{disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Number&&v.jsx("input",{type:"number",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Color&&v.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Datetime&&v.jsx("input",{type:"datetime-local",disabled:c.editable===!1||!a,value:s(i==null?void 0:i.getValue(c.name)),onChange:d=>t(i,c,n(d.target.value))}),c.type===_.Date&&v.jsx("input",{type:"date",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Time&&v.jsx("input",{type:"time",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Url&&v.jsx("input",{type:"url",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Boolean&&v.jsxs("div",{className:"daga-radio",children:[v.jsxs("label",{className:"daga-radio-item daga-radio-start"+((i==null?void 0:i.getValue(c.name))===!1?" daga-checked":""),children:[v.jsx("input",{type:"radio",disabled:c.editable===!1||!a,name:c.name,value:"false",checked:(i==null?void 0:i.getValue(c.name))===!1,onChange:()=>t(i,c,!1)}),"No"]}),v.jsxs("label",{className:"daga-radio-item daga-radio-end"+((i==null?void 0:i.getValue(c.name))===!0?" daga-checked":""),children:[v.jsx("input",{type:"radio",disabled:c.editable===!1||!a,name:c.name,value:"true",checked:(i==null?void 0:i.getValue(c.name))===!0,onChange:()=>t(i,c,!0)}),"Yes"]})]}),c.type===_.Option&&v.jsx("div",{className:"daga-relatively-positioned",children:v.jsx(Pi,{disabled:c.editable===!1||!a,options:c.options||[],value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d)})}),(c.type===_.OptionList||c.type===_.OptionSet)&&v.jsx(Ko,{disabled:c.editable===!1||!a,allowRepeats:c.type===_.OptionList,options:c.options||[],value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d)}),(c.type===_.TextList||c.type===_.TextSet)&&v.jsx(qo,{disabled:c.editable===!1||!a,allowRepeats:c.type===_.TextList,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d)}),c.type===_.TextMap&&v.jsx(Jo,{disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d)}),c.type===_.Object&&v.jsx("div",{className:"daga-left-bar",children:v.jsx(zi,{valueSet:i.getSubValueSet(c.name),onValueChange:t,depth:e+1})})]},c.name))})},Ri=({valueSet:i,depth:t})=>{const e=z.useContext(Lt),o=z.useRef(null),a=r=>"daga-property-name-"+r.replace(/\s/g,""),l=()=>{for(const r of(i==null?void 0:i.displayedProperties)||[]){let c=0,d=0,h=0;const u=N.select(o.current).select(`.daga-property.${a(r.name)}.daga-depth-${t}`);u.select("button.daga-move-button").call(N.drag().on(M.Start,p=>{var g;A(P.Grabbing);const m=e.getPointerLocationRelativeToScreen(p);if(m.length<2||isNaN(m[0])||isNaN(m[1]))return;const f=(g=u.node())==null?void 0:g.getBoundingClientRect();c=(f==null?void 0:f.width)||0,d=(f==null?void 0:f.height)||0,u.style("position","fixed").style("left",`${m[0]-c/2}px`).style("top",`${m[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1)}).on(M.Drag,p=>{A(P.Grabbing);const m=e.getPointerLocationRelativeToScreen(p);m.length<2||isNaN(m[0])||isNaN(m[1])||(u.style("position","fixed").style("left",`${m[0]-c/2}px`).style("top",`${m[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1),N.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0),h=s(m),N.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on(M.End,p=>{var f,g;A(P.Auto),u.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),N.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const m=e.getPointerLocationRelativeToScreen(p);m.length<2||isNaN(m[0])||isNaN(m[1])||(h=s(m),(f=i==null?void 0:i.displayedProperties)==null||f.splice(i.displayedProperties.indexOf(r),1),(g=i==null?void 0:i.displayedProperties)==null||g.splice(h,0,r))}))}},s=r=>{var h;const c=(i==null?void 0:i.propertySet.propertyList)||[],d=[];for(let u=0;u<=c.length;++u){const p=(h=N.select(o.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).node())==null?void 0:h.getBoundingClientRect();p&&d.push([p.x+p.width/2,p.y+p.height/2])}if(d.length>0){const u=d.map(m=>((r[0]-m[0])**2+(r[1]-m[1])**2)**.5);return u.indexOf(Math.min(...u))}return 0},n=r=>{var d;if(i===void 0)return;let c;r instanceof to?c=r:r instanceof Event?c=i==null?void 0:i.propertySet.getProperty(((d=r.target)==null?void 0:d.value)||""):c=i==null?void 0:i.propertySet.getProperty(r||""),c&&(i==null||i.hideProperty(c)),l()};return v.jsxs("daga-property-settings",{ref:o,children:[v.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),i==null?void 0:i.displayedProperties.map((r,c)=>v.jsxs("div",{className:`daga-property-and-dropbar ${a(r.name)} daga-depth-${t}`,children:[v.jsxs("div",{className:`daga-property ${a(r.name)} daga-depth-${t}`,children:[v.jsxs("div",{className:"daga-property-name",children:[v.jsx("span",{children:r.label||r.name}),v.jsxs("div",{className:"daga-buttons",children:[v.jsx("button",{className:"daga-property-button daga-move-button",children:v.jsx("div",{className:"daga-icon daga-move-icon"})}),v.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>n(r.name),children:v.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),r.type!==_.Object&&v.jsx("div",{className:"daga-property-value",children:Qo(i==null?void 0:i.getValue(r.name))}),r.type===_.Object&&v.jsx(Ri,{valueSet:i==null?void 0:i.getSubValueSet(r.name),depth:t+1})]}),v.jsx("div",{className:`daga-dropbar daga-index-${c+1} daga-depth-${t}`})]},r.name))]})},Qo=i=>Array.isArray(i)?i.join(", "):eo(i)?Object.entries(i).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):i instanceof Date?i.toLocaleString():i==null?"":""+i,ts=({location:i,direction:t,width:e,title:o,valueSet:a,onValueChange:l})=>{const s=z.useRef(null),[n,r]=z.useState(!1),[c,d]=z.useState(!1),h=()=>N.select(s.current);return z.useEffect(()=>{if(s.current)switch(t){case k.Bottom:case k.Top:h().style("width",e);break;case k.Left:case k.Right:h().style("height",e);break}},[e,t]),v.jsx("daga-property-editor",{children:v.jsxs("div",{ref:s,className:`daga-panel daga-bottom daga-${i} daga-${t}`,children:[v.jsx(Ce,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:n,direction:t,collapsableSelector:s,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:r}),a&&a.propertySet&&a.propertySet.hasProperties()&&!n&&v.jsxs("div",{className:"daga-panel-content",children:[o&&v.jsxs("p",{className:"daga-title",children:[o,v.jsx("button",{className:"daga-property-button",onClick:()=>d(!c),children:v.jsx("div",{className:`daga-icon daga-settings-icon ${c?"daga-unrotate":"daga-rotate"}`})})]}),!c&&v.jsx(zi,{valueSet:a,onValueChange:l,depth:0}),c&&v.jsx(Ri,{valueSet:a,depth:0})]})]})})},es=6,is=i=>{const t=z.useContext(Lt),[e,o]=z.useState(i.currentPalette||i.palettes[0]),[a,l]=z.useState(0),[s,n]=z.useState(void 0),r=z.useRef(null),c=f=>{if(o(f),d().selectAll("*").remove(),l(t.getPriorityThreshold()||0),f.categories&&h(f.categories),f.templates)for(const g of f.templates)u(g)},d=()=>N.select(r.current).select(".daga-palette-view"),h=f=>{const g=d().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");g.append("option").attr("value","").text("(None selected)");for(const y in f)g.append("option").attr("value",y).text(y);g.on(E.Change,()=>{s&&d().selectAll(".daga-template-container.daga-in-category").remove();const y=g.property("value");n(y);const w=f[y]||[];for(const b of w)u(b,"daga-in-category")}),s&&(g.property("value",s),g.dispatch(E.Change))},u=(f,g)=>{if(f.templateType==="node"){const y=t.model.nodes.types.get(f.type);y?p(y,f,g):console.error(`Could not find a node type called '${f.type}'`)}else if(f.templateType==="connection"){const y=t.model.connections.types.get(f.type);y?m(y,f,g):console.error(`Could not find a connection type called '${f.type}'`)}},p=(f,g,y)=>{if(a!==void 0&&f.priority<a)return;const w=f.defaultLook.lookType==="shaped-look"?f.defaultLook.borderThickness||1:0,b=f.defaultHeight+w,I=f.defaultWidth+w,S=g.height||b,L=g.width||I,$=d().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${L}px`).style("height",`${S}px`).call(N.drag().on(M.Drag,V=>{if(t.canUserPerformAction(C.AddNode)){const T=t.getPointerLocationRelativeToScreen(V);if(T.length<2||isNaN(T[0])||isNaN(T[1]))return;$.style("position","fixed").style("left",`${T[0]-L}px`).style("top",`${T[1]-S}px`).style("z-index",1)}}).on(M.Start,V=>{if(t.canUserPerformAction(C.AddNode)){A(P.Grabbing);const T=t.getPointerLocationRelativeToScreen(V);if(T.length<2||isNaN(T[0])||isNaN(T[1]))return;$.style("position","fixed").style("left",`${T[0]-L}px`).style("top",`${T[1]-S}px`).style("z-index",1),f.isUnique&&t.model.nodes.find(R=>!R.removed&&R.type.id===f.id)!==void 0&&A(P.NotAllowed)}}).on(M.End,V=>{var T;if(t.canUserPerformAction(C.AddNode)){if(A(P.Auto),$.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),f.isUnique&&t.model.nodes.find(It=>!It.removed&&It.type.id===f.id)!==void 0)return;const R=t.getPointerLocationRelativeToScreen(V);if(R.length<2||isNaN(R[0])||isNaN(R[1]))return;const Y=document.elementFromPoint(R[0],R[1]);if(Y&&!((T=t.selectCanvasView().node())!=null&&T.contains(Y)))return;const O=t.getPointerLocationRelativeToCanvas(V);if(O.length<2||isNaN(O[0])||isNaN(O[1]))return;let K=[O[0]-f.defaultWidth/2,O[1]-f.defaultHeight/2];t.snapToGrid&&(K=t.getClosestGridPoint(K));const B=t.model.nodes.getAtCoordinates(O[0],O[1]).filter(It=>It.type.childrenTypes.includes(f.id)),X=wi(B),at=X[X.length-1];if(!f.canBeParentless&&at===void 0)return;const gt=at==null?void 0:at.getLastAncestor(),_t=new bo(t,f,K,at==null?void 0:at.id,gt==null?void 0:gt.id,gt==null?void 0:gt.getGeometry(),void 0,g.label,g.values);_t.do(),t==null||t.actionStack.add(_t),A()}})).append("svg").attr("class",`palette-node ${f.id}`).attr("viewBox",`0 0 ${I} ${b}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${L}px`).style("height",`${S}px`),x=g.look||f.defaultLook;switch(x.lookType){case"shaped-look":$.append("path").attr("d",pe(x.shape||Rt.Rectangle,(x.borderThickness||1)/2,(x.borderThickness||1)/2,f.defaultWidth,f.defaultHeight)).attr("fill",x.fillColor||"#FFFFFF").attr("stroke",x.borderColor||"#000000").attr("stroke-width",`${x.borderThickness}px`);break;case"image-look":$.append("image").attr("x",0).attr("y",0).attr("width",f.defaultWidth).attr("height",f.defaultHeight).attr("href",x.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":$.append("image").attr("x",0).attr("y",0).attr("width",x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",0).attr("width",f.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTop).attr("preserveAspectRatio","none"),$.append("image").attr("x",f.defaultWidth-x.rightMargin).attr("y",0).attr("width",x.rightMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopRight).attr("preserveAspectRatio","none"),$.append("image").attr("x",0).attr("y",x.topMargin).attr("width",x.leftMargin).attr("height",f.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",x.topMargin).attr("width",f.defaultWidth-x.rightMargin-x.leftMargin).attr("height",f.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageCenter).attr("preserveAspectRatio","none"),$.append("image").attr("x",f.defaultWidth-x.rightMargin).attr("y",x.topMargin).attr("width",x.rightMargin).attr("height",f.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageRight).attr("preserveAspectRatio","none"),$.append("image").attr("x",0).attr("y",f.defaultHeight-x.bottomMargin).attr("width",x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",f.defaultHeight-x.bottomMargin).attr("width",f.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottom).attr("preserveAspectRatio","none"),$.append("image").attr("x",f.defaultWidth-x.rightMargin).attr("y",f.defaultHeight-x.bottomMargin).attr("width",x.rightMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(g.look===void 0){if(f.decorators)for(const V of f.decorators)$.append("foreignObject").attr("width",`${V.width}px`).attr("height",`${V.height}px`).attr("transform",`translate(${V.coords[0]},${V.coords[1]})`).html(V.html);if(g.label){const V={...D,...f.label,...g.labelLook};$.append("text").attr("transform",`translate(${(Q(V)+f.defaultWidth)/2},${(W(V)+f.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${V.fontSize}px`).attr("text-anchor","middle").attr("font-family",V.fontFamily).attr("font-weight",400).attr("fill",V.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(g.label)}}},m=(f,g,y)=>{const w=d().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${g.width}px`).style("height",`${g.height}px`).append("svg").attr("class",`palette-button ${f.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=f});w.append("path").attr("d",pe(Rt.Rectangle,0,0,g.width,g.height)).attr("fill",g.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),g.icon!==""&&w.append("image").attr("x",0).attr("y",0).attr("width",g.width).attr("height",g.height).attr("href",g.icon),g.label!==""&&w.append("text").attr("transform",`translate(${g.width/2},${g.height/2+es})`).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(g.label)};return z.useEffect(()=>{if(c(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}},[e,i.palettes]),v.jsx("daga-palette",{children:v.jsxs("div",{ref:r,className:`daga-panel daga-${i.location} daga-${i.direction}`,children:[v.jsx(Ce,{direction:i.direction,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),v.jsxs("div",{className:"daga-panel-content",children:[i.palettes.length>1&&v.jsx("div",{className:"daga-panel-tabs",children:i.palettes.map(f=>v.jsx("div",{className:`daga-panel-tab ${f===e?"daga-current-tab":""}`,onClick:()=>c(f),children:f.name}))}),v.jsx("div",{className:"daga-palette-view"})]})]})})},os=({location:i,direction:t,enableAction:e,enableFilter:o,enableLayout:a,enableSelection:l,enableZoom:s})=>{let n=!1,r=!0,c=!1,d,h,u,p;switch(t){case k.Bottom:d="height",h="scaleY",u="top",p="bottom";break;case k.Top:d="height",h="scaleY",u="bottom",p="top";break;case k.Left:d="width",h="scaleX",u="right",p="left";break;case k.Right:d="width",h="scaleX",u="left",p="right";break}const m=z.useRef(null),f=z.useRef(null),g=z.useRef(null);z.useEffect(()=>{N.select(m.current).style(`margin-${p}`,"-1rem").style(d,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const y=async()=>{const F=N.select(m.current);if(!c)if(r){r=!1;const at=`${4*F.selectChildren().size()}rem`;F.transition().duration(500).ease(N.easeLinear).style(d,at).style("transform",`${h}(1)`),setTimeout(()=>{c=!1},500)}else r=!0,F.transition().duration(500).ease(N.easeLinear).style(d,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{c=!1},500)},w=z.useContext(Lt),b=()=>{w.zoomBy(w.zoomFactor)},I=()=>{w.zoomBy(1/w.zoomFactor)},S=()=>{w.center()},L=()=>{w.layoutFormat&&w.layoutFormat in gi&&gi[w.layoutFormat].apply(w.model)},$=()=>{n=!n,N.select(g.current).classed("daga-on",n).classed("daga-off",!n);const F=w.getPriorityThresholdOptions();F&&F.length>=2&&w.setPriorityThreshold(F[n?1:0])},x=()=>{w.actionStack.undo()},V=()=>{w.actionStack.redo()},T=()=>{w.userSelection.copyToClipboard()},R=()=>{w.userSelection.cutToClipboard()},Y=()=>{w.userSelection.pasteFromClipboard()},O=()=>{w.userSelection.removeFromModel()},K=()=>{w.multipleSelectionOn=!0,N.select(f.current).classed("daga-on",!0).classed("daga-off",!1);const F=w.diagramEvent$.subscribe(B=>{B.type===Ii.Selection&&(N.select(f.current).classed("daga-on",!1).classed("daga-off",!0),F.unsubscribe())})};return v.jsx("daga-diagram-buttons",{children:v.jsxs("div",{className:`daga-diagram-buttons daga-${i} daga-${t}`,children:[s&&w.canUserPerformAction(C.Zoom)&&v.jsx("button",{className:"daga-zoom-in",onClick:b,children:v.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),s&&w.canUserPerformAction(C.Zoom)&&v.jsx("button",{className:"daga-zoom-out",onClick:I,children:v.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),v.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:m,children:[s&&w.canUserPerformAction(C.Zoom)&&v.jsx("button",{className:"daga-center",onClick:S,children:v.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&v.jsx("button",{className:"daga-undo",onClick:x,children:v.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&v.jsx("button",{className:"daga-redo",onClick:V,children:v.jsx("span",{className:"daga-tooltip",children:"Redo"})}),l&&v.jsx("button",{className:"daga-copy",onClick:T,children:v.jsx("span",{className:"daga-tooltip",children:"Copy"})}),l&&v.jsx("button",{className:"daga-cut",onClick:R,children:v.jsx("span",{className:"daga-tooltip",children:"Cut"})}),l&&v.jsx("button",{className:`daga-multiple-selection ${n?"daga-on":"daga-off"}`,onClick:K,ref:f,children:v.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),l&&v.jsx("button",{className:"daga-paste",onClick:Y,children:v.jsx("span",{className:"daga-tooltip",children:"Paste"})}),l&&v.jsx("button",{className:"daga-delete",onClick:O,children:v.jsx("span",{className:"daga-tooltip",children:"Delete"})}),a&&w.layoutFormat&&v.jsx("button",{className:"daga-layout",onClick:L,children:v.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),o&&v.jsx("button",{className:`daga-filter ${n?"daga-on":"daga-off"}`,onClick:$,ref:g,children:v.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),v.jsx("button",{className:"daga-more-options",onClick:y,children:r?v.jsx("span",{className:"daga-tooltip",children:"More options"}):v.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},ss=({config:i,model:t,onCanvasCreated:e,onDiagramEvent:o,onModelChange:a})=>{var $,x,V,T,R,Y,O,K,F,B,X,at,gt,_t,It,Se,Ie,Ae,Ee,Le,Te,$e,Me,Ne,Pe,ze,Re,Ve,_e,je,Oe,De,Fe,He,Ge,Be,Ue,Ye,Xe,We,Ze,Ke,qe,Je,Qe;const l=new Si,s=new Li,n=z.useRef(null),r=z.useRef(void 0),c=z.useRef(!1),d=[],[h,u]=z.useState(void 0),[p,m]=z.useState(void 0),f={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},g={refreshPalette:()=>{}},y=new Yo(dt=>u(dt),dt=>m(dt)),w={diagramButtons:f,palette:g,propertyEditor:y},b=(dt=!1)=>((!r.current||dt)&&(d.forEach(ut=>ut.unsubscribe()),r.current=new ye(w,i)),r.current),I=b(),S=dt=>{I.initView(dt),d.push(I.diagramEvent$.subscribe(ut=>{o==null||o(ut)})),d.push(I.diagramChange$.subscribe(()=>{const ut=s.export(I.model);a==null||a(ut)}))};z.useEffect(()=>{n.current&&(c.current||(S(n.current),c.current=!0,e==null||e(I)))},[n.current]),z.useMemo(()=>{n.current&&(b(!0),S(n.current),e==null||e(I))},[i]),z.useEffect(()=>{t&&l.import(I.model,t)},[t]);const L=(dt,ut,ti)=>{var ei;if(p!==void 0&&ut.editable!==!1&&!Et(dt.getValue(ut.name),ti)){dt.setValue(ut.name,ti);const ne=new xt(p.propertySet,p.rootElement);ne.setValues(p.getValues()),y.valueSet=ne,p.rootElement.valueSet=ne,(ei=I.propertyEditorChanges$)==null||ei.next()}};return v.jsx("daga-diagram",{children:v.jsx(Uo.Provider,{value:i,children:v.jsx(Lt.Provider,{value:I,children:v.jsxs("daga-diagram-editor",{children:[v.jsx("div",{className:"daga-append-to",ref:n}),v.jsxs(Lt.Provider,{value:I,children:[(($=i.components)==null?void 0:$.buttons)!==void 0&&((V=(x=i.components)==null?void 0:x.buttons)==null?void 0:V.enabled)!==!1&&v.jsx(os,{location:((R=(T=i.components)==null?void 0:T.buttons)==null?void 0:R.location)||Xt.BottomRight,direction:((O=(Y=i.components)==null?void 0:Y.buttons)==null?void 0:O.direction)||k.Top,enableAction:((F=(K=i.components)==null?void 0:K.buttons)==null?void 0:F.enableAction)!==!1,enableFilter:((X=(B=i.components)==null?void 0:B.buttons)==null?void 0:X.enableFilter)===!0,enableLayout:((gt=(at=i.components)==null?void 0:at.buttons)==null?void 0:gt.enableLayout)===!0,enableSelection:((It=(_t=i.components)==null?void 0:_t.buttons)==null?void 0:It.enableSelection)!==!1,enableZoom:((Ie=(Se=i.components)==null?void 0:Se.buttons)==null?void 0:Ie.enableZoom)!==!1}),((Ae=i.components)==null?void 0:Ae.palette)!==void 0&&((Le=(Ee=i.components)==null?void 0:Ee.palette)==null?void 0:Le.enabled)!==!1&&(($e=(Te=i.components)==null?void 0:Te.palette)==null?void 0:$e.sections)&&(((Pe=(Ne=(Me=i.components)==null?void 0:Me.palette)==null?void 0:Ne.sections)==null?void 0:Pe.length)||0)>0&&v.jsx(is,{location:((Re=(ze=i.components)==null?void 0:ze.palette)==null?void 0:Re.location)||Xt.TopLeft,direction:((_e=(Ve=i.components)==null?void 0:Ve.palette)==null?void 0:_e.direction)||k.Bottom,width:((Oe=(je=i.components)==null?void 0:je.palette)==null?void 0:Oe.width)||"12rem",palettes:((Fe=(De=i.components)==null?void 0:De.palette)==null?void 0:Fe.sections)||[]}),((He=i.components)==null?void 0:He.propertyEditor)!==void 0&&((Be=(Ge=i.components)==null?void 0:Ge.propertyEditor)==null?void 0:Be.enabled)!==!1&&v.jsx(ts,{location:((Ye=(Ue=i.components)==null?void 0:Ue.propertyEditor)==null?void 0:Ye.location)||Xt.TopRight,direction:((We=(Xe=i.components)==null?void 0:Xe.propertyEditor)==null?void 0:We.direction)||k.Bottom,width:((Ke=(Ze=i.components)==null?void 0:Ze.propertyEditor)==null?void 0:Ke.width)||"24rem",title:h,valueSet:p,onValueChange:L}),((qe=i.components)==null?void 0:qe.errors)!==void 0&&((Qe=(Je=i.components)==null?void 0:Je.errors)==null?void 0:Qe.enabled)!==!1&&v.jsx(Xo,{})]})]})})})})};exports.DagaDiagram=ss;