@metadev/daga-react 0.0.1
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 +212 -0
- package/LICENSE.md +13 -0
- package/README.md +67 -0
- package/index.d.ts +16 -0
- package/index.js +4 -0
- package/index.mjs +9977 -0
- package/lib/collapse-button/CollapseButtonComponent.d.ts +16 -0
- package/lib/contexts/CanvasContext.d.ts +4 -0
- package/lib/contexts/ConfigContext.d.ts +4 -0
- package/lib/daga-react.d.ts +2 -0
- package/lib/diagram/DagaDiagram.d.ts +12 -0
- package/lib/diagram-buttons/DiagramButtonsComponent.d.ts +14 -0
- package/lib/errors/DagaErrorsComponent.d.ts +4 -0
- package/lib/models/ReactPropertyEditor.d.ts +14 -0
- package/lib/palette/PaletteComponent.d.ts +13 -0
- package/lib/property-editor/PropertyEditor.d.ts +12 -0
- package/lib/property-editor/object-editor/DagaObjectEditorComponent.d.ts +8 -0
- package/lib/property-editor/property-settings/DagaPropertySettingsComponent.d.ts +8 -0
- package/package.json +38 -0
- package/style.css +1 -0
package/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("react/jsx-runtime"),B=require("react");var x=(n=>(n.Bottom="bottom",n.Left="left",n.Right="right",n.Top="top",n))(x||{}),Re=(n=>(n.BottomLeft="bottom-left",n.BottomRight="bottom-right",n.TopLeft="top-left",n.TopRight="top-right",n))(Re||{}),Kt=(n=>(n.Left="left",n.Center="center",n.Right="right",n))(Kt||{}),Be=(n=>(n.Top="top",n.Center="center",n.Bottom="bottom",n))(Be||{}),br={value:()=>{}};function tn(){for(var n=0,t=arguments.length,e={},o;n<t;++n){if(!(o=arguments[n]+"")||o in e||/[\s.]/.test(o))throw new Error("illegal type: "+o);e[o]=[]}return new ze(e)}function ze(n){this._=n}function wr(n,t){return n.trim().split(/^|\s+/).map(function(e){var o="",s=e.indexOf(".");if(s>=0&&(o=e.slice(s+1),e=e.slice(0,s)),e&&!t.hasOwnProperty(e))throw new Error("unknown type: "+e);return{type:e,name:o}})}ze.prototype=tn.prototype={constructor:ze,on:function(n,t){var e=this._,o=wr(n+"",e),s,a=-1,i=o.length;if(arguments.length<2){for(;++a<i;)if((s=(n=o[a]).type)&&(s=xr(e[s],n.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++a<i;)if(s=(n=o[a]).type)e[s]=Ii(e[s],n.name,t);else if(t==null)for(s in e)e[s]=Ii(e[s],n.name,null);return this},copy:function(){var n={},t=this._;for(var e in t)n[e]=t[e].slice();return new ze(n)},call:function(n,t){if((s=arguments.length-2)>0)for(var e=new Array(s),o=0,s,a;o<s;++o)e[o]=arguments[o+2];if(!this._.hasOwnProperty(n))throw new Error("unknown type: "+n);for(a=this._[n],o=0,s=a.length;o<s;++o)a[o].value.apply(t,e)},apply:function(n,t,e){if(!this._.hasOwnProperty(n))throw new Error("unknown type: "+n);for(var o=this._[n],s=0,a=o.length;s<a;++s)o[s].value.apply(t,e)}};function xr(n,t){for(var e=0,o=n.length,s;e<o;++e)if((s=n[e]).name===t)return s.value}function Ii(n,t,e){for(var o=0,s=n.length;o<s;++o)if(n[o].name===t){n[o]=br,n=n.slice(0,o).concat(n.slice(o+1));break}return e!=null&&n.push({name:t,value:e}),n}var En="http://www.w3.org/1999/xhtml";const Ti={svg:"http://www.w3.org/2000/svg",xhtml:En,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function en(n){var t=n+="",e=t.indexOf(":");return e>=0&&(t=n.slice(0,e))!=="xmlns"&&(n=n.slice(e+1)),Ti.hasOwnProperty(t)?{space:Ti[t],local:n}:n}function Cr(n){return function(){var t=this.ownerDocument,e=this.namespaceURI;return e===En&&t.documentElement.namespaceURI===En?t.createElement(n):t.createElementNS(e,n)}}function kr(n){return function(){return this.ownerDocument.createElementNS(n.space,n.local)}}function ro(n){var t=en(n);return(t.local?kr:Cr)(t)}function Sr(){}function jn(n){return n==null?Sr:function(){return this.querySelector(n)}}function Ar(n){typeof n!="function"&&(n=jn(n));for(var t=this._groups,e=t.length,o=new Array(e),s=0;s<e;++s)for(var a=t[s],i=a.length,r=o[s]=new Array(i),l,c,h=0;h<i;++h)(l=a[h])&&(c=n.call(l,l.__data__,h,a))&&("__data__"in l&&(c.__data__=l.__data__),r[h]=c);return new ft(o,this._parents)}function Ir(n){return n==null?[]:Array.isArray(n)?n:Array.from(n)}function Tr(){return[]}function so(n){return n==null?Tr:function(){return this.querySelectorAll(n)}}function Er(n){return function(){return Ir(n.apply(this,arguments))}}function $r(n){typeof n=="function"?n=Er(n):n=so(n);for(var t=this._groups,e=t.length,o=[],s=[],a=0;a<e;++a)for(var i=t[a],r=i.length,l,c=0;c<r;++c)(l=i[c])&&(o.push(n.call(l,l.__data__,c,i)),s.push(l));return new ft(o,s)}function ao(n){return function(){return this.matches(n)}}function lo(n){return function(t){return t.matches(n)}}var Mr=Array.prototype.find;function _r(n){return function(){return Mr.call(this.children,n)}}function Nr(){return this.firstElementChild}function Pr(n){return this.select(n==null?Nr:_r(typeof n=="function"?n:lo(n)))}var Rr=Array.prototype.filter;function zr(){return Array.from(this.children)}function Lr(n){return function(){return Rr.call(this.children,n)}}function Vr(n){return this.selectAll(n==null?zr:Lr(typeof n=="function"?n:lo(n)))}function Dr(n){typeof n!="function"&&(n=ao(n));for(var t=this._groups,e=t.length,o=new Array(e),s=0;s<e;++s)for(var a=t[s],i=a.length,r=o[s]=[],l,c=0;c<i;++c)(l=a[c])&&n.call(l,l.__data__,c,a)&&r.push(l);return new ft(o,this._parents)}function co(n){return new Array(n.length)}function Fr(){return new ft(this._enter||this._groups.map(co),this._parents)}function Ge(n,t){this.ownerDocument=n.ownerDocument,this.namespaceURI=n.namespaceURI,this._next=null,this._parent=n,this.__data__=t}Ge.prototype={constructor:Ge,appendChild:function(n){return this._parent.insertBefore(n,this._next)},insertBefore:function(n,t){return this._parent.insertBefore(n,t)},querySelector:function(n){return this._parent.querySelector(n)},querySelectorAll:function(n){return this._parent.querySelectorAll(n)}};function Or(n){return function(){return n}}function Br(n,t,e,o,s,a){for(var i=0,r,l=t.length,c=a.length;i<c;++i)(r=t[i])?(r.__data__=a[i],o[i]=r):e[i]=new Ge(n,a[i]);for(;i<l;++i)(r=t[i])&&(s[i]=r)}function Gr(n,t,e,o,s,a,i){var r,l,c=new Map,h=t.length,f=a.length,u=new Array(h),p;for(r=0;r<h;++r)(l=t[r])&&(u[r]=p=i.call(l,l.__data__,r,t)+"",c.has(p)?s[r]=l:c.set(p,l));for(r=0;r<f;++r)p=i.call(n,a[r],r,a)+"",(l=c.get(p))?(o[r]=l,l.__data__=a[r],c.delete(p)):e[r]=new Ge(n,a[r]);for(r=0;r<h;++r)(l=t[r])&&c.get(u[r])===l&&(s[r]=l)}function Ur(n){return n.__data__}function jr(n,t){if(!arguments.length)return Array.from(this,Ur);var e=t?Gr:Br,o=this._parents,s=this._groups;typeof n!="function"&&(n=Or(n));for(var a=s.length,i=new Array(a),r=new Array(a),l=new Array(a),c=0;c<a;++c){var h=o[c],f=s[c],u=f.length,p=Hr(n.call(h,h&&h.__data__,c,o)),g=p.length,d=r[c]=new Array(g),m=i[c]=new Array(g),v=l[c]=new Array(u);e(h,f,d,m,v,p,t);for(var w=0,C=0,y,k;w<g;++w)if(y=d[w]){for(w>=C&&(C=w+1);!(k=m[C])&&++C<g;);y._next=k||null}}return i=new ft(i,o),i._enter=r,i._exit=l,i}function Hr(n){return typeof n=="object"&&"length"in n?n:Array.from(n)}function Xr(){return new ft(this._exit||this._groups.map(co),this._parents)}function Yr(n,t,e){var o=this.enter(),s=this,a=this.exit();return typeof n=="function"?(o=n(o),o&&(o=o.selection())):o=o.append(n+""),t!=null&&(s=t(s),s&&(s=s.selection())),e==null?a.remove():e(a),o&&s?o.merge(s).order():s}function Wr(n){for(var t=n.selection?n.selection():n,e=this._groups,o=t._groups,s=e.length,a=o.length,i=Math.min(s,a),r=new Array(s),l=0;l<i;++l)for(var c=e[l],h=o[l],f=c.length,u=r[l]=new Array(f),p,g=0;g<f;++g)(p=c[g]||h[g])&&(u[g]=p);for(;l<s;++l)r[l]=e[l];return new ft(r,this._parents)}function qr(){for(var n=this._groups,t=-1,e=n.length;++t<e;)for(var o=n[t],s=o.length-1,a=o[s],i;--s>=0;)(i=o[s])&&(a&&i.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(i,a),a=i);return this}function Kr(n){n||(n=Zr);function t(f,u){return f&&u?n(f.__data__,u.__data__):!f-!u}for(var e=this._groups,o=e.length,s=new Array(o),a=0;a<o;++a){for(var i=e[a],r=i.length,l=s[a]=new Array(r),c,h=0;h<r;++h)(c=i[h])&&(l[h]=c);l.sort(t)}return new ft(s,this._parents).order()}function Zr(n,t){return n<t?-1:n>t?1:n>=t?0:NaN}function Qr(){var n=arguments[0];return arguments[0]=this,n.apply(null,arguments),this}function Jr(){return Array.from(this)}function ts(){for(var n=this._groups,t=0,e=n.length;t<e;++t)for(var o=n[t],s=0,a=o.length;s<a;++s){var i=o[s];if(i)return i}return null}function es(){let n=0;for(const t of this)++n;return n}function ns(){return!this.node()}function is(n){for(var t=this._groups,e=0,o=t.length;e<o;++e)for(var s=t[e],a=0,i=s.length,r;a<i;++a)(r=s[a])&&n.call(r,r.__data__,a,s);return this}function os(n){return function(){this.removeAttribute(n)}}function rs(n){return function(){this.removeAttributeNS(n.space,n.local)}}function ss(n,t){return function(){this.setAttribute(n,t)}}function as(n,t){return function(){this.setAttributeNS(n.space,n.local,t)}}function ls(n,t){return function(){var e=t.apply(this,arguments);e==null?this.removeAttribute(n):this.setAttribute(n,e)}}function cs(n,t){return function(){var e=t.apply(this,arguments);e==null?this.removeAttributeNS(n.space,n.local):this.setAttributeNS(n.space,n.local,e)}}function hs(n,t){var e=en(n);if(arguments.length<2){var o=this.node();return e.local?o.getAttributeNS(e.space,e.local):o.getAttribute(e)}return this.each((t==null?e.local?rs:os:typeof t=="function"?e.local?cs:ls:e.local?as:ss)(e,t))}function ho(n){return n.ownerDocument&&n.ownerDocument.defaultView||n.document&&n||n.defaultView}function ds(n){return function(){this.style.removeProperty(n)}}function us(n,t,e){return function(){this.style.setProperty(n,t,e)}}function fs(n,t,e){return function(){var o=t.apply(this,arguments);o==null?this.style.removeProperty(n):this.style.setProperty(n,o,e)}}function ps(n,t,e){return arguments.length>1?this.each((t==null?ds:typeof t=="function"?fs:us)(n,t,e??"")):ne(this.node(),n)}function ne(n,t){return n.style.getPropertyValue(t)||ho(n).getComputedStyle(n,null).getPropertyValue(t)}function gs(n){return function(){delete this[n]}}function ms(n,t){return function(){this[n]=t}}function vs(n,t){return function(){var e=t.apply(this,arguments);e==null?delete this[n]:this[n]=e}}function ys(n,t){return arguments.length>1?this.each((t==null?gs:typeof t=="function"?vs:ms)(n,t)):this.node()[n]}function uo(n){return n.trim().split(/^|\s+/)}function Hn(n){return n.classList||new fo(n)}function fo(n){this._node=n,this._names=uo(n.getAttribute("class")||"")}fo.prototype={add:function(n){var t=this._names.indexOf(n);t<0&&(this._names.push(n),this._node.setAttribute("class",this._names.join(" ")))},remove:function(n){var t=this._names.indexOf(n);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(n){return this._names.indexOf(n)>=0}};function po(n,t){for(var e=Hn(n),o=-1,s=t.length;++o<s;)e.add(t[o])}function go(n,t){for(var e=Hn(n),o=-1,s=t.length;++o<s;)e.remove(t[o])}function bs(n){return function(){po(this,n)}}function ws(n){return function(){go(this,n)}}function xs(n,t){return function(){(t.apply(this,arguments)?po:go)(this,n)}}function Cs(n,t){var e=uo(n+"");if(arguments.length<2){for(var o=Hn(this.node()),s=-1,a=e.length;++s<a;)if(!o.contains(e[s]))return!1;return!0}return this.each((typeof t=="function"?xs:t?bs:ws)(e,t))}function ks(){this.textContent=""}function Ss(n){return function(){this.textContent=n}}function As(n){return function(){var t=n.apply(this,arguments);this.textContent=t??""}}function Is(n){return arguments.length?this.each(n==null?ks:(typeof n=="function"?As:Ss)(n)):this.node().textContent}function Ts(){this.innerHTML=""}function Es(n){return function(){this.innerHTML=n}}function $s(n){return function(){var t=n.apply(this,arguments);this.innerHTML=t??""}}function Ms(n){return arguments.length?this.each(n==null?Ts:(typeof n=="function"?$s:Es)(n)):this.node().innerHTML}function _s(){this.nextSibling&&this.parentNode.appendChild(this)}function Ns(){return this.each(_s)}function Ps(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Rs(){return this.each(Ps)}function zs(n){var t=typeof n=="function"?n:ro(n);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function Ls(){return null}function Vs(n,t){var e=typeof n=="function"?n:ro(n),o=t==null?Ls:typeof t=="function"?t:jn(t);return this.select(function(){return this.insertBefore(e.apply(this,arguments),o.apply(this,arguments)||null)})}function Ds(){var n=this.parentNode;n&&n.removeChild(this)}function Fs(){return this.each(Ds)}function Os(){var n=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(n,this.nextSibling):n}function Bs(){var n=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(n,this.nextSibling):n}function Gs(n){return this.select(n?Bs:Os)}function Us(n){return arguments.length?this.property("__data__",n):this.node().__data__}function js(n){return function(t){n.call(this,t,this.__data__)}}function Hs(n){return n.trim().split(/^|\s+/).map(function(t){var e="",o=t.indexOf(".");return o>=0&&(e=t.slice(o+1),t=t.slice(0,o)),{type:t,name:e}})}function Xs(n){return function(){var t=this.__on;if(t){for(var e=0,o=-1,s=t.length,a;e<s;++e)a=t[e],(!n.type||a.type===n.type)&&a.name===n.name?this.removeEventListener(a.type,a.listener,a.options):t[++o]=a;++o?t.length=o:delete this.__on}}}function Ys(n,t,e){return function(){var o=this.__on,s,a=js(t);if(o){for(var i=0,r=o.length;i<r;++i)if((s=o[i]).type===n.type&&s.name===n.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=a,s.options=e),s.value=t;return}}this.addEventListener(n.type,a,e),s={type:n.type,name:n.name,value:t,listener:a,options:e},o?o.push(s):this.__on=[s]}}function Ws(n,t,e){var o=Hs(n+""),s,a=o.length,i;if(arguments.length<2){var r=this.node().__on;if(r){for(var l=0,c=r.length,h;l<c;++l)for(s=0,h=r[l];s<a;++s)if((i=o[s]).type===h.type&&i.name===h.name)return h.value}return}for(r=t?Ys:Xs,s=0;s<a;++s)this.each(r(o[s],t,e));return this}function mo(n,t,e){var o=ho(n),s=o.CustomEvent;typeof s=="function"?s=new s(t,e):(s=o.document.createEvent("Event"),e?(s.initEvent(t,e.bubbles,e.cancelable),s.detail=e.detail):s.initEvent(t,!1,!1)),n.dispatchEvent(s)}function qs(n,t){return function(){return mo(this,n,t)}}function Ks(n,t){return function(){return mo(this,n,t.apply(this,arguments))}}function Zs(n,t){return this.each((typeof t=="function"?Ks:qs)(n,t))}function*Qs(){for(var n=this._groups,t=0,e=n.length;t<e;++t)for(var o=n[t],s=0,a=o.length,i;s<a;++s)(i=o[s])&&(yield i)}var vo=[null];function ft(n,t){this._groups=n,this._parents=t}function Ce(){return new ft([[document.documentElement]],vo)}function Js(){return this}ft.prototype=Ce.prototype={constructor:ft,select:Ar,selectAll:$r,selectChild:Pr,selectChildren:Vr,filter:Dr,data:jr,enter:Fr,exit:Xr,join:Yr,merge:Wr,selection:Js,order:qr,sort:Kr,call:Qr,nodes:Jr,node:ts,size:es,empty:ns,each:is,attr:hs,style:ps,property:ys,classed:Cs,text:Is,html:Ms,raise:Ns,lower:Rs,append:zs,insert:Vs,remove:Fs,clone:Gs,datum:Us,on:Ws,dispatch:Zs,[Symbol.iterator]:Qs};function O(n){return typeof n=="string"?new ft([[document.querySelector(n)]],[document.documentElement]):new ft([[n]],vo)}function ta(n){let t;for(;t=n.sourceEvent;)n=t;return n}function vt(n,t){if(n=ta(n),t===void 0&&(t=n.currentTarget),t){var e=t.ownerSVGElement||t;if(e.createSVGPoint){var o=e.createSVGPoint();return o.x=n.clientX,o.y=n.clientY,o=o.matrixTransform(t.getScreenCTM().inverse()),[o.x,o.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[n.clientX-s.left-t.clientLeft,n.clientY-s.top-t.clientTop]}}return[n.pageX,n.pageY]}const ea={passive:!1},fe={capture:!0,passive:!1};function un(n){n.stopImmediatePropagation()}function Zt(n){n.preventDefault(),n.stopImmediatePropagation()}function yo(n){var t=n.document.documentElement,e=O(n).on("dragstart.drag",Zt,fe);"onselectstart"in t?e.on("selectstart.drag",Zt,fe):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function bo(n,t){var e=n.document.documentElement,o=O(n).on("dragstart.drag",null);t&&(o.on("click.drag",Zt,fe),setTimeout(function(){o.on("click.drag",null)},0)),"onselectstart"in e?o.on("selectstart.drag",null):(e.style.MozUserSelect=e.__noselect,delete e.__noselect)}const Te=n=>()=>n;function $n(n,{sourceEvent:t,subject:e,target:o,identifier:s,active:a,x:i,y:r,dx:l,dy:c,dispatch:h}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:e,enumerable:!0,configurable:!0},target:{value:o,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:r,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:h}})}$n.prototype.on=function(){var n=this._.on.apply(this._,arguments);return n===this._?this:n};function na(n){return!n.ctrlKey&&!n.button}function ia(){return this.parentNode}function oa(n,t){return t??{x:n.x,y:n.y}}function ra(){return navigator.maxTouchPoints||"ontouchstart"in this}function J(){var n=na,t=ia,e=oa,o=ra,s={},a=tn("start","drag","end"),i=0,r,l,c,h,f=0;function u(y){y.on("mousedown.drag",p).filter(o).on("touchstart.drag",m).on("touchmove.drag",v,ea).on("touchend.drag touchcancel.drag",w).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(y,k){if(!(h||!n.call(this,y,k))){var M=C(this,t.call(this,y,k),y,k,"mouse");M&&(O(y.view).on("mousemove.drag",g,fe).on("mouseup.drag",d,fe),yo(y.view),un(y),c=!1,r=y.clientX,l=y.clientY,M("start",y))}}function g(y){if(Zt(y),!c){var k=y.clientX-r,M=y.clientY-l;c=k*k+M*M>f}s.mouse("drag",y)}function d(y){O(y.view).on("mousemove.drag mouseup.drag",null),bo(y.view,c),Zt(y),s.mouse("end",y)}function m(y,k){if(n.call(this,y,k)){var M=y.changedTouches,N=t.call(this,y,k),R=M.length,F,H;for(F=0;F<R;++F)(H=C(this,N,y,k,M[F].identifier,M[F]))&&(un(y),H("start",y,M[F]))}}function v(y){var k=y.changedTouches,M=k.length,N,R;for(N=0;N<M;++N)(R=s[k[N].identifier])&&(Zt(y),R("drag",y,k[N]))}function w(y){var k=y.changedTouches,M=k.length,N,R;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),N=0;N<M;++N)(R=s[k[N].identifier])&&(un(y),R("end",y,k[N]))}function C(y,k,M,N,R,F){var H=a.copy(),W=vt(F||M,k),tt,rt,b;if((b=e.call(y,new $n("beforestart",{sourceEvent:M,target:u,identifier:R,active:i,x:W[0],y:W[1],dx:0,dy:0,dispatch:H}),N))!=null)return tt=b.x-W[0]||0,rt=b.y-W[1]||0,function E(S,_,z){var V=W,D;switch(S){case"start":s[R]=E,D=i++;break;case"end":delete s[R],--i;case"drag":W=vt(z||_,k),D=i;break}H.call(S,y,new $n(S,{sourceEvent:_,subject:b,target:u,identifier:R,active:D,x:W[0]+tt,y:W[1]+rt,dx:W[0]-V[0],dy:W[1]-V[1],dispatch:H}),N)}}return u.filter=function(y){return arguments.length?(n=typeof y=="function"?y:Te(!!y),u):n},u.container=function(y){return arguments.length?(t=typeof y=="function"?y:Te(y),u):t},u.subject=function(y){return arguments.length?(e=typeof y=="function"?y:Te(y),u):e},u.touchable=function(y){return arguments.length?(o=typeof y=="function"?y:Te(!!y),u):o},u.on=function(){var y=a.on.apply(a,arguments);return y===a?u:y},u.clickDistance=function(y){return arguments.length?(f=(y=+y)*y,u):Math.sqrt(f)},u}function Xn(n,t,e){n.prototype=t.prototype=e,e.constructor=n}function wo(n,t){var e=Object.create(n.prototype);for(var o in t)e[o]=t[o];return e}function ke(){}var pe=.7,Ue=1/pe,Qt="\\s*([+-]?\\d+)\\s*",ge="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",At="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",sa=/^#([0-9a-f]{3,8})$/,aa=new RegExp(`^rgb\\(${Qt},${Qt},${Qt}\\)$`),la=new RegExp(`^rgb\\(${At},${At},${At}\\)$`),ca=new RegExp(`^rgba\\(${Qt},${Qt},${Qt},${ge}\\)$`),ha=new RegExp(`^rgba\\(${At},${At},${At},${ge}\\)$`),da=new RegExp(`^hsl\\(${ge},${At},${At}\\)$`),ua=new RegExp(`^hsla\\(${ge},${At},${At},${ge}\\)$`),Ei={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Xn(ke,me,{copy(n){return Object.assign(new this.constructor,this,n)},displayable(){return this.rgb().displayable()},hex:$i,formatHex:$i,formatHex8:fa,formatHsl:pa,formatRgb:Mi,toString:Mi});function $i(){return this.rgb().formatHex()}function fa(){return this.rgb().formatHex8()}function pa(){return xo(this).formatHsl()}function Mi(){return this.rgb().formatRgb()}function me(n){var t,e;return n=(n+"").trim().toLowerCase(),(t=sa.exec(n))?(e=t[1].length,t=parseInt(t[1],16),e===6?_i(t):e===3?new ht(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):e===8?Ee(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):e===4?Ee(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=aa.exec(n))?new ht(t[1],t[2],t[3],1):(t=la.exec(n))?new ht(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=ca.exec(n))?Ee(t[1],t[2],t[3],t[4]):(t=ha.exec(n))?Ee(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=da.exec(n))?Ri(t[1],t[2]/100,t[3]/100,1):(t=ua.exec(n))?Ri(t[1],t[2]/100,t[3]/100,t[4]):Ei.hasOwnProperty(n)?_i(Ei[n]):n==="transparent"?new ht(NaN,NaN,NaN,0):null}function _i(n){return new ht(n>>16&255,n>>8&255,n&255,1)}function Ee(n,t,e,o){return o<=0&&(n=t=e=NaN),new ht(n,t,e,o)}function ga(n){return n instanceof ke||(n=me(n)),n?(n=n.rgb(),new ht(n.r,n.g,n.b,n.opacity)):new ht}function Mn(n,t,e,o){return arguments.length===1?ga(n):new ht(n,t,e,o??1)}function ht(n,t,e,o){this.r=+n,this.g=+t,this.b=+e,this.opacity=+o}Xn(ht,Mn,wo(ke,{brighter(n){return n=n==null?Ue:Math.pow(Ue,n),new ht(this.r*n,this.g*n,this.b*n,this.opacity)},darker(n){return n=n==null?pe:Math.pow(pe,n),new ht(this.r*n,this.g*n,this.b*n,this.opacity)},rgb(){return this},clamp(){return new ht(Gt(this.r),Gt(this.g),Gt(this.b),je(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Ni,formatHex:Ni,formatHex8:ma,formatRgb:Pi,toString:Pi}));function Ni(){return`#${Bt(this.r)}${Bt(this.g)}${Bt(this.b)}`}function ma(){return`#${Bt(this.r)}${Bt(this.g)}${Bt(this.b)}${Bt((isNaN(this.opacity)?1:this.opacity)*255)}`}function Pi(){const n=je(this.opacity);return`${n===1?"rgb(":"rgba("}${Gt(this.r)}, ${Gt(this.g)}, ${Gt(this.b)}${n===1?")":`, ${n})`}`}function je(n){return isNaN(n)?1:Math.max(0,Math.min(1,n))}function Gt(n){return Math.max(0,Math.min(255,Math.round(n)||0))}function Bt(n){return n=Gt(n),(n<16?"0":"")+n.toString(16)}function Ri(n,t,e,o){return o<=0?n=t=e=NaN:e<=0||e>=1?n=t=NaN:t<=0&&(n=NaN),new bt(n,t,e,o)}function xo(n){if(n instanceof bt)return new bt(n.h,n.s,n.l,n.opacity);if(n instanceof ke||(n=me(n)),!n)return new bt;if(n instanceof bt)return n;n=n.rgb();var t=n.r/255,e=n.g/255,o=n.b/255,s=Math.min(t,e,o),a=Math.max(t,e,o),i=NaN,r=a-s,l=(a+s)/2;return r?(t===a?i=(e-o)/r+(e<o)*6:e===a?i=(o-t)/r+2:i=(t-e)/r+4,r/=l<.5?a+s:2-a-s,i*=60):r=l>0&&l<1?0:i,new bt(i,r,l,n.opacity)}function va(n,t,e,o){return arguments.length===1?xo(n):new bt(n,t,e,o??1)}function bt(n,t,e,o){this.h=+n,this.s=+t,this.l=+e,this.opacity=+o}Xn(bt,va,wo(ke,{brighter(n){return n=n==null?Ue:Math.pow(Ue,n),new bt(this.h,this.s,this.l*n,this.opacity)},darker(n){return n=n==null?pe:Math.pow(pe,n),new bt(this.h,this.s,this.l*n,this.opacity)},rgb(){var n=this.h%360+(this.h<0)*360,t=isNaN(n)||isNaN(this.s)?0:this.s,e=this.l,o=e+(e<.5?e:1-e)*t,s=2*e-o;return new ht(fn(n>=240?n-240:n+120,s,o),fn(n,s,o),fn(n<120?n+240:n-120,s,o),this.opacity)},clamp(){return new bt(zi(this.h),$e(this.s),$e(this.l),je(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const n=je(this.opacity);return`${n===1?"hsl(":"hsla("}${zi(this.h)}, ${$e(this.s)*100}%, ${$e(this.l)*100}%${n===1?")":`, ${n})`}`}}));function zi(n){return n=(n||0)%360,n<0?n+360:n}function $e(n){return Math.max(0,Math.min(1,n||0))}function fn(n,t,e){return(n<60?t+(e-t)*n/60:n<180?e:n<240?t+(e-t)*(240-n)/60:t)*255}const Co=n=>()=>n;function ya(n,t){return function(e){return n+e*t}}function ba(n,t,e){return n=Math.pow(n,e),t=Math.pow(t,e)-n,e=1/e,function(o){return Math.pow(n+o*t,e)}}function wa(n){return(n=+n)==1?ko:function(t,e){return e-t?ba(t,e,n):Co(isNaN(t)?e:t)}}function ko(n,t){var e=t-n;return e?ya(n,e):Co(isNaN(n)?t:n)}const Li=function n(t){var e=wa(t);function o(s,a){var i=e((s=Mn(s)).r,(a=Mn(a)).r),r=e(s.g,a.g),l=e(s.b,a.b),c=ko(s.opacity,a.opacity);return function(h){return s.r=i(h),s.g=r(h),s.b=l(h),s.opacity=c(h),s+""}}return o.gamma=n,o}(1);function Lt(n,t){return n=+n,t=+t,function(e){return n*(1-e)+t*e}}var _n=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,pn=new RegExp(_n.source,"g");function xa(n){return function(){return n}}function Ca(n){return function(t){return n(t)+""}}function ka(n,t){var e=_n.lastIndex=pn.lastIndex=0,o,s,a,i=-1,r=[],l=[];for(n=n+"",t=t+"";(o=_n.exec(n))&&(s=pn.exec(t));)(a=s.index)>e&&(a=t.slice(e,a),r[i]?r[i]+=a:r[++i]=a),(o=o[0])===(s=s[0])?r[i]?r[i]+=s:r[++i]=s:(r[++i]=null,l.push({i,x:Lt(o,s)})),e=pn.lastIndex;return e<t.length&&(a=t.slice(e),r[i]?r[i]+=a:r[++i]=a),r.length<2?l[0]?Ca(l[0].x):xa(t):(t=l.length,function(c){for(var h=0,f;h<t;++h)r[(f=l[h]).i]=f.x(c);return r.join("")})}var Vi=180/Math.PI,Nn={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function So(n,t,e,o,s,a){var i,r,l;return(i=Math.sqrt(n*n+t*t))&&(n/=i,t/=i),(l=n*e+t*o)&&(e-=n*l,o-=t*l),(r=Math.sqrt(e*e+o*o))&&(e/=r,o/=r,l/=r),n*o<t*e&&(n=-n,t=-t,l=-l,i=-i),{translateX:s,translateY:a,rotate:Math.atan2(t,n)*Vi,skewX:Math.atan(l)*Vi,scaleX:i,scaleY:r}}var Me;function Sa(n){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(n+"");return t.isIdentity?Nn:So(t.a,t.b,t.c,t.d,t.e,t.f)}function Aa(n){return n==null||(Me||(Me=document.createElementNS("http://www.w3.org/2000/svg","g")),Me.setAttribute("transform",n),!(n=Me.transform.baseVal.consolidate()))?Nn:(n=n.matrix,So(n.a,n.b,n.c,n.d,n.e,n.f))}function Ao(n,t,e,o){function s(c){return c.length?c.pop()+" ":""}function a(c,h,f,u,p,g){if(c!==f||h!==u){var d=p.push("translate(",null,t,null,e);g.push({i:d-4,x:Lt(c,f)},{i:d-2,x:Lt(h,u)})}else(f||u)&&p.push("translate("+f+t+u+e)}function i(c,h,f,u){c!==h?(c-h>180?h+=360:h-c>180&&(c+=360),u.push({i:f.push(s(f)+"rotate(",null,o)-2,x:Lt(c,h)})):h&&f.push(s(f)+"rotate("+h+o)}function r(c,h,f,u){c!==h?u.push({i:f.push(s(f)+"skewX(",null,o)-2,x:Lt(c,h)}):h&&f.push(s(f)+"skewX("+h+o)}function l(c,h,f,u,p,g){if(c!==f||h!==u){var d=p.push(s(p)+"scale(",null,",",null,")");g.push({i:d-4,x:Lt(c,f)},{i:d-2,x:Lt(h,u)})}else(f!==1||u!==1)&&p.push(s(p)+"scale("+f+","+u+")")}return function(c,h){var f=[],u=[];return c=n(c),h=n(h),a(c.translateX,c.translateY,h.translateX,h.translateY,f,u),i(c.rotate,h.rotate,f,u),r(c.skewX,h.skewX,f,u),l(c.scaleX,c.scaleY,h.scaleX,h.scaleY,f,u),c=h=null,function(p){for(var g=-1,d=u.length,m;++g<d;)f[(m=u[g]).i]=m.x(p);return f.join("")}}}var Ia=Ao(Sa,"px, ","px)","deg)"),Ta=Ao(Aa,", ",")",")"),Ea=1e-12;function Di(n){return((n=Math.exp(n))+1/n)/2}function $a(n){return((n=Math.exp(n))-1/n)/2}function Ma(n){return((n=Math.exp(2*n))-1)/(n+1)}const _a=function n(t,e,o){function s(a,i){var r=a[0],l=a[1],c=a[2],h=i[0],f=i[1],u=i[2],p=h-r,g=f-l,d=p*p+g*g,m,v;if(d<Ea)v=Math.log(u/c)/t,m=function(N){return[r+N*p,l+N*g,c*Math.exp(t*N*v)]};else{var w=Math.sqrt(d),C=(u*u-c*c+o*d)/(2*c*e*w),y=(u*u-c*c-o*d)/(2*u*e*w),k=Math.log(Math.sqrt(C*C+1)-C),M=Math.log(Math.sqrt(y*y+1)-y);v=(M-k)/t,m=function(N){var R=N*v,F=Di(k),H=c/(e*w)*(F*Ma(t*R+k)-$a(k));return[r+H*p,l+H*g,c*F/Di(t*R+k)]}}return m.duration=v*1e3*t/Math.SQRT2,m}return s.rho=function(a){var i=Math.max(.001,+a),r=i*i,l=r*r;return n(i,r,l)},s}(Math.SQRT2,2,4);var ie=0,de=0,ce=0,Io=1e3,He,ue,Xe=0,jt=0,nn=0,ve=typeof performance=="object"&&performance.now?performance:Date,To=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(n){setTimeout(n,17)};function Yn(){return jt||(To(Na),jt=ve.now()+nn)}function Na(){jt=0}function Ye(){this._call=this._time=this._next=null}Ye.prototype=Eo.prototype={constructor:Ye,restart:function(n,t,e){if(typeof n!="function")throw new TypeError("callback is not a function");e=(e==null?Yn():+e)+(t==null?0:+t),!this._next&&ue!==this&&(ue?ue._next=this:He=this,ue=this),this._call=n,this._time=e,Pn()},stop:function(){this._call&&(this._call=null,this._time=1/0,Pn())}};function Eo(n,t,e){var o=new Ye;return o.restart(n,t,e),o}function Pa(){Yn(),++ie;for(var n=He,t;n;)(t=jt-n._time)>=0&&n._call.call(void 0,t),n=n._next;--ie}function Fi(){jt=(Xe=ve.now())+nn,ie=de=0;try{Pa()}finally{ie=0,za(),jt=0}}function Ra(){var n=ve.now(),t=n-Xe;t>Io&&(nn-=t,Xe=n)}function za(){for(var n,t=He,e,o=1/0;t;)t._call?(o>t._time&&(o=t._time),n=t,t=t._next):(e=t._next,t._next=null,t=n?n._next=e:He=e);ue=n,Pn(o)}function Pn(n){if(!ie){de&&(de=clearTimeout(de));var t=n-jt;t>24?(n<1/0&&(de=setTimeout(Fi,n-ve.now()-nn)),ce&&(ce=clearInterval(ce))):(ce||(Xe=ve.now(),ce=setInterval(Ra,Io)),ie=1,To(Fi))}}function Oi(n,t,e){var o=new Ye;return t=t==null?0:+t,o.restart(s=>{o.stop(),n(s+t)},t,e),o}var La=tn("start","end","cancel","interrupt"),Va=[],$o=0,Bi=1,Rn=2,Le=3,Gi=4,zn=5,Ve=6;function on(n,t,e,o,s,a){var i=n.__transition;if(!i)n.__transition={};else if(e in i)return;Da(n,e,{name:t,index:o,group:s,on:La,tween:Va,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:$o})}function Wn(n,t){var e=xt(n,t);if(e.state>$o)throw new Error("too late; already scheduled");return e}function It(n,t){var e=xt(n,t);if(e.state>Le)throw new Error("too late; already running");return e}function xt(n,t){var e=n.__transition;if(!e||!(e=e[t]))throw new Error("transition not found");return e}function Da(n,t,e){var o=n.__transition,s;o[t]=e,e.timer=Eo(a,0,e.time);function a(c){e.state=Bi,e.timer.restart(i,e.delay,e.time),e.delay<=c&&i(c-e.delay)}function i(c){var h,f,u,p;if(e.state!==Bi)return l();for(h in o)if(p=o[h],p.name===e.name){if(p.state===Le)return Oi(i);p.state===Gi?(p.state=Ve,p.timer.stop(),p.on.call("interrupt",n,n.__data__,p.index,p.group),delete o[h]):+h<t&&(p.state=Ve,p.timer.stop(),p.on.call("cancel",n,n.__data__,p.index,p.group),delete o[h])}if(Oi(function(){e.state===Le&&(e.state=Gi,e.timer.restart(r,e.delay,e.time),r(c))}),e.state=Rn,e.on.call("start",n,n.__data__,e.index,e.group),e.state===Rn){for(e.state=Le,s=new Array(u=e.tween.length),h=0,f=-1;h<u;++h)(p=e.tween[h].value.call(n,n.__data__,e.index,e.group))&&(s[++f]=p);s.length=f+1}}function r(c){for(var h=c<e.duration?e.ease.call(null,c/e.duration):(e.timer.restart(l),e.state=zn,1),f=-1,u=s.length;++f<u;)s[f].call(n,h);e.state===zn&&(e.on.call("end",n,n.__data__,e.index,e.group),l())}function l(){e.state=Ve,e.timer.stop(),delete o[t];for(var c in o)return;delete n.__transition}}function De(n,t){var e=n.__transition,o,s,a=!0,i;if(e){t=t==null?null:t+"";for(i in e){if((o=e[i]).name!==t){a=!1;continue}s=o.state>Rn&&o.state<zn,o.state=Ve,o.timer.stop(),o.on.call(s?"interrupt":"cancel",n,n.__data__,o.index,o.group),delete e[i]}a&&delete n.__transition}}function Fa(n){return this.each(function(){De(this,n)})}function Oa(n,t){var e,o;return function(){var s=It(this,n),a=s.tween;if(a!==e){o=e=a;for(var i=0,r=o.length;i<r;++i)if(o[i].name===t){o=o.slice(),o.splice(i,1);break}}s.tween=o}}function Ba(n,t,e){var o,s;if(typeof e!="function")throw new Error;return function(){var a=It(this,n),i=a.tween;if(i!==o){s=(o=i).slice();for(var r={name:t,value:e},l=0,c=s.length;l<c;++l)if(s[l].name===t){s[l]=r;break}l===c&&s.push(r)}a.tween=s}}function Ga(n,t){var e=this._id;if(n+="",arguments.length<2){for(var o=xt(this.node(),e).tween,s=0,a=o.length,i;s<a;++s)if((i=o[s]).name===n)return i.value;return null}return this.each((t==null?Oa:Ba)(e,n,t))}function qn(n,t,e){var o=n._id;return n.each(function(){var s=It(this,o);(s.value||(s.value={}))[t]=e.apply(this,arguments)}),function(s){return xt(s,o).value[t]}}function Mo(n,t){var e;return(typeof t=="number"?Lt:t instanceof me?Li:(e=me(t))?(t=e,Li):ka)(n,t)}function Ua(n){return function(){this.removeAttribute(n)}}function ja(n){return function(){this.removeAttributeNS(n.space,n.local)}}function Ha(n,t,e){var o,s=e+"",a;return function(){var i=this.getAttribute(n);return i===s?null:i===o?a:a=t(o=i,e)}}function Xa(n,t,e){var o,s=e+"",a;return function(){var i=this.getAttributeNS(n.space,n.local);return i===s?null:i===o?a:a=t(o=i,e)}}function Ya(n,t,e){var o,s,a;return function(){var i,r=e(this),l;return r==null?void this.removeAttribute(n):(i=this.getAttribute(n),l=r+"",i===l?null:i===o&&l===s?a:(s=l,a=t(o=i,r)))}}function Wa(n,t,e){var o,s,a;return function(){var i,r=e(this),l;return r==null?void this.removeAttributeNS(n.space,n.local):(i=this.getAttributeNS(n.space,n.local),l=r+"",i===l?null:i===o&&l===s?a:(s=l,a=t(o=i,r)))}}function qa(n,t){var e=en(n),o=e==="transform"?Ta:Mo;return this.attrTween(n,typeof t=="function"?(e.local?Wa:Ya)(e,o,qn(this,"attr."+n,t)):t==null?(e.local?ja:Ua)(e):(e.local?Xa:Ha)(e,o,t))}function Ka(n,t){return function(e){this.setAttribute(n,t.call(this,e))}}function Za(n,t){return function(e){this.setAttributeNS(n.space,n.local,t.call(this,e))}}function Qa(n,t){var e,o;function s(){var a=t.apply(this,arguments);return a!==o&&(e=(o=a)&&Za(n,a)),e}return s._value=t,s}function Ja(n,t){var e,o;function s(){var a=t.apply(this,arguments);return a!==o&&(e=(o=a)&&Ka(n,a)),e}return s._value=t,s}function tl(n,t){var e="attr."+n;if(arguments.length<2)return(e=this.tween(e))&&e._value;if(t==null)return this.tween(e,null);if(typeof t!="function")throw new Error;var o=en(n);return this.tween(e,(o.local?Qa:Ja)(o,t))}function el(n,t){return function(){Wn(this,n).delay=+t.apply(this,arguments)}}function nl(n,t){return t=+t,function(){Wn(this,n).delay=t}}function il(n){var t=this._id;return arguments.length?this.each((typeof n=="function"?el:nl)(t,n)):xt(this.node(),t).delay}function ol(n,t){return function(){It(this,n).duration=+t.apply(this,arguments)}}function rl(n,t){return t=+t,function(){It(this,n).duration=t}}function sl(n){var t=this._id;return arguments.length?this.each((typeof n=="function"?ol:rl)(t,n)):xt(this.node(),t).duration}function al(n,t){if(typeof t!="function")throw new Error;return function(){It(this,n).ease=t}}function ll(n){var t=this._id;return arguments.length?this.each(al(t,n)):xt(this.node(),t).ease}function cl(n,t){return function(){var e=t.apply(this,arguments);if(typeof e!="function")throw new Error;It(this,n).ease=e}}function hl(n){if(typeof n!="function")throw new Error;return this.each(cl(this._id,n))}function dl(n){typeof n!="function"&&(n=ao(n));for(var t=this._groups,e=t.length,o=new Array(e),s=0;s<e;++s)for(var a=t[s],i=a.length,r=o[s]=[],l,c=0;c<i;++c)(l=a[c])&&n.call(l,l.__data__,c,a)&&r.push(l);return new _t(o,this._parents,this._name,this._id)}function ul(n){if(n._id!==this._id)throw new Error;for(var t=this._groups,e=n._groups,o=t.length,s=e.length,a=Math.min(o,s),i=new Array(o),r=0;r<a;++r)for(var l=t[r],c=e[r],h=l.length,f=i[r]=new Array(h),u,p=0;p<h;++p)(u=l[p]||c[p])&&(f[p]=u);for(;r<o;++r)i[r]=t[r];return new _t(i,this._parents,this._name,this._id)}function fl(n){return(n+"").trim().split(/^|\s+/).every(function(t){var e=t.indexOf(".");return e>=0&&(t=t.slice(0,e)),!t||t==="start"})}function pl(n,t,e){var o,s,a=fl(t)?Wn:It;return function(){var i=a(this,n),r=i.on;r!==o&&(s=(o=r).copy()).on(t,e),i.on=s}}function gl(n,t){var e=this._id;return arguments.length<2?xt(this.node(),e).on.on(n):this.each(pl(e,n,t))}function ml(n){return function(){var t=this.parentNode;for(var e in this.__transition)if(+e!==n)return;t&&t.removeChild(this)}}function vl(){return this.on("end.remove",ml(this._id))}function yl(n){var t=this._name,e=this._id;typeof n!="function"&&(n=jn(n));for(var o=this._groups,s=o.length,a=new Array(s),i=0;i<s;++i)for(var r=o[i],l=r.length,c=a[i]=new Array(l),h,f,u=0;u<l;++u)(h=r[u])&&(f=n.call(h,h.__data__,u,r))&&("__data__"in h&&(f.__data__=h.__data__),c[u]=f,on(c[u],t,e,u,c,xt(h,e)));return new _t(a,this._parents,t,e)}function bl(n){var t=this._name,e=this._id;typeof n!="function"&&(n=so(n));for(var o=this._groups,s=o.length,a=[],i=[],r=0;r<s;++r)for(var l=o[r],c=l.length,h,f=0;f<c;++f)if(h=l[f]){for(var u=n.call(h,h.__data__,f,l),p,g=xt(h,e),d=0,m=u.length;d<m;++d)(p=u[d])&&on(p,t,e,d,u,g);a.push(u),i.push(h)}return new _t(a,i,t,e)}var wl=Ce.prototype.constructor;function xl(){return new wl(this._groups,this._parents)}function Cl(n,t){var e,o,s;return function(){var a=ne(this,n),i=(this.style.removeProperty(n),ne(this,n));return a===i?null:a===e&&i===o?s:s=t(e=a,o=i)}}function _o(n){return function(){this.style.removeProperty(n)}}function kl(n,t,e){var o,s=e+"",a;return function(){var i=ne(this,n);return i===s?null:i===o?a:a=t(o=i,e)}}function Sl(n,t,e){var o,s,a;return function(){var i=ne(this,n),r=e(this),l=r+"";return r==null&&(l=r=(this.style.removeProperty(n),ne(this,n))),i===l?null:i===o&&l===s?a:(s=l,a=t(o=i,r))}}function Al(n,t){var e,o,s,a="style."+t,i="end."+a,r;return function(){var l=It(this,n),c=l.on,h=l.value[a]==null?r||(r=_o(t)):void 0;(c!==e||s!==h)&&(o=(e=c).copy()).on(i,s=h),l.on=o}}function Il(n,t,e){var o=(n+="")=="transform"?Ia:Mo;return t==null?this.styleTween(n,Cl(n,o)).on("end.style."+n,_o(n)):typeof t=="function"?this.styleTween(n,Sl(n,o,qn(this,"style."+n,t))).each(Al(this._id,n)):this.styleTween(n,kl(n,o,t),e).on("end.style."+n,null)}function Tl(n,t,e){return function(o){this.style.setProperty(n,t.call(this,o),e)}}function El(n,t,e){var o,s;function a(){var i=t.apply(this,arguments);return i!==s&&(o=(s=i)&&Tl(n,i,e)),o}return a._value=t,a}function $l(n,t,e){var o="style."+(n+="");if(arguments.length<2)return(o=this.tween(o))&&o._value;if(t==null)return this.tween(o,null);if(typeof t!="function")throw new Error;return this.tween(o,El(n,t,e??""))}function Ml(n){return function(){this.textContent=n}}function _l(n){return function(){var t=n(this);this.textContent=t??""}}function Nl(n){return this.tween("text",typeof n=="function"?_l(qn(this,"text",n)):Ml(n==null?"":n+""))}function Pl(n){return function(t){this.textContent=n.call(this,t)}}function Rl(n){var t,e;function o(){var s=n.apply(this,arguments);return s!==e&&(t=(e=s)&&Pl(s)),t}return o._value=n,o}function zl(n){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(n==null)return this.tween(t,null);if(typeof n!="function")throw new Error;return this.tween(t,Rl(n))}function Ll(){for(var n=this._name,t=this._id,e=No(),o=this._groups,s=o.length,a=0;a<s;++a)for(var i=o[a],r=i.length,l,c=0;c<r;++c)if(l=i[c]){var h=xt(l,t);on(l,n,e,c,i,{time:h.time+h.delay+h.duration,delay:0,duration:h.duration,ease:h.ease})}return new _t(o,this._parents,n,e)}function Vl(){var n,t,e=this,o=e._id,s=e.size();return new Promise(function(a,i){var r={value:i},l={value:function(){--s===0&&a()}};e.each(function(){var c=It(this,o),h=c.on;h!==n&&(t=(n=h).copy(),t._.cancel.push(r),t._.interrupt.push(r),t._.end.push(l)),c.on=t}),s===0&&a()})}var Dl=0;function _t(n,t,e,o){this._groups=n,this._parents=t,this._name=e,this._id=o}function No(){return++Dl}var Tt=Ce.prototype;_t.prototype={constructor:_t,select:yl,selectAll:bl,selectChild:Tt.selectChild,selectChildren:Tt.selectChildren,filter:dl,merge:ul,selection:xl,transition:Ll,call:Tt.call,nodes:Tt.nodes,node:Tt.node,size:Tt.size,empty:Tt.empty,each:Tt.each,on:gl,attr:qa,attrTween:tl,style:Il,styleTween:$l,text:Nl,textTween:zl,remove:vl,tween:Ga,delay:il,duration:sl,ease:ll,easeVarying:hl,end:Vl,[Symbol.iterator]:Tt[Symbol.iterator]};const Ln=n=>+n;function Fl(n){return((n*=2)<=1?n*n*n:(n-=2)*n*n+2)/2}var Ol={time:null,delay:0,duration:250,ease:Fl};function Bl(n,t){for(var e;!(e=n.__transition)||!(e=e[t]);)if(!(n=n.parentNode))throw new Error(`transition ${t} not found`);return e}function Gl(n){var t,e;n instanceof _t?(t=n._id,n=n._name):(t=No(),(e=Ol).time=Yn(),n=n==null?null:n+"");for(var o=this._groups,s=o.length,a=0;a<s;++a)for(var i=o[a],r=i.length,l,c=0;c<r;++c)(l=i[c])&&on(l,n,t,c,i,e||Bl(l,t));return new _t(o,this._parents,n,t)}Ce.prototype.interrupt=Fa;Ce.prototype.transition=Gl;const _e=n=>()=>n;function Ul(n,{sourceEvent:t,target:e,transform:o,dispatch:s}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:e,enumerable:!0,configurable:!0},transform:{value:o,enumerable:!0,configurable:!0},_:{value:s}})}function $t(n,t,e){this.k=n,this.x=t,this.y=e}$t.prototype={constructor:$t,scale:function(n){return n===1?this:new $t(this.k*n,this.x,this.y)},translate:function(n,t){return n===0&t===0?this:new $t(this.k,this.x+this.k*n,this.y+this.k*t)},apply:function(n){return[n[0]*this.k+this.x,n[1]*this.k+this.y]},applyX:function(n){return n*this.k+this.x},applyY:function(n){return n*this.k+this.y},invert:function(n){return[(n[0]-this.x)/this.k,(n[1]-this.y)/this.k]},invertX:function(n){return(n-this.x)/this.k},invertY:function(n){return(n-this.y)/this.k},rescaleX:function(n){return n.copy().domain(n.range().map(this.invertX,this).map(n.invert,n))},rescaleY:function(n){return n.copy().domain(n.range().map(this.invertY,this).map(n.invert,n))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Kn=new $t(1,0,0);$t.prototype;function gn(n){n.stopImmediatePropagation()}function he(n){n.preventDefault(),n.stopImmediatePropagation()}function jl(n){return(!n.ctrlKey||n.type==="wheel")&&!n.button}function Hl(){var n=this;return n instanceof SVGElement?(n=n.ownerSVGElement||n,n.hasAttribute("viewBox")?(n=n.viewBox.baseVal,[[n.x,n.y],[n.x+n.width,n.y+n.height]]):[[0,0],[n.width.baseVal.value,n.height.baseVal.value]]):[[0,0],[n.clientWidth,n.clientHeight]]}function Ui(){return this.__zoom||Kn}function Xl(n){return-n.deltaY*(n.deltaMode===1?.05:n.deltaMode?1:.002)*(n.ctrlKey?10:1)}function Yl(){return navigator.maxTouchPoints||"ontouchstart"in this}function Wl(n,t,e){var o=n.invertX(t[0][0])-e[0][0],s=n.invertX(t[1][0])-e[1][0],a=n.invertY(t[0][1])-e[0][1],i=n.invertY(t[1][1])-e[1][1];return n.translate(s>o?(o+s)/2:Math.min(0,o)||Math.max(0,s),i>a?(a+i)/2:Math.min(0,a)||Math.max(0,i))}function ql(){var n=jl,t=Hl,e=Wl,o=Xl,s=Yl,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],r=250,l=_a,c=tn("start","zoom","end"),h,f,u,p=500,g=150,d=0,m=10;function v(b){b.property("__zoom",Ui).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",F).on("dblclick.zoom",H).filter(s).on("touchstart.zoom",W).on("touchmove.zoom",tt).on("touchend.zoom touchcancel.zoom",rt).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}v.transform=function(b,E,S,_){var z=b.selection?b.selection():b;z.property("__zoom",Ui),b!==z?k(b,E,S,_):z.interrupt().each(function(){M(this,arguments).event(_).start().zoom(null,typeof E=="function"?E.apply(this,arguments):E).end()})},v.scaleBy=function(b,E,S,_){v.scaleTo(b,function(){var z=this.__zoom.k,V=typeof E=="function"?E.apply(this,arguments):E;return z*V},S,_)},v.scaleTo=function(b,E,S,_){v.transform(b,function(){var z=t.apply(this,arguments),V=this.__zoom,D=S==null?y(z):typeof S=="function"?S.apply(this,arguments):S,G=V.invert(D),X=typeof E=="function"?E.apply(this,arguments):E;return e(C(w(V,X),D,G),z,i)},S,_)},v.translateBy=function(b,E,S,_){v.transform(b,function(){return e(this.__zoom.translate(typeof E=="function"?E.apply(this,arguments):E,typeof S=="function"?S.apply(this,arguments):S),t.apply(this,arguments),i)},null,_)},v.translateTo=function(b,E,S,_,z){v.transform(b,function(){var V=t.apply(this,arguments),D=this.__zoom,G=_==null?y(V):typeof _=="function"?_.apply(this,arguments):_;return e(Kn.translate(G[0],G[1]).scale(D.k).translate(typeof E=="function"?-E.apply(this,arguments):-E,typeof S=="function"?-S.apply(this,arguments):-S),V,i)},_,z)};function w(b,E){return E=Math.max(a[0],Math.min(a[1],E)),E===b.k?b:new $t(E,b.x,b.y)}function C(b,E,S){var _=E[0]-S[0]*b.k,z=E[1]-S[1]*b.k;return _===b.x&&z===b.y?b:new $t(b.k,_,z)}function y(b){return[(+b[0][0]+ +b[1][0])/2,(+b[0][1]+ +b[1][1])/2]}function k(b,E,S,_){b.on("start.zoom",function(){M(this,arguments).event(_).start()}).on("interrupt.zoom end.zoom",function(){M(this,arguments).event(_).end()}).tween("zoom",function(){var z=this,V=arguments,D=M(z,V).event(_),G=t.apply(z,V),X=S==null?y(G):typeof S=="function"?S.apply(z,V):S,dt=Math.max(G[1][0]-G[0][0],G[1][1]-G[0][1]),q=z.__zoom,lt=typeof E=="function"?E.apply(z,V):E,gt=l(q.invert(X).concat(dt/q.k),lt.invert(X).concat(dt/lt.k));return function(ct){if(ct===1)ct=lt;else{var mt=gt(ct),Wt=dt/mt[2];ct=new $t(Wt,X[0]-mt[0]*Wt,X[1]-mt[1]*Wt)}D.zoom(null,ct)}})}function M(b,E,S){return!S&&b.__zooming||new N(b,E)}function N(b,E){this.that=b,this.args=E,this.active=0,this.sourceEvent=null,this.extent=t.apply(b,E),this.taps=0}N.prototype={event:function(b){return b&&(this.sourceEvent=b),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(b,E){return this.mouse&&b!=="mouse"&&(this.mouse[1]=E.invert(this.mouse[0])),this.touch0&&b!=="touch"&&(this.touch0[1]=E.invert(this.touch0[0])),this.touch1&&b!=="touch"&&(this.touch1[1]=E.invert(this.touch1[0])),this.that.__zoom=E,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(b){var E=O(this.that).datum();c.call(b,this.that,new Ul(b,{sourceEvent:this.sourceEvent,target:v,type:b,transform:this.that.__zoom,dispatch:c}),E)}};function R(b,...E){if(!n.apply(this,arguments))return;var S=M(this,E).event(b),_=this.__zoom,z=Math.max(a[0],Math.min(a[1],_.k*Math.pow(2,o.apply(this,arguments)))),V=vt(b);if(S.wheel)(S.mouse[0][0]!==V[0]||S.mouse[0][1]!==V[1])&&(S.mouse[1]=_.invert(S.mouse[0]=V)),clearTimeout(S.wheel);else{if(_.k===z)return;S.mouse=[V,_.invert(V)],De(this),S.start()}he(b),S.wheel=setTimeout(D,g),S.zoom("mouse",e(C(w(_,z),S.mouse[0],S.mouse[1]),S.extent,i));function D(){S.wheel=null,S.end()}}function F(b,...E){if(u||!n.apply(this,arguments))return;var S=b.currentTarget,_=M(this,E,!0).event(b),z=O(b.view).on("mousemove.zoom",X,!0).on("mouseup.zoom",dt,!0),V=vt(b,S),D=b.clientX,G=b.clientY;yo(b.view),gn(b),_.mouse=[V,this.__zoom.invert(V)],De(this),_.start();function X(q){if(he(q),!_.moved){var lt=q.clientX-D,gt=q.clientY-G;_.moved=lt*lt+gt*gt>d}_.event(q).zoom("mouse",e(C(_.that.__zoom,_.mouse[0]=vt(q,S),_.mouse[1]),_.extent,i))}function dt(q){z.on("mousemove.zoom mouseup.zoom",null),bo(q.view,_.moved),he(q),_.event(q).end()}}function H(b,...E){if(n.apply(this,arguments)){var S=this.__zoom,_=vt(b.changedTouches?b.changedTouches[0]:b,this),z=S.invert(_),V=S.k*(b.shiftKey?.5:2),D=e(C(w(S,V),_,z),t.apply(this,E),i);he(b),r>0?O(this).transition().duration(r).call(k,D,_,b):O(this).call(v.transform,D,_,b)}}function W(b,...E){if(n.apply(this,arguments)){var S=b.touches,_=S.length,z=M(this,E,b.changedTouches.length===_).event(b),V,D,G,X;for(gn(b),D=0;D<_;++D)G=S[D],X=vt(G,this),X=[X,this.__zoom.invert(X),G.identifier],z.touch0?!z.touch1&&z.touch0[2]!==X[2]&&(z.touch1=X,z.taps=0):(z.touch0=X,V=!0,z.taps=1+!!h);h&&(h=clearTimeout(h)),V&&(z.taps<2&&(f=X[0],h=setTimeout(function(){h=null},p)),De(this),z.start())}}function tt(b,...E){if(this.__zooming){var S=M(this,E).event(b),_=b.changedTouches,z=_.length,V,D,G,X;for(he(b),V=0;V<z;++V)D=_[V],G=vt(D,this),S.touch0&&S.touch0[2]===D.identifier?S.touch0[0]=G:S.touch1&&S.touch1[2]===D.identifier&&(S.touch1[0]=G);if(D=S.that.__zoom,S.touch1){var dt=S.touch0[0],q=S.touch0[1],lt=S.touch1[0],gt=S.touch1[1],ct=(ct=lt[0]-dt[0])*ct+(ct=lt[1]-dt[1])*ct,mt=(mt=gt[0]-q[0])*mt+(mt=gt[1]-q[1])*mt;D=w(D,Math.sqrt(ct/mt)),G=[(dt[0]+lt[0])/2,(dt[1]+lt[1])/2],X=[(q[0]+gt[0])/2,(q[1]+gt[1])/2]}else if(S.touch0)G=S.touch0[0],X=S.touch0[1];else return;S.zoom("touch",e(C(D,G,X),S.extent,i))}}function rt(b,...E){if(this.__zooming){var S=M(this,E).event(b),_=b.changedTouches,z=_.length,V,D;for(gn(b),u&&clearTimeout(u),u=setTimeout(function(){u=null},p),V=0;V<z;++V)D=_[V],S.touch0&&S.touch0[2]===D.identifier?delete S.touch0:S.touch1&&S.touch1[2]===D.identifier&&delete S.touch1;if(S.touch1&&!S.touch0&&(S.touch0=S.touch1,delete S.touch1),S.touch0)S.touch0[1]=this.__zoom.invert(S.touch0[0]);else if(S.end(),S.taps===2&&(D=vt(D,this),Math.hypot(f[0]-D[0],f[1]-D[1])<m)){var G=O(this).on("dblclick.zoom");G&&G.apply(this,arguments)}}}return v.wheelDelta=function(b){return arguments.length?(o=typeof b=="function"?b:_e(+b),v):o},v.filter=function(b){return arguments.length?(n=typeof b=="function"?b:_e(!!b),v):n},v.touchable=function(b){return arguments.length?(s=typeof b=="function"?b:_e(!!b),v):s},v.extent=function(b){return arguments.length?(t=typeof b=="function"?b:_e([[+b[0][0],+b[0][1]],[+b[1][0],+b[1][1]]]),v):t},v.scaleExtent=function(b){return arguments.length?(a[0]=+b[0],a[1]=+b[1],v):[a[0],a[1]]},v.translateExtent=function(b){return arguments.length?(i[0][0]=+b[0][0],i[1][0]=+b[1][0],i[0][1]=+b[0][1],i[1][1]=+b[1][1],v):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},v.constrain=function(b){return arguments.length?(e=b,v):e},v.duration=function(b){return arguments.length?(r=+b,v):r},v.interpolate=function(b){return arguments.length?(l=b,v):l},v.on=function(){var b=c.on.apply(c,arguments);return b===c?v:b},v.clickDistance=function(b){return arguments.length?(d=(b=+b)*b,v):Math.sqrt(d)},v.tapDistance=function(b){return arguments.length?(m=+b,v):m},v}var Vn=function(n,t){return Vn=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,o){e.__proto__=o}||function(e,o){for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(e[s]=o[s])},Vn(n,t)};function Dt(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Vn(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function Kl(n,t,e,o){function s(a){return a instanceof e?a:new e(function(i){i(a)})}return new(e||(e=Promise))(function(a,i){function r(h){try{c(o.next(h))}catch(f){i(f)}}function l(h){try{c(o.throw(h))}catch(f){i(f)}}function c(h){h.done?a(h.value):s(h.value).then(r,l)}c((o=o.apply(n,t||[])).next())})}function Po(n,t){var e={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},o,s,a,i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=r(0),i.throw=r(1),i.return=r(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function r(c){return function(h){return l([c,h])}}function l(c){if(o)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(e=0)),e;)try{if(o=1,s&&(a=c[0]&2?s.return:c[0]?s.throw||((a=s.return)&&a.call(s),0):s.next)&&!(a=a.call(s,c[1])).done)return a;switch(s=0,a&&(c=[c[0]&2,a.value]),c[0]){case 0:case 1:a=c;break;case 4:return e.label++,{value:c[1],done:!1};case 5:e.label++,s=c[1],c=[0];continue;case 7:c=e.ops.pop(),e.trys.pop();continue;default:if(a=e.trys,!(a=a.length>0&&a[a.length-1])&&(c[0]===6||c[0]===2)){e=0;continue}if(c[0]===3&&(!a||c[1]>a[0]&&c[1]<a[3])){e.label=c[1];break}if(c[0]===6&&e.label<a[1]){e.label=a[1],a=c;break}if(a&&e.label<a[2]){e.label=a[2],e.ops.push(c);break}a[2]&&e.ops.pop(),e.trys.pop();continue}c=t.call(n,e)}catch(h){c=[6,h],s=0}finally{o=a=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function oe(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],o=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&o>=n.length&&(n=void 0),{value:n&&n[o++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function We(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var o=e.call(n),s,a=[],i;try{for(;(t===void 0||t-- >0)&&!(s=o.next()).done;)a.push(s.value)}catch(r){i={error:r}}finally{try{s&&!s.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return a}function qe(n,t,e){if(e||arguments.length===2)for(var o=0,s=t.length,a;o<s;o++)(a||!(o in t))&&(a||(a=Array.prototype.slice.call(t,0,o)),a[o]=t[o]);return n.concat(a||Array.prototype.slice.call(t))}function Jt(n){return this instanceof Jt?(this.v=n,this):new Jt(n)}function Zl(n,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o=e.apply(n,t||[]),s,a=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),r("next"),r("throw"),r("return",i),s[Symbol.asyncIterator]=function(){return this},s;function i(p){return function(g){return Promise.resolve(g).then(p,f)}}function r(p,g){o[p]&&(s[p]=function(d){return new Promise(function(m,v){a.push([p,d,m,v])>1||l(p,d)})},g&&(s[p]=g(s[p])))}function l(p,g){try{c(o[p](g))}catch(d){u(a[0][3],d)}}function c(p){p.value instanceof Jt?Promise.resolve(p.value.v).then(h,f):u(a[0][2],p)}function h(p){l("next",p)}function f(p){l("throw",p)}function u(p,g){p(g),a.shift(),a.length&&l(a[0][0],a[0][1])}}function Ql(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=n[Symbol.asyncIterator],e;return t?t.call(n):(n=typeof oe=="function"?oe(n):n[Symbol.iterator](),e={},o("next"),o("throw"),o("return"),e[Symbol.asyncIterator]=function(){return this},e);function o(a){e[a]=n[a]&&function(i){return new Promise(function(r,l){i=n[a](i),s(r,l,i.done,i.value)})}}function s(a,i,r,l){Promise.resolve(l).then(function(c){a({value:c,done:r})},i)}}function Q(n){return typeof n=="function"}function Ro(n){var t=function(o){Error.call(o),o.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var mn=Ro(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
|
|
2
|
+
`+e.map(function(o,s){return s+1+") "+o.toString()}).join(`
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=e}});function Ke(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var Se=function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,o,s,a;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var r=oe(i),l=r.next();!l.done;l=r.next()){var c=l.value;c.remove(this)}}catch(d){t={error:d}}finally{try{l&&!l.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}else i.remove(this);var h=this.initialTeardown;if(Q(h))try{h()}catch(d){a=d instanceof mn?d.errors:[d]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var u=oe(f),p=u.next();!p.done;p=u.next()){var g=p.value;try{ji(g)}catch(d){a=a??[],d instanceof mn?a=qe(qe([],We(a)),We(d.errors)):a.push(d)}}}catch(d){o={error:d}}finally{try{p&&!p.done&&(s=u.return)&&s.call(u)}finally{if(o)throw o.error}}}if(a)throw new mn(a)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)ji(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Ke(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&Ke(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}(),zo=Se.EMPTY;function Lo(n){return n instanceof Se||n&&"closed"in n&&Q(n.remove)&&Q(n.add)&&Q(n.unsubscribe)}function ji(n){Q(n)?n():n.unsubscribe()}var Vo={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},Do={setTimeout:function(n,t){for(var e=[],o=2;o<arguments.length;o++)e[o-2]=arguments[o];return setTimeout.apply(void 0,qe([n,t],We(e)))},clearTimeout:function(n){var t=Do.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function Fo(n){Do.setTimeout(function(){throw n})}function Hi(){}function Fe(n){n()}var Zn=function(n){Dt(t,n);function t(e){var o=n.call(this)||this;return o.isStopped=!1,e?(o.destination=e,Lo(e)&&e.add(o)):o.destination=nc,o}return t.create=function(e,o,s){return new Dn(e,o,s)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(Se),Jl=Function.prototype.bind;function vn(n,t){return Jl.call(n,t)}var tc=function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(o){Ne(o)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(o){Ne(o)}else Ne(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){Ne(e)}},n}(),Dn=function(n){Dt(t,n);function t(e,o,s){var a=n.call(this)||this,i;if(Q(e)||!e)i={next:e??void 0,error:o??void 0,complete:s??void 0};else{var r;a&&Vo.useDeprecatedNextContext?(r=Object.create(e),r.unsubscribe=function(){return a.unsubscribe()},i={next:e.next&&vn(e.next,r),error:e.error&&vn(e.error,r),complete:e.complete&&vn(e.complete,r)}):i=e}return a.destination=new tc(i),a}return t}(Zn);function Ne(n){Fo(n)}function ec(n){throw n}var nc={closed:!0,next:Hi,error:ec,complete:Hi},Qn=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Oo(n){return n}function ic(n){return n.length===0?Oo:n.length===1?n[0]:function(e){return n.reduce(function(o,s){return s(o)},e)}}var pt=function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,o){var s=this,a=rc(t)?t:new Dn(t,e,o);return Fe(function(){var i=s,r=i.operator,l=i.source;a.add(r?r.call(a,l):l?s._subscribe(a):s._trySubscribe(a))}),a},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var o=this;return e=Xi(e),new e(function(s,a){var i=new Dn({next:function(r){try{t(r)}catch(l){a(l),i.unsubscribe()}},error:a,complete:s});o.subscribe(i)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[Qn]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return ic(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=Xi(t),new t(function(o,s){var a;e.subscribe(function(i){return a=i},function(i){return s(i)},function(){return o(a)})})},n.create=function(t){return new n(t)},n}();function Xi(n){var t;return(t=n??Vo.Promise)!==null&&t!==void 0?t:Promise}function oc(n){return n&&Q(n.next)&&Q(n.error)&&Q(n.complete)}function rc(n){return n&&n instanceof Zn||oc(n)&&Lo(n)}function sc(n){return Q(n==null?void 0:n.lift)}function se(n){return function(t){if(sc(t))return t.lift(function(e){try{return n(e,this)}catch(o){this.error(o)}});throw new TypeError("Unable to lift unknown Observable type")}}function re(n,t,e,o,s){return new ac(n,t,e,o,s)}var ac=function(n){Dt(t,n);function t(e,o,s,a,i,r){var l=n.call(this,e)||this;return l.onFinalize=i,l.shouldUnsubscribe=r,l._next=o?function(c){try{o(c)}catch(h){e.error(h)}}:n.prototype._next,l._error=a?function(c){try{a(c)}catch(h){e.error(h)}finally{this.unsubscribe()}}:n.prototype._error,l._complete=s?function(){try{s()}catch(c){e.error(c)}finally{this.unsubscribe()}}:n.prototype._complete,l}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var o=this.closed;n.prototype.unsubscribe.call(this),!o&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(Zn),lc=Ro(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Ft=function(n){Dt(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var o=new Yi(this,this);return o.operator=e,o},t.prototype._throwIfClosed=function(){if(this.closed)throw new lc},t.prototype.next=function(e){var o=this;Fe(function(){var s,a;if(o._throwIfClosed(),!o.isStopped){o.currentObservers||(o.currentObservers=Array.from(o.observers));try{for(var i=oe(o.currentObservers),r=i.next();!r.done;r=i.next()){var l=r.value;l.next(e)}}catch(c){s={error:c}}finally{try{r&&!r.done&&(a=i.return)&&a.call(i)}finally{if(s)throw s.error}}}})},t.prototype.error=function(e){var o=this;Fe(function(){if(o._throwIfClosed(),!o.isStopped){o.hasError=o.isStopped=!0,o.thrownError=e;for(var s=o.observers;s.length;)s.shift().error(e)}})},t.prototype.complete=function(){var e=this;Fe(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var o=e.observers;o.length;)o.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var o=this,s=this,a=s.hasError,i=s.isStopped,r=s.observers;return a||i?zo:(this.currentObservers=null,r.push(e),new Se(function(){o.currentObservers=null,Ke(r,e)}))},t.prototype._checkFinalizedStatuses=function(e){var o=this,s=o.hasError,a=o.thrownError,i=o.isStopped;s?e.error(a):i&&e.complete()},t.prototype.asObservable=function(){var e=new pt;return e.source=this,e},t.create=function(e,o){return new Yi(e,o)},t}(pt),Yi=function(n){Dt(t,n);function t(e,o){var s=n.call(this)||this;return s.destination=e,s.source=o,s}return t.prototype.next=function(e){var o,s;(s=(o=this.destination)===null||o===void 0?void 0:o.next)===null||s===void 0||s.call(o,e)},t.prototype.error=function(e){var o,s;(s=(o=this.destination)===null||o===void 0?void 0:o.error)===null||s===void 0||s.call(o,e)},t.prototype.complete=function(){var e,o;(o=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||o===void 0||o.call(e)},t.prototype._subscribe=function(e){var o,s;return(s=(o=this.source)===null||o===void 0?void 0:o.subscribe(e))!==null&&s!==void 0?s:zo},t}(Ft),cc={now:function(){return Date.now()},delegate:void 0},hc=function(n){Dt(t,n);function t(e,o){return n.call(this)||this}return t.prototype.schedule=function(e,o){return this},t}(Se),Fn={setInterval:function(n,t){for(var e=[],o=2;o<arguments.length;o++)e[o-2]=arguments[o];return setInterval.apply(void 0,qe([n,t],We(e)))},clearInterval:function(n){var t=Fn.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(n)},delegate:void 0},dc=function(n){Dt(t,n);function t(e,o){var s=n.call(this,e,o)||this;return s.scheduler=e,s.work=o,s.pending=!1,s}return t.prototype.schedule=function(e,o){var s;if(o===void 0&&(o=0),this.closed)return this;this.state=e;var a=this.id,i=this.scheduler;return a!=null&&(this.id=this.recycleAsyncId(i,a,o)),this.pending=!0,this.delay=o,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(i,this.id,o),this},t.prototype.requestAsyncId=function(e,o,s){return s===void 0&&(s=0),Fn.setInterval(e.flush.bind(e,this),s)},t.prototype.recycleAsyncId=function(e,o,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return o;o!=null&&Fn.clearInterval(o)},t.prototype.execute=function(e,o){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(e,o);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,o){var s=!1,a;try{this.work(e)}catch(i){s=!0,a=i||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),a},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,o=e.id,s=e.scheduler,a=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,Ke(a,this),o!=null&&(this.id=this.recycleAsyncId(s,o,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t}(hc),Wi=function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,o){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(o,e)},n.now=cc.now,n}(),uc=function(n){Dt(t,n);function t(e,o){o===void 0&&(o=Wi.now);var s=n.call(this,e,o)||this;return s.actions=[],s._active=!1,s}return t.prototype.flush=function(e){var o=this.actions;if(this._active){o.push(e);return}var s;this._active=!0;do if(s=e.execute(e.state,e.delay))break;while(e=o.shift());if(this._active=!1,s){for(;e=o.shift();)e.unsubscribe();throw s}},t}(Wi),Jn=new uc(dc),fc=Jn,Bo=new pt(function(n){return n.complete()});function Go(n){return n&&Q(n.schedule)}function Uo(n){return n[n.length-1]}function pc(n){return Go(Uo(n))?n.pop():void 0}function gc(n,t){return typeof Uo(n)=="number"?n.pop():t}var jo=function(n){return n&&typeof n.length=="number"&&typeof n!="function"};function Ho(n){return Q(n==null?void 0:n.then)}function Xo(n){return Q(n[Qn])}function Yo(n){return Symbol.asyncIterator&&Q(n==null?void 0:n[Symbol.asyncIterator])}function Wo(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function mc(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var qo=mc();function Ko(n){return Q(n==null?void 0:n[qo])}function Zo(n){return Zl(this,arguments,function(){var e,o,s,a;return Po(this,function(i){switch(i.label){case 0:e=n.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,Jt(e.read())];case 3:return o=i.sent(),s=o.value,a=o.done,a?[4,Jt(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,Jt(s)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function Qo(n){return Q(n==null?void 0:n.getReader)}function Xt(n){if(n instanceof pt)return n;if(n!=null){if(Xo(n))return vc(n);if(jo(n))return yc(n);if(Ho(n))return bc(n);if(Yo(n))return Jo(n);if(Ko(n))return wc(n);if(Qo(n))return xc(n)}throw Wo(n)}function vc(n){return new pt(function(t){var e=n[Qn]();if(Q(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function yc(n){return new pt(function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()})}function bc(n){return new pt(function(t){n.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,Fo)})}function wc(n){return new pt(function(t){var e,o;try{for(var s=oe(n),a=s.next();!a.done;a=s.next()){var i=a.value;if(t.next(i),t.closed)return}}catch(r){e={error:r}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(e)throw e.error}}t.complete()})}function Jo(n){return new pt(function(t){Cc(n,t).catch(function(e){return t.error(e)})})}function xc(n){return Jo(Zo(n))}function Cc(n,t){var e,o,s,a;return Kl(this,void 0,void 0,function(){var i,r;return Po(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),e=Ql(n),l.label=1;case 1:return[4,e.next()];case 2:if(o=l.sent(),!!o.done)return[3,4];if(i=o.value,t.next(i),t.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return r=l.sent(),s={error:r},[3,11];case 6:return l.trys.push([6,,9,10]),o&&!o.done&&(a=e.return)?[4,a.call(e)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function Ut(n,t,e,o,s){o===void 0&&(o=0),s===void 0&&(s=!1);var a=t.schedule(function(){e(),s?n.add(this.schedule(null,o)):this.unsubscribe()},o);if(n.add(a),!s)return a}function tr(n,t){return t===void 0&&(t=0),se(function(e,o){e.subscribe(re(o,function(s){return Ut(o,n,function(){return o.next(s)},t)},function(){return Ut(o,n,function(){return o.complete()},t)},function(s){return Ut(o,n,function(){return o.error(s)},t)}))})}function er(n,t){return t===void 0&&(t=0),se(function(e,o){o.add(n.schedule(function(){return e.subscribe(o)},t))})}function kc(n,t){return Xt(n).pipe(er(t),tr(t))}function Sc(n,t){return Xt(n).pipe(er(t),tr(t))}function Ac(n,t){return new pt(function(e){var o=0;return t.schedule(function(){o===n.length?e.complete():(e.next(n[o++]),e.closed||this.schedule())})})}function Ic(n,t){return new pt(function(e){var o;return Ut(e,t,function(){o=n[qo](),Ut(e,t,function(){var s,a,i;try{s=o.next(),a=s.value,i=s.done}catch(r){e.error(r);return}i?e.complete():e.next(a)},0,!0)}),function(){return Q(o==null?void 0:o.return)&&o.return()}})}function nr(n,t){if(!n)throw new Error("Iterable cannot be null");return new pt(function(e){Ut(e,t,function(){var o=n[Symbol.asyncIterator]();Ut(e,t,function(){o.next().then(function(s){s.done?e.complete():e.next(s.value)})},0,!0)})})}function Tc(n,t){return nr(Zo(n),t)}function Ec(n,t){if(n!=null){if(Xo(n))return kc(n,t);if(jo(n))return Ac(n,t);if(Ho(n))return Sc(n,t);if(Yo(n))return nr(n,t);if(Ko(n))return Ic(n,t);if(Qo(n))return Tc(n,t)}throw Wo(n)}function $c(n,t){return t?Ec(n,t):Xt(n)}function Mc(n){return n instanceof Date&&!isNaN(n)}function ti(n,t){return se(function(e,o){var s=0;e.subscribe(re(o,function(a){o.next(n.call(t,a,s++))}))})}function _c(n,t,e,o,s,a,i,r){var l=[],c=0,h=0,f=!1,u=function(){f&&!l.length&&!c&&t.complete()},p=function(d){return c<o?g(d):l.push(d)},g=function(d){c++;var m=!1;Xt(e(d,h++)).subscribe(re(t,function(v){t.next(v)},function(){m=!0},void 0,function(){if(m)try{c--;for(var v=function(){var w=l.shift();i||g(w)};l.length&&c<o;)v();u()}catch(w){t.error(w)}}))};return n.subscribe(re(t,p,function(){f=!0,u()})),function(){}}function ei(n,t,e){return e===void 0&&(e=1/0),Q(t)?ei(function(o,s){return ti(function(a,i){return t(o,a,s,i)})(Xt(n(o,s)))},e):(typeof t=="number"&&(e=t),se(function(o,s){return _c(o,s,n,e)}))}function Nc(n){return n===void 0&&(n=1/0),ei(Oo,n)}function Pc(n,t,e){e===void 0&&(e=fc);var o=-1;return t!=null&&(Go(t)?e=t:o=t),new pt(function(s){var a=Mc(n)?+n-e.now():n;a<0&&(a=0);var i=0;return e.schedule(function(){s.closed||(s.next(i++),0<=o?this.schedule(void 0,o):s.complete())},a)})}function Rc(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=pc(n),o=gc(n,1/0),s=n;return s.length?s.length===1?Xt(s[0]):Nc(o)($c(s,e)):Bo}function zc(n,t){return t===void 0&&(t=Jn),se(function(e,o){var s=null,a=null,i=null,r=function(){if(s){s.unsubscribe(),s=null;var c=a;a=null,o.next(c)}};function l(){var c=i+n,h=t.now();if(h<c){s=this.schedule(void 0,c-h),o.add(s);return}r()}e.subscribe(re(o,function(c){a=c,i=t.now(),s||(s=t.schedule(l,n),o.add(s))},function(){r(),o.complete()},void 0,function(){a=s=null}))})}function Lc(n){return n<=0?function(){return Bo}:se(function(t,e){var o=0;t.subscribe(re(e,function(s){++o<=n&&(e.next(s),n<=o&&e.complete())}))})}function Vc(n){return ti(function(){return n})}function Dc(n,t){return ei(function(e,o){return Xt(n(e,o)).pipe(Lc(1),Vc(e))})}function Fc(n,t){t===void 0&&(t=Jn);var e=Pc(n,t);return Dc(function(){return e})}const Pe=n=>[Math.round(n[0]),Math.round(n[1])],Rt=(n,t,e)=>t<e?t<=n&&n<=e:e<=n&&n<=t,qi=(n,t,e)=>(n-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Ze=(n,t,e,o,s)=>[qi(n[0],t,o),qi(n[1],e,s)],ir=(n,t)=>((n[0]-t[0])**2+(n[1]-t[1])**2)**.5,Oc=(n,t)=>(Rt(n[0][0],t[0][0],t[1][0])||Rt(n[1][0],t[1][0],t[0][0])||Rt(t[0][0],n[0][0],n[1][0])||Rt(t[1][0],n[1][0],n[0][0]))&&(Rt(n[0][1],t[0][1],t[1][1])||Rt(n[1][1],t[1][1],t[0][1])||Rt(t[0][1],n[0][1],n[1][1])||Rt(t[1][1],n[1][1],n[0][1]));var T=(n=>(n.Blur="blur",n.Change="change",n.Click="click",n.ContextMenu="contextmenu",n.DoubleClick="dblclick",n.Focus="focus",n.FocusIn="focusin",n.FocusOut="focusout",n.Input="input",n.KeyDown="keydown",n.KeyUp="keyup",n.MouseDown="mousedown",n.MouseEnter="mouseenter",n.MouseLeave="mouseleave",n.MouseMove="mousemove",n.MouseOut="mouseout",n.MouseOver="mouseover",n.MouseUp="mouseup",n.TouchStart="touchstart",n.TouchEnd="touchend",n.Wheel="wheel",n))(T||{}),Et=(n=>(n.Alt="Alt",n.AltGraph="AltGraph",n.ArrowDown="ArrowDown",n.ArrowLeft="ArrowLeft",n.ArrowRight="ArrowRight",n.ArrowUp="ArrowUp",n.Backspace="Backspace",n.Control="Control",n.Delete="Delete",n.End="End",n.Enter="Enter",n.Escape="Escape",n.Home="Home",n.OS="OS",n.PageDown="PageDown",n.PageUp="PageUp",n.Shift="Shift",n.Tab="Tab",n))(Et||{}),P=(n=>(n.Drag="drag",n.Start="start",n.End="end",n))(P||{}),On=(n=>(n.Zoom="zoom",n.Start="start",n.End="end",n))(On||{}),or=(n=>(n.Straight="straight",n.Bezier="bezier",n.Square="square",n))(or||{}),rr=(n=>(n.Solid="solid",n.Dashed="dashed",n.GappedDashes="gapped-dashes",n.Dotted="dotted",n))(rr||{});const Bc=20,Gc=(n,t,e,o,s)=>{if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{s=s||Bc;let a="",i,r;switch(n){case"straight":a+=`M ${t[0][0]} ${t[0][1]}`;for(let l=1;l<t.length;++l)a+=` L ${t[l][0]} ${t[l][1]}`;break;case"bezier":i=e,a+=`M ${t[0][0]} ${t[0][1]}`;for(let l=1;l<t.length;++l){if(l+1>=t.length?r=o:Math.abs(t[l][0]-t[l-1][0])<Math.abs(t[l][1]-t[l-1][1])?t[l][1]>t[l-1][1]?r=x.Bottom:r=x.Top:t[l][0]>t[l-1][0]?r=x.Right:r=x.Left,i!==void 0){let c="",h="";const f=(Math.abs(t[l][0]-t[l-1][0])+Math.abs(t[l][1]-t[l-1][1]))/2;switch(i){case x.Bottom:c=`${t[l-1][0]} ${t[l-1][1]+f}`;break;case x.Top:c=`${t[l-1][0]} ${t[l-1][1]-f}`;break;case x.Right:c=`${t[l-1][0]+f} ${t[l-1][1]}`;break;case x.Left:c=`${t[l-1][0]-f} ${t[l-1][1]}`;break}if(r!==void 0){switch(r){case x.Bottom:h=`${t[l][0]} ${t[l][1]+f}`;break;case x.Top:h=`${t[l][0]} ${t[l][1]-f}`;break;case x.Right:h=`${t[l][0]+f} ${t[l][1]}`;break;case x.Left:h=`${t[l][0]-f} ${t[l][1]}`;break}a+=` C ${c} ${h} ${t[l][0]} ${t[l][1]}`}else a+=` Q ${c} ${t[l][0]} ${t[l][1]}`}else if(r!==void 0){let c="";const h=(Math.abs(t[l][0]-t[l-1][0])+Math.abs(t[l][1]-t[l-1][1]))/2;switch(r){case x.Bottom:c=`${t[l][0]} ${t[l][1]+h}`;break;case x.Top:c=`${t[l][0]} ${t[l][1]-h}`;break;case x.Right:c=`${t[l][0]+h} ${t[l][1]}`;break;case x.Left:c=`${t[l][0]-h} ${t[l][1]}`;break}a+=` Q ${c} ${t[l][0]} ${t[l][1]}`}else a+=` L ${t[l][0]} ${t[l][1]}`;i=r}break;case"square":if(a+=`M ${t[0][0]} ${t[0][1]}`,e)switch(e){case x.Bottom:t.splice(1,0,[t[0][0],t[0][1]+s]);break;case x.Top:t.splice(1,0,[t[0][0],t[0][1]-s]);break;case x.Right:t.splice(1,0,[t[0][0]+s,t[0][1]]);break;case x.Left:t.splice(1,0,[t[0][0]-s,t[0][1]]);break}if(o)switch(o){case x.Bottom:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]+s]);break;case x.Top:t.splice(t.length-1,0,[t[t.length-1][0],t[t.length-1][1]-s]);break;case x.Right:t.splice(t.length-1,0,[t[t.length-1][0]+s,t[t.length-1][1]]);break;case x.Left:t.splice(t.length-1,0,[t[t.length-1][0]-s,t[t.length-1][1]]);break}for(let l=1;l<t.length;++l)if(i!==void 0)switch(i){case x.Bottom:t[l][1]<t[l-1][1]&&t[l][0]!==t[l-1][0]?(a+=` H ${t[l][0]}`,a+=` V ${t[l][1]}`,i=x.Top):t[l][1]<t[l-1][1]&&t[l][0]===t[l-1][0]?(a+=` H ${t[l][0]+s}`,a+=` V ${t[l][1]}`,a+=` H ${t[l][0]}`,i=x.Left):t[l][1]===t[l-1][1]&&t[l][0]!==t[l-1][0]?(a+=` H ${t[l][0]}`,i=t[l][0]>t[l-1][0]?x.Right:x.Left):t[l][1]>t[l-1][1]&&t[l][0]!==t[l-1][0]?(a+=` H ${t[l][0]}`,a+=` V ${t[l][1]}`):t[l][1]>t[l-1][1]&&t[l][0]===t[l-1][0]&&(a+=` V ${t[l][1]}`);break;case x.Top:t[l][1]>t[l-1][1]&&t[l][0]!==t[l-1][0]?(a+=` H ${t[l][0]}`,a+=` V ${t[l][1]}`,i=x.Bottom):t[l][1]>t[l-1][1]&&t[l][0]===t[l-1][0]?(a+=` H ${t[l][0]-s}`,a+=` V ${t[l][1]}`,a+=` H ${t[l][0]}`,i=x.Right):t[l][1]===t[l-1][1]&&t[l][0]!==t[l-1][0]?(a+=` H ${t[l][0]}`,i=t[l][0]>t[l-1][0]?x.Right:x.Left):t[l][1]<t[l-1][1]&&t[l][0]!==t[l-1][0]?(a+=` H ${t[l][0]}`,a+=` V ${t[l][1]}`):t[l][1]<t[l-1][1]&&t[l][0]===t[l-1][0]&&(a+=` V ${t[l][1]}`);break;case x.Right:t[l][0]<t[l-1][0]&&t[l][1]!==t[l-1][1]?(a+=` V ${t[l][1]}`,a+=` H ${t[l][0]}`,i=x.Left):t[l][0]<t[l-1][0]&&t[l][1]===t[l-1][1]?(a+=` V ${t[l][1]+s}`,a+=` H ${t[l][0]}`,a+=` V ${t[l][1]}`,i=x.Top):t[l][0]===t[l-1][0]&&t[l][1]!==t[l-1][1]?(a+=` V ${t[l][1]}`,i=t[l][1]>t[l-1][1]?x.Bottom:x.Top):t[l][0]>t[l-1][0]&&t[l][1]!==t[l-1][1]?(a+=` V ${t[l][1]}`,a+=` H ${t[l][0]}`):t[l][0]>t[l-1][0]&&t[l][1]===t[l-1][1]&&(a+=` H ${t[l][0]}`);break;case x.Left:t[l][0]>t[l-1][0]&&t[l][1]!==t[l-1][1]?(a+=` V ${t[l][1]}`,a+=` H ${t[l][0]}`,i=x.Right):t[l][0]>t[l-1][0]&&t[l][1]===t[l-1][1]?(a+=` V ${t[l][1]-s}`,a+=` H ${t[l][0]}`,a+=` V ${t[l][1]}`,i=x.Bottom):t[l][0]===t[l-1][0]&&t[l][1]!==t[l-1][1]?(a+=` V ${t[l][1]}`,i=t[l][1]>t[l-1][1]?x.Bottom:x.Top):t[l][0]<t[l-1][0]&&t[l][1]!==t[l-1][1]?(a+=` V ${t[l][1]}`,a+=` H ${t[l][0]}`):t[l][0]<t[l-1][0]&&t[l][1]===t[l-1][1]&&(a+=` H ${t[l][0]}`);break}else t[l][0]!==t[l-1][0]&&(a+=` H ${t[l][0]}`,i=t[l][0]>t[l-1][0]?x.Right:x.Left),t[l][1]!==t[l-1][1]&&(a+=` V ${t[l][1]}`,i=t[l][1]>t[l-1][1]?x.Bottom:x.Top);break}return a}},Ki=(n,t)=>{switch(n){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},K=(n,t)=>{const e=n.indexOf(t);return e>=0&&n.splice(e,1),n};var rn=(n=>(n.Ellipse="ellipse",n.Empty="empty",n.Folder="folder",n.Hexagon="hexagon",n.Octagon="octagon",n.Pill="pill",n.Rectangle="rectangle",n.Rhombus="rhombus",n.RoundedRectangle="rounded-rectangle",n.StickyNote="sticky-note",n))(rn||{});const Qe=(n,t,e,o,s)=>{if(typeof n=="function")return n(t,e,o,s);switch(n){case"ellipse":return sr(t,e,o,s);case"empty":return Uc();case"folder":return jc(t,e,o,s);case"hexagon":return Hc(t,e,o,s);case"octagon":return Xc(t,e,o,s);case"pill":return Oe(t,e,o,s);case"rectangle":return Zi(t,e,o,s);case"rhombus":return Yc(t,e,o,s);case"rounded-rectangle":return Wc(t,e,o,s);case"sticky-note":return qc(t,e,o,s);default:return Zi(t,e,o,s)}},sr=(n,t,e,o)=>`M ${n+e/2} ${t} A ${e/2} ${o/2} 0 0 0 ${n+e/2} ${t+o} A ${e/2} ${o/2} 0 1 0 ${n+e/2} ${t} Z`,Uc=()=>"Z",jc=(n,t,e,o)=>`M ${n} ${t} L ${n+e/3} ${t} L ${n+e/2} ${t+o/6} L ${n+e} ${t+o/6} L ${n+e} ${t+o} L ${n} ${t+o} Z`,Hc=(n,t,e,o)=>`M ${n+e/4} ${t} L ${n+3*e/4} ${t} L ${n+e} ${t+o/2} L ${n+3*e/4} ${t+o} L ${n+e/4} ${t+o} L ${n} ${t+o/2} Z`,Xc=(n,t,e,o)=>`M ${n+e/4} ${t} L ${n+3*e/4} ${t} L ${n+e} ${t+o/4} L ${n+e} ${t+3*o/4} L ${n+3*e/4} ${t+o} L ${n+e/4} ${t+o} L ${n} ${t+3*o/4} L ${n} ${t+o/4} L ${n+e/4} ${t} Z`,Oe=(n,t,e,o)=>o<e?`M ${n+o/2} ${t} L ${n+e-o/2} ${t} A ${o/2} ${o/2} 0 0 1 ${n+e} ${t+o/2} A ${o/2} ${o/2} 0 0 1 ${n+e-o/2} ${t+o} L ${n+o/2} ${t+o} A ${o/2} ${o/2} 0 0 1 ${n} ${t+o/2} A ${o/2} ${o/2} 0 0 1 ${n+o/2} ${t} Z`:o>e?`M ${n} ${t+e/2} L ${n} ${t+o-e/2} A ${e/2} ${e/2} 0 0 0 ${n+e/2} ${t+o} A ${e/2} ${e/2} 0 0 0 ${n+e} ${t+o-e/2} L ${n+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${n+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${n} ${t+e/2} Z`:sr(n,t,e,o),Zi=(n,t,e,o)=>`M ${n} ${t} L ${n+e} ${t} L ${n+e} ${t+o} L ${n} ${t+o} Z`,Yc=(n,t,e,o)=>`M ${n+e/2} ${t} L ${n+e} ${t+o/2} L ${n+e/2} ${t+o} L ${n} ${t+o/2} Z`,Wc=(n,t,e,o)=>`M ${n+e/4} ${t} L ${n+3*e/4} ${t} A ${e/4} ${o/4} 0 0 1 ${n+e} ${t+o/4} L ${n+e} ${t+3*o/4} A ${e/4} ${o/4} 0 0 1 ${n+3*e/4} ${t+o} L ${n+e/4} ${t+o} A ${e/4} ${o/4} 0 0 1 ${n} ${t+3*o/4} L ${n} ${t+o/4} A ${e/4} ${o/4} 0 0 1 ${n+e/4} ${t} Z`,qc=(n,t,e,o)=>`M ${n} ${t} L ${n+3*e/4} ${t} L ${n+3*e/4} ${t+o/4} L ${n+3*e/4} ${t} L ${n+e} ${t+o/4} L ${n+3*e/4} ${t+o/4} L ${n+e} ${t+o/4} L ${n+e} ${t+o} L ${n} ${t+o} Z`;var L=(n=>(n.AllScroll="all-scroll",n.Auto="auto",n.Crosshair="crosshair",n.EWResize="ew-resize",n.Grab="grab",n.Grabbing="grabbing",n.Move="move",n.NoDrop="no-drop",n.NSResize="ns-resize",n.NotAllowed="not-allowed",n.ZoomIn="zoom-in",n.ZoomOut="zoom-out",n))(L||{});const Kc=n=>Math.max(...n.split(`
|
|
4
|
+
`).map(t=>t.length)),Zc=n=>{var t;return((t=n.match(/\n/g))==null?void 0:t.length)||0},et=[];for(let n=0;n<256;++n)et.push((n+256).toString(16).slice(1));function Qc(n,t=0){return(et[n[t+0]]+et[n[t+1]]+et[n[t+2]]+et[n[t+3]]+"-"+et[n[t+4]]+et[n[t+5]]+"-"+et[n[t+6]]+et[n[t+7]]+"-"+et[n[t+8]]+et[n[t+9]]+"-"+et[n[t+10]]+et[n[t+11]]+et[n[t+12]]+et[n[t+13]]+et[n[t+14]]+et[n[t+15]]).toLowerCase()}let yn;const Jc=new Uint8Array(16);function th(){if(!yn){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");yn=crypto.getRandomValues.bind(crypto)}return yn(Jc)}const eh=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Qi={randomUUID:eh};function Ji(n,t,e){if(Qi.randomUUID&&!t&&!n)return Qi.randomUUID();n=n||{};const o=n.random||(n.rng||th)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Qc(o)}class ni{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],K(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Ae=0;class Yt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userHighlight)==null?void 0:e.contains(this.id))||!1}get selected(){var t,e;return((e=(t=this.model.canvas)==null?void 0:t.userSelection)==null?void 0:e.contains(this.id))||!1}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`g#${this.id}`)}}class Pt extends ni{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,s,a)=>t(o,s,a)&&!o.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((o,s,a)=>t(o,s,a)&&!o.removed)}find(t,e=!1){return e?super.find(t):super.find((o,s,a)=>t(o,s,a)&&!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],K(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}}function ae(n,t){return!t||n[0]>t[0]?!0:n[0]===t[0]?n[1]>=t[1]:!1}class nh{constructor(t,e,o,s,a,i){this.name=t,this.type=e,this.defaultValue=o,this.basic=s,this.editable=a,this.rootAttribute=i,this.options=void 0,this.properties=void 0}}var ye=(n=>(n.Boolean="boolean",n.Color="color",n.Date="date",n.Datetime="datetime",n.Number="number",n.Object="object",n.Option="option",n.OptionList="option-list",n.OptionSet="option-set",n.Text="text",n.TextArea="text-area",n.TextList="text-list",n.TextSet="text-set",n.TextMap="text-map",n.Time="time",n.Url="url",n))(ye||{});class sn{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}class le{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 s=0;s<t.length-1;++s){const a=t[s];if(o==null)return;o=o[a]}if(o==null)return;o[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}getValue(t){var s;const e=(s=this.propertySet.getProperty(t))==null?void 0:s.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 s=this.ownTimestamps[e];s&&(t[e]=s)}return t}hasValue(t){const e=this.getValue(t);return!to(e)}hasSetValue(t){const e=this.getValue(t),o=this.propertySet.getProperty(t);return o&&o.type==="object"?this.getSubValueSet(t).hasAnySetValue():!to(e)&&!be(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,be(e,o.defaultValue)||this.displayProperty(o));const s=o.rootAttribute;s!=null&&this.setRootElementValue(s,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):ae(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?this.setRootElementValue(o,this.values[t]):this.values[t]=this.getRootElementValue(o)),e.basic?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),o=new sn(e.properties),s=new le(o,this.rootElement);return s.overwriteValues(structuredClone(e.defaultValue)),s}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),K(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),K(this.displayedProperties,t))}}const to=n=>n==null||n===""||n instanceof Array&&n.length===0||n instanceof Object&&Object.keys(n).length===0,be=(n,t)=>n===t||JSON.stringify(n)===JSON.stringify(t),ar=(n,t)=>{const e={},o={},s=[];for(const a in n)s.push(a);for(const a in t)a in n||s.push(a);for(const a of s)if(Bn(n[a])&&Bn(t[a])){const i=ar(n[a],t[a]);Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(e[a]=i[0],o[a]=i[1])}else be(n[a],t[a])||(e[a]=n[a],o[a]=t[a]);return[e,o]},Bn=n=>n!=null&&n.constructor===Object,ih={name:"",width:1,shape:or.Straight,style:rr.Solid,label:null,defaultStartMarkerLook:null,defaultEndMarkerLook:null,startTypes:[],endTypes:[],color:"#000000",selectedColor:"#000000",properties:[]};class lr{constructor(t){const e={...ih,...t};this.id=e.id,this.name=e.name,this.width=e.width,this.shape=e.shape,this.style=e.style,this.label=e.label,this.defaultStartMarkerLook=e.defaultStartMarkerLook,this.defaultEndMarkerLook=e.defaultEndMarkerLook,this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.color=e.color,this.selectedColor=e.selectedColor,this.propertySet=new sn(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class Ct extends Yt{constructor(t,e,o,s,a){if(t.connections.get(a)!==void 0)throw new Error(`DiagramConnection with id "${a}" already exists`);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 le(e.propertySet,this),this.originalData={},this.startMarkerLook=e.defaultStartMarkerLook,this.endMarkerLook=e.defaultEndMarkerLook,this.setStart(o),this.setEnd(s)}get name(){return this.middleLabel}set name(t){this.middleLabel=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateConnectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}setStart(t){this.start!==t?(this.start!==void 0&&K(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.coords)||[0,0])):(this.startDirection=t==null?void 0:t.direction,this.startCoords=(t==null?void 0:t.coords)||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&K(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.coords)||[0,0])):(this.endDirection=t==null?void 0:t.direction,this.endCoords=(t==null?void 0:t.coords)||[0,0]),this.updateInView()}tighten(){var t,e;if((t=this.start)!=null&&t.rootElement&&this.end){const o=this.start.rootElement.ports.map(s=>[s,s.distanceTo(this.end.coords)]).sort((s,a)=>s[1]-a[1]).map(s=>s[0]);t:for(const s of o){if(s===this.end)continue t;{for(const a of s.outgoingConnections)if(a!==this&&a.end===this.end)continue t;for(const a of s.incomingConnections)if(a!==this&&a.start===this.end)continue t}if(s===this.start)break t;this.setStart(s);break t}}if((e=this.end)!=null&&e.rootElement&&this.start){const o=this.end.rootElement.ports.map(s=>[s,s.distanceTo(this.start.coords)]).sort((s,a)=>s[1]-a[1]).map(s=>s[0]);t:for(const s of o){if(s===this.start)continue t;{for(const a of s.incomingConnections)if(a!==this&&a.start===this.start)continue t;for(const a of s.outgoingConnections)if(a!==this&&a.end===this.start)continue t}if(s===this.end)break t;this.setEnd(s);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Ae}}class oh extends Pt{constructor(t){super(),this.types=new ni,this.model=t}new(t,e,o,s){let a;if(t instanceof lr)a=t;else{const r=this.types.get(t);if(r===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);a=r}const i=new Ct(this.model,a,e,o,s);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){var o,s;const e=this.get(t,!0);e&&(K(((o=e.start)==null?void 0:o.outgoingConnections)||[],e),K(((s=e.end)==null?void 0:s.incomingConnections)||[],e),super.remove(t),e.updateInView())}}const U={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",horizontalAlign:Kt.Center,verticalAlign:Be.Center,fit:!1};class Mt extends Yt{constructor(t,e,o,s,a,i,r,l,c,h,f,u,p,g){const d=`${e==null?void 0:e.id}_field`;if(t.fields.get(d)!==void 0)throw new Error("DiagramField for rootElement already exists");super(t,d),this.textTimestamp=null,this.rootElement=e,this.coords=o,this.width=s,this.height=a,this.fontSize=i,this.fontFamily=r,this.color=l,this.selectedColor=c,this.horizontalAlign=h,this.verticalAlign=f,this.defaultText=u,this._text=u,this.editable=p,this.fit=g}get text(){return this._text}set text(t){var e;t.trim()===""&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&((e=this.model.canvas)==null||e.fitFieldRootInView(this.id))}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateFieldsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||Ae}}class rh extends Pt{constructor(t){super(),this.model=t}new(t,e,o,s,a,i,r,l,c,h,f,u,p){const g=new Mt(this.model,t,e,r,l,o,s,a,i,c,h,f,u,p);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 kt=n=>(n==null?void 0:n.margin)===null||(n==null?void 0:n.margin)===void 0?U.margin:typeof n.margin=="number"?n.margin:n.margin.length===0?U.margin:n.margin.length===1||n.margin.length===2?n.margin[0]:(n.margin.length===3,n.margin[2]),it=n=>(n==null?void 0:n.margin)===null||(n==null?void 0:n.margin)===void 0?U.margin:typeof n.margin=="number"?n.margin:n.margin.length===0?U.margin:n.margin.length===1?n.margin[0]:n.margin.length===2||n.margin.length===3?n.margin[1]:n.margin[3],St=n=>(n==null?void 0:n.margin)===null||(n==null?void 0:n.margin)===void 0?U.margin:typeof n.margin=="number"?n.margin:n.margin.length===0?U.margin:n.margin.length===1?n.margin[0]:(n.margin.length===2||n.margin.length===3,n.margin[1]),ot=n=>(n==null?void 0:n.margin)===null||(n==null?void 0:n.margin)===void 0?U.margin:typeof n.margin=="number"?n.margin:n.margin.length===0?U.margin:(n.margin.length===1||n.margin.length===2||n.margin.length===3,n.margin[0]),bn=n=>(n==null?void 0:n.padding)===null||(n==null?void 0:n.padding)===void 0?U.padding:typeof n.padding=="number"?n.padding:n.padding.length===0?U.padding:n.padding.length===1||n.padding.length===2?n.padding[0]:(n.padding.length===3,n.padding[2]),wn=n=>(n==null?void 0:n.padding)===null||(n==null?void 0:n.padding)===void 0?U.padding:typeof n.padding=="number"?n.padding:n.padding.length===0?U.padding:n.padding.length===1?n.padding[0]:n.padding.length===2||n.padding.length===3?n.padding[1]:n.padding[3],xn=n=>(n==null?void 0:n.padding)===null||(n==null?void 0:n.padding)===void 0?U.padding:typeof n.padding=="number"?n.padding:n.padding.length===0?U.padding:n.padding.length===1?n.padding[0]:(n.padding.length===2||n.padding.length===3,n.padding[1]),Cn=n=>(n==null?void 0:n.padding)===null||(n==null?void 0:n.padding)===void 0?U.padding:typeof n.padding=="number"?n.padding:n.padding.length===0?U.padding:(n.padding.length===1||n.padding.length===2||n.padding.length===3,n.padding[0]),sh={lookType:"shaped-look",shape:rn.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",selectedFillColor:"#FFFFFF",selectedBorderColor:"#000000"},ah={label:null,ports:[],look:sh,priority:Ae},eo=1,no=1,lh=1,ch=1;class nt extends Yt{constructor(t,e,o,s,a,i,r,l){if(t.sections.get(l)!==void 0)throw new Error(`DiagramSection with id "${l}" already exists`);super(t,l),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=o,this.indexYInNode=s,this.coords=a,this.width=i,this.height=r}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateSectionsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.decorators)e.raise()}getConfig(){var t,e,o,s,a;return(a=(s=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.sections)==null?void 0:s[this.indexYInNode])==null?void 0:a[this.indexXInNode]}getMinWidth(){var t,e,o,s;return((s=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.minWidths)==null?void 0:s[this.indexXInNode])||lh}getMinHeight(){var t,e,o,s;return((s=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.minHeights)==null?void 0:s[this.indexYInNode])||ch}getPriority(){var t,e,o,s,a,i;return((i=(a=(s=(o=(e=(t=this.node)==null?void 0:t.type)==null?void 0:e.sectionGrid)==null?void 0:o.sections)==null?void 0:s[this.indexYInNode])==null?void 0:a[this.indexXInNode])==null?void 0:i.priority)||ah.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)),o=e.indexOf(Math.min(...e));return this.ports[o]}}}getIncomingConnections(t=!1){const e=[];for(const o of this.ports)for(const s of o.incomingConnections)!t&&s.removed||e.push(s);return e}getOutgoingConnections(t=!1){const e=[];for(const o of this.ports)for(const s of o.outgoingConnections)!t&&s.removed||e.push(s);return e}getConnections(t=!1){const e=[];for(const o of this.ports){for(const s of o.incomingConnections)!t&&s.removed||e.push(s);for(const s of o.outgoingConnections)!t&&s.removed||e.push(s)}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],s=[this.coords[1],this.coords[1]+this.height];let a,i;switch(t){case x.Left:a=[o[0]-e,o[1]],i=[s[0],s[1]],a[1]-a[0]<this.getMinWidth()&&(a[0]=a[1]-this.getMinWidth());break;case x.Top:a=[o[0],o[1]],i=[s[0]-e,s[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case x.Right:a=[o[0],o[1]+e],i=[s[0],s[1]],a[1]-a[0]<this.getMinWidth()&&(a[1]=a[0]+this.getMinWidth());break;case x.Bottom:a=[o[0],o[1]],i=[s[0],s[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){var i,r,l,c,h,f;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 s=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];for(const u of this.ports)u.move(Ze(u.coords,e,o,s,a));this.label&&(this.label.coords=[this.coords[0]+it((i=this.getConfig())==null?void 0:i.label),this.coords[1]+ot((r=this.getConfig())==null?void 0:r.label)],this.label.width=this.width-it((l=this.getConfig())==null?void 0:l.label)-St((c=this.getConfig())==null?void 0:c.label),this.label.height=this.height-ot((h=this.getConfig())==null?void 0:h.label)-kt((f=this.getConfig())==null?void 0:f.label),this.label.updateInView());for(const u of this.decorators)u.move(Ze(u.coords,e,o,s,a));this.getConnections().forEach(u=>u.tighten()),this.updateInView()}}class hh extends Pt{constructor(t){super(),this.model=t}new(t,e,o,s,a,i,r){var f,u,p,g,d,m,v,w,C,y;const l=new nt(this.model,t,e,o,s,a,i,r);super.add(l),l.updateInView(),t.sections.push(l),t.updateInView();const c=(g=(p=(u=(f=t.type.sectionGrid)==null?void 0:f.sections)==null?void 0:u[o])==null?void 0:p[e])==null?void 0:g.ports;if(c&&c.length>0)for(let k=0;k<c.length;++k){const M=c[k],N=this.model.ports.new(l,[l.coords[0]+(((d=M==null?void 0:M.coords)==null?void 0:d[0])||0),l.coords[1]+(((m=M==null?void 0:M.coords)==null?void 0:m[1])||0)],M==null?void 0:M.direction,`${l.id}_${k}`);if(M.label){const R={...U,...M.label};let F;switch(N.direction){case x.Top:case x.Left:F=[N.coords[0]-R.fontSize,N.coords[1]-R.fontSize];break;case x.Bottom:F=[N.coords[0]-R.fontSize,N.coords[1]+R.fontSize];break;case x.Right:F=[N.coords[0]+R.fontSize,N.coords[1]-R.fontSize];break;default:F=N.coords}this.model.fields.new(N,F,R.fontSize,R.fontFamily,R.color,R.selectedColor,R.fontSize,R.fontSize,R.horizontalAlign,R.verticalAlign,"",R.editable,R.fit)}}const h=(y=(C=(w=(v=t.type.sectionGrid)==null?void 0:v.sections)==null?void 0:w[o])==null?void 0:C[e])==null?void 0:y.label;if(h){const k={...U,...h};this.model.fields.new(l,[l.coords[0]+it(k),l.coords[1]+ot(k)],k.fontSize,k.fontFamily,k.color,k.selectedColor,l.width-it(k)-St(k),l.height-ot(k)-kt(k),k.horizontalAlign,k.verticalAlign,"",k.editable,k.fit)}return l}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&&K(e.node.sections,e),super.remove(t),e.updateInView()}}}const dh={lookType:"shaped-look",shape:rn.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",selectedFillColor:"#FFFFFF",selectedBorderColor:"#000000"},Nt={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,padding:0,label:null,ports:[],sectionGrid:null,look:dh,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Ae,properties:[]};class cr{constructor(t){const e={...Nt,...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=fh(e),this.leftPadding=ph(e),this.rightPadding=gh(e),this.topPadding=mh(e),this.label=e.label,this.ports=e.ports,this.sectionGrid=e.sectionGrid,this.look=e.look,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new sn((t==null?void 0:t.properties)||[])}}class j extends Yt{constructor(t,e,o=[0,0],s){if(t.nodes.get(s)!==void 0)throw new Error(`DiagramNode with id "${s}" already exists`);super(t,s),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this.type=e,this.valueSet=new le(e.propertySet,this),this.originalData={},this.coords=o,this.width=e.defaultWidth,this.height=e.defaultHeight}get name(){var t;return((t=this.label)==null?void 0:t.text)||""}set name(t){this.label&&(this.label.text=t)}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateNodesInView(this.id)}raise(){var t;(t=this.select())==null||t.raise(),this.label&&this.label.raise();for(const e of this.ports)e.raise();for(const e of this.sections)e.raise();for(const e of this.decorators)e.raise();for(const e of this.children)e.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(a=>a.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 s of o.incomingConnections)!t&&s.removed||e.push(s);return e}getOutgoingConnections(t=!1){const e=[];for(const o of this.ports)for(const s of o.outgoingConnections)!t&&s.removed||e.push(s);return e}getConnections(t=!1){const e=[];for(const o of this.ports){for(const s of o.incomingConnections)!t&&s.removed||e.push(s);for(const s of o.outgoingConnections)!t&&s.removed||e.push(s)}return e}getAdjacentNodes(t=!1){var o,s;const e=[];for(const a of this.ports){for(const i of a.incomingConnections){if(!t&&i.removed)continue;const r=(o=i.start)==null?void 0:o.getNode();if(r){if(!t&&r.removed)continue;e.push(r)}}for(const i of a.outgoingConnections){if(!t&&i.removed)continue;const r=(s=i.end)==null?void 0:s.getNode();if(r){if(!t&&r.removed)continue;e.push(r)}}}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){K(this.children,t),t.parent=void 0}fitToChild(t){const e=this.coords[0]-t.coords[0]+this.type.leftPadding;e>=0&&this.stretch(x.Left,e);const o=this.coords[1]-t.coords[1]+this.type.topPadding;o>=0&&this.stretch(x.Top,o);const s=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;s>=0&&this.stretch(x.Right,s);const a=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;a>=0&&this.stretch(x.Bottom,a),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],s=[this.coords[1],this.coords[1]+this.height];let a,i;switch(t){case x.Left:a=[o[0]-e,o[1]],i=[s[0],s[1]],a[1]-a[0]<this.type.minWidth&&(a[0]=a[1]-this.type.minWidth);break;case x.Top:a=[o[0],o[1]],i=[s[0]-e,s[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case x.Right:a=[o[0],o[1]+e],i=[s[0],s[1]],a[1]-a[0]<this.type.minWidth&&(a[1]=a[0]+this.type.minWidth);break;case x.Bottom:a=[o[0],o[1]],i=[s[0],s[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,o,s){let a=Number.NEGATIVE_INFINITY;switch(t){case x.Bottom:for(const i of this.sections)i.indexYInNode===s&&(a=Math.max(a,i.getMinHeight()-i.height));e<a&&(e=a);for(const i of this.sections)i.indexYInNode===s?i.stretch(t,e):i.indexYInNode>s&&i.move([i.coords[0],i.coords[1]+e]);break;case x.Right:for(const i of this.sections)i.indexXInNode===o&&(a=Math.max(a,i.getMinWidth()-i.width));e<a&&(e=a);for(const i of this.sections)i.indexXInNode===o?i.stretch(t,e):i.indexXInNode>o&&i.move([i.coords[0]+e,i.coords[1]]);break;case x.Top:for(const i of this.sections)i.indexYInNode===s&&(a=Math.max(a,i.getMinHeight()-i.height));e<a&&(e=a);for(const i of this.sections)i.indexYInNode===s?i.stretch(t,e):i.indexYInNode<s&&i.move([i.coords[0],i.coords[1]-e]);break;case x.Left:for(const i of this.sections)i.indexXInNode===o&&(a=Math.max(a,i.getMinWidth()-i.width));e<a&&(e=a);for(const i of this.sections)i.indexXInNode===o?i.stretch(t,e):i.indexXInNode<o&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const s of this.sections)e[s.id]=s.getGeometry();const o={};for(const s of this.children)s.id!==t&&(o[s.id]=s.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:o}}setGeometry(t){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 s=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const r=t.children[i.id];r&&i.setGeometry(r)}for(const i of this.sections){const r=t.sections[i.id];r&&i.setGeometry(r)}for(const i of this.ports)i.move(Ze(i.coords,e,o,s,a));this.label&&(this.label.coords=[this.coords[0]+it(this.type.label),this.coords[1]+ot(this.type.label)],this.label.width=this.width-it(this.type.label)-St(this.type.label),this.label.height=this.height-ot(this.type.label)-kt(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Ze(i.coords,e,o,s,a));this.getConnections().forEach(i=>i.tighten()),this.updateInView()}}class uh extends Pt{constructor(t){super(),this.types=new ni,this.model=t}new(t,e,o){var i,r,l,c,h;let s;if(t instanceof cr)s=t;else{const f=this.types.get(t);if(f===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);s=f}const a=new j(this.model,s,e,o);if(super.add(a),a.updateInView(),s.sectionGrid!==null){let f=a.coords[1]+(s.sectionGrid.margin||0);for(let u=0;u<s.sectionGrid.sections.length;++u){let p=a.coords[0]+(s.sectionGrid.margin||0);for(let g=0;g<s.sectionGrid.sections[u].length;++g)this.model.sections.new(a,g,u,[p,f],((i=s.sectionGrid.defaultWidths)==null?void 0:i[g])||eo,((r=s.sectionGrid.defaultHeights)==null?void 0:r[u])||no,`${a.id}_${u}_${g}`),p+=(((l=s.sectionGrid.defaultWidths)==null?void 0:l[g])||eo)+(s.sectionGrid.margin||0);f+=(((c=s.sectionGrid.defaultHeights)==null?void 0:c[u])||no)+(s.sectionGrid.margin||0)}}if(s.ports.length>0)for(let f=0;f<s.ports.length;++f){const u=s.ports[f],p=this.model.ports.new(a,[a.coords[0]+u.coords[0],a.coords[1]+u.coords[1]],u.direction,`${a.id}_${f}`);if(u.label){const g={...U,...u.label};let d;switch(p.direction){case x.Top:case x.Left:d=[p.coords[0]-g.fontSize,p.coords[1]-g.fontSize];break;case x.Bottom:d=[p.coords[0]-g.fontSize,p.coords[1]+g.fontSize];break;case x.Right:d=[p.coords[0]+g.fontSize,p.coords[1]-g.fontSize];break;default:d=p.coords}this.model.fields.new(p,d,g.fontSize,g.fontFamily,g.color,g.selectedColor,g.fontSize,g.fontSize,g.horizontalAlign,g.verticalAlign,"",g.editable,g.fit)}}if(s.label){const f={...U,...s.label};this.model.fields.new(a,[a.coords[0]+it(f),a.coords[1]+ot(f)],f.fontSize,f.fontFamily,f.color,f.selectedColor,a.width-it(f)-St(f),a.height-ot(f)-kt(f),f.horizontalAlign,f.verticalAlign,"",f.editable,f.fit)}return a.valueSet.resetValues(),(h=a.model.canvas)==null||h.fitNodeInView(a.id),a}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&K(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 s of this)s.coords[0]<t&&t<s.coords[0]+s.width&&s.coords[1]<e&&e<s.coords[1]+s.height&&o.push(s);return o}}const hr=n=>{for(let t=0;t<n.length;++t)for(let e=0;e<n.length;++e)e!==t&&n[e].isAncestorOf(n[t])&&(n.splice(e,1),--e,t>e&&--t);return n},fh=n=>(n==null?void 0:n.padding)===null||(n==null?void 0:n.padding)===void 0?Nt.padding:typeof n.padding=="number"?n.padding:n.padding.length===0?Nt.padding:n.padding.length===1||n.padding.length===2?n.padding[0]:(n.padding.length===3,n.padding[2]),ph=n=>(n==null?void 0:n.padding)===null||(n==null?void 0:n.padding)===void 0?Nt.padding:typeof n.padding=="number"?n.padding:n.padding.length===0?Nt.padding:n.padding.length===1?n.padding[0]:n.padding.length===2||n.padding.length===3?n.padding[1]:n.padding[3],gh=n=>(n==null?void 0:n.padding)===null||(n==null?void 0:n.padding)===void 0?Nt.padding:typeof n.padding=="number"?n.padding:n.padding.length===0?Nt.padding:n.padding.length===1?n.padding[0]:(n.padding.length===2||n.padding.length===3,n.padding[1]),mh=n=>(n==null?void 0:n.padding)===null||(n==null?void 0:n.padding)===void 0?Nt.padding:typeof n.padding=="number"?n.padding:n.padding.length===0?Nt.padding:(n.padding.length===1||n.padding.length===2||n.padding.length===3,n.padding[0]),kn={radius:12,highlightedColor:"cyan",selectedColor:"violet"};class Vt extends Yt{constructor(t,e,o,s,a){if(t.ports.get(a)!==void 0)throw new Error(`DiagramPort with id "${a}" already exists`);super(t,a),this.outgoingConnections=[],this.incomingConnections=[],this.rootElement=e,this.coords=o,this.direction=s}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();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 nt)return this.rootElement.node}getPriority(){var t;return((t=this.rootElement)==null?void 0:t.getPriority())||Ae}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];this.coords=t;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 ir(this.coords,t)}}class vh extends Pt{constructor(t){super(),this.model=t}new(t,e,o,s){const a=new Vt(this.model,t,e,o,s);return super.add(a),a.updateInView(),t!==void 0&&t.ports.push(a),a}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 nt)&&K(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class dr{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 s,a,i,r,l,c,h,f,u,p;const o=t.nodes.types.get(e.type);if(o){const g=new j(t,o,e.coords,e.id);if(t.nodes.add(g),g.width=e.width,g.height=e.height,e.label&&o.label){const m={...U,...o.label},v=new Mt(t,g,[g.coords[0]+it(m),g.coords[1]+ot(m)],g.width-it(m)-St(m),g.height-ot(m)-kt(m),m.fontSize,m.fontFamily,m.color,m.selectedColor,m.horizontalAlign,m.verticalAlign,"",m.editable,m.fit);v.text=e.label,g.label=v,t.fields.add(v),v.updateInView()}for(const m of e.children||[]){const v=this.importNode(t,m);v!==void 0&&((s=g.children)==null||s.push(v),v.parent=g)}for(const m of e.sections||[]){const v=new nt(t,g,m.indexXInNode,m.indexYInNode,m.coords,m.width,m.height,m.id);if((a=g.sections)==null||a.push(v),t.sections.add(v),m.label&&(c=(l=(r=(i=o.sectionGrid)==null?void 0:i.sections)==null?void 0:r[m.indexYInNode])==null?void 0:l[m.indexXInNode])!=null&&c.label){const C={...U,...(p=(u=(f=(h=o.sectionGrid)==null?void 0:h.sections)==null?void 0:f[m.indexYInNode])==null?void 0:u[m.indexXInNode])==null?void 0:p.label},y=new Mt(t,v,[v.coords[0]+it(C),v.coords[1]+ot(C)],v.width-it(C)-St(C),v.height-ot(C)-kt(C),C.fontSize,C.fontFamily,C.color,C.selectedColor,C.horizontalAlign,C.verticalAlign,"",C.editable,C.fit);y.text=m.label,v.label=y,t.fields.add(y),y.updateInView()}let w=0;for(const C of m.ports||[]){const y=new Vt(t,v,C.coords,C.direction,C.id);if(v.ports.push(y),t.ports.add(y),C.label){if(o.ports.length>w&&o.ports[w].label){const k={...U,...o.ports[w].label};let M;switch(y.direction){case x.Top:case x.Left:M=[y.coords[0]-k.fontSize,y.coords[1]-k.fontSize];break;case x.Bottom:M=[y.coords[0]-k.fontSize,y.coords[1]+k.fontSize];break;case x.Right:M=[y.coords[0]+k.fontSize,y.coords[1]-k.fontSize];break;default:M=y.coords}const N=new Mt(t,y,M,k.fontSize,k.fontSize,k.fontSize,k.fontFamily,k.color,k.selectedColor,k.horizontalAlign,k.verticalAlign,"",k.editable,k.fit);N.text=C.label,y.label=N,t.fields.add(N),N.updateInView()}++w}C.collabMeta&&(y.selfRemoved=C.collabMeta.selfRemoved,y.selfRemovedTimestamp=C.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(y.label,C.collabMeta.label)),y.updateInView()}m.collabMeta&&(v.selfRemoved=m.collabMeta.selfRemoved,v.selfRemovedTimestamp=m.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(v.label,m.collabMeta.label)),v.updateInView()}let d=0;for(const m of e.ports||[]){const v=new Vt(t,g,m.coords,m.direction,m.id);if(g.ports.push(v),t.ports.add(v),m.label){if(o.ports.length>d&&o.ports[d].label){const w={...U,...o.ports[d].label};let C;switch(v.direction){case x.Top:case x.Left:C=[v.coords[0]-w.fontSize,v.coords[1]-w.fontSize];break;case x.Bottom:C=[v.coords[0]-w.fontSize,v.coords[1]+w.fontSize];break;case x.Right:C=[v.coords[0]+w.fontSize,v.coords[1]-w.fontSize];break;default:C=v.coords}const y=new Mt(t,v,C,w.fontSize,w.fontSize,w.fontSize,w.fontFamily,w.color,w.selectedColor,w.horizontalAlign,w.verticalAlign,"",w.editable,w.fit);y.text=m.label,v.label=y,t.fields.add(y),y.updateInView()}++d}m.collabMeta&&(v.selfRemoved=m.collabMeta.selfRemoved,v.selfRemovedTimestamp=m.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(v.label,m.collabMeta.label)),v.updateInView()}return e.data&&g.valueSet.setValues(e.data),e.collabMeta&&(g.selfRemoved=e.collabMeta.selfRemoved,g.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,g.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(g.label,e.collabMeta.label),g.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),g.updateInView(),g}}importConnection(t,e){const o=t.connections.types.get(e.type);if(o){const s=new Ct(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(s),s.startLabel=e.startLabel,s.middleLabel=e.middleLabel,s.endLabel=e.endLabel,s.points=e.points,e.data&&s.valueSet.setValues(e.data),e.collabMeta&&(s.selfRemoved=e.collabMeta.selfRemoved,s.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,s.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),s.updateInView(),s}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class an{constructor(t,e,o,s,a,i,r){this.canvas=t,this.id=e,this.typeId=o,this.coords=s,this.parentId=a,this.label=i,this.values=r}do(){var e;const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&((e=this.canvas.model.nodes.get(this.parentId))==null||e.addChild(t)),this.values!==void 0&&t.valueSet.setValues(structuredClone({...t.valueSet.getValues(),...this.values})),t.label&&(t.label.text=this.label||"")}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new an(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class we{constructor(t,e,o,s){this.canvas=t,this.nodeIds=e,this.delta=o,this.timestamp=s}do(){var t;for(const e of this.nodeIds){const o=this.canvas.model.nodes.get(e,!0);o&&ae(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 we(t,e.nodeIds,e.delta,e.timestamp)}}class ut{constructor(t,e,o,s){this.canvas=t,this.nodeId=e,this.to=o,this.timestamp=s}do(){var e,o,s;const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&ae(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),(e=t.label)!=null&&e.fit&&this.canvas.fitFieldRootInView(t.label.id);for(const a of t.sections)(o=a.label)!=null&&o.fit&&this.canvas.fitFieldRootInView(a.label.id);(s=t.parent)==null||s.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 ut(t,e.nodeId,e.to,e.timestamp)}}class xe{constructor(t,e,o,s,a){this.canvas=t,this.childId=e,this.parentId=o,this.childGeometry=s,this.timestamp=a}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)&&ae(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 xe(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class ln{constructor(t,e,o,s,a){this.canvas=t,this.id=e,this.typeId=o,this.startId=s,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 ln(t,e.id,e.typeId,e.startId,e.endId)}}class te{constructor(t,e,o,s){this.canvas=t,this.fieldId=e,this.to=o,this.timestamp=s}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&ae(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 te(t,e.fieldId,e.to,e.timestamp)}}class ee{constructor(t,e,o,s){this.canvas=t,this.id=e,this.to=o,this.timestamp=s}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 ee(t,e.id,e.to,e.timestamp)}}class wt{constructor(t,e,o,s,a,i,r,l){this.canvas=t,this.nodeIds=e,this.sectionIds=o,this.portIds=s,this.connectionIds=a,this.fieldIds=i,this.selfRemoved=r,this.timestamp=l}doOne(t){t&&ae(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 wt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class cn{constructor(t,e,o){this.canvas=t,this.nodes=e,this.connections=o}do(){const t=new dr;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 cn(t,e.nodes,e.connections)}}class yh{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=Ji()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+Ji()}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":{an.deserialize(this.canvas,t).do();break}case"move":{we.deserialize(this.canvas,t).do();break}case"setGeometry":{ut.deserialize(this.canvas,t).do();break}case"setParent":{xe.deserialize(this.canvas,t).do();break}case"addConnection":{ln.deserialize(this.canvas,t).do();break}case"editField":{te.deserialize(this.canvas,t).do();break}case"updateValues":{ee.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{wt.deserialize(this.canvas,t).do();break}case"paste":{cn.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class bh{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()}undo(){if(this.index>0){let t;do--this.index,t=this.history[this.index].undo();while(!t&&this.index>0)}this.canvas.diagramChange$.next()}redo(){if(this.index<this.history.length){let t;do t=this.history[this.index].redo(),++this.index;while(!t&&this.index<this.history.length)}this.canvas.diagramChange$.next()}}var I=(n=>(n.AddConnection="add-connection",n.AddNode="add-node",n.Clipboard="clipboard",n.ContextMenu="context-menu",n.EditField="edit-field",n.MoveNode="move-node",n.Paste="paste",n.Remove="remove",n.StretchNode="stretch-node",n.StretchSection="stretch-section",n.UpdateValues="update-values",n.Zoom="zoom",n))(I||{});class wh{constructor(t,e,o,s,a,i,r,l,c){this.canvas=t,this.type=e,this.coords=o,this.parentId=s,this.ancestorId=a,this.fromAncestorGeometry=i,this.toAncestorGeometry=r,this.label=l,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){const t=new an(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 ut(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 wt(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 ut(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 wt(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 ut(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t===void 0}}class Sn{constructor(t,e,o){this.canvas=t,this.nodeIds=e,this.delta=o}do(){const t=new we(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 we(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 Z{constructor(t,e,o,s,a,i,r,l){this.canvas=t,this.intent=e,this.nodeId=o,this.from=s,this.to=a,this.ancestorId=i,this.fromAncestorGeometry=r,this.toAncestorGeometry=l}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new ut(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 ut(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 ut(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 ut(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 ut(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class xh{constructor(t,e,o,s,a,i,r,l,c){this.canvas=t,this.childId=e,this.fromParentId=o,this.toParentId=s,this.fromChildGeometry=a,this.toChildGeometry=i,this.ancestorId=r,this.fromAncestorGeometry=l,this.toAncestorGeometry=c}do(){const t=this.canvas.model.nodes.get(this.childId),e=new xe(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 ut(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 xe(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 ut(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(o)}return t!==void 0}redo(){return this.do()}}class An{constructor(t,e,o,s){this.canvas=t,this.type=e,this.startId=o,this.endId=s,this.id=this.canvas.collabEngine.freshId()}do(){const t=new ln(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 wt(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 wt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class io{constructor(t,e,o,s){this.canvas=t,this.fieldId=e,this.from=o,this.to=s}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new te(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 te(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 te(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Ch{constructor(t,e,o,s){this.canvas=t,this.id=e,this.from=o,this.to=s}do(){const t=new ee(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new ee(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 ee(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 kh{constructor(t,e,o,s,a,i){this.canvas=t,this.nodeIds=e,this.sectionIds=o,this.portIds=s,this.connectionIds=a,this.fieldIds=i}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 wt(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 wt(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 Sh{constructor(t,e,o,s){this.canvas=t,this.nodes=e,this.connections=o,this.coords=s}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,o={};for(const a of this.nodes){const i=a.id,r=this.canvas.collabEngine.freshId();if(o[i]=r,a.id=r,e&&(a.coords=[a.coords[0]+e[0],a.coords[1]+e[1]]),a.sections)for(const l of a.sections){const c=l.id;if(l.id.includes(a.id)?l.id=l.id.replace(a.id,r):l.id=this.canvas.collabEngine.freshId(),o[c]=l.id,e&&(l.coords=[l.coords[0]+e[0],l.coords[1]+e[1]]),l.ports)for(const h of l.ports){const f=h.id;h.id.includes(a.id)?h.id=h.id.replace(a.id,r):h.id=this.canvas.collabEngine.freshId(),o[f]=h.id,e&&(h.coords=[h.coords[0]+e[0],h.coords[1]+e[1]])}}if(a.ports)for(const l of a.ports){const c=l.id;l.id.includes(a.id)?l.id=l.id.replace(a.id,r):l.id=this.canvas.collabEngine.freshId(),o[c]=l.id,e&&(l.coords=[l.coords[0]+e[0],l.coords[1]+e[1]])}}for(const a of this.connections){const i=this.canvas.collabEngine.freshId();if(o[a.id]=i,a.id=i,a.start=o[a.start]||a.start,a.end=o[a.end]||a.end,e)for(let r=0;r<a.points.length;++r)a.points[r]=[a.points[r][0]+e[0],a.points[r][1]+e[1]]}const s=new cn(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(s),!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 wt(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 wt(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 st{constructor(t,e,o,s){this.cause=t,this.type=e,this.target=o,this.coords=s,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}class Ah extends Yt{constructor(t,e,o,s,a,i,r,l){if(t.objects.get(l)!==void 0)throw new Error(`DiagramObject with id "${l}" already exists`);super(t,l),this.rootElement=e,this.coords=o,this.width=s,this.height=a,this.priority=i,this.html=r}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){var t;(t=this.model.canvas)==null||t.updateDecoratorsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Ih extends Pt{constructor(t){super(),this.model=t}new(t,e,o,s,a,i,r){const l=new Ah(this.model,t,e,o,s,a,i,r);return super.add(l),l.updateInView(),t!==void 0&&t.decorators.push(l),l}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof j||e.rootElement instanceof nt)&&K(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Th extends Yt{constructor(t,e,o,s,a,i,r){if(t.objects.get(r)!==void 0)throw new Error(`DiagramObject with id "${r}" already exists`);super(t,r),this.coords=e,this.width=o,this.height=s,this.priority=a,this.html=i}select(){var t,e;return(e=(t=this.model.canvas)==null?void 0:t.selectCanvasView())==null?void 0:e.select(`foreignObject#${this.id}`)}get removed(){return this.selfRemoved}updateInView(){var t;(t=this.model.canvas)==null||t.updateObjectsInView(this.id)}raise(){var t;(t=this.select())==null||t.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Eh extends Pt{constructor(t){super(),this.model=t}new(t,e,o,s,a,i){const r=new Th(this.model,t,e,o,s,a,i);return super.add(r),r.updateInView(),r}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class ur{constructor(t,e,o,s,a,i=[]){this.nodes=new uh(this),this.sections=new hh(this),this.ports=new vh(this),this.connections=new oh(this),this.fields=new rh(this),this.objects=new Eh(this),this.decorators=new Ih(this),this.canvas=t,this.id=e,this.name=o,this.description=s,this.type=a,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new le(new sn(i),this)}clear(){var t,e;(t=this.canvas)==null||t.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),(e=this.canvas)==null||e.updateModelInView()}}const Gn=96,at=32,qt=Gn+at,$h=Math.PI/4,Mh=100;class _h{constructor(t){this.canvas=t}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),o=this.canvas.getPointerLocationRelativeToCanvas(t),s=this.canvas.selectRoot().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-qt}px`).attr("y",`${e[1]-qt}px`).attr("width",`${2*qt}px`).attr("height",`${2*qt}px`).style("pointer-events","none").on(T.ContextMenu,i=>{this.canvas.canUserPerformAction(I.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(T.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=s;const a=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(I.Clipboard)&&this.canvas.canUserPerformAction(I.Remove)&&a.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.preventDefault(),this.canvas.userSelection.cutToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(I.Clipboard)&&a.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.preventDefault(),this.canvas.userSelection.copyToClipboard(),this.canvas.cancelAllUserActions()}}),this.canvas.canUserPerformAction(I.Paste)&&a.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.preventDefault(),this.canvas.userSelection.pasteFromClipboard(this.canvas.getClosestGridPoint(o)),this.canvas.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(I.Remove)&&a.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.preventDefault(),this.canvas.userSelection.removeFromModel(),this.canvas.cancelAllUserActions()}}),a.length===0&&a.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<a.length;++i){const r=a[i],l=r.onPress,c=(i+.5-a.length/2)*$h,h=s.append("xhtml:div").attr("class",`daga-context-menu-button ${r.imageClass}-button${r.onPress!=null?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*at}px`).style("height",`${2*at}px`).style("border-radius",`${at}px`).style("pointer-events","auto").on(T.Click,f=>{l&&l(f)}).on(T.KeyDown,f=>{l&&f.key===Et.Enter&&l(f)});h.append("xhtml:div").style("position","absolute").style("left",`${.75*at}px`).style("top",`${.5*at}px`).style("width",`${.5*at}px`).style("height",`${.5*at}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",r.imageClass),h.append("xhtml:span").style("position","absolute").style("left",`${.2*at}px`).style("top",`${1.1*at}px`).style("text-align","center").style("width",`${1.6*at}px`).style("height",`${.35*at}px`).style("margin","0").style("font-size",`${.35*at}px`).style("font-weight","700").style("user-select","none").text(r.name),h.transition().ease(Ln).duration(Mh).tween("progress",()=>f=>{const u=c*f;return h.style("left",`${Math.sin(u)*Gn-at+qt}px`).style("top",`${-Math.cos(u)*Gn-at+qt}px`)})}}close(){var t;(t=this.contextMenuContainer)==null||t.remove(),this.contextMenuContainer=void 0}}class Nh extends Pt{constructor(t){super(),this.focus=void 0,this.canvas=t}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,t instanceof Mt&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof j){for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateNodesInView(t.id)}else if(t instanceof nt){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 Ct&&this.canvas.updateConnectionsInView(t.id)}clear(){for(;this.entities.length>0;){const t=this.entities[0];this.remove(t.id),t.updateInView()}this.focus=void 0}}const Ph=1;class fr{export(t,e=!1){const o={name:t.name,type:t.type,typeVersion:Ph,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 s of t.nodes.all(!0))!e&&s.removed||s.parent===void 0&&o.nodes.push(this.exportNode(s,e));for(const s of t.connections.all(!0))!e&&s.removed||o.connections.push(this.exportConnection(s,e));return o}exportNode(t,e=!1){var i,r,l,c;const o=[];for(const h of t.children)o.push(this.exportNode(h,e));const s=[];for(const h of t.sections){const f=[];for(const u of h.ports)f.push({id:u.id,coords:Pe(u.coords),direction:u.direction,label:((i=u.label)==null?void 0:i.text)||"",...e?{collabMeta:{removed:u.removed,selfRemoved:u.selfRemoved,selfRemovedTimestamp:u.selfRemovedTimestamp,...this.exportLabelCollabMeta(u)}}:{}});s.push({id:h.id,ports:f,label:((r=h.label)==null?void 0:r.text)||"",indexXInNode:h.indexXInNode,indexYInNode:h.indexYInNode,coords:Pe(h.coords),width:h.width,height:h.height,...e?{collabMeta:{removed:h.removed,selfRemoved:h.selfRemoved,selfRemovedTimestamp:h.selfRemovedTimestamp,...this.exportLabelCollabMeta(h)}}:{}})}const a=[];for(const h of t.ports)a.push({id:h.id,coords:Pe(h.coords),direction:h.direction,label:((l=h.label)==null?void 0:l.text)||"",...e?{collabMeta:{removed:h.removed,selfRemoved:h.selfRemoved,selfRemovedTimestamp:h.selfRemovedTimestamp,...this.exportLabelCollabMeta(h)}}:{}});return{id:t.id,type:t.type.id,children:o,sections:s,ports:a,label:((c=t.label)==null?void 0:c.text)||"",coords:Pe(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,s;return{id:t.id,type:t.type.id,start:((o=t.start)==null?void 0:o.id)||"",end:((s=t.end)==null?void 0:s.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 Rh="Diagram properties";class zh extends Pt{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(zc(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof j||t instanceof Ct)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof nt?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=[],s=[],a=[];for(const r of this.all())r instanceof j?t.push(r.id):r instanceof nt?e.push(r.id):r instanceof Vt?o.push(r.id):r instanceof Ct?s.push(r.id):r instanceof Mt&&a.push(r.id);const i=new kh(this.canvas,t,e,o,s,a);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new fr;for(const o of this.all())o instanceof j&&t.nodes.push(e.exportNode(o,!1)),o instanceof Ct&&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 s=new Sh(this.canvas,o.nodes,o.connections,t);this.canvas.actionStack.add(s),s.do()}catch{return}})}openInPropertyEditor(t){var s;this.makeUpdateValuesAction();const e=(s=this.canvas.parentComponent)==null?void 0:s.propertyEditor;if(e===void 0)return;const o=t==null?void 0:t.valueSet;o?(this.propertyEditorSelection=t,this.propertyEditorValues=structuredClone(o.getValues()),e&&(t instanceof j||t instanceof Ct?(t instanceof j?t.name?e.title=`${t.type.name}: ${t.name}`:e.title=t.type.name:t instanceof Ct&&(e.title=t.type.name),e.valueSet=void 0,e.valueSet=o):(e.title=Rh,e.valueSet=void 0,e.valueSet=o))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,e&&(e.title="",e.valueSet=void 0))}makeUpdateValuesAction(){var r,l;if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof ur?void 0:this.propertyEditorSelection.id;if(be(this.propertyEditorValues,(r=this.propertyEditorSelection)==null?void 0:r.valueSet.getValues()))return;const e=this.propertyEditorValues,o=structuredClone((l=this.propertyEditorSelection)==null?void 0:l.valueSet.getValues()),[s,a]=ar(e,o),i=new Ch(this.canvas,t,s,a);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=o}}const Lh=12,Y=6,Vh=25,In="diagram-connection-unfinished",Dh=100,Je=class Je{constructor(t,e){var o,s,a,i,r,l,c,h,f,u,p,g,d,m,v,w,C,y;if(this.backgroundPatternId=`daga-background-pattern-id-${Je.canvasCount++}`,this.zoomTransform=Kn,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.viewInitialized$=new Ft,this.validatorChange$=new Ft,this.diagramChange$=new Ft,this.diagramImportantChange$=new Ft,this.propertyEditorChanges$=new Ft,this.diagramEvent$=new Ft,this.parentComponent=t,this.model=new ur(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new zh(this),this.userHighlight=new Nh(this),this.contextMenu=new _h(this),this.backgroundColor=((o=e.canvas)==null?void 0:o.backgroundColor)||"#FFFFFF",this.gridSize=((a=(s=e.canvas)==null?void 0:s.grid)==null?void 0:a.enabled)===!1||((i=e.canvas)==null?void 0:i.grid)===void 0?0:Math.abs(((l=(r=e.canvas)==null?void 0:r.grid)==null?void 0:l.spacing)||10),this.gridThickness=Math.abs(((h=(c=e.canvas)==null?void 0:c.grid)==null?void 0:h.thickness)||.05),this.gridColor=((u=(f=e.canvas)==null?void 0:f.grid)==null?void 0:u.color)||"rgba(0, 0, 0, 0.1)",this.snapToGrid=((g=(p=e.canvas)==null?void 0:p.grid)==null?void 0:g.enabled)===!1||((d=e.canvas)==null?void 0:d.grid)===void 0?!1:((v=(m=e.canvas)==null?void 0:m.grid)==null?void 0:v.snap)||!1,this.zoomFactor=((w=e.canvas)==null?void 0:w.zoomFactor)||2,this.panRate=((C=e.canvas)==null?void 0:C.panRate)||100,this.inferConnectionType=e.inferConnectionType||!1,this.multipleSelectionOn=!1,this.priorityThresholds=((y=e.canvas)==null?void 0:y.priorityThresholds)||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new bh(this,Vh),this.collabEngine=new yh(this),e.nodeTypes)for(const k of e.nodeTypes){const M=new cr({...e.nodeTypeDefaults,...k});this.model.nodes.types.add(M)}if(e.connectionTypes){for(const k of e.connectionTypes){const M=new lr({...e.connectionTypeDefaults,...k});this.model.connections.types.add(M)}this._connectionType=e.defaultConnection!==void 0?this.model.connections.types.get(e.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){var e,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){K(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 s of this.model.nodes)this.fitNodeInView(s.id);(o=(e=this.parentComponent)==null?void 0:e.palette)==null||o.refreshPalette()}initView(t){this.diagramRoot=O(t).append("div").node(),O(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),O(this.diagramRoot).on(T.Click,()=>{var a;(a=O(this.diagramRoot).node())==null||a.focus()}).on(T.ContextMenu,a=>{if(this.dragging){a.preventDefault(),a.stopPropagation(),this.dragging=!1;return}const i=new st(a,T.ContextMenu,void 0);this.diagramEvent$.next(i),!i.defaultPrevented&&this.canUserPerformAction(I.ContextMenu)&&(a.preventDefault(),this.contextMenu.open(a))}).on(T.DoubleClick,a=>{const i=new st(a,T.DoubleClick,void 0);this.diagramEvent$.next(i)}).on(T.KeyDown,a=>{if(!a.ctrlKey&&(a.key===Et.Delete||a.key===Et.Backspace)&&this.canUserPerformAction(I.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="a"){a.preventDefault();for(const i of this.model.nodes)this.userSelection.add(i);for(const i of this.model.connections)this.userSelection.add(i)}if(a.ctrlKey&&a.key==="i"){a.preventDefault();for(const i of this.model.nodes)this.userSelection.toggle(i);for(const i of this.model.connections)this.userSelection.toggle(i)}if(a.ctrlKey&&a.key==="c"&&(a.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="x"&&(a.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),a.ctrlKey&&a.key==="v"){a.preventDefault();const i=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(i[0][0]+i[1][0])/2,(i[0][1]+i[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==="+"&&(a.preventDefault(),this.zoomBy(this.zoomFactor)),a.key==="-"&&(a.preventDefault(),this.zoomBy(1/this.zoomFactor)),a.key===Et.ArrowLeft&&(a.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),a.key===Et.ArrowRight&&(a.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),a.key===Et.ArrowDown&&(a.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),a.key===Et.ArrowUp&&(a.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const e=this.selectRoot().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%"),o=e.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(T.MouseMove,a=>{if(this.unfinishedConnection!==void 0){const i=this.getPointerLocationRelativeToCanvas(a);this.unfinishedConnection.endCoords=i}}).on(T.MouseOver,()=>{this.userHighlight.clear()}).on(T.Click,()=>{this.userHighlight.clear(),this.contextMenu.close(),this.userSelection.clear(),this.userSelection.openInPropertyEditor(this.model)}).call(J().filter(a=>this.multipleSelectionOn||zt(a)).on(P.Start,a=>{this.startMultipleSelection(a)}).on(P.Drag,a=>{this.continueMultipleSelection(a)}).on(P.End,a=>{this.finishMultipleSelection(a)})).call(this.zoomBehavior=ql().on(On.Zoom,a=>{if(a.sourceEvent){if(!this.canUserPerformAction(I.Zoom)){$(L.NotAllowed);return}a.sourceEvent.type===T.Wheel&&a.sourceEvent.wheelDelta!==void 0?(a.sourceEvent.wheelDelta>0&&$(L.ZoomIn),a.sourceEvent.wheelDelta<0&&$(L.ZoomOut)):a.sourceEvent.type===T.MouseMove&&$(L.AllScroll)}this.zoomTransform=a.transform;const i=a.transform.toString();this.selectCanvasElements().attr("transform",i),O(`#${this.backgroundPatternId}`).attr("patternTransform",i),this.contextMenu.close()}).on(On.End,()=>{$()})),s=e.append("defs");if(this.gridSize>0&&isFinite(this.gridSize)){const a=s.append("pattern").attr("id",this.backgroundPatternId).attr("x",-this.gridSize/2).attr("y",-this.gridSize/2).attr("width",this.gridSize).attr("height",this.gridSize).attr("patternUnits","userSpaceOnUse");a.append("rect").attr("x",0).attr("y",0).attr("width",this.gridSize).attr("height",this.gridSize).attr("fill",this.backgroundColor),a.append("circle").attr("cx",this.gridSize/2).attr("cy",this.gridSize/2).attr("r",this.gridSize*this.gridThickness).attr("fill",this.gridColor),o.attr("fill",`url(#${this.backgroundPatternId})`)}e.append("g").attr("class","daga-canvas-elements"),this.viewInitialized$.next()}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView().select("rect"),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView().select("rect"),t)}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView().select("rect"),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView().select("rect"),t,e)}center(){if(this.model.nodes.length>0){const t=this.selectCanvasView().select("rect").node().getBBox(),e=this.model.nodes.all(),o=Math.min(...e.map(g=>g.coords[0])),s=Math.max(...e.map(g=>g.coords[0]+g.width)),a=(o+s)/2,i=s-o,r=t.width,l=Math.min(...e.map(g=>g.coords[1])),c=Math.max(...e.map(g=>g.coords[1]+g.height)),h=(l+c)/2,f=c-l,u=t.height,p=Math.min(r/i,u/f,1);this.translateTo(a,h),this.zoomTo(p)}}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.selectRoot().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 vt(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return vt(this.getEventHoldingCoordinates(t),this.selectRoot().node())}getPointerLocationRelativeToBody(t){return vt(this.getEventHoldingCoordinates(t),O("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 o=e.exit(),s=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.look.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=s.merge(e);o.remove(),s.on(T.MouseOver,(i,r)=>{this.dragging||this.userHighlight.focusOn(r)}).on(T.Click,(i,r)=>{!i.ctrlKey&&!i.shiftKey&&this.userSelection.clear(),this.userSelection.toggle(r)}).on(T.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const l=new st(i,T.ContextMenu,r);this.diagramEvent$.next(l),!l.defaultPrevented&&this.canUserPerformAction(I.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(r),this.userSelection.add(r),this.contextMenu.open(i))}).on(T.DoubleClick,(i,r)=>{const l=new st(i,T.DoubleClick,r);this.diagramEvent$.next(l)}).call(J().filter(i=>(this.secondaryButton=zt(i),!0)).on(P.Start,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,r)}).on(P.Drag,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,r)}).on(P.End,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,r),this.secondaryButton=!1})),s.filter(".shaped-look").append("path"),s.filter(".image-look").append("image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none"),s.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${Y}px`).on(T.MouseOver,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed&&$(L.EWResize)}).on(T.MouseOut,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed&&$()}).call(J().on(P.Start,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed?($(L.EWResize),this.currentAction=new Z(this,I.StretchNode,r.id,r.getGeometry(),r.getGeometry())):$(L.NotAllowed)}).on(P.Drag,(i,r)=>{if(this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed){const l=this.getPointerLocationRelativeToCanvas(i);r.stretch(x.Left,r.coords[0]-l[0])}}).on(P.End,(i,r)=>{if(this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed&&this.currentAction instanceof Z&&this.currentAction.intent===I.StretchNode){let l=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(l=this.getClosestGridPoint(l)),r.stretch(x.Left,r.coords[0]-l[0]),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}$()})),s.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${Y}px`).on(T.MouseOver,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed&&$(L.NSResize)}).on(T.MouseOut,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed&&$()}).call(J().on(P.Start,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed?($(L.NSResize),this.currentAction=new Z(this,I.StretchNode,r.id,r.getGeometry(),r.getGeometry())):$(L.NotAllowed)}).on(P.Drag,(i,r)=>{if(this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed){const l=this.getPointerLocationRelativeToCanvas(i);r.stretch(x.Top,r.coords[1]-l[1])}}).on(P.End,(i,r)=>{if(this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed&&this.currentAction instanceof Z&&this.currentAction.intent===I.StretchNode){let l=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(l=this.getClosestGridPoint(l)),r.stretch(x.Top,r.coords[1]-l[1]),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}$()})),s.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${Y}px`).on(T.MouseOver,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed&&$(L.EWResize)}).on(T.MouseOut,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed&&$()}).call(J().on(P.Start,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed?($(L.EWResize),this.currentAction=new Z(this,I.StretchNode,r.id,r.getGeometry(),r.getGeometry())):$(L.NotAllowed)}).on(P.Drag,(i,r)=>{if(this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed){const l=this.getPointerLocationRelativeToCanvas(i);r.stretch(x.Right,l[0]-(r.coords[0]+r.width))}}).on(P.End,(i,r)=>{if(this.canUserPerformAction(I.StretchNode)&&r.type.resizableX&&!r.removed&&this.currentAction instanceof Z&&this.currentAction.intent===I.StretchNode){let l=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(l=this.getClosestGridPoint(l)),r.stretch(x.Right,l[0]-(r.coords[0]+r.width)),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}$()})),s.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${Y}px`).on(T.MouseOver,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed&&$(L.NSResize)}).on(T.MouseOut,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed&&$()}).call(J().on(P.Start,(i,r)=>{this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed?($(L.NSResize),this.currentAction=new Z(this,I.StretchNode,r.id,r.getGeometry(),r.getGeometry())):$(L.NotAllowed)}).on(P.Drag,(i,r)=>{if(this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed){const l=this.getPointerLocationRelativeToCanvas(i);r.stretch(x.Bottom,l[1]-(r.coords[1]+r.height))}}).on(P.End,(i,r)=>{if(this.canUserPerformAction(I.StretchNode)&&r.type.resizableY&&!r.removed&&this.currentAction instanceof Z&&this.currentAction.intent===I.StretchNode){let l=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(l=this.getClosestGridPoint(l)),r.stretch(x.Bottom,l[1]-(r.coords[1]+r.height)),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}$()})),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),a.filter(".shaped-look").select("path").attr("d",i=>Qe(i.type.look.shape,0,0,i.width,i.height)).attr("fill",i=>i.selected?i.type.look.selectedFillColor:i.type.look.fillColor).attr("stroke",i=>i.selected?i.type.look.selectedBorderColor:i.type.look.borderColor).attr("stroke-width",i=>`${i.highlighted?3:1}px`),a.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",i=>i.width).attr("height",i=>i.height).attr("href",i=>i.selected?i.type.look.selectedBackgroundImage:i.type.look.backgroundImage),a.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTopLeft:i.type.look.backgroundImageTopLeft),a.filter(".stretchable-image-look").select("image.top-image").attr("x",i=>i.type.look.leftMargin).attr("y",0).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTop:i.type.look.backgroundImageTop),a.filter(".stretchable-image-look").select("image.top-right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",0).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageTopRight:i.type.look.backgroundImageTopRight),a.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageLeft:i.type.look.backgroundImageLeft),a.filter(".stretchable-image-look").select("image.center-image").attr("x",i=>i.type.look.leftMargin).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageCenter:i.type.look.backgroundImageCenter),a.filter(".stretchable-image-look").select("image.right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",i=>i.type.look.topMargin).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.height-i.type.look.bottomMargin-i.type.look.topMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageRight:i.type.look.backgroundImageRight),a.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.type.look.leftMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottomLeft:i.type.look.backgroundImageBottomLeft),a.filter(".stretchable-image-look").select("image.bottom-image").attr("x",i=>i.type.look.leftMargin).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.width-i.type.look.rightMargin-i.type.look.leftMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottom:i.type.look.backgroundImageBottom),a.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",i=>i.width-i.type.look.rightMargin).attr("y",i=>i.height-i.type.look.bottomMargin).attr("width",i=>i.type.look.rightMargin).attr("height",i=>i.type.look.bottomMargin).attr("href",i=>i.selected?i.type.look.selectedBackgroundImageBottomRight:i.type.look.backgroundImageBottomRight),a.filter(".resizable-x").select("line.left-resizer").attr("x1",Y/2).attr("x2",Y/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",Y/2).attr("y2",Y/2),a.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-Y/2).attr("x2",i=>i.width-Y/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-Y/2).attr("y2",i=>i.height-Y/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 o=e.exit(),s=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>{var r,l,c,h,f,u;return`diagram-section${(l=(r=i.node)==null?void 0:r.type)!=null&&l.resizableX?" resizable-x":""}${(h=(c=i.node)==null?void 0:c.type)!=null&&h.resizableY?" resizable-y":""} ${(u=(f=i.getConfig())==null?void 0:f.look)==null?void 0:u.lookType}`});t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=s.merge(e);o.remove(),s.on(T.MouseOver,(i,r)=>{this.dragging||this.userHighlight.focusOn(r)}).on(T.Click,(i,r)=>{!i.ctrlKey&&!i.shiftKey&&this.userSelection.clear(),this.userSelection.toggle(Ot(r))}).on(T.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const l=new st(i,T.ContextMenu,r);if(this.diagramEvent$.next(l),!l.defaultPrevented&&this.canUserPerformAction(I.ContextMenu)){i.preventDefault();const c=Ot(r);this.userHighlight.focusOn(c),this.userSelection.add(c),this.contextMenu.open(i)}}).on(T.DoubleClick,(i,r)=>{const l=new st(i,T.DoubleClick,r);this.diagramEvent$.next(l)}).call(J().filter(i=>(this.secondaryButton=zt(i),!0)).on(P.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const l=r==null?void 0:r.node;l?this.startMovingNode(i,l):$(L.NotAllowed)}}).on(P.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const l=r==null?void 0:r.node;l?this.continueMovingNode(i,l):$(L.NotAllowed)}}).on(P.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const l=r==null?void 0:r.node;l?this.finishMovingNode(i,l):$()}this.secondaryButton=!1})),s.filter(".shaped-look").append("path"),s.filter(".image-look").append("image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none"),s.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${Y}px`).on(T.MouseOver,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed&&$(L.EWResize)}).on(T.MouseOut,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed&&$()}).call(J().on(P.Start,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed?($(L.EWResize),this.currentAction=new Z(this,I.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):$(L.NotAllowed)}).on(P.Drag,(i,r)=>{var l,c;if(this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed){const h=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(x.Left,r.coords[0]-h[0],r.indexXInNode,r.indexYInNode)}}).on(P.End,(i,r)=>{var l,c;if(this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed&&this.currentAction instanceof Z&&this.currentAction.intent===I.StretchSection){let h=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(h=this.getClosestGridPoint(h)),r.node.stretchSections(x.Left,r.coords[0]-h[0],r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}$()})),s.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${Y}px`).on(T.MouseOver,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed&&$(L.NSResize)}).on(T.MouseOut,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed&&$()}).call(J().on(P.Start,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed?($(L.NSResize),this.currentAction=new Z(this,I.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):$(L.NotAllowed)}).on(P.Drag,(i,r)=>{var l,c;if(this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed){const h=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(x.Top,r.coords[1]-h[1],r.indexXInNode,r.indexYInNode)}}).on(P.End,(i,r)=>{var l,c;if(this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed&&this.currentAction instanceof Z&&this.currentAction.intent===I.StretchSection){let h=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(h=this.getClosestGridPoint(h)),r.node.stretchSections(x.Top,r.coords[1]-h[1],r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}$()})),s.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${Y}px`).on(T.MouseOver,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed&&$(L.EWResize)}).on(T.MouseOut,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed&&$()}).call(J().on(P.Start,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed?($(L.EWResize),this.currentAction=new Z(this,I.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):$(L.NotAllowed)}).on(P.Drag,(i,r)=>{var l,c;if(this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed){const h=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(x.Right,h[0]-(r.coords[0]+r.width),r.indexXInNode,r.indexYInNode)}}).on(P.End,(i,r)=>{var l,c;if(this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableX)&&!r.removed&&this.currentAction instanceof Z&&this.currentAction.intent===I.StretchSection){let h=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(h=this.getClosestGridPoint(h)),r.node.stretchSections(x.Right,h[0]-(r.coords[0]+r.width),r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}$()})),s.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${Y}px`).on(T.MouseOver,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed&&$(L.NSResize)}).on(T.MouseOut,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed&&$()}).call(J().on(P.Start,(i,r)=>{var l,c;this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed?($(L.NSResize),this.currentAction=new Z(this,I.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):$(L.NotAllowed)}).on(P.Drag,(i,r)=>{var l,c;if(this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed){const h=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(x.Bottom,h[1]-(r.coords[1]+r.height),r.indexXInNode,r.indexYInNode)}}).on(P.End,(i,r)=>{var l,c;if(this.canUserPerformAction(I.StretchSection)&&((c=(l=r.node)==null?void 0:l.type)!=null&&c.resizableY)&&!r.removed&&this.currentAction instanceof Z&&this.currentAction.intent===I.StretchSection){let h=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(h=this.getClosestGridPoint(h)),r.node.stretchSections(x.Bottom,h[1]-(r.coords[1]+r.height),r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}$()})),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),a.filter(".shaped-look").select("path").attr("d",i=>{var r;return Qe(((r=i.getConfig())==null?void 0:r.look).shape,0,0,i.width,i.height)}).attr("fill",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedFillColor:((l=i.getConfig())==null?void 0:l.look).fillColor}).attr("stroke",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBorderColor:((l=i.getConfig())==null?void 0:l.look).borderColor}).attr("stroke-width",i=>`${i.highlighted?3:1}px`),a.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",i=>i.width).attr("height",i=>i.height).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImage:((l=i.getConfig())==null?void 0:l.look).backgroundImage}),a.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).leftMargin}).attr("height",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).topMargin}).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImageTopLeft:((l=i.getConfig())==null?void 0:l.look).backgroundImageTopLeft}),a.filter(".stretchable-image-look").select("image.top-image").attr("x",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).leftMargin}).attr("y",0).attr("width",i=>{var r,l;return i.width-((r=i.getConfig())==null?void 0:r.look).rightMargin-((l=i.getConfig())==null?void 0:l.look).leftMargin}).attr("height",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).topMargin}).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImageTop:((l=i.getConfig())==null?void 0:l.look).backgroundImageTop}),a.filter(".stretchable-image-look").select("image.top-right-image").attr("x",i=>{var r;return i.width-((r=i.getConfig())==null?void 0:r.look).rightMargin}).attr("y",0).attr("width",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).rightMargin}).attr("height",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).topMargin}).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImageTopRight:((l=i.getConfig())==null?void 0:l.look).backgroundImageTopRight}),a.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).topMargin}).attr("width",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).leftMargin}).attr("height",i=>{var r,l;return i.height-((r=i.getConfig())==null?void 0:r.look).bottomMargin-((l=i.getConfig())==null?void 0:l.look).topMargin}).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImageLeft:((l=i.getConfig())==null?void 0:l.look).backgroundImageLeft}),a.filter(".stretchable-image-look").select("image.center-image").attr("x",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).leftMargin}).attr("y",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).topMargin}).attr("width",i=>{var r,l;return i.width-((r=i.getConfig())==null?void 0:r.look).rightMargin-((l=i.getConfig())==null?void 0:l.look).leftMargin}).attr("height",i=>{var r,l;return i.height-((r=i.getConfig())==null?void 0:r.look).bottomMargin-((l=i.getConfig())==null?void 0:l.look).topMargin}).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImageCenter:((l=i.getConfig())==null?void 0:l.look).backgroundImageCenter}),a.filter(".stretchable-image-look").select("image.right-image").attr("x",i=>{var r;return i.width-((r=i.getConfig())==null?void 0:r.look).rightMargin}).attr("y",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).topMargin}).attr("width",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).rightMargin}).attr("height",i=>{var r,l;return i.height-((r=i.getConfig())==null?void 0:r.look).bottomMargin-((l=i.getConfig())==null?void 0:l.look).topMargin}).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImageRight:((l=i.getConfig())==null?void 0:l.look).backgroundImageRight}),a.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",i=>{var r;return i.height-((r=i.getConfig())==null?void 0:r.look).bottomMargin}).attr("width",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).leftMargin}).attr("height",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).bottomMargin}).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImageBottomLeft:((l=i.getConfig())==null?void 0:l.look).backgroundImageBottomLeft}),a.filter(".stretchable-image-look").select("image.bottom-image").attr("x",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).leftMargin}).attr("y",i=>{var r;return i.height-((r=i.getConfig())==null?void 0:r.look).bottomMargin}).attr("width",i=>{var r,l;return i.width-((r=i.getConfig())==null?void 0:r.look).rightMargin-((l=i.getConfig())==null?void 0:l.look).leftMargin}).attr("height",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).bottomMargin}).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImageBottom:((l=i.getConfig())==null?void 0:l.look).backgroundImageBottom}),a.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",i=>{var r;return i.width-((r=i.getConfig())==null?void 0:r.look).rightMargin}).attr("y",i=>{var r;return i.height-((r=i.getConfig())==null?void 0:r.look).bottomMargin}).attr("width",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).rightMargin}).attr("height",i=>{var r;return((r=i.getConfig())==null?void 0:r.look).bottomMargin}).attr("href",i=>{var r,l;return i.selected?((r=i.getConfig())==null?void 0:r.look).selectedBackgroundImageBottomRight:((l=i.getConfig())==null?void 0:l.look).backgroundImageBottomRight}),a.filter(".resizable-x").select("line.left-resizer").attr("x1",Y/2).attr("x2",Y/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",Y/2).attr("y2",Y/2),a.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-Y/2).attr("x2",i=>i.width-Y/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-Y/2).attr("y2",i=>i.height-Y/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 o=e.exit(),s=e.enter().append("g").attr("id",i=>i.id).attr("class","diagram-port");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const a=s.merge(e);o.remove(),s.on(T.MouseOver,(i,r)=>{var l,c,h,f,u,p,g,d,m,v;!this.unfinishedConnection&&!this.dragging&&this.userHighlight.focusOn(r),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(((h=(c=(l=this.unfinishedConnection.start)==null?void 0:l.getNode())==null?void 0:c.type)==null?void 0:h.id)||"")&&this.unfinishedConnection.type.canFinishOnType(((u=(f=r.getNode())==null?void 0:f.type)==null?void 0:u.id)||"")||this.unfinishedConnection.type.canStartFromType(((g=(p=r.getNode())==null?void 0:p.type)==null?void 0:g.id)||"")&&this.unfinishedConnection.type.canFinishOnType(((v=(m=(d=this.unfinishedConnection.start)==null?void 0:d.getNode())==null?void 0:m.type)==null?void 0:v.id)||"")||$(L.NoDrop))}).on(T.MouseOut,()=>{this.unfinishedConnection&&$(L.Grabbing)}).on(T.Click,(i,r)=>{!i.ctrlKey&&!i.shiftKey&&this.userSelection.clear(),this.userSelection.toggle(Ot(r))}).on(T.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const l=new st(i,T.ContextMenu,r);if(this.diagramEvent$.next(l),!l.defaultPrevented&&this.canUserPerformAction(I.ContextMenu)){i.preventDefault();const c=Ot(r);this.userHighlight.focusOn(c),this.userSelection.add(c),this.contextMenu.open(i)}}).on(T.DoubleClick,(i,r)=>{const l=new st(i,T.DoubleClick,r);this.diagramEvent$.next(l)}).call(J().filter(i=>(this.secondaryButton=zt(i),!0)).on(P.Start,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(I.AddConnection)&&!r.removed?($(L.Grabbing),this.startConnection(r),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):$(L.NotAllowed)}).on(P.Drag,(i,r)=>{var l,c,h,f;if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(I.AddConnection)&&!r.removed&&this.unfinishedConnection!==void 0){const u=[i.x,i.y];(h=this.unfinishedConnectionTracer)==null||h.attr("d",Tn(this.unfinishedConnection.type.shape,this.unfinishedConnection.startCoords,u,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.width,(l=this.unfinishedConnection.startMarkerLook)==null?void 0:l.markerWidth,(c=this.unfinishedConnection.endMarkerLook)==null?void 0:c.markerWidth));const p=(f=this.unfinishedConnectionTracer)==null?void 0:f.node();if(p){let g=2;const d=p.getTotalLength();d<g&&(g=0);const m=p.getPointAtLength(d-g);this.unfinishedConnection.endCoords=[m.x,m.y]}else this.unfinishedConnection.endCoords=u;if(this.updateConnectionsInView(In),this.model.ports.length>0){const g=this.getPointerLocationRelativeToCanvas(i);let d=Number.POSITIVE_INFINITY,m;for(const v of this.model.ports){const w=v.distanceTo(g);w<d&&(d=w,m=v)}m&&d<Dh?this.userHighlight.focusOn(m):this.userHighlight.clear()}}}).on(P.End,(i,r)=>{var l;if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(I.AddConnection)&&!r.removed){(l=this.unfinishedConnectionTracer)==null||l.remove();const c=this.userHighlight.getFocus();if(c instanceof Vt)this.finishConnection(c);else if(c instanceof Mt&&c.rootElement instanceof Vt)this.finishConnection(c.rootElement);else if(c instanceof j||c instanceof nt||c instanceof Mt){let h;if(c instanceof j||c instanceof nt)h=c;else if(c.rootElement instanceof j||c.rootElement instanceof nt)h=c.rootElement;else{this.dropConnection();return}const f=h.getClosestPortToPoint([i.x,i.y]);f!==void 0?this.finishConnection(f):this.dropConnection()}else this.dropConnection()}$()}this.secondaryButton=!1})),s.append("circle"),a.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("circle").attr("cx",0).attr("cy",0).attr("r",kn.radius).attr("fill",i=>i.selected?kn.selectedColor:kn.highlightedColor).attr("opacity",i=>i.highlighted||i.selected?.5:0)}updateConnectionsInView(...t){const e=this.model.connections.filter(r=>this.priorityThreshold!==void 0?r.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let o=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,r=>r.id);const s=o.exit(),a=o.enter().append("g").attr("id",r=>r.id).attr("class","diagram-connection");t&&t.length>0&&(o=o.filter(r=>t.includes(r.id)));const i=a.merge(o);s.remove(),a.on(T.MouseOver,(r,l)=>{l.end!==void 0&&!this.dragging&&this.userHighlight.focusOn(l)}).on(T.Click,(r,l)=>{!r.ctrlKey&&!r.shiftKey&&this.userSelection.clear(),this.userSelection.toggle(l)}).on(T.ContextMenu,(r,l)=>{if(this.dragging){r.preventDefault(),r.stopPropagation(),this.dragging=!1;return}const c=new st(r,T.ContextMenu,l);this.diagramEvent$.next(c),!c.defaultPrevented&&this.canUserPerformAction(I.ContextMenu)&&(r.preventDefault(),this.userHighlight.focusOn(l),this.userSelection.add(l),this.contextMenu.open(r))}).on(T.DoubleClick,(r,l)=>{const c=new st(r,T.DoubleClick,l);this.diagramEvent$.next(c)}).call(J().filter(r=>(this.secondaryButton=zt(r),!0)).on(P.Start,r=>{this.startMultipleSelection(r)}).on(P.Drag,r=>{this.continueMultipleSelection(r)}).on(P.End,r=>{this.finishMultipleSelection(r)})),a.append("path").attr("class","diagram-connection-path"),a.append("path").attr("class","diagram-connection-path-box"),a.append("marker").attr("id",r=>`${r.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),a.append("marker").attr("id",r=>`${r.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",r=>r.removed?.5:1).select("path.diagram-connection-path").attr("d",r=>{var l,c;return Tn(r.type.shape,r.startCoords,r.endCoords,r.startDirection,r.endDirection,r.type.width,(l=r.startMarkerLook)==null?void 0:l.markerWidth,(c=r.endMarkerLook)==null?void 0:c.markerWidth)}).attr("marker-start",r=>`url(#${r.id}-start-marker)`).attr("marker-end",r=>`url(#${r.id}-end-marker)`).attr("stroke",r=>r.selected?r.type.selectedColor:r.type.color).attr("stroke-width",r=>`${r.highlighted?r.type.width+1:r.type.width}px`).attr("stroke-dasharray",r=>Ki(r.type.style,r.type.width)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",r=>{var l,c;return Tn(r.type.shape,r.startCoords,r.endCoords,r.startDirection,r.endDirection,r.type.width,(l=r.startMarkerLook)==null?void 0:l.markerWidth,(c=r.endMarkerLook)==null?void 0:c.markerWidth)}).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",r=>`${r.type.width+Lh}px`).attr("stroke-dasharray",r=>Ki(r.type.style,r.type.width)).attr("fill","none"),i.data().forEach(r=>{this.updateConnectionLabelsInView(r),this.updateConnectionMarkersInView(r)})}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 o=e.exit(),s=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=s.merge(e);o.remove(),s.style("box-sizing","border-box").on(T.MouseOver,(i,r)=>{this.dragging||this.userHighlight.focusOn(r)}).on(T.Click,(i,r)=>{!i.ctrlKey&&!i.shiftKey&&this.userSelection.clear(),this.userSelection.toggle(Ot(r))}).on(T.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const l=new st(i,T.ContextMenu,r);if(this.diagramEvent$.next(l),!l.defaultPrevented&&this.canUserPerformAction(I.ContextMenu)){i.preventDefault();const c=Ot(r);this.userHighlight.focusOn(c),this.userSelection.add(c),this.contextMenu.open(i)}}).on(T.DoubleClick,(i,r)=>{const l=new st(i,T.DoubleClick,r);this.diagramEvent$.next(l),!l.defaultPrevented&&this.canUserPerformAction(I.EditField)&&r.editable&&!r.removed&&(this.currentAction=new io(this,r.id,r.text,""),this.createInputField(r.text,r.coords,r.width,r.height,r.fontSize,r.fontFamily||U.fontFamily,c=>{r.text=c},c=>{r.text=c,this.currentAction instanceof io&&(this.currentAction.to=c,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(J().filter(i=>(this.secondaryButton=zt(i),!0)).on(P.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let l;r.rootElement instanceof j?l=r.rootElement:r.rootElement instanceof nt&&(l=r.rootElement.node),l?this.startMovingNode(i,l):$(L.NotAllowed)}}).on(P.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let l;r.rootElement instanceof j?l=r.rootElement:r.rootElement instanceof nt&&(l=r.rootElement.node),l?this.continueMovingNode(i,l):$(L.NotAllowed)}}).on(P.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let l;r.rootElement instanceof j?l=r.rootElement:r.rootElement instanceof nt&&(l=r.rootElement.node),l?this.finishMovingNode(i,l):$()}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===Kt.Center?"center":i.horizontalAlign===Kt.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Be.Center?"center":i.verticalAlign===Be.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":"100%").style("max-height",i=>i.fit?"default":"100%").style("overflow",i=>i.fit?"default":"hidden").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===Kt.Center?"center":i.horizontalAlign===Kt.Right?"end":"start").style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>"))}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-object").data(this.model.objects.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const o=e.exit(),s=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))),s.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),o.remove(),s.on(T.ContextMenu,i=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new st(i,T.ContextMenu,void 0);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(I.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(T.DoubleClick,(i,r)=>{const l=new st(i,T.DoubleClick,r);this.diagramEvent$.next(l)}).call(J().filter(i=>(this.secondaryButton=zt(i),!0)).on(P.Start,i=>{this.startMultipleSelection(i)}).on(P.Drag,i=>{this.continueMultipleSelection(i)}).on(P.End,i=>{this.finishMultipleSelection(i)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-decorator").data(this.model.decorators.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const o=e.exit(),s=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))),s.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),o.remove(),s.on(T.ContextMenu,i=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const r=new st(i,T.ContextMenu,void 0);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(I.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(T.DoubleClick,(i,r)=>{const l=new st(i,T.DoubleClick,r);this.diagramEvent$.next(l)}).call(J().filter(i=>(this.secondaryButton=zt(i),!0)).on(P.Start,i=>{this.startMultipleSelection(i)}).on(P.Drag,i=>{this.continueMultipleSelection(i)}).on(P.End,i=>{this.finishMultipleSelection(i)}))}updateConnectionLabelsInView(t){var i,r,l;const e=this.selectCanvasView().select(`g.diagram-connection#${t.id}`),s=e.select("path").node(),a={...U,...t.type.label};if(s){const c=s.getTotalLength();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 h=(i=e.select("g.diagram-connection-start-label text").node())==null?void 0:i.getBoundingClientRect();if(h){const p=t.startLabel?h.width/this.zoomTransform.k+wn(a)+xn(a):0,g=t.startLabel?h.height/this.zoomTransform.k+Cn(a)+bn(a):0,d=s.getPointAtLength(Math.max(it(a)+p/2,St(a)+p/2,ot(a)+g/2,kt(a)+g/2));e.select("g.diagram-connection-start-label path").attr("d",Oe(-p/2,-g/2,p,g)).attr("fill",t.selected?t.type.selectedColor:t.type.color).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${d.x},${d.y})`)}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 f=(r=e.select("g.diagram-connection-middle-label text").node())==null?void 0:r.getBoundingClientRect();if(f){const p=t.middleLabel?f.width/this.zoomTransform.k+wn(a)+xn(a):0,g=t.middleLabel?f.height/this.zoomTransform.k+Cn(a)+bn(a):0,d=s.getPointAtLength(c/2);e.select("g.diagram-connection-middle-label path").attr("d",Oe(-p/2,-g/2,p,g)).attr("fill",t.selected?t.type.selectedColor:t.type.color).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${d.x},${d.y})`)}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 u=(l=e.select("g.diagram-connection-end-label text").node())==null?void 0:l.getBoundingClientRect();if(u){const p=t.endLabel?u.width/this.zoomTransform.k+wn(a)+xn(a):0,g=t.endLabel?u.height/this.zoomTransform.k+Cn(a)+bn(a):0,d=s.getPointAtLength(c-Math.max(it(a)+p/2,St(a)+p/2,ot(a)+g/2,kt(a)+g/2));e.select("g.diagram-connection-end-label path").attr("d",Oe(-p/2,-g/2,p,g)).attr("fill",t.selected?t.type.selectedColor:t.type.color).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${d.x},${d.y})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`g.diagram-connection#${t.id}`),o=e.select("marker.diagram-connection-start-marker"),s=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?o.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.markerWidth).attr("markerHeight",t.startMarkerLook.markerHeight).attr("refX",t.startMarkerLook.markerRefX).attr("refY",t.startMarkerLook.markerRefY).select("image").attr("href",t.selected?t.startMarkerLook.selectedImage:t.startMarkerLook.image).attr("width",t.startMarkerLook.markerWidth).attr("height",t.startMarkerLook.markerHeight):o.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?s.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.markerWidth).attr("markerHeight",t.endMarkerLook.markerHeight).attr("refX",t.endMarkerLook.markerRefX).attr("refY",t.endMarkerLook.markerRefY).select("image").attr("href",t.selected?t.endMarkerLook.selectedImage:t.endMarkerLook.image).attr("width",t.endMarkerLook.markerWidth).attr("height",t.endMarkerLook.markerHeight):s.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fitFieldRootInView(t){var o,s,a,i,r,l,c,h,f,u,p;const e=this.model.fields.get(t);if(e){if(e.rootElement instanceof j&&e.fit){const g=this.minimumSizeOfField(e);let d=g[0]+it(e.rootElement.type.label)+St(e.rootElement.type.label)-e.rootElement.width,m=g[1]+ot(e.rootElement.type.label)+kt(e.rootElement.type.label)-e.rootElement.height;this.snapToGrid&&(d=Math.ceil(d/this.gridSize)*this.gridSize,m=Math.ceil(m/this.gridSize)*this.gridSize),e.rootElement.width+d<e.rootElement.type.minWidth&&(d=e.rootElement.type.minWidth-e.rootElement.width),e.rootElement.height+m<e.rootElement.type.minHeight&&(m=e.rootElement.type.minHeight-e.rootElement.height),e.rootElement.stretch(x.Right,d),e.rootElement.stretch(x.Bottom,m)}if(e.rootElement instanceof nt&&e.fit){const g=this.minimumSizeOfField(e);let d=g[0],m=g[1];for(const C of((o=e.rootElement.node)==null?void 0:o.sections)||[])C.label&&(C.indexXInNode===e.rootElement.indexXInNode&&C.indexYInNode!==e.rootElement.indexYInNode?d=Math.max(d,this.minimumSizeOfField(C.label)[0]):C.indexXInNode!==e.rootElement.indexXInNode&&C.indexYInNode===e.rootElement.indexYInNode&&(m=Math.max(m,this.minimumSizeOfField(C.label)[1])));g[0]<d&&(g[0]=d),g[1]<m&&(g[1]=m);let v=g[0]+it((a=(s=e.rootElement)==null?void 0:s.getConfig())==null?void 0:a.label)+St((r=(i=e.rootElement)==null?void 0:i.getConfig())==null?void 0:r.label)-e.rootElement.width,w=g[1]+ot((c=(l=e.rootElement)==null?void 0:l.getConfig())==null?void 0:c.label)+kt((f=(h=e.rootElement)==null?void 0:h.getConfig())==null?void 0:f.label)-e.rootElement.height;this.snapToGrid&&(v=Math.ceil(v/this.gridSize)*this.gridSize,w=Math.ceil(w/this.gridSize)*this.gridSize),e.rootElement.width+v<(e.rootElement.getMinWidth()||0)&&(v=(e.rootElement.getMinWidth()||0)-e.rootElement.width),e.rootElement.height+w<(e.rootElement.getMinHeight()||0)&&(w=(e.rootElement.getMinHeight()||0)-e.rootElement.height),(u=e.rootElement.node)==null||u.stretchSections(x.Right,v,e.rootElement.indexXInNode,e.rootElement.indexYInNode),(p=e.rootElement.node)==null||p.stretchSections(x.Bottom,w,e.rootElement.indexXInNode,e.rootElement.indexYInNode)}}}fitNodeInView(t){var o,s;const e=this.model.nodes.get(t);if(e&&e.sections.length>0&&this.priorityThreshold){let a=0,i=0;for(const r of e.sections)if(r.getPriority()>=this.priorityThreshold){const l=r.coords[0]+r.width-e.coords[0],c=r.coords[1]+r.height-e.coords[1];a=Math.max(a,l),i=Math.max(i,c)}a+=((o=e.type.sectionGrid)==null?void 0:o.margin)||0,i+=((s=e.type.sectionGrid)==null?void 0:s.margin)||0,e.stretch(x.Right,a-e.width),e.stretch(x.Bottom,i-e.height)}}selectRoot(){return O(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectRoot().select(".daga-canvas-view")}selectCanvasElements(){return this.selectRoot().select(".daga-canvas-elements")}startConnection(t){var e,o,s,a;if(this.connectionType&&(this.connectionType.canStartFromType(((o=(e=t.getNode())==null?void 0:e.type)==null?void 0:o.id)||"")||this.connectionType.canFinishOnType(((a=(s=t.getNode())==null?void 0:s.type)==null?void 0:a.id)||"")))this.unfinishedConnection=new Ct(this.model,this.connectionType,t,void 0,In);else if(this.inferConnectionType){let i=this.model.connections.types.all().find(r=>{var l,c;return r.canStartFromType(((c=(l=t.getNode())==null?void 0:l.type)==null?void 0:c.id)||"")});i===void 0&&(i=this.model.connections.types.all().find(r=>{var l,c;return r.canFinishOnType(((c=(l=t.getNode())==null?void 0:l.type)==null?void 0:c.id)||"")})),i!==void 0&&(this.unfinishedConnection=new Ct(this.model,i,t,void 0,In))}}finishConnection(t){var e,o,s,a,i,r,l,c,h,f,u,p,g,d,m,v;if(this.userHighlight.clear(),this.unfinishedConnection!==void 0)if(this.unfinishedConnection.start!==t)if(this.unfinishedConnection.type.canStartFromType(((a=(s=(o=(e=this.unfinishedConnection)==null?void 0:e.start)==null?void 0:o.getNode())==null?void 0:s.type)==null?void 0:a.id)||"")&&this.unfinishedConnection.type.canFinishOnType(((r=(i=t.getNode())==null?void 0:i.type)==null?void 0:r.id)||"")){const w=new An(this,this.unfinishedConnection.type,(l=this.unfinishedConnection.start)==null?void 0:l.id,t.id);this.dropConnection(),w.do(),this.actionStack.add(w)}else if(this.unfinishedConnection.type.canFinishOnType(((u=(f=(h=(c=this.unfinishedConnection)==null?void 0:c.start)==null?void 0:h.getNode())==null?void 0:f.type)==null?void 0:u.id)||"")&&this.unfinishedConnection.type.canStartFromType(((g=(p=t.getNode())==null?void 0:p.type)==null?void 0:g.id)||"")){const w=new An(this,this.unfinishedConnection.type,t.id,(d=this.unfinishedConnection.start)==null?void 0:d.id);this.dropConnection(),w.do(),this.actionStack.add(w)}else if(this.inferConnectionType){let w=this.model.connections.types.all().find(y=>{var k,M,N,R,F,H;return y.canStartFromType(((R=(N=(M=(k=this.unfinishedConnection)==null?void 0:k.start)==null?void 0:M.getNode())==null?void 0:N.type)==null?void 0:R.id)||"")&&y.canFinishOnType(((H=(F=t.getNode())==null?void 0:F.type)==null?void 0:H.id)||"")}),C=!1;if(w===void 0&&(w=this.model.connections.types.all().find(y=>{var k,M,N,R,F,H;return y.canFinishOnType(((R=(N=(M=(k=this.unfinishedConnection)==null?void 0:k.start)==null?void 0:M.getNode())==null?void 0:N.type)==null?void 0:R.id)||"")&&y.canStartFromType(((H=(F=t.getNode())==null?void 0:F.type)==null?void 0:H.id)||"")}),C=!0),w!==void 0){const y=new An(this,w,C?t.id:(m=this.unfinishedConnection.start)==null?void 0:m.id,C?(v=this.unfinishedConnection.start)==null?void 0:v.id:t.id);this.dropConnection(),y.do(),this.actionStack.add(y)}else this.dropConnection()}else this.dropConnection();else this.dropConnection()}dropConnection(){var t,e,o,s;(t=this.unfinishedConnection)==null||t.setStart(void 0),(e=this.unfinishedConnection)==null||e.setEnd(void 0),(s=(o=this.unfinishedConnection)==null?void 0:o.select())==null||s.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,s,a,i,r,l){this.removeInputField();const c=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${o}px`).attr("height",`${s}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=c;const h=c.append("xhtml:textarea");let f,u;h.text(t).style("box-sizing","border-box").style("width",`${o}px`).style("height",`${s}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(T.KeyDown,g=>{g.stopPropagation()}).on(T.KeyUp,g=>{if(g.stopPropagation(),g.key===Et.Escape){const d=h.property("value");this.removeInputField(),l&&l(d)}}).on(T.Input,()=>{const g=h.property("value");h.attr("cols",Kc(g)+1),h.attr("rows",Zc(g)+1),h.style("width",""),h.style("height",""),f=h.property("scrollWidth")+1,u=h.property("scrollHeight")+1;const d=Math.max(f,o),m=Math.max(u,s);c==null||c.attr("width",`${d}px`),h.style("width",`${d}px`),c==null||c.attr("height",`${m}px`),h.style("height",`${m}px`),r&&r(g)}).on(T.Click,g=>{g.stopPropagation()}).on(T.FocusOut,()=>{const g=h.property("value");this.removeInputField(),l&&l(g)});const p=h.node();p.focus(),p.select()}removeInputField(){var t,e,o;(e=(t=this.inputFieldContainer)==null?void 0:t.select("input"))==null||e.on(T.Blur,null),(o=this.inputFieldContainer)==null||o.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){var s,a;const e=(a=(s=t.select())==null?void 0:s.select("p"))==null?void 0:a.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(I.MoveNode)&&!e.removed)if($(L.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(o=>o instanceof j)>1)this.currentAction=new Sn(this,this.userSelection.filter(o=>o instanceof j).map(o=>o.id),e.coords);else{const o=e.getLastAncestor();this.currentAction=new Z(this,I.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 $(L.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(I.MoveNode)&&(this.currentAction instanceof Sn||this.currentAction instanceof Z)&&!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,s,a;if(this.canUserPerformAction(I.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let i=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(i=this.getClosestGridPoint(i)),this.currentAction instanceof Sn){const r=this.currentAction.delta;this.currentAction.delta=[i[0]-r[0],i[1]-r[1]],e.selected?this.userSelection.move([r[0]-e.coords[0],r[1]-e.coords[1]]):e.move(r)}else if(this.currentAction instanceof Z){e.move(i);const l=this.model.nodes.getAtCoordinates(t.x,t.y).filter(f=>f.id!==e.id&&!f.isDescendantOf(e)).filter(f=>f.type.childrenTypes.includes(e.type.id)),c=hr(l),h=c[c.length-1];if(h!==e.parent&&(e.type.canBeParentless||h!==void 0)){const f=h==null?void 0:h.getLastAncestor(),u=this.currentAction.from,p=new xh(this,e.id,(o=e.parent)==null?void 0:o.id,h==null?void 0:h.id,u,e.getGeometry(),f==null?void 0:f.id,f==null?void 0:f.getGeometry(e.id),f==null?void 0:f.getGeometry(e.id));(s=e.parent)==null||s.removeChild(e),h!==void 0&&h.addChild(e),p.toChildGeometry=e.getGeometry(e.id),p.toAncestorGeometry=f==null?void 0:f.getGeometry(e.id),this.currentAction=p}else{const f=e==null?void 0:e.getLastAncestor();this.currentAction.ancestorId=f==null?void 0:f.id,this.currentAction.fromAncestorGeometry=f==null?void 0:f.getGeometry(e.id),(a=e.parent)==null||a.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=f==null?void 0:f.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}$(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectCanvasElements().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){var o,s,a,i;const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&($(L.Crosshair),(i=(a=(s=(o=this.multipleSelectionContainer)==null?void 0:o.attr("x",Math.min(this.draggingFrom[0],e[0])))==null?void 0:s.attr("y",Math.min(this.draggingFrom[1],e[1])))==null?void 0:a.attr("width",Math.abs(this.draggingFrom[0]-e[0])))==null||i.attr("height",Math.abs(this.draggingFrom[1]-e[1])),this.dragging=!0)}finishMultipleSelection(t){var o;const e=this.getPointerLocationRelativeToCanvas(t);(o=this.multipleSelectionContainer)==null||o.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const s of this.model.nodes)Oc([s.coords,[s.coords[0]+s.width,s.coords[1]+s.height]],[this.draggingFrom,e])&&this.userSelection.add(s);this.multipleSelectionOn=!1,$()}};Je.canvasCount=0;let Un=Je;const zt=n=>!!n.button,Tn=(n,t,e,o,s,a,i,r)=>Gc(n,[t,e],o,s,Math.max(10,i||0,r||0)*a),$=n=>{n?O("body").style("cursor",n):O("body").style("cursor",L.Auto)},Ot=n=>n instanceof j?n:n instanceof nt?n.node||n:n.rootElement instanceof j||n.rootElement instanceof nt||n.rootElement instanceof Vt?Ot(n.rootElement):n;class pr{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 s=o%2>0?o:-o,a=s>0?1:-1,i=[e[0]+s,e[1]+s];for(let r=e[0];r!==i[0]+a;r+=a)if(e[0]=r,this.get(e)===void 0)return e;for(let r=e[1];r!==i[1]+a;r+=a)if(e[1]=r,this.get(e)===void 0)return e}}}class Fh{apply(t){var r,l;if(t.nodes.length===0)return t;const e=new pr,o=t.nodes.filter(c=>!c.parent);for(;o.length>0;)gr(o[0],e,[0,0],o);const s=Math.max(...t.nodes.map(c=>c.width)),a=Math.max(...t.nodes.map(c=>c.height)),i=(((r=t.canvas)==null?void 0:r.gridSize)||0)*2;for(let c=e.minY();c<=e.maxY();++c)for(let h=e.minX();h<=e.maxX();++h){const f=e.get([h,c]);f!==void 0&&f.move([h*(s+i),c*(a+i)])}return(l=t.canvas)==null||l.diagramChange$.next(),t}}const gr=(n,t,e,o)=>{const s=t.getClosestEmptyCoordinate(e);t.set(s,n),K(o,n);for(const a of n.getAdjacentNodes())o.includes(a)&&gr(a,t,s,o)};class Oh{apply(t){var h,f;if(t.nodes.length===0)return t;const e=new pr,o=t.nodes.filter(u=>!u.parent),s={},a=o[0];let i=[a];for(s[a.id]=[0,0];o.length>0;){const u=[];for(const p of i){e.set(e.getClosestEmptyCoordinate(s[p.id]),p),K(o,p);const g=p.getAdjacentNodes();for(const d of g)o.includes(d)&&(u.push(d),s[d.id]=s[p.id])}if(u.length>0)i=u;else if(o.length>0){const p=o[0];i=[p],s[p.id]=e.getClosestEmptyCoordinate([0,0])}}const r=Math.max(...t.nodes.map(u=>u.width)),l=Math.max(...t.nodes.map(u=>u.height)),c=(((h=t.canvas)==null?void 0:h.gridSize)||0)*2;for(let u=e.minY();u<=e.maxY();++u)for(let p=e.minX();p<=e.maxX();++p){const g=e.get([p,u]);g!==void 0&&g.move([p*(r+c),u*(l+c)])}return(f=t.canvas)==null||f.diagramChange$.next(),t}}class hn{apply(t){var r,l;if(t.nodes.length===0)return t;const e=(((r=t.canvas)==null?void 0:r.gridSize)||0)*2;let o=t.nodes.filter(c=>!c.parent);const s=o[0];K(o,s);const a=[[s]];for(;o.length>0;){const c=a[a.length-1],h=[];for(const f of c){const u=f.getAdjacentNodes();for(const p of u)o.includes(p)&&(K(o,p),h.push(p))}h.length>0?a.push(h):(a.push(o),o=[])}let i=0;for(const c of a){let h=0;for(const u of c)u.move([i,h]),h+=e+u.height;const f=Math.max(...c.map(u=>u.width));i+=e+f}for(const c of t.connections)c.tighten();return(l=t.canvas)==null||l.diagramChange$.next(),t}}class Bh{apply(t){var f,u;if(t.nodes.length===0)return t;new hn().apply(t);const e=(((f=t.canvas)==null?void 0:f.gridSize)||0)*2,o=.99,s=1,a=.1,i=2e5,r=.5,l=1,c=.002;let h=100;for(;h>s;){h=h*o;const p=[0,0];{for(const g of t.nodes)p[0]=p[0]+g.coords[0]+g.width/2,p[1]=p[1]+g.coords[1]+g.width/2;p[0]=p[0]/t.nodes.length,p[1]=p[1]/t.nodes.length}for(const g of t.nodes){const d=g.getAdjacentNodes();for(const m of t.nodes){const v=[g.coords[0]+g.width/2,g.coords[1]+g.height/2],w=[m.coords[0]+m.width/2,m.coords[1]+m.height/2],C=ir(g.coords,m.coords),y=[m.coords[0],m.coords[1]];if(d.includes(m)&&C>0&&(C>e+(Math.max(g.width,g.height)+Math.max(m.width,m.height))/2?(y[0]=y[0]-(w[0]-v[0])*a,y[1]=y[1]-(w[1]-v[1])*a):(y[0]=y[0]+(w[0]-v[0])*r,y[1]=y[1]+(w[1]-v[1])*r)),C>0){const k=i/(C*C);y[0]=y[0]+k*(w[0]-v[0])/C,y[1]=y[1]+k*(w[1]-v[1])/C}else y[0]=y[0]+l*(Math.random()*2-1),y[1]=y[1]+l*(Math.random()*2-1);y[0]=y[0]-(w[0]-p[0])*c,y[1]=y[1]-(w[1]-p[1])*c,y[0]-m.coords[0]>h?y[0]=m.coords[0]+h:y[0]-m.coords[0]<-h&&(y[0]=m.coords[0]-h),y[1]-m.coords[1]>h?y[1]=m.coords[1]+h:y[1]-m.coords[1]<-h&&(y[1]=m.coords[1]-h),m.move(y)}}}if(t.canvas&&t.canvas.snapToGrid)for(const p of t.nodes){const g=t.canvas.getClosestGridPoint(p.coords);p.move(g)}for(const p of t.connections)p.tighten();return(u=t.canvas)==null||u.diagramChange$.next(),t}}class Gh{apply(t){var a,i;if(t.nodes.length===0)return t;const e=(((a=t.canvas)==null?void 0:a.gridSize)||0)*2,o=t.nodes.filter(r=>!r.parent);o.sort((r,l)=>l.type.priority-r.type.priority);let s=0;for(const r of o)r.move([s,0]),s+=r.width+e;return(i=t.canvas)==null||i.diagramChange$.next(),t}}class Uh{apply(t){var h,f;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(u=>u.getPriority())),o=Math.min(...t.nodes.map(u=>u.getPriority()));if(e===o)return new hn().apply(t),t;const s=(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,a=t.nodes.filter(u=>!u.parent),i=[],r=t.nodes.filter(u=>!u.parent).filter(u=>u.getPriority()>=e),l=[];if(r.length>1){const u=r[0];r.splice(0,1),l.push(u);const p=[u],g=[u];for(;p.length>0;){const d=p[0];p.splice(0,1),r.includes(d)&&(l.push(d),K(r,d));const m=d.getAdjacentNodes();for(const v of m)g.includes(v)||(p.push(v),g.push(v))}for(const d of r)l.push(d)}else l.push(r[0]);for(const u of l)K(a,u),i.push([u]);for(i.push([]),a.sort((u,p)=>p.type.priority-u.type.priority);a.length>0;){const u=a[0];a.splice(0,1);const p=[u],g=[u];let d=!1;for(;p.length>0;){const m=p[0];p.splice(0,1);const v=l.indexOf(m);if(v>=0){i[v].push(u),d=!0;break}else{const w=m.getAdjacentNodes();for(const C of w)g.includes(C)||(p.push(C),g.push(C))}}d||i[i.length-1].push(u)}let c=0;for(let u=0;u<i.length;++u){let p=0;for(let d=0;d<i[u].length;++d){const m=i[u][d];m.move([c,p]),p+=s+m.height}const g=Math.max(...i[u].map(d=>d.width));c+=s+g}for(const u of t.connections)u.tighten();return(f=t.canvas)==null||f.diagramChange$.next(),t}}class jh{apply(t){var h,f;if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(u=>u.getPriority())),o=Math.min(...t.nodes.map(u=>u.getPriority()));if(e===o)return new hn().apply(t),t;const s=(((h=t.canvas)==null?void 0:h.gridSize)||0)*2,a=t.nodes.filter(u=>!u.parent).sort((u,p)=>p.getPriority()-u.getPriority()),i=[];for(;a.length>0;){const u=a[0];a.splice(0,1);const p=new ii(void 0,u);mr(p,a),i.push(p)}const r=[];for(const u of i)r.push([u]),vr(u,r,r.length);const l=Math.max(...t.nodes.map(u=>u.height));let c=0;for(let u=0;u<r.length;++u){let p=0;for(let d=0;d<r[u].length;++d){const m=r[u][d];m.node.move([c,p]),p+=(s+l)*m.countBranchHeight()}const g=Math.max(...r[u].map(d=>d.node.width));c+=s+g}for(const u of t.connections)u.tighten();return(f=t.canvas)==null||f.diagramChange$.next(),t}}const mr=(n,t)=>{for(const e of n.node.getAdjacentNodes().sort((o,s)=>s.getPriority()-o.getPriority())){const o=t.indexOf(e);if(o>=0){t.splice(o,1);const s=n.addBranch(e);mr(s,t)}}},vr=(n,t,e)=>{if(n.branches.length>0){for(;e>=t.length;)t.push([]);for(const o of n.branches)t[e].push(o),vr(o,t,e+1)}};class ii{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new ii(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 Hh{apply(t){var a,i;if(t.nodes.length===0)return t;const e=(((a=t.canvas)==null?void 0:a.gridSize)||0)*2,o=t.nodes.filter(r=>!r.parent);o.sort((r,l)=>l.type.priority-r.type.priority);let s=0;for(const r of o)r.move([0,s]),s+=r.height+e;return(i=t.canvas)==null||i.diagramChange$.next(),t}}const oo={adjacency:new Fh,breadth:new hn,"breadth-adjacency":new Oh,force:new Bh,horizontal:new Gh,priority:new Uh,tree:new jh,vertical:new Hh},Xh=B.createContext({}),Ht=B.createContext({});class Yh{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){console.log("highlightProperty",t)}}const oi=({direction:n,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:o,disabled:s,rule:a,collapsedValue:i,visibleValue:r,onCollapse:l})=>{const[c,h]=B.useState(o),f=()=>{if(!s){const p=!c;h(p),l==null||l(p);let g;if(typeof t=="string")g=O(t),e&&(g=g.select(e));else{const d=t;if(!d)throw new Error("collapsableSelector is not a valid ref");g=O(d.current),e&&(g=g.select(e))}g.style(a,p?i:r)}},u=()=>{switch(n){case x.Right:return s?"daga-horizontal-none":c?"daga-horizontal-right":"daga-horizontal-left";case x.Bottom:return s?"daga-vertical-none":c?"daga-vertical-down":"daga-vertical-up";case x.Left:return s?"daga-horizontal-none":c?"daga-horizontal-left":"daga-horizontal-right";case x.Top:return s?"daga-vertical-none":c?"daga-vertical-up":"daga-vertical-down"}};return A.jsx("daga-collapse-button",{children:A.jsx("button",{className:`daga-collapse-button daga-${n}`,onClick:f,children:A.jsx("div",{className:u()})})})},Wh=()=>{const n=B.useContext(Ht),t=B.useRef(null),[e,o]=B.useState([]);Rc(n.validatorChange$,n.diagramChange$).pipe(Fc(1),ti(()=>s())).subscribe();const s=()=>{o([]);for(const i of n.validators){const r=i.validate(n.model);o(r)}},a=i=>{var r,l,c,h;if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const f=n.model.nodes.get(i.elementId)||n.model.connections.get(i.elementId);f&&n.userHighlight.add(f)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){n.userSelection.openInPropertyEditor(n.model.nodes.get(i.elementId)||n.model.connections.get(i.elementId));const f=n.model.nodes.get(i.elementId)||n.model.connections.get(i.elementId);f&&n.userHighlight.add(f),(l=(r=n.parentComponent)==null?void 0:r.propertyEditor)==null||l.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(n.userSelection.openInPropertyEditor(),(h=(c=n.parentComponent)==null?void 0:c.propertyEditor)==null||h.highlightProperty(...i.propertyNames))};return A.jsx("daga-errors",{children:A.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&A.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:A.jsx("span",{children:"No errors found"})}),e.length>0&&A.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[A.jsxs("span",{children:[e.length," errors found"]}),A.jsx("div",{className:"daga-collapse-button-container",children:A.jsx(oi,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:x.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&A.jsx("div",{className:"daga-error-panel",children:A.jsx("ol",{children:e.map((i,r)=>A.jsx("li",{onClick:()=>a(i),dangerouslySetInnerHTML:{__html:i.message}},r))})})]})})},qh=({valueSet:n,onValueChange:t})=>{var i;const[e]=B.useState((n==null?void 0:n.displayedProperties)||[]),s=B.useContext(Ht).canUserPerformAction(I.UpdateValues)&&((i=n==null?void 0:n.rootElement)==null?void 0:i.removed)!==!0,a=r=>"daga-property-name-"+r.replace(/\s/g,"");return A.jsx("daga-object-editor",{children:e.map(r=>A.jsxs("div",{className:`daga-property ${a(r.name)}`,children:[A.jsx("p",{className:"daga-property-name",children:r.name}),r.type===ye.Text&&A.jsx("input",{type:"daga-text",disabled:!r.editable||!s,value:n==null?void 0:n.getValue(r.name),onChange:l=>t(r,l.target.value)}),r.type===ye.TextArea&&A.jsx("textarea",{disabled:!r.editable||!s,value:n==null?void 0:n.getValue(r.name),onChange:l=>t(r,l.target.value)})]},r.name))})},yr=({valueSet:n,depth:t})=>{const e=B.useContext(Ht),o=B.useRef(null),s=c=>"daga-property-name-"+c.replace(/\s/g,""),a=()=>{for(const c of(n==null?void 0:n.displayedProperties)||[]){let h=0,f=0,u=0;const p=O(o.current).select(`.daga-property.${s(c.name)}.daga-depth-${t}`);p.select("button.daga-move-button").call(J().on(P.Start,g=>{var v;$(L.Grabbing);const d=e.getPointerLocationRelativeToScreen(g);if(d.length<2||isNaN(d[0])||isNaN(d[1]))return;const m=(v=p.node())==null?void 0:v.getBoundingClientRect();h=(m==null?void 0:m.width)||0,f=(m==null?void 0:m.height)||0,p.style("position","fixed").style("left",`${d[0]-h/2}px`).style("top",`${d[1]-f/2}px`).style("width",`${h}px`).style("height",`${f}px`).style("z-index",1)}).on(P.Drag,g=>{$(L.Grabbing);const d=e.getPointerLocationRelativeToScreen(g);d.length<2||isNaN(d[0])||isNaN(d[1])||(p.style("position","fixed").style("left",`${d[0]-h/2}px`).style("top",`${d[1]-f/2}px`).style("width",`${h}px`).style("height",`${f}px`).style("z-index",1),O(o.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style("visibility","hidden").style("height",0),u=i(d),O(o.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on(P.End,g=>{var m,v;$(L.Auto),p.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),O(o.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const d=e.getPointerLocationRelativeToScreen(g);d.length<2||isNaN(d[0])||isNaN(d[1])||(u=i(d),(m=n==null?void 0:n.displayedProperties)==null||m.splice(n.displayedProperties.indexOf(c),1),(v=n==null?void 0:n.displayedProperties)==null||v.splice(u,0,c))}))}},i=c=>{var u;const h=(n==null?void 0:n.propertySet.propertyList)||[],f=[];for(let p=0;p<=h.length;++p){const g=(u=O(o.current).select(`.daga-dropbar.daga-index-${p}.daga-depth-${t}`).node())==null?void 0:u.getBoundingClientRect();g&&f.push([g.x+g.width/2,g.y+g.height/2])}if(f.length>0){const p=f.map(d=>((c[0]-d[0])**2+(c[1]-d[1])**2)**.5);return p.indexOf(Math.min(...p))}return 0},r=c=>{var f;if(n===void 0)return;let h;c instanceof nh?h=c:c instanceof Event?h=n==null?void 0:n.propertySet.getProperty(((f=c.target)==null?void 0:f.value)||""):h=n==null?void 0:n.propertySet.getProperty(c||""),h&&(n==null||n.hideProperty(h)),a()},l=c=>Array.isArray(c)?c.join(", "):Bn(c)?Object.entries(c).map(h=>h.map(f=>JSON.stringify(f)).join(": ")).join(", "):c instanceof Date?c.toLocaleString():c==null?"":""+c;return A.jsxs("daga-property-settings",{ref:o,children:[A.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),n==null?void 0:n.displayedProperties.map((c,h)=>A.jsxs("div",{className:`daga-property-and-dropbar ${s(c.name)} daga-depth-${t}`,children:[A.jsxs("div",{className:`daga-property ${s(c.name)} daga-depth-${t}`,children:[A.jsxs("div",{className:"daga-property-name",children:[A.jsx("span",{children:c.name}),A.jsxs("div",{className:"daga-buttons",children:[A.jsx("button",{className:"daga-property-button daga-move-button",children:A.jsx("div",{className:"daga-icon daga-move-icon"})}),A.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>r(c.name),children:A.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),c.type!==ye.Object&&A.jsx("div",{className:"daga-property-value",children:l(n==null?void 0:n.getValue(c.name))}),c.type===ye.Object&&A.jsx(yr,{valueSet:n==null?void 0:n.getSubValueSet(c.name),depth:t+1})]}),A.jsx("div",{className:`daga-dropbar daga-index-${h+1} daga-depth-${t}`})]},c.name))]})},Kh=({location:n,direction:t,width:e,title:o,valueSet:s,onValueChange:a})=>{const i=B.useRef(null),[r,l]=B.useState(!1),[c,h]=B.useState(!1),f=()=>O(i.current);return B.useEffect(()=>{if(i.current)switch(t){case x.Bottom:case x.Top:f().style("width",e);break;case x.Left:case x.Right:f().style("height",e);break}},[e,t]),A.jsx("daga-property-editor",{children:A.jsxs("div",{ref:i,className:`daga-panel daga-bottom daga-${n} daga-${t}`,children:[A.jsx(oi,{disabled:!s||!s.propertySet||!s.propertySet.hasProperties(),collapsed:r,direction:t,collapsableSelector:i,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:l}),s&&s.propertySet&&s.propertySet.hasProperties()&&!r&&A.jsxs("div",{className:"daga-panel-content",children:[o&&A.jsxs("p",{className:"daga-title",children:[o,A.jsx("button",{className:"daga-property-button",onClick:()=>h(!c),children:A.jsx("div",{className:`daga-icon daga-settings-icon ${c?"daga-unrotate":"daga-rotate"}`})})]}),!c&&A.jsx(qh,{valueSet:s,onValueChange:a}),c&&A.jsx(yr,{valueSet:s,depth:0})]})]})})},Zh=n=>{const t=B.useContext(Ht),[e,o]=B.useState(n.currentPalette||n.palettes[0]),[s,a]=B.useState(0),[i,r]=B.useState(void 0),l=B.useRef(null),c=d=>{if(o(d),h().selectAll("*").remove(),a(t.getPriorityThreshold()||0),d.categories&&f(d.categories),d.templates)for(const m of d.templates)u(m)},h=()=>O(l.current).select(".daga-palette-view"),f=d=>{const m=h().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");m.append("option").attr("value","").text("(None selected)");for(const v in d)m.append("option").attr("value",v).text(v);m.on(T.Change,()=>{i&&h().selectAll(".daga-template-container.daga-in-category").remove();const v=m.property("value");r(v);const w=d[v]||[];for(const C of w)u(C,"daga-in-category")}),i&&(m.property("value",i),m.dispatch(T.Change))},u=(d,m)=>{if(d.templateType==="node"){const v=t.model.nodes.types.get(d.type);v?p(v,d,m):console.error(`Could not find a node type called '${d.type}'`)}else if(d.templateType==="connection"){const v=t.model.connections.types.get(d.type);v?g(v,d,m):console.error(`Could not find a connection type called '${d.type}'`)}},p=(d,m,v)=>{if(s!==void 0&&d.priority<s)return;const w=h().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${d.defaultWidth}px`).style("height",`${d.defaultHeight}px`).call(J().on(P.Drag,C=>{if(t.canUserPerformAction(I.AddNode)){const y=t.getPointerLocationRelativeToScreen(C);if(y.length<2||isNaN(y[0])||isNaN(y[1]))return;w.style("position","fixed").style("left",`${y[0]-d.defaultWidth/2}px`).style("top",`${y[1]-d.defaultHeight/2}px`).style("z-index",1)}}).on(P.Start,C=>{if(t.canUserPerformAction(I.AddNode)){$(L.Grabbing);const y=t.getPointerLocationRelativeToScreen(C);if(y.length<2||isNaN(y[0])||isNaN(y[1]))return;w.style("position","fixed").style("left",`${y[0]-d.defaultWidth/2}px`).style("top",`${y[1]-d.defaultHeight/2}px`).style("z-index",1),d.isUnique&&t.model.nodes.find(k=>!k.removed&&k.type.id===d.id)!==void 0&&$(L.NotAllowed)}}).on(P.End,C=>{var y;if(t.canUserPerformAction(I.AddNode)){if($(L.Auto),w.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),d.isUnique&&t.model.nodes.find(E=>!E.removed&&E.type.id===d.id)!==void 0)return;const k=t.getPointerLocationRelativeToScreen(C);if(k.length<2||isNaN(k[0])||isNaN(k[1]))return;const M=document.elementFromPoint(k[0],k[1]);if(M&&!((y=t.selectCanvasView().node())!=null&&y.contains(M)))return;const N=t.getPointerLocationRelativeToCanvas(C);if(N.length<2||isNaN(N[0])||isNaN(N[1]))return;let R=[N[0]-d.defaultWidth/2,N[1]-d.defaultHeight/2];t.snapToGrid&&(R=t.getClosestGridPoint(R));const H=t.model.nodes.getAtCoordinates(N[0],N[1]).filter(E=>E.type.childrenTypes.includes(d.id)),W=hr(H),tt=W[W.length-1];if(!d.canBeParentless&&tt===void 0)return;const rt=tt==null?void 0:tt.getLastAncestor(),b=new wh(t,d,R,tt==null?void 0:tt.id,rt==null?void 0:rt.id,rt==null?void 0:rt.getGeometry(),void 0,m.label,m.values);b.do(),t==null||t.actionStack.add(b),$()}})).append("svg").attr("class",`palette-node ${d.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%");switch(d.look.lookType){case"shaped-look":w.append("path").attr("d",Qe(d.look.shape,0,0,d.defaultWidth,d.defaultHeight)).attr("fill",d.look.fillColor).attr("stroke",d.look.borderColor).attr("stroke-width","1px");break;case"image-look":w.append("image").attr("x",0).attr("y",0).attr("width",d.defaultWidth).attr("height",d.defaultHeight).attr("href",d.look.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":w.append("image").attr("x",0).attr("y",0).attr("width",d.look.leftMargin).attr("height",d.look.topMargin).attr("href",d.look.backgroundImageTopLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",d.look.leftMargin).attr("y",0).attr("width",d.defaultWidth-d.look.rightMargin-d.look.leftMargin).attr("height",d.look.topMargin).attr("href",d.look.backgroundImageTop).attr("preserveAspectRatio","none"),w.append("image").attr("x",d.defaultWidth-d.look.rightMargin).attr("y",0).attr("width",d.look.rightMargin).attr("height",d.look.topMargin).attr("href",d.look.backgroundImageTopRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",d.look.topMargin).attr("width",d.look.leftMargin).attr("height",d.defaultHeight-d.look.bottomMargin-d.look.topMargin).attr("href",d.look.backgroundImageLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",d.look.leftMargin).attr("y",d.look.topMargin).attr("width",d.defaultWidth-d.look.rightMargin-d.look.leftMargin).attr("height",d.defaultHeight-d.look.bottomMargin-d.look.topMargin).attr("href",d.look.backgroundImageCenter).attr("preserveAspectRatio","none"),w.append("image").attr("x",d.defaultWidth-d.look.rightMargin).attr("y",d.look.topMargin).attr("width",d.look.rightMargin).attr("height",d.defaultHeight-d.look.bottomMargin-d.look.topMargin).attr("href",d.look.backgroundImageRight).attr("preserveAspectRatio","none"),w.append("image").attr("x",0).attr("y",d.defaultHeight-d.look.bottomMargin).attr("width",d.look.leftMargin).attr("height",d.look.bottomMargin).attr("href",d.look.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),w.append("image").attr("x",d.look.leftMargin).attr("y",d.defaultHeight-d.look.bottomMargin).attr("width",d.defaultWidth-d.look.rightMargin-d.look.leftMargin).attr("height",d.look.bottomMargin).attr("href",d.look.backgroundImageBottom).attr("preserveAspectRatio","none"),w.append("image").attr("x",d.defaultWidth-d.look.rightMargin).attr("y",d.defaultHeight-d.look.bottomMargin).attr("width",d.look.rightMargin).attr("height",d.look.bottomMargin).attr("href",d.look.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(m.label){const C={...U,...d.label,...m.labelLook};w.append("text").attr("transform",`translate(${(it(C)+d.defaultWidth)/2},${(ot(C)+d.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${C.fontSize}px`).attr("text-anchor","middle").attr("font-family",C.fontFamily).attr("font-weight",400).attr("fill",C.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(m.label)}},g=(d,m,v)=>{const w=h().append("div").attr("class",`daga-template-container ${v!==void 0?v:""}`).style("width",`${m.width}px`).style("height",`${m.height}px`).append("svg").attr("class",`palette-button ${d.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=d});w.append("path").attr("d",Qe(rn.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+5})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(m.label)};return B.useEffect(()=>{if(o(e||n.palettes[0]),c(e),l.current)switch(n.direction){case x.Bottom:case x.Top:l.current.style.width=n.width;break;case x.Left:case x.Right:l.current.style.height=n.width;break}},[e,n.palettes]),A.jsx("daga-palette",{children:A.jsxs("div",{ref:l,className:`daga-panel daga-${n.location} daga-${n.direction}`,children:[A.jsx(oi,{direction:n.direction,collapsableSelector:l,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),A.jsxs("div",{className:"daga-panel-content",children:[n.palettes.length>1&&A.jsx("div",{className:"daga-panel-tabs",children:n.palettes.map(d=>A.jsx("div",{className:`daga-panel-tab ${d===e?"daga-current-tab":""}`,onClick:()=>c(d),children:d.name}))}),A.jsx("div",{className:"daga-palette-view"})]})]})})},Qh=({location:n,direction:t,enableAction:e,enableFilter:o,enableLayout:s,enableSelection:a,enableZoom:i})=>{let r=!1,l=!0,c=!1,h,f,u,p;switch(t){case x.Bottom:h="height",f="scaleY",u="top",p="bottom";break;case x.Top:h="height",f="scaleY",u="bottom",p="top";break;case x.Left:h="width",f="scaleX",u="right",p="left";break;case x.Right:h="width",f="scaleX",u="left",p="right";break}const g=B.useRef(null),d=B.useRef(null),m=B.useRef(null);B.useEffect(()=>{O(g.current).style(`margin-${p}`,"-1rem").style(h,"0rem").style("transform",`${f}(0)`).style("transform-origin",u)});const v=async()=>{const E=O(g.current);if(!c)if(l){l=!1;const z=`${4*E.selectChildren().size()}rem`;E.transition().duration(500).ease(Ln).style(h,z).style("transform",`${f}(1)`),setTimeout(()=>{c=!1},500)}else l=!0,E.transition().duration(500).ease(Ln).style(h,"0rem").style("transform",`${f}(0)`),setTimeout(()=>{c=!1},500)},w=B.useContext(Ht),C=()=>{w.zoomBy(w.zoomFactor)},y=()=>{w.zoomBy(1/w.zoomFactor)},k=()=>{w.center()},M=()=>{w.layoutFormat&&w.layoutFormat in oo&&oo[w.layoutFormat].apply(w.model)},N=()=>{r=!r,O(m.current).classed("daga-on",r).classed("daga-off",!r);const E=w.getPriorityThresholdOptions();E&&E.length>=2&&w.setPriorityThreshold(E[r?1:0])},R=()=>{w.actionStack.undo()},F=()=>{w.actionStack.redo()},H=()=>{w.userSelection.copyToClipboard()},W=()=>{w.userSelection.cutToClipboard()},tt=()=>{w.userSelection.pasteFromClipboard()},rt=()=>{w.userSelection.removeFromModel()},b=()=>{w.multipleSelectionOn=!0,O(d.current).classed("daga-on",!0).classed("daga-off",!1)};return A.jsx("daga-diagram-buttons",{children:A.jsxs("div",{className:`daga-diagram-buttons daga-${n} daga-${t}`,children:[i&&w.canUserPerformAction(I.Zoom)&&A.jsx("button",{className:"daga-zoom-in",onClick:C,children:A.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&w.canUserPerformAction(I.Zoom)&&A.jsx("button",{className:"daga-zoom-out",onClick:y,children:A.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),A.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:g,children:[i&&w.canUserPerformAction(I.Zoom)&&A.jsx("button",{className:"daga-center",onClick:k,children:A.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&A.jsx("button",{className:"daga-undo",onClick:R,children:A.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&A.jsx("button",{className:"daga-redo",onClick:F,children:A.jsx("span",{className:"daga-tooltip",children:"Redo"})}),a&&A.jsx("button",{className:"daga-copy",onClick:H,children:A.jsx("span",{className:"daga-tooltip",children:"Copy"})}),a&&A.jsx("button",{className:"daga-cut",onClick:W,children:A.jsx("span",{className:"daga-tooltip",children:"Cut"})}),a&&A.jsx("button",{className:`daga-multiple-selection ${r?"daga-on":"daga-off"}`,onClick:b,ref:d,children:A.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),a&&A.jsx("button",{className:"daga-paste",onClick:tt,children:A.jsx("span",{className:"daga-tooltip",children:"Paste"})}),a&&A.jsx("button",{className:"daga-delete",onClick:rt,children:A.jsx("span",{className:"daga-tooltip",children:"Delete"})}),s&&w.layoutFormat&&A.jsx("button",{className:"daga-layout",onClick:M,children:A.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),o&&A.jsx("button",{className:`daga-filter ${r?"daga-on":"daga-off"}`,onClick:N,ref:m,children:A.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),A.jsx("button",{className:"daga-more-options",onClick:v,children:l?A.jsx("span",{className:"daga-tooltip",children:"More options"}):A.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Jh=({config:n,model:t,onCanvasCreated:e,onDiagramEvent:o,onModelChange:s})=>{var y,k,M,N,R,F,H,W,tt,rt,b,E,S,_,z,V,D,G,X,dt,q,lt,gt,ct,mt,Wt,ri,si,ai,li,ci,hi,di,ui,fi,pi,gi,mi,vi,yi,bi,wi,xi,Ci,ki;const a=new dr,i=new fr,r=B.useRef(null),l=B.useRef(!1),[c,h]=B.useState(void 0),[f,u]=B.useState(void 0),p={zoomIn:()=>{console.log("zoomIn")},zoomOut:()=>{console.log("zoomOut")},center:()=>{console.log("center")},layout:()=>{console.log("layout")},filter:()=>{console.log("filter")},undo:()=>{console.log("undo")},redo:()=>{console.log("redo")}},g={refreshPalette:()=>{console.log("refreshPalette")}},d=new Yh(yt=>h(yt),yt=>u(yt)),m={diagramButtons:p,palette:g,propertyEditor:d},v=new Un(m,n);B.useEffect(()=>{t&&a.import(v.model,t)},[t]),v.diagramChange$.subscribe(()=>{const yt=i.export(v.model);s==null||s(yt)});const w=yt=>{v.initView(yt),v.diagramEvent$.subscribe(Ie=>{o==null||o(Ie)})};B.useEffect(()=>{r.current&&(l.current||(w(r.current),l.current=!0,e==null||e(v)))},[r.current]);const C=(yt,Ie)=>{var Si,Ai;if(f!==void 0&&yt.editable&&!be(f.getValue(yt.name),Ie)){const dn=new le(f.propertySet,f.rootElement);dn.setValues(f.values),dn.setValue(yt.name,Ie),d.valueSet=dn,(Si=v.diagramChange$)==null||Si.next(),(Ai=v.propertyEditorChanges$)==null||Ai.next()}};return A.jsx("daga-diagram",{children:A.jsx(Xh.Provider,{value:n,children:A.jsx(Ht.Provider,{value:v,children:A.jsxs("daga-diagram-editor",{children:[A.jsx("div",{className:"daga-append-to",ref:r}),A.jsxs(Ht.Provider,{value:v,children:[((y=n.components)==null?void 0:y.buttons)!==void 0&&((M=(k=n.components)==null?void 0:k.buttons)==null?void 0:M.enabled)!==!1&&A.jsx(Qh,{location:((R=(N=n.components)==null?void 0:N.buttons)==null?void 0:R.location)||Re.BottomRight,direction:((H=(F=n.components)==null?void 0:F.buttons)==null?void 0:H.direction)||x.Top,enableAction:((tt=(W=n.components)==null?void 0:W.buttons)==null?void 0:tt.enableAction)===!0,enableFilter:((b=(rt=n.components)==null?void 0:rt.buttons)==null?void 0:b.enableFilter)===!0,enableLayout:((S=(E=n.components)==null?void 0:E.buttons)==null?void 0:S.enableLayout)===!0,enableSelection:((z=(_=n.components)==null?void 0:_.buttons)==null?void 0:z.enableSelection)===!0,enableZoom:((D=(V=n.components)==null?void 0:V.buttons)==null?void 0:D.enableZoom)!==!1}),((G=n.components)==null?void 0:G.palette)!==void 0&&((dt=(X=n.components)==null?void 0:X.palette)==null?void 0:dt.enabled)!==!1&&((lt=(q=n.components)==null?void 0:q.palette)==null?void 0:lt.sections)&&(((mt=(ct=(gt=n.components)==null?void 0:gt.palette)==null?void 0:ct.sections)==null?void 0:mt.length)||0)>0&&A.jsx(Zh,{location:((ri=(Wt=n.components)==null?void 0:Wt.palette)==null?void 0:ri.location)||Re.TopLeft,direction:((ai=(si=n.components)==null?void 0:si.palette)==null?void 0:ai.direction)||x.Bottom,width:((ci=(li=n.components)==null?void 0:li.palette)==null?void 0:ci.width)||"12rem",palettes:((di=(hi=n.components)==null?void 0:hi.palette)==null?void 0:di.sections)||[]}),((ui=n.components)==null?void 0:ui.propertyEditor)!==void 0&&((pi=(fi=n.components)==null?void 0:fi.propertyEditor)==null?void 0:pi.enabled)!==!1&&A.jsx(Kh,{location:((mi=(gi=n.components)==null?void 0:gi.propertyEditor)==null?void 0:mi.location)||Re.TopRight,direction:((yi=(vi=n.components)==null?void 0:vi.propertyEditor)==null?void 0:yi.direction)||x.Bottom,width:((wi=(bi=n.components)==null?void 0:bi.propertyEditor)==null?void 0:wi.width)||"24rem",title:c,valueSet:f,onValueChange:C}),((xi=n.components)==null?void 0:xi.errors)!==void 0&&((ki=(Ci=n.components)==null?void 0:Ci.errors)==null?void 0:ki.enabled)!==!1&&A.jsx(Wh,{})]})]})})})})};exports.DagaDiagram=Jh;
|