@metadev/daga-react
Version:

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