@metadev/daga-react 4.2.7 → 4.2.8

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 +6 -0
  2. package/index.js +2 -2
  3. package/index.mjs +2695 -2629
  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 g=require("react/jsx-runtime"),ti=require("d3"),kt=require("rxjs"),T=require("react");function ei(o){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>o[e]})}}return t.default=o,Object.freeze(t)}const E=ei(ti);var f=(o=>(o.Bottom="bottom",o.Left="left",o.Right="right",o.Top="top",o))(f||{}),Bt=(o=>(o.BottomLeft="bottom-left",o.BottomRight="bottom-right",o.TopLeft="top-left",o.TopRight="top-right",o))(Bt||{}),At=(o=>(o.Left="left",o.Center="center",o.Right="right",o))(At||{}),Ut=(o=>(o.Top="top",o.Center="center",o.Bottom="bottom",o))(Ut||{});const Ct=o=>[Math.round(o[0]),Math.round(o[1])],gt=(o,t,e)=>t<e?t<=o&&o<=e:e<=o&&o<=t,ke=(o,t,e)=>(o-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Yt=(o,t,e,n,l,a,i)=>{const s=(()=>{switch(a){case"start":return n[0]+(o[0]-t[0]);case"end":return n[1]-(t[1]-o[0]);case"middle":{const c=(t[0]+t[1])/2,d=(n[0]+n[1])/2,h=t[1]-t[0],u=n[1]-n[0],y=(o[0]-c)/h;return d+y*u}case"floating":default:return ke(o[0],t,n)}})(),r=(()=>{switch(i){case"start":return l[0]+(o[1]-e[0]);case"end":return l[1]-(e[1]-o[1]);case"middle":{const c=(e[0]+e[1])/2,d=(l[0]+l[1])/2,h=e[1]-e[0],u=l[1]-l[0],y=(o[1]-c)/h;return d+y*u}case"floating":default:return ke(o[1],e,l)}})();return[s,r]},Me=(o,t)=>((o[0]-t[0])**2+(o[1]-t[1])**2)**.5,ii=(o,t)=>(gt(o[0][0],t[0][0],t[1][0])||gt(o[1][0],t[1][0],t[0][0])||gt(t[0][0],o[0][0],o[1][0])||gt(t[1][0],o[1][0],o[0][0]))&&(gt(o[0][1],t[0][1],t[1][1])||gt(o[1][1],t[1][1],t[0][1])||gt(t[0][1],o[0][1],o[1][1])||gt(t[1][1],o[1][1],o[0][1]));var C=(o=>(o.Blur="blur",o.Change="change",o.Click="click",o.ContextMenu="contextmenu",o.DoubleClick="dblclick",o.Focus="focus",o.FocusIn="focusin",o.FocusOut="focusout",o.Input="input",o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseEnter="mouseenter",o.MouseLeave="mouseleave",o.MouseMove="mousemove",o.MouseOut="mouseout",o.MouseOver="mouseover",o.MouseUp="mouseup",o.TouchStart="touchstart",o.TouchEnd="touchend",o.Wheel="wheel",o))(C||{}),W=(o=>(o.Alt="Alt",o.AltGraph="AltGraph",o.ArrowDown="ArrowDown",o.ArrowLeft="ArrowLeft",o.ArrowRight="ArrowRight",o.ArrowUp="ArrowUp",o.Backspace="Backspace",o.Control="Control",o.Delete="Delete",o.End="End",o.Enter="Enter",o.Escape="Escape",o.Home="Home",o.OS="OS",o.PageDown="PageDown",o.PageUp="PageUp",o.Shift="Shift",o.Tab="Tab",o))(W||{}),I=(o=>(o.Drag="drag",o.Start="start",o.End="end",o))(I||{}),le=(o=>(o.Zoom="zoom",o.Start="start",o.End="end",o))(le||{});const ce=o=>o.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var Pe=(o=>(o.Straight="straight",o.Bezier="bezier",o.Square="square",o))(Pe||{}),fe=(o=>(o.Solid="solid",o.Dashed="dashed",o.GappedDashes="gapped-dashes",o.Dotted="dotted",o))(fe||{});const oi=20,si=(o,t,e,n,l)=>{if(typeof o=="function")return o(t,e,n,l);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{l=l||oi;let a="",i,s;switch(o){case"straight":a+=`M ${t[0][0]} ${t[0][1]}`;for(let r=1;r<t.length;++r)a+=` L ${t[r][0]} ${t[r][1]}`;break;case"bezier":i=e,a+=`M ${t[0][0]} ${t[0][1]}`;for(let r=1;r<t.length;++r){if(r+1>=t.length?s=n: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]?s=f.Bottom:s=f.Top:t[r][0]>t[r-1][0]?s=f.Right:s=f.Left,i!==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(i){case f.Bottom:c=`${t[r-1][0]} ${t[r-1][1]+h}`;break;case f.Top:c=`${t[r-1][0]} ${t[r-1][1]-h}`;break;case f.Right:c=`${t[r-1][0]+h} ${t[r-1][1]}`;break;case f.Left:c=`${t[r-1][0]-h} ${t[r-1][1]}`;break}if(s!==void 0){switch(s){case f.Bottom:d=`${t[r][0]} ${t[r][1]+h}`;break;case f.Top:d=`${t[r][0]} ${t[r][1]-h}`;break;case f.Right:d=`${t[r][0]+h} ${t[r][1]}`;break;case f.Left:d=`${t[r][0]-h} ${t[r][1]}`;break}a+=` C ${c} ${d} ${t[r][0]} ${t[r][1]}`}else a+=` Q ${c} ${t[r][0]} ${t[r][1]}`}else if(s!==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(s){case f.Bottom:c=`${t[r][0]} ${t[r][1]+d}`;break;case f.Top:c=`${t[r][0]} ${t[r][1]-d}`;break;case f.Right:c=`${t[r][0]+d} ${t[r][1]}`;break;case f.Left:c=`${t[r][0]-d} ${t[r][1]}`;break}a+=` Q ${c} ${t[r][0]} ${t[r][1]}`}else a+=` L ${t[r][0]} ${t[r][1]}`;i=s}break;case"square":if(a+=`M ${t[0][0]} ${t[0][1]}`,e)switch(e){case f.Bottom:t.splice(1,0,[t[0][0],t[0][1]+l]);break;case f.Top:t.splice(1,0,[t[0][0],t[0][1]-l]);break;case f.Right:t.splice(1,0,[t[0][0]+l,t[0][1]]);break;case f.Left:t.splice(1,0,[t[0][0]-l,t[0][1]]);break}if(n)switch(n){case f.Bottom:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]+l]);break;case f.Top:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]-l]);break;case f.Right:t.splice(t.length-1,0,[t[t.length-1][0]+l,t[t.length-1][1]]);break;case f.Left:t.splice(t.length-1,0,[t[t.length-1][0]-l,t[t.length-1][1]]);break}for(let r=1;r<t.length;++r)if(i!==void 0)switch(i){case f.Bottom:t[r][1]<t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`,i=f.Top):t[r][1]<t[r-1][1]&&t[r][0]===t[r-1][0]?(a+=` H ${t[r][0]+l}`,a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`,i=f.Left):t[r][1]===t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,i=t[r][0]>t[r-1][0]?f.Right:f.Left):t[r][1]>t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`):t[r][1]>t[r-1][1]&&t[r][0]===t[r-1][0]&&(a+=` V ${t[r][1]}`);break;case f.Top:t[r][1]>t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`,i=f.Bottom):t[r][1]>t[r-1][1]&&t[r][0]===t[r-1][0]?(a+=` H ${t[r][0]-l}`,a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`,i=f.Right):t[r][1]===t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,i=t[r][0]>t[r-1][0]?f.Right:f.Left):t[r][1]<t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`):t[r][1]<t[r-1][1]&&t[r][0]===t[r-1][0]&&(a+=` V ${t[r][1]}`);break;case f.Right:t[r][0]<t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`,i=f.Left):t[r][0]<t[r-1][0]&&t[r][1]===t[r-1][1]?(a+=` V ${t[r][1]+l}`,a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`,i=f.Top):t[r][0]===t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,i=t[r][1]>t[r-1][1]?f.Bottom:f.Top):t[r][0]>t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`):t[r][0]>t[r-1][0]&&t[r][1]===t[r-1][1]&&(a+=` H ${t[r][0]}`);break;case f.Left:t[r][0]>t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`,i=f.Right):t[r][0]>t[r-1][0]&&t[r][1]===t[r-1][1]?(a+=` V ${t[r][1]-l}`,a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`,i=f.Bottom):t[r][0]===t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,i=t[r][1]>t[r-1][1]?f.Bottom:f.Top):t[r][0]<t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`):t[r][0]<t[r-1][0]&&t[r][1]===t[r-1][1]&&(a+=` H ${t[r][0]}`);break}else t[r][0]!==t[r-1][0]&&(a+=` H ${t[r][0]}`,i=t[r][0]>t[r-1][0]?f.Right:f.Left),t[r][1]!==t[r-1][1]&&(a+=` V ${t[r][1]}`,i=t[r][1]>t[r-1][1]?f.Bottom:f.Top);break}return a}},de=(o,t)=>{switch(o){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},G=(o,t)=>{const e=o.indexOf(t);return e>=0&&o.splice(e,1),o};var Tt=(o=>(o.Ellipse="ellipse",o.Empty="empty",o.Folder="folder",o.Hexagon="hexagon",o.Octagon="octagon",o.Pill="pill",o.Rectangle="rectangle",o.Rhombus="rhombus",o.RoundedRectangle="rounded-rectangle",o.StickyNote="sticky-note",o))(Tt||{});const he=(o,t,e,n,l)=>{if(typeof o=="function")return o(t,e,n,l);switch(o){case"ellipse":return ze(t,e,n,l);case"empty":return ni();case"folder":return ri(t,e,n,l);case"hexagon":return ai(t,e,n,l);case"octagon":return li(t,e,n,l);case"pill":return Gt(t,e,n,l);case"rectangle":return we(t,e,n,l);case"rhombus":return ci(t,e,n,l);case"rounded-rectangle":return di(t,e,n,l);case"sticky-note":return hi(t,e,n,l);default:return we(t,e,n,l)}},ze=(o,t,e,n)=>`M ${o+e/2} ${t} A ${e/2} ${n/2} 0 0 0 ${o+e/2} ${t+n} A ${e/2} ${n/2} 0 1 0 ${o+e/2} ${t} Z`,ni=()=>"Z",ri=(o,t,e,n)=>`M ${o} ${t} L ${o+e/3} ${t} L ${o+e/2} ${t+n/6} L ${o+e} ${t+n/6} L ${o+e} ${t+n} L ${o} ${t+n} Z`,ai=(o,t,e,n)=>`M ${o+e/4} ${t} L ${o+3*e/4} ${t} L ${o+e} ${t+n/2} L ${o+3*e/4} ${t+n} L ${o+e/4} ${t+n} L ${o} ${t+n/2} Z`,li=(o,t,e,n)=>`M ${o+e/4} ${t} L ${o+3*e/4} ${t} L ${o+e} ${t+n/4} L ${o+e} ${t+3*n/4} L ${o+3*e/4} ${t+n} L ${o+e/4} ${t+n} L ${o} ${t+3*n/4} L ${o} ${t+n/4} L ${o+e/4} ${t} Z`,Gt=(o,t,e,n)=>n<e?`M ${o+n/2} ${t} L ${o+e-n/2} ${t} A ${n/2} ${n/2} 0 0 1 ${o+e} ${t+n/2} A ${n/2} ${n/2} 0 0 1 ${o+e-n/2} ${t+n} L ${o+n/2} ${t+n} A ${n/2} ${n/2} 0 0 1 ${o} ${t+n/2} A ${n/2} ${n/2} 0 0 1 ${o+n/2} ${t} Z`:n>e?`M ${o} ${t+e/2} L ${o} ${t+n-e/2} A ${e/2} ${e/2} 0 0 0 ${o+e/2} ${t+n} A ${e/2} ${e/2} 0 0 0 ${o+e} ${t+n-e/2} L ${o+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${o+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${o} ${t+e/2} Z`:ze(o,t,e,n),we=(o,t,e,n)=>`M ${o} ${t} L ${o+e} ${t} L ${o+e} ${t+n} L ${o} ${t+n} Z`,ci=(o,t,e,n)=>`M ${o+e/2} ${t} L ${o+e} ${t+n/2} L ${o+e/2} ${t+n} L ${o} ${t+n/2} Z`,di=(o,t,e,n)=>`M ${o+e/4} ${t} L ${o+3*e/4} ${t} A ${e/4} ${n/4} 0 0 1 ${o+e} ${t+n/4} L ${o+e} ${t+3*n/4} A ${e/4} ${n/4} 0 0 1 ${o+3*e/4} ${t+n} L ${o+e/4} ${t+n} A ${e/4} ${n/4} 0 0 1 ${o} ${t+3*n/4} L ${o} ${t+n/4} A ${e/4} ${n/4} 0 0 1 ${o+e/4} ${t} Z`,hi=(o,t,e,n)=>`M ${o} ${t} L ${o+3*e/4} ${t} L ${o+3*e/4} ${t+n/4} L ${o+3*e/4} ${t} L ${o+e} ${t+n/4} L ${o+3*e/4} ${t+n/4} L ${o+e} ${t+n/4} L ${o+e} ${t+n} L ${o} ${t+n} Z`;var L=(o=>(o.AllScroll="all-scroll",o.Auto="auto",o.Crosshair="crosshair",o.EWResize="ew-resize",o.Grab="grab",o.Grabbing="grabbing",o.Move="move",o.NoDrop="no-drop",o.NSResize="ns-resize",o.NotAllowed="not-allowed",o.ZoomIn="zoom-in",o.ZoomOut="zoom-out",o))(L||{});const gi=o=>Math.max(...o.split(`
2
- `).map(t=>t.length)),ui=o=>o.match(/\n/g)?.length||0,X=[];for(let o=0;o<256;++o)X.push((o+256).toString(16).slice(1));function fi(o,t=0){return(X[o[t+0]]+X[o[t+1]]+X[o[t+2]]+X[o[t+3]]+"-"+X[o[t+4]]+X[o[t+5]]+"-"+X[o[t+6]]+X[o[t+7]]+"-"+X[o[t+8]]+X[o[t+9]]+"-"+X[o[t+10]]+X[o[t+11]]+X[o[t+12]]+X[o[t+13]]+X[o[t+14]]+X[o[t+15]]).toLowerCase()}let ee;const mi=new Uint8Array(16);function pi(){if(!ee){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ee=crypto.getRandomValues.bind(crypto)}return ee(mi)}const vi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Se={randomUUID:vi};function xe(o,t,e){if(Se.randomUUID&&!o)return Se.randomUUID();o=o||{};const n=o.random??o.rng?.()??pi();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,fi(n)}const it=o=>{const{selected:t,highlighted:e,...n}=o,l=n,a={...l,...t},i={...l,...e},s={...l,...e,...t};return{defaultLook:l,selectedLook:a,highlightedLook:i,selectedAndHighlightedLook:s}};class Wt{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],G(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const $t=0;class xt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${ce(this.id)}']`)}}class ht extends Wt{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((n,l,a)=>t(n,l,a)&&!n.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((n,l,a)=>t(n,l,a)&&!n.removed)}find(t,e=!1){return e?super.find(t):super.find((n,l,a)=>t(n,l,a)&&!n.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(n=>!n.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],G(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(n=>!n.removed))yield e}}class yi{constructor(t,e,n,l,a,i,s){this.name=t,this.label=e,this.type=n,this.defaultValue=l,this.basic=a,this.editable=i,this.rootAttribute=s,this.options=void 0,this.properties=void 0}}var N=(o=>(o.Boolean="boolean",o.Color="color",o.Date="date",o.Datetime="datetime",o.Number="number",o.Object="object",o.Option="option",o.OptionList="option-list",o.OptionSet="option-set",o.Text="text",o.TextArea="text-area",o.TextList="text-list",o.TextSet="text-set",o.TextMap="text-map",o.Time="time",o.Url="url",o))(N||{});class Zt{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 yt(o,t){return!t||o[0]>t[0]?!0:o[0]===t[0]?o[1]>=t[1]:!1}const Ce=o=>o==null||o===""||o instanceof Array&&o.length===0||o instanceof Object&&Object.keys(o).length===0,wt=(o,t)=>o===t||JSON.stringify(o)===JSON.stringify(t),Re=(o,t,e)=>{const n={},l={};for(const a in e.propertySet.propertyMap)if(e.propertySet.propertyMap[a].type===N.Object){const i=Re(o[a],t[a],e.getSubValueSet(a));Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(n[a]=i[0],l[a]=i[1])}else wt(o[a],t[a])||(n[a]=o[a],l[a]=t[a]);return[n,l]},bi=o=>o!=null&&o.constructor===Object;class pt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(this.rootElement){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const n of t){if(e==null)return;e=e[n]}return e}}}setRootElementValue(t,e){if(this.rootElement){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let n=this.rootElement;for(let l=0;l<t.length-1;++l){const a=t[l];if(n==null)return;n=n[a]}if(n==null)return;n[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}}getValue(t){const e=this.propertySet.getProperty(t)?.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===N.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===N.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const n in t)this.propertySet.getProperty(n).type===N.Object?e[n]=this.valueSets[n].getValuesForKeys(t[n]):e[n]=this.getValue(n);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===N.Object)t[e]=this.valueSets[e].getTimestamps();else{const l=this.ownTimestamps[e];l&&(t[e]=l)}return t}hasValue(t){const e=this.getValue(t);return!Ce(e)}hasSetValue(t){const e=this.getValue(t),n=this.propertySet.getProperty(t);return n&&n.type===N.Object?this.getSubValueSet(t).hasAnySetValue():!Ce(e)&&!wt(e,n?.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const n=this.propertySet.getProperty(t);if(n){n.type===N.Object?this.valueSets[t].setValues(e):(this.values[t]=e,wt(e,n.defaultValue)||this.displayProperty(n));const l=n.rootAttribute;l!=null&&this.setRootElementValue(l,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===N.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===N.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const n in t)this.propertySet.getProperty(n).type===N.Object?this.valueSets[n].overwriteValuesLww(t[n],e):yt(e,this.ownTimestamps[n])&&(this.setValue(n,t[n]),this.ownTimestamps[n]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),n=e.rootAttribute;e.type===N.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),n!=null&&e.defaultValue!==void 0&&!wt(this.getRootElementValue(n),e.defaultValue)&&this.setRootElementValue(n,this.values[t]),e.basic!==!1?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),n=new Zt(e.properties),l=new pt(n,this.rootElement);return l.overwriteValues(structuredClone(e.defaultValue)),l}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),G(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),G(this.displayedProperties,t))}}const Q={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:Pe.Straight,style:fe.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class Oe{constructor(t){const e={...Q,...t};this.id=e.id,this.name=e.name,this.label=e.label;const n=it(e.look);if(this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const l=it(e.startMarkerLook);this.defaultStartMarkerLook=l.defaultLook,this.selectedStartMarkerLook=l.selectedLook,this.highlightedStartMarkerLook=l.highlightedLook,this.selectedAndHighlightedStartMarkerLook=l.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const l=it(e.endMarkerLook);this.defaultEndMarkerLook=l.defaultLook,this.selectedEndMarkerLook=l.selectedLook,this.highlightedEndMarkerLook=l.highlightedLook,this.selectedAndHighlightedEndMarkerLook=l.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 Zt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class at extends xt{constructor(t,e,n,l,a){if(t.connections.get(a)!==void 0)throw new Error(`DiagramConnection with id "${a}" already exists`);if(!a)throw new Error("DiagramConnection cannot have an empty or null id");super(t,a),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new pt(e.propertySet,this),this.originalData={},this.setStart(n),this.setEnd(l)}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new pt(t.propertySet,this)),this.model.canvas?.userSelection?.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=it(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=it(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=it(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(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise()}setStart(t){this.start!==t?(this.start!==void 0&&G(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0])):(this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&G(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0])):(this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0]),this.updateInView()}tighten(){const t=this.model.canvas?.allowConnectionLoops||!1,e=this.model.canvas?.allowSharingPorts!==!1,n=this.model.canvas?.allowSharingBothPorts||!1;if(this.start?.rootElement&&this.end){const l=this.start.rootElement.ports.map(a=>[a,a.distanceTo(this.end.coords)]).sort((a,i)=>a[1]-i[1]).map(a=>a[0]);t:for(const a of l){if(!t&&a===this.end||!a.allowsOutgoing||!e&&(a.incomingConnections.length===1&&a.incomingConnections[0]!==this||a.incomingConnections.length>1||a.outgoingConnections.length===1&&a.outgoingConnections[0]!==this||a.outgoingConnections.length>1))continue t;if(!n){for(const i of a.outgoingConnections)if(i!==this&&i.end===this.end)continue t;for(const i of a.incomingConnections)if(i!==this&&i.start===this.end)continue t}if(a===this.start)break t;this.setStart(a);break t}}if(this.end?.rootElement&&this.start){const l=this.end.rootElement.ports.map(a=>[a,a.distanceTo(this.start.coords)]).sort((a,i)=>a[1]-i[1]).map(a=>a[0]);t:for(const a of l){if(!t&&a===this.start||!a.allowsIncoming||!e&&(a.outgoingConnections.length===1&&a.outgoingConnections[0]!==this||a.outgoingConnections.length>1||a.incomingConnections.length===1&&a.incomingConnections[0]!==this||a.incomingConnections.length>1))continue t;if(!n){for(const i of a.incomingConnections)if(i!==this&&i.start===this.start)continue t;for(const i of a.outgoingConnections)if(i!==this&&i.end===this.start)continue t}if(a===this.end)break t;this.setEnd(a);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():$t}}class ki extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,n,l){let a;if(t instanceof Oe)a=t;else{const s=this.types.get(t);if(s===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);a=s}const i=new at(this.model,a,e,n,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){const e=this.get(t,!0);e&&(G(e.start?.outgoingConnections||[],e),G(e.end?.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",backgroundColor:"#00000000",horizontalAlign:At.Center,verticalAlign:Ut.Center,orientation:f.Top,fit:!1,shrink:!0};class ct extends xt{constructor(t,e,n,l,a,i,s,r,c,d,h,u,y,p,v,m){const k=`${e?.id}_field`;if(t.fields.get(k)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,k),this.textTimestamp=null,this.rootElement=e,this.coords=n,this.width=l,this.height=a,this.fontSize=i,this.fontFamily=s,this.color=r,this.selectedColor=c,this.horizontalAlign=d,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case f.Top:this.orientation=0;break;case f.Right:this.orientation=90;break;case f.Bottom:this.orientation=180;break;case f.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=y,this._text=y,this.editable=p,this.fit=v,this.shrink=m}get text(){return this._text}set text(t){(t==null||t?.trim()==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||$t}}class wi extends ht{constructor(t){super(),this.model=t}new(t,e,n,l,a,i,s,r,c,d,h,u,y,p,v){const m=new ct(this.model,t,e,s,r,n,l,a,i,c,d,h,u,y,p,v);return super.add(m),m.updateInView(),t!==void 0&&(t.label=m),m}remove(t){const e=this.get(t,!0);e&&(e.rootElement?.label!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const Z=o=>o?.margin===null||o?.margin===void 0?O.margin:typeof o.margin=="number"?o.margin:o.margin.length===0?O.margin:o.margin.length===1||o.margin.length===2?o.margin[0]:(o.margin.length===3,o.margin[2]),B=o=>o?.margin===null||o?.margin===void 0?O.margin:typeof o.margin=="number"?o.margin:o.margin.length===0?O.margin:o.margin.length===1?o.margin[0]:o.margin.length===2||o.margin.length===3?o.margin[1]:o.margin[3],tt=o=>o?.margin===null||o?.margin===void 0?O.margin:typeof o.margin=="number"?o.margin:o.margin.length===0?O.margin:o.margin.length===1?o.margin[0]:(o.margin.length===2||o.margin.length===3,o.margin[1]),F=o=>o?.margin===null||o?.margin===void 0?O.margin:typeof o.margin=="number"?o.margin:o.margin.length===0?O.margin:(o.margin.length===1||o.margin.length===2||o.margin.length===3,o.margin[0]),Pt=o=>o?.padding===null||o?.padding===void 0?O.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?O.padding:o.padding.length===1||o.padding.length===2?o.padding[0]:(o.padding.length===3,o.padding[2]),zt=o=>o?.padding===null||o?.padding===void 0?O.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?O.padding:o.padding.length===1?o.padding[0]:o.padding.length===2||o.padding.length===3?o.padding[1]:o.padding[3],Rt=o=>o?.padding===null||o?.padding===void 0?O.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?O.padding:o.padding.length===1?o.padding[0]:(o.padding.length===2||o.padding.length===3,o.padding[1]),Ot=o=>o?.padding===null||o?.padding===void 0?O.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?O.padding:(o.padding.length===1||o.padding.length===2||o.padding.length===3,o.padding[0]),Ie=1,Ae=1,Si=1,xi=1;class Ci{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 n=[];this.sections.push(n);for(const l of e)n.push(new Ii(l))}}}class Ii{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||$t,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=it(t.look||Ve);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class H extends xt{constructor(t,e,n,l,a,i,s,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=n,this.indexYInNode=l,this.coords=a,this.width=i,this.height=s}get name(){return this.label?.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.node?.look:this._selectedLook!==void 0?this._selectedLook:this.type?.selectedLook||this.node?.look:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type?.highlightedLook||this.node?.look:this._defaultLook!==void 0?this._defaultLook:this.type?.defaultLook||this.node?.look}set look(t){if(t){const e=it(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(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||Si}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||xi}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||$t}getResizableX(){const t=this.type;return t?.resizableX!==void 0?t.resizableX:this.node?.type?.resizableX||!1}getResizableY(){const t=this.type;return t?.resizableY!==void 0?t.resizableY:this.node?.type?.resizableY||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(a=>a.distanceTo(t)),n=e.indexOf(Math.min(...e));return this.ports[n]}}}getIncomingConnections(t=!1){const e=[];for(const n of this.ports)for(const l of n.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const n of this.ports)for(const l of n.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const n of this.ports){for(const l of n.incomingConnections)!t&&l.removed||e.push(l);for(const l of n.outgoingConnections)!t&&l.removed||e.push(l)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const n=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let a,i;switch(t){case f.Left:a=[n[0]-e,n[1]],i=[l[0],l[1]],a[1]-a[0]<this.getMinWidth()&&(a[0]=a[1]-this.getMinWidth());break;case f.Top:a=[n[0],n[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case f.Right:a=[n[0],n[1]+e],i=[l[0],l[1]],a[1]-a[0]<this.getMinWidth()&&(a[1]=a[0]+this.getMinWidth());break;case f.Bottom:a=[n[0],n[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[a[0],i[0]],width:a[1]-a[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){const e=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];for(const s of this.ports)s.move(Yt(s.coords,e,n,l,a,s.anchorPointX,s.anchorPointY));const i=this.type;this.label&&(this.label.coords=[this.coords[0]+B(i?.label),this.coords[1]+F(i?.label)],this.label.width=this.width-B(i?.label)-tt(i?.label),this.label.height=this.height-F(i?.label)-Z(i?.label),this.label.updateInView());for(const s of this.decorators)s.move(Yt(s.coords,e,n,l,a,s.anchorPointX,s.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(s=>s.tighten()),this.updateInView()}}class Ai extends ht{constructor(t){super(),this.model=t}new(t,e,n,l,a,i,s){const r=new H(this.model,t,e,n,l,a,i,s);super.add(r),r.updateInView(),t.sections.push(r),t.updateInView();const c=t.type.sectionGrid?.sections?.[n]?.[e]?.ports;if(c&&c.length>0)for(let h=0;h<c.length;++h){const u=c[h],y=this.model.ports.new(u.type!==void 0?this.model.ports.types.get(u.type):void 0,r,[r.coords[0]+(u.coords[0]||0),r.coords[1]+(u.coords[1]||0)],u.connectionPoint!==void 0?[r.coords[0]+(u.connectionPoint[0]||0),r.coords[1]+(u.connectionPoint[1]||0)]:void 0,u?.direction,`${r.id}_${h}`,u.anchorPointX||"floating",u.anchorPointY||"floating");if(y.type?.label){const p={...O,...y.type?.label},v=6*p.fontSize+zt(p)+Rt(p),m=p.fontSize+Ot(p)+Pt(p);let k;switch(y.direction){case f.Bottom:case f.Left:case f.Right:k=[y.coords[0]-v/2,y.coords[1]-m-Z(p)];break;case f.Top:k=[y.coords[0]-v/2,y.coords[1]+F(p)];break;default:k=y.coords}this.model.fields.new(y,k,p.fontSize,p.fontFamily,p.color,p.selectedColor,v,m,p.horizontalAlign,p.verticalAlign,p.orientation,"",p.editable,p.fit,p.shrink)}}const d=t.type.sectionGrid?.sections?.[n]?.[e]?.label;if(d){const h={...O,...d};this.model.fields.new(r,[r.coords[0]+B(h),r.coords[1]+F(h)],h.fontSize,h.fontFamily,h.color,h.selectedColor,r.width-B(h)-tt(h),r.height-F(h)-Z(h),h.horizontalAlign,h.verticalAlign,h.orientation,"",h.editable,h.fit,h.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&&G(e.node.sections,e),super.remove(t),e.updateInView()}}}const Ve={lookType:"shaped-look",shape:Tt.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},dt={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:Ve,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:$t,properties:[]};class _e{constructor(t){const e={...dt,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.bottomPadding=Li(e),this.leftPadding=Ti(e),this.rightPadding=$i(e),this.topPadding=Ni(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new Ci(e.sectionGrid):null;const n=it(e.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new Zt(t?.properties||[])}}class z extends xt{constructor(t,e,n=[0,0],l){if(t.nodes.get(l)!==void 0)throw new Error(`DiagramNode with id "${l}" already exists`);if(!l)throw new Error("DiagramNode cannot have an empty or null id");super(t,l),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new pt(e.propertySet,this),this.originalData={},this.coords=n,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new pt(t.propertySet,this)),this.model.canvas?.userSelection?.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(){return this.label?.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=it(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(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(const t of this.sections)t.raise();this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise();for(const t of this.children)t.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(a=>a.distanceTo(t)),n=e.indexOf(Math.min(...e));return this.ports[n]}}}getIncomingConnections(t=!1){const e=[];for(const n of this.ports)for(const l of n.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const n of this.ports)for(const l of n.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const n of this.ports){for(const l of n.incomingConnections)!t&&l.removed||e.push(l);for(const l of n.outgoingConnections)!t&&l.removed||e.push(l)}return e}getAdjacentNodes(t=!1){const e=[];for(const n of this.ports){for(const l of n.incomingConnections){if(!t&&l.removed)continue;const a=l.start?.getNode();if(a){if(!t&&a.removed)continue;e.push(a)}}for(const l of n.outgoingConnections){if(!t&&l.removed)continue;const a=l.end?.getNode();if(a){if(!t&&a.removed)continue;e.push(a)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=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,n=!1;for(;e!==void 0;){if(e.id===t.id){n=!0;break}e=e.parent}n||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){G(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(r=>r.indexXInNode)),n=Math.max(...this.sections.map(r=>r.indexYInNode)),l=this.coords[0]-t.coords[0]+this.type.leftPadding;l>=0&&(this.sections.length>0?this.stretchSections(f.Left,l,e,n):this.stretch(f.Left,l));const a=this.coords[1]-t.coords[1]+this.type.topPadding;a>=0&&(this.sections.length>0?this.stretchSections(f.Top,a,e,n):this.stretch(f.Top,a));const i=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;i>=0&&(this.sections.length>0?this.stretchSections(f.Right,i,e,n):this.stretch(f.Right,i));const s=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;s>=0&&(this.sections.length>0?this.stretchSections(f.Bottom,s,e,n):this.stretch(f.Bottom,s)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const n of this.children)n.move([n.coords[0]+e[0],n.coords[1]+e[1]]);for(const n of this.sections)n.move([n.coords[0]+e[0],n.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const n=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let a,i;switch(t){case f.Left:a=[n[0]-e,n[1]],i=[l[0],l[1]],a[1]-a[0]<this.type.minWidth&&(a[0]=a[1]-this.type.minWidth);break;case f.Top:a=[n[0],n[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case f.Right:a=[n[0],n[1]+e],i=[l[0],l[1]],a[1]-a[0]<this.type.minWidth&&(a[1]=a[0]+this.type.minWidth);break;case f.Bottom:a=[n[0],n[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[a[0],i[0]],width:a[1]-a[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,n,l){let a=Number.NEGATIVE_INFINITY;switch(t){case f.Bottom:for(const i of this.sections)i.indexYInNode===l&&(a=Math.max(a,i.getMinHeight()-i.height));e<a&&(e=a);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode>l&&i.move([i.coords[0],i.coords[1]+e]);break;case f.Right:for(const i of this.sections)i.indexXInNode===n&&(a=Math.max(a,i.getMinWidth()-i.width));e<a&&(e=a);for(const i of this.sections)i.indexXInNode===n?i.stretch(t,e):i.indexXInNode>n&&i.move([i.coords[0]+e,i.coords[1]]);break;case f.Top:for(const i of this.sections)i.indexYInNode===l&&(a=Math.max(a,i.getMinHeight()-i.height));e<a&&(e=a);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode<l&&i.move([i.coords[0],i.coords[1]-e]);break;case f.Left:for(const i of this.sections)i.indexXInNode===n&&(a=Math.max(a,i.getMinWidth()-i.width));e<a&&(e=a);for(const i of this.sections)i.indexXInNode===n?i.stretch(t,e):i.indexXInNode<n&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const l of this.sections)e[l.id]=l.getGeometry();const n={};for(const l of this.children)l.id!==t&&(n[l.id]=l.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:n}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const s=t.children[i.id];s&&i.setGeometry(s)}for(const i of this.sections){const s=t.sections[i.id];s&&i.setGeometry(s)}for(const i of this.ports)i.move(Yt(i.coords,e,n,l,a,i.anchorPointX,i.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+B(this.type.label),this.coords[1]+F(this.type.label)],this.label.width=this.width-B(this.type.label)-tt(this.type.label),this.label.height=this.height-F(this.type.label)-Z(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Yt(i.coords,e,n,l,a,i.anchorPointX,i.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(i=>i.tighten()),this.updateInView()}removeSectionColumn(t){const e=this.type.sectionGrid?.margin||0;let n=0;const l=[...this.sections];for(const a of l)a.indexYInNode===t&&(n=Math.max(n,a.width),this.model.sections.remove(a.id));for(const a of l)a.indexYInNode>t&&(--a.indexYInNode,a.move([a.coords[0]-n-e,a.coords[1]]));this.stretch(f.Right,-e-n)}removeSectionRow(t){const e=this.type.sectionGrid?.margin||0;let n=0;const l=[...this.sections];for(const a of l)a.indexXInNode===t&&(n=Math.max(n,a.height),this.model.sections.remove(a.id));for(const a of l)a.indexYInNode>t&&(--a.indexXInNode,a.move([a.coords[0],a.coords[1]-n-e]));this.stretch(f.Bottom,-e-n)}copySectionColumn(t){const e=this.type.sectionGrid?.margin||0;let n=0;const l=[...this.sections];for(const a of l)if(a.indexXInNode===t){n=Math.max(n,a.width);let i=a.indexXInNode+1;for(;this.model.sections.get(`${a.id}_copy_${i}_${a.indexYInNode}`,!0)!==void 0;)++i;this.model.sections.new(this,a.indexXInNode+1,a.indexYInNode,[a.coords[0]+a.width+e,a.coords[1]],a.width,a.height,`${a.id}_copy_${i}_${a.indexYInNode}`)}for(const a of l)a.indexXInNode>t&&(++a.indexXInNode,a.move([a.coords[0]+n+e,a.coords[1]]));this.stretch(f.Right,e+n)}copySectionRow(t){const e=this.type.sectionGrid?.margin||0;let n=0;const l=[...this.sections];for(const a of l)if(a.indexYInNode===t){n=Math.max(n,a.height);let i=a.indexYInNode+1;for(;this.model.sections.get(`${a.id}_copy_${a.indexXInNode}_${i}`,!0)!==void 0;)++i;this.model.sections.new(this,a.indexXInNode,a.indexYInNode+1,[a.coords[0],a.coords[1]+a.height+e],a.width,a.height,`${a.id}_copy_${a.indexXInNode}_${i}`)}for(const a of l)a.indexYInNode>t&&(++a.indexYInNode,a.move([a.coords[0],a.coords[1]+n+e]));this.stretch(f.Bottom,e+n)}}class Ei extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,n){let l;if(t instanceof _e)l=t;else{const i=this.types.get(t);if(i===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);l=i}const a=new z(this.model,l,e,n);if(super.add(a),a.updateInView(),l.sectionGrid!==null){let i=a.coords[1]+(l.sectionGrid.margin||0);for(let s=0;s<l.sectionGrid.sections.length;++s){let r=a.coords[0]+(l.sectionGrid.margin||0);for(let c=0;c<l.sectionGrid.sections[s].length;++c)this.model.sections.new(a,c,s,[r,i],l.sectionGrid.defaultWidths?.[c]||Ie,l.sectionGrid.defaultHeights?.[s]||Ae,`${a.id}_${s}_${c}`),r+=(l.sectionGrid.defaultWidths?.[c]||Ie)+(l.sectionGrid.margin||0);i+=(l.sectionGrid.defaultHeights?.[s]||Ae)+(l.sectionGrid.margin||0)}}if(l.ports.length>0)for(let i=0;i<l.ports.length;++i){const s=l.ports[i],r=s.type!==void 0?this.model.ports.types.get(s.type):void 0,c=this.model.ports.new(r,a,[a.coords[0]+s.coords[0],a.coords[1]+s.coords[1]],s.connectionPoint!==void 0?[a.coords[0]+(s.connectionPoint[0]||0),a.coords[1]+(s.connectionPoint[1]||0)]:void 0,s.direction,`${a.id}_port_${i}`,s.anchorPointX||"floating",s.anchorPointY||"floating");if(c.type?.label){const d={...O,...c.type?.label},h=6*d.fontSize+zt(d)+Rt(d),u=d.fontSize+Ot(d)+Pt(d);let y;switch(c.direction){case f.Bottom:case f.Left:case f.Right:y=[c.coords[0]-h/2,c.coords[1]-u-Z(d)];break;case f.Top:y=[c.coords[0]-h/2,c.coords[1]+F(d)];break;default:y=c.coords}this.model.fields.new(c,y,d.fontSize,d.fontFamily,d.color,d.selectedColor,h,u,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink)}}if(l.label){const i={...O,...l.label};this.model.fields.new(a,[a.coords[0]+B(i),a.coords[1]+F(i)],i.fontSize,i.fontFamily,i.color,i.selectedColor,a.width-B(i)-tt(i),a.height-F(i)-Z(i),i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink)}if(l.decorators.length>0)for(let i=0;i<l.decorators.length;++i){const s=l.decorators[i];this.model.decorators.new(a,[a.coords[0]+s.coords[0],a.coords[1]+s.coords[1]],s.width,s.height,a.getPriority(),s.html,`${a.id}_decorator_${i}`,s.anchorPointX||"floating",s.anchorPointY||"floating")}return a.valueSet.resetValues(),a.model.canvas?.fitNodeInView(a.id),a}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&G(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 n=[];for(const l of this)l.coords[0]<t&&t<l.coords[0]+l.width&&l.coords[1]<e&&e<l.coords[1]+l.height&&n.push(l);return n}}const je=o=>{for(let t=0;t<o.length;++t)for(let e=0;e<o.length;++e)e!==t&&o[e].isAncestorOf(o[t])&&(o.splice(e,1),--e,t>e&&--t);return o},Li=o=>o?.padding===null||o?.padding===void 0?dt.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?dt.padding:o.padding.length===1||o.padding.length===2?o.padding[0]:(o.padding.length===3,o.padding[2]),Ti=o=>o?.padding===null||o?.padding===void 0?dt.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?dt.padding:o.padding.length===1?o.padding[0]:o.padding.length===2||o.padding.length===3?o.padding[1]:o.padding[3],$i=o=>o?.padding===null||o?.padding===void 0?dt.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?dt.padding:o.padding.length===1?o.padding[0]:(o.padding.length===2||o.padding.length===3,o.padding[1]),Ni=o=>o?.padding===null||o?.padding===void 0?dt.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?dt.padding:(o.padding.length===1||o.padding.length===2||o.padding.length===3,o.padding[0]),De={lookType:"shaped-look",shape:Tt.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Ht=it(De),Fe={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:De};class Mi{constructor(t){const e={...Fe,...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 n=it(e.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook}}class vt extends xt{constructor(t,e,n,l,a,i,s,r="floating",c="floating"){if(t.ports.get(s)!==void 0)throw new Error(`DiagramPort with id "${s}" already exists`);if(!s)throw new Error("DiagramPort cannot have an empty or null id");super(t,s),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=n,this.coords=l,this.connectionPoint=a||l,this.direction=i,this.anchorPointX=r,this.anchorPointY=c}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.updateInView())}get typeString(){return this.type?.id}set typeString(t){if(t!==this.type?.id)if(t===void 0)this.type=void 0;else{const e=this.model.ports.types.get(t);e&&(this.type=e)}}get allowsOutgoing(){return this.type?.allowsOutgoing!==void 0?this.type?.allowsOutgoing:!0}get allowsIncoming(){return this.type?.allowsIncoming!==void 0?this.type?.allowsIncoming:!0}get name(){return this.label?.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||Ht)?.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(this.type||Ht)?.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(this.type||Ht)?.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(this.type||Ht)?.defaultLook}set look(t){if(t){const e=it(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(){return this.type?.width||Fe.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updatePortsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.incomingConnections)t.raise();for(const t of this.outgoingConnections)t.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof z)return this.rootElement;if(this.rootElement instanceof H)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||$t}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 n of this.outgoingConnections)n.setStart(this);for(const n of this.incomingConnections)n.setEnd(this);this.label&&this.label.move([this.label.coords[0]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return Me(this.coords,t)}}class Pi extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,n,l,a,i,s="floating",r="floating"){const c=new vt(this.model,t,e,n,l,a,i,s,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 z||e.rootElement instanceof H)&&G(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class He{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 n of e.nodes||[])this.importNode(t,n);for(const n of e.connections||[])this.importConnection(t,n);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){const n=t.nodes.types.get(e.type);if(n){const l=new z(t,n,e.coords,e.id);if(t.nodes.add(l),l.width=e.width,l.height=e.height,e.label){if(n.decorators)for(let i=0;i<n.decorators.length;++i){const s=n.decorators[i];t.decorators.new(l,[l.coords[0]+s.coords[0],l.coords[1]+s.coords[1]],s.width,s.height,l.getPriority(),s.html,`${l.id}_decorator_${i}`)}if(n.label){const i={...O,...n.label},s=new ct(t,l,[l.coords[0]+B(i),l.coords[1]+F(i)],l.width-B(i)-tt(i),l.height-F(i)-Z(i),i.fontSize,i.fontFamily,i.color,i.selectedColor,i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink);s.text=e.label,l.label=s,t.fields.add(s),s.updateInView()}}for(const i of e.children||[]){const s=this.importNode(t,i);s!==void 0&&(l.children?.push(s),s.parent=l)}for(const i of e.sections||[]){const s=new H(t,l,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(l.sections?.push(s),t.sections.add(s),i.label&&n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){const c={...O,...n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label},d=new ct(t,s,[s.coords[0]+B(c),s.coords[1]+F(c)],s.width-B(c)-tt(c),s.height-F(c)-Z(c),c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);d.text=i.label,s.label=d,t.fields.add(d),d.updateInView()}let r=0;for(const c of i.ports||[]){const d=c.type!==void 0?t.ports.types.get(c.type):void 0,h=new vt(t,d,s,c.coords,c.connectionPoint||c.coords,c.direction,c.id);if(s.ports.push(h),t.ports.add(h),c.label){if(n.ports.length>r&&d?.label){const u={...O,...d?.label};let y;switch(h.direction){case f.Top:case f.Left:y=[h.coords[0]-u.fontSize,h.coords[1]-u.fontSize];break;case f.Bottom:y=[h.coords[0]-u.fontSize,h.coords[1]+u.fontSize];break;case f.Right:y=[h.coords[0]+u.fontSize,h.coords[1]-u.fontSize];break;default:y=h.coords}const p=new ct(t,h,y,u.fontSize,u.fontSize,u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,u.orientation,"",u.editable,u.fit,u.shrink);p.text=c.label,h.label=p,t.fields.add(p),p.updateInView()}++r}c.collabMeta&&(h.selfRemoved=c.collabMeta.selfRemoved,h.selfRemovedTimestamp=c.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(h.label,c.collabMeta.label)),h.updateInView()}i.collabMeta&&(s.selfRemoved=i.collabMeta.selfRemoved,s.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(s.label,i.collabMeta.label)),s.updateInView()}let a=0;for(const i of e.ports||[]){const s=i.type!==void 0?t.ports.types.get(i.type):void 0,r=new vt(t,s,l,i.coords,i.connectionPoint||i.coords,i.direction,i.id);if(l.ports.push(r),t.ports.add(r),i.label){if(n.ports.length>a&&s?.label){const c={...O,...s?.label};let d;switch(r.direction){case f.Top:case f.Left:d=[r.coords[0]-c.fontSize,r.coords[1]-c.fontSize];break;case f.Bottom:d=[r.coords[0]-c.fontSize,r.coords[1]+c.fontSize];break;case f.Right:d=[r.coords[0]+c.fontSize,r.coords[1]-c.fontSize];break;default:d=r.coords}const h=new ct(t,r,d,c.fontSize,c.fontSize,c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);h.text=i.label,r.label=h,t.fields.add(h),h.updateInView()}++a}i.collabMeta&&(r.selfRemoved=i.collabMeta.selfRemoved,r.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(r.label,i.collabMeta.label)),r.updateInView()}return e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(l.label,e.collabMeta.label),l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importConnection(t,e){const n=t.connections.types.get(e.type);if(n){const l=new at(t,n,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(l),l.startLabel=e.startLabel,l.middleLabel=e.middleLabel,l.endLabel=e.endLabel,l.points=e.points,e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class Kt{constructor(t,e,n,l,a,i,s){this.canvas=t,this.id=e,this.typeId=n,this.coords=l,this.parentId=a,this.label=i,this.values=s}do(){const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&this.canvas.model.nodes.get(this.parentId)?.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 Kt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class me{constructor(t,e,n,l,a,i,s){this.canvas=t,this.nodeId=e,this.copyColumnIndex=n,this.copyRowIndex=l,this.removeColumnIndex=a,this.removeRowIndex=i,this.timestamp=s}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&yt(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 me(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class pe{constructor(t,e,n){this.canvas=t,this.to=e,this.timestamp=n}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&yt(this.timestamp,e.geometryTimestamp)){const n=this.to[t];e.move([n[0],n[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new pe(t,e.to,e.timestamp)}}class Vt{constructor(t,e,n,l){this.canvas=t,this.nodeIds=e,this.delta=n,this.timestamp=l}do(){for(const t of this.nodeIds){const e=this.canvas.model.nodes.get(t,!0);e&&yt(this.timestamp,e.geometryTimestamp)&&(e.move([e.coords[0]+this.delta[0],e.coords[1]+this.delta[1]]),e.parent?.fitToChild(e),e.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new Vt(t,e.nodeIds,e.delta,e.timestamp)}}class et{constructor(t,e,n,l){this.canvas=t,this.nodeId=e,this.to=n,this.timestamp=l}do(){const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&yt(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),t.label?.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);for(const e of t.sections)e.label?.fit&&this.canvas.fitFieldRootInView(e.label.id,e.label.shrink);t.parent?.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 et(t,e.nodeId,e.to,e.timestamp)}}class _t{constructor(t,e,n,l,a){this.canvas=t,this.childId=e,this.parentId=n,this.childGeometry=l,this.timestamp=a}do(){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)&&yt(this.timestamp,t.geometryTimestamp)&&(t.parent?.removeChild(t),t.setGeometry(this.childGeometry),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 _t(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class qt{constructor(t,e,n,l,a){this.canvas=t,this.id=e,this.typeId=n,this.startId=l,this.endId=a}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 Et{constructor(t,e,n,l){this.canvas=t,this.fieldId=e,this.to=n,this.timestamp=l}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&yt(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 Et(t,e.fieldId,e.to,e.timestamp)}}class Lt{constructor(t,e,n,l){this.canvas=t,this.id=e,this.to=n,this.timestamp=l}getValueSet(){return this.id===void 0?this.canvas.model.valueSet:(this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))?.valueSet}do(){this.getValueSet()?.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Lt(t,e.id,e.to,e.timestamp)}}class nt{constructor(t,e,n,l,a,i,s,r){this.canvas=t,this.nodeIds=e,this.sectionIds=n,this.portIds=l,this.connectionIds=a,this.fieldIds=i,this.selfRemoved=s,this.timestamp=r}doOne(t){t&&yt(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 nt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class Jt{constructor(t,e,n){this.canvas=t,this.nodes=e,this.connections=n}do(){const t=new He;this.canvas.userSelection.clear();for(const e of this.nodes){const n=t.importNode(this.canvas.model,e);n&&this.canvas.userSelection.add(n)}for(const e of this.connections){const n=t.importConnection(this.canvas.model,e);n&&this.canvas.userSelection.add(n)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new Jt(t,e.nodes,e.connections)}}class zi{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=xe()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+xe()}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":{Kt.deserialize(this.canvas,t).do();break}case"addSection":{me.deserialize(this.canvas,t).do();break}case"applyLayout":{pe.deserialize(this.canvas,t).do();break}case"move":{Vt.deserialize(this.canvas,t).do();break}case"setGeometry":{et.deserialize(this.canvas,t).do();break}case"setParent":{_t.deserialize(this.canvas,t).do();break}case"addConnection":{qt.deserialize(this.canvas,t).do();break}case"editField":{Et.deserialize(this.canvas,t).do();break}case"updateValues":{Lt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{nt.deserialize(this.canvas,t).do();break}case"paste":{Jt.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class Ri{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 w=(o=>(o.AddConnection="add-connection",o.AddNode="add-node",o.AddSectionAction="add-section",o.ApplyLayout="apply-layout",o.Clipboard="clipboard",o.ContextMenu="context-menu",o.EditField="edit-field",o.MoveNode="move-node",o.Paste="paste",o.Remove="remove",o.StretchNode="stretch-node",o.StretchSection="stretch-section",o.UpdateValues="update-values",o.Zoom="zoom",o))(w||{});class Oi{constructor(t,e,n,l,a,i,s,r,c){this.canvas=t,this.type=e,this.coords=n,this.parentId=l,this.ancestorId=a,this.fromAncestorGeometry=i,this.toAncestorGeometry=s,this.label=r,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Kt(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 et(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 nt(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const n=new et(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new nt(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const n=new et(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return t===void 0}}class ie{constructor(t,e,n){this.canvas=t,this.nodeIds=e,this.delta=n}do(){const t=new Vt(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 Vt(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 U{constructor(t,e,n,l,a,i,s,r){this.canvas=t,this.intent=e,this.nodeId=n,this.from=l,this.to=a,this.ancestorId=i,this.fromAncestorGeometry=s,this.toAncestorGeometry=r}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new et(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 n=new et(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new et(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 n=new et(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new et(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Vi{constructor(t,e,n,l,a,i,s,r,c){this.canvas=t,this.childId=e,this.fromParentId=n,this.toParentId=l,this.fromChildGeometry=a,this.toChildGeometry=i,this.ancestorId=s,this.fromAncestorGeometry=r,this.toAncestorGeometry=c}do(){const t=this.canvas.model.nodes.get(this.childId),e=new _t(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 n=new et(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new _t(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 n=new et(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return t!==void 0}redo(){return this.do()}}class oe{constructor(t,e,n,l){this.canvas=t,this.type=e,this.startId=n,this.endId=l,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 nt(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 nt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class Ee{constructor(t,e,n,l){this.canvas=t,this.fieldId=e,this.from=n,this.to=l}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new Et(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 Et(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 Et(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class _i{constructor(t,e,n,l){this.canvas=t,this.id=e,this.from=n,this.to=l}do(){const t=new Lt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Lt(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 Lt(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 ji{constructor(t,e,n,l,a,i){this.canvas=t,this.nodeIds=e,this.sectionIds=n,this.portIds=l,this.connectionIds=a,this.fieldIds=i}do(){const t=this.nodeIds.map(n=>this.canvas.model.nodes.get(n)!==void 0).includes(!0)||this.sectionIds.map(n=>this.canvas.model.sections.get(n)!==void 0).includes(!0)||this.portIds.map(n=>this.canvas.model.ports.get(n)!==void 0).includes(!0)||this.connectionIds.map(n=>this.canvas.model.connections.get(n)!==void 0).includes(!0)||this.fieldIds.map(n=>this.canvas.model.fields.get(n)!==void 0).includes(!0),e=new nt(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(n=>this.canvas.model.nodes.get(n)===void 0).includes(!0)||this.sectionIds.map(n=>this.canvas.model.sections.get(n)===void 0).includes(!0)||this.portIds.map(n=>this.canvas.model.ports.get(n)===void 0).includes(!0)||this.connectionIds.map(n=>this.canvas.model.connections.get(n)===void 0).includes(!0)||this.fieldIds.map(n=>this.canvas.model.fields.get(n)===void 0).includes(!0),e=new nt(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 Di{constructor(t,e,n,l){this.canvas=t,this.nodes=e,this.connections=n,this.coords=l}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const a of this.nodes)a.coords[0]<t[0]&&(t[0]=a.coords[0]),a.coords[1]<t[1]&&(t[1]=a.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,n={};for(const a of this.nodes){const i=a.id,s=this.canvas.collabEngine.freshId();if(n[i]=s,a.id=s,e&&(a.coords=[a.coords[0]+e[0],a.coords[1]+e[1]]),a.sections)for(const r of a.sections){const c=r.id;if(r.id.includes(a.id)?r.id=r.id.replace(a.id,s):r.id=this.canvas.collabEngine.freshId(),n[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(a.id)?d.id=d.id.replace(a.id,s):d.id=this.canvas.collabEngine.freshId(),n[h]=d.id,e&&(d.coords=[d.coords[0]+e[0],d.coords[1]+e[1]],d.connectionPoint&&(d.connectionPoint=[d.connectionPoint[0]+e[0],d.connectionPoint[1]+e[1]]))}}if(a.ports)for(const r of a.ports){const c=r.id;r.id.includes(a.id)?r.id=r.id.replace(a.id,s):r.id=this.canvas.collabEngine.freshId(),n[c]=r.id,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]],r.connectionPoint&&(r.connectionPoint=[r.connectionPoint[0]+e[0],r.connectionPoint[1]+e[1]]))}}for(const a of this.connections){const i=this.canvas.collabEngine.freshId();if(n[a.id]=i,a.id=i,a.start=n[a.start]||a.start,a.end=n[a.end]||a.end,e)for(let s=0;s<a.points.length;++s)a.points[s]=[a.points[s][0]+e[0],a.points[s][1]+e[1]]}const l=new Jt(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(l),!0}undo(){const t=this.nodes.map(n=>this.canvas.model.nodes.get(n.id)!==void 0).includes(!0)||this.connections.map(n=>this.canvas.model.connections.get(n.id)!==void 0).includes(!0),e=new nt(this.canvas,this.nodes.map(n=>n.id),[],[],this.connections.map(n=>n.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=this.nodes.map(n=>this.canvas.model.nodes.get(n.id)===void 0).includes(!0)||this.connections.map(n=>this.canvas.model.connections.get(n.id)===void 0).includes(!0),e=new nt(this.canvas,this.nodes.map(n=>n.id),[],[],this.connections.map(n=>n.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class Qt{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Be=(o=>(o[o.DoubleClick=0]="DoubleClick",o[o.SecondaryClick=1]="SecondaryClick",o[o.Selection=2]="Selection",o[o.Highlight=3]="Highlight",o))(Be||{});class ut extends Qt{constructor(t,e,n){super(0),this.cause=t,this.target=e,this.coords=n}}class ft extends Qt{constructor(t,e,n){super(1),this.cause=t,this.target=e,this.coords=n}}class D extends Qt{constructor(t,e){super(2),this.targets=t,this.selected=e}}class q extends Qt{constructor(t){super(3),this.target=t}}class Ge extends xt{constructor(t,e,n,l,a,i,s,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=n,this.width=l,this.height=a,this.priority=i,this.html=s,this.anchorPointX=c,this.anchorPointY=d}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateDecoratorsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Fi extends ht{constructor(t){super(),this.model=t}new(t,e,n,l,a,i,s,r="floating",c="floating"){const d=new Ge(this.model,t,e,n,l,a,i,s,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 z||e.rootElement instanceof H)&&G(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Hi extends xt{constructor(t,e,n,l,a,i,s){if(t.objects.get(s)!==void 0)throw new Error(`DiagramObject with id "${s}" already exists`);if(!s)throw new Error("DiagramObject cannot have an empty or null id");super(t,s),this.coords=e,this.width=n,this.height=l,this.priority=a,this.html=i}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateObjectsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Bi extends ht{constructor(t){super(),this.model=t}new(t,e,n,l,a,i){const s=new Hi(this.model,t,e,n,l,a,i);return super.add(s),s.updateInView(),s}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Ue{constructor(t,e,n,l,a,i=[]){this.nodes=new Ei(this),this.sections=new Ai(this),this.ports=new Pi(this),this.connections=new ki(this),this.fields=new wi(this),this.objects=new Bi(this),this.decorators=new Fi(this),this.canvas=t,this.id=e,this.name=n,this.description=l,this.type=a,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new pt(new Zt(i),this)}clear(){this.canvas?.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(),this.canvas?.updateModelInView()}}const mt=o=>!!o.button,se=(o,t,e,n,l,a,i,s)=>si(o,[t,e],n,l,Math.max(10,i||0,s||0)*a),S=o=>{o?E.select("body").style("cursor",o):E.select("body").style("cursor",L.Auto)},lt=o=>o instanceof z?o:o instanceof H?o.node||o:o.rootElement instanceof z||o.rootElement instanceof H||o.rootElement instanceof vt?lt(o.rootElement):o,ne=o=>{o.filter(".shaped-look").append("path"),o.filter(".image-look").append("image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none")},Nt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:fe.Solid},re=o=>{o.filter(".shaped-look").select("path").attr("d",t=>he(t.look.shape||Tt.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||Nt.fillColor).attr("stroke",t=>t.look.borderColor||Nt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||Nt.borderThickness}px`).attr("stroke-dasharray",t=>de(t.look.borderStyle||Nt.borderStyle,t.type?.defaultLook?.borderThickness||t.look?.borderThickness||Nt.borderThickness)),o.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),o.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),o.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),o.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),o.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),o.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),o.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),o.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),o.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),o.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)},Mt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Gi=(o,t,e)=>{const n=t.append("defs");if(o.gridSize>0&&isFinite(o.gridSize)){const l=n.append("pattern").attr("id",e).attr("x",-o.gridSize/2).attr("y",-o.gridSize/2).attr("width",o.gridSize).attr("height",o.gridSize).attr("patternUnits","userSpaceOnUse");switch(l.append("rect").attr("x",0).attr("y",0).attr("width",o.gridSize).attr("height",o.gridSize).attr("fill",o.backgroundColor),o.gridStyle){case"dots":l.append("circle").attr("cx",o.gridSize/2).attr("cy",o.gridSize/2).attr("r",o.gridSize*o.gridThickness).attr("fill",o.gridColor);break;case"lines":l.append("line").attr("x1",o.gridSize/2).attr("x2",o.gridSize/2).attr("y1",0).attr("y2",o.gridSize).attr("stroke-width",o.gridSize*o.gridThickness).attr("stroke",o.gridColor),l.append("line").attr("x1",0).attr("x2",(o.gridSize-o.gridSize*o.gridThickness)/2).attr("y1",o.gridSize/2).attr("y2",o.gridSize/2).attr("stroke-width",o.gridSize*o.gridThickness).attr("stroke",o.gridColor),l.append("line").attr("x1",(o.gridSize+o.gridSize*o.gridThickness)/2).attr("x2",o.gridSize).attr("y1",o.gridSize/2).attr("y2",o.gridSize/2).attr("stroke-width",o.gridSize*o.gridThickness).attr("stroke",o.gridColor);break}t.select("rect").attr("fill",`url(#${e})`)}},ge=96,Y=32,It=ge+Y,Ui=Math.PI/4,Yi=100,Le={customButtons:[]};class Xi{constructor(t,e){this.canvas=t,this.config=e||Le}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),n=this.canvas.getPointerLocationRelativeToCanvas(t),l=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-It}px`).attr("y",`${e[1]-It}px`).attr("width",`${2*It}px`).attr("height",`${2*It}px`).style("pointer-events","none").on(C.ContextMenu,i=>{this.canvas.canUserPerformAction(w.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(C.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=l;const a=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Clipboard)&&this.canvas.canUserPerformAction(w.Remove)&&a.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.userSelection.cutToClipboard(),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Clipboard)&&a.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.userSelection.copyToClipboard(),i.cancelAllUserActions()}}),this.canvas.canUserPerformAction(w.Paste)&&a.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.userSelection.pasteFromClipboard(i.getClosestGridPoint(n)),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Remove)&&a.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.userSelection.removeFromModel(),i.cancelAllUserActions()}});for(const i of this.config.customButtons||Le.customButtons)(i.condition===void 0||i.condition(this.canvas))&&a.push(i);a.length===0&&a.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<a.length;++i){const s=a[i],r=s.onPress,c=(i+.5-a.length/2)*Ui,d=l.append("xhtml:div").attr("class",`daga-context-menu-button ${s.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*Y}px`).style("height",`${2*Y}px`).style("border-radius",`${Y}px`).style("pointer-events","auto").on(C.Click,h=>{r&&(h.preventDefault(),r(this.canvas))}).on(C.KeyDown,h=>{r&&h.key===W.Enter&&(h.preventDefault(),r(this.canvas))});s.imageClass!==void 0?d.append("xhtml:div").style("position","absolute").style("left",`${.75*Y}px`).style("top",`${.5*Y}px`).style("width",`${.5*Y}px`).style("height",`${.5*Y}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",s.imageClass):s.image!==void 0&&d.append("xhtml:img").style("position","absolute").style("left",`${.75*Y}px`).style("top",`${.5*Y}px`).style("width",`${.5*Y}px`).style("height",`${.5*Y}px`).attr("src",s.image),d.append("xhtml:span").style("position","absolute").style("left",`${.2*Y}px`).style("top",`${1.1*Y}px`).style("text-align","center").style("width",`${1.6*Y}px`).style("height",`${.35*Y}px`).style("margin","0").style("font-size",`${.35*Y}px`).style("font-weight","700").style("user-select","none").text(s.name),d.transition().ease(E.easeLinear).duration(Yi).tween("progress",()=>h=>{const u=c*h;return d.style("left",`${Math.sin(u)*ge-Y+It}px`).style("top",`${-Math.cos(u)*ge-Y+It}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}}class Wi extends ht{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 ct||t instanceof Ge)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof z){if(!this.highlightSections)for(const e of t.sections){super.add(e);for(const n of e.ports)super.add(n),this.canvas.updatePortsInView(n.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 H)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 vt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof at&&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 Zi=1;class Ye{export(t,e=!1){const n={name:t.name,type:t.type,typeVersion:Zi,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(n.id=t.id),t.description&&(n.description=t.description);for(const l of t.nodes.all(!0))!e&&l.removed||l.parent===void 0&&n.nodes.push(this.exportNode(l,e));for(const l of t.connections.all(!0))!e&&l.removed||n.connections.push(this.exportConnection(l,e));return n}exportNode(t,e=!1){const n=[];for(const i of t.children)n.push(this.exportNode(i,e));const l=[];for(const i of t.sections){const s=[];for(const r of i.ports)s.push({id:r.id,type:r.type?.id,coords:Ct(r.coords),connectionPoint:Ct(r.connectionPoint||r.coords),direction:r.direction,label:r.label?.text||"",...e?{collabMeta:{removed:r.removed,selfRemoved:r.selfRemoved,selfRemovedTimestamp:r.selfRemovedTimestamp,...this.exportLabelCollabMeta(r)}}:{}});l.push({id:i.id,ports:s,label:i.label?.text||"",indexXInNode:i.indexXInNode,indexYInNode:i.indexYInNode,coords:Ct(i.coords),width:i.width,height:i.height,...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}})}const a=[];for(const i of t.ports)a.push({id:i.id,type:i.type?.id,coords:Ct(i.coords),connectionPoint:Ct(i.connectionPoint||i.coords),direction:i.direction,label:i.label?.text||"",...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}});return{id:t.id,type:t.type.id,children:n,sections:l,ports:a,label:t.label?.text||"",coords:Ct(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){return{id:t.id,type:t.type.id,start:t.start?.id||"",end:t.end?.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 Ki="Diagram properties";class qi extends ht{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(kt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof z||t instanceof at)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof H?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof z&&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 z&&e.sections))for(const n of e.sections)super.remove(n.id),n.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 z&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],n=[],l=[],a=[];for(const s of this.all())s instanceof z?t.push(s.id):s instanceof H?e.push(s.id):s instanceof vt?n.push(s.id):s instanceof at?l.push(s.id):s instanceof ct&&a.push(s.id);const i=new ji(this.canvas,t,e,n,l,a);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Ye;for(const n of this.all())n instanceof z&&t.nodes.push(e.exportNode(n,!1)),n instanceof at&&t.connections.push(e.exportConnection(n,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const n=JSON.parse(e);if(n.type!=="daga-user-selection")return;const l=new Di(this.canvas,n.nodes,n.connections,t);this.canvas.actionStack.add(l),l.do()}catch{return}})}openInPropertyEditor(t,e=!0){e&&this.makeUpdateValuesAction();const n=this.canvas.parentComponent?.propertyEditor;if(n===void 0)return;const l=t?.valueSet;l?(this.propertyEditorSelection=t,e&&(this.propertyEditorValues=structuredClone(l.getValues())),n&&(t instanceof z||t instanceof at?(t instanceof z?t.name?n.title=`${t.type.name}: ${t.name}`:n.title=t.type.name:t instanceof at&&(n.title=t.type.name),n.valueSet=void 0,n.valueSet=l):(n.title=Ki,n.valueSet=void 0,n.valueSet=l))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,n&&(n.title="",n.valueSet=void 0))}makeUpdateValuesAction(){if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof Ue?void 0:this.propertyEditorSelection.id;if(wt(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;const e=this.propertyEditorValues,n=structuredClone(this.propertyEditorSelection?.valueSet.getValues()),[l,a]=Re(e,n,this.propertyEditorSelection?.valueSet),i=new _i(this.canvas,t,l,a);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=n}}const Ji=o=>o*Math.PI/180,Te=(o,t,e)=>{const n=Ji(e),l=Math.sin(n),a=Math.cos(n),i=(Math.abs(o*a)-Math.abs(t*l))/(a*a-l*l),s=(Math.abs(o*l)-Math.abs(t*a))/(l*l-a*a);return[i,s]},Qi=12,_=6,to=25,ae="diagram-connection-unfinished",Xt=class Xt{constructor(t,e){if(this.backgroundPatternId=`daga-background-pattern-id-${Xt.canvasCount++}`,this.zoomTransform=E.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new kt.Subject,this.diagramChange$=new kt.Subject,this.diagramEvent$=new kt.Subject,this.propertyEditorChanges$=new kt.Subject,this.parentComponent=t,this.model=new Ue(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new qi(this),this.userHighlight=new Wi(this,e.canvas?.highlightSections!==!1),this.contextMenu=new Xi(this,e.canvas?.contextMenu),this.backgroundColor=e.canvas?.backgroundColor||"#FFFFFF",this.gridStyle=e.canvas?.grid?.style??Mt.style,this.gridSize=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?0:Math.abs(e.canvas?.grid?.spacing||Mt.spacing),this.gridThickness=Math.abs(e.canvas?.grid?.thickness||Mt.thickness),this.gridColor=e.canvas?.grid?.color||Mt.color,this.snapToGrid=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?!1:e.canvas?.grid?.snap||Mt.snap,this.zoomFactor=e.canvas?.zoomFactor||2,this.panRate=e.canvas?.panRate||100,this.inferConnectionType=e.connectionSettings?.inferConnectionType||!1,this.autoTightenConnections=e.connectionSettings?.autoTighten!==!1,this.allowConnectionLoops=e.connectionSettings?.allowLoops||!1,this.allowSharingPorts=e.connectionSettings?.sharePorts!==!1,this.allowSharingBothPorts=e.connectionSettings?.shareBothPorts||!1,this.portHighlightRadius=e.connectionSettings?.portHighlightRadius||100,this.multipleSelectionOn=!1,this.priorityThresholds=e.canvas?.priorityThresholds||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new Ri(this,to),this.collabEngine=new zi(this),e.nodeTypes)for(const n of e.nodeTypes){const l=new _e({...e.nodeTypeDefaults,...n});this.model.nodes.types.add(l)}if(e.portTypes)for(const n of e.portTypes){const l=new Mi({...e.portTypeDefaults,...n});this.model.ports.types.add(l)}if(e.connectionTypes){for(const n of e.connectionTypes){const l=new Oe({...e.connectionTypeDefaults,...n});this.model.connections.types.add(l)}this._connectionType=e?.connectionSettings?.defaultConnection!==void 0?this.model.connections.types.get(e.connectionSettings.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){this._connectionType=t,this.parentComponent?.palette?.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){G(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){this.priorityThreshold=t,this.updateModelInView();for(const e of this.model.nodes)this.fitNodeInView(e.id);this.parentComponent?.palette?.refreshPalette()}initView(t){const e=E.select(t);e.html(""),this.diagramRoot=e.append("div").node(),E.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),E.select(this.diagramRoot).on(C.Click,()=>{E.select(this.diagramRoot).node()?.focus()}).on(C.ContextMenu,l=>{if(this.dragging){l.preventDefault(),l.stopPropagation(),this.dragging=!1;return}const a=new ft(l,null);this.diagramEvent$.next(a),!a.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(l.preventDefault(),this.contextMenu.open(l))}).on(C.DoubleClick,l=>{const a=new ut(l,null);this.diagramEvent$.next(a)}).on(C.KeyDown,l=>{if(!l.ctrlKey&&(l.key===W.Delete||l.key===W.Backspace)&&this.canUserPerformAction(w.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="a"){l.preventDefault();for(const a of this.model.nodes)this.userSelection.add(a);for(const a of this.model.connections)this.userSelection.add(a);this.diagramEvent$.next(new D(this.userSelection.all(),!0))}if(l.ctrlKey&&l.key==="i"){l.preventDefault();const a=[],i=[];for(const s of this.model.nodes)this.userSelection.toggle(s),s.selected?a.push(s):i.push(s);for(const s of this.model.connections)this.userSelection.toggle(s),s.selected?a.push(s):i.push(s);a.length>0&&this.diagramEvent$.next(new D(a,!0)),i.length>0&&this.diagramEvent$.next(new D(i,!1))}if(l.ctrlKey&&l.key==="c"&&this.canUserPerformAction(w.Clipboard)&&(l.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="x"&&this.canUserPerformAction(w.Clipboard)&&this.canUserPerformAction(w.Remove)&&(l.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="v"&&this.canUserPerformAction(w.Paste)){l.preventDefault();const a=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(a[0][0]+a[1][0])/2,(a[0][1]+a[1][1])/2])),this.cancelAllUserActions()}l.ctrlKey&&l.key==="y"&&(l.preventDefault(),this.actionStack.redo()),l.ctrlKey&&l.key==="z"&&(l.preventDefault(),this.actionStack.undo()),l.key==="+"&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.zoomBy(this.zoomFactor)),l.key==="-"&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.zoomBy(1/this.zoomFactor)),l.key===W.ArrowLeft&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowRight&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowDown&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),l.key===W.ArrowUp&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const n=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%");n.call(this.zoomBehavior=E.zoom().filter(l=>l.type!==C.DoubleClick).on(le.Zoom,l=>{if(l.sourceEvent){if(!this.canUserPerformAction(w.Zoom)){S(L.NotAllowed);return}l.sourceEvent.type===C.Wheel&&l.sourceEvent.wheelDelta!==void 0?(l.sourceEvent.wheelDelta>0&&S(L.ZoomIn),l.sourceEvent.wheelDelta<0&&S(L.ZoomOut)):l.sourceEvent.type===C.MouseMove&&S(L.AllScroll)}this.zoomTransform=l.transform;const a=l.transform.toString();this.selectCanvasElements().attr("transform",a),E.select(`#${this.backgroundPatternId}`).attr("patternTransform",a),this.contextMenu.close()}).on(le.End,()=>{S()})),n.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(C.MouseMove,l=>{if(this.unfinishedConnection!==void 0){const a=this.getPointerLocationRelativeToCanvas(l);this.unfinishedConnection.endCoords=a}}).on(C.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new q(null)))}).on(C.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new q(null))),this.contextMenu.close(),this.userSelection.size()>0){const l=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(l,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(E.drag().filter(l=>this.multipleSelectionOn||mt(l)).on(I.Start,l=>{this.startMultipleSelection(l)}).on(I.Drag,l=>{this.continueMultipleSelection(l)}).on(I.End,l=>{this.finishMultipleSelection(l)})),Gi(this,n,this.backgroundPatternId),n.append("g").attr("class","daga-canvas-elements")}getZoomLevel(){return this.zoomTransform.k}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView(),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView(),t)}getViewCoordinates(){return[this.zoomTransform.x,this.zoomTransform.y]}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(){if(this.model.nodes.length>0){const t=this.selectCanvasView().select("rect").node()?.getBBox(),e=this.model.nodes.all(),n=Math.min(...e.map(p=>p.coords[0])),l=Math.max(...e.map(p=>p.coords[0]+p.width)),a=(n+l)/2,i=l-n,s=t.width,r=Math.min(...e.map(p=>p.coords[1])),c=Math.max(...e.map(p=>p.coords[1]+p.height)),d=(r+c)/2,h=c-r,u=t.height,y=Math.min(s/i,u/h,1);this.translateTo(a,d),this.zoomTo(y)}}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(){const t=this.selectSVGElement().node()?.getBoundingClientRect(),e=[t?.width||0,t?.height||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return E.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return E.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return E.pointer(this.getEventHoldingCoordinates(t),E.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.defaultLook.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=l.merge(e);n.remove(),l.on(C.MouseOver,(i,s)=>{this.dragging||(this.userHighlight.focusOn(s),this.diagramEvent$.next(new q(s)))}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(r,!1))}this.userSelection.toggle(s),this.diagramEvent$.next(new D([s],s.selected))}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(s),this.diagramEvent$.next(new q(s)),this.userSelection.add(s),this.diagramEvent$.next(new D([s],!0)),this.contextMenu.open(i))}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,s)}).on(I.Drag,(i,s)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,s)}).on(I.End,(i,s)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,s),this.secondaryButton=!1})),ne(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed&&S(L.EWResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed?(S(L.EWResize),this.currentAction=new U(this,w.StretchNode,s.id,s.getGeometry(),s.getGeometry())):S(L.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed){const r=this.getPointerLocationRelativeToCanvas(i);s.stretch(f.Left,s.coords[0]-r[0])}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed&&this.currentAction instanceof U&&this.currentAction.intent===w.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.stretch(f.Left,s.coords[0]-r[0]),this.currentAction.to=s.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed&&S(L.NSResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed?(S(L.NSResize),this.currentAction=new U(this,w.StretchNode,s.id,s.getGeometry(),s.getGeometry())):S(L.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed){const r=this.getPointerLocationRelativeToCanvas(i);s.stretch(f.Top,s.coords[1]-r[1])}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed&&this.currentAction instanceof U&&this.currentAction.intent===w.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.stretch(f.Top,s.coords[1]-r[1]),this.currentAction.to=s.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed&&S(L.EWResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed?(S(L.EWResize),this.currentAction=new U(this,w.StretchNode,s.id,s.getGeometry(),s.getGeometry())):S(L.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed){const r=this.getPointerLocationRelativeToCanvas(i);s.stretch(f.Right,r[0]-(s.coords[0]+s.width))}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(w.StretchNode)&&s.type.resizableX&&!s.removed&&this.currentAction instanceof U&&this.currentAction.intent===w.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.stretch(f.Right,r[0]-(s.coords[0]+s.width)),this.currentAction.to=s.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed&&S(L.NSResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed?(S(L.NSResize),this.currentAction=new U(this,w.StretchNode,s.id,s.getGeometry(),s.getGeometry())):S(L.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed){const r=this.getPointerLocationRelativeToCanvas(i);s.stretch(f.Bottom,r[1]-(s.coords[1]+s.height))}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(w.StretchNode)&&s.type.resizableY&&!s.removed&&this.currentAction instanceof U&&this.currentAction.intent===w.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.stretch(f.Bottom,r[1]-(s.coords[1]+s.height)),this.currentAction.to=s.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),re(a),a.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),a.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updateSectionsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-section${i.getResizableX()?" resizable-x":""}${i.getResizableY()?" resizable-y":""} ${i.look?.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=l.merge(e);n.remove(),l.on(C.MouseOver,(i,s)=>{this.dragging||(this.userHighlight.focusOn(s),this.diagramEvent$.next(new q(s)))}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(c,!1))}const r=lt(s);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(s);this.userHighlight.focusOn(c),this.diagramEvent$.next(new q(c)),this.userSelection.add(c),this.diagramEvent$.next(new D([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const r=s?.node;r?this.startMovingNode(i,r):S(L.NotAllowed)}}).on(I.Drag,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const r=s?.node;r?this.continueMovingNode(i,r):S(L.NotAllowed)}}).on(I.End,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const r=s?.node;r?this.finishMovingNode(i,r):S()}this.secondaryButton=!1})),ne(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&S(L.EWResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&s.node?(S(L.EWResize),this.currentAction=new U(this,w.StretchSection,s.node.id,s.node.getGeometry(),s.node.getGeometry())):S(L.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&s.node){const r=this.getPointerLocationRelativeToCanvas(i);s.node.stretchSections(f.Left,s.coords[0]-r[0],s.indexXInNode,s.indexYInNode)}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&this.currentAction instanceof U&&this.currentAction.intent===w.StretchSection&&s.node){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.node.stretchSections(f.Left,s.coords[0]-r[0],s.indexXInNode,s.indexYInNode),this.currentAction.to=s.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&S(L.NSResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&s.node?(S(L.NSResize),this.currentAction=new U(this,w.StretchSection,s.node.id,s.node.getGeometry(),s.node.getGeometry())):S(L.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&s.node){const r=this.getPointerLocationRelativeToCanvas(i);s.node.stretchSections(f.Top,s.coords[1]-r[1],s.indexXInNode,s.indexYInNode)}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&this.currentAction instanceof U&&this.currentAction.intent===w.StretchSection&&s.node){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.node.stretchSections(f.Top,s.coords[1]-r[1],s.indexXInNode,s.indexYInNode),this.currentAction.to=s.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&S(L.EWResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&s.node?(S(L.EWResize),this.currentAction=new U(this,w.StretchSection,s.node.id,s.node.getGeometry(),s.node.getGeometry())):S(L.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&s.node){const r=this.getPointerLocationRelativeToCanvas(i);s.node.stretchSections(f.Right,r[0]-(s.coords[0]+s.width),s.indexXInNode,s.indexYInNode)}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(w.StretchSection)&&s.getResizableX()&&!s.removed&&this.currentAction instanceof U&&this.currentAction.intent===w.StretchSection&&s.node){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.node.stretchSections(f.Right,r[0]-(s.coords[0]+s.width),s.indexXInNode,s.indexYInNode),this.currentAction.to=s.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&S(L.NSResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&s.node?(S(L.NSResize),this.currentAction=new U(this,w.StretchSection,s.node.id,s.node.getGeometry(),s.node.getGeometry())):S(L.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&s.node){const r=this.getPointerLocationRelativeToCanvas(i);s.node.stretchSections(f.Bottom,r[1]-(s.coords[1]+s.height),s.indexXInNode,s.indexYInNode)}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(w.StretchSection)&&s.getResizableY()&&!s.removed&&this.currentAction instanceof U&&this.currentAction.intent===w.StretchSection&&s.node){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.node.stretchSections(f.Bottom,r[1]-(s.coords[1]+s.height),s.indexXInNode,s.indexYInNode),this.currentAction.to=s.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),re(a),a.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),a.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updatePortsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-port ${i.look.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=l.merge(e);n.remove(),l.on(C.MouseOver,(i,s)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(s),this.diagramEvent$.next(new q(s))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(s.getNode()?.type?.id||"")&&s.allowsIncoming||this.unfinishedConnection.type.canStartFromType(s.getNode()?.type?.id||"")&&s.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsIncoming||S(L.NoDrop))}).on(C.MouseOut,()=>{this.unfinishedConnection&&S(L.Grabbing)}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(c,!1))}const r=lt(s);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(s);this.userHighlight.focusOn(c),this.diagramEvent$.next(new q(c)),this.userSelection.add(c),this.diagramEvent$.next(new D([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(w.AddConnection)&&(this.allowSharingPorts||s.incomingConnections.length===0&&s.outgoingConnections.length===0)&&!s.removed?(S(L.Grabbing),this.startConnection(s),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):S(L.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(w.AddConnection)&&!s.removed&&this.unfinishedConnection!==void 0){const r=[i.x,i.y];this.unfinishedConnectionTracer?.attr("d",se(this.unfinishedConnection.look.shape||Q.look.shape,this.unfinishedConnection.startCoords,r,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.defaultLook.thickness||Q.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));const c=this.unfinishedConnectionTracer?.node();if(c){let d=2;const h=c.getTotalLength();h<d&&(d=0);const u=c.getPointAtLength(h-d);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=r;if(this.updateConnectionsInView(ae),this.model.ports.length>0){const d=this.getPointerLocationRelativeToCanvas(i);let h=Number.POSITIVE_INFINITY,u;for(const y of this.model.ports){const p=y.distanceTo(d);p<h&&(h=p,u=y)}u&&h<this.portHighlightRadius?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on(I.End,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(w.AddConnection)&&!s.removed){this.unfinishedConnectionTracer?.remove();const r=this.userHighlight.getFocus();if(r instanceof vt)this.finishConnection(r);else if(r instanceof ct&&r.rootElement instanceof vt)this.finishConnection(r.rootElement);else if(r instanceof z||r instanceof H||r instanceof ct){let c;if(r instanceof z||r instanceof H)c=r;else if(r.rootElement instanceof z||r.rootElement instanceof H)c=r.rootElement;else{this.dropConnection();return}const d=c.getClosestPortToPoint([i.x,i.y]);d!==void 0?this.finishConnection(d):this.dropConnection()}else this.dropConnection()}S()}this.secondaryButton=!1})),l.filter(".image-look").append("image"),ne(l),a.attr("transform",i=>`translate(${i.coords[0]-i.width/2},${i.coords[1]-i.width/2})`).attr("opacity",i=>i.removed?.5:1),re(a)}updateConnectionsInView(...t){const e=this.model.connections.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let n=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,s=>s.id);const l=n.exit(),a=n.enter().append("g").attr("id",s=>s.id).attr("class","diagram-connection");t&&t.length>0&&(n=n.filter(s=>t.includes(s.id)));const i=a.merge(n);l.remove(),a.on(C.MouseOver,(s,r)=>{r.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new q(r)))}).on(C.Click,(s,r)=>{if(!s.ctrlKey&&!s.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(c,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(C.ContextMenu,(s,r)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const c=new ft(s,r);this.diagramEvent$.next(c),!c.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(s.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new q(r)),this.userSelection.add(r),this.diagramEvent$.next(new D([r],!0)),this.contextMenu.open(s))}).on(C.DoubleClick,(s,r)=>{const c=new ut(s,r);this.diagramEvent$.next(c)}).call(E.drag().filter(s=>(this.secondaryButton=mt(s),!0)).on(I.Start,s=>{this.startMultipleSelection(s)}).on(I.Drag,s=>{this.continueMultipleSelection(s)}).on(I.End,s=>{this.finishMultipleSelection(s)})),a.append("path").attr("class","diagram-connection-path"),a.append("path").attr("class","diagram-connection-path-box"),a.append("marker").attr("id",s=>`${s.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),a.append("marker").attr("id",s=>`${s.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),a.append("g").attr("class","diagram-connection-start-label"),a.select("g.diagram-connection-start-label").append("path"),a.select("g.diagram-connection-start-label").append("text").style("user-select","none"),a.append("g").attr("class","diagram-connection-middle-label"),a.select("g.diagram-connection-middle-label").append("path"),a.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),a.append("g").attr("class","diagram-connection-end-label"),a.select("g.diagram-connection-end-label").append("path"),a.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",s=>s.removed?.5:1).select("path.diagram-connection-path").attr("d",s=>se(s.look.shape||Q.look.shape,s.startCoords,s.endCoords,s.startDirection,s.endDirection,s.type.defaultLook.thickness||Q.look.thickness,s.type.defaultStartMarkerLook?.width,s.type.defaultEndMarkerLook?.width)).attr("marker-start",s=>`url(#${s.id}-start-marker)`).attr("marker-end",s=>`url(#${s.id}-end-marker)`).attr("stroke",s=>s.look.color||Q.look.color).attr("stroke-width",s=>`${s.look.thickness}px`).attr("stroke-dasharray",s=>de(s.look.style||Q.look.style,s.type.defaultLook.thickness||Q.look.thickness)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",s=>se(s.look.shape||Q.look.shape,s.startCoords,s.endCoords,s.startDirection,s.endDirection,s.type.defaultLook.thickness||Q.look.thickness,s.type.defaultStartMarkerLook?.width,s.type.defaultEndMarkerLook?.width)).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",s=>`${(s.look.thickness||Q.look.thickness)+Qi}px`).attr("stroke-dasharray",s=>de(s.look.style||Q.look.style,s.type.defaultLook.thickness||Q.look.thickness)).attr("fill","none"),i.data().forEach(s=>{this.updateConnectionLabelsInView(s),this.updateConnectionMarkersInView(s)})}updateFieldsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=l.merge(e);n.remove(),l.style("box-sizing","border-box").on(C.MouseOver,(i,s)=>{this.dragging||(this.userHighlight.focusOn(s),this.diagramEvent$.next(new q(s)))}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(c,!1))}const r=lt(s);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(s);this.userHighlight.focusOn(c),this.diagramEvent$.next(new q(c)),this.userSelection.add(c),this.diagramEvent$.next(new D([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(w.EditField)&&s.editable&&!s.removed&&(this.currentAction=new Ee(this,s.id,s.text,""),this.createInputField(s.text,s.coords,s.width,s.height,s.fontSize,s.fontFamily||O.fontFamily,s.orientation,c=>{},c=>{s.text=c,this.currentAction instanceof Ee&&(this.currentAction.to=c,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof H&&(r=s.rootElement.node),r?this.startMovingNode(i,r):S(L.NotAllowed)}}).on(I.Drag,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof H&&(r=s.rootElement.node),r?this.continueMovingNode(i,r):S(L.NotAllowed)}}).on(I.End,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof H&&(r=s.rootElement.node),r?this.finishMovingNode(i,r):S()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),a.attr("x",0).attr("y",0).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("div").style("justify-content",i=>i.horizontalAlign===At.Center?"center":i.horizontalAlign===At.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Ut.Center?"center":i.verticalAlign===Ut.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":`${Te(i.width,i.height,i.orientation)[0]}px`).style("max-height",i=>i.fit?"default":`${Te(i.width,i.height,i.orientation)[1]}px`).style("overflow",i=>i.fit?"default":"clip").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===At.Center?"center":i.horizontalAlign===At.Right?"end":"start").style("transform",i=>`rotate(${i.orientation}deg)`).style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br/>"))}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),n.remove(),l.on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(i)}).on(I.Drag,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(i)}).on(I.End,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(i)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),n.remove(),l.on(C.MouseOver,(i,s)=>{this.dragging||(this.userHighlight.focusOn(s),this.diagramEvent$.next(new q(s)))}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(r,!1))}if(s.rootElement){const r=lt(s.rootElement);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&s.rootElement){i.preventDefault();const c=lt(s.rootElement);this.userHighlight.focusOn(c),this.diagramEvent$.next(new q(c)),this.userSelection.add(c),this.diagramEvent$.next(new D([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof H&&(r=s.rootElement.node),r?this.startMovingNode(i,r):S(L.NotAllowed)}}).on(I.Drag,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof H&&(r=s.rootElement.node),r?this.continueMovingNode(i,r):S(L.NotAllowed)}}).on(I.End,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof H&&(r=s.rootElement.node),r?this.finishMovingNode(i,r):S()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),l=e.select("path").node(),a={...O,...t.type.label};if(l){const i=l.getTotalLength();let s=0,r=0,c=0,d=0,h=0,u=0;if(a.backgroundColor==="#00000000"){const m=t.endCoords[0]-t.startCoords[0],k=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case f.Top:s=m>=0?-.5:.5,h=s;break;case f.Bottom:s=m>=0?-.5:.5,h=s;break;case f.Left:r=k>0?-.5:.5,u=r;break;case f.Right:r=k>0?-.5:.5,u=r;break;default:s=.5,h=s,r=-.5,u=r}switch(t.endDirection){case f.Top:h=m>=0?.5:-.5;break;case f.Bottom:h=m>=0?.5:-.5;break;case f.Left:u=k>0?.5:-.5;break;case f.Right:u=k>0?.5:-.5;break;default:h=.5,u=-.5}Math.abs(m)>=Math.abs(k)?(c=m>0?-.5:.5,d=k>0?.5:-.5):(c=m>0?.5:-.5,d=k>0?-.5:.5)}e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",a.fontSize/3).attr("text-anchor","middle").attr("font-family",a.fontFamily).attr("font-size",a.fontSize).attr("fill",t.selected?a.selectedColor:a.color).style("font-kerning","none").text(t.startLabel);const y=e.select("g.diagram-connection-start-label text").node()?.getBoundingClientRect();if(y){const m=t.startLabel?y.width/this.zoomTransform.k+zt(a)+Rt(a):0,k=t.startLabel?y.height/this.zoomTransform.k+Ot(a)+Pt(a):0;let b;switch(t.startDirection){case f.Left:b=l.getPointAtLength(tt(a)+m/2);break;case f.Right:b=l.getPointAtLength(B(a)+m/2);break;case f.Top:b=l.getPointAtLength(Z(a)+m/2);break;case f.Bottom:b=l.getPointAtLength(F(a)+m/2);break;default:b=l.getPointAtLength(Math.max(B(a)+m/2,tt(a)+m/2,F(a)+k/2,Z(a)+k/2))}e.select("g.diagram-connection-start-label path").attr("d",Gt(-m/2,-k/2,m,k)).attr("fill",a.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${b.x+s*m},${b.y+r*k})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",a.fontSize/3).attr("text-anchor","middle").attr("font-family",a.fontFamily).attr("font-size",a.fontSize).attr("fill",t.selected?a.selectedColor:a.color).style("font-kerning","none").text(t.middleLabel);const p=e.select("g.diagram-connection-middle-label text").node()?.getBoundingClientRect();if(p){const m=t.middleLabel?p.width/this.zoomTransform.k+zt(a)+Rt(a):0,k=t.middleLabel?p.height/this.zoomTransform.k+Ot(a)+Pt(a):0,b=l.getPointAtLength(i/2);e.select("g.diagram-connection-middle-label path").attr("d",Gt(-m/2,-k/2,m,k)).attr("fill",a.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${b.x+c*m},${b.y+d*k})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",a.fontSize/3).attr("text-anchor","middle").attr("font-family",a.fontFamily).attr("font-size",a.fontSize).attr("fill",t.selected?a.selectedColor:a.color).style("font-kerning","none").text(t.endLabel);const v=e.select("g.diagram-connection-end-label text").node()?.getBoundingClientRect();if(v){const m=t.endLabel?v.width/this.zoomTransform.k+zt(a)+Rt(a):0,k=t.endLabel?v.height/this.zoomTransform.k+Ot(a)+Pt(a):0;let b;switch(t.endDirection){case f.Left:b=l.getPointAtLength(i-(tt(a)+m/2));break;case f.Right:b=l.getPointAtLength(i-(B(a)+m/2));break;case f.Top:b=l.getPointAtLength(i-(Z(a)+m/2));break;case f.Bottom:b=l.getPointAtLength(i-(F(a)+m/2));break;default:b=l.getPointAtLength(i-Math.max(B(a)+m/2,tt(a)+m/2,F(a)+k/2,Z(a)+k/2))}e.select("g.diagram-connection-end-label path").attr("d",Gt(-m/2,-k/2,m,k)).attr("fill",a.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${b.x+h*m},${b.y+u*k})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),n=e.select("marker.diagram-connection-start-marker"),l=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?n.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):n.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?l.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):l.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof z||e.rootElement instanceof H){const n=this.minimumSizeOfField(e),l=n[0]+B(e.rootElement.type?.label)+tt(e.rootElement.type?.label)-e.rootElement.width,a=n[1]+F(e.rootElement.type?.label)+Z(e.rootElement.type?.label)-e.rootElement.height;return l<=0&&a<=0}return!0}fitFieldRootInView(t,e=!0){const n=this.model.fields.get(t);if(n){if(n.rootElement instanceof z){const l=this.minimumSizeOfField(n);let a=l[0]+B(n.rootElement.type.label)+tt(n.rootElement.type.label)-n.rootElement.width,i=l[1]+F(n.rootElement.type.label)+Z(n.rootElement.type.label)-n.rootElement.height;this.snapToGrid&&(a=Math.ceil(a/this.gridSize)*this.gridSize,i=Math.ceil(i/this.gridSize)*this.gridSize),n.rootElement.width+a<n.rootElement.type.minWidth&&(a=n.rootElement.type.minWidth-n.rootElement.width),n.rootElement.height+i<n.rootElement.type.minHeight&&(i=n.rootElement.type.minHeight-n.rootElement.height),(e!==!1||a>0)&&n.rootElement.stretch(f.Right,a),(e!==!1||i>0)&&n.rootElement.stretch(f.Bottom,i)}if(n.rootElement instanceof H){const l=this.minimumSizeOfField(n);let a=l[0],i=l[1];for(const d of n.rootElement.node?.sections||[])d.label&&(d.indexXInNode===n.rootElement.indexXInNode&&d.indexYInNode!==n.rootElement.indexYInNode?a=Math.max(a,this.minimumSizeOfField(d.label)[0]):d.indexXInNode!==n.rootElement.indexXInNode&&d.indexYInNode===n.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(d.label)[1])));l[0]<a&&(l[0]=a),l[1]<i&&(l[1]=i);const s=n.rootElement.type;let r=l[0]+B(s?.label)+tt(s?.label)-n.rootElement.width,c=l[1]+F(s?.label)+Z(s?.label)-n.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,c=Math.ceil(c/this.gridSize)*this.gridSize),n.rootElement.width+r<(n.rootElement.getMinWidth()||0)&&(r=(n.rootElement.getMinWidth()||0)-n.rootElement.width),n.rootElement.height+c<(n.rootElement.getMinHeight()||0)&&(c=(n.rootElement.getMinHeight()||0)-n.rootElement.height),(e||r>0)&&n.rootElement.node?.stretchSections(f.Right,r,n.rootElement.indexXInNode,n.rootElement.indexYInNode),(e||c>0)&&n.rootElement.node?.stretchSections(f.Bottom,c,n.rootElement.indexXInNode,n.rootElement.indexYInNode)}}}fitNodeInView(t,e=!0){const n=this.model.nodes.get(t);if(n&&n.sections.length>0&&this.priorityThreshold){let l=0,a=0;for(const i of n.sections)if(i.getPriority()>=this.priorityThreshold){const s=i.coords[0]+i.width-n.coords[0],r=i.coords[1]+i.height-n.coords[1];l=Math.max(l,s),a=Math.max(a,r)}l+=n.type.sectionGrid?.margin||0,a+=n.type.sectionGrid?.margin||0,(e||l>n.width)&&n.stretch(f.Right,l-n.width),(e||a>n.height)&&n.stretch(f.Bottom,a-n.height)}}selectRoot(){return E.select(this.diagramRoot)}selectSVGElement(){return E.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming))this.unfinishedConnection=new at(this.model,this.connectionType,t,void 0,ae);else if(this.inferConnectionType){let e=this.model.connections.types.all().find(n=>t.allowsOutgoing&&n.canStartFromType(t.getNode()?.type?.id||""));e===void 0&&(e=this.model.connections.types.all().find(n=>t.allowsIncoming&&n.canFinishOnType(t.getNode()?.type?.id||""))),e!==void 0&&(this.unfinishedConnection=new at(this.model,e,t,void 0,ae))}}}finishConnection(t){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(e=>e.start===this.unfinishedConnection?.start&&e.end===t||e.end===this.unfinishedConnection?.start&&e.start===t)!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming){const e=new oe(this,this.unfinishedConnection.type,this.unfinishedConnection.start?.id,t.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&this.unfinishedConnection.type.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing){const e=new oe(this,this.unfinishedConnection.type,t.id,this.unfinishedConnection.start?.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.inferConnectionType){let e=this.model.connections.types.all().find(l=>l.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&l.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming),n=!1;if(e===void 0&&(e=this.model.connections.types.all().find(l=>l.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&l.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing),n=!0),e!==void 0){const l=new oe(this,e,n?t.id:this.unfinishedConnection.start?.id,n?this.unfinishedConnection.start?.id:t.id);this.dropConnection(),l.do(),this.actionStack.add(l)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){this.unfinishedConnection?.setStart(void 0),this.unfinishedConnection?.setEnd(void 0),this.unfinishedConnection?.select()?.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,n,l,a,i,s,r,c){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${n}px`).attr("height",`${l}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const h=d.append("xhtml:textarea");let u,y;h.text(t).style("box-sizing","border-box").style("width",`${n}px`).style("height",`${l}px`).style("font-size",`${a}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(C.KeyDown,v=>{v.stopPropagation()}).on(C.KeyUp,v=>{if(v.stopPropagation(),v.key===W.Escape){const m=h.property("value");this.removeInputField(),c&&c(m)}}).on(C.Input,()=>{const v=h.property("value");h.attr("cols",gi(v)+1),h.attr("rows",ui(v)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,y=h.property("scrollHeight")+1;const m=Math.max(u,n),k=Math.max(y,l);d?.attr("width",`${m}px`),h.style("width",`${m}px`),d?.attr("height",`${k}px`),h.style("height",`${k}px`),r&&r(v)}).on(C.Click,v=>{v.stopPropagation()}).on(C.FocusOut,()=>{const v=h.property("value");this.removeInputField(),c&&c(v)});const p=h.node();p.focus(),p.select()}removeInputField(){this.inputFieldContainer?.select("input")?.on(C.Blur,null),this.inputFieldContainer?.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){const e=t.select()?.select("p")?.node();if(!e)return[0,0];const n=e.getBoundingClientRect();return[n.width/this.zoomTransform.k,n.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(w.MoveNode)&&!e.removed)if(S(L.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(n=>n instanceof z)>1)this.currentAction=new ie(this,this.userSelection.filter(n=>n instanceof z).map(n=>n.id),e.coords);else{const n=e.getLastAncestor();this.currentAction=new U(this,w.MoveNode,e.id,e.getGeometry(),e.getGeometry(),n?.id,n?.getGeometry(e.id),n?.getGeometry(e.id))}else S(L.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(w.MoveNode)&&(this.currentAction instanceof ie||this.currentAction instanceof U)&&!e.removed){const n=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([n[0]-e.coords[0],n[1]-e.coords[1]]):e.move(n),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){if(this.canUserPerformAction(w.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let n=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(n=this.getClosestGridPoint(n)),this.currentAction instanceof ie){const l=this.currentAction.delta;this.currentAction.delta=[n[0]-l[0],n[1]-l[1]],e.selected?this.userSelection.move([l[0]-e.coords[0],l[1]-e.coords[1]]):e.move(l)}else if(this.currentAction instanceof U){e.move(n);const a=this.model.nodes.getAtCoordinates(t.x,t.y).filter(r=>r.id!==e.id&&!r.isDescendantOf(e)).filter(r=>r.type.childrenTypes.includes(e.type.id)),i=je(a),s=i[i.length-1];if(s!==e.parent&&(e.type.canBeParentless||s!==void 0)){const r=s?.getLastAncestor(),c=this.currentAction.from,d=new Vi(this,e.id,e.parent?.id,s?.id,c,e.getGeometry(),r?.id,r?.getGeometry(e.id),r?.getGeometry(e.id));e.parent?.removeChild(e),s!==void 0&&s.addChild(e),d.toChildGeometry=e.getGeometry(e.id),d.toAncestorGeometry=r?.getGeometry(e.id),this.currentAction=d}else{const r=e?.getLastAncestor();this.currentAction.ancestorId=r?.id,this.currentAction.fromAncestorGeometry=r?.getGeometry(e.id),e.parent?.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=r?.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}S(),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){const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(S(L.Crosshair),this.multipleSelectionContainer?.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x)?.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y)?.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k)?.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);this.multipleSelectionContainer?.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const n of this.model.nodes)ii([n.coords,[n.coords[0]+n.width,n.coords[1]+n.height]],[this.draggingFrom,e])&&this.userSelection.add(n);this.multipleSelectionOn=!1,this.diagramEvent$.next(new D(this.userSelection.all(),!0)),S()}};Xt.canvasCount=0;let ue=Xt;class Xe{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 n=1;;++n){const l=n%2>0?n:-n,a=l>0?1:-1,i=[e[0]+l,e[1]+l];for(let s=e[0];s!==i[0]+a;s+=a)if(e[0]=s,this.get(e)===void 0)return e;for(let s=e[1];s!==i[1]+a;s+=a)if(e[1]=s,this.get(e)===void 0)return e}}}class eo{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Xe,n=t.nodes.filter(s=>!s.parent);for(;n.length>0;)We(n[0],e,[0,0],n);const l=Math.max(...t.nodes.map(s=>s.width)),a=Math.max(...t.nodes.map(s=>s.height)),i=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let s=e.minY();s<=e.maxY();++s)for(let r=e.minX();r<=e.maxX();++r){const c=e.get([r,s]);c!==void 0&&c.move([r*(l+i),s*(a+i)])}return t}}const We=(o,t,e,n)=>{const l=t.getClosestEmptyCoordinate(e);t.set(l,o),G(n,o);for(const a of o.getAdjacentNodes())n.includes(a)&&We(a,t,l,n)};class io{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Xe,n=t.nodes.filter(d=>!d.parent),l={},a=n[0];let i=[a];for(l[a.id]=[0,0];n.length>0;){const d=[];for(const h of i){e.set(e.getClosestEmptyCoordinate(l[h.id]),h),G(n,h);const u=h.getAdjacentNodes();for(const y of u)n.includes(y)&&(d.push(y),l[y.id]=l[h.id])}if(d.length>0)i=d;else if(n.length>0){const h=n[0];i=[h],l[h.id]=e.getClosestEmptyCoordinate([0,0])}}const s=Math.max(...t.nodes.map(d=>d.width)),r=Math.max(...t.nodes.map(d=>d.height)),c=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let d=e.minY();d<=e.maxY();++d)for(let h=e.minX();h<=e.maxX();++h){const u=e.get([h,d]);u!==void 0&&u.move([h*(s+c),d*(r+c)])}return t}}class te{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;let n=t.nodes.filter(s=>!s.parent);const l=n[0];G(n,l);const a=[[l]];for(;n.length>0;){const s=a[a.length-1],r=[];for(const c of s){const d=c.getAdjacentNodes();for(const h of d)n.includes(h)&&(G(n,h),r.push(h))}r.length>0?a.push(r):(a.push(n),n=[])}let i=0;for(const s of a){let r=0;for(const d of s)d.move([i,r]),r+=e+d.height;const c=Math.max(...s.map(d=>d.width));i+=e+c}for(const s of t.connections)s.tighten();return t}}class oo{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;new te(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=.99,l=1,a=.1,i=2e5,s=.5,r=1,c=.002;let d=100;for(;d>l;){d=d*n;const h=[0,0];{for(const u of t.nodes)h[0]=h[0]+u.coords[0]+u.width/2,h[1]=h[1]+u.coords[1]+u.width/2;h[0]=h[0]/t.nodes.length,h[1]=h[1]/t.nodes.length}for(const u of t.nodes){const y=u.getAdjacentNodes();for(const p of t.nodes){const v=[u.coords[0]+u.width/2,u.coords[1]+u.height/2],m=[p.coords[0]+p.width/2,p.coords[1]+p.height/2],k=Me(u.coords,p.coords),b=[p.coords[0],p.coords[1]];if(y.includes(p)&&k>0&&(k>e+(Math.max(u.width,u.height)+Math.max(p.width,p.height))/2?(b[0]=b[0]-(m[0]-v[0])*a,b[1]=b[1]-(m[1]-v[1])*a):(b[0]=b[0]+(m[0]-v[0])*s,b[1]=b[1]+(m[1]-v[1])*s)),k>0){const M=i/(k*k);b[0]=b[0]+M*(m[0]-v[0])/k,b[1]=b[1]+M*(m[1]-v[1])/k}else b[0]=b[0]+r*(Math.random()*2-1),b[1]=b[1]+r*(Math.random()*2-1);b[0]=b[0]-(m[0]-h[0])*c,b[1]=b[1]-(m[1]-h[1])*c,b[0]-p.coords[0]>d?b[0]=p.coords[0]+d:b[0]-p.coords[0]<-d&&(b[0]=p.coords[0]-d),b[1]-p.coords[1]>d?b[1]=p.coords[1]+d:b[1]-p.coords[1]<-d&&(b[1]=p.coords[1]-d),p.move(b)}}}if(t.canvas&&t.canvas.snapToGrid)for(const h of t.nodes){const u=t.canvas.getClosestGridPoint(h.coords);h.move(u)}for(const h of t.connections)h.tighten();return t}}class so{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=t.nodes.filter(a=>!a.parent);n.sort((a,i)=>i.type.priority-a.type.priority);let l=0;for(const a of n)a.move([l,0]),l+=a.width+e;return t}}class no{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),n=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===n)return new te(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(d=>!d.parent),i=[],s=t.nodes.filter(d=>!d.parent).filter(d=>d.getPriority()>=e),r=[];if(s.length>1){const d=s[0];s.splice(0,1),r.push(d);const h=[d],u=[d];for(;h.length>0;){const y=h[0];h.splice(0,1),s.includes(y)&&(r.push(y),G(s,y));const p=y.getAdjacentNodes();for(const v of p)u.includes(v)||(h.push(v),u.push(v))}for(const y of s)r.push(y)}else r.push(s[0]);for(const d of r)G(a,d),i.push([d]);for(i.push([]),a.sort((d,h)=>h.type.priority-d.type.priority);a.length>0;){const d=a[0];a.splice(0,1);const h=[d],u=[d];let y=!1;for(;h.length>0;){const p=h[0];h.splice(0,1);const v=r.indexOf(p);if(v>=0){i[v].push(d),y=!0;break}else{const m=p.getAdjacentNodes();for(const k of m)u.includes(k)||(h.push(k),u.push(k))}}y||i[i.length-1].push(d)}let c=0;for(let d=0;d<i.length;++d){let h=0;for(let y=0;y<i[d].length;++y){const p=i[d][y];p.move([c,h]),h+=l+p.height}const u=Math.max(...i[d].map(y=>y.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}class ro{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),n=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===n)return new te(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(d=>!d.parent).sort((d,h)=>h.getPriority()-d.getPriority()),i=[];for(;a.length>0;){const d=a[0];a.splice(0,1);const h=new ve(void 0,d);Ze(h,a),i.push(h)}const s=[];for(const d of i)s.push([d]),Ke(d,s,s.length);const r=Math.max(...t.nodes.map(d=>d.height));let c=0;for(let d=0;d<s.length;++d){let h=0;for(let y=0;y<s[d].length;++y){const p=s[d][y];p.node.move([c,h]),h+=(l+r)*p.countBranchHeight()}const u=Math.max(...s[d].map(y=>y.node.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}const Ze=(o,t)=>{for(const e of o.node.getAdjacentNodes().sort((n,l)=>l.getPriority()-n.getPriority())){const n=t.indexOf(e);if(n>=0){t.splice(n,1);const l=o.addBranch(e);Ze(l,t)}}},Ke=(o,t,e)=>{if(o.branches.length>0){for(;e>=t.length;)t.push([]);for(const n of o.branches)t[e].push(n),Ke(n,t,e+1)}};class ve{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new ve(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 ao{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=t.nodes.filter(a=>!a.parent);n.sort((a,i)=>i.type.priority-a.type.priority);let l=0;for(const a of n)a.move([0,l]),l+=a.height+e;return t}}const $e={adjacency:new eo,breadth:new te,"breadth-adjacency":new io,force:new oo,horizontal:new so,priority:new no,tree:new ro,vertical:new ao},lo=T.createContext({}),St=T.createContext({});class co{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 ye=({direction:o,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:n,disabled:l,rule:a,collapsedValue:i,visibleValue:s,onCollapse:r})=>{const[c,d]=T.useState(n),h=()=>{if(!l){const y=!c;d(y),r?.(y);let p;if(typeof t=="string")p=E.select(t),e&&(p=p.select(e));else{const v=t;if(!v)throw new Error("collapsableSelector is not a valid ref");p=E.select(v.current),e&&(p=p.select(e))}p.style(a,y?i:s)}},u=()=>{switch(o){case f.Right:return l?"daga-horizontal-none":c?"daga-horizontal-right":"daga-horizontal-left";case f.Bottom:return l?"daga-vertical-none":c?"daga-vertical-down":"daga-vertical-up";case f.Left:return l?"daga-horizontal-none":c?"daga-horizontal-left":"daga-horizontal-right";case f.Top:return l?"daga-vertical-none":c?"daga-vertical-up":"daga-vertical-down"}};return g.jsx("daga-collapse-button",{children:g.jsx("button",{className:`daga-collapse-button daga-${o}`,onClick:h,children:g.jsx("div",{className:u()})})})},ho=()=>{const o=T.useContext(St),t=T.useRef(null),[e,n]=T.useState([]);kt.merge(o.validatorChange$,o.diagramChange$).pipe(kt.map(()=>l())).subscribe();const l=()=>{n([]);for(const i of o.validators){const s=i.validate(o.model);n(s)}},a=i=>{if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const s=o.model.nodes.get(i.elementId)||o.model.connections.get(i.elementId);s&&o.userHighlight.add(s)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){o.userSelection.openInPropertyEditor(o.model.nodes.get(i.elementId)||o.model.connections.get(i.elementId));const s=o.model.nodes.get(i.elementId)||o.model.connections.get(i.elementId);s&&o.userHighlight.add(s),o.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(o.userSelection.openInPropertyEditor(),o.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames))};return g.jsx("daga-errors",{children:g.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&g.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:g.jsx("span",{children:"No errors found"})}),e.length>0&&g.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[g.jsxs("span",{children:[e.length," errors found"]}),g.jsx("div",{className:"daga-collapse-button-container",children:g.jsx(ye,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:f.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&g.jsx("div",{className:"daga-error-panel",children:g.jsx("ol",{children:e.map((i,s)=>g.jsx("li",{onClick:()=>a(i),dangerouslySetInnerHTML:{__html:i.message}},s))})})]})})},go=200,Ne=o=>(o||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),qe=({disabled:o,options:t,value:e,onChange:n})=>{const l=T.useRef(null),[a,i]=T.useState("");let s;const[r,c]=T.useState([]),[d,h]=T.useState([]),[u,y]=T.useState([]),[p,v]=T.useState([]),[m,k]=T.useState(!1);T.useEffect(()=>{i(t.find(A=>wt(A.key,e))?.label||"")},[e,t]);const b=A=>{if(!o)switch(A.key){case W.PageDown:s===void 0?(P(0),$(0)):(P(s+5),$(s)),A.preventDefault();break;case W.ArrowDown:s===void 0?(P(0),$(0)):(P(s+1),$(s)),A.preventDefault();break;case W.PageUp:s===void 0?(P(t.length-1),$(t.length-1)):(P(s-5),$(s)),A.preventDefault();break;case W.ArrowUp:s===void 0?(P(t.length-1),$(t.length-1)):(P(s-1),$(s)),A.preventDefault();break;case W.Escape:R(),A.preventDefault();break;case W.Enter:V(t[s||0]),A.preventDefault();break;default:M()}},M=()=>{if(!o){const A=Ne(a.trim());c([]),h([]),y([]),v([]);for(const j of t){const st=Ne(j.label).indexOf(A);if(st>=0){const jt=j.label.substring(0,st),K=j.label.substring(st,st+A.length),bt=j.label.substring(st+A.length);c(ot=>[...ot,j]),h(ot=>[...ot,jt]),y(ot=>[...ot,K]),v(ot=>[...ot,bt])}}k(!0)}},R=()=>{k(!1)},P=A=>{if(!o){if(s=A,A===void 0)return;A<0&&(s=0),A>=t.length&&(s=t.length-1)}},J=()=>{setTimeout(()=>{R()},go)},$=A=>{const j=l.current?.querySelectorAll("li")[A];j&&j.scrollIntoView({block:"center"})},x=()=>{o||(i(""),k(!1),s=void 0)},V=A=>{o||(i(A.label),k(!1),s=void 0,n(A.key))};return g.jsxs("div",{ref:l,className:`daga-autocomplete ${m?"daga-showing-options":""}`,children:[g.jsxs("div",{className:"daga-autocomplete-input",children:[g.jsx("input",{value:a,disabled:o,onKeyUp:b,onFocus:M,onBlur:J,onChange:A=>i(A.target.value)}),a!==""&&g.jsx("button",{className:"daga-clear",onClick:x})]}),g.jsx("div",{className:"daga-autocomplete-options",children:g.jsxs("ul",{className:"daga-autocomplete-option-list",children:[r.length===0&&g.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),r.map((A,j)=>g.jsxs("li",{className:`daga-autocomplete-option ${j===s?"daga-focused":""}`,onMouseMove:()=>P(j),onClick:()=>V(A),children:[g.jsx("span",{children:d[j]}),g.jsx("span",{className:"daga-match",children:u[j]}),g.jsx("span",{children:p[j]})]},j))]})})]})},uo=(o,t)=>o.find(e=>e.key===t)?.label||`${t}`,fo=({disabled:o,allowRepeats:t,options:e,value:n,onChange:l})=>{const[a,i]=T.useState(),[s,r]=T.useState([]),[c,d]=T.useState([]);T.useEffect(()=>{const m=n.length===0,k=n.map(b=>uo(e,b));r(k),m&&l(n),v()},[n,e]);const h=m=>{for(const k of n)if(k===m)return!0;return!1},u=m=>{n.length>m&&(n.splice(m,1),r(s.filter((k,b)=>b!==m)),l(n),v())},y=()=>{a!==void 0&&(t||!h(a))&&(l(n.concat(a)),p())},p=()=>{i("")},v=()=>{if(!t){const m=[];for(const k of e)h(k.key)||m.push(k);d(m)}};return g.jsxs("div",{children:[n.map((m,k)=>g.jsxs("div",{className:"daga-value-item-element",children:[g.jsx("span",{className:"daga-input",children:s[k]}),!o&&g.jsx("button",{className:"daga-property-button",onClick:()=>u(k),children:g.jsx("div",{className:"daga-icon daga-close-icon"})})]},k)),!o&&g.jsxs("div",{className:"daga-value-item-input",children:[g.jsx("div",{className:"daga-input daga-relatively-positioned",children:g.jsx(qe,{disabled:o,options:t?e||[]:c||[],value:a,onChange:i})}),g.jsx("button",{className:"daga-property-button",onClick:y,children:g.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},mo=({disabled:o,allowRepeats:t,value:e,onChange:n})=>{const[l,a]=T.useState(""),i=u=>{for(const y of u||[])if(y===u)return!0;return!1},s=u=>{e.length>u&&n(e.filter((y,p)=>p!==u))},r=(u,y,p)=>{const v=e.map((m,k)=>k===y?p==="blur"?u.trim():u:m);n(v)},c=()=>{const u=l.trim();u!==""&&(t||!i(u))&&(n(e.concat(u)),d())},d=()=>{a("")},h=u=>{u.key==="Enter"&&c()};return g.jsxs(g.Fragment,{children:[e.map((u,y)=>g.jsxs("div",{className:"daga-value-item-element",children:[g.jsx("input",{className:"daga-input",disabled:o,value:u,onChange:p=>r(p.target.value,y,"change"),onBlur:p=>r(p.target.value,y,"blur")}),g.jsx("button",{className:"daga-property-button",onClick:()=>s(y),children:g.jsx("div",{className:"daga-icon daga-close-icon"})})]},y)),!o&&g.jsxs("div",{className:"daga-value-item-input",children:[g.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[g.jsx("input",{type:"text",onKeyUp:h,value:l,onChange:u=>a(u.target.value)}),g.jsx("button",{className:"daga-clear",onClick:d})]}),g.jsx("button",{className:"daga-property-button",onClick:c,children:g.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},po=({disabled:o,value:t,onChange:e})=>{const[n,l]=T.useState(""),[a,i]=T.useState(""),[s,r]=T.useState({}),c=m=>{const k={};Object.keys(t).forEach(b=>{b!==m&&(k[b]=t[b])}),e(k)},d=(m,k,b)=>{const M=b==="blur"?k.trim():k;if(b==="blur"){if(m!==M){const R={};Object.keys(t).forEach(P=>{P===m?R[M]=t[P]:R[P]=t[P]}),e(R),r(P=>{const J={...P};return delete J[m],J})}}else r(R=>({...R,[m]:k}))},h=(m,k,b)=>{const M=b==="blur"?k.trim():k;if(M!==""){const R={};Object.keys(t).forEach(P=>{P===m?R[P]=M:R[P]=t[P]}),e(R)}},u=()=>{const m=n.trim(),k=a.trim();if(m!==""&&k!==""){const b={};Object.keys(t).forEach(M=>{b[M]=t[M]}),b[m]=k,e(b),l(""),i("")}},y=()=>{l("")},p=()=>{i("")},v=m=>{m.key==="Enter"&&u()};return g.jsxs("div",{children:[Object.entries(t).map(([m,k],b)=>g.jsxs("div",{className:"daga-value-item-element",children:[g.jsx("input",{id:`key-${b}`,className:"daga-input",type:"text",disabled:o,value:s[m]??m,onChange:M=>d(m,M.target.value,"change"),onBlur:M=>d(m,M.target.value,"blur")}),g.jsx("input",{id:`value-${b}`,className:"daga-input",type:"text",disabled:o,value:k,onChange:M=>h(m,M.target.value,"change"),onBlur:M=>h(m,M.target.value,"blur")}),g.jsx("button",{className:"daga-property-button",onClick:()=>c(m),children:g.jsx("div",{className:"daga-icon daga-close-icon"})})]},m)),!o&&g.jsxs("div",{className:"daga-value-item-input",children:[g.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[g.jsx("input",{type:"text",value:n,onKeyUp:v,onChange:m=>l(m.target.value),onBlur:m=>d(n,m.target.value,"blur")}),g.jsx("button",{className:"daga-clear",onClick:y})]}),g.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[g.jsx("input",{type:"text",value:a,onKeyUp:v,onChange:m=>i(m.target.value),onBlur:m=>h(n,m.target.value,"blur")}),g.jsx("button",{className:"daga-clear",onClick:p})]}),g.jsx("button",{className:"daga-property-button",onClick:u,children:g.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Je=({valueSet:o,onValueChange:t,depth:e})=>{const l=T.useContext(St).canUserPerformAction(w.UpdateValues)&&o?.rootElement?.removed!==!0,a=r=>"daga-property-name-"+r.replace(/\s/g,""),i=r=>{if(typeof r=="string")return r;if(r==null||isNaN(r.valueOf()))return"";const c=new Date(r),d=c.getTimezoneOffset();return c.setMinutes(c.getMinutes()-d),c.toISOString().substring(0,19)},s=r=>new Date(r);return g.jsx("daga-object-editor",{children:o.displayedProperties.map(r=>g.jsxs("div",{className:`daga-property ${a(r.name)}`,children:[g.jsx("p",{className:"daga-property-name",children:r.label||r.name}),r.type===N.Text&&g.jsx("input",{type:"daga-text",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.TextArea&&g.jsx("textarea",{disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Number&&g.jsx("input",{type:"number",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Color&&g.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Datetime&&g.jsx("input",{type:"datetime-local",disabled:r.editable===!1||!l,value:i(o?.getValue(r.name)),onChange:c=>t(o,r,s(c.target.value))}),r.type===N.Date&&g.jsx("input",{type:"date",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Time&&g.jsx("input",{type:"time",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Url&&g.jsx("input",{type:"url",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Boolean&&g.jsxs("div",{className:"daga-radio",children:[g.jsxs("label",{className:"daga-radio-item daga-radio-start"+(o?.getValue(r.name)===!1?" daga-checked":""),children:[g.jsx("input",{type:"radio",disabled:r.editable===!1||!l,name:r.name,value:"false",checked:o?.getValue(r.name)===!1,onChange:()=>t(o,r,!1)}),"No"]}),g.jsxs("label",{className:"daga-radio-item daga-radio-end"+(o?.getValue(r.name)===!0?" daga-checked":""),children:[g.jsx("input",{type:"radio",disabled:r.editable===!1||!l,name:r.name,value:"true",checked:o?.getValue(r.name)===!0,onChange:()=>t(o,r,!0)}),"Yes"]})]}),r.type===N.Option&&g.jsx("div",{className:"daga-relatively-positioned",children:g.jsx(qe,{disabled:r.editable===!1||!l,options:r.options||[],value:o?.getValue(r.name),onChange:c=>t(o,r,c)})}),(r.type===N.OptionList||r.type===N.OptionSet)&&g.jsx(fo,{disabled:r.editable===!1||!l,allowRepeats:r.type===N.OptionList,options:r.options||[],value:o?.getValue(r.name),onChange:c=>t(o,r,c)}),(r.type===N.TextList||r.type===N.TextSet)&&g.jsx(mo,{disabled:r.editable===!1||!l,allowRepeats:r.type===N.TextList,value:o?.getValue(r.name),onChange:c=>t(o,r,c)}),r.type===N.TextMap&&g.jsx(po,{disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c)}),r.type===N.Object&&g.jsx("div",{className:"daga-left-bar",children:g.jsx(Je,{valueSet:o.getSubValueSet(r.name),onValueChange:t,depth:e+1})})]},r.name))})},Qe=({valueSet:o,depth:t})=>{const e=T.useContext(St),n=T.useRef(null),l=r=>"daga-property-name-"+r.replace(/\s/g,""),a=()=>{for(const r of o?.displayedProperties||[]){let c=0,d=0,h=0;const u=E.select(n.current).select(`.daga-property.${l(r.name)}.daga-depth-${t}`);u.select("button.daga-move-button").call(E.drag().on(I.Start,y=>{S(L.Grabbing);const p=e.getPointerLocationRelativeToScreen(y);if(p.length<2||isNaN(p[0])||isNaN(p[1]))return;const v=u.node()?.getBoundingClientRect();c=v?.width||0,d=v?.height||0,u.style("position","fixed").style("left",`${p[0]-c/2}px`).style("top",`${p[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1)}).on(I.Drag,y=>{S(L.Grabbing);const p=e.getPointerLocationRelativeToScreen(y);p.length<2||isNaN(p[0])||isNaN(p[1])||(u.style("position","fixed").style("left",`${p[0]-c/2}px`).style("top",`${p[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1),E.select(n.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0),h=i(p),E.select(n.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on(I.End,y=>{S(L.Auto),u.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),E.select(n.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const p=e.getPointerLocationRelativeToScreen(y);p.length<2||isNaN(p[0])||isNaN(p[1])||(h=i(p),o?.displayedProperties?.splice(o.displayedProperties.indexOf(r),1),o?.displayedProperties?.splice(h,0,r))}))}},i=r=>{const c=o?.propertySet.propertyList||[],d=[];for(let h=0;h<=c.length;++h){const u=E.select(n.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).node()?.getBoundingClientRect();u&&d.push([u.x+u.width/2,u.y+u.height/2])}if(d.length>0){const h=d.map(y=>((r[0]-y[0])**2+(r[1]-y[1])**2)**.5);return h.indexOf(Math.min(...h))}return 0},s=r=>{if(o===void 0)return;let c;r instanceof yi?c=r:r instanceof Event?c=o?.propertySet.getProperty(r.target?.value||""):c=o?.propertySet.getProperty(r||""),c&&o?.hideProperty(c),a()};return g.jsxs("daga-property-settings",{ref:n,children:[g.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),o?.displayedProperties.map((r,c)=>g.jsxs("div",{className:`daga-property-and-dropbar ${l(r.name)} daga-depth-${t}`,children:[g.jsxs("div",{className:`daga-property ${l(r.name)} daga-depth-${t}`,children:[g.jsxs("div",{className:"daga-property-name",children:[g.jsx("span",{children:r.label||r.name}),g.jsxs("div",{className:"daga-buttons",children:[g.jsx("button",{className:"daga-property-button daga-move-button",children:g.jsx("div",{className:"daga-icon daga-move-icon"})}),g.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>s(r.name),children:g.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),r.type!==N.Object&&g.jsx("div",{className:"daga-property-value",children:vo(o?.getValue(r.name))}),r.type===N.Object&&g.jsx(Qe,{valueSet:o?.getSubValueSet(r.name),depth:t+1})]}),g.jsx("div",{className:`daga-dropbar daga-index-${c+1} daga-depth-${t}`})]},r.name))]})},vo=o=>Array.isArray(o)?o.join(", "):bi(o)?Object.entries(o).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):o instanceof Date?o.toLocaleString():o==null?"":""+o,yo=({location:o,direction:t,width:e,height:n,title:l,valueSet:a,onValueChange:i})=>{const s=T.useRef(null),[r,c]=T.useState(!1),[d,h]=T.useState(!1),u=()=>E.select(s.current);return T.useEffect(()=>{if(s.current)switch(t){case f.Bottom:case f.Top:u().style("width",e),n&&u().select(".daga-panel-content").style("height",n);break;case f.Left:case f.Right:u().style("height",e),n&&u().select(".daga-panel-content").style("width",n);break}},[e,t]),g.jsx("daga-property-editor",{children:g.jsxs("div",{ref:s,className:`daga-panel daga-bottom daga-${o} daga-${t}`,children:[g.jsx(ye,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:r,direction:t,collapsableSelector:s,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:c}),g.jsx("div",{className:"daga-panel-content",children:a&&a.propertySet&&a.propertySet.hasProperties()&&!r&&g.jsxs("div",{children:[l&&g.jsxs("p",{className:"daga-title",children:[l,g.jsx("button",{className:"daga-property-button",onClick:()=>h(!d),children:g.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&g.jsx(Je,{valueSet:a,onValueChange:i,depth:0}),d&&g.jsx(Qe,{valueSet:a,depth:0})]})})]})})},bo=6,ko=o=>{const t=T.useContext(St),[e,n]=T.useState(o.currentPalette||o.palettes[0]),[l,a]=T.useState(0),[i,s]=T.useState(void 0),r=T.useRef(null),c=v=>{if(n(v),d().selectAll("*").remove(),a(t.getPriorityThreshold()||0),v.categories&&h(v.categories),v.templates)for(const m of v.templates)u(m)},d=()=>E.select(r.current).select(".daga-palette-view"),h=v=>{const m=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");m.append("option").attr("value","").text("(None selected)");for(const k in v)m.append("option").attr("value",k).text(k);m.on(C.Change,()=>{i&&d().selectAll(".daga-template-container.daga-in-category").remove();const k=m.property("value");s(k);const b=v[k]||[];for(const M of b)u(M,"daga-in-category")}),i&&(m.property("value",i),m.dispatch(C.Change))},u=(v,m)=>{if(v.templateType==="node"){const k=t.model.nodes.types.get(v.type);k?y(k,v,m):console.error(`Could not find a node type called '${v.type}'`)}else if(v.templateType==="connection"){const k=t.model.connections.types.get(v.type);k?p(k,v,m):console.error(`Could not find a connection type called '${v.type}'`)}},y=(v,m,k)=>{if(l!==void 0&&v.priority<l)return;const b=v.defaultLook.lookType==="shaped-look"?v.defaultLook.borderThickness||1:0,M=v.defaultHeight+b,R=v.defaultWidth+b,P=m.height||M,J=m.width||R,$=d().append("div").attr("class",`daga-template-container ${k!==void 0?k:""}`).style("width",`${J}px`).style("height",`${P}px`).call(E.drag().on(I.Drag,V=>{if(t.canUserPerformAction(w.AddNode)){const A=t.getPointerLocationRelativeToScreen(V);if(A.length<2||isNaN(A[0])||isNaN(A[1]))return;$.style("position","fixed").style("left",`${A[0]-J/2}px`).style("top",`${A[1]-P/2}px`).style("z-index",1)}}).on(I.Start,V=>{if(t.canUserPerformAction(w.AddNode)){S(L.Grabbing);const A=t.getPointerLocationRelativeToScreen(V);if(A.length<2||isNaN(A[0])||isNaN(A[1]))return;$.style("position","fixed").style("left",`${A[0]-J/2}px`).style("top",`${A[1]-P/2}px`).style("z-index",1),v.isUnique&&t.model.nodes.find(j=>!j.removed&&j.type.id===v.id)!==void 0&&S(L.NotAllowed)}}).on(I.End,V=>{if(t.canUserPerformAction(w.AddNode)){if(S(L.Auto),$.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),v.isUnique&&t.model.nodes.find(Ft=>!Ft.removed&&Ft.type.id===v.id)!==void 0)return;const A=t.getPointerLocationRelativeToScreen(V);if(A.length<2||isNaN(A[0])||isNaN(A[1]))return;const j=document.elementFromPoint(A[0],A[1]);if(j&&!t.selectCanvasView().node()?.contains(j))return;const rt=t.getPointerLocationRelativeToCanvas(V);if(rt.length<2||isNaN(rt[0])||isNaN(rt[1]))return;let st=[rt[0]-v.defaultWidth/2,rt[1]-v.defaultHeight/2];t.snapToGrid&&(st=t.getClosestGridPoint(st));const K=t.model.nodes.getAtCoordinates(rt[0],rt[1]).filter(Ft=>Ft.type.childrenTypes.includes(v.id)),bt=je(K),ot=bt[bt.length-1];if(!v.canBeParentless&&ot===void 0)return;const Dt=ot?.getLastAncestor(),be=new Oi(t,v,st,ot?.id,Dt?.id,Dt?.getGeometry(),void 0,m.label,m.values);be.do(),t?.actionStack.add(be),S()}})).append("svg").attr("class",`palette-node ${v.id}`).attr("viewBox",`0 0 ${R} ${M}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${J}px`).style("height",`${P}px`),x=m.look||v.defaultLook;switch(x.lookType){case"shaped-look":$.append("path").attr("d",he(x.shape||Tt.Rectangle,(x.borderThickness||1)/2,(x.borderThickness||1)/2,v.defaultWidth,v.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",v.defaultWidth).attr("height",v.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",v.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTop).attr("preserveAspectRatio","none"),$.append("image").attr("x",v.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",v.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",x.topMargin).attr("width",v.defaultWidth-x.rightMargin-x.leftMargin).attr("height",v.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageCenter).attr("preserveAspectRatio","none"),$.append("image").attr("x",v.defaultWidth-x.rightMargin).attr("y",x.topMargin).attr("width",x.rightMargin).attr("height",v.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageRight).attr("preserveAspectRatio","none"),$.append("image").attr("x",0).attr("y",v.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",v.defaultHeight-x.bottomMargin).attr("width",v.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottom).attr("preserveAspectRatio","none"),$.append("image").attr("x",v.defaultWidth-x.rightMargin).attr("y",v.defaultHeight-x.bottomMargin).attr("width",x.rightMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(m.look===void 0){if(v.decorators)for(const V of v.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(m.label){const V={...O,...v.label,...m.labelLook};$.append("text").attr("transform",`translate(${(B(V)+v.defaultWidth)/2},${(F(V)+v.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(m.label)}}},p=(v,m,k)=>{const b=d().append("div").attr("class",`daga-template-container ${k!==void 0?k:""}`).style("width",`${m.width}px`).style("height",`${m.height}px`).append("svg").attr("class",`palette-button ${v.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=v});b.append("path").attr("d",he(Tt.Rectangle,0,0,m.width,m.height)).attr("fill",m.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),m.icon!==""&&b.append("image").attr("x",0).attr("y",0).attr("width",m.width).attr("height",m.height).attr("href",m.icon),m.label!==""&&b.append("text").attr("transform",`translate(${m.width/2},${m.height/2+bo})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(m.label)};return T.useEffect(()=>{if(c(o.palettes[0]),r.current)switch(o.direction){case f.Bottom:case f.Top:r.current.style.width=o.width,o.height&&(r.current.style.height=o.height);break;case f.Left:case f.Right:r.current.style.height=o.width,o.height&&(r.current.style.width=o.height);break}},[e,o.palettes]),g.jsx("daga-palette",{children:g.jsxs("div",{ref:r,className:`daga-panel daga-${o.location} daga-${o.direction}`,children:[g.jsx(ye,{direction:o.direction,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),g.jsxs("div",{className:"daga-panel-content",children:[o.palettes.length>1&&g.jsx("div",{className:"daga-panel-tabs",children:o.palettes.map(v=>g.jsx("div",{className:`daga-panel-tab ${v===e?"daga-current-tab":""}`,onClick:()=>c(v),children:v.name}))}),g.jsx("div",{className:"daga-palette-view"})]})]})})},wo=({location:o,direction:t,enableAction:e,enableFilter:n,enableLayout:l,enableSelection:a,enableZoom:i})=>{let s=!1,r=!0,c=!1,d,h,u,y;switch(t){case f.Bottom:d="height",h="scaleY",u="top",y="bottom";break;case f.Top:d="height",h="scaleY",u="bottom",y="top";break;case f.Left:d="width",h="scaleX",u="right",y="left";break;case f.Right:d="width",h="scaleX",u="left",y="right";break}const p=T.useRef(null),v=T.useRef(null),m=T.useRef(null);T.useEffect(()=>{E.select(p.current).style(`margin-${y}`,"-1rem").style(d,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const k=async()=>{const K=E.select(p.current);if(!c)if(r){r=!1;const Dt=`${4*K.selectChildren().size()}rem`;K.transition().duration(500).ease(E.easeLinear).style(d,Dt).style("transform",`${h}(1)`),setTimeout(()=>{c=!1},500)}else r=!0,K.transition().duration(500).ease(E.easeLinear).style(d,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{c=!1},500)},b=T.useContext(St),M=()=>{b.zoomBy(b.zoomFactor)},R=()=>{b.zoomBy(1/b.zoomFactor)},P=()=>{b.center()},J=()=>{b.layoutFormat&&b.layoutFormat in $e&&$e[b.layoutFormat].apply(b.model)},$=()=>{s=!s,E.select(m.current).classed("daga-on",s).classed("daga-off",!s);const K=b.getPriorityThresholdOptions();K&&K.length>=2&&b.setPriorityThreshold(K[s?1:0])},x=()=>{b.actionStack.undo()},V=()=>{b.actionStack.redo()},A=()=>{b.userSelection.copyToClipboard()},j=()=>{b.userSelection.cutToClipboard()},rt=()=>{b.userSelection.pasteFromClipboard()},st=()=>{b.userSelection.removeFromModel()},jt=()=>{b.multipleSelectionOn=!0,E.select(v.current).classed("daga-on",!0).classed("daga-off",!1);const K=b.diagramEvent$.subscribe(bt=>{bt.type===Be.Selection&&(E.select(v.current).classed("daga-on",!1).classed("daga-off",!0),K.unsubscribe())})};return g.jsx("daga-diagram-buttons",{children:g.jsxs("div",{className:`daga-diagram-buttons daga-${o} daga-${t}`,children:[i&&b.canUserPerformAction(w.Zoom)&&g.jsx("button",{className:"daga-zoom-in",onClick:M,children:g.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&b.canUserPerformAction(w.Zoom)&&g.jsx("button",{className:"daga-zoom-out",onClick:R,children:g.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),g.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:p,children:[i&&b.canUserPerformAction(w.Zoom)&&g.jsx("button",{className:"daga-center",onClick:P,children:g.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&g.jsx("button",{className:"daga-undo",onClick:x,children:g.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&g.jsx("button",{className:"daga-redo",onClick:V,children:g.jsx("span",{className:"daga-tooltip",children:"Redo"})}),a&&g.jsx("button",{className:"daga-copy",onClick:A,children:g.jsx("span",{className:"daga-tooltip",children:"Copy"})}),a&&g.jsx("button",{className:"daga-cut",onClick:j,children:g.jsx("span",{className:"daga-tooltip",children:"Cut"})}),a&&g.jsx("button",{className:`daga-multiple-selection ${s?"daga-on":"daga-off"}`,onClick:jt,ref:v,children:g.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),a&&g.jsx("button",{className:"daga-paste",onClick:rt,children:g.jsx("span",{className:"daga-tooltip",children:"Paste"})}),a&&g.jsx("button",{className:"daga-delete",onClick:st,children:g.jsx("span",{className:"daga-tooltip",children:"Delete"})}),l&&b.layoutFormat&&g.jsx("button",{className:"daga-layout",onClick:J,children:g.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),n&&g.jsx("button",{className:`daga-filter ${s?"daga-on":"daga-off"}`,onClick:$,ref:m,children:g.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),g.jsx("button",{className:"daga-more-options",onClick:k,children:r?g.jsx("span",{className:"daga-tooltip",children:"More options"}):g.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},So=({config:o,model:t,onCanvasCreated:e,onDiagramEvent:n,onModelChange:l})=>{const a=new He,i=new Ye,s=T.useRef(null),r=T.useRef(void 0),c=T.useRef(!1),d=[],[h,u]=T.useState(void 0),[y,p]=T.useState(void 0),v={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},m={refreshPalette:()=>{}},k=new co($=>u($),$=>p($)),b={diagramButtons:v,palette:m,propertyEditor:k},M=($=!1)=>((!r.current||$)&&(d.forEach(x=>x.unsubscribe()),r.current=new ue(b,o)),r.current),R=M(),P=$=>{R.initView($),d.push(R.diagramEvent$.subscribe(x=>{n?.(x)})),d.push(R.diagramChange$.subscribe(()=>{const x=i.export(R.model);l?.(x)}))};T.useEffect(()=>{s.current&&(c.current||(P(s.current),c.current=!0,e?.(R)))},[s.current]),T.useMemo(()=>{s.current&&(M(!0),P(s.current),e?.(R))},[o]),T.useEffect(()=>{t&&a.import(R.model,t)},[t]);const J=($,x,V)=>{if(y!==void 0&&x.editable!==!1&&!wt($.getValue(x.name),V)){$.setValue(x.name,V);const A=new pt(y.propertySet,void 0);A.setValues(y.getValues()),A.rootElement=y.rootElement,k.valueSet=A,y.rootElement.valueSet=A,R.propertyEditorChanges$?.next()}};return g.jsx("daga-diagram",{children:g.jsx(lo.Provider,{value:o,children:g.jsx(St.Provider,{value:R,children:g.jsxs("daga-diagram-editor",{children:[g.jsx("div",{className:"daga-append-to",ref:s}),g.jsxs(St.Provider,{value:R,children:[o.components?.buttons!==void 0&&o.components?.buttons?.enabled!==!1&&g.jsx(wo,{location:o.components?.buttons?.location||Bt.BottomRight,direction:o.components?.buttons?.direction||f.Top,enableAction:o.components?.buttons?.enableAction!==!1,enableFilter:o.components?.buttons?.enableFilter===!0,enableLayout:o.components?.buttons?.enableLayout===!0,enableSelection:o.components?.buttons?.enableSelection!==!1,enableZoom:o.components?.buttons?.enableZoom!==!1}),o.components?.palette!==void 0&&o.components?.palette?.enabled!==!1&&o.components?.palette?.sections&&(o.components?.palette?.sections?.length||0)>0&&g.jsx(ko,{location:o.components?.palette?.location||Bt.TopLeft,direction:o.components?.palette?.direction||f.Bottom,width:o.components?.palette?.width||"12rem",height:o.components?.palette?.height,palettes:o.components?.palette?.sections||[]}),o.components?.propertyEditor!==void 0&&o.components?.propertyEditor?.enabled!==!1&&g.jsx(yo,{location:o.components?.propertyEditor?.location||Bt.TopRight,direction:o.components?.propertyEditor?.direction||f.Bottom,width:o.components?.propertyEditor?.width||"24rem",height:o.components?.propertyEditor?.height,title:h,valueSet:y,onValueChange:J}),o.components?.errors!==void 0&&o.components?.errors?.enabled!==!1&&g.jsx(ho,{})]})]})})})})};exports.DagaDiagram=So;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),to=require("d3"),kt=require("rxjs"),E=require("react");function eo(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,a.get?a:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const A=eo(to);var g=(s=>(s.Bottom="bottom",s.Left="left",s.Right="right",s.Top="top",s))(g||{}),Ut=(s=>(s.BottomLeft="bottom-left",s.BottomRight="bottom-right",s.TopLeft="top-left",s.TopRight="top-right",s))(Ut||{}),It=(s=>(s.Left="left",s.Center="center",s.Right="right",s))(It||{}),Bt=(s=>(s.Top="top",s.Center="center",s.Bottom="bottom",s))(Bt||{});const Ct=s=>[Math.round(s[0]),Math.round(s[1])],gt=(s,t,e)=>t<e?t<=s&&s<=e:e<=s&&s<=t,ke=(s,t,e)=>(s-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Yt=(s,t,e,a,l,n,i)=>{const r=(()=>{switch(n){case"start":return a[0]+(s[0]-t[0]);case"end":return a[1]-(t[1]-s[0]);case"middle":{const c=(t[0]+t[1])/2,d=(a[0]+a[1])/2,h=t[1]-t[0],u=a[1]-a[0],y=(s[0]-c)/h;return d+y*u}case"floating":default:return ke(s[0],t,a)}})(),o=(()=>{switch(i){case"start":return l[0]+(s[1]-e[0]);case"end":return l[1]-(e[1]-s[1]);case"middle":{const c=(e[0]+e[1])/2,d=(l[0]+l[1])/2,h=e[1]-e[0],u=l[1]-l[0],y=(s[1]-c)/h;return d+y*u}case"floating":default:return ke(s[1],e,l)}})();return[r,o]},Ne=(s,t)=>((s[0]-t[0])**2+(s[1]-t[1])**2)**.5,oo=(s,t)=>(gt(s[0][0],t[0][0],t[1][0])||gt(s[1][0],t[1][0],t[0][0])||gt(t[0][0],s[0][0],s[1][0])||gt(t[1][0],s[1][0],s[0][0]))&&(gt(s[0][1],t[0][1],t[1][1])||gt(s[1][1],t[1][1],t[0][1])||gt(t[0][1],s[0][1],s[1][1])||gt(t[1][1],s[1][1],s[0][1]));var C=(s=>(s.Blur="blur",s.Change="change",s.Click="click",s.ContextMenu="contextmenu",s.DoubleClick="dblclick",s.Focus="focus",s.FocusIn="focusin",s.FocusOut="focusout",s.Input="input",s.KeyDown="keydown",s.KeyUp="keyup",s.MouseDown="mousedown",s.MouseEnter="mouseenter",s.MouseLeave="mouseleave",s.MouseMove="mousemove",s.MouseOut="mouseout",s.MouseOver="mouseover",s.MouseUp="mouseup",s.TouchStart="touchstart",s.TouchEnd="touchend",s.Wheel="wheel",s))(C||{}),W=(s=>(s.Alt="Alt",s.AltGraph="AltGraph",s.ArrowDown="ArrowDown",s.ArrowLeft="ArrowLeft",s.ArrowRight="ArrowRight",s.ArrowUp="ArrowUp",s.Backspace="Backspace",s.Control="Control",s.Delete="Delete",s.End="End",s.Enter="Enter",s.Escape="Escape",s.Home="Home",s.OS="OS",s.PageDown="PageDown",s.PageUp="PageUp",s.Shift="Shift",s.Tab="Tab",s))(W||{}),$=(s=>(s.Drag="drag",s.Start="start",s.End="end",s))($||{}),le=(s=>(s.Zoom="zoom",s.Start="start",s.End="end",s))(le||{});const ce=s=>s.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var Pe=(s=>(s.Straight="straight",s.Bezier="bezier",s.Square="square",s))(Pe||{}),ue=(s=>(s.Solid="solid",s.Dashed="dashed",s.GappedDashes="gapped-dashes",s.Dotted="dotted",s))(ue||{});const io=20,so=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{l=l||io;let n="",i,r;switch(s){case"straight":n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o)n+=` L ${t[o][0]} ${t[o][1]}`;break;case"bezier":i=e,n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case g.Bottom:r=g.Top;break;case g.Top:r=g.Bottom;break;case g.Right:r=g.Left;break;case g.Left:r=g.Right;break}else Math.abs(t[o][0]-t[o-1][0])<Math.abs(t[o][1]-t[o-1][1])?t[o][1]>t[o-1][1]?r=g.Bottom:r=g.Top:t[o][0]>t[o-1][0]?r=g.Right:r=g.Left;if(i!==void 0){let c="",d="";const h=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(i){case g.Bottom:c=`${t[o-1][0]} ${t[o-1][1]+h}`;break;case g.Top:c=`${t[o-1][0]} ${t[o-1][1]-h}`;break;case g.Right:c=`${t[o-1][0]+h} ${t[o-1][1]}`;break;case g.Left:c=`${t[o-1][0]-h} ${t[o-1][1]}`;break}if(r!==void 0){switch(r){case g.Top:d=`${t[o][0]} ${t[o][1]+h}`;break;case g.Bottom:d=`${t[o][0]} ${t[o][1]-h}`;break;case g.Left:d=`${t[o][0]+h} ${t[o][1]}`;break;case g.Right:d=`${t[o][0]-h} ${t[o][1]}`;break}n+=` C ${c} ${d} ${t[o][0]} ${t[o][1]}`}else n+=` Q ${c} ${t[o][0]} ${t[o][1]}`}else if(r!==void 0){let c="";const d=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(r){case g.Top:c=`${t[o][0]} ${t[o][1]+d}`;break;case g.Bottom:c=`${t[o][0]} ${t[o][1]-d}`;break;case g.Left:c=`${t[o][0]+d} ${t[o][1]}`;break;case g.Right:c=`${t[o][0]-d} ${t[o][1]}`;break}n+=` Q ${c} ${t[o][0]} ${t[o][1]}`}else n+=` L ${t[o][0]} ${t[o][1]}`;i=r}break;case"square":i=e,n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case g.Bottom:r=g.Top;break;case g.Top:r=g.Bottom;break;case g.Right:r=g.Left;break;case g.Left:r=g.Right;break}switch(i){case g.Bottom:switch(r){case g.Bottom:t[o][1]>t[o-1][1]?(t[o][0]!==t[o-1][0]?(n+=` V ${(t[o][1]+t[o-1][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):n+=` V ${t[o][1]}`,i=r):t[o][0]>t[o-1][0]?(n+=` V ${t[o-1][1]+l}`,n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Top:n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`;break;case g.Left:t[o][1]>t[o-1][1]+l?t[o][0]<t[o-1][0]-l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(n+=` V ${t[o-1][1]+l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Right:t[o][1]>t[o-1][1]+l?t[o][0]>t[o-1][0]+l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(n+=` V ${t[o-1][1]+l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;default:t[o][1]<t[o-1][1]+l?(n+=` V ${t[o-1][1]+l}`,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`),n+=` V ${t[o][1]}`,i=g.Top):(n+=` V ${t[o][1]}`,i=g.Bottom,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left));break}break;case g.Top:switch(r){case g.Top:t[o][1]<t[o-1][1]?(t[o][0]!==t[o-1][0]?(n+=` V ${(t[o][1]+t[o-1][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):n+=` V ${t[o][1]}`,i=r):t[o][0]<t[o-1][0]?(n+=` V ${t[o-1][1]-l}`,n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Bottom:n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`;break;case g.Right:t[o][1]<t[o-1][1]-l?t[o][0]>t[o-1][0]+l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(n+=` V ${t[o-1][1]-l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Left:t[o][1]<t[o-1][1]-l?t[o][0]<t[o-1][0]-l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(n+=` V ${t[o-1][1]-l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;default:t[o][1]>t[o-1][1]-l?(n+=` V ${t[o-1][1]-l}`,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`),n+=` V ${t[o][1]}`,i=g.Bottom):(n+=` V ${t[o][1]}`,i=g.Top,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left));break}break;case g.Left:switch(r){case g.Left:t[o][0]<t[o-1][0]?(t[o][1]!==t[o-1][1]?(n+=` H ${(t[o][0]+t[o-1][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):n+=` H ${t[o][0]}`,i=r):t[o][1]<t[o-1][1]?(n+=` H ${t[o-1][0]-l}`,n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Right:n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`;break;case g.Bottom:t[o][0]<t[o-1][0]-l?t[o][1]>t[o-1][1]+l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(n+=` H ${t[o-1][0]-l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Top:t[o][0]<t[o-1][0]-l?t[o][1]<t[o-1][1]-l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(n+=` H ${t[o-1][0]-l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;default:t[o][0]>t[o-1][0]-l?(n+=` H ${t[o-1][0]-l}`,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`),n+=` H ${t[o][0]}`,i=g.Right):(n+=` H ${t[o][0]}`,i=g.Left,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top));break}break;case g.Right:switch(r){case g.Right:t[o][0]>t[o-1][0]?(t[o][1]!==t[o-1][1]?(n+=` H ${(t[o][0]+t[o-1][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):n+=` H ${t[o][0]}`,i=r):t[o][1]>t[o-1][1]?(n+=` H ${t[o-1][0]+l}`,n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Left:n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`;break;case g.Top:t[o][0]>t[o-1][0]+l?t[o][1]<t[o-1][1]-l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(n+=` H ${t[o-1][0]+l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Bottom:t[o][0]>t[o-1][0]+l?t[o][1]>t[o-1][1]+l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(n+=` H ${t[o-1][0]+l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;default:t[o][0]<t[o-1][0]+l?(n+=` H ${t[o-1][0]+l}`,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`),n+=` H ${t[o][0]}`,i=g.Left):(n+=` H ${t[o][0]}`,i=g.Right,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top));break}break;default:t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left),t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top)}}break}return n}},de=(s,t)=>{switch(s){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},D=(s,t)=>{const e=s.indexOf(t);return e>=0&&s.splice(e,1),s};var Et=(s=>(s.Ellipse="ellipse",s.Empty="empty",s.Folder="folder",s.Hexagon="hexagon",s.Octagon="octagon",s.Pill="pill",s.Rectangle="rectangle",s.Rhombus="rhombus",s.RoundedRectangle="rounded-rectangle",s.StickyNote="sticky-note",s))(Et||{});const he=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);switch(s){case"ellipse":return Re(t,e,a,l);case"empty":return no();case"folder":return ro(t,e,a,l);case"hexagon":return ao(t,e,a,l);case"octagon":return lo(t,e,a,l);case"pill":return Dt(t,e,a,l);case"rectangle":return we(t,e,a,l);case"rhombus":return co(t,e,a,l);case"rounded-rectangle":return ho(t,e,a,l);case"sticky-note":return go(t,e,a,l);default:return we(t,e,a,l)}},Re=(s,t,e,a)=>`M ${s+e/2} ${t} A ${e/2} ${a/2} 0 0 0 ${s+e/2} ${t+a} A ${e/2} ${a/2} 0 1 0 ${s+e/2} ${t} Z`,no=()=>"Z",ro=(s,t,e,a)=>`M ${s} ${t} L ${s+e/3} ${t} L ${s+e/2} ${t+a/6} L ${s+e} ${t+a/6} L ${s+e} ${t+a} L ${s} ${t+a} Z`,ao=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+a/2} L ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} L ${s} ${t+a/2} Z`,lo=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+a/4} L ${s+e} ${t+3*a/4} L ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} L ${s} ${t+3*a/4} L ${s} ${t+a/4} L ${s+e/4} ${t} Z`,Dt=(s,t,e,a)=>a<e?`M ${s+a/2} ${t} L ${s+e-a/2} ${t} A ${a/2} ${a/2} 0 0 1 ${s+e} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+e-a/2} ${t+a} L ${s+a/2} ${t+a} A ${a/2} ${a/2} 0 0 1 ${s} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+a/2} ${t} Z`:a>e?`M ${s} ${t+e/2} L ${s} ${t+a-e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t+a} A ${e/2} ${e/2} 0 0 0 ${s+e} ${t+a-e/2} L ${s+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${s} ${t+e/2} Z`:Re(s,t,e,a),we=(s,t,e,a)=>`M ${s} ${t} L ${s+e} ${t} L ${s+e} ${t+a} L ${s} ${t+a} Z`,co=(s,t,e,a)=>`M ${s+e/2} ${t} L ${s+e} ${t+a/2} L ${s+e/2} ${t+a} L ${s} ${t+a/2} Z`,ho=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} A ${e/4} ${a/4} 0 0 1 ${s+e} ${t+a/4} L ${s+e} ${t+3*a/4} A ${e/4} ${a/4} 0 0 1 ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} A ${e/4} ${a/4} 0 0 1 ${s} ${t+3*a/4} L ${s} ${t+a/4} A ${e/4} ${a/4} 0 0 1 ${s+e/4} ${t} Z`,go=(s,t,e,a)=>`M ${s} ${t} L ${s+3*e/4} ${t} L ${s+3*e/4} ${t+a/4} L ${s+3*e/4} ${t} L ${s+e} ${t+a/4} L ${s+3*e/4} ${t+a/4} L ${s+e} ${t+a/4} L ${s+e} ${t+a} L ${s} ${t+a} Z`;var L=(s=>(s.AllScroll="all-scroll",s.Auto="auto",s.Crosshair="crosshair",s.EWResize="ew-resize",s.Grab="grab",s.Grabbing="grabbing",s.Move="move",s.NoDrop="no-drop",s.NSResize="ns-resize",s.NotAllowed="not-allowed",s.ZoomIn="zoom-in",s.ZoomOut="zoom-out",s))(L||{});const fo=s=>Math.max(...s.split(`
2
+ `).map(t=>t.length)),uo=s=>s.match(/\n/g)?.length||0,X=[];for(let s=0;s<256;++s)X.push((s+256).toString(16).slice(1));function po(s,t=0){return(X[s[t+0]]+X[s[t+1]]+X[s[t+2]]+X[s[t+3]]+"-"+X[s[t+4]]+X[s[t+5]]+"-"+X[s[t+6]]+X[s[t+7]]+"-"+X[s[t+8]]+X[s[t+9]]+"-"+X[s[t+10]]+X[s[t+11]]+X[s[t+12]]+X[s[t+13]]+X[s[t+14]]+X[s[t+15]]).toLowerCase()}let ee;const mo=new Uint8Array(16);function vo(){if(!ee){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ee=crypto.getRandomValues.bind(crypto)}return ee(mo)}const yo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Se={randomUUID:yo};function xe(s,t,e){if(Se.randomUUID&&!s)return Se.randomUUID();s=s||{};const a=s.random??s.rng?.()??vo();if(a.length<16)throw new Error("Random bytes length must be >= 16");return a[6]=a[6]&15|64,a[8]=a[8]&63|128,po(a)}const it=s=>{const{selected:t,highlighted:e,selectedAndHighlighted:a,...l}=s,n=l,i={...n,...t},r={...n,...e},o={...n,...e,...t,...a};return{defaultLook:n,selectedLook:i,highlightedLook:r,selectedAndHighlightedLook:o}};class Wt{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],D(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Mt=0;class xt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${ce(this.id)}']`)}}class ht extends Wt{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((a,l,n)=>t(a,l,n)&&!a.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((a,l,n)=>t(a,l,n)&&!a.removed)}find(t,e=!1){return e?super.find(t):super.find((a,l,n)=>t(a,l,n)&&!a.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(a=>!a.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],D(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(a=>!a.removed))yield e}}class bo{constructor(t,e,a,l,n,i,r){this.name=t,this.label=e,this.type=a,this.defaultValue=l,this.basic=n,this.editable=i,this.rootAttribute=r,this.options=void 0,this.properties=void 0}}var T=(s=>(s.Boolean="boolean",s.Color="color",s.Date="date",s.Datetime="datetime",s.Number="number",s.Object="object",s.Option="option",s.OptionList="option-list",s.OptionSet="option-set",s.Text="text",s.TextArea="text-area",s.TextList="text-list",s.TextSet="text-set",s.TextMap="text-map",s.Time="time",s.Url="url",s))(T||{});class Zt{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 yt(s,t){return!t||s[0]>t[0]?!0:s[0]===t[0]?s[1]>=t[1]:!1}const Ce=s=>s==null||s===""||s instanceof Array&&s.length===0||s instanceof Object&&Object.keys(s).length===0,wt=(s,t)=>s===t||JSON.stringify(s)===JSON.stringify(t),ze=(s,t,e)=>{const a={},l={};for(const n in e.propertySet.propertyMap)if(e.propertySet.propertyMap[n].type===T.Object){const i=ze(s[n],t[n],e.getSubValueSet(n));Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(a[n]=i[0],l[n]=i[1])}else wt(s[n],t[n])||(a[n]=s[n],l[n]=t[n]);return[a,l]},ko=s=>s!=null&&s.constructor===Object;class mt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(this.rootElement){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const a of t){if(e==null)return;e=e[a]}return e}}}setRootElementValue(t,e){if(this.rootElement){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let a=this.rootElement;for(let l=0;l<t.length-1;++l){const n=t[l];if(a==null)return;a=a[n]}if(a==null)return;a[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}}getValue(t){const e=this.propertySet.getProperty(t)?.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===T.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===T.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const a in t)this.propertySet.getProperty(a).type===T.Object?e[a]=this.valueSets[a].getValuesForKeys(t[a]):e[a]=this.getValue(a);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===T.Object)t[e]=this.valueSets[e].getTimestamps();else{const l=this.ownTimestamps[e];l&&(t[e]=l)}return t}hasValue(t){const e=this.getValue(t);return!Ce(e)}hasSetValue(t){const e=this.getValue(t),a=this.propertySet.getProperty(t);return a&&a.type===T.Object?this.getSubValueSet(t).hasAnySetValue():!Ce(e)&&!wt(e,a?.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const a=this.propertySet.getProperty(t);if(a){a.type===T.Object?this.valueSets[t].setValues(e):(this.values[t]=e,wt(e,a.defaultValue)||this.displayProperty(a));const l=a.rootAttribute;l!=null&&this.setRootElementValue(l,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===T.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===T.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===T.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const a in t)this.propertySet.getProperty(a).type===T.Object?this.valueSets[a].overwriteValuesLww(t[a],e):yt(e,this.ownTimestamps[a])&&(this.setValue(a,t[a]),this.ownTimestamps[a]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),a=e.rootAttribute;e.type===T.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),a!=null&&e.defaultValue!==void 0&&!wt(this.getRootElementValue(a),e.defaultValue)&&this.setRootElementValue(a,this.values[t]),e.basic!==!1?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),a=new Zt(e.properties),l=new mt(a,this.rootElement);return l.overwriteValues(structuredClone(e.defaultValue)),l}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),D(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),D(this.displayedProperties,t))}}const tt={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:Pe.Straight,style:ue.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class Ve{constructor(t){const e={...tt,...t};this.id=e.id,this.name=e.name,this.label=e.label;const a=it(e.look);if(this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const l=it(e.startMarkerLook);this.defaultStartMarkerLook=l.defaultLook,this.selectedStartMarkerLook=l.selectedLook,this.highlightedStartMarkerLook=l.highlightedLook,this.selectedAndHighlightedStartMarkerLook=l.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const l=it(e.endMarkerLook);this.defaultEndMarkerLook=l.defaultLook,this.selectedEndMarkerLook=l.selectedLook,this.highlightedEndMarkerLook=l.highlightedLook,this.selectedAndHighlightedEndMarkerLook=l.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 Zt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class at extends xt{constructor(t,e,a,l,n){if(t.connections.get(n)!==void 0)throw new Error(`DiagramConnection with id "${n}" already exists`);if(!n)throw new Error("DiagramConnection cannot have an empty or null id");super(t,n),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new mt(e.propertySet,this),this.originalData={},this.setStart(a),this.setEnd(l)}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new mt(t.propertySet,this)),this.model.canvas?.userSelection?.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=it(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=it(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=it(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(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise()}setStart(t){this.start!==t?(this.start!==void 0&&D(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0])):(this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&D(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0])):(this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0]),this.updateInView()}tighten(){const t=this.model.canvas?.allowConnectionLoops||!1,e=this.model.canvas?.allowSharingPorts!==!1,a=this.model.canvas?.allowSharingBothPorts||!1;if(this.start?.rootElement&&this.end){const l=this.start.rootElement.ports.map(n=>[n,n.distanceTo(this.end.coords)]).sort((n,i)=>n[1]-i[1]).map(n=>n[0]);t:for(const n of l){if(!t&&n===this.end||!n.allowsOutgoing||!e&&(n.incomingConnections.length===1&&n.incomingConnections[0]!==this||n.incomingConnections.length>1||n.outgoingConnections.length===1&&n.outgoingConnections[0]!==this||n.outgoingConnections.length>1))continue t;if(!a){for(const i of n.outgoingConnections)if(i!==this&&i.end===this.end)continue t;for(const i of n.incomingConnections)if(i!==this&&i.start===this.end)continue t}if(n===this.start)break t;this.setStart(n);break t}}if(this.end?.rootElement&&this.start){const l=this.end.rootElement.ports.map(n=>[n,n.distanceTo(this.start.coords)]).sort((n,i)=>n[1]-i[1]).map(n=>n[0]);t:for(const n of l){if(!t&&n===this.start||!n.allowsIncoming||!e&&(n.outgoingConnections.length===1&&n.outgoingConnections[0]!==this||n.outgoingConnections.length>1||n.incomingConnections.length===1&&n.incomingConnections[0]!==this||n.incomingConnections.length>1))continue t;if(!a){for(const i of n.incomingConnections)if(i!==this&&i.start===this.start)continue t;for(const i of n.outgoingConnections)if(i!==this&&i.end===this.start)continue t}if(n===this.end)break t;this.setEnd(n);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Mt}}class wo extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,a,l){let n;if(t instanceof Ve)n=t;else{const r=this.types.get(t);if(r===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);n=r}const i=new at(this.model,n,e,a,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){const e=this.get(t,!0);e&&(D(e.start?.outgoingConnections||[],e),D(e.end?.incomingConnections||[],e),super.remove(t),e.updateInView())}}const V={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:It.Center,verticalAlign:Bt.Center,orientation:g.Top,fit:!1,shrink:!0};class ct extends xt{constructor(t,e,a,l,n,i,r,o,c,d,h,u,y,v,m,p){const k=`${e?.id}_field`;if(t.fields.get(k)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,k),this.textTimestamp=null,this.rootElement=e,this.coords=a,this.width=l,this.height=n,this.fontSize=i,this.fontFamily=r,this.color=o,this.selectedColor=c,this.horizontalAlign=d,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case g.Top:this.orientation=0;break;case g.Right:this.orientation=90;break;case g.Bottom:this.orientation=180;break;case g.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=y,this._text=y,this.editable=v,this.fit=m,this.shrink=p}get text(){return this._text}set text(t){(t==null||t?.trim()==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||Mt}}class So extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r,o,c,d,h,u,y,v,m){const p=new ct(this.model,t,e,r,o,a,l,n,i,c,d,h,u,y,v,m);return super.add(p),p.updateInView(),t!==void 0&&(t.label=p),p}remove(t){const e=this.get(t,!0);e&&(e.rootElement?.label!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const Z=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),U=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],et=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1?s.margin[0]:(s.margin.length===2||s.margin.length===3,s.margin[1]),G=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Pt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Rt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],zt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Vt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),$e=1,Ie=1,xo=1,Co=1;class $o{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 a=[];this.sections.push(a);for(const l of e)a.push(new Io(l))}}}class Io{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||Mt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=it(t.look||Oe);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class F extends xt{constructor(t,e,a,l,n,i,r,o){if(t.sections.get(o)!==void 0)throw new Error(`DiagramSection with id "${o}" already exists`);if(!o)throw new Error("DiagramSection cannot have an empty or null id");super(t,o),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=a,this.indexYInNode=l,this.coords=n,this.width=i,this.height=r}get name(){return this.label?.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.node?.look:this._selectedLook!==void 0?this._selectedLook:this.type?.selectedLook||this.node?.look:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type?.highlightedLook||this.node?.look:this._defaultLook!==void 0?this._defaultLook:this.type?.defaultLook||this.node?.look}set look(t){if(t){const e=it(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(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||xo}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||Co}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||Mt}getResizableX(){const t=this.type;return t?.resizableX!==void 0?t.resizableX:this.node?.type?.resizableX||!1}getResizableY(){const t=this.type;return t?.resizableY!==void 0?t.resizableY:this.node?.type?.resizableY||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(n=>n.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let n,i;switch(t){case g.Left:n=[a[0]-e,a[1]],i=[l[0],l[1]],n[1]-n[0]<this.getMinWidth()&&(n[0]=n[1]-this.getMinWidth());break;case g.Top:n=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case g.Right:n=[a[0],a[1]+e],i=[l[0],l[1]],n[1]-n[0]<this.getMinWidth()&&(n[1]=n[0]+this.getMinWidth());break;case g.Bottom:n=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[n[0],i[0]],width:n[1]-n[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];for(const r of this.ports)r.move(Yt(r.coords,e,a,l,n,r.anchorPointX,r.anchorPointY));const i=this.type;this.label&&(this.label.coords=[this.coords[0]+U(i?.label),this.coords[1]+G(i?.label)],this.label.width=this.width-U(i?.label)-et(i?.label),this.label.height=this.height-G(i?.label)-Z(i?.label),this.label.updateInView());for(const r of this.decorators)r.move(Yt(r.coords,e,a,l,n,r.anchorPointX,r.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(r=>r.tighten()),this.updateInView()}}class Ao extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r){const o=new F(this.model,t,e,a,l,n,i,r);super.add(o),o.updateInView(),t.sections.push(o),t.updateInView();const c=t.type.sectionGrid?.sections?.[a]?.[e]?.ports;if(c&&c.length>0)for(let h=0;h<c.length;++h){const u=c[h],y=this.model.ports.new(u.type!==void 0?this.model.ports.types.get(u.type):void 0,o,[o.coords[0]+(u.coords[0]||0),o.coords[1]+(u.coords[1]||0)],u.connectionPoint!==void 0?[o.coords[0]+(u.connectionPoint[0]||0),o.coords[1]+(u.connectionPoint[1]||0)]:void 0,u?.direction,`${o.id}_${h}`,u.anchorPointX||"floating",u.anchorPointY||"floating");if(y.type?.label){const v={...V,...y.type?.label},m=6*v.fontSize+Rt(v)+zt(v),p=v.fontSize+Vt(v)+Pt(v);let k;switch(y.direction){case g.Bottom:case g.Left:case g.Right:k=[y.coords[0]-m/2,y.coords[1]-p-Z(v)];break;case g.Top:k=[y.coords[0]-m/2,y.coords[1]+G(v)];break;default:k=y.coords}this.model.fields.new(y,k,v.fontSize,v.fontFamily,v.color,v.selectedColor,m,p,v.horizontalAlign,v.verticalAlign,v.orientation,"",v.editable,v.fit,v.shrink)}}const d=t.type.sectionGrid?.sections?.[a]?.[e]?.label;if(d){const h={...V,...d};this.model.fields.new(o,[o.coords[0]+U(h),o.coords[1]+G(h)],h.fontSize,h.fontFamily,h.color,h.selectedColor,o.width-U(h)-et(h),o.height-G(h)-Z(h),h.horizontalAlign,h.verticalAlign,h.orientation,"",h.editable,h.fit,h.shrink)}return o}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&&D(e.node.sections,e),super.remove(t),e.updateInView()}}}const Oe={lookType:"shaped-look",shape:Et.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},dt={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,snapToGridOffset:[0,0,0,0],padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:Oe,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Mt,properties:[]};class He{constructor(t){const e={...dt,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.snapToGridOffset=e.snapToGridOffset,this.bottomPadding=Eo(e),this.leftPadding=Mo(e),this.rightPadding=To(e),this.topPadding=No(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new $o(e.sectionGrid):null;const a=it(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new Zt(t?.properties||[])}}class R extends xt{constructor(t,e,a=[0,0],l){if(t.nodes.get(l)!==void 0)throw new Error(`DiagramNode with id "${l}" already exists`);if(!l)throw new Error("DiagramNode cannot have an empty or null id");super(t,l),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new mt(e.propertySet,this),this.originalData={},this.coords=a,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new mt(t.propertySet,this)),this.model.canvas?.userSelection?.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(){return this.label?.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=it(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(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(const t of this.sections)t.raise();this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise();for(const t of this.children)t.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(n=>n.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}getAdjacentNodes(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections){if(!t&&l.removed)continue;const n=l.start?.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}for(const l of a.outgoingConnections){if(!t&&l.removed)continue;const n=l.end?.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=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,a=!1;for(;e!==void 0;){if(e.id===t.id){a=!0;break}e=e.parent}a||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){D(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(o=>o.indexXInNode)),a=Math.max(...this.sections.map(o=>o.indexYInNode)),l=this.coords[0]-t.coords[0]+this.type.leftPadding;l>=0&&(this.sections.length>0?this.stretchSections(g.Left,l,e,a):this.stretch(g.Left,l));const n=this.coords[1]-t.coords[1]+this.type.topPadding;n>=0&&(this.sections.length>0?this.stretchSections(g.Top,n,e,a):this.stretch(g.Top,n));const i=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;i>=0&&(this.sections.length>0?this.stretchSections(g.Right,i,e,a):this.stretch(g.Right,i));const r=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;r>=0&&(this.sections.length>0?this.stretchSections(g.Bottom,r,e,a):this.stretch(g.Bottom,r)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const a of this.children)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);for(const a of this.sections)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let n,i;switch(t){case g.Left:n=[a[0]-e,a[1]],i=[l[0],l[1]],n[1]-n[0]<this.type.minWidth&&(n[0]=n[1]-this.type.minWidth);break;case g.Top:n=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case g.Right:n=[a[0],a[1]+e],i=[l[0],l[1]],n[1]-n[0]<this.type.minWidth&&(n[1]=n[0]+this.type.minWidth);break;case g.Bottom:n=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[n[0],i[0]],width:n[1]-n[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,a,l){let n=Number.NEGATIVE_INFINITY;switch(t){case g.Bottom:for(const i of this.sections)i.indexYInNode===l&&(n=Math.max(n,i.getMinHeight()-i.height));e<n&&(e=n);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode>l&&i.move([i.coords[0],i.coords[1]+e]);break;case g.Right:for(const i of this.sections)i.indexXInNode===a&&(n=Math.max(n,i.getMinWidth()-i.width));e<n&&(e=n);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode>a&&i.move([i.coords[0]+e,i.coords[1]]);break;case g.Top:for(const i of this.sections)i.indexYInNode===l&&(n=Math.max(n,i.getMinHeight()-i.height));e<n&&(e=n);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode<l&&i.move([i.coords[0],i.coords[1]-e]);break;case g.Left:for(const i of this.sections)i.indexXInNode===a&&(n=Math.max(n,i.getMinWidth()-i.width));e<n&&(e=n);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode<a&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const l of this.sections)e[l.id]=l.getGeometry();const a={};for(const l of this.children)l.id!==t&&(a[l.id]=l.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:a}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const r=t.children[i.id];r&&i.setGeometry(r)}for(const i of this.sections){const r=t.sections[i.id];r&&i.setGeometry(r)}for(const i of this.ports)i.move(Yt(i.coords,e,a,l,n,i.anchorPointX,i.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+U(this.type.label),this.coords[1]+G(this.type.label)],this.label.width=this.width-U(this.type.label)-et(this.type.label),this.label.height=this.height-G(this.type.label)-Z(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Yt(i.coords,e,a,l,n,i.anchorPointX,i.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(i=>i.tighten()),this.updateInView()}removeSectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)n.indexYInNode===t&&(a=Math.max(a,n.width),this.model.sections.remove(n.id));for(const n of l)n.indexYInNode>t&&(--n.indexYInNode,n.move([n.coords[0]-a-e,n.coords[1]]));this.stretch(g.Right,-e-a)}removeSectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)n.indexXInNode===t&&(a=Math.max(a,n.height),this.model.sections.remove(n.id));for(const n of l)n.indexYInNode>t&&(--n.indexXInNode,n.move([n.coords[0],n.coords[1]-a-e]));this.stretch(g.Bottom,-e-a)}copySectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)if(n.indexXInNode===t){a=Math.max(a,n.width);let i=n.indexXInNode+1;for(;this.model.sections.get(`${n.id}_copy_${i}_${n.indexYInNode}`,!0)!==void 0;)++i;this.model.sections.new(this,n.indexXInNode+1,n.indexYInNode,[n.coords[0]+n.width+e,n.coords[1]],n.width,n.height,`${n.id}_copy_${i}_${n.indexYInNode}`)}for(const n of l)n.indexXInNode>t&&(++n.indexXInNode,n.move([n.coords[0]+a+e,n.coords[1]]));this.stretch(g.Right,e+a)}copySectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)if(n.indexYInNode===t){a=Math.max(a,n.height);let i=n.indexYInNode+1;for(;this.model.sections.get(`${n.id}_copy_${n.indexXInNode}_${i}`,!0)!==void 0;)++i;this.model.sections.new(this,n.indexXInNode,n.indexYInNode+1,[n.coords[0],n.coords[1]+n.height+e],n.width,n.height,`${n.id}_copy_${n.indexXInNode}_${i}`)}for(const n of l)n.indexYInNode>t&&(++n.indexYInNode,n.move([n.coords[0],n.coords[1]+a+e]));this.stretch(g.Bottom,e+a)}}class Lo extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,a){let l;if(t instanceof He)l=t;else{const i=this.types.get(t);if(i===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);l=i}const n=new R(this.model,l,e,a);if(super.add(n),n.updateInView(),l.sectionGrid!==null){let i=n.coords[1]+(l.sectionGrid.margin||0);for(let r=0;r<l.sectionGrid.sections.length;++r){let o=n.coords[0]+(l.sectionGrid.margin||0);for(let c=0;c<l.sectionGrid.sections[r].length;++c)this.model.sections.new(n,c,r,[o,i],l.sectionGrid.defaultWidths?.[c]||$e,l.sectionGrid.defaultHeights?.[r]||Ie,`${n.id}_${r}_${c}`),o+=(l.sectionGrid.defaultWidths?.[c]||$e)+(l.sectionGrid.margin||0);i+=(l.sectionGrid.defaultHeights?.[r]||Ie)+(l.sectionGrid.margin||0)}}if(l.ports.length>0)for(let i=0;i<l.ports.length;++i){const r=l.ports[i],o=r.type!==void 0?this.model.ports.types.get(r.type):void 0,c=this.model.ports.new(o,n,[n.coords[0]+r.coords[0],n.coords[1]+r.coords[1]],r.connectionPoint!==void 0?[n.coords[0]+(r.connectionPoint[0]||0),n.coords[1]+(r.connectionPoint[1]||0)]:void 0,r.direction,`${n.id}_port_${i}`,r.anchorPointX||"floating",r.anchorPointY||"floating");if(c.type?.label){const d={...V,...c.type?.label},h=6*d.fontSize+Rt(d)+zt(d),u=d.fontSize+Vt(d)+Pt(d);let y;switch(c.direction){case g.Bottom:case g.Left:case g.Right:y=[c.coords[0]-h/2,c.coords[1]-u-Z(d)];break;case g.Top:y=[c.coords[0]-h/2,c.coords[1]+G(d)];break;default:y=c.coords}this.model.fields.new(c,y,d.fontSize,d.fontFamily,d.color,d.selectedColor,h,u,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink)}}if(l.label){const i={...V,...l.label};this.model.fields.new(n,[n.coords[0]+U(i),n.coords[1]+G(i)],i.fontSize,i.fontFamily,i.color,i.selectedColor,n.width-U(i)-et(i),n.height-G(i)-Z(i),i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink)}if(l.decorators.length>0)for(let i=0;i<l.decorators.length;++i){const r=l.decorators[i];this.model.decorators.new(n,[n.coords[0]+r.coords[0],n.coords[1]+r.coords[1]],r.width,r.height,n.getPriority(),r.html,`${n.id}_decorator_${i}`,r.anchorPointX||"floating",r.anchorPointY||"floating")}return n.valueSet.resetValues(),n.model.canvas?.fitNodeInView(n.id),n}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&D(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 a=[];for(const l of this)l.coords[0]<t&&t<l.coords[0]+l.width&&l.coords[1]<e&&e<l.coords[1]+l.height&&a.push(l);return a}}const _e=s=>{for(let t=0;t<s.length;++t)for(let e=0;e<s.length;++e)e!==t&&s[e].isAncestorOf(s[t])&&(s.splice(e,1),--e,t>e&&--t);return s},Eo=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Mo=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],To=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),No=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),je={lookType:"shaped-look",shape:Et.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Ft=it(je),Ge={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:je};class Po{constructor(t){const e={...Ge,...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 a=it(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook}}class vt extends xt{constructor(t,e,a,l,n,i,r,o="floating",c="floating"){if(t.ports.get(r)!==void 0)throw new Error(`DiagramPort with id "${r}" already exists`);if(!r)throw new Error("DiagramPort cannot have an empty or null id");super(t,r),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=a,this.coords=l,this.connectionPoint=n||l,this.direction=i,this.anchorPointX=o,this.anchorPointY=c}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.updateInView())}get typeString(){return this.type?.id}set typeString(t){if(t!==this.type?.id)if(t===void 0)this.type=void 0;else{const e=this.model.ports.types.get(t);e&&(this.type=e)}}get allowsOutgoing(){return this.type?.allowsOutgoing!==void 0?this.type?.allowsOutgoing:!0}get allowsIncoming(){return this.type?.allowsIncoming!==void 0?this.type?.allowsIncoming:!0}get name(){return this.label?.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||Ft)?.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(this.type||Ft)?.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(this.type||Ft)?.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(this.type||Ft)?.defaultLook}set look(t){if(t){const e=it(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(){return this.type?.width||Ge.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updatePortsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.incomingConnections)t.raise();for(const t of this.outgoingConnections)t.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof R)return this.rootElement;if(this.rootElement instanceof F)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||Mt}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 a of this.outgoingConnections)a.setStart(this);for(const a of this.incomingConnections)a.setEnd(this);this.label&&this.label.move([this.label.coords[0]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return Ne(this.coords,t)}}class Ro extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,a,l,n,i,r="floating",o="floating"){const c=new vt(this.model,t,e,a,l,n,i,r,o);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 R||e.rootElement instanceof F)&&D(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class Fe{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 a of e.nodes||[])this.importNode(t,a);for(const a of e.connections||[])this.importConnection(t,a);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){const a=t.nodes.types.get(e.type);if(a){const l=new R(t,a,e.coords,e.id);if(t.nodes.add(l),l.width=e.width,l.height=e.height,e.label){if(a.decorators)for(let i=0;i<a.decorators.length;++i){const r=a.decorators[i];t.decorators.new(l,[l.coords[0]+r.coords[0],l.coords[1]+r.coords[1]],r.width,r.height,l.getPriority(),r.html,`${l.id}_decorator_${i}`)}if(a.label){const i={...V,...a.label},r=new ct(t,l,[l.coords[0]+U(i),l.coords[1]+G(i)],l.width-U(i)-et(i),l.height-G(i)-Z(i),i.fontSize,i.fontFamily,i.color,i.selectedColor,i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink);r.text=e.label,l.label=r,t.fields.add(r),r.updateInView()}}for(const i of e.children||[]){const r=this.importNode(t,i);r!==void 0&&(l.children?.push(r),r.parent=l)}for(const i of e.sections||[]){const r=new F(t,l,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(l.sections?.push(r),t.sections.add(r),i.label&&a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){const c={...V,...a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label},d=new ct(t,r,[r.coords[0]+U(c),r.coords[1]+G(c)],r.width-U(c)-et(c),r.height-G(c)-Z(c),c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);d.text=i.label,r.label=d,t.fields.add(d),d.updateInView()}let o=0;for(const c of i.ports||[]){const d=c.type!==void 0?t.ports.types.get(c.type):void 0,h=new vt(t,d,r,c.coords,c.connectionPoint||c.coords,c.direction,c.id);if(r.ports.push(h),t.ports.add(h),c.label){if(a.ports.length>o&&d?.label){const u={...V,...d?.label};let y;switch(h.direction){case g.Top:case g.Left:y=[h.coords[0]-u.fontSize,h.coords[1]-u.fontSize];break;case g.Bottom:y=[h.coords[0]-u.fontSize,h.coords[1]+u.fontSize];break;case g.Right:y=[h.coords[0]+u.fontSize,h.coords[1]-u.fontSize];break;default:y=h.coords}const v=new ct(t,h,y,u.fontSize,u.fontSize,u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,u.orientation,"",u.editable,u.fit,u.shrink);v.text=c.label,h.label=v,t.fields.add(v),v.updateInView()}++o}c.collabMeta&&(h.selfRemoved=c.collabMeta.selfRemoved,h.selfRemovedTimestamp=c.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(h.label,c.collabMeta.label)),h.updateInView()}i.collabMeta&&(r.selfRemoved=i.collabMeta.selfRemoved,r.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(r.label,i.collabMeta.label)),r.updateInView()}let n=0;for(const i of e.ports||[]){const r=i.type!==void 0?t.ports.types.get(i.type):void 0,o=new vt(t,r,l,i.coords,i.connectionPoint||i.coords,i.direction,i.id);if(l.ports.push(o),t.ports.add(o),i.label){if(a.ports.length>n&&r?.label){const c={...V,...r?.label};let d;switch(o.direction){case g.Top:case g.Left:d=[o.coords[0]-c.fontSize,o.coords[1]-c.fontSize];break;case g.Bottom:d=[o.coords[0]-c.fontSize,o.coords[1]+c.fontSize];break;case g.Right:d=[o.coords[0]+c.fontSize,o.coords[1]-c.fontSize];break;default:d=o.coords}const h=new ct(t,o,d,c.fontSize,c.fontSize,c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);h.text=i.label,o.label=h,t.fields.add(h),h.updateInView()}++n}i.collabMeta&&(o.selfRemoved=i.collabMeta.selfRemoved,o.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,i.collabMeta.label)),o.updateInView()}return e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(l.label,e.collabMeta.label),l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importConnection(t,e){const a=t.connections.types.get(e.type);if(a){const l=new at(t,a,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(l),l.startLabel=e.startLabel,l.middleLabel=e.middleLabel,l.endLabel=e.endLabel,l.points=e.points,e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class Kt{constructor(t,e,a,l,n,i,r){this.canvas=t,this.id=e,this.typeId=a,this.coords=l,this.parentId=n,this.label=i,this.values=r}do(){const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&this.canvas.model.nodes.get(this.parentId)?.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 Kt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class pe{constructor(t,e,a,l,n,i,r){this.canvas=t,this.nodeId=e,this.copyColumnIndex=a,this.copyRowIndex=l,this.removeColumnIndex=n,this.removeRowIndex=i,this.timestamp=r}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&yt(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 me{constructor(t,e,a){this.canvas=t,this.to=e,this.timestamp=a}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&yt(this.timestamp,e.geometryTimestamp)){const a=this.to[t];e.move([a[0],a[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new me(t,e.to,e.timestamp)}}class Ot{constructor(t,e,a,l){this.canvas=t,this.nodeIds=e,this.delta=a,this.timestamp=l}do(){for(const t of this.nodeIds){const e=this.canvas.model.nodes.get(t,!0);e&&yt(this.timestamp,e.geometryTimestamp)&&(e.move([e.coords[0]+this.delta[0],e.coords[1]+this.delta[1]]),e.parent?.fitToChild(e),e.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new Ot(t,e.nodeIds,e.delta,e.timestamp)}}class ot{constructor(t,e,a,l){this.canvas=t,this.nodeId=e,this.to=a,this.timestamp=l}do(){const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&yt(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),t.label?.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);for(const e of t.sections)e.label?.fit&&this.canvas.fitFieldRootInView(e.label.id,e.label.shrink);t.parent?.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 ot(t,e.nodeId,e.to,e.timestamp)}}class Ht{constructor(t,e,a,l,n){this.canvas=t,this.childId=e,this.parentId=a,this.childGeometry=l,this.timestamp=n}do(){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)&&yt(this.timestamp,t.geometryTimestamp)&&(t.parent?.removeChild(t),t.setGeometry(this.childGeometry),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 Ht(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class qt{constructor(t,e,a,l,n){this.canvas=t,this.id=e,this.typeId=a,this.startId=l,this.endId=n}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 At{constructor(t,e,a,l){this.canvas=t,this.fieldId=e,this.to=a,this.timestamp=l}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&yt(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 At(t,e.fieldId,e.to,e.timestamp)}}class Lt{constructor(t,e,a,l){this.canvas=t,this.id=e,this.to=a,this.timestamp=l}getValueSet(){return this.id===void 0?this.canvas.model.valueSet:(this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))?.valueSet}do(){this.getValueSet()?.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Lt(t,e.id,e.to,e.timestamp)}}class nt{constructor(t,e,a,l,n,i,r,o){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=n,this.fieldIds=i,this.selfRemoved=r,this.timestamp=o}doOne(t){t&&yt(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 nt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class Jt{constructor(t,e,a){this.canvas=t,this.nodes=e,this.connections=a}do(){const t=new Fe;this.canvas.userSelection.clear();for(const e of this.nodes){const a=t.importNode(this.canvas.model,e);a&&this.canvas.userSelection.add(a)}for(const e of this.connections){const a=t.importConnection(this.canvas.model,e);a&&this.canvas.userSelection.add(a)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new Jt(t,e.nodes,e.connections)}}class zo{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=xe()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+xe()}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":{Kt.deserialize(this.canvas,t).do();break}case"addSection":{pe.deserialize(this.canvas,t).do();break}case"applyLayout":{me.deserialize(this.canvas,t).do();break}case"move":{Ot.deserialize(this.canvas,t).do();break}case"setGeometry":{ot.deserialize(this.canvas,t).do();break}case"setParent":{Ht.deserialize(this.canvas,t).do();break}case"addConnection":{qt.deserialize(this.canvas,t).do();break}case"editField":{At.deserialize(this.canvas,t).do();break}case"updateValues":{Lt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{nt.deserialize(this.canvas,t).do();break}case"paste":{Jt.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 w=(s=>(s.AddConnection="add-connection",s.AddNode="add-node",s.AddSectionAction="add-section",s.ApplyLayout="apply-layout",s.Clipboard="clipboard",s.ContextMenu="context-menu",s.EditField="edit-field",s.MoveNode="move-node",s.Paste="paste",s.Remove="remove",s.StretchNode="stretch-node",s.StretchSection="stretch-section",s.UpdateValues="update-values",s.Zoom="zoom",s))(w||{});class Oo{constructor(t,e,a,l,n,i,r,o,c){this.canvas=t,this.type=e,this.coords=a,this.parentId=l,this.ancestorId=n,this.fromAncestorGeometry=i,this.toAncestorGeometry=r,this.label=o,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Kt(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 ot(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 nt(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new ot(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new nt(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new ot(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t===void 0}}class oe{constructor(t,e,a){this.canvas=t,this.nodeIds=e,this.delta=a}do(){const t=new Ot(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 Ot(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class B{constructor(t,e,a,l,n,i,r,o){this.canvas=t,this.intent=e,this.nodeId=a,this.from=l,this.to=n,this.ancestorId=i,this.fromAncestorGeometry=r,this.toAncestorGeometry=o}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new ot(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 a=new ot(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new ot(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 a=new ot(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new ot(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Ho{constructor(t,e,a,l,n,i,r,o,c){this.canvas=t,this.childId=e,this.fromParentId=a,this.toParentId=l,this.fromChildGeometry=n,this.toChildGeometry=i,this.ancestorId=r,this.fromAncestorGeometry=o,this.toAncestorGeometry=c}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Ht(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 a=new ot(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Ht(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 a=new ot(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}redo(){return this.do()}}class ie{constructor(t,e,a,l){this.canvas=t,this.type=e,this.startId=a,this.endId=l,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 nt(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 nt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class Ae{constructor(t,e,a,l){this.canvas=t,this.fieldId=e,this.from=a,this.to=l}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new At(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 At(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 At(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class _o{constructor(t,e,a,l){this.canvas=t,this.id=e,this.from=a,this.to=l}do(){const t=new Lt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Lt(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 Lt(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 jo{constructor(t,e,a,l,n,i){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=n,this.fieldIds=i}do(){const t=this.nodeIds.map(a=>this.canvas.model.nodes.get(a)!==void 0).includes(!0)||this.sectionIds.map(a=>this.canvas.model.sections.get(a)!==void 0).includes(!0)||this.portIds.map(a=>this.canvas.model.ports.get(a)!==void 0).includes(!0)||this.connectionIds.map(a=>this.canvas.model.connections.get(a)!==void 0).includes(!0)||this.fieldIds.map(a=>this.canvas.model.fields.get(a)!==void 0).includes(!0),e=new nt(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(a=>this.canvas.model.nodes.get(a)===void 0).includes(!0)||this.sectionIds.map(a=>this.canvas.model.sections.get(a)===void 0).includes(!0)||this.portIds.map(a=>this.canvas.model.ports.get(a)===void 0).includes(!0)||this.connectionIds.map(a=>this.canvas.model.connections.get(a)===void 0).includes(!0)||this.fieldIds.map(a=>this.canvas.model.fields.get(a)===void 0).includes(!0),e=new nt(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 Go{constructor(t,e,a,l){this.canvas=t,this.nodes=e,this.connections=a,this.coords=l}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const n of this.nodes)n.coords[0]<t[0]&&(t[0]=n.coords[0]),n.coords[1]<t[1]&&(t[1]=n.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,a={};for(const n of this.nodes){const i=n.id,r=this.canvas.collabEngine.freshId();if(a[i]=r,n.id=r,e&&(n.coords=[n.coords[0]+e[0],n.coords[1]+e[1]]),n.sections)for(const o of n.sections){const c=o.id;if(o.id.includes(n.id)?o.id=o.id.replace(n.id,r):o.id=this.canvas.collabEngine.freshId(),a[c]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]]),o.ports)for(const d of o.ports){const h=d.id;d.id.includes(n.id)?d.id=d.id.replace(n.id,r):d.id=this.canvas.collabEngine.freshId(),a[h]=d.id,e&&(d.coords=[d.coords[0]+e[0],d.coords[1]+e[1]],d.connectionPoint&&(d.connectionPoint=[d.connectionPoint[0]+e[0],d.connectionPoint[1]+e[1]]))}}if(n.ports)for(const o of n.ports){const c=o.id;o.id.includes(n.id)?o.id=o.id.replace(n.id,r):o.id=this.canvas.collabEngine.freshId(),a[c]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]],o.connectionPoint&&(o.connectionPoint=[o.connectionPoint[0]+e[0],o.connectionPoint[1]+e[1]]))}}for(const n of this.connections){const i=this.canvas.collabEngine.freshId();if(a[n.id]=i,n.id=i,n.start=a[n.start]||n.start,n.end=a[n.end]||n.end,e)for(let r=0;r<n.points.length;++r)n.points[r]=[n.points[r][0]+e[0],n.points[r][1]+e[1]]}const l=new Jt(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(l),!0}undo(){const t=this.nodes.map(a=>this.canvas.model.nodes.get(a.id)!==void 0).includes(!0)||this.connections.map(a=>this.canvas.model.connections.get(a.id)!==void 0).includes(!0),e=new nt(this.canvas,this.nodes.map(a=>a.id),[],[],this.connections.map(a=>a.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=this.nodes.map(a=>this.canvas.model.nodes.get(a.id)===void 0).includes(!0)||this.connections.map(a=>this.canvas.model.connections.get(a.id)===void 0).includes(!0),e=new nt(this.canvas,this.nodes.map(a=>a.id),[],[],this.connections.map(a=>a.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class Qt{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Ue=(s=>(s[s.DoubleClick=0]="DoubleClick",s[s.SecondaryClick=1]="SecondaryClick",s[s.Selection=2]="Selection",s[s.Highlight=3]="Highlight",s))(Ue||{});class ft extends Qt{constructor(t,e,a){super(0),this.cause=t,this.target=e,this.coords=a}}class ut extends Qt{constructor(t,e,a){super(1),this.cause=t,this.target=e,this.coords=a}}class j extends Qt{constructor(t,e){super(2),this.targets=t,this.selected=e}}class J extends Qt{constructor(t){super(3),this.target=t}}class De extends xt{constructor(t,e,a,l,n,i,r,o,c="floating",d="floating"){if(t.objects.get(o)!==void 0)throw new Error(`DiagramDecorator with id "${o}" already exists`);if(!o)throw new Error("DiagramDecorator cannot have an empty or null id");super(t,o),this.rootElement=e,this.coords=a,this.width=l,this.height=n,this.priority=i,this.html=r,this.anchorPointX=c,this.anchorPointY=d}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateDecoratorsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Fo extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r,o="floating",c="floating"){const d=new De(this.model,t,e,a,l,n,i,r,o,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 R||e.rootElement instanceof F)&&D(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Uo extends xt{constructor(t,e,a,l,n,i,r){if(t.objects.get(r)!==void 0)throw new Error(`DiagramObject with id "${r}" already exists`);if(!r)throw new Error("DiagramObject cannot have an empty or null id");super(t,r),this.coords=e,this.width=a,this.height=l,this.priority=n,this.html=i}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateObjectsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Do extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i){const r=new Uo(this.model,t,e,a,l,n,i);return super.add(r),r.updateInView(),r}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Be{constructor(t,e,a,l,n,i=[]){this.nodes=new Lo(this),this.sections=new Ao(this),this.ports=new Ro(this),this.connections=new wo(this),this.fields=new So(this),this.objects=new Do(this),this.decorators=new Fo(this),this.canvas=t,this.id=e,this.name=a,this.description=l,this.type=n,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new mt(new Zt(i),this)}clear(){this.canvas?.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(),this.canvas?.updateModelInView()}}const pt=s=>!!s.button,se=(s,t,e,a,l,n,i,r)=>so(s,[t,e],a,l,Math.max(10,i||0,r||0)*n),S=s=>{s?A.select("body").style("cursor",s):A.select("body").style("cursor",L.Auto)},lt=s=>s instanceof R?s:s instanceof F?s.node||s:s.rootElement instanceof R||s.rootElement instanceof F||s.rootElement instanceof vt?lt(s.rootElement):s,ne=s=>{s.filter(".shaped-look").append("path"),s.filter(".image-look").append("image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none")},Tt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:ue.Solid},re=s=>{s.filter(".shaped-look").select("path").attr("d",t=>he(t.look.shape||Et.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||Tt.fillColor).attr("stroke",t=>t.look.borderColor||Tt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||Tt.borderThickness}px`).attr("stroke-dasharray",t=>de(t.look.borderStyle||Tt.borderStyle,t.type?.defaultLook?.borderThickness||t.look?.borderThickness||Tt.borderThickness)),s.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),s.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),s.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),s.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),s.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),s.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),s.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),s.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),s.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),s.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)},Nt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Bo=(s,t,e)=>{const a=t.append("defs");if(s.gridSize>0&&isFinite(s.gridSize)){const l=a.append("pattern").attr("id",e).attr("x",-s.gridSize/2).attr("y",-s.gridSize/2).attr("width",s.gridSize).attr("height",s.gridSize).attr("patternUnits","userSpaceOnUse");switch(l.append("rect").attr("x",0).attr("y",0).attr("width",s.gridSize).attr("height",s.gridSize).attr("fill",s.backgroundColor),s.gridStyle){case"dots":l.append("circle").attr("cx",s.gridSize/2).attr("cy",s.gridSize/2).attr("r",s.gridSize*s.gridThickness).attr("fill",s.gridColor);break;case"lines":l.append("line").attr("x1",s.gridSize/2).attr("x2",s.gridSize/2).attr("y1",0).attr("y2",s.gridSize).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor),l.append("line").attr("x1",0).attr("x2",(s.gridSize-s.gridSize*s.gridThickness)/2).attr("y1",s.gridSize/2).attr("y2",s.gridSize/2).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor),l.append("line").attr("x1",(s.gridSize+s.gridSize*s.gridThickness)/2).attr("x2",s.gridSize).attr("y1",s.gridSize/2).attr("y2",s.gridSize/2).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor);break}t.select("rect").attr("fill",`url(#${e})`)}},ge=96,Y=32,$t=ge+Y,Yo=Math.PI/4,Xo=100,Le={customButtons:[]};class Wo{constructor(t,e){this.canvas=t,this.config=e||Le}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),a=this.canvas.getPointerLocationRelativeToCanvas(t),l=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(C.ContextMenu,i=>{this.canvas.canUserPerformAction(w.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(C.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=l;const n=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Clipboard)&&this.canvas.canUserPerformAction(w.Remove)&&n.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.userSelection.cutToClipboard(),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Clipboard)&&n.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.userSelection.copyToClipboard(),i.cancelAllUserActions()}}),this.canvas.canUserPerformAction(w.Paste)&&n.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.userSelection.pasteFromClipboard(i.getClosestGridPoint(a)),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Remove)&&n.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.userSelection.removeFromModel(),i.cancelAllUserActions()}});for(const i of this.config.customButtons||Le.customButtons)(i.condition===void 0||i.condition(this.canvas))&&n.push(i);n.length===0&&n.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<n.length;++i){const r=n[i],o=r.onPress,c=(i+.5-n.length/2)*Yo,d=l.append("xhtml:div").attr("class",`daga-context-menu-button ${r.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*Y}px`).style("height",`${2*Y}px`).style("border-radius",`${Y}px`).style("pointer-events","auto").on(C.Click,h=>{o&&(h.preventDefault(),o(this.canvas))}).on(C.KeyDown,h=>{o&&h.key===W.Enter&&(h.preventDefault(),o(this.canvas))});r.imageClass!==void 0?d.append("xhtml:div").style("position","absolute").style("left",`${.75*Y}px`).style("top",`${.5*Y}px`).style("width",`${.5*Y}px`).style("height",`${.5*Y}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",r.imageClass):r.image!==void 0&&d.append("xhtml:img").style("position","absolute").style("left",`${.75*Y}px`).style("top",`${.5*Y}px`).style("width",`${.5*Y}px`).style("height",`${.5*Y}px`).attr("src",r.image),d.append("xhtml:span").style("position","absolute").style("left",`${.2*Y}px`).style("top",`${1.1*Y}px`).style("text-align","center").style("width",`${1.6*Y}px`).style("height",`${.35*Y}px`).style("margin","0").style("font-size",`${.35*Y}px`).style("font-weight","700").style("user-select","none").text(r.name),d.transition().ease(A.easeLinear).duration(Xo).tween("progress",()=>h=>{const u=c*h;return d.style("left",`${Math.sin(u)*ge-Y+$t}px`).style("top",`${-Math.cos(u)*ge-Y+$t}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}}class Zo extends ht{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 ct||t instanceof De)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof R){if(!this.highlightSections)for(const e of t.sections){super.add(e);for(const a of e.ports)super.add(a),this.canvas.updatePortsInView(a.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 F)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 vt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof at&&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 Ko=1;class Ye{export(t,e=!1){const a={name:t.name,type:t.type,typeVersion:Ko,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(a.id=t.id),t.description&&(a.description=t.description);for(const l of t.nodes.all(!0))!e&&l.removed||l.parent===void 0&&a.nodes.push(this.exportNode(l,e));for(const l of t.connections.all(!0))!e&&l.removed||a.connections.push(this.exportConnection(l,e));return a}exportNode(t,e=!1){const a=[];for(const i of t.children)a.push(this.exportNode(i,e));const l=[];for(const i of t.sections){const r=[];for(const o of i.ports)r.push({id:o.id,type:o.type?.id,coords:Ct(o.coords),connectionPoint:Ct(o.connectionPoint||o.coords),direction:o.direction,label:o.label?.text||"",...e?{collabMeta:{removed:o.removed,selfRemoved:o.selfRemoved,selfRemovedTimestamp:o.selfRemovedTimestamp,...this.exportLabelCollabMeta(o)}}:{}});l.push({id:i.id,ports:r,label:i.label?.text||"",indexXInNode:i.indexXInNode,indexYInNode:i.indexYInNode,coords:Ct(i.coords),width:i.width,height:i.height,...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}})}const n=[];for(const i of t.ports)n.push({id:i.id,type:i.type?.id,coords:Ct(i.coords),connectionPoint:Ct(i.connectionPoint||i.coords),direction:i.direction,label:i.label?.text||"",...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}});return{id:t.id,type:t.type.id,children:a,sections:l,ports:n,label:t.label?.text||"",coords:Ct(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){return{id:t.id,type:t.type.id,start:t.start?.id||"",end:t.end?.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 qo="Diagram properties";class Jo extends ht{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(kt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof R||t instanceof at)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof F?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof R&&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 R&&e.sections))for(const a of e.sections)super.remove(a.id),a.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 R&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],a=[],l=[],n=[];for(const r of this.all())r instanceof R?t.push(r.id):r instanceof F?e.push(r.id):r instanceof vt?a.push(r.id):r instanceof at?l.push(r.id):r instanceof ct&&n.push(r.id);const i=new jo(this.canvas,t,e,a,l,n);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Ye;for(const a of this.all())a instanceof R&&t.nodes.push(e.exportNode(a,!1)),a instanceof at&&t.connections.push(e.exportConnection(a,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const a=JSON.parse(e);if(a.type!=="daga-user-selection")return;const l=new Go(this.canvas,a.nodes,a.connections,t);this.canvas.actionStack.add(l),l.do()}catch{return}})}openInPropertyEditor(t,e=!0){e&&this.makeUpdateValuesAction();const a=this.canvas.parentComponent?.propertyEditor;if(a===void 0)return;const l=t?.valueSet;l?(this.propertyEditorSelection=t,e&&(this.propertyEditorValues=structuredClone(l.getValues())),a&&(t instanceof R||t instanceof at?(t instanceof R?t.name?a.title=`${t.type.name}: ${t.name}`:a.title=t.type.name:t instanceof at&&(a.title=t.type.name),a.valueSet=void 0,a.valueSet=l):(a.title=qo,a.valueSet=void 0,a.valueSet=l))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,a&&(a.title="",a.valueSet=void 0))}makeUpdateValuesAction(){if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof Be?void 0:this.propertyEditorSelection.id;if(wt(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;const e=this.propertyEditorValues,a=structuredClone(this.propertyEditorSelection?.valueSet.getValues()),[l,n]=ze(e,a,this.propertyEditorSelection?.valueSet),i=new _o(this.canvas,t,l,n);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=a}}const Qo=s=>s*Math.PI/180,Ee=(s,t,e)=>{const a=Qo(e),l=Math.sin(a),n=Math.cos(a),i=(Math.abs(s*n)-Math.abs(t*l))/(n*n-l*l),r=(Math.abs(s*l)-Math.abs(t*n))/(l*l-n*n);return[i,r]},ti=12,H=6,ei=25,ae="diagram-connection-unfinished",Xt=class Xt{constructor(t,e){if(this.backgroundPatternId=`daga-background-pattern-id-${Xt.canvasCount++}`,this.zoomTransform=A.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new kt.Subject,this.diagramChange$=new kt.Subject,this.diagramEvent$=new kt.Subject,this.propertyEditorChanges$=new kt.Subject,this.parentComponent=t,this.model=new Be(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new Jo(this),this.userHighlight=new Zo(this,e.canvas?.highlightSections!==!1),this.contextMenu=new Wo(this,e.canvas?.contextMenu),this.backgroundColor=e.canvas?.backgroundColor||"#FFFFFF",this.gridStyle=e.canvas?.grid?.style??Nt.style,this.gridSize=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?0:Math.abs(e.canvas?.grid?.spacing||Nt.spacing),this.gridThickness=Math.abs(e.canvas?.grid?.thickness||Nt.thickness),this.gridColor=e.canvas?.grid?.color||Nt.color,this.snapToGrid=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?!1:e.canvas?.grid?.snap||Nt.snap,this.zoomFactor=e.canvas?.zoomFactor||2,this.panRate=e.canvas?.panRate||100,this.inferConnectionType=e.connectionSettings?.inferConnectionType||!1,this.autoTightenConnections=e.connectionSettings?.autoTighten!==!1,this.allowConnectionLoops=e.connectionSettings?.allowLoops||!1,this.allowSharingPorts=e.connectionSettings?.sharePorts!==!1,this.allowSharingBothPorts=e.connectionSettings?.shareBothPorts||!1,this.portHighlightRadius=e.connectionSettings?.portHighlightRadius||100,this.multipleSelectionOn=!1,this.priorityThresholds=e.canvas?.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,ei),this.collabEngine=new zo(this),e.nodeTypes)for(const a of e.nodeTypes){const l=new He({...e.nodeTypeDefaults,...a});this.model.nodes.types.add(l)}if(e.portTypes)for(const a of e.portTypes){const l=new Po({...e.portTypeDefaults,...a});this.model.ports.types.add(l)}if(e.connectionTypes){for(const a of e.connectionTypes){const l=new Ve({...e.connectionTypeDefaults,...a});this.model.connections.types.add(l)}this._connectionType=e?.connectionSettings?.defaultConnection!==void 0?this.model.connections.types.get(e.connectionSettings.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){this._connectionType=t,this.parentComponent?.palette?.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){D(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){this.priorityThreshold=t,this.updateModelInView();for(const e of this.model.nodes)this.fitNodeInView(e.id);this.parentComponent?.palette?.refreshPalette()}initView(t){const e=A.select(t);e.html(""),this.diagramRoot=e.append("div").node(),A.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),A.select(this.diagramRoot).on(C.Click,()=>{A.select(this.diagramRoot).node()?.focus()}).on(C.ContextMenu,l=>{if(this.dragging){l.preventDefault(),l.stopPropagation(),this.dragging=!1;return}const n=new ut(l,null);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(l.preventDefault(),this.contextMenu.open(l))}).on(C.DoubleClick,l=>{const n=new ft(l,null);this.diagramEvent$.next(n)}).on(C.KeyDown,l=>{if(!l.ctrlKey&&(l.key===W.Delete||l.key===W.Backspace)&&this.canUserPerformAction(w.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="a"){l.preventDefault();for(const n of this.model.nodes)this.userSelection.add(n);for(const n of this.model.connections)this.userSelection.add(n);this.diagramEvent$.next(new j(this.userSelection.all(),!0))}if(l.ctrlKey&&l.key==="i"){l.preventDefault();const n=[],i=[];for(const r of this.model.nodes)this.userSelection.toggle(r),r.selected?n.push(r):i.push(r);for(const r of this.model.connections)this.userSelection.toggle(r),r.selected?n.push(r):i.push(r);n.length>0&&this.diagramEvent$.next(new j(n,!0)),i.length>0&&this.diagramEvent$.next(new j(i,!1))}if(l.ctrlKey&&l.key==="c"&&this.canUserPerformAction(w.Clipboard)&&(l.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="x"&&this.canUserPerformAction(w.Clipboard)&&this.canUserPerformAction(w.Remove)&&(l.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="v"&&this.canUserPerformAction(w.Paste)){l.preventDefault();const n=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(n[0][0]+n[1][0])/2,(n[0][1]+n[1][1])/2])),this.cancelAllUserActions()}l.ctrlKey&&l.key==="y"&&(l.preventDefault(),this.actionStack.redo()),l.ctrlKey&&l.key==="z"&&(l.preventDefault(),this.actionStack.undo()),l.key==="+"&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.zoomBy(this.zoomFactor)),l.key==="-"&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.zoomBy(1/this.zoomFactor)),l.key===W.ArrowLeft&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowRight&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowDown&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),l.key===W.ArrowUp&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const a=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%");a.call(this.zoomBehavior=A.zoom().filter(l=>l.type!==C.DoubleClick).on(le.Zoom,l=>{if(l.sourceEvent){if(!this.canUserPerformAction(w.Zoom)){S(L.NotAllowed);return}l.sourceEvent.type===C.Wheel&&l.sourceEvent.wheelDelta!==void 0?(l.sourceEvent.wheelDelta>0&&S(L.ZoomIn),l.sourceEvent.wheelDelta<0&&S(L.ZoomOut)):l.sourceEvent.type===C.MouseMove&&S(L.AllScroll)}this.zoomTransform=l.transform;const n=l.transform.toString();this.selectCanvasElements().attr("transform",n),A.select(`#${this.backgroundPatternId}`).attr("patternTransform",n),this.contextMenu.close()}).on(le.End,()=>{S()})),a.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(C.MouseMove,l=>{if(this.unfinishedConnection!==void 0){const n=this.getPointerLocationRelativeToCanvas(l);this.unfinishedConnection.endCoords=n}}).on(C.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new J(null)))}).on(C.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new J(null))),this.contextMenu.close(),this.userSelection.size()>0){const l=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(l,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(A.drag().filter(l=>this.multipleSelectionOn||pt(l)).on($.Start,l=>{this.startMultipleSelection(l)}).on($.Drag,l=>{this.continueMultipleSelection(l)}).on($.End,l=>{this.finishMultipleSelection(l)})),Bo(this,a,this.backgroundPatternId),a.append("g").attr("class","daga-canvas-elements")}getZoomLevel(){return this.zoomTransform.k}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView(),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView(),t)}getViewCoordinates(){return[this.zoomTransform.x,this.zoomTransform.y]}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(){if(this.model.nodes.length>0){const t=this.selectCanvasView().select("rect").node()?.getBBox(),e=this.model.nodes.all(),a=Math.min(...e.map(v=>v.coords[0])),l=Math.max(...e.map(v=>v.coords[0]+v.width)),n=(a+l)/2,i=l-a,r=t.width,o=Math.min(...e.map(v=>v.coords[1])),c=Math.max(...e.map(v=>v.coords[1]+v.height)),d=(o+c)/2,h=c-o,u=t.height,y=Math.min(r/i,u/h,1);this.translateTo(n,d),this.zoomTo(y)}}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(){const t=this.selectSVGElement().node()?.getBoundingClientRect(),e=[t?.width||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 A.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return A.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return A.pointer(this.getEventHoldingCoordinates(t),A.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.defaultLook.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const n=l.merge(e);a.remove(),l.on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(o,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new j([r],r.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)),this.userSelection.add(r),this.diagramEvent$.next(new j([r],!0)),this.contextMenu.open(i))}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,r)}).on($.Drag,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,r)}).on($.End,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,r),this.secondaryButton=!1})),ne(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed?(S(L.EWResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Left,r.coords[0]-o[0])}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[0],o[1]-r.type.snapToGridOffset[1]]),o[0]+=r.type.snapToGridOffset[0],o[1]+=r.type.snapToGridOffset[1]),r.stretch(g.Left,r.coords[0]-o[0]),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed?(S(L.NSResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Top,r.coords[1]-o[1])}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[0],o[1]-r.type.snapToGridOffset[1]]),o[0]+=r.type.snapToGridOffset[0],o[1]+=r.type.snapToGridOffset[1]),r.stretch(g.Top,r.coords[1]-o[1]),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed?(S(L.EWResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Right,o[0]-(r.coords[0]+r.width))}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[2],o[1]-r.type.snapToGridOffset[3]]),o[0]+=r.type.snapToGridOffset[2],o[1]+=r.type.snapToGridOffset[3]),r.stretch(g.Right,o[0]-(r.coords[0]+r.width)),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed?(S(L.NSResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Bottom,o[1]-(r.coords[1]+r.height))}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[2],o[1]-r.type.snapToGridOffset[3]]),o[0]+=r.type.snapToGridOffset[2],o[1]+=r.type.snapToGridOffset[3]),r.stretch(g.Bottom,o[1]-(r.coords[1]+r.height)),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),n.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),re(n),n.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",H/2).attr("y2",H/2),n.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-H/2).attr("x2",i=>i.width-H/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-H/2).attr("y2",i=>i.height-H/2)}updateSectionsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-section${i.getResizableX()?" resizable-x":""}${i.getResizableY()?" resizable-y":""} ${i.look?.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const n=l.merge(e);a.remove(),l.on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}const o=lt(r);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(r);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const o=r?.node;o?this.startMovingNode(i,o):S(L.NotAllowed)}}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const o=r?.node;o?this.continueMovingNode(i,o):S(L.NotAllowed)}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const o=r?.node;o?this.finishMovingNode(i,o):S()}this.secondaryButton=!1})),ne(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node?(S(L.EWResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Left,r.coords[0]-o[0],r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Left,r.coords[0]-o[0],r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node?(S(L.NSResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Top,r.coords[1]-o[1],r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Top,r.coords[1]-o[1],r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node?(S(L.EWResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Right,o[0]-(r.coords[0]+r.width),r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Right,o[0]-(r.coords[0]+r.width),r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node?(S(L.NSResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Bottom,o[1]-(r.coords[1]+r.height),r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Bottom,o[1]-(r.coords[1]+r.height),r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),n.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),re(n),n.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",H/2).attr("y2",H/2),n.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-H/2).attr("x2",i=>i.width-H/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-H/2).attr("y2",i=>i.height-H/2)}updatePortsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-port ${i.look.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const n=l.merge(e);a.remove(),l.on(C.MouseOver,(i,r)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(r.getNode()?.type?.id||"")&&r.allowsIncoming||this.unfinishedConnection.type.canStartFromType(r.getNode()?.type?.id||"")&&r.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsIncoming||S(L.NoDrop))}).on(C.MouseOut,()=>{this.unfinishedConnection&&S(L.Grabbing)}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}const o=lt(r);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(r);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(w.AddConnection)&&(this.allowSharingPorts||r.incomingConnections.length===0&&r.outgoingConnections.length===0)&&!r.removed?(S(L.Grabbing),this.startConnection(r),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(w.AddConnection)&&!r.removed&&this.unfinishedConnection!==void 0){const o=[i.x,i.y];this.unfinishedConnectionTracer?.attr("d",se(this.unfinishedConnection.look.shape||tt.look.shape,this.unfinishedConnection.startCoords,o,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.defaultLook.thickness||tt.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));const c=this.unfinishedConnectionTracer?.node();if(c){let d=2;const h=c.getTotalLength();h<d&&(d=0);const u=c.getPointAtLength(h-d);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=o;if(this.updateConnectionsInView(ae),this.model.ports.length>0){const d=this.getPointerLocationRelativeToCanvas(i);let h=Number.POSITIVE_INFINITY,u;for(const y of this.model.ports){const v=y.distanceTo(d);v<h&&(h=v,u=y)}u&&h<this.portHighlightRadius?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(w.AddConnection)&&!r.removed){this.unfinishedConnectionTracer?.remove();const o=this.userHighlight.getFocus();if(o instanceof vt)this.finishConnection(o);else if(o instanceof ct&&o.rootElement instanceof vt)this.finishConnection(o.rootElement);else if(o instanceof R||o instanceof F||o instanceof ct){let c;if(o instanceof R||o instanceof F)c=o;else if(o.rootElement instanceof R||o.rootElement instanceof F)c=o.rootElement;else{this.dropConnection();return}const d=c.getClosestPortToPoint([i.x,i.y]);d!==void 0?this.finishConnection(d):this.dropConnection()}else this.dropConnection()}S()}this.secondaryButton=!1})),l.filter(".image-look").append("image"),ne(l),n.attr("transform",i=>`translate(${i.coords[0]-i.width/2},${i.coords[1]-i.width/2})`).attr("opacity",i=>i.removed?.5:1),re(n)}updateConnectionsInView(...t){const e=this.model.connections.filter(r=>this.priorityThreshold!==void 0?r.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let a=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,r=>r.id);const l=a.exit(),n=a.enter().append("g").attr("id",r=>r.id).attr("class","diagram-connection");t&&t.length>0&&(a=a.filter(r=>t.includes(r.id)));const i=n.merge(a);l.remove(),n.on(C.MouseOver,(r,o)=>{o.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(o),this.diagramEvent$.next(new J(o)))}).on(C.Click,(r,o)=>{if(!r.ctrlKey&&!r.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(r,o)=>{if(this.dragging){r.preventDefault(),r.stopPropagation(),this.dragging=!1;return}const c=new ut(r,o);this.diagramEvent$.next(c),!c.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(r.preventDefault(),this.userHighlight.focusOn(o),this.diagramEvent$.next(new J(o)),this.userSelection.add(o),this.diagramEvent$.next(new j([o],!0)),this.contextMenu.open(r))}).on(C.DoubleClick,(r,o)=>{const c=new ft(r,o);this.diagramEvent$.next(c)}).call(A.drag().filter(r=>(this.secondaryButton=pt(r),!0)).on($.Start,r=>{this.startMultipleSelection(r)}).on($.Drag,r=>{this.continueMultipleSelection(r)}).on($.End,r=>{this.finishMultipleSelection(r)})),n.append("path").attr("class","diagram-connection-path"),n.append("path").attr("class","diagram-connection-path-box"),n.append("marker").attr("id",r=>`${r.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),n.append("marker").attr("id",r=>`${r.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),n.append("g").attr("class","diagram-connection-start-label"),n.select("g.diagram-connection-start-label").append("path"),n.select("g.diagram-connection-start-label").append("text").style("user-select","none"),n.append("g").attr("class","diagram-connection-middle-label"),n.select("g.diagram-connection-middle-label").append("path"),n.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),n.append("g").attr("class","diagram-connection-end-label"),n.select("g.diagram-connection-end-label").append("path"),n.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",r=>r.removed?.5:1).select("path.diagram-connection-path").attr("d",r=>se(r.look.shape||tt.look.shape,r.startCoords,r.endCoords,r.startDirection,r.endDirection,r.type.defaultLook.thickness||tt.look.thickness,r.type.defaultStartMarkerLook?.width,r.type.defaultEndMarkerLook?.width)).attr("marker-start",r=>`url(#${r.id}-start-marker)`).attr("marker-end",r=>`url(#${r.id}-end-marker)`).attr("stroke",r=>r.look.color||tt.look.color).attr("stroke-width",r=>`${r.look.thickness}px`).attr("stroke-dasharray",r=>de(r.look.style||tt.look.style,r.type.defaultLook.thickness||tt.look.thickness)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",r=>se(r.look.shape||tt.look.shape,r.startCoords,r.endCoords,r.startDirection,r.endDirection,r.type.defaultLook.thickness||tt.look.thickness,r.type.defaultStartMarkerLook?.width,r.type.defaultEndMarkerLook?.width)).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",r=>`${(r.look.thickness||tt.look.thickness)+ti}px`).attr("stroke-dasharray",r=>de(r.look.style||tt.look.style,r.type.defaultLook.thickness||tt.look.thickness)).attr("fill","none"),i.data().forEach(r=>{this.updateConnectionLabelsInView(r),this.updateConnectionMarkersInView(r)})}updateFieldsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const n=l.merge(e);a.remove(),l.style("box-sizing","border-box").on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}const o=lt(r);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(r);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.EditField)&&r.editable&&!r.removed&&(this.currentAction=new Ae(this,r.id,r.text,""),this.createInputField(r.text,r.coords,r.width,r.height,r.fontSize,r.fontFamily||V.fontFamily,r.orientation,c=>{},c=>{r.text=c,this.currentAction instanceof Ae&&(this.currentAction.to=c,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.startMovingNode(i,o):S(L.NotAllowed)}}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.continueMovingNode(i,o):S(L.NotAllowed)}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.finishMovingNode(i,o):S()}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"),n.attr("x",0).attr("y",0).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("div").style("justify-content",i=>i.horizontalAlign===It.Center?"center":i.horizontalAlign===It.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Bt.Center?"center":i.verticalAlign===Bt.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":`${Ee(i.width,i.height,i.orientation)[0]}px`).style("max-height",i=>i.fit?"default":`${Ee(i.width,i.height,i.orientation)[1]}px`).style("overflow",i=>i.fit?"default":"clip").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===It.Center?"center":i.horizontalAlign===It.Right?"end":"start").style("transform",i=>`rotate(${i.orientation}deg)`).style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br/>"))}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),a.remove(),l.on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(i)}).on($.Drag,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(i)}).on($.End,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(i)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),a.remove(),l.on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(o,!1))}if(r.rootElement){const o=lt(r.rootElement);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&r.rootElement){i.preventDefault();const c=lt(r.rootElement);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.startMovingNode(i,o):S(L.NotAllowed)}}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.continueMovingNode(i,o):S(L.NotAllowed)}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.finishMovingNode(i,o):S()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),l=e.select("path").node(),n={...V,...t.type.label};if(l){const i=l.getTotalLength();let r=0,o=0,c=0,d=0,h=0,u=0;if(n.backgroundColor==="#00000000"){const p=t.endCoords[0]-t.startCoords[0],k=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case g.Top:r=p>=0?-.5:.5,h=r;break;case g.Bottom:r=p>=0?-.5:.5,h=r;break;case g.Left:o=k>0?-.5:.5,u=o;break;case g.Right:o=k>0?-.5:.5,u=o;break;default:r=.5,h=r,o=-.5,u=o}switch(t.endDirection){case g.Top:h=p>=0?.5:-.5;break;case g.Bottom:h=p>=0?.5:-.5;break;case g.Left:u=k>0?.5:-.5;break;case g.Right:u=k>0?.5:-.5;break;default:h=.5,u=-.5}Math.abs(p)>=Math.abs(k)?(c=p>0?-.5:.5,d=k>0?.5:-.5):(c=p>0?.5:-.5,d=k>0?-.5:.5)}e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",n.fontSize/3).attr("text-anchor","middle").attr("font-family",n.fontFamily).attr("font-size",n.fontSize).attr("fill",t.selected?n.selectedColor:n.color).style("font-kerning","none").text(t.startLabel);const y=e.select("g.diagram-connection-start-label text").node()?.getBoundingClientRect();if(y){const p=t.startLabel?y.width/this.zoomTransform.k+Rt(n)+zt(n):0,k=t.startLabel?y.height/this.zoomTransform.k+Vt(n)+Pt(n):0;let b;switch(t.startDirection){case g.Left:b=l.getPointAtLength(et(n)+p/2);break;case g.Right:b=l.getPointAtLength(U(n)+p/2);break;case g.Top:b=l.getPointAtLength(Z(n)+p/2);break;case g.Bottom:b=l.getPointAtLength(G(n)+p/2);break;default:b=l.getPointAtLength(Math.max(U(n)+p/2,et(n)+p/2,G(n)+k/2,Z(n)+k/2))}e.select("g.diagram-connection-start-label path").attr("d",Dt(-p/2,-k/2,p,k)).attr("fill",n.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${b.x+r*p},${b.y+o*k})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",n.fontSize/3).attr("text-anchor","middle").attr("font-family",n.fontFamily).attr("font-size",n.fontSize).attr("fill",t.selected?n.selectedColor:n.color).style("font-kerning","none").text(t.middleLabel);const v=e.select("g.diagram-connection-middle-label text").node()?.getBoundingClientRect();if(v){const p=t.middleLabel?v.width/this.zoomTransform.k+Rt(n)+zt(n):0,k=t.middleLabel?v.height/this.zoomTransform.k+Vt(n)+Pt(n):0,b=l.getPointAtLength(i/2);e.select("g.diagram-connection-middle-label path").attr("d",Dt(-p/2,-k/2,p,k)).attr("fill",n.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${b.x+c*p},${b.y+d*k})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",n.fontSize/3).attr("text-anchor","middle").attr("font-family",n.fontFamily).attr("font-size",n.fontSize).attr("fill",t.selected?n.selectedColor:n.color).style("font-kerning","none").text(t.endLabel);const m=e.select("g.diagram-connection-end-label text").node()?.getBoundingClientRect();if(m){const p=t.endLabel?m.width/this.zoomTransform.k+Rt(n)+zt(n):0,k=t.endLabel?m.height/this.zoomTransform.k+Vt(n)+Pt(n):0;let b;switch(t.endDirection){case g.Left:b=l.getPointAtLength(i-(et(n)+p/2));break;case g.Right:b=l.getPointAtLength(i-(U(n)+p/2));break;case g.Top:b=l.getPointAtLength(i-(Z(n)+p/2));break;case g.Bottom:b=l.getPointAtLength(i-(G(n)+p/2));break;default:b=l.getPointAtLength(i-Math.max(U(n)+p/2,et(n)+p/2,G(n)+k/2,Z(n)+k/2))}e.select("g.diagram-connection-end-label path").attr("d",Dt(-p/2,-k/2,p,k)).attr("fill",n.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${b.x+h*p},${b.y+u*k})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),a=e.select("marker.diagram-connection-start-marker"),l=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?a.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):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?l.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):l.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof R||e.rootElement instanceof F){const a=this.minimumSizeOfField(e),l=a[0]+U(e.rootElement.type?.label)+et(e.rootElement.type?.label)-e.rootElement.width,n=a[1]+G(e.rootElement.type?.label)+Z(e.rootElement.type?.label)-e.rootElement.height;return l<=0&&n<=0}return!0}fitFieldRootInView(t,e=!0){const a=this.model.fields.get(t);if(a){if(a.rootElement instanceof R){const l=this.minimumSizeOfField(a);let n=l[0]+U(a.rootElement.type.label)+et(a.rootElement.type.label)-a.rootElement.width,i=l[1]+G(a.rootElement.type.label)+Z(a.rootElement.type.label)-a.rootElement.height;this.snapToGrid&&(n=Math.ceil(n/this.gridSize)*this.gridSize,i=Math.ceil(i/this.gridSize)*this.gridSize),a.rootElement.width+n<a.rootElement.type.minWidth&&(n=a.rootElement.type.minWidth-a.rootElement.width),a.rootElement.height+i<a.rootElement.type.minHeight&&(i=a.rootElement.type.minHeight-a.rootElement.height),(e!==!1||n>0)&&a.rootElement.stretch(g.Right,n),(e!==!1||i>0)&&a.rootElement.stretch(g.Bottom,i)}if(a.rootElement instanceof F){const l=this.minimumSizeOfField(a);let n=l[0],i=l[1];for(const d of a.rootElement.node?.sections||[])d.label&&(d.indexXInNode===a.rootElement.indexXInNode&&d.indexYInNode!==a.rootElement.indexYInNode?n=Math.max(n,this.minimumSizeOfField(d.label)[0]):d.indexXInNode!==a.rootElement.indexXInNode&&d.indexYInNode===a.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(d.label)[1])));l[0]<n&&(l[0]=n),l[1]<i&&(l[1]=i);const r=a.rootElement.type;let o=l[0]+U(r?.label)+et(r?.label)-a.rootElement.width,c=l[1]+G(r?.label)+Z(r?.label)-a.rootElement.height;this.snapToGrid&&(o=Math.ceil(o/this.gridSize)*this.gridSize,c=Math.ceil(c/this.gridSize)*this.gridSize),a.rootElement.width+o<(a.rootElement.getMinWidth()||0)&&(o=(a.rootElement.getMinWidth()||0)-a.rootElement.width),a.rootElement.height+c<(a.rootElement.getMinHeight()||0)&&(c=(a.rootElement.getMinHeight()||0)-a.rootElement.height),(e||o>0)&&a.rootElement.node?.stretchSections(g.Right,o,a.rootElement.indexXInNode,a.rootElement.indexYInNode),(e||c>0)&&a.rootElement.node?.stretchSections(g.Bottom,c,a.rootElement.indexXInNode,a.rootElement.indexYInNode)}}}fitNodeInView(t,e=!0){const a=this.model.nodes.get(t);if(a&&a.sections.length>0&&this.priorityThreshold){let l=0,n=0;for(const i of a.sections)if(i.getPriority()>=this.priorityThreshold){const r=i.coords[0]+i.width-a.coords[0],o=i.coords[1]+i.height-a.coords[1];l=Math.max(l,r),n=Math.max(n,o)}l+=a.type.sectionGrid?.margin||0,n+=a.type.sectionGrid?.margin||0,(e||l>a.width)&&a.stretch(g.Right,l-a.width),(e||n>a.height)&&a.stretch(g.Bottom,n-a.height)}}selectRoot(){return A.select(this.diagramRoot)}selectSVGElement(){return A.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming))this.unfinishedConnection=new at(this.model,this.connectionType,t,void 0,ae);else if(this.inferConnectionType){let e=this.model.connections.types.all().find(a=>t.allowsOutgoing&&a.canStartFromType(t.getNode()?.type?.id||""));e===void 0&&(e=this.model.connections.types.all().find(a=>t.allowsIncoming&&a.canFinishOnType(t.getNode()?.type?.id||""))),e!==void 0&&(this.unfinishedConnection=new at(this.model,e,t,void 0,ae))}}}finishConnection(t){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(e=>e.start===this.unfinishedConnection?.start&&e.end===t||e.end===this.unfinishedConnection?.start&&e.start===t)!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming){const e=new ie(this,this.unfinishedConnection.type,this.unfinishedConnection.start?.id,t.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&this.unfinishedConnection.type.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing){const e=new ie(this,this.unfinishedConnection.type,t.id,this.unfinishedConnection.start?.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.inferConnectionType){let e=this.model.connections.types.all().find(l=>l.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&l.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming),a=!1;if(e===void 0&&(e=this.model.connections.types.all().find(l=>l.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&l.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing),a=!0),e!==void 0){const l=new ie(this,e,a?t.id:this.unfinishedConnection.start?.id,a?this.unfinishedConnection.start?.id:t.id);this.dropConnection(),l.do(),this.actionStack.add(l)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){this.unfinishedConnection?.setStart(void 0),this.unfinishedConnection?.setEnd(void 0),this.unfinishedConnection?.select()?.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,a,l,n,i,r,o,c){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${a}px`).attr("height",`${l}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const h=d.append("xhtml:textarea");let u,y;h.text(t).style("box-sizing","border-box").style("width",`${a}px`).style("height",`${l}px`).style("font-size",`${n}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(C.KeyDown,m=>{m.stopPropagation()}).on(C.KeyUp,m=>{if(m.stopPropagation(),m.key===W.Escape){const p=h.property("value");this.removeInputField(),c&&c(p)}}).on(C.Input,()=>{const m=h.property("value");h.attr("cols",fo(m)+1),h.attr("rows",uo(m)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,y=h.property("scrollHeight")+1;const p=Math.max(u,a),k=Math.max(y,l);d?.attr("width",`${p}px`),h.style("width",`${p}px`),d?.attr("height",`${k}px`),h.style("height",`${k}px`),o&&o(m)}).on(C.Click,m=>{m.stopPropagation()}).on(C.FocusOut,()=>{const m=h.property("value");this.removeInputField(),c&&c(m)});const v=h.node();v.focus(),v.select()}removeInputField(){this.inputFieldContainer?.select("input")?.on(C.Blur,null),this.inputFieldContainer?.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){const e=t.select()?.select("p")?.node();if(!e)return[0,0];const a=e.getBoundingClientRect();return[a.width/this.zoomTransform.k,a.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(w.MoveNode)&&!e.removed)if(S(L.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(a=>a instanceof R)>1)this.currentAction=new oe(this,this.userSelection.filter(a=>a instanceof R).map(a=>a.id),e.coords);else{const a=e.getLastAncestor();this.currentAction=new B(this,w.MoveNode,e.id,e.getGeometry(),e.getGeometry(),a?.id,a?.getGeometry(e.id),a?.getGeometry(e.id))}else S(L.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(w.MoveNode)&&(this.currentAction instanceof oe||this.currentAction instanceof B)&&!e.removed){const a=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([a[0]-e.coords[0],a[1]-e.coords[1]]):e.move(a),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){if(this.canUserPerformAction(w.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let a=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(a=this.getClosestGridPoint([a[0]-e.type.snapToGridOffset[0],a[1]-e.type.snapToGridOffset[1]]),a[0]+=e.type.snapToGridOffset[0],a[1]+=e.type.snapToGridOffset[1]),this.currentAction instanceof oe){const l=this.currentAction.delta;this.currentAction.delta=[a[0]-l[0],a[1]-l[1]],e.selected?this.userSelection.move([l[0]-e.coords[0],l[1]-e.coords[1]]):e.move(l)}else if(this.currentAction instanceof B){e.move(a);const n=this.model.nodes.getAtCoordinates(t.x,t.y).filter(o=>o.id!==e.id&&!o.isDescendantOf(e)).filter(o=>o.type.childrenTypes.includes(e.type.id)),i=_e(n),r=i[i.length-1];if(r!==e.parent&&(e.type.canBeParentless||r!==void 0)){const o=r?.getLastAncestor(),c=this.currentAction.from,d=new Ho(this,e.id,e.parent?.id,r?.id,c,e.getGeometry(),o?.id,o?.getGeometry(e.id),o?.getGeometry(e.id));e.parent?.removeChild(e),r!==void 0&&r.addChild(e),d.toChildGeometry=e.getGeometry(e.id),d.toAncestorGeometry=o?.getGeometry(e.id),this.currentAction=d}else{const o=e?.getLastAncestor();this.currentAction.ancestorId=o?.id,this.currentAction.fromAncestorGeometry=o?.getGeometry(e.id),e.parent?.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=o?.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}S(),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){const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(S(L.Crosshair),this.multipleSelectionContainer?.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x)?.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y)?.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k)?.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);this.multipleSelectionContainer?.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)oo([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 j(this.userSelection.all(),!0)),S()}};Xt.canvasCount=0;let fe=Xt;class Xe{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 a=1;;++a){const l=a%2>0?a:-a,n=l>0?1:-1,i=[e[0]+l,e[1]+l];for(let r=e[0];r!==i[0]+n;r+=n)if(e[0]=r,this.get(e)===void 0)return e;for(let r=e[1];r!==i[1]+n;r+=n)if(e[1]=r,this.get(e)===void 0)return e}}}class oi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Xe,a=t.nodes.filter(r=>!r.parent);for(;a.length>0;)We(a[0],e,[0,0],a);const l=Math.max(...t.nodes.map(r=>r.width)),n=Math.max(...t.nodes.map(r=>r.height)),i=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let r=e.minY();r<=e.maxY();++r)for(let o=e.minX();o<=e.maxX();++o){const c=e.get([o,r]);c!==void 0&&c.move([o*(l+i),r*(n+i)])}return t}}const We=(s,t,e,a)=>{const l=t.getClosestEmptyCoordinate(e);t.set(l,s),D(a,s);for(const n of s.getAdjacentNodes())a.includes(n)&&We(n,t,l,a)};class ii{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Xe,a=t.nodes.filter(d=>!d.parent),l={},n=a[0];let i=[n];for(l[n.id]=[0,0];a.length>0;){const d=[];for(const h of i){e.set(e.getClosestEmptyCoordinate(l[h.id]),h),D(a,h);const u=h.getAdjacentNodes();for(const y of u)a.includes(y)&&(d.push(y),l[y.id]=l[h.id])}if(d.length>0)i=d;else if(a.length>0){const h=a[0];i=[h],l[h.id]=e.getClosestEmptyCoordinate([0,0])}}const r=Math.max(...t.nodes.map(d=>d.width)),o=Math.max(...t.nodes.map(d=>d.height)),c=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let d=e.minY();d<=e.maxY();++d)for(let h=e.minX();h<=e.maxX();++h){const u=e.get([h,d]);u!==void 0&&u.move([h*(r+c),d*(o+c)])}return t}}class te{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;let a=t.nodes.filter(r=>!r.parent);const l=a[0];D(a,l);const n=[[l]];for(;a.length>0;){const r=n[n.length-1],o=[];for(const c of r){const d=c.getAdjacentNodes();for(const h of d)a.includes(h)&&(D(a,h),o.push(h))}o.length>0?n.push(o):(n.push(a),a=[])}let i=0;for(const r of n){let o=0;for(const d of r)d.move([i,o]),o+=e+d.height;const c=Math.max(...r.map(d=>d.width));i+=e+c}for(const r of t.connections)r.tighten();return t}}class si{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;new te(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=.99,l=1,n=.1,i=2e5,r=.5,o=1,c=.002;let d=100;for(;d>l;){d=d*a;const h=[0,0];{for(const u of t.nodes)h[0]=h[0]+u.coords[0]+u.width/2,h[1]=h[1]+u.coords[1]+u.width/2;h[0]=h[0]/t.nodes.length,h[1]=h[1]/t.nodes.length}for(const u of t.nodes){const y=u.getAdjacentNodes();for(const v of t.nodes){const m=[u.coords[0]+u.width/2,u.coords[1]+u.height/2],p=[v.coords[0]+v.width/2,v.coords[1]+v.height/2],k=Ne(u.coords,v.coords),b=[v.coords[0],v.coords[1]];if(y.includes(v)&&k>0&&(k>e+(Math.max(u.width,u.height)+Math.max(v.width,v.height))/2?(b[0]=b[0]-(p[0]-m[0])*n,b[1]=b[1]-(p[1]-m[1])*n):(b[0]=b[0]+(p[0]-m[0])*r,b[1]=b[1]+(p[1]-m[1])*r)),k>0){const N=i/(k*k);b[0]=b[0]+N*(p[0]-m[0])/k,b[1]=b[1]+N*(p[1]-m[1])/k}else b[0]=b[0]+o*(Math.random()*2-1),b[1]=b[1]+o*(Math.random()*2-1);b[0]=b[0]-(p[0]-h[0])*c,b[1]=b[1]-(p[1]-h[1])*c,b[0]-v.coords[0]>d?b[0]=v.coords[0]+d:b[0]-v.coords[0]<-d&&(b[0]=v.coords[0]-d),b[1]-v.coords[1]>d?b[1]=v.coords[1]+d:b[1]-v.coords[1]<-d&&(b[1]=v.coords[1]-d),v.move(b)}}}if(t.canvas&&t.canvas.snapToGrid)for(const h of t.nodes){const u=t.canvas.getClosestGridPoint([h.coords[0]-h.type.snapToGridOffset[0],h.coords[1]-h.type.snapToGridOffset[1]]);u[0]+=h.type.snapToGridOffset[0],u[1]+=h.type.snapToGridOffset[1],h.move(u)}for(const h of t.connections)h.tighten();return t}}class ni{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(n=>!n.parent);a.sort((n,i)=>i.type.priority-n.type.priority);let l=0;for(const n of a)n.move([l,0]),l+=n.width+e;return t}}class ri{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),a=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===a)return new te(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=t.nodes.filter(d=>!d.parent),i=[],r=t.nodes.filter(d=>!d.parent).filter(d=>d.getPriority()>=e),o=[];if(r.length>1){const d=r[0];r.splice(0,1),o.push(d);const h=[d],u=[d];for(;h.length>0;){const y=h[0];h.splice(0,1),r.includes(y)&&(o.push(y),D(r,y));const v=y.getAdjacentNodes();for(const m of v)u.includes(m)||(h.push(m),u.push(m))}for(const y of r)o.push(y)}else o.push(r[0]);for(const d of o)D(n,d),i.push([d]);for(i.push([]),n.sort((d,h)=>h.type.priority-d.type.priority);n.length>0;){const d=n[0];n.splice(0,1);const h=[d],u=[d];let y=!1;for(;h.length>0;){const v=h[0];h.splice(0,1);const m=o.indexOf(v);if(m>=0){i[m].push(d),y=!0;break}else{const p=v.getAdjacentNodes();for(const k of p)u.includes(k)||(h.push(k),u.push(k))}}y||i[i.length-1].push(d)}let c=0;for(let d=0;d<i.length;++d){let h=0;for(let y=0;y<i[d].length;++y){const v=i[d][y];v.move([c,h]),h+=l+v.height}const u=Math.max(...i[d].map(y=>y.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}class ai{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),a=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===a)return new te(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=t.nodes.filter(d=>!d.parent).sort((d,h)=>h.getPriority()-d.getPriority()),i=[];for(;n.length>0;){const d=n[0];n.splice(0,1);const h=new ve(void 0,d);Ze(h,n),i.push(h)}const r=[];for(const d of i)r.push([d]),Ke(d,r,r.length);const o=Math.max(...t.nodes.map(d=>d.height));let c=0;for(let d=0;d<r.length;++d){let h=0;for(let y=0;y<r[d].length;++y){const v=r[d][y];v.node.move([c,h]),h+=(l+o)*v.countBranchHeight()}const u=Math.max(...r[d].map(y=>y.node.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}const Ze=(s,t)=>{for(const e of s.node.getAdjacentNodes().sort((a,l)=>l.getPriority()-a.getPriority())){const a=t.indexOf(e);if(a>=0){t.splice(a,1);const l=s.addBranch(e);Ze(l,t)}}},Ke=(s,t,e)=>{if(s.branches.length>0){for(;e>=t.length;)t.push([]);for(const a of s.branches)t[e].push(a),Ke(a,t,e+1)}};class ve{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new ve(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 li{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(n=>!n.parent);a.sort((n,i)=>i.type.priority-n.type.priority);let l=0;for(const n of a)n.move([0,l]),l+=n.height+e;return t}}const Me={adjacency:new oi,breadth:new te,"breadth-adjacency":new ii,force:new si,horizontal:new ni,priority:new ri,tree:new ai,vertical:new li},ci=E.createContext({}),St=E.createContext({});class di{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 ye=({direction:s,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:a,disabled:l,rule:n,collapsedValue:i,visibleValue:r,onCollapse:o})=>{const[c,d]=E.useState(a),h=()=>{if(!l){const y=!c;d(y),o?.(y);let v;if(typeof t=="string")v=A.select(t),e&&(v=v.select(e));else{const m=t;if(!m)throw new Error("collapsableSelector is not a valid ref");v=A.select(m.current),e&&(v=v.select(e))}v.style(n,y?i:r)}},u=()=>{switch(s){case g.Right:return l?"daga-horizontal-none":c?"daga-horizontal-right":"daga-horizontal-left";case g.Bottom:return l?"daga-vertical-none":c?"daga-vertical-down":"daga-vertical-up";case g.Left:return l?"daga-horizontal-none":c?"daga-horizontal-left":"daga-horizontal-right";case g.Top:return l?"daga-vertical-none":c?"daga-vertical-up":"daga-vertical-down"}};return f.jsx("daga-collapse-button",{children:f.jsx("button",{className:`daga-collapse-button daga-${s}`,onClick:h,children:f.jsx("div",{className:u()})})})},hi=()=>{const s=E.useContext(St),t=E.useRef(null),[e,a]=E.useState([]);kt.merge(s.validatorChange$,s.diagramChange$).pipe(kt.map(()=>l())).subscribe();const l=()=>{a([]);for(const i of s.validators){const r=i.validate(s.model);a(r)}},n=i=>{if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const r=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);r&&s.userHighlight.add(r)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){s.userSelection.openInPropertyEditor(s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId));const r=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);r&&s.userHighlight.add(r),s.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(s.userSelection.openInPropertyEditor(),s.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames))};return f.jsx("daga-errors",{children:f.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&f.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:f.jsx("span",{children:"No errors found"})}),e.length>0&&f.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[f.jsxs("span",{children:[e.length," errors found"]}),f.jsx("div",{className:"daga-collapse-button-container",children:f.jsx(ye,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:g.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&f.jsx("div",{className:"daga-error-panel",children:f.jsx("ol",{children:e.map((i,r)=>f.jsx("li",{onClick:()=>n(i),dangerouslySetInnerHTML:{__html:i.message}},r))})})]})})},gi=200,Te=s=>(s||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),qe=({disabled:s,options:t,value:e,onChange:a})=>{const l=E.useRef(null),[n,i]=E.useState("");let r;const[o,c]=E.useState([]),[d,h]=E.useState([]),[u,y]=E.useState([]),[v,m]=E.useState([]),[p,k]=E.useState(!1);E.useEffect(()=>{i(t.find(I=>wt(I.key,e))?.label||"")},[e,t]);const b=I=>{if(!s)switch(I.key){case W.PageDown:r===void 0?(P(0),M(0)):(P(r+5),M(r)),I.preventDefault();break;case W.ArrowDown:r===void 0?(P(0),M(0)):(P(r+1),M(r)),I.preventDefault();break;case W.PageUp:r===void 0?(P(t.length-1),M(t.length-1)):(P(r-5),M(r)),I.preventDefault();break;case W.ArrowUp:r===void 0?(P(t.length-1),M(t.length-1)):(P(r-1),M(r)),I.preventDefault();break;case W.Escape:z(),I.preventDefault();break;case W.Enter:O(t[r||0]),I.preventDefault();break;default:N()}},N=()=>{if(!s){const I=Te(n.trim());c([]),h([]),y([]),m([]);for(const _ of t){const K=Te(_.label).indexOf(I);if(K>=0){const _t=_.label.substring(0,K),q=_.label.substring(K,K+I.length),bt=_.label.substring(K+I.length);c(st=>[...st,_]),h(st=>[...st,_t]),y(st=>[...st,q]),m(st=>[...st,bt])}}k(!0)}},z=()=>{k(!1)},P=I=>{if(!s){if(r=I,I===void 0)return;I<0&&(r=0),I>=t.length&&(r=t.length-1)}},Q=()=>{setTimeout(()=>{z()},gi)},M=I=>{const _=l.current?.querySelectorAll("li")[I];_&&_.scrollIntoView({block:"center"})},x=()=>{s||(i(""),k(!1),r=void 0)},O=I=>{s||(i(I.label),k(!1),r=void 0,a(I.key))};return f.jsxs("div",{ref:l,className:`daga-autocomplete ${p?"daga-showing-options":""}`,children:[f.jsxs("div",{className:"daga-autocomplete-input",children:[f.jsx("input",{value:n,disabled:s,onKeyUp:b,onFocus:N,onBlur:Q,onChange:I=>i(I.target.value)}),n!==""&&f.jsx("button",{className:"daga-clear",onClick:x})]}),f.jsx("div",{className:"daga-autocomplete-options",children:f.jsxs("ul",{className:"daga-autocomplete-option-list",children:[o.length===0&&f.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),o.map((I,_)=>f.jsxs("li",{className:`daga-autocomplete-option ${_===r?"daga-focused":""}`,onMouseMove:()=>P(_),onClick:()=>O(I),children:[f.jsx("span",{children:d[_]}),f.jsx("span",{className:"daga-match",children:u[_]}),f.jsx("span",{children:v[_]})]},_))]})})]})},fi=(s,t)=>s.find(e=>e.key===t)?.label||`${t}`,ui=({disabled:s,allowRepeats:t,options:e,value:a,onChange:l})=>{const[n,i]=E.useState(),[r,o]=E.useState([]),[c,d]=E.useState([]);E.useEffect(()=>{const p=a.length===0,k=a.map(b=>fi(e,b));o(k),p&&l(a),m()},[a,e]);const h=p=>{for(const k of a)if(k===p)return!0;return!1},u=p=>{a.length>p&&(a.splice(p,1),o(r.filter((k,b)=>b!==p)),l(a),m())},y=()=>{n!==void 0&&(t||!h(n))&&(l(a.concat(n)),v())},v=()=>{i("")},m=()=>{if(!t){const p=[];for(const k of e)h(k.key)||p.push(k);d(p)}};return f.jsxs("div",{children:[a.map((p,k)=>f.jsxs("div",{className:"daga-value-item-element",children:[f.jsx("span",{className:"daga-input",children:r[k]}),!s&&f.jsx("button",{className:"daga-property-button",onClick:()=>u(k),children:f.jsx("div",{className:"daga-icon daga-close-icon"})})]},k)),!s&&f.jsxs("div",{className:"daga-value-item-input",children:[f.jsx("div",{className:"daga-input daga-relatively-positioned",children:f.jsx(qe,{disabled:s,options:t?e||[]:c||[],value:n,onChange:i})}),f.jsx("button",{className:"daga-property-button",onClick:y,children:f.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},pi=({disabled:s,allowRepeats:t,value:e,onChange:a})=>{const[l,n]=E.useState(""),i=u=>{for(const y of u||[])if(y===u)return!0;return!1},r=u=>{e.length>u&&a(e.filter((y,v)=>v!==u))},o=(u,y,v)=>{const m=e.map((p,k)=>k===y?v==="blur"?u.trim():u:p);a(m)},c=()=>{const u=l.trim();u!==""&&(t||!i(u))&&(a(e.concat(u)),d())},d=()=>{n("")},h=u=>{u.key==="Enter"&&c()};return f.jsxs(f.Fragment,{children:[e.map((u,y)=>f.jsxs("div",{className:"daga-value-item-element",children:[f.jsx("input",{className:"daga-input",disabled:s,value:u,onChange:v=>o(v.target.value,y,"change"),onBlur:v=>o(v.target.value,y,"blur")}),f.jsx("button",{className:"daga-property-button",onClick:()=>r(y),children:f.jsx("div",{className:"daga-icon daga-close-icon"})})]},y)),!s&&f.jsxs("div",{className:"daga-value-item-input",children:[f.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[f.jsx("input",{type:"text",onKeyUp:h,value:l,onChange:u=>n(u.target.value)}),f.jsx("button",{className:"daga-clear",onClick:d})]}),f.jsx("button",{className:"daga-property-button",onClick:c,children:f.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},mi=({disabled:s,value:t,onChange:e})=>{const[a,l]=E.useState(""),[n,i]=E.useState(""),[r,o]=E.useState({}),c=p=>{const k={};Object.keys(t).forEach(b=>{b!==p&&(k[b]=t[b])}),e(k)},d=(p,k,b)=>{const N=b==="blur"?k.trim():k;if(b==="blur"){if(p!==N){const z={};Object.keys(t).forEach(P=>{P===p?z[N]=t[P]:z[P]=t[P]}),e(z),o(P=>{const Q={...P};return delete Q[p],Q})}}else o(z=>({...z,[p]:k}))},h=(p,k,b)=>{const N=b==="blur"?k.trim():k;if(N!==""){const z={};Object.keys(t).forEach(P=>{P===p?z[P]=N:z[P]=t[P]}),e(z)}},u=()=>{const p=a.trim(),k=n.trim();if(p!==""&&k!==""){const b={};Object.keys(t).forEach(N=>{b[N]=t[N]}),b[p]=k,e(b),l(""),i("")}},y=()=>{l("")},v=()=>{i("")},m=p=>{p.key==="Enter"&&u()};return f.jsxs("div",{children:[Object.entries(t).map(([p,k],b)=>f.jsxs("div",{className:"daga-value-item-element",children:[f.jsx("input",{id:`key-${b}`,className:"daga-input",type:"text",disabled:s,value:r[p]??p,onChange:N=>d(p,N.target.value,"change"),onBlur:N=>d(p,N.target.value,"blur")}),f.jsx("input",{id:`value-${b}`,className:"daga-input",type:"text",disabled:s,value:k,onChange:N=>h(p,N.target.value,"change"),onBlur:N=>h(p,N.target.value,"blur")}),f.jsx("button",{className:"daga-property-button",onClick:()=>c(p),children:f.jsx("div",{className:"daga-icon daga-close-icon"})})]},p)),!s&&f.jsxs("div",{className:"daga-value-item-input",children:[f.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[f.jsx("input",{type:"text",value:a,onKeyUp:m,onChange:p=>l(p.target.value),onBlur:p=>d(a,p.target.value,"blur")}),f.jsx("button",{className:"daga-clear",onClick:y})]}),f.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[f.jsx("input",{type:"text",value:n,onKeyUp:m,onChange:p=>i(p.target.value),onBlur:p=>h(a,p.target.value,"blur")}),f.jsx("button",{className:"daga-clear",onClick:v})]}),f.jsx("button",{className:"daga-property-button",onClick:u,children:f.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Je=({valueSet:s,onValueChange:t,depth:e})=>{const l=E.useContext(St).canUserPerformAction(w.UpdateValues)&&s?.rootElement?.removed!==!0,n=o=>"daga-property-name-"+o.replace(/\s/g,""),i=o=>{if(typeof o=="string")return o;if(o==null||isNaN(o.valueOf()))return"";const c=new Date(o),d=c.getTimezoneOffset();return c.setMinutes(c.getMinutes()-d),c.toISOString().substring(0,19)},r=o=>new Date(o);return f.jsx("daga-object-editor",{children:s.displayedProperties.map(o=>f.jsxs("div",{className:`daga-property ${n(o.name)}`,children:[f.jsx("p",{className:"daga-property-name",children:o.label||o.name}),o.type===T.Text&&f.jsx("input",{type:"daga-text",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.TextArea&&f.jsx("textarea",{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Number&&f.jsx("input",{type:"number",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Color&&f.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Datetime&&f.jsx("input",{type:"datetime-local",disabled:o.editable===!1||!l,value:i(s?.getValue(o.name)),onChange:c=>t(s,o,r(c.target.value))}),o.type===T.Date&&f.jsx("input",{type:"date",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Time&&f.jsx("input",{type:"time",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Url&&f.jsx("input",{type:"url",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Boolean&&f.jsxs("div",{className:"daga-radio",children:[f.jsxs("label",{className:"daga-radio-item daga-radio-start"+(s?.getValue(o.name)===!1?" daga-checked":""),children:[f.jsx("input",{type:"radio",disabled:o.editable===!1||!l,name:o.name,value:"false",checked:s?.getValue(o.name)===!1,onChange:()=>t(s,o,!1)}),"No"]}),f.jsxs("label",{className:"daga-radio-item daga-radio-end"+(s?.getValue(o.name)===!0?" daga-checked":""),children:[f.jsx("input",{type:"radio",disabled:o.editable===!1||!l,name:o.name,value:"true",checked:s?.getValue(o.name)===!0,onChange:()=>t(s,o,!0)}),"Yes"]})]}),o.type===T.Option&&f.jsx("div",{className:"daga-relatively-positioned",children:f.jsx(qe,{disabled:o.editable===!1||!l,options:o.options||[],value:s?.getValue(o.name),onChange:c=>t(s,o,c)})}),(o.type===T.OptionList||o.type===T.OptionSet)&&f.jsx(ui,{disabled:o.editable===!1||!l,allowRepeats:o.type===T.OptionList,options:o.options||[],value:s?.getValue(o.name),onChange:c=>t(s,o,c)}),(o.type===T.TextList||o.type===T.TextSet)&&f.jsx(pi,{disabled:o.editable===!1||!l,allowRepeats:o.type===T.TextList,value:s?.getValue(o.name),onChange:c=>t(s,o,c)}),o.type===T.TextMap&&f.jsx(mi,{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c)}),o.type===T.Object&&f.jsx("div",{className:"daga-left-bar",children:f.jsx(Je,{valueSet:s.getSubValueSet(o.name),onValueChange:t,depth:e+1})})]},o.name))})},Qe=({valueSet:s,depth:t})=>{const e=E.useContext(St),a=E.useRef(null),l=o=>"daga-property-name-"+o.replace(/\s/g,""),n=()=>{for(const o of s?.displayedProperties||[]){let c=0,d=0,h=0;const u=A.select(a.current).select(`.daga-property.${l(o.name)}.daga-depth-${t}`);u.select("button.daga-move-button").call(A.drag().on($.Start,y=>{S(L.Grabbing);const v=e.getPointerLocationRelativeToScreen(y);if(v.length<2||isNaN(v[0])||isNaN(v[1]))return;const m=u.node()?.getBoundingClientRect();c=m?.width||0,d=m?.height||0,u.style("position","fixed").style("left",`${v[0]-c/2}px`).style("top",`${v[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1)}).on($.Drag,y=>{S(L.Grabbing);const v=e.getPointerLocationRelativeToScreen(y);v.length<2||isNaN(v[0])||isNaN(v[1])||(u.style("position","fixed").style("left",`${v[0]-c/2}px`).style("top",`${v[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0),h=i(v),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on($.End,y=>{S(L.Auto),u.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const v=e.getPointerLocationRelativeToScreen(y);v.length<2||isNaN(v[0])||isNaN(v[1])||(h=i(v),s?.displayedProperties?.splice(s.displayedProperties.indexOf(o),1),s?.displayedProperties?.splice(h,0,o))}))}},i=o=>{const c=s?.propertySet.propertyList||[],d=[];for(let h=0;h<=c.length;++h){const u=A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).node()?.getBoundingClientRect();u&&d.push([u.x+u.width/2,u.y+u.height/2])}if(d.length>0){const h=d.map(y=>((o[0]-y[0])**2+(o[1]-y[1])**2)**.5);return h.indexOf(Math.min(...h))}return 0},r=o=>{if(s===void 0)return;let c;o instanceof bo?c=o:o instanceof Event?c=s?.propertySet.getProperty(o.target?.value||""):c=s?.propertySet.getProperty(o||""),c&&s?.hideProperty(c),n()};return f.jsxs("daga-property-settings",{ref:a,children:[f.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),s?.displayedProperties.map((o,c)=>f.jsxs("div",{className:`daga-property-and-dropbar ${l(o.name)} daga-depth-${t}`,children:[f.jsxs("div",{className:`daga-property ${l(o.name)} daga-depth-${t}`,children:[f.jsxs("div",{className:"daga-property-name",children:[f.jsx("span",{children:o.label||o.name}),f.jsxs("div",{className:"daga-buttons",children:[f.jsx("button",{className:"daga-property-button daga-move-button",children:f.jsx("div",{className:"daga-icon daga-move-icon"})}),f.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>r(o.name),children:f.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),o.type!==T.Object&&f.jsx("div",{className:"daga-property-value",children:vi(s?.getValue(o.name))}),o.type===T.Object&&f.jsx(Qe,{valueSet:s?.getSubValueSet(o.name),depth:t+1})]}),f.jsx("div",{className:`daga-dropbar daga-index-${c+1} daga-depth-${t}`})]},o.name))]})},vi=s=>Array.isArray(s)?s.join(", "):ko(s)?Object.entries(s).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):s instanceof Date?s.toLocaleString():s==null?"":""+s,yi=({location:s,direction:t,width:e,height:a,title:l,valueSet:n,onValueChange:i})=>{const r=E.useRef(null),[o,c]=E.useState(!1),[d,h]=E.useState(!1),u=()=>A.select(r.current);return E.useEffect(()=>{if(r.current)switch(t){case g.Bottom:case g.Top:u().style("width",e),a&&u().select(".daga-panel-content").style("height",a);break;case g.Left:case g.Right:u().style("height",e),a&&u().select(".daga-panel-content").style("width",a);break}},[e,t]),f.jsx("daga-property-editor",{children:f.jsxs("div",{ref:r,className:`daga-panel daga-bottom daga-${s} daga-${t}`,children:[f.jsx(ye,{disabled:!n||!n.propertySet||!n.propertySet.hasProperties(),collapsed:o,direction:t,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:c}),f.jsx("div",{className:"daga-panel-content",children:n&&n.propertySet&&n.propertySet.hasProperties()&&!o&&f.jsxs("div",{children:[l&&f.jsxs("p",{className:"daga-title",children:[l,f.jsx("button",{className:"daga-property-button",onClick:()=>h(!d),children:f.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&f.jsx(Je,{valueSet:n,onValueChange:i,depth:0}),d&&f.jsx(Qe,{valueSet:n,depth:0})]})})]})})},bi=6,ki=s=>{const t=E.useContext(St),[e,a]=E.useState(s.currentPalette||s.palettes[0]),[l,n]=E.useState(0),[i,r]=E.useState(void 0),o=E.useRef(null),c=m=>{if(a(m),d().selectAll("*").remove(),n(t.getPriorityThreshold()||0),m.categories&&h(m.categories),m.templates)for(const p of m.templates)u(p)},d=()=>A.select(o.current).select(".daga-palette-view"),h=m=>{const p=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");p.append("option").attr("value","").text("(None selected)");for(const k in m)p.append("option").attr("value",k).text(k);p.on(C.Change,()=>{i&&d().selectAll(".daga-template-container.daga-in-category").remove();const k=p.property("value");r(k);const b=m[k]||[];for(const N of b)u(N,"daga-in-category")}),i&&(p.property("value",i),p.dispatch(C.Change))},u=(m,p)=>{if(m.templateType==="node"){const k=t.model.nodes.types.get(m.type);k?y(k,m,p):console.error(`Could not find a node type called '${m.type}'`)}else if(m.templateType==="connection"){const k=t.model.connections.types.get(m.type);k?v(k,m,p):console.error(`Could not find a connection type called '${m.type}'`)}},y=(m,p,k)=>{if(l!==void 0&&m.priority<l)return;const b=m.defaultLook.lookType==="shaped-look"?m.defaultLook.borderThickness||1:0,N=m.defaultHeight+b,z=m.defaultWidth+b,P=p.height||N,Q=p.width||z,M=d().append("div").attr("class",`daga-template-container ${k!==void 0?k:""}`).style("width",`${Q}px`).style("height",`${P}px`).call(A.drag().on($.Drag,O=>{if(t.canUserPerformAction(w.AddNode)){const I=t.getPointerLocationRelativeToScreen(O);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;M.style("position","fixed").style("left",`${I[0]-Q/2}px`).style("top",`${I[1]-P/2}px`).style("z-index",1)}}).on($.Start,O=>{if(t.canUserPerformAction(w.AddNode)){S(L.Grabbing);const I=t.getPointerLocationRelativeToScreen(O);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;M.style("position","fixed").style("left",`${I[0]-Q/2}px`).style("top",`${I[1]-P/2}px`).style("z-index",1),m.isUnique&&t.model.nodes.find(_=>!_.removed&&_.type.id===m.id)!==void 0&&S(L.NotAllowed)}}).on($.End,O=>{if(t.canUserPerformAction(w.AddNode)){if(S(L.Auto),M.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),m.isUnique&&t.model.nodes.find(Gt=>!Gt.removed&&Gt.type.id===m.id)!==void 0)return;const I=t.getPointerLocationRelativeToScreen(O);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;const _=document.elementFromPoint(I[0],I[1]);if(_&&!t.selectCanvasView().node()?.contains(_))return;const rt=t.getPointerLocationRelativeToCanvas(O);if(rt.length<2||isNaN(rt[0])||isNaN(rt[1]))return;let K=[rt[0]-m.defaultWidth/2,rt[1]-m.defaultHeight/2];t.snapToGrid&&(K=t.getClosestGridPoint([K[0]-m.snapToGridOffset[0],K[1]-m.snapToGridOffset[1]]),K[0]+=m.snapToGridOffset[0],K[1]+=m.snapToGridOffset[1]);const q=t.model.nodes.getAtCoordinates(rt[0],rt[1]).filter(Gt=>Gt.type.childrenTypes.includes(m.id)),bt=_e(q),st=bt[bt.length-1];if(!m.canBeParentless&&st===void 0)return;const jt=st?.getLastAncestor(),be=new Oo(t,m,K,st?.id,jt?.id,jt?.getGeometry(),void 0,p.label,p.values);be.do(),t?.actionStack.add(be),S()}})).append("svg").attr("class",`palette-node ${m.id}`).attr("viewBox",`0 0 ${z} ${N}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${Q}px`).style("height",`${P}px`),x=p.look||m.defaultLook;switch(x.lookType){case"shaped-look":M.append("path").attr("d",he(x.shape||Et.Rectangle,(x.borderThickness||1)/2,(x.borderThickness||1)/2,m.defaultWidth,m.defaultHeight)).attr("fill",x.fillColor||"#FFFFFF").attr("stroke",x.borderColor||"#000000").attr("stroke-width",`${x.borderThickness}px`);break;case"image-look":M.append("image").attr("x",0).attr("y",0).attr("width",m.defaultWidth).attr("height",m.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",m.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTop).attr("preserveAspectRatio","none"),M.append("image").attr("x",m.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",m.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",m.defaultWidth-x.rightMargin-x.leftMargin).attr("height",m.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageCenter).attr("preserveAspectRatio","none"),M.append("image").attr("x",m.defaultWidth-x.rightMargin).attr("y",x.topMargin).attr("width",x.rightMargin).attr("height",m.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",m.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",m.defaultHeight-x.bottomMargin).attr("width",m.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottom).attr("preserveAspectRatio","none"),M.append("image").attr("x",m.defaultWidth-x.rightMargin).attr("y",m.defaultHeight-x.bottomMargin).attr("width",x.rightMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(p.look===void 0){if(m.decorators)for(const O of m.decorators)M.append("foreignObject").attr("width",`${O.width}px`).attr("height",`${O.height}px`).attr("transform",`translate(${O.coords[0]},${O.coords[1]})`).html(O.html);if(p.label){const O={...V,...m.label,...p.labelLook};M.append("text").attr("transform",`translate(${(U(O)+m.defaultWidth)/2},${(G(O)+m.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${O.fontSize}px`).attr("text-anchor","middle").attr("font-family",O.fontFamily).attr("font-weight",400).attr("fill",O.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(p.label)}}},v=(m,p,k)=>{const b=d().append("div").attr("class",`daga-template-container ${k!==void 0?k:""}`).style("width",`${p.width}px`).style("height",`${p.height}px`).append("svg").attr("class",`palette-button ${m.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=m});b.append("path").attr("d",he(Et.Rectangle,0,0,p.width,p.height)).attr("fill",p.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),p.icon!==""&&b.append("image").attr("x",0).attr("y",0).attr("width",p.width).attr("height",p.height).attr("href",p.icon),p.label!==""&&b.append("text").attr("transform",`translate(${p.width/2},${p.height/2+bi})`).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(p.label)};return E.useEffect(()=>{if(c(s.palettes[0]),o.current)switch(s.direction){case g.Bottom:case g.Top:o.current.style.width=s.width,s.height&&(o.current.style.height=s.height);break;case g.Left:case g.Right:o.current.style.height=s.width,s.height&&(o.current.style.width=s.height);break}},[e,s.palettes]),f.jsx("daga-palette",{children:f.jsxs("div",{ref:o,className:`daga-panel daga-${s.location} daga-${s.direction}`,children:[f.jsx(ye,{direction:s.direction,collapsableSelector:o,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),f.jsxs("div",{className:"daga-panel-content",children:[s.palettes.length>1&&f.jsx("div",{className:"daga-panel-tabs",children:s.palettes.map(m=>f.jsx("div",{className:`daga-panel-tab ${m===e?"daga-current-tab":""}`,onClick:()=>c(m),children:m.name}))}),f.jsx("div",{className:"daga-palette-view"})]})]})})},wi=({location:s,direction:t,enableAction:e,enableFilter:a,enableLayout:l,enableSelection:n,enableZoom:i})=>{let r=!1,o=!0,c=!1,d,h,u,y;switch(t){case g.Bottom:d="height",h="scaleY",u="top",y="bottom";break;case g.Top:d="height",h="scaleY",u="bottom",y="top";break;case g.Left:d="width",h="scaleX",u="right",y="left";break;case g.Right:d="width",h="scaleX",u="left",y="right";break}const v=E.useRef(null),m=E.useRef(null),p=E.useRef(null);E.useEffect(()=>{A.select(v.current).style(`margin-${y}`,"-1rem").style(d,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const k=async()=>{const q=A.select(v.current);if(!c)if(o){o=!1;const jt=`${4*q.selectChildren().size()}rem`;q.transition().duration(500).ease(A.easeLinear).style(d,jt).style("transform",`${h}(1)`),setTimeout(()=>{c=!1},500)}else o=!0,q.transition().duration(500).ease(A.easeLinear).style(d,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{c=!1},500)},b=E.useContext(St),N=()=>{b.zoomBy(b.zoomFactor)},z=()=>{b.zoomBy(1/b.zoomFactor)},P=()=>{b.center()},Q=()=>{b.layoutFormat&&b.layoutFormat in Me&&Me[b.layoutFormat].apply(b.model)},M=()=>{r=!r,A.select(p.current).classed("daga-on",r).classed("daga-off",!r);const q=b.getPriorityThresholdOptions();q&&q.length>=2&&b.setPriorityThreshold(q[r?1:0])},x=()=>{b.actionStack.undo()},O=()=>{b.actionStack.redo()},I=()=>{b.userSelection.copyToClipboard()},_=()=>{b.userSelection.cutToClipboard()},rt=()=>{b.userSelection.pasteFromClipboard()},K=()=>{b.userSelection.removeFromModel()},_t=()=>{b.multipleSelectionOn=!0,A.select(m.current).classed("daga-on",!0).classed("daga-off",!1);const q=b.diagramEvent$.subscribe(bt=>{bt.type===Ue.Selection&&(A.select(m.current).classed("daga-on",!1).classed("daga-off",!0),q.unsubscribe())})};return f.jsx("daga-diagram-buttons",{children:f.jsxs("div",{className:`daga-diagram-buttons daga-${s} daga-${t}`,children:[i&&b.canUserPerformAction(w.Zoom)&&f.jsx("button",{className:"daga-zoom-in",onClick:N,children:f.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&b.canUserPerformAction(w.Zoom)&&f.jsx("button",{className:"daga-zoom-out",onClick:z,children:f.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),f.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:v,children:[i&&b.canUserPerformAction(w.Zoom)&&f.jsx("button",{className:"daga-center",onClick:P,children:f.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&f.jsx("button",{className:"daga-undo",onClick:x,children:f.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&f.jsx("button",{className:"daga-redo",onClick:O,children:f.jsx("span",{className:"daga-tooltip",children:"Redo"})}),n&&f.jsx("button",{className:"daga-copy",onClick:I,children:f.jsx("span",{className:"daga-tooltip",children:"Copy"})}),n&&f.jsx("button",{className:"daga-cut",onClick:_,children:f.jsx("span",{className:"daga-tooltip",children:"Cut"})}),n&&f.jsx("button",{className:`daga-multiple-selection ${r?"daga-on":"daga-off"}`,onClick:_t,ref:m,children:f.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),n&&f.jsx("button",{className:"daga-paste",onClick:rt,children:f.jsx("span",{className:"daga-tooltip",children:"Paste"})}),n&&f.jsx("button",{className:"daga-delete",onClick:K,children:f.jsx("span",{className:"daga-tooltip",children:"Delete"})}),l&&b.layoutFormat&&f.jsx("button",{className:"daga-layout",onClick:Q,children:f.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),a&&f.jsx("button",{className:`daga-filter ${r?"daga-on":"daga-off"}`,onClick:M,ref:p,children:f.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),f.jsx("button",{className:"daga-more-options",onClick:k,children:o?f.jsx("span",{className:"daga-tooltip",children:"More options"}):f.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Si=({config:s,model:t,onCanvasCreated:e,onDiagramEvent:a,onModelChange:l})=>{const n=new Fe,i=new Ye,r=E.useRef(null),o=E.useRef(void 0),c=E.useRef(!1),d=[],[h,u]=E.useState(void 0),[y,v]=E.useState(void 0),m={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},p={refreshPalette:()=>{}},k=new di(M=>u(M),M=>v(M)),b={diagramButtons:m,palette:p,propertyEditor:k},N=(M=!1)=>((!o.current||M)&&(d.forEach(x=>x.unsubscribe()),o.current=new fe(b,s)),o.current),z=N(),P=M=>{z.initView(M),d.push(z.diagramEvent$.subscribe(x=>{a?.(x)})),d.push(z.diagramChange$.subscribe(()=>{const x=i.export(z.model);l?.(x)}))};E.useEffect(()=>{r.current&&(c.current||(P(r.current),c.current=!0,e?.(z)))},[r.current]),E.useMemo(()=>{r.current&&(N(!0),P(r.current),e?.(z))},[s]),E.useEffect(()=>{t&&n.import(z.model,t)},[t]);const Q=(M,x,O)=>{if(y!==void 0&&x.editable!==!1&&!wt(M.getValue(x.name),O)){M.setValue(x.name,O);const I=new mt(y.propertySet,void 0);I.setValues(y.getValues()),I.rootElement=y.rootElement,k.valueSet=I,y.rootElement.valueSet=I,z.propertyEditorChanges$?.next()}};return f.jsx("daga-diagram",{children:f.jsx(ci.Provider,{value:s,children:f.jsx(St.Provider,{value:z,children:f.jsxs("daga-diagram-editor",{children:[f.jsx("div",{className:"daga-append-to",ref:r}),f.jsxs(St.Provider,{value:z,children:[s.components?.buttons!==void 0&&s.components?.buttons?.enabled!==!1&&f.jsx(wi,{location:s.components?.buttons?.location||Ut.BottomRight,direction:s.components?.buttons?.direction||g.Top,enableAction:s.components?.buttons?.enableAction!==!1,enableFilter:s.components?.buttons?.enableFilter===!0,enableLayout:s.components?.buttons?.enableLayout===!0,enableSelection:s.components?.buttons?.enableSelection!==!1,enableZoom:s.components?.buttons?.enableZoom!==!1}),s.components?.palette!==void 0&&s.components?.palette?.enabled!==!1&&s.components?.palette?.sections&&(s.components?.palette?.sections?.length||0)>0&&f.jsx(ki,{location:s.components?.palette?.location||Ut.TopLeft,direction:s.components?.palette?.direction||g.Bottom,width:s.components?.palette?.width||"12rem",height:s.components?.palette?.height,palettes:s.components?.palette?.sections||[]}),s.components?.propertyEditor!==void 0&&s.components?.propertyEditor?.enabled!==!1&&f.jsx(yi,{location:s.components?.propertyEditor?.location||Ut.TopRight,direction:s.components?.propertyEditor?.direction||g.Bottom,width:s.components?.propertyEditor?.width||"24rem",height:s.components?.propertyEditor?.height,title:h,valueSet:y,onValueChange:Q}),s.components?.errors!==void 0&&s.components?.errors?.enabled!==!1&&f.jsx(hi,{})]})]})})})})};exports.DagaDiagram=Si;