@metadev/daga-react 0.0.3 → 1.0.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 +6 -0
- package/index.js +2 -2
- package/index.mjs +4401 -3952
- package/lib/property-editor/autocomplete/DagaAutocompleteComponent.d.ts +9 -0
- package/lib/property-editor/object-editor/DagaObjectEditorComponent.d.ts +1 -0
- package/lib/property-editor/option-list/DagaOptionListComponent.d.ts +10 -0
- package/lib/property-editor/property-settings/DagaPropertySettingsComponent.d.ts +2 -1
- package/lib/property-editor/text-list/DagaTextListComponent.d.ts +8 -0
- package/lib/property-editor/text-map/DagaTextMapComponent.d.ts +11 -0
- package/package.json +2 -2
- package/style.css +1 -1
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`).map(t=>t.length)),Ei=s=>{var t;return((t=s.match(/\n/g))==null?void 0:t.length)||0},_=[];for(let s=0;s<256;++s)_.push((s+256).toString(16).slice(1));function Mi(s,t=0){return(_[s[t+0]]+_[s[t+1]]+_[s[t+2]]+_[s[t+3]]+"-"+_[s[t+4]]+_[s[t+5]]+"-"+_[s[t+6]]+_[s[t+7]]+"-"+_[s[t+8]]+_[s[t+9]]+"-"+_[s[t+10]]+_[s[t+11]]+_[s[t+12]]+_[s[t+13]]+_[s[t+14]]+_[s[t+15]]).toLowerCase()}let Qt;const Pi=new Uint8Array(16);function Ni(){if(!Qt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Qt=crypto.getRandomValues.bind(crypto)}return Qt(Pi)}const Ri=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),_e={randomUUID:Ri};function Ye(s,t,e){var a;if(_e.randomUUID&&!s)return _e.randomUUID();s=s||{};const r=s.random??((a=s.rng)==null?void 0:a.call(s))??Ni();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=r[6]&15|64,r[8]=r[8]&63|128,Mi(r)}class _t{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],j(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const zt=0;class vt{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(`g#${this.id}`)}}class ct extends _t{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((r,a,l)=>t(r,a,l)&&!r.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((r,a,l)=>t(r,a,l)&&!r.removed)}find(t,e=!1){return e?super.find(t):super.find((r,a,l)=>t(r,a,l)&&!r.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(r=>!r.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],j(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(r=>!r.removed))yield e}}function wt(s,t){return!t||s[0]>t[0]?!0:s[0]===t[0]?s[1]>=t[1]:!1}class zi{constructor(t,e,r,a,l,i){this.name=t,this.type=e,this.defaultValue=r,this.basic=a,this.editable=l,this.rootAttribute=i,this.options=void 0,this.properties=void 0}}var tt=(s=>(s.Boolean="boolean",s.Color="color",s.Date="date",s.Datetime="datetime",s.Number="number",s.Object="object",s.Option="option",s.OptionList="option-list",s.OptionSet="option-set",s.Text="text",s.TextArea="text-area",s.TextList="text-list",s.TextSet="text-set",s.TextMap="text-map",s.Time="time",s.Url="url",s))(tt||{});class Yt{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}}class At{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 r of t){if(e==null)return;e=e[r]}return e}}setRootElementValue(t,e){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let r=this.rootElement;for(let a=0;a<t.length-1;++a){const l=t[a];if(r==null)return;r=r[l]}if(r==null)return;r[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 r in t)this.propertySet.getProperty(r).type==="object"?e[r]=this.valueSets[r].getValuesForKeys(t[r]):e[r]=this.getValue(r);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!Xe(e)}hasSetValue(t){const e=this.getValue(t),r=this.propertySet.getProperty(t);return r&&r.type==="object"?this.getSubValueSet(t).hasAnySetValue():!Xe(e)&&!Pt(e,r==null?void 0:r.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const r=this.propertySet.getProperty(t);if(r){r.type==="object"?this.valueSets[t].setValues(e):(this.values[t]=e,Pt(e,r.defaultValue)||this.displayProperty(r));const a=r.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 r in t)this.propertySet.getProperty(r).type==="object"?this.valueSets[r].overwriteValuesLww(t[r],e):wt(e,this.ownTimestamps[r])&&(this.setValue(r,t[r]),this.ownTimestamps[r]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),r=e.rootAttribute;e.type==="object"?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),r!=null&&(e.defaultValue!==void 0?this.setRootElementValue(r,this.values[t]):this.values[t]=this.getRootElementValue(r)),e.basic?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),r=new Yt(e.properties),a=new At(r,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),j(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),j(this.displayedProperties,t))}}const Xe=s=>s==null||s===""||s instanceof Array&&s.length===0||s instanceof Object&&Object.keys(s).length===0,Pt=(s,t)=>s===t||JSON.stringify(s)===JSON.stringify(t),oi=(s,t)=>{const e={},r={},a=[];for(const l in s)a.push(l);for(const l in t)l in s||a.push(l);for(const l of a)if(ne(s[l])&&ne(t[l])){const i=oi(s[l],t[l]);Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(e[l]=i[0],r[l]=i[1])}else Pt(s[l],t[l])||(e[l]=s[l],r[l]=t[l]);return[e,r]},ne=s=>s!=null&&s.constructor===Object,Li={name:"",width:1,shape:ti.Straight,style:ei.Solid,label:null,defaultStartMarkerLook:null,defaultEndMarkerLook:null,startTypes:[],endTypes:[],color:"#000000",selectedColor:"#000000",properties:[]};class si{constructor(t){const e={...Li,...t};this.id=e.id,this.name=e.name,this.width=e.width,this.shape=e.shape,this.style=e.style,this.label=e.label,this.defaultStartMarkerLook=e.defaultStartMarkerLook,this.defaultEndMarkerLook=e.defaultEndMarkerLook,this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.color=e.color,this.selectedColor=e.selectedColor,this.propertySet=new Yt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class st extends vt{constructor(t,e,r,a,l){if(t.connections.get(l)!==void 0)throw new Error(`DiagramConnection with id "${l}" already exists`);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 At(e.propertySet,this),this.originalData={},this.startMarkerLook=e.defaultStartMarkerLook,this.endMarkerLook=e.defaultEndMarkerLook,this.setStart(r),this.setEnd(a)}get name(){return this.middleLabel}set name(t){this.middleLabel=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&&j(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&&j(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 r=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 r){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 r=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 r){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 Vi extends ct{constructor(t){super(),this.types=new _t,this.model=t}new(t,e,r,a){let l;if(t instanceof si)l=t;else{const o=this.types.get(t);if(o===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);l=o}const i=new st(this.model,l,e,r,a);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){var r,a;const e=this.get(t,!0);e&&(j(((r=e.start)==null?void 0:r.outgoingConnections)||[],e),j(((a=e.end)==null?void 0:a.incomingConnections)||[],e),super.remove(t),e.updateInView())}}const z={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",horizontalAlign:xt.Center,verticalAlign:Bt.Center,fit:!1};class lt extends vt{constructor(t,e,r,a,l,i,o,n,d,g,h,m,p,u){const c=`${e==null?void 0:e.id}_field`;if(t.fields.get(c)!==void 0)throw new Error("DiagramField for rootElement already exists");super(t,c),this.textTimestamp=null,this.rootElement=e,this.coords=r,this.width=a,this.height=l,this.fontSize=i,this.fontFamily=o,this.color=n,this.selectedColor=d,this.horizontalAlign=g,this.verticalAlign=h,this.defaultText=m,this._text=m,this.editable=p,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))}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`foreignObject#${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 Di extends ct{constructor(t){super(),this.model=t}new(t,e,r,a,l,i,o,n,d,g,h,m,p){const u=new lt(this.model,t,e,o,n,r,a,l,i,d,g,h,m,p);return super.add(u),u.updateInView(),t!==void 0&&(t.label=u),u}remove(t){var r;const e=this.get(t,!0);e&&(((r=e.rootElement)==null?void 0:r.label)!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const et=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),X=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],nt=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:s.margin.length===1?s.margin[0]:(s.margin.length===2||s.margin.length===3,s.margin[1]),F=s=>(s==null?void 0:s.margin)===null||(s==null?void 0:s.margin)===void 0?z.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?z.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Tt=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),$t=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],Et=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Mt=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?z.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?z.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Oi={lookType:"shaped-look",shape:Ht.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",selectedFillColor:"#FFFFFF",selectedBorderColor:"#000000"},ji={label:null,ports:[],look:Oi,priority:zt},We=1,Ze=1,Bi=1,Fi=1;class Y extends vt{constructor(t,e,r,a,l,i,o,n){if(t.sections.get(n)!==void 0)throw new Error(`DiagramSection with id "${n}" already exists`);super(t,n),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=r,this.indexYInNode=a,this.coords=l,this.width=i,this.height=o}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=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()}getConfig(){var t,e,r,a,l;return(l=(a=(r=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:r.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode]}getMinWidth(){var t,e,r,a;return((a=(r=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:r.minWidths)==null?void 0:a[this.indexXInNode])||Bi}getMinHeight(){var t,e,r,a;return((a=(r=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:r.minHeights)==null?void 0:a[this.indexYInNode])||Fi}getPriority(){var t,e,r,a,l,i;return((i=(l=(a=(r=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:r.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode])==null?void 0:i.priority)||ji.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)),r=e.indexOf(Math.min(...e));return this.ports[r]}}}getIncomingConnections(t=!1){const e=[];for(const r of this.ports)for(const a of r.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const r of this.ports)for(const a of r.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const r of this.ports){for(const a of r.incomingConnections)!t&&a.removed||e.push(a);for(const a of r.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 r=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,i;switch(t){case y.Left:l=[r[0]-e,r[1]],i=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[0]=l[1]-this.getMinWidth());break;case y.Top:l=[r[0],r[1]],i=[a[0]-e,a[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case y.Right:l=[r[0],r[1]+e],i=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[1]=l[0]+this.getMinWidth());break;case y.Bottom:l=[r[0],r[1]],i=[a[0],a[1]+e],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[l[0],i[0]],width:l[1]-l[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){var i,o,n,d,g,h;const e=[this.coords[0],this.coords[0]+this.width],r=[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 m of this.ports)m.move(Ft(m.coords,e,r,a,l));this.label&&(this.label.coords=[this.coords[0]+X((i=this.getConfig())==null?void 0:i.label),this.coords[1]+F((o=this.getConfig())==null?void 0:o.label)],this.label.width=this.width-X((n=this.getConfig())==null?void 0:n.label)-nt((d=this.getConfig())==null?void 0:d.label),this.label.height=this.height-F((g=this.getConfig())==null?void 0:g.label)-et((h=this.getConfig())==null?void 0:h.label),this.label.updateInView());for(const m of this.decorators)m.move(Ft(m.coords,e,r,a,l));this.getConnections().forEach(m=>m.tighten()),this.updateInView()}}class Gi extends ct{constructor(t){super(),this.model=t}new(t,e,r,a,l,i,o){var h,m,p,u,c,f,v,w,b,$;const n=new Y(this.model,t,e,r,a,l,i,o);super.add(n),n.updateInView(),t.sections.push(n),t.updateInView();const d=(u=(p=(m=(h=t.type.sectionGrid)==null?void 0:h.sections)==null?void 0:m[r])==null?void 0:p[e])==null?void 0:u.ports;if(d&&d.length>0)for(let I=0;I<d.length;++I){const T=d[I],N=this.model.ports.new(T.type!==void 0?this.model.ports.types.get(T.type):void 0,n,[n.coords[0]+(T.coords[0]||0),n.coords[1]+(T.coords[1]||0)],T.connectionPoint!==void 0?[n.coords[0]+(T.connectionPoint[0]||0),n.coords[1]+(T.connectionPoint[1]||0)]:void 0,T==null?void 0:T.direction,`${n.id}_${I}`);if((c=N.type)!=null&&c.label){const P={...z,...(f=N.type)==null?void 0:f.label},W=6*P.fontSize+$t(P)+Et(P),Z=P.fontSize+Mt(P)+Tt(P);let G;switch(N.direction){case y.Bottom:case y.Left:case y.Right:G=[N.coords[0]-W/2,N.coords[1]-Z-et(P)];break;case y.Top:G=[N.coords[0]-W/2,N.coords[1]+F(P)];break;default:G=N.coords}this.model.fields.new(N,G,P.fontSize,P.fontFamily,P.color,P.selectedColor,W,Z,P.horizontalAlign,P.verticalAlign,"",P.editable,P.fit)}}const g=($=(b=(w=(v=t.type.sectionGrid)==null?void 0:v.sections)==null?void 0:w[r])==null?void 0:b[e])==null?void 0:$.label;if(g){const I={...z,...g};this.model.fields.new(n,[n.coords[0]+X(I),n.coords[1]+F(I)],I.fontSize,I.fontFamily,I.color,I.selectedColor,n.width-X(I)-nt(I),n.height-F(I)-et(I),I.horizontalAlign,I.verticalAlign,"",I.editable,I.fit)}return n}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&&j(e.node.sections,e),super.remove(t),e.updateInView()}}}const Ui={lookType:"shaped-look",shape:Ht.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",selectedFillColor:"#FFFFFF",selectedBorderColor:"#000000"},dt={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],sectionGrid:null,look:Ui,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:zt,properties:[]};class ni{constructor(t){const e={...dt,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.bottomPadding=_i(e),this.leftPadding=Yi(e),this.rightPadding=Xi(e),this.topPadding=Wi(e),this.label=e.label,this.ports=e.ports,this.sectionGrid=e.sectionGrid,this.look=e.look,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new Yt((t==null?void 0:t.properties)||[])}}class L extends vt{constructor(t,e,r=[0,0],a){if(t.nodes.get(a)!==void 0)throw new Error(`DiagramNode with id "${a}" already exists`);super(t,a),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this.type=e,this.valueSet=new At(e.propertySet,this),this.originalData={},this.coords=r,this.width=e.defaultWidth,this.height=e.defaultHeight}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=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(),this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.sections)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)),r=e.indexOf(Math.min(...e));return this.ports[r]}}}getIncomingConnections(t=!1){const e=[];for(const r of this.ports)for(const a of r.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const r of this.ports)for(const a of r.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const r of this.ports){for(const a of r.incomingConnections)!t&&a.removed||e.push(a);for(const a of r.outgoingConnections)!t&&a.removed||e.push(a)}return e}getAdjacentNodes(t=!1){var r,a;const e=[];for(const l of this.ports){for(const i of l.incomingConnections){if(!t&&i.removed)continue;const o=(r=i.start)==null?void 0:r.getNode();if(o){if(!t&&o.removed)continue;e.push(o)}}for(const i of l.outgoingConnections){if(!t&&i.removed)continue;const o=(a=i.end)==null?void 0:a.getNode();if(o){if(!t&&o.removed)continue;e.push(o)}}}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,r=!1;for(;e!==void 0;){if(e.id===t.id){r=!0;break}e=e.parent}r||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){j(this.children,t),t.parent=void 0}fitToChild(t){const e=this.coords[0]-t.coords[0]+this.type.leftPadding;e>=0&&this.stretch(y.Left,e);const r=this.coords[1]-t.coords[1]+this.type.topPadding;r>=0&&this.stretch(y.Top,r);const a=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;a>=0&&this.stretch(y.Right,a);const l=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;l>=0&&this.stretch(y.Bottom,l),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const r of this.children)r.move([r.coords[0]+e[0],r.coords[1]+e[1]]);for(const r of this.sections)r.move([r.coords[0]+e[0],r.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const r=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,i;switch(t){case y.Left:l=[r[0]-e,r[1]],i=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[0]=l[1]-this.type.minWidth);break;case y.Top:l=[r[0],r[1]],i=[a[0]-e,a[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case y.Right:l=[r[0],r[1]+e],i=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[1]=l[0]+this.type.minWidth);break;case y.Bottom:l=[r[0],r[1]],i=[a[0],a[1]+e],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[l[0],i[0]],width:l[1]-l[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,r,a){let l=Number.NEGATIVE_INFINITY;switch(t){case y.Bottom:for(const i of this.sections)i.indexYInNode===a&&(l=Math.max(l,i.getMinHeight()-i.height));e<l&&(e=l);for(const i of this.sections)i.indexYInNode===a?i.stretch(t,e):i.indexYInNode>a&&i.move([i.coords[0],i.coords[1]+e]);break;case y.Right:for(const i of this.sections)i.indexXInNode===r&&(l=Math.max(l,i.getMinWidth()-i.width));e<l&&(e=l);for(const i of this.sections)i.indexXInNode===r?i.stretch(t,e):i.indexXInNode>r&&i.move([i.coords[0]+e,i.coords[1]]);break;case y.Top:for(const i of this.sections)i.indexYInNode===a&&(l=Math.max(l,i.getMinHeight()-i.height));e<l&&(e=l);for(const i of this.sections)i.indexYInNode===a?i.stretch(t,e):i.indexYInNode<a&&i.move([i.coords[0],i.coords[1]-e]);break;case y.Left:for(const i of this.sections)i.indexXInNode===r&&(l=Math.max(l,i.getMinWidth()-i.width));e<l&&(e=l);for(const i of this.sections)i.indexXInNode===r?i.stretch(t,e):i.indexXInNode<r&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const a of this.sections)e[a.id]=a.getGeometry();const r={};for(const a of this.children)a.id!==t&&(r[a.id]=a.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:r}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],r=[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 i of this.children){const o=t.children[i.id];o&&i.setGeometry(o)}for(const i of this.sections){const o=t.sections[i.id];o&&i.setGeometry(o)}for(const i of this.ports)i.move(Ft(i.coords,e,r,a,l));this.label&&(this.label.coords=[this.coords[0]+X(this.type.label),this.coords[1]+F(this.type.label)],this.label.width=this.width-X(this.type.label)-nt(this.type.label),this.label.height=this.height-F(this.type.label)-et(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Ft(i.coords,e,r,a,l));this.getConnections().forEach(i=>i.tighten()),this.updateInView()}}class Hi extends ct{constructor(t){super(),this.types=new _t,this.model=t}new(t,e,r){var i,o,n,d,g,h,m;let a;if(t instanceof ni)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 L(this.model,a,e,r);if(super.add(l),l.updateInView(),a.sectionGrid!==null){let p=l.coords[1]+(a.sectionGrid.margin||0);for(let u=0;u<a.sectionGrid.sections.length;++u){let c=l.coords[0]+(a.sectionGrid.margin||0);for(let f=0;f<a.sectionGrid.sections[u].length;++f)this.model.sections.new(l,f,u,[c,p],((i=a.sectionGrid.defaultWidths)==null?void 0:i[f])||We,((o=a.sectionGrid.defaultHeights)==null?void 0:o[u])||Ze,`${l.id}_${u}_${f}`),c+=(((n=a.sectionGrid.defaultWidths)==null?void 0:n[f])||We)+(a.sectionGrid.margin||0);p+=(((d=a.sectionGrid.defaultHeights)==null?void 0:d[u])||Ze)+(a.sectionGrid.margin||0)}}if(a.ports.length>0)for(let p=0;p<a.ports.length;++p){const u=a.ports[p],c=this.model.ports.new(u.type!==void 0?this.model.ports.types.get(u.type):void 0,l,[l.coords[0]+u.coords[0],l.coords[1]+u.coords[1]],u.connectionPoint!==void 0?[l.coords[0]+(u.connectionPoint[0]||0),l.coords[1]+(u.connectionPoint[1]||0)]:void 0,u.direction,`${l.id}_${p}`);if((g=c.type)!=null&&g.label){const f={...z,...(h=c.type)==null?void 0:h.label},v=6*f.fontSize+$t(f)+Et(f),w=f.fontSize+Mt(f)+Tt(f);let b;switch(c.direction){case y.Bottom:case y.Left:case y.Right:b=[c.coords[0]-v/2,c.coords[1]-w-et(f)];break;case y.Top:b=[c.coords[0]-v/2,c.coords[1]+F(f)];break;default:b=c.coords}this.model.fields.new(c,b,f.fontSize,f.fontFamily,f.color,f.selectedColor,v,w,f.horizontalAlign,f.verticalAlign,"",f.editable,f.fit)}}if(a.label){const p={...z,...a.label};this.model.fields.new(l,[l.coords[0]+X(p),l.coords[1]+F(p)],p.fontSize,p.fontFamily,p.color,p.selectedColor,l.width-X(p)-nt(p),l.height-F(p)-et(p),p.horizontalAlign,p.verticalAlign,"",p.editable,p.fit)}return l.valueSet.resetValues(),(m=l.model.canvas)==null||m.fitNodeInView(l.id),l}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&j(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 r=[];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&&r.push(a);return r}}const ri=s=>{for(let t=0;t<s.length;++t)for(let e=0;e<s.length;++e)e!==t&&s[e].isAncestorOf(s[t])&&(s.splice(e,1),--e,t>e&&--t);return s},_i=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Yi=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],Xi=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Wi=s=>(s==null?void 0:s.padding)===null||(s==null?void 0:s.padding)===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Ke={highlightedColor:"cyan",selectedColor:"violet"},ai={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24};class Zi{constructor(t){const e={...ai,...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,this.look=e.look}}class mt extends vt{constructor(t,e,r,a,l,i,o){if(t.ports.get(o)!==void 0)throw new Error(`DiagramPort with id "${o}" already exists`);super(t,o),this.outgoingConnections=[],this.incomingConnections=[],this.type=e,this.rootElement=r,this.coords=a,this.connectionPoint=l||a,this.direction=i}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 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 L)return this.rootElement;if(this.rootElement instanceof Y)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 r of this.outgoingConnections)r.setStart(this);for(const r of this.incomingConnections)r.setEnd(this);this.label&&this.label.move([this.label.coords[0]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return Qe(this.coords,t)}}class Ki extends ct{constructor(t){super(),this.types=new _t,this.model=t}new(t,e,r,a,l,i){const o=new mt(this.model,t,e,r,a,l,i);return super.add(o),o.updateInView(),e!==void 0&&e.ports.push(o),o}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 L||e.rootElement instanceof Y)&&j(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class li{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 r of e.nodes||[])this.importNode(t,r);for(const r of e.connections||[])this.importConnection(t,r);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,i,o,n,d,g,h,m,p;const r=t.nodes.types.get(e.type);if(r){const u=new L(t,r,e.coords,e.id);if(t.nodes.add(u),u.width=e.width,u.height=e.height,e.label&&r.label){const f={...z,...r.label},v=new lt(t,u,[u.coords[0]+X(f),u.coords[1]+F(f)],u.width-X(f)-nt(f),u.height-F(f)-et(f),f.fontSize,f.fontFamily,f.color,f.selectedColor,f.horizontalAlign,f.verticalAlign,"",f.editable,f.fit);v.text=e.label,u.label=v,t.fields.add(v),v.updateInView()}for(const f of e.children||[]){const v=this.importNode(t,f);v!==void 0&&((a=u.children)==null||a.push(v),v.parent=u)}for(const f of e.sections||[]){const v=new Y(t,u,f.indexXInNode,f.indexYInNode,f.coords,f.width,f.height,f.id);if((l=u.sections)==null||l.push(v),t.sections.add(v),f.label&&(d=(n=(o=(i=r.sectionGrid)==null?void 0:i.sections)==null?void 0:o[f.indexYInNode])==null?void 0:n[f.indexXInNode])!=null&&d.label){const b={...z,...(p=(m=(h=(g=r.sectionGrid)==null?void 0:g.sections)==null?void 0:h[f.indexYInNode])==null?void 0:m[f.indexXInNode])==null?void 0:p.label},$=new lt(t,v,[v.coords[0]+X(b),v.coords[1]+F(b)],v.width-X(b)-nt(b),v.height-F(b)-et(b),b.fontSize,b.fontFamily,b.color,b.selectedColor,b.horizontalAlign,b.verticalAlign,"",b.editable,b.fit);$.text=f.label,v.label=$,t.fields.add($),$.updateInView()}let w=0;for(const b of f.ports||[]){const $=b.type!==void 0?t.ports.types.get(b.type):void 0,I=new mt(t,$,v,b.coords,b.connectionPoint,b.direction,b.id);if(v.ports.push(I),t.ports.add(I),b.label){if(r.ports.length>w&&($!=null&&$.label)){const T={...z,...$==null?void 0:$.label};let N;switch(I.direction){case y.Top:case y.Left:N=[I.coords[0]-T.fontSize,I.coords[1]-T.fontSize];break;case y.Bottom:N=[I.coords[0]-T.fontSize,I.coords[1]+T.fontSize];break;case y.Right:N=[I.coords[0]+T.fontSize,I.coords[1]-T.fontSize];break;default:N=I.coords}const P=new lt(t,I,N,T.fontSize,T.fontSize,T.fontSize,T.fontFamily,T.color,T.selectedColor,T.horizontalAlign,T.verticalAlign,"",T.editable,T.fit);P.text=b.label,I.label=P,t.fields.add(P),P.updateInView()}++w}b.collabMeta&&(I.selfRemoved=b.collabMeta.selfRemoved,I.selfRemovedTimestamp=b.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(I.label,b.collabMeta.label)),I.updateInView()}f.collabMeta&&(v.selfRemoved=f.collabMeta.selfRemoved,v.selfRemovedTimestamp=f.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(v.label,f.collabMeta.label)),v.updateInView()}let c=0;for(const f of e.ports||[]){const v=f.type!==void 0?t.ports.types.get(f.type):void 0,w=new mt(t,v,u,f.coords,f.connectionPoint,f.direction,f.id);if(u.ports.push(w),t.ports.add(w),f.label){if(r.ports.length>c&&(v!=null&&v.label)){const b={...z,...v==null?void 0:v.label};let $;switch(w.direction){case y.Top:case y.Left:$=[w.coords[0]-b.fontSize,w.coords[1]-b.fontSize];break;case y.Bottom:$=[w.coords[0]-b.fontSize,w.coords[1]+b.fontSize];break;case y.Right:$=[w.coords[0]+b.fontSize,w.coords[1]-b.fontSize];break;default:$=w.coords}const I=new lt(t,w,$,b.fontSize,b.fontSize,b.fontSize,b.fontFamily,b.color,b.selectedColor,b.horizontalAlign,b.verticalAlign,"",b.editable,b.fit);I.text=f.label,w.label=I,t.fields.add(I),I.updateInView()}++c}f.collabMeta&&(w.selfRemoved=f.collabMeta.selfRemoved,w.selfRemovedTimestamp=f.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(w.label,f.collabMeta.label)),w.updateInView()}return e.data&&u.valueSet.setValues(e.data),e.collabMeta&&(u.selfRemoved=e.collabMeta.selfRemoved,u.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,u.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(u.label,e.collabMeta.label),u.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),u.updateInView(),u.raise(),u}}importConnection(t,e){const r=t.connections.types.get(e.type);if(r){const a=new st(t,r,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 Xt{constructor(t,e,r,a,l,i,o){this.canvas=t,this.id=e,this.typeId=r,this.coords=a,this.parentId=l,this.label=i,this.values=o}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)),this.values!==void 0&&t.valueSet.setValues(structuredClone({...t.valueSet.getValues(),...this.values})),t.label&&(t.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(t,e){return new Xt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class le{constructor(t,e,r){this.canvas=t,this.to=e,this.timestamp=r}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&wt(this.timestamp,e.geometryTimestamp)){const r=this.to[t];e.move([r[0],r[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new le(t,e.to,e.timestamp)}}class Nt{constructor(t,e,r,a){this.canvas=t,this.nodeIds=e,this.delta=r,this.timestamp=a}do(){var t;for(const e of this.nodeIds){const r=this.canvas.model.nodes.get(e,!0);r&&wt(this.timestamp,r.geometryTimestamp)&&(r.move([r.coords[0]+this.delta[0],r.coords[1]+this.delta[1]]),(t=r.parent)==null||t.fitToChild(r),r.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new Nt(t,e.nodeIds,e.delta,e.timestamp)}}class J{constructor(t,e,r,a){this.canvas=t,this.nodeId=e,this.to=r,this.timestamp=a}do(){var e,r,a;const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&wt(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)(r=l.label)!=null&&r.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 J(t,e.nodeId,e.to,e.timestamp)}}class Rt{constructor(t,e,r,a,l){this.canvas=t,this.childId=e,this.parentId=r,this.childGeometry=a,this.timestamp=l}do(){var r;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)&&wt(this.timestamp,t.geometryTimestamp)&&((r=t.parent)==null||r.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 Rt(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class Wt{constructor(t,e,r,a,l){this.canvas=t,this.id=e,this.typeId=r,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 Wt(t,e.id,e.typeId,e.startId,e.endId)}}class It{constructor(t,e,r,a){this.canvas=t,this.fieldId=e,this.to=r,this.timestamp=a}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&wt(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 It(t,e.fieldId,e.to,e.timestamp)}}class St{constructor(t,e,r,a){this.canvas=t,this.id=e,this.to=r,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 St(t,e.id,e.to,e.timestamp)}}class ot{constructor(t,e,r,a,l,i,o,n){this.canvas=t,this.nodeIds=e,this.sectionIds=r,this.portIds=a,this.connectionIds=l,this.fieldIds=i,this.selfRemoved=o,this.timestamp=n}doOne(t){t&&wt(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 ot(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class Zt{constructor(t,e,r){this.canvas=t,this.nodes=e,this.connections=r}do(){const t=new li;this.canvas.userSelection.clear();for(const e of this.nodes){const r=t.importNode(this.canvas.model,e);r&&this.canvas.userSelection.add(r)}for(const e of this.connections){const r=t.importConnection(this.canvas.model,e);r&&this.canvas.userSelection.add(r)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new Zt(t,e.nodes,e.connections)}}class qi{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=Ye()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+Ye()}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":{Xt.deserialize(this.canvas,t).do();break}case"applyLayout":{le.deserialize(this.canvas,t).do();break}case"move":{Nt.deserialize(this.canvas,t).do();break}case"setGeometry":{J.deserialize(this.canvas,t).do();break}case"setParent":{Rt.deserialize(this.canvas,t).do();break}case"addConnection":{Wt.deserialize(this.canvas,t).do();break}case"editField":{It.deserialize(this.canvas,t).do();break}case"updateValues":{St.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{ot.deserialize(this.canvas,t).do();break}case"paste":{Zt.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class Ji{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 k=(s=>(s.AddConnection="add-connection",s.AddNode="add-node",s.ApplyLayout="apply-layout",s.Clipboard="clipboard",s.ContextMenu="context-menu",s.EditField="edit-field",s.MoveNode="move-node",s.Paste="paste",s.Remove="remove",s.StretchNode="stretch-node",s.StretchSection="stretch-section",s.UpdateValues="update-values",s.Zoom="zoom",s))(k||{});class Qi{constructor(t,e,r,a,l,i,o,n,d){this.canvas=t,this.type=e,this.coords=r,this.parentId=a,this.ancestorId=l,this.fromAncestorGeometry=i,this.toAncestorGeometry=o,this.label=n,this.values=d,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Xt(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 J(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 ot(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const r=new J(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new ot(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const r=new J(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}return t===void 0}}class te{constructor(t,e,r){this.canvas=t,this.nodeIds=e,this.delta=r}do(){const t=new Nt(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 Nt(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class B{constructor(t,e,r,a,l,i,o,n){this.canvas=t,this.intent=e,this.nodeId=r,this.from=a,this.to=l,this.ancestorId=i,this.fromAncestorGeometry=o,this.toAncestorGeometry=n}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new J(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 r=new J(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new J(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 r=new J(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new J(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class to{constructor(t,e,r,a,l,i,o,n,d){this.canvas=t,this.childId=e,this.fromParentId=r,this.toParentId=a,this.fromChildGeometry=l,this.toChildGeometry=i,this.ancestorId=o,this.fromAncestorGeometry=n,this.toAncestorGeometry=d}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Rt(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 r=new J(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Rt(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 r=new J(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(r)}return t!==void 0}redo(){return this.do()}}class ee{constructor(t,e,r,a){this.canvas=t,this.type=e,this.startId=r,this.endId=a,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Wt(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 ot(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 ot(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class qe{constructor(t,e,r,a){this.canvas=t,this.fieldId=e,this.from=r,this.to=a}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new It(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 It(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 It(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class eo{constructor(t,e,r,a){this.canvas=t,this.id=e,this.from=r,this.to=a}do(){const t=new St(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new St(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 St(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 io{constructor(t,e,r,a,l,i){this.canvas=t,this.nodeIds=e,this.sectionIds=r,this.portIds=a,this.connectionIds=l,this.fieldIds=i}do(){const t=this.nodeIds.map(r=>this.canvas.model.nodes.get(r)!==void 0).includes(!0)||this.sectionIds.map(r=>this.canvas.model.sections.get(r)!==void 0).includes(!0)||this.portIds.map(r=>this.canvas.model.ports.get(r)!==void 0).includes(!0)||this.connectionIds.map(r=>this.canvas.model.connections.get(r)!==void 0).includes(!0)||this.fieldIds.map(r=>this.canvas.model.fields.get(r)!==void 0).includes(!0),e=new ot(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(r=>this.canvas.model.nodes.get(r)===void 0).includes(!0)||this.sectionIds.map(r=>this.canvas.model.sections.get(r)===void 0).includes(!0)||this.portIds.map(r=>this.canvas.model.ports.get(r)===void 0).includes(!0)||this.connectionIds.map(r=>this.canvas.model.connections.get(r)===void 0).includes(!0)||this.fieldIds.map(r=>this.canvas.model.fields.get(r)===void 0).includes(!0),e=new ot(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 oo{constructor(t,e,r,a){this.canvas=t,this.nodes=e,this.connections=r,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,r={};for(const l of this.nodes){const i=l.id,o=this.canvas.collabEngine.freshId();if(r[i]=o,l.id=o,e&&(l.coords=[l.coords[0]+e[0],l.coords[1]+e[1]]),l.sections)for(const n of l.sections){const d=n.id;if(n.id.includes(l.id)?n.id=n.id.replace(l.id,o):n.id=this.canvas.collabEngine.freshId(),r[d]=n.id,e&&(n.coords=[n.coords[0]+e[0],n.coords[1]+e[1]]),n.ports)for(const g of n.ports){const h=g.id;g.id.includes(l.id)?g.id=g.id.replace(l.id,o):g.id=this.canvas.collabEngine.freshId(),r[h]=g.id,e&&(g.coords=[g.coords[0]+e[0],g.coords[1]+e[1]])}}if(l.ports)for(const n of l.ports){const d=n.id;n.id.includes(l.id)?n.id=n.id.replace(l.id,o):n.id=this.canvas.collabEngine.freshId(),r[d]=n.id,e&&(n.coords=[n.coords[0]+e[0],n.coords[1]+e[1]])}}for(const l of this.connections){const i=this.canvas.collabEngine.freshId();if(r[l.id]=i,l.id=i,l.start=r[l.start]||l.start,l.end=r[l.end]||l.end,e)for(let o=0;o<l.points.length;++o)l.points[o]=[l.points[o][0]+e[0],l.points[o][1]+e[1]]}const a=new Zt(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(a),!0}undo(){const t=this.nodes.map(r=>this.canvas.model.nodes.get(r.id)!==void 0).includes(!0)||this.connections.map(r=>this.canvas.model.connections.get(r.id)!==void 0).includes(!0),e=new ot(this.canvas,this.nodes.map(r=>r.id),[],[],this.connections.map(r=>r.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=this.nodes.map(r=>this.canvas.model.nodes.get(r.id)===void 0).includes(!0)||this.connections.map(r=>this.canvas.model.connections.get(r.id)===void 0).includes(!0),e=new ot(this.canvas,this.nodes.map(r=>r.id),[],[],this.connections.map(r=>r.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class Kt{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}class gt extends Kt{constructor(t,e,r){super(0),this.cause=t,this.target=e,this.coords=r}}class ut extends Kt{constructor(t,e,r){super(1),this.cause=t,this.target=e,this.coords=r}}class O extends Kt{constructor(t,e){super(2),this.targets=t,this.selected=e}}class Q extends Kt{constructor(t){super(3),this.target=t}}class so extends vt{constructor(t,e,r,a,l,i,o,n){if(t.objects.get(n)!==void 0)throw new Error(`DiagramObject with id "${n}" already exists`);super(t,n),this.rootElement=e,this.coords=r,this.width=a,this.height=l,this.priority=i,this.html=o}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`foreignObject#${this.id}`)}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 no extends ct{constructor(t){super(),this.model=t}new(t,e,r,a,l,i,o){const n=new so(this.model,t,e,r,a,l,i,o);return super.add(n),n.updateInView(),t!==void 0&&t.decorators.push(n),n}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof L||e.rootElement instanceof Y)&&j(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class ro extends vt{constructor(t,e,r,a,l,i,o){if(t.objects.get(o)!==void 0)throw new Error(`DiagramObject with id "${o}" already exists`);super(t,o),this.coords=e,this.width=r,this.height=a,this.priority=l,this.html=i}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateObjectsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class ao extends ct{constructor(t){super(),this.model=t}new(t,e,r,a,l,i){const o=new ro(this.model,t,e,r,a,l,i);return super.add(o),o.updateInView(),o}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class di{constructor(t,e,r,a,l,i=[]){this.nodes=new Hi(this),this.sections=new Gi(this),this.ports=new Ki(this),this.connections=new Vi(this),this.fields=new Di(this),this.objects=new ao(this),this.decorators=new no(this),this.canvas=t,this.id=e,this.name=r,this.description=a,this.type=l,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new At(new Yt(i),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 re=96,K=32,kt=re+K,lo=Math.PI/4,co=100;class ho{constructor(t){this.canvas=t}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),r=this.canvas.getPointerLocationRelativeToCanvas(t),a=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-kt}px`).attr("y",`${e[1]-kt}px`).attr("width",`${2*kt}px`).attr("height",`${2*kt}px`).style("pointer-events","none").on(S.ContextMenu,i=>{this.canvas.canUserPerformAction(k.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(S.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=a;const l=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&this.canvas.canUserPerformAction(k.Remove)&&l.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.preventDefault(),this.canvas.userSelection.cutToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&l.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.preventDefault(),this.canvas.userSelection.copyToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.canUserPerformAction(k.Paste)&&l.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.preventDefault(),this.canvas.userSelection.pasteFromClipboard(this.canvas.getClosestGridPoint(r)),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Remove)&&l.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.preventDefault(),this.canvas.userSelection.removeFromModel(),this.canvas.cancelAllUserActions()}}),l.length===0&&l.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<l.length;++i){const o=l[i],n=o.onPress,d=(i+.5-l.length/2)*lo,g=a.append("xhtml:div").attr("class",`daga-context-menu-button ${o.imageClass}-button${o.onPress!=null?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*K}px`).style("height",`${2*K}px`).style("border-radius",`${K}px`).style("pointer-events","auto").on(S.Click,h=>{n&&n(h)}).on(S.KeyDown,h=>{n&&h.key===at.Enter&&n(h)});g.append("xhtml:div").style("position","absolute").style("left",`${.75*K}px`).style("top",`${.5*K}px`).style("width",`${.5*K}px`).style("height",`${.5*K}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",o.imageClass),g.append("xhtml:span").style("position","absolute").style("left",`${.2*K}px`).style("top",`${1.1*K}px`).style("text-align","center").style("width",`${1.6*K}px`).style("height",`${.35*K}px`).style("margin","0").style("font-size",`${.35*K}px`).style("font-weight","700").style("user-select","none").text(o.name),g.transition().ease(E.easeLinear).duration(co).tween("progress",()=>h=>{const m=d*h;return g.style("left",`${Math.sin(m)*re-K+kt}px`).style("top",`${-Math.cos(m)*re-K+kt}px`)})}}close(){var t;(t=this.contextMenuContainer)==null||t.remove(),this.contextMenuContainer=void 0}}class go extends ct{constructor(t){super(),this.focus=void 0,this.canvas=t}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,t instanceof lt&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof L){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 Y){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 mt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof st&&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 uo=1;class ci{export(t,e=!1){const r={name:t.name,type:t.type,typeVersion:uo,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(r.id=t.id),t.description&&(r.description=t.description);for(const a of t.nodes.all(!0))!e&&a.removed||a.parent===void 0&&r.nodes.push(this.exportNode(a,e));for(const a of t.connections.all(!0))!e&&a.removed||r.connections.push(this.exportConnection(a,e));return r}exportNode(t,e=!1){var i,o,n,d,g,h;const r=[];for(const m of t.children)r.push(this.exportNode(m,e));const a=[];for(const m of t.sections){const p=[];for(const u of m.ports)p.push({id:u.id,type:(i=u.type)==null?void 0:i.id,coords:Ct(u.coords),connectionPoint:Ct(u.connectionPoint),direction:u.direction,label:((o=u.label)==null?void 0:o.text)||"",...e?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}});a.push({id:m.id,ports:p,label:((n=m.label)==null?void 0:n.text)||"",indexXInNode:m.indexXInNode,indexYInNode:m.indexYInNode,coords:Ct(m.coords),width:m.width,height:m.height,...e?{collabMeta:{removed:m.removed,selfRemoved:m.selfRemoved,selfRemovedTimestamp:m.selfRemovedTimestamp,...this.exportLabelCollabMeta(m)}}:{}})}const l=[];for(const m of t.ports)l.push({id:m.id,type:(d=m.type)==null?void 0:d.id,coords:Ct(m.coords),connectionPoint:Ct(m.connectionPoint),direction:m.direction,label:((g=m.label)==null?void 0:g.text)||"",...e?{collabMeta:{removed:m.removed,selfRemoved:m.selfRemoved,selfRemovedTimestamp:m.selfRemovedTimestamp,...this.exportLabelCollabMeta(m)}}:{}});return{id:t.id,type:t.type.id,children:r,sections:a,ports:l,label:((h=t.label)==null?void 0:h.text)||"",coords:Ct(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){var r,a;return{id:t.id,type:t.type.id,start:((r=t.start)==null?void 0:r.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 fo="Diagram properties";class mo extends ct{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(yt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof L||t instanceof st)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof Y?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof L&&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 L&&e.sections))for(const r of e.sections)super.remove(r.id),r.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 L&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],r=[],a=[],l=[];for(const o of this.all())o instanceof L?t.push(o.id):o instanceof Y?e.push(o.id):o instanceof mt?r.push(o.id):o instanceof st?a.push(o.id):o instanceof lt&&l.push(o.id);const i=new io(this.canvas,t,e,r,a,l);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new ci;for(const r of this.all())r instanceof L&&t.nodes.push(e.exportNode(r,!1)),r instanceof st&&t.connections.push(e.exportConnection(r,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const r=JSON.parse(e);if(r.type!=="daga-user-selection")return;const a=new oo(this.canvas,r.nodes,r.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 r=t==null?void 0:t.valueSet;r?(this.propertyEditorSelection=t,this.propertyEditorValues=structuredClone(r.getValues()),e&&(t instanceof L||t instanceof st?(t instanceof L?t.name?e.title=`${t.type.name}: ${t.name}`:e.title=t.type.name:t instanceof st&&(e.title=t.type.name),e.valueSet=void 0,e.valueSet=r):(e.title=fo,e.valueSet=void 0,e.valueSet=r))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,e&&(e.title="",e.valueSet=void 0))}makeUpdateValuesAction(){var o,n;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof di?void 0:this.propertyEditorSelection.id;if(Pt(this.propertyEditorValues,(o=this.propertyEditorSelection)==null?void 0:o.valueSet.getValues()))return;const e=this.propertyEditorValues,r=structuredClone((n=this.propertyEditorSelection)==null?void 0:n.valueSet.getValues()),[a,l]=oi(e,r),i=new eo(this.canvas,t,a,l);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=r}}const po=12,V=6,yo=25,ie="diagram-connection-unfinished",bo=100,Ut=class Ut{constructor(t,e){var r,a,l,i,o,n,d,g,h,m,p,u,c,f,v,w,b,$;if(this.backgroundPatternId=`daga-background-pattern-id-${Ut.canvasCount++}`,this.zoomTransform=E.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new yt.Subject,this.diagramChange$=new yt.Subject,this.diagramEvent$=new yt.Subject,this.propertyEditorChanges$=new yt.Subject,this.parentComponent=t,this.model=new di(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new mo(this),this.userHighlight=new go(this),this.contextMenu=new ho(this),this.backgroundColor=((r=e.canvas)==null?void 0:r.backgroundColor)||"#FFFFFF",this.gridSize=((l=(a=e.canvas)==null?void 0:a.grid)==null?void 0:l.enabled)===!1||((i=e.canvas)==null?void 0:i.grid)===void 0?0:Math.abs(((n=(o=e.canvas)==null?void 0:o.grid)==null?void 0:n.spacing)||10),this.gridThickness=Math.abs(((g=(d=e.canvas)==null?void 0:d.grid)==null?void 0:g.thickness)||.05),this.gridColor=((m=(h=e.canvas)==null?void 0:h.grid)==null?void 0:m.color)||"rgba(0, 0, 0, 0.1)",this.snapToGrid=((u=(p=e.canvas)==null?void 0:p.grid)==null?void 0:u.enabled)===!1||((c=e.canvas)==null?void 0:c.grid)===void 0?!1:((v=(f=e.canvas)==null?void 0:f.grid)==null?void 0:v.snap)||!1,this.zoomFactor=((w=e.canvas)==null?void 0:w.zoomFactor)||2,this.panRate=((b=e.canvas)==null?void 0:b.panRate)||100,this.inferConnectionType=e.inferConnectionType||!1,this.multipleSelectionOn=!1,this.priorityThresholds=(($=e.canvas)==null?void 0:$.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new Ji(this,yo),this.collabEngine=new qi(this),e.nodeTypes)for(const I of e.nodeTypes){const T=new ni({...e.nodeTypeDefaults,...I});this.model.nodes.types.add(T)}if(e.portTypes)for(const I of e.portTypes){const T=new Zi({...e.portTypeDefaults,...I});this.model.ports.types.add(T)}if(e.connectionTypes){for(const I of e.connectionTypes){const T=new si({...e.connectionTypeDefaults,...I});this.model.connections.types.add(T)}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,r;this._connectionType=t,(r=(e=this.parentComponent)==null?void 0:e.palette)==null||r.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){j(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){var e,r;this.priorityThreshold=t,this.updateModelInView();for(const a of this.model.nodes)this.fitNodeInView(a.id);(r=(e=this.parentComponent)==null?void 0:e.palette)==null||r.refreshPalette()}initView(t){const e=E.select(t);e.html(""),this.diagramRoot=e.append("div").node(),E.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),E.select(this.diagramRoot).on(S.Click,()=>{var i;(i=E.select(this.diagramRoot).node())==null||i.focus()}).on(S.ContextMenu,i=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,null);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(S.DoubleClick,i=>{const o=new gt(i,null);this.diagramEvent$.next(o)}).on(S.KeyDown,i=>{if(!i.ctrlKey&&(i.key===at.Delete||i.key===at.Backspace)&&this.canUserPerformAction(k.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),i.ctrlKey&&i.key==="a"){i.preventDefault();for(const o of this.model.nodes)this.userSelection.add(o);for(const o of this.model.connections)this.userSelection.add(o);this.diagramEvent$.next(new O(this.userSelection.all(),!0))}if(i.ctrlKey&&i.key==="i"){i.preventDefault();const o=[],n=[];for(const d of this.model.nodes)this.userSelection.toggle(d),d.selected?o.push(d):n.push(d);for(const d of this.model.connections)this.userSelection.toggle(d),d.selected?o.push(d):n.push(d);o.length>0&&this.diagramEvent$.next(new O(o,!0)),n.length>0&&this.diagramEvent$.next(new O(n,!1))}if(i.ctrlKey&&i.key==="c"&&(i.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),i.ctrlKey&&i.key==="x"&&(i.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),i.ctrlKey&&i.key==="v"){i.preventDefault();const o=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(o[0][0]+o[1][0])/2,(o[0][1]+o[1][1])/2])),this.cancelAllUserActions()}i.ctrlKey&&i.key==="y"&&(i.preventDefault(),this.actionStack.redo()),i.ctrlKey&&i.key==="z"&&(i.preventDefault(),this.actionStack.undo()),i.key==="+"&&(i.preventDefault(),this.zoomBy(this.zoomFactor)),i.key==="-"&&(i.preventDefault(),this.zoomBy(1/this.zoomFactor)),i.key===at.ArrowLeft&&(i.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),i.key===at.ArrowRight&&(i.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),i.key===at.ArrowDown&&(i.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),i.key===at.ArrowUp&&(i.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const r=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%"),a=r.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(S.MouseMove,i=>{if(this.unfinishedConnection!==void 0){const o=this.getPointerLocationRelativeToCanvas(i);this.unfinishedConnection.endCoords=o}}).on(S.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null)))}).on(S.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null))),this.contextMenu.close(),this.userSelection.size()>0){const i=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(i,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(E.drag().filter(i=>this.multipleSelectionOn||ft(i)).on(A.Start,i=>{this.startMultipleSelection(i)}).on(A.Drag,i=>{this.continueMultipleSelection(i)}).on(A.End,i=>{this.finishMultipleSelection(i)})).call(this.zoomBehavior=E.zoom().on(se.Zoom,i=>{if(i.sourceEvent){if(!this.canUserPerformAction(k.Zoom)){x(M.NotAllowed);return}i.sourceEvent.type===S.Wheel&&i.sourceEvent.wheelDelta!==void 0?(i.sourceEvent.wheelDelta>0&&x(M.ZoomIn),i.sourceEvent.wheelDelta<0&&x(M.ZoomOut)):i.sourceEvent.type===S.MouseMove&&x(M.AllScroll)}this.zoomTransform=i.transform;const o=i.transform.toString();this.selectCanvasElements().attr("transform",o),E.select(`#${this.backgroundPatternId}`).attr("patternTransform",o),this.contextMenu.close()}).on(se.End,()=>{x()})),l=r.append("defs");if(this.gridSize>0&&isFinite(this.gridSize)){const i=l.append("pattern").attr("id",this.backgroundPatternId).attr("x",-this.gridSize/2).attr("y",-this.gridSize/2).attr("width",this.gridSize).attr("height",this.gridSize).attr("patternUnits","userSpaceOnUse");i.append("rect").attr("x",0).attr("y",0).attr("width",this.gridSize).attr("height",this.gridSize).attr("fill",this.backgroundColor),i.append("circle").attr("cx",this.gridSize/2).attr("cy",this.gridSize/2).attr("r",this.gridSize*this.gridThickness).attr("fill",this.gridColor),a.attr("fill",`url(#${this.backgroundPatternId})`)}r.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(),r=this.model.nodes.all(),a=Math.min(...r.map(c=>c.coords[0])),l=Math.max(...r.map(c=>c.coords[0]+c.width)),i=(a+l)/2,o=l-a,n=e.width,d=Math.min(...r.map(c=>c.coords[1])),g=Math.max(...r.map(c=>c.coords[1]+c.height)),h=(d+g)/2,m=g-d,p=e.height,u=Math.min(n/o,p/m,1);this.translateTo(i,h),this.zoomTo(u)}}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 r;const t=(r=this.selectSVGElement().node())==null?void 0:r.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 E.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return E.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return E.pointer(this.getEventHoldingCoordinates(t),E.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.look.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const l=a.merge(e);r.remove(),a.on(S.MouseOver,(i,o)=>{this.dragging||(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)))}).on(S.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const n=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(n,!1))}this.userSelection.toggle(o),this.diagramEvent$.next(new O([o],o.selected))}).on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)),this.userSelection.add(o),this.diagramEvent$.next(new O([o],!0)),this.contextMenu.open(i))}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,o)}).on(A.Drag,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,o)}).on(A.End,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,o),this.secondaryButton=!1})),a.filter(".shaped-look").append("path"),a.filter(".image-look").append("image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none"),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x(M.EWResize)}).on(S.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed?(x(M.EWResize),this.currentAction=new B(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed){const n=this.getPointerLocationRelativeToCanvas(i);o.stretch(y.Left,o.coords[0]-n[0])}}).on(A.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchNode){let n=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(n=this.getClosestGridPoint(n)),o.stretch(y.Left,o.coords[0]-n[0]),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x(M.NSResize)}).on(S.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed?(x(M.NSResize),this.currentAction=new B(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed){const n=this.getPointerLocationRelativeToCanvas(i);o.stretch(y.Top,o.coords[1]-n[1])}}).on(A.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchNode){let n=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(n=this.getClosestGridPoint(n)),o.stretch(y.Top,o.coords[1]-n[1]),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x(M.EWResize)}).on(S.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed?(x(M.EWResize),this.currentAction=new B(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed){const n=this.getPointerLocationRelativeToCanvas(i);o.stretch(y.Right,n[0]-(o.coords[0]+o.width))}}).on(A.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableX&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchNode){let n=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(n=this.getClosestGridPoint(n)),o.stretch(y.Right,n[0]-(o.coords[0]+o.width)),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x(M.NSResize)}).on(S.MouseOut,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed?(x(M.NSResize),this.currentAction=new B(this,k.StretchNode,o.id,o.getGeometry(),o.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed){const n=this.getPointerLocationRelativeToCanvas(i);o.stretch(y.Bottom,n[1]-(o.coords[1]+o.height))}}).on(A.End,(i,o)=>{if(this.canUserPerformAction(k.StretchNode)&&o.type.resizableY&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchNode){let n=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(n=this.getClosestGridPoint(n)),o.stretch(y.Bottom,n[1]-(o.coords[1]+o.height)),this.currentAction.to=o.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),l.filter(".shaped-look").select("path").attr("d",i=>Gt(i.type.look.shape,0,0,i.width,i.height)).attr("fill",i=>i.selected?i.type.look.selectedFillColor:i.type.look.fillColor).attr("stroke",i=>i.selected?i.type.look.selectedBorderColor:i.type.look.borderColor).attr("stroke-width",i=>`${i.highlighted?3:1}px`),l.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",i=>i.width).attr("height",i=>i.height).attr("href",i=>i.selected?i.type.look.selectedBackgroundImage:i.type.look.backgroundImage),l.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTopLeft:i.type.look.backgroundImageTopLeft),l.filter(".stretchable-image-look").select("image.top-image").attr("x",i=>i.type.look.leftMargin).attr("y",0).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTop:i.type.look.backgroundImageTop),l.filter(".stretchable-image-look").select("image.top-right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",0).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTopRight:i.type.look.backgroundImageTopRight),l.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageLeft:i.type.look.backgroundImageLeft),l.filter(".stretchable-image-look").select("image.center-image").attr("x",i=>i.type.look.leftMargin).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageCenter:i.type.look.backgroundImageCenter),l.filter(".stretchable-image-look").select("image.right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageRight:i.type.look.backgroundImageRight),l.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottomLeft:i.type.look.backgroundImageBottomLeft),l.filter(".stretchable-image-look").select("image.bottom-image").attr("x",i=>i.type.look.leftMargin).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottom:i.type.look.backgroundImageBottom),l.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottomRight:i.type.look.backgroundImageBottomRight),l.filter(".resizable-x").select("line.left-resizer").attr("x1",V/2).attr("x2",V/2).attr("y1",0).attr("y2",i=>i.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",V/2).attr("y2",V/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-V/2).attr("x2",i=>i.width-V/2).attr("y1",0).attr("y2",i=>i.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-V/2).attr("y2",i=>i.height-V/2)}updateSectionsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>{var o,n,d,g,h,m;return`diagram-section${(n=(o=i.node)==null?void 0:o.type)!=null&&n.resizableX?" resizable-x":""}${(g=(d=i.node)==null?void 0:d.type)!=null&&g.resizableY?" resizable-y":""} ${(m=(h=i.getConfig())==null?void 0:h.look)==null?void 0:m.lookType}`});t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const l=a.merge(e);r.remove(),a.on(S.MouseOver,(i,o)=>{this.dragging||(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)))}).on(S.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(d,!1))}const n=pt(o);this.userSelection.toggle(n),this.diagramEvent$.next(new O([n],n.selected))}).on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=pt(o);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new O([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const n=o==null?void 0:o.node;n?this.startMovingNode(i,n):x(M.NotAllowed)}}).on(A.Drag,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const n=o==null?void 0:o.node;n?this.continueMovingNode(i,n):x(M.NotAllowed)}}).on(A.End,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const n=o==null?void 0:o.node;n?this.finishMovingNode(i,n):x()}this.secondaryButton=!1})),a.filter(".shaped-look").append("path"),a.filter(".image-look").append("image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),a.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none"),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&x(M.EWResize)}).on(S.MouseOut,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed?(x(M.EWResize),this.currentAction=new B(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed){const g=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(y.Left,o.coords[0]-g[0],o.indexXInNode,o.indexYInNode)}}).on(A.End,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchSection){let g=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(g=this.getClosestGridPoint(g)),o.node.stretchSections(y.Left,o.coords[0]-g[0],o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&x(M.NSResize)}).on(S.MouseOut,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed?(x(M.NSResize),this.currentAction=new B(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed){const g=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(y.Top,o.coords[1]-g[1],o.indexXInNode,o.indexYInNode)}}).on(A.End,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchSection){let g=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(g=this.getClosestGridPoint(g)),o.node.stretchSections(y.Top,o.coords[1]-g[1],o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&x(M.EWResize)}).on(S.MouseOut,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed?(x(M.EWResize),this.currentAction=new B(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed){const g=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(y.Right,g[0]-(o.coords[0]+o.width),o.indexXInNode,o.indexYInNode)}}).on(A.End,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableX)&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchSection){let g=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(g=this.getClosestGridPoint(g)),o.node.stretchSections(y.Right,g[0]-(o.coords[0]+o.width),o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${V}px`).on(S.MouseOver,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&x(M.NSResize)}).on(S.MouseOut,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&x()}).call(E.drag().on(A.Start,(i,o)=>{var n,d;this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed?(x(M.NSResize),this.currentAction=new B(this,k.StretchSection,o.node.id,o.node.getGeometry(),o.node.getGeometry())):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed){const g=this.getPointerLocationRelativeToCanvas(i);o.node.stretchSections(y.Bottom,g[1]-(o.coords[1]+o.height),o.indexXInNode,o.indexYInNode)}}).on(A.End,(i,o)=>{var n,d;if(this.canUserPerformAction(k.StretchSection)&&((d=(n=o.node)==null?void 0:n.type)!=null&&d.resizableY)&&!o.removed&&this.currentAction instanceof B&&this.currentAction.intent===k.StretchSection){let g=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(g=this.getClosestGridPoint(g)),o.node.stretchSections(y.Bottom,g[1]-(o.coords[1]+o.height),o.indexXInNode,o.indexYInNode),this.currentAction.to=o.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}x()})),l.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),l.filter(".shaped-look").select("path").attr("d",i=>{var o;return Gt(((o=i.getConfig())==null?void 0:o.look).shape,0,0,i.width,i.height)}).attr("fill",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedFillColor:((n=i.getConfig())==null?void 0:n.look).fillColor}).attr("stroke",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBorderColor:((n=i.getConfig())==null?void 0:n.look).borderColor}).attr("stroke-width",i=>`${i.highlighted?3:1}px`),l.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",i=>i.width).attr("height",i=>i.height).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImage:((n=i.getConfig())==null?void 0:n.look).backgroundImage}),l.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageTopLeft:((n=i.getConfig())==null?void 0:n.look).backgroundImageTopLeft}),l.filter(".stretchable-image-look").select("image.top-image").attr("x",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("y",0).attr("width",i=>{var o,n;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin-((n=i.getConfig())==null?void 0:n.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageTop:((n=i.getConfig())==null?void 0:n.look).backgroundImageTop}),l.filter(".stretchable-image-look").select("image.top-right-image").attr("x",i=>{var o;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("y",0).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageTopRight:((n=i.getConfig())==null?void 0:n.look).backgroundImageTopRight}),l.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("height",i=>{var o,n;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin-((n=i.getConfig())==null?void 0:n.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageLeft:((n=i.getConfig())==null?void 0:n.look).backgroundImageLeft}),l.filter(".stretchable-image-look").select("image.center-image").attr("x",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("y",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("width",i=>{var o,n;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin-((n=i.getConfig())==null?void 0:n.look).leftMargin}).attr("height",i=>{var o,n;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin-((n=i.getConfig())==null?void 0:n.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageCenter:((n=i.getConfig())==null?void 0:n.look).backgroundImageCenter}),l.filter(".stretchable-image-look").select("image.right-image").attr("x",i=>{var o;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("y",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).topMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("height",i=>{var o,n;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin-((n=i.getConfig())==null?void 0:n.look).topMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageRight:((n=i.getConfig())==null?void 0:n.look).backgroundImageRight}),l.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",i=>{var o;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageBottomLeft:((n=i.getConfig())==null?void 0:n.look).backgroundImageBottomLeft}),l.filter(".stretchable-image-look").select("image.bottom-image").attr("x",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).leftMargin}).attr("y",i=>{var o;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("width",i=>{var o,n;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin-((n=i.getConfig())==null?void 0:n.look).leftMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageBottom:((n=i.getConfig())==null?void 0:n.look).backgroundImageBottom}),l.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",i=>{var o;return i.width-((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("y",i=>{var o;return i.height-((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("width",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).rightMargin}).attr("height",i=>{var o;return((o=i.getConfig())==null?void 0:o.look).bottomMargin}).attr("href",i=>{var o,n;return i.selected?((o=i.getConfig())==null?void 0:o.look).selectedBackgroundImageBottomRight:((n=i.getConfig())==null?void 0:n.look).backgroundImageBottomRight}),l.filter(".resizable-x").select("line.left-resizer").attr("x1",V/2).attr("x2",V/2).attr("y1",0).attr("y2",i=>i.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",V/2).attr("y2",V/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-V/2).attr("x2",i=>i.width-V/2).attr("y1",0).attr("y2",i=>i.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-V/2).attr("y2",i=>i.height-V/2)}updatePortsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>{var o,n;return`diagram-port ${((n=(o=i.type)==null?void 0:o.look)==null?void 0:n.lookType)||"default"}`});t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const l=a.merge(e);r.remove(),a.on(S.MouseOver,(i,o)=>{var n,d,g,h,m,p,u,c,f,v,w,b;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((g=(d=(n=this.unfinishedConnection.start)==null?void 0:n.getNode())==null?void 0:d.type)==null?void 0:g.id)||"")&&((h=this.unfinishedConnection.start)!=null&&h.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((p=(m=o.getNode())==null?void 0:m.type)==null?void 0:p.id)||"")&&o.allowsIncoming||this.unfinishedConnection.type.canStartFromType(((c=(u=o.getNode())==null?void 0:u.type)==null?void 0:c.id)||"")&&o.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(((w=(v=(f=this.unfinishedConnection.start)==null?void 0:f.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&((b=this.unfinishedConnection.start)!=null&&b.allowsIncoming)||x(M.NoDrop))}).on(S.MouseOut,()=>{this.unfinishedConnection&&x(M.Grabbing)}).on(S.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(d,!1))}const n=pt(o);this.userSelection.toggle(n),this.diagramEvent$.next(new O([n],n.selected))}).on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=pt(o);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new O([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,(i,o)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(k.AddConnection)&&!o.removed?(x(M.Grabbing),this.startConnection(o),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):x(M.NotAllowed)}).on(A.Drag,(i,o)=>{var n,d,g,h;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(k.AddConnection)&&!o.removed&&this.unfinishedConnection!==void 0){const m=[i.x,i.y];(g=this.unfinishedConnectionTracer)==null||g.attr("d",oe(this.unfinishedConnection.type.shape,this.unfinishedConnection.startCoords,m,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.width,(n=this.unfinishedConnection.startMarkerLook)==null?void 0:n.markerWidth,(d=this.unfinishedConnection.endMarkerLook)==null?void 0:d.markerWidth));const p=(h=this.unfinishedConnectionTracer)==null?void 0:h.node();if(p){let u=2;const c=p.getTotalLength();c<u&&(u=0);const f=p.getPointAtLength(c-u);this.unfinishedConnection.endCoords=[f.x,f.y]}else this.unfinishedConnection.endCoords=m;if(this.updateConnectionsInView(ie),this.model.ports.length>0){const u=this.getPointerLocationRelativeToCanvas(i);let c=Number.POSITIVE_INFINITY,f;for(const v of this.model.ports){const w=v.distanceTo(u);w<c&&(c=w,f=v)}f&&c<bo?this.userHighlight.focusOn(f):this.userHighlight.clear()}}}).on(A.End,(i,o)=>{var n;if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(k.AddConnection)&&!o.removed){(n=this.unfinishedConnectionTracer)==null||n.remove();const d=this.userHighlight.getFocus();if(d instanceof mt)this.finishConnection(d);else if(d instanceof lt&&d.rootElement instanceof mt)this.finishConnection(d.rootElement);else if(d instanceof L||d instanceof Y||d instanceof lt){let g;if(d instanceof L||d instanceof Y)g=d;else if(d.rootElement instanceof L||d.rootElement instanceof Y)g=d.rootElement;else{this.dropConnection();return}const h=g.getClosestPortToPoint([i.x,i.y]);h!==void 0?this.finishConnection(h):this.dropConnection()}else this.dropConnection()}x()}this.secondaryButton=!1})),a.filter(".default").append("circle"),a.filter(".image-look").append("image"),l.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),l.filter(".default").select("circle").attr("cx",0).attr("cy",0).attr("r",ai.width/2).attr("fill",i=>i.selected?Ke.selectedColor:Ke.highlightedColor).attr("opacity",i=>i.highlighted||i.selected?.5:0),l.filter(".image-look").select("image").attr("x",i=>-i.type.width/2).attr("y",i=>-i.type.width/2).attr("width",i=>i.type.width).attr("height",i=>i.type.width).attr("href",i=>{var o,n;return i.selected?((o=i.type)==null?void 0:o.look).selectedBackgroundImage:((n=i.type)==null?void 0:n.look).backgroundImage})}updateConnectionsInView(...t){const e=this.model.connections.filter(o=>this.priorityThreshold!==void 0?o.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let r=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,o=>o.id);const a=r.exit(),l=r.enter().append("g").attr("id",o=>o.id).attr("class","diagram-connection");t&&t.length>0&&(r=r.filter(o=>t.includes(o.id)));const i=l.merge(r);a.remove(),l.on(S.MouseOver,(o,n)=>{n.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(o,n)=>{if(!o.ctrlKey&&!o.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(d,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new O([n],n.selected))}).on(S.ContextMenu,(o,n)=>{if(this.dragging){o.preventDefault(),o.stopPropagation(),this.dragging=!1;return}const d=new ut(o,n);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(o.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)),this.userSelection.add(n),this.diagramEvent$.next(new O([n],!0)),this.contextMenu.open(o))}).on(S.DoubleClick,(o,n)=>{const d=new gt(o,n);this.diagramEvent$.next(d)}).call(E.drag().filter(o=>(this.secondaryButton=ft(o),!0)).on(A.Start,o=>{this.startMultipleSelection(o)}).on(A.Drag,o=>{this.continueMultipleSelection(o)}).on(A.End,o=>{this.finishMultipleSelection(o)})),l.append("path").attr("class","diagram-connection-path"),l.append("path").attr("class","diagram-connection-path-box"),l.append("marker").attr("id",o=>`${o.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),l.append("marker").attr("id",o=>`${o.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"),i.attr("opacity",o=>o.removed?.5:1).select("path.diagram-connection-path").attr("d",o=>{var n,d;return oe(o.type.shape,o.startCoords,o.endCoords,o.startDirection,o.endDirection,o.type.width,(n=o.startMarkerLook)==null?void 0:n.markerWidth,(d=o.endMarkerLook)==null?void 0:d.markerWidth)}).attr("marker-start",o=>`url(#${o.id}-start-marker)`).attr("marker-end",o=>`url(#${o.id}-end-marker)`).attr("stroke",o=>o.selected?o.type.selectedColor:o.type.color).attr("stroke-width",o=>`${o.highlighted?o.type.width+1:o.type.width}px`).attr("stroke-dasharray",o=>Ue(o.type.style,o.type.width)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",o=>{var n,d;return oe(o.type.shape,o.startCoords,o.endCoords,o.startDirection,o.endDirection,o.type.width,(n=o.startMarkerLook)==null?void 0:n.markerWidth,(d=o.endMarkerLook)==null?void 0:d.markerWidth)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",o=>`${o.type.width+po}px`).attr("stroke-dasharray",o=>Ue(o.type.style,o.type.width)).attr("fill","none"),i.data().forEach(o=>{this.updateConnectionLabelsInView(o),this.updateConnectionMarkersInView(o)})}updateFieldsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const l=a.merge(e);r.remove(),a.style("box-sizing","border-box").on(S.MouseOver,(i,o)=>{this.dragging||(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)))}).on(S.Click,(i,o)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new O(d,!1))}const n=pt(o);this.userSelection.toggle(n),this.diagramEvent$.next(new O([n],n.selected))}).on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=pt(o);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new O([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.EditField)&&o.editable&&!o.removed&&(this.currentAction=new qe(this,o.id,o.text,""),this.createInputField(o.text,o.coords,o.width,o.height,o.fontSize,o.fontFamily||z.fontFamily,d=>{o.text=d},d=>{o.text=d,this.currentAction instanceof qe&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let n;o.rootElement instanceof L?n=o.rootElement:o.rootElement instanceof Y&&(n=o.rootElement.node),n?this.startMovingNode(i,n):x(M.NotAllowed)}}).on(A.Drag,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let n;o.rootElement instanceof L?n=o.rootElement:o.rootElement instanceof Y&&(n=o.rootElement.node),n?this.continueMovingNode(i,n):x(M.NotAllowed)}}).on(A.End,(i,o)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let n;o.rootElement instanceof L?n=o.rootElement:o.rootElement instanceof Y&&(n=o.rootElement.node),n?this.finishMovingNode(i,n):x()}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",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("div").style("justify-content",i=>i.horizontalAlign===xt.Center?"center":i.horizontalAlign===xt.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Bt.Center?"center":i.verticalAlign===Bt.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":"100%").style("max-height",i=>i.fit?"default":"100%").style("overflow",i=>i.fit?"default":"hidden").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===xt.Center?"center":i.horizontalAlign===xt.Right?"end":"start").style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"))}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),a.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),r.remove(),a.on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,i=>{this.startMultipleSelection(i)}).on(A.Drag,i=>{this.continueMultipleSelection(i)}).on(A.End,i=>{this.finishMultipleSelection(i)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const r=e.exit(),a=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),a.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),r.remove(),a.on(S.ContextMenu,(i,o)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const n=new ut(i,o);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(S.DoubleClick,(i,o)=>{const n=new gt(i,o);this.diagramEvent$.next(n)}).call(E.drag().filter(i=>(this.secondaryButton=ft(i),!0)).on(A.Start,i=>{this.startMultipleSelection(i)}).on(A.Drag,i=>{this.continueMultipleSelection(i)}).on(A.End,i=>{this.finishMultipleSelection(i)}))}updateConnectionLabelsInView(t){var i,o,n;const e=this.selectCanvasView().select(`g.diagram-connection#${t.id}`),a=e.select("path").node(),l={...z,...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 g=(i=e.select("g.diagram-connection-start-label text").node())==null?void 0:i.getBoundingClientRect();if(g){const p=t.startLabel?g.width/this.zoomTransform.k+$t(l)+Et(l):0,u=t.startLabel?g.height/this.zoomTransform.k+Mt(l)+Tt(l):0,c=a.getPointAtLength(Math.max(X(l)+p/2,nt(l)+p/2,F(l)+u/2,et(l)+u/2));e.select("g.diagram-connection-start-label path").attr("d",jt(-p/2,-u/2,p,u)).attr("fill",t.selected?t.type.selectedColor:t.type.color).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${c.x},${c.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 h=(o=e.select("g.diagram-connection-middle-label text").node())==null?void 0:o.getBoundingClientRect();if(h){const p=t.middleLabel?h.width/this.zoomTransform.k+$t(l)+Et(l):0,u=t.middleLabel?h.height/this.zoomTransform.k+Mt(l)+Tt(l):0,c=a.getPointAtLength(d/2);e.select("g.diagram-connection-middle-label path").attr("d",jt(-p/2,-u/2,p,u)).attr("fill",t.selected?t.type.selectedColor:t.type.color).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${c.x},${c.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 m=(n=e.select("g.diagram-connection-end-label text").node())==null?void 0:n.getBoundingClientRect();if(m){const p=t.endLabel?m.width/this.zoomTransform.k+$t(l)+Et(l):0,u=t.endLabel?m.height/this.zoomTransform.k+Mt(l)+Tt(l):0,c=a.getPointAtLength(d-Math.max(X(l)+p/2,nt(l)+p/2,F(l)+u/2,et(l)+u/2));e.select("g.diagram-connection-end-label path").attr("d",jt(-p/2,-u/2,p,u)).attr("fill",t.selected?t.type.selectedColor:t.type.color).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${c.x},${c.y})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`g.diagram-connection#${t.id}`),r=e.select("marker.diagram-connection-start-marker"),a=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?r.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.markerWidth).attr("markerHeight",t.startMarkerLook.markerHeight).attr("refX",t.startMarkerLook.markerRefX).attr("refY",t.startMarkerLook.markerRefY).select("image").attr("href",t.selected?t.startMarkerLook.selectedImage:t.startMarkerLook.image).attr("width",t.startMarkerLook.markerWidth).attr("height",t.startMarkerLook.markerHeight):r.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.markerWidth).attr("markerHeight",t.endMarkerLook.markerHeight).attr("refX",t.endMarkerLook.markerRefX).attr("refY",t.endMarkerLook.markerRefY).select("image").attr("href",t.selected?t.endMarkerLook.selectedImage:t.endMarkerLook.image).attr("width",t.endMarkerLook.markerWidth).attr("height",t.endMarkerLook.markerHeight):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fitFieldRootInView(t){var r,a,l,i,o,n,d,g,h,m,p;const e=this.model.fields.get(t);if(e){if(e.rootElement instanceof L&&e.fit){const u=this.minimumSizeOfField(e);let c=u[0]+X(e.rootElement.type.label)+nt(e.rootElement.type.label)-e.rootElement.width,f=u[1]+F(e.rootElement.type.label)+et(e.rootElement.type.label)-e.rootElement.height;this.snapToGrid&&(c=Math.ceil(c/this.gridSize)*this.gridSize,f=Math.ceil(f/this.gridSize)*this.gridSize),e.rootElement.width+c<e.rootElement.type.minWidth&&(c=e.rootElement.type.minWidth-e.rootElement.width),e.rootElement.height+f<e.rootElement.type.minHeight&&(f=e.rootElement.type.minHeight-e.rootElement.height),e.rootElement.stretch(y.Right,c),e.rootElement.stretch(y.Bottom,f)}if(e.rootElement instanceof Y&&e.fit){const u=this.minimumSizeOfField(e);let c=u[0],f=u[1];for(const b of((r=e.rootElement.node)==null?void 0:r.sections)||[])b.label&&(b.indexXInNode===e.rootElement.indexXInNode&&b.indexYInNode!==e.rootElement.indexYInNode?c=Math.max(c,this.minimumSizeOfField(b.label)[0]):b.indexXInNode!==e.rootElement.indexXInNode&&b.indexYInNode===e.rootElement.indexYInNode&&(f=Math.max(f,this.minimumSizeOfField(b.label)[1])));u[0]<c&&(u[0]=c),u[1]<f&&(u[1]=f);let v=u[0]+X((l=(a=e.rootElement)==null?void 0:a.getConfig())==null?void 0:l.label)+nt((o=(i=e.rootElement)==null?void 0:i.getConfig())==null?void 0:o.label)-e.rootElement.width,w=u[1]+F((d=(n=e.rootElement)==null?void 0:n.getConfig())==null?void 0:d.label)+et((h=(g=e.rootElement)==null?void 0:g.getConfig())==null?void 0:h.label)-e.rootElement.height;this.snapToGrid&&(v=Math.ceil(v/this.gridSize)*this.gridSize,w=Math.ceil(w/this.gridSize)*this.gridSize),e.rootElement.width+v<(e.rootElement.getMinWidth()||0)&&(v=(e.rootElement.getMinWidth()||0)-e.rootElement.width),e.rootElement.height+w<(e.rootElement.getMinHeight()||0)&&(w=(e.rootElement.getMinHeight()||0)-e.rootElement.height),(m=e.rootElement.node)==null||m.stretchSections(y.Right,v,e.rootElement.indexXInNode,e.rootElement.indexYInNode),(p=e.rootElement.node)==null||p.stretchSections(y.Bottom,w,e.rootElement.indexXInNode,e.rootElement.indexYInNode)}}}fitNodeInView(t){var r,a;const e=this.model.nodes.get(t);if(e&&e.sections.length>0&&this.priorityThreshold){let l=0,i=0;for(const o of e.sections)if(o.getPriority()>=this.priorityThreshold){const n=o.coords[0]+o.width-e.coords[0],d=o.coords[1]+o.height-e.coords[1];l=Math.max(l,n),i=Math.max(i,d)}l+=((r=e.type.sectionGrid)==null?void 0:r.margin)||0,i+=((a=e.type.sectionGrid)==null?void 0:a.margin)||0,e.stretch(y.Right,l-e.width),e.stretch(y.Bottom,i-e.height)}}selectRoot(){return E.select(this.diagramRoot)}selectSVGElement(){return E.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){var e,r,a,l;if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(((r=(e=t.getNode())==null?void 0:e.type)==null?void 0:r.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 st(this.model,this.connectionType,t,void 0,ie);else if(this.inferConnectionType){let i=this.model.connections.types.all().find(o=>{var n,d;return t.allowsOutgoing&&o.canStartFromType(((d=(n=t.getNode())==null?void 0:n.type)==null?void 0:d.id)||"")});i===void 0&&(i=this.model.connections.types.all().find(o=>{var n,d;return t.allowsIncoming&&o.canFinishOnType(((d=(n=t.getNode())==null?void 0:n.type)==null?void 0:d.id)||"")})),i!==void 0&&(this.unfinishedConnection=new st(this.model,i,t,void 0,ie))}}}finishConnection(t){var e,r,a,l,i,o,n,d,g,h,m,p,u,c,f,v,w,b,$,I;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0)if(this.unfinishedConnection.start!==t)if(this.unfinishedConnection.type.canStartFromType(((l=(a=(r=(e=this.unfinishedConnection)==null?void 0:e.start)==null?void 0:r.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&((o=(i=this.unfinishedConnection)==null?void 0:i.start)!=null&&o.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((d=(n=t.getNode())==null?void 0:n.type)==null?void 0:d.id)||"")&&t.allowsIncoming){const T=new ee(this,this.unfinishedConnection.type,(g=this.unfinishedConnection.start)==null?void 0:g.id,t.id);this.dropConnection(),T.do(),this.actionStack.add(T)}else if(this.unfinishedConnection.type.canFinishOnType(((u=(p=(m=(h=this.unfinishedConnection)==null?void 0:h.start)==null?void 0:m.getNode())==null?void 0:p.type)==null?void 0:u.id)||"")&&((f=(c=this.unfinishedConnection)==null?void 0:c.start)!=null&&f.allowsIncoming)&&this.unfinishedConnection.type.canStartFromType(((w=(v=t.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&t.allowsOutgoing){const T=new ee(this,this.unfinishedConnection.type,t.id,(b=this.unfinishedConnection.start)==null?void 0:b.id);this.dropConnection(),T.do(),this.actionStack.add(T)}else if(this.inferConnectionType){let T=this.model.connections.types.all().find(P=>{var W,Z,G,U,H,q,D,rt;return P.canStartFromType(((U=(G=(Z=(W=this.unfinishedConnection)==null?void 0:W.start)==null?void 0:Z.getNode())==null?void 0:G.type)==null?void 0:U.id)||"")&&((q=(H=this.unfinishedConnection)==null?void 0:H.start)==null?void 0:q.allowsOutgoing)&&P.canFinishOnType(((rt=(D=t.getNode())==null?void 0:D.type)==null?void 0:rt.id)||"")&&t.allowsIncoming}),N=!1;if(T===void 0&&(T=this.model.connections.types.all().find(P=>{var W,Z,G,U,H,q,D,rt;return P.canFinishOnType(((U=(G=(Z=(W=this.unfinishedConnection)==null?void 0:W.start)==null?void 0:Z.getNode())==null?void 0:G.type)==null?void 0:U.id)||"")&&((q=(H=this.unfinishedConnection)==null?void 0:H.start)==null?void 0:q.allowsIncoming)&&P.canStartFromType(((rt=(D=t.getNode())==null?void 0:D.type)==null?void 0:rt.id)||"")&&t.allowsOutgoing}),N=!0),T!==void 0){const P=new ee(this,T,N?t.id:($=this.unfinishedConnection.start)==null?void 0:$.id,N?(I=this.unfinishedConnection.start)==null?void 0:I.id:t.id);this.dropConnection(),P.do(),this.actionStack.add(P)}else this.dropConnection()}else this.dropConnection();else this.dropConnection()}dropConnection(){var t,e,r,a;(t=this.unfinishedConnection)==null||t.setStart(void 0),(e=this.unfinishedConnection)==null||e.setEnd(void 0),(a=(r=this.unfinishedConnection)==null?void 0:r.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,r,a,l,i,o,n){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${r}px`).attr("height",`${a}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const g=d.append("xhtml:textarea");let h,m;g.text(t).style("box-sizing","border-box").style("width",`${r}px`).style("height",`${a}px`).style("font-size",`${l}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(S.KeyDown,u=>{u.stopPropagation()}).on(S.KeyUp,u=>{if(u.stopPropagation(),u.key===at.Escape){const c=g.property("value");this.removeInputField(),n&&n(c)}}).on(S.Input,()=>{const u=g.property("value");g.attr("cols",$i(u)+1),g.attr("rows",Ei(u)+1),g.style("width",""),g.style("height",""),h=g.property("scrollWidth")+1,m=g.property("scrollHeight")+1;const c=Math.max(h,r),f=Math.max(m,a);d==null||d.attr("width",`${c}px`),g.style("width",`${c}px`),d==null||d.attr("height",`${f}px`),g.style("height",`${f}px`),o&&o(u)}).on(S.Click,u=>{u.stopPropagation()}).on(S.FocusOut,()=>{const u=g.property("value");this.removeInputField(),n&&n(u)});const p=g.node();p.focus(),p.select()}removeInputField(){var t,e,r;(e=(t=this.inputFieldContainer)==null?void 0:t.select("input"))==null||e.on(S.Blur,null),(r=this.inputFieldContainer)==null||r.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 r=e.getBoundingClientRect();return[r.width/this.zoomTransform.k,r.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed)if(x(M.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(r=>r instanceof L)>1)this.currentAction=new te(this,this.userSelection.filter(r=>r instanceof L).map(r=>r.id),e.coords);else{const r=e.getLastAncestor();this.currentAction=new B(this,k.MoveNode,e.id,e.getGeometry(),e.getGeometry(),r==null?void 0:r.id,r==null?void 0:r.getGeometry(e.id),r==null?void 0:r.getGeometry(e.id))}else x(M.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&(this.currentAction instanceof te||this.currentAction instanceof B)&&!e.removed){const r=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([r[0]-e.coords[0],r[1]-e.coords[1]]):e.move(r),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){var r,a,l;if(this.canUserPerformAction(k.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let i=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(i=this.getClosestGridPoint(i)),this.currentAction instanceof te){const o=this.currentAction.delta;this.currentAction.delta=[i[0]-o[0],i[1]-o[1]],e.selected?this.userSelection.move([o[0]-e.coords[0],o[1]-e.coords[1]]):e.move(o)}else if(this.currentAction instanceof B){e.move(i);const n=this.model.nodes.getAtCoordinates(t.x,t.y).filter(h=>h.id!==e.id&&!h.isDescendantOf(e)).filter(h=>h.type.childrenTypes.includes(e.type.id)),d=ri(n),g=d[d.length-1];if(g!==e.parent&&(e.type.canBeParentless||g!==void 0)){const h=g==null?void 0:g.getLastAncestor(),m=this.currentAction.from,p=new to(this,e.id,(r=e.parent)==null?void 0:r.id,g==null?void 0:g.id,m,e.getGeometry(),h==null?void 0:h.id,h==null?void 0:h.getGeometry(e.id),h==null?void 0:h.getGeometry(e.id));(a=e.parent)==null||a.removeChild(e),g!==void 0&&g.addChild(e),p.toChildGeometry=e.getGeometry(e.id),p.toAncestorGeometry=h==null?void 0:h.getGeometry(e.id),this.currentAction=p}else{const h=e==null?void 0:e.getLastAncestor();this.currentAction.ancestorId=h==null?void 0:h.id,this.currentAction.fromAncestorGeometry=h==null?void 0:h.getGeometry(e.id),(l=e.parent)==null||l.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=h==null?void 0:h.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}x(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectCanvasElements().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){var r,a,l,i;const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(x(M.Crosshair),(i=(l=(a=(r=this.multipleSelectionContainer)==null?void 0:r.attr("x",Math.min(this.draggingFrom[0],e[0])))==null?void 0:a.attr("y",Math.min(this.draggingFrom[1],e[1])))==null?void 0:l.attr("width",Math.abs(this.draggingFrom[0]-e[0])))==null||i.attr("height",Math.abs(this.draggingFrom[1]-e[1])),this.dragging=!0)}finishMultipleSelection(t){var r;const e=this.getPointerLocationRelativeToCanvas(t);(r=this.multipleSelectionContainer)==null||r.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)bi([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 O(this.userSelection.all(),!0)),x()}};Ut.canvasCount=0;let ae=Ut;const ft=s=>!!s.button,oe=(s,t,e,r,a,l,i,o)=>wi(s,[t,e],r,a,Math.max(10,i||0,o||0)*l),x=s=>{s?E.select("body").style("cursor",s):E.select("body").style("cursor",M.Auto)},pt=s=>s instanceof L?s:s instanceof Y?s.node||s:s.rootElement instanceof L||s.rootElement instanceof Y||s.rootElement instanceof mt?pt(s.rootElement):s;class hi{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 r=1;;++r){const a=r%2>0?r:-r,l=a>0?1:-1,i=[e[0]+a,e[1]+a];for(let o=e[0];o!==i[0]+l;o+=l)if(e[0]=o,this.get(e)===void 0)return e;for(let o=e[1];o!==i[1]+l;o+=l)if(e[1]=o,this.get(e)===void 0)return e}}}class vo{apply(t){var o;if(t.nodes.length===0)return t;const e=new hi,r=t.nodes.filter(n=>!n.parent);for(;r.length>0;)gi(r[0],e,[0,0],r);const a=Math.max(...t.nodes.map(n=>n.width)),l=Math.max(...t.nodes.map(n=>n.height)),i=(((o=t.canvas)==null?void 0:o.gridSize)||0)*2;for(let n=e.minY();n<=e.maxY();++n)for(let d=e.minX();d<=e.maxX();++d){const g=e.get([d,n]);g!==void 0&&g.move([d*(a+i),n*(l+i)])}return t}}const gi=(s,t,e,r)=>{const a=t.getClosestEmptyCoordinate(e);t.set(a,s),j(r,s);for(const l of s.getAdjacentNodes())r.includes(l)&&gi(l,t,a,r)};class wo{apply(t){var g;if(t.nodes.length===0)return t;const e=new hi,r=t.nodes.filter(h=>!h.parent),a={},l=r[0];let i=[l];for(a[l.id]=[0,0];r.length>0;){const h=[];for(const m of i){e.set(e.getClosestEmptyCoordinate(a[m.id]),m),j(r,m);const p=m.getAdjacentNodes();for(const u of p)r.includes(u)&&(h.push(u),a[u.id]=a[m.id])}if(h.length>0)i=h;else if(r.length>0){const m=r[0];i=[m],a[m.id]=e.getClosestEmptyCoordinate([0,0])}}const o=Math.max(...t.nodes.map(h=>h.width)),n=Math.max(...t.nodes.map(h=>h.height)),d=(((g=t.canvas)==null?void 0:g.gridSize)||0)*2;for(let h=e.minY();h<=e.maxY();++h)for(let m=e.minX();m<=e.maxX();++m){const p=e.get([m,h]);p!==void 0&&p.move([m*(o+d),h*(n+d)])}return t}}class qt{apply(t){var o;if(t.nodes.length===0)return t;const e=(((o=t.canvas)==null?void 0:o.gridSize)||0)*2;let r=t.nodes.filter(n=>!n.parent);const a=r[0];j(r,a);const l=[[a]];for(;r.length>0;){const n=l[l.length-1],d=[];for(const g of n){const h=g.getAdjacentNodes();for(const m of h)r.includes(m)&&(j(r,m),d.push(m))}d.length>0?l.push(d):(l.push(r),r=[])}let i=0;for(const n of l){let d=0;for(const h of n)h.move([i,d]),d+=e+h.height;const g=Math.max(...n.map(h=>h.width));i+=e+g}for(const n of t.connections)n.tighten();return t}}class Co{apply(t){var h;if(t.nodes.length===0)return t;new qt().apply(t);const e=(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,r=.99,a=1,l=.1,i=2e5,o=.5,n=1,d=.002;let g=100;for(;g>a;){g=g*r;const m=[0,0];{for(const p of t.nodes)m[0]=m[0]+p.coords[0]+p.width/2,m[1]=m[1]+p.coords[1]+p.width/2;m[0]=m[0]/t.nodes.length,m[1]=m[1]/t.nodes.length}for(const p of t.nodes){const u=p.getAdjacentNodes();for(const c of t.nodes){const f=[p.coords[0]+p.width/2,p.coords[1]+p.height/2],v=[c.coords[0]+c.width/2,c.coords[1]+c.height/2],w=Qe(p.coords,c.coords),b=[c.coords[0],c.coords[1]];if(u.includes(c)&&w>0&&(w>e+(Math.max(p.width,p.height)+Math.max(c.width,c.height))/2?(b[0]=b[0]-(v[0]-f[0])*l,b[1]=b[1]-(v[1]-f[1])*l):(b[0]=b[0]+(v[0]-f[0])*o,b[1]=b[1]+(v[1]-f[1])*o)),w>0){const $=i/(w*w);b[0]=b[0]+$*(v[0]-f[0])/w,b[1]=b[1]+$*(v[1]-f[1])/w}else b[0]=b[0]+n*(Math.random()*2-1),b[1]=b[1]+n*(Math.random()*2-1);b[0]=b[0]-(v[0]-m[0])*d,b[1]=b[1]-(v[1]-m[1])*d,b[0]-c.coords[0]>g?b[0]=c.coords[0]+g:b[0]-c.coords[0]<-g&&(b[0]=c.coords[0]-g),b[1]-c.coords[1]>g?b[1]=c.coords[1]+g:b[1]-c.coords[1]<-g&&(b[1]=c.coords[1]-g),c.move(b)}}}if(t.canvas&&t.canvas.snapToGrid)for(const m of t.nodes){const p=t.canvas.getClosestGridPoint(m.coords);m.move(p)}for(const m of t.connections)m.tighten();return t}}class ko{apply(t){var l;if(t.nodes.length===0)return t;const e=(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,r=t.nodes.filter(i=>!i.parent);r.sort((i,o)=>o.type.priority-i.type.priority);let a=0;for(const i of r)i.move([a,0]),a+=i.width+e;return t}}class xo{apply(t){var g;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(h=>h.getPriority())),r=Math.min(...t.nodes.map(h=>h.getPriority()));if(e===r)return new qt().apply(t),t;const a=(((g=t.canvas)==null?void 0:g.gridSize)||0)*2,l=t.nodes.filter(h=>!h.parent),i=[],o=t.nodes.filter(h=>!h.parent).filter(h=>h.getPriority()>=e),n=[];if(o.length>1){const h=o[0];o.splice(0,1),n.push(h);const m=[h],p=[h];for(;m.length>0;){const u=m[0];m.splice(0,1),o.includes(u)&&(n.push(u),j(o,u));const c=u.getAdjacentNodes();for(const f of c)p.includes(f)||(m.push(f),p.push(f))}for(const u of o)n.push(u)}else n.push(o[0]);for(const h of n)j(l,h),i.push([h]);for(i.push([]),l.sort((h,m)=>m.type.priority-h.type.priority);l.length>0;){const h=l[0];l.splice(0,1);const m=[h],p=[h];let u=!1;for(;m.length>0;){const c=m[0];m.splice(0,1);const f=n.indexOf(c);if(f>=0){i[f].push(h),u=!0;break}else{const v=c.getAdjacentNodes();for(const w of v)p.includes(w)||(m.push(w),p.push(w))}}u||i[i.length-1].push(h)}let d=0;for(let h=0;h<i.length;++h){let m=0;for(let u=0;u<i[h].length;++u){const c=i[h][u];c.move([d,m]),m+=a+c.height}const p=Math.max(...i[h].map(u=>u.width));d+=a+p}for(const h of t.connections)h.tighten();return t}}class Io{apply(t){var g;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(h=>h.getPriority())),r=Math.min(...t.nodes.map(h=>h.getPriority()));if(e===r)return new qt().apply(t),t;const a=(((g=t.canvas)==null?void 0:g.gridSize)||0)*2,l=t.nodes.filter(h=>!h.parent).sort((h,m)=>m.getPriority()-h.getPriority()),i=[];for(;l.length>0;){const h=l[0];l.splice(0,1);const m=new de(void 0,h);ui(m,l),i.push(m)}const o=[];for(const h of i)o.push([h]),fi(h,o,o.length);const n=Math.max(...t.nodes.map(h=>h.height));let d=0;for(let h=0;h<o.length;++h){let m=0;for(let u=0;u<o[h].length;++u){const c=o[h][u];c.node.move([d,m]),m+=(a+n)*c.countBranchHeight()}const p=Math.max(...o[h].map(u=>u.node.width));d+=a+p}for(const h of t.connections)h.tighten();return t}}const ui=(s,t)=>{for(const e of s.node.getAdjacentNodes().sort((r,a)=>a.getPriority()-r.getPriority())){const r=t.indexOf(e);if(r>=0){t.splice(r,1);const a=s.addBranch(e);ui(a,t)}}},fi=(s,t,e)=>{if(s.branches.length>0){for(;e>=t.length;)t.push([]);for(const r of s.branches)t[e].push(r),fi(r,t,e+1)}};class de{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new de(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 So{apply(t){var l;if(t.nodes.length===0)return t;const e=(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,r=t.nodes.filter(i=>!i.parent);r.sort((i,o)=>o.type.priority-i.type.priority);let a=0;for(const i of r)i.move([0,a]),a+=i.height+e;return t}}const Je={adjacency:new vo,breadth:new qt,"breadth-adjacency":new wo,force:new Co,horizontal:new ko,priority:new xo,tree:new Io,vertical:new So},Ao=R.createContext({}),bt=R.createContext({});class To{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){console.log("highlightProperty",t)}}const ce=({direction:s,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:r,disabled:a,rule:l,collapsedValue:i,visibleValue:o,onCollapse:n})=>{const[d,g]=R.useState(r),h=()=>{if(!a){const p=!d;g(p),n==null||n(p);let u;if(typeof t=="string")u=E.select(t),e&&(u=u.select(e));else{const c=t;if(!c)throw new Error("collapsableSelector is not a valid ref");u=E.select(c.current),e&&(u=u.select(e))}u.style(l,p?i:o)}},m=()=>{switch(s){case y.Right:return a?"daga-horizontal-none":d?"daga-horizontal-right":"daga-horizontal-left";case y.Bottom:return a?"daga-vertical-none":d?"daga-vertical-down":"daga-vertical-up";case y.Left:return a?"daga-horizontal-none":d?"daga-horizontal-left":"daga-horizontal-right";case y.Top:return a?"daga-vertical-none":d?"daga-vertical-up":"daga-vertical-down"}};return C.jsx("daga-collapse-button",{children:C.jsx("button",{className:`daga-collapse-button daga-${s}`,onClick:h,children:C.jsx("div",{className:m()})})})},$o=()=>{const s=R.useContext(bt),t=R.useRef(null),[e,r]=R.useState([]);yt.merge(s.validatorChange$,s.diagramChange$).pipe(yt.map(()=>a())).subscribe();const a=()=>{r([]);for(const i of s.validators){const o=i.validate(s.model);r(o)}},l=i=>{var o,n,d,g;if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const h=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);h&&s.userHighlight.add(h)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){s.userSelection.openInPropertyEditor(s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId));const h=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);h&&s.userHighlight.add(h),(n=(o=s.parentComponent)==null?void 0:o.propertyEditor)==null||n.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(s.userSelection.openInPropertyEditor(),(g=(d=s.parentComponent)==null?void 0:d.propertyEditor)==null||g.highlightProperty(...i.propertyNames))};return C.jsx("daga-errors",{children:C.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&C.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:C.jsx("span",{children:"No errors found"})}),e.length>0&&C.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[C.jsxs("span",{children:[e.length," errors found"]}),C.jsx("div",{className:"daga-collapse-button-container",children:C.jsx(ce,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:y.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&C.jsx("div",{className:"daga-error-panel",children:C.jsx("ol",{children:e.map((i,o)=>C.jsx("li",{onClick:()=>l(i),dangerouslySetInnerHTML:{__html:i.message}},o))})})]})})},Eo=({valueSet:s,onValueChange:t})=>{var o;const r=R.useContext(bt).canUserPerformAction(k.UpdateValues)&&((o=s==null?void 0:s.rootElement)==null?void 0:o.removed)!==!0,a=n=>"daga-property-name-"+n.replace(/\s/g,""),l=n=>{if(typeof n=="string")return n;if(n==null||isNaN(n.valueOf()))return"";const d=new Date(n),g=d.getTimezoneOffset();return d.setMinutes(d.getMinutes()-g),d.toISOString().substring(0,19)},i=n=>new Date(n);return C.jsx("daga-object-editor",{children:s.displayedProperties.map(n=>C.jsxs("div",{className:`daga-property ${a(n.name)}`,children:[C.jsx("p",{className:"daga-property-name",children:n.name}),n.type===tt.Text&&C.jsx("input",{type:"daga-text",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.TextArea&&C.jsx("textarea",{disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Number&&C.jsx("input",{type:"number",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Color&&C.jsx("input",{type:"text",pattern:"#\\d{6}",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Datetime&&C.jsx("input",{type:"datetime-local",disabled:!n.editable||!r,value:l(s==null?void 0:s.getValue(n.name)),onChange:d=>t(n,i(d.target.value))}),n.type===tt.Date&&C.jsx("input",{type:"date",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Time&&C.jsx("input",{type:"time",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Url&&C.jsx("input",{type:"url",disabled:!n.editable||!r,value:s==null?void 0:s.getValue(n.name),onChange:d=>t(n,d.target.value)}),n.type===tt.Boolean&&C.jsxs("div",{className:"daga-radio",children:[C.jsxs("label",{className:"daga-radio-item daga-radio-start",children:[C.jsx("input",{type:"radio",disabled:!n.editable||!r,name:n.name,value:"false",checked:(s==null?void 0:s.getValue(n.name))===!1,onChange:()=>t(n,!1)}),"No"]}),C.jsxs("label",{className:"daga-radio-item daga-radio-end",children:[C.jsx("input",{type:"radio",disabled:!n.editable||!r,name:n.name,value:"true",checked:(s==null?void 0:s.getValue(n.name))===!0,onChange:()=>t(n,!0)}),"Yes"]})]})]},n.name))})},mi=({valueSet:s,depth:t})=>{const e=R.useContext(bt),r=R.useRef(null),a=d=>"daga-property-name-"+d.replace(/\s/g,""),l=()=>{for(const d of(s==null?void 0:s.displayedProperties)||[]){let g=0,h=0,m=0;const p=E.select(r.current).select(`.daga-property.${a(d.name)}.daga-depth-${t}`);p.select("button.daga-move-button").call(E.drag().on(A.Start,u=>{var v;x(M.Grabbing);const c=e.getPointerLocationRelativeToScreen(u);if(c.length<2||isNaN(c[0])||isNaN(c[1]))return;const f=(v=p.node())==null?void 0:v.getBoundingClientRect();g=(f==null?void 0:f.width)||0,h=(f==null?void 0:f.height)||0,p.style("position","fixed").style("left",`${c[0]-g/2}px`).style("top",`${c[1]-h/2}px`).style("width",`${g}px`).style("height",`${h}px`).style("z-index",1)}).on(A.Drag,u=>{x(M.Grabbing);const c=e.getPointerLocationRelativeToScreen(u);c.length<2||isNaN(c[0])||isNaN(c[1])||(p.style("position","fixed").style("left",`${c[0]-g/2}px`).style("top",`${c[1]-h/2}px`).style("width",`${g}px`).style("height",`${h}px`).style("z-index",1),E.select(r.current).select(`.daga-dropbar.daga-index-${m}.daga-depth-${t}`).style("visibility","hidden").style("height",0),m=i(c),E.select(r.current).select(`.daga-dropbar.daga-index-${m}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on(A.End,u=>{var f,v;x(M.Auto),p.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),E.select(r.current).select(`.daga-dropbar.daga-index-${m}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const c=e.getPointerLocationRelativeToScreen(u);c.length<2||isNaN(c[0])||isNaN(c[1])||(m=i(c),(f=s==null?void 0:s.displayedProperties)==null||f.splice(s.displayedProperties.indexOf(d),1),(v=s==null?void 0:s.displayedProperties)==null||v.splice(m,0,d))}))}},i=d=>{var m;const g=(s==null?void 0:s.propertySet.propertyList)||[],h=[];for(let p=0;p<=g.length;++p){const u=(m=E.select(r.current).select(`.daga-dropbar.daga-index-${p}.daga-depth-${t}`).node())==null?void 0:m.getBoundingClientRect();u&&h.push([u.x+u.width/2,u.y+u.height/2])}if(h.length>0){const p=h.map(c=>((d[0]-c[0])**2+(d[1]-c[1])**2)**.5);return p.indexOf(Math.min(...p))}return 0},o=d=>{var h;if(s===void 0)return;let g;d instanceof zi?g=d:d instanceof Event?g=s==null?void 0:s.propertySet.getProperty(((h=d.target)==null?void 0:h.value)||""):g=s==null?void 0:s.propertySet.getProperty(d||""),g&&(s==null||s.hideProperty(g)),l()},n=d=>Array.isArray(d)?d.join(", "):ne(d)?Object.entries(d).map(g=>g.map(h=>JSON.stringify(h)).join(": ")).join(", "):d instanceof Date?d.toLocaleString():d==null?"":""+d;return C.jsxs("daga-property-settings",{ref:r,children:[C.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),s==null?void 0:s.displayedProperties.map((d,g)=>C.jsxs("div",{className:`daga-property-and-dropbar ${a(d.name)} daga-depth-${t}`,children:[C.jsxs("div",{className:`daga-property ${a(d.name)} daga-depth-${t}`,children:[C.jsxs("div",{className:"daga-property-name",children:[C.jsx("span",{children:d.name}),C.jsxs("div",{className:"daga-buttons",children:[C.jsx("button",{className:"daga-property-button daga-move-button",children:C.jsx("div",{className:"daga-icon daga-move-icon"})}),C.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>o(d.name),children:C.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),d.type!==tt.Object&&C.jsx("div",{className:"daga-property-value",children:n(s==null?void 0:s.getValue(d.name))}),d.type===tt.Object&&C.jsx(mi,{valueSet:s==null?void 0:s.getSubValueSet(d.name),depth:t+1})]}),C.jsx("div",{className:`daga-dropbar daga-index-${g+1} daga-depth-${t}`})]},d.name))]})},Mo=({location:s,direction:t,width:e,title:r,valueSet:a,onValueChange:l})=>{const i=R.useRef(null),[o,n]=R.useState(!1),[d,g]=R.useState(!1),h=()=>E.select(i.current);return R.useEffect(()=>{if(i.current)switch(t){case y.Bottom:case y.Top:h().style("width",e);break;case y.Left:case y.Right:h().style("height",e);break}},[e,t]),C.jsx("daga-property-editor",{children:C.jsxs("div",{ref:i,className:`daga-panel daga-bottom daga-${s} daga-${t}`,children:[C.jsx(ce,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:o,direction:t,collapsableSelector:i,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:n}),a&&a.propertySet&&a.propertySet.hasProperties()&&!o&&C.jsxs("div",{className:"daga-panel-content",children:[r&&C.jsxs("p",{className:"daga-title",children:[r,C.jsx("button",{className:"daga-property-button",onClick:()=>g(!d),children:C.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&C.jsx(Eo,{valueSet:a,onValueChange:l}),d&&C.jsx(mi,{valueSet:a,depth:0})]})]})})},Po=s=>{const t=R.useContext(bt),[e,r]=R.useState(s.currentPalette||s.palettes[0]),[a,l]=R.useState(0),[i,o]=R.useState(void 0),n=R.useRef(null),d=c=>{if(r(c),g().selectAll("*").remove(),l(t.getPriorityThreshold()||0),c.categories&&h(c.categories),c.templates)for(const f of c.templates)m(f)},g=()=>E.select(n.current).select(".daga-palette-view"),h=c=>{const f=g().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");f.append("option").attr("value","").text("(None selected)");for(const v in c)f.append("option").attr("value",v).text(v);f.on(S.Change,()=>{i&&g().selectAll(".daga-template-container.daga-in-category").remove();const v=f.property("value");o(v);const w=c[v]||[];for(const b of w)m(b,"daga-in-category")}),i&&(f.property("value",i),f.dispatch(S.Change))},m=(c,f)=>{if(c.templateType==="node"){const v=t.model.nodes.types.get(c.type);v?p(v,c,f):console.error(`Could not find a node type called '${c.type}'`)}else if(c.templateType==="connection"){const v=t.model.connections.types.get(c.type);v?u(v,c,f):console.error(`Could not find a connection type called '${c.type}'`)}},p=(c,f,v)=>{if(a!==void 0&&c.priority<a)return;const w=g().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${c.defaultWidth}px`).style("height",`${c.defaultHeight}px`).call(E.drag().on(A.Drag,b=>{if(t.canUserPerformAction(k.AddNode)){const $=t.getPointerLocationRelativeToScreen(b);if($.length<2||isNaN($[0])||isNaN($[1]))return;w.style("position","fixed").style("left",`${$[0]-c.defaultWidth/2}px`).style("top",`${$[1]-c.defaultHeight/2}px`).style("z-index",1)}}).on(A.Start,b=>{if(t.canUserPerformAction(k.AddNode)){x(M.Grabbing);const $=t.getPointerLocationRelativeToScreen(b);if($.length<2||isNaN($[0])||isNaN($[1]))return;w.style("position","fixed").style("left",`${$[0]-c.defaultWidth/2}px`).style("top",`${$[1]-c.defaultHeight/2}px`).style("z-index",1),c.isUnique&&t.model.nodes.find(I=>!I.removed&&I.type.id===c.id)!==void 0&&x(M.NotAllowed)}}).on(A.End,b=>{var $;if(t.canUserPerformAction(k.AddNode)){if(x(M.Auto),w.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),c.isUnique&&t.model.nodes.find(D=>!D.removed&&D.type.id===c.id)!==void 0)return;const I=t.getPointerLocationRelativeToScreen(b);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;const T=document.elementFromPoint(I[0],I[1]);if(T&&!(($=t.selectCanvasView().node())!=null&&$.contains(T)))return;const N=t.getPointerLocationRelativeToCanvas(b);if(N.length<2||isNaN(N[0])||isNaN(N[1]))return;let P=[N[0]-c.defaultWidth/2,N[1]-c.defaultHeight/2];t.snapToGrid&&(P=t.getClosestGridPoint(P));const Z=t.model.nodes.getAtCoordinates(N[0],N[1]).filter(D=>D.type.childrenTypes.includes(c.id)),G=ri(Z),U=G[G.length-1];if(!c.canBeParentless&&U===void 0)return;const H=U==null?void 0:U.getLastAncestor(),q=new Qi(t,c,P,U==null?void 0:U.id,H==null?void 0:H.id,H==null?void 0:H.getGeometry(),void 0,f.label,f.values);q.do(),t==null||t.actionStack.add(q),x()}})).append("svg").attr("class",`palette-node ${c.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%");switch(c.look.lookType){case"shaped-look":w.append("path").attr("d",Gt(c.look.shape,0,0,c.defaultWidth,c.defaultHeight)).attr("fill",c.look.fillColor).attr("stroke",c.look.borderColor).attr("stroke-width","1px");break;case"image-look":w.append("image").attr("x",0).attr("y",0).attr("width",c.defaultWidth).attr("height",c.defaultHeight).attr("href",c.look.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":w.append("image").attr("x",0).attr("y",0).attr("width",c.look.leftMargin).attr("height",c.look.topMargin).attr("href",c.look.backgroundImageTopLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.look.leftMargin).attr("y",0).attr("width",c.defaultWidth-c.look.rightMargin-c.look.leftMargin).attr("height",c.look.topMargin).attr("href",c.look.backgroundImageTop).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.defaultWidth-c.look.rightMargin).attr("y",0).attr("width",c.look.rightMargin).attr("height",c.look.topMargin).attr("href",c.look.backgroundImageTopRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",c.look.topMargin).attr("width",c.look.leftMargin).attr("height",c.defaultHeight-c.look.bottomMargin-c.look.topMargin).attr("href",c.look.backgroundImageLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.look.leftMargin).attr("y",c.look.topMargin).attr("width",c.defaultWidth-c.look.rightMargin-c.look.leftMargin).attr("height",c.defaultHeight-c.look.bottomMargin-c.look.topMargin).attr("href",c.look.backgroundImageCenter).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.defaultWidth-c.look.rightMargin).attr("y",c.look.topMargin).attr("width",c.look.rightMargin).attr("height",c.defaultHeight-c.look.bottomMargin-c.look.topMargin).attr("href",c.look.backgroundImageRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",c.defaultHeight-c.look.bottomMargin).attr("width",c.look.leftMargin).attr("height",c.look.bottomMargin).attr("href",c.look.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.look.leftMargin).attr("y",c.defaultHeight-c.look.bottomMargin).attr("width",c.defaultWidth-c.look.rightMargin-c.look.leftMargin).attr("height",c.look.bottomMargin).attr("href",c.look.backgroundImageBottom).attr("preserveAspectRatio","none"),w.append("image").attr("x",c.defaultWidth-c.look.rightMargin).attr("y",c.defaultHeight-c.look.bottomMargin).attr("width",c.look.rightMargin).attr("height",c.look.bottomMargin).attr("href",c.look.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(f.label){const b={...z,...c.label,...f.labelLook};w.append("text").attr("transform",`translate(${(X(b)+c.defaultWidth)/2},${(F(b)+c.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${b.fontSize}px`).attr("text-anchor","middle").attr("font-family",b.fontFamily).attr("font-weight",400).attr("fill",b.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(f.label)}},u=(c,f,v)=>{const w=g().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${f.width}px`).style("height",`${f.height}px`).append("svg").attr("class",`palette-button ${c.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=c});w.append("path").attr("d",Gt(Ht.Rectangle,0,0,f.width,f.height)).attr("fill",f.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),f.icon!==""&&w.append("image").attr("x",0).attr("y",0).attr("width",f.width).attr("height",f.height).attr("href",f.icon),f.label!==""&&w.append("text").attr("transform",`translate(${f.width/2},${f.height/2+5})`).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(f.label)};return R.useEffect(()=>{if(r(e||s.palettes[0]),d(e),n.current)switch(s.direction){case y.Bottom:case y.Top:n.current.style.width=s.width;break;case y.Left:case y.Right:n.current.style.height=s.width;break}},[e,s.palettes]),C.jsx("daga-palette",{children:C.jsxs("div",{ref:n,className:`daga-panel daga-${s.location} daga-${s.direction}`,children:[C.jsx(ce,{direction:s.direction,collapsableSelector:n,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),C.jsxs("div",{className:"daga-panel-content",children:[s.palettes.length>1&&C.jsx("div",{className:"daga-panel-tabs",children:s.palettes.map(c=>C.jsx("div",{className:`daga-panel-tab ${c===e?"daga-current-tab":""}`,onClick:()=>d(c),children:c.name}))}),C.jsx("div",{className:"daga-palette-view"})]})]})})},No=({location:s,direction:t,enableAction:e,enableFilter:r,enableLayout:a,enableSelection:l,enableZoom:i})=>{let o=!1,n=!0,d=!1,g,h,m,p;switch(t){case y.Bottom:g="height",h="scaleY",m="top",p="bottom";break;case y.Top:g="height",h="scaleY",m="bottom",p="top";break;case y.Left:g="width",h="scaleX",m="right",p="left";break;case y.Right:g="width",h="scaleX",m="left",p="right";break}const u=R.useRef(null),c=R.useRef(null),f=R.useRef(null);R.useEffect(()=>{E.select(u.current).style(`margin-${p}`,"-1rem").style(g,"0rem").style("transform",`${h}(0)`).style("transform-origin",m)});const v=async()=>{const D=E.select(u.current);if(!d)if(n){n=!1;const Lt=`${4*D.selectChildren().size()}rem`;D.transition().duration(500).ease(E.easeLinear).style(g,Lt).style("transform",`${h}(1)`),setTimeout(()=>{d=!1},500)}else n=!0,D.transition().duration(500).ease(E.easeLinear).style(g,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{d=!1},500)},w=R.useContext(bt),b=()=>{w.zoomBy(w.zoomFactor)},$=()=>{w.zoomBy(1/w.zoomFactor)},I=()=>{w.center()},T=()=>{w.layoutFormat&&w.layoutFormat in Je&&Je[w.layoutFormat].apply(w.model)},N=()=>{o=!o,E.select(f.current).classed("daga-on",o).classed("daga-off",!o);const D=w.getPriorityThresholdOptions();D&&D.length>=2&&w.setPriorityThreshold(D[o?1:0])},P=()=>{w.actionStack.undo()},W=()=>{w.actionStack.redo()},Z=()=>{w.userSelection.copyToClipboard()},G=()=>{w.userSelection.cutToClipboard()},U=()=>{w.userSelection.pasteFromClipboard()},H=()=>{w.userSelection.removeFromModel()},q=()=>{w.multipleSelectionOn=!0,E.select(c.current).classed("daga-on",!0).classed("daga-off",!1)};return C.jsx("daga-diagram-buttons",{children:C.jsxs("div",{className:`daga-diagram-buttons daga-${s} daga-${t}`,children:[i&&w.canUserPerformAction(k.Zoom)&&C.jsx("button",{className:"daga-zoom-in",onClick:b,children:C.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&w.canUserPerformAction(k.Zoom)&&C.jsx("button",{className:"daga-zoom-out",onClick:$,children:C.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),C.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:u,children:[i&&w.canUserPerformAction(k.Zoom)&&C.jsx("button",{className:"daga-center",onClick:I,children:C.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&C.jsx("button",{className:"daga-undo",onClick:P,children:C.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&C.jsx("button",{className:"daga-redo",onClick:W,children:C.jsx("span",{className:"daga-tooltip",children:"Redo"})}),l&&C.jsx("button",{className:"daga-copy",onClick:Z,children:C.jsx("span",{className:"daga-tooltip",children:"Copy"})}),l&&C.jsx("button",{className:"daga-cut",onClick:G,children:C.jsx("span",{className:"daga-tooltip",children:"Cut"})}),l&&C.jsx("button",{className:`daga-multiple-selection ${o?"daga-on":"daga-off"}`,onClick:q,ref:c,children:C.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),l&&C.jsx("button",{className:"daga-paste",onClick:U,children:C.jsx("span",{className:"daga-tooltip",children:"Paste"})}),l&&C.jsx("button",{className:"daga-delete",onClick:H,children:C.jsx("span",{className:"daga-tooltip",children:"Delete"})}),a&&w.layoutFormat&&C.jsx("button",{className:"daga-layout",onClick:T,children:C.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),r&&C.jsx("button",{className:`daga-filter ${o?"daga-on":"daga-off"}`,onClick:N,ref:f,children:C.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),C.jsx("button",{className:"daga-more-options",onClick:v,children:n?C.jsx("span",{className:"daga-tooltip",children:"More options"}):C.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Ro=({config:s,model:t,onCanvasCreated:e,onDiagramEvent:r,onModelChange:a})=>{var $,I,T,N,P,W,Z,G,U,H,q,D,rt,Jt,Lt,he,ge,ue,fe,me,pe,ye,be,ve,we,Ce,ke,xe,Ie,Se,Ae,Te,$e,Ee,Me,Pe,Ne,Re,ze,Le,Ve,De,Oe,je,Be;const l=new li,i=new ci,o=R.useRef(null),n=R.useRef(!1),[d,g]=R.useState(void 0),[h,m]=R.useState(void 0),p={zoomIn:()=>{console.log("zoomIn")},zoomOut:()=>{console.log("zoomOut")},center:()=>{console.log("center")},layout:()=>{console.log("layout")},filter:()=>{console.log("filter")},undo:()=>{console.log("undo")},redo:()=>{console.log("redo")}},u={refreshPalette:()=>{console.log("refreshPalette")}},c=new To(it=>g(it),it=>m(it)),f={diagramButtons:p,palette:u,propertyEditor:c},v=new ae(f,s);R.useEffect(()=>{t&&l.import(v.model,t)},[t]),v.diagramChange$.subscribe(()=>{const it=i.export(v.model);a==null||a(it)});const w=it=>{v.initView(it),v.diagramEvent$.subscribe(Vt=>{r==null||r(Vt)})};R.useEffect(()=>{o.current&&(n.current||(w(o.current),n.current=!0,e==null||e(v)))},[o.current]);const b=(it,Vt)=>{var Fe;if(h!==void 0&&it.editable&&!Pt(h.getValue(it.name),Vt)){const Dt=new At(h.propertySet,h.rootElement);Dt.setValues(h.values),Dt.setValue(it.name,Vt),c.valueSet=Dt,h.rootElement.valueSet=Dt,(Fe=v.propertyEditorChanges$)==null||Fe.next()}};return C.jsx("daga-diagram",{children:C.jsx(Ao.Provider,{value:s,children:C.jsx(bt.Provider,{value:v,children:C.jsxs("daga-diagram-editor",{children:[C.jsx("div",{className:"daga-append-to",ref:o}),C.jsxs(bt.Provider,{value:v,children:[(($=s.components)==null?void 0:$.buttons)!==void 0&&((T=(I=s.components)==null?void 0:I.buttons)==null?void 0:T.enabled)!==!1&&C.jsx(No,{location:((P=(N=s.components)==null?void 0:N.buttons)==null?void 0:P.location)||Ot.BottomRight,direction:((Z=(W=s.components)==null?void 0:W.buttons)==null?void 0:Z.direction)||y.Top,enableAction:((U=(G=s.components)==null?void 0:G.buttons)==null?void 0:U.enableAction)===!0,enableFilter:((q=(H=s.components)==null?void 0:H.buttons)==null?void 0:q.enableFilter)===!0,enableLayout:((rt=(D=s.components)==null?void 0:D.buttons)==null?void 0:rt.enableLayout)===!0,enableSelection:((Lt=(Jt=s.components)==null?void 0:Jt.buttons)==null?void 0:Lt.enableSelection)===!0,enableZoom:((ge=(he=s.components)==null?void 0:he.buttons)==null?void 0:ge.enableZoom)!==!1}),((ue=s.components)==null?void 0:ue.palette)!==void 0&&((me=(fe=s.components)==null?void 0:fe.palette)==null?void 0:me.enabled)!==!1&&((ye=(pe=s.components)==null?void 0:pe.palette)==null?void 0:ye.sections)&&(((we=(ve=(be=s.components)==null?void 0:be.palette)==null?void 0:ve.sections)==null?void 0:we.length)||0)>0&&C.jsx(Po,{location:((ke=(Ce=s.components)==null?void 0:Ce.palette)==null?void 0:ke.location)||Ot.TopLeft,direction:((Ie=(xe=s.components)==null?void 0:xe.palette)==null?void 0:Ie.direction)||y.Bottom,width:((Ae=(Se=s.components)==null?void 0:Se.palette)==null?void 0:Ae.width)||"12rem",palettes:(($e=(Te=s.components)==null?void 0:Te.palette)==null?void 0:$e.sections)||[]}),((Ee=s.components)==null?void 0:Ee.propertyEditor)!==void 0&&((Pe=(Me=s.components)==null?void 0:Me.propertyEditor)==null?void 0:Pe.enabled)!==!1&&C.jsx(Mo,{location:((Re=(Ne=s.components)==null?void 0:Ne.propertyEditor)==null?void 0:Re.location)||Ot.TopRight,direction:((Le=(ze=s.components)==null?void 0:ze.propertyEditor)==null?void 0:Le.direction)||y.Bottom,width:((De=(Ve=s.components)==null?void 0:Ve.propertyEditor)==null?void 0:De.width)||"24rem",title:d,valueSet:h,onValueChange:b}),((Oe=s.components)==null?void 0:Oe.errors)!==void 0&&((Be=(je=s.components)==null?void 0:je.errors)==null?void 0:Be.enabled)!==!1&&C.jsx($o,{})]})]})})})})};exports.DagaDiagram=Ro;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),Li=require("d3"),we=require("rxjs"),$=require("react");function Ei(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const T=Ei(Li);var k=(i=>(i.Bottom="bottom",i.Left="left",i.Right="right",i.Top="top",i))(k||{}),He=(i=>(i.BottomLeft="bottom-left",i.BottomRight="bottom-right",i.TopLeft="top-left",i.TopRight="top-right",i))(He||{}),Ee=(i=>(i.Left="left",i.Center="center",i.Right="right",i))(Ee||{}),Fe=(i=>(i.Top="top",i.Center="center",i.Bottom="bottom",i))(Fe||{});const Ie=i=>[Math.round(i[0]),Math.round(i[1])],ge=(i,e,t)=>e<t?e<=i&&i<=t:t<=i&&i<=e,Wt=(i,e,t)=>(i-e[0])/(e[1]-e[0])*(t[1]-t[0])+t[0],Be=(i,e,t,o,a)=>[Wt(i[0],e,o),Wt(i[1],t,a)],ni=(i,e)=>((i[0]-e[0])**2+(i[1]-e[1])**2)**.5,Ti=(i,e)=>(ge(i[0][0],e[0][0],e[1][0])||ge(i[1][0],e[1][0],e[0][0])||ge(e[0][0],i[0][0],i[1][0])||ge(e[1][0],i[1][0],i[0][0]))&&(ge(i[0][1],e[0][1],e[1][1])||ge(i[1][1],e[1][1],e[0][1])||ge(e[0][1],i[0][1],i[1][1])||ge(e[1][1],i[1][1],i[0][1]));var I=(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))(I||{}),ee=(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))(ee||{}),E=(i=>(i.Drag="drag",i.Start="start",i.End="end",i))(E||{}),at=(i=>(i.Zoom="zoom",i.Start="start",i.End="end",i))(at||{}),ri=(i=>(i.Straight="straight",i.Bezier="bezier",i.Square="square",i))(ri||{}),ai=(i=>(i.Solid="solid",i.Dashed="dashed",i.GappedDashes="gapped-dashes",i.Dotted="dotted",i))(ai||{});const $i=20,Mi=(i,e,t,o,a)=>{if(typeof i=="function")return i(e,t,o,a);if(e.length===0)return"";if(e.length===1)return`M ${e[0][0]} ${e[0][1]}`;{a=a||$i;let l="",s,n;switch(i){case"straight":l+=`M ${e[0][0]} ${e[0][1]}`;for(let r=1;r<e.length;++r)l+=` L ${e[r][0]} ${e[r][1]}`;break;case"bezier":s=t,l+=`M ${e[0][0]} ${e[0][1]}`;for(let r=1;r<e.length;++r){if(r+1>=e.length?n=o:Math.abs(e[r][0]-e[r-1][0])<Math.abs(e[r][1]-e[r-1][1])?e[r][1]>e[r-1][1]?n=k.Bottom:n=k.Top:e[r][0]>e[r-1][0]?n=k.Right:n=k.Left,s!==void 0){let d="",c="";const h=(Math.abs(e[r][0]-e[r-1][0])+Math.abs(e[r][1]-e[r-1][1]))/2;switch(s){case k.Bottom:d=`${e[r-1][0]} ${e[r-1][1]+h}`;break;case k.Top:d=`${e[r-1][0]} ${e[r-1][1]-h}`;break;case k.Right:d=`${e[r-1][0]+h} ${e[r-1][1]}`;break;case k.Left:d=`${e[r-1][0]-h} ${e[r-1][1]}`;break}if(n!==void 0){switch(n){case k.Bottom:c=`${e[r][0]} ${e[r][1]+h}`;break;case k.Top:c=`${e[r][0]} ${e[r][1]-h}`;break;case k.Right:c=`${e[r][0]+h} ${e[r][1]}`;break;case k.Left:c=`${e[r][0]-h} ${e[r][1]}`;break}l+=` C ${d} ${c} ${e[r][0]} ${e[r][1]}`}else l+=` Q ${d} ${e[r][0]} ${e[r][1]}`}else if(n!==void 0){let d="";const c=(Math.abs(e[r][0]-e[r-1][0])+Math.abs(e[r][1]-e[r-1][1]))/2;switch(n){case k.Bottom:d=`${e[r][0]} ${e[r][1]+c}`;break;case k.Top:d=`${e[r][0]} ${e[r][1]-c}`;break;case k.Right:d=`${e[r][0]+c} ${e[r][1]}`;break;case k.Left:d=`${e[r][0]-c} ${e[r][1]}`;break}l+=` Q ${d} ${e[r][0]} ${e[r][1]}`}else l+=` L ${e[r][0]} ${e[r][1]}`;s=n}break;case"square":if(l+=`M ${e[0][0]} ${e[0][1]}`,t)switch(t){case k.Bottom:e.splice(1,0,[e[0][0],e[0][1]+a]);break;case k.Top:e.splice(1,0,[e[0][0],e[0][1]-a]);break;case k.Right:e.splice(1,0,[e[0][0]+a,e[0][1]]);break;case k.Left:e.splice(1,0,[e[0][0]-a,e[0][1]]);break}if(o)switch(o){case k.Bottom:e.splice(e.length-1,0,[e[e.length-1][0],e[e.length-1][1]+a]);break;case k.Top:e.splice(e.length-1,0,[e[e.length-1][0],e[e.length-1][1]-a]);break;case k.Right:e.splice(e.length-1,0,[e[e.length-1][0]+a,e[e.length-1][1]]);break;case k.Left:e.splice(e.length-1,0,[e[e.length-1][0]-a,e[e.length-1][1]]);break}for(let r=1;r<e.length;++r)if(s!==void 0)switch(s){case k.Bottom:e[r][1]<e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`,s=k.Top):e[r][1]<e[r-1][1]&&e[r][0]===e[r-1][0]?(l+=` H ${e[r][0]+a}`,l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`,s=k.Left):e[r][1]===e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,s=e[r][0]>e[r-1][0]?k.Right:k.Left):e[r][1]>e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`):e[r][1]>e[r-1][1]&&e[r][0]===e[r-1][0]&&(l+=` V ${e[r][1]}`);break;case k.Top:e[r][1]>e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`,s=k.Bottom):e[r][1]>e[r-1][1]&&e[r][0]===e[r-1][0]?(l+=` H ${e[r][0]-a}`,l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`,s=k.Right):e[r][1]===e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,s=e[r][0]>e[r-1][0]?k.Right:k.Left):e[r][1]<e[r-1][1]&&e[r][0]!==e[r-1][0]?(l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`):e[r][1]<e[r-1][1]&&e[r][0]===e[r-1][0]&&(l+=` V ${e[r][1]}`);break;case k.Right:e[r][0]<e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`,s=k.Left):e[r][0]<e[r-1][0]&&e[r][1]===e[r-1][1]?(l+=` V ${e[r][1]+a}`,l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`,s=k.Top):e[r][0]===e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,s=e[r][1]>e[r-1][1]?k.Bottom:k.Top):e[r][0]>e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`):e[r][0]>e[r-1][0]&&e[r][1]===e[r-1][1]&&(l+=` H ${e[r][0]}`);break;case k.Left:e[r][0]>e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`,s=k.Right):e[r][0]>e[r-1][0]&&e[r][1]===e[r-1][1]?(l+=` V ${e[r][1]-a}`,l+=` H ${e[r][0]}`,l+=` V ${e[r][1]}`,s=k.Bottom):e[r][0]===e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,s=e[r][1]>e[r-1][1]?k.Bottom:k.Top):e[r][0]<e[r-1][0]&&e[r][1]!==e[r-1][1]?(l+=` V ${e[r][1]}`,l+=` H ${e[r][0]}`):e[r][0]<e[r-1][0]&&e[r][1]===e[r-1][1]&&(l+=` H ${e[r][0]}`);break}else e[r][0]!==e[r-1][0]&&(l+=` H ${e[r][0]}`,s=e[r][0]>e[r-1][0]?k.Right:k.Left),e[r][1]!==e[r-1][1]&&(l+=` V ${e[r][1]}`,s=e[r][1]>e[r-1][1]?k.Bottom:k.Top);break}return l}},Zt=(i,e)=>{switch(i){case"dotted":return`${e}`;case"dashed":return`${4*e} ${e}`;case"gapped-dashes":return`${4*e} ${4*e}`;case"solid":default:return"none"}},B=(i,e)=>{const t=i.indexOf(e);return t>=0&&i.splice(t,1),i};var Ye=(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))(Ye||{});const lt=(i,e,t,o,a)=>{if(typeof i=="function")return i(e,t,o,a);switch(i){case"ellipse":return li(e,t,o,a);case"empty":return Ni();case"folder":return Pi(e,t,o,a);case"hexagon":return zi(e,t,o,a);case"octagon":return Ri(e,t,o,a);case"pill":return Ge(e,t,o,a);case"rectangle":return Kt(e,t,o,a);case"rhombus":return Vi(e,t,o,a);case"rounded-rectangle":return ji(e,t,o,a);case"sticky-note":return _i(e,t,o,a);default:return Kt(e,t,o,a)}},li=(i,e,t,o)=>`M ${i+t/2} ${e} A ${t/2} ${o/2} 0 0 0 ${i+t/2} ${e+o} A ${t/2} ${o/2} 0 1 0 ${i+t/2} ${e} Z`,Ni=()=>"Z",Pi=(i,e,t,o)=>`M ${i} ${e} L ${i+t/3} ${e} L ${i+t/2} ${e+o/6} L ${i+t} ${e+o/6} L ${i+t} ${e+o} L ${i} ${e+o} Z`,zi=(i,e,t,o)=>`M ${i+t/4} ${e} L ${i+3*t/4} ${e} L ${i+t} ${e+o/2} L ${i+3*t/4} ${e+o} L ${i+t/4} ${e+o} L ${i} ${e+o/2} Z`,Ri=(i,e,t,o)=>`M ${i+t/4} ${e} L ${i+3*t/4} ${e} L ${i+t} ${e+o/4} L ${i+t} ${e+3*o/4} L ${i+3*t/4} ${e+o} L ${i+t/4} ${e+o} L ${i} ${e+3*o/4} L ${i} ${e+o/4} L ${i+t/4} ${e} Z`,Ge=(i,e,t,o)=>o<t?`M ${i+o/2} ${e} L ${i+t-o/2} ${e} A ${o/2} ${o/2} 0 0 1 ${i+t} ${e+o/2} A ${o/2} ${o/2} 0 0 1 ${i+t-o/2} ${e+o} L ${i+o/2} ${e+o} A ${o/2} ${o/2} 0 0 1 ${i} ${e+o/2} A ${o/2} ${o/2} 0 0 1 ${i+o/2} ${e} Z`:o>t?`M ${i} ${e+t/2} L ${i} ${e+o-t/2} A ${t/2} ${t/2} 0 0 0 ${i+t/2} ${e+o} A ${t/2} ${t/2} 0 0 0 ${i+t} ${e+o-t/2} L ${i+t} ${e+t/2} A ${t/2} ${t/2} 0 0 0 ${i+t/2} ${e} A ${t/2} ${t/2} 0 0 0 ${i} ${e+t/2} Z`:li(i,e,t,o),Kt=(i,e,t,o)=>`M ${i} ${e} L ${i+t} ${e} L ${i+t} ${e+o} L ${i} ${e+o} Z`,Vi=(i,e,t,o)=>`M ${i+t/2} ${e} L ${i+t} ${e+o/2} L ${i+t/2} ${e+o} L ${i} ${e+o/2} Z`,ji=(i,e,t,o)=>`M ${i+t/4} ${e} L ${i+3*t/4} ${e} A ${t/4} ${o/4} 0 0 1 ${i+t} ${e+o/4} L ${i+t} ${e+3*o/4} A ${t/4} ${o/4} 0 0 1 ${i+3*t/4} ${e+o} L ${i+t/4} ${e+o} A ${t/4} ${o/4} 0 0 1 ${i} ${e+3*o/4} L ${i} ${e+o/4} A ${t/4} ${o/4} 0 0 1 ${i+t/4} ${e} Z`,_i=(i,e,t,o)=>`M ${i} ${e} L ${i+3*t/4} ${e} L ${i+3*t/4} ${e+o/4} L ${i+3*t/4} ${e} L ${i+t} ${e+o/4} L ${i+3*t/4} ${e+o/4} L ${i+t} ${e+o/4} L ${i+t} ${e+o} L ${i} ${e+o} Z`;var M=(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))(M||{});const Oi=i=>Math.max(...i.split(`
|
|
2
|
+
`).map(e=>e.length)),Di=i=>{var e;return((e=i.match(/\n/g))==null?void 0:e.length)||0},K=[];for(let i=0;i<256;++i)K.push((i+256).toString(16).slice(1));function Hi(i,e=0){return(K[i[e+0]]+K[i[e+1]]+K[i[e+2]]+K[i[e+3]]+"-"+K[i[e+4]]+K[i[e+5]]+"-"+K[i[e+6]]+K[i[e+7]]+"-"+K[i[e+8]]+K[i[e+9]]+"-"+K[i[e+10]]+K[i[e+11]]+K[i[e+12]]+K[i[e+13]]+K[i[e+14]]+K[i[e+15]]).toLowerCase()}let et;const Gi=new Uint8Array(16);function Fi(){if(!et){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");et=crypto.getRandomValues.bind(crypto)}return et(Gi)}const Bi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),qt={randomUUID:Bi};function Jt(i,e,t){var a;if(qt.randomUUID&&!i)return qt.randomUUID();i=i||{};const o=i.random??((a=i.rng)==null?void 0:a.call(i))??Fi();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Hi(o)}const ie=i=>{const{selected:e,highlighted:t,...o}=i,a=o,l={...a,...e},s={...a,...t},n={...a,...t,...e};return{defaultLook:a,selectedLook:l,highlightedLook:s,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],B(this.entities,t))}size(){return this.entities.length}*[Symbol.iterator](){for(const e of this.entities)yield e}}const Me=0;class Se{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(`g#${this.id}`)}}class ue 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((o,a,l)=>e(o,a,l)&&!o.removed)}filter(e,t=!1){return t?super.filter(e):super.filter((o,a,l)=>e(o,a,l)&&!o.removed)}find(e,t=!1){return t?super.find(e):super.find((o,a,l)=>e(o,a,l)&&!o.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(o=>!o.removed).map(e)}remove(e){const t=this.get(e,!0);t!==void 0&&(delete this.entityMap[e],B(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(o=>!o.removed))yield t}}function Ae(i,e){return!e||i[0]>e[0]?!0:i[0]===e[0]?i[1]>=e[1]:!1}class Ui{constructor(e,t,o,a,l,s){this.name=e,this.type=t,this.defaultValue=o,this.basic=a,this.editable=l,this.rootAttribute=s,this.options=void 0,this.properties=void 0}}var G=(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))(G||{});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}}class be{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 o of e){if(t==null)return;t=t[o]}return t}}setRootElementValue(e,t){if(typeof e=="string"&&(this.rootElement[e]=t),Array.isArray(e)&&e.length>0){let o=this.rootElement;for(let a=0;a<e.length-1;++a){const l=e[a];if(o==null)return;o=o[l]}if(o==null)return;o[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==="object"?this.valueSets[e].getValues():this.values[e]}getValues(){const e={};for(const t in this.propertySet.propertyMap)this.propertySet.getProperty(t).type==="object"?e[t]=this.valueSets[t].getValues():e[t]=this.getValue(t);return e}getValuesForKeys(e){const t={};for(const o in e)this.propertySet.getProperty(o).type==="object"?t[o]=this.valueSets[o].getValuesForKeys(e[o]):t[o]=this.getValue(o);return t}getTimestamps(){const e={};for(const t in this.propertySet.propertyMap)if(this.propertySet.getProperty(t).type==="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!Qt(t)}hasSetValue(e){const t=this.getValue(e),o=this.propertySet.getProperty(e);return o&&o.type==="object"?this.getSubValueSet(e).hasAnySetValue():!Qt(t)&&!xe(t,o==null?void 0:o.defaultValue)}hasAnySetValue(){for(const e of this.propertySet.propertyList)if(this.hasSetValue(e.name))return!0;return!1}setValue(e,t){const o=this.propertySet.getProperty(e);if(o){o.type==="object"?this.valueSets[e].setValues(t):(this.values[e]=t,xe(t,o.defaultValue)||this.displayProperty(o));const a=o.rootAttribute;a!=null&&this.setRootElementValue(a,t)}}setValues(e){this.resetValues();for(const t in e)this.propertySet.getProperty(t).type==="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==="object"?this.valueSets[t].setTimestamps(e[t]):this.ownTimestamps[t]=e[t]}overwriteValues(e){for(const t in e)this.propertySet.getProperty(t).type==="object"?this.valueSets[t].overwriteValues(e[t]):this.setValue(t,e[t])}overwriteValuesLww(e,t){for(const o in e)this.propertySet.getProperty(o).type==="object"?this.valueSets[o].overwriteValuesLww(e[o],t):Ae(t,this.ownTimestamps[o])&&(this.setValue(o,e[o]),this.ownTimestamps[o]=t)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const e in this.propertySet.propertyMap){const t=this.propertySet.getProperty(e),o=t.rootAttribute;t.type==="object"?this.valueSets[e]=this.constructSubValueSet(e):this.values[e]=structuredClone(t.defaultValue),o!=null&&(t.defaultValue!==void 0&&!xe(this.values[e],t.defaultValue)?this.setRootElementValue(o,this.values[e]):this.values[e]=this.getRootElementValue(o)),t.basic?this.displayedProperties.push(t):this.hiddenProperties.push(t)}}constructSubValueSet(e){const t=this.propertySet.getProperty(e),o=new We(t.properties),a=new be(o,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),B(this.hiddenProperties,e))}hideProperty(e){this.hiddenProperties.includes(e)||(this.hiddenProperties.push(e),B(this.displayedProperties,e))}}const Qt=i=>i==null||i===""||i instanceof Array&&i.length===0||i instanceof Object&&Object.keys(i).length===0,xe=(i,e)=>i===e||JSON.stringify(i)===JSON.stringify(e),di=(i,e,t)=>{const o={},a={};for(const l in t.propertySet.propertyMap)if(t.propertySet.propertyMap[l].type==="object"){const s=di(i[l],e[l],t.getSubValueSet(l));Object.keys(s[0]).length>0&&Object.keys(s[1]).length>0&&(o[l]=s[0],a[l]=s[1])}else xe(i[l],e[l])||(o[l]=i[l],a[l]=e[l]);return[o,a]},Yi=i=>i!=null&&i.constructor===Object,Xi={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:ri.Straight,style:ai.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class ci{constructor(e){const t={...Xi,...e};this.id=t.id,this.name=t.name,this.label=t.label;const o=ie(t.look);if(this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook,t.startMarkerLook!==void 0){const a=ie(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=ie(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 le extends Se{constructor(e,t,o,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 be(t.propertySet,this),this.originalData={},this.setStart(o),this.setEnd(a)}get type(){return this._type}set type(e){var t,o;(o=(t=this.model.canvas)==null?void 0:t.userSelection)==null||o.openInPropertyEditor(void 0),this._type=e,this.valueSet&&(this.valueSet=new be(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=ie(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=ie(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=ie(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&&B(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&&B(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 o=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 o){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 o=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 o){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 Wi extends ue{constructor(e){super(),this.types=new Xe,this.model=e}new(e,t,o,a){let l;if(e instanceof ci)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 s=new le(this.model,l,t,o,a);return super.add(s),s.updateInView(),s.valueSet.resetValues(),s}remove(e){var o,a;const t=this.get(e,!0);t&&(B(((o=t.start)==null?void 0:o.outgoingConnections)||[],t),B(((a=t.end)==null?void 0:a.incomingConnections)||[],t),super.remove(e),t.updateInView())}}const V={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",horizontalAlign:Ee.Center,verticalAlign:Fe.Center,fit:!1};class ce extends Se{constructor(e,t,o,a,l,s,n,r,d,c,h,g,b,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=o,this.width=a,this.height=l,this.fontSize=s,this.fontFamily=n,this.color=r,this.selectedColor=d,this.horizontalAlign=c,this.verticalAlign=h,this.defaultText=g,this._text=g,this.editable=b,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))}select(){var e,t;return(t=(e=this.model.canvas)==null?void 0:e.selectCanvasView())==null?void 0:t.select(`foreignObject#${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 Zi extends ue{constructor(e){super(),this.model=e}new(e,t,o,a,l,s,n,r,d,c,h,g,b){const f=new ce(this.model,e,t,n,r,o,a,l,s,d,c,h,g,b);return super.add(f),f.updateInView(),e!==void 0&&(e.label=f),f}remove(e){var o;const t=this.get(e,!0);t&&(((o=t.rootElement)==null?void 0:o.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?V.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?V.margin:i.margin.length===1||i.margin.length===2?i.margin[0]:(i.margin.length===3,i.margin[2]),J=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?V.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?V.margin:i.margin.length===1?i.margin[0]:i.margin.length===2||i.margin.length===3?i.margin[1]:i.margin[3],de=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?V.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?V.margin:i.margin.length===1?i.margin[0]:(i.margin.length===2||i.margin.length===3,i.margin[1]),X=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?V.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?V.margin:(i.margin.length===1||i.margin.length===2||i.margin.length===3,i.margin[0]),Ne=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?V.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?V.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),Pe=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?V.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?V.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],ze=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?V.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?V.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),Re=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?V.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?V.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),ei=1,ti=1,Ki=1,qi=1;class Ji{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 o=[];this.sections.push(o);for(const a of t)o.push(new Qi(a))}}}class Qi{constructor(e){this.label=e.label||null,this.ports=e.ports||[],this.priority=e.priority||Me;const t=ie(e.look||hi);this.defaultLook=t.defaultLook,this.selectedLook=t.selectedLook,this.highlightedLook=t.highlightedLook,this.selectedAndHighlightedLook=t.selectedAndHighlightedLook}}class q extends Se{constructor(e,t,o,a,l,s,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=o,this.indexYInNode=a,this.coords=l,this.width=s,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,o,a,l,s,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:((o=this.type)==null?void 0:o.selectedLook)||((a=this.node)==null?void 0:a.look):this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:((l=this.type)==null?void 0:l.highlightedLook)||((s=this.node)==null?void 0:s.look):this._defaultLook!==void 0?this._defaultLook:((n=this.type)==null?void 0:n.defaultLook)||((r=this.node)==null?void 0:r.look)}set look(e){if(e){const t=ie(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,o,a,l;return(l=(a=(o=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode]}getMinWidth(){var e,t,o,a;return((a=(o=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:o.minWidths)==null?void 0:a[this.indexXInNode])||Ki}getMinHeight(){var e,t,o,a;return((a=(o=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:o.minHeights)==null?void 0:a[this.indexYInNode])||qi}getPriority(){var e,t,o,a,l,s;return((s=(l=(a=(o=(t=(e=this.node)==null?void 0:e.type)==null?void 0:t.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode])==null?void 0:s.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)),o=t.indexOf(Math.min(...t));return this.ports[o]}}}getIncomingConnections(e=!1){const t=[];for(const o of this.ports)for(const a of o.incomingConnections)!e&&a.removed||t.push(a);return t}getOutgoingConnections(e=!1){const t=[];for(const o of this.ports)for(const a of o.outgoingConnections)!e&&a.removed||t.push(a);return t}getConnections(e=!1){const t=[];for(const o of this.ports){for(const a of o.incomingConnections)!e&&a.removed||t.push(a);for(const a of o.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 o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(e){case k.Left:l=[o[0]-t,o[1]],s=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[0]=l[1]-this.getMinWidth());break;case k.Top:l=[o[0],o[1]],s=[a[0]-t,a[1]],s[1]-s[0]<this.getMinHeight()&&(s[0]=s[1]-this.getMinHeight());break;case k.Right:l=[o[0],o[1]+t],s=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[1]=l[0]+this.getMinWidth());break;case k.Bottom:l=[o[0],o[1]],s=[a[0],a[1]+t],s[1]-s[0]<this.getMinHeight()&&(s[1]=s[0]+this.getMinHeight());break}this.setGeometry({coords:[l[0],s[0]],width:l[1]-l[0],height:s[1]-s[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(e){const t=[this.coords[0],this.coords[0]+this.width],o=[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,o,a,l));const s=this.type;this.label&&(this.label.coords=[this.coords[0]+J(s==null?void 0:s.label),this.coords[1]+X(s==null?void 0:s.label)],this.label.width=this.width-J(s==null?void 0:s.label)-de(s==null?void 0:s.label),this.label.height=this.height-X(s==null?void 0:s.label)-oe(s==null?void 0:s.label),this.label.updateInView());for(const n of this.decorators)n.move(Be(n.coords,t,o,a,l));this.getConnections().forEach(n=>n.tighten()),this.updateInView()}}class es extends ue{constructor(e){super(),this.model=e}new(e,t,o,a,l,s,n){var h,g,b,f,m,u,v,w,p,S;const r=new q(this.model,e,t,o,a,l,s,n);super.add(r),r.updateInView(),e.sections.push(r),e.updateInView();const d=(f=(b=(g=(h=e.type.sectionGrid)==null?void 0:h.sections)==null?void 0:g[o])==null?void 0:b[t])==null?void 0:f.ports;if(d&&d.length>0)for(let x=0;x<d.length;++x){const L=d[x],z=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}_${x}`);if((m=z.type)!=null&&m.label){const N={...V,...(u=z.type)==null?void 0:u.label},H=6*N.fontSize+Pe(N)+ze(N),P=N.fontSize+Re(N)+Ne(N);let R;switch(z.direction){case k.Bottom:case k.Left:case k.Right:R=[z.coords[0]-H/2,z.coords[1]-P-oe(N)];break;case k.Top:R=[z.coords[0]-H/2,z.coords[1]+X(N)];break;default:R=z.coords}this.model.fields.new(z,R,N.fontSize,N.fontFamily,N.color,N.selectedColor,H,P,N.horizontalAlign,N.verticalAlign,"",N.editable,N.fit)}}const c=(S=(p=(w=(v=e.type.sectionGrid)==null?void 0:v.sections)==null?void 0:w[o])==null?void 0:p[t])==null?void 0:S.label;if(c){const x={...V,...c};this.model.fields.new(r,[r.coords[0]+J(x),r.coords[1]+X(x)],x.fontSize,x.fontFamily,x.color,x.selectedColor,r.width-J(x)-de(x),r.height-X(x)-oe(x),x.horizontalAlign,x.verticalAlign,"",x.editable,x.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&&B(t.node.sections,t),super.remove(e),t.updateInView()}}}const hi={lookType:"shaped-look",shape:Ye.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},he={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],sectionGrid:null,look:hi,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Me,properties:[]};class ui{constructor(e){const t={...he,...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=is(t),this.leftPadding=ss(t),this.rightPadding=os(t),this.topPadding=ns(t),this.label=t.label,this.ports=t.ports,this.sectionGrid=t.sectionGrid?new Ji(t.sectionGrid):null;const o=ie(t.look);this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.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 Se{constructor(e,t,o=[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 be(t.propertySet,this),this.originalData={},this.coords=o,this.width=t.defaultWidth,this.height=t.defaultHeight}get type(){return this._type}set type(e){var t,o;(o=(t=this.model.canvas)==null?void 0:t.userSelection)==null||o.openInPropertyEditor(void 0),this._type=e,this.valueSet&&(this.valueSet=new be(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=ie(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(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.sections)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)),o=t.indexOf(Math.min(...t));return this.ports[o]}}}getIncomingConnections(e=!1){const t=[];for(const o of this.ports)for(const a of o.incomingConnections)!e&&a.removed||t.push(a);return t}getOutgoingConnections(e=!1){const t=[];for(const o of this.ports)for(const a of o.outgoingConnections)!e&&a.removed||t.push(a);return t}getConnections(e=!1){const t=[];for(const o of this.ports){for(const a of o.incomingConnections)!e&&a.removed||t.push(a);for(const a of o.outgoingConnections)!e&&a.removed||t.push(a)}return t}getAdjacentNodes(e=!1){var o,a;const t=[];for(const l of this.ports){for(const s of l.incomingConnections){if(!e&&s.removed)continue;const n=(o=s.start)==null?void 0:o.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}for(const s of l.outgoingConnections){if(!e&&s.removed)continue;const n=(a=s.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,o=!1;for(;t!==void 0;){if(t.id===e.id){o=!0;break}t=t.parent}o||this.children.indexOf(e)>=0||(this.fitToChild(e),this.children.push(e),e.parent=this,e.raise())}removeChild(e){B(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 o=this.coords[1]-e.coords[1]+this.type.topPadding;o>=0&&this.stretch(k.Top,o);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 o of this.children)o.move([o.coords[0]+t[0],o.coords[1]+t[1]]);for(const o of this.sections)o.move([o.coords[0]+t[0],o.coords[1]+t[1]]);this.setGeometry({coords:e,width:this.width,height:this.height,sections:{},children:{}})}stretch(e,t){const o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(e){case k.Left:l=[o[0]-t,o[1]],s=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[0]=l[1]-this.type.minWidth);break;case k.Top:l=[o[0],o[1]],s=[a[0]-t,a[1]],s[1]-s[0]<this.type.minHeight&&(s[0]=s[1]-this.type.minHeight);break;case k.Right:l=[o[0],o[1]+t],s=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[1]=l[0]+this.type.minWidth);break;case k.Bottom:l=[o[0],o[1]],s=[a[0],a[1]+t],s[1]-s[0]<this.type.minHeight&&(s[1]=s[0]+this.type.minHeight);break}this.setGeometry({coords:[l[0],s[0]],width:l[1]-l[0],height:s[1]-s[0],sections:{},children:{}})}stretchSections(e,t,o,a){let l=Number.NEGATIVE_INFINITY;switch(e){case k.Bottom:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));t<l&&(t=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(e,t):s.indexYInNode>a&&s.move([s.coords[0],s.coords[1]+t]);break;case k.Right:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));t<l&&(t=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(e,t):s.indexXInNode>o&&s.move([s.coords[0]+t,s.coords[1]]);break;case k.Top:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));t<l&&(t=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(e,t):s.indexYInNode<a&&s.move([s.coords[0],s.coords[1]-t]);break;case k.Left:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));t<l&&(t=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(e,t):s.indexXInNode<o&&s.move([s.coords[0]-t,s.coords[1]]);break}this.stretch(e,t)}getGeometry(e){const t={};for(const a of this.sections)t[a.id]=a.getGeometry();const o={};for(const a of this.children)a.id!==e&&(o[a.id]=a.getGeometry(e));return{coords:[...this.coords],width:this.width,height:this.height,sections:t,children:o}}setGeometry(e){this.raise();const t=[this.coords[0],this.coords[0]+this.width],o=[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 s of this.children){const n=e.children[s.id];n&&s.setGeometry(n)}for(const s of this.sections){const n=e.sections[s.id];n&&s.setGeometry(n)}for(const s of this.ports)s.move(Be(s.coords,t,o,a,l));this.label&&(this.label.coords=[this.coords[0]+J(this.type.label),this.coords[1]+X(this.type.label)],this.label.width=this.width-J(this.type.label)-de(this.type.label),this.label.height=this.height-X(this.type.label)-oe(this.type.label),this.label.updateInView());for(const s of this.decorators)s.move(Be(s.coords,t,o,a,l));this.getConnections().forEach(s=>s.tighten()),this.updateInView()}}class ts extends ue{constructor(e){super(),this.types=new Xe,this.model=e}new(e,t,o){var s,n,r,d,c,h,g;let a;if(e instanceof ui)a=e;else{const b=this.types.get(e);if(b===void 0)throw new TypeError(`Node type with id '${e}' could not be found.`);a=b}const l=new j(this.model,a,t,o);if(super.add(l),l.updateInView(),a.sectionGrid!==null){let b=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,b],((s=a.sectionGrid.defaultWidths)==null?void 0:s[u])||ei,((n=a.sectionGrid.defaultHeights)==null?void 0:n[f])||ti,`${l.id}_${f}_${u}`),m+=(((r=a.sectionGrid.defaultWidths)==null?void 0:r[u])||ei)+(a.sectionGrid.margin||0);b+=(((d=a.sectionGrid.defaultHeights)==null?void 0:d[f])||ti)+(a.sectionGrid.margin||0)}}if(a.ports.length>0)for(let b=0;b<a.ports.length;++b){const f=a.ports[b],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}_${b}`);if((c=u.type)!=null&&c.label){const v={...V,...(h=u.type)==null?void 0:h.label},w=6*v.fontSize+Pe(v)+ze(v),p=v.fontSize+Re(v)+Ne(v);let S;switch(u.direction){case k.Bottom:case k.Left:case k.Right:S=[u.coords[0]-w/2,u.coords[1]-p-oe(v)];break;case k.Top:S=[u.coords[0]-w/2,u.coords[1]+X(v)];break;default:S=u.coords}this.model.fields.new(u,S,v.fontSize,v.fontFamily,v.color,v.selectedColor,w,p,v.horizontalAlign,v.verticalAlign,"",v.editable,v.fit)}}if(a.label){const b={...V,...a.label};this.model.fields.new(l,[l.coords[0]+J(b),l.coords[1]+X(b)],b.fontSize,b.fontFamily,b.color,b.selectedColor,l.width-J(b)-de(b),l.height-X(b)-oe(b),b.horizontalAlign,b.verticalAlign,"",b.editable,b.fit)}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&&B(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 o=[];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&&o.push(a);return o}}const fi=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},is=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?he.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?he.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),ss=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?he.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?he.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],os=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?he.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?he.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),ns=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?he.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?he.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),gi={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=ie(gi),mi={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:gi};class rs{constructor(e){const t={...mi,...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 o=ie(t.look);this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook}}class ve extends Se{constructor(e,t,o,a,l,s,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=o,this.coords=a,this.connectionPoint=l||a,this.direction=s}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,o,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:(o=this.type||De)==null?void 0:o.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(a=this.type||De)==null?void 0:a.defaultLook}set look(e){if(e){const t=ie(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)||mi.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 q)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 o of this.outgoingConnections)o.setStart(this);for(const o of this.incomingConnections)o.setEnd(this);this.label&&this.label.move([this.label.coords[0]+t[0],this.label.coords[1]+t[1]]),this.updateInView()}distanceTo(e){return ni(this.coords,e)}}class as extends ue{constructor(e){super(),this.types=new Xe,this.model=e}new(e,t,o,a,l,s){const n=new ve(this.model,e,t,o,a,l,s);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 q)&&B(t.rootElement.ports,t),super.remove(e),t.updateInView()}}}class pi{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 o of t.nodes||[])this.importNode(e,o);for(const o of t.connections||[])this.importConnection(e,o);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,s,n,r,d,c,h,g,b;const o=e.nodes.types.get(t.type);if(o){const f=new j(e,o,t.coords,t.id);if(e.nodes.add(f),f.width=t.width,f.height=t.height,t.label&&o.label){const u={...V,...o.label},v=new ce(e,f,[f.coords[0]+J(u),f.coords[1]+X(u)],f.width-J(u)-de(u),f.height-X(u)-oe(u),u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,"",u.editable,u.fit);v.text=t.label,f.label=v,e.fields.add(v),v.updateInView()}for(const u of t.children||[]){const v=this.importNode(e,u);v!==void 0&&((a=f.children)==null||a.push(v),v.parent=f)}for(const u of t.sections||[]){const v=new q(e,f,u.indexXInNode,u.indexYInNode,u.coords,u.width,u.height,u.id);if((l=f.sections)==null||l.push(v),e.sections.add(v),u.label&&(d=(r=(n=(s=o.sectionGrid)==null?void 0:s.sections)==null?void 0:n[u.indexYInNode])==null?void 0:r[u.indexXInNode])!=null&&d.label){const p={...V,...(b=(g=(h=(c=o.sectionGrid)==null?void 0:c.sections)==null?void 0:h[u.indexYInNode])==null?void 0:g[u.indexXInNode])==null?void 0:b.label},S=new ce(e,v,[v.coords[0]+J(p),v.coords[1]+X(p)],v.width-J(p)-de(p),v.height-X(p)-oe(p),p.fontSize,p.fontFamily,p.color,p.selectedColor,p.horizontalAlign,p.verticalAlign,"",p.editable,p.fit);S.text=u.label,v.label=S,e.fields.add(S),S.updateInView()}let w=0;for(const p of u.ports||[]){const S=p.type!==void 0?e.ports.types.get(p.type):void 0,x=new ve(e,S,v,p.coords,p.connectionPoint,p.direction,p.id);if(v.ports.push(x),e.ports.add(x),p.label){if(o.ports.length>w&&(S!=null&&S.label)){const L={...V,...S==null?void 0:S.label};let z;switch(x.direction){case k.Top:case k.Left:z=[x.coords[0]-L.fontSize,x.coords[1]-L.fontSize];break;case k.Bottom:z=[x.coords[0]-L.fontSize,x.coords[1]+L.fontSize];break;case k.Right:z=[x.coords[0]+L.fontSize,x.coords[1]-L.fontSize];break;default:z=x.coords}const N=new ce(e,x,z,L.fontSize,L.fontSize,L.fontSize,L.fontFamily,L.color,L.selectedColor,L.horizontalAlign,L.verticalAlign,"",L.editable,L.fit);N.text=p.label,x.label=N,e.fields.add(N),N.updateInView()}++w}p.collabMeta&&(x.selfRemoved=p.collabMeta.selfRemoved,x.selfRemovedTimestamp=p.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(x.label,p.collabMeta.label)),x.updateInView()}u.collabMeta&&(v.selfRemoved=u.collabMeta.selfRemoved,v.selfRemovedTimestamp=u.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(v.label,u.collabMeta.label)),v.updateInView()}let m=0;for(const u of t.ports||[]){const v=u.type!==void 0?e.ports.types.get(u.type):void 0,w=new ve(e,v,f,u.coords,u.connectionPoint,u.direction,u.id);if(f.ports.push(w),e.ports.add(w),u.label){if(o.ports.length>m&&(v!=null&&v.label)){const p={...V,...v==null?void 0:v.label};let S;switch(w.direction){case k.Top:case k.Left:S=[w.coords[0]-p.fontSize,w.coords[1]-p.fontSize];break;case k.Bottom:S=[w.coords[0]-p.fontSize,w.coords[1]+p.fontSize];break;case k.Right:S=[w.coords[0]+p.fontSize,w.coords[1]-p.fontSize];break;default:S=w.coords}const x=new ce(e,w,S,p.fontSize,p.fontSize,p.fontSize,p.fontFamily,p.color,p.selectedColor,p.horizontalAlign,p.verticalAlign,"",p.editable,p.fit);x.text=u.label,w.label=x,e.fields.add(x),x.updateInView()}++m}u.collabMeta&&(w.selfRemoved=u.collabMeta.selfRemoved,w.selfRemovedTimestamp=u.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(w.label,u.collabMeta.label)),w.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 o=e.connections.types.get(t.type);if(o){const a=new le(e,o,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,o,a,l,s,n){this.canvas=e,this.id=t,this.typeId=o,this.coords=a,this.parentId=l,this.label=s,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 ht{constructor(e,t,o){this.canvas=e,this.to=t,this.timestamp=o}do(){for(const e in this.to){const t=this.canvas.model.nodes.get(e,!0);if(t&&Ae(this.timestamp,t.geometryTimestamp)){const o=this.to[e];t.move([o[0],o[1]]),t.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(e,t){return new ht(e,t.to,t.timestamp)}}class Ve{constructor(e,t,o,a){this.canvas=e,this.nodeIds=t,this.delta=o,this.timestamp=a}do(){var e;for(const t of this.nodeIds){const o=this.canvas.model.nodes.get(t,!0);o&&Ae(this.timestamp,o.geometryTimestamp)&&(o.move([o.coords[0]+this.delta[0],o.coords[1]+this.delta[1]]),(e=o.parent)==null||e.fitToChild(o),o.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(e,t){return new Ve(e,t.nodeIds,t.delta,t.timestamp)}}class te{constructor(e,t,o,a){this.canvas=e,this.nodeId=t,this.to=o,this.timestamp=a}do(){var t,o,a;const e=this.canvas.model.nodes.get(this.nodeId,!0);if(e&&Ae(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)(o=l.label)!=null&&o.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 te(e,t.nodeId,t.to,t.timestamp)}}class je{constructor(e,t,o,a,l){this.canvas=e,this.childId=t,this.parentId=o,this.childGeometry=a,this.timestamp=l}do(){var o;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)&&Ae(this.timestamp,e.geometryTimestamp)&&((o=e.parent)==null||o.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,o,a,l){this.canvas=e,this.id=t,this.typeId=o,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 Te{constructor(e,t,o,a){this.canvas=e,this.fieldId=t,this.to=o,this.timestamp=a}do(){const e=this.canvas.model.fields.get(this.fieldId,!0);e&&Ae(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 Te(e,t.fieldId,t.to,t.timestamp)}}class $e{constructor(e,t,o,a){this.canvas=e,this.id=t,this.to=o,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,o,a,l,s,n,r){this.canvas=e,this.nodeIds=t,this.sectionIds=o,this.portIds=a,this.connectionIds=l,this.fieldIds=s,this.selfRemoved=n,this.timestamp=r}doOne(e){e&&Ae(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,o){this.canvas=e,this.nodes=t,this.connections=o}do(){const e=new pi;this.canvas.userSelection.clear();for(const t of this.nodes){const o=e.importNode(this.canvas.model,t);o&&this.canvas.userSelection.add(o)}for(const t of this.connections){const o=e.importConnection(this.canvas.model,t);o&&this.canvas.userSelection.add(o)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(e,t){return new qe(e,t.nodes,t.connections)}}class ls{constructor(e){this.isInRoom=!1,this.canvas=e,this.replicaId=Jt()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+Jt()}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"applyLayout":{ht.deserialize(this.canvas,e).do();break}case"move":{Ve.deserialize(this.canvas,e).do();break}case"setGeometry":{te.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":{Te.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 ds{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.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 cs{constructor(e,t,o,a,l,s,n,r,d){this.canvas=e,this.type=t,this.coords=o,this.parentId=a,this.ancestorId=l,this.fromAncestorGeometry=s,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 te(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 o=new te(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}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 o=new te(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return e===void 0}}class tt{constructor(e,t,o){this.canvas=e,this.nodeIds=t,this.delta=o}do(){const e=new Ve(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 Ve(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 Y{constructor(e,t,o,a,l,s,n,r){this.canvas=e,this.intent=t,this.nodeId=o,this.from=a,this.to=l,this.ancestorId=s,this.fromAncestorGeometry=n,this.toAncestorGeometry=r}do(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){const t=new te(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 o=new te(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}}return e!==void 0}undo(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){this.to=e.getGeometry();const t=new te(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 o=new te(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}}return e!==void 0}redo(){const e=this.canvas.model.nodes.get(this.nodeId);if(e){this.from=e.getGeometry();const t=new te(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}}class hs{constructor(e,t,o,a,l,s,n,r,d){this.canvas=e,this.childId=t,this.fromParentId=o,this.toParentId=a,this.fromChildGeometry=l,this.toChildGeometry=s,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 o=new te(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}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 o=new te(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return e!==void 0}redo(){return this.do()}}class it{constructor(e,t,o,a){this.canvas=e,this.type=t,this.startId=o,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 ii{constructor(e,t,o,a){this.canvas=e,this.fieldId=t,this.from=o,this.to=a}do(){const e=this.canvas.model.fields.get(this.fieldId),t=new Te(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 Te(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 Te(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}}class us{constructor(e,t,o,a){this.canvas=e,this.id=t,this.from=o,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 fs{constructor(e,t,o,a,l,s){this.canvas=e,this.nodeIds=t,this.sectionIds=o,this.portIds=a,this.connectionIds=l,this.fieldIds=s}do(){const e=this.nodeIds.map(o=>this.canvas.model.nodes.get(o)!==void 0).includes(!0)||this.sectionIds.map(o=>this.canvas.model.sections.get(o)!==void 0).includes(!0)||this.portIds.map(o=>this.canvas.model.ports.get(o)!==void 0).includes(!0)||this.connectionIds.map(o=>this.canvas.model.connections.get(o)!==void 0).includes(!0)||this.fieldIds.map(o=>this.canvas.model.fields.get(o)!==void 0).includes(!0),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(o=>this.canvas.model.nodes.get(o)===void 0).includes(!0)||this.sectionIds.map(o=>this.canvas.model.sections.get(o)===void 0).includes(!0)||this.portIds.map(o=>this.canvas.model.ports.get(o)===void 0).includes(!0)||this.connectionIds.map(o=>this.canvas.model.connections.get(o)===void 0).includes(!0)||this.fieldIds.map(o=>this.canvas.model.fields.get(o)===void 0).includes(!0),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 gs{constructor(e,t,o,a){this.canvas=e,this.nodes=t,this.connections=o,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,o={};for(const l of this.nodes){const s=l.id,n=this.canvas.collabEngine.freshId();if(o[s]=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(),o[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(),o[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(),o[d]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]])}}for(const l of this.connections){const s=this.canvas.collabEngine.freshId();if(o[l.id]=s,l.id=s,l.start=o[l.start]||l.start,l.end=o[l.end]||l.end,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(o=>this.canvas.model.nodes.get(o.id)!==void 0).includes(!0)||this.connections.map(o=>this.canvas.model.connections.get(o.id)!==void 0).includes(!0),t=new ae(this.canvas,this.nodes.map(o=>o.id),[],[],this.connections.map(o=>o.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){const e=this.nodes.map(o=>this.canvas.model.nodes.get(o.id)===void 0).includes(!0)||this.connections.map(o=>this.canvas.model.connections.get(o.id)===void 0).includes(!0),t=new ae(this.canvas,this.nodes.map(o=>o.id),[],[],this.connections.map(o=>o.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 yi=(i=>(i[i.DoubleClick=0]="DoubleClick",i[i.SecondaryClick=1]="SecondaryClick",i[i.Selection=2]="Selection",i[i.Highlight=3]="Highlight",i))(yi||{});class me extends Je{constructor(e,t,o){super(0),this.cause=e,this.target=t,this.coords=o}}class pe extends Je{constructor(e,t,o){super(1),this.cause=e,this.target=t,this.coords=o}}class F extends Je{constructor(e,t){super(2),this.targets=e,this.selected=t}}class se extends Je{constructor(e){super(3),this.target=e}}class ms extends Se{constructor(e,t,o,a,l,s,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=o,this.width=a,this.height=l,this.priority=s,this.html=n}select(){var e,t;return(t=(e=this.model.canvas)==null?void 0:e.selectCanvasView())==null?void 0:t.select(`foreignObject#${this.id}`)}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 ps extends ue{constructor(e){super(),this.model=e}new(e,t,o,a,l,s,n){const r=new ms(this.model,e,t,o,a,l,s,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 q)&&B(t.rootElement.decorators,t),super.remove(e),t.updateInView())}}class ys extends Se{constructor(e,t,o,a,l,s,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=o,this.height=a,this.priority=l,this.html=s}select(){var e,t;return(t=(e=this.model.canvas)==null?void 0:e.selectCanvasView())==null?void 0:t.select(`foreignObject#${this.id}`)}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 bs extends ue{constructor(e){super(),this.model=e}new(e,t,o,a,l,s){const n=new ys(this.model,e,t,o,a,l,s);return super.add(n),n.updateInView(),n}remove(e){const t=this.get(e,!0);t&&(super.remove(e),t.updateInView())}}class bi{constructor(e,t,o,a,l,s=[]){this.nodes=new ts(this),this.sections=new es(this),this.ports=new as(this),this.connections=new Wi(this),this.fields=new Zi(this),this.objects=new bs(this),this.decorators=new ps(this),this.canvas=e,this.id=t,this.name=o,this.description=a,this.type=l,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new be(new We(s),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 ye=i=>!!i.button,st=(i,e,t,o,a,l,s,n)=>Mi(i,[e,t],o,a,Math.max(10,s||0,n||0)*l),A=i=>{i?T.select("body").style("cursor",i):T.select("body").style("cursor",M.Auto)},ke=i=>i instanceof j?i:i instanceof q?i.node||i:i.rootElement instanceof j||i.rootElement instanceof q||i.rootElement instanceof ve?ke(i.rootElement):i,ot=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")},nt=i=>{i.filter(".shaped-look").select("path").attr("d",e=>lt(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)},dt=96,Q=32,Le=dt+Q,vs=Math.PI/4,ks=100;class ws{constructor(e){this.canvas=e}open(e){this.close();const t=this.canvas.getPointerLocationRelativeToRoot(e),o=this.canvas.getPointerLocationRelativeToCanvas(e),a=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${t[0]-Le}px`).attr("y",`${t[1]-Le}px`).attr("width",`${2*Le}px`).attr("height",`${2*Le}px`).style("pointer-events","none").on(I.ContextMenu,s=>{this.canvas.canUserPerformAction(C.ContextMenu)&&(e.preventDefault(),this.open(s))}).on(I.Click,s=>{s.preventDefault(),this.close()});this.contextMenuContainer=a;const l=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"CUT",imageClass:"daga-cut",onPress:s=>{s.preventDefault(),this.canvas.userSelection.cutToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&l.push({name:"COPY",imageClass:"daga-copy",onPress:s=>{s.preventDefault(),this.canvas.userSelection.copyToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.canUserPerformAction(C.Paste)&&l.push({name:"PASTE",imageClass:"daga-paste",onPress:s=>{s.preventDefault(),this.canvas.userSelection.pasteFromClipboard(this.canvas.getClosestGridPoint(o)),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"DELETE",imageClass:"daga-delete",onPress:s=>{s.preventDefault(),this.canvas.userSelection.removeFromModel(),this.canvas.cancelAllUserActions()}}),l.length===0&&l.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let s=0;s<l.length;++s){const n=l[s],r=n.onPress,d=(s+.5-l.length/2)*vs,c=a.append("xhtml:div").attr("class",`daga-context-menu-button ${n.imageClass}-button${n.onPress!=null?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*Q}px`).style("height",`${2*Q}px`).style("border-radius",`${Q}px`).style("pointer-events","auto").on(I.Click,h=>{r&&r(h)}).on(I.KeyDown,h=>{r&&h.key===ee.Enter&&r(h)});c.append("xhtml:div").style("position","absolute").style("left",`${.75*Q}px`).style("top",`${.5*Q}px`).style("width",`${.5*Q}px`).style("height",`${.5*Q}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass),c.append("xhtml:span").style("position","absolute").style("left",`${.2*Q}px`).style("top",`${1.1*Q}px`).style("text-align","center").style("width",`${1.6*Q}px`).style("height",`${.35*Q}px`).style("margin","0").style("font-size",`${.35*Q}px`).style("font-weight","700").style("user-select","none").text(n.name),c.transition().ease(T.easeLinear).duration(ks).tween("progress",()=>h=>{const g=d*h;return c.style("left",`${Math.sin(g)*dt-Q+Le}px`).style("top",`${-Math.cos(g)*dt-Q+Le}px`)})}}close(){var e;(e=this.contextMenuContainer)==null||e.remove(),this.contextMenuContainer=void 0}}class xs extends ue{constructor(e){super(),this.focus=void 0,this.canvas=e}getFocus(){return this.focus}focusOn(e){this.clear(),this.focus=e,e instanceof ce&&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 q){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 ve?(e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updatePortsInView(e.id)):e instanceof le&&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 Cs=1;class vi{export(e,t=!1){const o={name:e.name,type:e.type,typeVersion:Cs,createdAt:e.createdAt,updatedAt:e.updatedAt,nodes:[],connections:[],data:e.valueSet.getValues(),...t?{collabMeta:{logicalClock:e.logicalClock,dataTimestamps:e.valueSet.getTimestamps()}}:{}};e.id&&(o.id=e.id),e.description&&(o.description=e.description);for(const a of e.nodes.all(!0))!t&&a.removed||a.parent===void 0&&o.nodes.push(this.exportNode(a,t));for(const a of e.connections.all(!0))!t&&a.removed||o.connections.push(this.exportConnection(a,t));return o}exportNode(e,t=!1){var s,n,r,d,c,h;const o=[];for(const g of e.children)o.push(this.exportNode(g,t));const a=[];for(const g of e.sections){const b=[];for(const f of g.ports)b.push({id:f.id,type:(s=f.type)==null?void 0:s.id,coords:Ie(f.coords),connectionPoint:Ie(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:b,label:((r=g.label)==null?void 0:r.text)||"",indexXInNode:g.indexXInNode,indexYInNode:g.indexYInNode,coords:Ie(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:Ie(g.coords),connectionPoint:Ie(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:o,sections:a,ports:l,label:((h=e.label)==null?void 0:h.text)||"",coords:Ie(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 o,a;return{id:e.id,type:e.type.id,start:((o=e.start)==null?void 0:o.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 Ss="Diagram properties";class As extends ue{constructor(e){super(),this.canvas=e,this.canvas.propertyEditorChanges$.pipe(we.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(e){if(!this.contains(e.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(e instanceof j||e instanceof le)?this.openInPropertyEditor(e):this.propertyEditorSelection===void 0&&e instanceof q?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 o of t.sections)super.remove(o.id),o.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=[],o=[],a=[],l=[];for(const n of this.all())n instanceof j?e.push(n.id):n instanceof q?t.push(n.id):n instanceof ve?o.push(n.id):n instanceof le?a.push(n.id):n instanceof ce&&l.push(n.id);const s=new fs(this.canvas,e,t,o,a,l);s.do(),this.canvas.actionStack.add(s)}}copyToClipboard(){const e={type:"daga-user-selection",nodes:[],connections:[]},t=new vi;for(const o of this.all())o instanceof j&&e.nodes.push(t.exportNode(o,!1)),o instanceof le&&e.connections.push(t.exportConnection(o,!1));navigator.clipboard.writeText(JSON.stringify(e))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(e){navigator.clipboard.readText().then(t=>{try{const o=JSON.parse(t);if(o.type!=="daga-user-selection")return;const a=new gs(this.canvas,o.nodes,o.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 o=e==null?void 0:e.valueSet;o?(this.propertyEditorSelection=e,this.propertyEditorValues=structuredClone(o.getValues()),t&&(e instanceof j||e instanceof le?(e instanceof j?e.name?t.title=`${e.type.name}: ${e.name}`:t.title=e.type.name:e instanceof le&&(t.title=e.type.name),t.valueSet=void 0,t.valueSet=o):(t.title=Ss,t.valueSet=void 0,t.valueSet=o))):(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 bi?void 0:this.propertyEditorSelection.id;if(xe(this.propertyEditorValues,(n=this.propertyEditorSelection)==null?void 0:n.valueSet.getValues()))return;const t=this.propertyEditorValues,o=structuredClone((r=this.propertyEditorSelection)==null?void 0:r.valueSet.getValues()),[a,l]=di(t,o,(d=this.propertyEditorSelection)==null?void 0:d.valueSet),s=new us(this.canvas,e,a,l);s.do(),this.canvas.actionStack.add(s),this.propertyEditorValues=o}}const Is=12,D=6,Ls=25,rt="diagram-connection-unfinished",Es=100,Ue=class Ue{constructor(e,t){var o,a,l,s,n,r,d,c,h,g,b,f,m,u,v,w,p,S;if(this.backgroundPatternId=`daga-background-pattern-id-${Ue.canvasCount++}`,this.zoomTransform=T.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new we.Subject,this.diagramChange$=new we.Subject,this.diagramEvent$=new we.Subject,this.propertyEditorChanges$=new we.Subject,this.parentComponent=e,this.model=new bi(this,void 0,t.name||"unnamed","",t.type||"",t.properties||[]),this.userSelection=new As(this),this.userHighlight=new xs(this),this.contextMenu=new ws(this),this.backgroundColor=((o=t.canvas)==null?void 0:o.backgroundColor)||"#FFFFFF",this.gridSize=((l=(a=t.canvas)==null?void 0:a.grid)==null?void 0:l.enabled)===!1||((s=t.canvas)==null?void 0:s.grid)===void 0?0:Math.abs(((r=(n=t.canvas)==null?void 0:n.grid)==null?void 0:r.spacing)||10),this.gridThickness=Math.abs(((c=(d=t.canvas)==null?void 0:d.grid)==null?void 0:c.thickness)||.05),this.gridColor=((g=(h=t.canvas)==null?void 0:h.grid)==null?void 0:g.color)||"rgba(0, 0, 0, 0.1)",this.snapToGrid=((f=(b=t.canvas)==null?void 0:b.grid)==null?void 0:f.enabled)===!1||((m=t.canvas)==null?void 0:m.grid)===void 0?!1:((v=(u=t.canvas)==null?void 0:u.grid)==null?void 0:v.snap)||!1,this.zoomFactor=((w=t.canvas)==null?void 0:w.zoomFactor)||2,this.panRate=((p=t.canvas)==null?void 0:p.panRate)||100,this.inferConnectionType=t.inferConnectionType||!1,this.multipleSelectionOn=!1,this.priorityThresholds=((S=t.canvas)==null?void 0:S.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=t.layoutFormat,this.userActions=t.userActions||{},this.validators=[],this.actionStack=new ds(this,Ls),this.collabEngine=new ls(this),t.nodeTypes)for(const x of t.nodeTypes){const L=new ui({...t.nodeTypeDefaults,...x});this.model.nodes.types.add(L)}if(t.portTypes)for(const x of t.portTypes){const L=new rs({...t.portTypeDefaults,...x});this.model.ports.types.add(L)}if(t.connectionTypes){for(const x of t.connectionTypes){const L=new ci({...t.connectionTypeDefaults,...x});this.model.connections.types.add(L)}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,o;this._connectionType=e,(o=(t=this.parentComponent)==null?void 0:t.palette)==null||o.refreshPalette()}addValidator(e){this.validators.push(e),this.validatorChange$.next()}removeValidator(e){B(this.validators,e),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(e){var t,o;this.priorityThreshold=e,this.updateModelInView();for(const a of this.model.nodes)this.fitNodeInView(a.id);(o=(t=this.parentComponent)==null?void 0:t.palette)==null||o.refreshPalette()}initView(e){const t=T.select(e);t.html(""),this.diagramRoot=t.append("div").node(),T.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),T.select(this.diagramRoot).on(I.Click,()=>{var s;(s=T.select(this.diagramRoot).node())==null||s.focus()}).on(I.ContextMenu,s=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const n=new pe(s,null);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.contextMenu.open(s))}).on(I.DoubleClick,s=>{const n=new me(s,null);this.diagramEvent$.next(n)}).on(I.KeyDown,s=>{if(!s.ctrlKey&&(s.key===ee.Delete||s.key===ee.Backspace)&&this.canUserPerformAction(C.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),s.ctrlKey&&s.key==="a"){s.preventDefault();for(const n of this.model.nodes)this.userSelection.add(n);for(const n of this.model.connections)this.userSelection.add(n);this.diagramEvent$.next(new F(this.userSelection.all(),!0))}if(s.ctrlKey&&s.key==="i"){s.preventDefault();const n=[],r=[];for(const d of this.model.nodes)this.userSelection.toggle(d),d.selected?n.push(d):r.push(d);for(const d of this.model.connections)this.userSelection.toggle(d),d.selected?n.push(d):r.push(d);n.length>0&&this.diagramEvent$.next(new F(n,!0)),r.length>0&&this.diagramEvent$.next(new F(r,!1))}if(s.ctrlKey&&s.key==="c"&&(s.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),s.ctrlKey&&s.key==="x"&&(s.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),s.ctrlKey&&s.key==="v"){s.preventDefault();const n=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(n[0][0]+n[1][0])/2,(n[0][1]+n[1][1])/2])),this.cancelAllUserActions()}s.ctrlKey&&s.key==="y"&&(s.preventDefault(),this.actionStack.redo()),s.ctrlKey&&s.key==="z"&&(s.preventDefault(),this.actionStack.undo()),s.key==="+"&&(s.preventDefault(),this.zoomBy(this.zoomFactor)),s.key==="-"&&(s.preventDefault(),this.zoomBy(1/this.zoomFactor)),s.key===ee.ArrowLeft&&(s.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),s.key===ee.ArrowRight&&(s.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),s.key===ee.ArrowDown&&(s.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),s.key===ee.ArrowUp&&(s.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const o=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%"),a=o.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(I.MouseMove,s=>{if(this.unfinishedConnection!==void 0){const n=this.getPointerLocationRelativeToCanvas(s);this.unfinishedConnection.endCoords=n}}).on(I.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new se(null)))}).on(I.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new se(null))),this.contextMenu.close(),this.userSelection.size()>0){const s=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(s,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(T.drag().filter(s=>this.multipleSelectionOn||ye(s)).on(E.Start,s=>{this.startMultipleSelection(s)}).on(E.Drag,s=>{this.continueMultipleSelection(s)}).on(E.End,s=>{this.finishMultipleSelection(s)})).call(this.zoomBehavior=T.zoom().on(at.Zoom,s=>{if(s.sourceEvent){if(!this.canUserPerformAction(C.Zoom)){A(M.NotAllowed);return}s.sourceEvent.type===I.Wheel&&s.sourceEvent.wheelDelta!==void 0?(s.sourceEvent.wheelDelta>0&&A(M.ZoomIn),s.sourceEvent.wheelDelta<0&&A(M.ZoomOut)):s.sourceEvent.type===I.MouseMove&&A(M.AllScroll)}this.zoomTransform=s.transform;const n=s.transform.toString();this.selectCanvasElements().attr("transform",n),T.select(`#${this.backgroundPatternId}`).attr("patternTransform",n),this.contextMenu.close()}).on(at.End,()=>{A()})),l=o.append("defs");if(this.gridSize>0&&isFinite(this.gridSize)){const s=l.append("pattern").attr("id",this.backgroundPatternId).attr("x",-this.gridSize/2).attr("y",-this.gridSize/2).attr("width",this.gridSize).attr("height",this.gridSize).attr("patternUnits","userSpaceOnUse");s.append("rect").attr("x",0).attr("y",0).attr("width",this.gridSize).attr("height",this.gridSize).attr("fill",this.backgroundColor),s.append("circle").attr("cx",this.gridSize/2).attr("cy",this.gridSize/2).attr("r",this.gridSize*this.gridThickness).attr("fill",this.gridColor),a.attr("fill",`url(#${this.backgroundPatternId})`)}o.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(),o=this.model.nodes.all(),a=Math.min(...o.map(m=>m.coords[0])),l=Math.max(...o.map(m=>m.coords[0]+m.width)),s=(a+l)/2,n=l-a,r=t.width,d=Math.min(...o.map(m=>m.coords[1])),c=Math.max(...o.map(m=>m.coords[1]+m.height)),h=(d+c)/2,g=c-d,b=t.height,f=Math.min(r/n,b/g,1);this.translateTo(s,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 o;const e=(o=this.selectSVGElement().node())==null?void 0:o.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 T.pointer(this.getEventHoldingCoordinates(e),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(e){return T.pointer(this.getEventHoldingCoordinates(e),this.selectSVGElement().node())}getPointerLocationRelativeToBody(e){return T.pointer(this.getEventHoldingCoordinates(e),T.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(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("g").attr("id",s=>s.id).attr("class",s=>`diagram-node${s.type.resizableX?" resizable-x":""}${s.type.resizableY?" resizable-y":""} ${s.type.defaultLook.lookType}`);e&&e.length>0&&(t=t.filter(s=>e.includes(s.id)));const l=a.merge(t);o.remove(),a.on(I.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(n)))}).on(I.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(r,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new F([n],n.selected))}).on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(n)),this.userSelection.add(n),this.diagramEvent$.next(new F([n],!0)),this.contextMenu.open(s))}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(s):this.startMovingNode(s,n)}).on(E.Drag,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(s):this.continueMovingNode(s,n)}).on(E.End,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(s):this.finishMovingNode(s,n),this.secondaryButton=!1})),ot(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${D}px`).on(I.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A(M.EWResize)}).on(I.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(A(M.EWResize),this.currentAction=new Y(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(s);n.stretch(k.Left,n.coords[0]-r[0])}}).on(E.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Left,n.coords[0]-r[0]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${D}px`).on(I.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A(M.NSResize)}).on(I.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(A(M.NSResize),this.currentAction=new Y(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(s);n.stretch(k.Top,n.coords[1]-r[1])}}).on(E.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Top,n.coords[1]-r[1]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${D}px`).on(I.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A(M.EWResize)}).on(I.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(A(M.EWResize),this.currentAction=new Y(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(s);n.stretch(k.Right,r[0]-(n.coords[0]+n.width))}}).on(E.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Right,r[0]-(n.coords[0]+n.width)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${D}px`).on(I.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A(M.NSResize)}).on(I.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(A(M.NSResize),this.currentAction=new Y(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed){const r=this.getPointerLocationRelativeToCanvas(s);n.stretch(k.Bottom,r[1]-(n.coords[1]+n.height))}}).on(E.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof Y&&this.currentAction.intent===C.StretchNode){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.stretch(k.Bottom,r[1]-(n.coords[1]+n.height)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}A()})),l.attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).attr("opacity",s=>s.removed?.5:1),nt(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",D/2).attr("x2",D/2).attr("y1",0).attr("y2",s=>s.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",s=>s.width).attr("y1",D/2).attr("y2",D/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",s=>s.width-D/2).attr("x2",s=>s.width-D/2).attr("y1",0).attr("y2",s=>s.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",s=>s.width).attr("y1",s=>s.height-D/2).attr("y2",s=>s.height-D/2)}updateSectionsInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("g").attr("id",s=>s.id).attr("class",s=>{var n,r,d,c,h;return`diagram-section${(r=(n=s.node)==null?void 0:n.type)!=null&&r.resizableX?" resizable-x":""}${(c=(d=s.node)==null?void 0:d.type)!=null&&c.resizableY?" resizable-y":""} ${(h=s.look)==null?void 0:h.lookType}`});e&&e.length>0&&(t=t.filter(s=>e.includes(s.id)));const l=a.merge(t);o.remove(),a.on(I.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(n)))}).on(I.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(d,!1))}const r=ke(n);this.userSelection.toggle(r),this.diagramEvent$.next(new F([r],r.selected))}).on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const d=ke(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new se(d)),this.userSelection.add(d),this.diagramEvent$.next(new F([d],!0)),this.contextMenu.open(s)}}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(s);else{const r=n==null?void 0:n.node;r?this.startMovingNode(s,r):A(M.NotAllowed)}}).on(E.Drag,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else{const r=n==null?void 0:n.node;r?this.continueMovingNode(s,r):A(M.NotAllowed)}}).on(E.End,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{const r=n==null?void 0:n.node;r?this.finishMovingNode(s,r):A()}this.secondaryButton=!1})),ot(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${D}px`).on(I.MouseOver,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&A(M.EWResize)}).on(I.MouseOut,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed?(A(M.EWResize),this.currentAction=new Y(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,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(s);n.node.stretchSections(k.Left,n.coords[0]-c[0],n.indexXInNode,n.indexYInNode)}}).on(E.End,(s,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 Y&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(s);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}A()})),a.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${D}px`).on(I.MouseOver,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&A(M.NSResize)}).on(I.MouseOut,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed?(A(M.NSResize),this.currentAction=new Y(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,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(s);n.node.stretchSections(k.Top,n.coords[1]-c[1],n.indexXInNode,n.indexYInNode)}}).on(E.End,(s,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 Y&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(s);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}A()})),a.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${D}px`).on(I.MouseOver,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&A(M.EWResize)}).on(I.MouseOut,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableX)&&!n.removed?(A(M.EWResize),this.currentAction=new Y(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,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(s);n.node.stretchSections(k.Right,c[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on(E.End,(s,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 Y&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(s);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}A()})),a.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${D}px`).on(I.MouseOver,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&A(M.NSResize)}).on(I.MouseOut,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed&&A()}).call(T.drag().on(E.Start,(s,n)=>{var r,d;this.canUserPerformAction(C.StretchSection)&&((d=(r=n.node)==null?void 0:r.type)!=null&&d.resizableY)&&!n.removed?(A(M.NSResize),this.currentAction=new Y(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(M.NotAllowed)}).on(E.Drag,(s,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(s);n.node.stretchSections(k.Bottom,c[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on(E.End,(s,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 Y&&this.currentAction.intent===C.StretchSection){let c=this.getPointerLocationRelativeToCanvas(s);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}A()})),l.attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).attr("opacity",s=>s.removed?.5:1),nt(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",D/2).attr("x2",D/2).attr("y1",0).attr("y2",s=>s.height),l.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",s=>s.width).attr("y1",D/2).attr("y2",D/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",s=>s.width-D/2).attr("x2",s=>s.width-D/2).attr("y1",0).attr("y2",s=>s.height),l.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",s=>s.width).attr("y1",s=>s.height-D/2).attr("y2",s=>s.height-D/2)}updatePortsInView(...e){let t=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("g").attr("id",s=>s.id).attr("class",s=>`diagram-port ${s.look.lookType}`);e&&e.length>0&&(t=t.filter(s=>e.includes(s.id)));const l=a.merge(t);o.remove(),a.on(I.MouseOver,(s,n)=>{var r,d,c,h,g,b,f,m,u,v,w,p;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(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(((b=(g=n.getNode())==null?void 0:g.type)==null?void 0:b.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(((w=(v=(u=this.unfinishedConnection.start)==null?void 0:u.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&((p=this.unfinishedConnection.start)!=null&&p.allowsIncoming)||A(M.NoDrop))}).on(I.MouseOut,()=>{this.unfinishedConnection&&A(M.Grabbing)}).on(I.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(d,!1))}const r=ke(n);this.userSelection.toggle(r),this.diagramEvent$.next(new F([r],r.selected))}).on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const d=ke(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new se(d)),this.userSelection.add(d),this.diagramEvent$.next(new F([d],!0)),this.contextMenu.open(s)}}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(s):this.canUserPerformAction(C.AddConnection)&&!n.removed?(A(M.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):A(M.NotAllowed)}).on(E.Drag,(s,n)=>{var r,d,c,h;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else if(this.canUserPerformAction(C.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const g=[s.x,s.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 b=(h=this.unfinishedConnectionTracer)==null?void 0:h.node();if(b){let f=2;const m=b.getTotalLength();m<f&&(f=0);const u=b.getPointAtLength(m-f);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=g;if(this.updateConnectionsInView(rt),this.model.ports.length>0){const f=this.getPointerLocationRelativeToCanvas(s);let m=Number.POSITIVE_INFINITY,u;for(const v of this.model.ports){const w=v.distanceTo(f);w<m&&(m=w,u=v)}u&&m<Es?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on(E.End,(s,n)=>{var r;if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{if(this.canUserPerformAction(C.AddConnection)&&!n.removed){(r=this.unfinishedConnectionTracer)==null||r.remove();const d=this.userHighlight.getFocus();if(d instanceof ve)this.finishConnection(d);else if(d instanceof ce&&d.rootElement instanceof ve)this.finishConnection(d.rootElement);else if(d instanceof j||d instanceof q||d instanceof ce){let c;if(d instanceof j||d instanceof q)c=d;else if(d.rootElement instanceof j||d.rootElement instanceof q)c=d.rootElement;else{this.dropConnection();return}const h=c.getClosestPortToPoint([s.x,s.y]);h!==void 0?this.finishConnection(h):this.dropConnection()}else this.dropConnection()}A()}this.secondaryButton=!1})),a.filter(".image-look").append("image"),ot(a),l.attr("transform",s=>`translate(${s.coords[0]-s.width/2},${s.coords[1]-s.width/2})`).attr("opacity",s=>s.removed?.5:1),nt(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 o=this.selectCanvasElements().selectAll("g.diagram-connection").data(t,n=>n.id);const a=o.exit(),l=o.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");e&&e.length>0&&(o=o.filter(n=>e.includes(n.id)));const s=l.merge(o);a.remove(),l.on(I.MouseOver,(n,r)=>{r.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new se(r)))}).on(I.Click,(n,r)=>{if(!n.ctrlKey&&!n.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(d,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new F([r],r.selected))}).on(I.ContextMenu,(n,r)=>{if(this.dragging){n.preventDefault(),n.stopPropagation(),this.dragging=!1;return}const d=new pe(n,r);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new se(r)),this.userSelection.add(r),this.diagramEvent$.next(new F([r],!0)),this.contextMenu.open(n))}).on(I.DoubleClick,(n,r)=>{const d=new me(n,r);this.diagramEvent$.next(d)}).call(T.drag().filter(n=>(this.secondaryButton=ye(n),!0)).on(E.Start,n=>{this.startMultipleSelection(n)}).on(E.Drag,n=>{this.continueMultipleSelection(n)}).on(E.End,n=>{this.finishMultipleSelection(n)})),l.append("path").attr("class","diagram-connection-path"),l.append("path").attr("class","diagram-connection-path-box"),l.append("marker").attr("id",n=>`${n.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),l.append("marker").attr("id",n=>`${n.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),l.append("g").attr("class","diagram-connection-start-label"),l.select("g.diagram-connection-start-label").append("path"),l.select("g.diagram-connection-start-label").append("text").style("user-select","none"),l.append("g").attr("class","diagram-connection-middle-label"),l.select("g.diagram-connection-middle-label").append("path"),l.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),l.append("g").attr("class","diagram-connection-end-label"),l.select("g.diagram-connection-end-label").append("path"),l.select("g.diagram-connection-end-label").append("text").style("user-select","none"),s.attr("opacity",n=>n.removed?.5:1).select("path.diagram-connection-path").attr("d",n=>{var r,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=>Zt(n.look.style,n.look.thickness)).attr("fill","none"),s.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+Is}px`).attr("stroke-dasharray",n=>Zt(n.look.style,n.look.thickness)).attr("fill","none"),s.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-field");e&&e.length>0&&(t=t.filter(s=>e.includes(s.id)));const l=a.merge(t);o.remove(),a.style("box-sizing","border-box").on(I.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new se(n)))}).on(I.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new F(d,!1))}const r=ke(n);this.userSelection.toggle(r),this.diagramEvent$.next(new F([r],r.selected))}).on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const d=ke(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new se(d)),this.userSelection.add(d),this.diagramEvent$.next(new F([d],!0)),this.contextMenu.open(s)}}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.EditField)&&n.editable&&!n.removed&&(this.currentAction=new ii(this,n.id,n.text,""),this.createInputField(n.text,n.coords,n.width,n.height,n.fontSize,n.fontFamily||V.fontFamily,d=>{n.text=d},d=>{n.text=d,this.currentAction instanceof ii&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof q&&(r=n.rootElement.node),r?this.startMovingNode(s,r):A(M.NotAllowed)}}).on(E.Drag,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof q&&(r=n.rootElement.node),r?this.continueMovingNode(s,r):A(M.NotAllowed)}}).on(E.End,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof q&&(r=n.rootElement.node),r?this.finishMovingNode(s,r):A()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),l.attr("x",0).attr("y",0).attr("width",s=>`${s.width}px`).attr("height",s=>`${s.height}px`).attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).attr("opacity",s=>s.removed?.5:1).select("div").style("justify-content",s=>s.horizontalAlign===Ee.Center?"center":s.horizontalAlign===Ee.Right?"flex-end":"flex-start").style("align-items",s=>s.verticalAlign===Fe.Center?"center":s.verticalAlign===Fe.Bottom?"end":"start").select("p").style("max-width",s=>s.fit?"default":"100%").style("max-height",s=>s.fit?"default":"100%").style("overflow",s=>s.fit?"default":"hidden").style("text-overflow",s=>s.fit?"default":"ellipsis").style("text-align",s=>s.horizontalAlign===Ee.Center?"center":s.horizontalAlign===Ee.Right?"end":"start").style("font-size",s=>`${s.fontSize}px`).style("font-family",s=>s.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",s=>s.highlighted?600:400).style("color",s=>s.selected?s.selectedColor||"#000000":s.color||"#000000").html(s=>s.text.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"))}updateObjectsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-object");e&&e.length>0&&(t=t.filter(s=>e.includes(s.id))),a.merge(t).attr("width",s=>`${s.width}px`).attr("height",s=>`${s.height}px`).attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).html(s=>s.html),o.remove(),a.on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.contextMenu.open(s))}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,s=>{this.startMultipleSelection(s)}).on(E.Drag,s=>{this.continueMultipleSelection(s)}).on(E.End,s=>{this.finishMultipleSelection(s)}))}updateDecoratorsInView(...e){let t=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=t.exit(),a=t.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-decorator");e&&e.length>0&&(t=t.filter(s=>e.includes(s.id))),a.merge(t).attr("width",s=>`${s.width}px`).attr("height",s=>`${s.height}px`).attr("transform",s=>`translate(${s.coords[0]},${s.coords[1]})`).html(s=>s.html),o.remove(),a.on(I.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new pe(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.contextMenu.open(s))}).on(I.DoubleClick,(s,n)=>{const r=new me(s,n);this.diagramEvent$.next(r)}).call(T.drag().filter(s=>(this.secondaryButton=ye(s),!0)).on(E.Start,s=>{this.startMultipleSelection(s)}).on(E.Drag,s=>{this.continueMultipleSelection(s)}).on(E.End,s=>{this.finishMultipleSelection(s)}))}updateConnectionLabelsInView(e){var s,n,r;const t=this.selectCanvasView().select(`g.diagram-connection#${e.id}`),a=t.select("path").node(),l={...V,...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=(s=t.select("g.diagram-connection-start-label text").node())==null?void 0:s.getBoundingClientRect();if(c){const b=e.startLabel?c.width/this.zoomTransform.k+Pe(l)+ze(l):0,f=e.startLabel?c.height/this.zoomTransform.k+Re(l)+Ne(l):0,m=a.getPointAtLength(Math.max(J(l)+b/2,de(l)+b/2,X(l)+f/2,oe(l)+f/2));t.select("g.diagram-connection-start-label path").attr("d",Ge(-b/2,-f/2,b,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 b=e.middleLabel?h.width/this.zoomTransform.k+Pe(l)+ze(l):0,f=e.middleLabel?h.height/this.zoomTransform.k+Re(l)+Ne(l):0,m=a.getPointAtLength(d/2);t.select("g.diagram-connection-middle-label path").attr("d",Ge(-b/2,-f/2,b,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 b=e.endLabel?g.width/this.zoomTransform.k+Pe(l)+ze(l):0,f=e.endLabel?g.height/this.zoomTransform.k+Re(l)+Ne(l):0,m=a.getPointAtLength(d-Math.max(J(l)+b/2,de(l)+b/2,X(l)+f/2,oe(l)+f/2));t.select("g.diagram-connection-end-label path").attr("d",Ge(-b/2,-f/2,b,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(`g.diagram-connection#${e.id}`),o=t.select("marker.diagram-connection-start-marker"),a=t.select("marker.diagram-connection-end-marker");e.startMarkerLook!==null?o.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):o.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)}fitFieldRootInView(e){var o,a,l;const t=this.model.fields.get(e);if(t){if(t.rootElement instanceof j&&t.fit){const s=this.minimumSizeOfField(t);let n=s[0]+J(t.rootElement.type.label)+de(t.rootElement.type.label)-t.rootElement.width,r=s[1]+X(t.rootElement.type.label)+oe(t.rootElement.type.label)-t.rootElement.height;this.snapToGrid&&(n=Math.ceil(n/this.gridSize)*this.gridSize,r=Math.ceil(r/this.gridSize)*this.gridSize),t.rootElement.width+n<t.rootElement.type.minWidth&&(n=t.rootElement.type.minWidth-t.rootElement.width),t.rootElement.height+r<t.rootElement.type.minHeight&&(r=t.rootElement.type.minHeight-t.rootElement.height),t.rootElement.stretch(k.Right,n),t.rootElement.stretch(k.Bottom,r)}if(t.rootElement instanceof q&&t.fit){const s=this.minimumSizeOfField(t);let n=s[0],r=s[1];for(const g of((o=t.rootElement.node)==null?void 0:o.sections)||[])g.label&&(g.indexXInNode===t.rootElement.indexXInNode&&g.indexYInNode!==t.rootElement.indexYInNode?n=Math.max(n,this.minimumSizeOfField(g.label)[0]):g.indexXInNode!==t.rootElement.indexXInNode&&g.indexYInNode===t.rootElement.indexYInNode&&(r=Math.max(r,this.minimumSizeOfField(g.label)[1])));s[0]<n&&(s[0]=n),s[1]<r&&(s[1]=r);const d=t.rootElement.type;let c=s[0]+J(d==null?void 0:d.label)+de(d==null?void 0:d.label)-t.rootElement.width,h=s[1]+X(d==null?void 0:d.label)+oe(d==null?void 0:d.label)-t.rootElement.height;this.snapToGrid&&(c=Math.ceil(c/this.gridSize)*this.gridSize,h=Math.ceil(h/this.gridSize)*this.gridSize),t.rootElement.width+c<(t.rootElement.getMinWidth()||0)&&(c=(t.rootElement.getMinWidth()||0)-t.rootElement.width),t.rootElement.height+h<(t.rootElement.getMinHeight()||0)&&(h=(t.rootElement.getMinHeight()||0)-t.rootElement.height),(a=t.rootElement.node)==null||a.stretchSections(k.Right,c,t.rootElement.indexXInNode,t.rootElement.indexYInNode),(l=t.rootElement.node)==null||l.stretchSections(k.Bottom,h,t.rootElement.indexXInNode,t.rootElement.indexYInNode)}}}fitNodeInView(e){var o,a;const t=this.model.nodes.get(e);if(t&&t.sections.length>0&&this.priorityThreshold){let l=0,s=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),s=Math.max(s,d)}l+=((o=t.type.sectionGrid)==null?void 0:o.margin)||0,s+=((a=t.type.sectionGrid)==null?void 0:a.margin)||0,t.stretch(k.Right,l-t.width),t.stretch(k.Bottom,s-t.height)}}selectRoot(){return T.select(this.diagramRoot)}selectSVGElement(){return T.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,o,a,l;if(e.allowsOutgoing||e.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(((o=(t=e.getNode())==null?void 0:t.type)==null?void 0:o.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 le(this.model,this.connectionType,e,void 0,rt);else if(this.inferConnectionType){let s=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)||"")});s===void 0&&(s=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)||"")})),s!==void 0&&(this.unfinishedConnection=new le(this.model,s,e,void 0,rt))}}}finishConnection(e){var t,o,a,l,s,n,r,d,c,h,g,b,f,m,u,v,w,p,S,x;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0)if(this.unfinishedConnection.start!==e)if(this.unfinishedConnection.type.canStartFromType(((l=(a=(o=(t=this.unfinishedConnection)==null?void 0:t.start)==null?void 0:o.getNode())==null?void 0:a.type)==null?void 0:l.id)||"")&&((n=(s=this.unfinishedConnection)==null?void 0:s.start)!=null&&n.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((d=(r=e.getNode())==null?void 0:r.type)==null?void 0:d.id)||"")&&e.allowsIncoming){const L=new it(this,this.unfinishedConnection.type,(c=this.unfinishedConnection.start)==null?void 0:c.id,e.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.unfinishedConnection.type.canFinishOnType(((f=(b=(g=(h=this.unfinishedConnection)==null?void 0:h.start)==null?void 0:g.getNode())==null?void 0:b.type)==null?void 0:f.id)||"")&&((u=(m=this.unfinishedConnection)==null?void 0:m.start)!=null&&u.allowsIncoming)&&this.unfinishedConnection.type.canStartFromType(((w=(v=e.getNode())==null?void 0:v.type)==null?void 0:w.id)||"")&&e.allowsOutgoing){const L=new it(this,this.unfinishedConnection.type,e.id,(p=this.unfinishedConnection.start)==null?void 0:p.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.inferConnectionType){let L=this.model.connections.types.all().find(N=>{var H,P,R,Z,_,U,O,W;return N.canStartFromType(((Z=(R=(P=(H=this.unfinishedConnection)==null?void 0:H.start)==null?void 0:P.getNode())==null?void 0:R.type)==null?void 0:Z.id)||"")&&((U=(_=this.unfinishedConnection)==null?void 0:_.start)==null?void 0:U.allowsOutgoing)&&N.canFinishOnType(((W=(O=e.getNode())==null?void 0:O.type)==null?void 0:W.id)||"")&&e.allowsIncoming}),z=!1;if(L===void 0&&(L=this.model.connections.types.all().find(N=>{var H,P,R,Z,_,U,O,W;return N.canFinishOnType(((Z=(R=(P=(H=this.unfinishedConnection)==null?void 0:H.start)==null?void 0:P.getNode())==null?void 0:R.type)==null?void 0:Z.id)||"")&&((U=(_=this.unfinishedConnection)==null?void 0:_.start)==null?void 0:U.allowsIncoming)&&N.canStartFromType(((W=(O=e.getNode())==null?void 0:O.type)==null?void 0:W.id)||"")&&e.allowsOutgoing}),z=!0),L!==void 0){const N=new it(this,L,z?e.id:(S=this.unfinishedConnection.start)==null?void 0:S.id,z?(x=this.unfinishedConnection.start)==null?void 0:x.id:e.id);this.dropConnection(),N.do(),this.actionStack.add(N)}else this.dropConnection()}else this.dropConnection();else this.dropConnection()}dropConnection(){var e,t,o,a;(e=this.unfinishedConnection)==null||e.setStart(void 0),(t=this.unfinishedConnection)==null||t.setEnd(void 0),(a=(o=this.unfinishedConnection)==null?void 0:o.select())==null||a.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(e){return this.userActions[e]!==!1}createInputField(e,t,o,a,l,s,n,r){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${t[0]}px`).attr("y",`${t[1]}px`).attr("width",`${o}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",`${o}px`).style("height",`${a}px`).style("font-size",`${l}px`).style("font-family",s).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(I.KeyDown,f=>{f.stopPropagation()}).on(I.KeyUp,f=>{if(f.stopPropagation(),f.key===ee.Escape){const m=c.property("value");this.removeInputField(),r&&r(m)}}).on(I.Input,()=>{const f=c.property("value");c.attr("cols",Oi(f)+1),c.attr("rows",Di(f)+1),c.style("width",""),c.style("height",""),h=c.property("scrollWidth")+1,g=c.property("scrollHeight")+1;const m=Math.max(h,o),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(I.Click,f=>{f.stopPropagation()}).on(I.FocusOut,()=>{const f=c.property("value");this.removeInputField(),r&&r(f)});const b=c.node();b.focus(),b.select()}removeInputField(){var e,t,o;(t=(e=this.inputFieldContainer)==null?void 0:e.select("input"))==null||t.on(I.Blur,null),(o=this.inputFieldContainer)==null||o.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 o=t.getBoundingClientRect();return[o.width/this.zoomTransform.k,o.height/this.zoomTransform.k]}startMovingNode(e,t){if(this.canUserPerformAction(C.MoveNode)&&!t.removed)if(A(M.Grabbing),this.draggingFrom=[e.x,e.y],t.selected&&this.userSelection.count(o=>o instanceof j)>1)this.currentAction=new tt(this,this.userSelection.filter(o=>o instanceof j).map(o=>o.id),t.coords);else{const o=t.getLastAncestor();this.currentAction=new Y(this,C.MoveNode,t.id,t.getGeometry(),t.getGeometry(),o==null?void 0:o.id,o==null?void 0:o.getGeometry(t.id),o==null?void 0:o.getGeometry(t.id))}else A(M.NotAllowed)}continueMovingNode(e,t){if(this.canUserPerformAction(C.MoveNode)&&(this.currentAction instanceof tt||this.currentAction instanceof Y)&&!t.removed){const o=[e.x-t.width/2,e.y-t.height/2];t.selected?this.userSelection.move([o[0]-t.coords[0],o[1]-t.coords[1]]):t.move(o),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(e,t){var o,a,l;if(this.canUserPerformAction(C.MoveNode)&&!t.removed&&(this.draggingFrom[0]!==e.x||this.draggingFrom[1]!==e.y)){let s=[e.x-t.width/2,e.y-t.height/2];if(this.snapToGrid&&(s=this.getClosestGridPoint(s)),this.currentAction instanceof tt){const n=this.currentAction.delta;this.currentAction.delta=[s[0]-n[0],s[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 Y){t.move(s);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=fi(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,b=new hs(this,t.id,(o=t.parent)==null?void 0:o.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),b.toChildGeometry=t.getGeometry(t.id),b.toAncestorGeometry=h==null?void 0:h.getGeometry(t.id),this.currentAction=b}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)}A(),this.dragging=!1}startMultipleSelection(e){this.draggingFrom=this.getPointerLocationRelativeToCanvas(e),this.multipleSelectionContainer=this.selectCanvasElements().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(e){var o,a,l,s;const t=this.getPointerLocationRelativeToCanvas(e);(this.draggingFrom[0]!==t[0]||this.draggingFrom[1]!==t[1])&&(A(M.Crosshair),(s=(l=(a=(o=this.multipleSelectionContainer)==null?void 0:o.attr("x",Math.min(this.draggingFrom[0],t[0])))==null?void 0:a.attr("y",Math.min(this.draggingFrom[1],t[1])))==null?void 0:l.attr("width",Math.abs(this.draggingFrom[0]-t[0])))==null||s.attr("height",Math.abs(this.draggingFrom[1]-t[1])),this.dragging=!0)}finishMultipleSelection(e){var o;const t=this.getPointerLocationRelativeToCanvas(e);(o=this.multipleSelectionContainer)==null||o.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)Ti([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 F(this.userSelection.all(),!0)),A()}};Ue.canvasCount=0;let ct=Ue;class ki{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 o=1;;++o){const a=o%2>0?o:-o,l=a>0?1:-1,s=[t[0]+a,t[1]+a];for(let n=t[0];n!==s[0]+l;n+=l)if(t[0]=n,this.get(t)===void 0)return t;for(let n=t[1];n!==s[1]+l;n+=l)if(t[1]=n,this.get(t)===void 0)return t}}}class Ts{apply(e){var n;if(e.nodes.length===0)return e;const t=new ki,o=e.nodes.filter(r=>!r.parent);for(;o.length>0;)wi(o[0],t,[0,0],o);const a=Math.max(...e.nodes.map(r=>r.width)),l=Math.max(...e.nodes.map(r=>r.height)),s=(((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+s),r*(l+s)])}return e}}const wi=(i,e,t,o)=>{const a=e.getClosestEmptyCoordinate(t);e.set(a,i),B(o,i);for(const l of i.getAdjacentNodes())o.includes(l)&&wi(l,e,a,o)};class $s{apply(e){var c;if(e.nodes.length===0)return e;const t=new ki,o=e.nodes.filter(h=>!h.parent),a={},l=o[0];let s=[l];for(a[l.id]=[0,0];o.length>0;){const h=[];for(const g of s){t.set(t.getClosestEmptyCoordinate(a[g.id]),g),B(o,g);const b=g.getAdjacentNodes();for(const f of b)o.includes(f)&&(h.push(f),a[f.id]=a[g.id])}if(h.length>0)s=h;else if(o.length>0){const g=o[0];s=[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=(((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 b=t.get([g,h]);b!==void 0&&b.move([g*(n+d),h*(r+d)])}return e}}class Qe{apply(e){var n;if(e.nodes.length===0)return e;const t=(((n=e.canvas)==null?void 0:n.gridSize)||0)*2;let o=e.nodes.filter(r=>!r.parent);const a=o[0];B(o,a);const l=[[a]];for(;o.length>0;){const r=l[l.length-1],d=[];for(const c of r){const h=c.getAdjacentNodes();for(const g of h)o.includes(g)&&(B(o,g),d.push(g))}d.length>0?l.push(d):(l.push(o),o=[])}let s=0;for(const r of l){let d=0;for(const h of r)h.move([s,d]),d+=t+h.height;const c=Math.max(...r.map(h=>h.width));s+=t+c}for(const r of e.connections)r.tighten();return e}}class Ms{apply(e){var h;if(e.nodes.length===0)return e;new Qe().apply(e);const t=(((h=e.canvas)==null?void 0:h.gridSize)||0)*2,o=.99,a=1,l=.1,s=2e5,n=.5,r=1,d=.002;let c=100;for(;c>a;){c=c*o;const g=[0,0];{for(const b of e.nodes)g[0]=g[0]+b.coords[0]+b.width/2,g[1]=g[1]+b.coords[1]+b.width/2;g[0]=g[0]/e.nodes.length,g[1]=g[1]/e.nodes.length}for(const b of e.nodes){const f=b.getAdjacentNodes();for(const m of e.nodes){const u=[b.coords[0]+b.width/2,b.coords[1]+b.height/2],v=[m.coords[0]+m.width/2,m.coords[1]+m.height/2],w=ni(b.coords,m.coords),p=[m.coords[0],m.coords[1]];if(f.includes(m)&&w>0&&(w>t+(Math.max(b.width,b.height)+Math.max(m.width,m.height))/2?(p[0]=p[0]-(v[0]-u[0])*l,p[1]=p[1]-(v[1]-u[1])*l):(p[0]=p[0]+(v[0]-u[0])*n,p[1]=p[1]+(v[1]-u[1])*n)),w>0){const S=s/(w*w);p[0]=p[0]+S*(v[0]-u[0])/w,p[1]=p[1]+S*(v[1]-u[1])/w}else p[0]=p[0]+r*(Math.random()*2-1),p[1]=p[1]+r*(Math.random()*2-1);p[0]=p[0]-(v[0]-g[0])*d,p[1]=p[1]-(v[1]-g[1])*d,p[0]-m.coords[0]>c?p[0]=m.coords[0]+c:p[0]-m.coords[0]<-c&&(p[0]=m.coords[0]-c),p[1]-m.coords[1]>c?p[1]=m.coords[1]+c:p[1]-m.coords[1]<-c&&(p[1]=m.coords[1]-c),m.move(p)}}}if(e.canvas&&e.canvas.snapToGrid)for(const g of e.nodes){const b=e.canvas.getClosestGridPoint(g.coords);g.move(b)}for(const g of e.connections)g.tighten();return e}}class Ns{apply(e){var l;if(e.nodes.length===0)return e;const t=(((l=e.canvas)==null?void 0:l.gridSize)||0)*2,o=e.nodes.filter(s=>!s.parent);o.sort((s,n)=>n.type.priority-s.type.priority);let a=0;for(const s of o)s.move([a,0]),a+=s.width+t;return e}}class Ps{apply(e){var c;if(e.nodes.length===0)return e;const t=Math.max(...e.nodes.map(h=>h.getPriority())),o=Math.min(...e.nodes.map(h=>h.getPriority()));if(t===o)return new Qe().apply(e),e;const a=(((c=e.canvas)==null?void 0:c.gridSize)||0)*2,l=e.nodes.filter(h=>!h.parent),s=[],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],b=[h];for(;g.length>0;){const f=g[0];g.splice(0,1),n.includes(f)&&(r.push(f),B(n,f));const m=f.getAdjacentNodes();for(const u of m)b.includes(u)||(g.push(u),b.push(u))}for(const f of n)r.push(f)}else r.push(n[0]);for(const h of r)B(l,h),s.push([h]);for(s.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],b=[h];let f=!1;for(;g.length>0;){const m=g[0];g.splice(0,1);const u=r.indexOf(m);if(u>=0){s[u].push(h),f=!0;break}else{const v=m.getAdjacentNodes();for(const w of v)b.includes(w)||(g.push(w),b.push(w))}}f||s[s.length-1].push(h)}let d=0;for(let h=0;h<s.length;++h){let g=0;for(let f=0;f<s[h].length;++f){const m=s[h][f];m.move([d,g]),g+=a+m.height}const b=Math.max(...s[h].map(f=>f.width));d+=a+b}for(const h of e.connections)h.tighten();return e}}class zs{apply(e){var c;if(e.nodes.length===0)return e;const t=Math.max(...e.nodes.map(h=>h.getPriority())),o=Math.min(...e.nodes.map(h=>h.getPriority()));if(t===o)return new Qe().apply(e),e;const a=(((c=e.canvas)==null?void 0:c.gridSize)||0)*2,l=e.nodes.filter(h=>!h.parent).sort((h,g)=>g.getPriority()-h.getPriority()),s=[];for(;l.length>0;){const h=l[0];l.splice(0,1);const g=new ut(void 0,h);xi(g,l),s.push(g)}const n=[];for(const h of s)n.push([h]),Ci(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 b=Math.max(...n[h].map(f=>f.node.width));d+=a+b}for(const h of e.connections)h.tighten();return e}}const xi=(i,e)=>{for(const t of i.node.getAdjacentNodes().sort((o,a)=>a.getPriority()-o.getPriority())){const o=e.indexOf(t);if(o>=0){e.splice(o,1);const a=i.addBranch(t);xi(a,e)}}},Ci=(i,e,t)=>{if(i.branches.length>0){for(;t>=e.length;)e.push([]);for(const o of i.branches)e[t].push(o),Ci(o,e,t+1)}};class ut{constructor(e,t){this.parent=e,this.branches=[],this.depth=0,this.node=t}addBranch(e){const t=new ut(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 Rs{apply(e){var l;if(e.nodes.length===0)return e;const t=(((l=e.canvas)==null?void 0:l.gridSize)||0)*2,o=e.nodes.filter(s=>!s.parent);o.sort((s,n)=>n.type.priority-s.type.priority);let a=0;for(const s of o)s.move([0,a]),a+=s.height+t;return e}}const si={adjacency:new Ts,breadth:new Qe,"breadth-adjacency":new $s,force:new Ms,horizontal:new Ns,priority:new Ps,tree:new zs,vertical:new Rs},Vs=$.createContext({}),Ce=$.createContext({});class js{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 ft=({direction:i,collapsableSelector:e,collapsableAdditionalSelector:t,collapsed:o,disabled:a,rule:l,collapsedValue:s,visibleValue:n,onCollapse:r})=>{const[d,c]=$.useState(o),h=()=>{if(!a){const b=!d;c(b),r==null||r(b);let f;if(typeof e=="string")f=T.select(e),t&&(f=f.select(t));else{const m=e;if(!m)throw new Error("collapsableSelector is not a valid ref");f=T.select(m.current),t&&(f=f.select(t))}f.style(l,b?s: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()})})})},_s=()=>{const i=$.useContext(Ce),e=$.useRef(null),[t,o]=$.useState([]);we.merge(i.validatorChange$,i.diagramChange$).pipe(we.map(()=>a())).subscribe();const a=()=>{o([]);for(const s of i.validators){const n=s.validate(i.model);o(n)}},l=s=>{var n,r,d,c;if(s.elementId&&(s.propertyNames===void 0||s.propertyNames.length===0)){const h=i.model.nodes.get(s.elementId)||i.model.connections.get(s.elementId);h&&i.userHighlight.add(h)}else if(s.elementId&&s.propertyNames!==void 0&&s.propertyNames.length>0){i.userSelection.openInPropertyEditor(i.model.nodes.get(s.elementId)||i.model.connections.get(s.elementId));const h=i.model.nodes.get(s.elementId)||i.model.connections.get(s.elementId);h&&i.userHighlight.add(h),(r=(n=i.parentComponent)==null?void 0:n.propertyEditor)==null||r.highlightProperty(...s.propertyNames)}else!s.elementId&&s.propertyNames!==void 0&&s.propertyNames.length>0&&(i.userSelection.openInPropertyEditor(),(c=(d=i.parentComponent)==null?void 0:d.propertyEditor)==null||c.highlightProperty(...s.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(ft,{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((s,n)=>y.jsx("li",{onClick:()=>l(s),dangerouslySetInnerHTML:{__html:s.message}},n))})})]})})},Os=200,oi=i=>(i||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),Si=({disabled:i,options:e,value:t,onChange:o})=>{const a=$.useRef(null),[l,s]=$.useState("");let n;const[r,d]=$.useState([]),[c,h]=$.useState([]),[g,b]=$.useState([]),[f,m]=$.useState([]),[u,v]=$.useState(!1);$.useEffect(()=>{var P;s(((P=e.find(R=>xe(R.key,t)))==null?void 0:P.label)||"")},[t,e]);const w=P=>{if(!i)switch(P.key){case ee.PageDown:n===void 0?(x(0),z(0)):(x(n+5),z(n)),P.preventDefault();break;case ee.ArrowDown:n===void 0?(x(0),z(0)):(x(n+1),z(n)),P.preventDefault();break;case ee.PageUp:n===void 0?(x(e.length-1),z(e.length-1)):(x(n-5),z(n)),P.preventDefault();break;case ee.ArrowUp:n===void 0?(x(e.length-1),z(e.length-1)):(x(n-1),z(n)),P.preventDefault();break;case ee.Escape:S(),P.preventDefault();break;case ee.Enter:H(e[n||0]),P.preventDefault();break;default:p()}},p=()=>{if(!i){const P=oi(l.trim());d([]),h([]),b([]),m([]);for(const R of e){const _=oi(R.label).indexOf(P);if(_>=0){const U=R.label.substring(0,_),O=R.label.substring(_,_+P.length),W=R.label.substring(_+P.length);d(ne=>[...ne,R]),h(ne=>[...ne,U]),b(ne=>[...ne,O]),m(ne=>[...ne,W])}}v(!0)}},S=()=>{v(!1)},x=P=>{if(!i){if(n=P,P===void 0)return;P<0&&(n=0),P>=e.length&&(n=e.length-1)}},L=()=>{setTimeout(()=>{S()},Os)},z=P=>{var Z;const R=(Z=a.current)==null?void 0:Z.querySelectorAll("li")[P];R&&R.scrollIntoView({block:"center"})},N=()=>{i||(s(""),v(!1),n=void 0)},H=P=>{i||(s(P.label),v(!1),n=void 0,o(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:w,onFocus:p,onBlur:L,onChange:P=>s(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:()=>x(R),onClick:()=>H(P),children:[y.jsx("span",{children:c[R]}),y.jsx("span",{className:"daga-match",children:g[R]}),y.jsx("span",{children:f[R]})]},R))]})})]})},Ds=(i,e)=>{var t;return((t=i.find(o=>o.key===e))==null?void 0:t.label)||`${e}`},Hs=({disabled:i,allowRepeats:e,options:t,value:o,onChange:a})=>{const[l,s]=$.useState(),[n,r]=$.useState([]),[d,c]=$.useState([]);$.useEffect(()=>{const u=o.length===0,v=o.map(w=>Ds(t,w));r(v),u&&a(o),m()},[o,t]);const h=u=>{for(const v of o)if(v===u)return!0;return!1},g=u=>{o.length>u&&(o.splice(u,1),r(n.filter((v,w)=>w!==u)),a(o),m())},b=()=>{l!==void 0&&(e||!h(l))&&(a(o.concat(l)),f())},f=()=>{s("")},m=()=>{if(!e){const u=[];for(const v of t)h(v.key)||u.push(v);c(u)}};return y.jsxs("div",{children:[o.map((u,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:()=>g(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(Si,{disabled:i,options:e?t||[]:d||[],value:l,onChange:s})}),y.jsx("button",{className:"daga-property-button",onClick:b,children:y.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Gs=({disabled:i,allowRepeats:e,value:t,onChange:o})=>{const[a,l]=$.useState(""),s=g=>{for(const b of g||[])if(b===g)return!0;return!1},n=g=>{t.length>g&&o(t.filter((b,f)=>f!==g))},r=(g,b,f)=>{const m=t.map((u,v)=>v===b?f==="blur"?g.trim():g:u);o(m)},d=()=>{const g=a.trim();g!==""&&(e||!s(g))&&(o(t.concat(g)),c())},c=()=>{l("")},h=g=>{g.key==="Enter"&&d()};return y.jsxs(y.Fragment,{children:[t.map((g,b)=>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,b,"change"),onBlur:f=>r(f.target.value,b,"blur")}),y.jsx("button",{className:"daga-property-button",onClick:()=>n(b),children:y.jsx("div",{className:"daga-icon daga-close-icon"})})]},b)),!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"})})]})]})},Fs=({disabled:i,value:e,onChange:t})=>{const[o,a]=$.useState(""),[l,s]=$.useState(""),[n,r]=$.useState({}),d=u=>{const v={};Object.keys(e).forEach(w=>{w!==u&&(v[w]=e[w])}),t(v)},c=(u,v,w)=>{const p=w==="blur"?v.trim():v;if(w==="blur"){if(u!==p){const S={};Object.keys(e).forEach(x=>{x===u?S[p]=e[x]:S[x]=e[x]}),t(S),r(x=>{const L={...x};return delete L[u],L})}}else r(S=>({...S,[u]:v}))},h=(u,v,w)=>{const p=w==="blur"?v.trim():v;if(p!==""){const S={};Object.keys(e).forEach(x=>{x===u?S[x]=p:S[x]=e[x]}),t(S)}},g=()=>{const u=o.trim(),v=l.trim();if(u!==""&&v!==""){const w={};Object.keys(e).forEach(p=>{w[p]=e[p]}),w[u]=v,t(w),a(""),s("")}},b=()=>{a("")},f=()=>{s("")},m=u=>{u.key==="Enter"&&g()};return y.jsxs("div",{children:[Object.entries(e).map(([u,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[u]??u,onChange:p=>c(u,p.target.value,"change"),onBlur:p=>c(u,p.target.value,"blur")}),y.jsx("input",{id:`value-${w}`,className:"daga-input",type:"text",disabled:i,value:v,onChange:p=>h(u,p.target.value,"change"),onBlur:p=>h(u,p.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:o,onKeyUp:m,onChange:u=>a(u.target.value),onBlur:u=>c(o,u.target.value,"blur")}),y.jsx("button",{className:"daga-clear",onClick:b})]}),y.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[y.jsx("input",{type:"text",value:l,onKeyUp:m,onChange:u=>s(u.target.value),onBlur:u=>h(o,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"})})]})]})},Ai=({valueSet:i,onValueChange:e,depth:t})=>{var r;const a=$.useContext(Ce).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,""),s=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===G.Text&&y.jsx("input",{type:"daga-text",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.TextArea&&y.jsx("textarea",{disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Number&&y.jsx("input",{type:"number",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Color&&y.jsx("input",{type:"text",pattern:"#\\d{6}",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Datetime&&y.jsx("input",{type:"datetime-local",disabled:!d.editable||!a,value:s(i==null?void 0:i.getValue(d.name)),onChange:c=>e(d,n(c.target.value))}),d.type===G.Date&&y.jsx("input",{type:"date",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Time&&y.jsx("input",{type:"time",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Url&&y.jsx("input",{type:"url",disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c.target.value)}),d.type===G.Boolean&&y.jsxs("div",{className:"daga-radio",children:[y.jsxs("label",{className:"daga-radio-item daga-radio-start",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(d,!1)}),"No"]}),y.jsxs("label",{className:"daga-radio-item daga-radio-end",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(d,!0)}),"Yes"]})]}),d.type===G.Option&&y.jsx("div",{className:"daga-relatively-positioned",children:y.jsx(Si,{disabled:!d.editable||!a,options:d.options||[],value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c)})}),(d.type===G.OptionList||d.type===G.OptionSet)&&y.jsx(Hs,{disabled:!d.editable||!a,allowRepeats:d.type===G.OptionList,options:d.options||[],value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c)}),(d.type===G.TextList||d.type===G.TextSet)&&y.jsx(Gs,{disabled:!d.editable||!a,allowRepeats:d.type===G.TextList,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c)}),d.type===G.TextMap&&y.jsx(Fs,{disabled:!d.editable||!a,value:i==null?void 0:i.getValue(d.name),onChange:c=>e(d,c)}),d.type===G.Object&&y.jsx("div",{className:"daga-left-bar",children:y.jsx(Ai,{valueSet:i.getSubValueSet(d.name),onValueChange:e,depth:t+1})})]},d.name))})},Ii=({valueSet:i,depth:e})=>{const t=$.useContext(Ce),o=$.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=T.select(o.current).select(`.daga-property.${a(r.name)}.daga-depth-${e}`);g.select("button.daga-move-button").call(T.drag().on(E.Start,b=>{var u;A(M.Grabbing);const f=t.getPointerLocationRelativeToScreen(b);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(E.Drag,b=>{A(M.Grabbing);const f=t.getPointerLocationRelativeToScreen(b);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),T.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${e}`).style("visibility","hidden").style("height",0),h=s(f),T.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${e}`).style("visibility","visible").style("height","0.25rem"))}).on(E.End,b=>{var m,u;A(M.Auto),g.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),T.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${e}`).style("visibility","hidden").style("height",0);const f=t.getPointerLocationRelativeToScreen(b);f.length<2||isNaN(f[0])||isNaN(f[1])||(h=s(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))}))}},s=r=>{var h;const d=(i==null?void 0:i.propertySet.propertyList)||[],c=[];for(let g=0;g<=d.length;++g){const b=(h=T.select(o.current).select(`.daga-dropbar.daga-index-${g}.daga-depth-${e}`).node())==null?void 0:h.getBoundingClientRect();b&&c.push([b.x+b.width/2,b.y+b.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 Ui?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:o,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!==G.Object&&y.jsx("div",{className:"daga-property-value",children:Bs(i==null?void 0:i.getValue(r.name))}),r.type===G.Object&&y.jsx(Ii,{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))]})},Bs=i=>Array.isArray(i)?i.join(", "):Yi(i)?Object.entries(i).map(e=>e.map(t=>JSON.stringify(t)).join(": ")).join(", "):i instanceof Date?i.toLocaleString():i==null?"":""+i,Us=({location:i,direction:e,width:t,title:o,valueSet:a,onValueChange:l})=>{const s=$.useRef(null),[n,r]=$.useState(!1),[d,c]=$.useState(!1),h=()=>T.select(s.current);return $.useEffect(()=>{if(s.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:s,className:`daga-panel daga-bottom daga-${i} daga-${e}`,children:[y.jsx(ft,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:n,direction:e,collapsableSelector:s,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:[o&&y.jsxs("p",{className:"daga-title",children:[o,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(Ai,{valueSet:a,onValueChange:l,depth:0}),d&&y.jsx(Ii,{valueSet:a,depth:0})]})]})})},Ys=i=>{const e=$.useContext(Ce),[t,o]=$.useState(i.currentPalette||i.palettes[0]),[a,l]=$.useState(0),[s,n]=$.useState(void 0),r=$.useRef(null),d=m=>{if(o(m),c().selectAll("*").remove(),l(e.getPriorityThreshold()||0),m.categories&&h(m.categories),m.templates)for(const u of m.templates)g(u)},c=()=>T.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 v in m)u.append("option").attr("value",v).text(v);u.on(I.Change,()=>{s&&c().selectAll(".daga-template-container.daga-in-category").remove();const v=u.property("value");n(v);const w=m[v]||[];for(const p of w)g(p,"daga-in-category")}),s&&(u.property("value",s),u.dispatch(I.Change))},g=(m,u)=>{if(m.templateType==="node"){const v=e.model.nodes.types.get(m.type);v?b(v,m,u):console.error(`Could not find a node type called '${m.type}'`)}else if(m.templateType==="connection"){const v=e.model.connections.types.get(m.type);v?f(v,m,u):console.error(`Could not find a connection type called '${m.type}'`)}},b=(m,u,v)=>{if(a!==void 0&&m.priority<a)return;const w=c().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${m.defaultWidth}px`).style("height",`${m.defaultHeight}px`).call(T.drag().on(E.Drag,S=>{if(e.canUserPerformAction(C.AddNode)){const x=e.getPointerLocationRelativeToScreen(S);if(x.length<2||isNaN(x[0])||isNaN(x[1]))return;w.style("position","fixed").style("left",`${x[0]-m.defaultWidth/2}px`).style("top",`${x[1]-m.defaultHeight/2}px`).style("z-index",1)}}).on(E.Start,S=>{if(e.canUserPerformAction(C.AddNode)){A(M.Grabbing);const x=e.getPointerLocationRelativeToScreen(S);if(x.length<2||isNaN(x[0])||isNaN(x[1]))return;w.style("position","fixed").style("left",`${x[0]-m.defaultWidth/2}px`).style("top",`${x[1]-m.defaultHeight/2}px`).style("z-index",1),m.isUnique&&e.model.nodes.find(L=>!L.removed&&L.type.id===m.id)!==void 0&&A(M.NotAllowed)}}).on(E.End,S=>{var x;if(e.canUserPerformAction(C.AddNode)){if(A(M.Auto),w.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),m.isUnique&&e.model.nodes.find(W=>!W.removed&&W.type.id===m.id)!==void 0)return;const L=e.getPointerLocationRelativeToScreen(S);if(L.length<2||isNaN(L[0])||isNaN(L[1]))return;const z=document.elementFromPoint(L[0],L[1]);if(z&&!((x=e.selectCanvasView().node())!=null&&x.contains(z)))return;const N=e.getPointerLocationRelativeToCanvas(S);if(N.length<2||isNaN(N[0])||isNaN(N[1]))return;let H=[N[0]-m.defaultWidth/2,N[1]-m.defaultHeight/2];e.snapToGrid&&(H=e.getClosestGridPoint(H));const R=e.model.nodes.getAtCoordinates(N[0],N[1]).filter(W=>W.type.childrenTypes.includes(m.id)),Z=fi(R),_=Z[Z.length-1];if(!m.canBeParentless&&_===void 0)return;const U=_==null?void 0:_.getLastAncestor(),O=new cs(e,m,H,_==null?void 0:_.id,U==null?void 0:U.id,U==null?void 0:U.getGeometry(),void 0,u.label,u.values);O.do(),e==null||e.actionStack.add(O),A()}})).append("svg").attr("class",`palette-node ${m.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%"),p=u.look||m.defaultLook;switch(p.lookType){case"shaped-look":w.append("path").attr("d",lt(p.shape,0,0,m.defaultWidth,m.defaultHeight)).attr("fill",p.fillColor).attr("stroke",p.borderColor).attr("stroke-width",`${p.borderThickness}px`);break;case"image-look":w.append("image").attr("x",0).attr("y",0).attr("width",m.defaultWidth).attr("height",m.defaultHeight).attr("href",p.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":w.append("image").attr("x",0).attr("y",0).attr("width",p.leftMargin).attr("height",p.topMargin).attr("href",p.backgroundImageTopLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",p.leftMargin).attr("y",0).attr("width",m.defaultWidth-p.rightMargin-p.leftMargin).attr("height",p.topMargin).attr("href",p.backgroundImageTop).attr("preserveAspectRatio","none"),w.append("image").attr("x",m.defaultWidth-p.rightMargin).attr("y",0).attr("width",p.rightMargin).attr("height",p.topMargin).attr("href",p.backgroundImageTopRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",p.topMargin).attr("width",p.leftMargin).attr("height",m.defaultHeight-p.bottomMargin-p.topMargin).attr("href",p.backgroundImageLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",p.leftMargin).attr("y",p.topMargin).attr("width",m.defaultWidth-p.rightMargin-p.leftMargin).attr("height",m.defaultHeight-p.bottomMargin-p.topMargin).attr("href",p.backgroundImageCenter).attr("preserveAspectRatio","none"),w.append("image").attr("x",m.defaultWidth-p.rightMargin).attr("y",p.topMargin).attr("width",p.rightMargin).attr("height",m.defaultHeight-p.bottomMargin-p.topMargin).attr("href",p.backgroundImageRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",m.defaultHeight-p.bottomMargin).attr("width",p.leftMargin).attr("height",p.bottomMargin).attr("href",p.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",p.leftMargin).attr("y",m.defaultHeight-p.bottomMargin).attr("width",m.defaultWidth-p.rightMargin-p.leftMargin).attr("height",p.bottomMargin).attr("href",p.backgroundImageBottom).attr("preserveAspectRatio","none"),w.append("image").attr("x",m.defaultWidth-p.rightMargin).attr("y",m.defaultHeight-p.bottomMargin).attr("width",p.rightMargin).attr("height",p.bottomMargin).attr("href",p.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(u.label){const S={...V,...m.label,...u.labelLook};w.append("text").attr("transform",`translate(${(J(S)+m.defaultWidth)/2},${(X(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,v)=>{const w=c().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).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});w.append("path").attr("d",lt(Ye.Rectangle,0,0,u.width,u.height)).attr("fill",u.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),u.icon!==""&&w.append("image").attr("x",0).attr("y",0).attr("width",u.width).attr("height",u.height).attr("href",u.icon),u.label!==""&&w.append("text").attr("transform",`translate(${u.width/2},${u.height/2+5})`).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 $.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(ft,{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"})]})]})})},Xs=({location:i,direction:e,enableAction:t,enableFilter:o,enableLayout:a,enableSelection:l,enableZoom:s})=>{let n=!1,r=!0,d=!1,c,h,g,b;switch(e){case k.Bottom:c="height",h="scaleY",g="top",b="bottom";break;case k.Top:c="height",h="scaleY",g="bottom",b="top";break;case k.Left:c="width",h="scaleX",g="right",b="left";break;case k.Right:c="width",h="scaleX",g="left",b="right";break}const f=$.useRef(null),m=$.useRef(null),u=$.useRef(null);$.useEffect(()=>{T.select(f.current).style(`margin-${b}`,"-1rem").style(c,"0rem").style("transform",`${h}(0)`).style("transform-origin",g)});const v=async()=>{const O=T.select(f.current);if(!d)if(r){r=!1;const _e=`${4*O.selectChildren().size()}rem`;O.transition().duration(500).ease(T.easeLinear).style(c,_e).style("transform",`${h}(1)`),setTimeout(()=>{d=!1},500)}else r=!0,O.transition().duration(500).ease(T.easeLinear).style(c,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{d=!1},500)},w=$.useContext(Ce),p=()=>{w.zoomBy(w.zoomFactor)},S=()=>{w.zoomBy(1/w.zoomFactor)},x=()=>{w.center()},L=()=>{w.layoutFormat&&w.layoutFormat in si&&si[w.layoutFormat].apply(w.model)},z=()=>{n=!n,T.select(u.current).classed("daga-on",n).classed("daga-off",!n);const O=w.getPriorityThresholdOptions();O&&O.length>=2&&w.setPriorityThreshold(O[n?1:0])},N=()=>{w.actionStack.undo()},H=()=>{w.actionStack.redo()},P=()=>{w.userSelection.copyToClipboard()},R=()=>{w.userSelection.cutToClipboard()},Z=()=>{w.userSelection.pasteFromClipboard()},_=()=>{w.userSelection.removeFromModel()},U=()=>{w.multipleSelectionOn=!0,T.select(m.current).classed("daga-on",!0).classed("daga-off",!1);const O=w.diagramEvent$.subscribe(W=>{W.type===yi.Selection&&(T.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:[s&&w.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-zoom-in",onClick:p,children:y.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),s&&w.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-zoom-out",onClick:S,children:y.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),y.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:f,children:[s&&w.canUserPerformAction(C.Zoom)&&y.jsx("button",{className:"daga-center",onClick:x,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:H,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:U,ref:m,children:y.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),l&&y.jsx("button",{className:"daga-paste",onClick:Z,children:y.jsx("span",{className:"daga-tooltip",children:"Paste"})}),l&&y.jsx("button",{className:"daga-delete",onClick:_,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"})}),o&&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:v,children:r?y.jsx("span",{className:"daga-tooltip",children:"More options"}):y.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Ws=({config:i,model:e,onCanvasCreated:t,onDiagramEvent:o,onModelChange:a})=>{var z,N,H,P,R,Z,_,U,O,W,ne,_e,gt,mt,pt,yt,bt,vt,kt,wt,xt,Ct,St,At,It,Lt,Et,Tt,$t,Mt,Nt,Pt,zt,Rt,Vt,jt,_t,Ot,Dt,Ht,Gt,Ft,Bt,Ut,Yt;const l=new pi,s=new vi,n=$.useRef(null),r=$.useRef(void 0),d=$.useRef(!1),c=[],[h,g]=$.useState(void 0),[b,f]=$.useState(void 0),m={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},u={refreshPalette:()=>{}},v=new js(re=>g(re),re=>f(re)),w={diagramButtons:m,palette:u,propertyEditor:v},p=(re=!1)=>((!r.current||re)&&(c.forEach(fe=>fe.unsubscribe()),r.current=new ct(w,i)),r.current),S=p(),x=re=>{S.initView(re),c.push(S.diagramEvent$.subscribe(fe=>{o==null||o(fe)})),c.push(S.diagramChange$.subscribe(()=>{const fe=s.export(S.model);a==null||a(fe)}))};$.useEffect(()=>{n.current&&(d.current||(x(n.current),d.current=!0,t==null||t(S)))},[n.current]),$.useMemo(()=>{n.current&&(p(!0),x(n.current),t==null||t(S))},[i]),$.useEffect(()=>{e&&l.import(S.model,e)},[e]);const L=(re,fe)=>{var Xt;if(b!==void 0&&re.editable&&!xe(b.getValue(re.name),fe)){const Oe=new be(b.propertySet,b.rootElement);Oe.setValues(b.getValues()),Oe.setValue(re.name,fe),v.valueSet=Oe,b.rootElement.valueSet=Oe,(Xt=S.propertyEditorChanges$)==null||Xt.next()}};return y.jsx("daga-diagram",{children:y.jsx(Vs.Provider,{value:i,children:y.jsx(Ce.Provider,{value:S,children:y.jsxs("daga-diagram-editor",{children:[y.jsx("div",{className:"daga-append-to",ref:n}),y.jsxs(Ce.Provider,{value:S,children:[((z=i.components)==null?void 0:z.buttons)!==void 0&&((H=(N=i.components)==null?void 0:N.buttons)==null?void 0:H.enabled)!==!1&&y.jsx(Xs,{location:((R=(P=i.components)==null?void 0:P.buttons)==null?void 0:R.location)||He.BottomRight,direction:((_=(Z=i.components)==null?void 0:Z.buttons)==null?void 0:_.direction)||k.Top,enableAction:((O=(U=i.components)==null?void 0:U.buttons)==null?void 0:O.enableAction)!==!1,enableFilter:((ne=(W=i.components)==null?void 0:W.buttons)==null?void 0:ne.enableFilter)===!0,enableLayout:((gt=(_e=i.components)==null?void 0:_e.buttons)==null?void 0:gt.enableLayout)===!0,enableSelection:((pt=(mt=i.components)==null?void 0:mt.buttons)==null?void 0:pt.enableSelection)!==!1,enableZoom:((bt=(yt=i.components)==null?void 0:yt.buttons)==null?void 0:bt.enableZoom)!==!1}),((vt=i.components)==null?void 0:vt.palette)!==void 0&&((wt=(kt=i.components)==null?void 0:kt.palette)==null?void 0:wt.enabled)!==!1&&((Ct=(xt=i.components)==null?void 0:xt.palette)==null?void 0:Ct.sections)&&(((It=(At=(St=i.components)==null?void 0:St.palette)==null?void 0:At.sections)==null?void 0:It.length)||0)>0&&y.jsx(Ys,{location:((Et=(Lt=i.components)==null?void 0:Lt.palette)==null?void 0:Et.location)||He.TopLeft,direction:(($t=(Tt=i.components)==null?void 0:Tt.palette)==null?void 0:$t.direction)||k.Bottom,width:((Nt=(Mt=i.components)==null?void 0:Mt.palette)==null?void 0:Nt.width)||"12rem",palettes:((zt=(Pt=i.components)==null?void 0:Pt.palette)==null?void 0:zt.sections)||[]}),((Rt=i.components)==null?void 0:Rt.propertyEditor)!==void 0&&((jt=(Vt=i.components)==null?void 0:Vt.propertyEditor)==null?void 0:jt.enabled)!==!1&&y.jsx(Us,{location:((Ot=(_t=i.components)==null?void 0:_t.propertyEditor)==null?void 0:Ot.location)||He.TopRight,direction:((Ht=(Dt=i.components)==null?void 0:Dt.propertyEditor)==null?void 0:Ht.direction)||k.Bottom,width:((Ft=(Gt=i.components)==null?void 0:Gt.propertyEditor)==null?void 0:Ft.width)||"24rem",title:h,valueSet:b,onValueChange:L}),((Bt=i.components)==null?void 0:Bt.errors)!==void 0&&((Yt=(Ut=i.components)==null?void 0:Ut.errors)==null?void 0:Yt.enabled)!==!1&&y.jsx(_s,{})]})]})})})})};exports.DagaDiagram=Ws;
|