UNPKG

@metadev/daga-react

Version:

![Daga banner](https://metadev.pro/content/daga/daga-banner.png)

2 lines 202 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),zi=require("d3"),It=require("rxjs"),z=require("react");function Ri(i){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const e in i)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>i[e]})}}return t.default=i,Object.freeze(t)}const N=Ri(zi);var k=(i=>(i.Bottom="bottom",i.Left="left",i.Right="right",i.Top="top",i))(k||{}),Ft=(i=>(i.BottomLeft="bottom-left",i.BottomRight="bottom-right",i.TopLeft="top-left",i.TopRight="top-right",i))(Ft||{}),Mt=(i=>(i.Left="left",i.Center="center",i.Right="right",i))(Mt||{}),Yt=(i=>(i.Top="top",i.Center="center",i.Bottom="bottom",i))(Yt||{});const Tt=i=>[Math.round(i[0]),Math.round(i[1])],vt=(i,t,e)=>t<e?t<=i&&i<=e:e<=i&&i<=t,Je=(i,t,e)=>(i-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Xt=(i,t,e,o,a,l,s)=>{const n=(()=>{switch(l){case"start":return o[0]+(i[0]-t[0]);case"end":return o[1]-(t[1]-i[0]);case"middle":{const c=(t[0]+t[1])/2,d=(o[0]+o[1])/2,h=t[1]-t[0],u=o[1]-o[0],p=(i[0]-c)/h;return d+p*u}case"floating":default:return Je(i[0],t,o)}})(),r=(()=>{switch(s){case"start":return a[0]+(i[1]-e[0]);case"end":return a[1]-(e[1]-i[1]);case"middle":{const c=(e[0]+e[1])/2,d=(a[0]+a[1])/2,h=e[1]-e[0],u=a[1]-a[0],p=(i[1]-c)/h;return d+p*u}case"floating":default:return Je(i[1],e,a)}})();return[n,r]},hi=(i,t)=>((i[0]-t[0])**2+(i[1]-t[1])**2)**.5,Vi=(i,t)=>(vt(i[0][0],t[0][0],t[1][0])||vt(i[1][0],t[1][0],t[0][0])||vt(t[0][0],i[0][0],i[1][0])||vt(t[1][0],i[1][0],i[0][0]))&&(vt(i[0][1],t[0][1],t[1][1])||vt(i[1][1],t[1][1],t[0][1])||vt(t[0][1],i[0][1],i[1][1])||vt(t[1][1],i[1][1],i[0][1]));var E=(i=>(i.Blur="blur",i.Change="change",i.Click="click",i.ContextMenu="contextmenu",i.DoubleClick="dblclick",i.Focus="focus",i.FocusIn="focusin",i.FocusOut="focusout",i.Input="input",i.KeyDown="keydown",i.KeyUp="keyup",i.MouseDown="mousedown",i.MouseEnter="mouseenter",i.MouseLeave="mouseleave",i.MouseMove="mousemove",i.MouseOut="mouseout",i.MouseOver="mouseover",i.MouseUp="mouseup",i.TouchStart="touchstart",i.TouchEnd="touchend",i.Wheel="wheel",i))(E||{}),et=(i=>(i.Alt="Alt",i.AltGraph="AltGraph",i.ArrowDown="ArrowDown",i.ArrowLeft="ArrowLeft",i.ArrowRight="ArrowRight",i.ArrowUp="ArrowUp",i.Backspace="Backspace",i.Control="Control",i.Delete="Delete",i.End="End",i.Enter="Enter",i.Escape="Escape",i.Home="Home",i.OS="OS",i.PageDown="PageDown",i.PageUp="PageUp",i.Shift="Shift",i.Tab="Tab",i))(et||{}),M=(i=>(i.Drag="drag",i.Start="start",i.End="end",i))(M||{}),he=(i=>(i.Zoom="zoom",i.Start="start",i.End="end",i))(he||{});const ge=i=>i.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var gi=(i=>(i.Straight="straight",i.Bezier="bezier",i.Square="square",i))(gi||{}),ui=(i=>(i.Solid="solid",i.Dashed="dashed",i.GappedDashes="gapped-dashes",i.Dotted="dotted",i))(ui||{});const _i=20,ji=(i,t,e,o,a)=>{if(typeof i=="function")return i(t,e,o,a);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{a=a||_i;let l="",s,n;switch(i){case"straight":l+=`M ${t[0][0]} ${t[0][1]}`;for(let r=1;r<t.length;++r)l+=` L ${t[r][0]} ${t[r][1]}`;break;case"bezier":s=e,l+=`M ${t[0][0]} ${t[0][1]}`;for(let r=1;r<t.length;++r){if(r+1>=t.length?n=o:Math.abs(t[r][0]-t[r-1][0])<Math.abs(t[r][1]-t[r-1][1])?t[r][1]>t[r-1][1]?n=k.Bottom:n=k.Top:t[r][0]>t[r-1][0]?n=k.Right:n=k.Left,s!==void 0){let c="",d="";const h=(Math.abs(t[r][0]-t[r-1][0])+Math.abs(t[r][1]-t[r-1][1]))/2;switch(s){case k.Bottom:c=`${t[r-1][0]} ${t[r-1][1]+h}`;break;case k.Top:c=`${t[r-1][0]} ${t[r-1][1]-h}`;break;case k.Right:c=`${t[r-1][0]+h} ${t[r-1][1]}`;break;case k.Left:c=`${t[r-1][0]-h} ${t[r-1][1]}`;break}if(n!==void 0){switch(n){case k.Bottom:d=`${t[r][0]} ${t[r][1]+h}`;break;case k.Top:d=`${t[r][0]} ${t[r][1]-h}`;break;case k.Right:d=`${t[r][0]+h} ${t[r][1]}`;break;case k.Left:d=`${t[r][0]-h} ${t[r][1]}`;break}l+=` C ${c} ${d} ${t[r][0]} ${t[r][1]}`}else l+=` Q ${c} ${t[r][0]} ${t[r][1]}`}else if(n!==void 0){let c="";const d=(Math.abs(t[r][0]-t[r-1][0])+Math.abs(t[r][1]-t[r-1][1]))/2;switch(n){case k.Bottom:c=`${t[r][0]} ${t[r][1]+d}`;break;case k.Top:c=`${t[r][0]} ${t[r][1]-d}`;break;case k.Right:c=`${t[r][0]+d} ${t[r][1]}`;break;case k.Left:c=`${t[r][0]-d} ${t[r][1]}`;break}l+=` Q ${c} ${t[r][0]} ${t[r][1]}`}else l+=` L ${t[r][0]} ${t[r][1]}`;s=n}break;case"square":if(l+=`M ${t[0][0]} ${t[0][1]}`,e)switch(e){case k.Bottom:t.splice(1,0,[t[0][0],t[0][1]+a]);break;case k.Top:t.splice(1,0,[t[0][0],t[0][1]-a]);break;case k.Right:t.splice(1,0,[t[0][0]+a,t[0][1]]);break;case k.Left:t.splice(1,0,[t[0][0]-a,t[0][1]]);break}if(o)switch(o){case k.Bottom:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]+a]);break;case k.Top:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]-a]);break;case k.Right:t.splice(t.length-1,0,[t[t.length-1][0]+a,t[t.length-1][1]]);break;case k.Left:t.splice(t.length-1,0,[t[t.length-1][0]-a,t[t.length-1][1]]);break}for(let r=1;r<t.length;++r)if(s!==void 0)switch(s){case k.Bottom:t[r][1]<t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`,s=k.Top):t[r][1]<t[r-1][1]&&t[r][0]===t[r-1][0]?(l+=` H ${t[r][0]+a}`,l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`,s=k.Left):t[r][1]===t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,s=t[r][0]>t[r-1][0]?k.Right:k.Left):t[r][1]>t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`):t[r][1]>t[r-1][1]&&t[r][0]===t[r-1][0]&&(l+=` V ${t[r][1]}`);break;case k.Top:t[r][1]>t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`,s=k.Bottom):t[r][1]>t[r-1][1]&&t[r][0]===t[r-1][0]?(l+=` H ${t[r][0]-a}`,l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`,s=k.Right):t[r][1]===t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,s=t[r][0]>t[r-1][0]?k.Right:k.Left):t[r][1]<t[r-1][1]&&t[r][0]!==t[r-1][0]?(l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`):t[r][1]<t[r-1][1]&&t[r][0]===t[r-1][0]&&(l+=` V ${t[r][1]}`);break;case k.Right:t[r][0]<t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`,s=k.Left):t[r][0]<t[r-1][0]&&t[r][1]===t[r-1][1]?(l+=` V ${t[r][1]+a}`,l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`,s=k.Top):t[r][0]===t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,s=t[r][1]>t[r-1][1]?k.Bottom:k.Top):t[r][0]>t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`):t[r][0]>t[r-1][0]&&t[r][1]===t[r-1][1]&&(l+=` H ${t[r][0]}`);break;case k.Left:t[r][0]>t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`,s=k.Right):t[r][0]>t[r-1][0]&&t[r][1]===t[r-1][1]?(l+=` V ${t[r][1]-a}`,l+=` H ${t[r][0]}`,l+=` V ${t[r][1]}`,s=k.Bottom):t[r][0]===t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,s=t[r][1]>t[r-1][1]?k.Bottom:k.Top):t[r][0]<t[r-1][0]&&t[r][1]!==t[r-1][1]?(l+=` V ${t[r][1]}`,l+=` H ${t[r][0]}`):t[r][0]<t[r-1][0]&&t[r][1]===t[r-1][1]&&(l+=` H ${t[r][0]}`);break}else t[r][0]!==t[r-1][0]&&(l+=` H ${t[r][0]}`,s=t[r][0]>t[r-1][0]?k.Right:k.Left),t[r][1]!==t[r-1][1]&&(l+=` V ${t[r][1]}`,s=t[r][1]>t[r-1][1]?k.Bottom:k.Top);break}return l}},Qe=(i,t)=>{switch(i){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},Z=(i,t)=>{const e=i.indexOf(t);return e>=0&&i.splice(e,1),i};var Zt=(i=>(i.Ellipse="ellipse",i.Empty="empty",i.Folder="folder",i.Hexagon="hexagon",i.Octagon="octagon",i.Pill="pill",i.Rectangle="rectangle",i.Rhombus="rhombus",i.RoundedRectangle="rounded-rectangle",i.StickyNote="sticky-note",i))(Zt||{});const ue=(i,t,e,o,a)=>{if(typeof i=="function")return i(t,e,o,a);switch(i){case"ellipse":return mi(t,e,o,a);case"empty":return Oi();case"folder":return Di(t,e,o,a);case"hexagon":return Hi(t,e,o,a);case"octagon":return Gi(t,e,o,a);case"pill":return Ut(t,e,o,a);case"rectangle":return ti(t,e,o,a);case"rhombus":return Bi(t,e,o,a);case"rounded-rectangle":return Fi(t,e,o,a);case"sticky-note":return Ui(t,e,o,a);default:return ti(t,e,o,a)}},mi=(i,t,e,o)=>`M ${i+e/2} ${t} A ${e/2} ${o/2} 0 0 0 ${i+e/2} ${t+o} A ${e/2} ${o/2} 0 1 0 ${i+e/2} ${t} Z`,Oi=()=>"Z",Di=(i,t,e,o)=>`M ${i} ${t} L ${i+e/3} ${t} L ${i+e/2} ${t+o/6} L ${i+e} ${t+o/6} L ${i+e} ${t+o} L ${i} ${t+o} Z`,Hi=(i,t,e,o)=>`M ${i+e/4} ${t} L ${i+3*e/4} ${t} L ${i+e} ${t+o/2} L ${i+3*e/4} ${t+o} L ${i+e/4} ${t+o} L ${i} ${t+o/2} Z`,Gi=(i,t,e,o)=>`M ${i+e/4} ${t} L ${i+3*e/4} ${t} L ${i+e} ${t+o/4} L ${i+e} ${t+3*o/4} L ${i+3*e/4} ${t+o} L ${i+e/4} ${t+o} L ${i} ${t+3*o/4} L ${i} ${t+o/4} L ${i+e/4} ${t} Z`,Ut=(i,t,e,o)=>o<e?`M ${i+o/2} ${t} L ${i+e-o/2} ${t} A ${o/2} ${o/2} 0 0 1 ${i+e} ${t+o/2} A ${o/2} ${o/2} 0 0 1 ${i+e-o/2} ${t+o} L ${i+o/2} ${t+o} A ${o/2} ${o/2} 0 0 1 ${i} ${t+o/2} A ${o/2} ${o/2} 0 0 1 ${i+o/2} ${t} Z`:o>e?`M ${i} ${t+e/2} L ${i} ${t+o-e/2} A ${e/2} ${e/2} 0 0 0 ${i+e/2} ${t+o} A ${e/2} ${e/2} 0 0 0 ${i+e} ${t+o-e/2} L ${i+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${i+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${i} ${t+e/2} Z`:mi(i,t,e,o),ti=(i,t,e,o)=>`M ${i} ${t} L ${i+e} ${t} L ${i+e} ${t+o} L ${i} ${t+o} Z`,Bi=(i,t,e,o)=>`M ${i+e/2} ${t} L ${i+e} ${t+o/2} L ${i+e/2} ${t+o} L ${i} ${t+o/2} Z`,Fi=(i,t,e,o)=>`M ${i+e/4} ${t} L ${i+3*e/4} ${t} A ${e/4} ${o/4} 0 0 1 ${i+e} ${t+o/4} L ${i+e} ${t+3*o/4} A ${e/4} ${o/4} 0 0 1 ${i+3*e/4} ${t+o} L ${i+e/4} ${t+o} A ${e/4} ${o/4} 0 0 1 ${i} ${t+3*o/4} L ${i} ${t+o/4} A ${e/4} ${o/4} 0 0 1 ${i+e/4} ${t} Z`,Ui=(i,t,e,o)=>`M ${i} ${t} L ${i+3*e/4} ${t} L ${i+3*e/4} ${t+o/4} L ${i+3*e/4} ${t} L ${i+e} ${t+o/4} L ${i+3*e/4} ${t+o/4} L ${i+e} ${t+o/4} L ${i+e} ${t+o} L ${i} ${t+o} Z`;var P=(i=>(i.AllScroll="all-scroll",i.Auto="auto",i.Crosshair="crosshair",i.EWResize="ew-resize",i.Grab="grab",i.Grabbing="grabbing",i.Move="move",i.NoDrop="no-drop",i.NSResize="ns-resize",i.NotAllowed="not-allowed",i.ZoomIn="zoom-in",i.ZoomOut="zoom-out",i))(P||{});const Yi=i=>Math.max(...i.split(` `).map(t=>t.length)),Xi=i=>{var t;return((t=i.match(/\n/g))==null?void 0:t.length)||0},tt=[];for(let i=0;i<256;++i)tt.push((i+256).toString(16).slice(1));function Wi(i,t=0){return(tt[i[t+0]]+tt[i[t+1]]+tt[i[t+2]]+tt[i[t+3]]+"-"+tt[i[t+4]]+tt[i[t+5]]+"-"+tt[i[t+6]]+tt[i[t+7]]+"-"+tt[i[t+8]]+tt[i[t+9]]+"-"+tt[i[t+10]]+tt[i[t+11]]+tt[i[t+12]]+tt[i[t+13]]+tt[i[t+14]]+tt[i[t+15]]).toLowerCase()}let se;const Zi=new Uint8Array(16);function Ki(){if(!se){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");se=crypto.getRandomValues.bind(crypto)}return se(Zi)}const qi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ei={randomUUID:qi};function ii(i,t,e){var a;if(ei.randomUUID&&!i)return ei.randomUUID();i=i||{};const o=i.random??((a=i.rng)==null?void 0:a.call(i))??Ki();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Wi(o)}const nt=i=>{const{selected:t,highlighted:e,...o}=i,a=o,l={...a,...t},s={...a,...e},n={...a,...e,...t};return{defaultLook:a,selectedLook:l,highlightedLook:s,selectedAndHighlightedLook:n}};class Kt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],Z(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const zt=0;class Lt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userHighlight)==null?void 0:e.contains(this.id))||!1}get selected(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userSelection)==null?void 0:e.contains(this.id))||!1}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`[id='${ge(this.id)}']`)}}class pt extends Kt{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((o,a,l)=>t(o,a,l)&&!o.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((o,a,l)=>t(o,a,l)&&!o.removed)}find(t,e=!1){return e?super.find(t):super.find((o,a,l)=>t(o,a,l)&&!o.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(o=>!o.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],Z(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(o=>!o.removed))yield e}}class Ji{constructor(t,e,o,a,l,s){this.name=t,this.type=e,this.defaultValue=o,this.basic=a,this.editable=l,this.rootAttribute=s,this.options=void 0,this.properties=void 0}}var _=(i=>(i.Boolean="boolean",i.Color="color",i.Date="date",i.Datetime="datetime",i.Number="number",i.Object="object",i.Option="option",i.OptionList="option-list",i.OptionSet="option-set",i.Text="text",i.TextArea="text-area",i.TextList="text-list",i.TextSet="text-set",i.TextMap="text-map",i.Time="time",i.Url="url",i))(_||{});class qt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}function Ct(i,t){return!t||i[0]>t[0]?!0:i[0]===t[0]?i[1]>=t[1]:!1}const oi=i=>i==null||i===""||i instanceof Array&&i.length===0||i instanceof Object&&Object.keys(i).length===0,At=(i,t)=>i===t||JSON.stringify(i)===JSON.stringify(t),fi=(i,t,e)=>{const o={},a={};for(const l in e.propertySet.propertyMap)if(e.propertySet.propertyMap[l].type===_.Object){const s=fi(i[l],t[l],e.getSubValueSet(l));Object.keys(s[0]).length>0&&Object.keys(s[1]).length>0&&(o[l]=s[0],a[l]=s[1])}else At(i[l],t[l])||(o[l]=i[l],a[l]=t[l]);return[o,a]},Qi=i=>i!=null&&i.constructor===Object;class wt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const o of t){if(e==null)return;e=e[o]}return e}}setRootElementValue(t,e){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let o=this.rootElement;for(let a=0;a<t.length-1;++a){const l=t[a];if(o==null)return;o=o[l]}if(o==null)return;o[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}getValue(t){var a;const e=(a=this.propertySet.getProperty(t))==null?void 0:a.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===_.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===_.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const o in t)this.propertySet.getProperty(o).type===_.Object?e[o]=this.valueSets[o].getValuesForKeys(t[o]):e[o]=this.getValue(o);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===_.Object)t[e]=this.valueSets[e].getTimestamps();else{const a=this.ownTimestamps[e];a&&(t[e]=a)}return t}hasValue(t){const e=this.getValue(t);return!oi(e)}hasSetValue(t){const e=this.getValue(t),o=this.propertySet.getProperty(t);return o&&o.type===_.Object?this.getSubValueSet(t).hasAnySetValue():!oi(e)&&!At(e,o==null?void 0:o.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const o=this.propertySet.getProperty(t);if(o){o.type===_.Object?this.valueSets[t].setValues(e):(this.values[t]=e,At(e,o.defaultValue)||this.displayProperty(o));const a=o.rootAttribute;a!=null&&this.setRootElementValue(a,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const o in t)this.propertySet.getProperty(o).type===_.Object?this.valueSets[o].overwriteValuesLww(t[o],e):Ct(e,this.ownTimestamps[o])&&(this.setValue(o,t[o]),this.ownTimestamps[o]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),o=e.rootAttribute;e.type===_.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),o!=null&&e.defaultValue!==void 0&&!At(this.getRootElementValue(o),e.defaultValue)&&this.setRootElementValue(o,this.values[t]),e.basic?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),o=new qt(e.properties),a=new wt(o,this.rootElement);return a.overwriteValues(structuredClone(e.defaultValue)),a}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),Z(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),Z(this.displayedProperties,t))}}const to={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:gi.Straight,style:ui.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class pi{constructor(t){const e={...to,...t};this.id=e.id,this.name=e.name,this.label=e.label;const o=nt(e.look);if(this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const a=nt(e.startMarkerLook);this.defaultStartMarkerLook=a.defaultLook,this.selectedStartMarkerLook=a.selectedLook,this.highlightedStartMarkerLook=a.highlightedLook,this.selectedAndHighlightedStartMarkerLook=a.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const a=nt(e.endMarkerLook);this.defaultEndMarkerLook=a.defaultLook,this.selectedEndMarkerLook=a.selectedLook,this.highlightedEndMarkerLook=a.highlightedLook,this.selectedAndHighlightedEndMarkerLook=a.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.propertySet=new qt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class dt extends Lt{constructor(t,e,o,a,l){if(t.connections.get(l)!==void 0)throw new Error(`DiagramConnection with id "${l}" already exists`);if(!l)throw new Error("DiagramConnection cannot have an empty or null id");super(t,l),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new wt(e.propertySet,this),this.originalData={},this.setStart(o),this.setEnd(a)}get type(){return this._type}set type(t){var e,o;t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new wt(t.propertySet,this)),(o=(e=this.model.canvas)==null?void 0:e.userSelection)==null||o.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.connections.types.get(t);e&&(this.type=e)}}get name(){return this.middleLabel}set name(t){this.middleLabel=t}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){if(t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook!==void 0?this._selectedAndHighlightedStartMarkerLook:this.type.selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook!==void 0?this._selectedStartMarkerLook:this.type.selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook!==void 0?this._highlightedStartMarkerLook:this.type.highlightedStartMarkerLook:this._defaultStartMarkerLook!==void 0?this._defaultStartMarkerLook:this.type.defaultStartMarkerLook}set startMarkerLook(t){if(t){const e=nt(t);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...e.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...e.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...e.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=t,this._selectedStartMarkerLook=t,this._highlightedStartMarkerLook=t,this._selectedAndHighlightedStartMarkerLook=t}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook!==void 0?this._selectedAndHighlightedEndMarkerLook:this.type.selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook!==void 0?this._selectedEndMarkerLook:this.type.selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook!==void 0?this._highlightedEndMarkerLook:this.type.highlightedEndMarkerLook:this._defaultEndMarkerLook!==void 0?this._defaultEndMarkerLook:this.type.defaultEndMarkerLook}set endMarkerLook(t){if(t){const e=nt(t);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...e.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...e.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...e.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=t,this._selectedEndMarkerLook=t,this._highlightedEndMarkerLook=t,this._selectedAndHighlightedEndMarkerLook=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateConnectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}setStart(t){this.start!==t?(this.start!==void 0&&Z(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&Z(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}tighten(){var a,l,s,n,r;const t=((a=this.model.canvas)==null?void 0:a.allowConnectionLoops)||!1,e=((l=this.model.canvas)==null?void 0:l.allowSharingPorts)!==!1,o=((s=this.model.canvas)==null?void 0:s.allowSharingBothPorts)||!1;if((n=this.start)!=null&&n.rootElement&&this.end){const c=this.start.rootElement.ports.map(d=>[d,d.distanceTo(this.end.coords)]).sort((d,h)=>d[1]-h[1]).map(d=>d[0]);t:for(const d of c){if(!t&&d===this.end||!d.allowsOutgoing||!e&&(d.incomingConnections.length===1&&d.incomingConnections[0]!==this||d.incomingConnections.length>1||d.outgoingConnections.length===1&&d.outgoingConnections[0]!==this||d.outgoingConnections.length>1))continue t;if(!o){for(const h of d.outgoingConnections)if(h!==this&&h.end===this.end)continue t;for(const h of d.incomingConnections)if(h!==this&&h.start===this.end)continue t}if(d===this.start)break t;this.setStart(d);break t}}if((r=this.end)!=null&&r.rootElement&&this.start){const c=this.end.rootElement.ports.map(d=>[d,d.distanceTo(this.start.coords)]).sort((d,h)=>d[1]-h[1]).map(d=>d[0]);t:for(const d of c){if(!t&&d===this.start||!d.allowsIncoming||!e&&(d.outgoingConnections.length===1&&d.outgoingConnections[0]!==this||d.outgoingConnections.length>1||d.incomingConnections.length===1&&d.incomingConnections[0]!==this||d.incomingConnections.length>1))continue t;if(!o){for(const h of d.incomingConnections)if(h!==this&&h.start===this.start)continue t;for(const h of d.outgoingConnections)if(h!==this&&h.end===this.start)continue t}if(d===this.end)break t;this.setEnd(d);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():zt}}class eo extends pt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,o,a){let l;if(t instanceof pi)l=t;else{const n=this.types.get(t);if(n===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);l=n}const s=new dt(this.model,l,e,o,a);return super.add(s),s.updateInView(),s.valueSet.resetValues(),s}remove(t){var o,a;const e=this.get(t,!0);e&&(Z(((o=e.start)==null?void 0:o.outgoingConnections)||[],e),Z(((a=e.end)==null?void 0:a.incomingConnections)||[],e),super.remove(t),e.updateInView())}}const D={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:Mt.Center,verticalAlign:Yt.Center,orientation:k.Top,fit:!1,shrink:!0};class mt extends Lt{constructor(t,e,o,a,l,s,n,r,c,d,h,u,p,f,m,g){const y=`${e==null?void 0:e.id}_field`;if(t.fields.get(y)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,y),this.textTimestamp=null,this.rootElement=e,this.coords=o,this.width=a,this.height=l,this.fontSize=s,this.fontFamily=n,this.color=r,this.selectedColor=c,this.horizontalAlign=d,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case k.Top:this.orientation=0;break;case k.Right:this.orientation=90;break;case k.Bottom:this.orientation=180;break;case k.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=p,this._text=p,this.editable=f,this.fit=m,this.shrink=g}get text(){return this._text}set text(t){var e;(t==null||(t==null?void 0:t.trim())==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&((e=this.model.canvas)==null||e.fitFieldRootInView(this.id,this.shrink))}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateFieldsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||zt}}class io extends pt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s,n,r,c,d,h,u,p,f,m){const g=new mt(this.model,t,e,n,r,o,a,l,s,c,d,h,u,p,f,m);return super.add(g),g.updateInView(),t!==void 0&&(t.label=g),g}remove(t){var o;const e=this.get(t,!0);e&&(((o=e.rootElement)==null?void 0:o.label)!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const ot=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:i.margin.length===1||i.margin.length===2?i.margin[0]:(i.margin.length===3,i.margin[2]),Q=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:i.margin.length===1?i.margin[0]:i.margin.length===2||i.margin.length===3?i.margin[1]:i.margin[3],at=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:i.margin.length===1?i.margin[0]:(i.margin.length===2||i.margin.length===3,i.margin[1]),W=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:(i.margin.length===1||i.margin.length===2||i.margin.length===3,i.margin[0]),_t=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),jt=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],Ot=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),Dt=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),si=1,ni=1,oo=1,so=1;class no{constructor(t){this.margin=t.margin||0,this.defaultWidths=t.defaultWidths||null,this.defaultHeights=t.defaultHeights||null,this.minWidths=t.minWidths||null,this.minHeights=t.minHeights||null,this.sections=[];for(const e of t.sections){const o=[];this.sections.push(o);for(const a of e)o.push(new ro(a))}}}class ro{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||zt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=nt(t.look||vi);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class U extends Lt{constructor(t,e,o,a,l,s,n,r){if(t.sections.get(r)!==void 0)throw new Error(`DiagramSection with id "${r}" already exists`);if(!r)throw new Error("DiagramSection cannot have an empty or null id");super(t,r),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=o,this.indexYInNode=a,this.coords=l,this.width=s,this.height=n}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){var t,e,o,a,l,s,n,r;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:((t=this.type)==null?void 0:t.selectedAndHighlightedLook)||((e=this.node)==null?void 0:e.look):this._selectedLook!==void 0?this._selectedLook:((o=this.type)==null?void 0:o.selectedLook)||((a=this.node)==null?void 0:a.look):this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:((l=this.type)==null?void 0:l.highlightedLook)||((s=this.node)==null?void 0:s.look):this._defaultLook!==void 0?this._defaultLook:((n=this.type)==null?void 0:n.defaultLook)||((r=this.node)==null?void 0:r.look)}set look(t){if(t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateSectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise()}get type(){var t,e,o,a,l;return(l=(a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode]}getMinWidth(){var t,e,o,a;return((a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.minWidths)==null?void 0:a[this.indexXInNode])||oo}getMinHeight(){var t,e,o,a;return((a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.minHeights)==null?void 0:a[this.indexYInNode])||so}getPriority(){var t,e,o,a,l,s;return((s=(l=(a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode])==null?void 0:s.priority)||zt}getResizableX(){var e,o;const t=this.type;return(t==null?void 0:t.resizableX)!==void 0?t.resizableX:((o=(e=this.node)==null?void 0:e.type)==null?void 0:o.resizableX)||!1}getResizableY(){var e,o;const t=this.type;return(t==null?void 0:t.resizableY)!==void 0?t.resizableY:((o=(e=this.node)==null?void 0:e.type)==null?void 0:o.resizableY)||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),o=e.indexOf(Math.min(...e));return this.ports[o]}}}getIncomingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const o of this.ports){for(const a of o.incomingConnections)!t&&a.removed||e.push(a);for(const a of o.outgoingConnections)!t&&a.removed||e.push(a)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(t){case k.Left:l=[o[0]-e,o[1]],s=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[0]=l[1]-this.getMinWidth());break;case k.Top:l=[o[0],o[1]],s=[a[0]-e,a[1]],s[1]-s[0]<this.getMinHeight()&&(s[0]=s[1]-this.getMinHeight());break;case k.Right:l=[o[0],o[1]+e],s=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[1]=l[0]+this.getMinWidth());break;case k.Bottom:l=[o[0],o[1]],s=[a[0],a[1]+e],s[1]-s[0]<this.getMinHeight()&&(s[1]=s[0]+this.getMinHeight());break}this.setGeometry({coords:[l[0],s[0]],width:l[1]-l[0],height:s[1]-s[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){var n;const e=[this.coords[0],this.coords[0]+this.width],o=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const r of this.ports)r.move(Xt(r.coords,e,o,a,l,r.anchorPointX,r.anchorPointY));const s=this.type;this.label&&(this.label.coords=[this.coords[0]+Q(s==null?void 0:s.label),this.coords[1]+W(s==null?void 0:s.label)],this.label.width=this.width-Q(s==null?void 0:s.label)-at(s==null?void 0:s.label),this.label.height=this.height-W(s==null?void 0:s.label)-ot(s==null?void 0:s.label),this.label.updateInView());for(const r of this.decorators)r.move(Xt(r.coords,e,o,a,l,r.anchorPointX,r.anchorPointY));((n=this.model.canvas)==null?void 0:n.autoTightenConnections)!==!1&&this.getConnections().forEach(r=>r.tighten()),this.updateInView()}}class ao extends pt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s,n){var h,u,p,f,m,g,y,w,b,I;const r=new U(this.model,t,e,o,a,l,s,n);super.add(r),r.updateInView(),t.sections.push(r),t.updateInView();const c=(f=(p=(u=(h=t.type.sectionGrid)==null?void 0:h.sections)==null?void 0:u[o])==null?void 0:p[e])==null?void 0:f.ports;if(c&&c.length>0)for(let S=0;S<c.length;++S){const L=c[S],$=this.model.ports.new(L.type!==void 0?this.model.ports.types.get(L.type):void 0,r,[r.coords[0]+(L.coords[0]||0),r.coords[1]+(L.coords[1]||0)],L.connectionPoint!==void 0?[r.coords[0]+(L.connectionPoint[0]||0),r.coords[1]+(L.connectionPoint[1]||0)]:void 0,L==null?void 0:L.direction,`${r.id}_${S}`,L.anchorPointX||"floating",L.anchorPointY||"floating");if((m=$.type)!=null&&m.label){const x={...D,...(g=$.type)==null?void 0:g.label},V=6*x.fontSize+jt(x)+Ot(x),T=x.fontSize+Dt(x)+_t(x);let R;switch($.direction){case k.Bottom:case k.Left:case k.Right:R=[$.coords[0]-V/2,$.coords[1]-T-ot(x)];break;case k.Top:R=[$.coords[0]-V/2,$.coords[1]+W(x)];break;default:R=$.coords}this.model.fields.new($,R,x.fontSize,x.fontFamily,x.color,x.selectedColor,V,T,x.horizontalAlign,x.verticalAlign,x.orientation,"",x.editable,x.fit,x.shrink)}}const d=(I=(b=(w=(y=t.type.sectionGrid)==null?void 0:y.sections)==null?void 0:w[o])==null?void 0:b[e])==null?void 0:I.label;if(d){const S={...D,...d};this.model.fields.new(r,[r.coords[0]+Q(S),r.coords[1]+W(S)],S.fontSize,S.fontFamily,S.color,S.selectedColor,r.width-Q(S)-at(S),r.height-W(S)-ot(S),S.horizontalAlign,S.verticalAlign,S.orientation,"",S.editable,S.fit,S.shrink)}return r}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&Z(e.node.sections,e),super.remove(t),e.updateInView()}}}const vi={lookType:"shaped-look",shape:Zt.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},ft={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:vi,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:zt,properties:[]};class yi{constructor(t){const e={...ft,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.bottomPadding=co(e),this.leftPadding=ho(e),this.rightPadding=go(e),this.topPadding=uo(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new no(e.sectionGrid):null;const o=nt(e.look);this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new qt((t==null?void 0:t.properties)||[])}}class j extends Lt{constructor(t,e,o=[0,0],a){if(t.nodes.get(a)!==void 0)throw new Error(`DiagramNode with id "${a}" already exists`);if(!a)throw new Error("DiagramNode cannot have an empty or null id");super(t,a),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new wt(e.propertySet,this),this.originalData={},this.coords=o,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){var e,o;t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new wt(t.propertySet,this)),(o=(e=this.model.canvas)==null?void 0:e.userSelection)==null||o.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.nodes.types.get(t);e&&(this.type=e)}}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){if(t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateNodesInView(this.id)}raise(){var t;(t=this.select())==null||t.raise();for(const e of this.sections)e.raise();this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise();for(const e of this.children)e.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),o=e.indexOf(Math.min(...e));return this.ports[o]}}}getIncomingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const o of this.ports){for(const a of o.incomingConnections)!t&&a.removed||e.push(a);for(const a of o.outgoingConnections)!t&&a.removed||e.push(a)}return e}getAdjacentNodes(t=!1){var o,a;const e=[];for(const l of this.ports){for(const s of l.incomingConnections){if(!t&&s.removed)continue;const n=(o=s.start)==null?void 0:o.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}for(const s of l.outgoingConnections){if(!t&&s.removed)continue;const n=(a=s.end)==null?void 0:a.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t==null?void 0:t.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,o=!1;for(;e!==void 0;){if(e.id===t.id){o=!0;break}e=e.parent}o||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){Z(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(r=>r.indexXInNode)),o=Math.max(...this.sections.map(r=>r.indexYInNode)),a=this.coords[0]-t.coords[0]+this.type.leftPadding;a>=0&&(this.sections.length>0?this.stretchSections(k.Left,a,e,o):this.stretch(k.Left,a));const l=this.coords[1]-t.coords[1]+this.type.topPadding;l>=0&&(this.sections.length>0?this.stretchSections(k.Top,l,e,o):this.stretch(k.Top,l));const s=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;s>=0&&(this.sections.length>0?this.stretchSections(k.Right,s,e,o):this.stretch(k.Right,s));const n=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;n>=0&&(this.sections.length>0?this.stretchSections(k.Bottom,n,e,o):this.stretch(k.Bottom,n)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const o of this.children)o.move([o.coords[0]+e[0],o.coords[1]+e[1]]);for(const o of this.sections)o.move([o.coords[0]+e[0],o.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(t){case k.Left:l=[o[0]-e,o[1]],s=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[0]=l[1]-this.type.minWidth);break;case k.Top:l=[o[0],o[1]],s=[a[0]-e,a[1]],s[1]-s[0]<this.type.minHeight&&(s[0]=s[1]-this.type.minHeight);break;case k.Right:l=[o[0],o[1]+e],s=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[1]=l[0]+this.type.minWidth);break;case k.Bottom:l=[o[0],o[1]],s=[a[0],a[1]+e],s[1]-s[0]<this.type.minHeight&&(s[1]=s[0]+this.type.minHeight);break}this.setGeometry({coords:[l[0],s[0]],width:l[1]-l[0],height:s[1]-s[0],sections:{},children:{}})}stretchSections(t,e,o,a){let l=Number.NEGATIVE_INFINITY;switch(t){case k.Bottom:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));e<l&&(e=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(t,e):s.indexYInNode>a&&s.move([s.coords[0],s.coords[1]+e]);break;case k.Right:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));e<l&&(e=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(t,e):s.indexXInNode>o&&s.move([s.coords[0]+e,s.coords[1]]);break;case k.Top:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));e<l&&(e=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(t,e):s.indexYInNode<a&&s.move([s.coords[0],s.coords[1]-e]);break;case k.Left:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));e<l&&(e=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(t,e):s.indexXInNode<o&&s.move([s.coords[0]-e,s.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const a of this.sections)e[a.id]=a.getGeometry();const o={};for(const a of this.children)a.id!==t&&(o[a.id]=a.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:o}}setGeometry(t){var s;this.raise();const e=[this.coords[0],this.coords[0]+this.width],o=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const n of this.children){const r=t.children[n.id];r&&n.setGeometry(r)}for(const n of this.sections){const r=t.sections[n.id];r&&n.setGeometry(r)}for(const n of this.ports)n.move(Xt(n.coords,e,o,a,l,n.anchorPointX,n.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+Q(this.type.label),this.coords[1]+W(this.type.label)],this.label.width=this.width-Q(this.type.label)-at(this.type.label),this.label.height=this.height-W(this.type.label)-ot(this.type.label),this.label.updateInView());for(const n of this.decorators)n.move(Xt(n.coords,e,o,a,l,n.anchorPointX,n.anchorPointY));((s=this.model.canvas)==null?void 0:s.autoTightenConnections)!==!1&&this.getConnections().forEach(n=>n.tighten()),this.updateInView()}removeSectionColumn(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)s.indexYInNode===t&&(o=Math.max(o,s.width),this.model.sections.remove(s.id));for(const s of a)s.indexYInNode>t&&(--s.indexYInNode,s.move([s.coords[0]-o-e,s.coords[1]]));this.stretch(k.Right,-e-o)}removeSectionRow(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)s.indexXInNode===t&&(o=Math.max(o,s.height),this.model.sections.remove(s.id));for(const s of a)s.indexYInNode>t&&(--s.indexXInNode,s.move([s.coords[0],s.coords[1]-o-e]));this.stretch(k.Bottom,-e-o)}copySectionColumn(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)if(s.indexXInNode===t){o=Math.max(o,s.width);let n=s.indexXInNode+1;for(;this.model.sections.get(`${s.id}_copy_${n}_${s.indexYInNode}`,!0)!==void 0;)++n;this.model.sections.new(this,s.indexXInNode+1,s.indexYInNode,[s.coords[0]+s.width+e,s.coords[1]],s.width,s.height,`${s.id}_copy_${n}_${s.indexYInNode}`)}for(const s of a)s.indexXInNode>t&&(++s.indexXInNode,s.move([s.coords[0]+o+e,s.coords[1]]));this.stretch(k.Right,e+o)}copySectionRow(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)if(s.indexYInNode===t){o=Math.max(o,s.height);let n=s.indexYInNode+1;for(;this.model.sections.get(`${s.id}_copy_${s.indexXInNode}_${n}`,!0)!==void 0;)++n;this.model.sections.new(this,s.indexXInNode,s.indexYInNode+1,[s.coords[0],s.coords[1]+s.height+e],s.width,s.height,`${s.id}_copy_${s.indexXInNode}_${n}`)}for(const s of a)s.indexYInNode>t&&(++s.indexYInNode,s.move([s.coords[0],s.coords[1]+o+e]));this.stretch(k.Bottom,e+o)}}class lo extends pt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,o){var s,n,r,c,d,h,u;let a;if(t instanceof yi)a=t;else{const p=this.types.get(t);if(p===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);a=p}const l=new j(this.model,a,e,o);if(super.add(l),l.updateInView(),a.sectionGrid!==null){let p=l.coords[1]+(a.sectionGrid.margin||0);for(let f=0;f<a.sectionGrid.sections.length;++f){let m=l.coords[0]+(a.sectionGrid.margin||0);for(let g=0;g<a.sectionGrid.sections[f].length;++g)this.model.sections.new(l,g,f,[m,p],((s=a.sectionGrid.defaultWidths)==null?void 0:s[g])||si,((n=a.sectionGrid.defaultHeights)==null?voi