@metadev/daga-react 4.2.4 → 4.2.6
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 +12 -0
- package/index.js +2 -2
- package/index.mjs +3322 -3438
- package/lib/palette/PaletteComponent.d.ts +1 -0
- package/lib/property-editor/PropertyEditor.d.ts +1 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`).map(t=>t.length)),Zi=i=>{var t;return((t=i.match(/\n/g))==null?void 0:t.length)||0},tt=[];for(let i=0;i<256;++i)tt.push((i+256).toString(16).slice(1));function Ki(i,t=0){return(tt[i[t+0]]+tt[i[t+1]]+tt[i[t+2]]+tt[i[t+3]]+"-"+tt[i[t+4]]+tt[i[t+5]]+"-"+tt[i[t+6]]+tt[i[t+7]]+"-"+tt[i[t+8]]+tt[i[t+9]]+"-"+tt[i[t+10]]+tt[i[t+11]]+tt[i[t+12]]+tt[i[t+13]]+tt[i[t+14]]+tt[i[t+15]]).toLowerCase()}let re;const qi=new Uint8Array(16);function Ji(){if(!re){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");re=crypto.getRandomValues.bind(crypto)}return re(qi)}const Qi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),si={randomUUID:Qi};function ni(i,t,e){var a;if(si.randomUUID&&!i)return si.randomUUID();i=i||{};const o=i.random??((a=i.rng)==null?void 0:a.call(i))??Ji();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,Ki(o)}const rt=i=>{const{selected:t,highlighted:e,...o}=i,a=o,l={...a,...t},s={...a,...e},n={...a,...e,...t};return{defaultLook:a,selectedLook:l,highlightedLook:s,selectedAndHighlightedLook:n}};class Jt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],Z(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Vt=0;class Tt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userHighlight)==null?void 0:e.contains(this.id))||!1}get selected(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userSelection)==null?void 0:e.contains(this.id))||!1}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`[id='${fe(this.id)}']`)}}class vt extends Jt{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((o,a,l)=>t(o,a,l)&&!o.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((o,a,l)=>t(o,a,l)&&!o.removed)}find(t,e=!1){return e?super.find(t):super.find((o,a,l)=>t(o,a,l)&&!o.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(o=>!o.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],Z(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(o=>!o.removed))yield e}}class to{constructor(t,e,o,a,l,s,n){this.name=t,this.label=e,this.type=o,this.defaultValue=a,this.basic=l,this.editable=s,this.rootAttribute=n,this.options=void 0,this.properties=void 0}}var _=(i=>(i.Boolean="boolean",i.Color="color",i.Date="date",i.Datetime="datetime",i.Number="number",i.Object="object",i.Option="option",i.OptionList="option-list",i.OptionSet="option-set",i.Text="text",i.TextArea="text-area",i.TextList="text-list",i.TextSet="text-set",i.TextMap="text-map",i.Time="time",i.Url="url",i))(_||{});class Qt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}function St(i,t){return!t||i[0]>t[0]?!0:i[0]===t[0]?i[1]>=t[1]:!1}const ri=i=>i==null||i===""||i instanceof Array&&i.length===0||i instanceof Object&&Object.keys(i).length===0,Et=(i,t)=>i===t||JSON.stringify(i)===JSON.stringify(t),vi=(i,t,e)=>{const o={},a={};for(const l in e.propertySet.propertyMap)if(e.propertySet.propertyMap[l].type===_.Object){const s=vi(i[l],t[l],e.getSubValueSet(l));Object.keys(s[0]).length>0&&Object.keys(s[1]).length>0&&(o[l]=s[0],a[l]=s[1])}else Et(i[l],t[l])||(o[l]=i[l],a[l]=t[l]);return[o,a]},eo=i=>i!=null&&i.constructor===Object;class xt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const o of t){if(e==null)return;e=e[o]}return e}}setRootElementValue(t,e){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let o=this.rootElement;for(let a=0;a<t.length-1;++a){const l=t[a];if(o==null)return;o=o[l]}if(o==null)return;o[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}getValue(t){var a;const e=(a=this.propertySet.getProperty(t))==null?void 0:a.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===_.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===_.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const o in t)this.propertySet.getProperty(o).type===_.Object?e[o]=this.valueSets[o].getValuesForKeys(t[o]):e[o]=this.getValue(o);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===_.Object)t[e]=this.valueSets[e].getTimestamps();else{const a=this.ownTimestamps[e];a&&(t[e]=a)}return t}hasValue(t){const e=this.getValue(t);return!ri(e)}hasSetValue(t){const e=this.getValue(t),o=this.propertySet.getProperty(t);return o&&o.type===_.Object?this.getSubValueSet(t).hasAnySetValue():!ri(e)&&!Et(e,o==null?void 0:o.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const o=this.propertySet.getProperty(t);if(o){o.type===_.Object?this.valueSets[t].setValues(e):(this.values[t]=e,Et(e,o.defaultValue)||this.displayProperty(o));const a=o.rootAttribute;a!=null&&this.setRootElementValue(a,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===_.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const o in t)this.propertySet.getProperty(o).type===_.Object?this.valueSets[o].overwriteValuesLww(t[o],e):St(e,this.ownTimestamps[o])&&(this.setValue(o,t[o]),this.ownTimestamps[o]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),o=e.rootAttribute;e.type===_.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),o!=null&&e.defaultValue!==void 0&&!Et(this.getRootElementValue(o),e.defaultValue)&&this.setRootElementValue(o,this.values[t]),e.basic!==!1?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),o=new Qt(e.properties),a=new xt(o,this.rootElement);return a.overwriteValues(structuredClone(e.defaultValue)),a}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),Z(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),Z(this.displayedProperties,t))}}const ot={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:mi.Straight,style:be.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class yi{constructor(t){const e={...ot,...t};this.id=e.id,this.name=e.name,this.label=e.label;const o=rt(e.look);if(this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const a=rt(e.startMarkerLook);this.defaultStartMarkerLook=a.defaultLook,this.selectedStartMarkerLook=a.selectedLook,this.highlightedStartMarkerLook=a.highlightedLook,this.selectedAndHighlightedStartMarkerLook=a.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const a=rt(e.endMarkerLook);this.defaultEndMarkerLook=a.defaultLook,this.selectedEndMarkerLook=a.selectedLook,this.highlightedEndMarkerLook=a.highlightedLook,this.selectedAndHighlightedEndMarkerLook=a.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.propertySet=new Qt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class ht extends Tt{constructor(t,e,o,a,l){if(t.connections.get(l)!==void 0)throw new Error(`DiagramConnection with id "${l}" already exists`);if(!l)throw new Error("DiagramConnection cannot have an empty or null id");super(t,l),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new xt(e.propertySet,this),this.originalData={},this.setStart(o),this.setEnd(a)}get type(){return this._type}set type(t){var e,o;t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new xt(t.propertySet,this)),(o=(e=this.model.canvas)==null?void 0:e.userSelection)==null||o.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.connections.types.get(t);e&&(this.type=e)}}get name(){return this.middleLabel}set name(t){this.middleLabel=t}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){if(t){const e=rt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook!==void 0?this._selectedAndHighlightedStartMarkerLook:this.type.selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook!==void 0?this._selectedStartMarkerLook:this.type.selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook!==void 0?this._highlightedStartMarkerLook:this.type.highlightedStartMarkerLook:this._defaultStartMarkerLook!==void 0?this._defaultStartMarkerLook:this.type.defaultStartMarkerLook}set startMarkerLook(t){if(t){const e=rt(t);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...e.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...e.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...e.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=t,this._selectedStartMarkerLook=t,this._highlightedStartMarkerLook=t,this._selectedAndHighlightedStartMarkerLook=t}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook!==void 0?this._selectedAndHighlightedEndMarkerLook:this.type.selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook!==void 0?this._selectedEndMarkerLook:this.type.selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook!==void 0?this._highlightedEndMarkerLook:this.type.highlightedEndMarkerLook:this._defaultEndMarkerLook!==void 0?this._defaultEndMarkerLook:this.type.defaultEndMarkerLook}set endMarkerLook(t){if(t){const e=rt(t);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...e.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...e.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...e.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=t,this._selectedEndMarkerLook=t,this._highlightedEndMarkerLook=t,this._selectedAndHighlightedEndMarkerLook=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateConnectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}setStart(t){this.start!==t?(this.start!==void 0&&Z(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&Z(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0])):(this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.connectionPoint)||[0,0]),this.updateInView()}tighten(){var a,l,s,n,r;const t=((a=this.model.canvas)==null?void 0:a.allowConnectionLoops)||!1,e=((l=this.model.canvas)==null?void 0:l.allowSharingPorts)!==!1,o=((s=this.model.canvas)==null?void 0:s.allowSharingBothPorts)||!1;if((n=this.start)!=null&&n.rootElement&&this.end){const c=this.start.rootElement.ports.map(d=>[d,d.distanceTo(this.end.coords)]).sort((d,h)=>d[1]-h[1]).map(d=>d[0]);t:for(const d of c){if(!t&&d===this.end||!d.allowsOutgoing||!e&&(d.incomingConnections.length===1&&d.incomingConnections[0]!==this||d.incomingConnections.length>1||d.outgoingConnections.length===1&&d.outgoingConnections[0]!==this||d.outgoingConnections.length>1))continue t;if(!o){for(const h of d.outgoingConnections)if(h!==this&&h.end===this.end)continue t;for(const h of d.incomingConnections)if(h!==this&&h.start===this.end)continue t}if(d===this.start)break t;this.setStart(d);break t}}if((r=this.end)!=null&&r.rootElement&&this.start){const c=this.end.rootElement.ports.map(d=>[d,d.distanceTo(this.start.coords)]).sort((d,h)=>d[1]-h[1]).map(d=>d[0]);t:for(const d of c){if(!t&&d===this.start||!d.allowsIncoming||!e&&(d.outgoingConnections.length===1&&d.outgoingConnections[0]!==this||d.outgoingConnections.length>1||d.incomingConnections.length===1&&d.incomingConnections[0]!==this||d.incomingConnections.length>1))continue t;if(!o){for(const h of d.incomingConnections)if(h!==this&&h.start===this.start)continue t;for(const h of d.outgoingConnections)if(h!==this&&h.end===this.start)continue t}if(d===this.end)break t;this.setEnd(d);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Vt}}class io extends vt{constructor(t){super(),this.types=new Jt,this.model=t}new(t,e,o,a){let l;if(t instanceof yi)l=t;else{const n=this.types.get(t);if(n===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);l=n}const s=new ht(this.model,l,e,o,a);return super.add(s),s.updateInView(),s.valueSet.resetValues(),s}remove(t){var o,a;const e=this.get(t,!0);e&&(Z(((o=e.start)==null?void 0:o.outgoingConnections)||[],e),Z(((a=e.end)==null?void 0:a.incomingConnections)||[],e),super.remove(t),e.updateInView())}}const D={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:Nt.Center,verticalAlign:Zt.Center,orientation:k.Top,fit:!1,shrink:!0};class mt extends Tt{constructor(t,e,o,a,l,s,n,r,c,d,h,u,p,m,f,g){const y=`${e==null?void 0:e.id}_field`;if(t.fields.get(y)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,y),this.textTimestamp=null,this.rootElement=e,this.coords=o,this.width=a,this.height=l,this.fontSize=s,this.fontFamily=n,this.color=r,this.selectedColor=c,this.horizontalAlign=d,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case k.Top:this.orientation=0;break;case k.Right:this.orientation=90;break;case k.Bottom:this.orientation=180;break;case k.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=p,this._text=p,this.editable=m,this.fit=f,this.shrink=g}get text(){return this._text}set text(t){var e;(t==null||(t==null?void 0:t.trim())==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&((e=this.model.canvas)==null||e.fitFieldRootInView(this.id,this.shrink))}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateFieldsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||Vt}}class oo extends vt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s,n,r,c,d,h,u,p,m,f){const g=new mt(this.model,t,e,n,r,o,a,l,s,c,d,h,u,p,m,f);return super.add(g),g.updateInView(),t!==void 0&&(t.label=g),g}remove(t){var o;const e=this.get(t,!0);e&&(((o=e.rootElement)==null?void 0:o.label)!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const st=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:i.margin.length===1||i.margin.length===2?i.margin[0]:(i.margin.length===3,i.margin[2]),Q=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:i.margin.length===1?i.margin[0]:i.margin.length===2||i.margin.length===3?i.margin[1]:i.margin[3],lt=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:i.margin.length===1?i.margin[0]:(i.margin.length===2||i.margin.length===3,i.margin[1]),W=i=>(i==null?void 0:i.margin)===null||(i==null?void 0:i.margin)===void 0?D.margin:typeof i.margin=="number"?i.margin:i.margin.length===0?D.margin:(i.margin.length===1||i.margin.length===2||i.margin.length===3,i.margin[0]),Dt=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),Ft=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],Ht=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),Gt=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?D.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?D.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),ai=1,li=1,so=1,no=1;class ro{constructor(t){this.margin=t.margin||0,this.defaultWidths=t.defaultWidths||null,this.defaultHeights=t.defaultHeights||null,this.minWidths=t.minWidths||null,this.minHeights=t.minHeights||null,this.sections=[];for(const e of t.sections){const o=[];this.sections.push(o);for(const a of e)o.push(new ao(a))}}}class ao{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||Vt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=rt(t.look||bi);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class U extends Tt{constructor(t,e,o,a,l,s,n,r){if(t.sections.get(r)!==void 0)throw new Error(`DiagramSection with id "${r}" already exists`);if(!r)throw new Error("DiagramSection cannot have an empty or null id");super(t,r),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=o,this.indexYInNode=a,this.coords=l,this.width=s,this.height=n}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){var t,e,o,a,l,s,n,r;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:((t=this.type)==null?void 0:t.selectedAndHighlightedLook)||((e=this.node)==null?void 0:e.look):this._selectedLook!==void 0?this._selectedLook:((o=this.type)==null?void 0:o.selectedLook)||((a=this.node)==null?void 0:a.look):this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:((l=this.type)==null?void 0:l.highlightedLook)||((s=this.node)==null?void 0:s.look):this._defaultLook!==void 0?this._defaultLook:((n=this.type)==null?void 0:n.defaultLook)||((r=this.node)==null?void 0:r.look)}set look(t){if(t){const e=rt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateSectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise()}get type(){var t,e,o,a,l;return(l=(a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode]}getMinWidth(){var t,e,o,a;return((a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.minWidths)==null?void 0:a[this.indexXInNode])||so}getMinHeight(){var t,e,o,a;return((a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.minHeights)==null?void 0:a[this.indexYInNode])||no}getPriority(){var t,e,o,a,l,s;return((s=(l=(a=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.sections)==null?void 0:a[this.indexYInNode])==null?void 0:l[this.indexXInNode])==null?void 0:s.priority)||Vt}getResizableX(){var e,o;const t=this.type;return(t==null?void 0:t.resizableX)!==void 0?t.resizableX:((o=(e=this.node)==null?void 0:e.type)==null?void 0:o.resizableX)||!1}getResizableY(){var e,o;const t=this.type;return(t==null?void 0:t.resizableY)!==void 0?t.resizableY:((o=(e=this.node)==null?void 0:e.type)==null?void 0:o.resizableY)||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),o=e.indexOf(Math.min(...e));return this.ports[o]}}}getIncomingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const o of this.ports){for(const a of o.incomingConnections)!t&&a.removed||e.push(a);for(const a of o.outgoingConnections)!t&&a.removed||e.push(a)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(t){case k.Left:l=[o[0]-e,o[1]],s=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[0]=l[1]-this.getMinWidth());break;case k.Top:l=[o[0],o[1]],s=[a[0]-e,a[1]],s[1]-s[0]<this.getMinHeight()&&(s[0]=s[1]-this.getMinHeight());break;case k.Right:l=[o[0],o[1]+e],s=[a[0],a[1]],l[1]-l[0]<this.getMinWidth()&&(l[1]=l[0]+this.getMinWidth());break;case k.Bottom:l=[o[0],o[1]],s=[a[0],a[1]+e],s[1]-s[0]<this.getMinHeight()&&(s[1]=s[0]+this.getMinHeight());break}this.setGeometry({coords:[l[0],s[0]],width:l[1]-l[0],height:s[1]-s[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){var n;const e=[this.coords[0],this.coords[0]+this.width],o=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const r of this.ports)r.move(Kt(r.coords,e,o,a,l,r.anchorPointX,r.anchorPointY));const s=this.type;this.label&&(this.label.coords=[this.coords[0]+Q(s==null?void 0:s.label),this.coords[1]+W(s==null?void 0:s.label)],this.label.width=this.width-Q(s==null?void 0:s.label)-lt(s==null?void 0:s.label),this.label.height=this.height-W(s==null?void 0:s.label)-st(s==null?void 0:s.label),this.label.updateInView());for(const r of this.decorators)r.move(Kt(r.coords,e,o,a,l,r.anchorPointX,r.anchorPointY));((n=this.model.canvas)==null?void 0:n.autoTightenConnections)!==!1&&this.getConnections().forEach(r=>r.tighten()),this.updateInView()}}class lo extends vt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s,n){var h,u,p,m,f,g,y,w,b,I;const r=new U(this.model,t,e,o,a,l,s,n);super.add(r),r.updateInView(),t.sections.push(r),t.updateInView();const c=(m=(p=(u=(h=t.type.sectionGrid)==null?void 0:h.sections)==null?void 0:u[o])==null?void 0:p[e])==null?void 0:m.ports;if(c&&c.length>0)for(let S=0;S<c.length;++S){const L=c[S],$=this.model.ports.new(L.type!==void 0?this.model.ports.types.get(L.type):void 0,r,[r.coords[0]+(L.coords[0]||0),r.coords[1]+(L.coords[1]||0)],L.connectionPoint!==void 0?[r.coords[0]+(L.connectionPoint[0]||0),r.coords[1]+(L.connectionPoint[1]||0)]:void 0,L==null?void 0:L.direction,`${r.id}_${S}`,L.anchorPointX||"floating",L.anchorPointY||"floating");if((f=$.type)!=null&&f.label){const x={...D,...(g=$.type)==null?void 0:g.label},V=6*x.fontSize+Ft(x)+Ht(x),T=x.fontSize+Gt(x)+Dt(x);let R;switch($.direction){case k.Bottom:case k.Left:case k.Right:R=[$.coords[0]-V/2,$.coords[1]-T-st(x)];break;case k.Top:R=[$.coords[0]-V/2,$.coords[1]+W(x)];break;default:R=$.coords}this.model.fields.new($,R,x.fontSize,x.fontFamily,x.color,x.selectedColor,V,T,x.horizontalAlign,x.verticalAlign,x.orientation,"",x.editable,x.fit,x.shrink)}}const d=(I=(b=(w=(y=t.type.sectionGrid)==null?void 0:y.sections)==null?void 0:w[o])==null?void 0:b[e])==null?void 0:I.label;if(d){const S={...D,...d};this.model.fields.new(r,[r.coords[0]+Q(S),r.coords[1]+W(S)],S.fontSize,S.fontFamily,S.color,S.selectedColor,r.width-Q(S)-lt(S),r.height-W(S)-st(S),S.horizontalAlign,S.verticalAlign,S.orientation,"",S.editable,S.fit,S.shrink)}return r}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&Z(e.node.sections,e),super.remove(t),e.updateInView()}}}const bi={lookType:"shaped-look",shape:Rt.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},pt={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:bi,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Vt,properties:[]};class ki{constructor(t){const e={...pt,...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=ho(e),this.leftPadding=go(e),this.rightPadding=uo(e),this.topPadding=fo(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new ro(e.sectionGrid):null;const o=rt(e.look);this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new Qt((t==null?void 0:t.properties)||[])}}class j extends Tt{constructor(t,e,o=[0,0],a){if(t.nodes.get(a)!==void 0)throw new Error(`DiagramNode with id "${a}" already exists`);if(!a)throw new Error("DiagramNode cannot have an empty or null id");super(t,a),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new xt(e.propertySet,this),this.originalData={},this.coords=o,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){var e,o;t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new xt(t.propertySet,this)),(o=(e=this.model.canvas)==null?void 0:e.userSelection)==null||o.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.nodes.types.get(t);e&&(this.type=e)}}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){if(t){const e=rt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateNodesInView(this.id)}raise(){var t;(t=this.select())==null||t.raise();for(const e of this.sections)e.raise();this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise();for(const e of this.children)e.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(l=>l.distanceTo(t)),o=e.indexOf(Math.min(...e));return this.ports[o]}}}getIncomingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.incomingConnections)!t&&a.removed||e.push(a);return e}getOutgoingConnections(t=!1){const e=[];for(const o of this.ports)for(const a of o.outgoingConnections)!t&&a.removed||e.push(a);return e}getConnections(t=!1){const e=[];for(const o of this.ports){for(const a of o.incomingConnections)!t&&a.removed||e.push(a);for(const a of o.outgoingConnections)!t&&a.removed||e.push(a)}return e}getAdjacentNodes(t=!1){var o,a;const e=[];for(const l of this.ports){for(const s of l.incomingConnections){if(!t&&s.removed)continue;const n=(o=s.start)==null?void 0:o.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}for(const s of l.outgoingConnections){if(!t&&s.removed)continue;const n=(a=s.end)==null?void 0:a.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t==null?void 0:t.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,o=!1;for(;e!==void 0;){if(e.id===t.id){o=!0;break}e=e.parent}o||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){Z(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(r=>r.indexXInNode)),o=Math.max(...this.sections.map(r=>r.indexYInNode)),a=this.coords[0]-t.coords[0]+this.type.leftPadding;a>=0&&(this.sections.length>0?this.stretchSections(k.Left,a,e,o):this.stretch(k.Left,a));const l=this.coords[1]-t.coords[1]+this.type.topPadding;l>=0&&(this.sections.length>0?this.stretchSections(k.Top,l,e,o):this.stretch(k.Top,l));const s=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;s>=0&&(this.sections.length>0?this.stretchSections(k.Right,s,e,o):this.stretch(k.Right,s));const n=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;n>=0&&(this.sections.length>0?this.stretchSections(k.Bottom,n,e,o):this.stretch(k.Bottom,n)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const o of this.children)o.move([o.coords[0]+e[0],o.coords[1]+e[1]]);for(const o of this.sections)o.move([o.coords[0]+e[0],o.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const o=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];let l,s;switch(t){case k.Left:l=[o[0]-e,o[1]],s=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[0]=l[1]-this.type.minWidth);break;case k.Top:l=[o[0],o[1]],s=[a[0]-e,a[1]],s[1]-s[0]<this.type.minHeight&&(s[0]=s[1]-this.type.minHeight);break;case k.Right:l=[o[0],o[1]+e],s=[a[0],a[1]],l[1]-l[0]<this.type.minWidth&&(l[1]=l[0]+this.type.minWidth);break;case k.Bottom:l=[o[0],o[1]],s=[a[0],a[1]+e],s[1]-s[0]<this.type.minHeight&&(s[1]=s[0]+this.type.minHeight);break}this.setGeometry({coords:[l[0],s[0]],width:l[1]-l[0],height:s[1]-s[0],sections:{},children:{}})}stretchSections(t,e,o,a){let l=Number.NEGATIVE_INFINITY;switch(t){case k.Bottom:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));e<l&&(e=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(t,e):s.indexYInNode>a&&s.move([s.coords[0],s.coords[1]+e]);break;case k.Right:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));e<l&&(e=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(t,e):s.indexXInNode>o&&s.move([s.coords[0]+e,s.coords[1]]);break;case k.Top:for(const s of this.sections)s.indexYInNode===a&&(l=Math.max(l,s.getMinHeight()-s.height));e<l&&(e=l);for(const s of this.sections)s.indexYInNode===a?s.stretch(t,e):s.indexYInNode<a&&s.move([s.coords[0],s.coords[1]-e]);break;case k.Left:for(const s of this.sections)s.indexXInNode===o&&(l=Math.max(l,s.getMinWidth()-s.width));e<l&&(e=l);for(const s of this.sections)s.indexXInNode===o?s.stretch(t,e):s.indexXInNode<o&&s.move([s.coords[0]-e,s.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const a of this.sections)e[a.id]=a.getGeometry();const o={};for(const a of this.children)a.id!==t&&(o[a.id]=a.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:o}}setGeometry(t){var s;this.raise();const e=[this.coords[0],this.coords[0]+this.width],o=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];for(const n of this.children){const r=t.children[n.id];r&&n.setGeometry(r)}for(const n of this.sections){const r=t.sections[n.id];r&&n.setGeometry(r)}for(const n of this.ports)n.move(Kt(n.coords,e,o,a,l,n.anchorPointX,n.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+Q(this.type.label),this.coords[1]+W(this.type.label)],this.label.width=this.width-Q(this.type.label)-lt(this.type.label),this.label.height=this.height-W(this.type.label)-st(this.type.label),this.label.updateInView());for(const n of this.decorators)n.move(Kt(n.coords,e,o,a,l,n.anchorPointX,n.anchorPointY));((s=this.model.canvas)==null?void 0:s.autoTightenConnections)!==!1&&this.getConnections().forEach(n=>n.tighten()),this.updateInView()}removeSectionColumn(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)s.indexYInNode===t&&(o=Math.max(o,s.width),this.model.sections.remove(s.id));for(const s of a)s.indexYInNode>t&&(--s.indexYInNode,s.move([s.coords[0]-o-e,s.coords[1]]));this.stretch(k.Right,-e-o)}removeSectionRow(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)s.indexXInNode===t&&(o=Math.max(o,s.height),this.model.sections.remove(s.id));for(const s of a)s.indexYInNode>t&&(--s.indexXInNode,s.move([s.coords[0],s.coords[1]-o-e]));this.stretch(k.Bottom,-e-o)}copySectionColumn(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)if(s.indexXInNode===t){o=Math.max(o,s.width);let n=s.indexXInNode+1;for(;this.model.sections.get(`${s.id}_copy_${n}_${s.indexYInNode}`,!0)!==void 0;)++n;this.model.sections.new(this,s.indexXInNode+1,s.indexYInNode,[s.coords[0]+s.width+e,s.coords[1]],s.width,s.height,`${s.id}_copy_${n}_${s.indexYInNode}`)}for(const s of a)s.indexXInNode>t&&(++s.indexXInNode,s.move([s.coords[0]+o+e,s.coords[1]]));this.stretch(k.Right,e+o)}copySectionRow(t){var l;const e=((l=this.type.sectionGrid)==null?void 0:l.margin)||0;let o=0;const a=[...this.sections];for(const s of a)if(s.indexYInNode===t){o=Math.max(o,s.height);let n=s.indexYInNode+1;for(;this.model.sections.get(`${s.id}_copy_${s.indexXInNode}_${n}`,!0)!==void 0;)++n;this.model.sections.new(this,s.indexXInNode,s.indexYInNode+1,[s.coords[0],s.coords[1]+s.height+e],s.width,s.height,`${s.id}_copy_${s.indexXInNode}_${n}`)}for(const s of a)s.indexYInNode>t&&(++s.indexYInNode,s.move([s.coords[0],s.coords[1]+o+e]));this.stretch(k.Bottom,e+o)}}class co extends vt{constructor(t){super(),this.types=new Jt,this.model=t}new(t,e,o){var s,n,r,c,d,h,u;let a;if(t instanceof ki)a=t;else{const p=this.types.get(t);if(p===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);a=p}const l=new j(this.model,a,e,o);if(super.add(l),l.updateInView(),a.sectionGrid!==null){let p=l.coords[1]+(a.sectionGrid.margin||0);for(let m=0;m<a.sectionGrid.sections.length;++m){let f=l.coords[0]+(a.sectionGrid.margin||0);for(let g=0;g<a.sectionGrid.sections[m].length;++g)this.model.sections.new(l,g,m,[f,p],((s=a.sectionGrid.defaultWidths)==null?void 0:s[g])||ai,((n=a.sectionGrid.defaultHeights)==null?void 0:n[m])||li,`${l.id}_${m}_${g}`),f+=(((r=a.sectionGrid.defaultWidths)==null?void 0:r[g])||ai)+(a.sectionGrid.margin||0);p+=(((c=a.sectionGrid.defaultHeights)==null?void 0:c[m])||li)+(a.sectionGrid.margin||0)}}if(a.ports.length>0)for(let p=0;p<a.ports.length;++p){const m=a.ports[p],f=m.type!==void 0?this.model.ports.types.get(m.type):void 0,g=this.model.ports.new(f,l,[l.coords[0]+m.coords[0],l.coords[1]+m.coords[1]],m.connectionPoint!==void 0?[l.coords[0]+(m.connectionPoint[0]||0),l.coords[1]+(m.connectionPoint[1]||0)]:void 0,m.direction,`${l.id}_port_${p}`,m.anchorPointX||"floating",m.anchorPointY||"floating");if((d=g.type)!=null&&d.label){const y={...D,...(h=g.type)==null?void 0:h.label},w=6*y.fontSize+Ft(y)+Ht(y),b=y.fontSize+Gt(y)+Dt(y);let I;switch(g.direction){case k.Bottom:case k.Left:case k.Right:I=[g.coords[0]-w/2,g.coords[1]-b-st(y)];break;case k.Top:I=[g.coords[0]-w/2,g.coords[1]+W(y)];break;default:I=g.coords}this.model.fields.new(g,I,y.fontSize,y.fontFamily,y.color,y.selectedColor,w,b,y.horizontalAlign,y.verticalAlign,y.orientation,"",y.editable,y.fit,y.shrink)}}if(a.label){const p={...D,...a.label};this.model.fields.new(l,[l.coords[0]+Q(p),l.coords[1]+W(p)],p.fontSize,p.fontFamily,p.color,p.selectedColor,l.width-Q(p)-lt(p),l.height-W(p)-st(p),p.horizontalAlign,p.verticalAlign,p.orientation,"",p.editable,p.fit,p.shrink)}if(a.decorators.length>0)for(let p=0;p<a.decorators.length;++p){const m=a.decorators[p];this.model.decorators.new(l,[l.coords[0]+m.coords[0],l.coords[1]+m.coords[1]],m.width,m.height,l.getPriority(),m.html,`${l.id}_decorator_${p}`,m.anchorPointX||"floating",m.anchorPointY||"floating")}return l.valueSet.resetValues(),(u=l.model.canvas)==null||u.fitNodeInView(l.id),l}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&Z(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 o=[];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&&o.push(a);return o}}const wi=i=>{for(let t=0;t<i.length;++t)for(let e=0;e<i.length;++e)e!==t&&i[e].isAncestorOf(i[t])&&(i.splice(e,1),--e,t>e&&--t);return i},ho=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?pt.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?pt.padding:i.padding.length===1||i.padding.length===2?i.padding[0]:(i.padding.length===3,i.padding[2]),go=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?pt.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?pt.padding:i.padding.length===1?i.padding[0]:i.padding.length===2||i.padding.length===3?i.padding[1]:i.padding[3],uo=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?pt.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?pt.padding:i.padding.length===1?i.padding[0]:(i.padding.length===2||i.padding.length===3,i.padding[1]),fo=i=>(i==null?void 0:i.padding)===null||(i==null?void 0:i.padding)===void 0?pt.padding:typeof i.padding=="number"?i.padding:i.padding.length===0?pt.padding:(i.padding.length===1||i.padding.length===2||i.padding.length===3,i.padding[0]),xi={lookType:"shaped-look",shape:Rt.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Yt=rt(xi),Ci={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:xi};class mo{constructor(t){const e={...Ci,...t};this.id=e.id,this.name=e.name,this.label=e.label,this.allowsOutgoing=e.allowsOutgoing,this.allowsIncoming=e.allowsIncoming,this.width=e.width;const o=rt(e.look);this.defaultLook=o.defaultLook,this.selectedLook=o.selectedLook,this.highlightedLook=o.highlightedLook,this.selectedAndHighlightedLook=o.selectedAndHighlightedLook}}class Ct extends Tt{constructor(t,e,o,a,l,s,n,r="floating",c="floating"){if(t.ports.get(n)!==void 0)throw new Error(`DiagramPort with id "${n}" already exists`);if(!n)throw new Error("DiagramPort cannot have an empty or null id");super(t,n),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=o,this.coords=a,this.connectionPoint=l||a,this.direction=s,this.anchorPointX=r,this.anchorPointY=c}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.updateInView())}get typeString(){var t;return(t=this.type)==null?void 0:t.id}set typeString(t){var e;if(t!==((e=this.type)==null?void 0:e.id))if(t===void 0)this.type=void 0;else{const o=this.model.ports.types.get(t);o&&(this.type=o)}}get allowsOutgoing(){var t,e;return((t=this.type)==null?void 0:t.allowsOutgoing)!==void 0?(e=this.type)==null?void 0:e.allowsOutgoing:!0}get allowsIncoming(){var t,e;return((t=this.type)==null?void 0:t.allowsIncoming)!==void 0?(e=this.type)==null?void 0:e.allowsIncoming:!0}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get look(){var t,e,o,a;return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(t=this.type||Yt)==null?void 0:t.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(e=this.type||Yt)==null?void 0:e.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(o=this.type||Yt)==null?void 0:o.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(a=this.type||Yt)==null?void 0:a.defaultLook}set look(t){if(t){const e=rt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get width(){var t;return((t=this.type)==null?void 0:t.width)||Ci.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updatePortsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.incomingConnections)e.raise();for(const e of this.outgoingConnections)e.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof j)return this.rootElement;if(this.rootElement instanceof U)return this.rootElement.node}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||Vt}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 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]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return fi(this.coords,t)}}class po extends vt{constructor(t){super(),this.types=new Jt,this.model=t}new(t,e,o,a,l,s,n="floating",r="floating"){const c=new Ct(this.model,t,e,o,a,l,s,n,r);return super.add(c),c.updateInView(),e!==void 0&&e.ports.push(c),c}remove(t){const e=this.get(t,!0);if(e){for(;e.outgoingConnections.length>0;)this.model.connections.remove(e.outgoingConnections[0].id);for(;e.incomingConnections.length>0;)this.model.connections.remove(e.incomingConnections[0].id);e.label&&this.model.fields.remove(e.label.id),(e.rootElement instanceof j||e.rootElement instanceof U)&&Z(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class Si{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 o of e.nodes||[])this.importNode(t,o);for(const o of e.connections||[])this.importConnection(t,o);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,s,n,r,c,d,h,u,p;const o=t.nodes.types.get(e.type);if(o){const m=new j(t,o,e.coords,e.id);if(t.nodes.add(m),m.width=e.width,m.height=e.height,e.label){if(o.decorators)for(let g=0;g<o.decorators.length;++g){const y=o.decorators[g];t.decorators.new(m,[m.coords[0]+y.coords[0],m.coords[1]+y.coords[1]],y.width,y.height,m.getPriority(),y.html,`${m.id}_decorator_${g}`)}if(o.label){const g={...D,...o.label},y=new mt(t,m,[m.coords[0]+Q(g),m.coords[1]+W(g)],m.width-Q(g)-lt(g),m.height-W(g)-st(g),g.fontSize,g.fontFamily,g.color,g.selectedColor,g.horizontalAlign,g.verticalAlign,g.orientation,"",g.editable,g.fit,g.shrink);y.text=e.label,m.label=y,t.fields.add(y),y.updateInView()}}for(const g of e.children||[]){const y=this.importNode(t,g);y!==void 0&&((a=m.children)==null||a.push(y),y.parent=m)}for(const g of e.sections||[]){const y=new U(t,m,g.indexXInNode,g.indexYInNode,g.coords,g.width,g.height,g.id);if((l=m.sections)==null||l.push(y),t.sections.add(y),g.label&&(c=(r=(n=(s=o.sectionGrid)==null?void 0:s.sections)==null?void 0:n[g.indexYInNode])==null?void 0:r[g.indexXInNode])!=null&&c.label){const b={...D,...(p=(u=(h=(d=o.sectionGrid)==null?void 0:d.sections)==null?void 0:h[g.indexYInNode])==null?void 0:u[g.indexXInNode])==null?void 0:p.label},I=new mt(t,y,[y.coords[0]+Q(b),y.coords[1]+W(b)],y.width-Q(b)-lt(b),y.height-W(b)-st(b),b.fontSize,b.fontFamily,b.color,b.selectedColor,b.horizontalAlign,b.verticalAlign,b.orientation,"",b.editable,b.fit,b.shrink);I.text=g.label,y.label=I,t.fields.add(I),I.updateInView()}let w=0;for(const b of g.ports||[]){const I=b.type!==void 0?t.ports.types.get(b.type):void 0,S=new Ct(t,I,y,b.coords,b.connectionPoint,b.direction,b.id);if(y.ports.push(S),t.ports.add(S),b.label){if(o.ports.length>w&&(I!=null&&I.label)){const L={...D,...I==null?void 0:I.label};let $;switch(S.direction){case k.Top:case k.Left:$=[S.coords[0]-L.fontSize,S.coords[1]-L.fontSize];break;case k.Bottom:$=[S.coords[0]-L.fontSize,S.coords[1]+L.fontSize];break;case k.Right:$=[S.coords[0]+L.fontSize,S.coords[1]-L.fontSize];break;default:$=S.coords}const x=new mt(t,S,$,L.fontSize,L.fontSize,L.fontSize,L.fontFamily,L.color,L.selectedColor,L.horizontalAlign,L.verticalAlign,L.orientation,"",L.editable,L.fit,L.shrink);x.text=b.label,S.label=x,t.fields.add(x),x.updateInView()}++w}b.collabMeta&&(S.selfRemoved=b.collabMeta.selfRemoved,S.selfRemovedTimestamp=b.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(S.label,b.collabMeta.label)),S.updateInView()}g.collabMeta&&(y.selfRemoved=g.collabMeta.selfRemoved,y.selfRemovedTimestamp=g.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(y.label,g.collabMeta.label)),y.updateInView()}let f=0;for(const g of e.ports||[]){const y=g.type!==void 0?t.ports.types.get(g.type):void 0,w=new Ct(t,y,m,g.coords,g.connectionPoint,g.direction,g.id);if(m.ports.push(w),t.ports.add(w),g.label){if(o.ports.length>f&&(y!=null&&y.label)){const b={...D,...y==null?void 0:y.label};let I;switch(w.direction){case k.Top:case k.Left:I=[w.coords[0]-b.fontSize,w.coords[1]-b.fontSize];break;case k.Bottom:I=[w.coords[0]-b.fontSize,w.coords[1]+b.fontSize];break;case k.Right:I=[w.coords[0]+b.fontSize,w.coords[1]-b.fontSize];break;default:I=w.coords}const S=new mt(t,w,I,b.fontSize,b.fontSize,b.fontSize,b.fontFamily,b.color,b.selectedColor,b.horizontalAlign,b.verticalAlign,b.orientation,"",b.editable,b.fit,b.shrink);S.text=g.label,w.label=S,t.fields.add(S),S.updateInView()}++f}g.collabMeta&&(w.selfRemoved=g.collabMeta.selfRemoved,w.selfRemovedTimestamp=g.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(w.label,g.collabMeta.label)),w.updateInView()}return e.data&&m.valueSet.setValues(e.data),e.collabMeta&&(m.selfRemoved=e.collabMeta.selfRemoved,m.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,m.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(m.label,e.collabMeta.label),m.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),m.updateInView(),m.raise(),m}}importConnection(t,e){const o=t.connections.types.get(e.type);if(o){const a=new ht(t,o,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 te{constructor(t,e,o,a,l,s,n){this.canvas=t,this.id=e,this.typeId=o,this.coords=a,this.parentId=l,this.label=s,this.values=n}do(){var e;const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&((e=this.canvas.model.nodes.get(this.parentId))==null||e.addChild(t)),t.label&&(t.label.text=this.label||""),this.values!==void 0?t.valueSet.setValues(structuredClone({...t.valueSet.getValues(),...this.values})):t.valueSet.resetValues()}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new te(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class ke{constructor(t,e,o,a,l,s,n){this.canvas=t,this.nodeId=e,this.copyColumnIndex=o,this.copyRowIndex=a,this.removeColumnIndex=l,this.removeRowIndex=s,this.timestamp=n}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&St(this.timestamp,t.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&t.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&t.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&t.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&t.removeSectionRow(this.removeRowIndex),t.geometryTimestamp=this.timestamp)}serialize(){return{type:"addSection",nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(t,e){return new ke(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class we{constructor(t,e,o){this.canvas=t,this.to=e,this.timestamp=o}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&St(this.timestamp,e.geometryTimestamp)){const o=this.to[t];e.move([o[0],o[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new we(t,e.to,e.timestamp)}}class Bt{constructor(t,e,o,a){this.canvas=t,this.nodeIds=e,this.delta=o,this.timestamp=a}do(){var t;for(const e of this.nodeIds){const o=this.canvas.model.nodes.get(e,!0);o&&St(this.timestamp,o.geometryTimestamp)&&(o.move([o.coords[0]+this.delta[0],o.coords[1]+this.delta[1]]),(t=o.parent)==null||t.fitToChild(o),o.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new Bt(t,e.nodeIds,e.delta,e.timestamp)}}class nt{constructor(t,e,o,a){this.canvas=t,this.nodeId=e,this.to=o,this.timestamp=a}do(){var e,o,a;const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&St(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),(e=t.label)!=null&&e.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);for(const l of t.sections)(o=l.label)!=null&&o.fit&&this.canvas.fitFieldRootInView(l.label.id,l.label.shrink);(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 nt(t,e.nodeId,e.to,e.timestamp)}}class Ut{constructor(t,e,o,a,l){this.canvas=t,this.childId=e,this.parentId=o,this.childGeometry=a,this.timestamp=l}do(){var o;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)&&St(this.timestamp,t.geometryTimestamp)&&((o=t.parent)==null||o.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 Ut(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class ee{constructor(t,e,o,a,l){this.canvas=t,this.id=e,this.typeId=o,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 ee(t,e.id,e.typeId,e.startId,e.endId)}}class Pt{constructor(t,e,o,a){this.canvas=t,this.fieldId=e,this.to=o,this.timestamp=a}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&St(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 Pt(t,e.fieldId,e.to,e.timestamp)}}class zt{constructor(t,e,o,a){this.canvas=t,this.id=e,this.to=o,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 zt(t,e.id,e.to,e.timestamp)}}class ct{constructor(t,e,o,a,l,s,n,r){this.canvas=t,this.nodeIds=e,this.sectionIds=o,this.portIds=a,this.connectionIds=l,this.fieldIds=s,this.selfRemoved=n,this.timestamp=r}doOne(t){t&&St(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 ct(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class ie{constructor(t,e,o){this.canvas=t,this.nodes=e,this.connections=o}do(){const t=new Si;this.canvas.userSelection.clear();for(const e of this.nodes){const o=t.importNode(this.canvas.model,e);o&&this.canvas.userSelection.add(o)}for(const e of this.connections){const o=t.importConnection(this.canvas.model,e);o&&this.canvas.userSelection.add(o)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new ie(t,e.nodes,e.connections)}}class vo{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=ni()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+ni()}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":{te.deserialize(this.canvas,t).do();break}case"addSection":{ke.deserialize(this.canvas,t).do();break}case"applyLayout":{we.deserialize(this.canvas,t).do();break}case"move":{Bt.deserialize(this.canvas,t).do();break}case"setGeometry":{nt.deserialize(this.canvas,t).do();break}case"setParent":{Ut.deserialize(this.canvas,t).do();break}case"addConnection":{ee.deserialize(this.canvas,t).do();break}case"editField":{Pt.deserialize(this.canvas,t).do();break}case"updateValues":{zt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{ct.deserialize(this.canvas,t).do();break}case"paste":{ie.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class yo{constructor(t,e){this.canvas=t,this.maximum=e,this.history=[],this.index=0}add(t){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(t)):(this.history.push(t),++this.index),this.canvas.diagramChange$.next({action:t,method:0})}undo(){let t;if(this.index>0){let e;do--this.index,t=this.history[this.index],e=t.undo();while(!e&&this.index>0)}this.canvas.diagramChange$.next({action:t,method:1})}redo(){let t;if(this.index<this.history.length){let e;do t=this.history[this.index],e=t.redo(),++this.index;while(!e&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:t,method:2})}}var C=(i=>(i.AddConnection="add-connection",i.AddNode="add-node",i.AddSectionAction="add-section",i.ApplyLayout="apply-layout",i.Clipboard="clipboard",i.ContextMenu="context-menu",i.EditField="edit-field",i.MoveNode="move-node",i.Paste="paste",i.Remove="remove",i.StretchNode="stretch-node",i.StretchSection="stretch-section",i.UpdateValues="update-values",i.Zoom="zoom",i))(C||{});class bo{constructor(t,e,o,a,l,s,n,r,c){this.canvas=t,this.type=e,this.coords=o,this.parentId=a,this.ancestorId=l,this.fromAncestorGeometry=s,this.toAncestorGeometry=n,this.label=r,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){const t=new te(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 nt(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 ct(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const o=new nt(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new ct(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const o=new nt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t===void 0}}class ae{constructor(t,e,o){this.canvas=t,this.nodeIds=e,this.delta=o}do(){const t=new Bt(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 Bt(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 q{constructor(t,e,o,a,l,s,n,r){this.canvas=t,this.intent=e,this.nodeId=o,this.from=a,this.to=l,this.ancestorId=s,this.fromAncestorGeometry=n,this.toAncestorGeometry=r}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new nt(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 o=new nt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new nt(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 o=new nt(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new nt(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class ko{constructor(t,e,o,a,l,s,n,r,c){this.canvas=t,this.childId=e,this.fromParentId=o,this.toParentId=a,this.fromChildGeometry=l,this.toChildGeometry=s,this.ancestorId=n,this.fromAncestorGeometry=r,this.toAncestorGeometry=c}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Ut(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 o=new nt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Ut(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 o=new nt(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t!==void 0}redo(){return this.do()}}class le{constructor(t,e,o,a){this.canvas=t,this.type=e,this.startId=o,this.endId=a,this.id=this.canvas.collabEngine.freshId()}do(){const t=new ee(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 ct(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 ct(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class ci{constructor(t,e,o,a){this.canvas=t,this.fieldId=e,this.from=o,this.to=a}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new Pt(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 Pt(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 Pt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class wo{constructor(t,e,o,a){this.canvas=t,this.id=e,this.from=o,this.to=a}do(){const t=new zt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new zt(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 zt(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 xo{constructor(t,e,o,a,l,s){this.canvas=t,this.nodeIds=e,this.sectionIds=o,this.portIds=a,this.connectionIds=l,this.fieldIds=s}do(){const t=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),e=new ct(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(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),e=new ct(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 Co{constructor(t,e,o,a){this.canvas=t,this.nodes=e,this.connections=o,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,o={};for(const l of this.nodes){const s=l.id,n=this.canvas.collabEngine.freshId();if(o[s]=n,l.id=n,e&&(l.coords=[l.coords[0]+e[0],l.coords[1]+e[1]]),l.sections)for(const r of l.sections){const c=r.id;if(r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),o[c]=r.id,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]]),r.ports)for(const d of r.ports){const h=d.id;d.id.includes(l.id)?d.id=d.id.replace(l.id,n):d.id=this.canvas.collabEngine.freshId(),o[h]=d.id,e&&(d.coords=[d.coords[0]+e[0],d.coords[1]+e[1]])}}if(l.ports)for(const r of l.ports){const c=r.id;r.id.includes(l.id)?r.id=r.id.replace(l.id,n):r.id=this.canvas.collabEngine.freshId(),o[c]=r.id,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[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,e)for(let n=0;n<l.points.length;++n)l.points[n]=[l.points[n][0]+e[0],l.points[n][1]+e[1]]}const a=new ie(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(a),!0}undo(){const t=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),e=new ct(this.canvas,this.nodes.map(o=>o.id),[],[],this.connections.map(o=>o.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=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),e=new ct(this.canvas,this.nodes.map(o=>o.id),[],[],this.connections.map(o=>o.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class oe{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Ii=(i=>(i[i.DoubleClick=0]="DoubleClick",i[i.SecondaryClick=1]="SecondaryClick",i[i.Selection=2]="Selection",i[i.Highlight=3]="Highlight",i))(Ii||{});class bt extends oe{constructor(t,e,o){super(0),this.cause=t,this.target=e,this.coords=o}}class kt extends oe{constructor(t,e,o){super(1),this.cause=t,this.target=e,this.coords=o}}class G extends oe{constructor(t,e){super(2),this.targets=t,this.selected=e}}class it extends oe{constructor(t){super(3),this.target=t}}class Ai extends Tt{constructor(t,e,o,a,l,s,n,r,c="floating",d="floating"){if(t.objects.get(r)!==void 0)throw new Error(`DiagramDecorator with id "${r}" already exists`);if(!r)throw new Error("DiagramDecorator cannot have an empty or null id");super(t,r),this.rootElement=e,this.coords=o,this.width=a,this.height=l,this.priority=s,this.html=n,this.anchorPointX=c,this.anchorPointY=d}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 So extends vt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s,n,r="floating",c="floating"){const d=new Ai(this.model,t,e,o,a,l,s,n,r,c);return super.add(d),d.updateInView(),t!==void 0&&t.decorators.push(d),d}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof j||e.rootElement instanceof U)&&Z(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Io extends Tt{constructor(t,e,o,a,l,s,n){if(t.objects.get(n)!==void 0)throw new Error(`DiagramObject with id "${n}" already exists`);if(!n)throw new Error("DiagramObject cannot have an empty or null id");super(t,n),this.coords=e,this.width=o,this.height=a,this.priority=l,this.html=s}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 vt{constructor(t){super(),this.model=t}new(t,e,o,a,l,s){const n=new Io(this.model,t,e,o,a,l,s);return super.add(n),n.updateInView(),n}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Ei{constructor(t,e,o,a,l,s=[]){this.nodes=new co(this),this.sections=new lo(this),this.ports=new po(this),this.connections=new io(this),this.fields=new oo(this),this.objects=new Ao(this),this.decorators=new So(this),this.canvas=t,this.id=e,this.name=o,this.description=a,this.type=l,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new xt(new Qt(s),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 wt=i=>!!i.button,ce=(i,t,e,o,a,l,s,n)=>Di(i,[t,e],o,a,Math.max(10,s||0,n||0)*l),A=i=>{i?N.select("body").style("cursor",i):N.select("body").style("cursor",P.Auto)},ft=i=>i instanceof j?i:i instanceof U?i.node||i:i.rootElement instanceof j||i.rootElement instanceof U||i.rootElement instanceof Ct?ft(i.rootElement):i,de=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")},jt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:be.Solid},he=i=>{i.filter(".shaped-look").select("path").attr("d",t=>pe(t.look.shape||Rt.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||jt.fillColor).attr("stroke",t=>t.look.borderColor||jt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||jt.borderThickness}px`).attr("stroke-dasharray",t=>me(t.look.borderStyle||jt.borderStyle,t.look.borderThickness||jt.borderThickness)),i.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",t=>t.width).attr("height",t=>t.height).attr("href",t=>t.look.backgroundImage),i.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopLeft),i.filter(".stretchable-image-look").select("image.top-image").attr("x",t=>t.look.leftMargin).attr("y",0).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTop),i.filter(".stretchable-image-look").select("image.top-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",0).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopRight),i.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageLeft),i.filter(".stretchable-image-look").select("image.center-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageCenter),i.filter(".stretchable-image-look").select("image.right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageRight),i.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomLeft),i.filter(".stretchable-image-look").select("image.bottom-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottom),i.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomRight)},Ot={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Eo=(i,t,e)=>{const o=t.append("defs");if(i.gridSize>0&&isFinite(i.gridSize)){const a=o.append("pattern").attr("id",e).attr("x",-i.gridSize/2).attr("y",-i.gridSize/2).attr("width",i.gridSize).attr("height",i.gridSize).attr("patternUnits","userSpaceOnUse");switch(a.append("rect").attr("x",0).attr("y",0).attr("width",i.gridSize).attr("height",i.gridSize).attr("fill",i.backgroundColor),i.gridStyle){case"dots":a.append("circle").attr("cx",i.gridSize/2).attr("cy",i.gridSize/2).attr("r",i.gridSize*i.gridThickness).attr("fill",i.gridColor);break;case"lines":a.append("line").attr("x1",i.gridSize/2).attr("x2",i.gridSize/2).attr("y1",0).attr("y2",i.gridSize).attr("stroke-width",i.gridSize*i.gridThickness).attr("stroke",i.gridColor),a.append("line").attr("x1",0).attr("x2",(i.gridSize-i.gridSize*i.gridThickness)/2).attr("y1",i.gridSize/2).attr("y2",i.gridSize/2).attr("stroke-width",i.gridSize*i.gridThickness).attr("stroke",i.gridColor),a.append("line").attr("x1",(i.gridSize+i.gridSize*i.gridThickness)/2).attr("x2",i.gridSize).attr("y1",i.gridSize/2).attr("y2",i.gridSize/2).attr("stroke-width",i.gridSize*i.gridThickness).attr("stroke",i.gridColor);break}t.select("rect").attr("fill",`url(#${e})`)}},ve=96,J=32,Mt=ve+J,Lo=Math.PI/4,To=100,di={customButtons:[]};class $o{constructor(t,e){this.canvas=t,this.config=e||di}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),o=this.canvas.getPointerLocationRelativeToCanvas(t),a=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-Mt}px`).attr("y",`${e[1]-Mt}px`).attr("width",`${2*Mt}px`).attr("height",`${2*Mt}px`).style("pointer-events","none").on(E.ContextMenu,s=>{this.canvas.canUserPerformAction(C.ContextMenu)&&(t.preventDefault(),this.open(s))}).on(E.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.userSelection.cutToClipboard(),s.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Clipboard)&&l.push({name:"COPY",imageClass:"daga-copy",onPress:s=>{s.userSelection.copyToClipboard(),s.cancelAllUserActions()}}),this.canvas.canUserPerformAction(C.Paste)&&l.push({name:"PASTE",imageClass:"daga-paste",onPress:s=>{s.userSelection.pasteFromClipboard(s.getClosestGridPoint(o)),s.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(C.Remove)&&l.push({name:"DELETE",imageClass:"daga-delete",onPress:s=>{s.userSelection.removeFromModel(),s.cancelAllUserActions()}});for(const s of this.config.customButtons||di.customButtons)(s.condition===void 0||s.condition(this.canvas))&&l.push(s);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,c=(s+.5-l.length/2)*Lo,d=a.append("xhtml:div").attr("class",`daga-context-menu-button ${n.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*J}px`).style("height",`${2*J}px`).style("border-radius",`${J}px`).style("pointer-events","auto").on(E.Click,h=>{r&&(h.preventDefault(),r(this.canvas))}).on(E.KeyDown,h=>{r&&h.key===et.Enter&&(h.preventDefault(),r(this.canvas))});n.imageClass!==void 0?d.append("xhtml:div").style("position","absolute").style("left",`${.75*J}px`).style("top",`${.5*J}px`).style("width",`${.5*J}px`).style("height",`${.5*J}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass):n.image!==void 0&&d.append("xhtml:img").style("position","absolute").style("left",`${.75*J}px`).style("top",`${.5*J}px`).style("width",`${.5*J}px`).style("height",`${.5*J}px`).attr("src",n.image),d.append("xhtml:span").style("position","absolute").style("left",`${.2*J}px`).style("top",`${1.1*J}px`).style("text-align","center").style("width",`${1.6*J}px`).style("height",`${.35*J}px`).style("margin","0").style("font-size",`${.35*J}px`).style("font-weight","700").style("user-select","none").text(n.name),d.transition().ease(N.easeLinear).duration(To).tween("progress",()=>h=>{const u=c*h;return d.style("left",`${Math.sin(u)*ve-J+Mt}px`).style("top",`${-Math.cos(u)*ve-J+Mt}px`)})}}close(){var t;(t=this.contextMenuContainer)==null||t.remove(),this.contextMenuContainer=void 0}}class Mo extends vt{constructor(t,e=!0){super(),this.focus=void 0,this.canvas=t,this.highlightSections=e}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,(t instanceof mt||t instanceof Ai)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof j){if(!this.highlightSections)for(const e of t.sections){super.add(e);for(const o of e.ports)super.add(o),this.canvas.updatePortsInView(o.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateNodesInView(t.id)}else if(t instanceof U)if(!this.highlightSections&&t.node)this.add(t.node);else{for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}else t instanceof Ct?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof ht&&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 No=1;class Li{export(t,e=!1){const o={name:t.name,type:t.type,typeVersion:No,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(o.id=t.id),t.description&&(o.description=t.description);for(const a of t.nodes.all(!0))!e&&a.removed||a.parent===void 0&&o.nodes.push(this.exportNode(a,e));for(const a of t.connections.all(!0))!e&&a.removed||o.connections.push(this.exportConnection(a,e));return o}exportNode(t,e=!1){var s,n,r,c,d,h;const o=[];for(const u of t.children)o.push(this.exportNode(u,e));const a=[];for(const u of t.sections){const p=[];for(const m of u.ports)p.push({id:m.id,type:(s=m.type)==null?void 0:s.id,coords:$t(m.coords),connectionPoint:$t(m.connectionPoint),direction:m.direction,label:((n=m.label)==null?void 0:n.text)||"",...e?{collabMeta:{removed:m.removed,selfRemoved:m.selfRemoved,selfRemovedTimestamp:m.selfRemovedTimestamp,...this.exportLabelCollabMeta(m)}}:{}});a.push({id:u.id,ports:p,label:((r=u.label)==null?void 0:r.text)||"",indexXInNode:u.indexXInNode,indexYInNode:u.indexYInNode,coords:$t(u.coords),width:u.width,height:u.height,...e?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}})}const l=[];for(const u of t.ports)l.push({id:u.id,type:(c=u.type)==null?void 0:c.id,coords:$t(u.coords),connectionPoint:$t(u.connectionPoint),direction:u.direction,label:((d=u.label)==null?void 0:d.text)||"",...e?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}});return{id:t.id,type:t.type.id,children:o,sections:a,ports:l,label:((h=t.label)==null?void 0:h.text)||"",coords:$t(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 o,a;return{id:t.id,type:t.type.id,start:((o=t.start)==null?void 0:o.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 Po="Diagram properties";class zo extends vt{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(At.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof j||t instanceof ht)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof U?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof j&&t.sections))for(const e of t.sections)super.add(e),e.updateInView()}remove(t){const e=this.get(t);if(e&&(this.propertyEditorSelection===e&&this.openInPropertyEditor(void 0),super.remove(t),e.updateInView(),e instanceof j&&e.sections))for(const o of e.sections)super.remove(o.id),o.updateInView()}toggle(t){this.contains(t.id)?this.remove(t.id):this.add(t)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const t=this.entities[0];super.remove(t.id),t.updateInView()}}move(t){for(const e of this.all())e instanceof j&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],o=[],a=[],l=[];for(const n of this.all())n instanceof j?t.push(n.id):n instanceof U?e.push(n.id):n instanceof Ct?o.push(n.id):n instanceof ht?a.push(n.id):n instanceof mt&&l.push(n.id);const s=new xo(this.canvas,t,e,o,a,l);s.do(),this.canvas.actionStack.add(s)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Li;for(const o of this.all())o instanceof j&&t.nodes.push(e.exportNode(o,!1)),o instanceof ht&&t.connections.push(e.exportConnection(o,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const o=JSON.parse(e);if(o.type!=="daga-user-selection")return;const a=new Co(this.canvas,o.nodes,o.connections,t);this.canvas.actionStack.add(a),a.do()}catch{return}})}openInPropertyEditor(t,e=!0){var l;e&&this.makeUpdateValuesAction();const o=(l=this.canvas.parentComponent)==null?void 0:l.propertyEditor;if(o===void 0)return;const a=t==null?void 0:t.valueSet;a?(this.propertyEditorSelection=t,e&&(this.propertyEditorValues=structuredClone(a.getValues())),o&&(t instanceof j||t instanceof ht?(t instanceof j?t.name?o.title=`${t.type.name}: ${t.name}`:o.title=t.type.name:t instanceof ht&&(o.title=t.type.name),o.valueSet=void 0,o.valueSet=a):(o.title=Po,o.valueSet=void 0,o.valueSet=a))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,o&&(o.title="",o.valueSet=void 0))}makeUpdateValuesAction(){var n,r,c;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof Ei?void 0:this.propertyEditorSelection.id;if(Et(this.propertyEditorValues,(n=this.propertyEditorSelection)==null?void 0:n.valueSet.getValues()))return;const e=this.propertyEditorValues,o=structuredClone((r=this.propertyEditorSelection)==null?void 0:r.valueSet.getValues()),[a,l]=vi(e,o,(c=this.propertyEditorSelection)==null?void 0:c.valueSet),s=new wo(this.canvas,t,a,l);s.do(),this.canvas.actionStack.add(s),this.propertyEditorValues=o}}const Ro=i=>i*Math.PI/180,hi=(i,t,e)=>{const o=Ro(e),a=Math.sin(o),l=Math.cos(o),s=(Math.abs(i*l)-Math.abs(t*a))/(l*l-a*a),n=(Math.abs(i*a)-Math.abs(t*l))/(a*a-l*l);return[s,n]},Vo=12,H=6,_o=25,ge="diagram-connection-unfinished",qt=class qt{constructor(t,e){var o,a,l,s,n,r,c,d,h,u,p,m,f,g,y,w,b,I,S,L,$,x,V,T,R,Y,O,K,F;if(this.backgroundPatternId=`daga-background-pattern-id-${qt.canvasCount++}`,this.zoomTransform=N.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new At.Subject,this.diagramChange$=new At.Subject,this.diagramEvent$=new At.Subject,this.propertyEditorChanges$=new At.Subject,this.parentComponent=t,this.model=new Ei(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new zo(this),this.userHighlight=new Mo(this,((o=e.canvas)==null?void 0:o.highlightSections)!==!1),this.contextMenu=new $o(this,(a=e.canvas)==null?void 0:a.contextMenu),this.backgroundColor=((l=e.canvas)==null?void 0:l.backgroundColor)||"#FFFFFF",this.gridStyle=((n=(s=e.canvas)==null?void 0:s.grid)==null?void 0:n.style)??Ot.style,this.gridSize=((c=(r=e.canvas)==null?void 0:r.grid)==null?void 0:c.enabled)===!1||((d=e.canvas)==null?void 0:d.grid)===void 0?0:Math.abs(((u=(h=e.canvas)==null?void 0:h.grid)==null?void 0:u.spacing)||Ot.spacing),this.gridThickness=Math.abs(((m=(p=e.canvas)==null?void 0:p.grid)==null?void 0:m.thickness)||Ot.thickness),this.gridColor=((g=(f=e.canvas)==null?void 0:f.grid)==null?void 0:g.color)||Ot.color,this.snapToGrid=((w=(y=e.canvas)==null?void 0:y.grid)==null?void 0:w.enabled)===!1||((b=e.canvas)==null?void 0:b.grid)===void 0?!1:((S=(I=e.canvas)==null?void 0:I.grid)==null?void 0:S.snap)||Ot.snap,this.zoomFactor=((L=e.canvas)==null?void 0:L.zoomFactor)||2,this.panRate=(($=e.canvas)==null?void 0:$.panRate)||100,this.inferConnectionType=((x=e.connectionSettings)==null?void 0:x.inferConnectionType)||!1,this.autoTightenConnections=((V=e.connectionSettings)==null?void 0:V.autoTighten)!==!1,this.allowConnectionLoops=((T=e.connectionSettings)==null?void 0:T.allowLoops)||!1,this.allowSharingPorts=((R=e.connectionSettings)==null?void 0:R.sharePorts)!==!1,this.allowSharingBothPorts=((Y=e.connectionSettings)==null?void 0:Y.shareBothPorts)||!1,this.portHighlightRadius=((O=e.connectionSettings)==null?void 0:O.portHighlightRadius)||100,this.multipleSelectionOn=!1,this.priorityThresholds=((K=e.canvas)==null?void 0:K.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new yo(this,_o),this.collabEngine=new vo(this),e.nodeTypes)for(const B of e.nodeTypes){const X=new ki({...e.nodeTypeDefaults,...B});this.model.nodes.types.add(X)}if(e.portTypes)for(const B of e.portTypes){const X=new mo({...e.portTypeDefaults,...B});this.model.ports.types.add(X)}if(e.connectionTypes){for(const B of e.connectionTypes){const X=new yi({...e.connectionTypeDefaults,...B});this.model.connections.types.add(X)}this._connectionType=((F=e==null?void 0:e.connectionSettings)==null?void 0:F.defaultConnection)!==void 0?this.model.connections.types.get(e.connectionSettings.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){var e,o;this._connectionType=t,(o=(e=this.parentComponent)==null?void 0:e.palette)==null||o.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){Z(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){var e,o;this.priorityThreshold=t,this.updateModelInView();for(const a of this.model.nodes)this.fitNodeInView(a.id);(o=(e=this.parentComponent)==null?void 0:e.palette)==null||o.refreshPalette()}initView(t){const e=N.select(t);e.html(""),this.diagramRoot=e.append("div").node(),N.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),N.select(this.diagramRoot).on(E.Click,()=>{var a;(a=N.select(this.diagramRoot).node())==null||a.focus()}).on(E.ContextMenu,a=>{if(this.dragging){a.preventDefault(),a.stopPropagation(),this.dragging=!1;return}const l=new kt(a,null);this.diagramEvent$.next(l),!l.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(a.preventDefault(),this.contextMenu.open(a))}).on(E.DoubleClick,a=>{const l=new bt(a,null);this.diagramEvent$.next(l)}).on(E.KeyDown,a=>{if(!a.ctrlKey&&(a.key===et.Delete||a.key===et.Backspace)&&this.canUserPerformAction(C.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="a"){a.preventDefault();for(const l of this.model.nodes)this.userSelection.add(l);for(const l of this.model.connections)this.userSelection.add(l);this.diagramEvent$.next(new G(this.userSelection.all(),!0))}if(a.ctrlKey&&a.key==="i"){a.preventDefault();const l=[],s=[];for(const n of this.model.nodes)this.userSelection.toggle(n),n.selected?l.push(n):s.push(n);for(const n of this.model.connections)this.userSelection.toggle(n),n.selected?l.push(n):s.push(n);l.length>0&&this.diagramEvent$.next(new G(l,!0)),s.length>0&&this.diagramEvent$.next(new G(s,!1))}if(a.ctrlKey&&a.key==="c"&&this.canUserPerformAction(C.Clipboard)&&(a.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="x"&&this.canUserPerformAction(C.Clipboard)&&this.canUserPerformAction(C.Remove)&&(a.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="v"&&this.canUserPerformAction(C.Paste)){a.preventDefault();const l=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(l[0][0]+l[1][0])/2,(l[0][1]+l[1][1])/2])),this.cancelAllUserActions()}a.ctrlKey&&a.key==="y"&&(a.preventDefault(),this.actionStack.redo()),a.ctrlKey&&a.key==="z"&&(a.preventDefault(),this.actionStack.undo()),a.key==="+"&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.zoomBy(this.zoomFactor)),a.key==="-"&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.zoomBy(1/this.zoomFactor)),a.key===et.ArrowLeft&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),a.key===et.ArrowRight&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),a.key===et.ArrowDown&&this.canUserPerformAction(C.Zoom)&&(a.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),a.key===et.ArrowUp&&this.canUserPerformAction(C.Zoom)&&(a.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%");o.call(this.zoomBehavior=N.zoom().filter(a=>a.type!==E.DoubleClick).on(ue.Zoom,a=>{if(a.sourceEvent){if(!this.canUserPerformAction(C.Zoom)){A(P.NotAllowed);return}a.sourceEvent.type===E.Wheel&&a.sourceEvent.wheelDelta!==void 0?(a.sourceEvent.wheelDelta>0&&A(P.ZoomIn),a.sourceEvent.wheelDelta<0&&A(P.ZoomOut)):a.sourceEvent.type===E.MouseMove&&A(P.AllScroll)}this.zoomTransform=a.transform;const l=a.transform.toString();this.selectCanvasElements().attr("transform",l),N.select(`#${this.backgroundPatternId}`).attr("patternTransform",l),this.contextMenu.close()}).on(ue.End,()=>{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(E.MouseMove,a=>{if(this.unfinishedConnection!==void 0){const l=this.getPointerLocationRelativeToCanvas(a);this.unfinishedConnection.endCoords=l}}).on(E.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new it(null)))}).on(E.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new it(null))),this.contextMenu.close(),this.userSelection.size()>0){const a=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(a,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(N.drag().filter(a=>this.multipleSelectionOn||wt(a)).on(M.Start,a=>{this.startMultipleSelection(a)}).on(M.Drag,a=>{this.continueMultipleSelection(a)}).on(M.End,a=>{this.finishMultipleSelection(a)})),Eo(this,o,this.backgroundPatternId),o.append("g").attr("class","daga-canvas-elements")}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView(),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView(),t)}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView(),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView(),t,e)}center(){var t;if(this.model.nodes.length>0){const e=(t=this.selectCanvasView().select("rect").node())==null?void 0:t.getBBox(),o=this.model.nodes.all(),a=Math.min(...o.map(f=>f.coords[0])),l=Math.max(...o.map(f=>f.coords[0]+f.width)),s=(a+l)/2,n=l-a,r=e.width,c=Math.min(...o.map(f=>f.coords[1])),d=Math.max(...o.map(f=>f.coords[1]+f.height)),h=(c+d)/2,u=d-c,p=e.height,m=Math.min(r/n,p/u,1);this.translateTo(s,h),this.zoomTo(m)}}getClosestGridPoint(t){return this.gridSize===0||!isFinite(this.gridSize)?t:[Math.round(t[0]/this.gridSize)*this.gridSize,Math.round(t[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){var o;const t=(o=this.selectSVGElement().node())==null?void 0:o.getBoundingClientRect(),e=[(t==null?void 0:t.width)||0,(t==null?void 0:t.height)||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return N.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return N.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return N.pointer(this.getEventHoldingCoordinates(t),N.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0),s=>s.id);const o=e.exit(),a=e.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}`);t&&t.length>0&&(e=e.filter(s=>t.includes(s.id)));const l=a.merge(e);o.remove(),a.on(E.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(r,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new G([n],n.selected))}).on(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)),this.userSelection.add(n),this.diagramEvent$.next(new G([n],!0)),this.contextMenu.open(s))}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(s):this.startMovingNode(s,n)}).on(M.Drag,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(s):this.continueMovingNode(s,n)}).on(M.End,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(s):this.finishMovingNode(s,n),this.secondaryButton=!1})),de(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A(P.EWResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(A(P.EWResize),this.currentAction=new q(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(P.NotAllowed)}).on(M.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(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof q&&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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A(P.NSResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(A(P.NSResize),this.currentAction=new q(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(P.NotAllowed)}).on(M.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(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof q&&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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A(P.EWResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed?(A(P.EWResize),this.currentAction=new q(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(P.NotAllowed)}).on(M.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(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof q&&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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A(P.NSResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed?(A(P.NSResize),this.currentAction=new q(this,C.StretchNode,n.id,n.getGeometry(),n.getGeometry())):A(P.NotAllowed)}).on(M.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(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof q&&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),he(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/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",H/2).attr("y2",H/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",s=>s.width-H/2).attr("x2",s=>s.width-H/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-H/2).attr("y2",s=>s.height-H/2)}updateSectionsInView(...t){let e=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=e.exit(),a=e.enter().append("g").attr("id",s=>s.id).attr("class",s=>{var n;return`diagram-section${s.getResizableX()?" resizable-x":""}${s.getResizableY()?" resizable-y":""} ${(n=s.look)==null?void 0:n.lookType}`});t&&t.length>0&&(e=e.filter(s=>t.includes(s.id)));const l=a.merge(e);o.remove(),a.on(E.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}const r=ft(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const c=ft(n);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(s)}}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.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(P.NotAllowed)}}).on(M.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(P.NotAllowed)}}).on(M.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})),de(a),a.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&A(P.EWResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(A(P.EWResize),this.currentAction=new q(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const r=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Left,n.coords[0]-r[0],n.indexXInNode,n.indexYInNode)}}).on(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof q&&this.currentAction.intent===C.StretchSection&&n.node){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.node.stretchSections(k.Left,n.coords[0]-r[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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&A(P.NSResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(A(P.NSResize),this.currentAction=new q(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const r=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Top,n.coords[1]-r[1],n.indexXInNode,n.indexYInNode)}}).on(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof q&&this.currentAction.intent===C.StretchSection&&n.node){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.node.stretchSections(k.Top,n.coords[1]-r[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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&A(P.EWResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(A(P.EWResize),this.currentAction=new q(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const r=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Right,r[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof q&&this.currentAction.intent===C.StretchSection&&n.node){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.node.stretchSections(k.Right,r[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",`${H}px`).on(E.MouseOver,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&A(P.NSResize)}).on(E.MouseOut,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&A()}).call(N.drag().on(M.Start,(s,n)=>{this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(A(P.NSResize),this.currentAction=new q(this,C.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const r=this.getPointerLocationRelativeToCanvas(s);n.node.stretchSections(k.Bottom,r[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on(M.End,(s,n)=>{if(this.canUserPerformAction(C.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof q&&this.currentAction.intent===C.StretchSection&&n.node){let r=this.getPointerLocationRelativeToCanvas(s);this.snapToGrid&&(r=this.getClosestGridPoint(r)),n.node.stretchSections(k.Bottom,r[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),he(l),l.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/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",H/2).attr("y2",H/2),l.filter(".resizable-x").select("line.right-resizer").attr("x1",s=>s.width-H/2).attr("x2",s=>s.width-H/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-H/2).attr("y2",s=>s.height-H/2)}updatePortsInView(...t){let e=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=e.exit(),a=e.enter().append("g").attr("id",s=>s.id).attr("class",s=>`diagram-port ${s.look.lookType}`);t&&t.length>0&&(e=e.filter(s=>t.includes(s.id)));const l=a.merge(e);o.remove(),a.on(E.MouseOver,(s,n)=>{var r,c,d,h,u,p,m,f,g,y,w,b;!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((d=(c=(r=this.unfinishedConnection.start)==null?void 0:r.getNode())==null?void 0:c.type)==null?void 0:d.id)||"")&&((h=this.unfinishedConnection.start)!=null&&h.allowsOutgoing)&&this.unfinishedConnection.type.canFinishOnType(((p=(u=n.getNode())==null?void 0:u.type)==null?void 0:p.id)||"")&&n.allowsIncoming||this.unfinishedConnection.type.canStartFromType(((f=(m=n.getNode())==null?void 0:m.type)==null?void 0:f.id)||"")&&n.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(((w=(y=(g=this.unfinishedConnection.start)==null?void 0:g.getNode())==null?void 0:y.type)==null?void 0:w.id)||"")&&((b=this.unfinishedConnection.start)!=null&&b.allowsIncoming)||A(P.NoDrop))}).on(E.MouseOut,()=>{this.unfinishedConnection&&A(P.Grabbing)}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}const r=ft(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const c=ft(n);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(s)}}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,(s,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(s):this.canUserPerformAction(C.AddConnection)&&(this.allowSharingPorts||n.incomingConnections.length===0&&n.outgoingConnections.length===0)&&!n.removed?(A(P.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):A(P.NotAllowed)}).on(M.Drag,(s,n)=>{var r,c,d,h;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else if(this.canUserPerformAction(C.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const u=[s.x,s.y];(d=this.unfinishedConnectionTracer)==null||d.attr("d",ce(this.unfinishedConnection.look.shape||ot.look.shape,this.unfinishedConnection.startCoords,u,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.look.thickness||ot.look.thickness,(r=this.unfinishedConnection.startMarkerLook)==null?void 0:r.width,(c=this.unfinishedConnection.endMarkerLook)==null?void 0:c.width));const p=(h=this.unfinishedConnectionTracer)==null?void 0:h.node();if(p){let m=2;const f=p.getTotalLength();f<m&&(m=0);const g=p.getPointAtLength(f-m);this.unfinishedConnection.endCoords=[g.x,g.y]}else this.unfinishedConnection.endCoords=u;if(this.updateConnectionsInView(ge),this.model.ports.length>0){const m=this.getPointerLocationRelativeToCanvas(s);let f=Number.POSITIVE_INFINITY,g;for(const y of this.model.ports){const w=y.distanceTo(m);w<f&&(f=w,g=y)}g&&f<this.portHighlightRadius?this.userHighlight.focusOn(g):this.userHighlight.clear()}}}).on(M.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 c=this.userHighlight.getFocus();if(c instanceof Ct)this.finishConnection(c);else if(c instanceof mt&&c.rootElement instanceof Ct)this.finishConnection(c.rootElement);else if(c instanceof j||c instanceof U||c instanceof mt){let d;if(c instanceof j||c instanceof U)d=c;else if(c.rootElement instanceof j||c.rootElement instanceof U)d=c.rootElement;else{this.dropConnection();return}const h=d.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"),de(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),he(l)}updateConnectionsInView(...t){const e=this.model.connections.filter(n=>this.priorityThreshold!==void 0?n.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let o=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,n=>n.id);const a=o.exit(),l=o.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");t&&t.length>0&&(o=o.filter(n=>t.includes(n.id)));const s=l.merge(o);a.remove(),l.on(E.MouseOver,(n,r)=>{r.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new it(r)))}).on(E.Click,(n,r)=>{if(!n.ctrlKey&&!n.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(n,r)=>{if(this.dragging){n.preventDefault(),n.stopPropagation(),this.dragging=!1;return}const c=new kt(n,r);this.diagramEvent$.next(c),!c.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new it(r)),this.userSelection.add(r),this.diagramEvent$.next(new G([r],!0)),this.contextMenu.open(n))}).on(E.DoubleClick,(n,r)=>{const c=new bt(n,r);this.diagramEvent$.next(c)}).call(N.drag().filter(n=>(this.secondaryButton=wt(n),!0)).on(M.Start,n=>{this.startMultipleSelection(n)}).on(M.Drag,n=>{this.continueMultipleSelection(n)}).on(M.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,c;return ce(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness||ot.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(c=n.endMarkerLook)==null?void 0:c.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||ot.look.color).attr("stroke-width",n=>`${n.look.thickness}px`).attr("stroke-dasharray",n=>me(n.look.style||ot.look.style,n.look.thickness||ot.look.thickness)).attr("fill","none"),s.select("path.diagram-connection-path-box").attr("d",n=>{var r,c;return ce(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.look.thickness||ot.look.thickness,(r=n.startMarkerLook)==null?void 0:r.width,(c=n.endMarkerLook)==null?void 0:c.width)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",n=>`${(n.look.thickness||ot.look.thickness)+Vo}px`).attr("stroke-dasharray",n=>me(n.look.style||ot.look.style,n.look.thickness||ot.look.thickness)).attr("fill","none"),s.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...t){let e=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=e.exit(),a=e.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(s=>t.includes(s.id)));const l=a.merge(e);o.remove(),a.style("box-sizing","border-box").on(E.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(c,!1))}const r=ft(n);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}).on(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)){s.preventDefault();const c=ft(n);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(s)}}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.EditField)&&n.editable&&!n.removed&&(this.currentAction=new ci(this,n.id,n.text,""),this.createInputField(n.text,n.coords,n.width,n.height,n.fontSize,n.fontFamily||D.fontFamily,n.orientation,c=>{},c=>{n.text=c,this.currentAction instanceof ci&&(this.currentAction.to=c,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.startMovingNode(s,r):A(P.NotAllowed)}}).on(M.Drag,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.continueMovingNode(s,r):A(P.NotAllowed)}}).on(M.End,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(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===Nt.Center?"center":s.horizontalAlign===Nt.Right?"flex-end":"flex-start").style("align-items",s=>s.verticalAlign===Zt.Center?"center":s.verticalAlign===Zt.Bottom?"end":"start").select("p").style("max-width",s=>s.fit?"default":`${hi(s.width,s.height,s.orientation)[0]}px`).style("max-height",s=>s.fit?"default":`${hi(s.width,s.height,s.orientation)[1]}px`).style("overflow",s=>s.fit?"default":"clip").style("text-overflow",s=>s.fit?"default":"ellipsis").style("text-align",s=>s.horizontalAlign===Nt.Center?"center":s.horizontalAlign===Nt.Right?"end":"start").style("transform",s=>`rotate(${s.orientation}deg)`).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(...t){let e=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=e.exit(),a=e.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(s=>t.includes(s.id))),a.merge(e).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(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&(s.preventDefault(),this.contextMenu.open(s))}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,s=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(s)}).on(M.Drag,s=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(s)}).on(M.End,s=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(s)}))}updateDecoratorsInView(...t){let e=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=e.exit(),a=e.enter().append("foreignObject").attr("id",s=>s.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(s=>t.includes(s.id))),a.merge(e).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(E.MouseOver,(s,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new it(n)))}).on(E.Click,(s,n)=>{if(!s.ctrlKey&&!s.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new G(r,!1))}if(n.rootElement){const r=ft(n.rootElement);this.userSelection.toggle(r),this.diagramEvent$.next(new G([r],r.selected))}}).on(E.ContextMenu,(s,n)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const r=new kt(s,n);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(C.ContextMenu)&&n.rootElement){s.preventDefault();const c=ft(n.rootElement);this.userHighlight.focusOn(c),this.diagramEvent$.next(new it(c)),this.userSelection.add(c),this.diagramEvent$.next(new G([c],!0)),this.contextMenu.open(s)}}).on(E.DoubleClick,(s,n)=>{const r=new bt(s,n);this.diagramEvent$.next(r)}).call(N.drag().filter(s=>(this.secondaryButton=wt(s),!0)).on(M.Start,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.startMovingNode(s,r):A(P.NotAllowed)}}).on(M.Drag,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.continueMovingNode(s,r):A(P.NotAllowed)}}).on(M.End,(s,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(s);else{let r;n.rootElement instanceof j?r=n.rootElement:n.rootElement instanceof U&&(r=n.rootElement.node),r?this.finishMovingNode(s,r):A()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){var s,n,r;const e=this.selectCanvasView().select(`[id='${fe(t.id)}']`),a=e.select("path").node(),l={...D,...t.type.label};if(a){const c=a.getTotalLength();let d=0,h=0,u=0,p=0,m=0,f=0;if(l.backgroundColor==="#00000000"){const b=t.endCoords[0]-t.startCoords[0],I=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case k.Top:d=b>=0?1:-1,u=d,m=d,h=-1;break;case k.Bottom:d=b>=0?1:-1,u=d,m=d,h=1;break;case k.Left:d=-1,h=I>0?1:-1,p=h,f=h;break;case k.Right:d=1,h=I>0?1:-1,p=h,f=h;break;default:d=1,u=d,m=d,h=-1,p=h,f=h}switch(t.endDirection){case k.Top:m=b>=0?1:-1,u=m,f=1;break;case k.Bottom:m=b>=0?1:-1,u=m,f=-1;break;case k.Left:m=-1,f=I>0?1:-1,p=f;break;case k.Right:m=1,f=I>0?1:-1,p=f;break;default:m=1,u=m,f=-1,p=f}}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=(s=e.select("g.diagram-connection-start-label text").node())==null?void 0:s.getBoundingClientRect();if(g){const b=t.startLabel?g.width/this.zoomTransform.k+Ft(l)+Ht(l):0,I=t.startLabel?g.height/this.zoomTransform.k+Gt(l)+Dt(l):0,S=a.getPointAtLength(Math.max(Q(l)+b/2,lt(l)+b/2,W(l)+I/2,st(l)+I/2));e.select("g.diagram-connection-start-label path").attr("d",Wt(-b/2,-I/2,b,I)).attr("fill",l.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${S.x+d*b},${S.y+h*I})`)}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 y=(n=e.select("g.diagram-connection-middle-label text").node())==null?void 0:n.getBoundingClientRect();if(y){const b=t.middleLabel?y.width/this.zoomTransform.k+Ft(l)+Ht(l):0,I=t.middleLabel?y.height/this.zoomTransform.k+Gt(l)+Dt(l):0,S=a.getPointAtLength(c/2);e.select("g.diagram-connection-middle-label path").attr("d",Wt(-b/2,-I/2,b,I)).attr("fill",l.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${S.x+u*b},${S.y+p*I})`)}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 w=(r=e.select("g.diagram-connection-end-label text").node())==null?void 0:r.getBoundingClientRect();if(w){const b=t.endLabel?w.width/this.zoomTransform.k+Ft(l)+Ht(l):0,I=t.endLabel?w.height/this.zoomTransform.k+Gt(l)+Dt(l):0,S=a.getPointAtLength(c-Math.max(Q(l)+b/2,lt(l)+b/2,W(l)+I/2,st(l)+I/2));e.select("g.diagram-connection-end-label path").attr("d",Wt(-b/2,-I/2,b,I)).attr("fill",l.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${S.x+m*b},${S.y+f*I})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${fe(t.id)}']`),o=e.select("marker.diagram-connection-start-marker"),a=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?o.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.width).attr("markerHeight",t.startMarkerLook.height).attr("refX",t.startMarkerLook.refX).attr("refY",t.startMarkerLook.refY).select("image").attr("href",t.startMarkerLook.image).attr("width",t.startMarkerLook.width).attr("height",t.startMarkerLook.height):o.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.width).attr("markerHeight",t.endMarkerLook.height).attr("refX",t.endMarkerLook.refX).attr("refY",t.endMarkerLook.refY).select("image").attr("href",t.endMarkerLook.image).attr("width",t.endMarkerLook.width).attr("height",t.endMarkerLook.height):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){var o,a,l,s;const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof j||e.rootElement instanceof U){const n=this.minimumSizeOfField(e),r=n[0]+Q((o=e.rootElement.type)==null?void 0:o.label)+lt((a=e.rootElement.type)==null?void 0:a.label)-e.rootElement.width,c=n[1]+W((l=e.rootElement.type)==null?void 0:l.label)+st((s=e.rootElement.type)==null?void 0:s.label)-e.rootElement.height;return r<=0&&c<=0}return!0}fitFieldRootInView(t,e=!0){var a,l,s;const o=this.model.fields.get(t);if(o){if(o.rootElement instanceof j){const n=this.minimumSizeOfField(o);let r=n[0]+Q(o.rootElement.type.label)+lt(o.rootElement.type.label)-o.rootElement.width,c=n[1]+W(o.rootElement.type.label)+st(o.rootElement.type.label)-o.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,c=Math.ceil(c/this.gridSize)*this.gridSize),o.rootElement.width+r<o.rootElement.type.minWidth&&(r=o.rootElement.type.minWidth-o.rootElement.width),o.rootElement.height+c<o.rootElement.type.minHeight&&(c=o.rootElement.type.minHeight-o.rootElement.height),(e!==!1||r>0)&&o.rootElement.stretch(k.Right,r),(e!==!1||c>0)&&o.rootElement.stretch(k.Bottom,c)}if(o.rootElement instanceof U){const n=this.minimumSizeOfField(o);let r=n[0],c=n[1];for(const p of((a=o.rootElement.node)==null?void 0:a.sections)||[])p.label&&(p.indexXInNode===o.rootElement.indexXInNode&&p.indexYInNode!==o.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(p.label)[0]):p.indexXInNode!==o.rootElement.indexXInNode&&p.indexYInNode===o.rootElement.indexYInNode&&(c=Math.max(c,this.minimumSizeOfField(p.label)[1])));n[0]<r&&(n[0]=r),n[1]<c&&(n[1]=c);const d=o.rootElement.type;let h=n[0]+Q(d==null?void 0:d.label)+lt(d==null?void 0:d.label)-o.rootElement.width,u=n[1]+W(d==null?void 0:d.label)+st(d==null?void 0:d.label)-o.rootElement.height;this.snapToGrid&&(h=Math.ceil(h/this.gridSize)*this.gridSize,u=Math.ceil(u/this.gridSize)*this.gridSize),o.rootElement.width+h<(o.rootElement.getMinWidth()||0)&&(h=(o.rootElement.getMinWidth()||0)-o.rootElement.width),o.rootElement.height+u<(o.rootElement.getMinHeight()||0)&&(u=(o.rootElement.getMinHeight()||0)-o.rootElement.height),(e||h>0)&&((l=o.rootElement.node)==null||l.stretchSections(k.Right,h,o.rootElement.indexXInNode,o.rootElement.indexYInNode)),(e||u>0)&&((s=o.rootElement.node)==null||s.stretchSections(k.Bottom,u,o.rootElement.indexXInNode,o.rootElement.indexYInNode))}}}fitNodeInView(t,e=!0){var a,l;const o=this.model.nodes.get(t);if(o&&o.sections.length>0&&this.priorityThreshold){let s=0,n=0;for(const r of o.sections)if(r.getPriority()>=this.priorityThreshold){const c=r.coords[0]+r.width-o.coords[0],d=r.coords[1]+r.height-o.coords[1];s=Math.max(s,c),n=Math.max(n,d)}s+=((a=o.type.sectionGrid)==null?void 0:a.margin)||0,n+=((l=o.type.sectionGrid)==null?void 0:l.margin)||0,(e||s>o.width)&&o.stretch(k.Right,s-o.width),(e||n>o.height)&&o.stretch(k.Bottom,n-o.height)}}selectRoot(){return N.select(this.diagramRoot)}selectSVGElement(){return N.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){var e,o,a,l;if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(((o=(e=t.getNode())==null?void 0:e.type)==null?void 0:o.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 ht(this.model,this.connectionType,t,void 0,ge);else if(this.inferConnectionType){let s=this.model.connections.types.all().find(n=>{var r,c;return t.allowsOutgoing&&n.canStartFromType(((c=(r=t.getNode())==null?void 0:r.type)==null?void 0:c.id)||"")});s===void 0&&(s=this.model.connections.types.all().find(n=>{var r,c;return t.allowsIncoming&&n.canFinishOnType(((c=(r=t.getNode())==null?void 0:r.type)==null?void 0:c.id)||"")})),s!==void 0&&(this.unfinishedConnection=new ht(this.model,s,t,void 0,ge))}}}finishConnection(t){var e,o,a,l,s,n,r,c,d,h,u,p,m,f,g,y,w,b,I,S;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0){if(!this.allowConnectionLoops&&this.unfinishedConnection.start===t){this.dropConnection();return}if(!this.allowSharingPorts&&(t.incomingConnections.length>0||t.outgoingConnections.length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(L=>{var $,x;return L.start===(($=this.unfinishedConnection)==null?void 0:$.start)&&L.end===t||L.end===((x=this.unfinishedConnection)==null?void 0:x.start)&&L.start===t})!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(((l=(a=(o=(e=this.unfinishedConnection)==null?void 0:e.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(((c=(r=t.getNode())==null?void 0:r.type)==null?void 0:c.id)||"")&&t.allowsIncoming){const L=new le(this,this.unfinishedConnection.type,(d=this.unfinishedConnection.start)==null?void 0:d.id,t.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.unfinishedConnection.type.canFinishOnType(((m=(p=(u=(h=this.unfinishedConnection)==null?void 0:h.start)==null?void 0:u.getNode())==null?void 0:p.type)==null?void 0:m.id)||"")&&((g=(f=this.unfinishedConnection)==null?void 0:f.start)!=null&&g.allowsIncoming)&&this.unfinishedConnection.type.canStartFromType(((w=(y=t.getNode())==null?void 0:y.type)==null?void 0:w.id)||"")&&t.allowsOutgoing){const L=new le(this,this.unfinishedConnection.type,t.id,(b=this.unfinishedConnection.start)==null?void 0:b.id);this.dropConnection(),L.do(),this.actionStack.add(L)}else if(this.inferConnectionType){let L=this.model.connections.types.all().find(x=>{var V,T,R,Y,O,K,F,B;return x.canStartFromType(((Y=(R=(T=(V=this.unfinishedConnection)==null?void 0:V.start)==null?void 0:T.getNode())==null?void 0:R.type)==null?void 0:Y.id)||"")&&((K=(O=this.unfinishedConnection)==null?void 0:O.start)==null?void 0:K.allowsOutgoing)&&x.canFinishOnType(((B=(F=t.getNode())==null?void 0:F.type)==null?void 0:B.id)||"")&&t.allowsIncoming}),$=!1;if(L===void 0&&(L=this.model.connections.types.all().find(x=>{var V,T,R,Y,O,K,F,B;return x.canFinishOnType(((Y=(R=(T=(V=this.unfinishedConnection)==null?void 0:V.start)==null?void 0:T.getNode())==null?void 0:R.type)==null?void 0:Y.id)||"")&&((K=(O=this.unfinishedConnection)==null?void 0:O.start)==null?void 0:K.allowsIncoming)&&x.canStartFromType(((B=(F=t.getNode())==null?void 0:F.type)==null?void 0:B.id)||"")&&t.allowsOutgoing}),$=!0),L!==void 0){const x=new le(this,L,$?t.id:(I=this.unfinishedConnection.start)==null?void 0:I.id,$?(S=this.unfinishedConnection.start)==null?void 0:S.id:t.id);this.dropConnection(),x.do(),this.actionStack.add(x)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){var t,e,o,a;(t=this.unfinishedConnection)==null||t.setStart(void 0),(e=this.unfinishedConnection)==null||e.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(t){return this.userActions[t]!==!1}createInputField(t,e,o,a,l,s,n,r,c){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${o}px`).attr("height",`${a}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const h=d.append("xhtml:textarea");let u,p;h.text(t).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(E.KeyDown,f=>{f.stopPropagation()}).on(E.KeyUp,f=>{if(f.stopPropagation(),f.key===et.Escape){const g=h.property("value");this.removeInputField(),c&&c(g)}}).on(E.Input,()=>{const f=h.property("value");h.attr("cols",Wi(f)+1),h.attr("rows",Zi(f)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,p=h.property("scrollHeight")+1;const g=Math.max(u,o),y=Math.max(p,a);d==null||d.attr("width",`${g}px`),h.style("width",`${g}px`),d==null||d.attr("height",`${y}px`),h.style("height",`${y}px`),r&&r(f)}).on(E.Click,f=>{f.stopPropagation()}).on(E.FocusOut,()=>{const f=h.property("value");this.removeInputField(),c&&c(f)});const m=h.node();m.focus(),m.select()}removeInputField(){var t,e,o;(e=(t=this.inputFieldContainer)==null?void 0:t.select("input"))==null||e.on(E.Blur,null),(o=this.inputFieldContainer)==null||o.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 o=e.getBoundingClientRect();return[o.width/this.zoomTransform.k,o.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(C.MoveNode)&&!e.removed)if(A(P.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(o=>o instanceof j)>1)this.currentAction=new ae(this,this.userSelection.filter(o=>o instanceof j).map(o=>o.id),e.coords);else{const o=e.getLastAncestor();this.currentAction=new q(this,C.MoveNode,e.id,e.getGeometry(),e.getGeometry(),o==null?void 0:o.id,o==null?void 0:o.getGeometry(e.id),o==null?void 0:o.getGeometry(e.id))}else A(P.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(C.MoveNode)&&(this.currentAction instanceof ae||this.currentAction instanceof q)&&!e.removed){const o=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([o[0]-e.coords[0],o[1]-e.coords[1]]):e.move(o),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){var o,a,l;if(this.canUserPerformAction(C.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let s=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(s=this.getClosestGridPoint(s)),this.currentAction instanceof ae){const n=this.currentAction.delta;this.currentAction.delta=[s[0]-n[0],s[1]-n[1]],e.selected?this.userSelection.move([n[0]-e.coords[0],n[1]-e.coords[1]]):e.move(n)}else if(this.currentAction instanceof q){e.move(s);const r=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)),c=wi(r),d=c[c.length-1];if(d!==e.parent&&(e.type.canBeParentless||d!==void 0)){const h=d==null?void 0:d.getLastAncestor(),u=this.currentAction.from,p=new ko(this,e.id,(o=e.parent)==null?void 0:o.id,d==null?void 0:d.id,u,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),d!==void 0&&d.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)}A(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectSVGElement().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){var o,a,l,s;const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(A(P.Crosshair),(s=(l=(a=(o=this.multipleSelectionContainer)==null?void 0:o.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x))==null?void 0:a.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y))==null?void 0:l.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k))==null||s.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){var o;const e=this.getPointerLocationRelativeToCanvas(t);(o=this.multipleSelectionContainer)==null||o.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)ji([a.coords,[a.coords[0]+a.width,a.coords[1]+a.height]],[this.draggingFrom,e])&&this.userSelection.add(a);this.multipleSelectionOn=!1,this.diagramEvent$.next(new G(this.userSelection.all(),!0)),A()}};qt.canvasCount=0;let ye=qt;class Ti{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 o=1;;++o){const a=o%2>0?o:-o,l=a>0?1:-1,s=[e[0]+a,e[1]+a];for(let n=e[0];n!==s[0]+l;n+=l)if(e[0]=n,this.get(e)===void 0)return e;for(let n=e[1];n!==s[1]+l;n+=l)if(e[1]=n,this.get(e)===void 0)return e}}}class jo{constructor(t){this.gapSize=t}apply(t){var n;if(t.nodes.length===0)return t;const e=new Ti,o=t.nodes.filter(r=>!r.parent);for(;o.length>0;)$i(o[0],e,[0,0],o);const a=Math.max(...t.nodes.map(r=>r.width)),l=Math.max(...t.nodes.map(r=>r.height)),s=this.gapSize!==void 0?this.gapSize:(((n=t.canvas)==null?void 0:n.gridSize)||0)*2;for(let r=e.minY();r<=e.maxY();++r)for(let c=e.minX();c<=e.maxX();++c){const d=e.get([c,r]);d!==void 0&&d.move([c*(a+s),r*(l+s)])}return t}}const $i=(i,t,e,o)=>{const a=t.getClosestEmptyCoordinate(e);t.set(a,i),Z(o,i);for(const l of i.getAdjacentNodes())o.includes(l)&&$i(l,t,a,o)};class Oo{constructor(t){this.gapSize=t}apply(t){var d;if(t.nodes.length===0)return t;const e=new Ti,o=t.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 u of s){e.set(e.getClosestEmptyCoordinate(a[u.id]),u),Z(o,u);const p=u.getAdjacentNodes();for(const m of p)o.includes(m)&&(h.push(m),a[m.id]=a[u.id])}if(h.length>0)s=h;else if(o.length>0){const u=o[0];s=[u],a[u.id]=e.getClosestEmptyCoordinate([0,0])}}const n=Math.max(...t.nodes.map(h=>h.width)),r=Math.max(...t.nodes.map(h=>h.height)),c=this.gapSize!==void 0?this.gapSize:(((d=t.canvas)==null?void 0:d.gridSize)||0)*2;for(let h=e.minY();h<=e.maxY();++h)for(let u=e.minX();u<=e.maxX();++u){const p=e.get([u,h]);p!==void 0&&p.move([u*(n+c),h*(r+c)])}return t}}class se{constructor(t){this.gapSize=t}apply(t){var n;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((n=t.canvas)==null?void 0:n.gridSize)||0)*2;let o=t.nodes.filter(r=>!r.parent);const a=o[0];Z(o,a);const l=[[a]];for(;o.length>0;){const r=l[l.length-1],c=[];for(const d of r){const h=d.getAdjacentNodes();for(const u of h)o.includes(u)&&(Z(o,u),c.push(u))}c.length>0?l.push(c):(l.push(o),o=[])}let s=0;for(const r of l){let c=0;for(const h of r)h.move([s,c]),c+=e+h.height;const d=Math.max(...r.map(h=>h.width));s+=e+d}for(const r of t.connections)r.tighten();return t}}class Do{constructor(t){this.gapSize=t}apply(t){var h;if(t.nodes.length===0)return t;new se(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,o=.99,a=1,l=.1,s=2e5,n=.5,r=1,c=.002;let d=100;for(;d>a;){d=d*o;const u=[0,0];{for(const p of t.nodes)u[0]=u[0]+p.coords[0]+p.width/2,u[1]=u[1]+p.coords[1]+p.width/2;u[0]=u[0]/t.nodes.length,u[1]=u[1]/t.nodes.length}for(const p of t.nodes){const m=p.getAdjacentNodes();for(const f of t.nodes){const g=[p.coords[0]+p.width/2,p.coords[1]+p.height/2],y=[f.coords[0]+f.width/2,f.coords[1]+f.height/2],w=fi(p.coords,f.coords),b=[f.coords[0],f.coords[1]];if(m.includes(f)&&w>0&&(w>e+(Math.max(p.width,p.height)+Math.max(f.width,f.height))/2?(b[0]=b[0]-(y[0]-g[0])*l,b[1]=b[1]-(y[1]-g[1])*l):(b[0]=b[0]+(y[0]-g[0])*n,b[1]=b[1]+(y[1]-g[1])*n)),w>0){const I=s/(w*w);b[0]=b[0]+I*(y[0]-g[0])/w,b[1]=b[1]+I*(y[1]-g[1])/w}else b[0]=b[0]+r*(Math.random()*2-1),b[1]=b[1]+r*(Math.random()*2-1);b[0]=b[0]-(y[0]-u[0])*c,b[1]=b[1]-(y[1]-u[1])*c,b[0]-f.coords[0]>d?b[0]=f.coords[0]+d:b[0]-f.coords[0]<-d&&(b[0]=f.coords[0]-d),b[1]-f.coords[1]>d?b[1]=f.coords[1]+d:b[1]-f.coords[1]<-d&&(b[1]=f.coords[1]-d),f.move(b)}}}if(t.canvas&&t.canvas.snapToGrid)for(const u of t.nodes){const p=t.canvas.getClosestGridPoint(u.coords);u.move(p)}for(const u of t.connections)u.tighten();return t}}class Fo{constructor(t){this.gapSize=t}apply(t){var l;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,o=t.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+e;return t}}class Ho{constructor(t){this.gapSize=t}apply(t){var d;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(h=>h.getPriority())),o=Math.min(...t.nodes.map(h=>h.getPriority()));if(e===o)return new se(this.gapSize).apply(t),t;const a=this.gapSize!==void 0?this.gapSize:(((d=t.canvas)==null?void 0:d.gridSize)||0)*2,l=t.nodes.filter(h=>!h.parent),s=[],n=t.nodes.filter(h=>!h.parent).filter(h=>h.getPriority()>=e),r=[];if(n.length>1){const h=n[0];n.splice(0,1),r.push(h);const u=[h],p=[h];for(;u.length>0;){const m=u[0];u.splice(0,1),n.includes(m)&&(r.push(m),Z(n,m));const f=m.getAdjacentNodes();for(const g of f)p.includes(g)||(u.push(g),p.push(g))}for(const m of n)r.push(m)}else r.push(n[0]);for(const h of r)Z(l,h),s.push([h]);for(s.push([]),l.sort((h,u)=>u.type.priority-h.type.priority);l.length>0;){const h=l[0];l.splice(0,1);const u=[h],p=[h];let m=!1;for(;u.length>0;){const f=u[0];u.splice(0,1);const g=r.indexOf(f);if(g>=0){s[g].push(h),m=!0;break}else{const y=f.getAdjacentNodes();for(const w of y)p.includes(w)||(u.push(w),p.push(w))}}m||s[s.length-1].push(h)}let c=0;for(let h=0;h<s.length;++h){let u=0;for(let m=0;m<s[h].length;++m){const f=s[h][m];f.move([c,u]),u+=a+f.height}const p=Math.max(...s[h].map(m=>m.width));c+=a+p}for(const h of t.connections)h.tighten();return t}}class Go{constructor(t){this.gapSize=t}apply(t){var d;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(h=>h.getPriority())),o=Math.min(...t.nodes.map(h=>h.getPriority()));if(e===o)return new se(this.gapSize).apply(t),t;const a=this.gapSize!==void 0?this.gapSize:(((d=t.canvas)==null?void 0:d.gridSize)||0)*2,l=t.nodes.filter(h=>!h.parent).sort((h,u)=>u.getPriority()-h.getPriority()),s=[];for(;l.length>0;){const h=l[0];l.splice(0,1);const u=new xe(void 0,h);Mi(u,l),s.push(u)}const n=[];for(const h of s)n.push([h]),Ni(h,n,n.length);const r=Math.max(...t.nodes.map(h=>h.height));let c=0;for(let h=0;h<n.length;++h){let u=0;for(let m=0;m<n[h].length;++m){const f=n[h][m];f.node.move([c,u]),u+=(a+r)*f.countBranchHeight()}const p=Math.max(...n[h].map(m=>m.node.width));c+=a+p}for(const h of t.connections)h.tighten();return t}}const Mi=(i,t)=>{for(const e of i.node.getAdjacentNodes().sort((o,a)=>a.getPriority()-o.getPriority())){const o=t.indexOf(e);if(o>=0){t.splice(o,1);const a=i.addBranch(e);Mi(a,t)}}},Ni=(i,t,e)=>{if(i.branches.length>0){for(;e>=t.length;)t.push([]);for(const o of i.branches)t[e].push(o),Ni(o,t,e+1)}};class xe{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new xe(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 Bo{constructor(t){this.gapSize=t}apply(t){var l;if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(((l=t.canvas)==null?void 0:l.gridSize)||0)*2,o=t.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+e;return t}}const gi={adjacency:new jo,breadth:new se,"breadth-adjacency":new Oo,force:new Do,horizontal:new Fo,priority:new Ho,tree:new Go,vertical:new Bo},Uo=z.createContext({}),Lt=z.createContext({});class Yo{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){}}const Ce=({direction:i,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:o,disabled:a,rule:l,collapsedValue:s,visibleValue:n,onCollapse:r})=>{const[c,d]=z.useState(o),h=()=>{if(!a){const p=!c;d(p),r==null||r(p);let m;if(typeof t=="string")m=N.select(t),e&&(m=m.select(e));else{const f=t;if(!f)throw new Error("collapsableSelector is not a valid ref");m=N.select(f.current),e&&(m=m.select(e))}m.style(l,p?s:n)}},u=()=>{switch(i){case k.Right:return a?"daga-horizontal-none":c?"daga-horizontal-right":"daga-horizontal-left";case k.Bottom:return a?"daga-vertical-none":c?"daga-vertical-down":"daga-vertical-up";case k.Left:return a?"daga-horizontal-none":c?"daga-horizontal-left":"daga-horizontal-right";case k.Top:return a?"daga-vertical-none":c?"daga-vertical-up":"daga-vertical-down"}};return v.jsx("daga-collapse-button",{children:v.jsx("button",{className:`daga-collapse-button daga-${i}`,onClick:h,children:v.jsx("div",{className:u()})})})},Xo=()=>{const i=z.useContext(Lt),t=z.useRef(null),[e,o]=z.useState([]);At.merge(i.validatorChange$,i.diagramChange$).pipe(At.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,c,d;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(),(d=(c=i.parentComponent)==null?void 0:c.propertyEditor)==null||d.highlightProperty(...s.propertyNames))};return v.jsx("daga-errors",{children:v.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&v.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:v.jsx("span",{children:"No errors found"})}),e.length>0&&v.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[v.jsxs("span",{children:[e.length," errors found"]}),v.jsx("div",{className:"daga-collapse-button-container",children:v.jsx(Ce,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:k.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&v.jsx("div",{className:"daga-error-panel",children:v.jsx("ol",{children:e.map((s,n)=>v.jsx("li",{onClick:()=>l(s),dangerouslySetInnerHTML:{__html:s.message}},n))})})]})})},Wo=200,ui=i=>(i||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),Pi=({disabled:i,options:t,value:e,onChange:o})=>{const a=z.useRef(null),[l,s]=z.useState("");let n;const[r,c]=z.useState([]),[d,h]=z.useState([]),[u,p]=z.useState([]),[m,f]=z.useState([]),[g,y]=z.useState(!1);z.useEffect(()=>{var T;s(((T=t.find(R=>Et(R.key,e)))==null?void 0:T.label)||"")},[e,t]);const w=T=>{if(!i)switch(T.key){case et.PageDown:n===void 0?(S(0),$(0)):(S(n+5),$(n)),T.preventDefault();break;case et.ArrowDown:n===void 0?(S(0),$(0)):(S(n+1),$(n)),T.preventDefault();break;case et.PageUp:n===void 0?(S(t.length-1),$(t.length-1)):(S(n-5),$(n)),T.preventDefault();break;case et.ArrowUp:n===void 0?(S(t.length-1),$(t.length-1)):(S(n-1),$(n)),T.preventDefault();break;case et.Escape:I(),T.preventDefault();break;case et.Enter:V(t[n||0]),T.preventDefault();break;default:b()}},b=()=>{if(!i){const T=ui(l.trim());c([]),h([]),p([]),f([]);for(const R of t){const O=ui(R.label).indexOf(T);if(O>=0){const K=R.label.substring(0,O),F=R.label.substring(O,O+T.length),B=R.label.substring(O+T.length);c(X=>[...X,R]),h(X=>[...X,K]),p(X=>[...X,F]),f(X=>[...X,B])}}y(!0)}},I=()=>{y(!1)},S=T=>{if(!i){if(n=T,T===void 0)return;T<0&&(n=0),T>=t.length&&(n=t.length-1)}},L=()=>{setTimeout(()=>{I()},Wo)},$=T=>{var Y;const R=(Y=a.current)==null?void 0:Y.querySelectorAll("li")[T];R&&R.scrollIntoView({block:"center"})},x=()=>{i||(s(""),y(!1),n=void 0)},V=T=>{i||(s(T.label),y(!1),n=void 0,o(T.key))};return v.jsxs("div",{ref:a,className:`daga-autocomplete ${g?"daga-showing-options":""}`,children:[v.jsxs("div",{className:"daga-autocomplete-input",children:[v.jsx("input",{value:l,disabled:i,onKeyUp:w,onFocus:b,onBlur:L,onChange:T=>s(T.target.value)}),l!==""&&v.jsx("button",{className:"daga-clear",onClick:x})]}),v.jsx("div",{className:"daga-autocomplete-options",children:v.jsxs("ul",{className:"daga-autocomplete-option-list",children:[r.length===0&&v.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),r.map((T,R)=>v.jsxs("li",{className:`daga-autocomplete-option ${R===n?"daga-focused":""}`,onMouseMove:()=>S(R),onClick:()=>V(T),children:[v.jsx("span",{children:d[R]}),v.jsx("span",{className:"daga-match",children:u[R]}),v.jsx("span",{children:m[R]})]},R))]})})]})},Zo=(i,t)=>{var e;return((e=i.find(o=>o.key===t))==null?void 0:e.label)||`${t}`},Ko=({disabled:i,allowRepeats:t,options:e,value:o,onChange:a})=>{const[l,s]=z.useState(),[n,r]=z.useState([]),[c,d]=z.useState([]);z.useEffect(()=>{const g=o.length===0,y=o.map(w=>Zo(e,w));r(y),g&&a(o),f()},[o,e]);const h=g=>{for(const y of o)if(y===g)return!0;return!1},u=g=>{o.length>g&&(o.splice(g,1),r(n.filter((y,w)=>w!==g)),a(o),f())},p=()=>{l!==void 0&&(t||!h(l))&&(a(o.concat(l)),m())},m=()=>{s("")},f=()=>{if(!t){const g=[];for(const y of e)h(y.key)||g.push(y);d(g)}};return v.jsxs("div",{children:[o.map((g,y)=>v.jsxs("div",{className:"daga-value-item-element",children:[v.jsx("span",{className:"daga-input",children:n[y]}),!i&&v.jsx("button",{className:"daga-property-button",onClick:()=>u(y),children:v.jsx("div",{className:"daga-icon daga-close-icon"})})]},y)),!i&&v.jsxs("div",{className:"daga-value-item-input",children:[v.jsx("div",{className:"daga-input daga-relatively-positioned",children:v.jsx(Pi,{disabled:i,options:t?e||[]:c||[],value:l,onChange:s})}),v.jsx("button",{className:"daga-property-button",onClick:p,children:v.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},qo=({disabled:i,allowRepeats:t,value:e,onChange:o})=>{const[a,l]=z.useState(""),s=u=>{for(const p of u||[])if(p===u)return!0;return!1},n=u=>{e.length>u&&o(e.filter((p,m)=>m!==u))},r=(u,p,m)=>{const f=e.map((g,y)=>y===p?m==="blur"?u.trim():u:g);o(f)},c=()=>{const u=a.trim();u!==""&&(t||!s(u))&&(o(e.concat(u)),d())},d=()=>{l("")},h=u=>{u.key==="Enter"&&c()};return v.jsxs(v.Fragment,{children:[e.map((u,p)=>v.jsxs("div",{className:"daga-value-item-element",children:[v.jsx("input",{className:"daga-input",disabled:i,value:u,onChange:m=>r(m.target.value,p,"change"),onBlur:m=>r(m.target.value,p,"blur")}),v.jsx("button",{className:"daga-property-button",onClick:()=>n(p),children:v.jsx("div",{className:"daga-icon daga-close-icon"})})]},p)),!i&&v.jsxs("div",{className:"daga-value-item-input",children:[v.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[v.jsx("input",{type:"text",onKeyUp:h,value:a,onChange:u=>l(u.target.value)}),v.jsx("button",{className:"daga-clear",onClick:d})]}),v.jsx("button",{className:"daga-property-button",onClick:c,children:v.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Jo=({disabled:i,value:t,onChange:e})=>{const[o,a]=z.useState(""),[l,s]=z.useState(""),[n,r]=z.useState({}),c=g=>{const y={};Object.keys(t).forEach(w=>{w!==g&&(y[w]=t[w])}),e(y)},d=(g,y,w)=>{const b=w==="blur"?y.trim():y;if(w==="blur"){if(g!==b){const I={};Object.keys(t).forEach(S=>{S===g?I[b]=t[S]:I[S]=t[S]}),e(I),r(S=>{const L={...S};return delete L[g],L})}}else r(I=>({...I,[g]:y}))},h=(g,y,w)=>{const b=w==="blur"?y.trim():y;if(b!==""){const I={};Object.keys(t).forEach(S=>{S===g?I[S]=b:I[S]=t[S]}),e(I)}},u=()=>{const g=o.trim(),y=l.trim();if(g!==""&&y!==""){const w={};Object.keys(t).forEach(b=>{w[b]=t[b]}),w[g]=y,e(w),a(""),s("")}},p=()=>{a("")},m=()=>{s("")},f=g=>{g.key==="Enter"&&u()};return v.jsxs("div",{children:[Object.entries(t).map(([g,y],w)=>v.jsxs("div",{className:"daga-value-item-element",children:[v.jsx("input",{id:`key-${w}`,className:"daga-input",type:"text",disabled:i,value:n[g]??g,onChange:b=>d(g,b.target.value,"change"),onBlur:b=>d(g,b.target.value,"blur")}),v.jsx("input",{id:`value-${w}`,className:"daga-input",type:"text",disabled:i,value:y,onChange:b=>h(g,b.target.value,"change"),onBlur:b=>h(g,b.target.value,"blur")}),v.jsx("button",{className:"daga-property-button",onClick:()=>c(g),children:v.jsx("div",{className:"daga-icon daga-close-icon"})})]},g)),!i&&v.jsxs("div",{className:"daga-value-item-input",children:[v.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[v.jsx("input",{type:"text",value:o,onKeyUp:f,onChange:g=>a(g.target.value),onBlur:g=>d(o,g.target.value,"blur")}),v.jsx("button",{className:"daga-clear",onClick:p})]}),v.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[v.jsx("input",{type:"text",value:l,onKeyUp:f,onChange:g=>s(g.target.value),onBlur:g=>h(o,g.target.value,"blur")}),v.jsx("button",{className:"daga-clear",onClick:m})]}),v.jsx("button",{className:"daga-property-button",onClick:u,children:v.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},zi=({valueSet:i,onValueChange:t,depth:e})=>{var r;const a=z.useContext(Lt).canUserPerformAction(C.UpdateValues)&&((r=i==null?void 0:i.rootElement)==null?void 0:r.removed)!==!0,l=c=>"daga-property-name-"+c.replace(/\s/g,""),s=c=>{if(typeof c=="string")return c;if(c==null||isNaN(c.valueOf()))return"";const d=new Date(c),h=d.getTimezoneOffset();return d.setMinutes(d.getMinutes()-h),d.toISOString().substring(0,19)},n=c=>new Date(c);return v.jsx("daga-object-editor",{children:i.displayedProperties.map(c=>v.jsxs("div",{className:`daga-property ${l(c.name)}`,children:[v.jsx("p",{className:"daga-property-name",children:c.label||c.name}),c.type===_.Text&&v.jsx("input",{type:"daga-text",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.TextArea&&v.jsx("textarea",{disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Number&&v.jsx("input",{type:"number",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Color&&v.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Datetime&&v.jsx("input",{type:"datetime-local",disabled:c.editable===!1||!a,value:s(i==null?void 0:i.getValue(c.name)),onChange:d=>t(i,c,n(d.target.value))}),c.type===_.Date&&v.jsx("input",{type:"date",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Time&&v.jsx("input",{type:"time",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Url&&v.jsx("input",{type:"url",disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d.target.value)}),c.type===_.Boolean&&v.jsxs("div",{className:"daga-radio",children:[v.jsxs("label",{className:"daga-radio-item daga-radio-start"+((i==null?void 0:i.getValue(c.name))===!1?" daga-checked":""),children:[v.jsx("input",{type:"radio",disabled:c.editable===!1||!a,name:c.name,value:"false",checked:(i==null?void 0:i.getValue(c.name))===!1,onChange:()=>t(i,c,!1)}),"No"]}),v.jsxs("label",{className:"daga-radio-item daga-radio-end"+((i==null?void 0:i.getValue(c.name))===!0?" daga-checked":""),children:[v.jsx("input",{type:"radio",disabled:c.editable===!1||!a,name:c.name,value:"true",checked:(i==null?void 0:i.getValue(c.name))===!0,onChange:()=>t(i,c,!0)}),"Yes"]})]}),c.type===_.Option&&v.jsx("div",{className:"daga-relatively-positioned",children:v.jsx(Pi,{disabled:c.editable===!1||!a,options:c.options||[],value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d)})}),(c.type===_.OptionList||c.type===_.OptionSet)&&v.jsx(Ko,{disabled:c.editable===!1||!a,allowRepeats:c.type===_.OptionList,options:c.options||[],value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d)}),(c.type===_.TextList||c.type===_.TextSet)&&v.jsx(qo,{disabled:c.editable===!1||!a,allowRepeats:c.type===_.TextList,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d)}),c.type===_.TextMap&&v.jsx(Jo,{disabled:c.editable===!1||!a,value:i==null?void 0:i.getValue(c.name),onChange:d=>t(i,c,d)}),c.type===_.Object&&v.jsx("div",{className:"daga-left-bar",children:v.jsx(zi,{valueSet:i.getSubValueSet(c.name),onValueChange:t,depth:e+1})})]},c.name))})},Ri=({valueSet:i,depth:t})=>{const e=z.useContext(Lt),o=z.useRef(null),a=r=>"daga-property-name-"+r.replace(/\s/g,""),l=()=>{for(const r of(i==null?void 0:i.displayedProperties)||[]){let c=0,d=0,h=0;const u=N.select(o.current).select(`.daga-property.${a(r.name)}.daga-depth-${t}`);u.select("button.daga-move-button").call(N.drag().on(M.Start,p=>{var g;A(P.Grabbing);const m=e.getPointerLocationRelativeToScreen(p);if(m.length<2||isNaN(m[0])||isNaN(m[1]))return;const f=(g=u.node())==null?void 0:g.getBoundingClientRect();c=(f==null?void 0:f.width)||0,d=(f==null?void 0:f.height)||0,u.style("position","fixed").style("left",`${m[0]-c/2}px`).style("top",`${m[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1)}).on(M.Drag,p=>{A(P.Grabbing);const m=e.getPointerLocationRelativeToScreen(p);m.length<2||isNaN(m[0])||isNaN(m[1])||(u.style("position","fixed").style("left",`${m[0]-c/2}px`).style("top",`${m[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1),N.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0),h=s(m),N.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on(M.End,p=>{var f,g;A(P.Auto),u.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),N.select(o.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const m=e.getPointerLocationRelativeToScreen(p);m.length<2||isNaN(m[0])||isNaN(m[1])||(h=s(m),(f=i==null?void 0:i.displayedProperties)==null||f.splice(i.displayedProperties.indexOf(r),1),(g=i==null?void 0:i.displayedProperties)==null||g.splice(h,0,r))}))}},s=r=>{var h;const c=(i==null?void 0:i.propertySet.propertyList)||[],d=[];for(let u=0;u<=c.length;++u){const p=(h=N.select(o.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).node())==null?void 0:h.getBoundingClientRect();p&&d.push([p.x+p.width/2,p.y+p.height/2])}if(d.length>0){const u=d.map(m=>((r[0]-m[0])**2+(r[1]-m[1])**2)**.5);return u.indexOf(Math.min(...u))}return 0},n=r=>{var d;if(i===void 0)return;let c;r instanceof to?c=r:r instanceof Event?c=i==null?void 0:i.propertySet.getProperty(((d=r.target)==null?void 0:d.value)||""):c=i==null?void 0:i.propertySet.getProperty(r||""),c&&(i==null||i.hideProperty(c)),l()};return v.jsxs("daga-property-settings",{ref:o,children:[v.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),i==null?void 0:i.displayedProperties.map((r,c)=>v.jsxs("div",{className:`daga-property-and-dropbar ${a(r.name)} daga-depth-${t}`,children:[v.jsxs("div",{className:`daga-property ${a(r.name)} daga-depth-${t}`,children:[v.jsxs("div",{className:"daga-property-name",children:[v.jsx("span",{children:r.label||r.name}),v.jsxs("div",{className:"daga-buttons",children:[v.jsx("button",{className:"daga-property-button daga-move-button",children:v.jsx("div",{className:"daga-icon daga-move-icon"})}),v.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>n(r.name),children:v.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),r.type!==_.Object&&v.jsx("div",{className:"daga-property-value",children:Qo(i==null?void 0:i.getValue(r.name))}),r.type===_.Object&&v.jsx(Ri,{valueSet:i==null?void 0:i.getSubValueSet(r.name),depth:t+1})]}),v.jsx("div",{className:`daga-dropbar daga-index-${c+1} daga-depth-${t}`})]},r.name))]})},Qo=i=>Array.isArray(i)?i.join(", "):eo(i)?Object.entries(i).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):i instanceof Date?i.toLocaleString():i==null?"":""+i,ts=({location:i,direction:t,width:e,title:o,valueSet:a,onValueChange:l})=>{const s=z.useRef(null),[n,r]=z.useState(!1),[c,d]=z.useState(!1),h=()=>N.select(s.current);return z.useEffect(()=>{if(s.current)switch(t){case k.Bottom:case k.Top:h().style("width",e);break;case k.Left:case k.Right:h().style("height",e);break}},[e,t]),v.jsx("daga-property-editor",{children:v.jsxs("div",{ref:s,className:`daga-panel daga-bottom daga-${i} daga-${t}`,children:[v.jsx(Ce,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:n,direction:t,collapsableSelector:s,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:r}),a&&a.propertySet&&a.propertySet.hasProperties()&&!n&&v.jsxs("div",{className:"daga-panel-content",children:[o&&v.jsxs("p",{className:"daga-title",children:[o,v.jsx("button",{className:"daga-property-button",onClick:()=>d(!c),children:v.jsx("div",{className:`daga-icon daga-settings-icon ${c?"daga-unrotate":"daga-rotate"}`})})]}),!c&&v.jsx(zi,{valueSet:a,onValueChange:l,depth:0}),c&&v.jsx(Ri,{valueSet:a,depth:0})]})]})})},es=6,is=i=>{const t=z.useContext(Lt),[e,o]=z.useState(i.currentPalette||i.palettes[0]),[a,l]=z.useState(0),[s,n]=z.useState(void 0),r=z.useRef(null),c=f=>{if(o(f),d().selectAll("*").remove(),l(t.getPriorityThreshold()||0),f.categories&&h(f.categories),f.templates)for(const g of f.templates)u(g)},d=()=>N.select(r.current).select(".daga-palette-view"),h=f=>{const g=d().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");g.append("option").attr("value","").text("(None selected)");for(const y in f)g.append("option").attr("value",y).text(y);g.on(E.Change,()=>{s&&d().selectAll(".daga-template-container.daga-in-category").remove();const y=g.property("value");n(y);const w=f[y]||[];for(const b of w)u(b,"daga-in-category")}),s&&(g.property("value",s),g.dispatch(E.Change))},u=(f,g)=>{if(f.templateType==="node"){const y=t.model.nodes.types.get(f.type);y?p(y,f,g):console.error(`Could not find a node type called '${f.type}'`)}else if(f.templateType==="connection"){const y=t.model.connections.types.get(f.type);y?m(y,f,g):console.error(`Could not find a connection type called '${f.type}'`)}},p=(f,g,y)=>{if(a!==void 0&&f.priority<a)return;const w=f.defaultLook.lookType==="shaped-look"?f.defaultLook.borderThickness||1:0,b=f.defaultHeight+w,I=f.defaultWidth+w,S=g.height||b,L=g.width||I,$=d().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${L}px`).style("height",`${S}px`).call(N.drag().on(M.Drag,V=>{if(t.canUserPerformAction(C.AddNode)){const T=t.getPointerLocationRelativeToScreen(V);if(T.length<2||isNaN(T[0])||isNaN(T[1]))return;$.style("position","fixed").style("left",`${T[0]-L}px`).style("top",`${T[1]-S}px`).style("z-index",1)}}).on(M.Start,V=>{if(t.canUserPerformAction(C.AddNode)){A(P.Grabbing);const T=t.getPointerLocationRelativeToScreen(V);if(T.length<2||isNaN(T[0])||isNaN(T[1]))return;$.style("position","fixed").style("left",`${T[0]-L}px`).style("top",`${T[1]-S}px`).style("z-index",1),f.isUnique&&t.model.nodes.find(R=>!R.removed&&R.type.id===f.id)!==void 0&&A(P.NotAllowed)}}).on(M.End,V=>{var T;if(t.canUserPerformAction(C.AddNode)){if(A(P.Auto),$.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),f.isUnique&&t.model.nodes.find(It=>!It.removed&&It.type.id===f.id)!==void 0)return;const R=t.getPointerLocationRelativeToScreen(V);if(R.length<2||isNaN(R[0])||isNaN(R[1]))return;const Y=document.elementFromPoint(R[0],R[1]);if(Y&&!((T=t.selectCanvasView().node())!=null&&T.contains(Y)))return;const O=t.getPointerLocationRelativeToCanvas(V);if(O.length<2||isNaN(O[0])||isNaN(O[1]))return;let K=[O[0]-f.defaultWidth/2,O[1]-f.defaultHeight/2];t.snapToGrid&&(K=t.getClosestGridPoint(K));const B=t.model.nodes.getAtCoordinates(O[0],O[1]).filter(It=>It.type.childrenTypes.includes(f.id)),X=wi(B),at=X[X.length-1];if(!f.canBeParentless&&at===void 0)return;const gt=at==null?void 0:at.getLastAncestor(),_t=new bo(t,f,K,at==null?void 0:at.id,gt==null?void 0:gt.id,gt==null?void 0:gt.getGeometry(),void 0,g.label,g.values);_t.do(),t==null||t.actionStack.add(_t),A()}})).append("svg").attr("class",`palette-node ${f.id}`).attr("viewBox",`0 0 ${I} ${b}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${L}px`).style("height",`${S}px`),x=g.look||f.defaultLook;switch(x.lookType){case"shaped-look":$.append("path").attr("d",pe(x.shape||Rt.Rectangle,(x.borderThickness||1)/2,(x.borderThickness||1)/2,f.defaultWidth,f.defaultHeight)).attr("fill",x.fillColor||"#FFFFFF").attr("stroke",x.borderColor||"#000000").attr("stroke-width",`${x.borderThickness}px`);break;case"image-look":$.append("image").attr("x",0).attr("y",0).attr("width",f.defaultWidth).attr("height",f.defaultHeight).attr("href",x.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":$.append("image").attr("x",0).attr("y",0).attr("width",x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",0).attr("width",f.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTop).attr("preserveAspectRatio","none"),$.append("image").attr("x",f.defaultWidth-x.rightMargin).attr("y",0).attr("width",x.rightMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopRight).attr("preserveAspectRatio","none"),$.append("image").attr("x",0).attr("y",x.topMargin).attr("width",x.leftMargin).attr("height",f.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",x.topMargin).attr("width",f.defaultWidth-x.rightMargin-x.leftMargin).attr("height",f.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageCenter).attr("preserveAspectRatio","none"),$.append("image").attr("x",f.defaultWidth-x.rightMargin).attr("y",x.topMargin).attr("width",x.rightMargin).attr("height",f.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageRight).attr("preserveAspectRatio","none"),$.append("image").attr("x",0).attr("y",f.defaultHeight-x.bottomMargin).attr("width",x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",f.defaultHeight-x.bottomMargin).attr("width",f.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottom).attr("preserveAspectRatio","none"),$.append("image").attr("x",f.defaultWidth-x.rightMargin).attr("y",f.defaultHeight-x.bottomMargin).attr("width",x.rightMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(g.look===void 0){if(f.decorators)for(const V of f.decorators)$.append("foreignObject").attr("width",`${V.width}px`).attr("height",`${V.height}px`).attr("transform",`translate(${V.coords[0]},${V.coords[1]})`).html(V.html);if(g.label){const V={...D,...f.label,...g.labelLook};$.append("text").attr("transform",`translate(${(Q(V)+f.defaultWidth)/2},${(W(V)+f.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${V.fontSize}px`).attr("text-anchor","middle").attr("font-family",V.fontFamily).attr("font-weight",400).attr("fill",V.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(g.label)}}},m=(f,g,y)=>{const w=d().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${g.width}px`).style("height",`${g.height}px`).append("svg").attr("class",`palette-button ${f.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=f});w.append("path").attr("d",pe(Rt.Rectangle,0,0,g.width,g.height)).attr("fill",g.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),g.icon!==""&&w.append("image").attr("x",0).attr("y",0).attr("width",g.width).attr("height",g.height).attr("href",g.icon),g.label!==""&&w.append("text").attr("transform",`translate(${g.width/2},${g.height/2+es})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(g.label)};return z.useEffect(()=>{if(c(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}},[e,i.palettes]),v.jsx("daga-palette",{children:v.jsxs("div",{ref:r,className:`daga-panel daga-${i.location} daga-${i.direction}`,children:[v.jsx(Ce,{direction:i.direction,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),v.jsxs("div",{className:"daga-panel-content",children:[i.palettes.length>1&&v.jsx("div",{className:"daga-panel-tabs",children:i.palettes.map(f=>v.jsx("div",{className:`daga-panel-tab ${f===e?"daga-current-tab":""}`,onClick:()=>c(f),children:f.name}))}),v.jsx("div",{className:"daga-palette-view"})]})]})})},os=({location:i,direction:t,enableAction:e,enableFilter:o,enableLayout:a,enableSelection:l,enableZoom:s})=>{let n=!1,r=!0,c=!1,d,h,u,p;switch(t){case k.Bottom:d="height",h="scaleY",u="top",p="bottom";break;case k.Top:d="height",h="scaleY",u="bottom",p="top";break;case k.Left:d="width",h="scaleX",u="right",p="left";break;case k.Right:d="width",h="scaleX",u="left",p="right";break}const m=z.useRef(null),f=z.useRef(null),g=z.useRef(null);z.useEffect(()=>{N.select(m.current).style(`margin-${p}`,"-1rem").style(d,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const y=async()=>{const F=N.select(m.current);if(!c)if(r){r=!1;const at=`${4*F.selectChildren().size()}rem`;F.transition().duration(500).ease(N.easeLinear).style(d,at).style("transform",`${h}(1)`),setTimeout(()=>{c=!1},500)}else r=!0,F.transition().duration(500).ease(N.easeLinear).style(d,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{c=!1},500)},w=z.useContext(Lt),b=()=>{w.zoomBy(w.zoomFactor)},I=()=>{w.zoomBy(1/w.zoomFactor)},S=()=>{w.center()},L=()=>{w.layoutFormat&&w.layoutFormat in gi&&gi[w.layoutFormat].apply(w.model)},$=()=>{n=!n,N.select(g.current).classed("daga-on",n).classed("daga-off",!n);const F=w.getPriorityThresholdOptions();F&&F.length>=2&&w.setPriorityThreshold(F[n?1:0])},x=()=>{w.actionStack.undo()},V=()=>{w.actionStack.redo()},T=()=>{w.userSelection.copyToClipboard()},R=()=>{w.userSelection.cutToClipboard()},Y=()=>{w.userSelection.pasteFromClipboard()},O=()=>{w.userSelection.removeFromModel()},K=()=>{w.multipleSelectionOn=!0,N.select(f.current).classed("daga-on",!0).classed("daga-off",!1);const F=w.diagramEvent$.subscribe(B=>{B.type===Ii.Selection&&(N.select(f.current).classed("daga-on",!1).classed("daga-off",!0),F.unsubscribe())})};return v.jsx("daga-diagram-buttons",{children:v.jsxs("div",{className:`daga-diagram-buttons daga-${i} daga-${t}`,children:[s&&w.canUserPerformAction(C.Zoom)&&v.jsx("button",{className:"daga-zoom-in",onClick:b,children:v.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),s&&w.canUserPerformAction(C.Zoom)&&v.jsx("button",{className:"daga-zoom-out",onClick:I,children:v.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),v.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:m,children:[s&&w.canUserPerformAction(C.Zoom)&&v.jsx("button",{className:"daga-center",onClick:S,children:v.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&v.jsx("button",{className:"daga-undo",onClick:x,children:v.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&v.jsx("button",{className:"daga-redo",onClick:V,children:v.jsx("span",{className:"daga-tooltip",children:"Redo"})}),l&&v.jsx("button",{className:"daga-copy",onClick:T,children:v.jsx("span",{className:"daga-tooltip",children:"Copy"})}),l&&v.jsx("button",{className:"daga-cut",onClick:R,children:v.jsx("span",{className:"daga-tooltip",children:"Cut"})}),l&&v.jsx("button",{className:`daga-multiple-selection ${n?"daga-on":"daga-off"}`,onClick:K,ref:f,children:v.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),l&&v.jsx("button",{className:"daga-paste",onClick:Y,children:v.jsx("span",{className:"daga-tooltip",children:"Paste"})}),l&&v.jsx("button",{className:"daga-delete",onClick:O,children:v.jsx("span",{className:"daga-tooltip",children:"Delete"})}),a&&w.layoutFormat&&v.jsx("button",{className:"daga-layout",onClick:L,children:v.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),o&&v.jsx("button",{className:`daga-filter ${n?"daga-on":"daga-off"}`,onClick:$,ref:g,children:v.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),v.jsx("button",{className:"daga-more-options",onClick:y,children:r?v.jsx("span",{className:"daga-tooltip",children:"More options"}):v.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},ss=({config:i,model:t,onCanvasCreated:e,onDiagramEvent:o,onModelChange:a})=>{var $,x,V,T,R,Y,O,K,F,B,X,at,gt,_t,It,Se,Ie,Ae,Ee,Le,Te,$e,Me,Ne,Pe,ze,Re,Ve,_e,je,Oe,De,Fe,He,Ge,Be,Ue,Ye,Xe,We,Ze,Ke,qe,Je,Qe;const l=new Si,s=new Li,n=z.useRef(null),r=z.useRef(void 0),c=z.useRef(!1),d=[],[h,u]=z.useState(void 0),[p,m]=z.useState(void 0),f={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},g={refreshPalette:()=>{}},y=new Yo(dt=>u(dt),dt=>m(dt)),w={diagramButtons:f,palette:g,propertyEditor:y},b=(dt=!1)=>((!r.current||dt)&&(d.forEach(ut=>ut.unsubscribe()),r.current=new ye(w,i)),r.current),I=b(),S=dt=>{I.initView(dt),d.push(I.diagramEvent$.subscribe(ut=>{o==null||o(ut)})),d.push(I.diagramChange$.subscribe(()=>{const ut=s.export(I.model);a==null||a(ut)}))};z.useEffect(()=>{n.current&&(c.current||(S(n.current),c.current=!0,e==null||e(I)))},[n.current]),z.useMemo(()=>{n.current&&(b(!0),S(n.current),e==null||e(I))},[i]),z.useEffect(()=>{t&&l.import(I.model,t)},[t]);const L=(dt,ut,ti)=>{var ei;if(p!==void 0&&ut.editable!==!1&&!Et(dt.getValue(ut.name),ti)){dt.setValue(ut.name,ti);const ne=new xt(p.propertySet,p.rootElement);ne.setValues(p.getValues()),y.valueSet=ne,p.rootElement.valueSet=ne,(ei=I.propertyEditorChanges$)==null||ei.next()}};return v.jsx("daga-diagram",{children:v.jsx(Uo.Provider,{value:i,children:v.jsx(Lt.Provider,{value:I,children:v.jsxs("daga-diagram-editor",{children:[v.jsx("div",{className:"daga-append-to",ref:n}),v.jsxs(Lt.Provider,{value:I,children:[(($=i.components)==null?void 0:$.buttons)!==void 0&&((V=(x=i.components)==null?void 0:x.buttons)==null?void 0:V.enabled)!==!1&&v.jsx(os,{location:((R=(T=i.components)==null?void 0:T.buttons)==null?void 0:R.location)||Xt.BottomRight,direction:((O=(Y=i.components)==null?void 0:Y.buttons)==null?void 0:O.direction)||k.Top,enableAction:((F=(K=i.components)==null?void 0:K.buttons)==null?void 0:F.enableAction)!==!1,enableFilter:((X=(B=i.components)==null?void 0:B.buttons)==null?void 0:X.enableFilter)===!0,enableLayout:((gt=(at=i.components)==null?void 0:at.buttons)==null?void 0:gt.enableLayout)===!0,enableSelection:((It=(_t=i.components)==null?void 0:_t.buttons)==null?void 0:It.enableSelection)!==!1,enableZoom:((Ie=(Se=i.components)==null?void 0:Se.buttons)==null?void 0:Ie.enableZoom)!==!1}),((Ae=i.components)==null?void 0:Ae.palette)!==void 0&&((Le=(Ee=i.components)==null?void 0:Ee.palette)==null?void 0:Le.enabled)!==!1&&(($e=(Te=i.components)==null?void 0:Te.palette)==null?void 0:$e.sections)&&(((Pe=(Ne=(Me=i.components)==null?void 0:Me.palette)==null?void 0:Ne.sections)==null?void 0:Pe.length)||0)>0&&v.jsx(is,{location:((Re=(ze=i.components)==null?void 0:ze.palette)==null?void 0:Re.location)||Xt.TopLeft,direction:((_e=(Ve=i.components)==null?void 0:Ve.palette)==null?void 0:_e.direction)||k.Bottom,width:((Oe=(je=i.components)==null?void 0:je.palette)==null?void 0:Oe.width)||"12rem",palettes:((Fe=(De=i.components)==null?void 0:De.palette)==null?void 0:Fe.sections)||[]}),((He=i.components)==null?void 0:He.propertyEditor)!==void 0&&((Be=(Ge=i.components)==null?void 0:Ge.propertyEditor)==null?void 0:Be.enabled)!==!1&&v.jsx(ts,{location:((Ye=(Ue=i.components)==null?void 0:Ue.propertyEditor)==null?void 0:Ye.location)||Xt.TopRight,direction:((We=(Xe=i.components)==null?void 0:Xe.propertyEditor)==null?void 0:We.direction)||k.Bottom,width:((Ke=(Ze=i.components)==null?void 0:Ze.propertyEditor)==null?void 0:Ke.width)||"24rem",title:h,valueSet:p,onValueChange:L}),((qe=i.components)==null?void 0:qe.errors)!==void 0&&((Qe=(Je=i.components)==null?void 0:Je.errors)==null?void 0:Qe.enabled)!==!1&&v.jsx(Xo,{})]})]})})})})};exports.DagaDiagram=ss;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),ti=require("d3"),kt=require("rxjs"),L=require("react");function ei(o){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>o[e]})}}return t.default=o,Object.freeze(t)}const E=ei(ti);var f=(o=>(o.Bottom="bottom",o.Left="left",o.Right="right",o.Top="top",o))(f||{}),Bt=(o=>(o.BottomLeft="bottom-left",o.BottomRight="bottom-right",o.TopLeft="top-left",o.TopRight="top-right",o))(Bt||{}),At=(o=>(o.Left="left",o.Center="center",o.Right="right",o))(At||{}),Ut=(o=>(o.Top="top",o.Center="center",o.Bottom="bottom",o))(Ut||{});const Ct=o=>[Math.round(o[0]),Math.round(o[1])],gt=(o,t,e)=>t<e?t<=o&&o<=e:e<=o&&o<=t,ke=(o,t,e)=>(o-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Yt=(o,t,e,n,l,a,i)=>{const s=(()=>{switch(a){case"start":return n[0]+(o[0]-t[0]);case"end":return n[1]-(t[1]-o[0]);case"middle":{const c=(t[0]+t[1])/2,d=(n[0]+n[1])/2,h=t[1]-t[0],u=n[1]-n[0],y=(o[0]-c)/h;return d+y*u}case"floating":default:return ke(o[0],t,n)}})(),r=(()=>{switch(i){case"start":return l[0]+(o[1]-e[0]);case"end":return l[1]-(e[1]-o[1]);case"middle":{const c=(e[0]+e[1])/2,d=(l[0]+l[1])/2,h=e[1]-e[0],u=l[1]-l[0],y=(o[1]-c)/h;return d+y*u}case"floating":default:return ke(o[1],e,l)}})();return[s,r]},Me=(o,t)=>((o[0]-t[0])**2+(o[1]-t[1])**2)**.5,ii=(o,t)=>(gt(o[0][0],t[0][0],t[1][0])||gt(o[1][0],t[1][0],t[0][0])||gt(t[0][0],o[0][0],o[1][0])||gt(t[1][0],o[1][0],o[0][0]))&&(gt(o[0][1],t[0][1],t[1][1])||gt(o[1][1],t[1][1],t[0][1])||gt(t[0][1],o[0][1],o[1][1])||gt(t[1][1],o[1][1],o[0][1]));var C=(o=>(o.Blur="blur",o.Change="change",o.Click="click",o.ContextMenu="contextmenu",o.DoubleClick="dblclick",o.Focus="focus",o.FocusIn="focusin",o.FocusOut="focusout",o.Input="input",o.KeyDown="keydown",o.KeyUp="keyup",o.MouseDown="mousedown",o.MouseEnter="mouseenter",o.MouseLeave="mouseleave",o.MouseMove="mousemove",o.MouseOut="mouseout",o.MouseOver="mouseover",o.MouseUp="mouseup",o.TouchStart="touchstart",o.TouchEnd="touchend",o.Wheel="wheel",o))(C||{}),W=(o=>(o.Alt="Alt",o.AltGraph="AltGraph",o.ArrowDown="ArrowDown",o.ArrowLeft="ArrowLeft",o.ArrowRight="ArrowRight",o.ArrowUp="ArrowUp",o.Backspace="Backspace",o.Control="Control",o.Delete="Delete",o.End="End",o.Enter="Enter",o.Escape="Escape",o.Home="Home",o.OS="OS",o.PageDown="PageDown",o.PageUp="PageUp",o.Shift="Shift",o.Tab="Tab",o))(W||{}),I=(o=>(o.Drag="drag",o.Start="start",o.End="end",o))(I||{}),le=(o=>(o.Zoom="zoom",o.Start="start",o.End="end",o))(le||{});const ce=o=>o.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var Pe=(o=>(o.Straight="straight",o.Bezier="bezier",o.Square="square",o))(Pe||{}),fe=(o=>(o.Solid="solid",o.Dashed="dashed",o.GappedDashes="gapped-dashes",o.Dotted="dotted",o))(fe||{});const oi=20,si=(o,t,e,n,l)=>{if(typeof o=="function")return o(t,e,n,l);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{l=l||oi;let a="",i,s;switch(o){case"straight":a+=`M ${t[0][0]} ${t[0][1]}`;for(let r=1;r<t.length;++r)a+=` L ${t[r][0]} ${t[r][1]}`;break;case"bezier":i=e,a+=`M ${t[0][0]} ${t[0][1]}`;for(let r=1;r<t.length;++r){if(r+1>=t.length?s=n:Math.abs(t[r][0]-t[r-1][0])<Math.abs(t[r][1]-t[r-1][1])?t[r][1]>t[r-1][1]?s=f.Bottom:s=f.Top:t[r][0]>t[r-1][0]?s=f.Right:s=f.Left,i!==void 0){let c="",d="";const h=(Math.abs(t[r][0]-t[r-1][0])+Math.abs(t[r][1]-t[r-1][1]))/2;switch(i){case f.Bottom:c=`${t[r-1][0]} ${t[r-1][1]+h}`;break;case f.Top:c=`${t[r-1][0]} ${t[r-1][1]-h}`;break;case f.Right:c=`${t[r-1][0]+h} ${t[r-1][1]}`;break;case f.Left:c=`${t[r-1][0]-h} ${t[r-1][1]}`;break}if(s!==void 0){switch(s){case f.Bottom:d=`${t[r][0]} ${t[r][1]+h}`;break;case f.Top:d=`${t[r][0]} ${t[r][1]-h}`;break;case f.Right:d=`${t[r][0]+h} ${t[r][1]}`;break;case f.Left:d=`${t[r][0]-h} ${t[r][1]}`;break}a+=` C ${c} ${d} ${t[r][0]} ${t[r][1]}`}else a+=` Q ${c} ${t[r][0]} ${t[r][1]}`}else if(s!==void 0){let c="";const d=(Math.abs(t[r][0]-t[r-1][0])+Math.abs(t[r][1]-t[r-1][1]))/2;switch(s){case f.Bottom:c=`${t[r][0]} ${t[r][1]+d}`;break;case f.Top:c=`${t[r][0]} ${t[r][1]-d}`;break;case f.Right:c=`${t[r][0]+d} ${t[r][1]}`;break;case f.Left:c=`${t[r][0]-d} ${t[r][1]}`;break}a+=` Q ${c} ${t[r][0]} ${t[r][1]}`}else a+=` L ${t[r][0]} ${t[r][1]}`;i=s}break;case"square":if(a+=`M ${t[0][0]} ${t[0][1]}`,e)switch(e){case f.Bottom:t.splice(1,0,[t[0][0],t[0][1]+l]);break;case f.Top:t.splice(1,0,[t[0][0],t[0][1]-l]);break;case f.Right:t.splice(1,0,[t[0][0]+l,t[0][1]]);break;case f.Left:t.splice(1,0,[t[0][0]-l,t[0][1]]);break}if(n)switch(n){case f.Bottom:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]+l]);break;case f.Top:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]-l]);break;case f.Right:t.splice(t.length-1,0,[t[t.length-1][0]+l,t[t.length-1][1]]);break;case f.Left:t.splice(t.length-1,0,[t[t.length-1][0]-l,t[t.length-1][1]]);break}for(let r=1;r<t.length;++r)if(i!==void 0)switch(i){case f.Bottom:t[r][1]<t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`,i=f.Top):t[r][1]<t[r-1][1]&&t[r][0]===t[r-1][0]?(a+=` H ${t[r][0]+l}`,a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`,i=f.Left):t[r][1]===t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,i=t[r][0]>t[r-1][0]?f.Right:f.Left):t[r][1]>t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`):t[r][1]>t[r-1][1]&&t[r][0]===t[r-1][0]&&(a+=` V ${t[r][1]}`);break;case f.Top:t[r][1]>t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`,i=f.Bottom):t[r][1]>t[r-1][1]&&t[r][0]===t[r-1][0]?(a+=` H ${t[r][0]-l}`,a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`,i=f.Right):t[r][1]===t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,i=t[r][0]>t[r-1][0]?f.Right:f.Left):t[r][1]<t[r-1][1]&&t[r][0]!==t[r-1][0]?(a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`):t[r][1]<t[r-1][1]&&t[r][0]===t[r-1][0]&&(a+=` V ${t[r][1]}`);break;case f.Right:t[r][0]<t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`,i=f.Left):t[r][0]<t[r-1][0]&&t[r][1]===t[r-1][1]?(a+=` V ${t[r][1]+l}`,a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`,i=f.Top):t[r][0]===t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,i=t[r][1]>t[r-1][1]?f.Bottom:f.Top):t[r][0]>t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`):t[r][0]>t[r-1][0]&&t[r][1]===t[r-1][1]&&(a+=` H ${t[r][0]}`);break;case f.Left:t[r][0]>t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`,i=f.Right):t[r][0]>t[r-1][0]&&t[r][1]===t[r-1][1]?(a+=` V ${t[r][1]-l}`,a+=` H ${t[r][0]}`,a+=` V ${t[r][1]}`,i=f.Bottom):t[r][0]===t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,i=t[r][1]>t[r-1][1]?f.Bottom:f.Top):t[r][0]<t[r-1][0]&&t[r][1]!==t[r-1][1]?(a+=` V ${t[r][1]}`,a+=` H ${t[r][0]}`):t[r][0]<t[r-1][0]&&t[r][1]===t[r-1][1]&&(a+=` H ${t[r][0]}`);break}else t[r][0]!==t[r-1][0]&&(a+=` H ${t[r][0]}`,i=t[r][0]>t[r-1][0]?f.Right:f.Left),t[r][1]!==t[r-1][1]&&(a+=` V ${t[r][1]}`,i=t[r][1]>t[r-1][1]?f.Bottom:f.Top);break}return a}},de=(o,t)=>{switch(o){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},B=(o,t)=>{const e=o.indexOf(t);return e>=0&&o.splice(e,1),o};var Lt=(o=>(o.Ellipse="ellipse",o.Empty="empty",o.Folder="folder",o.Hexagon="hexagon",o.Octagon="octagon",o.Pill="pill",o.Rectangle="rectangle",o.Rhombus="rhombus",o.RoundedRectangle="rounded-rectangle",o.StickyNote="sticky-note",o))(Lt||{});const he=(o,t,e,n,l)=>{if(typeof o=="function")return o(t,e,n,l);switch(o){case"ellipse":return ze(t,e,n,l);case"empty":return ni();case"folder":return ri(t,e,n,l);case"hexagon":return ai(t,e,n,l);case"octagon":return li(t,e,n,l);case"pill":return Gt(t,e,n,l);case"rectangle":return we(t,e,n,l);case"rhombus":return ci(t,e,n,l);case"rounded-rectangle":return di(t,e,n,l);case"sticky-note":return hi(t,e,n,l);default:return we(t,e,n,l)}},ze=(o,t,e,n)=>`M ${o+e/2} ${t} A ${e/2} ${n/2} 0 0 0 ${o+e/2} ${t+n} A ${e/2} ${n/2} 0 1 0 ${o+e/2} ${t} Z`,ni=()=>"Z",ri=(o,t,e,n)=>`M ${o} ${t} L ${o+e/3} ${t} L ${o+e/2} ${t+n/6} L ${o+e} ${t+n/6} L ${o+e} ${t+n} L ${o} ${t+n} Z`,ai=(o,t,e,n)=>`M ${o+e/4} ${t} L ${o+3*e/4} ${t} L ${o+e} ${t+n/2} L ${o+3*e/4} ${t+n} L ${o+e/4} ${t+n} L ${o} ${t+n/2} Z`,li=(o,t,e,n)=>`M ${o+e/4} ${t} L ${o+3*e/4} ${t} L ${o+e} ${t+n/4} L ${o+e} ${t+3*n/4} L ${o+3*e/4} ${t+n} L ${o+e/4} ${t+n} L ${o} ${t+3*n/4} L ${o} ${t+n/4} L ${o+e/4} ${t} Z`,Gt=(o,t,e,n)=>n<e?`M ${o+n/2} ${t} L ${o+e-n/2} ${t} A ${n/2} ${n/2} 0 0 1 ${o+e} ${t+n/2} A ${n/2} ${n/2} 0 0 1 ${o+e-n/2} ${t+n} L ${o+n/2} ${t+n} A ${n/2} ${n/2} 0 0 1 ${o} ${t+n/2} A ${n/2} ${n/2} 0 0 1 ${o+n/2} ${t} Z`:n>e?`M ${o} ${t+e/2} L ${o} ${t+n-e/2} A ${e/2} ${e/2} 0 0 0 ${o+e/2} ${t+n} A ${e/2} ${e/2} 0 0 0 ${o+e} ${t+n-e/2} L ${o+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${o+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${o} ${t+e/2} Z`:ze(o,t,e,n),we=(o,t,e,n)=>`M ${o} ${t} L ${o+e} ${t} L ${o+e} ${t+n} L ${o} ${t+n} Z`,ci=(o,t,e,n)=>`M ${o+e/2} ${t} L ${o+e} ${t+n/2} L ${o+e/2} ${t+n} L ${o} ${t+n/2} Z`,di=(o,t,e,n)=>`M ${o+e/4} ${t} L ${o+3*e/4} ${t} A ${e/4} ${n/4} 0 0 1 ${o+e} ${t+n/4} L ${o+e} ${t+3*n/4} A ${e/4} ${n/4} 0 0 1 ${o+3*e/4} ${t+n} L ${o+e/4} ${t+n} A ${e/4} ${n/4} 0 0 1 ${o} ${t+3*n/4} L ${o} ${t+n/4} A ${e/4} ${n/4} 0 0 1 ${o+e/4} ${t} Z`,hi=(o,t,e,n)=>`M ${o} ${t} L ${o+3*e/4} ${t} L ${o+3*e/4} ${t+n/4} L ${o+3*e/4} ${t} L ${o+e} ${t+n/4} L ${o+3*e/4} ${t+n/4} L ${o+e} ${t+n/4} L ${o+e} ${t+n} L ${o} ${t+n} Z`;var T=(o=>(o.AllScroll="all-scroll",o.Auto="auto",o.Crosshair="crosshair",o.EWResize="ew-resize",o.Grab="grab",o.Grabbing="grabbing",o.Move="move",o.NoDrop="no-drop",o.NSResize="ns-resize",o.NotAllowed="not-allowed",o.ZoomIn="zoom-in",o.ZoomOut="zoom-out",o))(T||{});const gi=o=>Math.max(...o.split(`
|
|
2
|
+
`).map(t=>t.length)),ui=o=>o.match(/\n/g)?.length||0,X=[];for(let o=0;o<256;++o)X.push((o+256).toString(16).slice(1));function fi(o,t=0){return(X[o[t+0]]+X[o[t+1]]+X[o[t+2]]+X[o[t+3]]+"-"+X[o[t+4]]+X[o[t+5]]+"-"+X[o[t+6]]+X[o[t+7]]+"-"+X[o[t+8]]+X[o[t+9]]+"-"+X[o[t+10]]+X[o[t+11]]+X[o[t+12]]+X[o[t+13]]+X[o[t+14]]+X[o[t+15]]).toLowerCase()}let ee;const mi=new Uint8Array(16);function pi(){if(!ee){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ee=crypto.getRandomValues.bind(crypto)}return ee(mi)}const vi=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Se={randomUUID:vi};function xe(o,t,e){if(Se.randomUUID&&!o)return Se.randomUUID();o=o||{};const n=o.random??o.rng?.()??pi();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,fi(n)}const et=o=>{const{selected:t,highlighted:e,...n}=o,l=n,a={...l,...t},i={...l,...e},s={...l,...e,...t};return{defaultLook:l,selectedLook:a,highlightedLook:i,selectedAndHighlightedLook:s}};class Wt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],B(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const $t=0;class xt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${ce(this.id)}']`)}}class ht extends Wt{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((n,l,a)=>t(n,l,a)&&!n.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((n,l,a)=>t(n,l,a)&&!n.removed)}find(t,e=!1){return e?super.find(t):super.find((n,l,a)=>t(n,l,a)&&!n.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(n=>!n.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],B(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(n=>!n.removed))yield e}}class yi{constructor(t,e,n,l,a,i,s){this.name=t,this.label=e,this.type=n,this.defaultValue=l,this.basic=a,this.editable=i,this.rootAttribute=s,this.options=void 0,this.properties=void 0}}var N=(o=>(o.Boolean="boolean",o.Color="color",o.Date="date",o.Datetime="datetime",o.Number="number",o.Object="object",o.Option="option",o.OptionList="option-list",o.OptionSet="option-set",o.Text="text",o.TextArea="text-area",o.TextList="text-list",o.TextSet="text-set",o.TextMap="text-map",o.Time="time",o.Url="url",o))(N||{});class Zt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}function yt(o,t){return!t||o[0]>t[0]?!0:o[0]===t[0]?o[1]>=t[1]:!1}const Ce=o=>o==null||o===""||o instanceof Array&&o.length===0||o instanceof Object&&Object.keys(o).length===0,wt=(o,t)=>o===t||JSON.stringify(o)===JSON.stringify(t),Re=(o,t,e)=>{const n={},l={};for(const a in e.propertySet.propertyMap)if(e.propertySet.propertyMap[a].type===N.Object){const i=Re(o[a],t[a],e.getSubValueSet(a));Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(n[a]=i[0],l[a]=i[1])}else wt(o[a],t[a])||(n[a]=o[a],l[a]=t[a]);return[n,l]},bi=o=>o!=null&&o.constructor===Object;class pt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(this.rootElement){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const n of t){if(e==null)return;e=e[n]}return e}}}setRootElementValue(t,e){if(this.rootElement){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let n=this.rootElement;for(let l=0;l<t.length-1;++l){const a=t[l];if(n==null)return;n=n[a]}if(n==null)return;n[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}}getValue(t){const e=this.propertySet.getProperty(t)?.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===N.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===N.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const n in t)this.propertySet.getProperty(n).type===N.Object?e[n]=this.valueSets[n].getValuesForKeys(t[n]):e[n]=this.getValue(n);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===N.Object)t[e]=this.valueSets[e].getTimestamps();else{const l=this.ownTimestamps[e];l&&(t[e]=l)}return t}hasValue(t){const e=this.getValue(t);return!Ce(e)}hasSetValue(t){const e=this.getValue(t),n=this.propertySet.getProperty(t);return n&&n.type===N.Object?this.getSubValueSet(t).hasAnySetValue():!Ce(e)&&!wt(e,n?.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const n=this.propertySet.getProperty(t);if(n){n.type===N.Object?this.valueSets[t].setValues(e):(this.values[t]=e,wt(e,n.defaultValue)||this.displayProperty(n));const l=n.rootAttribute;l!=null&&this.setRootElementValue(l,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const n in t)this.propertySet.getProperty(n).type===N.Object?this.valueSets[n].overwriteValuesLww(t[n],e):yt(e,this.ownTimestamps[n])&&(this.setValue(n,t[n]),this.ownTimestamps[n]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),n=e.rootAttribute;e.type===N.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),n!=null&&e.defaultValue!==void 0&&!wt(this.getRootElementValue(n),e.defaultValue)&&this.setRootElementValue(n,this.values[t]),e.basic!==!1?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),n=new Zt(e.properties),l=new pt(n,this.rootElement);return l.overwriteValues(structuredClone(e.defaultValue)),l}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),B(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),B(this.displayedProperties,t))}}const J={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:Pe.Straight,style:fe.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class Oe{constructor(t){const e={...J,...t};this.id=e.id,this.name=e.name,this.label=e.label;const n=et(e.look);if(this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const l=et(e.startMarkerLook);this.defaultStartMarkerLook=l.defaultLook,this.selectedStartMarkerLook=l.selectedLook,this.highlightedStartMarkerLook=l.highlightedLook,this.selectedAndHighlightedStartMarkerLook=l.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const l=et(e.endMarkerLook);this.defaultEndMarkerLook=l.defaultLook,this.selectedEndMarkerLook=l.selectedLook,this.highlightedEndMarkerLook=l.highlightedLook,this.selectedAndHighlightedEndMarkerLook=l.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.propertySet=new Zt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class at extends xt{constructor(t,e,n,l,a){if(t.connections.get(a)!==void 0)throw new Error(`DiagramConnection with id "${a}" already exists`);if(!a)throw new Error("DiagramConnection cannot have an empty or null id");super(t,a),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new pt(e.propertySet,this),this.originalData={},this.setStart(n),this.setEnd(l)}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new pt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.connections.types.get(t);e&&(this.type=e)}}get name(){return this.middleLabel}set name(t){this.middleLabel=t}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){if(t){const e=et(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook!==void 0?this._selectedAndHighlightedStartMarkerLook:this.type.selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook!==void 0?this._selectedStartMarkerLook:this.type.selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook!==void 0?this._highlightedStartMarkerLook:this.type.highlightedStartMarkerLook:this._defaultStartMarkerLook!==void 0?this._defaultStartMarkerLook:this.type.defaultStartMarkerLook}set startMarkerLook(t){if(t){const e=et(t);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...e.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...e.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...e.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=t,this._selectedStartMarkerLook=t,this._highlightedStartMarkerLook=t,this._selectedAndHighlightedStartMarkerLook=t}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook!==void 0?this._selectedAndHighlightedEndMarkerLook:this.type.selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook!==void 0?this._selectedEndMarkerLook:this.type.selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook!==void 0?this._highlightedEndMarkerLook:this.type.highlightedEndMarkerLook:this._defaultEndMarkerLook!==void 0?this._defaultEndMarkerLook:this.type.defaultEndMarkerLook}set endMarkerLook(t){if(t){const e=et(t);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...e.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...e.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...e.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=t,this._selectedEndMarkerLook=t,this._highlightedEndMarkerLook=t,this._selectedAndHighlightedEndMarkerLook=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise()}setStart(t){this.start!==t?(this.start!==void 0&&B(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0])):(this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&B(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0])):(this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0]),this.updateInView()}tighten(){const t=this.model.canvas?.allowConnectionLoops||!1,e=this.model.canvas?.allowSharingPorts!==!1,n=this.model.canvas?.allowSharingBothPorts||!1;if(this.start?.rootElement&&this.end){const l=this.start.rootElement.ports.map(a=>[a,a.distanceTo(this.end.coords)]).sort((a,i)=>a[1]-i[1]).map(a=>a[0]);t:for(const a of l){if(!t&&a===this.end||!a.allowsOutgoing||!e&&(a.incomingConnections.length===1&&a.incomingConnections[0]!==this||a.incomingConnections.length>1||a.outgoingConnections.length===1&&a.outgoingConnections[0]!==this||a.outgoingConnections.length>1))continue t;if(!n){for(const i of a.outgoingConnections)if(i!==this&&i.end===this.end)continue t;for(const i of a.incomingConnections)if(i!==this&&i.start===this.end)continue t}if(a===this.start)break t;this.setStart(a);break t}}if(this.end?.rootElement&&this.start){const l=this.end.rootElement.ports.map(a=>[a,a.distanceTo(this.start.coords)]).sort((a,i)=>a[1]-i[1]).map(a=>a[0]);t:for(const a of l){if(!t&&a===this.start||!a.allowsIncoming||!e&&(a.outgoingConnections.length===1&&a.outgoingConnections[0]!==this||a.outgoingConnections.length>1||a.incomingConnections.length===1&&a.incomingConnections[0]!==this||a.incomingConnections.length>1))continue t;if(!n){for(const i of a.incomingConnections)if(i!==this&&i.start===this.start)continue t;for(const i of a.outgoingConnections)if(i!==this&&i.end===this.start)continue t}if(a===this.end)break t;this.setEnd(a);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():$t}}class ki extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,n,l){let a;if(t instanceof Oe)a=t;else{const s=this.types.get(t);if(s===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);a=s}const i=new at(this.model,a,e,n,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){const e=this.get(t,!0);e&&(B(e.start?.outgoingConnections||[],e),B(e.end?.incomingConnections||[],e),super.remove(t),e.updateInView())}}const O={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:At.Center,verticalAlign:Ut.Center,orientation:f.Top,fit:!1,shrink:!0};class ct extends xt{constructor(t,e,n,l,a,i,s,r,c,d,h,u,y,p,v,m){const b=`${e?.id}_field`;if(t.fields.get(b)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,b),this.textTimestamp=null,this.rootElement=e,this.coords=n,this.width=l,this.height=a,this.fontSize=i,this.fontFamily=s,this.color=r,this.selectedColor=c,this.horizontalAlign=d,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case f.Top:this.orientation=0;break;case f.Right:this.orientation=90;break;case f.Bottom:this.orientation=180;break;case f.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=y,this._text=y,this.editable=p,this.fit=v,this.shrink=m}get text(){return this._text}set text(t){(t==null||t?.trim()==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||$t}}class wi extends ht{constructor(t){super(),this.model=t}new(t,e,n,l,a,i,s,r,c,d,h,u,y,p,v){const m=new ct(this.model,t,e,s,r,n,l,a,i,c,d,h,u,y,p,v);return super.add(m),m.updateInView(),t!==void 0&&(t.label=m),m}remove(t){const e=this.get(t,!0);e&&(e.rootElement?.label!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const Q=o=>o?.margin===null||o?.margin===void 0?O.margin:typeof o.margin=="number"?o.margin:o.margin.length===0?O.margin:o.margin.length===1||o.margin.length===2?o.margin[0]:(o.margin.length===3,o.margin[2]),Y=o=>o?.margin===null||o?.margin===void 0?O.margin:typeof o.margin=="number"?o.margin:o.margin.length===0?O.margin:o.margin.length===1?o.margin[0]:o.margin.length===2||o.margin.length===3?o.margin[1]:o.margin[3],st=o=>o?.margin===null||o?.margin===void 0?O.margin:typeof o.margin=="number"?o.margin:o.margin.length===0?O.margin:o.margin.length===1?o.margin[0]:(o.margin.length===2||o.margin.length===3,o.margin[1]),H=o=>o?.margin===null||o?.margin===void 0?O.margin:typeof o.margin=="number"?o.margin:o.margin.length===0?O.margin:(o.margin.length===1||o.margin.length===2||o.margin.length===3,o.margin[0]),Pt=o=>o?.padding===null||o?.padding===void 0?O.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?O.padding:o.padding.length===1||o.padding.length===2?o.padding[0]:(o.padding.length===3,o.padding[2]),zt=o=>o?.padding===null||o?.padding===void 0?O.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?O.padding:o.padding.length===1?o.padding[0]:o.padding.length===2||o.padding.length===3?o.padding[1]:o.padding[3],Rt=o=>o?.padding===null||o?.padding===void 0?O.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?O.padding:o.padding.length===1?o.padding[0]:(o.padding.length===2||o.padding.length===3,o.padding[1]),Ot=o=>o?.padding===null||o?.padding===void 0?O.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?O.padding:(o.padding.length===1||o.padding.length===2||o.padding.length===3,o.padding[0]),Ie=1,Ae=1,Si=1,xi=1;class Ci{constructor(t){this.margin=t.margin||0,this.defaultWidths=t.defaultWidths||null,this.defaultHeights=t.defaultHeights||null,this.minWidths=t.minWidths||null,this.minHeights=t.minHeights||null,this.sections=[];for(const e of t.sections){const n=[];this.sections.push(n);for(const l of e)n.push(new Ii(l))}}}class Ii{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||$t,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=et(t.look||Ve);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class F extends xt{constructor(t,e,n,l,a,i,s,r){if(t.sections.get(r)!==void 0)throw new Error(`DiagramSection with id "${r}" already exists`);if(!r)throw new Error("DiagramSection cannot have an empty or null id");super(t,r),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=n,this.indexYInNode=l,this.coords=a,this.width=i,this.height=s}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type?.selectedAndHighlightedLook||this.node?.look:this._selectedLook!==void 0?this._selectedLook:this.type?.selectedLook||this.node?.look:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type?.highlightedLook||this.node?.look:this._defaultLook!==void 0?this._defaultLook:this.type?.defaultLook||this.node?.look}set look(t){if(t){const e=et(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||Si}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||xi}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||$t}getResizableX(){const t=this.type;return t?.resizableX!==void 0?t.resizableX:this.node?.type?.resizableX||!1}getResizableY(){const t=this.type;return t?.resizableY!==void 0?t.resizableY:this.node?.type?.resizableY||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(a=>a.distanceTo(t)),n=e.indexOf(Math.min(...e));return this.ports[n]}}}getIncomingConnections(t=!1){const e=[];for(const n of this.ports)for(const l of n.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const n of this.ports)for(const l of n.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const n of this.ports){for(const l of n.incomingConnections)!t&&l.removed||e.push(l);for(const l of n.outgoingConnections)!t&&l.removed||e.push(l)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const n=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let a,i;switch(t){case f.Left:a=[n[0]-e,n[1]],i=[l[0],l[1]],a[1]-a[0]<this.getMinWidth()&&(a[0]=a[1]-this.getMinWidth());break;case f.Top:a=[n[0],n[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case f.Right:a=[n[0],n[1]+e],i=[l[0],l[1]],a[1]-a[0]<this.getMinWidth()&&(a[1]=a[0]+this.getMinWidth());break;case f.Bottom:a=[n[0],n[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[a[0],i[0]],width:a[1]-a[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){const e=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];for(const s of this.ports)s.move(Yt(s.coords,e,n,l,a,s.anchorPointX,s.anchorPointY));const i=this.type;this.label&&(this.label.coords=[this.coords[0]+Y(i?.label),this.coords[1]+H(i?.label)],this.label.width=this.width-Y(i?.label)-st(i?.label),this.label.height=this.height-H(i?.label)-Q(i?.label),this.label.updateInView());for(const s of this.decorators)s.move(Yt(s.coords,e,n,l,a,s.anchorPointX,s.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(s=>s.tighten()),this.updateInView()}}class Ai extends ht{constructor(t){super(),this.model=t}new(t,e,n,l,a,i,s){const r=new F(this.model,t,e,n,l,a,i,s);super.add(r),r.updateInView(),t.sections.push(r),t.updateInView();const c=t.type.sectionGrid?.sections?.[n]?.[e]?.ports;if(c&&c.length>0)for(let h=0;h<c.length;++h){const u=c[h],y=this.model.ports.new(u.type!==void 0?this.model.ports.types.get(u.type):void 0,r,[r.coords[0]+(u.coords[0]||0),r.coords[1]+(u.coords[1]||0)],u.connectionPoint!==void 0?[r.coords[0]+(u.connectionPoint[0]||0),r.coords[1]+(u.connectionPoint[1]||0)]:void 0,u?.direction,`${r.id}_${h}`,u.anchorPointX||"floating",u.anchorPointY||"floating");if(y.type?.label){const p={...O,...y.type?.label},v=6*p.fontSize+zt(p)+Rt(p),m=p.fontSize+Ot(p)+Pt(p);let b;switch(y.direction){case f.Bottom:case f.Left:case f.Right:b=[y.coords[0]-v/2,y.coords[1]-m-Q(p)];break;case f.Top:b=[y.coords[0]-v/2,y.coords[1]+H(p)];break;default:b=y.coords}this.model.fields.new(y,b,p.fontSize,p.fontFamily,p.color,p.selectedColor,v,m,p.horizontalAlign,p.verticalAlign,p.orientation,"",p.editable,p.fit,p.shrink)}}const d=t.type.sectionGrid?.sections?.[n]?.[e]?.label;if(d){const h={...O,...d};this.model.fields.new(r,[r.coords[0]+Y(h),r.coords[1]+H(h)],h.fontSize,h.fontFamily,h.color,h.selectedColor,r.width-Y(h)-st(h),r.height-H(h)-Q(h),h.horizontalAlign,h.verticalAlign,h.orientation,"",h.editable,h.fit,h.shrink)}return r}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&B(e.node.sections,e),super.remove(t),e.updateInView()}}}const Ve={lookType:"shaped-look",shape:Lt.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},dt={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:Ve,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:$t,properties:[]};class _e{constructor(t){const e={...dt,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.bottomPadding=Ti(e),this.leftPadding=Li(e),this.rightPadding=$i(e),this.topPadding=Ni(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new Ci(e.sectionGrid):null;const n=et(e.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new Zt(t?.properties||[])}}class z extends xt{constructor(t,e,n=[0,0],l){if(t.nodes.get(l)!==void 0)throw new Error(`DiagramNode with id "${l}" already exists`);if(!l)throw new Error("DiagramNode cannot have an empty or null id");super(t,l),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new pt(e.propertySet,this),this.originalData={},this.coords=n,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new pt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.nodes.types.get(t);e&&(this.type=e)}}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){if(t){const e=et(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(const t of this.sections)t.raise();this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise();for(const t of this.children)t.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(a=>a.distanceTo(t)),n=e.indexOf(Math.min(...e));return this.ports[n]}}}getIncomingConnections(t=!1){const e=[];for(const n of this.ports)for(const l of n.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const n of this.ports)for(const l of n.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const n of this.ports){for(const l of n.incomingConnections)!t&&l.removed||e.push(l);for(const l of n.outgoingConnections)!t&&l.removed||e.push(l)}return e}getAdjacentNodes(t=!1){const e=[];for(const n of this.ports){for(const l of n.incomingConnections){if(!t&&l.removed)continue;const a=l.start?.getNode();if(a){if(!t&&a.removed)continue;e.push(a)}}for(const l of n.outgoingConnections){if(!t&&l.removed)continue;const a=l.end?.getNode();if(a){if(!t&&a.removed)continue;e.push(a)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t?.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,n=!1;for(;e!==void 0;){if(e.id===t.id){n=!0;break}e=e.parent}n||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){B(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(r=>r.indexXInNode)),n=Math.max(...this.sections.map(r=>r.indexYInNode)),l=this.coords[0]-t.coords[0]+this.type.leftPadding;l>=0&&(this.sections.length>0?this.stretchSections(f.Left,l,e,n):this.stretch(f.Left,l));const a=this.coords[1]-t.coords[1]+this.type.topPadding;a>=0&&(this.sections.length>0?this.stretchSections(f.Top,a,e,n):this.stretch(f.Top,a));const i=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;i>=0&&(this.sections.length>0?this.stretchSections(f.Right,i,e,n):this.stretch(f.Right,i));const s=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;s>=0&&(this.sections.length>0?this.stretchSections(f.Bottom,s,e,n):this.stretch(f.Bottom,s)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const n of this.children)n.move([n.coords[0]+e[0],n.coords[1]+e[1]]);for(const n of this.sections)n.move([n.coords[0]+e[0],n.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const n=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let a,i;switch(t){case f.Left:a=[n[0]-e,n[1]],i=[l[0],l[1]],a[1]-a[0]<this.type.minWidth&&(a[0]=a[1]-this.type.minWidth);break;case f.Top:a=[n[0],n[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case f.Right:a=[n[0],n[1]+e],i=[l[0],l[1]],a[1]-a[0]<this.type.minWidth&&(a[1]=a[0]+this.type.minWidth);break;case f.Bottom:a=[n[0],n[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[a[0],i[0]],width:a[1]-a[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,n,l){let a=Number.NEGATIVE_INFINITY;switch(t){case f.Bottom:for(const i of this.sections)i.indexYInNode===l&&(a=Math.max(a,i.getMinHeight()-i.height));e<a&&(e=a);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode>l&&i.move([i.coords[0],i.coords[1]+e]);break;case f.Right:for(const i of this.sections)i.indexXInNode===n&&(a=Math.max(a,i.getMinWidth()-i.width));e<a&&(e=a);for(const i of this.sections)i.indexXInNode===n?i.stretch(t,e):i.indexXInNode>n&&i.move([i.coords[0]+e,i.coords[1]]);break;case f.Top:for(const i of this.sections)i.indexYInNode===l&&(a=Math.max(a,i.getMinHeight()-i.height));e<a&&(e=a);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode<l&&i.move([i.coords[0],i.coords[1]-e]);break;case f.Left:for(const i of this.sections)i.indexXInNode===n&&(a=Math.max(a,i.getMinWidth()-i.width));e<a&&(e=a);for(const i of this.sections)i.indexXInNode===n?i.stretch(t,e):i.indexXInNode<n&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const l of this.sections)e[l.id]=l.getGeometry();const n={};for(const l of this.children)l.id!==t&&(n[l.id]=l.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:n}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const s=t.children[i.id];s&&i.setGeometry(s)}for(const i of this.sections){const s=t.sections[i.id];s&&i.setGeometry(s)}for(const i of this.ports)i.move(Yt(i.coords,e,n,l,a,i.anchorPointX,i.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+Y(this.type.label),this.coords[1]+H(this.type.label)],this.label.width=this.width-Y(this.type.label)-st(this.type.label),this.label.height=this.height-H(this.type.label)-Q(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Yt(i.coords,e,n,l,a,i.anchorPointX,i.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(i=>i.tighten()),this.updateInView()}removeSectionColumn(t){const e=this.type.sectionGrid?.margin||0;let n=0;const l=[...this.sections];for(const a of l)a.indexYInNode===t&&(n=Math.max(n,a.width),this.model.sections.remove(a.id));for(const a of l)a.indexYInNode>t&&(--a.indexYInNode,a.move([a.coords[0]-n-e,a.coords[1]]));this.stretch(f.Right,-e-n)}removeSectionRow(t){const e=this.type.sectionGrid?.margin||0;let n=0;const l=[...this.sections];for(const a of l)a.indexXInNode===t&&(n=Math.max(n,a.height),this.model.sections.remove(a.id));for(const a of l)a.indexYInNode>t&&(--a.indexXInNode,a.move([a.coords[0],a.coords[1]-n-e]));this.stretch(f.Bottom,-e-n)}copySectionColumn(t){const e=this.type.sectionGrid?.margin||0;let n=0;const l=[...this.sections];for(const a of l)if(a.indexXInNode===t){n=Math.max(n,a.width);let i=a.indexXInNode+1;for(;this.model.sections.get(`${a.id}_copy_${i}_${a.indexYInNode}`,!0)!==void 0;)++i;this.model.sections.new(this,a.indexXInNode+1,a.indexYInNode,[a.coords[0]+a.width+e,a.coords[1]],a.width,a.height,`${a.id}_copy_${i}_${a.indexYInNode}`)}for(const a of l)a.indexXInNode>t&&(++a.indexXInNode,a.move([a.coords[0]+n+e,a.coords[1]]));this.stretch(f.Right,e+n)}copySectionRow(t){const e=this.type.sectionGrid?.margin||0;let n=0;const l=[...this.sections];for(const a of l)if(a.indexYInNode===t){n=Math.max(n,a.height);let i=a.indexYInNode+1;for(;this.model.sections.get(`${a.id}_copy_${a.indexXInNode}_${i}`,!0)!==void 0;)++i;this.model.sections.new(this,a.indexXInNode,a.indexYInNode+1,[a.coords[0],a.coords[1]+a.height+e],a.width,a.height,`${a.id}_copy_${a.indexXInNode}_${i}`)}for(const a of l)a.indexYInNode>t&&(++a.indexYInNode,a.move([a.coords[0],a.coords[1]+n+e]));this.stretch(f.Bottom,e+n)}}class Ei extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,n){let l;if(t instanceof _e)l=t;else{const i=this.types.get(t);if(i===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);l=i}const a=new z(this.model,l,e,n);if(super.add(a),a.updateInView(),l.sectionGrid!==null){let i=a.coords[1]+(l.sectionGrid.margin||0);for(let s=0;s<l.sectionGrid.sections.length;++s){let r=a.coords[0]+(l.sectionGrid.margin||0);for(let c=0;c<l.sectionGrid.sections[s].length;++c)this.model.sections.new(a,c,s,[r,i],l.sectionGrid.defaultWidths?.[c]||Ie,l.sectionGrid.defaultHeights?.[s]||Ae,`${a.id}_${s}_${c}`),r+=(l.sectionGrid.defaultWidths?.[c]||Ie)+(l.sectionGrid.margin||0);i+=(l.sectionGrid.defaultHeights?.[s]||Ae)+(l.sectionGrid.margin||0)}}if(l.ports.length>0)for(let i=0;i<l.ports.length;++i){const s=l.ports[i],r=s.type!==void 0?this.model.ports.types.get(s.type):void 0,c=this.model.ports.new(r,a,[a.coords[0]+s.coords[0],a.coords[1]+s.coords[1]],s.connectionPoint!==void 0?[a.coords[0]+(s.connectionPoint[0]||0),a.coords[1]+(s.connectionPoint[1]||0)]:void 0,s.direction,`${a.id}_port_${i}`,s.anchorPointX||"floating",s.anchorPointY||"floating");if(c.type?.label){const d={...O,...c.type?.label},h=6*d.fontSize+zt(d)+Rt(d),u=d.fontSize+Ot(d)+Pt(d);let y;switch(c.direction){case f.Bottom:case f.Left:case f.Right:y=[c.coords[0]-h/2,c.coords[1]-u-Q(d)];break;case f.Top:y=[c.coords[0]-h/2,c.coords[1]+H(d)];break;default:y=c.coords}this.model.fields.new(c,y,d.fontSize,d.fontFamily,d.color,d.selectedColor,h,u,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink)}}if(l.label){const i={...O,...l.label};this.model.fields.new(a,[a.coords[0]+Y(i),a.coords[1]+H(i)],i.fontSize,i.fontFamily,i.color,i.selectedColor,a.width-Y(i)-st(i),a.height-H(i)-Q(i),i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink)}if(l.decorators.length>0)for(let i=0;i<l.decorators.length;++i){const s=l.decorators[i];this.model.decorators.new(a,[a.coords[0]+s.coords[0],a.coords[1]+s.coords[1]],s.width,s.height,a.getPriority(),s.html,`${a.id}_decorator_${i}`,s.anchorPointX||"floating",s.anchorPointY||"floating")}return a.valueSet.resetValues(),a.model.canvas?.fitNodeInView(a.id),a}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&B(e.parent.children,e);e.children.length>0;)this.model.nodes.remove(e.children[0].id);for(;e.sections.length>0;)this.model.sections.remove(e.sections[0].id);for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);for(;e.decorators.length>0;)this.model.decorators.remove(e.decorators[0].id);e.label&&this.model.fields.remove(e.label.id),super.remove(t),e.updateInView()}}getAtCoordinates(t,e){const n=[];for(const l of this)l.coords[0]<t&&t<l.coords[0]+l.width&&l.coords[1]<e&&e<l.coords[1]+l.height&&n.push(l);return n}}const je=o=>{for(let t=0;t<o.length;++t)for(let e=0;e<o.length;++e)e!==t&&o[e].isAncestorOf(o[t])&&(o.splice(e,1),--e,t>e&&--t);return o},Ti=o=>o?.padding===null||o?.padding===void 0?dt.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?dt.padding:o.padding.length===1||o.padding.length===2?o.padding[0]:(o.padding.length===3,o.padding[2]),Li=o=>o?.padding===null||o?.padding===void 0?dt.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?dt.padding:o.padding.length===1?o.padding[0]:o.padding.length===2||o.padding.length===3?o.padding[1]:o.padding[3],$i=o=>o?.padding===null||o?.padding===void 0?dt.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?dt.padding:o.padding.length===1?o.padding[0]:(o.padding.length===2||o.padding.length===3,o.padding[1]),Ni=o=>o?.padding===null||o?.padding===void 0?dt.padding:typeof o.padding=="number"?o.padding:o.padding.length===0?dt.padding:(o.padding.length===1||o.padding.length===2||o.padding.length===3,o.padding[0]),De={lookType:"shaped-look",shape:Lt.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Ht=et(De),Fe={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:De};class Mi{constructor(t){const e={...Fe,...t};this.id=e.id,this.name=e.name,this.label=e.label,this.allowsOutgoing=e.allowsOutgoing,this.allowsIncoming=e.allowsIncoming,this.width=e.width;const n=et(e.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook}}class vt extends xt{constructor(t,e,n,l,a,i,s,r="floating",c="floating"){if(t.ports.get(s)!==void 0)throw new Error(`DiagramPort with id "${s}" already exists`);if(!s)throw new Error("DiagramPort cannot have an empty or null id");super(t,s),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=n,this.coords=l,this.connectionPoint=a||l,this.direction=i,this.anchorPointX=r,this.anchorPointY=c}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.updateInView())}get typeString(){return this.type?.id}set typeString(t){if(t!==this.type?.id)if(t===void 0)this.type=void 0;else{const e=this.model.ports.types.get(t);e&&(this.type=e)}}get allowsOutgoing(){return this.type?.allowsOutgoing!==void 0?this.type?.allowsOutgoing:!0}get allowsIncoming(){return this.type?.allowsIncoming!==void 0?this.type?.allowsIncoming:!0}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(this.type||Ht)?.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(this.type||Ht)?.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(this.type||Ht)?.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(this.type||Ht)?.defaultLook}set look(t){if(t){const e=et(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get width(){return this.type?.width||Fe.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updatePortsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.incomingConnections)t.raise();for(const t of this.outgoingConnections)t.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof z)return this.rootElement;if(this.rootElement instanceof F)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||$t}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];this.coords=t,this.connectionPoint[0]=this.connectionPoint[0]+e[0],this.connectionPoint[1]=this.connectionPoint[1]+e[1];for(const n of this.outgoingConnections)n.setStart(this);for(const n of this.incomingConnections)n.setEnd(this);this.label&&this.label.move([this.label.coords[0]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return Me(this.coords,t)}}class Pi extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,n,l,a,i,s="floating",r="floating"){const c=new vt(this.model,t,e,n,l,a,i,s,r);return super.add(c),c.updateInView(),e!==void 0&&e.ports.push(c),c}remove(t){const e=this.get(t,!0);if(e){for(;e.outgoingConnections.length>0;)this.model.connections.remove(e.outgoingConnections[0].id);for(;e.incomingConnections.length>0;)this.model.connections.remove(e.incomingConnections[0].id);e.label&&this.model.fields.remove(e.label.id),(e.rootElement instanceof z||e.rootElement instanceof F)&&B(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class He{import(t,e){t.clear(),e.id&&(t.id=e.id),t.name=e.name,t.description=e.description,t.type=e.type,t.createdAt=new Date(e.createdAt),t.updatedAt=new Date(e.updatedAt);for(const n of e.nodes||[])this.importNode(t,n);for(const n of e.connections||[])this.importConnection(t,n);return e.data&&t.valueSet.setValues(e.data),e.collabMeta&&(t.logicalClock=e.collabMeta.logicalClock,t.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),t}importNode(t,e){const n=t.nodes.types.get(e.type);if(n){const l=new z(t,n,e.coords,e.id);if(t.nodes.add(l),l.width=e.width,l.height=e.height,e.label){if(n.decorators)for(let i=0;i<n.decorators.length;++i){const s=n.decorators[i];t.decorators.new(l,[l.coords[0]+s.coords[0],l.coords[1]+s.coords[1]],s.width,s.height,l.getPriority(),s.html,`${l.id}_decorator_${i}`)}if(n.label){const i={...O,...n.label},s=new ct(t,l,[l.coords[0]+Y(i),l.coords[1]+H(i)],l.width-Y(i)-st(i),l.height-H(i)-Q(i),i.fontSize,i.fontFamily,i.color,i.selectedColor,i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink);s.text=e.label,l.label=s,t.fields.add(s),s.updateInView()}}for(const i of e.children||[]){const s=this.importNode(t,i);s!==void 0&&(l.children?.push(s),s.parent=l)}for(const i of e.sections||[]){const s=new F(t,l,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(l.sections?.push(s),t.sections.add(s),i.label&&n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){const c={...O,...n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label},d=new ct(t,s,[s.coords[0]+Y(c),s.coords[1]+H(c)],s.width-Y(c)-st(c),s.height-H(c)-Q(c),c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);d.text=i.label,s.label=d,t.fields.add(d),d.updateInView()}let r=0;for(const c of i.ports||[]){const d=c.type!==void 0?t.ports.types.get(c.type):void 0,h=new vt(t,d,s,c.coords,c.connectionPoint||c.coords,c.direction,c.id);if(s.ports.push(h),t.ports.add(h),c.label){if(n.ports.length>r&&d?.label){const u={...O,...d?.label};let y;switch(h.direction){case f.Top:case f.Left:y=[h.coords[0]-u.fontSize,h.coords[1]-u.fontSize];break;case f.Bottom:y=[h.coords[0]-u.fontSize,h.coords[1]+u.fontSize];break;case f.Right:y=[h.coords[0]+u.fontSize,h.coords[1]-u.fontSize];break;default:y=h.coords}const p=new ct(t,h,y,u.fontSize,u.fontSize,u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,u.orientation,"",u.editable,u.fit,u.shrink);p.text=c.label,h.label=p,t.fields.add(p),p.updateInView()}++r}c.collabMeta&&(h.selfRemoved=c.collabMeta.selfRemoved,h.selfRemovedTimestamp=c.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(h.label,c.collabMeta.label)),h.updateInView()}i.collabMeta&&(s.selfRemoved=i.collabMeta.selfRemoved,s.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(s.label,i.collabMeta.label)),s.updateInView()}let a=0;for(const i of e.ports||[]){const s=i.type!==void 0?t.ports.types.get(i.type):void 0,r=new vt(t,s,l,i.coords,i.connectionPoint||i.coords,i.direction,i.id);if(l.ports.push(r),t.ports.add(r),i.label){if(n.ports.length>a&&s?.label){const c={...O,...s?.label};let d;switch(r.direction){case f.Top:case f.Left:d=[r.coords[0]-c.fontSize,r.coords[1]-c.fontSize];break;case f.Bottom:d=[r.coords[0]-c.fontSize,r.coords[1]+c.fontSize];break;case f.Right:d=[r.coords[0]+c.fontSize,r.coords[1]-c.fontSize];break;default:d=r.coords}const h=new ct(t,r,d,c.fontSize,c.fontSize,c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);h.text=i.label,r.label=h,t.fields.add(h),h.updateInView()}++a}i.collabMeta&&(r.selfRemoved=i.collabMeta.selfRemoved,r.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(r.label,i.collabMeta.label)),r.updateInView()}return e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(l.label,e.collabMeta.label),l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importConnection(t,e){const n=t.connections.types.get(e.type);if(n){const l=new at(t,n,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(l),l.startLabel=e.startLabel,l.middleLabel=e.middleLabel,l.endLabel=e.endLabel,l.points=e.points,e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class Kt{constructor(t,e,n,l,a,i,s){this.canvas=t,this.id=e,this.typeId=n,this.coords=l,this.parentId=a,this.label=i,this.values=s}do(){const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&this.canvas.model.nodes.get(this.parentId)?.addChild(t),t.label&&(t.label.text=this.label||""),this.values!==void 0?t.valueSet.setValues(structuredClone({...t.valueSet.getValues(),...this.values})):t.valueSet.resetValues()}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new Kt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class me{constructor(t,e,n,l,a,i,s){this.canvas=t,this.nodeId=e,this.copyColumnIndex=n,this.copyRowIndex=l,this.removeColumnIndex=a,this.removeRowIndex=i,this.timestamp=s}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&yt(this.timestamp,t.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&t.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&t.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&t.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&t.removeSectionRow(this.removeRowIndex),t.geometryTimestamp=this.timestamp)}serialize(){return{type:"addSection",nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(t,e){return new me(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class pe{constructor(t,e,n){this.canvas=t,this.to=e,this.timestamp=n}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&yt(this.timestamp,e.geometryTimestamp)){const n=this.to[t];e.move([n[0],n[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new pe(t,e.to,e.timestamp)}}class Vt{constructor(t,e,n,l){this.canvas=t,this.nodeIds=e,this.delta=n,this.timestamp=l}do(){for(const t of this.nodeIds){const e=this.canvas.model.nodes.get(t,!0);e&&yt(this.timestamp,e.geometryTimestamp)&&(e.move([e.coords[0]+this.delta[0],e.coords[1]+this.delta[1]]),e.parent?.fitToChild(e),e.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new Vt(t,e.nodeIds,e.delta,e.timestamp)}}class tt{constructor(t,e,n,l){this.canvas=t,this.nodeId=e,this.to=n,this.timestamp=l}do(){const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&yt(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),t.label?.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);for(const e of t.sections)e.label?.fit&&this.canvas.fitFieldRootInView(e.label.id,e.label.shrink);t.parent?.fitToChild(t),t.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new tt(t,e.nodeId,e.to,e.timestamp)}}class _t{constructor(t,e,n,l,a){this.canvas=t,this.childId=e,this.parentId=n,this.childGeometry=l,this.timestamp=a}do(){const t=this.canvas.model.nodes.get(this.childId,!0),e=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;t&&(this.parentId===void 0||e)&&yt(this.timestamp,t.geometryTimestamp)&&(t.parent?.removeChild(t),t.setGeometry(this.childGeometry),e?.addChild(t))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,e){return new _t(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class qt{constructor(t,e,n,l,a){this.canvas=t,this.id=e,this.typeId=n,this.startId=l,this.endId=a}do(){const t=this.canvas.model.ports.get(this.startId,!0),e=this.canvas.model.ports.get(this.endId,!0);t&&e&&this.canvas.model.connections.new(this.typeId,t,e,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,e){return new qt(t,e.id,e.typeId,e.startId,e.endId)}}class Et{constructor(t,e,n,l){this.canvas=t,this.fieldId=e,this.to=n,this.timestamp=l}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&yt(this.timestamp,t.textTimestamp)&&(t.text=this.to,t.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Et(t,e.fieldId,e.to,e.timestamp)}}class Tt{constructor(t,e,n,l){this.canvas=t,this.id=e,this.to=n,this.timestamp=l}getValueSet(){return this.id===void 0?this.canvas.model.valueSet:(this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))?.valueSet}do(){this.getValueSet()?.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Tt(t,e.id,e.to,e.timestamp)}}class nt{constructor(t,e,n,l,a,i,s,r){this.canvas=t,this.nodeIds=e,this.sectionIds=n,this.portIds=l,this.connectionIds=a,this.fieldIds=i,this.selfRemoved=s,this.timestamp=r}doOne(t){t&&yt(this.timestamp,t.selfRemovedTimestamp)&&(t.selfRemoved=this.selfRemoved,t.selfRemovedTimestamp=this.timestamp)}do(){for(const t of this.nodeIds)this.doOne(this.canvas.model.nodes.get(t,!0));for(const t of this.sectionIds)this.doOne(this.canvas.model.sections.get(t,!0));for(const t of this.portIds)this.doOne(this.canvas.model.ports.get(t,!0));for(const t of this.connectionIds)this.doOne(this.canvas.model.connections.get(t,!0));for(const t of this.fieldIds)this.doOne(this.canvas.model.fields.get(t,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,e){return new nt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class Jt{constructor(t,e,n){this.canvas=t,this.nodes=e,this.connections=n}do(){const t=new He;this.canvas.userSelection.clear();for(const e of this.nodes){const n=t.importNode(this.canvas.model,e);n&&this.canvas.userSelection.add(n)}for(const e of this.connections){const n=t.importConnection(this.canvas.model,e);n&&this.canvas.userSelection.add(n)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new Jt(t,e.nodes,e.connections)}}class zi{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=xe()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+xe()}doCollaboratively(t){if(t.do(),this.onSend){const e=t.serialize();this.onSend(e)}}receive(t){switch("timestamp"in t&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,t.timestamp[0])),t.type){case"addNode":{Kt.deserialize(this.canvas,t).do();break}case"addSection":{me.deserialize(this.canvas,t).do();break}case"applyLayout":{pe.deserialize(this.canvas,t).do();break}case"move":{Vt.deserialize(this.canvas,t).do();break}case"setGeometry":{tt.deserialize(this.canvas,t).do();break}case"setParent":{_t.deserialize(this.canvas,t).do();break}case"addConnection":{qt.deserialize(this.canvas,t).do();break}case"editField":{Et.deserialize(this.canvas,t).do();break}case"updateValues":{Tt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{nt.deserialize(this.canvas,t).do();break}case"paste":{Jt.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class Ri{constructor(t,e){this.canvas=t,this.maximum=e,this.history=[],this.index=0}add(t){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(t)):(this.history.push(t),++this.index),this.canvas.diagramChange$.next({action:t,method:0})}undo(){let t;if(this.index>0){let e;do--this.index,t=this.history[this.index],e=t.undo();while(!e&&this.index>0)}this.canvas.diagramChange$.next({action:t,method:1})}redo(){let t;if(this.index<this.history.length){let e;do t=this.history[this.index],e=t.redo(),++this.index;while(!e&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:t,method:2})}}var k=(o=>(o.AddConnection="add-connection",o.AddNode="add-node",o.AddSectionAction="add-section",o.ApplyLayout="apply-layout",o.Clipboard="clipboard",o.ContextMenu="context-menu",o.EditField="edit-field",o.MoveNode="move-node",o.Paste="paste",o.Remove="remove",o.StretchNode="stretch-node",o.StretchSection="stretch-section",o.UpdateValues="update-values",o.Zoom="zoom",o))(k||{});class Oi{constructor(t,e,n,l,a,i,s,r,c){this.canvas=t,this.type=e,this.coords=n,this.parentId=l,this.ancestorId=a,this.fromAncestorGeometry=i,this.toAncestorGeometry=s,this.label=r,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Kt(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const e=new tt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){const t=this.canvas.model.nodes.get(this.id),e=new nt(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const n=new tt(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new nt(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const n=new tt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return t===void 0}}class ie{constructor(t,e,n){this.canvas=t,this.nodeIds=e,this.delta=n}do(){const t=new Vt(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const t=new Vt(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class G{constructor(t,e,n,l,a,i,s,r){this.canvas=t,this.intent=e,this.nodeId=n,this.from=l,this.to=a,this.ancestorId=i,this.fromAncestorGeometry=s,this.toAncestorGeometry=r}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new tt(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const n=new tt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new tt(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const n=new tt(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new tt(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Vi{constructor(t,e,n,l,a,i,s,r,c){this.canvas=t,this.childId=e,this.fromParentId=n,this.toParentId=l,this.fromChildGeometry=a,this.toChildGeometry=i,this.ancestorId=s,this.fromAncestorGeometry=r,this.toAncestorGeometry=c}do(){const t=this.canvas.model.nodes.get(this.childId),e=new _t(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const n=new tt(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new _t(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const n=new tt(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(n)}return t!==void 0}redo(){return this.do()}}class oe{constructor(t,e,n,l){this.canvas=t,this.type=e,this.startId=n,this.endId=l,this.id=this.canvas.collabEngine.freshId()}do(){const t=new qt(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=this.canvas.model.connections.get(this.id),e=new nt(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}redo(){const t=this.canvas.model.connections.get(this.id),e=new nt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class Ee{constructor(t,e,n,l){this.canvas=t,this.fieldId=e,this.from=n,this.to=l}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new Et(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}undo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.to=t.text;const e=new Et(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}redo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.from=t.text;const e=new Et(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class _i{constructor(t,e,n,l){this.canvas=t,this.id=e,this.from=n,this.to=l}do(){const t=new Tt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Tt(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 Tt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.from=e.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}}class ji{constructor(t,e,n,l,a,i){this.canvas=t,this.nodeIds=e,this.sectionIds=n,this.portIds=l,this.connectionIds=a,this.fieldIds=i}do(){const t=this.nodeIds.map(n=>this.canvas.model.nodes.get(n)!==void 0).includes(!0)||this.sectionIds.map(n=>this.canvas.model.sections.get(n)!==void 0).includes(!0)||this.portIds.map(n=>this.canvas.model.ports.get(n)!==void 0).includes(!0)||this.connectionIds.map(n=>this.canvas.model.connections.get(n)!==void 0).includes(!0)||this.fieldIds.map(n=>this.canvas.model.fields.get(n)!==void 0).includes(!0),e=new nt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}undo(){const t=this.nodeIds.map(n=>this.canvas.model.nodes.get(n)===void 0).includes(!0)||this.sectionIds.map(n=>this.canvas.model.sections.get(n)===void 0).includes(!0)||this.portIds.map(n=>this.canvas.model.ports.get(n)===void 0).includes(!0)||this.connectionIds.map(n=>this.canvas.model.connections.get(n)===void 0).includes(!0)||this.fieldIds.map(n=>this.canvas.model.fields.get(n)===void 0).includes(!0),e=new nt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){return this.do()}}class Di{constructor(t,e,n,l){this.canvas=t,this.nodes=e,this.connections=n,this.coords=l}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const a of this.nodes)a.coords[0]<t[0]&&(t[0]=a.coords[0]),a.coords[1]<t[1]&&(t[1]=a.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,n={};for(const a of this.nodes){const i=a.id,s=this.canvas.collabEngine.freshId();if(n[i]=s,a.id=s,e&&(a.coords=[a.coords[0]+e[0],a.coords[1]+e[1]]),a.sections)for(const r of a.sections){const c=r.id;if(r.id.includes(a.id)?r.id=r.id.replace(a.id,s):r.id=this.canvas.collabEngine.freshId(),n[c]=r.id,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]]),r.ports)for(const d of r.ports){const h=d.id;d.id.includes(a.id)?d.id=d.id.replace(a.id,s):d.id=this.canvas.collabEngine.freshId(),n[h]=d.id,e&&(d.coords=[d.coords[0]+e[0],d.coords[1]+e[1]],d.connectionPoint&&(d.connectionPoint=[d.connectionPoint[0]+e[0],d.connectionPoint[1]+e[1]]))}}if(a.ports)for(const r of a.ports){const c=r.id;r.id.includes(a.id)?r.id=r.id.replace(a.id,s):r.id=this.canvas.collabEngine.freshId(),n[c]=r.id,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]],r.connectionPoint&&(r.connectionPoint=[r.connectionPoint[0]+e[0],r.connectionPoint[1]+e[1]]))}}for(const a of this.connections){const i=this.canvas.collabEngine.freshId();if(n[a.id]=i,a.id=i,a.start=n[a.start]||a.start,a.end=n[a.end]||a.end,e)for(let s=0;s<a.points.length;++s)a.points[s]=[a.points[s][0]+e[0],a.points[s][1]+e[1]]}const l=new Jt(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(l),!0}undo(){const t=this.nodes.map(n=>this.canvas.model.nodes.get(n.id)!==void 0).includes(!0)||this.connections.map(n=>this.canvas.model.connections.get(n.id)!==void 0).includes(!0),e=new nt(this.canvas,this.nodes.map(n=>n.id),[],[],this.connections.map(n=>n.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=this.nodes.map(n=>this.canvas.model.nodes.get(n.id)===void 0).includes(!0)||this.connections.map(n=>this.canvas.model.connections.get(n.id)===void 0).includes(!0),e=new nt(this.canvas,this.nodes.map(n=>n.id),[],[],this.connections.map(n=>n.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class Qt{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Be=(o=>(o[o.DoubleClick=0]="DoubleClick",o[o.SecondaryClick=1]="SecondaryClick",o[o.Selection=2]="Selection",o[o.Highlight=3]="Highlight",o))(Be||{});class ut extends Qt{constructor(t,e,n){super(0),this.cause=t,this.target=e,this.coords=n}}class ft extends Qt{constructor(t,e,n){super(1),this.cause=t,this.target=e,this.coords=n}}class D extends Qt{constructor(t,e){super(2),this.targets=t,this.selected=e}}class K extends Qt{constructor(t){super(3),this.target=t}}class Ge extends xt{constructor(t,e,n,l,a,i,s,r,c="floating",d="floating"){if(t.objects.get(r)!==void 0)throw new Error(`DiagramDecorator with id "${r}" already exists`);if(!r)throw new Error("DiagramDecorator cannot have an empty or null id");super(t,r),this.rootElement=e,this.coords=n,this.width=l,this.height=a,this.priority=i,this.html=s,this.anchorPointX=c,this.anchorPointY=d}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateDecoratorsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Fi extends ht{constructor(t){super(),this.model=t}new(t,e,n,l,a,i,s,r="floating",c="floating"){const d=new Ge(this.model,t,e,n,l,a,i,s,r,c);return super.add(d),d.updateInView(),t!==void 0&&t.decorators.push(d),d}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof z||e.rootElement instanceof F)&&B(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Hi extends xt{constructor(t,e,n,l,a,i,s){if(t.objects.get(s)!==void 0)throw new Error(`DiagramObject with id "${s}" already exists`);if(!s)throw new Error("DiagramObject cannot have an empty or null id");super(t,s),this.coords=e,this.width=n,this.height=l,this.priority=a,this.html=i}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateObjectsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Bi extends ht{constructor(t){super(),this.model=t}new(t,e,n,l,a,i){const s=new Hi(this.model,t,e,n,l,a,i);return super.add(s),s.updateInView(),s}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Ue{constructor(t,e,n,l,a,i=[]){this.nodes=new Ei(this),this.sections=new Ai(this),this.ports=new Pi(this),this.connections=new ki(this),this.fields=new wi(this),this.objects=new Bi(this),this.decorators=new Fi(this),this.canvas=t,this.id=e,this.name=n,this.description=l,this.type=a,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new pt(new Zt(i),this)}clear(){this.canvas?.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),this.canvas?.updateModelInView()}}const mt=o=>!!o.button,se=(o,t,e,n,l,a,i,s)=>si(o,[t,e],n,l,Math.max(10,i||0,s||0)*a),S=o=>{o?E.select("body").style("cursor",o):E.select("body").style("cursor",T.Auto)},lt=o=>o instanceof z?o:o instanceof F?o.node||o:o.rootElement instanceof z||o.rootElement instanceof F||o.rootElement instanceof vt?lt(o.rootElement):o,ne=o=>{o.filter(".shaped-look").append("path"),o.filter(".image-look").append("image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),o.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none")},Nt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:fe.Solid},re=o=>{o.filter(".shaped-look").select("path").attr("d",t=>he(t.look.shape||Lt.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||Nt.fillColor).attr("stroke",t=>t.look.borderColor||Nt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||Nt.borderThickness}px`).attr("stroke-dasharray",t=>de(t.look.borderStyle||Nt.borderStyle,t.look.borderThickness||Nt.borderThickness)),o.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",t=>t.width).attr("height",t=>t.height).attr("href",t=>t.look.backgroundImage),o.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopLeft),o.filter(".stretchable-image-look").select("image.top-image").attr("x",t=>t.look.leftMargin).attr("y",0).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTop),o.filter(".stretchable-image-look").select("image.top-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",0).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopRight),o.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageLeft),o.filter(".stretchable-image-look").select("image.center-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageCenter),o.filter(".stretchable-image-look").select("image.right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageRight),o.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomLeft),o.filter(".stretchable-image-look").select("image.bottom-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottom),o.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomRight)},Mt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Gi=(o,t,e)=>{const n=t.append("defs");if(o.gridSize>0&&isFinite(o.gridSize)){const l=n.append("pattern").attr("id",e).attr("x",-o.gridSize/2).attr("y",-o.gridSize/2).attr("width",o.gridSize).attr("height",o.gridSize).attr("patternUnits","userSpaceOnUse");switch(l.append("rect").attr("x",0).attr("y",0).attr("width",o.gridSize).attr("height",o.gridSize).attr("fill",o.backgroundColor),o.gridStyle){case"dots":l.append("circle").attr("cx",o.gridSize/2).attr("cy",o.gridSize/2).attr("r",o.gridSize*o.gridThickness).attr("fill",o.gridColor);break;case"lines":l.append("line").attr("x1",o.gridSize/2).attr("x2",o.gridSize/2).attr("y1",0).attr("y2",o.gridSize).attr("stroke-width",o.gridSize*o.gridThickness).attr("stroke",o.gridColor),l.append("line").attr("x1",0).attr("x2",(o.gridSize-o.gridSize*o.gridThickness)/2).attr("y1",o.gridSize/2).attr("y2",o.gridSize/2).attr("stroke-width",o.gridSize*o.gridThickness).attr("stroke",o.gridColor),l.append("line").attr("x1",(o.gridSize+o.gridSize*o.gridThickness)/2).attr("x2",o.gridSize).attr("y1",o.gridSize/2).attr("y2",o.gridSize/2).attr("stroke-width",o.gridSize*o.gridThickness).attr("stroke",o.gridColor);break}t.select("rect").attr("fill",`url(#${e})`)}},ge=96,U=32,It=ge+U,Ui=Math.PI/4,Yi=100,Te={customButtons:[]};class Xi{constructor(t,e){this.canvas=t,this.config=e||Te}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),n=this.canvas.getPointerLocationRelativeToCanvas(t),l=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-It}px`).attr("y",`${e[1]-It}px`).attr("width",`${2*It}px`).attr("height",`${2*It}px`).style("pointer-events","none").on(C.ContextMenu,i=>{this.canvas.canUserPerformAction(k.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(C.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=l;const a=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&this.canvas.canUserPerformAction(k.Remove)&&a.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.userSelection.cutToClipboard(),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&a.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.userSelection.copyToClipboard(),i.cancelAllUserActions()}}),this.canvas.canUserPerformAction(k.Paste)&&a.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.userSelection.pasteFromClipboard(i.getClosestGridPoint(n)),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Remove)&&a.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.userSelection.removeFromModel(),i.cancelAllUserActions()}});for(const i of this.config.customButtons||Te.customButtons)(i.condition===void 0||i.condition(this.canvas))&&a.push(i);a.length===0&&a.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<a.length;++i){const s=a[i],r=s.onPress,c=(i+.5-a.length/2)*Ui,d=l.append("xhtml:div").attr("class",`daga-context-menu-button ${s.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*U}px`).style("height",`${2*U}px`).style("border-radius",`${U}px`).style("pointer-events","auto").on(C.Click,h=>{r&&(h.preventDefault(),r(this.canvas))}).on(C.KeyDown,h=>{r&&h.key===W.Enter&&(h.preventDefault(),r(this.canvas))});s.imageClass!==void 0?d.append("xhtml:div").style("position","absolute").style("left",`${.75*U}px`).style("top",`${.5*U}px`).style("width",`${.5*U}px`).style("height",`${.5*U}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",s.imageClass):s.image!==void 0&&d.append("xhtml:img").style("position","absolute").style("left",`${.75*U}px`).style("top",`${.5*U}px`).style("width",`${.5*U}px`).style("height",`${.5*U}px`).attr("src",s.image),d.append("xhtml:span").style("position","absolute").style("left",`${.2*U}px`).style("top",`${1.1*U}px`).style("text-align","center").style("width",`${1.6*U}px`).style("height",`${.35*U}px`).style("margin","0").style("font-size",`${.35*U}px`).style("font-weight","700").style("user-select","none").text(s.name),d.transition().ease(E.easeLinear).duration(Yi).tween("progress",()=>h=>{const u=c*h;return d.style("left",`${Math.sin(u)*ge-U+It}px`).style("top",`${-Math.cos(u)*ge-U+It}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}}class Wi extends ht{constructor(t,e=!0){super(),this.focus=void 0,this.canvas=t,this.highlightSections=e}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,(t instanceof ct||t instanceof Ge)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof z){if(!this.highlightSections)for(const e of t.sections){super.add(e);for(const n of e.ports)super.add(n),this.canvas.updatePortsInView(n.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateNodesInView(t.id)}else if(t instanceof F)if(!this.highlightSections&&t.node)this.add(t.node);else{for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}else t instanceof vt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof at&&this.canvas.updateConnectionsInView(t.id)}clear(){for(;this.entities.length>0;){const t=this.entities[0];this.remove(t.id),t.updateInView()}this.focus=void 0}}const Zi=1;class Ye{export(t,e=!1){const n={name:t.name,type:t.type,typeVersion:Zi,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(n.id=t.id),t.description&&(n.description=t.description);for(const l of t.nodes.all(!0))!e&&l.removed||l.parent===void 0&&n.nodes.push(this.exportNode(l,e));for(const l of t.connections.all(!0))!e&&l.removed||n.connections.push(this.exportConnection(l,e));return n}exportNode(t,e=!1){const n=[];for(const i of t.children)n.push(this.exportNode(i,e));const l=[];for(const i of t.sections){const s=[];for(const r of i.ports)s.push({id:r.id,type:r.type?.id,coords:Ct(r.coords),connectionPoint:Ct(r.connectionPoint||r.coords),direction:r.direction,label:r.label?.text||"",...e?{collabMeta:{removed:r.removed,selfRemoved:r.selfRemoved,selfRemovedTimestamp:r.selfRemovedTimestamp,...this.exportLabelCollabMeta(r)}}:{}});l.push({id:i.id,ports:s,label:i.label?.text||"",indexXInNode:i.indexXInNode,indexYInNode:i.indexYInNode,coords:Ct(i.coords),width:i.width,height:i.height,...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}})}const a=[];for(const i of t.ports)a.push({id:i.id,type:i.type?.id,coords:Ct(i.coords),connectionPoint:Ct(i.connectionPoint||i.coords),direction:i.direction,label:i.label?.text||"",...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}});return{id:t.id,type:t.type.id,children:n,sections:l,ports:a,label:t.label?.text||"",coords:Ct(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){return{id:t.id,type:t.type.id,start:t.start?.id||"",end:t.end?.id||"",startLabel:t.startLabel,middleLabel:t.middleLabel,endLabel:t.endLabel,points:t.points,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,dataTimestamps:t.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:t}){return t?{label:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,textTimestamp:t.textTimestamp}}:{}}}const Ki="Diagram properties";class qi extends ht{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(kt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof z||t instanceof at)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof F?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof z&&t.sections))for(const e of t.sections)super.add(e),e.updateInView()}remove(t){const e=this.get(t);if(e&&(this.propertyEditorSelection===e&&this.openInPropertyEditor(void 0),super.remove(t),e.updateInView(),e instanceof z&&e.sections))for(const n of e.sections)super.remove(n.id),n.updateInView()}toggle(t){this.contains(t.id)?this.remove(t.id):this.add(t)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const t=this.entities[0];super.remove(t.id),t.updateInView()}}move(t){for(const e of this.all())e instanceof z&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],n=[],l=[],a=[];for(const s of this.all())s instanceof z?t.push(s.id):s instanceof F?e.push(s.id):s instanceof vt?n.push(s.id):s instanceof at?l.push(s.id):s instanceof ct&&a.push(s.id);const i=new ji(this.canvas,t,e,n,l,a);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Ye;for(const n of this.all())n instanceof z&&t.nodes.push(e.exportNode(n,!1)),n instanceof at&&t.connections.push(e.exportConnection(n,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const n=JSON.parse(e);if(n.type!=="daga-user-selection")return;const l=new Di(this.canvas,n.nodes,n.connections,t);this.canvas.actionStack.add(l),l.do()}catch{return}})}openInPropertyEditor(t,e=!0){e&&this.makeUpdateValuesAction();const n=this.canvas.parentComponent?.propertyEditor;if(n===void 0)return;const l=t?.valueSet;l?(this.propertyEditorSelection=t,e&&(this.propertyEditorValues=structuredClone(l.getValues())),n&&(t instanceof z||t instanceof at?(t instanceof z?t.name?n.title=`${t.type.name}: ${t.name}`:n.title=t.type.name:t instanceof at&&(n.title=t.type.name),n.valueSet=void 0,n.valueSet=l):(n.title=Ki,n.valueSet=void 0,n.valueSet=l))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,n&&(n.title="",n.valueSet=void 0))}makeUpdateValuesAction(){if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof Ue?void 0:this.propertyEditorSelection.id;if(wt(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;const e=this.propertyEditorValues,n=structuredClone(this.propertyEditorSelection?.valueSet.getValues()),[l,a]=Re(e,n,this.propertyEditorSelection?.valueSet),i=new _i(this.canvas,t,l,a);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=n}}const Ji=o=>o*Math.PI/180,Le=(o,t,e)=>{const n=Ji(e),l=Math.sin(n),a=Math.cos(n),i=(Math.abs(o*a)-Math.abs(t*l))/(a*a-l*l),s=(Math.abs(o*l)-Math.abs(t*a))/(l*l-a*a);return[i,s]},Qi=12,_=6,to=25,ae="diagram-connection-unfinished",Xt=class Xt{constructor(t,e){if(this.backgroundPatternId=`daga-background-pattern-id-${Xt.canvasCount++}`,this.zoomTransform=E.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new kt.Subject,this.diagramChange$=new kt.Subject,this.diagramEvent$=new kt.Subject,this.propertyEditorChanges$=new kt.Subject,this.parentComponent=t,this.model=new Ue(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new qi(this),this.userHighlight=new Wi(this,e.canvas?.highlightSections!==!1),this.contextMenu=new Xi(this,e.canvas?.contextMenu),this.backgroundColor=e.canvas?.backgroundColor||"#FFFFFF",this.gridStyle=e.canvas?.grid?.style??Mt.style,this.gridSize=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?0:Math.abs(e.canvas?.grid?.spacing||Mt.spacing),this.gridThickness=Math.abs(e.canvas?.grid?.thickness||Mt.thickness),this.gridColor=e.canvas?.grid?.color||Mt.color,this.snapToGrid=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?!1:e.canvas?.grid?.snap||Mt.snap,this.zoomFactor=e.canvas?.zoomFactor||2,this.panRate=e.canvas?.panRate||100,this.inferConnectionType=e.connectionSettings?.inferConnectionType||!1,this.autoTightenConnections=e.connectionSettings?.autoTighten!==!1,this.allowConnectionLoops=e.connectionSettings?.allowLoops||!1,this.allowSharingPorts=e.connectionSettings?.sharePorts!==!1,this.allowSharingBothPorts=e.connectionSettings?.shareBothPorts||!1,this.portHighlightRadius=e.connectionSettings?.portHighlightRadius||100,this.multipleSelectionOn=!1,this.priorityThresholds=e.canvas?.priorityThresholds||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new Ri(this,to),this.collabEngine=new zi(this),e.nodeTypes)for(const n of e.nodeTypes){const l=new _e({...e.nodeTypeDefaults,...n});this.model.nodes.types.add(l)}if(e.portTypes)for(const n of e.portTypes){const l=new Mi({...e.portTypeDefaults,...n});this.model.ports.types.add(l)}if(e.connectionTypes){for(const n of e.connectionTypes){const l=new Oe({...e.connectionTypeDefaults,...n});this.model.connections.types.add(l)}this._connectionType=e?.connectionSettings?.defaultConnection!==void 0?this.model.connections.types.get(e.connectionSettings.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){this._connectionType=t,this.parentComponent?.palette?.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){B(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){this.priorityThreshold=t,this.updateModelInView();for(const e of this.model.nodes)this.fitNodeInView(e.id);this.parentComponent?.palette?.refreshPalette()}initView(t){const e=E.select(t);e.html(""),this.diagramRoot=e.append("div").node(),E.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),E.select(this.diagramRoot).on(C.Click,()=>{E.select(this.diagramRoot).node()?.focus()}).on(C.ContextMenu,l=>{if(this.dragging){l.preventDefault(),l.stopPropagation(),this.dragging=!1;return}const a=new ft(l,null);this.diagramEvent$.next(a),!a.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(l.preventDefault(),this.contextMenu.open(l))}).on(C.DoubleClick,l=>{const a=new ut(l,null);this.diagramEvent$.next(a)}).on(C.KeyDown,l=>{if(!l.ctrlKey&&(l.key===W.Delete||l.key===W.Backspace)&&this.canUserPerformAction(k.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="a"){l.preventDefault();for(const a of this.model.nodes)this.userSelection.add(a);for(const a of this.model.connections)this.userSelection.add(a);this.diagramEvent$.next(new D(this.userSelection.all(),!0))}if(l.ctrlKey&&l.key==="i"){l.preventDefault();const a=[],i=[];for(const s of this.model.nodes)this.userSelection.toggle(s),s.selected?a.push(s):i.push(s);for(const s of this.model.connections)this.userSelection.toggle(s),s.selected?a.push(s):i.push(s);a.length>0&&this.diagramEvent$.next(new D(a,!0)),i.length>0&&this.diagramEvent$.next(new D(i,!1))}if(l.ctrlKey&&l.key==="c"&&this.canUserPerformAction(k.Clipboard)&&(l.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="x"&&this.canUserPerformAction(k.Clipboard)&&this.canUserPerformAction(k.Remove)&&(l.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="v"&&this.canUserPerformAction(k.Paste)){l.preventDefault();const a=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(a[0][0]+a[1][0])/2,(a[0][1]+a[1][1])/2])),this.cancelAllUserActions()}l.ctrlKey&&l.key==="y"&&(l.preventDefault(),this.actionStack.redo()),l.ctrlKey&&l.key==="z"&&(l.preventDefault(),this.actionStack.undo()),l.key==="+"&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.zoomBy(this.zoomFactor)),l.key==="-"&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.zoomBy(1/this.zoomFactor)),l.key===W.ArrowLeft&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowRight&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowDown&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),l.key===W.ArrowUp&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const n=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%");n.call(this.zoomBehavior=E.zoom().filter(l=>l.type!==C.DoubleClick).on(le.Zoom,l=>{if(l.sourceEvent){if(!this.canUserPerformAction(k.Zoom)){S(T.NotAllowed);return}l.sourceEvent.type===C.Wheel&&l.sourceEvent.wheelDelta!==void 0?(l.sourceEvent.wheelDelta>0&&S(T.ZoomIn),l.sourceEvent.wheelDelta<0&&S(T.ZoomOut)):l.sourceEvent.type===C.MouseMove&&S(T.AllScroll)}this.zoomTransform=l.transform;const a=l.transform.toString();this.selectCanvasElements().attr("transform",a),E.select(`#${this.backgroundPatternId}`).attr("patternTransform",a),this.contextMenu.close()}).on(le.End,()=>{S()})),n.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(C.MouseMove,l=>{if(this.unfinishedConnection!==void 0){const a=this.getPointerLocationRelativeToCanvas(l);this.unfinishedConnection.endCoords=a}}).on(C.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new K(null)))}).on(C.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new K(null))),this.contextMenu.close(),this.userSelection.size()>0){const l=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(l,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(E.drag().filter(l=>this.multipleSelectionOn||mt(l)).on(I.Start,l=>{this.startMultipleSelection(l)}).on(I.Drag,l=>{this.continueMultipleSelection(l)}).on(I.End,l=>{this.finishMultipleSelection(l)})),Gi(this,n,this.backgroundPatternId),n.append("g").attr("class","daga-canvas-elements")}getZoomLevel(){return this.zoomTransform.k}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView(),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView(),t)}getViewCoordinates(){return[this.zoomTransform.x,this.zoomTransform.y]}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView(),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView(),t,e)}center(){if(this.model.nodes.length>0){const t=this.selectCanvasView().select("rect").node()?.getBBox(),e=this.model.nodes.all(),n=Math.min(...e.map(p=>p.coords[0])),l=Math.max(...e.map(p=>p.coords[0]+p.width)),a=(n+l)/2,i=l-n,s=t.width,r=Math.min(...e.map(p=>p.coords[1])),c=Math.max(...e.map(p=>p.coords[1]+p.height)),d=(r+c)/2,h=c-r,u=t.height,y=Math.min(s/i,u/h,1);this.translateTo(a,d),this.zoomTo(y)}}getClosestGridPoint(t){return this.gridSize===0||!isFinite(this.gridSize)?t:[Math.round(t[0]/this.gridSize)*this.gridSize,Math.round(t[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){const t=this.selectSVGElement().node()?.getBoundingClientRect(),e=[t?.width||0,t?.height||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return E.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return E.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return E.pointer(this.getEventHoldingCoordinates(t),E.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.defaultLook.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=l.merge(e);n.remove(),l.on(C.MouseOver,(i,s)=>{this.dragging||(this.userHighlight.focusOn(s),this.diagramEvent$.next(new K(s)))}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(r,!1))}this.userSelection.toggle(s),this.diagramEvent$.next(new D([s],s.selected))}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(s),this.diagramEvent$.next(new K(s)),this.userSelection.add(s),this.diagramEvent$.next(new D([s],!0)),this.contextMenu.open(i))}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,s)}).on(I.Drag,(i,s)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,s)}).on(I.End,(i,s)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,s),this.secondaryButton=!1})),ne(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed&&S(T.EWResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed?(S(T.EWResize),this.currentAction=new G(this,k.StretchNode,s.id,s.getGeometry(),s.getGeometry())):S(T.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed){const r=this.getPointerLocationRelativeToCanvas(i);s.stretch(f.Left,s.coords[0]-r[0])}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed&&this.currentAction instanceof G&&this.currentAction.intent===k.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.stretch(f.Left,s.coords[0]-r[0]),this.currentAction.to=s.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed&&S(T.NSResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed?(S(T.NSResize),this.currentAction=new G(this,k.StretchNode,s.id,s.getGeometry(),s.getGeometry())):S(T.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed){const r=this.getPointerLocationRelativeToCanvas(i);s.stretch(f.Top,s.coords[1]-r[1])}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed&&this.currentAction instanceof G&&this.currentAction.intent===k.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.stretch(f.Top,s.coords[1]-r[1]),this.currentAction.to=s.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed&&S(T.EWResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed?(S(T.EWResize),this.currentAction=new G(this,k.StretchNode,s.id,s.getGeometry(),s.getGeometry())):S(T.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed){const r=this.getPointerLocationRelativeToCanvas(i);s.stretch(f.Right,r[0]-(s.coords[0]+s.width))}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(k.StretchNode)&&s.type.resizableX&&!s.removed&&this.currentAction instanceof G&&this.currentAction.intent===k.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.stretch(f.Right,r[0]-(s.coords[0]+s.width)),this.currentAction.to=s.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed&&S(T.NSResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed?(S(T.NSResize),this.currentAction=new G(this,k.StretchNode,s.id,s.getGeometry(),s.getGeometry())):S(T.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed){const r=this.getPointerLocationRelativeToCanvas(i);s.stretch(f.Bottom,r[1]-(s.coords[1]+s.height))}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(k.StretchNode)&&s.type.resizableY&&!s.removed&&this.currentAction instanceof G&&this.currentAction.intent===k.StretchNode){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.stretch(f.Bottom,r[1]-(s.coords[1]+s.height)),this.currentAction.to=s.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),re(a),a.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),a.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updateSectionsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-section${i.getResizableX()?" resizable-x":""}${i.getResizableY()?" resizable-y":""} ${i.look?.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=l.merge(e);n.remove(),l.on(C.MouseOver,(i,s)=>{this.dragging||(this.userHighlight.focusOn(s),this.diagramEvent$.next(new K(s)))}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(c,!1))}const r=lt(s);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const c=lt(s);this.userHighlight.focusOn(c),this.diagramEvent$.next(new K(c)),this.userSelection.add(c),this.diagramEvent$.next(new D([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const r=s?.node;r?this.startMovingNode(i,r):S(T.NotAllowed)}}).on(I.Drag,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const r=s?.node;r?this.continueMovingNode(i,r):S(T.NotAllowed)}}).on(I.End,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const r=s?.node;r?this.finishMovingNode(i,r):S()}this.secondaryButton=!1})),ne(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&S(T.EWResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&s.node?(S(T.EWResize),this.currentAction=new G(this,k.StretchSection,s.node.id,s.node.getGeometry(),s.node.getGeometry())):S(T.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&s.node){const r=this.getPointerLocationRelativeToCanvas(i);s.node.stretchSections(f.Left,s.coords[0]-r[0],s.indexXInNode,s.indexYInNode)}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&this.currentAction instanceof G&&this.currentAction.intent===k.StretchSection&&s.node){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.node.stretchSections(f.Left,s.coords[0]-r[0],s.indexXInNode,s.indexYInNode),this.currentAction.to=s.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&S(T.NSResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&s.node?(S(T.NSResize),this.currentAction=new G(this,k.StretchSection,s.node.id,s.node.getGeometry(),s.node.getGeometry())):S(T.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&s.node){const r=this.getPointerLocationRelativeToCanvas(i);s.node.stretchSections(f.Top,s.coords[1]-r[1],s.indexXInNode,s.indexYInNode)}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&this.currentAction instanceof G&&this.currentAction.intent===k.StretchSection&&s.node){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.node.stretchSections(f.Top,s.coords[1]-r[1],s.indexXInNode,s.indexYInNode),this.currentAction.to=s.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&S(T.EWResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&s.node?(S(T.EWResize),this.currentAction=new G(this,k.StretchSection,s.node.id,s.node.getGeometry(),s.node.getGeometry())):S(T.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&s.node){const r=this.getPointerLocationRelativeToCanvas(i);s.node.stretchSections(f.Right,r[0]-(s.coords[0]+s.width),s.indexXInNode,s.indexYInNode)}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(k.StretchSection)&&s.getResizableX()&&!s.removed&&this.currentAction instanceof G&&this.currentAction.intent===k.StretchSection&&s.node){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.node.stretchSections(f.Right,r[0]-(s.coords[0]+s.width),s.indexXInNode,s.indexYInNode),this.currentAction.to=s.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&S(T.NSResize)}).on(C.MouseOut,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&S()}).call(E.drag().on(I.Start,(i,s)=>{this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&s.node?(S(T.NSResize),this.currentAction=new G(this,k.StretchSection,s.node.id,s.node.getGeometry(),s.node.getGeometry())):S(T.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&s.node){const r=this.getPointerLocationRelativeToCanvas(i);s.node.stretchSections(f.Bottom,r[1]-(s.coords[1]+s.height),s.indexXInNode,s.indexYInNode)}}).on(I.End,(i,s)=>{if(this.canUserPerformAction(k.StretchSection)&&s.getResizableY()&&!s.removed&&this.currentAction instanceof G&&this.currentAction.intent===k.StretchSection&&s.node){let r=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(r=this.getClosestGridPoint(r)),s.node.stretchSections(f.Bottom,r[1]-(s.coords[1]+s.height),s.indexXInNode,s.indexYInNode),this.currentAction.to=s.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),re(a),a.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),a.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),a.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updatePortsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-port ${i.look.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=l.merge(e);n.remove(),l.on(C.MouseOver,(i,s)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(s),this.diagramEvent$.next(new K(s))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(s.getNode()?.type?.id||"")&&s.allowsIncoming||this.unfinishedConnection.type.canStartFromType(s.getNode()?.type?.id||"")&&s.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsIncoming||S(T.NoDrop))}).on(C.MouseOut,()=>{this.unfinishedConnection&&S(T.Grabbing)}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(c,!1))}const r=lt(s);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const c=lt(s);this.userHighlight.focusOn(c),this.diagramEvent$.next(new K(c)),this.userSelection.add(c),this.diagramEvent$.next(new D([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(k.AddConnection)&&(this.allowSharingPorts||s.incomingConnections.length===0&&s.outgoingConnections.length===0)&&!s.removed?(S(T.Grabbing),this.startConnection(s),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):S(T.NotAllowed)}).on(I.Drag,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(k.AddConnection)&&!s.removed&&this.unfinishedConnection!==void 0){const r=[i.x,i.y];this.unfinishedConnectionTracer?.attr("d",se(this.unfinishedConnection.look.shape||J.look.shape,this.unfinishedConnection.startCoords,r,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.look.thickness||J.look.thickness,this.unfinishedConnection.startMarkerLook?.width,this.unfinishedConnection.endMarkerLook?.width));const c=this.unfinishedConnectionTracer?.node();if(c){let d=2;const h=c.getTotalLength();h<d&&(d=0);const u=c.getPointAtLength(h-d);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=r;if(this.updateConnectionsInView(ae),this.model.ports.length>0){const d=this.getPointerLocationRelativeToCanvas(i);let h=Number.POSITIVE_INFINITY,u;for(const y of this.model.ports){const p=y.distanceTo(d);p<h&&(h=p,u=y)}u&&h<this.portHighlightRadius?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on(I.End,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(k.AddConnection)&&!s.removed){this.unfinishedConnectionTracer?.remove();const r=this.userHighlight.getFocus();if(r instanceof vt)this.finishConnection(r);else if(r instanceof ct&&r.rootElement instanceof vt)this.finishConnection(r.rootElement);else if(r instanceof z||r instanceof F||r instanceof ct){let c;if(r instanceof z||r instanceof F)c=r;else if(r.rootElement instanceof z||r.rootElement instanceof F)c=r.rootElement;else{this.dropConnection();return}const d=c.getClosestPortToPoint([i.x,i.y]);d!==void 0?this.finishConnection(d):this.dropConnection()}else this.dropConnection()}S()}this.secondaryButton=!1})),l.filter(".image-look").append("image"),ne(l),a.attr("transform",i=>`translate(${i.coords[0]-i.width/2},${i.coords[1]-i.width/2})`).attr("opacity",i=>i.removed?.5:1),re(a)}updateConnectionsInView(...t){const e=this.model.connections.filter(s=>this.priorityThreshold!==void 0?s.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let n=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,s=>s.id);const l=n.exit(),a=n.enter().append("g").attr("id",s=>s.id).attr("class","diagram-connection");t&&t.length>0&&(n=n.filter(s=>t.includes(s.id)));const i=a.merge(n);l.remove(),a.on(C.MouseOver,(s,r)=>{r.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new K(r)))}).on(C.Click,(s,r)=>{if(!s.ctrlKey&&!s.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(c,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(C.ContextMenu,(s,r)=>{if(this.dragging){s.preventDefault(),s.stopPropagation(),this.dragging=!1;return}const c=new ft(s,r);this.diagramEvent$.next(c),!c.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(s.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new K(r)),this.userSelection.add(r),this.diagramEvent$.next(new D([r],!0)),this.contextMenu.open(s))}).on(C.DoubleClick,(s,r)=>{const c=new ut(s,r);this.diagramEvent$.next(c)}).call(E.drag().filter(s=>(this.secondaryButton=mt(s),!0)).on(I.Start,s=>{this.startMultipleSelection(s)}).on(I.Drag,s=>{this.continueMultipleSelection(s)}).on(I.End,s=>{this.finishMultipleSelection(s)})),a.append("path").attr("class","diagram-connection-path"),a.append("path").attr("class","diagram-connection-path-box"),a.append("marker").attr("id",s=>`${s.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),a.append("marker").attr("id",s=>`${s.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),a.append("g").attr("class","diagram-connection-start-label"),a.select("g.diagram-connection-start-label").append("path"),a.select("g.diagram-connection-start-label").append("text").style("user-select","none"),a.append("g").attr("class","diagram-connection-middle-label"),a.select("g.diagram-connection-middle-label").append("path"),a.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),a.append("g").attr("class","diagram-connection-end-label"),a.select("g.diagram-connection-end-label").append("path"),a.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",s=>s.removed?.5:1).select("path.diagram-connection-path").attr("d",s=>se(s.look.shape||J.look.shape,s.startCoords,s.endCoords,s.startDirection,s.endDirection,s.look.thickness||J.look.thickness,s.startMarkerLook?.width,s.endMarkerLook?.width)).attr("marker-start",s=>`url(#${s.id}-start-marker)`).attr("marker-end",s=>`url(#${s.id}-end-marker)`).attr("stroke",s=>s.look.color||J.look.color).attr("stroke-width",s=>`${s.look.thickness}px`).attr("stroke-dasharray",s=>de(s.look.style||J.look.style,s.look.thickness||J.look.thickness)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",s=>se(s.look.shape||J.look.shape,s.startCoords,s.endCoords,s.startDirection,s.endDirection,s.look.thickness||J.look.thickness,s.startMarkerLook?.width,s.endMarkerLook?.width)).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",s=>`${(s.look.thickness||J.look.thickness)+Qi}px`).attr("stroke-dasharray",s=>de(s.look.style||J.look.style,s.look.thickness||J.look.thickness)).attr("fill","none"),i.data().forEach(s=>{this.updateConnectionLabelsInView(s),this.updateConnectionMarkersInView(s)})}updateFieldsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=l.merge(e);n.remove(),l.style("box-sizing","border-box").on(C.MouseOver,(i,s)=>{this.dragging||(this.userHighlight.focusOn(s),this.diagramEvent$.next(new K(s)))}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(c,!1))}const r=lt(s);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const c=lt(s);this.userHighlight.focusOn(c),this.diagramEvent$.next(new K(c)),this.userSelection.add(c),this.diagramEvent$.next(new D([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.EditField)&&s.editable&&!s.removed&&(this.currentAction=new Ee(this,s.id,s.text,""),this.createInputField(s.text,s.coords,s.width,s.height,s.fontSize,s.fontFamily||O.fontFamily,s.orientation,c=>{},c=>{s.text=c,this.currentAction instanceof Ee&&(this.currentAction.to=c,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof F&&(r=s.rootElement.node),r?this.startMovingNode(i,r):S(T.NotAllowed)}}).on(I.Drag,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof F&&(r=s.rootElement.node),r?this.continueMovingNode(i,r):S(T.NotAllowed)}}).on(I.End,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof F&&(r=s.rootElement.node),r?this.finishMovingNode(i,r):S()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),a.attr("x",0).attr("y",0).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("div").style("justify-content",i=>i.horizontalAlign===At.Center?"center":i.horizontalAlign===At.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Ut.Center?"center":i.verticalAlign===Ut.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":`${Le(i.width,i.height,i.orientation)[0]}px`).style("max-height",i=>i.fit?"default":`${Le(i.width,i.height,i.orientation)[1]}px`).style("overflow",i=>i.fit?"default":"clip").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===At.Center?"center":i.horizontalAlign===At.Right?"end":"start").style("transform",i=>`rotate(${i.orientation}deg)`).style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"<").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 n=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),n.remove(),l.on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(i)}).on(I.Drag,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(i)}).on(I.End,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(i)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const n=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),n.remove(),l.on(C.MouseOver,(i,s)=>{this.dragging||(this.userHighlight.focusOn(s),this.diagramEvent$.next(new K(s)))}).on(C.Click,(i,s)=>{if(!i.ctrlKey&&!i.shiftKey){const r=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new D(r,!1))}if(s.rootElement){const r=lt(s.rootElement);this.userSelection.toggle(r),this.diagramEvent$.next(new D([r],r.selected))}}).on(C.ContextMenu,(i,s)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new ft(i,s);if(this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&s.rootElement){i.preventDefault();const c=lt(s.rootElement);this.userHighlight.focusOn(c),this.diagramEvent$.next(new K(c)),this.userSelection.add(c),this.diagramEvent$.next(new D([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,s)=>{const r=new ut(i,s);this.diagramEvent$.next(r)}).call(E.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on(I.Start,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof F&&(r=s.rootElement.node),r?this.startMovingNode(i,r):S(T.NotAllowed)}}).on(I.Drag,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof F&&(r=s.rootElement.node),r?this.continueMovingNode(i,r):S(T.NotAllowed)}}).on(I.End,(i,s)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let r;s.rootElement instanceof z?r=s.rootElement:s.rootElement instanceof F&&(r=s.rootElement.node),r?this.finishMovingNode(i,r):S()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),l=e.select("path").node(),a={...O,...t.type.label};if(l){const i=l.getTotalLength();let s=0,r=0,c=0,d=0,h=0,u=0;if(a.backgroundColor==="#00000000"){const m=t.endCoords[0]-t.startCoords[0],b=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case f.Top:s=m>=0?-.5:.5,h=s,r=-.5;break;case f.Bottom:s=m>=0?-.5:.5,h=s,r=.5;break;case f.Left:s=-.5,r=b>0?-.5:.5,u=r;break;case f.Right:s=.5,r=b>0?-.5:.5,u=r;break;default:s=.5,h=s,r=-.5,u=r}switch(t.endDirection){case f.Top:h=m>=0?.5:-.5,u=.5;break;case f.Bottom:h=m>=0?.5:-.5,u=-.5;break;case f.Left:h=-.5,u=b>0?.5:-.5;break;case f.Right:h=.5,u=b>0?.5:-.5;break;default:h=.5,u=-.5}Math.abs(m)>=Math.abs(b)?(c=m>0?-.5:.5,d=b>0?.5:-.5):(c=m>0?.5:-.5,d=b>0?-.5:.5)}e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",a.fontSize/3).attr("text-anchor","middle").attr("font-family",a.fontFamily).attr("font-size",a.fontSize).attr("fill",t.selected?a.selectedColor:a.color).style("font-kerning","none").text(t.startLabel);const y=e.select("g.diagram-connection-start-label text").node()?.getBoundingClientRect();if(y){const m=t.startLabel?y.width/this.zoomTransform.k+zt(a)+Rt(a):0,b=t.startLabel?y.height/this.zoomTransform.k+Ot(a)+Pt(a):0,w=l.getPointAtLength(Math.max(Y(a)+m/2,st(a)+m/2,H(a)+b/2,Q(a)+b/2));e.select("g.diagram-connection-start-label path").attr("d",Gt(-m/2,-b/2,m,b)).attr("fill",a.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${w.x+s*m},${w.y+r*b})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",a.fontSize/3).attr("text-anchor","middle").attr("font-family",a.fontFamily).attr("font-size",a.fontSize).attr("fill",t.selected?a.selectedColor:a.color).style("font-kerning","none").text(t.middleLabel);const p=e.select("g.diagram-connection-middle-label text").node()?.getBoundingClientRect();if(p){const m=t.middleLabel?p.width/this.zoomTransform.k+zt(a)+Rt(a):0,b=t.middleLabel?p.height/this.zoomTransform.k+Ot(a)+Pt(a):0,w=l.getPointAtLength(i/2);e.select("g.diagram-connection-middle-label path").attr("d",Gt(-m/2,-b/2,m,b)).attr("fill",a.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${w.x+c*m},${w.y+d*b})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",a.fontSize/3).attr("text-anchor","middle").attr("font-family",a.fontFamily).attr("font-size",a.fontSize).attr("fill",t.selected?a.selectedColor:a.color).style("font-kerning","none").text(t.endLabel);const v=e.select("g.diagram-connection-end-label text").node()?.getBoundingClientRect();if(v){const m=t.endLabel?v.width/this.zoomTransform.k+zt(a)+Rt(a):0,b=t.endLabel?v.height/this.zoomTransform.k+Ot(a)+Pt(a):0,w=l.getPointAtLength(i-Math.max(Y(a)+m/2,st(a)+m/2,H(a)+b/2,Q(a)+b/2));e.select("g.diagram-connection-end-label path").attr("d",Gt(-m/2,-b/2,m,b)).attr("fill",a.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${w.x+h*m},${w.y+u*b})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),n=e.select("marker.diagram-connection-start-marker"),l=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?n.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.width).attr("markerHeight",t.startMarkerLook.height).attr("refX",t.startMarkerLook.refX).attr("refY",t.startMarkerLook.refY).select("image").attr("href",t.startMarkerLook.image).attr("width",t.startMarkerLook.width).attr("height",t.startMarkerLook.height):n.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?l.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.width).attr("markerHeight",t.endMarkerLook.height).attr("refX",t.endMarkerLook.refX).attr("refY",t.endMarkerLook.refY).select("image").attr("href",t.endMarkerLook.image).attr("width",t.endMarkerLook.width).attr("height",t.endMarkerLook.height):l.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof z||e.rootElement instanceof F){const n=this.minimumSizeOfField(e),l=n[0]+Y(e.rootElement.type?.label)+st(e.rootElement.type?.label)-e.rootElement.width,a=n[1]+H(e.rootElement.type?.label)+Q(e.rootElement.type?.label)-e.rootElement.height;return l<=0&&a<=0}return!0}fitFieldRootInView(t,e=!0){const n=this.model.fields.get(t);if(n){if(n.rootElement instanceof z){const l=this.minimumSizeOfField(n);let a=l[0]+Y(n.rootElement.type.label)+st(n.rootElement.type.label)-n.rootElement.width,i=l[1]+H(n.rootElement.type.label)+Q(n.rootElement.type.label)-n.rootElement.height;this.snapToGrid&&(a=Math.ceil(a/this.gridSize)*this.gridSize,i=Math.ceil(i/this.gridSize)*this.gridSize),n.rootElement.width+a<n.rootElement.type.minWidth&&(a=n.rootElement.type.minWidth-n.rootElement.width),n.rootElement.height+i<n.rootElement.type.minHeight&&(i=n.rootElement.type.minHeight-n.rootElement.height),(e!==!1||a>0)&&n.rootElement.stretch(f.Right,a),(e!==!1||i>0)&&n.rootElement.stretch(f.Bottom,i)}if(n.rootElement instanceof F){const l=this.minimumSizeOfField(n);let a=l[0],i=l[1];for(const d of n.rootElement.node?.sections||[])d.label&&(d.indexXInNode===n.rootElement.indexXInNode&&d.indexYInNode!==n.rootElement.indexYInNode?a=Math.max(a,this.minimumSizeOfField(d.label)[0]):d.indexXInNode!==n.rootElement.indexXInNode&&d.indexYInNode===n.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(d.label)[1])));l[0]<a&&(l[0]=a),l[1]<i&&(l[1]=i);const s=n.rootElement.type;let r=l[0]+Y(s?.label)+st(s?.label)-n.rootElement.width,c=l[1]+H(s?.label)+Q(s?.label)-n.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,c=Math.ceil(c/this.gridSize)*this.gridSize),n.rootElement.width+r<(n.rootElement.getMinWidth()||0)&&(r=(n.rootElement.getMinWidth()||0)-n.rootElement.width),n.rootElement.height+c<(n.rootElement.getMinHeight()||0)&&(c=(n.rootElement.getMinHeight()||0)-n.rootElement.height),(e||r>0)&&n.rootElement.node?.stretchSections(f.Right,r,n.rootElement.indexXInNode,n.rootElement.indexYInNode),(e||c>0)&&n.rootElement.node?.stretchSections(f.Bottom,c,n.rootElement.indexXInNode,n.rootElement.indexYInNode)}}}fitNodeInView(t,e=!0){const n=this.model.nodes.get(t);if(n&&n.sections.length>0&&this.priorityThreshold){let l=0,a=0;for(const i of n.sections)if(i.getPriority()>=this.priorityThreshold){const s=i.coords[0]+i.width-n.coords[0],r=i.coords[1]+i.height-n.coords[1];l=Math.max(l,s),a=Math.max(a,r)}l+=n.type.sectionGrid?.margin||0,a+=n.type.sectionGrid?.margin||0,(e||l>n.width)&&n.stretch(f.Right,l-n.width),(e||a>n.height)&&n.stretch(f.Bottom,a-n.height)}}selectRoot(){return E.select(this.diagramRoot)}selectSVGElement(){return E.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming))this.unfinishedConnection=new at(this.model,this.connectionType,t,void 0,ae);else if(this.inferConnectionType){let e=this.model.connections.types.all().find(n=>t.allowsOutgoing&&n.canStartFromType(t.getNode()?.type?.id||""));e===void 0&&(e=this.model.connections.types.all().find(n=>t.allowsIncoming&&n.canFinishOnType(t.getNode()?.type?.id||""))),e!==void 0&&(this.unfinishedConnection=new at(this.model,e,t,void 0,ae))}}}finishConnection(t){if(this.userHighlight.clear(),this.unfinishedConnection!==void 0){if(!this.allowConnectionLoops&&this.unfinishedConnection.start===t){this.dropConnection();return}if(!this.allowSharingPorts&&(t.incomingConnections.length>0||t.outgoingConnections.length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(e=>e.start===this.unfinishedConnection?.start&&e.end===t||e.end===this.unfinishedConnection?.start&&e.start===t)!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming){const e=new oe(this,this.unfinishedConnection.type,this.unfinishedConnection.start?.id,t.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&this.unfinishedConnection.type.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing){const e=new oe(this,this.unfinishedConnection.type,t.id,this.unfinishedConnection.start?.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.inferConnectionType){let e=this.model.connections.types.all().find(l=>l.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&l.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming),n=!1;if(e===void 0&&(e=this.model.connections.types.all().find(l=>l.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&l.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing),n=!0),e!==void 0){const l=new oe(this,e,n?t.id:this.unfinishedConnection.start?.id,n?this.unfinishedConnection.start?.id:t.id);this.dropConnection(),l.do(),this.actionStack.add(l)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){this.unfinishedConnection?.setStart(void 0),this.unfinishedConnection?.setEnd(void 0),this.unfinishedConnection?.select()?.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(t){return this.userActions[t]!==!1}createInputField(t,e,n,l,a,i,s,r,c){this.removeInputField();const d=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${n}px`).attr("height",`${l}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=d;const h=d.append("xhtml:textarea");let u,y;h.text(t).style("box-sizing","border-box").style("width",`${n}px`).style("height",`${l}px`).style("font-size",`${a}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(C.KeyDown,v=>{v.stopPropagation()}).on(C.KeyUp,v=>{if(v.stopPropagation(),v.key===W.Escape){const m=h.property("value");this.removeInputField(),c&&c(m)}}).on(C.Input,()=>{const v=h.property("value");h.attr("cols",gi(v)+1),h.attr("rows",ui(v)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,y=h.property("scrollHeight")+1;const m=Math.max(u,n),b=Math.max(y,l);d?.attr("width",`${m}px`),h.style("width",`${m}px`),d?.attr("height",`${b}px`),h.style("height",`${b}px`),r&&r(v)}).on(C.Click,v=>{v.stopPropagation()}).on(C.FocusOut,()=>{const v=h.property("value");this.removeInputField(),c&&c(v)});const p=h.node();p.focus(),p.select()}removeInputField(){this.inputFieldContainer?.select("input")?.on(C.Blur,null),this.inputFieldContainer?.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){const e=t.select()?.select("p")?.node();if(!e)return[0,0];const n=e.getBoundingClientRect();return[n.width/this.zoomTransform.k,n.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed)if(S(T.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(n=>n instanceof z)>1)this.currentAction=new ie(this,this.userSelection.filter(n=>n instanceof z).map(n=>n.id),e.coords);else{const n=e.getLastAncestor();this.currentAction=new G(this,k.MoveNode,e.id,e.getGeometry(),e.getGeometry(),n?.id,n?.getGeometry(e.id),n?.getGeometry(e.id))}else S(T.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&(this.currentAction instanceof ie||this.currentAction instanceof G)&&!e.removed){const n=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([n[0]-e.coords[0],n[1]-e.coords[1]]):e.move(n),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let n=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(n=this.getClosestGridPoint(n)),this.currentAction instanceof ie){const l=this.currentAction.delta;this.currentAction.delta=[n[0]-l[0],n[1]-l[1]],e.selected?this.userSelection.move([l[0]-e.coords[0],l[1]-e.coords[1]]):e.move(l)}else if(this.currentAction instanceof G){e.move(n);const a=this.model.nodes.getAtCoordinates(t.x,t.y).filter(r=>r.id!==e.id&&!r.isDescendantOf(e)).filter(r=>r.type.childrenTypes.includes(e.type.id)),i=je(a),s=i[i.length-1];if(s!==e.parent&&(e.type.canBeParentless||s!==void 0)){const r=s?.getLastAncestor(),c=this.currentAction.from,d=new Vi(this,e.id,e.parent?.id,s?.id,c,e.getGeometry(),r?.id,r?.getGeometry(e.id),r?.getGeometry(e.id));e.parent?.removeChild(e),s!==void 0&&s.addChild(e),d.toChildGeometry=e.getGeometry(e.id),d.toAncestorGeometry=r?.getGeometry(e.id),this.currentAction=d}else{const r=e?.getLastAncestor();this.currentAction.ancestorId=r?.id,this.currentAction.fromAncestorGeometry=r?.getGeometry(e.id),e.parent?.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=r?.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}S(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectSVGElement().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(S(T.Crosshair),this.multipleSelectionContainer?.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x)?.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y)?.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k)?.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);this.multipleSelectionContainer?.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const n of this.model.nodes)ii([n.coords,[n.coords[0]+n.width,n.coords[1]+n.height]],[this.draggingFrom,e])&&this.userSelection.add(n);this.multipleSelectionOn=!1,this.diagramEvent$.next(new D(this.userSelection.all(),!0)),S()}};Xt.canvasCount=0;let ue=Xt;class Xe{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const t of this.grid)t.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const t of this.grid)t.push(void 0)}addRowTop(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.splice(0,0,t),this.offsetY=this.offsetY+1}addRowBottom(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.push(t)}get(t){if(this.grid[t[1]+this.offsetY])return this.grid[t[1]+this.offsetY][t[0]+this.offsetX]}set(t,e){for(;t[0]<-this.offsetX;)this.addColumnLeft();for(;t[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;t[1]<-this.offsetY;)this.addRowTop();for(;t[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[t[1]+this.offsetY][t[0]+this.offsetX]=e}getClosestEmptyCoordinate(t){if(this.get(t)===void 0)return t;const e=[...t];for(let n=1;;++n){const l=n%2>0?n:-n,a=l>0?1:-1,i=[e[0]+l,e[1]+l];for(let s=e[0];s!==i[0]+a;s+=a)if(e[0]=s,this.get(e)===void 0)return e;for(let s=e[1];s!==i[1]+a;s+=a)if(e[1]=s,this.get(e)===void 0)return e}}}class eo{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Xe,n=t.nodes.filter(s=>!s.parent);for(;n.length>0;)We(n[0],e,[0,0],n);const l=Math.max(...t.nodes.map(s=>s.width)),a=Math.max(...t.nodes.map(s=>s.height)),i=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let s=e.minY();s<=e.maxY();++s)for(let r=e.minX();r<=e.maxX();++r){const c=e.get([r,s]);c!==void 0&&c.move([r*(l+i),s*(a+i)])}return t}}const We=(o,t,e,n)=>{const l=t.getClosestEmptyCoordinate(e);t.set(l,o),B(n,o);for(const a of o.getAdjacentNodes())n.includes(a)&&We(a,t,l,n)};class io{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Xe,n=t.nodes.filter(d=>!d.parent),l={},a=n[0];let i=[a];for(l[a.id]=[0,0];n.length>0;){const d=[];for(const h of i){e.set(e.getClosestEmptyCoordinate(l[h.id]),h),B(n,h);const u=h.getAdjacentNodes();for(const y of u)n.includes(y)&&(d.push(y),l[y.id]=l[h.id])}if(d.length>0)i=d;else if(n.length>0){const h=n[0];i=[h],l[h.id]=e.getClosestEmptyCoordinate([0,0])}}const s=Math.max(...t.nodes.map(d=>d.width)),r=Math.max(...t.nodes.map(d=>d.height)),c=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let d=e.minY();d<=e.maxY();++d)for(let h=e.minX();h<=e.maxX();++h){const u=e.get([h,d]);u!==void 0&&u.move([h*(s+c),d*(r+c)])}return t}}class te{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;let n=t.nodes.filter(s=>!s.parent);const l=n[0];B(n,l);const a=[[l]];for(;n.length>0;){const s=a[a.length-1],r=[];for(const c of s){const d=c.getAdjacentNodes();for(const h of d)n.includes(h)&&(B(n,h),r.push(h))}r.length>0?a.push(r):(a.push(n),n=[])}let i=0;for(const s of a){let r=0;for(const d of s)d.move([i,r]),r+=e+d.height;const c=Math.max(...s.map(d=>d.width));i+=e+c}for(const s of t.connections)s.tighten();return t}}class oo{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;new te(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=.99,l=1,a=.1,i=2e5,s=.5,r=1,c=.002;let d=100;for(;d>l;){d=d*n;const h=[0,0];{for(const u of t.nodes)h[0]=h[0]+u.coords[0]+u.width/2,h[1]=h[1]+u.coords[1]+u.width/2;h[0]=h[0]/t.nodes.length,h[1]=h[1]/t.nodes.length}for(const u of t.nodes){const y=u.getAdjacentNodes();for(const p of t.nodes){const v=[u.coords[0]+u.width/2,u.coords[1]+u.height/2],m=[p.coords[0]+p.width/2,p.coords[1]+p.height/2],b=Me(u.coords,p.coords),w=[p.coords[0],p.coords[1]];if(y.includes(p)&&b>0&&(b>e+(Math.max(u.width,u.height)+Math.max(p.width,p.height))/2?(w[0]=w[0]-(m[0]-v[0])*a,w[1]=w[1]-(m[1]-v[1])*a):(w[0]=w[0]+(m[0]-v[0])*s,w[1]=w[1]+(m[1]-v[1])*s)),b>0){const M=i/(b*b);w[0]=w[0]+M*(m[0]-v[0])/b,w[1]=w[1]+M*(m[1]-v[1])/b}else w[0]=w[0]+r*(Math.random()*2-1),w[1]=w[1]+r*(Math.random()*2-1);w[0]=w[0]-(m[0]-h[0])*c,w[1]=w[1]-(m[1]-h[1])*c,w[0]-p.coords[0]>d?w[0]=p.coords[0]+d:w[0]-p.coords[0]<-d&&(w[0]=p.coords[0]-d),w[1]-p.coords[1]>d?w[1]=p.coords[1]+d:w[1]-p.coords[1]<-d&&(w[1]=p.coords[1]-d),p.move(w)}}}if(t.canvas&&t.canvas.snapToGrid)for(const h of t.nodes){const u=t.canvas.getClosestGridPoint(h.coords);h.move(u)}for(const h of t.connections)h.tighten();return t}}class so{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=t.nodes.filter(a=>!a.parent);n.sort((a,i)=>i.type.priority-a.type.priority);let l=0;for(const a of n)a.move([l,0]),l+=a.width+e;return t}}class no{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),n=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===n)return new te(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(d=>!d.parent),i=[],s=t.nodes.filter(d=>!d.parent).filter(d=>d.getPriority()>=e),r=[];if(s.length>1){const d=s[0];s.splice(0,1),r.push(d);const h=[d],u=[d];for(;h.length>0;){const y=h[0];h.splice(0,1),s.includes(y)&&(r.push(y),B(s,y));const p=y.getAdjacentNodes();for(const v of p)u.includes(v)||(h.push(v),u.push(v))}for(const y of s)r.push(y)}else r.push(s[0]);for(const d of r)B(a,d),i.push([d]);for(i.push([]),a.sort((d,h)=>h.type.priority-d.type.priority);a.length>0;){const d=a[0];a.splice(0,1);const h=[d],u=[d];let y=!1;for(;h.length>0;){const p=h[0];h.splice(0,1);const v=r.indexOf(p);if(v>=0){i[v].push(d),y=!0;break}else{const m=p.getAdjacentNodes();for(const b of m)u.includes(b)||(h.push(b),u.push(b))}}y||i[i.length-1].push(d)}let c=0;for(let d=0;d<i.length;++d){let h=0;for(let y=0;y<i[d].length;++y){const p=i[d][y];p.move([c,h]),h+=l+p.height}const u=Math.max(...i[d].map(y=>y.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}class ro{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),n=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===n)return new te(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(d=>!d.parent).sort((d,h)=>h.getPriority()-d.getPriority()),i=[];for(;a.length>0;){const d=a[0];a.splice(0,1);const h=new ve(void 0,d);Ze(h,a),i.push(h)}const s=[];for(const d of i)s.push([d]),Ke(d,s,s.length);const r=Math.max(...t.nodes.map(d=>d.height));let c=0;for(let d=0;d<s.length;++d){let h=0;for(let y=0;y<s[d].length;++y){const p=s[d][y];p.node.move([c,h]),h+=(l+r)*p.countBranchHeight()}const u=Math.max(...s[d].map(y=>y.node.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}const Ze=(o,t)=>{for(const e of o.node.getAdjacentNodes().sort((n,l)=>l.getPriority()-n.getPriority())){const n=t.indexOf(e);if(n>=0){t.splice(n,1);const l=o.addBranch(e);Ze(l,t)}}},Ke=(o,t,e)=>{if(o.branches.length>0){for(;e>=t.length;)t.push([]);for(const n of o.branches)t[e].push(n),Ke(n,t,e+1)}};class ve{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new ve(this,t);return e.depth=this.depth+1,this.branches.push(e),e}countBranchHeight(){if(this.branches.length<=0)return 1;{let t=0;for(const e of this.branches)t+=e.countBranchHeight();return t}}}class ao{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=t.nodes.filter(a=>!a.parent);n.sort((a,i)=>i.type.priority-a.type.priority);let l=0;for(const a of n)a.move([0,l]),l+=a.height+e;return t}}const $e={adjacency:new eo,breadth:new te,"breadth-adjacency":new io,force:new oo,horizontal:new so,priority:new no,tree:new ro,vertical:new ao},lo=L.createContext({}),St=L.createContext({});class co{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){}}const ye=({direction:o,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:n,disabled:l,rule:a,collapsedValue:i,visibleValue:s,onCollapse:r})=>{const[c,d]=L.useState(n),h=()=>{if(!l){const y=!c;d(y),r?.(y);let p;if(typeof t=="string")p=E.select(t),e&&(p=p.select(e));else{const v=t;if(!v)throw new Error("collapsableSelector is not a valid ref");p=E.select(v.current),e&&(p=p.select(e))}p.style(a,y?i:s)}},u=()=>{switch(o){case f.Right:return l?"daga-horizontal-none":c?"daga-horizontal-right":"daga-horizontal-left";case f.Bottom:return l?"daga-vertical-none":c?"daga-vertical-down":"daga-vertical-up";case f.Left:return l?"daga-horizontal-none":c?"daga-horizontal-left":"daga-horizontal-right";case f.Top:return l?"daga-vertical-none":c?"daga-vertical-up":"daga-vertical-down"}};return g.jsx("daga-collapse-button",{children:g.jsx("button",{className:`daga-collapse-button daga-${o}`,onClick:h,children:g.jsx("div",{className:u()})})})},ho=()=>{const o=L.useContext(St),t=L.useRef(null),[e,n]=L.useState([]);kt.merge(o.validatorChange$,o.diagramChange$).pipe(kt.map(()=>l())).subscribe();const l=()=>{n([]);for(const i of o.validators){const s=i.validate(o.model);n(s)}},a=i=>{if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const s=o.model.nodes.get(i.elementId)||o.model.connections.get(i.elementId);s&&o.userHighlight.add(s)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){o.userSelection.openInPropertyEditor(o.model.nodes.get(i.elementId)||o.model.connections.get(i.elementId));const s=o.model.nodes.get(i.elementId)||o.model.connections.get(i.elementId);s&&o.userHighlight.add(s),o.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(o.userSelection.openInPropertyEditor(),o.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames))};return g.jsx("daga-errors",{children:g.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&g.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:g.jsx("span",{children:"No errors found"})}),e.length>0&&g.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[g.jsxs("span",{children:[e.length," errors found"]}),g.jsx("div",{className:"daga-collapse-button-container",children:g.jsx(ye,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:f.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&g.jsx("div",{className:"daga-error-panel",children:g.jsx("ol",{children:e.map((i,s)=>g.jsx("li",{onClick:()=>a(i),dangerouslySetInnerHTML:{__html:i.message}},s))})})]})})},go=200,Ne=o=>(o||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),qe=({disabled:o,options:t,value:e,onChange:n})=>{const l=L.useRef(null),[a,i]=L.useState("");let s;const[r,c]=L.useState([]),[d,h]=L.useState([]),[u,y]=L.useState([]),[p,v]=L.useState([]),[m,b]=L.useState(!1);L.useEffect(()=>{i(t.find(A=>wt(A.key,e))?.label||"")},[e,t]);const w=A=>{if(!o)switch(A.key){case W.PageDown:s===void 0?(P(0),$(0)):(P(s+5),$(s)),A.preventDefault();break;case W.ArrowDown:s===void 0?(P(0),$(0)):(P(s+1),$(s)),A.preventDefault();break;case W.PageUp:s===void 0?(P(t.length-1),$(t.length-1)):(P(s-5),$(s)),A.preventDefault();break;case W.ArrowUp:s===void 0?(P(t.length-1),$(t.length-1)):(P(s-1),$(s)),A.preventDefault();break;case W.Escape:R(),A.preventDefault();break;case W.Enter:V(t[s||0]),A.preventDefault();break;default:M()}},M=()=>{if(!o){const A=Ne(a.trim());c([]),h([]),y([]),v([]);for(const j of t){const ot=Ne(j.label).indexOf(A);if(ot>=0){const jt=j.label.substring(0,ot),Z=j.label.substring(ot,ot+A.length),bt=j.label.substring(ot+A.length);c(it=>[...it,j]),h(it=>[...it,jt]),y(it=>[...it,Z]),v(it=>[...it,bt])}}b(!0)}},R=()=>{b(!1)},P=A=>{if(!o){if(s=A,A===void 0)return;A<0&&(s=0),A>=t.length&&(s=t.length-1)}},q=()=>{setTimeout(()=>{R()},go)},$=A=>{const j=l.current?.querySelectorAll("li")[A];j&&j.scrollIntoView({block:"center"})},x=()=>{o||(i(""),b(!1),s=void 0)},V=A=>{o||(i(A.label),b(!1),s=void 0,n(A.key))};return g.jsxs("div",{ref:l,className:`daga-autocomplete ${m?"daga-showing-options":""}`,children:[g.jsxs("div",{className:"daga-autocomplete-input",children:[g.jsx("input",{value:a,disabled:o,onKeyUp:w,onFocus:M,onBlur:q,onChange:A=>i(A.target.value)}),a!==""&&g.jsx("button",{className:"daga-clear",onClick:x})]}),g.jsx("div",{className:"daga-autocomplete-options",children:g.jsxs("ul",{className:"daga-autocomplete-option-list",children:[r.length===0&&g.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),r.map((A,j)=>g.jsxs("li",{className:`daga-autocomplete-option ${j===s?"daga-focused":""}`,onMouseMove:()=>P(j),onClick:()=>V(A),children:[g.jsx("span",{children:d[j]}),g.jsx("span",{className:"daga-match",children:u[j]}),g.jsx("span",{children:p[j]})]},j))]})})]})},uo=(o,t)=>o.find(e=>e.key===t)?.label||`${t}`,fo=({disabled:o,allowRepeats:t,options:e,value:n,onChange:l})=>{const[a,i]=L.useState(),[s,r]=L.useState([]),[c,d]=L.useState([]);L.useEffect(()=>{const m=n.length===0,b=n.map(w=>uo(e,w));r(b),m&&l(n),v()},[n,e]);const h=m=>{for(const b of n)if(b===m)return!0;return!1},u=m=>{n.length>m&&(n.splice(m,1),r(s.filter((b,w)=>w!==m)),l(n),v())},y=()=>{a!==void 0&&(t||!h(a))&&(l(n.concat(a)),p())},p=()=>{i("")},v=()=>{if(!t){const m=[];for(const b of e)h(b.key)||m.push(b);d(m)}};return g.jsxs("div",{children:[n.map((m,b)=>g.jsxs("div",{className:"daga-value-item-element",children:[g.jsx("span",{className:"daga-input",children:s[b]}),!o&&g.jsx("button",{className:"daga-property-button",onClick:()=>u(b),children:g.jsx("div",{className:"daga-icon daga-close-icon"})})]},b)),!o&&g.jsxs("div",{className:"daga-value-item-input",children:[g.jsx("div",{className:"daga-input daga-relatively-positioned",children:g.jsx(qe,{disabled:o,options:t?e||[]:c||[],value:a,onChange:i})}),g.jsx("button",{className:"daga-property-button",onClick:y,children:g.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},mo=({disabled:o,allowRepeats:t,value:e,onChange:n})=>{const[l,a]=L.useState(""),i=u=>{for(const y of u||[])if(y===u)return!0;return!1},s=u=>{e.length>u&&n(e.filter((y,p)=>p!==u))},r=(u,y,p)=>{const v=e.map((m,b)=>b===y?p==="blur"?u.trim():u:m);n(v)},c=()=>{const u=l.trim();u!==""&&(t||!i(u))&&(n(e.concat(u)),d())},d=()=>{a("")},h=u=>{u.key==="Enter"&&c()};return g.jsxs(g.Fragment,{children:[e.map((u,y)=>g.jsxs("div",{className:"daga-value-item-element",children:[g.jsx("input",{className:"daga-input",disabled:o,value:u,onChange:p=>r(p.target.value,y,"change"),onBlur:p=>r(p.target.value,y,"blur")}),g.jsx("button",{className:"daga-property-button",onClick:()=>s(y),children:g.jsx("div",{className:"daga-icon daga-close-icon"})})]},y)),!o&&g.jsxs("div",{className:"daga-value-item-input",children:[g.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[g.jsx("input",{type:"text",onKeyUp:h,value:l,onChange:u=>a(u.target.value)}),g.jsx("button",{className:"daga-clear",onClick:d})]}),g.jsx("button",{className:"daga-property-button",onClick:c,children:g.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},po=({disabled:o,value:t,onChange:e})=>{const[n,l]=L.useState(""),[a,i]=L.useState(""),[s,r]=L.useState({}),c=m=>{const b={};Object.keys(t).forEach(w=>{w!==m&&(b[w]=t[w])}),e(b)},d=(m,b,w)=>{const M=w==="blur"?b.trim():b;if(w==="blur"){if(m!==M){const R={};Object.keys(t).forEach(P=>{P===m?R[M]=t[P]:R[P]=t[P]}),e(R),r(P=>{const q={...P};return delete q[m],q})}}else r(R=>({...R,[m]:b}))},h=(m,b,w)=>{const M=w==="blur"?b.trim():b;if(M!==""){const R={};Object.keys(t).forEach(P=>{P===m?R[P]=M:R[P]=t[P]}),e(R)}},u=()=>{const m=n.trim(),b=a.trim();if(m!==""&&b!==""){const w={};Object.keys(t).forEach(M=>{w[M]=t[M]}),w[m]=b,e(w),l(""),i("")}},y=()=>{l("")},p=()=>{i("")},v=m=>{m.key==="Enter"&&u()};return g.jsxs("div",{children:[Object.entries(t).map(([m,b],w)=>g.jsxs("div",{className:"daga-value-item-element",children:[g.jsx("input",{id:`key-${w}`,className:"daga-input",type:"text",disabled:o,value:s[m]??m,onChange:M=>d(m,M.target.value,"change"),onBlur:M=>d(m,M.target.value,"blur")}),g.jsx("input",{id:`value-${w}`,className:"daga-input",type:"text",disabled:o,value:b,onChange:M=>h(m,M.target.value,"change"),onBlur:M=>h(m,M.target.value,"blur")}),g.jsx("button",{className:"daga-property-button",onClick:()=>c(m),children:g.jsx("div",{className:"daga-icon daga-close-icon"})})]},m)),!o&&g.jsxs("div",{className:"daga-value-item-input",children:[g.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[g.jsx("input",{type:"text",value:n,onKeyUp:v,onChange:m=>l(m.target.value),onBlur:m=>d(n,m.target.value,"blur")}),g.jsx("button",{className:"daga-clear",onClick:y})]}),g.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[g.jsx("input",{type:"text",value:a,onKeyUp:v,onChange:m=>i(m.target.value),onBlur:m=>h(n,m.target.value,"blur")}),g.jsx("button",{className:"daga-clear",onClick:p})]}),g.jsx("button",{className:"daga-property-button",onClick:u,children:g.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Je=({valueSet:o,onValueChange:t,depth:e})=>{const l=L.useContext(St).canUserPerformAction(k.UpdateValues)&&o?.rootElement?.removed!==!0,a=r=>"daga-property-name-"+r.replace(/\s/g,""),i=r=>{if(typeof r=="string")return r;if(r==null||isNaN(r.valueOf()))return"";const c=new Date(r),d=c.getTimezoneOffset();return c.setMinutes(c.getMinutes()-d),c.toISOString().substring(0,19)},s=r=>new Date(r);return g.jsx("daga-object-editor",{children:o.displayedProperties.map(r=>g.jsxs("div",{className:`daga-property ${a(r.name)}`,children:[g.jsx("p",{className:"daga-property-name",children:r.label||r.name}),r.type===N.Text&&g.jsx("input",{type:"daga-text",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.TextArea&&g.jsx("textarea",{disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Number&&g.jsx("input",{type:"number",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Color&&g.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Datetime&&g.jsx("input",{type:"datetime-local",disabled:r.editable===!1||!l,value:i(o?.getValue(r.name)),onChange:c=>t(o,r,s(c.target.value))}),r.type===N.Date&&g.jsx("input",{type:"date",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Time&&g.jsx("input",{type:"time",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Url&&g.jsx("input",{type:"url",disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c.target.value)}),r.type===N.Boolean&&g.jsxs("div",{className:"daga-radio",children:[g.jsxs("label",{className:"daga-radio-item daga-radio-start"+(o?.getValue(r.name)===!1?" daga-checked":""),children:[g.jsx("input",{type:"radio",disabled:r.editable===!1||!l,name:r.name,value:"false",checked:o?.getValue(r.name)===!1,onChange:()=>t(o,r,!1)}),"No"]}),g.jsxs("label",{className:"daga-radio-item daga-radio-end"+(o?.getValue(r.name)===!0?" daga-checked":""),children:[g.jsx("input",{type:"radio",disabled:r.editable===!1||!l,name:r.name,value:"true",checked:o?.getValue(r.name)===!0,onChange:()=>t(o,r,!0)}),"Yes"]})]}),r.type===N.Option&&g.jsx("div",{className:"daga-relatively-positioned",children:g.jsx(qe,{disabled:r.editable===!1||!l,options:r.options||[],value:o?.getValue(r.name),onChange:c=>t(o,r,c)})}),(r.type===N.OptionList||r.type===N.OptionSet)&&g.jsx(fo,{disabled:r.editable===!1||!l,allowRepeats:r.type===N.OptionList,options:r.options||[],value:o?.getValue(r.name),onChange:c=>t(o,r,c)}),(r.type===N.TextList||r.type===N.TextSet)&&g.jsx(mo,{disabled:r.editable===!1||!l,allowRepeats:r.type===N.TextList,value:o?.getValue(r.name),onChange:c=>t(o,r,c)}),r.type===N.TextMap&&g.jsx(po,{disabled:r.editable===!1||!l,value:o?.getValue(r.name),onChange:c=>t(o,r,c)}),r.type===N.Object&&g.jsx("div",{className:"daga-left-bar",children:g.jsx(Je,{valueSet:o.getSubValueSet(r.name),onValueChange:t,depth:e+1})})]},r.name))})},Qe=({valueSet:o,depth:t})=>{const e=L.useContext(St),n=L.useRef(null),l=r=>"daga-property-name-"+r.replace(/\s/g,""),a=()=>{for(const r of o?.displayedProperties||[]){let c=0,d=0,h=0;const u=E.select(n.current).select(`.daga-property.${l(r.name)}.daga-depth-${t}`);u.select("button.daga-move-button").call(E.drag().on(I.Start,y=>{S(T.Grabbing);const p=e.getPointerLocationRelativeToScreen(y);if(p.length<2||isNaN(p[0])||isNaN(p[1]))return;const v=u.node()?.getBoundingClientRect();c=v?.width||0,d=v?.height||0,u.style("position","fixed").style("left",`${p[0]-c/2}px`).style("top",`${p[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1)}).on(I.Drag,y=>{S(T.Grabbing);const p=e.getPointerLocationRelativeToScreen(y);p.length<2||isNaN(p[0])||isNaN(p[1])||(u.style("position","fixed").style("left",`${p[0]-c/2}px`).style("top",`${p[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1),E.select(n.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0),h=i(p),E.select(n.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on(I.End,y=>{S(T.Auto),u.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),E.select(n.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const p=e.getPointerLocationRelativeToScreen(y);p.length<2||isNaN(p[0])||isNaN(p[1])||(h=i(p),o?.displayedProperties?.splice(o.displayedProperties.indexOf(r),1),o?.displayedProperties?.splice(h,0,r))}))}},i=r=>{const c=o?.propertySet.propertyList||[],d=[];for(let h=0;h<=c.length;++h){const u=E.select(n.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).node()?.getBoundingClientRect();u&&d.push([u.x+u.width/2,u.y+u.height/2])}if(d.length>0){const h=d.map(y=>((r[0]-y[0])**2+(r[1]-y[1])**2)**.5);return h.indexOf(Math.min(...h))}return 0},s=r=>{if(o===void 0)return;let c;r instanceof yi?c=r:r instanceof Event?c=o?.propertySet.getProperty(r.target?.value||""):c=o?.propertySet.getProperty(r||""),c&&o?.hideProperty(c),a()};return g.jsxs("daga-property-settings",{ref:n,children:[g.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),o?.displayedProperties.map((r,c)=>g.jsxs("div",{className:`daga-property-and-dropbar ${l(r.name)} daga-depth-${t}`,children:[g.jsxs("div",{className:`daga-property ${l(r.name)} daga-depth-${t}`,children:[g.jsxs("div",{className:"daga-property-name",children:[g.jsx("span",{children:r.label||r.name}),g.jsxs("div",{className:"daga-buttons",children:[g.jsx("button",{className:"daga-property-button daga-move-button",children:g.jsx("div",{className:"daga-icon daga-move-icon"})}),g.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>s(r.name),children:g.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),r.type!==N.Object&&g.jsx("div",{className:"daga-property-value",children:vo(o?.getValue(r.name))}),r.type===N.Object&&g.jsx(Qe,{valueSet:o?.getSubValueSet(r.name),depth:t+1})]}),g.jsx("div",{className:`daga-dropbar daga-index-${c+1} daga-depth-${t}`})]},r.name))]})},vo=o=>Array.isArray(o)?o.join(", "):bi(o)?Object.entries(o).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):o instanceof Date?o.toLocaleString():o==null?"":""+o,yo=({location:o,direction:t,width:e,height:n,title:l,valueSet:a,onValueChange:i})=>{const s=L.useRef(null),[r,c]=L.useState(!1),[d,h]=L.useState(!1),u=()=>E.select(s.current);return L.useEffect(()=>{if(s.current)switch(t){case f.Bottom:case f.Top:u().style("width",e),n&&u().select(".daga-panel-content").style("height",n);break;case f.Left:case f.Right:u().style("height",e),n&&u().select(".daga-panel-content").style("width",n);break}},[e,t]),g.jsx("daga-property-editor",{children:g.jsxs("div",{ref:s,className:`daga-panel daga-bottom daga-${o} daga-${t}`,children:[g.jsx(ye,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:r,direction:t,collapsableSelector:s,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:c}),g.jsx("div",{className:"daga-panel-content",children:a&&a.propertySet&&a.propertySet.hasProperties()&&!r&&g.jsxs("div",{children:[l&&g.jsxs("p",{className:"daga-title",children:[l,g.jsx("button",{className:"daga-property-button",onClick:()=>h(!d),children:g.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&g.jsx(Je,{valueSet:a,onValueChange:i,depth:0}),d&&g.jsx(Qe,{valueSet:a,depth:0})]})})]})})},bo=6,ko=o=>{const t=L.useContext(St),[e,n]=L.useState(o.currentPalette||o.palettes[0]),[l,a]=L.useState(0),[i,s]=L.useState(void 0),r=L.useRef(null),c=v=>{if(n(v),d().selectAll("*").remove(),a(t.getPriorityThreshold()||0),v.categories&&h(v.categories),v.templates)for(const m of v.templates)u(m)},d=()=>E.select(r.current).select(".daga-palette-view"),h=v=>{const m=d().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");m.append("option").attr("value","").text("(None selected)");for(const b in v)m.append("option").attr("value",b).text(b);m.on(C.Change,()=>{i&&d().selectAll(".daga-template-container.daga-in-category").remove();const b=m.property("value");s(b);const w=v[b]||[];for(const M of w)u(M,"daga-in-category")}),i&&(m.property("value",i),m.dispatch(C.Change))},u=(v,m)=>{if(v.templateType==="node"){const b=t.model.nodes.types.get(v.type);b?y(b,v,m):console.error(`Could not find a node type called '${v.type}'`)}else if(v.templateType==="connection"){const b=t.model.connections.types.get(v.type);b?p(b,v,m):console.error(`Could not find a connection type called '${v.type}'`)}},y=(v,m,b)=>{if(l!==void 0&&v.priority<l)return;const w=v.defaultLook.lookType==="shaped-look"?v.defaultLook.borderThickness||1:0,M=v.defaultHeight+w,R=v.defaultWidth+w,P=m.height||M,q=m.width||R,$=d().append("div").attr("class",`daga-template-container ${b!==void 0?b:""}`).style("width",`${q}px`).style("height",`${P}px`).call(E.drag().on(I.Drag,V=>{if(t.canUserPerformAction(k.AddNode)){const A=t.getPointerLocationRelativeToScreen(V);if(A.length<2||isNaN(A[0])||isNaN(A[1]))return;$.style("position","fixed").style("left",`${A[0]-q/2}px`).style("top",`${A[1]-P/2}px`).style("z-index",1)}}).on(I.Start,V=>{if(t.canUserPerformAction(k.AddNode)){S(T.Grabbing);const A=t.getPointerLocationRelativeToScreen(V);if(A.length<2||isNaN(A[0])||isNaN(A[1]))return;$.style("position","fixed").style("left",`${A[0]-q/2}px`).style("top",`${A[1]-P/2}px`).style("z-index",1),v.isUnique&&t.model.nodes.find(j=>!j.removed&&j.type.id===v.id)!==void 0&&S(T.NotAllowed)}}).on(I.End,V=>{if(t.canUserPerformAction(k.AddNode)){if(S(T.Auto),$.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),v.isUnique&&t.model.nodes.find(Ft=>!Ft.removed&&Ft.type.id===v.id)!==void 0)return;const A=t.getPointerLocationRelativeToScreen(V);if(A.length<2||isNaN(A[0])||isNaN(A[1]))return;const j=document.elementFromPoint(A[0],A[1]);if(j&&!t.selectCanvasView().node()?.contains(j))return;const rt=t.getPointerLocationRelativeToCanvas(V);if(rt.length<2||isNaN(rt[0])||isNaN(rt[1]))return;let ot=[rt[0]-v.defaultWidth/2,rt[1]-v.defaultHeight/2];t.snapToGrid&&(ot=t.getClosestGridPoint(ot));const Z=t.model.nodes.getAtCoordinates(rt[0],rt[1]).filter(Ft=>Ft.type.childrenTypes.includes(v.id)),bt=je(Z),it=bt[bt.length-1];if(!v.canBeParentless&&it===void 0)return;const Dt=it?.getLastAncestor(),be=new Oi(t,v,ot,it?.id,Dt?.id,Dt?.getGeometry(),void 0,m.label,m.values);be.do(),t?.actionStack.add(be),S()}})).append("svg").attr("class",`palette-node ${v.id}`).attr("viewBox",`0 0 ${R} ${M}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${q}px`).style("height",`${P}px`),x=m.look||v.defaultLook;switch(x.lookType){case"shaped-look":$.append("path").attr("d",he(x.shape||Lt.Rectangle,(x.borderThickness||1)/2,(x.borderThickness||1)/2,v.defaultWidth,v.defaultHeight)).attr("fill",x.fillColor||"#FFFFFF").attr("stroke",x.borderColor||"#000000").attr("stroke-width",`${x.borderThickness}px`);break;case"image-look":$.append("image").attr("x",0).attr("y",0).attr("width",v.defaultWidth).attr("height",v.defaultHeight).attr("href",x.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":$.append("image").attr("x",0).attr("y",0).attr("width",x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",0).attr("width",v.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTop).attr("preserveAspectRatio","none"),$.append("image").attr("x",v.defaultWidth-x.rightMargin).attr("y",0).attr("width",x.rightMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopRight).attr("preserveAspectRatio","none"),$.append("image").attr("x",0).attr("y",x.topMargin).attr("width",x.leftMargin).attr("height",v.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",x.topMargin).attr("width",v.defaultWidth-x.rightMargin-x.leftMargin).attr("height",v.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageCenter).attr("preserveAspectRatio","none"),$.append("image").attr("x",v.defaultWidth-x.rightMargin).attr("y",x.topMargin).attr("width",x.rightMargin).attr("height",v.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageRight).attr("preserveAspectRatio","none"),$.append("image").attr("x",0).attr("y",v.defaultHeight-x.bottomMargin).attr("width",x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),$.append("image").attr("x",x.leftMargin).attr("y",v.defaultHeight-x.bottomMargin).attr("width",v.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottom).attr("preserveAspectRatio","none"),$.append("image").attr("x",v.defaultWidth-x.rightMargin).attr("y",v.defaultHeight-x.bottomMargin).attr("width",x.rightMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(m.look===void 0){if(v.decorators)for(const V of v.decorators)$.append("foreignObject").attr("width",`${V.width}px`).attr("height",`${V.height}px`).attr("transform",`translate(${V.coords[0]},${V.coords[1]})`).html(V.html);if(m.label){const V={...O,...v.label,...m.labelLook};$.append("text").attr("transform",`translate(${(Y(V)+v.defaultWidth)/2},${(H(V)+v.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${V.fontSize}px`).attr("text-anchor","middle").attr("font-family",V.fontFamily).attr("font-weight",400).attr("fill",V.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(m.label)}}},p=(v,m,b)=>{const w=d().append("div").attr("class",`daga-template-container ${b!==void 0?b:""}`).style("width",`${m.width}px`).style("height",`${m.height}px`).append("svg").attr("class",`palette-button ${v.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=v});w.append("path").attr("d",he(Lt.Rectangle,0,0,m.width,m.height)).attr("fill",m.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),m.icon!==""&&w.append("image").attr("x",0).attr("y",0).attr("width",m.width).attr("height",m.height).attr("href",m.icon),m.label!==""&&w.append("text").attr("transform",`translate(${m.width/2},${m.height/2+bo})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(m.label)};return L.useEffect(()=>{if(c(o.palettes[0]),r.current)switch(o.direction){case f.Bottom:case f.Top:r.current.style.width=o.width,o.height&&(r.current.style.height=o.height);break;case f.Left:case f.Right:r.current.style.height=o.width,o.height&&(r.current.style.width=o.height);break}},[e,o.palettes]),g.jsx("daga-palette",{children:g.jsxs("div",{ref:r,className:`daga-panel daga-${o.location} daga-${o.direction}`,children:[g.jsx(ye,{direction:o.direction,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),g.jsxs("div",{className:"daga-panel-content",children:[o.palettes.length>1&&g.jsx("div",{className:"daga-panel-tabs",children:o.palettes.map(v=>g.jsx("div",{className:`daga-panel-tab ${v===e?"daga-current-tab":""}`,onClick:()=>c(v),children:v.name}))}),g.jsx("div",{className:"daga-palette-view"})]})]})})},wo=({location:o,direction:t,enableAction:e,enableFilter:n,enableLayout:l,enableSelection:a,enableZoom:i})=>{let s=!1,r=!0,c=!1,d,h,u,y;switch(t){case f.Bottom:d="height",h="scaleY",u="top",y="bottom";break;case f.Top:d="height",h="scaleY",u="bottom",y="top";break;case f.Left:d="width",h="scaleX",u="right",y="left";break;case f.Right:d="width",h="scaleX",u="left",y="right";break}const p=L.useRef(null),v=L.useRef(null),m=L.useRef(null);L.useEffect(()=>{E.select(p.current).style(`margin-${y}`,"-1rem").style(d,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const b=async()=>{const Z=E.select(p.current);if(!c)if(r){r=!1;const Dt=`${4*Z.selectChildren().size()}rem`;Z.transition().duration(500).ease(E.easeLinear).style(d,Dt).style("transform",`${h}(1)`),setTimeout(()=>{c=!1},500)}else r=!0,Z.transition().duration(500).ease(E.easeLinear).style(d,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{c=!1},500)},w=L.useContext(St),M=()=>{w.zoomBy(w.zoomFactor)},R=()=>{w.zoomBy(1/w.zoomFactor)},P=()=>{w.center()},q=()=>{w.layoutFormat&&w.layoutFormat in $e&&$e[w.layoutFormat].apply(w.model)},$=()=>{s=!s,E.select(m.current).classed("daga-on",s).classed("daga-off",!s);const Z=w.getPriorityThresholdOptions();Z&&Z.length>=2&&w.setPriorityThreshold(Z[s?1:0])},x=()=>{w.actionStack.undo()},V=()=>{w.actionStack.redo()},A=()=>{w.userSelection.copyToClipboard()},j=()=>{w.userSelection.cutToClipboard()},rt=()=>{w.userSelection.pasteFromClipboard()},ot=()=>{w.userSelection.removeFromModel()},jt=()=>{w.multipleSelectionOn=!0,E.select(v.current).classed("daga-on",!0).classed("daga-off",!1);const Z=w.diagramEvent$.subscribe(bt=>{bt.type===Be.Selection&&(E.select(v.current).classed("daga-on",!1).classed("daga-off",!0),Z.unsubscribe())})};return g.jsx("daga-diagram-buttons",{children:g.jsxs("div",{className:`daga-diagram-buttons daga-${o} daga-${t}`,children:[i&&w.canUserPerformAction(k.Zoom)&&g.jsx("button",{className:"daga-zoom-in",onClick:M,children:g.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&w.canUserPerformAction(k.Zoom)&&g.jsx("button",{className:"daga-zoom-out",onClick:R,children:g.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),g.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:p,children:[i&&w.canUserPerformAction(k.Zoom)&&g.jsx("button",{className:"daga-center",onClick:P,children:g.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&g.jsx("button",{className:"daga-undo",onClick:x,children:g.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&g.jsx("button",{className:"daga-redo",onClick:V,children:g.jsx("span",{className:"daga-tooltip",children:"Redo"})}),a&&g.jsx("button",{className:"daga-copy",onClick:A,children:g.jsx("span",{className:"daga-tooltip",children:"Copy"})}),a&&g.jsx("button",{className:"daga-cut",onClick:j,children:g.jsx("span",{className:"daga-tooltip",children:"Cut"})}),a&&g.jsx("button",{className:`daga-multiple-selection ${s?"daga-on":"daga-off"}`,onClick:jt,ref:v,children:g.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),a&&g.jsx("button",{className:"daga-paste",onClick:rt,children:g.jsx("span",{className:"daga-tooltip",children:"Paste"})}),a&&g.jsx("button",{className:"daga-delete",onClick:ot,children:g.jsx("span",{className:"daga-tooltip",children:"Delete"})}),l&&w.layoutFormat&&g.jsx("button",{className:"daga-layout",onClick:q,children:g.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),n&&g.jsx("button",{className:`daga-filter ${s?"daga-on":"daga-off"}`,onClick:$,ref:m,children:g.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),g.jsx("button",{className:"daga-more-options",onClick:b,children:r?g.jsx("span",{className:"daga-tooltip",children:"More options"}):g.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},So=({config:o,model:t,onCanvasCreated:e,onDiagramEvent:n,onModelChange:l})=>{const a=new He,i=new Ye,s=L.useRef(null),r=L.useRef(void 0),c=L.useRef(!1),d=[],[h,u]=L.useState(void 0),[y,p]=L.useState(void 0),v={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},m={refreshPalette:()=>{}},b=new co($=>u($),$=>p($)),w={diagramButtons:v,palette:m,propertyEditor:b},M=($=!1)=>((!r.current||$)&&(d.forEach(x=>x.unsubscribe()),r.current=new ue(w,o)),r.current),R=M(),P=$=>{R.initView($),d.push(R.diagramEvent$.subscribe(x=>{n?.(x)})),d.push(R.diagramChange$.subscribe(()=>{const x=i.export(R.model);l?.(x)}))};L.useEffect(()=>{s.current&&(c.current||(P(s.current),c.current=!0,e?.(R)))},[s.current]),L.useMemo(()=>{s.current&&(M(!0),P(s.current),e?.(R))},[o]),L.useEffect(()=>{t&&a.import(R.model,t)},[t]);const q=($,x,V)=>{if(y!==void 0&&x.editable!==!1&&!wt($.getValue(x.name),V)){$.setValue(x.name,V);const A=new pt(y.propertySet,void 0);A.setValues(y.getValues()),A.rootElement=y.rootElement,b.valueSet=A,y.rootElement.valueSet=A,R.propertyEditorChanges$?.next()}};return g.jsx("daga-diagram",{children:g.jsx(lo.Provider,{value:o,children:g.jsx(St.Provider,{value:R,children:g.jsxs("daga-diagram-editor",{children:[g.jsx("div",{className:"daga-append-to",ref:s}),g.jsxs(St.Provider,{value:R,children:[o.components?.buttons!==void 0&&o.components?.buttons?.enabled!==!1&&g.jsx(wo,{location:o.components?.buttons?.location||Bt.BottomRight,direction:o.components?.buttons?.direction||f.Top,enableAction:o.components?.buttons?.enableAction!==!1,enableFilter:o.components?.buttons?.enableFilter===!0,enableLayout:o.components?.buttons?.enableLayout===!0,enableSelection:o.components?.buttons?.enableSelection!==!1,enableZoom:o.components?.buttons?.enableZoom!==!1}),o.components?.palette!==void 0&&o.components?.palette?.enabled!==!1&&o.components?.palette?.sections&&(o.components?.palette?.sections?.length||0)>0&&g.jsx(ko,{location:o.components?.palette?.location||Bt.TopLeft,direction:o.components?.palette?.direction||f.Bottom,width:o.components?.palette?.width||"12rem",height:o.components?.palette?.height,palettes:o.components?.palette?.sections||[]}),o.components?.propertyEditor!==void 0&&o.components?.propertyEditor?.enabled!==!1&&g.jsx(yo,{location:o.components?.propertyEditor?.location||Bt.TopRight,direction:o.components?.propertyEditor?.direction||f.Bottom,width:o.components?.propertyEditor?.width||"24rem",height:o.components?.propertyEditor?.height,title:h,valueSet:y,onValueChange:q}),o.components?.errors!==void 0&&o.components?.errors?.enabled!==!1&&g.jsx(ho,{})]})]})})})})};exports.DagaDiagram=So;
|