@metadev/daga-react 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +10 -2
- package/README.md +1 -0
- package/index.js +2 -2
- package/index.mjs +3440 -3413
- package/package.json +2 -2
- package/style.css +0 -1
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),Pi=require("d3"),
|
|
2
|
-
`).map(e=>e.length)),Yi=i=>{var e;return((e=i.match(/\n/g))==null?void 0:e.length)||0},q=[];for(let i=0;i<256;++i)q.push((i+256).toString(16).slice(1));function Xi(i,e=0){return(q[i[e+0]]+q[i[e+1]]+q[i[e+2]]+q[i[e+3]]+"-"+q[i[e+4]]+q[i[e+5]]+"-"+q[i[e+6]]+q[i[e+7]]+"-"+q[i[e+8]]+q[i[e+9]]+"-"+q[i[e+10]]+q[i[e+11]]+q[i[e+12]]+q[i[e+13]]+q[i[e+14]]+q[i[e+15]]).toLowerCase()}let tt;const Wi=new Uint8Array(16);function Zi(){if(!tt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");tt=crypto.getRandomValues.bind(crypto)}return tt(Wi)}const Ki=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ti={randomUUID:Ki};function ii(i,e,t){var a;if(ti.randomUUID&&!i)return ti.randomUUID();i=i||{};const s=i.random??((a=i.rng)==null?void 0:a.call(i))??Zi();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,Xi(s)}const ne=i=>{const{selected:e,highlighted:t,...s}=i,a=s,l={...a,...e},o={...a,...t},n={...a,...t,...e};return{defaultLook:a,selectedLook:l,highlightedLook:o,selectedAndHighlightedLook:n}};class Xe{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(e){this.entityMap[e.id]===void 0&&(this.entityMap[e.id]=e,this.entities.push(e))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(e){return this.entityMap[e]!==void 0}count(e){return this.entities.filter(e).length}filter(e){return this.entities.filter(e)}find(e){return this.entities.find(e)}get(e){return this.entityMap[e]}map(e){return this.entities.map(e)}remove(e){const t=this.get(e);t!==void 0&&(delete this.entityMap[e],Y(this.entities,t))}size(){return this.entities.length}*[Symbol.iterator](){for(const e of this.entities)yield e}}const ct=i=>i.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1"),Me=0;class Ie{constructor(e,t){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=e,this._id=t}get id(){return this._id}get highlighted(){var e,t;return((t=(e=this.model.canvas)==null?void 0:e.userHighlight)==null?void 0:t.contains(this.id))||!1}get selected(){var e,t;return((t=(e=this.model.canvas)==null?void 0:e.userSelection)==null?void 0:t.contains(this.id))||!1}select(){var e,t;return(t=(e=this.model.canvas)==null?void 0:e.selectCanvasView())==null?void 0:t.select(`[id='${ct(this.id)}']`)}}class ge extends Xe{all(e=!1){return e?super.all():super.filter(t=>!t.removed)}contains(e,t=!1){return t?super.contains(e):super.contains(e)&&!this.entityMap[e].removed}count(e,t=!1){return t?super.count(e):super.count((s,a,l)=>e(s,a,l)&&!s.removed)}filter(e,t=!1){return t?super.filter(e):super.filter((s,a,l)=>e(s,a,l)&&!s.removed)}find(e,t=!1){return t?super.find(e):super.find((s,a,l)=>e(s,a,l)&&!s.removed)}get(e,t=!1){return t?super.get(e):this.contains(e)?super.get(e):void 0}map(e,t=!1){return t?super.map(e):super.filter(s=>!s.removed).map(e)}remove(e){const t=this.get(e,!0);t!==void 0&&(delete this.entityMap[e],Y(this.entities,t))}size(e=!1){return e?super.size():super.filter(t=>!t.removed).length}*[Symbol.iterator](e=!1){if(e)for(const t of this.entities)yield t;else for(const t of this.entities.filter(s=>!s.removed))yield t}}class qi{constructor(e,t,s,a,l,o){this.name=e,this.type=t,this.defaultValue=s,this.basic=a,this.editable=l,this.rootAttribute=o,this.options=void 0,this.properties=void 0}}var V=(i=>(i.Boolean="boolean",i.Color="color",i.Date="date",i.Datetime="datetime",i.Number="number",i.Object="object",i.Option="option",i.OptionList="option-list",i.OptionSet="option-set",i.Text="text",i.TextArea="text-area",i.TextList="text-list",i.TextSet="text-set",i.TextMap="text-map",i.Time="time",i.Url="url",i))(V||{});class We{constructor(e=[]){this.propertyList=e,this.propertyMap={};for(const t of this.propertyList)this.propertyMap[t.name]=t}getProperty(e){return this.propertyMap[e]}hasProperty(e){return this.propertyMap[e]!==void 0}hasProperties(){return this.propertyList.length>0}}function we(i,e){return!e||i[0]>e[0]?!0:i[0]===e[0]?i[1]>=e[1]:!1}const oi=i=>i==null||i===""||i instanceof Array&&i.length===0||i instanceof Object&&Object.keys(i).length===0,Ce=(i,e)=>i===e||JSON.stringify(i)===JSON.stringify(e),gi=(i,e,t)=>{const s={},a={};for(const l in t.propertySet.propertyMap)if(t.propertySet.propertyMap[l].type===V.Object){const o=gi(i[l],e[l],t.getSubValueSet(l));Object.keys(o[0]).length>0&&Object.keys(o[1]).length>0&&(s[l]=o[0],a[l]=o[1])}else Ce(i[l],e[l])||(s[l]=i[l],a[l]=e[l]);return[s,a]},Ji=i=>i!=null&&i.constructor===Object;class ve{constructor(e,t){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=e,this.rootElement=t,this.resetValues()}getRootElementValue(e){if(typeof e=="string")return this.rootElement[e];if(Array.isArray(e)&&e.length>0){let t=this.rootElement;for(const s of e){if(t==null)return;t=t[s]}return t}}setRootElementValue(e,t){if(typeof e=="string"&&(this.rootElement[e]=t),Array.isArray(e)&&e.length>0){let s=this.rootElement;for(let a=0;a<e.length-1;++a){const l=e[a];if(s==null)return;s=s[l]}if(s==null)return;s[e[e.length-1]]=t}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}getValue(e){var a;const t=(a=this.propertySet.getProperty(e))==null?void 0:a.rootAttribute;return t!=null&&(this.values[e]=this.getRootElementValue(t)),this.propertySet.getProperty(e).type===V.Object?this.valueSets[e].getValues():this.values[e]}getValues(){const e={};for(const t in this.propertySet.propertyMap)this.propertySet.getProperty(t).type===V.Object?e[t]=this.valueSets[t].getValues():e[t]=this.getValue(t);return e}getValuesForKeys(e){const t={};for(const s in e)this.propertySet.getProperty(s).type===V.Object?t[s]=this.valueSets[s].getValuesForKeys(e[s]):t[s]=this.getValue(s);return t}getTimestamps(){const e={};for(const t in this.propertySet.propertyMap)if(this.propertySet.getProperty(t).type===V.Object)e[t]=this.valueSets[t].getTimestamps();else{const a=this.ownTimestamps[t];a&&(e[t]=a)}return e}hasValue(e){const t=this.getValue(e);return!oi(t)}hasSetValue(e){const t=this.getValue(e),s=this.propertySet.getProperty(e);return s&&s.type===V.Object?this.getSubValueSet(e).hasAnySetValue():!oi(t)&&!Ce(t,s==null?void 0:s.defaultValue)}hasAnySetValue(){for(const e of this.propertySet.propertyList)if(this.hasSetValue(e.name))return!0;return!1}setValue(e,t){const s=this.propertySet.getProperty(e);if(s){s.type===V.Object?this.valueSets[e].setValues(t):(this.values[e]=t,Ce(t,s.defaultValue)||this.displayProperty(s));const a=s.rootAttribute;a!=null&&this.setRootElementValue(a,t)}}setValues(e){this.resetValues();for(const t in e)this.propertySet.getProperty(t).type===V.Object?this.valueSets[t].setValues(e[t]):this.setValue(t,e[t])}setTimestamps(e){this.ownTimestamps={};for(const t in e)this.propertySet.getProperty(t).type===V.Object?this.valueSets[t].setTimestamps(e[t]):this.ownTimestamps[t]=e[t]}overwriteValues(e){for(const t in e)this.propertySet.getProperty(t).type===V.Object?this.valueSets[t].overwriteValues(e[t]):this.setValue(t,e[t])}overwriteValuesLww(e,t){for(const s in e)this.propertySet.getProperty(s).type===V.Object?this.valueSets[s].overwriteValuesLww(e[s],t):we(t,this.ownTimestamps[s])&&(this.setValue(s,e[s]),this.ownTimestamps[s]=t)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const e in this.propertySet.propertyMap){const t=this.propertySet.getProperty(e),s=t.rootAttribute;t.type===V.Object?this.valueSets[e]=this.constructSubValueSet(e):this.values[e]=structuredClone(t.defaultValue),s!=null&&t.defaultValue!==void 0&&!Ce(this.getRootElementValue(s),t.defaultValue)&&this.setRootElementValue(s,this.values[e]),t.basic?this.displayedProperties.push(t):this.hiddenProperties.push(t)}}constructSubValueSet(e){const t=this.propertySet.getProperty(e),s=new We(t.properties),a=new ve(s,this.rootElement);return a.overwriteValues(structuredClone(t.defaultValue)),a}getSubValueSet(e){return this.valueSets[e]}displayProperty(e){this.displayedProperties.includes(e)||(this.displayedProperties.push(e),Y(this.hiddenProperties,e))}hideProperty(e){this.hiddenProperties.includes(e)||(this.hiddenProperties.push(e),Y(this.displayedProperties,e))}}const Qi={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:hi.Straight,style:ui.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class mi{constructor(e){const t={...Qi,...e};this.id=t.id,this.name=t.name,this.label=t.label;const s=ne(t.look);if(this.defaultLook=s.defaultLook,this.selectedLook=s.selectedLook,this.highlightedLook=s.highlightedLook,this.selectedAndHighlightedLook=s.selectedAndHighlightedLook,t.startMarkerLook!==void 0){const a=ne(t.startMarkerLook);this.defaultStartMarkerLook=a.defaultLook,this.selectedStartMarkerLook=a.selectedLook,this.highlightedStartMarkerLook=a.highlightedLook,this.selectedAndHighlightedStartMarkerLook=a.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(t.endMarkerLook!==void 0){const a=ne(t.endMarkerLook);this.defaultEndMarkerLook=a.defaultLook,this.selectedEndMarkerLook=a.selectedLook,this.highlightedEndMarkerLook=a.highlightedLook,this.selectedAndHighlightedEndMarkerLook=a.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=t.startTypes,this.endTypes=t.endTypes,this.propertySet=new We(t.properties)}canStartFromType(e){return this.startTypes.indexOf(e)>=0}canFinishOnType(e){return this.endTypes.indexOf(e)>=0}}class de extends Ie{constructor(e,t,s,a,l){if(e.connections.get(l)!==void 0)throw new Error(`DiagramConnection with id "${l}" already exists`);if(!l)throw new Error("DiagramConnection cannot have an empty or null id");super(e,l),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=t,this.valueSet=new ve(t.propertySet,this),this.originalData={},this.setStart(s),this.setEnd(a)}get type(){return this._type}set type(e){var t,s;(s=(t=this.model.canvas)==null?void 0:t.userSelection)==null||s.openInPropertyEditor(void 0),this._type=e,this.valueSet&&(this.valueSet=new ve(e.propertySet,this)),this.updateInView()}get typeString(){return this.type.id}set typeString(e){const t=this.model.connections.types.get(e);t&&(this.type=t)}get name(){return this.middleLabel}set name(e){this.middleLabel=e}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(e){if(e){const t=ne(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook!==void 0?this._selectedAndHighlightedStartMarkerLook:this.type.selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook!==void 0?this._selectedStartMarkerLook:this.type.selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook!==void 0?this._highlightedStartMarkerLook:this.type.highlightedStartMarkerLook:this._defaultStartMarkerLook!==void 0?this._defaultStartMarkerLook:this.type.defaultStartMarkerLook}set startMarkerLook(e){if(e){const t=ne(e);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...t.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...t.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...t.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=e,this._selectedStartMarkerLook=e,this._highlightedStartMarkerLook=e,this._selectedAndHighlightedStartMarkerLook=e}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook!==void 0?this._selectedAndHighlightedEndMarkerLook:this.type.selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook!==void 0?this._selectedEndMarkerLook:this.type.selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook!==void 0?this._highlightedEndMarkerLook:this.type.highlightedEndMarkerLook:this._defaultEndMarkerLook!==void 0?this._defaultEndMarkerLook:this.type.defaultEndMarkerLook}set endMarkerLook(e){if(e){const t=ne(e);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...t.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...t.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...t.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=e,this._selectedEndMarkerLook=e,this._highlightedEndMarkerLook=e,this._selectedAndHighlightedEndMarkerLook=e}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updateConnectionsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise()}setStart(e){this.start!==e?(this.start!==void 0&&Y(this.start.outgoingConnections,this),this.start=e,e!==void 0&&(e.outgoingConnections.push(this),this.startDirection=e==null?void 0:e.direction,this.startCoords=(e==null?void 0:e.connectionPoint)||[0,0])):(this.startDirection=e==null?void 0:e.direction,this.startCoords=(e==null?void 0:e.connectionPoint)||[0,0]),this.updateInView()}setEnd(e){this.end!==e?(this.end!==void 0&&Y(this.end.incomingConnections,this),this.end=e,e!==void 0&&(e.incomingConnections.push(this),this.endDirection=e==null?void 0:e.direction,this.endCoords=(e==null?void 0:e.connectionPoint)||[0,0])):(this.endDirection=e==null?void 0:e.direction,this.endCoords=(e==null?void 0:e.connectionPoint)||[0,0]),this.updateInView()}tighten(){var e,t;if((e=this.start)!=null&&e.rootElement&&this.end){const s=this.start.rootElement.ports.map(a=>[a,a.distanceTo(this.end.coords)]).sort((a,l)=>a[1]-l[1]).map(a=>a[0]);e:for(const a of s){if(a===this.end||!a.allowsOutgoing)continue e;{for(const l of a.outgoingConnections)if(l!==this&&l.end===this.end)continue e;for(const l of a.incomingConnections)if(l!==this&&l.start===this.end)continue e}if(a===this.start)break e;this.setStart(a);break e}}if((t=this.end)!=null&&t.rootElement&&this.start){const s=this.end.rootElement.ports.map(a=>[a,a.distanceTo(this.start.coords)]).sort((a,l)=>a[1]-l[1]).map(a=>a[0]);e:for(const a of s){if(a===this.start||!a.allowsIncoming)continue e;{for(const l of a.incomingConnections)if(l!==this&&l.start===this.start)continue e;for(const l of a.outgoingConnections)if(l!==this&&l.end===this.start)continue e}if(a===this.end)break e;this.setEnd(a);break e}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Me}}class eo extends ge{constructor(e){super(),this.types=new Xe,this.model=e}new(e,t,s,a){let l;if(e instanceof mi)l=e;else{const n=this.types.get(e);if(n===void 0)throw new TypeError(`Connection type with id '${e}' could not be found.`);l=n}const o=new de(this.model,l,t,s,a);return super.add(o),o.updateInView(),o.valueSet.resetValues(),o}remove(e){var s,a;const t=this.get(e,!0);t&&(Y(((s=t.start)==null?void 0:s.outgoingConnections)||[],t),Y(((a=t.end)==null?void 0:a.incomingConnections)||[],t),super.remove(e),t.updateInView())}}const D={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",horizontalAlign:Te.Center,verticalAlign:Fe.Center,fit:!1};class ue extends Ie{constructor(e,t,s,a,l,o,n,r,d,c,h,g,p,f){const m=`${t==null?void 0:t.id}_field`;if(e.fields.get(m)!==void 0)throw new Error("DiagramField for rootElement already exists");super(e,m),this.textTimestamp=null,this.rootElement=t,this.coords=s,this.width=a,this.height=l,this.fontSize=o,this.fontFamily=n,this.color=r,this.selectedColor=d,this.horizontalAlign=c,this.verticalAlign=h,this.defaultText=g,this._text=g,this.editable=p,this.fit=f}get text(){return this._text}set text(e){var t;(e==null||(e==null?void 0:e.trim())==="")&&(e=this.defaultText),this._text=e,this.updateInView(),this.fit&&((t=this.model.canvas)==null||t.fitFieldRootInView(this.id))}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updateFieldsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){var e;return((e=this.rootElement)==null?void 0:e.getPriority())||Me}}class to extends ge{constructor(e){super(),this.model=e}new(e,t,s,a,l,o,n,r,d,c,h,g,p){const f=new ue(this.model,e,t,n,r,s,a,l,o,d,c,h,g,p);return super.add(f),f.updateInView(),e!==void 0&&(e.label=f),f}remove(e){var s;const t=this.get(e,!0);t&&(((s=t.rootElement)==null?void 0:s.label)!==void 0&&t.rootElement.label===t&&(t.rootElement.label=void 0),super.remove(e),t.updateInView())}}const oe=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:i.margin.length===1||i.margin.length===2?i.margin[0]:(i.margin.length===3,i.margin[2]),K=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:i.margin.length===1?i.margin[0]:i.margin.length===2||i.margin.length===3?i.margin[1]:i.margin[3],re=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:i.margin.length===1?i.margin[0]:(i.margin.length===2||i.margin.length===3,i.margin[1]),U=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:(i.margin.length===1||i.margin.length===2||i.margin.length===3,i.margin[0]),Pe=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),ze=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],Re=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),Ve=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),si=1,ni=1,io=1,oo=1;class so{constructor(e){this.margin=e.margin||0,this.defaultWidths=e.defaultWidths||null,this.defaultHeights=e.defaultHeights||null,this.minWidths=e.minWidths||null,this.minHeights=e.minHeights||null,this.sections=[];for(const t of e.sections){const s=[];this.sections.push(s);for(const a of t)s.push(new no(a))}}}class no{constructor(e){this.label=e.label||null,this.ports=e.ports||[],this.priority=e.priority||Me;const t=ne(e.look||pi);this.defaultLook=t.defaultLook,this.selectedLook=t.selectedLook,this.highlightedLook=t.highlightedLook,this.selectedAndHighlightedLook=t.selectedAndHighlightedLook}}class F extends Ie{constructor(e,t,s,a,l,o,n,r){if(e.sections.get(r)!==void 0)throw new Error(`DiagramSection with id "${r}" already exists`);if(!r)throw new Error("DiagramSection cannot have an empty or null id");super(e,r),this.ports=[],this.decorators=[],this.node=t,this.indexXInNode=s,this.indexYInNode=a,this.coords=l,this.width=o,this.height=n}get name(){var e;return((e=this.label)==null?void 0:e.text)||""}set name(e){this.label&&(this.label.text=e)}get look(){var e,t,s,a,l,o,n,r;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:((e=this.type)==null?void 0:e.selectedAndHighlightedLook)||((t=this.node)==null?void 0:t.look):this._selectedLook!==void 0?this._selectedLook:((s=this.type)==null?void 0:s.selectedLook)||((a=this.node)==null?void 0:a.look):this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:((l=this.type)==null?void 0:l.highlightedLook)||((o=this.node)==null?void 0:o.look):this._defaultLook!==void 0?this._defaultLook:((n=this.type)==null?void 0:n.defaultLook)||((r=this.node)==null?void 0:r.look)}set look(e){if(e){const t=ne(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updateSectionsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise()}get type(){var e,t,s,a,l;return(l=(a=(s=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:s.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode]}getMinWidth(){var e,t,s,a;return((a=(s=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:s.minWidths)==null?void 0:a[this.indexXInNode])||io}getMinHeight(){var e,t,s,a;return((a=(s=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:s.minHeights)==null?void 0:a[this.indexYInNode])||oo}getPriority(){var e,t,s,a,l,o;return((o=(l=(a=(s=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:s.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode])==null?void 0:o.priority)||Me}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const t=this.ports.map(l=>l.distanceTo(e)),s=t.indexOf(Math.min(...t));return this.ports[s]}}}getIncomingConnections(e=!1){const t=[];for(const s of this.ports)for(const a of s.incomingConnections)!e&&a.removed||t.push(a);return t}getOutgoingConnections(e=!1){const t=[];for(const s of this.ports)for(const a of s.outgoingConnections)!e&&a.removed||t.push(a);return t}getConnections(e=!1){const t=[];for(const s of this.ports){for(const a of s.incomingConnections)!e&&a.removed||t.push(a);for(const a of s.outgoingConnections)!e&&a.removed||t.push(a)}return t}move(e){this.setGeometry({coords:e,width:this.width,height:this.height})}stretch(e,t){const s=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,o;switch(e){case k.Left:l=[s[0]-t,s[1]],o=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[0]=l[1]-this.getMinWidth());break;case k.Top:l=[s[0],s[1]],o=[a[0]-t,a[1]],o[1]-o[0]<this.getMinHeight()&&(o[0]=o[1]-this.getMinHeight());break;case k.Right:l=[s[0],s[1]+t],o=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[1]=l[0]+this.getMinWidth());break;case k.Bottom:l=[s[0],s[1]],o=[a[0],a[1]+t],o[1]-o[0]<this.getMinHeight()&&(o[1]=o[0]+this.getMinHeight());break}this.setGeometry({coords:[l[0],o[0]],width:l[1]-l[0],height:o[1]-o[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(e){const t=[this.coords[0],this.coords[0]+this.width],s=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const n of this.ports)n.move(Be(n.coords,t,s,a,l));const o=this.type;this.label&&(this.label.coords=[this.coords[0]+K(o==null?void 0:o.label),this.coords[1]+U(o==null?void 0:o.label)],this.label.width=this.width-K(o==null?void 0:o.label)-re(o==null?void 0:o.label),this.label.height=this.height-U(o==null?void 0:o.label)-oe(o==null?void 0:o.label),this.label.updateInView());for(const n of this.decorators)n.move(Be(n.coords,t,s,a,l));this.getConnections().forEach(n=>n.tighten()),this.updateInView()}}class ro extends ge{constructor(e){super(),this.model=e}new(e,t,s,a,l,o,n){var h,g,p,f,m,u,b,x,v,w;const r=new F(this.model,e,t,s,a,l,o,n);super.add(r),r.updateInView(),e.sections.push(r),e.updateInView();const d=(f=(p=(g=(h=e.type.sectionGrid)==null?void 0:h.sections)==null?void 0:g[s])==null?void 0:p[t])==null?void 0:f.ports;if(d&&d.length>0)for(let S=0;S<d.length;++S){const A=d[S],z=this.model.ports.new(A.type!==void 0?this.model.ports.types.get(A.type):void 0,r,[r.coords[0]+(A.coords[0]||0),r.coords[1]+(A.coords[1]||0)],A.connectionPoint!==void 0?[r.coords[0]+(A.connectionPoint[0]||0),r.coords[1]+(A.connectionPoint[1]||0)]:void 0,A==null?void 0:A.direction,`${r.id}_${S}`);if((m=z.type)!=null&&m.label){const N={...D,...(u=z.type)==null?void 0:u.label},_=6*N.fontSize+ze(N)+Re(N),P=N.fontSize+Ve(N)+Pe(N);let R;switch(z.direction){case k.Bottom:case k.Left:case k.Right:R=[z.coords[0]-_/2,z.coords[1]-P-oe(N)];break;case k.Top:R=[z.coords[0]-_/2,z.coords[1]+U(N)];break;default:R=z.coords}this.model.fields.new(z,R,N.fontSize,N.fontFamily,N.color,N.selectedColor,_,P,N.horizontalAlign,N.verticalAlign,"",N.editable,N.fit)}}const c=(w=(v=(x=(b=e.type.sectionGrid)==null?void 0:b.sections)==null?void 0:x[s])==null?void 0:v[t])==null?void 0:w.label;if(c){const S={...D,...c};this.model.fields.new(r,[r.coords[0]+K(S),r.coords[1]+U(S)],S.fontSize,S.fontFamily,S.color,S.selectedColor,r.width-K(S)-re(S),r.height-U(S)-oe(S),S.horizontalAlign,S.verticalAlign,"",S.editable,S.fit)}return r}remove(e){const t=this.get(e,!0);if(t){for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);t.label&&this.model.fields.remove(t.label.id),t.node&&Y(t.node.sections,t),super.remove(e),t.updateInView()}}}const pi={lookType:"shaped-look",shape:Ye.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},fe={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:pi,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Me,properties:[]};class yi{constructor(e){const t={...fe,...e};this.id=t.id,this.name=t.name,this.defaultWidth=t.defaultWidth,this.defaultHeight=t.defaultHeight,this.minWidth=t.minWidth,this.minHeight=t.minHeight,this.resizableX=t.resizableX,this.resizableY=t.resizableY,this.bottomPadding=lo(t),this.leftPadding=co(t),this.rightPadding=ho(t),this.topPadding=uo(t),this.label=t.label,this.ports=t.ports,this.decorators=t.decorators,this.sectionGrid=t.sectionGrid?new so(t.sectionGrid):null;const s=ne(t.look);this.defaultLook=s.defaultLook,this.selectedLook=s.selectedLook,this.highlightedLook=s.highlightedLook,this.selectedAndHighlightedLook=s.selectedAndHighlightedLook,this.isUnique=t.isUnique,this.canBeParentless=t.canBeParentless,this.childrenTypes=t.childrenTypes,this.priority=t.priority,this.propertySet=new We((e==null?void 0:e.properties)||[])}}class j extends Ie{constructor(e,t,s=[0,0],a){if(e.nodes.get(a)!==void 0)throw new Error(`DiagramNode with id "${a}" already exists`);if(!a)throw new Error("DiagramNode cannot have an empty or null id");super(e,a),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=t,this.valueSet=new ve(t.propertySet,this),this.originalData={},this.coords=s,this.width=t.defaultWidth,this.height=t.defaultHeight}get type(){return this._type}set type(e){var t,s;(s=(t=this.model.canvas)==null?void 0:t.userSelection)==null||s.openInPropertyEditor(void 0),this._type=e,this.valueSet&&(this.valueSet=new ve(e.propertySet,this)),this.updateInView()}get typeString(){return this.type.id}set typeString(e){const t=this.model.nodes.types.get(e);t&&(this.type=t)}get name(){var e;return((e=this.label)==null?void 0:e.text)||""}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(e){if(e){const t=ne(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get removed(){return this.selfRemoved}updateInView(){var e;(e=this.model.canvas)==null||e.updateNodesInView(this.id)}raise(){var e;(e=this.select())==null||e.raise();for(const t of this.sections)t.raise();this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise();for(const t of this.children)t.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const t=this.ports.map(l=>l.distanceTo(e)),s=t.indexOf(Math.min(...t));return this.ports[s]}}}getIncomingConnections(e=!1){const t=[];for(const s of this.ports)for(const a of s.incomingConnections)!e&&a.removed||t.push(a);return t}getOutgoingConnections(e=!1){const t=[];for(const s of this.ports)for(const a of s.outgoingConnections)!e&&a.removed||t.push(a);return t}getConnections(e=!1){const t=[];for(const s of this.ports){for(const a of s.incomingConnections)!e&&a.removed||t.push(a);for(const a of s.outgoingConnections)!e&&a.removed||t.push(a)}return t}getAdjacentNodes(e=!1){var s,a;const t=[];for(const l of this.ports){for(const o of l.incomingConnections){if(!e&&o.removed)continue;const n=(s=o.start)==null?void 0:s.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}for(const o of l.outgoingConnections){if(!e&&o.removed)continue;const n=(a=o.end)==null?void 0:a.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}}return t}getLastAncestor(){let e=this;for(;e.parent!==void 0;)e=e==null?void 0:e.parent;return e}isAncestorOf(e){let t=e;for(;t!==void 0;){if(this.id===t.id)return!0;t=t.parent}return!1}isDescendantOf(e){return e.isAncestorOf(this)}addChild(e){if(e.id===this.id)return;let t=this.parent,s=!1;for(;t!==void 0;){if(t.id===e.id){s=!0;break}t=t.parent}s||this.children.indexOf(e)>=0||(this.fitToChild(e),this.children.push(e),e.parent=this,e.raise())}removeChild(e){Y(this.children,e),e.parent=void 0}fitToChild(e){const t=this.coords[0]-e.coords[0]+this.type.leftPadding;t>=0&&this.stretch(k.Left,t);const s=this.coords[1]-e.coords[1]+this.type.topPadding;s>=0&&this.stretch(k.Top,s);const a=e.coords[0]+e.width-(this.coords[0]+this.width)+this.type.rightPadding;a>=0&&this.stretch(k.Right,a);const l=e.coords[1]+e.height-(this.coords[1]+this.height)+this.type.bottomPadding;l>=0&&this.stretch(k.Bottom,l),this.parent&&this.parent.fitToChild(this)}move(e){const t=[e[0]-this.coords[0],e[1]-this.coords[1]];for(const s of this.children)s.move([s.coords[0]+t[0],s.coords[1]+t[1]]);for(const s of this.sections)s.move([s.coords[0]+t[0],s.coords[1]+t[1]]);this.setGeometry({coords:e,width:this.width,height:this.height,sections:{},children:{}})}stretch(e,t){const s=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,o;switch(e){case k.Left:l=[s[0]-t,s[1]],o=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[0]=l[1]-this.type.minWidth);break;case k.Top:l=[s[0],s[1]],o=[a[0]-t,a[1]],o[1]-o[0]<this.type.minHeight&&(o[0]=o[1]-this.type.minHeight);break;case k.Right:l=[s[0],s[1]+t],o=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[1]=l[0]+this.type.minWidth);break;case k.Bottom:l=[s[0],s[1]],o=[a[0],a[1]+t],o[1]-o[0]<this.type.minHeight&&(o[1]=o[0]+this.type.minHeight);break}this.setGeometry({coords:[l[0],o[0]],width:l[1]-l[0],height:o[1]-o[0],sections:{},children:{}})}stretchSections(e,t,s,a){let l=Number.NEGATIVE_INFINITY;switch(e){case k.Bottom:for(const o of this.sections)o.indexYInNode===a&&(l=Math.max(l,o.getMinHeight()-o.height));t<l&&(t=l);for(const o of this.sections)o.indexYInNode===a?o.stretch(e,t):o.indexYInNode>a&&o.move([o.coords[0],o.coords[1]+t]);break;case k.Right:for(const o of this.sections)o.indexXInNode===s&&(l=Math.max(l,o.getMinWidth()-o.width));t<l&&(t=l);for(const o of this.sections)o.indexXInNode===s?o.stretch(e,t):o.indexXInNode>s&&o.move([o.coords[0]+t,o.coords[1]]);break;case k.Top:for(const o of this.sections)o.indexYInNode===a&&(l=Math.max(l,o.getMinHeight()-o.height));t<l&&(t=l);for(const o of this.sections)o.indexYInNode===a?o.stretch(e,t):o.indexYInNode<a&&o.move([o.coords[0],o.coords[1]-t]);break;case k.Left:for(const o of this.sections)o.indexXInNode===s&&(l=Math.max(l,o.getMinWidth()-o.width));t<l&&(t=l);for(const o of this.sections)o.indexXInNode===s?o.stretch(e,t):o.indexXInNode<s&&o.move([o.coords[0]-t,o.coords[1]]);break}this.stretch(e,t)}getGeometry(e){const t={};for(const a of this.sections)t[a.id]=a.getGeometry();const s={};for(const a of this.children)a.id!==e&&(s[a.id]=a.getGeometry(e));return{coords:[...this.coords],width:this.width,height:this.height,sections:t,children:s}}setGeometry(e){this.raise();const t=[this.coords[0],this.coords[0]+this.width],s=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const o of this.children){const n=e.children[o.id];n&&o.setGeometry(n)}for(const o of this.sections){const n=e.sections[o.id];n&&o.setGeometry(n)}for(const o of this.ports)o.move(Be(o.coords,t,s,a,l));this.label&&(this.label.coords=[this.coords[0]+K(this.type.label),this.coords[1]+U(this.type.label)],this.label.width=this.width-K(this.type.label)-re(this.type.label),this.label.height=this.height-U(this.type.label)-oe(this.type.label),this.label.updateInView());for(const o of this.decorators)o.move(Be(o.coords,t,s,a,l));this.getConnections().forEach(o=>o.tighten()),this.updateInView()}removeSectionColumn(e){var l;const t=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let s=0;const a=[...this.sections];for(const o of a)o.indexYInNode===e&&(s=Math.max(s,o.width),this.model.sections.remove(o.id));for(const o of a)o.indexYInNode>e&&(--o.indexYInNode,o.move([o.coords[0]-s-t,o.coords[1]]));this.stretch(k.Right,-t-s)}removeSectionRow(e){var l;const t=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let s=0;const a=[...this.sections];for(const o of a)o.indexXInNode===e&&(s=Math.max(s,o.height),this.model.sections.remove(o.id));for(const o of a)o.indexYInNode>e&&(--o.indexXInNode,o.move([o.coords[0],o.coords[1]-s-t]));this.stretch(k.Bottom,-t-s)}copySectionColumn(e){var l;const t=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let s=0;const a=[...this.sections];for(const o of a)if(o.indexXInNode===e){s=Math.max(s,o.width);let n=o.indexXInNode+1;for(;this.model.sections.get(`${o.id}_copy_${n}_${o.indexYInNode}`,!0)!==void 0;)++n;this.model.sections.new(this,o.indexXInNode+1,o.indexYInNode,[o.coords[0]+o.width+t,o.coords[1]],o.width,o.height,`${o.id}_copy_${n}_${o.indexYInNode}`)}for(const o of a)o.indexXInNode>e&&(++o.indexXInNode,o.move([o.coords[0]+s+t,o.coords[1]]));this.stretch(k.Right,t+s)}copySectionRow(e){var l;const t=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let s=0;const a=[...this.sections];for(const o of a)if(o.indexYInNode===e){s=Math.max(s,o.height);let n=o.indexYInNode+1;for(;this.model.sections.get(`${o.id}_copy_${o.indexXInNode}_${n}`,!0)!==void 0;)++n;this.model.sections.new(this,o.indexXInNode,o.indexYInNode+1,[o.coords[0],o.coords[1]+o.height+t],o.width,o.height,`${o.id}_copy_${o.indexXInNode}_${n}`)}for(const o of a)o.indexYInNode>e&&(++o.indexYInNode,o.move([o.coords[0],o.coords[1]+s+t]));this.stretch(k.Bottom,t+s)}}class ao extends ge{constructor(e){super(),this.types=new Xe,this.model=e}new(e,t,s){var o,n,r,d,c,h,g;let a;if(e instanceof yi)a=e;else{const p=this.types.get(e);if(p===void 0)throw new TypeError(`Node type with id '${e}' could not be found.`);a=p}const l=new j(this.model,a,t,s);if(super.add(l),l.updateInView(),a.sectionGrid!==null){let p=l.coords[1]+(a.sectionGrid.margin||0);for(let f=0;f<a.sectionGrid.sections.length;++f){let m=l.coords[0]+(a.sectionGrid.margin||0);for(let u=0;u<a.sectionGrid.sections[f].length;++u)this.model.sections.new(l,u,f,[m,p],((o=a.sectionGrid.defaultWidths)==null?void 0:o[u])||si,((n=a.sectionGrid.defaultHeights)==null?void 0:n[f])||ni,`${l.id}_${f}_${u}`),m+=(((r=a.sectionGrid.defaultWidths)==null?void 0:r[u])||si)+(a.sectionGrid.margin||0);p+=(((d=a.sectionGrid.defaultHeights)==null?void 0:d[f])||ni)+(a.sectionGrid.margin||0)}}if(a.ports.length>0)for(let p=0;p<a.ports.length;++p){const f=a.ports[p],m=f.type!==void 0?this.model.ports.types.get(f.type):void 0,u=this.model.ports.new(m,l,[l.coords[0]+f.coords[0],l.coords[1]+f.coords[1]],f.connectionPoint!==void 0?[l.coords[0]+(f.connectionPoint[0]||0),l.coords[1]+(f.connectionPoint[1]||0)]:void 0,f.direction,`${l.id}_port_${p}`);if((c=u.type)!=null&&c.label){const b={...D,...(h=u.type)==null?void 0:h.label},x=6*b.fontSize+ze(b)+Re(b),v=b.fontSize+Ve(b)+Pe(b);let w;switch(u.direction){case k.Bottom:case k.Left:case k.Right:w=[u.coords[0]-x/2,u.coords[1]-v-oe(b)];break;case k.Top:w=[u.coords[0]-x/2,u.coords[1]+U(b)];break;default:w=u.coords}this.model.fields.new(u,w,b.fontSize,b.fontFamily,b.color,b.selectedColor,x,v,b.horizontalAlign,b.verticalAlign,"",b.editable,b.fit)}}if(a.label){const p={...D,...a.label};this.model.fields.new(l,[l.coords[0]+K(p),l.coords[1]+U(p)],p.fontSize,p.fontFamily,p.color,p.selectedColor,l.width-K(p)-re(p),l.height-U(p)-oe(p),p.horizontalAlign,p.verticalAlign,"",p.editable,p.fit)}if(a.decorators.length>0)for(let p=0;p<a.decorators.length;++p){const f=a.decorators[p];this.model.decorators.new(l,[l.coords[0]+f.coords[0],l.coords[1]+f.coords[1]],f.width,f.height,l.getPriority(),f.html,`${l.id}_decorator_${p}`)}return l.valueSet.resetValues(),(g=l.model.canvas)==null||g.fitNodeInView(l.id),l}remove(e){const t=this.get(e,!0);if(t){for(t.parent&&Y(t.parent.children,t);t.children.length>0;)this.model.nodes.remove(t.children[0].id);for(;t.sections.length>0;)this.model.sections.remove(t.sections[0].id);for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);for(;t.decorators.length>0;)this.model.decorators.remove(t.decorators[0].id);t.label&&this.model.fields.remove(t.label.id),super.remove(e),t.updateInView()}}getAtCoordinates(e,t){const s=[];for(const a of this)a.coords[0]<e&&e<a.coords[0]+a.width&&a.coords[1]<t&&t<a.coords[1]+a.height&&s.push(a);return s}}const bi=i=>{for(let e=0;e<i.length;++e)for(let t=0;t<i.length;++t)t!==e&&i[t].isAncestorOf(i[e])&&(i.splice(t,1),--t,e>t&&--e);return i},lo=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?fe.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?fe.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),co=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?fe.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?fe.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],ho=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?fe.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?fe.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),uo=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?fe.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?fe.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),vi={lookType:"shaped-look",shape:Ye.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},De=ne(vi),ki={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:vi};class fo{constructor(e){const t={...ki,...e};this.id=t.id,this.name=t.name,this.label=t.label,this.allowsOutgoing=t.allowsOutgoing,this.allowsIncoming=t.allowsIncoming,this.width=t.width;const s=ne(t.look);this.defaultLook=s.defaultLook,this.selectedLook=s.selectedLook,this.highlightedLook=s.highlightedLook,this.selectedAndHighlightedLook=s.selectedAndHighlightedLook}}class ke extends Ie{constructor(e,t,s,a,l,o,n){if(e.ports.get(n)!==void 0)throw new Error(`DiagramPort with id "${n}" already exists`);if(!n)throw new Error("DiagramPort cannot have an empty or null id");super(e,n),this.outgoingConnections=[],this.incomingConnections=[],this._type=t,this.rootElement=s,this.coords=a,this.connectionPoint=l||a,this.direction=o}get type(){return this._type}set type(e){this._type=e,this.updateInView()}get typeString(){var e;return(e=this.type)==null?void 0:e.id}set typeString(e){if(e===void 0)this.type=void 0;else{const t=this.model.ports.types.get(e);t&&(this.type=t)}}get allowsOutgoing(){var e,t;return((e=this.type)==null?void 0:e.allowsOutgoing)!==void 0?(t=this.type)==null?void 0:t.allowsOutgoing:!0}get allowsIncoming(){var e,t;return((e=this.type)==null?void 0:e.allowsIncoming)!==void 0?(t=this.type)==null?void 0:t.allowsIncoming:!0}get name(){var e;return((e=this.label)==null?void 0:e.text)||""}set name(e){this.label&&(this.label.text=e)}get look(){var e,t,s,a;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(e=this.type||De)==null?void 0:e.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(t=this.type||De)==null?void 0:t.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(s=this.type||De)==null?void 0:s.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(a=this.type||De)==null?void 0:a.defaultLook}set look(e){if(e){const t=ne(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get width(){var e;return((e=this.type)==null?void 0:e.width)||ki.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updatePortsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise(),this.label&&this.label.raise();for(const t of this.incomingConnections)t.raise();for(const t of this.outgoingConnections)t.raise()}startConnection(e){this.outgoingConnections.push(e)}finishConnection(e){this.incomingConnections.push(e)}getNode(){if(this.rootElement instanceof j)return this.rootElement;if(this.rootElement instanceof F)return this.rootElement.node}getPriority(){var e;return((e=this.rootElement)==null?void 0:e.getPriority())||Me}move(e){const t=[e[0]-this.coords[0],e[1]-this.coords[1]];this.coords=e,this.connectionPoint[0]=this.connectionPoint[0]+t[0],this.connectionPoint[1]=this.connectionPoint[1]+t[1];for(const s of this.outgoingConnections)s.setStart(this);for(const s of this.incomingConnections)s.setEnd(this);this.label&&this.label.move([this.label.coords[0]+t[0],this.label.coords[1]+t[1]]),this.updateInView()}distanceTo(e){return ci(this.coords,e)}}class go extends ge{constructor(e){super(),this.types=new Xe,this.model=e}new(e,t,s,a,l,o){const n=new ke(this.model,e,t,s,a,l,o);return super.add(n),n.updateInView(),t!==void 0&&t.ports.push(n),n}remove(e){const t=this.get(e,!0);if(t){for(;t.outgoingConnections.length>0;)this.model.connections.remove(t.outgoingConnections[0].id);for(;t.incomingConnections.length>0;)this.model.connections.remove(t.incomingConnections[0].id);t.label&&this.model.fields.remove(t.label.id),(t.rootElement instanceof j||t.rootElement instanceof F)&&Y(t.rootElement.ports,t),super.remove(e),t.updateInView()}}}class wi{import(e,t){e.clear(),t.id&&(e.id=t.id),e.name=t.name,e.description=t.description,e.type=t.type,e.createdAt=new Date(t.createdAt),e.updatedAt=new Date(t.updatedAt);for(const s of t.nodes||[])this.importNode(e,s);for(const s of t.connections||[])this.importConnection(e,s);return t.data&&e.valueSet.setValues(t.data),t.collabMeta&&(e.logicalClock=t.collabMeta.logicalClock,e.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),e}importNode(e,t){var a,l,o,n,r,d,c,h,g,p;const s=e.nodes.types.get(t.type);if(s){const f=new j(e,s,t.coords,t.id);if(e.nodes.add(f),f.width=t.width,f.height=t.height,t.label){if(s.decorators)for(let u=0;u<s.decorators.length;++u){const b=s.decorators[u];e.decorators.new(f,[f.coords[0]+b.coords[0],f.coords[1]+b.coords[1]],b.width,b.height,f.getPriority(),b.html,`${f.id}_decorator_${u}`)}if(s.label){const u={...D,...s.label},b=new ue(e,f,[f.coords[0]+K(u),f.coords[1]+U(u)],f.width-K(u)-re(u),f.height-U(u)-oe(u),u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,"",u.editable,u.fit);b.text=t.label,f.label=b,e.fields.add(b),b.updateInView()}}for(const u of t.children||[]){const b=this.importNode(e,u);b!==void 0&&((a=f.children)==null||a.push(b),b.parent=f)}for(const u of t.sections||[]){const b=new F(e,f,u.indexXInNode,u.indexYInNode,u.coords,u.width,u.height,u.id);if((l=f.sections)==null||l.push(b),e.sections.add(b),u.label&&(d=(r=(n=(o=s.sectionGrid)==null?void 0:o.sections)==null?void 0:n[u.indexYInNode])==null?void 0:r[u.indexXInNode])!=null&&d.label){const v={...D,...(p=(g=(h=(c=s.sectionGrid)==null?void 0:c.sections)==null?void 0:h[u.indexYInNode])==null?void 0:g[u.indexXInNode])==null?void 0:p.label},w=new ue(e,b,[b.coords[0]+K(v),b.coords[1]+U(v)],b.width-K(v)-re(v),b.height-U(v)-oe(v),v.fontSize,v.fontFamily,v.color,v.selectedColor,v.horizontalAlign,v.verticalAlign,"",v.editable,v.fit);w.text=u.label,b.label=w,e.fields.add(w),w.updateInView()}let x=0;for(const v of u.ports||[]){const w=v.type!==void 0?e.ports.types.get(v.type):void 0,S=new ke(e,w,b,v.coords,v.connectionPoint,v.direction,v.id);if(b.ports.push(S),e.ports.add(S),v.label){if(s.ports.length>x&&(w!=null&&w.label)){const A={...D,...w==null?void 0:w.label};let z;switch(S.direction){case k.Top:case k.Left:z=[S.coords[0]-A.fontSize,S.coords[1]-A.fontSize];break;case k.Bottom:z=[S.coords[0]-A.fontSize,S.coords[1]+A.fontSize];break;case k.Right:z=[S.coords[0]+A.fontSize,S.coords[1]-A.fontSize];break;default:z=S.coords}const N=new ue(e,S,z,A.fontSize,A.fontSize,A.fontSize,A.fontFamily,A.color,A.selectedColor,A.horizontalAlign,A.verticalAlign,"",A.editable,A.fit);N.text=v.label,S.label=N,e.fields.add(N),N.updateInView()}++x}v.collabMeta&&(S.selfRemoved=v.collabMeta.selfRemoved,S.selfRemovedTimestamp=v.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(S.label,v.collabMeta.label)),S.updateInView()}u.collabMeta&&(b.selfRemoved=u.collabMeta.selfRemoved,b.selfRemovedTimestamp=u.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(b.label,u.collabMeta.label)),b.updateInView()}let m=0;for(const u of t.ports||[]){const b=u.type!==void 0?e.ports.types.get(u.type):void 0,x=new ke(e,b,f,u.coords,u.connectionPoint,u.direction,u.id);if(f.ports.push(x),e.ports.add(x),u.label){if(s.ports.length>m&&(b!=null&&b.label)){const v={...D,...b==null?void 0:b.label};let w;switch(x.direction){case k.Top:case k.Left:w=[x.coords[0]-v.fontSize,x.coords[1]-v.fontSize];break;case k.Bottom:w=[x.coords[0]-v.fontSize,x.coords[1]+v.fontSize];break;case k.Right:w=[x.coords[0]+v.fontSize,x.coords[1]-v.fontSize];break;default:w=x.coords}const S=new ue(e,x,w,v.fontSize,v.fontSize,v.fontSize,v.fontFamily,v.color,v.selectedColor,v.horizontalAlign,v.verticalAlign,"",v.editable,v.fit);S.text=u.label,x.label=S,e.fields.add(S),S.updateInView()}++m}u.collabMeta&&(x.selfRemoved=u.collabMeta.selfRemoved,x.selfRemovedTimestamp=u.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(x.label,u.collabMeta.label)),x.updateInView()}return t.data&&f.valueSet.setValues(t.data),t.collabMeta&&(f.selfRemoved=t.collabMeta.selfRemoved,f.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,f.geometryTimestamp=t.collabMeta.geometryTimestamp,this.importLabelCollabMeta(f.label,t.collabMeta.label),f.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),f.updateInView(),f.raise(),f}}importConnection(e,t){const s=e.connections.types.get(t.type);if(s){const a=new de(e,s,t.start?e.ports.get(t.start):void 0,t.end?e.ports.get(t.end):void 0,t.id);return e.connections.add(a),a.startLabel=t.startLabel,a.middleLabel=t.middleLabel,a.endLabel=t.endLabel,a.points=t.points,t.data&&a.valueSet.setValues(t.data),t.collabMeta&&(a.selfRemoved=t.collabMeta.selfRemoved,a.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,a.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),a.updateInView(),a.raise(),a}}importLabelCollabMeta(e,t){e&&t&&(e.selfRemoved=t.selfRemoved,e.selfRemovedTimestamp=t.selfRemovedTimestamp,e.textTimestamp=t.textTimestamp)}}class Ze{constructor(e,t,s,a,l,o,n){this.canvas=e,this.id=t,this.typeId=s,this.coords=a,this.parentId=l,this.label=o,this.values=n}do(){var t;const e=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&((t=this.canvas.model.nodes.get(this.parentId))==null||t.addChild(e)),this.values!==void 0&&e.valueSet.setValues(structuredClone({...e.valueSet.getValues(),...this.values})),e.label&&(e.label.text=this.label||"")}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(e,t){return new Ze(e,t.id,t.typeId,t.coords,t.parentId,t.label,t.values)}}class ft{constructor(e,t,s,a,l,o,n){this.canvas=e,this.nodeId=t,this.copyColumnIndex=s,this.copyRowIndex=a,this.removeColumnIndex=l,this.removeRowIndex=o,this.timestamp=n}do(){const e=this.canvas.model.nodes.get(this.nodeId);e&&we(this.timestamp,e.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&e.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&e.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&e.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&e.removeSectionRow(this.removeRowIndex),e.geometryTimestamp=this.timestamp)}serialize(){return{type:"addSection",nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(e,t){return new ft(e,t.nodeId,t.copyColumnIndex,t.copyRowIndex,t.removeColumnIndex,t.removeRowIndex,t.timestamp)}}class gt{constructor(e,t,s){this.canvas=e,this.to=t,this.timestamp=s}do(){for(const e in this.to){const t=this.canvas.model.nodes.get(e,!0);if(t&&we(this.timestamp,t.geometryTimestamp)){const s=this.to[e];t.move([s[0],s[1]]),t.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new gt(e,t.to,t.timestamp)}}class _e{constructor(e,t,s,a){this.canvas=e,this.nodeIds=t,this.delta=s,this.timestamp=a}do(){var e;for(const t of this.nodeIds){const s=this.canvas.model.nodes.get(t,!0);s&&we(this.timestamp,s.geometryTimestamp)&&(s.move([s.coords[0]+this.delta[0],s.coords[1]+this.delta[1]]),(e=s.parent)==null||e.fitToChild(s),s.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(e,t){return new _e(e,t.nodeIds,t.delta,t.timestamp)}}class se{constructor(e,t,s,a){this.canvas=e,this.nodeId=t,this.to=s,this.timestamp=a}do(){var t,s,a;const e=this.canvas.model.nodes.get(this.nodeId,!0);if(e&&we(this.timestamp,e.geometryTimestamp)){e.setGeometry(this.to),(t=e.label)!=null&&t.fit&&this.canvas.fitFieldRootInView(e.label.id);for(const l of e.sections)(s=l.label)!=null&&s.fit&&this.canvas.fitFieldRootInView(l.label.id);(a=e.parent)==null||a.fitToChild(e),e.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new se(e,t.nodeId,t.to,t.timestamp)}}class je{constructor(e,t,s,a,l){this.canvas=e,this.childId=t,this.parentId=s,this.childGeometry=a,this.timestamp=l}do(){var s;const e=this.canvas.model.nodes.get(this.childId,!0),t=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;e&&(this.parentId===void 0||t)&&we(this.timestamp,e.geometryTimestamp)&&((s=e.parent)==null||s.removeChild(e),e.setGeometry(this.childGeometry),t==null||t.addChild(e))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(e,t){return new je(e,t.childId,t.parentId,t.childGeometry,t.timestamp)}}class Ke{constructor(e,t,s,a,l){this.canvas=e,this.id=t,this.typeId=s,this.startId=a,this.endId=l}do(){const e=this.canvas.model.ports.get(this.startId,!0),t=this.canvas.model.ports.get(this.endId,!0);e&&t&&this.canvas.model.connections.new(this.typeId,e,t,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(e,t){return new Ke(e,t.id,t.typeId,t.startId,t.endId)}}class Le{constructor(e,t,s,a){this.canvas=e,this.fieldId=t,this.to=s,this.timestamp=a}do(){const e=this.canvas.model.fields.get(this.fieldId,!0);e&&we(this.timestamp,e.textTimestamp)&&(e.text=this.to,e.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new Le(e,t.fieldId,t.to,t.timestamp)}}class $e{constructor(e,t,s,a){this.canvas=e,this.id=t,this.to=s,this.timestamp=a}getValueSet(){var e;return this.id===void 0?this.canvas.model.valueSet:(e=this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))==null?void 0:e.valueSet}do(){var e;(e=this.getValueSet())==null||e.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new $e(e,t.id,t.to,t.timestamp)}}class ae{constructor(e,t,s,a,l,o,n,r){this.canvas=e,this.nodeIds=t,this.sectionIds=s,this.portIds=a,this.connectionIds=l,this.fieldIds=o,this.selfRemoved=n,this.timestamp=r}doOne(e){e&&we(this.timestamp,e.selfRemovedTimestamp)&&(e.selfRemoved=this.selfRemoved,e.selfRemovedTimestamp=this.timestamp)}do(){for(const e of this.nodeIds)this.doOne(this.canvas.model.nodes.get(e,!0));for(const e of this.sectionIds)this.doOne(this.canvas.model.sections.get(e,!0));for(const e of this.portIds)this.doOne(this.canvas.model.ports.get(e,!0));for(const e of this.connectionIds)this.doOne(this.canvas.model.connections.get(e,!0));for(const e of this.fieldIds)this.doOne(this.canvas.model.fields.get(e,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(e,t){return new ae(e,t.nodeIds,t.sectionIds,t.portIds,t.connectionIds,t.fieldIds,t.removed,t.timestamp)}}class qe{constructor(e,t,s){this.canvas=e,this.nodes=t,this.connections=s}do(){const e=new wi;this.canvas.userSelection.clear();for(const t of this.nodes){const s=e.importNode(this.canvas.model,t);s&&this.canvas.userSelection.add(s)}for(const t of this.connections){const s=e.importConnection(this.canvas.model,t);s&&this.canvas.userSelection.add(s)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(e,t){return new qe(e,t.nodes,t.connections)}}class mo{constructor(e){this.isInRoom=!1,this.canvas=e,this.replicaId=ii()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+ii()}doCollaboratively(e){if(e.do(),this.onSend){const t=e.serialize();this.onSend(t)}}receive(e){switch("timestamp"in e&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,e.timestamp[0])),e.type){case"addNode":{Ze.deserialize(this.canvas,e).do();break}case"addSection":{ft.deserialize(this.canvas,e).do();break}case"applyLayout":{gt.deserialize(this.canvas,e).do();break}case"move":{_e.deserialize(this.canvas,e).do();break}case"setGeometry":{se.deserialize(this.canvas,e).do();break}case"setParent":{je.deserialize(this.canvas,e).do();break}case"addConnection":{Ke.deserialize(this.canvas,e).do();break}case"editField":{Le.deserialize(this.canvas,e).do();break}case"updateValues":{$e.deserialize(this.canvas,e).do();break}case"setSelfRemoved":{ae.deserialize(this.canvas,e).do();break}case"paste":{qe.deserialize(this.canvas,e).do();break}default:console.error("Unknown CollabAction type, skipping:",e)}}}class po{constructor(e,t){this.canvas=e,this.maximum=t,this.history=[],this.index=0}add(e){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(e)):(this.history.push(e),++this.index),this.canvas.diagramChange$.next({action:e,method:0})}undo(){let e;if(this.index>0){let t;do--this.index,e=this.history[this.index],t=e.undo();while(!t&&this.index>0)}this.canvas.diagramChange$.next({action:e,method:1})}redo(){let e;if(this.index<this.history.length){let t;do e=this.history[this.index],t=e.redo(),++this.index;while(!t&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:e,method:2})}}var C=(i=>(i.AddConnection="add-connection",i.AddNode="add-node",i.AddSectionAction="add-section",i.ApplyLayout="apply-layout",i.Clipboard="clipboard",i.ContextMenu="context-menu",i.EditField="edit-field",i.MoveNode="move-node",i.Paste="paste",i.Remove="remove",i.StretchNode="stretch-node",i.StretchSection="stretch-section",i.UpdateValues="update-values",i.Zoom="zoom",i))(C||{});class yo{constructor(e,t,s,a,l,o,n,r,d){this.canvas=e,this.type=t,this.coords=s,this.parentId=a,this.ancestorId=l,this.fromAncestorGeometry=o,this.toAncestorGeometry=n,this.label=r,this.values=d,this.id=this.canvas.collabEngine.freshId()}do(){const e=new Ze(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const t=new se(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return!0}undo(){const e=this.canvas.model.nodes.get(this.id),t=new ae(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const s=new se(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return e!==void 0}redo(){const e=this.canvas.model.nodes.get(this.id),t=new ae(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const s=new se(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return e===void 0}}class it{constructor(e,t,s){this.canvas=e,this.nodeIds=t,this.delta=s}do(){const e=new _e(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(t=>this.canvas.model.nodes.get(t)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const e=new _e(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(t=>this.canvas.model.nodes.get(t)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class W{constructor(e,t,s,a,l,o,n,r){this.canvas=e,this.intent=t,this.nodeId=s,this.from=a,this.to=l,this.ancestorId=o,this.fromAncestorGeometry=n,this.toAncestorGeometry=r}do(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){const t=new se(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const s=new se(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}}return e!==void 0}undo(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){this.to=e.getGeometry();const t=new se(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const s=new se(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}}return e!==void 0}redo(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){this.from=e.getGeometry();const t=new se(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}}class bo{constructor(e,t,s,a,l,o,n,r,d){this.canvas=e,this.childId=t,this.fromParentId=s,this.toParentId=a,this.fromChildGeometry=l,this.toChildGeometry=o,this.ancestorId=n,this.fromAncestorGeometry=r,this.toAncestorGeometry=d}do(){const e=this.canvas.model.nodes.get(this.childId),t=new je(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const s=new se(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return e!==void 0}undo(){const e=this.canvas.model.nodes.get(this.childId),t=new je(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const s=new se(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return e!==void 0}redo(){return this.do()}}class ot{constructor(e,t,s,a){this.canvas=e,this.type=t,this.startId=s,this.endId=a,this.id=this.canvas.collabEngine.freshId()}do(){const e=new Ke(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){const e=this.canvas.model.connections.get(this.id),t=new ae(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}redo(){const e=this.canvas.model.connections.get(this.id),t=new ae(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e===void 0}}class ri{constructor(e,t,s,a){this.canvas=e,this.fieldId=t,this.from=s,this.to=a}do(){const e=this.canvas.model.fields.get(this.fieldId),t=new Le(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}undo(){const e=this.canvas.model.fields.get(this.fieldId);if(e){this.to=e.text;const t=new Le(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}redo(){const e=this.canvas.model.fields.get(this.fieldId);if(e){this.from=e.text;const t=new Le(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}}class vo{constructor(e,t,s,a){this.canvas=e,this.id=t,this.from=s,this.to=a}do(){const e=new $e(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){const e=new $e(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.to=t.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}redo(){const e=new $e(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.from=t.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}}class ko{constructor(e,t,s,a,l,o){this.canvas=e,this.nodeIds=t,this.sectionIds=s,this.portIds=a,this.connectionIds=l,this.fieldIds=o}do(){const e=this.nodeIds.map(s=>this.canvas.model.nodes.get(s)!==void 0).includes(!0)||this.sectionIds.map(s=>this.canvas.model.sections.get(s)!==void 0).includes(!0)||this.portIds.map(s=>this.canvas.model.ports.get(s)!==void 0).includes(!0)||this.connectionIds.map(s=>this.canvas.model.connections.get(s)!==void 0).includes(!0)||this.fieldIds.map(s=>this.canvas.model.fields.get(s)!==void 0).includes(!0),t=new ae(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}undo(){const e=this.nodeIds.map(s=>this.canvas.model.nodes.get(s)===void 0).includes(!0)||this.sectionIds.map(s=>this.canvas.model.sections.get(s)===void 0).includes(!0)||this.portIds.map(s=>this.canvas.model.ports.get(s)===void 0).includes(!0)||this.connectionIds.map(s=>this.canvas.model.connections.get(s)===void 0).includes(!0)||this.fieldIds.map(s=>this.canvas.model.fields.get(s)===void 0).includes(!0),t=new ae(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){return this.do()}}class wo{constructor(e,t,s,a){this.canvas=e,this.nodes=t,this.connections=s,this.coords=a}do(){const e=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const l of this.nodes)l.coords[0]<e[0]&&(e[0]=l.coords[0]),l.coords[1]<e[1]&&(e[1]=l.coords[1]);const t=this.coords!==void 0?[this.coords[0]-e[0],this.coords[1]-e[1]]:void 0,s={};for(const l of this.nodes){const o=l.id,n=this.canvas.collabEngine.freshId();if(s[o]=n,l.id=n,t&&(l.coords=[l.coords[0]+t[0],l.coords[1]+t[1]]),l.sections)for(const r of l.sections){const d=r.id;if(r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),s[d]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]]),r.ports)for(const c of r.ports){const h=c.id;c.id.includes(l.id)?c.id=c.id.replace(l.id,n):c.id=this.canvas.collabEngine.freshId(),s[h]=c.id,t&&(c.coords=[c.coords[0]+t[0],c.coords[1]+t[1]])}}if(l.ports)for(const r of l.ports){const d=r.id;r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),s[d]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]])}}for(const l of this.connections){const o=this.canvas.collabEngine.freshId();if(s[l.id]=o,l.id=o,l.start=s[l.start]||l.start,l.end=s[l.end]||l.end,t)for(let n=0;n<l.points.length;++n)l.points[n]=[l.points[n][0]+t[0],l.points[n][1]+t[1]]}const a=new qe(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(a),!0}undo(){const e=this.nodes.map(s=>this.canvas.model.nodes.get(s.id)!==void 0).includes(!0)||this.connections.map(s=>this.canvas.model.connections.get(s.id)!==void 0).includes(!0),t=new ae(this.canvas,this.nodes.map(s=>s.id),[],[],this.connections.map(s=>s.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){const e=this.nodes.map(s=>this.canvas.model.nodes.get(s.id)===void 0).includes(!0)||this.connections.map(s=>this.canvas.model.connections.get(s.id)===void 0).includes(!0),t=new ae(this.canvas,this.nodes.map(s=>s.id),[],[],this.connections.map(s=>s.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}}class Je{constructor(e){this.type=e,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var xi=(i=>(i[i.DoubleClick=0]="DoubleClick",i[i.SecondaryClick=1]="SecondaryClick",i[i.Selection=2]="Selection",i[i.Highlight=3]="Highlight",i))(xi||{});class pe extends Je{constructor(e,t,s){super(0),this.cause=e,this.target=t,this.coords=s}}class ye extends Je{constructor(e,t,s){super(1),this.cause=e,this.target=t,this.coords=s}}class G extends Je{constructor(e,t){super(2),this.targets=e,this.selected=t}}class ie extends Je{constructor(e){super(3),this.target=e}}class Ci extends Ie{constructor(e,t,s,a,l,o,n,r){if(e.objects.get(r)!==void 0)throw new Error(`DiagramDecorator with id "${r}" already exists`);if(!r)throw new Error("DiagramDecorator cannot have an empty or null id");super(e,r),this.rootElement=t,this.coords=s,this.width=a,this.height=l,this.priority=o,this.html=n}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var e;(e=this.model.canvas)==null||e.updateDecoratorsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}}class xo extends ge{constructor(e){super(),this.model=e}new(e,t,s,a,l,o,n){const r=new Ci(this.model,e,t,s,a,l,o,n);return super.add(r),r.updateInView(),e!==void 0&&e.decorators.push(r),r}remove(e){const t=this.get(e,!0);t&&((t.rootElement instanceof j||t.rootElement instanceof F)&&Y(t.rootElement.decorators,t),super.remove(e),t.updateInView())}}class Co extends Ie{constructor(e,t,s,a,l,o,n){if(e.objects.get(n)!==void 0)throw new Error(`DiagramObject with id "${n}" already exists`);if(!n)throw new Error("DiagramObject cannot have an empty or null id");super(e,n),this.coords=t,this.width=s,this.height=a,this.priority=l,this.html=o}get removed(){return this.selfRemoved}updateInView(){var e;(e=this.model.canvas)==null||e.updateObjectsInView(this.id)}raise(){var e;(e=this.select())==null||e.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}}class So extends ge{constructor(e){super(),this.model=e}new(e,t,s,a,l,o){const n=new Co(this.model,e,t,s,a,l,o);return super.add(n),n.updateInView(),n}remove(e){const t=this.get(e,!0);t&&(super.remove(e),t.updateInView())}}class Si{constructor(e,t,s,a,l,o=[]){this.nodes=new ao(this),this.sections=new ro(this),this.ports=new go(this),this.connections=new eo(this),this.fields=new to(this),this.objects=new So(this),this.decorators=new xo(this),this.canvas=e,this.id=t,this.name=s,this.description=a,this.type=l,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new ve(new We(o),this)}clear(){var e,t;(e=this.canvas)==null||e.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),(t=this.canvas)==null||t.updateModelInView()}}const be=i=>!!i.button,st=(i,e,t,s,a,l,o,n)=>_i(i,[e,t],s,a,Math.max(10,o||0,n||0)*l),I=i=>{i?L.select("body").style("cursor",i):L.select("body").style("cursor",$.Auto)},he=i=>i instanceof j?i:i instanceof F?i.node||i:i.rootElement instanceof j||i.rootElement instanceof F||i.rootElement instanceof ke?he(i.rootElement):i,nt=i=>{i.filter(".shaped-look").append("path"),i.filter(".image-look").append("image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none")},rt=i=>{i.filter(".shaped-look").select("path").attr("d",e=>dt(e.look.shape,0,0,e.width,e.height)).attr("fill",e=>e.look.fillColor).attr("stroke",e=>e.look.borderColor).attr("stroke-width",e=>`${e.look.borderThickness}px`),i.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",e=>e.width).attr("height",e=>e.height).attr("href",e=>e.look.backgroundImage),i.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",e=>e.look.leftMargin).attr("height",e=>e.look.topMargin).attr("href",e=>e.look.backgroundImageTopLeft),i.filter(".stretchable-image-look").select("image.top-image").attr("x",e=>e.look.leftMargin).attr("y",0).attr("width",e=>e.width-e.look.rightMargin-e.look.leftMargin).attr("height",e=>e.look.topMargin).attr("href",e=>e.look.backgroundImageTop),i.filter(".stretchable-image-look").select("image.top-right-image").attr("x",e=>e.width-e.look.rightMargin).attr("y",0).attr("width",e=>e.look.rightMargin).attr("height",e=>e.look.topMargin).attr("href",e=>e.look.backgroundImageTopRight),i.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",e=>e.look.topMargin).attr("width",e=>e.look.leftMargin).attr("height",e=>e.height-e.look.bottomMargin-e.look.topMargin).attr("href",e=>e.look.backgroundImageLeft),i.filter(".stretchable-image-look").select("image.center-image").attr("x",e=>e.look.leftMargin).attr("y",e=>e.look.topMargin).attr("width",e=>e.width-e.look.rightMargin-e.look.leftMargin).attr("height",e=>e.height-e.look.bottomMargin-e.look.topMargin).attr("href",e=>e.look.backgroundImageCenter),i.filter(".stretchable-image-look").select("image.right-image").attr("x",e=>e.width-e.look.rightMargin).attr("y",e=>e.look.topMargin).attr("width",e=>e.look.rightMargin).attr("height",e=>e.height-e.look.bottomMargin-e.look.topMargin).attr("href",e=>e.look.backgroundImageRight),i.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",e=>e.height-e.look.bottomMargin).attr("width",e=>e.look.leftMargin).attr("height",e=>e.look.bottomMargin).attr("href",e=>e.look.backgroundImageBottomLeft),i.filter(".stretchable-image-look").select("image.bottom-image").attr("x",e=>e.look.leftMargin).attr("y",e=>e.height-e.look.bottomMargin).attr("width",e=>e.width-e.look.rightMargin-e.look.leftMargin).attr("height",e=>e.look.bottomMargin).attr("href",e=>e.look.backgroundImageBottom),i.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",e=>e.width-e.look.rightMargin).attr("y",e=>e.height-e.look.bottomMargin).attr("width",e=>e.look.rightMargin).attr("height",e=>e.look.bottomMargin).attr("href",e=>e.look.backgroundImageBottomRight)},Ne={enabled:!0,style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Io=(i,e,t)=>{const s=e.append("defs");if(i.gridSize>0&&isFinite(i.gridSize)){const a=s.append("pattern").attr("id",t).attr("x",-i.gridSize/2).attr("y",-i.gridSize/2).attr("width",i.gridSize).attr("height",i.gridSize).attr("patternUnits","userSpaceOnUse");switch(a.append("rect").attr("x",0).attr("y",0).attr("width",i.gridSize).attr("height",i.gridSize).attr("fill",i.backgroundColor),i.gridStyle){case"dots":a.append("circle").attr("cx",i.gridSize/2).attr("cy",i.gridSize/2).attr("r",i.gridSize*i.gridThickness).attr("fill",i.gridColor);break;case"lines":a.append("line").attr("x1",i.gridSize/2).attr("x2",i.gridSize/2).attr("y1",0).attr("y2",i.gridSize).attr("stroke-width",i.gridSize*i.gridThickness).attr("stroke",i.gridColor),a.append("line").attr("x1",0).attr("x2",(i.gridSize-i.gridSize*i.gridThickness)/2).attr("y1",i.gridSize/2).attr("y2",i.gridSize/2).attr("stroke-width",i.gridSize*i.gridThickness).attr("stroke",i.gridColor),a.append("line").attr("x1",(i.gridSize+i.gridSize*i.gridThickness)/2).attr("x2",i.gridSize).attr("y1",i.gridSize/2).attr("y2",i.gridSize/2).attr("stroke-width",i.gridSize*i.gridThickness).attr("stroke",i.gridColor);break}e.select("rect").attr("fill",`url(#${t})`)}},ht=96,Z=32,Ee=ht+Z,Ao=Math.PI/4,Eo=100,ai={customButtons:[]};class To{constructor(e,t){this.canvas=e,this.config=t||ai}open(e){this.close();const t=this.canvas.getPointerLocationRelativeToRoot(e),s=this.canvas.getPointerLocationRelativeToCanvas(e),a=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${t[0]-Ee}px`).attr("y",`${t[1]-Ee}px`).attr("width",`${2*Ee}px`).attr("height",`${2*Ee}px`).style("pointer-events","none").on(E.ContextMenu,o=>{this.canvas.canUserPerformAction(C.ContextMenu)&&(e.preventDefault(),this.open(o))}).on(E.Click,o=>{o.preventDefault(),this.close()});this.contextMenuContainer=a;const l=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"CUT",imageClass:"daga-cut",onPress:o=>{o.userSelection.cutToClipboard(),o.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&l.push({name:"COPY",imageClass:"daga-copy",onPress:o=>{o.userSelection.copyToClipboard(),o.cancelAllUserActions()}}),this.canvas.canUserPerformAction(C.Paste)&&l.push({name:"PASTE",imageClass:"daga-paste",onPress:o=>{o.userSelection.pasteFromClipboard(o.getClosestGridPoint(s)),o.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"DELETE",imageClass:"daga-delete",onPress:o=>{o.userSelection.removeFromModel(),o.cancelAllUserActions()}});for(const o of this.config.customButtons||ai.customButtons)(o.condition===void 0||o.condition(this.canvas))&&l.push(o);l.length===0&&l.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let o=0;o<l.length;++o){const n=l[o],r=n.onPress,d=(o+.5-l.length/2)*Ao,c=a.append("xhtml:div").attr("class",`daga-context-menu-button ${n.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*Z}px`).style("height",`${2*Z}px`).style("border-radius",`${Z}px`).style("pointer-events","auto").on(E.Click,h=>{r&&(h.preventDefault(),r(this.canvas))}).on(E.KeyDown,h=>{r&&h.key===te.Enter&&(h.preventDefault(),r(this.canvas))});n.imageClass!==void 0?c.append("xhtml:div").style("position","absolute").style("left",`${.75*Z}px`).style("top",`${.5*Z}px`).style("width",`${.5*Z}px`).style("height",`${.5*Z}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass):n.image!==void 0&&c.append("xhtml:img").style("position","absolute").style("left",`${.75*Z}px`).style("top",`${.5*Z}px`).style("width",`${.5*Z}px`).style("height",`${.5*Z}px`).attr("src",n.image),c.append("xhtml:span").style("position","absolute").style("left",`${.2*Z}px`).style("top",`${1.1*Z}px`).style("text-align","center").style("width",`${1.6*Z}px`).style("height",`${.35*Z}px`).style("margin","0").style("font-size",`${.35*Z}px`).style("font-weight","700").style("user-select","none").text(n.name),c.transition().ease(L.easeLinear).duration(Eo).tween("progress",()=>h=>{const g=d*h;return c.style("left",`${Math.sin(g)*ht-Z+Ee}px`).style("top",`${-Math.cos(g)*ht-Z+Ee}px`)})}}close(){var e;(e=this.contextMenuContainer)==null||e.remove(),this.contextMenuContainer=void 0}}class Lo extends ge{constructor(e){super(),this.focus=void 0,this.canvas=e}getFocus(){return this.focus}focusOn(e){this.clear(),this.focus=e,(e instanceof ue||e instanceof Ci)&&e.rootElement?this.focusOn(e.rootElement):this.add(e)}add(e){if(super.add(e),e instanceof j){for(const t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateNodesInView(e.id)}else if(e instanceof F){for(const t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}else e instanceof ke?(e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updatePortsInView(e.id)):e instanceof de&&this.canvas.updateConnectionsInView(e.id)}clear(){for(;this.entities.length>0;){const e=this.entities[0];this.remove(e.id),e.updateInView()}this.focus=void 0}}const $o=1;class Ii{export(e,t=!1){const s={name:e.name,type:e.type,typeVersion:$o,createdAt:e.createdAt,updatedAt:e.updatedAt,nodes:[],connections:[],data:e.valueSet.getValues(),...t?{collabMeta:{logicalClock:e.logicalClock,dataTimestamps:e.valueSet.getTimestamps()}}:{}};e.id&&(s.id=e.id),e.description&&(s.description=e.description);for(const a of e.nodes.all(!0))!t&&a.removed||a.parent===void 0&&s.nodes.push(this.exportNode(a,t));for(const a of e.connections.all(!0))!t&&a.removed||s.connections.push(this.exportConnection(a,t));return s}exportNode(e,t=!1){var o,n,r,d,c,h;const s=[];for(const g of e.children)s.push(this.exportNode(g,t));const a=[];for(const g of e.sections){const p=[];for(const f of g.ports)p.push({id:f.id,type:(o=f.type)==null?void 0:o.id,coords:Ae(f.coords),connectionPoint:Ae(f.connectionPoint),direction:f.direction,label:((n=f.label)==null?void 0:n.text)||"",...t?{collabMeta:{removed:f.removed,selfRemoved:f.selfRemoved,selfRemovedTimestamp:f.selfRemovedTimestamp,...this.exportLabelCollabMeta(f)}}:{}});a.push({id:g.id,ports:p,label:((r=g.label)==null?void 0:r.text)||"",indexXInNode:g.indexXInNode,indexYInNode:g.indexYInNode,coords:Ae(g.coords),width:g.width,height:g.height,...t?{collabMeta:{removed:g.removed,selfRemoved:g.selfRemoved,selfRemovedTimestamp:g.selfRemovedTimestamp,...this.exportLabelCollabMeta(g)}}:{}})}const l=[];for(const g of e.ports)l.push({id:g.id,type:(d=g.type)==null?void 0:d.id,coords:Ae(g.coords),connectionPoint:Ae(g.connectionPoint),direction:g.direction,label:((c=g.label)==null?void 0:c.text)||"",...t?{collabMeta:{removed:g.removed,selfRemoved:g.selfRemoved,selfRemovedTimestamp:g.selfRemovedTimestamp,...this.exportLabelCollabMeta(g)}}:{}});return{id:e.id,type:e.type.id,children:s,sections:a,ports:l,label:((h=e.label)==null?void 0:h.text)||"",coords:Ae(e.coords),width:e.width,height:e.height,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,geometryTimestamp:e.geometryTimestamp,dataTimestamps:e.valueSet.getTimestamps(),...this.exportLabelCollabMeta(e)}}:{}}}exportConnection(e,t=!1){var s,a;return{id:e.id,type:e.type.id,start:((s=e.start)==null?void 0:s.id)||"",end:((a=e.end)==null?void 0:a.id)||"",startLabel:e.startLabel,middleLabel:e.middleLabel,endLabel:e.endLabel,points:e.points,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,dataTimestamps:e.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:e}){return e?{label:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,textTimestamp:e.textTimestamp}}:{}}}const Mo="Diagram properties";class No extends ge{constructor(e){super(),this.canvas=e,this.canvas.propertyEditorChanges$.pipe(xe.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(e){if(!this.contains(e.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(e instanceof j||e instanceof de)?this.openInPropertyEditor(e):this.propertyEditorSelection===void 0&&e instanceof F?this.openInPropertyEditor(e.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(e),e.updateInView(),e instanceof j&&e.sections))for(const t of e.sections)super.add(t),t.updateInView()}remove(e){const t=this.get(e);if(t&&(this.propertyEditorSelection===t&&this.openInPropertyEditor(void 0),super.remove(e),t.updateInView(),t instanceof j&&t.sections))for(const s of t.sections)super.remove(s.id),s.updateInView()}toggle(e){this.contains(e.id)?this.remove(e.id):this.add(e)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const e=this.entities[0];super.remove(e.id),e.updateInView()}}move(e){for(const t of this.all())t instanceof j&&t.move([t.coords[0]+e[0],t.coords[1]+e[1]])}removeFromModel(){if(this.length>0){const e=[],t=[],s=[],a=[],l=[];for(const n of this.all())n instanceof j?e.push(n.id):n instanceof F?t.push(n.id):n instanceof ke?s.push(n.id):n instanceof de?a.push(n.id):n instanceof ue&&l.push(n.id);const o=new ko(this.canvas,e,t,s,a,l);o.do(),this.canvas.actionStack.add(o)}}copyToClipboard(){const e={type:"daga-user-selection",nodes:[],connections:[]},t=new Ii;for(const s of this.all())s instanceof j&&e.nodes.push(t.exportNode(s,!1)),s instanceof de&&e.connections.push(t.exportConnection(s,!1));navigator.clipboard.writeText(JSON.stringify(e))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(e){navigator.clipboard.readText().then(t=>{try{const s=JSON.parse(t);if(s.type!=="daga-user-selection")return;const a=new wo(this.canvas,s.nodes,s.connections,e);this.canvas.actionStack.add(a),a.do()}catch{return}})}openInPropertyEditor(e){var a;this.makeUpdateValuesAction();const t=(a=this.canvas.parentComponent)==null?void 0:a.propertyEditor;if(t===void 0)return;const s=e==null?void 0:e.valueSet;s?(this.propertyEditorSelection=e,this.propertyEditorValues=structuredClone(s.getValues()),t&&(e instanceof j||e instanceof de?(e instanceof j?e.name?t.title=`${e.type.name}: ${e.name}`:t.title=e.type.name:e instanceof de&&(t.title=e.type.name),t.valueSet=void 0,t.valueSet=s):(t.title=Mo,t.valueSet=void 0,t.valueSet=s))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,t&&(t.title="",t.valueSet=void 0))}makeUpdateValuesAction(){var n,r,d;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const e=this.propertyEditorSelection instanceof Si?void 0:this.propertyEditorSelection.id;if(Ce(this.propertyEditorValues,(n=this.propertyEditorSelection)==null?void 0:n.valueSet.getValues()))return;const t=this.propertyEditorValues,s=structuredClone((r=this.propertyEditorSelection)==null?void 0:r.valueSet.getValues()),[a,l]=gi(t,s,(d=this.propertyEditorSelection)==null?void 0:d.valueSet),o=new vo(this.canvas,e,a,l);o.do(),this.canvas.actionStack.add(o),this.propertyEditorValues=s}}const Po=12,H=6,zo=25,at="diagram-connection-unfinished",Ro=100,Ue=class Ue{constructor(e,t){var s,a,l,o,n,r,d,c,h,g,p,f,m,u,b,x,v,w,S,A,z;if(this.backgroundPatternId=`daga-background-pattern-id-${Ue.canvasCount++}`,this.zoomTransform=L.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new xe.Subject,this.diagramChange$=new xe.Subject,this.diagramEvent$=new xe.Subject,this.propertyEditorChanges$=new xe.Subject,this.parentComponent=e,this.model=new Si(this,void 0,t.name||"unnamed","",t.type||"",t.properties||[]),this.userSelection=new No(this),this.userHighlight=new Lo(this),this.contextMenu=new To(this,(s=t.canvas)==null?void 0:s.contextMenu),this.backgroundColor=((a=t.canvas)==null?void 0:a.backgroundColor)||"#FFFFFF",this.gridStyle=((o=(l=t.canvas)==null?void 0:l.grid)==null?void 0:o.style)??Ne.style,this.gridSize=((r=(n=t.canvas)==null?void 0:n.grid)==null?void 0:r.enabled)===!1||((d=t.canvas)==null?void 0:d.grid)===void 0?0:Math.abs(((h=(c=t.canvas)==null?void 0:c.grid)==null?void 0:h.spacing)||Ne.spacing),this.gridThickness=Math.abs(((p=(g=t.canvas)==null?void 0:g.grid)==null?void 0:p.thickness)||Ne.thickness),this.gridColor=((m=(f=t.canvas)==null?void 0:f.grid)==null?void 0:m.color)||Ne.color,this.snapToGrid=((b=(u=t.canvas)==null?void 0:u.grid)==null?void 0:b.enabled)===!1||((x=t.canvas)==null?void 0:x.grid)===void 0?!1:((w=(v=t.canvas)==null?void 0:v.grid)==null?void 0:w.snap)||Ne.snap,this.zoomFactor=((S=t.canvas)==null?void 0:S.zoomFactor)||2,this.panRate=((A=t.canvas)==null?void 0:A.panRate)||100,this.inferConnectionType=t.inferConnectionType||!1,this.multipleSelectionOn=!1,this.priorityThresholds=((z=t.canvas)==null?void 0:z.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=t.layoutFormat,this.userActions=t.userActions||{},this.validators=[],this.actionStack=new po(this,zo),this.collabEngine=new mo(this),t.nodeTypes)for(const N of t.nodeTypes){const _=new yi({...t.nodeTypeDefaults,...N});this.model.nodes.types.add(_)}if(t.portTypes)for(const N of t.portTypes){const _=new fo({...t.portTypeDefaults,...N});this.model.ports.types.add(_)}if(t.connectionTypes){for(const N of t.connectionTypes){const _=new mi({...t.connectionTypeDefaults,...N});this.model.connections.types.add(_)}this._connectionType=t.defaultConnection!==void 0?this.model.connections.types.get(t.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(e){var t,s;this._connectionType=e,(s=(t=this.parentComponent)==null?void 0:t.palette)==null||s.refreshPalette()}addValidator(e){this.validators.push(e),this.validatorChange$.next()}removeValidator(e){Y(this.validators,e),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(e){var t,s;this.priorityThreshold=e,this.updateModelInView();for(const a of this.model.nodes)this.fitNodeInView(a.id);(s=(t=this.parentComponent)==null?void 0:t.palette)==null||s.refreshPalette()}initView(e){const t=L.select(e);t.html(""),this.diagramRoot=t.append("div").node(),L.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),L.select(this.diagramRoot).on(E.Click,()=>{var a;(a=L.select(this.diagramRoot).node())==null||a.focus()}).on(E.ContextMenu,a=>{if(this.dragging){a.preventDefault(),a.stopPropagation(),this.dragging=!1;return}const l=new ye(a,null);this.diagramEvent$.next(l),!l.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(a.preventDefault(),this.contextMenu.open(a))}).on(E.DoubleClick,a=>{const l=new pe(a,null);this.diagramEvent$.next(l)}).on(E.KeyDown,a=>{if(!a.ctrlKey&&(a.key===te.Delete||a.key===te.Backspace)&&this.canUserPerformAction(C.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="a"){a.preventDefault();for(const l of this.model.nodes)this.userSelection.add(l);for(const l of this.model.connections)this.userSelection.add(l);this.diagramEvent$.next(new G(this.userSelection.all(),!0))}if(a.ctrlKey&&a.key==="i"){a.preventDefault();const l=[],o=[];for(const n of this.model.nodes)this.userSelection.toggle(n),n.selected?l.push(n):o.push(n);for(const n of this.model.connections)this.userSelection.toggle(n),n.selected?l.push(n):o.push(n);l.length>0&&this.diagramEvent$.next(new G(l,!0)),o.length>0&&this.diagramEvent$.next(new G(o,!1))}if(a.ctrlKey&&a.key==="c"&&this.canUserPerformAction(C.Clipboard)&&(a.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="x"&&this.canUserPerformAction(C.Clipboard)&&this.canUserPerformAction(C.Remove)&&(a.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="v"&&this.canUserPerformAction(C.Paste)){a.preventDefault();const l=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(l[0][0]+l[1][0])/2,(l[0][1]+l[1][1])/2])),this.cancelAllUserActions()}a.ctrlKey&&a.key==="y"&&(a.preventDefault(),this.actionStack.redo()),a.ctrlKey&&a.key==="z"&&(a.preventDefault(),this.actionStack.undo()),a.key==="+"&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.zoomBy(this.zoomFactor)),a.key==="-"&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.zoomBy(1/this.zoomFactor)),a.key===te.ArrowLeft&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),a.key===te.ArrowRight&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),a.key===te.ArrowDown&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),a.key===te.ArrowUp&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const s=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%");s.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(E.MouseMove,a=>{if(this.unfinishedConnection!==void 0){const l=this.getPointerLocationRelativeToCanvas(a);this.unfinishedConnection.endCoords=l}}).on(E.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new ie(null)))}).on(E.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new ie(null))),this.contextMenu.close(),this.userSelection.size()>0){const a=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(a,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(L.drag().filter(a=>this.multipleSelectionOn||be(a)).on(T.Start,a=>{this.startMultipleSelection(a)}).on(T.Drag,a=>{this.continueMultipleSelection(a)}).on(T.End,a=>{this.finishMultipleSelection(a)})).call(this.zoomBehavior=L.zoom().on(lt.Zoom,a=>{if(a.sourceEvent){if(!this.canUserPerformAction(C.Zoom)){I($.NotAllowed);return}a.sourceEvent.type===E.Wheel&&a.sourceEvent.wheelDelta!==void 0?(a.sourceEvent.wheelDelta>0&&I($.ZoomIn),a.sourceEvent.wheelDelta<0&&I($.ZoomOut)):a.sourceEvent.type===E.MouseMove&&I($.AllScroll)}this.zoomTransform=a.transform;const l=a.transform.toString();this.selectCanvasElements().attr("transform",l),L.select(`#${this.backgroundPatternId}`).attr("patternTransform",l),this.contextMenu.close()}).on(lt.End,()=>{I()})),Io(this,s,this.backgroundPatternId),s.append("g").attr("class","daga-canvas-elements")}zoomBy(e){isNaN(e)||this.zoomBehavior.scaleBy(this.selectCanvasView().select("rect"),e)}zoomTo(e){isNaN(e)||this.zoomBehavior.scaleTo(this.selectCanvasView().select("rect"),e)}translateBy(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateBy(this.selectCanvasView().select("rect"),e,t)}translateTo(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateTo(this.selectCanvasView().select("rect"),e,t)}center(){var e;if(this.model.nodes.length>0){const t=(e=this.selectCanvasView().select("rect").node())==null?void 0:e.getBBox(),s=this.model.nodes.all(),a=Math.min(...s.map(m=>m.coords[0])),l=Math.max(...s.map(m=>m.coords[0]+m.width)),o=(a+l)/2,n=l-a,r=t.width,d=Math.min(...s.map(m=>m.coords[1])),c=Math.max(...s.map(m=>m.coords[1]+m.height)),h=(d+c)/2,g=c-d,p=t.height,f=Math.min(r/n,p/g,1);this.translateTo(o,h),this.zoomTo(f)}}getClosestGridPoint(e){return this.gridSize===0||!isFinite(this.gridSize)?e:[Math.round(e[0]/this.gridSize)*this.gridSize,Math.round(e[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){var s;const e=(s=this.selectSVGElement().node())==null?void 0:s.getBoundingClientRect(),t=[(e==null?void 0:e.width)||0,(e==null?void 0:e.height)||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(t[0]-this.zoomTransform.x)/this.zoomTransform.k,(t[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(e){if(e.type==="drag"||e.type==="start"||e.type==="end"){const t=e.sourceEvent;if(t&&(t.type==="touchmove"||t.type==="touchstart"||t.type==="touchend"))return e.sourceEvent.touches[0]||e.sourceEvent.changedTouches[0]}return e}getPointerLocationRelativeToCanvas(e){return L.pointer(this.getEventHoldingCoordinates(e),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(e){return L.pointer(this.getEventHoldingCoordinates(e),this.selectSVGElement().node())}getPointerLocationRelativeToBody(e){return L.pointer(this.getEventHoldingCoordinates(e),L.select("body").node())}getPointerLocationRelativeToScreen(e){const t=this.getPointerLocationRelativeToBody(e);return[t[0]-window.scrollX,t[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=t.exit(),a=t.enter().append("g").attr("id",o=>o.id).attr("class",o=>`diagram-node${o.type.resizableX?" resizable-x":""}${o.type.resizableY?" resizable-y":""} ${o.type.defaultLook.lookType}`);e&&e.length>0&&(t=t.filter(o=>e.includes(o.id)));const l=a.merge(t);s.remove(),a.on(E.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new ie(n)))}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(r,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new G([n],n.selected))}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new ye(o,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(o.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new ie(n)),this.userSelection.add(n),this.diagramEvent$.next(new G([n],!0)),this.contextMenu.open(o))}).on(E.DoubleClick,(o,n)=>{const r=new pe(o,n);this.diagramEvent$.next(r)}).call(L.drag().filter(o=>(this.secondaryButton=be(o),!0)).on(T.Start,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(o):this.startMovingNode(o,n)}).on(T.Drag,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(o):this.continueMovingNode(o,n)}).on(T.End,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(o):this.finishMovingNode(o,n),this.secondaryButton=!1})),nt(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&I($.EWResize)}).on(E.MouseOut,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&I()}).call(L.drag().on(T.Start,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(I($.EWResize),this.currentAction=new W(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I($.NotAllowed)}).on(T.Drag,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(o);n.stretch(k.Left,n.coords[0]-r[0])}}).on(T.End,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof W&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Left,n.coords[0]-r[0]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&I($.NSResize)}).on(E.MouseOut,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&I()}).call(L.drag().on(T.Start,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(I($.NSResize),this.currentAction=new W(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I($.NotAllowed)}).on(T.Drag,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(o);n.stretch(k.Top,n.coords[1]-r[1])}}).on(T.End,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof W&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Top,n.coords[1]-r[1]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&I($.EWResize)}).on(E.MouseOut,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&I()}).call(L.drag().on(T.Start,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(I($.EWResize),this.currentAction=new W(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I($.NotAllowed)}).on(T.Drag,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(o);n.stretch(k.Right,r[0]-(n.coords[0]+n.width))}}).on(T.End,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof W&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Right,r[0]-(n.coords[0]+n.width)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&I($.NSResize)}).on(E.MouseOut,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&I()}).call(L.drag().on(T.Start,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(I($.NSResize),this.currentAction=new W(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I($.NotAllowed)}).on(T.Drag,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(o);n.stretch(k.Bottom,r[1]-(n.coords[1]+n.height))}}).on(T.End,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof W&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Bottom,r[1]-(n.coords[1]+n.height)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),l.attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).attr("opacity",o=>o.removed?.5:1),rt(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/2).attr("y1",0).attr("y2",o=>o.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",o=>o.width).attr("y1",H/2).attr("y2",H/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",o=>o.width-H/2).attr("x2",o=>o.width-H/2).attr("y1",0).attr("y2",o=>o.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",o=>o.width).attr("y1",o=>o.height-H/2).attr("y2",o=>o.height-H/2)}updateSectionsInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=t.exit(),a=t.enter().append("g").attr("id",o=>o.id).attr("class",o=>{var n,r,d,c,h;return`diagram-section${(r=(n=o.node)==null?void 0:n.type)!=null&&r.resizableX?" resizable-x":""}${(c=(d=o.node)==null?void 0:d.type)!=null&&c.resizableY?" resizable-y":""} ${(h=o.look)==null?void 0:h.lookType}`});e&&e.length>0&&(t=t.filter(o=>e.includes(o.id)));const l=a.merge(t);s.remove(),a.on(E.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new ie(n)))}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(d,!1))}const r=he(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new ye(o,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){o.preventDefault();const d=he(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new ie(d)),this.userSelection.add(d),this.diagramEvent$.next(new G([d],!0)),this.contextMenu.open(o)}}).on(E.DoubleClick,(o,n)=>{const r=new pe(o,n);this.diagramEvent$.next(r)}).call(L.drag().filter(o=>(this.secondaryButton=be(o),!0)).on(T.Start,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(o);else{const r=n==null?void 0:n.node;r?this.startMovingNode(o,r):I($.NotAllowed)}}).on(T.Drag,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else{const r=n==null?void 0:n.node;r?this.continueMovingNode(o,r):I($.NotAllowed)}}).on(T.End,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{const r=n==null?void 0:n.node;r?this.finishMovingNode(o,r):I()}this.secondaryButton=!1})),nt(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&I($.EWResize)}).on(E.MouseOut,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&I()}).call(L.drag().on(T.Start,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed?(I($.EWResize),this.currentAction=new W(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I($.NotAllowed)}).on(T.Drag,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed){const c=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(k.Left,n.coords[0]-c[0],n.indexXInNode,n.indexYInNode)}}).on(T.End,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&this.currentAction instanceof W&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(c=this.getClosestGridPoint(c)),n.node.stretchSections(k.Left,n.coords[0]-c[0],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&I($.NSResize)}).on(E.MouseOut,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&I()}).call(L.drag().on(T.Start,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed?(I($.NSResize),this.currentAction=new W(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I($.NotAllowed)}).on(T.Drag,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed){const c=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(k.Top,n.coords[1]-c[1],n.indexXInNode,n.indexYInNode)}}).on(T.End,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&this.currentAction instanceof W&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(c=this.getClosestGridPoint(c)),n.node.stretchSections(k.Top,n.coords[1]-c[1],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&I($.EWResize)}).on(E.MouseOut,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&I()}).call(L.drag().on(T.Start,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed?(I($.EWResize),this.currentAction=new W(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I($.NotAllowed)}).on(T.Drag,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed){const c=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(k.Right,c[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on(T.End,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&this.currentAction instanceof W&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(c=this.getClosestGridPoint(c)),n.node.stretchSections(k.Right,c[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&I($.NSResize)}).on(E.MouseOut,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&I()}).call(L.drag().on(T.Start,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed?(I($.NSResize),this.currentAction=new W(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I($.NotAllowed)}).on(T.Drag,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed){const c=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(k.Bottom,c[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on(T.End,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&this.currentAction instanceof W&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(c=this.getClosestGridPoint(c)),n.node.stretchSections(k.Bottom,c[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),l.attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).attr("opacity",o=>o.removed?.5:1),rt(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/2).attr("y1",0).attr("y2",o=>o.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",o=>o.width).attr("y1",H/2).attr("y2",H/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",o=>o.width-H/2).attr("x2",o=>o.width-H/2).attr("y1",0).attr("y2",o=>o.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",o=>o.width).attr("y1",o=>o.height-H/2).attr("y2",o=>o.height-H/2)}updatePortsInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=t.exit(),a=t.enter().append("g").attr("id",o=>o.id).attr("class",o=>`diagram-port ${o.look.lookType}`);e&&e.length>0&&(t=t.filter(o=>e.includes(o.id)));const l=a.merge(t);s.remove(),a.on(E.MouseOver,(o,n)=>{var r,d,c,h,g,p,f,m,u,b,x,v;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new ie(n))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((c=(d=(r=this.unfinishedConnection.start)==null?void 0:r.getNode())==null?void 0:d.type)==null?void 0:c.id)||"")&&((h=this.unfinishedConnection.start)!=null&&h.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((p=(g=n.getNode())==null?void 0:g.type)==null?void 0:p.id)||"")&&n.allowsIncoming||this.unfinishedConnection.type.canStartFromType(((m=(f=n.getNode())==null?void 0:f.type)==null?void 0:m.id)||"")&&n.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(((x=(b=(u=this.unfinishedConnection.start)==null?void 0:u.getNode())==null?void 0:b.type)==null?void 0:x.id)||"")&&((v=this.unfinishedConnection.start)!=null&&v.allowsIncoming)||I($.NoDrop))}).on(E.MouseOut,()=>{this.unfinishedConnection&&I($.Grabbing)}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(d,!1))}const r=he(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new ye(o,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){o.preventDefault();const d=he(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new ie(d)),this.userSelection.add(d),this.diagramEvent$.next(new G([d],!0)),this.contextMenu.open(o)}}).on(E.DoubleClick,(o,n)=>{const r=new pe(o,n);this.diagramEvent$.next(r)}).call(L.drag().filter(o=>(this.secondaryButton=be(o),!0)).on(T.Start,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(o):this.canUserPerformAction(C.AddConnection)&&!n.removed?(I($.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):I($.NotAllowed)}).on(T.Drag,(o,n)=>{var r,d,c,h;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else if(this.canUserPerformAction(C.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const g=[o.x,o.y];(c=this.unfinishedConnectionTracer)==null||c.attr("d",st(this.unfinishedConnection.look.shape,this.unfinishedConnection.startCoords,g,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.look.thickness,(r=this.unfinishedConnection.startMarkerLook)==null?void 0:r.width,(d=this.unfinishedConnection.endMarkerLook)==null?void 0:d.width));const p=(h=this.unfinishedConnectionTracer)==null?void 0:h.node();if(p){let f=2;const m=p.getTotalLength();m<f&&(f=0);const u=p.getPointAtLength(m-f);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=g;if(this.updateConnectionsInView(at),this.model.ports.length>0){const f=this.getPointerLocationRelativeToCanvas(o);let m=Number.POSITIVE_INFINITY,u;for(const b of this.model.ports){const x=b.distanceTo(f);x<m&&(m=x,u=b)}u&&m<Ro?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on(T.End,(o,n)=>{var r;if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{if(this.canUserPerformAction(C.AddConnection)&&!n.removed){(r=this.unfinishedConnectionTracer)==null||r.remove();const d=this.userHighlight.getFocus();if(d instanceof ke)this.finishConnection(d);else if(d instanceof ue&&d.rootElement instanceof ke)this.finishConnection(d.rootElement);else if(d instanceof j||d instanceof F||d instanceof ue){let c;if(d instanceof j||d instanceof F)c=d;else if(d.rootElement instanceof j||d.rootElement instanceof F)c=d.rootElement;else{this.dropConnection();return}const h=c.getClosestPortToPoint([o.x,o.y]);h!==void 0?this.finishConnection(h):this.dropConnection()}else this.dropConnection()}I()}this.secondaryButton=!1})),a.filter(".image-look").append("image"),nt(a),l.attr("transform",o=>`translate(${o.coords[0]-o.width/2},${o.coords[1]-o.width/2})`).attr("opacity",o=>o.removed?.5:1),rt(l)}updateConnectionsInView(...e){const t=this.model.connections.filter(n=>this.priorityThreshold!==void 0?n.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&t.push(this.unfinishedConnection);let s=this.selectCanvasElements().selectAll("g.diagram-connection").data(t,n=>n.id);const a=s.exit(),l=s.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");e&&e.length>0&&(s=s.filter(n=>e.includes(n.id)));const o=l.merge(s);a.remove(),l.on(E.MouseOver,(n,r)=>{r.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new ie(r)))}).on(E.Click,(n,r)=>{if(!n.ctrlKey&&!n.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(d,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(n,r)=>{if(this.dragging){n.preventDefault(),n.stopPropagation(),this.dragging=!1;return}const d=new ye(n,r);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new ie(r)),this.userSelection.add(r),this.diagramEvent$.next(new G([r],!0)),this.contextMenu.open(n))}).on(E.DoubleClick,(n,r)=>{const d=new pe(n,r);this.diagramEvent$.next(d)}).call(L.drag().filter(n=>(this.secondaryButton=be(n),!0)).on(T.Start,n=>{this.startMultipleSelection(n)}).on(T.Drag,n=>{this.continueMultipleSelection(n)}).on(T.End,n=>{this.finishMultipleSelection(n)})),l.append("path").attr("class","diagram-connection-path"),l.append("path").attr("class","diagram-connection-path-box"),l.append("marker").attr("id",n=>`${n.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),l.append("marker").attr("id",n=>`${n.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),l.append("g").attr("class","diagram-connection-start-label"),l.select("g.diagram-connection-start-label").append("path"),l.select("g.diagram-connection-start-label").append("text").style("user-select","none"),l.append("g").attr("class","diagram-connection-middle-label"),l.select("g.diagram-connection-middle-label").append("path"),l.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),l.append("g").attr("class","diagram-connection-end-label"),l.select("g.diagram-connection-end-label").append("path"),l.select("g.diagram-connection-end-label").append("text").style("user-select","none"),o.attr("opacity",n=>n.removed?.5:1).select("path.diagram-connection-path").attr("d",n=>{var r,d;return st(n.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(d=n.endMarkerLook)==null?void 0:d.width)}).attr("marker-start",n=>`url(#${n.id}-start-marker)`).attr("marker-end",n=>`url(#${n.id}-end-marker)`).attr("stroke",n=>n.look.color).attr("stroke-width",n=>`${n.look.thickness}px`).attr("stroke-dasharray",n=>Qt(n.look.style,n.look.thickness)).attr("fill","none"),o.select("path.diagram-connection-path-box").attr("d",n=>{var r,d;return st(n.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(d=n.endMarkerLook)==null?void 0:d.width)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",n=>`${n.look.thickness+Po}px`).attr("stroke-dasharray",n=>Qt(n.look.style,n.look.thickness)).attr("fill","none"),o.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=t.exit(),a=t.enter().append("foreignObject").attr("id",o=>o.id).attr("class","diagram-field");e&&e.length>0&&(t=t.filter(o=>e.includes(o.id)));const l=a.merge(t);s.remove(),a.style("box-sizing","border-box").on(E.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new ie(n)))}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(d,!1))}const r=he(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new ye(o,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){o.preventDefault();const d=he(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new ie(d)),this.userSelection.add(d),this.diagramEvent$.next(new G([d],!0)),this.contextMenu.open(o)}}).on(E.DoubleClick,(o,n)=>{const r=new pe(o,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.EditField)&&n.editable&&!n.removed&&(this.currentAction=new ri(this,n.id,n.text,""),this.createInputField(n.text,n.coords,n.width,n.height,n.fontSize,n.fontFamily||D.fontFamily,d=>{n.text=d},d=>{n.text=d,this.currentAction instanceof ri&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(L.drag().filter(o=>(this.secondaryButton=be(o),!0)).on(T.Start,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof F&&(r=n.rootElement.node),r?this.startMovingNode(o,r):I($.NotAllowed)}}).on(T.Drag,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof F&&(r=n.rootElement.node),r?this.continueMovingNode(o,r):I($.NotAllowed)}}).on(T.End,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof F&&(r=n.rootElement.node),r?this.finishMovingNode(o,r):I()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),l.attr("x",0).attr("y",0).attr("width",o=>`${o.width}px`).attr("height",o=>`${o.height}px`).attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).attr("opacity",o=>o.removed?.5:1).select("div").style("justify-content",o=>o.horizontalAlign===Te.Center?"center":o.horizontalAlign===Te.Right?"flex-end":"flex-start").style("align-items",o=>o.verticalAlign===Fe.Center?"center":o.verticalAlign===Fe.Bottom?"end":"start").select("p").style("max-width",o=>o.fit?"default":"100%").style("max-height",o=>o.fit?"default":"100%").style("overflow",o=>o.fit?"default":"hidden").style("text-overflow",o=>o.fit?"default":"ellipsis").style("text-align",o=>o.horizontalAlign===Te.Center?"center":o.horizontalAlign===Te.Right?"end":"start").style("font-size",o=>`${o.fontSize}px`).style("font-family",o=>o.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",o=>o.highlighted?600:400).style("color",o=>o.selected?o.selectedColor||"#000000":o.color||"#000000").html(o=>o.text.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"))}updateObjectsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=t.exit(),a=t.enter().append("foreignObject").attr("id",o=>o.id).attr("class","diagram-object");e&&e.length>0&&(t=t.filter(o=>e.includes(o.id))),a.merge(t).attr("width",o=>`${o.width}px`).attr("height",o=>`${o.height}px`).attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).html(o=>o.html),s.remove(),a.on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new ye(o,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(o.preventDefault(),this.contextMenu.open(o))}).on(E.DoubleClick,(o,n)=>{const r=new pe(o,n);this.diagramEvent$.next(r)}).call(L.drag().filter(o=>(this.secondaryButton=be(o),!0)).on(T.Start,o=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(o)}).on(T.Drag,o=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(o)}).on(T.End,o=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(o)}))}updateDecoratorsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=t.exit(),a=t.enter().append("foreignObject").attr("id",o=>o.id).attr("class","diagram-decorator");e&&e.length>0&&(t=t.filter(o=>e.includes(o.id))),a.merge(t).attr("width",o=>`${o.width}px`).attr("height",o=>`${o.height}px`).attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).html(o=>o.html),s.remove(),a.on(E.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new ie(n)))}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(r,!1))}if(n.rootElement){const r=he(n.rootElement);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new ye(o,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&n.rootElement){o.preventDefault();const d=he(n.rootElement);this.userHighlight.focusOn(d),this.diagramEvent$.next(new ie(d)),this.userSelection.add(d),this.diagramEvent$.next(new G([d],!0)),this.contextMenu.open(o)}}).on(E.DoubleClick,(o,n)=>{const r=new pe(o,n);this.diagramEvent$.next(r)}).call(L.drag().filter(o=>(this.secondaryButton=be(o),!0)).on(T.Start,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof F&&(r=n.rootElement.node),r?this.startMovingNode(o,r):I($.NotAllowed)}}).on(T.Drag,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof F&&(r=n.rootElement.node),r?this.continueMovingNode(o,r):I($.NotAllowed)}}).on(T.End,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof F&&(r=n.rootElement.node),r?this.finishMovingNode(o,r):I()}this.secondaryButton=!1}))}updateConnectionLabelsInView(e){var o,n,r;const t=this.selectCanvasView().select(`[id='${ct(e.id)}']`),a=t.select("path").node(),l={...D,...e.type.label};if(a){const d=a.getTotalLength();t.select("g.diagram-connection-start-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",e.selected?l.selectedColor:l.color).style("font-kerning","none").text(e.startLabel);const c=(o=t.select("g.diagram-connection-start-label text").node())==null?void 0:o.getBoundingClientRect();if(c){const p=e.startLabel?c.width/this.zoomTransform.k+ze(l)+Re(l):0,f=e.startLabel?c.height/this.zoomTransform.k+Ve(l)+Pe(l):0,m=a.getPointAtLength(Math.max(K(l)+p/2,re(l)+p/2,U(l)+f/2,oe(l)+f/2));t.select("g.diagram-connection-start-label path").attr("d",Ge(-p/2,-f/2,p,f)).attr("fill",e.look.color).attr("stroke","none"),t.select("g.diagram-connection-start-label").attr("transform",`translate(${m.x},${m.y})`)}t.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",e.selected?l.selectedColor:l.color).style("font-kerning","none").text(e.middleLabel);const h=(n=t.select("g.diagram-connection-middle-label text").node())==null?void 0:n.getBoundingClientRect();if(h){const p=e.middleLabel?h.width/this.zoomTransform.k+ze(l)+Re(l):0,f=e.middleLabel?h.height/this.zoomTransform.k+Ve(l)+Pe(l):0,m=a.getPointAtLength(d/2);t.select("g.diagram-connection-middle-label path").attr("d",Ge(-p/2,-f/2,p,f)).attr("fill",e.look.color).attr("stroke","none"),t.select("g.diagram-connection-middle-label").attr("transform",`translate(${m.x},${m.y})`)}t.select("g.diagram-connection-end-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",e.selected?l.selectedColor:l.color).style("font-kerning","none").text(e.endLabel);const g=(r=t.select("g.diagram-connection-end-label text").node())==null?void 0:r.getBoundingClientRect();if(g){const p=e.endLabel?g.width/this.zoomTransform.k+ze(l)+Re(l):0,f=e.endLabel?g.height/this.zoomTransform.k+Ve(l)+Pe(l):0,m=a.getPointAtLength(d-Math.max(K(l)+p/2,re(l)+p/2,U(l)+f/2,oe(l)+f/2));t.select("g.diagram-connection-end-label path").attr("d",Ge(-p/2,-f/2,p,f)).attr("fill",e.look.color).attr("stroke","none"),t.select("g.diagram-connection-end-label").attr("transform",`translate(${m.x},${m.y})`)}}}updateConnectionMarkersInView(e){const t=this.selectCanvasView().select(`[id='${ct(e.id)}']`),s=t.select("marker.diagram-connection-start-marker"),a=t.select("marker.diagram-connection-end-marker");e.startMarkerLook!==null?s.attr("orient","auto-start-reverse").attr("markerWidth",e.startMarkerLook.width).attr("markerHeight",e.startMarkerLook.height).attr("refX",e.startMarkerLook.refX).attr("refY",e.startMarkerLook.refY).select("image").attr("href",e.startMarkerLook.image).attr("width",e.startMarkerLook.width).attr("height",e.startMarkerLook.height):s.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),e.endMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",e.endMarkerLook.width).attr("markerHeight",e.endMarkerLook.height).attr("refX",e.endMarkerLook.refX).attr("refY",e.endMarkerLook.refY).select("image").attr("href",e.endMarkerLook.image).attr("width",e.endMarkerLook.width).attr("height",e.endMarkerLook.height):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(e){var s,a,l,o;const t=this.model.fields.get(e);if(!t)return!1;if(t.rootElement instanceof j||t.rootElement instanceof F){const n=this.minimumSizeOfField(t),r=n[0]+K((s=t.rootElement.type)==null?void 0:s.label)+re((a=t.rootElement.type)==null?void 0:a.label)-t.rootElement.width,d=n[1]+U((l=t.rootElement.type)==null?void 0:l.label)+oe((o=t.rootElement.type)==null?void 0:o.label)-t.rootElement.height;return r<=0&&d<=0}return!0}fitFieldRootInView(e,t){var a,l,o;const s=this.model.fields.get(e);if(s){if(s.rootElement instanceof j){const n=this.minimumSizeOfField(s);let r=n[0]+K(s.rootElement.type.label)+re(s.rootElement.type.label)-s.rootElement.width,d=n[1]+U(s.rootElement.type.label)+oe(s.rootElement.type.label)-s.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,d=Math.ceil(d/this.gridSize)*this.gridSize),s.rootElement.width+r<s.rootElement.type.minWidth&&(r=s.rootElement.type.minWidth-s.rootElement.width),s.rootElement.height+d<s.rootElement.type.minHeight&&(d=s.rootElement.type.minHeight-s.rootElement.height),(t!==!1||r>0)&&s.rootElement.stretch(k.Right,r),(t!==!1||d>0)&&s.rootElement.stretch(k.Bottom,d)}if(s.rootElement instanceof F){const n=this.minimumSizeOfField(s);let r=n[0],d=n[1];for(const p of((a=s.rootElement.node)==null?void 0:a.sections)||[])p.label&&(p.indexXInNode===s.rootElement.indexXInNode&&p.indexYInNode!==s.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(p.label)[0]):p.indexXInNode!==s.rootElement.indexXInNode&&p.indexYInNode===s.rootElement.indexYInNode&&(d=Math.max(d,this.minimumSizeOfField(p.label)[1])));n[0]<r&&(n[0]=r),n[1]<d&&(n[1]=d);const c=s.rootElement.type;let h=n[0]+K(c==null?void 0:c.label)+re(c==null?void 0:c.label)-s.rootElement.width,g=n[1]+U(c==null?void 0:c.label)+oe(c==null?void 0:c.label)-s.rootElement.height;this.snapToGrid&&(h=Math.ceil(h/this.gridSize)*this.gridSize,g=Math.ceil(g/this.gridSize)*this.gridSize),s.rootElement.width+h<(s.rootElement.getMinWidth()||0)&&(h=(s.rootElement.getMinWidth()||0)-s.rootElement.width),s.rootElement.height+g<(s.rootElement.getMinHeight()||0)&&(g=(s.rootElement.getMinHeight()||0)-s.rootElement.height),(t!==!1||h>0)&&((l=s.rootElement.node)==null||l.stretchSections(k.Right,h,s.rootElement.indexXInNode,s.rootElement.indexYInNode)),(t!==!1||g>0)&&((o=s.rootElement.node)==null||o.stretchSections(k.Bottom,g,s.rootElement.indexXInNode,s.rootElement.indexYInNode))}}}fitNodeInView(e){var s,a;const t=this.model.nodes.get(e);if(t&&t.sections.length>0&&this.priorityThreshold){let l=0,o=0;for(const n of t.sections)if(n.getPriority()>=this.priorityThreshold){const r=n.coords[0]+n.width-t.coords[0],d=n.coords[1]+n.height-t.coords[1];l=Math.max(l,r),o=Math.max(o,d)}l+=((s=t.type.sectionGrid)==null?void 0:s.margin)||0,o+=((a=t.type.sectionGrid)==null?void 0:a.margin)||0,t.stretch(k.Right,l-t.width),t.stretch(k.Bottom,o-t.height)}}selectRoot(){return L.select(this.diagramRoot)}selectSVGElement(){return L.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(e){var t,s,a,l;if(e.allowsOutgoing||e.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(((s=(t=e.getNode())==null?void 0:t.type)==null?void 0:s.id)||"")&&e.allowsOutgoing||this.connectionType.canFinishOnType(((l=(a=e.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&e.allowsIncoming))this.unfinishedConnection=new de(this.model,this.connectionType,e,void 0,at);else if(this.inferConnectionType){let o=this.model.connections.types.all().find(n=>{var r,d;return e.allowsOutgoing&&n.canStartFromType(((d=(r=e.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")});o===void 0&&(o=this.model.connections.types.all().find(n=>{var r,d;return e.allowsIncoming&&n.canFinishOnType(((d=(r=e.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")})),o!==void 0&&(this.unfinishedConnection=new de(this.model,o,e,void 0,at))}}}finishConnection(e){var t,s,a,l,o,n,r,d,c,h,g,p,f,m,u,b,x,v,w,S;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0)if(this.unfinishedConnection.start!==e)if(this.unfinishedConnection.type.canStartFromType(((l=(a=(s=(t=this.unfinishedConnection)==null?void 0:t.start)==null?void 0:s.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&((n=(o=this.unfinishedConnection)==null?void 0:o.start)!=null&&n.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((d=(r=e.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")&&e.allowsIncoming){const A=new ot(this,this.unfinishedConnection.type,(c=this.unfinishedConnection.start)==null?void 0:c.id,e.id);this.dropConnection(),A.do(),this.actionStack.add(A)}else if(this.unfinishedConnection.type.canFinishOnType(((f=(p=(g=(h=this.unfinishedConnection)==null?void 0:h.start)==null?void 0:g.getNode())==null?void 0:p.type)==null?void 0:f.id)||"")&&((u=(m=this.unfinishedConnection)==null?void 0:m.start)!=null&&u.allowsIncoming)&&this.unfinishedConnection.type.canStartFromType(((x=(b=e.getNode())==null?void 0:b.type)==null?void 0:x.id)||"")&&e.allowsOutgoing){const A=new ot(this,this.unfinishedConnection.type,e.id,(v=this.unfinishedConnection.start)==null?void 0:v.id);this.dropConnection(),A.do(),this.actionStack.add(A)}else if(this.inferConnectionType){let A=this.model.connections.types.all().find(N=>{var _,P,R,J,X,B,O,Q;return N.canStartFromType(((J=(R=(P=(_=this.unfinishedConnection)==null?void 0:_.start)==null?void 0:P.getNode())==null?void 0:R.type)==null?void 0:J.id)||"")&&((B=(X=this.unfinishedConnection)==null?void 0:X.start)==null?void 0:B.allowsOutgoing)&&N.canFinishOnType(((Q=(O=e.getNode())==null?void 0:O.type)==null?void 0:Q.id)||"")&&e.allowsIncoming}),z=!1;if(A===void 0&&(A=this.model.connections.types.all().find(N=>{var _,P,R,J,X,B,O,Q;return N.canFinishOnType(((J=(R=(P=(_=this.unfinishedConnection)==null?void 0:_.start)==null?void 0:P.getNode())==null?void 0:R.type)==null?void 0:J.id)||"")&&((B=(X=this.unfinishedConnection)==null?void 0:X.start)==null?void 0:B.allowsIncoming)&&N.canStartFromType(((Q=(O=e.getNode())==null?void 0:O.type)==null?void 0:Q.id)||"")&&e.allowsOutgoing}),z=!0),A!==void 0){const N=new ot(this,A,z?e.id:(w=this.unfinishedConnection.start)==null?void 0:w.id,z?(S=this.unfinishedConnection.start)==null?void 0:S.id:e.id);this.dropConnection(),N.do(),this.actionStack.add(N)}else this.dropConnection()}else this.dropConnection();else this.dropConnection()}dropConnection(){var e,t,s,a;(e=this.unfinishedConnection)==null||e.setStart(void 0),(t=this.unfinishedConnection)==null||t.setEnd(void 0),(a=(s=this.unfinishedConnection)==null?void 0:s.select())==null||a.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(e){return this.userActions[e]!==!1}createInputField(e,t,s,a,l,o,n,r){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${t[0]}px`).attr("y",`${t[1]}px`).attr("width",`${s}px`).attr("height",`${a}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const c=d.append("xhtml:textarea");let h,g;c.text(e).style("box-sizing","border-box").style("width",`${s}px`).style("height",`${a}px`).style("font-size",`${l}px`).style("font-family",o).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(E.KeyDown,f=>{f.stopPropagation()}).on(E.KeyUp,f=>{if(f.stopPropagation(),f.key===te.Escape){const m=c.property("value");this.removeInputField(),r&&r(m)}}).on(E.Input,()=>{const f=c.property("value");c.attr("cols",Ui(f)+1),c.attr("rows",Yi(f)+1),c.style("width",""),c.style("height",""),h=c.property("scrollWidth")+1,g=c.property("scrollHeight")+1;const m=Math.max(h,s),u=Math.max(g,a);d==null||d.attr("width",`${m}px`),c.style("width",`${m}px`),d==null||d.attr("height",`${u}px`),c.style("height",`${u}px`),n&&n(f)}).on(E.Click,f=>{f.stopPropagation()}).on(E.FocusOut,()=>{const f=c.property("value");this.removeInputField(),r&&r(f)});const p=c.node();p.focus(),p.select()}removeInputField(){var e,t,s;(t=(e=this.inputFieldContainer)==null?void 0:e.select("input"))==null||t.on(E.Blur,null),(s=this.inputFieldContainer)==null||s.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(e){var a,l;const t=(l=(a=e.select())==null?void 0:a.select("p"))==null?void 0:l.node();if(!t)return[0,0];const s=t.getBoundingClientRect();return[s.width/this.zoomTransform.k,s.height/this.zoomTransform.k]}startMovingNode(e,t){if(this.canUserPerformAction(C.MoveNode)&&!t.removed)if(I($.Grabbing),this.draggingFrom=[e.x,e.y],t.selected&&this.userSelection.count(s=>s instanceof j)>1)this.currentAction=new it(this,this.userSelection.filter(s=>s instanceof j).map(s=>s.id),t.coords);else{const s=t.getLastAncestor();this.currentAction=new W(this,C.MoveNode,t.id,t.getGeometry(),t.getGeometry(),s==null?void 0:s.id,s==null?void 0:s.getGeometry(t.id),s==null?void 0:s.getGeometry(t.id))}else I($.NotAllowed)}continueMovingNode(e,t){if(this.canUserPerformAction(C.MoveNode)&&(this.currentAction instanceof it||this.currentAction instanceof W)&&!t.removed){const s=[e.x-t.width/2,e.y-t.height/2];t.selected?this.userSelection.move([s[0]-t.coords[0],s[1]-t.coords[1]]):t.move(s),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(e,t){var s,a,l;if(this.canUserPerformAction(C.MoveNode)&&!t.removed&&(this.draggingFrom[0]!==e.x||this.draggingFrom[1]!==e.y)){let o=[e.x-t.width/2,e.y-t.height/2];if(this.snapToGrid&&(o=this.getClosestGridPoint(o)),this.currentAction instanceof it){const n=this.currentAction.delta;this.currentAction.delta=[o[0]-n[0],o[1]-n[1]],t.selected?this.userSelection.move([n[0]-t.coords[0],n[1]-t.coords[1]]):t.move(n)}else if(this.currentAction instanceof W){t.move(o);const r=this.model.nodes.getAtCoordinates(e.x,e.y).filter(h=>h.id!==t.id&&!h.isDescendantOf(t)).filter(h=>h.type.childrenTypes.includes(t.type.id)),d=bi(r),c=d[d.length-1];if(c!==t.parent&&(t.type.canBeParentless||c!==void 0)){const h=c==null?void 0:c.getLastAncestor(),g=this.currentAction.from,p=new bo(this,t.id,(s=t.parent)==null?void 0:s.id,c==null?void 0:c.id,g,t.getGeometry(),h==null?void 0:h.id,h==null?void 0:h.getGeometry(t.id),h==null?void 0:h.getGeometry(t.id));(a=t.parent)==null||a.removeChild(t),c!==void 0&&c.addChild(t),p.toChildGeometry=t.getGeometry(t.id),p.toAncestorGeometry=h==null?void 0:h.getGeometry(t.id),this.currentAction=p}else{const h=t==null?void 0:t.getLastAncestor();this.currentAction.ancestorId=h==null?void 0:h.id,this.currentAction.fromAncestorGeometry=h==null?void 0:h.getGeometry(t.id),(l=t.parent)==null||l.fitToChild(t),this.currentAction.to=t.getGeometry(t.id),this.currentAction.toAncestorGeometry=h==null?void 0:h.getGeometry(t.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}I(),this.dragging=!1}startMultipleSelection(e){this.draggingFrom=this.getPointerLocationRelativeToCanvas(e),this.multipleSelectionContainer=this.selectSVGElement().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(e){var s,a,l,o;const t=this.getPointerLocationRelativeToCanvas(e);(this.draggingFrom[0]!==t[0]||this.draggingFrom[1]!==t[1])&&(I($.Crosshair),(o=(l=(a=(s=this.multipleSelectionContainer)==null?void 0:s.attr("x",Math.min(this.draggingFrom[0],t[0])*this.zoomTransform.k+this.zoomTransform.x))==null?void 0:a.attr("y",Math.min(this.draggingFrom[1],t[1])*this.zoomTransform.k+this.zoomTransform.y))==null?void 0:l.attr("width",Math.abs(this.draggingFrom[0]-t[0])*this.zoomTransform.k))==null||o.attr("height",Math.abs(this.draggingFrom[1]-t[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(e){var s;const t=this.getPointerLocationRelativeToCanvas(e);(s=this.multipleSelectionContainer)==null||s.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)Ri([a.coords,[a.coords[0]+a.width,a.coords[1]+a.height]],[this.draggingFrom,t])&&this.userSelection.add(a);this.multipleSelectionOn=!1,this.diagramEvent$.next(new G(this.userSelection.all(),!0)),I()}};Ue.canvasCount=0;let ut=Ue;class Ai{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const e of this.grid)e.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const e of this.grid)e.push(void 0)}addRowTop(){const e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.splice(0,0,e),this.offsetY=this.offsetY+1}addRowBottom(){const e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.push(e)}get(e){if(this.grid[e[1]+this.offsetY])return this.grid[e[1]+this.offsetY][e[0]+this.offsetX]}set(e,t){for(;e[0]<-this.offsetX;)this.addColumnLeft();for(;e[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;e[1]<-this.offsetY;)this.addRowTop();for(;e[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[e[1]+this.offsetY][e[0]+this.offsetX]=t}getClosestEmptyCoordinate(e){if(this.get(e)===void 0)return e;const t=[...e];for(let s=1;;++s){const a=s%2>0?s:-s,l=a>0?1:-1,o=[t[0]+a,t[1]+a];for(let n=t[0];n!==o[0]+l;n+=l)if(t[0]=n,this.get(t)===void 0)return t;for(let n=t[1];n!==o[1]+l;n+=l)if(t[1]=n,this.get(t)===void 0)return t}}}class Vo{constructor(e){this.gapSize=e}apply(e){var n;if(e.nodes.length===0)return e;const t=new Ai,s=e.nodes.filter(r=>!r.parent);for(;s.length>0;)Ei(s[0],t,[0,0],s);const a=Math.max(...e.nodes.map(r=>r.width)),l=Math.max(...e.nodes.map(r=>r.height)),o=this.gapSize!==void 0?this.gapSize:(((n=e.canvas)==null?void 0:n.gridSize)||0)*2;for(let r=t.minY();r<=t.maxY();++r)for(let d=t.minX();d<=t.maxX();++d){const c=t.get([d,r]);c!==void 0&&c.move([d*(a+o),r*(l+o)])}return e}}const Ei=(i,e,t,s)=>{const a=e.getClosestEmptyCoordinate(t);e.set(a,i),Y(s,i);for(const l of i.getAdjacentNodes())s.includes(l)&&Ei(l,e,a,s)};class _o{constructor(e){this.gapSize=e}apply(e){var c;if(e.nodes.length===0)return e;const t=new Ai,s=e.nodes.filter(h=>!h.parent),a={},l=s[0];let o=[l];for(a[l.id]=[0,0];s.length>0;){const h=[];for(const g of o){t.set(t.getClosestEmptyCoordinate(a[g.id]),g),Y(s,g);const p=g.getAdjacentNodes();for(const f of p)s.includes(f)&&(h.push(f),a[f.id]=a[g.id])}if(h.length>0)o=h;else if(s.length>0){const g=s[0];o=[g],a[g.id]=t.getClosestEmptyCoordinate([0,0])}}const n=Math.max(...e.nodes.map(h=>h.width)),r=Math.max(...e.nodes.map(h=>h.height)),d=this.gapSize!==void 0?this.gapSize:(((c=e.canvas)==null?void 0:c.gridSize)||0)*2;for(let h=t.minY();h<=t.maxY();++h)for(let g=t.minX();g<=t.maxX();++g){const p=t.get([g,h]);p!==void 0&&p.move([g*(n+d),h*(r+d)])}return e}}class Qe{constructor(e){this.gapSize=e}apply(e){var n;if(e.nodes.length===0)return e;const t=this.gapSize!==void 0?this.gapSize:(((n=e.canvas)==null?void 0:n.gridSize)||0)*2;let s=e.nodes.filter(r=>!r.parent);const a=s[0];Y(s,a);const l=[[a]];for(;s.length>0;){const r=l[l.length-1],d=[];for(const c of r){const h=c.getAdjacentNodes();for(const g of h)s.includes(g)&&(Y(s,g),d.push(g))}d.length>0?l.push(d):(l.push(s),s=[])}let o=0;for(const r of l){let d=0;for(const h of r)h.move([o,d]),d+=t+h.height;const c=Math.max(...r.map(h=>h.width));o+=t+c}for(const r of e.connections)r.tighten();return e}}class jo{constructor(e){this.gapSize=e}apply(e){var h;if(e.nodes.length===0)return e;new Qe().apply(e);const t=this.gapSize!==void 0?this.gapSize:(((h=e.canvas)==null?void 0:h.gridSize)||0)*2,s=.99,a=1,l=.1,o=2e5,n=.5,r=1,d=.002;let c=100;for(;c>a;){c=c*s;const g=[0,0];{for(const p of e.nodes)g[0]=g[0]+p.coords[0]+p.width/2,g[1]=g[1]+p.coords[1]+p.width/2;g[0]=g[0]/e.nodes.length,g[1]=g[1]/e.nodes.length}for(const p of e.nodes){const f=p.getAdjacentNodes();for(const m of e.nodes){const u=[p.coords[0]+p.width/2,p.coords[1]+p.height/2],b=[m.coords[0]+m.width/2,m.coords[1]+m.height/2],x=ci(p.coords,m.coords),v=[m.coords[0],m.coords[1]];if(f.includes(m)&&x>0&&(x>t+(Math.max(p.width,p.height)+Math.max(m.width,m.height))/2?(v[0]=v[0]-(b[0]-u[0])*l,v[1]=v[1]-(b[1]-u[1])*l):(v[0]=v[0]+(b[0]-u[0])*n,v[1]=v[1]+(b[1]-u[1])*n)),x>0){const w=o/(x*x);v[0]=v[0]+w*(b[0]-u[0])/x,v[1]=v[1]+w*(b[1]-u[1])/x}else v[0]=v[0]+r*(Math.random()*2-1),v[1]=v[1]+r*(Math.random()*2-1);v[0]=v[0]-(b[0]-g[0])*d,v[1]=v[1]-(b[1]-g[1])*d,v[0]-m.coords[0]>c?v[0]=m.coords[0]+c:v[0]-m.coords[0]<-c&&(v[0]=m.coords[0]-c),v[1]-m.coords[1]>c?v[1]=m.coords[1]+c:v[1]-m.coords[1]<-c&&(v[1]=m.coords[1]-c),m.move(v)}}}if(e.canvas&&e.canvas.snapToGrid)for(const g of e.nodes){const p=e.canvas.getClosestGridPoint(g.coords);g.move(p)}for(const g of e.connections)g.tighten();return e}}class Oo{constructor(e){this.gapSize=e}apply(e){var l;if(e.nodes.length===0)return e;const t=this.gapSize!==void 0?this.gapSize:(((l=e.canvas)==null?void 0:l.gridSize)||0)*2,s=e.nodes.filter(o=>!o.parent);s.sort((o,n)=>n.type.priority-o.type.priority);let a=0;for(const o of s)o.move([a,0]),a+=o.width+t;return e}}class Do{constructor(e){this.gapSize=e}apply(e){var c;if(e.nodes.length===0)return e;const t=Math.max(...e.nodes.map(h=>h.getPriority())),s=Math.min(...e.nodes.map(h=>h.getPriority()));if(t===s)return new Qe().apply(e),e;const a=this.gapSize!==void 0?this.gapSize:(((c=e.canvas)==null?void 0:c.gridSize)||0)*2,l=e.nodes.filter(h=>!h.parent),o=[],n=e.nodes.filter(h=>!h.parent).filter(h=>h.getPriority()>=t),r=[];if(n.length>1){const h=n[0];n.splice(0,1),r.push(h);const g=[h],p=[h];for(;g.length>0;){const f=g[0];g.splice(0,1),n.includes(f)&&(r.push(f),Y(n,f));const m=f.getAdjacentNodes();for(const u of m)p.includes(u)||(g.push(u),p.push(u))}for(const f of n)r.push(f)}else r.push(n[0]);for(const h of r)Y(l,h),o.push([h]);for(o.push([]),l.sort((h,g)=>g.type.priority-h.type.priority);l.length>0;){const h=l[0];l.splice(0,1);const g=[h],p=[h];let f=!1;for(;g.length>0;){const m=g[0];g.splice(0,1);const u=r.indexOf(m);if(u>=0){o[u].push(h),f=!0;break}else{const b=m.getAdjacentNodes();for(const x of b)p.includes(x)||(g.push(x),p.push(x))}}f||o[o.length-1].push(h)}let d=0;for(let h=0;h<o.length;++h){let g=0;for(let f=0;f<o[h].length;++f){const m=o[h][f];m.move([d,g]),g+=a+m.height}const p=Math.max(...o[h].map(f=>f.width));d+=a+p}for(const h of e.connections)h.tighten();return e}}class Ho{constructor(e){this.gapSize=e}apply(e){var c;if(e.nodes.length===0)return e;const t=Math.max(...e.nodes.map(h=>h.getPriority())),s=Math.min(...e.nodes.map(h=>h.getPriority()));if(t===s)return new Qe().apply(e),e;const a=this.gapSize!==void 0?this.gapSize:(((c=e.canvas)==null?void 0:c.gridSize)||0)*2,l=e.nodes.filter(h=>!h.parent).sort((h,g)=>g.getPriority()-h.getPriority()),o=[];for(;l.length>0;){const h=l[0];l.splice(0,1);const g=new mt(void 0,h);Ti(g,l),o.push(g)}const n=[];for(const h of o)n.push([h]),Li(h,n,n.length);const r=Math.max(...e.nodes.map(h=>h.height));let d=0;for(let h=0;h<n.length;++h){let g=0;for(let f=0;f<n[h].length;++f){const m=n[h][f];m.node.move([d,g]),g+=(a+r)*m.countBranchHeight()}const p=Math.max(...n[h].map(f=>f.node.width));d+=a+p}for(const h of e.connections)h.tighten();return e}}const Ti=(i,e)=>{for(const t of i.node.getAdjacentNodes().sort((s,a)=>a.getPriority()-s.getPriority())){const s=e.indexOf(t);if(s>=0){e.splice(s,1);const a=i.addBranch(t);Ti(a,e)}}},Li=(i,e,t)=>{if(i.branches.length>0){for(;t>=e.length;)e.push([]);for(const s of i.branches)e[t].push(s),Li(s,e,t+1)}};class mt{constructor(e,t){this.parent=e,this.branches=[],this.depth=0,this.node=t}addBranch(e){const t=new mt(this,e);return t.depth=this.depth+1,this.branches.push(t),t}countBranchHeight(){if(this.branches.length<=0)return 1;{let e=0;for(const t of this.branches)e+=t.countBranchHeight();return e}}}class Go{constructor(e){this.gapSize=e}apply(e){var l;if(e.nodes.length===0)return e;const t=this.gapSize!==void 0?this.gapSize:(((l=e.canvas)==null?void 0:l.gridSize)||0)*2,s=e.nodes.filter(o=>!o.parent);s.sort((o,n)=>n.type.priority-o.type.priority);let a=0;for(const o of s)o.move([0,a]),a+=o.height+t;return e}}const li={adjacency:new Vo,breadth:new Qe,"breadth-adjacency":new _o,force:new jo,horizontal:new Oo,priority:new Do,tree:new Ho,vertical:new Go},Fo=M.createContext({}),Se=M.createContext({});class Bo{constructor(e,t){this.onTitleChange=e,this.onValueSetChange=t}get title(){return this._title}set title(e){this._title=e,this.onTitleChange(e)}get valueSet(){return this._valueSet}set valueSet(e){this._valueSet=e,this.onValueSetChange(e)}highlightProperty(...e){}}const pt=({direction:i,collapsableSelector:e,collapsableAdditionalSelector:t,collapsed:s,disabled:a,rule:l,collapsedValue:o,visibleValue:n,onCollapse:r})=>{const[d,c]=M.useState(s),h=()=>{if(!a){const p=!d;c(p),r==null||r(p);let f;if(typeof e=="string")f=L.select(e),t&&(f=f.select(t));else{const m=e;if(!m)throw new Error("collapsableSelector is not a valid ref");f=L.select(m.current),t&&(f=f.select(t))}f.style(l,p?o:n)}},g=()=>{switch(i){case k.Right:return a?"daga-horizontal-none":d?"daga-horizontal-right":"daga-horizontal-left";case k.Bottom:return a?"daga-vertical-none":d?"daga-vertical-down":"daga-vertical-up";case k.Left:return a?"daga-horizontal-none":d?"daga-horizontal-left":"daga-horizontal-right";case k.Top:return a?"daga-vertical-none":d?"daga-vertical-up":"daga-vertical-down"}};return y.jsx("daga-collapse-button",{children:y.jsx("button",{className:`daga-collapse-button daga-${i}`,onClick:h,children:y.jsx("div",{className:g()})})})},Uo=()=>{const i=M.useContext(Se),e=M.useRef(null),[t,s]=M.useState([]);xe.merge(i.validatorChange$,i.diagramChange$).pipe(xe.map(()=>a())).subscribe();const a=()=>{s([]);for(const o of i.validators){const n=o.validate(i.model);s(n)}},l=o=>{var n,r,d,c;if(o.elementId&&(o.propertyNames===void 0||o.propertyNames.length===0)){const h=i.model.nodes.get(o.elementId)||i.model.connections.get(o.elementId);h&&i.userHighlight.add(h)}else if(o.elementId&&o.propertyNames!==void 0&&o.propertyNames.length>0){i.userSelection.openInPropertyEditor(i.model.nodes.get(o.elementId)||i.model.connections.get(o.elementId));const h=i.model.nodes.get(o.elementId)||i.model.connections.get(o.elementId);h&&i.userHighlight.add(h),(r=(n=i.parentComponent)==null?void 0:n.propertyEditor)==null||r.highlightProperty(...o.propertyNames)}else!o.elementId&&o.propertyNames!==void 0&&o.propertyNames.length>0&&(i.userSelection.openInPropertyEditor(),(c=(d=i.parentComponent)==null?void 0:d.propertyEditor)==null||c.highlightProperty(...o.propertyNames))};return y.jsx("daga-errors",{children:y.jsxs("div",{ref:e,className:"daga-errors",children:[t.length===0&&y.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:y.jsx("span",{children:"No errors found"})}),t.length>0&&y.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[y.jsxs("span",{children:[t.length," errors found"]}),y.jsx("div",{className:"daga-collapse-button-container",children:y.jsx(pt,{collapsableSelector:e,collapsableAdditionalSelector:".daga-error-panel",direction:k.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),t.length>0&&y.jsx("div",{className:"daga-error-panel",children:y.jsx("ol",{children:t.map((o,n)=>y.jsx("li",{onClick:()=>l(o),dangerouslySetInnerHTML:{__html:o.message}},n))})})]})})},Yo=200,di=i=>(i||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),$i=({disabled:i,options:e,value:t,onChange:s})=>{const a=M.useRef(null),[l,o]=M.useState("");let n;const[r,d]=M.useState([]),[c,h]=M.useState([]),[g,p]=M.useState([]),[f,m]=M.useState([]),[u,b]=M.useState(!1);M.useEffect(()=>{var P;o(((P=e.find(R=>Ce(R.key,t)))==null?void 0:P.label)||"")},[t,e]);const x=P=>{if(!i)switch(P.key){case te.PageDown:n===void 0?(S(0),z(0)):(S(n+5),z(n)),P.preventDefault();break;case te.ArrowDown:n===void 0?(S(0),z(0)):(S(n+1),z(n)),P.preventDefault();break;case te.PageUp:n===void 0?(S(e.length-1),z(e.length-1)):(S(n-5),z(n)),P.preventDefault();break;case te.ArrowUp:n===void 0?(S(e.length-1),z(e.length-1)):(S(n-1),z(n)),P.preventDefault();break;case te.Escape:w(),P.preventDefault();break;case te.Enter:_(e[n||0]),P.preventDefault();break;default:v()}},v=()=>{if(!i){const P=di(l.trim());d([]),h([]),p([]),m([]);for(const R of e){const X=di(R.label).indexOf(P);if(X>=0){const B=R.label.substring(0,X),O=R.label.substring(X,X+P.length),Q=R.label.substring(X+P.length);d(ee=>[...ee,R]),h(ee=>[...ee,B]),p(ee=>[...ee,O]),m(ee=>[...ee,Q])}}b(!0)}},w=()=>{b(!1)},S=P=>{if(!i){if(n=P,P===void 0)return;P<0&&(n=0),P>=e.length&&(n=e.length-1)}},A=()=>{setTimeout(()=>{w()},Yo)},z=P=>{var J;const R=(J=a.current)==null?void 0:J.querySelectorAll("li")[P];R&&R.scrollIntoView({block:"center"})},N=()=>{i||(o(""),b(!1),n=void 0)},_=P=>{i||(o(P.label),b(!1),n=void 0,s(P.key))};return y.jsxs("div",{ref:a,className:`daga-autocomplete ${u?"daga-showing-options":""}`,children:[y.jsxs("div",{className:"daga-autocomplete-input",children:[y.jsx("input",{value:l,disabled:i,onKeyUp:x,onFocus:v,onBlur:A,onChange:P=>o(P.target.value)}),l!==""&&y.jsx("button",{className:"daga-clear",onClick:N})]}),y.jsx("div",{className:"daga-autocomplete-options",children:y.jsxs("ul",{className:"daga-autocomplete-option-list",children:[r.length===0&&y.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),r.map((P,R)=>y.jsxs("li",{className:`daga-autocomplete-option ${R===n?"daga-focused":""}`,onMouseMove:()=>S(R),onClick:()=>_(P),children:[y.jsx("span",{children:c[R]}),y.jsx("span",{className:"daga-match",children:g[R]}),y.jsx("span",{children:f[R]})]},R))]})})]})},Xo=(i,e)=>{var t;return((t=i.find(s=>s.key===e))==null?void 0:t.label)||`${e}`},Wo=({disabled:i,allowRepeats:e,options:t,value:s,onChange:a})=>{const[l,o]=M.useState(),[n,r]=M.useState([]),[d,c]=M.useState([]);M.useEffect(()=>{const u=s.length===0,b=s.map(x=>Xo(t,x));r(b),u&&a(s),m()},[s,t]);const h=u=>{for(const b of s)if(b===u)return!0;return!1},g=u=>{s.length>u&&(s.splice(u,1),r(n.filter((b,x)=>x!==u)),a(s),m())},p=()=>{l!==void 0&&(e||!h(l))&&(a(s.concat(l)),f())},f=()=>{o("")},m=()=>{if(!e){const u=[];for(const b of t)h(b.key)||u.push(b);c(u)}};return y.jsxs("div",{children:[s.map((u,b)=>y.jsxs("div",{className:"daga-value-item-element",children:[y.jsx("span",{className:"daga-input",children:n[b]}),!i&&y.jsx("button",{className:"daga-property-button",onClick:()=>g(b),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},b)),!i&&y.jsxs("div",{className:"daga-value-item-input",children:[y.jsx("div",{className:"daga-input daga-relatively-positioned",children:y.jsx($i,{disabled:i,options:e?t||[]:d||[],value:l,onChange:o})}),y.jsx("button",{className:"daga-property-button",onClick:p,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Zo=({disabled:i,allowRepeats:e,value:t,onChange:s})=>{const[a,l]=M.useState(""),o=g=>{for(const p of g||[])if(p===g)return!0;return!1},n=g=>{t.length>g&&s(t.filter((p,f)=>f!==g))},r=(g,p,f)=>{const m=t.map((u,b)=>b===p?f==="blur"?g.trim():g:u);s(m)},d=()=>{const g=a.trim();g!==""&&(e||!o(g))&&(s(t.concat(g)),c())},c=()=>{l("")},h=g=>{g.key==="Enter"&&d()};return y.jsxs(y.Fragment,{children:[t.map((g,p)=>y.jsxs("div",{className:"daga-value-item-element",children:[y.jsx("input",{className:"daga-input",disabled:i,value:g,onChange:f=>r(f.target.value,p,"change"),onBlur:f=>r(f.target.value,p,"blur")}),y.jsx("button",{className:"daga-property-button",onClick:()=>n(p),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},p)),!i&&y.jsxs("div",{className:"daga-value-item-input",children:[y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",onKeyUp:h,value:a,onChange:g=>l(g.target.value)}),y.jsx("button",{className:"daga-clear",onClick:c})]}),y.jsx("button",{className:"daga-property-button",onClick:d,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Ko=({disabled:i,value:e,onChange:t})=>{const[s,a]=M.useState(""),[l,o]=M.useState(""),[n,r]=M.useState({}),d=u=>{const b={};Object.keys(e).forEach(x=>{x!==u&&(b[x]=e[x])}),t(b)},c=(u,b,x)=>{const v=x==="blur"?b.trim():b;if(x==="blur"){if(u!==v){const w={};Object.keys(e).forEach(S=>{S===u?w[v]=e[S]:w[S]=e[S]}),t(w),r(S=>{const A={...S};return delete A[u],A})}}else r(w=>({...w,[u]:b}))},h=(u,b,x)=>{const v=x==="blur"?b.trim():b;if(v!==""){const w={};Object.keys(e).forEach(S=>{S===u?w[S]=v:w[S]=e[S]}),t(w)}},g=()=>{const u=s.trim(),b=l.trim();if(u!==""&&b!==""){const x={};Object.keys(e).forEach(v=>{x[v]=e[v]}),x[u]=b,t(x),a(""),o("")}},p=()=>{a("")},f=()=>{o("")},m=u=>{u.key==="Enter"&&g()};return y.jsxs("div",{children:[Object.entries(e).map(([u,b],x)=>y.jsxs("div",{className:"daga-value-item-element",children:[y.jsx("input",{id:`key-${x}`,className:"daga-input",type:"text",disabled:i,value:n[u]??u,onChange:v=>c(u,v.target.value,"change"),onBlur:v=>c(u,v.target.value,"blur")}),y.jsx("input",{id:`value-${x}`,className:"daga-input",type:"text",disabled:i,value:b,onChange:v=>h(u,v.target.value,"change"),onBlur:v=>h(u,v.target.value,"blur")}),y.jsx("button",{className:"daga-property-button",onClick:()=>d(u),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},u)),!i&&y.jsxs("div",{className:"daga-value-item-input",children:[y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",value:s,onKeyUp:m,onChange:u=>a(u.target.value),onBlur:u=>c(s,u.target.value,"blur")}),y.jsx("button",{className:"daga-clear",onClick:p})]}),y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",value:l,onKeyUp:m,onChange:u=>o(u.target.value),onBlur:u=>h(s,u.target.value,"blur")}),y.jsx("button",{className:"daga-clear",onClick:f})]}),y.jsx("button",{className:"daga-property-button",onClick:g,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Mi=({valueSet:i,onValueChange:e,depth:t})=>{var r;const a=M.useContext(Se).canUserPerformAction(C.UpdateValues)&&((r=i==null?void 0:i.rootElement)==null?void 0:r.removed)!==!0,l=d=>"daga-property-name-"+d.replace(/\s/g,""),o=d=>{if(typeof d=="string")return d;if(d==null||isNaN(d.valueOf()))return"";const c=new Date(d),h=c.getTimezoneOffset();return c.setMinutes(c.getMinutes()-h),c.toISOString().substring(0,19)},n=d=>new Date(d);return y.jsx("daga-object-editor",{children:i.displayedProperties.map(d=>y.jsxs("div",{className:`daga-property ${l(d.name)}`,children:[y.jsx("p",{className:"daga-property-name",children:d.name}),d.type===V.Text&&y.jsx("input",{type:"daga-text",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c.target.value)}),d.type===V.TextArea&&y.jsx("textarea",{disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c.target.value)}),d.type===V.Number&&y.jsx("input",{type:"number",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c.target.value)}),d.type===V.Color&&y.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c.target.value)}),d.type===V.Datetime&&y.jsx("input",{type:"datetime-local",disabled:!d.editable||!a,value:o(i==null?void 0:i.getValue(d.name)),onChange:c=>e(i,d,n(c.target.value))}),d.type===V.Date&&y.jsx("input",{type:"date",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c.target.value)}),d.type===V.Time&&y.jsx("input",{type:"time",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c.target.value)}),d.type===V.Url&&y.jsx("input",{type:"url",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c.target.value)}),d.type===V.Boolean&&y.jsxs("div",{className:"daga-radio",children:[y.jsxs("label",{className:"daga-radio-item daga-radio-start"+((i==null?void 0:i.getValue(d.name))===!1?" daga-checked":""),children:[y.jsx("input",{type:"radio",disabled:!d.editable||!a,name:d.name,value:"false",checked:(i==null?void 0:i.getValue(d.name))===!1,onChange:()=>e(i,d,!1)}),"No"]}),y.jsxs("label",{className:"daga-radio-item daga-radio-end"+((i==null?void 0:i.getValue(d.name))===!0?" daga-checked":""),children:[y.jsx("input",{type:"radio",disabled:!d.editable||!a,name:d.name,value:"true",checked:(i==null?void 0:i.getValue(d.name))===!0,onChange:()=>e(i,d,!0)}),"Yes"]})]}),d.type===V.Option&&y.jsx("div",{className:"daga-relatively-positioned",children:y.jsx($i,{disabled:!d.editable||!a,options:d.options||[],value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c)})}),(d.type===V.OptionList||d.type===V.OptionSet)&&y.jsx(Wo,{disabled:!d.editable||!a,allowRepeats:d.type===V.OptionList,options:d.options||[],value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c)}),(d.type===V.TextList||d.type===V.TextSet)&&y.jsx(Zo,{disabled:!d.editable||!a,allowRepeats:d.type===V.TextList,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c)}),d.type===V.TextMap&&y.jsx(Ko,{disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(i,d,c)}),d.type===V.Object&&y.jsx("div",{className:"daga-left-bar",children:y.jsx(Mi,{valueSet:i.getSubValueSet(d.name),onValueChange:e,depth:t+1})})]},d.name))})},Ni=({valueSet:i,depth:e})=>{const t=M.useContext(Se),s=M.useRef(null),a=r=>"daga-property-name-"+r.replace(/\s/g,""),l=()=>{for(const r of(i==null?void 0:i.displayedProperties)||[]){let d=0,c=0,h=0;const g=L.select(s.current).select(`.daga-property.${a(r.name)}.daga-depth-${e}`);g.select("button.daga-move-button").call(L.drag().on(T.Start,p=>{var u;I($.Grabbing);const f=t.getPointerLocationRelativeToScreen(p);if(f.length<2||isNaN(f[0])||isNaN(f[1]))return;const m=(u=g.node())==null?void 0:u.getBoundingClientRect();d=(m==null?void 0:m.width)||0,c=(m==null?void 0:m.height)||0,g.style("position","fixed").style("left",`${f[0]-d/2}px`).style("top",`${f[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1)}).on(T.Drag,p=>{I($.Grabbing);const f=t.getPointerLocationRelativeToScreen(p);f.length<2||isNaN(f[0])||isNaN(f[1])||(g.style("position","fixed").style("left",`${f[0]-d/2}px`).style("top",`${f[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1),L.select(s.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${e}`).style("visibility","hidden").style("height",0),h=o(f),L.select(s.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${e}`).style("visibility","visible").style("height","0.25rem"))}).on(T.End,p=>{var m,u;I($.Auto),g.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),L.select(s.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${e}`).style("visibility","hidden").style("height",0);const f=t.getPointerLocationRelativeToScreen(p);f.length<2||isNaN(f[0])||isNaN(f[1])||(h=o(f),(m=i==null?void 0:i.displayedProperties)==null||m.splice(i.displayedProperties.indexOf(r),1),(u=i==null?void 0:i.displayedProperties)==null||u.splice(h,0,r))}))}},o=r=>{var h;const d=(i==null?void 0:i.propertySet.propertyList)||[],c=[];for(let g=0;g<=d.length;++g){const p=(h=L.select(s.current).select(`.daga-dropbar.daga-index-${g}.daga-depth-${e}`).node())==null?void 0:h.getBoundingClientRect();p&&c.push([p.x+p.width/2,p.y+p.height/2])}if(c.length>0){const g=c.map(f=>((r[0]-f[0])**2+(r[1]-f[1])**2)**.5);return g.indexOf(Math.min(...g))}return 0},n=r=>{var c;if(i===void 0)return;let d;r instanceof qi?d=r:r instanceof Event?d=i==null?void 0:i.propertySet.getProperty(((c=r.target)==null?void 0:c.value)||""):d=i==null?void 0:i.propertySet.getProperty(r||""),d&&(i==null||i.hideProperty(d)),l()};return y.jsxs("daga-property-settings",{ref:s,children:[y.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${e}`}),i==null?void 0:i.displayedProperties.map((r,d)=>y.jsxs("div",{className:`daga-property-and-dropbar ${a(r.name)} daga-depth-${e}`,children:[y.jsxs("div",{className:`daga-property ${a(r.name)} daga-depth-${e}`,children:[y.jsxs("div",{className:"daga-property-name",children:[y.jsx("span",{children:r.name}),y.jsxs("div",{className:"daga-buttons",children:[y.jsx("button",{className:"daga-property-button daga-move-button",children:y.jsx("div",{className:"daga-icon daga-move-icon"})}),y.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>n(r.name),children:y.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),r.type!==V.Object&&y.jsx("div",{className:"daga-property-value",children:qo(i==null?void 0:i.getValue(r.name))}),r.type===V.Object&&y.jsx(Ni,{valueSet:i==null?void 0:i.getSubValueSet(r.name),depth:e+1})]}),y.jsx("div",{className:`daga-dropbar daga-index-${d+1} daga-depth-${e}`})]},r.name))]})},qo=i=>Array.isArray(i)?i.join(", "):Ji(i)?Object.entries(i).map(e=>e.map(t=>JSON.stringify(t)).join(": ")).join(", "):i instanceof Date?i.toLocaleString():i==null?"":""+i,Jo=({location:i,direction:e,width:t,title:s,valueSet:a,onValueChange:l})=>{const o=M.useRef(null),[n,r]=M.useState(!1),[d,c]=M.useState(!1),h=()=>L.select(o.current);return M.useEffect(()=>{if(o.current)switch(e){case k.Bottom:case k.Top:h().style("width",t);break;case k.Left:case k.Right:h().style("height",t);break}},[t,e]),y.jsx("daga-property-editor",{children:y.jsxs("div",{ref:o,className:`daga-panel daga-bottom daga-${i} daga-${e}`,children:[y.jsx(pt,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:n,direction:e,collapsableSelector:o,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:r}),a&&a.propertySet&&a.propertySet.hasProperties()&&!n&&y.jsxs("div",{className:"daga-panel-content",children:[s&&y.jsxs("p",{className:"daga-title",children:[s,y.jsx("button",{className:"daga-property-button",onClick:()=>c(!d),children:y.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&y.jsx(Mi,{valueSet:a,onValueChange:l,depth:0}),d&&y.jsx(Ni,{valueSet:a,depth:0})]})]})})},Qo=6,es=i=>{const e=M.useContext(Se),[t,s]=M.useState(i.currentPalette||i.palettes[0]),[a,l]=M.useState(0),[o,n]=M.useState(void 0),r=M.useRef(null),d=m=>{if(s(m),c().selectAll("*").remove(),l(e.getPriorityThreshold()||0),m.categories&&h(m.categories),m.templates)for(const u of m.templates)g(u)},c=()=>L.select(r.current).select(".daga-palette-view"),h=m=>{const u=c().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");u.append("option").attr("value","").text("(None selected)");for(const b in m)u.append("option").attr("value",b).text(b);u.on(E.Change,()=>{o&&c().selectAll(".daga-template-container.daga-in-category").remove();const b=u.property("value");n(b);const x=m[b]||[];for(const v of x)g(v,"daga-in-category")}),o&&(u.property("value",o),u.dispatch(E.Change))},g=(m,u)=>{if(m.templateType==="node"){const b=e.model.nodes.types.get(m.type);b?p(b,m,u):console.error(`Could not find a node type called '${m.type}'`)}else if(m.templateType==="connection"){const b=e.model.connections.types.get(m.type);b?f(b,m,u):console.error(`Could not find a connection type called '${m.type}'`)}},p=(m,u,b)=>{if(a!==void 0&&m.priority<a)return;const x=m.defaultLook.lookType==="shaped-look"?m.defaultLook.borderThickness:0,v=c().append("div").attr("class",`daga-template-container ${b!==void 0?b:""}`).style("width",`${m.defaultWidth+x}px`).style("height",`${m.defaultHeight+x}px`).call(L.drag().on(T.Drag,S=>{if(e.canUserPerformAction(C.AddNode)){const A=e.getPointerLocationRelativeToScreen(S);if(A.length<2||isNaN(A[0])||isNaN(A[1]))return;v.style("position","fixed").style("left",`${A[0]-m.defaultWidth/2-x/2}px`).style("top",`${A[1]-m.defaultHeight/2-x/2}px`).style("z-index",1)}}).on(T.Start,S=>{if(e.canUserPerformAction(C.AddNode)){I($.Grabbing);const A=e.getPointerLocationRelativeToScreen(S);if(A.length<2||isNaN(A[0])||isNaN(A[1]))return;v.style("position","fixed").style("left",`${A[0]-m.defaultWidth/2-x/2}px`).style("top",`${A[1]-m.defaultHeight/2-x/2}px`).style("z-index",1),m.isUnique&&e.model.nodes.find(z=>!z.removed&&z.type.id===m.id)!==void 0&&I($.NotAllowed)}}).on(T.End,S=>{var A;if(e.canUserPerformAction(C.AddNode)){if(I($.Auto),v.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),m.isUnique&&e.model.nodes.find(ee=>!ee.removed&&ee.type.id===m.id)!==void 0)return;const z=e.getPointerLocationRelativeToScreen(S);if(z.length<2||isNaN(z[0])||isNaN(z[1]))return;const N=document.elementFromPoint(z[0],z[1]);if(N&&!((A=e.selectCanvasView().node())!=null&&A.contains(N)))return;const _=e.getPointerLocationRelativeToCanvas(S);if(_.length<2||isNaN(_[0])||isNaN(_[1]))return;let P=[_[0]-m.defaultWidth/2,_[1]-m.defaultHeight/2];e.snapToGrid&&(P=e.getClosestGridPoint(P));const J=e.model.nodes.getAtCoordinates(_[0],_[1]).filter(ee=>ee.type.childrenTypes.includes(m.id)),X=bi(J),B=X[X.length-1];if(!m.canBeParentless&&B===void 0)return;const O=B==null?void 0:B.getLastAncestor(),Q=new yo(e,m,P,B==null?void 0:B.id,O==null?void 0:O.id,O==null?void 0:O.getGeometry(),void 0,u.label,u.values);Q.do(),e==null||e.actionStack.add(Q),I()}})).append("svg").attr("class",`palette-node ${m.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%"),w=u.look||m.defaultLook;switch(w.lookType){case"shaped-look":v.append("path").attr("d",dt(w.shape,w.borderThickness/2,w.borderThickness/2,m.defaultWidth,m.defaultHeight)).attr("fill",w.fillColor).attr("stroke",w.borderColor).attr("stroke-width",`${w.borderThickness}px`);break;case"image-look":v.append("image").attr("x",0).attr("y",0).attr("width",m.defaultWidth).attr("height",m.defaultHeight).attr("href",w.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":v.append("image").attr("x",0).attr("y",0).attr("width",w.leftMargin).attr("height",w.topMargin).attr("href",w.backgroundImageTopLeft).attr("preserveAspectRatio","none"),v.append("image").attr("x",w.leftMargin).attr("y",0).attr("width",m.defaultWidth-w.rightMargin-w.leftMargin).attr("height",w.topMargin).attr("href",w.backgroundImageTop).attr("preserveAspectRatio","none"),v.append("image").attr("x",m.defaultWidth-w.rightMargin).attr("y",0).attr("width",w.rightMargin).attr("height",w.topMargin).attr("href",w.backgroundImageTopRight).attr("preserveAspectRatio","none"),v.append("image").attr("x",0).attr("y",w.topMargin).attr("width",w.leftMargin).attr("height",m.defaultHeight-w.bottomMargin-w.topMargin).attr("href",w.backgroundImageLeft).attr("preserveAspectRatio","none"),v.append("image").attr("x",w.leftMargin).attr("y",w.topMargin).attr("width",m.defaultWidth-w.rightMargin-w.leftMargin).attr("height",m.defaultHeight-w.bottomMargin-w.topMargin).attr("href",w.backgroundImageCenter).attr("preserveAspectRatio","none"),v.append("image").attr("x",m.defaultWidth-w.rightMargin).attr("y",w.topMargin).attr("width",w.rightMargin).attr("height",m.defaultHeight-w.bottomMargin-w.topMargin).attr("href",w.backgroundImageRight).attr("preserveAspectRatio","none"),v.append("image").attr("x",0).attr("y",m.defaultHeight-w.bottomMargin).attr("width",w.leftMargin).attr("height",w.bottomMargin).attr("href",w.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),v.append("image").attr("x",w.leftMargin).attr("y",m.defaultHeight-w.bottomMargin).attr("width",m.defaultWidth-w.rightMargin-w.leftMargin).attr("height",w.bottomMargin).attr("href",w.backgroundImageBottom).attr("preserveAspectRatio","none"),v.append("image").attr("x",m.defaultWidth-w.rightMargin).attr("y",m.defaultHeight-w.bottomMargin).attr("width",w.rightMargin).attr("height",w.bottomMargin).attr("href",w.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(m.decorators)for(const S of m.decorators)v.append("foreignObject").attr("width",`${S.width}px`).attr("height",`${S.height}px`).attr("transform",`translate(${S.coords[0]},${S.coords[1]})`).html(S.html);if(u.label){const S={...D,...m.label,...u.labelLook};v.append("text").attr("transform",`translate(${(K(S)+m.defaultWidth)/2},${(U(S)+m.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${S.fontSize}px`).attr("text-anchor","middle").attr("font-family",S.fontFamily).attr("font-weight",400).attr("fill",S.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(u.label)}},f=(m,u,b)=>{const x=c().append("div").attr("class",`daga-template-container ${b!==void 0?b:""}`).style("width",`${u.width}px`).style("height",`${u.height}px`).append("svg").attr("class",`palette-button ${m.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{e.connectionType=m});x.append("path").attr("d",dt(Ye.Rectangle,0,0,u.width,u.height)).attr("fill",u.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),u.icon!==""&&x.append("image").attr("x",0).attr("y",0).attr("width",u.width).attr("height",u.height).attr("href",u.icon),u.label!==""&&x.append("text").attr("transform",`translate(${u.width/2},${u.height/2+Qo})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(u.label)};return M.useEffect(()=>{if(d(i.palettes[0]),r.current)switch(i.direction){case k.Bottom:case k.Top:r.current.style.width=i.width;break;case k.Left:case k.Right:r.current.style.height=i.width;break}},[t,i.palettes]),y.jsx("daga-palette",{children:y.jsxs("div",{ref:r,className:`daga-panel daga-${i.location} daga-${i.direction}`,children:[y.jsx(pt,{direction:i.direction,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),y.jsxs("div",{className:"daga-panel-content",children:[i.palettes.length>1&&y.jsx("div",{className:"daga-panel-tabs",children:i.palettes.map(m=>y.jsx("div",{className:`daga-panel-tab ${m===t?"daga-current-tab":""}`,onClick:()=>d(m),children:m.name}))}),y.jsx("div",{className:"daga-palette-view"})]})]})})},ts=({location:i,direction:e,enableAction:t,enableFilter:s,enableLayout:a,enableSelection:l,enableZoom:o})=>{let n=!1,r=!0,d=!1,c,h,g,p;switch(e){case k.Bottom:c="height",h="scaleY",g="top",p="bottom";break;case k.Top:c="height",h="scaleY",g="bottom",p="top";break;case k.Left:c="width",h="scaleX",g="right",p="left";break;case k.Right:c="width",h="scaleX",g="left",p="right";break}const f=M.useRef(null),m=M.useRef(null),u=M.useRef(null);M.useEffect(()=>{L.select(f.current).style(`margin-${p}`,"-1rem").style(c,"0rem").style("transform",`${h}(0)`).style("transform-origin",g)});const b=async()=>{const O=L.select(f.current);if(!d)if(r){r=!1;const Oe=`${4*O.selectChildren().size()}rem`;O.transition().duration(500).ease(L.easeLinear).style(c,Oe).style("transform",`${h}(1)`),setTimeout(()=>{d=!1},500)}else r=!0,O.transition().duration(500).ease(L.easeLinear).style(c,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{d=!1},500)},x=M.useContext(Se),v=()=>{x.zoomBy(x.zoomFactor)},w=()=>{x.zoomBy(1/x.zoomFactor)},S=()=>{x.center()},A=()=>{x.layoutFormat&&x.layoutFormat in li&&li[x.layoutFormat].apply(x.model)},z=()=>{n=!n,L.select(u.current).classed("daga-on",n).classed("daga-off",!n);const O=x.getPriorityThresholdOptions();O&&O.length>=2&&x.setPriorityThreshold(O[n?1:0])},N=()=>{x.actionStack.undo()},_=()=>{x.actionStack.redo()},P=()=>{x.userSelection.copyToClipboard()},R=()=>{x.userSelection.cutToClipboard()},J=()=>{x.userSelection.pasteFromClipboard()},X=()=>{x.userSelection.removeFromModel()},B=()=>{x.multipleSelectionOn=!0,L.select(m.current).classed("daga-on",!0).classed("daga-off",!1);const O=x.diagramEvent$.subscribe(Q=>{Q.type===xi.Selection&&(L.select(m.current).classed("daga-on",!1).classed("daga-off",!0),O.unsubscribe())})};return y.jsx("daga-diagram-buttons",{children:y.jsxs("div",{className:`daga-diagram-buttons daga-${i} daga-${e}`,children:[o&&x.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-zoom-in",onClick:v,children:y.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),o&&x.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-zoom-out",onClick:w,children:y.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),y.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:f,children:[o&&x.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-center",onClick:S,children:y.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),t&&y.jsx("button",{className:"daga-undo",onClick:N,children:y.jsx("span",{className:"daga-tooltip",children:"Undo"})}),t&&y.jsx("button",{className:"daga-redo",onClick:_,children:y.jsx("span",{className:"daga-tooltip",children:"Redo"})}),l&&y.jsx("button",{className:"daga-copy",onClick:P,children:y.jsx("span",{className:"daga-tooltip",children:"Copy"})}),l&&y.jsx("button",{className:"daga-cut",onClick:R,children:y.jsx("span",{className:"daga-tooltip",children:"Cut"})}),l&&y.jsx("button",{className:`daga-multiple-selection ${n?"daga-on":"daga-off"}`,onClick:B,ref:m,children:y.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),l&&y.jsx("button",{className:"daga-paste",onClick:J,children:y.jsx("span",{className:"daga-tooltip",children:"Paste"})}),l&&y.jsx("button",{className:"daga-delete",onClick:X,children:y.jsx("span",{className:"daga-tooltip",children:"Delete"})}),a&&x.layoutFormat&&y.jsx("button",{className:"daga-layout",onClick:A,children:y.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),s&&y.jsx("button",{className:`daga-filter ${n?"daga-on":"daga-off"}`,onClick:z,ref:u,children:y.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),y.jsx("button",{className:"daga-more-options",onClick:b,children:r?y.jsx("span",{className:"daga-tooltip",children:"More options"}):y.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},is=({config:i,model:e,onCanvasCreated:t,onDiagramEvent:s,onModelChange:a})=>{var z,N,_,P,R,J,X,B,O,Q,ee,Oe,yt,bt,vt,kt,wt,xt,Ct,St,It,At,Et,Tt,Lt,$t,Mt,Nt,Pt,zt,Rt,Vt,_t,jt,Ot,Dt,Ht,Gt,Ft,Bt,Ut,Yt,Xt,Wt,Zt;const l=new wi,o=new Ii,n=M.useRef(null),r=M.useRef(void 0),d=M.useRef(!1),c=[],[h,g]=M.useState(void 0),[p,f]=M.useState(void 0),m={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},u={refreshPalette:()=>{}},b=new Bo(le=>g(le),le=>f(le)),x={diagramButtons:m,palette:u,propertyEditor:b},v=(le=!1)=>((!r.current||le)&&(c.forEach(ce=>ce.unsubscribe()),r.current=new ut(x,i)),r.current),w=v(),S=le=>{w.initView(le),c.push(w.diagramEvent$.subscribe(ce=>{s==null||s(ce)})),c.push(w.diagramChange$.subscribe(()=>{const ce=o.export(w.model);a==null||a(ce)}))};M.useEffect(()=>{n.current&&(d.current||(S(n.current),d.current=!0,t==null||t(w)))},[n.current]),M.useMemo(()=>{n.current&&(v(!0),S(n.current),t==null||t(w))},[i]),M.useEffect(()=>{e&&l.import(w.model,e)},[e]);const A=(le,ce,Kt)=>{var qt;if(p!==void 0&&ce.editable&&!Ce(le.getValue(ce.name),Kt)){le.setValue(ce.name,Kt);const et=new ve(p.propertySet,p.rootElement);et.setValues(p.getValues()),b.valueSet=et,p.rootElement.valueSet=et,(qt=w.propertyEditorChanges$)==null||qt.next()}};return y.jsx("daga-diagram",{children:y.jsx(Fo.Provider,{value:i,children:y.jsx(Se.Provider,{value:w,children:y.jsxs("daga-diagram-editor",{children:[y.jsx("div",{className:"daga-append-to",ref:n}),y.jsxs(Se.Provider,{value:w,children:[((z=i.components)==null?void 0:z.buttons)!==void 0&&((_=(N=i.components)==null?void 0:N.buttons)==null?void 0:_.enabled)!==!1&&y.jsx(ts,{location:((R=(P=i.components)==null?void 0:P.buttons)==null?void 0:R.location)||He.BottomRight,direction:((X=(J=i.components)==null?void 0:J.buttons)==null?void 0:X.direction)||k.Top,enableAction:((O=(B=i.components)==null?void 0:B.buttons)==null?void 0:O.enableAction)!==!1,enableFilter:((ee=(Q=i.components)==null?void 0:Q.buttons)==null?void 0:ee.enableFilter)===!0,enableLayout:((yt=(Oe=i.components)==null?void 0:Oe.buttons)==null?void 0:yt.enableLayout)===!0,enableSelection:((vt=(bt=i.components)==null?void 0:bt.buttons)==null?void 0:vt.enableSelection)!==!1,enableZoom:((wt=(kt=i.components)==null?void 0:kt.buttons)==null?void 0:wt.enableZoom)!==!1}),((xt=i.components)==null?void 0:xt.palette)!==void 0&&((St=(Ct=i.components)==null?void 0:Ct.palette)==null?void 0:St.enabled)!==!1&&((At=(It=i.components)==null?void 0:It.palette)==null?void 0:At.sections)&&(((Lt=(Tt=(Et=i.components)==null?void 0:Et.palette)==null?void 0:Tt.sections)==null?void 0:Lt.length)||0)>0&&y.jsx(es,{location:((Mt=($t=i.components)==null?void 0:$t.palette)==null?void 0:Mt.location)||He.TopLeft,direction:((Pt=(Nt=i.components)==null?void 0:Nt.palette)==null?void 0:Pt.direction)||k.Bottom,width:((Rt=(zt=i.components)==null?void 0:zt.palette)==null?void 0:Rt.width)||"12rem",palettes:((_t=(Vt=i.components)==null?void 0:Vt.palette)==null?void 0:_t.sections)||[]}),((jt=i.components)==null?void 0:jt.propertyEditor)!==void 0&&((Dt=(Ot=i.components)==null?void 0:Ot.propertyEditor)==null?void 0:Dt.enabled)!==!1&&y.jsx(Jo,{location:((Gt=(Ht=i.components)==null?void 0:Ht.propertyEditor)==null?void 0:Gt.location)||He.TopRight,direction:((Bt=(Ft=i.components)==null?void 0:Ft.propertyEditor)==null?void 0:Bt.direction)||k.Bottom,width:((Yt=(Ut=i.components)==null?void 0:Ut.propertyEditor)==null?void 0:Yt.width)||"24rem",title:h,valueSet:p,onValueChange:A}),((Xt=i.components)==null?void 0:Xt.errors)!==void 0&&((Zt=(Wt=i.components)==null?void 0:Wt.errors)==null?void 0:Zt.enabled)!==!1&&y.jsx(Uo,{})]})]})})})})};exports.DagaDiagram=is;
|
|
1
|
+
"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(`
|
|
2
|
+
`).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)===null||(i==null?void 0:i.padding)===void 0?ft.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?ft.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],ho=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?ft.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?ft.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),go=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?ft.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?ft.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),bi={lookType:"shaped-look",shape:Zt.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Ft=nt(bi),ki={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:bi};class uo{constructor(t){const e={...ki,...t};this.id=e.id,this.name=e.name,this.label=e.label,this.allowsOutgoing=e.allowsOutgoing,this.allowsIncoming=e.allowsIncoming,this.width=e.width;const s=nt(e.look);this.defaultLook=s.defaultLook,this.selectedLook=s.selectedLook,this.highlightedLook=s.highlightedLook,this.selectedAndHighlightedLook=s.selectedAndHighlightedLook}}class xt extends Tt{constructor(t,e,s,a,l,o,n){if(t.ports.get(n)!==void 0)throw new Error(`DiagramPort with id "${n}" already exists`);if(!n)throw new Error("DiagramPort cannot have an empty or null id");super(t,n),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=s,this.coords=a,this.connectionPoint=l||a,this.direction=o}get type(){return this._type}set type(t){this._type=t,this.updateInView()}get typeString(){var t;return(t=this.type)==null?void 0:t.id}set typeString(t){if(t===void 0)this.type=void 0;else{const e=this.model.ports.types.get(t);e&&(this.type=e)}}get allowsOutgoing(){var t,e;return((t=this.type)==null?void 0:t.allowsOutgoing)!==void 0?(e=this.type)==null?void 0:e.allowsOutgoing:!0}get allowsIncoming(){var t,e;return((t=this.type)==null?void 0:t.allowsIncoming)!==void 0?(e=this.type)==null?void 0:e.allowsIncoming:!0}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){var t,e,s,a;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(t=this.type||Ft)==null?void 0:t.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(e=this.type||Ft)==null?void 0:e.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(s=this.type||Ft)==null?void 0:s.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(a=this.type||Ft)==null?void 0:a.defaultLook}set look(t){if(t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get width(){var t;return((t=this.type)==null?void 0:t.width)||ki.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updatePortsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.incomingConnections)e.raise();for(const e of this.outgoingConnections)e.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof j)return this.rootElement;if(this.rootElement instanceof B)return this.rootElement.node}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||zt}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];this.coords=t,this.connectionPoint[0]=this.connectionPoint[0]+e[0],this.connectionPoint[1]=this.connectionPoint[1]+e[1];for(const s of this.outgoingConnections)s.setStart(this);for(const s of this.incomingConnections)s.setEnd(this);this.label&&this.label.move([this.label.coords[0]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return ci(this.coords,t)}}class mo extends pt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,s,a,l,o){const n=new xt(this.model,t,e,s,a,l,o);return super.add(n),n.updateInView(),e!==void 0&&e.ports.push(n),n}remove(t){const e=this.get(t,!0);if(e){for(;e.outgoingConnections.length>0;)this.model.connections.remove(e.outgoingConnections[0].id);for(;e.incomingConnections.length>0;)this.model.connections.remove(e.incomingConnections[0].id);e.label&&this.model.fields.remove(e.label.id),(e.rootElement instanceof j||e.rootElement instanceof B)&&Y(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class wi{import(t,e){t.clear(),e.id&&(t.id=e.id),t.name=e.name,t.description=e.description,t.type=e.type,t.createdAt=new Date(e.createdAt),t.updatedAt=new Date(e.updatedAt);for(const s of e.nodes||[])this.importNode(t,s);for(const s of e.connections||[])this.importConnection(t,s);return e.data&&t.valueSet.setValues(e.data),e.collabMeta&&(t.logicalClock=e.collabMeta.logicalClock,t.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),t}importNode(t,e){var a,l,o,n,r,d,h,c,f,p;const s=t.nodes.types.get(e.type);if(s){const m=new j(t,s,e.coords,e.id);if(t.nodes.add(m),m.width=e.width,m.height=e.height,e.label){if(s.decorators)for(let g=0;g<s.decorators.length;++g){const v=s.decorators[g];t.decorators.new(m,[m.coords[0]+v.coords[0],m.coords[1]+v.coords[1]],v.width,v.height,m.getPriority(),v.html,`${m.id}_decorator_${g}`)}if(s.label){const g={...O,...s.label},v=new mt(t,m,[m.coords[0]+Z(g),m.coords[1]+U(g)],m.width-Z(g)-at(g),m.height-U(g)-ot(g),g.fontSize,g.fontFamily,g.color,g.selectedColor,g.horizontalAlign,g.verticalAlign,g.orientation,"",g.editable,g.fit);v.text=e.label,m.label=v,t.fields.add(v),v.updateInView()}}for(const g of e.children||[]){const v=this.importNode(t,g);v!==void 0&&((a=m.children)==null||a.push(v),v.parent=m)}for(const g of e.sections||[]){const v=new B(t,m,g.indexXInNode,g.indexYInNode,g.coords,g.width,g.height,g.id);if((l=m.sections)==null||l.push(v),t.sections.add(v),g.label&&(d=(r=(n=(o=s.sectionGrid)==null?void 0:o.sections)==null?void 0:n[g.indexYInNode])==null?void 0:r[g.indexXInNode])!=null&&d.label){const k={...O,...(p=(f=(c=(h=s.sectionGrid)==null?void 0:h.sections)==null?void 0:c[g.indexYInNode])==null?void 0:f[g.indexXInNode])==null?void 0:p.label},A=new mt(t,v,[v.coords[0]+Z(k),v.coords[1]+U(k)],v.width-Z(k)-at(k),v.height-U(k)-ot(k),k.fontSize,k.fontFamily,k.color,k.selectedColor,k.horizontalAlign,k.verticalAlign,k.orientation,"",k.editable,k.fit);A.text=g.label,v.label=A,t.fields.add(A),A.updateInView()}let w=0;for(const k of g.ports||[]){const A=k.type!==void 0?t.ports.types.get(k.type):void 0,S=new xt(t,A,v,k.coords,k.connectionPoint,k.direction,k.id);if(v.ports.push(S),t.ports.add(S),k.label){if(s.ports.length>w&&(A!=null&&A.label)){const L={...O,...A==null?void 0:A.label};let M;switch(S.direction){case b.Top:case b.Left:M=[S.coords[0]-L.fontSize,S.coords[1]-L.fontSize];break;case b.Bottom:M=[S.coords[0]-L.fontSize,S.coords[1]+L.fontSize];break;case b.Right:M=[S.coords[0]+L.fontSize,S.coords[1]-L.fontSize];break;default:M=S.coords}const x=new mt(t,S,M,L.fontSize,L.fontSize,L.fontSize,L.fontFamily,L.color,L.selectedColor,L.horizontalAlign,L.verticalAlign,L.orientation,"",L.editable,L.fit);x.text=k.label,S.label=x,t.fields.add(x),x.updateInView()}++w}k.collabMeta&&(S.selfRemoved=k.collabMeta.selfRemoved,S.selfRemovedTimestamp=k.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(S.label,k.collabMeta.label)),S.updateInView()}g.collabMeta&&(v.selfRemoved=g.collabMeta.selfRemoved,v.selfRemovedTimestamp=g.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(v.label,g.collabMeta.label)),v.updateInView()}let u=0;for(const g of e.ports||[]){const v=g.type!==void 0?t.ports.types.get(g.type):void 0,w=new xt(t,v,m,g.coords,g.connectionPoint,g.direction,g.id);if(m.ports.push(w),t.ports.add(w),g.label){if(s.ports.length>u&&(v!=null&&v.label)){const k={...O,...v==null?void 0:v.label};let A;switch(w.direction){case b.Top:case b.Left:A=[w.coords[0]-k.fontSize,w.coords[1]-k.fontSize];break;case b.Bottom:A=[w.coords[0]-k.fontSize,w.coords[1]+k.fontSize];break;case b.Right:A=[w.coords[0]+k.fontSize,w.coords[1]-k.fontSize];break;default:A=w.coords}const S=new mt(t,w,A,k.fontSize,k.fontSize,k.fontSize,k.fontFamily,k.color,k.selectedColor,k.horizontalAlign,k.verticalAlign,k.orientation,"",k.editable,k.fit);S.text=g.label,w.label=S,t.fields.add(S),S.updateInView()}++u}g.collabMeta&&(w.selfRemoved=g.collabMeta.selfRemoved,w.selfRemovedTimestamp=g.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(w.label,g.collabMeta.label)),w.updateInView()}return e.data&&m.valueSet.setValues(e.data),e.collabMeta&&(m.selfRemoved=e.collabMeta.selfRemoved,m.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,m.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(m.label,e.collabMeta.label),m.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),m.updateInView(),m.raise(),m}}importConnection(t,e){const s=t.connections.types.get(e.type);if(s){const a=new ct(t,s,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(a),a.startLabel=e.startLabel,a.middleLabel=e.middleLabel,a.endLabel=e.endLabel,a.points=e.points,e.data&&a.valueSet.setValues(e.data),e.collabMeta&&(a.selfRemoved=e.collabMeta.selfRemoved,a.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,a.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),a.updateInView(),a.raise(),a}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class Jt{constructor(t,e,s,a,l,o,n){this.canvas=t,this.id=e,this.typeId=s,this.coords=a,this.parentId=l,this.label=o,this.values=n}do(){var e;const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&((e=this.canvas.model.nodes.get(this.parentId))==null||e.addChild(t)),t.label&&(t.label.text=this.label||""),this.values!==void 0?t.valueSet.setValues(structuredClone({...t.valueSet.getValues(),...this.values})):t.valueSet.resetValues()}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new Jt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class pe{constructor(t,e,s,a,l,o,n){this.canvas=t,this.nodeId=e,this.copyColumnIndex=s,this.copyRowIndex=a,this.removeColumnIndex=l,this.removeRowIndex=o,this.timestamp=n}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&Ct(this.timestamp,t.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&t.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&t.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&t.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&t.removeSectionRow(this.removeRowIndex),t.geometryTimestamp=this.timestamp)}serialize(){return{type:"addSection",nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(t,e){return new pe(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class ye{constructor(t,e,s){this.canvas=t,this.to=e,this.timestamp=s}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&Ct(this.timestamp,e.geometryTimestamp)){const s=this.to[t];e.move([s[0],s[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new ye(t,e.to,e.timestamp)}}class Ht{constructor(t,e,s,a){this.canvas=t,this.nodeIds=e,this.delta=s,this.timestamp=a}do(){var t;for(const e of this.nodeIds){const s=this.canvas.model.nodes.get(e,!0);s&&Ct(this.timestamp,s.geometryTimestamp)&&(s.move([s.coords[0]+this.delta[0],s.coords[1]+this.delta[1]]),(t=s.parent)==null||t.fitToChild(s),s.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new Ht(t,e.nodeIds,e.delta,e.timestamp)}}class st{constructor(t,e,s,a){this.canvas=t,this.nodeId=e,this.to=s,this.timestamp=a}do(){var e,s,a;const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&Ct(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),(e=t.label)!=null&&e.fit&&this.canvas.fitFieldRootInView(t.label.id);for(const l of t.sections)(s=l.label)!=null&&s.fit&&this.canvas.fitFieldRootInView(l.label.id);(a=t.parent)==null||a.fitToChild(t),t.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new st(t,e.nodeId,e.to,e.timestamp)}}class Gt{constructor(t,e,s,a,l){this.canvas=t,this.childId=e,this.parentId=s,this.childGeometry=a,this.timestamp=l}do(){var s;const t=this.canvas.model.nodes.get(this.childId,!0),e=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;t&&(this.parentId===void 0||e)&&Ct(this.timestamp,t.geometryTimestamp)&&((s=t.parent)==null||s.removeChild(t),t.setGeometry(this.childGeometry),e==null||e.addChild(t))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,e){return new Gt(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class Qt{constructor(t,e,s,a,l){this.canvas=t,this.id=e,this.typeId=s,this.startId=a,this.endId=l}do(){const t=this.canvas.model.ports.get(this.startId,!0),e=this.canvas.model.ports.get(this.endId,!0);t&&e&&this.canvas.model.connections.new(this.typeId,t,e,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,e){return new Qt(t,e.id,e.typeId,e.startId,e.endId)}}class Nt{constructor(t,e,s,a){this.canvas=t,this.fieldId=e,this.to=s,this.timestamp=a}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&Ct(this.timestamp,t.textTimestamp)&&(t.text=this.to,t.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Nt(t,e.fieldId,e.to,e.timestamp)}}class Pt{constructor(t,e,s,a){this.canvas=t,this.id=e,this.to=s,this.timestamp=a}getValueSet(){var t;return this.id===void 0?this.canvas.model.valueSet:(t=this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))==null?void 0:t.valueSet}do(){var t;(t=this.getValueSet())==null||t.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Pt(t,e.id,e.to,e.timestamp)}}class lt{constructor(t,e,s,a,l,o,n,r){this.canvas=t,this.nodeIds=e,this.sectionIds=s,this.portIds=a,this.connectionIds=l,this.fieldIds=o,this.selfRemoved=n,this.timestamp=r}doOne(t){t&&Ct(this.timestamp,t.selfRemovedTimestamp)&&(t.selfRemoved=this.selfRemoved,t.selfRemovedTimestamp=this.timestamp)}do(){for(const t of this.nodeIds)this.doOne(this.canvas.model.nodes.get(t,!0));for(const t of this.sectionIds)this.doOne(this.canvas.model.sections.get(t,!0));for(const t of this.portIds)this.doOne(this.canvas.model.ports.get(t,!0));for(const t of this.connectionIds)this.doOne(this.canvas.model.connections.get(t,!0));for(const t of this.fieldIds)this.doOne(this.canvas.model.fields.get(t,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,e){return new lt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class te{constructor(t,e,s){this.canvas=t,this.nodes=e,this.connections=s}do(){const t=new wi;this.canvas.userSelection.clear();for(const e of this.nodes){const s=t.importNode(this.canvas.model,e);s&&this.canvas.userSelection.add(s)}for(const e of this.connections){const s=t.importConnection(this.canvas.model,e);s&&this.canvas.userSelection.add(s)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new te(t,e.nodes,e.connections)}}class fo{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=ii()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+ii()}doCollaboratively(t){if(t.do(),this.onSend){const e=t.serialize();this.onSend(e)}}receive(t){switch("timestamp"in t&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,t.timestamp[0])),t.type){case"addNode":{Jt.deserialize(this.canvas,t).do();break}case"addSection":{pe.deserialize(this.canvas,t).do();break}case"applyLayout":{ye.deserialize(this.canvas,t).do();break}case"move":{Ht.deserialize(this.canvas,t).do();break}case"setGeometry":{st.deserialize(this.canvas,t).do();break}case"setParent":{Gt.deserialize(this.canvas,t).do();break}case"addConnection":{Qt.deserialize(this.canvas,t).do();break}case"editField":{Nt.deserialize(this.canvas,t).do();break}case"updateValues":{Pt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{lt.deserialize(this.canvas,t).do();break}case"paste":{te.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class po{constructor(t,e){this.canvas=t,this.maximum=e,this.history=[],this.index=0}add(t){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(t)):(this.history.push(t),++this.index),this.canvas.diagramChange$.next({action:t,method:0})}undo(){let t;if(this.index>0){let e;do--this.index,t=this.history[this.index],e=t.undo();while(!e&&this.index>0)}this.canvas.diagramChange$.next({action:t,method:1})}redo(){let t;if(this.index<this.history.length){let e;do t=this.history[this.index],e=t.redo(),++this.index;while(!e&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:t,method:2})}}var C=(i=>(i.AddConnection="add-connection",i.AddNode="add-node",i.AddSectionAction="add-section",i.ApplyLayout="apply-layout",i.Clipboard="clipboard",i.ContextMenu="context-menu",i.EditField="edit-field",i.MoveNode="move-node",i.Paste="paste",i.Remove="remove",i.StretchNode="stretch-node",i.StretchSection="stretch-section",i.UpdateValues="update-values",i.Zoom="zoom",i))(C||{});class yo{constructor(t,e,s,a,l,o,n,r,d){this.canvas=t,this.type=e,this.coords=s,this.parentId=a,this.ancestorId=l,this.fromAncestorGeometry=o,this.toAncestorGeometry=n,this.label=r,this.values=d,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Jt(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const e=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){const t=this.canvas.model.nodes.get(this.id),e=new lt(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new lt(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return t===void 0}}class ne{constructor(t,e,s){this.canvas=t,this.nodeIds=e,this.delta=s}do(){const t=new Ht(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const t=new Ht(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class X{constructor(t,e,s,a,l,o,n,r){this.canvas=t,this.intent=e,this.nodeId=s,this.from=a,this.to=l,this.ancestorId=o,this.fromAncestorGeometry=n,this.toAncestorGeometry=r}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class vo{constructor(t,e,s,a,l,o,n,r,d){this.canvas=t,this.childId=e,this.fromParentId=s,this.toParentId=a,this.fromChildGeometry=l,this.toChildGeometry=o,this.ancestorId=n,this.fromAncestorGeometry=r,this.toAncestorGeometry=d}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const s=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(s)}return t!==void 0}redo(){return this.do()}}class re{constructor(t,e,s,a){this.canvas=t,this.type=e,this.startId=s,this.endId=a,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Qt(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=this.canvas.model.connections.get(this.id),e=new lt(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}redo(){const t=this.canvas.model.connections.get(this.id),e=new lt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class ri{constructor(t,e,s,a){this.canvas=t,this.fieldId=e,this.from=s,this.to=a}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new Nt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}undo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.to=t.text;const e=new Nt(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}redo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.from=t.text;const e=new Nt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class bo{constructor(t,e,s,a){this.canvas=t,this.id=e,this.from=s,this.to=a}do(){const t=new Pt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Pt(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.to=e.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}redo(){const t=new Pt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.from=e.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}}class ko{constructor(t,e,s,a,l,o){this.canvas=t,this.nodeIds=e,this.sectionIds=s,this.portIds=a,this.connectionIds=l,this.fieldIds=o}do(){const t=this.nodeIds.map(s=>this.canvas.model.nodes.get(s)!==void 0).includes(!0)||this.sectionIds.map(s=>this.canvas.model.sections.get(s)!==void 0).includes(!0)||this.portIds.map(s=>this.canvas.model.ports.get(s)!==void 0).includes(!0)||this.connectionIds.map(s=>this.canvas.model.connections.get(s)!==void 0).includes(!0)||this.fieldIds.map(s=>this.canvas.model.fields.get(s)!==void 0).includes(!0),e=new lt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}undo(){const t=this.nodeIds.map(s=>this.canvas.model.nodes.get(s)===void 0).includes(!0)||this.sectionIds.map(s=>this.canvas.model.sections.get(s)===void 0).includes(!0)||this.portIds.map(s=>this.canvas.model.ports.get(s)===void 0).includes(!0)||this.connectionIds.map(s=>this.canvas.model.connections.get(s)===void 0).includes(!0)||this.fieldIds.map(s=>this.canvas.model.fields.get(s)===void 0).includes(!0),e=new lt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){return this.do()}}class wo{constructor(t,e,s,a){this.canvas=t,this.nodes=e,this.connections=s,this.coords=a}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const l of this.nodes)l.coords[0]<t[0]&&(t[0]=l.coords[0]),l.coords[1]<t[1]&&(t[1]=l.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,s={};for(const l of this.nodes){const o=l.id,n=this.canvas.collabEngine.freshId();if(s[o]=n,l.id=n,e&&(l.coords=[l.coords[0]+e[0],l.coords[1]+e[1]]),l.sections)for(const r of l.sections){const d=r.id;if(r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),s[d]=r.id,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]]),r.ports)for(const h of r.ports){const c=h.id;h.id.includes(l.id)?h.id=h.id.replace(l.id,n):h.id=this.canvas.collabEngine.freshId(),s[c]=h.id,e&&(h.coords=[h.coords[0]+e[0],h.coords[1]+e[1]])}}if(l.ports)for(const r of l.ports){const d=r.id;r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),s[d]=r.id,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]])}}for(const l of this.connections){const o=this.canvas.collabEngine.freshId();if(s[l.id]=o,l.id=o,l.start=s[l.start]||l.start,l.end=s[l.end]||l.end,e)for(let n=0;n<l.points.length;++n)l.points[n]=[l.points[n][0]+e[0],l.points[n][1]+e[1]]}const a=new te(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(a),!0}undo(){const t=this.nodes.map(s=>this.canvas.model.nodes.get(s.id)!==void 0).includes(!0)||this.connections.map(s=>this.canvas.model.connections.get(s.id)!==void 0).includes(!0),e=new lt(this.canvas,this.nodes.map(s=>s.id),[],[],this.connections.map(s=>s.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=this.nodes.map(s=>this.canvas.model.nodes.get(s.id)===void 0).includes(!0)||this.connections.map(s=>this.canvas.model.connections.get(s.id)===void 0).includes(!0),e=new lt(this.canvas,this.nodes.map(s=>s.id),[],[],this.connections.map(s=>s.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class ee{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var xi=(i=>(i[i.DoubleClick=0]="DoubleClick",i[i.SecondaryClick=1]="SecondaryClick",i[i.Selection=2]="Selection",i[i.Highlight=3]="Highlight",i))(xi||{});class vt extends ee{constructor(t,e,s){super(0),this.cause=t,this.target=e,this.coords=s}}class bt extends ee{constructor(t,e,s){super(1),this.cause=t,this.target=e,this.coords=s}}class G extends ee{constructor(t,e){super(2),this.targets=t,this.selected=e}}class it extends ee{constructor(t){super(3),this.target=t}}class Ci extends Tt{constructor(t,e,s,a,l,o,n,r){if(t.objects.get(r)!==void 0)throw new Error(`DiagramDecorator with id "${r}" already exists`);if(!r)throw new Error("DiagramDecorator cannot have an empty or null id");super(t,r),this.rootElement=e,this.coords=s,this.width=a,this.height=l,this.priority=o,this.html=n}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateDecoratorsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class xo extends pt{constructor(t){super(),this.model=t}new(t,e,s,a,l,o,n){const r=new Ci(this.model,t,e,s,a,l,o,n);return super.add(r),r.updateInView(),t!==void 0&&t.decorators.push(r),r}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof j||e.rootElement instanceof B)&&Y(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Co extends Tt{constructor(t,e,s,a,l,o,n){if(t.objects.get(n)!==void 0)throw new Error(`DiagramObject with id "${n}" already exists`);if(!n)throw new Error("DiagramObject cannot have an empty or null id");super(t,n),this.coords=e,this.width=s,this.height=a,this.priority=l,this.html=o}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateObjectsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class So extends pt{constructor(t){super(),this.model=t}new(t,e,s,a,l,o){const n=new Co(this.model,t,e,s,a,l,o);return super.add(n),n.updateInView(),n}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Si{constructor(t,e,s,a,l,o=[]){this.nodes=new ao(this),this.sections=new ro(this),this.ports=new mo(this),this.connections=new to(this),this.fields=new eo(this),this.objects=new So(this),this.decorators=new xo(this),this.canvas=t,this.id=e,this.name=s,this.description=a,this.type=l,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new wt(new qt(o),this)}clear(){var t,e;(t=this.canvas)==null||t.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),(e=this.canvas)==null||e.updateModelInView()}}const kt=i=>!!i.button,ae=(i,t,e,s,a,l,o,n)=>_i(i,[t,e],s,a,Math.max(10,o||0,n||0)*l),I=i=>{i?N.select("body").style("cursor",i):N.select("body").style("cursor",P.Auto)},ut=i=>i instanceof j?i:i instanceof B?i.node||i:i.rootElement instanceof j||i.rootElement instanceof B||i.rootElement instanceof xt?ut(i.rootElement):i,le=i=>{i.filter(".shaped-look").append("path"),i.filter(".image-look").append("image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),i.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none")},de=i=>{i.filter(".shaped-look").select("path").attr("d",t=>ge(t.look.shape,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor).attr("stroke",t=>t.look.borderColor).attr("stroke-width",t=>`${t.look.borderThickness}px`),i.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",t=>t.width).attr("height",t=>t.height).attr("href",t=>t.look.backgroundImage),i.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopLeft),i.filter(".stretchable-image-look").select("image.top-image").attr("x",t=>t.look.leftMargin).attr("y",0).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTop),i.filter(".stretchable-image-look").select("image.top-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",0).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopRight),i.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageLeft),i.filter(".stretchable-image-look").select("image.center-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageCenter),i.filter(".stretchable-image-look").select("image.right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageRight),i.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomLeft),i.filter(".stretchable-image-look").select("image.bottom-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottom),i.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomRight)},Vt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Io=(i,t,e)=>{const s=t.append("defs");if(i.gridSize>0&&isFinite(i.gridSize)){const a=s.append("pattern").attr("id",e).attr("x",-i.gridSize/2).attr("y",-i.gridSize/2).attr("width",i.gridSize).attr("height",i.gridSize).attr("patternUnits","userSpaceOnUse");switch(a.append("rect").attr("x",0).attr("y",0).attr("width",i.gridSize).attr("height",i.gridSize).attr("fill",i.backgroundColor),i.gridStyle){case"dots":a.append("circle").attr("cx",i.gridSize/2).attr("cy",i.gridSize/2).attr("r",i.gridSize*i.gridThickness).attr("fill",i.gridColor);break;case"lines":a.append("line").attr("x1",i.gridSize/2).attr("x2",i.gridSize/2).attr("y1",0).attr("y2",i.gridSize).attr("stroke-width",i.gridSize*i.gridThickness).attr("stroke",i.gridColor),a.append("line").attr("x1",0).attr("x2",(i.gridSize-i.gridSize*i.gridThickness)/2).attr("y1",i.gridSize/2).attr("y2",i.gridSize/2).attr("stroke-width",i.gridSize*i.gridThickness).attr("stroke",i.gridColor),a.append("line").attr("x1",(i.gridSize+i.gridSize*i.gridThickness)/2).attr("x2",i.gridSize).attr("y1",i.gridSize/2).attr("y2",i.gridSize/2).attr("stroke-width",i.gridSize*i.gridThickness).attr("stroke",i.gridColor);break}t.select("rect").attr("fill",`url(#${e})`)}},me=96,W=32,$t=me+W,Ao=Math.PI/4,Eo=100,ai={customButtons:[]};class To{constructor(t,e){this.canvas=t,this.config=e||ai}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),s=this.canvas.getPointerLocationRelativeToCanvas(t),a=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-$t}px`).attr("y",`${e[1]-$t}px`).attr("width",`${2*$t}px`).attr("height",`${2*$t}px`).style("pointer-events","none").on(E.ContextMenu,o=>{this.canvas.canUserPerformAction(C.ContextMenu)&&(t.preventDefault(),this.open(o))}).on(E.Click,o=>{o.preventDefault(),this.close()});this.contextMenuContainer=a;const l=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"CUT",imageClass:"daga-cut",onPress:o=>{o.userSelection.cutToClipboard(),o.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&l.push({name:"COPY",imageClass:"daga-copy",onPress:o=>{o.userSelection.copyToClipboard(),o.cancelAllUserActions()}}),this.canvas.canUserPerformAction(C.Paste)&&l.push({name:"PASTE",imageClass:"daga-paste",onPress:o=>{o.userSelection.pasteFromClipboard(o.getClosestGridPoint(s)),o.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"DELETE",imageClass:"daga-delete",onPress:o=>{o.userSelection.removeFromModel(),o.cancelAllUserActions()}});for(const o of this.config.customButtons||ai.customButtons)(o.condition===void 0||o.condition(this.canvas))&&l.push(o);l.length===0&&l.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let o=0;o<l.length;++o){const n=l[o],r=n.onPress,d=(o+.5-l.length/2)*Ao,h=a.append("xhtml:div").attr("class",`daga-context-menu-button ${n.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*W}px`).style("height",`${2*W}px`).style("border-radius",`${W}px`).style("pointer-events","auto").on(E.Click,c=>{r&&(c.preventDefault(),r(this.canvas))}).on(E.KeyDown,c=>{r&&c.key===tt.Enter&&(c.preventDefault(),r(this.canvas))});n.imageClass!==void 0?h.append("xhtml:div").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass):n.image!==void 0&&h.append("xhtml:img").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).attr("src",n.image),h.append("xhtml:span").style("position","absolute").style("left",`${.2*W}px`).style("top",`${1.1*W}px`).style("text-align","center").style("width",`${1.6*W}px`).style("height",`${.35*W}px`).style("margin","0").style("font-size",`${.35*W}px`).style("font-weight","700").style("user-select","none").text(n.name),h.transition().ease(N.easeLinear).duration(Eo).tween("progress",()=>c=>{const f=d*c;return h.style("left",`${Math.sin(f)*me-W+$t}px`).style("top",`${-Math.cos(f)*me-W+$t}px`)})}}close(){var t;(t=this.contextMenuContainer)==null||t.remove(),this.contextMenuContainer=void 0}}class Lo extends pt{constructor(t){super(),this.focus=void 0,this.canvas=t}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,(t instanceof mt||t instanceof Ci)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof j){for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateNodesInView(t.id)}else if(t instanceof B){for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}else t instanceof xt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof ct&&this.canvas.updateConnectionsInView(t.id)}clear(){for(;this.entities.length>0;){const t=this.entities[0];this.remove(t.id),t.updateInView()}this.focus=void 0}}const $o=1;class Ii{export(t,e=!1){const s={name:t.name,type:t.type,typeVersion:$o,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(s.id=t.id),t.description&&(s.description=t.description);for(const a of t.nodes.all(!0))!e&&a.removed||a.parent===void 0&&s.nodes.push(this.exportNode(a,e));for(const a of t.connections.all(!0))!e&&a.removed||s.connections.push(this.exportConnection(a,e));return s}exportNode(t,e=!1){var o,n,r,d,h,c;const s=[];for(const f of t.children)s.push(this.exportNode(f,e));const a=[];for(const f of t.sections){const p=[];for(const m of f.ports)p.push({id:m.id,type:(o=m.type)==null?void 0:o.id,coords:Lt(m.coords),connectionPoint:Lt(m.connectionPoint),direction:m.direction,label:((n=m.label)==null?void 0:n.text)||"",...e?{collabMeta:{removed:m.removed,selfRemoved:m.selfRemoved,selfRemovedTimestamp:m.selfRemovedTimestamp,...this.exportLabelCollabMeta(m)}}:{}});a.push({id:f.id,ports:p,label:((r=f.label)==null?void 0:r.text)||"",indexXInNode:f.indexXInNode,indexYInNode:f.indexYInNode,coords:Lt(f.coords),width:f.width,height:f.height,...e?{collabMeta:{removed:f.removed,selfRemoved:f.selfRemoved,selfRemovedTimestamp:f.selfRemovedTimestamp,...this.exportLabelCollabMeta(f)}}:{}})}const l=[];for(const f of t.ports)l.push({id:f.id,type:(d=f.type)==null?void 0:d.id,coords:Lt(f.coords),connectionPoint:Lt(f.connectionPoint),direction:f.direction,label:((h=f.label)==null?void 0:h.text)||"",...e?{collabMeta:{removed:f.removed,selfRemoved:f.selfRemoved,selfRemovedTimestamp:f.selfRemovedTimestamp,...this.exportLabelCollabMeta(f)}}:{}});return{id:t.id,type:t.type.id,children:s,sections:a,ports:l,label:((c=t.label)==null?void 0:c.text)||"",coords:Lt(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){var s,a;return{id:t.id,type:t.type.id,start:((s=t.start)==null?void 0:s.id)||"",end:((a=t.end)==null?void 0:a.id)||"",startLabel:t.startLabel,middleLabel:t.middleLabel,endLabel:t.endLabel,points:t.points,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,dataTimestamps:t.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:t}){return t?{label:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,textTimestamp:t.textTimestamp}}:{}}}const Mo="Diagram properties";class No extends pt{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(It.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof j||t instanceof ct)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof B?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof j&&t.sections))for(const e of t.sections)super.add(e),e.updateInView()}remove(t){const e=this.get(t);if(e&&(this.propertyEditorSelection===e&&this.openInPropertyEditor(void 0),super.remove(t),e.updateInView(),e instanceof j&&e.sections))for(const s of e.sections)super.remove(s.id),s.updateInView()}toggle(t){this.contains(t.id)?this.remove(t.id):this.add(t)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const t=this.entities[0];super.remove(t.id),t.updateInView()}}move(t){for(const e of this.all())e instanceof j&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],s=[],a=[],l=[];for(const n of this.all())n instanceof j?t.push(n.id):n instanceof B?e.push(n.id):n instanceof xt?s.push(n.id):n instanceof ct?a.push(n.id):n instanceof mt&&l.push(n.id);const o=new ko(this.canvas,t,e,s,a,l);o.do(),this.canvas.actionStack.add(o)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Ii;for(const s of this.all())s instanceof j&&t.nodes.push(e.exportNode(s,!1)),s instanceof ct&&t.connections.push(e.exportConnection(s,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const s=JSON.parse(e);if(s.type!=="daga-user-selection")return;const a=new wo(this.canvas,s.nodes,s.connections,t);this.canvas.actionStack.add(a),a.do()}catch{return}})}openInPropertyEditor(t){var a;this.makeUpdateValuesAction();const e=(a=this.canvas.parentComponent)==null?void 0:a.propertyEditor;if(e===void 0)return;const s=t==null?void 0:t.valueSet;s?(this.propertyEditorSelection=t,this.propertyEditorValues=structuredClone(s.getValues()),e&&(t instanceof j||t instanceof ct?(t instanceof j?t.name?e.title=`${t.type.name}: ${t.name}`:e.title=t.type.name:t instanceof ct&&(e.title=t.type.name),e.valueSet=void 0,e.valueSet=s):(e.title=Mo,e.valueSet=void 0,e.valueSet=s))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,e&&(e.title="",e.valueSet=void 0))}makeUpdateValuesAction(){var n,r,d;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof Si?void 0:this.propertyEditorSelection.id;if(At(this.propertyEditorValues,(n=this.propertyEditorSelection)==null?void 0:n.valueSet.getValues()))return;const e=this.propertyEditorValues,s=structuredClone((r=this.propertyEditorSelection)==null?void 0:r.valueSet.getValues()),[a,l]=mi(e,s,(d=this.propertyEditorSelection)==null?void 0:d.valueSet),o=new bo(this.canvas,t,a,l);o.do(),this.canvas.actionStack.add(o),this.propertyEditorValues=s}}const Po=12,H=6,zo=25,ce="diagram-connection-unfinished",Ro=100,Wt=class Wt{constructor(t,e){var s,a,l,o,n,r,d,h,c,f,p,m,u,g,v,w,k,A,S,L,M;if(this.backgroundPatternId=`daga-background-pattern-id-${Wt.canvasCount++}`,this.zoomTransform=N.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new It.Subject,this.diagramChange$=new It.Subject,this.diagramEvent$=new It.Subject,this.propertyEditorChanges$=new It.Subject,this.parentComponent=t,this.model=new Si(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new No(this),this.userHighlight=new Lo(this),this.contextMenu=new To(this,(s=e.canvas)==null?void 0:s.contextMenu),this.backgroundColor=((a=e.canvas)==null?void 0:a.backgroundColor)||"#FFFFFF",this.gridStyle=((o=(l=e.canvas)==null?void 0:l.grid)==null?void 0:o.style)??Vt.style,this.gridSize=((r=(n=e.canvas)==null?void 0:n.grid)==null?void 0:r.enabled)===!1||((d=e.canvas)==null?void 0:d.grid)===void 0?0:Math.abs(((c=(h=e.canvas)==null?void 0:h.grid)==null?void 0:c.spacing)||Vt.spacing),this.gridThickness=Math.abs(((p=(f=e.canvas)==null?void 0:f.grid)==null?void 0:p.thickness)||Vt.thickness),this.gridColor=((u=(m=e.canvas)==null?void 0:m.grid)==null?void 0:u.color)||Vt.color,this.snapToGrid=((v=(g=e.canvas)==null?void 0:g.grid)==null?void 0:v.enabled)===!1||((w=e.canvas)==null?void 0:w.grid)===void 0?!1:((A=(k=e.canvas)==null?void 0:k.grid)==null?void 0:A.snap)||Vt.snap,this.zoomFactor=((S=e.canvas)==null?void 0:S.zoomFactor)||2,this.panRate=((L=e.canvas)==null?void 0:L.panRate)||100,this.inferConnectionType=e.inferConnectionType||!1,this.multipleSelectionOn=!1,this.priorityThresholds=((M=e.canvas)==null?void 0:M.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new po(this,zo),this.collabEngine=new fo(this),e.nodeTypes)for(const x of e.nodeTypes){const R=new yi({...e.nodeTypeDefaults,...x});this.model.nodes.types.add(R)}if(e.portTypes)for(const x of e.portTypes){const R=new uo({...e.portTypeDefaults,...x});this.model.ports.types.add(R)}if(e.connectionTypes){for(const x of e.connectionTypes){const R=new fi({...e.connectionTypeDefaults,...x});this.model.connections.types.add(R)}this._connectionType=e.defaultConnection!==void 0?this.model.connections.types.get(e.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){var e,s;this._connectionType=t,(s=(e=this.parentComponent)==null?void 0:e.palette)==null||s.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){Y(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){var e,s;this.priorityThreshold=t,this.updateModelInView();for(const a of this.model.nodes)this.fitNodeInView(a.id);(s=(e=this.parentComponent)==null?void 0:e.palette)==null||s.refreshPalette()}initView(t){const e=N.select(t);e.html(""),this.diagramRoot=e.append("div").node(),N.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),N.select(this.diagramRoot).on(E.Click,()=>{var a;(a=N.select(this.diagramRoot).node())==null||a.focus()}).on(E.ContextMenu,a=>{if(this.dragging){a.preventDefault(),a.stopPropagation(),this.dragging=!1;return}const l=new bt(a,null);this.diagramEvent$.next(l),!l.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(a.preventDefault(),this.contextMenu.open(a))}).on(E.DoubleClick,a=>{const l=new vt(a,null);this.diagramEvent$.next(l)}).on(E.KeyDown,a=>{if(!a.ctrlKey&&(a.key===tt.Delete||a.key===tt.Backspace)&&this.canUserPerformAction(C.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="a"){a.preventDefault();for(const l of this.model.nodes)this.userSelection.add(l);for(const l of this.model.connections)this.userSelection.add(l);this.diagramEvent$.next(new G(this.userSelection.all(),!0))}if(a.ctrlKey&&a.key==="i"){a.preventDefault();const l=[],o=[];for(const n of this.model.nodes)this.userSelection.toggle(n),n.selected?l.push(n):o.push(n);for(const n of this.model.connections)this.userSelection.toggle(n),n.selected?l.push(n):o.push(n);l.length>0&&this.diagramEvent$.next(new G(l,!0)),o.length>0&&this.diagramEvent$.next(new G(o,!1))}if(a.ctrlKey&&a.key==="c"&&this.canUserPerformAction(C.Clipboard)&&(a.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="x"&&this.canUserPerformAction(C.Clipboard)&&this.canUserPerformAction(C.Remove)&&(a.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="v"&&this.canUserPerformAction(C.Paste)){a.preventDefault();const l=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(l[0][0]+l[1][0])/2,(l[0][1]+l[1][1])/2])),this.cancelAllUserActions()}a.ctrlKey&&a.key==="y"&&(a.preventDefault(),this.actionStack.redo()),a.ctrlKey&&a.key==="z"&&(a.preventDefault(),this.actionStack.undo()),a.key==="+"&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.zoomBy(this.zoomFactor)),a.key==="-"&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.zoomBy(1/this.zoomFactor)),a.key===tt.ArrowLeft&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),a.key===tt.ArrowRight&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),a.key===tt.ArrowDown&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),a.key===tt.ArrowUp&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const s=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%");s.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(E.MouseMove,a=>{if(this.unfinishedConnection!==void 0){const l=this.getPointerLocationRelativeToCanvas(a);this.unfinishedConnection.endCoords=l}}).on(E.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new it(null)))}).on(E.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new it(null))),this.contextMenu.close(),this.userSelection.size()>0){const a=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(a,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(N.drag().filter(a=>this.multipleSelectionOn||kt(a)).on($.Start,a=>{this.startMultipleSelection(a)}).on($.Drag,a=>{this.continueMultipleSelection(a)}).on($.End,a=>{this.finishMultipleSelection(a)})).call(this.zoomBehavior=N.zoom().on(he.Zoom,a=>{if(a.sourceEvent){if(!this.canUserPerformAction(C.Zoom)){I(P.NotAllowed);return}a.sourceEvent.type===E.Wheel&&a.sourceEvent.wheelDelta!==void 0?(a.sourceEvent.wheelDelta>0&&I(P.ZoomIn),a.sourceEvent.wheelDelta<0&&I(P.ZoomOut)):a.sourceEvent.type===E.MouseMove&&I(P.AllScroll)}this.zoomTransform=a.transform;const l=a.transform.toString();this.selectCanvasElements().attr("transform",l),N.select(`#${this.backgroundPatternId}`).attr("patternTransform",l),this.contextMenu.close()}).on(he.End,()=>{I()})),Io(this,s,this.backgroundPatternId),s.append("g").attr("class","daga-canvas-elements")}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView().select("rect"),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView().select("rect"),t)}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView().select("rect"),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView().select("rect"),t,e)}center(){var t;if(this.model.nodes.length>0){const e=(t=this.selectCanvasView().select("rect").node())==null?void 0:t.getBBox(),s=this.model.nodes.all(),a=Math.min(...s.map(u=>u.coords[0])),l=Math.max(...s.map(u=>u.coords[0]+u.width)),o=(a+l)/2,n=l-a,r=e.width,d=Math.min(...s.map(u=>u.coords[1])),h=Math.max(...s.map(u=>u.coords[1]+u.height)),c=(d+h)/2,f=h-d,p=e.height,m=Math.min(r/n,p/f,1);this.translateTo(o,c),this.zoomTo(m)}}getClosestGridPoint(t){return this.gridSize===0||!isFinite(this.gridSize)?t:[Math.round(t[0]/this.gridSize)*this.gridSize,Math.round(t[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){var s;const t=(s=this.selectSVGElement().node())==null?void 0:s.getBoundingClientRect(),e=[(t==null?void 0:t.width)||0,(t==null?void 0:t.height)||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return N.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return N.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return N.pointer(this.getEventHoldingCoordinates(t),N.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=e.exit(),a=e.enter().append("g").attr("id",o=>o.id).attr("class",o=>`diagram-node${o.type.resizableX?" resizable-x":""}${o.type.resizableY?" resizable-y":""} ${o.type.defaultLook.lookType}`);t&&t.length>0&&(e=e.filter(o=>t.includes(o.id)));const l=a.merge(e);s.remove(),a.on(E.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(r,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new G([n],n.selected))}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new bt(o,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(o.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)),this.userSelection.add(n),this.diagramEvent$.next(new G([n],!0)),this.contextMenu.open(o))}).on(E.DoubleClick,(o,n)=>{const r=new vt(o,n);this.diagramEvent$.next(r)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(o):this.startMovingNode(o,n)}).on($.Drag,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(o):this.continueMovingNode(o,n)}).on($.End,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(o):this.finishMovingNode(o,n),this.secondaryButton=!1})),le(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&I(P.EWResize)}).on(E.MouseOut,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(I(P.EWResize),this.currentAction=new X(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(o);n.stretch(b.Left,n.coords[0]-r[0])}}).on($.End,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(b.Left,n.coords[0]-r[0]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&I(P.NSResize)}).on(E.MouseOut,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(I(P.NSResize),this.currentAction=new X(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(o);n.stretch(b.Top,n.coords[1]-r[1])}}).on($.End,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(b.Top,n.coords[1]-r[1]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&I(P.EWResize)}).on(E.MouseOut,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(I(P.EWResize),this.currentAction=new X(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(o);n.stretch(b.Right,r[0]-(n.coords[0]+n.width))}}).on($.End,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(b.Right,r[0]-(n.coords[0]+n.width)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&I(P.NSResize)}).on(E.MouseOut,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(I(P.NSResize),this.currentAction=new X(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(o);n.stretch(b.Bottom,r[1]-(n.coords[1]+n.height))}}).on($.End,(o,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(b.Bottom,r[1]-(n.coords[1]+n.height)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),l.attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).attr("opacity",o=>o.removed?.5:1),de(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/2).attr("y1",0).attr("y2",o=>o.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",o=>o.width).attr("y1",H/2).attr("y2",H/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",o=>o.width-H/2).attr("x2",o=>o.width-H/2).attr("y1",0).attr("y2",o=>o.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",o=>o.width).attr("y1",o=>o.height-H/2).attr("y2",o=>o.height-H/2)}updateSectionsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=e.exit(),a=e.enter().append("g").attr("id",o=>o.id).attr("class",o=>{var n,r,d,h,c;return`diagram-section${(r=(n=o.node)==null?void 0:n.type)!=null&&r.resizableX?" resizable-x":""}${(h=(d=o.node)==null?void 0:d.type)!=null&&h.resizableY?" resizable-y":""} ${(c=o.look)==null?void 0:c.lookType}`});t&&t.length>0&&(e=e.filter(o=>t.includes(o.id)));const l=a.merge(e);s.remove(),a.on(E.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(d,!1))}const r=ut(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new bt(o,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){o.preventDefault();const d=ut(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new it(d)),this.userSelection.add(d),this.diagramEvent$.next(new G([d],!0)),this.contextMenu.open(o)}}).on(E.DoubleClick,(o,n)=>{const r=new vt(o,n);this.diagramEvent$.next(r)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(o);else{const r=n==null?void 0:n.node;r?this.startMovingNode(o,r):I(P.NotAllowed)}}).on($.Drag,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else{const r=n==null?void 0:n.node;r?this.continueMovingNode(o,r):I(P.NotAllowed)}}).on($.End,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{const r=n==null?void 0:n.node;r?this.finishMovingNode(o,r):I()}this.secondaryButton=!1})),le(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&I(P.EWResize)}).on(E.MouseOut,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed?(I(P.EWResize),this.currentAction=new X(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed){const h=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(b.Left,n.coords[0]-h[0],n.indexXInNode,n.indexYInNode)}}).on($.End,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===C.StretchSection){let h=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(h=this.getClosestGridPoint(h)),n.node.stretchSections(b.Left,n.coords[0]-h[0],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&I(P.NSResize)}).on(E.MouseOut,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed?(I(P.NSResize),this.currentAction=new X(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed){const h=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(b.Top,n.coords[1]-h[1],n.indexXInNode,n.indexYInNode)}}).on($.End,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===C.StretchSection){let h=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(h=this.getClosestGridPoint(h)),n.node.stretchSections(b.Top,n.coords[1]-h[1],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&I(P.EWResize)}).on(E.MouseOut,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed?(I(P.EWResize),this.currentAction=new X(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed){const h=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(b.Right,h[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on($.End,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===C.StretchSection){let h=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(h=this.getClosestGridPoint(h)),n.node.stretchSections(b.Right,h[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&I(P.NSResize)}).on(E.MouseOut,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&I()}).call(N.drag().on($.Start,(o,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed?(I(P.NSResize),this.currentAction=new X(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):I(P.NotAllowed)}).on($.Drag,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed){const h=this.getPointerLocationRelativeToCanvas(o);n.node.stretchSections(b.Bottom,h[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on($.End,(o,n)=>{var r,d;if(this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===C.StretchSection){let h=this.getPointerLocationRelativeToCanvas(o);this.snapToGrid&&(h=this.getClosestGridPoint(h)),n.node.stretchSections(b.Bottom,h[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}I()})),l.attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).attr("opacity",o=>o.removed?.5:1),de(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/2).attr("y1",0).attr("y2",o=>o.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",o=>o.width).attr("y1",H/2).attr("y2",H/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",o=>o.width-H/2).attr("x2",o=>o.width-H/2).attr("y1",0).attr("y2",o=>o.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",o=>o.width).attr("y1",o=>o.height-H/2).attr("y2",o=>o.height-H/2)}updatePortsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=e.exit(),a=e.enter().append("g").attr("id",o=>o.id).attr("class",o=>`diagram-port ${o.look.lookType}`);t&&t.length>0&&(e=e.filter(o=>t.includes(o.id)));const l=a.merge(e);s.remove(),a.on(E.MouseOver,(o,n)=>{var r,d,h,c,f,p,m,u,g,v,w,k;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((h=(d=(r=this.unfinishedConnection.start)==null?void 0:r.getNode())==null?void 0:d.type)==null?void 0:h.id)||"")&&((c=this.unfinishedConnection.start)!=null&&c.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((p=(f=n.getNode())==null?void 0:f.type)==null?void 0:p.id)||"")&&n.allowsIncoming||this.unfinishedConnection.type.canStartFromType(((u=(m=n.getNode())==null?void 0:m.type)==null?void 0:u.id)||"")&&n.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(((w=(v=(g=this.unfinishedConnection.start)==null?void 0:g.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&((k=this.unfinishedConnection.start)!=null&&k.allowsIncoming)||I(P.NoDrop))}).on(E.MouseOut,()=>{this.unfinishedConnection&&I(P.Grabbing)}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(d,!1))}const r=ut(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new bt(o,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){o.preventDefault();const d=ut(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new it(d)),this.userSelection.add(d),this.diagramEvent$.next(new G([d],!0)),this.contextMenu.open(o)}}).on(E.DoubleClick,(o,n)=>{const r=new vt(o,n);this.diagramEvent$.next(r)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(o):this.canUserPerformAction(C.AddConnection)&&!n.removed?(I(P.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):I(P.NotAllowed)}).on($.Drag,(o,n)=>{var r,d,h,c;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else if(this.canUserPerformAction(C.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const f=[o.x,o.y];(h=this.unfinishedConnectionTracer)==null||h.attr("d",ae(this.unfinishedConnection.look.shape,this.unfinishedConnection.startCoords,f,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.look.thickness,(r=this.unfinishedConnection.startMarkerLook)==null?void 0:r.width,(d=this.unfinishedConnection.endMarkerLook)==null?void 0:d.width));const p=(c=this.unfinishedConnectionTracer)==null?void 0:c.node();if(p){let m=2;const u=p.getTotalLength();u<m&&(m=0);const g=p.getPointAtLength(u-m);this.unfinishedConnection.endCoords=[g.x,g.y]}else this.unfinishedConnection.endCoords=f;if(this.updateConnectionsInView(ce),this.model.ports.length>0){const m=this.getPointerLocationRelativeToCanvas(o);let u=Number.POSITIVE_INFINITY,g;for(const v of this.model.ports){const w=v.distanceTo(m);w<u&&(u=w,g=v)}g&&u<Ro?this.userHighlight.focusOn(g):this.userHighlight.clear()}}}).on($.End,(o,n)=>{var r;if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{if(this.canUserPerformAction(C.AddConnection)&&!n.removed){(r=this.unfinishedConnectionTracer)==null||r.remove();const d=this.userHighlight.getFocus();if(d instanceof xt)this.finishConnection(d);else if(d instanceof mt&&d.rootElement instanceof xt)this.finishConnection(d.rootElement);else if(d instanceof j||d instanceof B||d instanceof mt){let h;if(d instanceof j||d instanceof B)h=d;else if(d.rootElement instanceof j||d.rootElement instanceof B)h=d.rootElement;else{this.dropConnection();return}const c=h.getClosestPortToPoint([o.x,o.y]);c!==void 0?this.finishConnection(c):this.dropConnection()}else this.dropConnection()}I()}this.secondaryButton=!1})),a.filter(".image-look").append("image"),le(a),l.attr("transform",o=>`translate(${o.coords[0]-o.width/2},${o.coords[1]-o.width/2})`).attr("opacity",o=>o.removed?.5:1),de(l)}updateConnectionsInView(...t){const e=this.model.connections.filter(n=>this.priorityThreshold!==void 0?n.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let s=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,n=>n.id);const a=s.exit(),l=s.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");t&&t.length>0&&(s=s.filter(n=>t.includes(n.id)));const o=l.merge(s);a.remove(),l.on(E.MouseOver,(n,r)=>{r.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new it(r)))}).on(E.Click,(n,r)=>{if(!n.ctrlKey&&!n.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(d,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(n,r)=>{if(this.dragging){n.preventDefault(),n.stopPropagation(),this.dragging=!1;return}const d=new bt(n,r);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new it(r)),this.userSelection.add(r),this.diagramEvent$.next(new G([r],!0)),this.contextMenu.open(n))}).on(E.DoubleClick,(n,r)=>{const d=new vt(n,r);this.diagramEvent$.next(d)}).call(N.drag().filter(n=>(this.secondaryButton=kt(n),!0)).on($.Start,n=>{this.startMultipleSelection(n)}).on($.Drag,n=>{this.continueMultipleSelection(n)}).on($.End,n=>{this.finishMultipleSelection(n)})),l.append("path").attr("class","diagram-connection-path"),l.append("path").attr("class","diagram-connection-path-box"),l.append("marker").attr("id",n=>`${n.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),l.append("marker").attr("id",n=>`${n.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),l.append("g").attr("class","diagram-connection-start-label"),l.select("g.diagram-connection-start-label").append("path"),l.select("g.diagram-connection-start-label").append("text").style("user-select","none"),l.append("g").attr("class","diagram-connection-middle-label"),l.select("g.diagram-connection-middle-label").append("path"),l.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),l.append("g").attr("class","diagram-connection-end-label"),l.select("g.diagram-connection-end-label").append("path"),l.select("g.diagram-connection-end-label").append("text").style("user-select","none"),o.attr("opacity",n=>n.removed?.5:1).select("path.diagram-connection-path").attr("d",n=>{var r,d;return ae(n.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(d=n.endMarkerLook)==null?void 0:d.width)}).attr("marker-start",n=>`url(#${n.id}-start-marker)`).attr("marker-end",n=>`url(#${n.id}-end-marker)`).attr("stroke",n=>n.look.color).attr("stroke-width",n=>`${n.look.thickness}px`).attr("stroke-dasharray",n=>Qe(n.look.style,n.look.thickness)).attr("fill","none"),o.select("path.diagram-connection-path-box").attr("d",n=>{var r,d;return ae(n.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(d=n.endMarkerLook)==null?void 0:d.width)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",n=>`${n.look.thickness+Po}px`).attr("stroke-dasharray",n=>Qe(n.look.style,n.look.thickness)).attr("fill","none"),o.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=e.exit(),a=e.enter().append("foreignObject").attr("id",o=>o.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(o=>t.includes(o.id)));const l=a.merge(e);s.remove(),a.style("box-sizing","border-box").on(E.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(d,!1))}const r=ut(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new bt(o,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){o.preventDefault();const d=ut(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new it(d)),this.userSelection.add(d),this.diagramEvent$.next(new G([d],!0)),this.contextMenu.open(o)}}).on(E.DoubleClick,(o,n)=>{const r=new vt(o,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.EditField)&&n.editable&&!n.removed&&(this.currentAction=new ri(this,n.id,n.text,""),this.createInputField(n.text,n.coords,n.width,n.height,n.fontSize,n.fontFamily||O.fontFamily,n.orientation,d=>{},d=>{n.text=d,this.currentAction instanceof ri&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof B&&(r=n.rootElement.node),r?this.startMovingNode(o,r):I(P.NotAllowed)}}).on($.Drag,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof B&&(r=n.rootElement.node),r?this.continueMovingNode(o,r):I(P.NotAllowed)}}).on($.End,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof B&&(r=n.rootElement.node),r?this.finishMovingNode(o,r):I()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),l.attr("x",0).attr("y",0).attr("width",o=>`${o.width}px`).attr("height",o=>`${o.height}px`).attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).attr("opacity",o=>o.removed?.5:1).select("div").style("justify-content",o=>o.horizontalAlign===Mt.Center?"center":o.horizontalAlign===Mt.Right?"flex-end":"flex-start").style("align-items",o=>o.verticalAlign===Yt.Center?"center":o.verticalAlign===Yt.Bottom?"end":"start").select("p").style("max-width",o=>o.fit?"default":"100%").style("max-height",o=>o.fit?"default":"100%").style("overflow",o=>o.fit?"default":"hidden").style("text-overflow",o=>o.fit?"default":"ellipsis").style("text-align",o=>o.horizontalAlign===Mt.Center?"center":o.horizontalAlign===Mt.Right?"end":"start").style("transform",o=>{if(isNaN(Number(o.orientation)))switch(o.orientation){case b.Top:return"rotate(0deg)";case b.Right:return"rotate(90deg)";case b.Bottom:return"rotate(180deg)";case b.Left:return"rotate(270deg)";default:return"rotate(0deg)"}else return`rotate(${o.orientation}deg)`}).style("font-size",o=>`${o.fontSize}px`).style("font-family",o=>o.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",o=>o.highlighted?600:400).style("color",o=>o.selected?o.selectedColor||"#000000":o.color||"#000000").html(o=>o.text.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"))}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=e.exit(),a=e.enter().append("foreignObject").attr("id",o=>o.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(o=>t.includes(o.id))),a.merge(e).attr("width",o=>`${o.width}px`).attr("height",o=>`${o.height}px`).attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).html(o=>o.html),s.remove(),a.on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new bt(o,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(o.preventDefault(),this.contextMenu.open(o))}).on(E.DoubleClick,(o,n)=>{const r=new vt(o,n);this.diagramEvent$.next(r)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,o=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(o)}).on($.Drag,o=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(o)}).on($.End,o=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(o)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0),o=>o.id);const s=e.exit(),a=e.enter().append("foreignObject").attr("id",o=>o.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(o=>t.includes(o.id))),a.merge(e).attr("width",o=>`${o.width}px`).attr("height",o=>`${o.height}px`).attr("transform",o=>`translate(${o.coords[0]},${o.coords[1]})`).html(o=>o.html),s.remove(),a.on(E.MouseOver,(o,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(r,!1))}if(n.rootElement){const r=ut(n.rootElement);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}}).on(E.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const r=new bt(o,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&n.rootElement){o.preventDefault();const d=ut(n.rootElement);this.userHighlight.focusOn(d),this.diagramEvent$.next(new it(d)),this.userSelection.add(d),this.diagramEvent$.next(new G([d],!0)),this.contextMenu.open(o)}}).on(E.DoubleClick,(o,n)=>{const r=new vt(o,n);this.diagramEvent$.next(r)}).call(N.drag().filter(o=>(this.secondaryButton=kt(o),!0)).on($.Start,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof B&&(r=n.rootElement.node),r?this.startMovingNode(o,r):I(P.NotAllowed)}}).on($.Drag,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof B&&(r=n.rootElement.node),r?this.continueMovingNode(o,r):I(P.NotAllowed)}}).on($.End,(o,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(o);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof B&&(r=n.rootElement.node),r?this.finishMovingNode(o,r):I()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){var o,n,r;const e=this.selectCanvasView().select(`[id='${ue(t.id)}']`),a=e.select("path").node(),l={...O,...t.type.label};if(a){const d=a.getTotalLength();e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.startLabel);const h=(o=e.select("g.diagram-connection-start-label text").node())==null?void 0:o.getBoundingClientRect();if(h){const p=t.startLabel?h.width/this.zoomTransform.k+jt(l)+Ot(l):0,m=t.startLabel?h.height/this.zoomTransform.k+Dt(l)+_t(l):0,u=a.getPointAtLength(Math.max(Z(l)+p/2,at(l)+p/2,U(l)+m/2,ot(l)+m/2));e.select("g.diagram-connection-start-label path").attr("d",Ut(-p/2,-m/2,p,m)).attr("fill",t.look.color).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${u.x},${u.y})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.middleLabel);const c=(n=e.select("g.diagram-connection-middle-label text").node())==null?void 0:n.getBoundingClientRect();if(c){const p=t.middleLabel?c.width/this.zoomTransform.k+jt(l)+Ot(l):0,m=t.middleLabel?c.height/this.zoomTransform.k+Dt(l)+_t(l):0,u=a.getPointAtLength(d/2);e.select("g.diagram-connection-middle-label path").attr("d",Ut(-p/2,-m/2,p,m)).attr("fill",t.look.color).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${u.x},${u.y})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",l.fontSize/3).attr("text-anchor","middle").attr("font-family",l.fontFamily).attr("font-size",l.fontSize).attr("fill",t.selected?l.selectedColor:l.color).style("font-kerning","none").text(t.endLabel);const f=(r=e.select("g.diagram-connection-end-label text").node())==null?void 0:r.getBoundingClientRect();if(f){const p=t.endLabel?f.width/this.zoomTransform.k+jt(l)+Ot(l):0,m=t.endLabel?f.height/this.zoomTransform.k+Dt(l)+_t(l):0,u=a.getPointAtLength(d-Math.max(Z(l)+p/2,at(l)+p/2,U(l)+m/2,ot(l)+m/2));e.select("g.diagram-connection-end-label path").attr("d",Ut(-p/2,-m/2,p,m)).attr("fill",t.look.color).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${u.x},${u.y})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${ue(t.id)}']`),s=e.select("marker.diagram-connection-start-marker"),a=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?s.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.width).attr("markerHeight",t.startMarkerLook.height).attr("refX",t.startMarkerLook.refX).attr("refY",t.startMarkerLook.refY).select("image").attr("href",t.startMarkerLook.image).attr("width",t.startMarkerLook.width).attr("height",t.startMarkerLook.height):s.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.width).attr("markerHeight",t.endMarkerLook.height).attr("refX",t.endMarkerLook.refX).attr("refY",t.endMarkerLook.refY).select("image").attr("href",t.endMarkerLook.image).attr("width",t.endMarkerLook.width).attr("height",t.endMarkerLook.height):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){var s,a,l,o;const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof j||e.rootElement instanceof B){const n=this.minimumSizeOfField(e),r=n[0]+Z((s=e.rootElement.type)==null?void 0:s.label)+at((a=e.rootElement.type)==null?void 0:a.label)-e.rootElement.width,d=n[1]+U((l=e.rootElement.type)==null?void 0:l.label)+ot((o=e.rootElement.type)==null?void 0:o.label)-e.rootElement.height;return r<=0&&d<=0}return!0}fitFieldRootInView(t,e){var a,l,o;const s=this.model.fields.get(t);if(s){if(s.rootElement instanceof j){const n=this.minimumSizeOfField(s);let r=n[0]+Z(s.rootElement.type.label)+at(s.rootElement.type.label)-s.rootElement.width,d=n[1]+U(s.rootElement.type.label)+ot(s.rootElement.type.label)-s.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,d=Math.ceil(d/this.gridSize)*this.gridSize),s.rootElement.width+r<s.rootElement.type.minWidth&&(r=s.rootElement.type.minWidth-s.rootElement.width),s.rootElement.height+d<s.rootElement.type.minHeight&&(d=s.rootElement.type.minHeight-s.rootElement.height),(e!==!1||r>0)&&s.rootElement.stretch(b.Right,r),(e!==!1||d>0)&&s.rootElement.stretch(b.Bottom,d)}if(s.rootElement instanceof B){const n=this.minimumSizeOfField(s);let r=n[0],d=n[1];for(const p of((a=s.rootElement.node)==null?void 0:a.sections)||[])p.label&&(p.indexXInNode===s.rootElement.indexXInNode&&p.indexYInNode!==s.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(p.label)[0]):p.indexXInNode!==s.rootElement.indexXInNode&&p.indexYInNode===s.rootElement.indexYInNode&&(d=Math.max(d,this.minimumSizeOfField(p.label)[1])));n[0]<r&&(n[0]=r),n[1]<d&&(n[1]=d);const h=s.rootElement.type;let c=n[0]+Z(h==null?void 0:h.label)+at(h==null?void 0:h.label)-s.rootElement.width,f=n[1]+U(h==null?void 0:h.label)+ot(h==null?void 0:h.label)-s.rootElement.height;this.snapToGrid&&(c=Math.ceil(c/this.gridSize)*this.gridSize,f=Math.ceil(f/this.gridSize)*this.gridSize),s.rootElement.width+c<(s.rootElement.getMinWidth()||0)&&(c=(s.rootElement.getMinWidth()||0)-s.rootElement.width),s.rootElement.height+f<(s.rootElement.getMinHeight()||0)&&(f=(s.rootElement.getMinHeight()||0)-s.rootElement.height),(e!==!1||c>0)&&((l=s.rootElement.node)==null||l.stretchSections(b.Right,c,s.rootElement.indexXInNode,s.rootElement.indexYInNode)),(e!==!1||f>0)&&((o=s.rootElement.node)==null||o.stretchSections(b.Bottom,f,s.rootElement.indexXInNode,s.rootElement.indexYInNode))}}}fitNodeInView(t){var s,a;const e=this.model.nodes.get(t);if(e&&e.sections.length>0&&this.priorityThreshold){let l=0,o=0;for(const n of e.sections)if(n.getPriority()>=this.priorityThreshold){const r=n.coords[0]+n.width-e.coords[0],d=n.coords[1]+n.height-e.coords[1];l=Math.max(l,r),o=Math.max(o,d)}l+=((s=e.type.sectionGrid)==null?void 0:s.margin)||0,o+=((a=e.type.sectionGrid)==null?void 0:a.margin)||0,e.stretch(b.Right,l-e.width),e.stretch(b.Bottom,o-e.height)}}selectRoot(){return N.select(this.diagramRoot)}selectSVGElement(){return N.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){var e,s,a,l;if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(((s=(e=t.getNode())==null?void 0:e.type)==null?void 0:s.id)||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(((l=(a=t.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&t.allowsIncoming))this.unfinishedConnection=new ct(this.model,this.connectionType,t,void 0,ce);else if(this.inferConnectionType){let o=this.model.connections.types.all().find(n=>{var r,d;return t.allowsOutgoing&&n.canStartFromType(((d=(r=t.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")});o===void 0&&(o=this.model.connections.types.all().find(n=>{var r,d;return t.allowsIncoming&&n.canFinishOnType(((d=(r=t.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")})),o!==void 0&&(this.unfinishedConnection=new ct(this.model,o,t,void 0,ce))}}}finishConnection(t){var e,s,a,l,o,n,r,d,h,c,f,p,m,u,g,v,w,k,A,S;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0)if(this.unfinishedConnection.start!==t)if(this.unfinishedConnection.type.canStartFromType(((l=(a=(s=(e=this.unfinishedConnection)==null?void 0:e.start)==null?void 0:s.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&((n=(o=this.unfinishedConnection)==null?void 0:o.start)!=null&&n.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((d=(r=t.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")&&t.allowsIncoming){const L=new re(this,this.unfinishedConnection.type,(h=this.unfinishedConnection.start)==null?void 0:h.id,t.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.unfinishedConnection.type.canFinishOnType(((m=(p=(f=(c=this.unfinishedConnection)==null?void 0:c.start)==null?void 0:f.getNode())==null?void 0:p.type)==null?void 0:m.id)||"")&&((g=(u=this.unfinishedConnection)==null?void 0:u.start)!=null&&g.allowsIncoming)&&this.unfinishedConnection.type.canStartFromType(((w=(v=t.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&t.allowsOutgoing){const L=new re(this,this.unfinishedConnection.type,t.id,(k=this.unfinishedConnection.start)==null?void 0:k.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.inferConnectionType){let L=this.model.connections.types.all().find(x=>{var R,T,V,K,D,J,F,Q;return x.canStartFromType(((K=(V=(T=(R=this.unfinishedConnection)==null?void 0:R.start)==null?void 0:T.getNode())==null?void 0:V.type)==null?void 0:K.id)||"")&&((J=(D=this.unfinishedConnection)==null?void 0:D.start)==null?void 0:J.allowsOutgoing)&&x.canFinishOnType(((Q=(F=t.getNode())==null?void 0:F.type)==null?void 0:Q.id)||"")&&t.allowsIncoming}),M=!1;if(L===void 0&&(L=this.model.connections.types.all().find(x=>{var R,T,V,K,D,J,F,Q;return x.canFinishOnType(((K=(V=(T=(R=this.unfinishedConnection)==null?void 0:R.start)==null?void 0:T.getNode())==null?void 0:V.type)==null?void 0:K.id)||"")&&((J=(D=this.unfinishedConnection)==null?void 0:D.start)==null?void 0:J.allowsIncoming)&&x.canStartFromType(((Q=(F=t.getNode())==null?void 0:F.type)==null?void 0:Q.id)||"")&&t.allowsOutgoing}),M=!0),L!==void 0){const x=new re(this,L,M?t.id:(A=this.unfinishedConnection.start)==null?void 0:A.id,M?(S=this.unfinishedConnection.start)==null?void 0:S.id:t.id);this.dropConnection(),x.do(),this.actionStack.add(x)}else this.dropConnection()}else this.dropConnection();else this.dropConnection()}dropConnection(){var t,e,s,a;(t=this.unfinishedConnection)==null||t.setStart(void 0),(e=this.unfinishedConnection)==null||e.setEnd(void 0),(a=(s=this.unfinishedConnection)==null?void 0:s.select())==null||a.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(t){return this.userActions[t]!==!1}createInputField(t,e,s,a,l,o,n,r,d){this.removeInputField();const h=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${s}px`).attr("height",`${a}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=h;const c=h.append("xhtml:textarea");let f,p;c.text(t).style("box-sizing","border-box").style("width",`${s}px`).style("height",`${a}px`).style("font-size",`${l}px`).style("font-family",o).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(E.KeyDown,u=>{u.stopPropagation()}).on(E.KeyUp,u=>{if(u.stopPropagation(),u.key===tt.Escape){const g=c.property("value");this.removeInputField(),d&&d(g)}}).on(E.Input,()=>{const u=c.property("value");c.attr("cols",Ui(u)+1),c.attr("rows",Yi(u)+1),c.style("width",""),c.style("height",""),f=c.property("scrollWidth")+1,p=c.property("scrollHeight")+1;const g=Math.max(f,s),v=Math.max(p,a);h==null||h.attr("width",`${g}px`),c.style("width",`${g}px`),h==null||h.attr("height",`${v}px`),c.style("height",`${v}px`),r&&r(u)}).on(E.Click,u=>{u.stopPropagation()}).on(E.FocusOut,()=>{const u=c.property("value");this.removeInputField(),d&&d(u)});const m=c.node();m.focus(),m.select()}removeInputField(){var t,e,s;(e=(t=this.inputFieldContainer)==null?void 0:t.select("input"))==null||e.on(E.Blur,null),(s=this.inputFieldContainer)==null||s.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){var a,l;const e=(l=(a=t.select())==null?void 0:a.select("p"))==null?void 0:l.node();if(!e)return[0,0];const s=e.getBoundingClientRect();return[s.width/this.zoomTransform.k,s.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(C.MoveNode)&&!e.removed)if(I(P.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(s=>s instanceof j)>1)this.currentAction=new ne(this,this.userSelection.filter(s=>s instanceof j).map(s=>s.id),e.coords);else{const s=e.getLastAncestor();this.currentAction=new X(this,C.MoveNode,e.id,e.getGeometry(),e.getGeometry(),s==null?void 0:s.id,s==null?void 0:s.getGeometry(e.id),s==null?void 0:s.getGeometry(e.id))}else I(P.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(C.MoveNode)&&(this.currentAction instanceof ne||this.currentAction instanceof X)&&!e.removed){const s=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([s[0]-e.coords[0],s[1]-e.coords[1]]):e.move(s),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){var s,a,l;if(this.canUserPerformAction(C.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let o=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(o=this.getClosestGridPoint(o)),this.currentAction instanceof ne){const n=this.currentAction.delta;this.currentAction.delta=[o[0]-n[0],o[1]-n[1]],e.selected?this.userSelection.move([n[0]-e.coords[0],n[1]-e.coords[1]]):e.move(n)}else if(this.currentAction instanceof X){e.move(o);const r=this.model.nodes.getAtCoordinates(t.x,t.y).filter(c=>c.id!==e.id&&!c.isDescendantOf(e)).filter(c=>c.type.childrenTypes.includes(e.type.id)),d=vi(r),h=d[d.length-1];if(h!==e.parent&&(e.type.canBeParentless||h!==void 0)){const c=h==null?void 0:h.getLastAncestor(),f=this.currentAction.from,p=new vo(this,e.id,(s=e.parent)==null?void 0:s.id,h==null?void 0:h.id,f,e.getGeometry(),c==null?void 0:c.id,c==null?void 0:c.getGeometry(e.id),c==null?void 0:c.getGeometry(e.id));(a=e.parent)==null||a.removeChild(e),h!==void 0&&h.addChild(e),p.toChildGeometry=e.getGeometry(e.id),p.toAncestorGeometry=c==null?void 0:c.getGeometry(e.id),this.currentAction=p}else{const c=e==null?void 0:e.getLastAncestor();this.currentAction.ancestorId=c==null?void 0:c.id,this.currentAction.fromAncestorGeometry=c==null?void 0:c.getGeometry(e.id),(l=e.parent)==null||l.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=c==null?void 0:c.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}I(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectSVGElement().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){var s,a,l,o;const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(I(P.Crosshair),(o=(l=(a=(s=this.multipleSelectionContainer)==null?void 0:s.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x))==null?void 0:a.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y))==null?void 0:l.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k))==null||o.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){var s;const e=this.getPointerLocationRelativeToCanvas(t);(s=this.multipleSelectionContainer)==null||s.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)Ri([a.coords,[a.coords[0]+a.width,a.coords[1]+a.height]],[this.draggingFrom,e])&&this.userSelection.add(a);this.multipleSelectionOn=!1,this.diagramEvent$.next(new G(this.userSelection.all(),!0)),I()}};Wt.canvasCount=0;let fe=Wt;class Ai{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const t of this.grid)t.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const t of this.grid)t.push(void 0)}addRowTop(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.splice(0,0,t),this.offsetY=this.offsetY+1}addRowBottom(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.push(t)}get(t){if(this.grid[t[1]+this.offsetY])return this.grid[t[1]+this.offsetY][t[0]+this.offsetX]}set(t,e){for(;t[0]<-this.offsetX;)this.addColumnLeft();for(;t[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;t[1]<-this.offsetY;)this.addRowTop();for(;t[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[t[1]+this.offsetY][t[0]+this.offsetX]=e}getClosestEmptyCoordinate(t){if(this.get(t)===void 0)return t;const e=[...t];for(let s=1;;++s){const a=s%2>0?s:-s,l=a>0?1:-1,o=[e[0]+a,e[1]+a];for(let n=e[0];n!==o[0]+l;n+=l)if(e[0]=n,this.get(e)===void 0)return e;for(let n=e[1];n!==o[1]+l;n+=l)if(e[1]=n,this.get(e)===void 0)return e}}}class Vo{constructor(t){this.gapSize=t}apply(t){var n;if(t.nodes.length===0)return t;const e=new Ai,s=t.nodes.filter(r=>!r.parent);for(;s.length>0;)Ei(s[0],e,[0,0],s);const a=Math.max(...t.nodes.map(r=>r.width)),l=Math.max(...t.nodes.map(r=>r.height)),o=this.gapSize!==void 0?this.gapSize:(((n=t.canvas)==null?void 0:n.gridSize)||0)*2;for(let r=e.minY();r<=e.maxY();++r)for(let d=e.minX();d<=e.maxX();++d){const h=e.get([d,r]);h!==void 0&&h.move([d*(a+o),r*(l+o)])}return t}}const Ei=(i,t,e,s)=>{const a=t.getClosestEmptyCoordinate(e);t.set(a,i),Y(s,i);for(const l of i.getAdjacentNodes())s.includes(l)&&Ei(l,t,a,s)};class _o{constructor(t){this.gapSize=t}apply(t){var h;if(t.nodes.length===0)return t;const e=new Ai,s=t.nodes.filter(c=>!c.parent),a={},l=s[0];let o=[l];for(a[l.id]=[0,0];s.length>0;){const c=[];for(const f of o){e.set(e.getClosestEmptyCoordinate(a[f.id]),f),Y(s,f);const p=f.getAdjacentNodes();for(const m of p)s.includes(m)&&(c.push(m),a[m.id]=a[f.id])}if(c.length>0)o=c;else if(s.length>0){const f=s[0];o=[f],a[f.id]=e.getClosestEmptyCoordinate([0,0])}}const n=Math.max(...t.nodes.map(c=>c.width)),r=Math.max(...t.nodes.map(c=>c.height)),d=this.gapSize!==void 0?this.gapSize:(((h=t.canvas)==null?void 0:h.gridSize)||0)*2;for(let c=e.minY();c<=e.maxY();++c)for(let f=e.minX();f<=e.maxX();++f){const p=e.get([f,c]);p!==void 0&&p.move([f*(n+d),c*(r+d)])}return t}}class ie{constructor(t){this.gapSize=t}apply(t){var n;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((n=t.canvas)==null?void 0:n.gridSize)||0)*2;let s=t.nodes.filter(r=>!r.parent);const a=s[0];Y(s,a);const l=[[a]];for(;s.length>0;){const r=l[l.length-1],d=[];for(const h of r){const c=h.getAdjacentNodes();for(const f of c)s.includes(f)&&(Y(s,f),d.push(f))}d.length>0?l.push(d):(l.push(s),s=[])}let o=0;for(const r of l){let d=0;for(const c of r)c.move([o,d]),d+=e+c.height;const h=Math.max(...r.map(c=>c.width));o+=e+h}for(const r of t.connections)r.tighten();return t}}class jo{constructor(t){this.gapSize=t}apply(t){var c;if(t.nodes.length===0)return t;new ie().apply(t);const e=this.gapSize!==void 0?this.gapSize:(((c=t.canvas)==null?void 0:c.gridSize)||0)*2,s=.99,a=1,l=.1,o=2e5,n=.5,r=1,d=.002;let h=100;for(;h>a;){h=h*s;const f=[0,0];{for(const p of t.nodes)f[0]=f[0]+p.coords[0]+p.width/2,f[1]=f[1]+p.coords[1]+p.width/2;f[0]=f[0]/t.nodes.length,f[1]=f[1]/t.nodes.length}for(const p of t.nodes){const m=p.getAdjacentNodes();for(const u of t.nodes){const g=[p.coords[0]+p.width/2,p.coords[1]+p.height/2],v=[u.coords[0]+u.width/2,u.coords[1]+u.height/2],w=ci(p.coords,u.coords),k=[u.coords[0],u.coords[1]];if(m.includes(u)&&w>0&&(w>e+(Math.max(p.width,p.height)+Math.max(u.width,u.height))/2?(k[0]=k[0]-(v[0]-g[0])*l,k[1]=k[1]-(v[1]-g[1])*l):(k[0]=k[0]+(v[0]-g[0])*n,k[1]=k[1]+(v[1]-g[1])*n)),w>0){const A=o/(w*w);k[0]=k[0]+A*(v[0]-g[0])/w,k[1]=k[1]+A*(v[1]-g[1])/w}else k[0]=k[0]+r*(Math.random()*2-1),k[1]=k[1]+r*(Math.random()*2-1);k[0]=k[0]-(v[0]-f[0])*d,k[1]=k[1]-(v[1]-f[1])*d,k[0]-u.coords[0]>h?k[0]=u.coords[0]+h:k[0]-u.coords[0]<-h&&(k[0]=u.coords[0]-h),k[1]-u.coords[1]>h?k[1]=u.coords[1]+h:k[1]-u.coords[1]<-h&&(k[1]=u.coords[1]-h),u.move(k)}}}if(t.canvas&&t.canvas.snapToGrid)for(const f of t.nodes){const p=t.canvas.getClosestGridPoint(f.coords);f.move(p)}for(const f of t.connections)f.tighten();return t}}class Oo{constructor(t){this.gapSize=t}apply(t){var l;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,s=t.nodes.filter(o=>!o.parent);s.sort((o,n)=>n.type.priority-o.type.priority);let a=0;for(const o of s)o.move([a,0]),a+=o.width+e;return t}}class Do{constructor(t){this.gapSize=t}apply(t){var h;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(c=>c.getPriority())),s=Math.min(...t.nodes.map(c=>c.getPriority()));if(e===s)return new ie().apply(t),t;const a=this.gapSize!==void 0?this.gapSize:(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,l=t.nodes.filter(c=>!c.parent),o=[],n=t.nodes.filter(c=>!c.parent).filter(c=>c.getPriority()>=e),r=[];if(n.length>1){const c=n[0];n.splice(0,1),r.push(c);const f=[c],p=[c];for(;f.length>0;){const m=f[0];f.splice(0,1),n.includes(m)&&(r.push(m),Y(n,m));const u=m.getAdjacentNodes();for(const g of u)p.includes(g)||(f.push(g),p.push(g))}for(const m of n)r.push(m)}else r.push(n[0]);for(const c of r)Y(l,c),o.push([c]);for(o.push([]),l.sort((c,f)=>f.type.priority-c.type.priority);l.length>0;){const c=l[0];l.splice(0,1);const f=[c],p=[c];let m=!1;for(;f.length>0;){const u=f[0];f.splice(0,1);const g=r.indexOf(u);if(g>=0){o[g].push(c),m=!0;break}else{const v=u.getAdjacentNodes();for(const w of v)p.includes(w)||(f.push(w),p.push(w))}}m||o[o.length-1].push(c)}let d=0;for(let c=0;c<o.length;++c){let f=0;for(let m=0;m<o[c].length;++m){const u=o[c][m];u.move([d,f]),f+=a+u.height}const p=Math.max(...o[c].map(m=>m.width));d+=a+p}for(const c of t.connections)c.tighten();return t}}class Ho{constructor(t){this.gapSize=t}apply(t){var h;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(c=>c.getPriority())),s=Math.min(...t.nodes.map(c=>c.getPriority()));if(e===s)return new ie().apply(t),t;const a=this.gapSize!==void 0?this.gapSize:(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,l=t.nodes.filter(c=>!c.parent).sort((c,f)=>f.getPriority()-c.getPriority()),o=[];for(;l.length>0;){const c=l[0];l.splice(0,1);const f=new ve(void 0,c);Ti(f,l),o.push(f)}const n=[];for(const c of o)n.push([c]),Li(c,n,n.length);const r=Math.max(...t.nodes.map(c=>c.height));let d=0;for(let c=0;c<n.length;++c){let f=0;for(let m=0;m<n[c].length;++m){const u=n[c][m];u.node.move([d,f]),f+=(a+r)*u.countBranchHeight()}const p=Math.max(...n[c].map(m=>m.node.width));d+=a+p}for(const c of t.connections)c.tighten();return t}}const Ti=(i,t)=>{for(const e of i.node.getAdjacentNodes().sort((s,a)=>a.getPriority()-s.getPriority())){const s=t.indexOf(e);if(s>=0){t.splice(s,1);const a=i.addBranch(e);Ti(a,t)}}},Li=(i,t,e)=>{if(i.branches.length>0){for(;e>=t.length;)t.push([]);for(const s of i.branches)t[e].push(s),Li(s,t,e+1)}};class ve{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new ve(this,t);return e.depth=this.depth+1,this.branches.push(e),e}countBranchHeight(){if(this.branches.length<=0)return 1;{let t=0;for(const e of this.branches)t+=e.countBranchHeight();return t}}}class Go{constructor(t){this.gapSize=t}apply(t){var l;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,s=t.nodes.filter(o=>!o.parent);s.sort((o,n)=>n.type.priority-o.type.priority);let a=0;for(const o of s)o.move([0,a]),a+=o.height+e;return t}}const li={adjacency:new Vo,breadth:new ie,"breadth-adjacency":new _o,force:new jo,horizontal:new Oo,priority:new Do,tree:new Ho,vertical:new Go},Fo=z.createContext({}),Et=z.createContext({});class Bo{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){}}const be=({direction:i,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:s,disabled:a,rule:l,collapsedValue:o,visibleValue:n,onCollapse:r})=>{const[d,h]=z.useState(s),c=()=>{if(!a){const p=!d;h(p),r==null||r(p);let m;if(typeof t=="string")m=N.select(t),e&&(m=m.select(e));else{const u=t;if(!u)throw new Error("collapsableSelector is not a valid ref");m=N.select(u.current),e&&(m=m.select(e))}m.style(l,p?o:n)}},f=()=>{switch(i){case b.Right:return a?"daga-horizontal-none":d?"daga-horizontal-right":"daga-horizontal-left";case b.Bottom:return a?"daga-vertical-none":d?"daga-vertical-down":"daga-vertical-up";case b.Left:return a?"daga-horizontal-none":d?"daga-horizontal-left":"daga-horizontal-right";case b.Top:return a?"daga-vertical-none":d?"daga-vertical-up":"daga-vertical-down"}};return y.jsx("daga-collapse-button",{children:y.jsx("button",{className:`daga-collapse-button daga-${i}`,onClick:c,children:y.jsx("div",{className:f()})})})},Uo=()=>{const i=z.useContext(Et),t=z.useRef(null),[e,s]=z.useState([]);It.merge(i.validatorChange$,i.diagramChange$).pipe(It.map(()=>a())).subscribe();const a=()=>{s([]);for(const o of i.validators){const n=o.validate(i.model);s(n)}},l=o=>{var n,r,d,h;if(o.elementId&&(o.propertyNames===void 0||o.propertyNames.length===0)){const c=i.model.nodes.get(o.elementId)||i.model.connections.get(o.elementId);c&&i.userHighlight.add(c)}else if(o.elementId&&o.propertyNames!==void 0&&o.propertyNames.length>0){i.userSelection.openInPropertyEditor(i.model.nodes.get(o.elementId)||i.model.connections.get(o.elementId));const c=i.model.nodes.get(o.elementId)||i.model.connections.get(o.elementId);c&&i.userHighlight.add(c),(r=(n=i.parentComponent)==null?void 0:n.propertyEditor)==null||r.highlightProperty(...o.propertyNames)}else!o.elementId&&o.propertyNames!==void 0&&o.propertyNames.length>0&&(i.userSelection.openInPropertyEditor(),(h=(d=i.parentComponent)==null?void 0:d.propertyEditor)==null||h.highlightProperty(...o.propertyNames))};return y.jsx("daga-errors",{children:y.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&y.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:y.jsx("span",{children:"No errors found"})}),e.length>0&&y.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[y.jsxs("span",{children:[e.length," errors found"]}),y.jsx("div",{className:"daga-collapse-button-container",children:y.jsx(be,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:b.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&y.jsx("div",{className:"daga-error-panel",children:y.jsx("ol",{children:e.map((o,n)=>y.jsx("li",{onClick:()=>l(o),dangerouslySetInnerHTML:{__html:o.message}},n))})})]})})},Yo=200,di=i=>(i||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),$i=({disabled:i,options:t,value:e,onChange:s})=>{const a=z.useRef(null),[l,o]=z.useState("");let n;const[r,d]=z.useState([]),[h,c]=z.useState([]),[f,p]=z.useState([]),[m,u]=z.useState([]),[g,v]=z.useState(!1);z.useEffect(()=>{var T;o(((T=t.find(V=>At(V.key,e)))==null?void 0:T.label)||"")},[e,t]);const w=T=>{if(!i)switch(T.key){case tt.PageDown:n===void 0?(S(0),M(0)):(S(n+5),M(n)),T.preventDefault();break;case tt.ArrowDown:n===void 0?(S(0),M(0)):(S(n+1),M(n)),T.preventDefault();break;case tt.PageUp:n===void 0?(S(t.length-1),M(t.length-1)):(S(n-5),M(n)),T.preventDefault();break;case tt.ArrowUp:n===void 0?(S(t.length-1),M(t.length-1)):(S(n-1),M(n)),T.preventDefault();break;case tt.Escape:A(),T.preventDefault();break;case tt.Enter:R(t[n||0]),T.preventDefault();break;default:k()}},k=()=>{if(!i){const T=di(l.trim());d([]),c([]),p([]),u([]);for(const V of t){const D=di(V.label).indexOf(T);if(D>=0){const J=V.label.substring(0,D),F=V.label.substring(D,D+T.length),Q=V.label.substring(D+T.length);d(et=>[...et,V]),c(et=>[...et,J]),p(et=>[...et,F]),u(et=>[...et,Q])}}v(!0)}},A=()=>{v(!1)},S=T=>{if(!i){if(n=T,T===void 0)return;T<0&&(n=0),T>=t.length&&(n=t.length-1)}},L=()=>{setTimeout(()=>{A()},Yo)},M=T=>{var K;const V=(K=a.current)==null?void 0:K.querySelectorAll("li")[T];V&&V.scrollIntoView({block:"center"})},x=()=>{i||(o(""),v(!1),n=void 0)},R=T=>{i||(o(T.label),v(!1),n=void 0,s(T.key))};return y.jsxs("div",{ref:a,className:`daga-autocomplete ${g?"daga-showing-options":""}`,children:[y.jsxs("div",{className:"daga-autocomplete-input",children:[y.jsx("input",{value:l,disabled:i,onKeyUp:w,onFocus:k,onBlur:L,onChange:T=>o(T.target.value)}),l!==""&&y.jsx("button",{className:"daga-clear",onClick:x})]}),y.jsx("div",{className:"daga-autocomplete-options",children:y.jsxs("ul",{className:"daga-autocomplete-option-list",children:[r.length===0&&y.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),r.map((T,V)=>y.jsxs("li",{className:`daga-autocomplete-option ${V===n?"daga-focused":""}`,onMouseMove:()=>S(V),onClick:()=>R(T),children:[y.jsx("span",{children:h[V]}),y.jsx("span",{className:"daga-match",children:f[V]}),y.jsx("span",{children:m[V]})]},V))]})})]})},Xo=(i,t)=>{var e;return((e=i.find(s=>s.key===t))==null?void 0:e.label)||`${t}`},Wo=({disabled:i,allowRepeats:t,options:e,value:s,onChange:a})=>{const[l,o]=z.useState(),[n,r]=z.useState([]),[d,h]=z.useState([]);z.useEffect(()=>{const g=s.length===0,v=s.map(w=>Xo(e,w));r(v),g&&a(s),u()},[s,e]);const c=g=>{for(const v of s)if(v===g)return!0;return!1},f=g=>{s.length>g&&(s.splice(g,1),r(n.filter((v,w)=>w!==g)),a(s),u())},p=()=>{l!==void 0&&(t||!c(l))&&(a(s.concat(l)),m())},m=()=>{o("")},u=()=>{if(!t){const g=[];for(const v of e)c(v.key)||g.push(v);h(g)}};return y.jsxs("div",{children:[s.map((g,v)=>y.jsxs("div",{className:"daga-value-item-element",children:[y.jsx("span",{className:"daga-input",children:n[v]}),!i&&y.jsx("button",{className:"daga-property-button",onClick:()=>f(v),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},v)),!i&&y.jsxs("div",{className:"daga-value-item-input",children:[y.jsx("div",{className:"daga-input daga-relatively-positioned",children:y.jsx($i,{disabled:i,options:t?e||[]:d||[],value:l,onChange:o})}),y.jsx("button",{className:"daga-property-button",onClick:p,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Zo=({disabled:i,allowRepeats:t,value:e,onChange:s})=>{const[a,l]=z.useState(""),o=f=>{for(const p of f||[])if(p===f)return!0;return!1},n=f=>{e.length>f&&s(e.filter((p,m)=>m!==f))},r=(f,p,m)=>{const u=e.map((g,v)=>v===p?m==="blur"?f.trim():f:g);s(u)},d=()=>{const f=a.trim();f!==""&&(t||!o(f))&&(s(e.concat(f)),h())},h=()=>{l("")},c=f=>{f.key==="Enter"&&d()};return y.jsxs(y.Fragment,{children:[e.map((f,p)=>y.jsxs("div",{className:"daga-value-item-element",children:[y.jsx("input",{className:"daga-input",disabled:i,value:f,onChange:m=>r(m.target.value,p,"change"),onBlur:m=>r(m.target.value,p,"blur")}),y.jsx("button",{className:"daga-property-button",onClick:()=>n(p),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},p)),!i&&y.jsxs("div",{className:"daga-value-item-input",children:[y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",onKeyUp:c,value:a,onChange:f=>l(f.target.value)}),y.jsx("button",{className:"daga-clear",onClick:h})]}),y.jsx("button",{className:"daga-property-button",onClick:d,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Ko=({disabled:i,value:t,onChange:e})=>{const[s,a]=z.useState(""),[l,o]=z.useState(""),[n,r]=z.useState({}),d=g=>{const v={};Object.keys(t).forEach(w=>{w!==g&&(v[w]=t[w])}),e(v)},h=(g,v,w)=>{const k=w==="blur"?v.trim():v;if(w==="blur"){if(g!==k){const A={};Object.keys(t).forEach(S=>{S===g?A[k]=t[S]:A[S]=t[S]}),e(A),r(S=>{const L={...S};return delete L[g],L})}}else r(A=>({...A,[g]:v}))},c=(g,v,w)=>{const k=w==="blur"?v.trim():v;if(k!==""){const A={};Object.keys(t).forEach(S=>{S===g?A[S]=k:A[S]=t[S]}),e(A)}},f=()=>{const g=s.trim(),v=l.trim();if(g!==""&&v!==""){const w={};Object.keys(t).forEach(k=>{w[k]=t[k]}),w[g]=v,e(w),a(""),o("")}},p=()=>{a("")},m=()=>{o("")},u=g=>{g.key==="Enter"&&f()};return y.jsxs("div",{children:[Object.entries(t).map(([g,v],w)=>y.jsxs("div",{className:"daga-value-item-element",children:[y.jsx("input",{id:`key-${w}`,className:"daga-input",type:"text",disabled:i,value:n[g]??g,onChange:k=>h(g,k.target.value,"change"),onBlur:k=>h(g,k.target.value,"blur")}),y.jsx("input",{id:`value-${w}`,className:"daga-input",type:"text",disabled:i,value:v,onChange:k=>c(g,k.target.value,"change"),onBlur:k=>c(g,k.target.value,"blur")}),y.jsx("button",{className:"daga-property-button",onClick:()=>d(g),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},g)),!i&&y.jsxs("div",{className:"daga-value-item-input",children:[y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",value:s,onKeyUp:u,onChange:g=>a(g.target.value),onBlur:g=>h(s,g.target.value,"blur")}),y.jsx("button",{className:"daga-clear",onClick:p})]}),y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",value:l,onKeyUp:u,onChange:g=>o(g.target.value),onBlur:g=>c(s,g.target.value,"blur")}),y.jsx("button",{className:"daga-clear",onClick:m})]}),y.jsx("button",{className:"daga-property-button",onClick:f,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Mi=({valueSet:i,onValueChange:t,depth:e})=>{var r;const a=z.useContext(Et).canUserPerformAction(C.UpdateValues)&&((r=i==null?void 0:i.rootElement)==null?void 0:r.removed)!==!0,l=d=>"daga-property-name-"+d.replace(/\s/g,""),o=d=>{if(typeof d=="string")return d;if(d==null||isNaN(d.valueOf()))return"";const h=new Date(d),c=h.getTimezoneOffset();return h.setMinutes(h.getMinutes()-c),h.toISOString().substring(0,19)},n=d=>new Date(d);return y.jsx("daga-object-editor",{children:i.displayedProperties.map(d=>y.jsxs("div",{className:`daga-property ${l(d.name)}`,children:[y.jsx("p",{className:"daga-property-name",children:d.name}),d.type===_.Text&&y.jsx("input",{type:"daga-text",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h.target.value)}),d.type===_.TextArea&&y.jsx("textarea",{disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h.target.value)}),d.type===_.Number&&y.jsx("input",{type:"number",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h.target.value)}),d.type===_.Color&&y.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h.target.value)}),d.type===_.Datetime&&y.jsx("input",{type:"datetime-local",disabled:!d.editable||!a,value:o(i==null?void 0:i.getValue(d.name)),onChange:h=>t(i,d,n(h.target.value))}),d.type===_.Date&&y.jsx("input",{type:"date",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h.target.value)}),d.type===_.Time&&y.jsx("input",{type:"time",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h.target.value)}),d.type===_.Url&&y.jsx("input",{type:"url",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h.target.value)}),d.type===_.Boolean&&y.jsxs("div",{className:"daga-radio",children:[y.jsxs("label",{className:"daga-radio-item daga-radio-start"+((i==null?void 0:i.getValue(d.name))===!1?" daga-checked":""),children:[y.jsx("input",{type:"radio",disabled:!d.editable||!a,name:d.name,value:"false",checked:(i==null?void 0:i.getValue(d.name))===!1,onChange:()=>t(i,d,!1)}),"No"]}),y.jsxs("label",{className:"daga-radio-item daga-radio-end"+((i==null?void 0:i.getValue(d.name))===!0?" daga-checked":""),children:[y.jsx("input",{type:"radio",disabled:!d.editable||!a,name:d.name,value:"true",checked:(i==null?void 0:i.getValue(d.name))===!0,onChange:()=>t(i,d,!0)}),"Yes"]})]}),d.type===_.Option&&y.jsx("div",{className:"daga-relatively-positioned",children:y.jsx($i,{disabled:!d.editable||!a,options:d.options||[],value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h)})}),(d.type===_.OptionList||d.type===_.OptionSet)&&y.jsx(Wo,{disabled:!d.editable||!a,allowRepeats:d.type===_.OptionList,options:d.options||[],value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h)}),(d.type===_.TextList||d.type===_.TextSet)&&y.jsx(Zo,{disabled:!d.editable||!a,allowRepeats:d.type===_.TextList,value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h)}),d.type===_.TextMap&&y.jsx(Ko,{disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:h=>t(i,d,h)}),d.type===_.Object&&y.jsx("div",{className:"daga-left-bar",children:y.jsx(Mi,{valueSet:i.getSubValueSet(d.name),onValueChange:t,depth:e+1})})]},d.name))})},Ni=({valueSet:i,depth:t})=>{const e=z.useContext(Et),s=z.useRef(null),a=r=>"daga-property-name-"+r.replace(/\s/g,""),l=()=>{for(const r of(i==null?void 0:i.displayedProperties)||[]){let d=0,h=0,c=0;const f=N.select(s.current).select(`.daga-property.${a(r.name)}.daga-depth-${t}`);f.select("button.daga-move-button").call(N.drag().on($.Start,p=>{var g;I(P.Grabbing);const m=e.getPointerLocationRelativeToScreen(p);if(m.length<2||isNaN(m[0])||isNaN(m[1]))return;const u=(g=f.node())==null?void 0:g.getBoundingClientRect();d=(u==null?void 0:u.width)||0,h=(u==null?void 0:u.height)||0,f.style("position","fixed").style("left",`${m[0]-d/2}px`).style("top",`${m[1]-h/2}px`).style("width",`${d}px`).style("height",`${h}px`).style("z-index",1)}).on($.Drag,p=>{I(P.Grabbing);const m=e.getPointerLocationRelativeToScreen(p);m.length<2||isNaN(m[0])||isNaN(m[1])||(f.style("position","fixed").style("left",`${m[0]-d/2}px`).style("top",`${m[1]-h/2}px`).style("width",`${d}px`).style("height",`${h}px`).style("z-index",1),N.select(s.current).select(`.daga-dropbar.daga-index-${c}.daga-depth-${t}`).style("visibility","hidden").style("height",0),c=o(m),N.select(s.current).select(`.daga-dropbar.daga-index-${c}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on($.End,p=>{var u,g;I(P.Auto),f.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),N.select(s.current).select(`.daga-dropbar.daga-index-${c}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const m=e.getPointerLocationRelativeToScreen(p);m.length<2||isNaN(m[0])||isNaN(m[1])||(c=o(m),(u=i==null?void 0:i.displayedProperties)==null||u.splice(i.displayedProperties.indexOf(r),1),(g=i==null?void 0:i.displayedProperties)==null||g.splice(c,0,r))}))}},o=r=>{var c;const d=(i==null?void 0:i.propertySet.propertyList)||[],h=[];for(let f=0;f<=d.length;++f){const p=(c=N.select(s.current).select(`.daga-dropbar.daga-index-${f}.daga-depth-${t}`).node())==null?void 0:c.getBoundingClientRect();p&&h.push([p.x+p.width/2,p.y+p.height/2])}if(h.length>0){const f=h.map(m=>((r[0]-m[0])**2+(r[1]-m[1])**2)**.5);return f.indexOf(Math.min(...f))}return 0},n=r=>{var h;if(i===void 0)return;let d;r instanceof qi?d=r:r instanceof Event?d=i==null?void 0:i.propertySet.getProperty(((h=r.target)==null?void 0:h.value)||""):d=i==null?void 0:i.propertySet.getProperty(r||""),d&&(i==null||i.hideProperty(d)),l()};return y.jsxs("daga-property-settings",{ref:s,children:[y.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),i==null?void 0:i.displayedProperties.map((r,d)=>y.jsxs("div",{className:`daga-property-and-dropbar ${a(r.name)} daga-depth-${t}`,children:[y.jsxs("div",{className:`daga-property ${a(r.name)} daga-depth-${t}`,children:[y.jsxs("div",{className:"daga-property-name",children:[y.jsx("span",{children:r.name}),y.jsxs("div",{className:"daga-buttons",children:[y.jsx("button",{className:"daga-property-button daga-move-button",children:y.jsx("div",{className:"daga-icon daga-move-icon"})}),y.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>n(r.name),children:y.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),r.type!==_.Object&&y.jsx("div",{className:"daga-property-value",children:qo(i==null?void 0:i.getValue(r.name))}),r.type===_.Object&&y.jsx(Ni,{valueSet:i==null?void 0:i.getSubValueSet(r.name),depth:t+1})]}),y.jsx("div",{className:`daga-dropbar daga-index-${d+1} daga-depth-${t}`})]},r.name))]})},qo=i=>Array.isArray(i)?i.join(", "):Ji(i)?Object.entries(i).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):i instanceof Date?i.toLocaleString():i==null?"":""+i,Jo=({location:i,direction:t,width:e,title:s,valueSet:a,onValueChange:l})=>{const o=z.useRef(null),[n,r]=z.useState(!1),[d,h]=z.useState(!1),c=()=>N.select(o.current);return z.useEffect(()=>{if(o.current)switch(t){case b.Bottom:case b.Top:c().style("width",e);break;case b.Left:case b.Right:c().style("height",e);break}},[e,t]),y.jsx("daga-property-editor",{children:y.jsxs("div",{ref:o,className:`daga-panel daga-bottom daga-${i} daga-${t}`,children:[y.jsx(be,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:n,direction:t,collapsableSelector:o,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:r}),a&&a.propertySet&&a.propertySet.hasProperties()&&!n&&y.jsxs("div",{className:"daga-panel-content",children:[s&&y.jsxs("p",{className:"daga-title",children:[s,y.jsx("button",{className:"daga-property-button",onClick:()=>h(!d),children:y.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&y.jsx(Mi,{valueSet:a,onValueChange:l,depth:0}),d&&y.jsx(Ni,{valueSet:a,depth:0})]})]})})},Qo=6,ts=i=>{const t=z.useContext(Et),[e,s]=z.useState(i.currentPalette||i.palettes[0]),[a,l]=z.useState(0),[o,n]=z.useState(void 0),r=z.useRef(null),d=u=>{if(s(u),h().selectAll("*").remove(),l(t.getPriorityThreshold()||0),u.categories&&c(u.categories),u.templates)for(const g of u.templates)f(g)},h=()=>N.select(r.current).select(".daga-palette-view"),c=u=>{const g=h().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");g.append("option").attr("value","").text("(None selected)");for(const v in u)g.append("option").attr("value",v).text(v);g.on(E.Change,()=>{o&&h().selectAll(".daga-template-container.daga-in-category").remove();const v=g.property("value");n(v);const w=u[v]||[];for(const k of w)f(k,"daga-in-category")}),o&&(g.property("value",o),g.dispatch(E.Change))},f=(u,g)=>{if(u.templateType==="node"){const v=t.model.nodes.types.get(u.type);v?p(v,u,g):console.error(`Could not find a node type called '${u.type}'`)}else if(u.templateType==="connection"){const v=t.model.connections.types.get(u.type);v?m(v,u,g):console.error(`Could not find a connection type called '${u.type}'`)}},p=(u,g,v)=>{if(a!==void 0&&u.priority<a)return;const w=u.defaultLook.lookType==="shaped-look"?u.defaultLook.borderThickness:0,k=u.defaultHeight+w,A=u.defaultWidth+w,S=g.height||k,L=g.width||A,M=h().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${L}px`).style("height",`${S}px`).call(N.drag().on($.Drag,R=>{if(t.canUserPerformAction(C.AddNode)){const T=t.getPointerLocationRelativeToScreen(R);if(T.length<2||isNaN(T[0])||isNaN(T[1]))return;M.style("position","fixed").style("left",`${T[0]-L}px`).style("top",`${T[1]-S}px`).style("z-index",1)}}).on($.Start,R=>{if(t.canUserPerformAction(C.AddNode)){I(P.Grabbing);const T=t.getPointerLocationRelativeToScreen(R);if(T.length<2||isNaN(T[0])||isNaN(T[1]))return;M.style("position","fixed").style("left",`${T[0]-L}px`).style("top",`${T[1]-S}px`).style("z-index",1),u.isUnique&&t.model.nodes.find(V=>!V.removed&&V.type.id===u.id)!==void 0&&I(P.NotAllowed)}}).on($.End,R=>{var T;if(t.canUserPerformAction(C.AddNode)){if(I(P.Auto),M.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),u.isUnique&&t.model.nodes.find(St=>!St.removed&&St.type.id===u.id)!==void 0)return;const V=t.getPointerLocationRelativeToScreen(R);if(V.length<2||isNaN(V[0])||isNaN(V[1]))return;const K=document.elementFromPoint(V[0],V[1]);if(K&&!((T=t.selectCanvasView().node())!=null&&T.contains(K)))return;const D=t.getPointerLocationRelativeToCanvas(R);if(D.length<2||isNaN(D[0])||isNaN(D[1]))return;let J=[D[0]-u.defaultWidth/2,D[1]-u.defaultHeight/2];t.snapToGrid&&(J=t.getClosestGridPoint(J));const Q=t.model.nodes.getAtCoordinates(D[0],D[1]).filter(St=>St.type.childrenTypes.includes(u.id)),et=vi(Q),rt=et[et.length-1];if(!u.canBeParentless&&rt===void 0)return;const ht=rt==null?void 0:rt.getLastAncestor(),Rt=new yo(t,u,J,rt==null?void 0:rt.id,ht==null?void 0:ht.id,ht==null?void 0:ht.getGeometry(),void 0,g.label,g.values);Rt.do(),t==null||t.actionStack.add(Rt),I()}})).append("svg").attr("class",`palette-node ${u.id}`).attr("viewBox",`0 0 ${A} ${k}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${L}px`).style("height",`${S}px`),x=g.look||u.defaultLook;switch(x.lookType){case"shaped-look":M.append("path").attr("d",ge(x.shape,x.borderThickness/2,x.borderThickness/2,u.defaultWidth,u.defaultHeight)).attr("fill",x.fillColor).attr("stroke",x.borderColor).attr("stroke-width",`${x.borderThickness}px`);break;case"image-look":M.append("image").attr("x",0).attr("y",0).attr("width",u.defaultWidth).attr("height",u.defaultHeight).attr("href",x.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":M.append("image").attr("x",0).attr("y",0).attr("width",x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",0).attr("width",u.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTop).attr("preserveAspectRatio","none"),M.append("image").attr("x",u.defaultWidth-x.rightMargin).attr("y",0).attr("width",x.rightMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",x.topMargin).attr("width",x.leftMargin).attr("height",u.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",x.topMargin).attr("width",u.defaultWidth-x.rightMargin-x.leftMargin).attr("height",u.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageCenter).attr("preserveAspectRatio","none"),M.append("image").attr("x",u.defaultWidth-x.rightMargin).attr("y",x.topMargin).attr("width",x.rightMargin).attr("height",u.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",u.defaultHeight-x.bottomMargin).attr("width",x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",u.defaultHeight-x.bottomMargin).attr("width",u.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottom).attr("preserveAspectRatio","none"),M.append("image").attr("x",u.defaultWidth-x.rightMargin).attr("y",u.defaultHeight-x.bottomMargin).attr("width",x.rightMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(g.look===void 0){if(u.decorators)for(const R of u.decorators)M.append("foreignObject").attr("width",`${R.width}px`).attr("height",`${R.height}px`).attr("transform",`translate(${R.coords[0]},${R.coords[1]})`).html(R.html);if(g.label){const R={...O,...u.label,...g.labelLook};M.append("text").attr("transform",`translate(${(Z(R)+u.defaultWidth)/2},${(U(R)+u.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${R.fontSize}px`).attr("text-anchor","middle").attr("font-family",R.fontFamily).attr("font-weight",400).attr("fill",R.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(g.label)}}},m=(u,g,v)=>{const w=h().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${g.width}px`).style("height",`${g.height}px`).append("svg").attr("class",`palette-button ${u.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=u});w.append("path").attr("d",ge(Zt.Rectangle,0,0,g.width,g.height)).attr("fill",g.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),g.icon!==""&&w.append("image").attr("x",0).attr("y",0).attr("width",g.width).attr("height",g.height).attr("href",g.icon),g.label!==""&&w.append("text").attr("transform",`translate(${g.width/2},${g.height/2+Qo})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(g.label)};return z.useEffect(()=>{if(d(i.palettes[0]),r.current)switch(i.direction){case b.Bottom:case b.Top:r.current.style.width=i.width;break;case b.Left:case b.Right:r.current.style.height=i.width;break}},[e,i.palettes]),y.jsx("daga-palette",{children:y.jsxs("div",{ref:r,className:`daga-panel daga-${i.location} daga-${i.direction}`,children:[y.jsx(be,{direction:i.direction,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),y.jsxs("div",{className:"daga-panel-content",children:[i.palettes.length>1&&y.jsx("div",{className:"daga-panel-tabs",children:i.palettes.map(u=>y.jsx("div",{className:`daga-panel-tab ${u===e?"daga-current-tab":""}`,onClick:()=>d(u),children:u.name}))}),y.jsx("div",{className:"daga-palette-view"})]})]})})},es=({location:i,direction:t,enableAction:e,enableFilter:s,enableLayout:a,enableSelection:l,enableZoom:o})=>{let n=!1,r=!0,d=!1,h,c,f,p;switch(t){case b.Bottom:h="height",c="scaleY",f="top",p="bottom";break;case b.Top:h="height",c="scaleY",f="bottom",p="top";break;case b.Left:h="width",c="scaleX",f="right",p="left";break;case b.Right:h="width",c="scaleX",f="left",p="right";break}const m=z.useRef(null),u=z.useRef(null),g=z.useRef(null);z.useEffect(()=>{N.select(m.current).style(`margin-${p}`,"-1rem").style(h,"0rem").style("transform",`${c}(0)`).style("transform-origin",f)});const v=async()=>{const F=N.select(m.current);if(!d)if(r){r=!1;const rt=`${4*F.selectChildren().size()}rem`;F.transition().duration(500).ease(N.easeLinear).style(h,rt).style("transform",`${c}(1)`),setTimeout(()=>{d=!1},500)}else r=!0,F.transition().duration(500).ease(N.easeLinear).style(h,"0rem").style("transform",`${c}(0)`),setTimeout(()=>{d=!1},500)},w=z.useContext(Et),k=()=>{w.zoomBy(w.zoomFactor)},A=()=>{w.zoomBy(1/w.zoomFactor)},S=()=>{w.center()},L=()=>{w.layoutFormat&&w.layoutFormat in li&&li[w.layoutFormat].apply(w.model)},M=()=>{n=!n,N.select(g.current).classed("daga-on",n).classed("daga-off",!n);const F=w.getPriorityThresholdOptions();F&&F.length>=2&&w.setPriorityThreshold(F[n?1:0])},x=()=>{w.actionStack.undo()},R=()=>{w.actionStack.redo()},T=()=>{w.userSelection.copyToClipboard()},V=()=>{w.userSelection.cutToClipboard()},K=()=>{w.userSelection.pasteFromClipboard()},D=()=>{w.userSelection.removeFromModel()},J=()=>{w.multipleSelectionOn=!0,N.select(u.current).classed("daga-on",!0).classed("daga-off",!1);const F=w.diagramEvent$.subscribe(Q=>{Q.type===xi.Selection&&(N.select(u.current).classed("daga-on",!1).classed("daga-off",!0),F.unsubscribe())})};return y.jsx("daga-diagram-buttons",{children:y.jsxs("div",{className:`daga-diagram-buttons daga-${i} daga-${t}`,children:[o&&w.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-zoom-in",onClick:k,children:y.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),o&&w.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-zoom-out",onClick:A,children:y.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),y.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:m,children:[o&&w.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-center",onClick:S,children:y.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&y.jsx("button",{className:"daga-undo",onClick:x,children:y.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&y.jsx("button",{className:"daga-redo",onClick:R,children:y.jsx("span",{className:"daga-tooltip",children:"Redo"})}),l&&y.jsx("button",{className:"daga-copy",onClick:T,children:y.jsx("span",{className:"daga-tooltip",children:"Copy"})}),l&&y.jsx("button",{className:"daga-cut",onClick:V,children:y.jsx("span",{className:"daga-tooltip",children:"Cut"})}),l&&y.jsx("button",{className:`daga-multiple-selection ${n?"daga-on":"daga-off"}`,onClick:J,ref:u,children:y.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),l&&y.jsx("button",{className:"daga-paste",onClick:K,children:y.jsx("span",{className:"daga-tooltip",children:"Paste"})}),l&&y.jsx("button",{className:"daga-delete",onClick:D,children:y.jsx("span",{className:"daga-tooltip",children:"Delete"})}),a&&w.layoutFormat&&y.jsx("button",{className:"daga-layout",onClick:L,children:y.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),s&&y.jsx("button",{className:`daga-filter ${n?"daga-on":"daga-off"}`,onClick:M,ref:g,children:y.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),y.jsx("button",{className:"daga-more-options",onClick:v,children:r?y.jsx("span",{className:"daga-tooltip",children:"More options"}):y.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},is=({config:i,model:t,onCanvasCreated:e,onDiagramEvent:s,onModelChange:a})=>{var M,x,R,T,V,K,D,J,F,Q,et,rt,ht,Rt,St,ke,we,xe,Ce,Se,Ie,Ae,Ee,Te,Le,$e,Me,Ne,Pe,ze,Re,Ve,_e,je,Oe,De,He,Ge,Fe,Be,Ue,Ye,Xe,We,Ze;const l=new wi,o=new Ii,n=z.useRef(null),r=z.useRef(void 0),d=z.useRef(!1),h=[],[c,f]=z.useState(void 0),[p,m]=z.useState(void 0),u={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},g={refreshPalette:()=>{}},v=new Bo(dt=>f(dt),dt=>m(dt)),w={diagramButtons:u,palette:g,propertyEditor:v},k=(dt=!1)=>((!r.current||dt)&&(h.forEach(gt=>gt.unsubscribe()),r.current=new fe(w,i)),r.current),A=k(),S=dt=>{A.initView(dt),h.push(A.diagramEvent$.subscribe(gt=>{s==null||s(gt)})),h.push(A.diagramChange$.subscribe(()=>{const gt=o.export(A.model);a==null||a(gt)}))};z.useEffect(()=>{n.current&&(d.current||(S(n.current),d.current=!0,e==null||e(A)))},[n.current]),z.useMemo(()=>{n.current&&(k(!0),S(n.current),e==null||e(A))},[i]),z.useEffect(()=>{t&&l.import(A.model,t)},[t]);const L=(dt,gt,Ke)=>{var qe;if(p!==void 0&>.editable&&!At(dt.getValue(gt.name),Ke)){dt.setValue(gt.name,Ke);const oe=new wt(p.propertySet,p.rootElement);oe.setValues(p.getValues()),v.valueSet=oe,p.rootElement.valueSet=oe,(qe=A.propertyEditorChanges$)==null||qe.next()}};return y.jsx("daga-diagram",{children:y.jsx(Fo.Provider,{value:i,children:y.jsx(Et.Provider,{value:A,children:y.jsxs("daga-diagram-editor",{children:[y.jsx("div",{className:"daga-append-to",ref:n}),y.jsxs(Et.Provider,{value:A,children:[((M=i.components)==null?void 0:M.buttons)!==void 0&&((R=(x=i.components)==null?void 0:x.buttons)==null?void 0:R.enabled)!==!1&&y.jsx(es,{location:((V=(T=i.components)==null?void 0:T.buttons)==null?void 0:V.location)||Bt.BottomRight,direction:((D=(K=i.components)==null?void 0:K.buttons)==null?void 0:D.direction)||b.Top,enableAction:((F=(J=i.components)==null?void 0:J.buttons)==null?void 0:F.enableAction)!==!1,enableFilter:((et=(Q=i.components)==null?void 0:Q.buttons)==null?void 0:et.enableFilter)===!0,enableLayout:((ht=(rt=i.components)==null?void 0:rt.buttons)==null?void 0:ht.enableLayout)===!0,enableSelection:((St=(Rt=i.components)==null?void 0:Rt.buttons)==null?void 0:St.enableSelection)!==!1,enableZoom:((we=(ke=i.components)==null?void 0:ke.buttons)==null?void 0:we.enableZoom)!==!1}),((xe=i.components)==null?void 0:xe.palette)!==void 0&&((Se=(Ce=i.components)==null?void 0:Ce.palette)==null?void 0:Se.enabled)!==!1&&((Ae=(Ie=i.components)==null?void 0:Ie.palette)==null?void 0:Ae.sections)&&(((Le=(Te=(Ee=i.components)==null?void 0:Ee.palette)==null?void 0:Te.sections)==null?void 0:Le.length)||0)>0&&y.jsx(ts,{location:((Me=($e=i.components)==null?void 0:$e.palette)==null?void 0:Me.location)||Bt.TopLeft,direction:((Pe=(Ne=i.components)==null?void 0:Ne.palette)==null?void 0:Pe.direction)||b.Bottom,width:((Re=(ze=i.components)==null?void 0:ze.palette)==null?void 0:Re.width)||"12rem",palettes:((_e=(Ve=i.components)==null?void 0:Ve.palette)==null?void 0:_e.sections)||[]}),((je=i.components)==null?void 0:je.propertyEditor)!==void 0&&((De=(Oe=i.components)==null?void 0:Oe.propertyEditor)==null?void 0:De.enabled)!==!1&&y.jsx(Jo,{location:((Ge=(He=i.components)==null?void 0:He.propertyEditor)==null?void 0:Ge.location)||Bt.TopRight,direction:((Be=(Fe=i.components)==null?void 0:Fe.propertyEditor)==null?void 0:Be.direction)||b.Bottom,width:((Ye=(Ue=i.components)==null?void 0:Ue.propertyEditor)==null?void 0:Ye.width)||"24rem",title:c,valueSet:p,onValueChange:L}),((Xe=i.components)==null?void 0:Xe.errors)!==void 0&&((Ze=(We=i.components)==null?void 0:We.errors)==null?void 0:Ze.enabled)!==!1&&y.jsx(Uo,{})]})]})})})})};exports.DagaDiagram=is;
|