ima2-gen 3.26.1 → 3.26.2

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/docs/migration/runtime-test-inventory.md +8 -1
  3. package/lib/oauthImages.js +45 -30
  4. package/lib/oauthJobDeadline.js +70 -0
  5. package/lib/oauthProxy/runtime.js +15 -5
  6. package/lib/oauthRateLimit.js +6 -7
  7. package/lib/providers/adapters/openaiExecution.js +41 -15
  8. package/lib/responsesTransport.js +117 -109
  9. package/package.json +6 -6
  10. package/ui/dist/.vite/manifest.json +69 -69
  11. package/ui/dist/assets/{AgentWorkspace-DGEWNErN.js → AgentWorkspace-B49xr58Q.js} +1 -1
  12. package/ui/dist/assets/App-Bq_IUqRU.js +9 -0
  13. package/ui/dist/assets/{AssetGenWorkspace-woj0orEW.js → AssetGenWorkspace-BkF-1HG-.js} +2 -2
  14. package/ui/dist/assets/{AssetMediaLightbox-39eeVLgg.js → AssetMediaLightbox-CxfO1QUc.js} +1 -1
  15. package/ui/dist/assets/{AssetsWorkspace-feT-v8BY.js → AssetsWorkspace-BkWynV74.js} +1 -1
  16. package/ui/dist/assets/{CardNewsWorkspace-Bce7Qq0s.js → CardNewsWorkspace-BKSfq0oA.js} +1 -1
  17. package/ui/dist/assets/{GenerationRequestLogPanel-D6jO_fXj.js → GenerationRequestLogPanel-Bvlv8UCB.js} +1 -1
  18. package/ui/dist/assets/{HomeWorkspace-C7SABT2o.js → HomeWorkspace-Ck7uEYz4.js} +1 -1
  19. package/ui/dist/assets/{KeyingPanel-DWaV9fRG.js → KeyingPanel-B5yKvszy.js} +1 -1
  20. package/ui/dist/assets/{NodeCanvas-ybOBBYto.js → NodeCanvas-Bf9bEiX2.js} +3 -3
  21. package/ui/dist/assets/{PromptBuilderPanel-C1DLHD9Q.js → PromptBuilderPanel-Bz2e5lKO.js} +1 -1
  22. package/ui/dist/assets/{PromptImportDialog-OGyYU5K5.js → PromptImportDialog-ctIs_XxZ.js} +2 -2
  23. package/ui/dist/assets/{PromptImportDiscoverySection-Cwigr40k.js → PromptImportDiscoverySection-CDppFhg4.js} +1 -1
  24. package/ui/dist/assets/{PromptImportFolderSection-B1XqjRbl.js → PromptImportFolderSection-Cvd73I4D.js} +1 -1
  25. package/ui/dist/assets/{PromptLibraryPanel-v7hIoYy-.js → PromptLibraryPanel-DtP62WHm.js} +2 -2
  26. package/ui/dist/assets/{SettingsWorkspace-CGZXJLgN.js → SettingsWorkspace-5IEsIqqb.js} +1 -1
  27. package/ui/dist/assets/{SpriteRecipeWorkspace-Cm5wizr5.js → SpriteRecipeWorkspace-DQsk4cc5.js} +1 -1
  28. package/ui/dist/assets/{index-CUMOJ4Vx.js → index-CRUYCtE2.js} +3 -3
  29. package/ui/dist/assets/index-CizoKwOj.css +1 -0
  30. package/ui/dist/assets/index-WbTkAEzk.js +23 -0
  31. package/ui/dist/assets/{pptxgen.es-XHiluGIr.js → pptxgen.es-B6CA1Typ.js} +1 -1
  32. package/ui/dist/assets/{promptBuilderStore-BKNNtgtk.js → promptBuilderStore-CJBR66MD.js} +1 -1
  33. package/ui/dist/assets/useAgentDialogFocus-CyM46tgI.js +1 -0
  34. package/ui/dist/index.html +2 -2
  35. package/ui/dist/assets/App-b7KJO01r.js +0 -9
  36. package/ui/dist/assets/index-CJ-sBrSx.js +0 -23
  37. package/ui/dist/assets/index-Dznqt1dP.css +0 -1
  38. package/ui/dist/assets/useAgentDialogFocus-CZabQdET.js +0 -1
@@ -1,7 +1,7 @@
1
- import{m as Kr,n as Qa,R as Ja,f as N,j as h}from"./index-CJ-sBrSx.js";import{u as ae,a as K,r as ec,i as Vt,S as tc,f as nc,g as oc,b as rc,n as ic,c as sc,w as ac,d as cc,e as Qr,h as lc,l as uc,j as dc,k as fc,m as hc,o as Qe,p as pc,q as gc}from"./App-b7KJO01r.js";import{c as mc}from"./clipboard-DirTPLEi.js";import{A as yc}from"./AssetMediaLightbox-39eeVLgg.js";import"./useAgentDialogFocus-CZabQdET.js";function se(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,o;n<e.length;n++)(o=se(e[n]))!==""&&(t+=(t&&" ")+o);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var xc={value:()=>{}};function an(){for(var e=0,t=arguments.length,n={},o;e<t;++e){if(!(o=arguments[e]+"")||o in n||/[\s.]/.test(o))throw new Error("illegal type: "+o);n[o]=[]}return new Ft(n)}function Ft(e){this._=e}function wc(e,t){return e.trim().split(/^|\s+/).map(function(n){var o="",r=n.indexOf(".");if(r>=0&&(o=n.slice(r+1),n=n.slice(0,r)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:o}})}Ft.prototype=an.prototype={constructor:Ft,on:function(e,t){var n=this._,o=wc(e+"",n),r,i=-1,s=o.length;if(arguments.length<2){for(;++i<s;)if((r=(e=o[i]).type)&&(r=vc(n[r],e.name)))return r;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++i<s;)if(r=(e=o[i]).type)n[r]=Po(n[r],e.name,t);else if(t==null)for(r in n)n[r]=Po(n[r],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Ft(e)},call:function(e,t){if((r=arguments.length-2)>0)for(var n=new Array(r),o=0,r,i;o<r;++o)n[o]=arguments[o+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(i=this._[e],o=0,r=i.length;o<r;++o)i[o].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var o=this._[e],r=0,i=o.length;r<i;++r)o[r].value.apply(t,n)}};function vc(e,t){for(var n=0,o=e.length,r;n<o;++n)if((r=e[n]).name===t)return r.value}function Po(e,t,n){for(var o=0,r=e.length;o<r;++o)if(e[o].name===t){e[o]=xc,e=e.slice(0,o).concat(e.slice(o+1));break}return n!=null&&e.push({name:t,value:n}),e}var On="http://www.w3.org/1999/xhtml";const Do={svg:"http://www.w3.org/2000/svg",xhtml:On,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function cn(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Do.hasOwnProperty(t)?{space:Do[t],local:e}:e}function bc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===On&&t.documentElement.namespaceURI===On?t.createElement(e):t.createElementNS(n,e)}}function _c(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Jr(e){var t=cn(e);return(t.local?_c:bc)(t)}function Sc(){}function oo(e){return e==null?Sc:function(){return this.querySelector(e)}}function Ec(e){typeof e!="function"&&(e=oo(e));for(var t=this._groups,n=t.length,o=new Array(n),r=0;r<n;++r)for(var i=t[r],s=i.length,a=o[r]=new Array(s),c,l,u=0;u<s;++u)(c=i[u])&&(l=e.call(c,c.__data__,u,i))&&("__data__"in c&&(l.__data__=c.__data__),a[u]=l);return new de(o,this._parents)}function Nc(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Cc(){return[]}function ei(e){return e==null?Cc:function(){return this.querySelectorAll(e)}}function Ic(e){return function(){return Nc(e.apply(this,arguments))}}function kc(e){typeof e=="function"?e=Ic(e):e=ei(e);for(var t=this._groups,n=t.length,o=[],r=[],i=0;i<n;++i)for(var s=t[i],a=s.length,c,l=0;l<a;++l)(c=s[l])&&(o.push(e.call(c,c.__data__,l,s)),r.push(c));return new de(o,r)}function ti(e){return function(){return this.matches(e)}}function ni(e){return function(t){return t.matches(e)}}var Mc=Array.prototype.find;function Tc(e){return function(){return Mc.call(this.children,e)}}function Ac(){return this.firstElementChild}function Pc(e){return this.select(e==null?Ac:Tc(typeof e=="function"?e:ni(e)))}var Dc=Array.prototype.filter;function jc(){return Array.from(this.children)}function $c(e){return function(){return Dc.call(this.children,e)}}function Rc(e){return this.selectAll(e==null?jc:$c(typeof e=="function"?e:ni(e)))}function Hc(e){typeof e!="function"&&(e=ti(e));for(var t=this._groups,n=t.length,o=new Array(n),r=0;r<n;++r)for(var i=t[r],s=i.length,a=o[r]=[],c,l=0;l<s;++l)(c=i[l])&&e.call(c,c.__data__,l,i)&&a.push(c);return new de(o,this._parents)}function oi(e){return new Array(e.length)}function Lc(){return new de(this._enter||this._groups.map(oi),this._parents)}function Ut(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Ut.prototype={constructor:Ut,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Oc(e){return function(){return e}}function zc(e,t,n,o,r,i){for(var s=0,a,c=t.length,l=i.length;s<l;++s)(a=t[s])?(a.__data__=i[s],o[s]=a):n[s]=new Ut(e,i[s]);for(;s<c;++s)(a=t[s])&&(r[s]=a)}function Bc(e,t,n,o,r,i,s){var a,c,l=new Map,u=t.length,f=i.length,d=new Array(u),p;for(a=0;a<u;++a)(c=t[a])&&(d[a]=p=s.call(c,c.__data__,a,t)+"",l.has(p)?r[a]=c:l.set(p,c));for(a=0;a<f;++a)p=s.call(e,i[a],a,i)+"",(c=l.get(p))?(o[a]=c,c.__data__=i[a],l.delete(p)):n[a]=new Ut(e,i[a]);for(a=0;a<u;++a)(c=t[a])&&l.get(d[a])===c&&(r[a]=c)}function Vc(e){return e.__data__}function Fc(e,t){if(!arguments.length)return Array.from(this,Vc);var n=t?Bc:zc,o=this._parents,r=this._groups;typeof e!="function"&&(e=Oc(e));for(var i=r.length,s=new Array(i),a=new Array(i),c=new Array(i),l=0;l<i;++l){var u=o[l],f=r[l],d=f.length,p=Yc(e.call(u,u&&u.__data__,l,o)),g=p.length,v=a[l]=new Array(g),w=s[l]=new Array(g),x=c[l]=new Array(d);n(u,f,v,w,x,p,t);for(var S=0,m=0,y,I;S<g;++S)if(y=v[S]){for(S>=m&&(m=S+1);!(I=w[m])&&++m<g;);y._next=I||null}}return s=new de(s,o),s._enter=a,s._exit=c,s}function Yc(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Xc(){return new de(this._exit||this._groups.map(oi),this._parents)}function Wc(e,t,n){var o=this.enter(),r=this,i=this.exit();return typeof e=="function"?(o=e(o),o&&(o=o.selection())):o=o.append(e+""),t!=null&&(r=t(r),r&&(r=r.selection())),n==null?i.remove():n(i),o&&r?o.merge(r).order():r}function Zc(e){for(var t=e.selection?e.selection():e,n=this._groups,o=t._groups,r=n.length,i=o.length,s=Math.min(r,i),a=new Array(r),c=0;c<s;++c)for(var l=n[c],u=o[c],f=l.length,d=a[c]=new Array(f),p,g=0;g<f;++g)(p=l[g]||u[g])&&(d[g]=p);for(;c<r;++c)a[c]=n[c];return new de(a,this._parents)}function Gc(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var o=e[t],r=o.length-1,i=o[r],s;--r>=0;)(s=o[r])&&(i&&s.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(s,i),i=s);return this}function Uc(e){e||(e=qc);function t(f,d){return f&&d?e(f.__data__,d.__data__):!f-!d}for(var n=this._groups,o=n.length,r=new Array(o),i=0;i<o;++i){for(var s=n[i],a=s.length,c=r[i]=new Array(a),l,u=0;u<a;++u)(l=s[u])&&(c[u]=l);c.sort(t)}return new de(r,this._parents).order()}function qc(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Kc(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Qc(){return Array.from(this)}function Jc(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var o=e[t],r=0,i=o.length;r<i;++r){var s=o[r];if(s)return s}return null}function el(){let e=0;for(const t of this)++e;return e}function tl(){return!this.node()}function nl(e){for(var t=this._groups,n=0,o=t.length;n<o;++n)for(var r=t[n],i=0,s=r.length,a;i<s;++i)(a=r[i])&&e.call(a,a.__data__,i,r);return this}function ol(e){return function(){this.removeAttribute(e)}}function rl(e){return function(){this.removeAttributeNS(e.space,e.local)}}function il(e,t){return function(){this.setAttribute(e,t)}}function sl(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function al(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function cl(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function ll(e,t){var n=cn(e);if(arguments.length<2){var o=this.node();return n.local?o.getAttributeNS(n.space,n.local):o.getAttribute(n)}return this.each((t==null?n.local?rl:ol:typeof t=="function"?n.local?cl:al:n.local?sl:il)(n,t))}function ri(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function ul(e){return function(){this.style.removeProperty(e)}}function dl(e,t,n){return function(){this.style.setProperty(e,t,n)}}function fl(e,t,n){return function(){var o=t.apply(this,arguments);o==null?this.style.removeProperty(e):this.style.setProperty(e,o,n)}}function hl(e,t,n){return arguments.length>1?this.each((t==null?ul:typeof t=="function"?fl:dl)(e,t,n??"")):it(this.node(),e)}function it(e,t){return e.style.getPropertyValue(t)||ri(e).getComputedStyle(e,null).getPropertyValue(t)}function pl(e){return function(){delete this[e]}}function gl(e,t){return function(){this[e]=t}}function ml(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function yl(e,t){return arguments.length>1?this.each((t==null?pl:typeof t=="function"?ml:gl)(e,t)):this.node()[e]}function ii(e){return e.trim().split(/^|\s+/)}function ro(e){return e.classList||new si(e)}function si(e){this._node=e,this._names=ii(e.getAttribute("class")||"")}si.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function ai(e,t){for(var n=ro(e),o=-1,r=t.length;++o<r;)n.add(t[o])}function ci(e,t){for(var n=ro(e),o=-1,r=t.length;++o<r;)n.remove(t[o])}function xl(e){return function(){ai(this,e)}}function wl(e){return function(){ci(this,e)}}function vl(e,t){return function(){(t.apply(this,arguments)?ai:ci)(this,e)}}function bl(e,t){var n=ii(e+"");if(arguments.length<2){for(var o=ro(this.node()),r=-1,i=n.length;++r<i;)if(!o.contains(n[r]))return!1;return!0}return this.each((typeof t=="function"?vl:t?xl:wl)(n,t))}function _l(){this.textContent=""}function Sl(e){return function(){this.textContent=e}}function El(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function Nl(e){return arguments.length?this.each(e==null?_l:(typeof e=="function"?El:Sl)(e)):this.node().textContent}function Cl(){this.innerHTML=""}function Il(e){return function(){this.innerHTML=e}}function kl(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function Ml(e){return arguments.length?this.each(e==null?Cl:(typeof e=="function"?kl:Il)(e)):this.node().innerHTML}function Tl(){this.nextSibling&&this.parentNode.appendChild(this)}function Al(){return this.each(Tl)}function Pl(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Dl(){return this.each(Pl)}function jl(e){var t=typeof e=="function"?e:Jr(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function $l(){return null}function Rl(e,t){var n=typeof e=="function"?e:Jr(e),o=t==null?$l:typeof t=="function"?t:oo(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),o.apply(this,arguments)||null)})}function Hl(){var e=this.parentNode;e&&e.removeChild(this)}function Ll(){return this.each(Hl)}function Ol(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function zl(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Bl(e){return this.select(e?zl:Ol)}function Vl(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Fl(e){return function(t){e.call(this,t,this.__data__)}}function Yl(e){return e.trim().split(/^|\s+/).map(function(t){var n="",o=t.indexOf(".");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{type:t,name:n}})}function Xl(e){return function(){var t=this.__on;if(t){for(var n=0,o=-1,r=t.length,i;n<r;++n)i=t[n],(!e.type||i.type===e.type)&&i.name===e.name?this.removeEventListener(i.type,i.listener,i.options):t[++o]=i;++o?t.length=o:delete this.__on}}}function Wl(e,t,n){return function(){var o=this.__on,r,i=Fl(t);if(o){for(var s=0,a=o.length;s<a;++s)if((r=o[s]).type===e.type&&r.name===e.name){this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=i,r.options=n),r.value=t;return}}this.addEventListener(e.type,i,n),r={type:e.type,name:e.name,value:t,listener:i,options:n},o?o.push(r):this.__on=[r]}}function Zl(e,t,n){var o=Yl(e+""),r,i=o.length,s;if(arguments.length<2){var a=this.node().__on;if(a){for(var c=0,l=a.length,u;c<l;++c)for(r=0,u=a[c];r<i;++r)if((s=o[r]).type===u.type&&s.name===u.name)return u.value}return}for(a=t?Wl:Xl,r=0;r<i;++r)this.each(a(o[r],t,n));return this}function li(e,t,n){var o=ri(e),r=o.CustomEvent;typeof r=="function"?r=new r(t,n):(r=o.document.createEvent("Event"),n?(r.initEvent(t,n.bubbles,n.cancelable),r.detail=n.detail):r.initEvent(t,!1,!1)),e.dispatchEvent(r)}function Gl(e,t){return function(){return li(this,e,t)}}function Ul(e,t){return function(){return li(this,e,t.apply(this,arguments))}}function ql(e,t){return this.each((typeof t=="function"?Ul:Gl)(e,t))}function*Kl(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var o=e[t],r=0,i=o.length,s;r<i;++r)(s=o[r])&&(yield s)}var ui=[null];function de(e,t){this._groups=e,this._parents=t}function It(){return new de([[document.documentElement]],ui)}function Ql(){return this}de.prototype=It.prototype={constructor:de,select:Ec,selectAll:kc,selectChild:Pc,selectChildren:Rc,filter:Hc,data:Fc,enter:Lc,exit:Xc,join:Wc,merge:Zc,selection:Ql,order:Gc,sort:Uc,call:Kc,nodes:Qc,node:Jc,size:el,empty:tl,each:nl,attr:ll,style:hl,property:yl,classed:bl,text:Nl,html:Ml,raise:Al,lower:Dl,append:jl,insert:Rl,remove:Ll,clone:Bl,datum:Vl,on:Zl,dispatch:ql,[Symbol.iterator]:Kl};function ue(e){return typeof e=="string"?new de([[document.querySelector(e)]],[document.documentElement]):new de([[e]],ui)}function Jl(e){let t;for(;t=e.sourceEvent;)e=t;return e}function he(e,t){if(e=Jl(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var o=n.createSVGPoint();return o.x=e.clientX,o.y=e.clientY,o=o.matrixTransform(t.getScreenCTM().inverse()),[o.x,o.y]}if(t.getBoundingClientRect){var r=t.getBoundingClientRect();return[e.clientX-r.left-t.clientLeft,e.clientY-r.top-t.clientTop]}}return[e.pageX,e.pageY]}const eu={passive:!1},xt={capture:!0,passive:!1};function Sn(e){e.stopImmediatePropagation()}function nt(e){e.preventDefault(),e.stopImmediatePropagation()}function di(e){var t=e.document.documentElement,n=ue(e).on("dragstart.drag",nt,xt);"onselectstart"in t?n.on("selectstart.drag",nt,xt):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function fi(e,t){var n=e.document.documentElement,o=ue(e).on("dragstart.drag",null);t&&(o.on("click.drag",nt,xt),setTimeout(function(){o.on("click.drag",null)},0)),"onselectstart"in n?o.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Dt=e=>()=>e;function zn(e,{sourceEvent:t,subject:n,target:o,identifier:r,active:i,x:s,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:o,enumerable:!0,configurable:!0},identifier:{value:r,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}zn.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function tu(e){return!e.ctrlKey&&!e.button}function nu(){return this.parentNode}function ou(e,t){return t??{x:e.x,y:e.y}}function ru(){return navigator.maxTouchPoints||"ontouchstart"in this}function hi(){var e=tu,t=nu,n=ou,o=ru,r={},i=an("start","drag","end"),s=0,a,c,l,u,f=0;function d(y){y.on("mousedown.drag",p).filter(o).on("touchstart.drag",w).on("touchmove.drag",x,eu).on("touchend.drag touchcancel.drag",S).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(y,I){if(!(u||!e.call(this,y,I))){var b=m(this,t.call(this,y,I),y,I,"mouse");b&&(ue(y.view).on("mousemove.drag",g,xt).on("mouseup.drag",v,xt),di(y.view),Sn(y),l=!1,a=y.clientX,c=y.clientY,b("start",y))}}function g(y){if(nt(y),!l){var I=y.clientX-a,b=y.clientY-c;l=I*I+b*b>f}r.mouse("drag",y)}function v(y){ue(y.view).on("mousemove.drag mouseup.drag",null),fi(y.view,l),nt(y),r.mouse("end",y)}function w(y,I){if(e.call(this,y,I)){var b=y.changedTouches,C=t.call(this,y,I),E=b.length,A,B;for(A=0;A<E;++A)(B=m(this,C,y,I,b[A].identifier,b[A]))&&(Sn(y),B("start",y,b[A]))}}function x(y){var I=y.changedTouches,b=I.length,C,E;for(C=0;C<b;++C)(E=r[I[C].identifier])&&(nt(y),E("drag",y,I[C]))}function S(y){var I=y.changedTouches,b=I.length,C,E;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),C=0;C<b;++C)(E=r[I[C].identifier])&&(Sn(y),E("end",y,I[C]))}function m(y,I,b,C,E,A){var B=i.copy(),T=he(A||b,I),L,H,_;if((_=n.call(y,new zn("beforestart",{sourceEvent:b,target:d,identifier:E,active:s,x:T[0],y:T[1],dx:0,dy:0,dispatch:B}),C))!=null)return L=_.x-T[0]||0,H=_.y-T[1]||0,function k(M,P,j){var $=T,O;switch(M){case"start":r[E]=k,O=s++;break;case"end":delete r[E],--s;case"drag":T=he(j||P,I),O=s;break}B.call(M,y,new zn(M,{sourceEvent:P,subject:_,target:d,identifier:E,active:O,x:T[0]+L,y:T[1]+H,dx:T[0]-$[0],dy:T[1]-$[1],dispatch:B}),C)}}return d.filter=function(y){return arguments.length?(e=typeof y=="function"?y:Dt(!!y),d):e},d.container=function(y){return arguments.length?(t=typeof y=="function"?y:Dt(y),d):t},d.subject=function(y){return arguments.length?(n=typeof y=="function"?y:Dt(y),d):n},d.touchable=function(y){return arguments.length?(o=typeof y=="function"?y:Dt(!!y),d):o},d.on=function(){var y=i.on.apply(i,arguments);return y===i?d:y},d.clickDistance=function(y){return arguments.length?(f=(y=+y)*y,d):Math.sqrt(f)},d}function io(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function pi(e,t){var n=Object.create(e.prototype);for(var o in t)n[o]=t[o];return n}function kt(){}var wt=.7,qt=1/wt,ot="\\s*([+-]?\\d+)\\s*",vt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Se="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",iu=/^#([0-9a-f]{3,8})$/,su=new RegExp(`^rgb\\(${ot},${ot},${ot}\\)$`),au=new RegExp(`^rgb\\(${Se},${Se},${Se}\\)$`),cu=new RegExp(`^rgba\\(${ot},${ot},${ot},${vt}\\)$`),lu=new RegExp(`^rgba\\(${Se},${Se},${Se},${vt}\\)$`),uu=new RegExp(`^hsl\\(${vt},${Se},${Se}\\)$`),du=new RegExp(`^hsla\\(${vt},${Se},${Se},${vt}\\)$`),jo={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};io(kt,Xe,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:$o,formatHex:$o,formatHex8:fu,formatHsl:hu,formatRgb:Ro,toString:Ro});function $o(){return this.rgb().formatHex()}function fu(){return this.rgb().formatHex8()}function hu(){return gi(this).formatHsl()}function Ro(){return this.rgb().formatRgb()}function Xe(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=iu.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Ho(t):n===3?new le(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?jt(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?jt(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=su.exec(e))?new le(t[1],t[2],t[3],1):(t=au.exec(e))?new le(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=cu.exec(e))?jt(t[1],t[2],t[3],t[4]):(t=lu.exec(e))?jt(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=uu.exec(e))?zo(t[1],t[2]/100,t[3]/100,1):(t=du.exec(e))?zo(t[1],t[2]/100,t[3]/100,t[4]):jo.hasOwnProperty(e)?Ho(jo[e]):e==="transparent"?new le(NaN,NaN,NaN,0):null}function Ho(e){return new le(e>>16&255,e>>8&255,e&255,1)}function jt(e,t,n,o){return o<=0&&(e=t=n=NaN),new le(e,t,n,o)}function pu(e){return e instanceof kt||(e=Xe(e)),e?(e=e.rgb(),new le(e.r,e.g,e.b,e.opacity)):new le}function Bn(e,t,n,o){return arguments.length===1?pu(e):new le(e,t,n,o??1)}function le(e,t,n,o){this.r=+e,this.g=+t,this.b=+n,this.opacity=+o}io(le,Bn,pi(kt,{brighter(e){return e=e==null?qt:Math.pow(qt,e),new le(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?wt:Math.pow(wt,e),new le(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new le(Fe(this.r),Fe(this.g),Fe(this.b),Kt(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:Lo,formatHex:Lo,formatHex8:gu,formatRgb:Oo,toString:Oo}));function Lo(){return`#${Ve(this.r)}${Ve(this.g)}${Ve(this.b)}`}function gu(){return`#${Ve(this.r)}${Ve(this.g)}${Ve(this.b)}${Ve((isNaN(this.opacity)?1:this.opacity)*255)}`}function Oo(){const e=Kt(this.opacity);return`${e===1?"rgb(":"rgba("}${Fe(this.r)}, ${Fe(this.g)}, ${Fe(this.b)}${e===1?")":`, ${e})`}`}function Kt(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Fe(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Ve(e){return e=Fe(e),(e<16?"0":"")+e.toString(16)}function zo(e,t,n,o){return o<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new pe(e,t,n,o)}function gi(e){if(e instanceof pe)return new pe(e.h,e.s,e.l,e.opacity);if(e instanceof kt||(e=Xe(e)),!e)return new pe;if(e instanceof pe)return e;e=e.rgb();var t=e.r/255,n=e.g/255,o=e.b/255,r=Math.min(t,n,o),i=Math.max(t,n,o),s=NaN,a=i-r,c=(i+r)/2;return a?(t===i?s=(n-o)/a+(n<o)*6:n===i?s=(o-t)/a+2:s=(t-n)/a+4,a/=c<.5?i+r:2-i-r,s*=60):a=c>0&&c<1?0:s,new pe(s,a,c,e.opacity)}function mu(e,t,n,o){return arguments.length===1?gi(e):new pe(e,t,n,o??1)}function pe(e,t,n,o){this.h=+e,this.s=+t,this.l=+n,this.opacity=+o}io(pe,mu,pi(kt,{brighter(e){return e=e==null?qt:Math.pow(qt,e),new pe(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?wt:Math.pow(wt,e),new pe(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,o=n+(n<.5?n:1-n)*t,r=2*n-o;return new le(En(e>=240?e-240:e+120,r,o),En(e,r,o),En(e<120?e+240:e-120,r,o),this.opacity)},clamp(){return new pe(Bo(this.h),$t(this.s),$t(this.l),Kt(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 e=Kt(this.opacity);return`${e===1?"hsl(":"hsla("}${Bo(this.h)}, ${$t(this.s)*100}%, ${$t(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Bo(e){return e=(e||0)%360,e<0?e+360:e}function $t(e){return Math.max(0,Math.min(1,e||0))}function En(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const so=e=>()=>e;function yu(e,t){return function(n){return e+n*t}}function xu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(o){return Math.pow(e+o*t,n)}}function wu(e){return(e=+e)==1?mi:function(t,n){return n-t?xu(t,n,e):so(isNaN(t)?n:t)}}function mi(e,t){var n=t-e;return n?yu(e,n):so(isNaN(e)?t:e)}const Qt=(function e(t){var n=wu(t);function o(r,i){var s=n((r=Bn(r)).r,(i=Bn(i)).r),a=n(r.g,i.g),c=n(r.b,i.b),l=mi(r.opacity,i.opacity);return function(u){return r.r=s(u),r.g=a(u),r.b=c(u),r.opacity=l(u),r+""}}return o.gamma=e,o})(1);function vu(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,o=t.slice(),r;return function(i){for(r=0;r<n;++r)o[r]=e[r]*(1-i)+t[r]*i;return o}}function bu(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function _u(e,t){var n=t?t.length:0,o=e?Math.min(n,e.length):0,r=new Array(o),i=new Array(n),s;for(s=0;s<o;++s)r[s]=mt(e[s],t[s]);for(;s<n;++s)i[s]=t[s];return function(a){for(s=0;s<o;++s)i[s]=r[s](a);return i}}function Su(e,t){var n=new Date;return e=+e,t=+t,function(o){return n.setTime(e*(1-o)+t*o),n}}function _e(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Eu(e,t){var n={},o={},r;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(r in t)r in e?n[r]=mt(e[r],t[r]):o[r]=t[r];return function(i){for(r in n)o[r]=n[r](i);return o}}var Vn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Nn=new RegExp(Vn.source,"g");function Nu(e){return function(){return e}}function Cu(e){return function(t){return e(t)+""}}function yi(e,t){var n=Vn.lastIndex=Nn.lastIndex=0,o,r,i,s=-1,a=[],c=[];for(e=e+"",t=t+"";(o=Vn.exec(e))&&(r=Nn.exec(t));)(i=r.index)>n&&(i=t.slice(n,i),a[s]?a[s]+=i:a[++s]=i),(o=o[0])===(r=r[0])?a[s]?a[s]+=r:a[++s]=r:(a[++s]=null,c.push({i:s,x:_e(o,r)})),n=Nn.lastIndex;return n<t.length&&(i=t.slice(n),a[s]?a[s]+=i:a[++s]=i),a.length<2?c[0]?Cu(c[0].x):Nu(t):(t=c.length,function(l){for(var u=0,f;u<t;++u)a[(f=c[u]).i]=f.x(l);return a.join("")})}function mt(e,t){var n=typeof t,o;return t==null||n==="boolean"?so(t):(n==="number"?_e:n==="string"?(o=Xe(t))?(t=o,Qt):yi:t instanceof Xe?Qt:t instanceof Date?Su:bu(t)?vu:Array.isArray(t)?_u:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?Eu:_e)(e,t)}var Vo=180/Math.PI,Fn={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function xi(e,t,n,o,r,i){var s,a,c;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(c=e*n+t*o)&&(n-=e*c,o-=t*c),(a=Math.sqrt(n*n+o*o))&&(n/=a,o/=a,c/=a),e*o<t*n&&(e=-e,t=-t,c=-c,s=-s),{translateX:r,translateY:i,rotate:Math.atan2(t,e)*Vo,skewX:Math.atan(c)*Vo,scaleX:s,scaleY:a}}var Rt;function Iu(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Fn:xi(t.a,t.b,t.c,t.d,t.e,t.f)}function ku(e){return e==null||(Rt||(Rt=document.createElementNS("http://www.w3.org/2000/svg","g")),Rt.setAttribute("transform",e),!(e=Rt.transform.baseVal.consolidate()))?Fn:(e=e.matrix,xi(e.a,e.b,e.c,e.d,e.e,e.f))}function wi(e,t,n,o){function r(l){return l.length?l.pop()+" ":""}function i(l,u,f,d,p,g){if(l!==f||u!==d){var v=p.push("translate(",null,t,null,n);g.push({i:v-4,x:_e(l,f)},{i:v-2,x:_e(u,d)})}else(f||d)&&p.push("translate("+f+t+d+n)}function s(l,u,f,d){l!==u?(l-u>180?u+=360:u-l>180&&(l+=360),d.push({i:f.push(r(f)+"rotate(",null,o)-2,x:_e(l,u)})):u&&f.push(r(f)+"rotate("+u+o)}function a(l,u,f,d){l!==u?d.push({i:f.push(r(f)+"skewX(",null,o)-2,x:_e(l,u)}):u&&f.push(r(f)+"skewX("+u+o)}function c(l,u,f,d,p,g){if(l!==f||u!==d){var v=p.push(r(p)+"scale(",null,",",null,")");g.push({i:v-4,x:_e(l,f)},{i:v-2,x:_e(u,d)})}else(f!==1||d!==1)&&p.push(r(p)+"scale("+f+","+d+")")}return function(l,u){var f=[],d=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,f,d),s(l.rotate,u.rotate,f,d),a(l.skewX,u.skewX,f,d),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,f,d),l=u=null,function(p){for(var g=-1,v=d.length,w;++g<v;)f[(w=d[g]).i]=w.x(p);return f.join("")}}}var Mu=wi(Iu,"px, ","px)","deg)"),Tu=wi(ku,", ",")",")"),Au=1e-12;function Fo(e){return((e=Math.exp(e))+1/e)/2}function Pu(e){return((e=Math.exp(e))-1/e)/2}function Du(e){return((e=Math.exp(2*e))-1)/(e+1)}const Yt=(function e(t,n,o){function r(i,s){var a=i[0],c=i[1],l=i[2],u=s[0],f=s[1],d=s[2],p=u-a,g=f-c,v=p*p+g*g,w,x;if(v<Au)x=Math.log(d/l)/t,w=function(C){return[a+C*p,c+C*g,l*Math.exp(t*C*x)]};else{var S=Math.sqrt(v),m=(d*d-l*l+o*v)/(2*l*n*S),y=(d*d-l*l-o*v)/(2*d*n*S),I=Math.log(Math.sqrt(m*m+1)-m),b=Math.log(Math.sqrt(y*y+1)-y);x=(b-I)/t,w=function(C){var E=C*x,A=Fo(I),B=l/(n*S)*(A*Du(t*E+I)-Pu(I));return[a+B*p,c+B*g,l*A/Fo(t*E+I)]}}return w.duration=x*1e3*t/Math.SQRT2,w}return r.rho=function(i){var s=Math.max(.001,+i),a=s*s,c=a*a;return e(s,a,c)},r})(Math.SQRT2,2,4);var st=0,pt=0,dt=0,vi=1e3,Jt,gt,en=0,We=0,ln=0,bt=typeof performance=="object"&&performance.now?performance:Date,bi=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function ao(){return We||(bi(ju),We=bt.now()+ln)}function ju(){We=0}function tn(){this._call=this._time=this._next=null}tn.prototype=_i.prototype={constructor:tn,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?ao():+n)+(t==null?0:+t),!this._next&&gt!==this&&(gt?gt._next=this:Jt=this,gt=this),this._call=e,this._time=n,Yn()},stop:function(){this._call&&(this._call=null,this._time=1/0,Yn())}};function _i(e,t,n){var o=new tn;return o.restart(e,t,n),o}function $u(){ao(),++st;for(var e=Jt,t;e;)(t=We-e._time)>=0&&e._call.call(void 0,t),e=e._next;--st}function Yo(){We=(en=bt.now())+ln,st=pt=0;try{$u()}finally{st=0,Hu(),We=0}}function Ru(){var e=bt.now(),t=e-en;t>vi&&(ln-=t,en=e)}function Hu(){for(var e,t=Jt,n,o=1/0;t;)t._call?(o>t._time&&(o=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Jt=n);gt=e,Yn(o)}function Yn(e){if(!st){pt&&(pt=clearTimeout(pt));var t=e-We;t>24?(e<1/0&&(pt=setTimeout(Yo,e-bt.now()-ln)),dt&&(dt=clearInterval(dt))):(dt||(en=bt.now(),dt=setInterval(Ru,vi)),st=1,bi(Yo))}}function Xo(e,t,n){var o=new tn;return t=t==null?0:+t,o.restart(r=>{o.stop(),e(r+t)},t,n),o}var Lu=an("start","end","cancel","interrupt"),Ou=[],Si=0,Wo=1,Xn=2,Xt=3,Zo=4,Wn=5,Wt=6;function un(e,t,n,o,r,i){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;zu(e,n,{name:t,index:o,group:r,on:Lu,tween:Ou,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Si})}function co(e,t){var n=xe(e,t);if(n.state>Si)throw new Error("too late; already scheduled");return n}function Ee(e,t){var n=xe(e,t);if(n.state>Xt)throw new Error("too late; already running");return n}function xe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function zu(e,t,n){var o=e.__transition,r;o[t]=n,n.timer=_i(i,0,n.time);function i(l){n.state=Wo,n.timer.restart(s,n.delay,n.time),n.delay<=l&&s(l-n.delay)}function s(l){var u,f,d,p;if(n.state!==Wo)return c();for(u in o)if(p=o[u],p.name===n.name){if(p.state===Xt)return Xo(s);p.state===Zo?(p.state=Wt,p.timer.stop(),p.on.call("interrupt",e,e.__data__,p.index,p.group),delete o[u]):+u<t&&(p.state=Wt,p.timer.stop(),p.on.call("cancel",e,e.__data__,p.index,p.group),delete o[u])}if(Xo(function(){n.state===Xt&&(n.state=Zo,n.timer.restart(a,n.delay,n.time),a(l))}),n.state=Xn,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Xn){for(n.state=Xt,r=new Array(d=n.tween.length),u=0,f=-1;u<d;++u)(p=n.tween[u].value.call(e,e.__data__,n.index,n.group))&&(r[++f]=p);r.length=f+1}}function a(l){for(var u=l<n.duration?n.ease.call(null,l/n.duration):(n.timer.restart(c),n.state=Wn,1),f=-1,d=r.length;++f<d;)r[f].call(e,u);n.state===Wn&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=Wt,n.timer.stop(),delete o[t];for(var l in o)return;delete e.__transition}}function Zt(e,t){var n=e.__transition,o,r,i=!0,s;if(n){t=t==null?null:t+"";for(s in n){if((o=n[s]).name!==t){i=!1;continue}r=o.state>Xn&&o.state<Wn,o.state=Wt,o.timer.stop(),o.on.call(r?"interrupt":"cancel",e,e.__data__,o.index,o.group),delete n[s]}i&&delete e.__transition}}function Bu(e){return this.each(function(){Zt(this,e)})}function Vu(e,t){var n,o;return function(){var r=Ee(this,e),i=r.tween;if(i!==n){o=n=i;for(var s=0,a=o.length;s<a;++s)if(o[s].name===t){o=o.slice(),o.splice(s,1);break}}r.tween=o}}function Fu(e,t,n){var o,r;if(typeof n!="function")throw new Error;return function(){var i=Ee(this,e),s=i.tween;if(s!==o){r=(o=s).slice();for(var a={name:t,value:n},c=0,l=r.length;c<l;++c)if(r[c].name===t){r[c]=a;break}c===l&&r.push(a)}i.tween=r}}function Yu(e,t){var n=this._id;if(e+="",arguments.length<2){for(var o=xe(this.node(),n).tween,r=0,i=o.length,s;r<i;++r)if((s=o[r]).name===e)return s.value;return null}return this.each((t==null?Vu:Fu)(n,e,t))}function lo(e,t,n){var o=e._id;return e.each(function(){var r=Ee(this,o);(r.value||(r.value={}))[t]=n.apply(this,arguments)}),function(r){return xe(r,o).value[t]}}function Ei(e,t){var n;return(typeof t=="number"?_e:t instanceof Xe?Qt:(n=Xe(t))?(t=n,Qt):yi)(e,t)}function Xu(e){return function(){this.removeAttribute(e)}}function Wu(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Zu(e,t,n){var o,r=n+"",i;return function(){var s=this.getAttribute(e);return s===r?null:s===o?i:i=t(o=s,n)}}function Gu(e,t,n){var o,r=n+"",i;return function(){var s=this.getAttributeNS(e.space,e.local);return s===r?null:s===o?i:i=t(o=s,n)}}function Uu(e,t,n){var o,r,i;return function(){var s,a=n(this),c;return a==null?void this.removeAttribute(e):(s=this.getAttribute(e),c=a+"",s===c?null:s===o&&c===r?i:(r=c,i=t(o=s,a)))}}function qu(e,t,n){var o,r,i;return function(){var s,a=n(this),c;return a==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),c=a+"",s===c?null:s===o&&c===r?i:(r=c,i=t(o=s,a)))}}function Ku(e,t){var n=cn(e),o=n==="transform"?Tu:Ei;return this.attrTween(e,typeof t=="function"?(n.local?qu:Uu)(n,o,lo(this,"attr."+e,t)):t==null?(n.local?Wu:Xu)(n):(n.local?Gu:Zu)(n,o,t))}function Qu(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Ju(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function ed(e,t){var n,o;function r(){var i=t.apply(this,arguments);return i!==o&&(n=(o=i)&&Ju(e,i)),n}return r._value=t,r}function td(e,t){var n,o;function r(){var i=t.apply(this,arguments);return i!==o&&(n=(o=i)&&Qu(e,i)),n}return r._value=t,r}function nd(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var o=cn(e);return this.tween(n,(o.local?ed:td)(o,t))}function od(e,t){return function(){co(this,e).delay=+t.apply(this,arguments)}}function rd(e,t){return t=+t,function(){co(this,e).delay=t}}function id(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?od:rd)(t,e)):xe(this.node(),t).delay}function sd(e,t){return function(){Ee(this,e).duration=+t.apply(this,arguments)}}function ad(e,t){return t=+t,function(){Ee(this,e).duration=t}}function cd(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?sd:ad)(t,e)):xe(this.node(),t).duration}function ld(e,t){if(typeof t!="function")throw new Error;return function(){Ee(this,e).ease=t}}function ud(e){var t=this._id;return arguments.length?this.each(ld(t,e)):xe(this.node(),t).ease}function dd(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ee(this,e).ease=n}}function fd(e){if(typeof e!="function")throw new Error;return this.each(dd(this._id,e))}function hd(e){typeof e!="function"&&(e=ti(e));for(var t=this._groups,n=t.length,o=new Array(n),r=0;r<n;++r)for(var i=t[r],s=i.length,a=o[r]=[],c,l=0;l<s;++l)(c=i[l])&&e.call(c,c.__data__,l,i)&&a.push(c);return new Pe(o,this._parents,this._name,this._id)}function pd(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,o=t.length,r=n.length,i=Math.min(o,r),s=new Array(o),a=0;a<i;++a)for(var c=t[a],l=n[a],u=c.length,f=s[a]=new Array(u),d,p=0;p<u;++p)(d=c[p]||l[p])&&(f[p]=d);for(;a<o;++a)s[a]=t[a];return new Pe(s,this._parents,this._name,this._id)}function gd(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function md(e,t,n){var o,r,i=gd(t)?co:Ee;return function(){var s=i(this,e),a=s.on;a!==o&&(r=(o=a).copy()).on(t,n),s.on=r}}function yd(e,t){var n=this._id;return arguments.length<2?xe(this.node(),n).on.on(e):this.each(md(n,e,t))}function xd(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function wd(){return this.on("end.remove",xd(this._id))}function vd(e){var t=this._name,n=this._id;typeof e!="function"&&(e=oo(e));for(var o=this._groups,r=o.length,i=new Array(r),s=0;s<r;++s)for(var a=o[s],c=a.length,l=i[s]=new Array(c),u,f,d=0;d<c;++d)(u=a[d])&&(f=e.call(u,u.__data__,d,a))&&("__data__"in u&&(f.__data__=u.__data__),l[d]=f,un(l[d],t,n,d,l,xe(u,n)));return new Pe(i,this._parents,t,n)}function bd(e){var t=this._name,n=this._id;typeof e!="function"&&(e=ei(e));for(var o=this._groups,r=o.length,i=[],s=[],a=0;a<r;++a)for(var c=o[a],l=c.length,u,f=0;f<l;++f)if(u=c[f]){for(var d=e.call(u,u.__data__,f,c),p,g=xe(u,n),v=0,w=d.length;v<w;++v)(p=d[v])&&un(p,t,n,v,d,g);i.push(d),s.push(u)}return new Pe(i,s,t,n)}var _d=It.prototype.constructor;function Sd(){return new _d(this._groups,this._parents)}function Ed(e,t){var n,o,r;return function(){var i=it(this,e),s=(this.style.removeProperty(e),it(this,e));return i===s?null:i===n&&s===o?r:r=t(n=i,o=s)}}function Ni(e){return function(){this.style.removeProperty(e)}}function Nd(e,t,n){var o,r=n+"",i;return function(){var s=it(this,e);return s===r?null:s===o?i:i=t(o=s,n)}}function Cd(e,t,n){var o,r,i;return function(){var s=it(this,e),a=n(this),c=a+"";return a==null&&(c=a=(this.style.removeProperty(e),it(this,e))),s===c?null:s===o&&c===r?i:(r=c,i=t(o=s,a))}}function Id(e,t){var n,o,r,i="style."+t,s="end."+i,a;return function(){var c=Ee(this,e),l=c.on,u=c.value[i]==null?a||(a=Ni(t)):void 0;(l!==n||r!==u)&&(o=(n=l).copy()).on(s,r=u),c.on=o}}function kd(e,t,n){var o=(e+="")=="transform"?Mu:Ei;return t==null?this.styleTween(e,Ed(e,o)).on("end.style."+e,Ni(e)):typeof t=="function"?this.styleTween(e,Cd(e,o,lo(this,"style."+e,t))).each(Id(this._id,e)):this.styleTween(e,Nd(e,o,t),n).on("end.style."+e,null)}function Md(e,t,n){return function(o){this.style.setProperty(e,t.call(this,o),n)}}function Td(e,t,n){var o,r;function i(){var s=t.apply(this,arguments);return s!==r&&(o=(r=s)&&Md(e,s,n)),o}return i._value=t,i}function Ad(e,t,n){var o="style."+(e+="");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,Td(e,t,n??""))}function Pd(e){return function(){this.textContent=e}}function Dd(e){return function(){var t=e(this);this.textContent=t??""}}function jd(e){return this.tween("text",typeof e=="function"?Dd(lo(this,"text",e)):Pd(e==null?"":e+""))}function $d(e){return function(t){this.textContent=e.call(this,t)}}function Rd(e){var t,n;function o(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&$d(r)),t}return o._value=e,o}function Hd(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,Rd(e))}function Ld(){for(var e=this._name,t=this._id,n=Ci(),o=this._groups,r=o.length,i=0;i<r;++i)for(var s=o[i],a=s.length,c,l=0;l<a;++l)if(c=s[l]){var u=xe(c,t);un(c,e,n,l,s,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Pe(o,this._parents,e,n)}function Od(){var e,t,n=this,o=n._id,r=n.size();return new Promise(function(i,s){var a={value:s},c={value:function(){--r===0&&i()}};n.each(function(){var l=Ee(this,o),u=l.on;u!==e&&(t=(e=u).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(c)),l.on=t}),r===0&&i()})}var zd=0;function Pe(e,t,n,o){this._groups=e,this._parents=t,this._name=n,this._id=o}function Ci(){return++zd}var Me=It.prototype;Pe.prototype={constructor:Pe,select:vd,selectAll:bd,selectChild:Me.selectChild,selectChildren:Me.selectChildren,filter:hd,merge:pd,selection:Sd,transition:Ld,call:Me.call,nodes:Me.nodes,node:Me.node,size:Me.size,empty:Me.empty,each:Me.each,on:yd,attr:Ku,attrTween:nd,style:kd,styleTween:Ad,text:jd,textTween:Hd,remove:wd,tween:Yu,delay:id,duration:cd,ease:ud,easeVarying:fd,end:Od,[Symbol.iterator]:Me[Symbol.iterator]};function Bd(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Vd={time:null,delay:0,duration:250,ease:Bd};function Fd(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function Yd(e){var t,n;e instanceof Pe?(t=e._id,e=e._name):(t=Ci(),(n=Vd).time=ao(),e=e==null?null:e+"");for(var o=this._groups,r=o.length,i=0;i<r;++i)for(var s=o[i],a=s.length,c,l=0;l<a;++l)(c=s[l])&&un(c,e,t,l,s,n||Fd(c,t));return new Pe(o,this._parents,e,t)}It.prototype.interrupt=Bu;It.prototype.transition=Yd;const Ht=e=>()=>e;function Xd(e,{sourceEvent:t,target:n,transform:o,dispatch:r}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:o,enumerable:!0,configurable:!0},_:{value:r}})}function Te(e,t,n){this.k=e,this.x=t,this.y=n}Te.prototype={constructor:Te,scale:function(e){return e===1?this:new Te(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Te(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var dn=new Te(1,0,0);Ii.prototype=Te.prototype;function Ii(e){for(;!e.__zoom;)if(!(e=e.parentNode))return dn;return e.__zoom}function Cn(e){e.stopImmediatePropagation()}function ft(e){e.preventDefault(),e.stopImmediatePropagation()}function Wd(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Zd(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Go(){return this.__zoom||dn}function Gd(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Ud(){return navigator.maxTouchPoints||"ontouchstart"in this}function qd(e,t,n){var o=e.invertX(t[0][0])-n[0][0],r=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],s=e.invertY(t[1][1])-n[1][1];return e.translate(r>o?(o+r)/2:Math.min(0,o)||Math.max(0,r),s>i?(i+s)/2:Math.min(0,i)||Math.max(0,s))}function ki(){var e=Wd,t=Zd,n=qd,o=Gd,r=Ud,i=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Yt,l=an("start","zoom","end"),u,f,d,p=500,g=150,v=0,w=10;function x(_){_.property("__zoom",Go).on("wheel.zoom",E,{passive:!1}).on("mousedown.zoom",A).on("dblclick.zoom",B).filter(r).on("touchstart.zoom",T).on("touchmove.zoom",L).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}x.transform=function(_,k,M,P){var j=_.selection?_.selection():_;j.property("__zoom",Go),_!==j?I(_,k,M,P):j.interrupt().each(function(){b(this,arguments).event(P).start().zoom(null,typeof k=="function"?k.apply(this,arguments):k).end()})},x.scaleBy=function(_,k,M,P){x.scaleTo(_,function(){var j=this.__zoom.k,$=typeof k=="function"?k.apply(this,arguments):k;return j*$},M,P)},x.scaleTo=function(_,k,M,P){x.transform(_,function(){var j=t.apply(this,arguments),$=this.__zoom,O=M==null?y(j):typeof M=="function"?M.apply(this,arguments):M,V=$.invert(O),z=typeof k=="function"?k.apply(this,arguments):k;return n(m(S($,z),O,V),j,s)},M,P)},x.translateBy=function(_,k,M,P){x.transform(_,function(){return n(this.__zoom.translate(typeof k=="function"?k.apply(this,arguments):k,typeof M=="function"?M.apply(this,arguments):M),t.apply(this,arguments),s)},null,P)},x.translateTo=function(_,k,M,P,j){x.transform(_,function(){var $=t.apply(this,arguments),O=this.__zoom,V=P==null?y($):typeof P=="function"?P.apply(this,arguments):P;return n(dn.translate(V[0],V[1]).scale(O.k).translate(typeof k=="function"?-k.apply(this,arguments):-k,typeof M=="function"?-M.apply(this,arguments):-M),$,s)},P,j)};function S(_,k){return k=Math.max(i[0],Math.min(i[1],k)),k===_.k?_:new Te(k,_.x,_.y)}function m(_,k,M){var P=k[0]-M[0]*_.k,j=k[1]-M[1]*_.k;return P===_.x&&j===_.y?_:new Te(_.k,P,j)}function y(_){return[(+_[0][0]+ +_[1][0])/2,(+_[0][1]+ +_[1][1])/2]}function I(_,k,M,P){_.on("start.zoom",function(){b(this,arguments).event(P).start()}).on("interrupt.zoom end.zoom",function(){b(this,arguments).event(P).end()}).tween("zoom",function(){var j=this,$=arguments,O=b(j,$).event(P),V=t.apply(j,$),z=M==null?y(V):typeof M=="function"?M.apply(j,$):M,W=Math.max(V[1][0]-V[0][0],V[1][1]-V[0][1]),Y=j.__zoom,Z=typeof k=="function"?k.apply(j,$):k,J=c(Y.invert(z).concat(W/Y.k),Z.invert(z).concat(W/Z.k));return function(R){if(R===1)R=Z;else{var D=J(R),F=W/D[2];R=new Te(F,z[0]-D[0]*F,z[1]-D[1]*F)}O.zoom(null,R)}})}function b(_,k,M){return!M&&_.__zooming||new C(_,k)}function C(_,k){this.that=_,this.args=k,this.active=0,this.sourceEvent=null,this.extent=t.apply(_,k),this.taps=0}C.prototype={event:function(_){return _&&(this.sourceEvent=_),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(_,k){return this.mouse&&_!=="mouse"&&(this.mouse[1]=k.invert(this.mouse[0])),this.touch0&&_!=="touch"&&(this.touch0[1]=k.invert(this.touch0[0])),this.touch1&&_!=="touch"&&(this.touch1[1]=k.invert(this.touch1[0])),this.that.__zoom=k,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(_){var k=ue(this.that).datum();l.call(_,this.that,new Xd(_,{sourceEvent:this.sourceEvent,target:x,transform:this.that.__zoom,dispatch:l}),k)}};function E(_,...k){if(!e.apply(this,arguments))return;var M=b(this,k).event(_),P=this.__zoom,j=Math.max(i[0],Math.min(i[1],P.k*Math.pow(2,o.apply(this,arguments)))),$=he(_);if(M.wheel)(M.mouse[0][0]!==$[0]||M.mouse[0][1]!==$[1])&&(M.mouse[1]=P.invert(M.mouse[0]=$)),clearTimeout(M.wheel);else{if(P.k===j)return;M.mouse=[$,P.invert($)],Zt(this),M.start()}ft(_),M.wheel=setTimeout(O,g),M.zoom("mouse",n(m(S(P,j),M.mouse[0],M.mouse[1]),M.extent,s));function O(){M.wheel=null,M.end()}}function A(_,...k){if(d||!e.apply(this,arguments))return;var M=_.currentTarget,P=b(this,k,!0).event(_),j=ue(_.view).on("mousemove.zoom",z,!0).on("mouseup.zoom",W,!0),$=he(_,M),O=_.clientX,V=_.clientY;di(_.view),Cn(_),P.mouse=[$,this.__zoom.invert($)],Zt(this),P.start();function z(Y){if(ft(Y),!P.moved){var Z=Y.clientX-O,J=Y.clientY-V;P.moved=Z*Z+J*J>v}P.event(Y).zoom("mouse",n(m(P.that.__zoom,P.mouse[0]=he(Y,M),P.mouse[1]),P.extent,s))}function W(Y){j.on("mousemove.zoom mouseup.zoom",null),fi(Y.view,P.moved),ft(Y),P.event(Y).end()}}function B(_,...k){if(e.apply(this,arguments)){var M=this.__zoom,P=he(_.changedTouches?_.changedTouches[0]:_,this),j=M.invert(P),$=M.k*(_.shiftKey?.5:2),O=n(m(S(M,$),P,j),t.apply(this,k),s);ft(_),a>0?ue(this).transition().duration(a).call(I,O,P,_):ue(this).call(x.transform,O,P,_)}}function T(_,...k){if(e.apply(this,arguments)){var M=_.touches,P=M.length,j=b(this,k,_.changedTouches.length===P).event(_),$,O,V,z;for(Cn(_),O=0;O<P;++O)V=M[O],z=he(V,this),z=[z,this.__zoom.invert(z),V.identifier],j.touch0?!j.touch1&&j.touch0[2]!==z[2]&&(j.touch1=z,j.taps=0):(j.touch0=z,$=!0,j.taps=1+!!u);u&&(u=clearTimeout(u)),$&&(j.taps<2&&(f=z[0],u=setTimeout(function(){u=null},p)),Zt(this),j.start())}}function L(_,...k){if(this.__zooming){var M=b(this,k).event(_),P=_.changedTouches,j=P.length,$,O,V,z;for(ft(_),$=0;$<j;++$)O=P[$],V=he(O,this),M.touch0&&M.touch0[2]===O.identifier?M.touch0[0]=V:M.touch1&&M.touch1[2]===O.identifier&&(M.touch1[0]=V);if(O=M.that.__zoom,M.touch1){var W=M.touch0[0],Y=M.touch0[1],Z=M.touch1[0],J=M.touch1[1],R=(R=Z[0]-W[0])*R+(R=Z[1]-W[1])*R,D=(D=J[0]-Y[0])*D+(D=J[1]-Y[1])*D;O=S(O,Math.sqrt(R/D)),V=[(W[0]+Z[0])/2,(W[1]+Z[1])/2],z=[(Y[0]+J[0])/2,(Y[1]+J[1])/2]}else if(M.touch0)V=M.touch0[0],z=M.touch0[1];else return;M.zoom("touch",n(m(O,V,z),M.extent,s))}}function H(_,...k){if(this.__zooming){var M=b(this,k).event(_),P=_.changedTouches,j=P.length,$,O;for(Cn(_),d&&clearTimeout(d),d=setTimeout(function(){d=null},p),$=0;$<j;++$)O=P[$],M.touch0&&M.touch0[2]===O.identifier?delete M.touch0:M.touch1&&M.touch1[2]===O.identifier&&delete M.touch1;if(M.touch1&&!M.touch0&&(M.touch0=M.touch1,delete M.touch1),M.touch0)M.touch0[1]=this.__zoom.invert(M.touch0[0]);else if(M.end(),M.taps===2&&(O=he(O,this),Math.hypot(f[0]-O[0],f[1]-O[1])<w)){var V=ue(this).on("dblclick.zoom");V&&V.apply(this,arguments)}}}return x.wheelDelta=function(_){return arguments.length?(o=typeof _=="function"?_:Ht(+_),x):o},x.filter=function(_){return arguments.length?(e=typeof _=="function"?_:Ht(!!_),x):e},x.touchable=function(_){return arguments.length?(r=typeof _=="function"?_:Ht(!!_),x):r},x.extent=function(_){return arguments.length?(t=typeof _=="function"?_:Ht([[+_[0][0],+_[0][1]],[+_[1][0],+_[1][1]]]),x):t},x.scaleExtent=function(_){return arguments.length?(i[0]=+_[0],i[1]=+_[1],x):[i[0],i[1]]},x.translateExtent=function(_){return arguments.length?(s[0][0]=+_[0][0],s[1][0]=+_[1][0],s[0][1]=+_[0][1],s[1][1]=+_[1][1],x):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},x.constrain=function(_){return arguments.length?(n=_,x):n},x.duration=function(_){return arguments.length?(a=+_,x):a},x.interpolate=function(_){return arguments.length?(c=_,x):c},x.on=function(){var _=l.on.apply(l,arguments);return _===l?x:_},x.clickDistance=function(_){return arguments.length?(v=(_=+_)*_,x):Math.sqrt(v)},x.tapDistance=function(_){return arguments.length?(w=+_,x):w},x}const ye={error001:(e="react")=>`Seems like you have not used ${e==="svelte"?"SvelteFlowProvider":"ReactFlowProvider"} as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:o})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:o}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.",error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},_t=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Mi=["Enter"," ","Escape"],Ti={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Ze;(function(e){e.Strict="strict",e.Loose="loose"})(Ze||(Ze={}));var Ye;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Ye||(Ye={}));var St;(function(e){e.Partial="partial",e.Full="full"})(St||(St={}));const Ai={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Re;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Re||(Re={}));var nn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(nn||(nn={}));var X;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(X||(X={}));const Uo={[X.Left]:X.Right,[X.Right]:X.Left,[X.Top]:X.Bottom,[X.Bottom]:X.Top},Pi=e=>!!e&&typeof e=="object"&&"id"in e&&"source"in e&&"target"in e,Kd=e=>!!e&&typeof e=="object"&&"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),uo=e=>!!e&&typeof e=="object"&&"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Mt=(e,t=[0,0])=>{const{width:n,height:o}=we(e),r=e.origin??t,i=n*r[0],s=o*r[1];return{x:e.position.x-i,y:e.position.y-s}},Qd=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};let n=!1;const o=e.reduce((r,i)=>{const s=typeof i=="string";let a=!t.nodeLookup&&!s?i:void 0;return t.nodeLookup&&(a=s?t.nodeLookup.get(i):uo(i)?i:t.nodeLookup.get(i.id)),a?(n=!0,fn(r,on(a,t.nodeOrigin))):r},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return n?hn(o):{x:0,y:0,width:0,height:0}},Tt=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},o=!1;return e.forEach(r=>{(t.filter===void 0||t.filter(r))&&(n=fn(n,on(r)),o=!0)}),o?hn(n):{x:0,y:0,width:0,height:0}},fo=(e,t,[n,o,r]=[0,0,1],i=!1,s=!1)=>{const a=(t.x-n)/r,c=(t.y-o)/r,l=t.width/r,u=t.height/r,f=[];for(const d of e.values()){const{measured:p,selectable:g=!0,hidden:v=!1}=d;if(s&&!g||v)continue;const w=p.width??d.width??d.initialWidth??0,x=p.height??d.height??d.initialHeight??0,{x:S,y:m}=d.internals.positionAbsolute,y=Ri(a,c,l,u,S,m,w,x),I=w*x,b=i&&y>0;(!d.internals.handleBounds||b||y>=I||d.dragging)&&f.push(d)}return f},Jd=(e,t)=>{const n=new Set;return e.forEach(o=>{n.add(o.id)}),t.filter(o=>n.has(o.source)||n.has(o.target))};function ef(e,t){const n=new Map,o=t?.nodes?new Set(t.nodes.map(r=>r.id)):null;return e.forEach(r=>{let i;if(t?.includeHiddenNodes){const{width:s,height:a}=we(r);i=s>0&&a>0}else i=!!(r.measured.width&&r.measured.height&&!r.hidden);i&&(!o||o.has(r.id))&&n.set(r.id,r)}),n}async function tf({nodes:e,width:t,height:n,panZoom:o,minZoom:r,maxZoom:i},s){if(e.size===0)return!0;const a=ef(e,s),c=Tt(a),l=po(c,t,n,s?.minZoom??r,s?.maxZoom??i,s?.padding??.1);return await o.setViewport(l,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),!0}function Di({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:o=[0,0],nodeExtent:r,onError:i}){const s=n.get(e),a=s.parentId?n.get(s.parentId):void 0,{x:c,y:l}=a?a.internals.positionAbsolute:{x:0,y:0},u=s.origin??o;let f=s.extent||r;if(s.extent==="parent"&&!s.expandParent)if(!a)i?.("005",ye.error005());else{const{width:p,height:g}=we(a);p&&g&&(f=[[c,l],[c+p,l+g]])}else a&&Ue(s.extent)&&(f=[[s.extent[0][0]+c,s.extent[0][1]+l],[s.extent[1][0]+c,s.extent[1][1]+l]]);const d=Ue(f)?Ge(t,f,s.measured):t;return(s.measured.width===void 0||s.measured.height===void 0)&&i?.("015",ye.error015()),{position:{x:d.x-c+(s.measured.width??0)*u[0],y:d.y-l+(s.measured.height??0)*u[1]},positionAbsolute:d}}async function nf({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:o,onBeforeDelete:r}){const i=new Set(e.map(d=>d.id)),s=[];for(const d of n){if(d.deletable===!1)continue;const p=i.has(d.id),g=!p&&d.parentId&&s.find(v=>v.id===d.parentId);(p||g)&&s.push(d)}const a=new Set(t.map(d=>d.id)),c=o.filter(d=>d.deletable!==!1),u=Jd(s,c);for(const d of c)a.has(d.id)&&!u.find(g=>g.id===d.id)&&u.push(d);if(!r)return{edges:u,nodes:s};const f=await r({nodes:s,edges:u});return typeof f=="boolean"?f?{edges:u,nodes:s}:{edges:[],nodes:[]}:f}const at=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Ge=(e={x:0,y:0},t,n)=>({x:at(e.x,t[0][0],t[1][0]-(n?.width??0)),y:at(e.y,t[0][1],t[1][1]-(n?.height??0))});function ji(e,t,n){const{width:o,height:r}=we(n),{x:i,y:s}=n.internals.positionAbsolute;return Ge(e,[[i,s],[i+o,s+r]],t)}const qo=(e,t,n)=>e<t?at(Math.abs(e-t),1,t)/t:e>n?-at(Math.abs(e-n),1,t)/t:0,ho=(e,t,n=15,o=40)=>{const r=qo(e.x,o,t.width-o)*n,i=qo(e.y,o,t.height-o)*n;return[r,i]},fn=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Zn=({x:e,y:t,width:n,height:o})=>({x:e,y:t,x2:e+n,y2:t+o}),hn=({x:e,y:t,x2:n,y2:o})=>({x:e,y:t,width:n-e,height:o-t}),Et=(e,t=[0,0])=>{const{x:n,y:o}=uo(e)?e.internals.positionAbsolute:Mt(e,t);return{x:n,y:o,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},on=(e,t=[0,0])=>{const{x:n,y:o}=uo(e)?e.internals.positionAbsolute:Mt(e,t);return{x:n,y:o,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:o+(e.measured?.height??e.height??e.initialHeight??0)}},$i=(e,t)=>hn(fn(Zn(e),Zn(t))),Ri=(e,t,n,o,r,i,s,a)=>{const c=Math.max(0,Math.min(e+n,r+s)-Math.max(e,r)),l=Math.max(0,Math.min(t+o,i+a)-Math.max(t,i));return Math.ceil(c*l)},rn=(e,t)=>Ri(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),Ko=e=>ge(e.width)&&ge(e.height)&&ge(e.x)&&ge(e.y),ge=e=>!isNaN(e)&&isFinite(e),Hi=(e,t)=>(n,o)=>{},At=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Pt=({x:e,y:t},[n,o,r],i=!1,s=[1,1])=>{const a={x:(e-n)/r,y:(t-o)/r};return i?At(a,s):a},ct=({x:e,y:t},[n,o,r])=>({x:e*r+n,y:t*r+o});function Je(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function of(e,t,n){if(typeof e=="string"||typeof e=="number"){const o=Je(e,n),r=Je(e,t);return{top:o,right:r,bottom:o,left:r,x:r*2,y:o*2}}if(typeof e=="object"){const o=Je(e.top??e.y??0,n),r=Je(e.bottom??e.y??0,n),i=Je(e.left??e.x??0,t),s=Je(e.right??e.x??0,t);return{top:o,right:s,bottom:r,left:i,x:i+s,y:o+r}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function rf(e,t,n,o,r,i){const{x:s,y:a}=ct(e,[t,n,o]),{x:c,y:l}=ct({x:e.x+e.width,y:e.y+e.height},[t,n,o]),u=r-c,f=i-l;return{left:Math.floor(s),top:Math.floor(a),right:Math.floor(u),bottom:Math.floor(f)}}const po=(e,t,n,o,r,i)=>{const s=of(i,t,n),a=(t-s.x)/e.width,c=(n-s.y)/e.height,l=Math.min(a,c),u=at(l,o,r),f=e.x+e.width/2,d=e.y+e.height/2,p=t/2-f*u,g=n/2-d*u,v=rf(e,p,g,u,t,n),w={left:Math.min(v.left-s.left,0),top:Math.min(v.top-s.top,0),right:Math.min(v.right-s.right,0),bottom:Math.min(v.bottom-s.bottom,0)};return{x:p-w.left+w.right,y:g-w.top+w.bottom,zoom:u}},Nt=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Ue(e){return e!=null&&e!=="parent"}function we(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function Li(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function Oi(e,t={width:0,height:0},n,o,r){const i={...e},s=o.get(n);if(s){const a=s.origin||r;i.x+=s.internals.positionAbsolute.x-(t.width??0)*a[0],i.y+=s.internals.positionAbsolute.y-(t.height??0)*a[1]}return i}function Qo(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function sf(){let e,t;return{promise:new Promise((o,r)=>{e=o,t=r}),resolve:e,reject:t}}function af(e){return{...Ti,...e||{}}}function zi(e){return e===null?null:e?"valid":"invalid"}function yt(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:o,containerBounds:r}){const{x:i,y:s}=me(e),a=Pt({x:i-(r?.left??0),y:s-(r?.top??0)},o),{x:c,y:l}=n?At(a,t):a;return{xSnapped:c,ySnapped:l,...a}}const go=e=>({width:e.offsetWidth,height:e.offsetHeight}),Bi=e=>e?.getRootNode?.()||window?.document,cf=["INPUT","SELECT","TEXTAREA"];function Vi(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:cf.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const Fi=e=>"clientX"in e,me=(e,t)=>{const n=Fi(e),o=n?e.clientX:e.touches?.[0].clientX,r=n?e.clientY:e.touches?.[0].clientY;return{x:o-(t?.left??0),y:r-(t?.top??0)}},Jo=(e,t,n,o,r)=>{const i=t.querySelectorAll(`.${e}`);return!i||!i.length?null:Array.from(i).map(s=>{const a=s.getBoundingClientRect();return{id:s.getAttribute("data-handleid"),type:e,nodeId:r,position:s.getAttribute("data-handlepos"),x:(a.left-n.left)/o,y:(a.top-n.top)/o,...go(s)}})};function Yi({sourceX:e,sourceY:t,targetX:n,targetY:o,sourceControlX:r,sourceControlY:i,targetControlX:s,targetControlY:a}){const c=e*.125+r*.375+s*.375+n*.125,l=t*.125+i*.375+a*.375+o*.125,u=Math.abs(c-e),f=Math.abs(l-t);return[c,l,u,f]}function Lt(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function er({pos:e,x1:t,y1:n,x2:o,y2:r,c:i}){switch(e){case X.Left:return[t-Lt(t-o,i),n];case X.Right:return[t+Lt(o-t,i),n];case X.Top:return[t,n-Lt(n-r,i)];case X.Bottom:return[t,n+Lt(r-n,i)]}}function Xi({sourceX:e,sourceY:t,sourcePosition:n=X.Bottom,targetX:o,targetY:r,targetPosition:i=X.Top,curvature:s=.25}){const[a,c]=er({pos:n,x1:e,y1:t,x2:o,y2:r,c:s}),[l,u]=er({pos:i,x1:o,y1:r,x2:e,y2:t,c:s}),[f,d,p,g]=Yi({sourceX:e,sourceY:t,targetX:o,targetY:r,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${o},${r}`,f,d,p,g]}function Wi({sourceX:e,sourceY:t,targetX:n,targetY:o}){const r=Math.abs(n-e)/2,i=n<e?n+r:n-r,s=Math.abs(o-t)/2,a=o<t?o+s:o-s;return[i,a,r,s]}function lf({sourceNode:e,targetNode:t,selected:n=!1,zIndex:o=0,elevateOnSelect:r=!1,zIndexMode:i="basic"}){if(i==="manual")return o;const s=r&&n?o+1e3:o,a=Math.max(e.parentId||r&&e.selected?e.internals.z:0,t.parentId||r&&t.selected?t.internals.z:0);return s+a}function uf({sourceNode:e,targetNode:t,width:n,height:o,transform:r}){const i=fn(on(e),on(t));i.x===i.x2&&(i.x2+=1),i.y===i.y2&&(i.y2+=1);const s={x:-r[0]/r[2],y:-r[1]/r[2],width:n/r[2],height:o/r[2]};return rn(s,hn(i))>0}const df=({source:e,sourceHandle:t,target:n,targetHandle:o})=>`xy-edge__${e}${t||""}-${n}${o||""}`,ff=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),hf=(e,t,n={})=>{if(!e.source||!e.target)return n.onError?.("006",ye.error006()),t;const o=n.getEdgeId||df;let r;return Pi(e)?r={...e}:r={...e,id:o(e)},ff(r,t)?t:(r.sourceHandle===null&&delete r.sourceHandle,r.targetHandle===null&&delete r.targetHandle,t.concat(r))};function Zi({sourceX:e,sourceY:t,targetX:n,targetY:o}){const[r,i,s,a]=Wi({sourceX:e,sourceY:t,targetX:n,targetY:o});return[`M ${e},${t}L ${n},${o}`,r,i,s,a]}const tr={[X.Left]:{x:-1,y:0},[X.Right]:{x:1,y:0},[X.Top]:{x:0,y:-1},[X.Bottom]:{x:0,y:1}},pf=({source:e,sourcePosition:t=X.Bottom,target:n})=>t===X.Left||t===X.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},nr=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function gf({source:e,sourcePosition:t=X.Bottom,target:n,targetPosition:o=X.Top,center:r,offset:i,stepPosition:s}){const a=tr[t],c=tr[o],l={x:e.x+a.x*i,y:e.y+a.y*i},u={x:n.x+c.x*i,y:n.y+c.y*i},f=pf({source:l,sourcePosition:t,target:u}),d=f.x!==0?"x":"y",p=f[d];let g=[],v,w;const x={x:0,y:0},S={x:0,y:0},[,,m,y]=Wi({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(a[d]*c[d]===-1){d==="x"?(v=r.x??l.x+(u.x-l.x)*s,w=r.y??(l.y+u.y)/2):(v=r.x??(l.x+u.x)/2,w=r.y??l.y+(u.y-l.y)*s);const E=[{x:v,y:l.y},{x:v,y:u.y}],A=[{x:l.x,y:w},{x:u.x,y:w}];a[d]===p?g=d==="x"?E:A:g=d==="x"?A:E}else{const E=[{x:l.x,y:u.y}],A=[{x:u.x,y:l.y}];if(d==="x"?g=a.x===p?A:E:g=a.y===p?E:A,t===o){const _=Math.abs(e[d]-n[d]);if(_<=i){const k=Math.min(i-1,i-_);a[d]===p?x[d]=(l[d]>e[d]?-1:1)*k:S[d]=(u[d]>n[d]?-1:1)*k}}if(t!==o){const _=d==="x"?"y":"x",k=a[d]===c[_],M=l[_]>u[_],P=l[_]<u[_];(a[d]===1&&(!k&&M||k&&P)||a[d]!==1&&(!k&&P||k&&M))&&(g=d==="x"?E:A)}const B={x:l.x+x.x,y:l.y+x.y},T={x:u.x+S.x,y:u.y+S.y},L=Math.max(Math.abs(B.x-g[0].x),Math.abs(T.x-g[0].x)),H=Math.max(Math.abs(B.y-g[0].y),Math.abs(T.y-g[0].y));L>=H?(v=(B.x+T.x)/2,w=g[0].y):(v=g[0].x,w=(B.y+T.y)/2)}const I={x:l.x+x.x,y:l.y+x.y},b={x:u.x+S.x,y:u.y+S.y};return[[e,...I.x!==g[0].x||I.y!==g[0].y?[I]:[],...g,...b.x!==g[g.length-1].x||b.y!==g[g.length-1].y?[b]:[],n],v,w,m,y]}function mf(e,t,n,o){const r=Math.min(nr(e,t)/2,nr(t,n)/2,o),{x:i,y:s}=t;if(e.x===i&&i===n.x||e.y===s&&s===n.y)return`L${i} ${s}`;if(e.y===s){const l=e.x<n.x?-1:1,u=e.y<n.y?1:-1;return`L ${i+r*l},${s}Q ${i},${s} ${i},${s+r*u}`}const a=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${i},${s+r*c}Q ${i},${s} ${i+r*a},${s}`}function Gn({sourceX:e,sourceY:t,sourcePosition:n=X.Bottom,targetX:o,targetY:r,targetPosition:i=X.Top,borderRadius:s=5,centerX:a,centerY:c,offset:l=20,stepPosition:u=.5}){const[f,d,p,g,v]=gf({source:{x:e,y:t},sourcePosition:n,target:{x:o,y:r},targetPosition:i,center:{x:a,y:c},offset:l,stepPosition:u});let w=`M${f[0].x} ${f[0].y}`;for(let x=1;x<f.length-1;x++)w+=mf(f[x-1],f[x],f[x+1],s);return w+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[w,d,p,g,v]}function or(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function yf(e){const{sourceNode:t,targetNode:n}=e;if(!or(t)||!or(n))return null;const o=t.internals.handleBounds||rr(t.handles),r=n.internals.handleBounds||rr(n.handles),i=ir(o?.source??[],e.sourceHandle),s=ir(e.connectionMode===Ze.Strict?r?.target??[]:(r?.target??[]).concat(r?.source??[]),e.targetHandle);if(!i||!s)return e.onError?.("008",ye.error008(i?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const a=i?.position||X.Bottom,c=s?.position||X.Top,l=qe(t,i,a),u=qe(n,s,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:a,targetPosition:c}}function rr(e){if(!e)return null;const t=[],n=[];for(const o of e)o.width=o.width??1,o.height=o.height??1,o.type==="source"?t.push(o):o.type==="target"&&n.push(o);return{source:t,target:n}}function qe(e,t,n=X.Left,o=!1){const r=(t?.x??0)+e.internals.positionAbsolute.x,i=(t?.y??0)+e.internals.positionAbsolute.y,{width:s,height:a}=t??we(e);if(o)return{x:r+s/2,y:i+a/2};switch(t?.position??n){case X.Top:return{x:r+s/2,y:i};case X.Right:return{x:r+s,y:i+a/2};case X.Bottom:return{x:r+s/2,y:i+a};case X.Left:return{x:r,y:i+a/2}}}function ir(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function Un(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`:""}function xf(e,{id:t,defaultColor:n,defaultMarkerStart:o,defaultMarkerEnd:r}){const i=new Set;return e.reduce((s,a)=>([a.markerStart||o,a.markerEnd||r].forEach(c=>{if(c&&typeof c=="object"){const l=Un(c,t);i.has(l)||(s.push({id:l,color:c.color||n,...c}),i.add(l))}}),s),[]).sort((s,a)=>s.id.localeCompare(a.id))}const Gi=1e3,wf=10,mo={nodeOrigin:[0,0],nodeExtent:_t,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},vf={...mo,checkEquality:!0};function yo(e,t){const n={...e};for(const o in t)t[o]!==void 0&&(n[o]=t[o]);return n}function bf(e,t,n){const o=yo(mo,n);for(const r of e.values())if(r.parentId)wo(r,e,t,o);else{const i=Mt(r,o.nodeOrigin),s=Ue(r.extent)?r.extent:o.nodeExtent,a=Ge(i,s,we(r));r.internals.positionAbsolute=a}}function _f(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],o=[];for(const r of e.handles){const i={id:r.id,width:r.width??1,height:r.height??1,nodeId:e.id,x:r.x,y:r.y,position:r.position,type:r.type};r.type==="source"?n.push(i):r.type==="target"&&o.push(i)}return{source:n,target:o}}function xo(e){return e==="manual"}function qn(e,t,n,o={}){const r=yo(vf,o),i={i:0},s=new Map(t),a=r?.elevateNodesOnSelect&&!xo(r.zIndexMode)?Gi:0;let c=e.length>0,l=!1;t.clear(),n.clear();for(const u of e){let f=s.get(u.id);if(r.checkEquality&&u===f?.internals.userNode)t.set(u.id,f);else{const d=Mt(u,r.nodeOrigin),p=Ue(u.extent)?u.extent:r.nodeExtent,g=Ge(d,p,we(u));f={...r.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:g,handleBounds:_f(u,f),z:Ui(u,a,r.zIndexMode),userNode:u}},t.set(u.id,f)}(f.measured===void 0||f.measured.width===void 0||f.measured.height===void 0)&&!f.hidden&&(c=!1),u.parentId&&wo(f,t,n,o,i),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function Sf(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function wo(e,t,n,o,r){const{elevateNodesOnSelect:i,nodeOrigin:s,nodeExtent:a,zIndexMode:c}=yo(mo,o),l=e.parentId,u=t.get(l);if(!u){console.warn(`Parent node ${l} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Sf(e,n),r&&!u.parentId&&u.internals.rootParentIndex===void 0&&c==="auto"&&(u.internals.rootParentIndex=++r.i,u.internals.z=u.internals.z+r.i*wf),r&&u.internals.rootParentIndex!==void 0&&(r.i=u.internals.rootParentIndex);const f=i&&!xo(c)?Gi:0,{x:d,y:p,z:g}=Ef(e,u,s,a,f,c),{positionAbsolute:v}=e.internals,w=d!==v.x||p!==v.y;(w||g!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:d,y:p}:v,z:g}})}function Ui(e,t,n){const o=ge(e.zIndex)?e.zIndex:0;return xo(n)?o:o+(e.selected?t:0)}function Ef(e,t,n,o,r,i){const{x:s,y:a}=t.internals.positionAbsolute,c=we(e),l=Mt(e,n),u=Ue(e.extent)?Ge(l,e.extent,c):l;let f=Ge({x:s+u.x,y:a+u.y},o,c);e.extent==="parent"&&(f=ji(f,c,t));const d=Ui(e,r,i),p=t.internals.z??0;return{x:f.x,y:f.y,z:p>=d?p+1:d}}function vo(e,t,n,o=[0,0]){const r=[],i=new Map;for(const s of e){const a=t.get(s.parentId);if(!a)continue;const c=i.get(s.parentId)?.expandedRect??Et(a),l=$i(c,s.rect);i.set(s.parentId,{expandedRect:l,parent:a})}return i.size>0&&i.forEach(({expandedRect:s,parent:a},c)=>{const l=a.internals.positionAbsolute,u=we(a),f=a.origin??o,d=s.x<l.x?Math.round(Math.abs(l.x-s.x)):0,p=s.y<l.y?Math.round(Math.abs(l.y-s.y)):0,g=Math.max(u.width,Math.round(s.width)),v=Math.max(u.height,Math.round(s.height)),w=(g-u.width)*f[0],x=(v-u.height)*f[1];(d>0||p>0||w||x)&&(r.push({id:c,type:"position",position:{x:a.position.x-d+w,y:a.position.y-p+x}}),n.get(c)?.forEach(S=>{e.some(m=>m.id===S.id)||r.push({id:S.id,type:"position",position:{x:S.position.x+d,y:S.position.y+p}})})),(u.width<s.width||u.height<s.height||d||p)&&r.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(d?f[0]*d-w:0),height:v+(p?f[1]*p-x:0)}})}),r}function Nf(e,t,n,o,r,i,s){const a=o?.querySelector(".xyflow__viewport");let c=!1;if(!a)return{changes:[],updatedInternals:c};const l=[],u=window.getComputedStyle(a),{m22:f}=new window.DOMMatrixReadOnly(u.transform),d=[];for(const p of e.values()){const g=t.get(p.id);if(!g)continue;if(g.hidden){t.set(g.id,{...g,internals:{...g.internals,handleBounds:void 0}}),c=!0;continue}const v=go(p.nodeElement),w=g.measured.width!==v.width||g.measured.height!==v.height;if(!!(v.width&&v.height&&(w||!g.internals.handleBounds||p.force))){const S=p.nodeElement.getBoundingClientRect(),m=Ue(g.extent)?g.extent:i;let{positionAbsolute:y}=g.internals;if(g.parentId&&g.extent==="parent"){const b=t.get(g.parentId);b&&(y=ji(y,v,b))}else m&&(y=Ge(y,m,v));const I={...g,measured:v,internals:{...g.internals,positionAbsolute:y,handleBounds:{source:Jo("source",p.nodeElement,S,f,g.id),target:Jo("target",p.nodeElement,S,f,g.id)}}};t.set(g.id,I),g.parentId&&wo(I,t,n,{nodeOrigin:r,zIndexMode:s}),c=!0,w&&(l.push({id:g.id,type:"dimensions",dimensions:v}),g.expandParent&&g.parentId&&d.push({id:g.id,parentId:g.parentId,rect:Et(I,r)}))}}if(d.length>0){const p=vo(d,t,n,r);l.push(...p)}return{changes:l,updatedInternals:c}}async function Cf({delta:e,panZoom:t,transform:n,translateExtent:o,width:r,height:i}){if(!t||!e.x&&!e.y)return!1;const s=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[r,i]],o);return!!s&&(s.x!==n[0]||s.y!==n[1]||s.k!==n[2])}function sr(e,t,n,o,r,i){let s=r;const a=o.get(s)||new Map;o.set(s,a.set(n,t)),s=`${r}-${e}`;const c=o.get(s)||new Map;if(o.set(s,c.set(n,t)),i){s=`${r}-${e}-${i}`;const l=o.get(s)||new Map;o.set(s,l.set(n,t))}}function qi(e,t,n){e.clear(),t.clear();for(const o of n){const{source:r,target:i,sourceHandle:s=null,targetHandle:a=null}=o,c={edgeId:o.id,source:r,target:i,sourceHandle:s,targetHandle:a},l=`${r}-${s}--${i}-${a}`,u=`${i}-${a}--${r}-${s}`;sr("source",c,u,e,r,s),sr("target",c,l,e,i,a),t.set(o.id,o)}}function Ki(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:Ki(n,t):!1}function ar(e,t,n){let o=e;do{if(o?.matches?.(t))return!0;if(o===n)return!1;o=o?.parentElement}while(o);return!1}function If(e,t,n,o){const r=new Map;for(const[i,s]of e)if((s.selected||s.id===o)&&(!s.parentId||!Ki(s,e))&&(s.draggable||t&&typeof s.draggable>"u")){const a=e.get(i);a&&r.set(i,{id:i,position:a.position||{x:0,y:0},distance:{x:n.x-a.internals.positionAbsolute.x,y:n.y-a.internals.positionAbsolute.y},extent:a.extent,parentId:a.parentId,origin:a.origin,expandParent:a.expandParent,internals:{positionAbsolute:a.internals.positionAbsolute||{x:0,y:0}},measured:{width:a.measured.width??0,height:a.measured.height??0}})}return r}function In({nodeId:e,dragItems:t,nodeLookup:n,dragging:o=!0}){const r=[];for(const[s,a]of t){const c=n.get(s)?.internals.userNode;c&&r.push({...c,position:a.position,dragging:o})}if(!e)return[r[0],r];const i=n.get(e)?.internals.userNode;return[i?{...i,position:t.get(e)?.position||i.position,dragging:o}:r[0],r]}function kf({dragItems:e,snapGrid:t,x:n,y:o}){const r=e.values().next().value;if(!r)return null;const i={x:n-r.distance.x,y:o-r.distance.y},s=At(i,t);return{x:s.x-i.x,y:s.y-i.y}}function Mf({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:o,onDragStop:r}){let i={x:null,y:null},s=0,a=new Map,c=!1,l={x:0,y:0},u=null,f=!1,d=null,p=!1,g=!1,v=null;function w({noDragClassName:S,handleSelector:m,domNode:y,isSelectable:I,nodeId:b,nodeClickDistance:C=0}){d=ue(y);function E({x:L,y:H}){const{nodeLookup:_,nodeExtent:k,snapGrid:M,snapToGrid:P,nodeOrigin:j,onNodeDrag:$,onSelectionDrag:O,onError:V,updateNodePositions:z}=t();i={x:L,y:H};let W=!1;const Y=a.size>1,Z=Y&&k?Zn(Tt(a)):null,J=Y&&P?kf({dragItems:a,snapGrid:M,x:L,y:H}):null;for(const[R,D]of a){if(!_.has(R))continue;let F={x:L-D.distance.x,y:H-D.distance.y};P&&(F=J?{x:Math.round(F.x+J.x),y:Math.round(F.y+J.y)}:At(F,M));let U=null;if(Y&&k&&!D.extent&&Z){const{positionAbsolute:q}=D.internals,ee=q.x-Z.x+k[0][0],ne=q.x+D.measured.width-Z.x2+k[1][0],oe=q.y-Z.y+k[0][1],ce=q.y+D.measured.height-Z.y2+k[1][1];U=[[ee,oe],[ne,ce]]}const{position:Q,positionAbsolute:G}=Di({nodeId:R,nextPosition:F,nodeLookup:_,nodeExtent:U||k,nodeOrigin:j,onError:V});W=W||D.position.x!==Q.x||D.position.y!==Q.y,D.position=Q,D.internals.positionAbsolute=G}if(g=g||W,!!W&&(z(a,!0),v&&(o||$||!b&&O))){const[R,D]=In({nodeId:b,dragItems:a,nodeLookup:_});o?.(v,a,R,D),$?.(v,R,D),b||O?.(v,D)}}async function A(){if(!u)return;const{transform:L,panBy:H,autoPanSpeed:_,autoPanOnNodeDrag:k}=t();if(!k){c=!1,cancelAnimationFrame(s);return}const[M,P]=ho(l,u,_);(M!==0||P!==0)&&(i.x=(i.x??0)-M/L[2],i.y=(i.y??0)-P/L[2],await H({x:M,y:P})&&E(i)),s=requestAnimationFrame(A)}function B(L){const{nodeLookup:H,multiSelectionActive:_,nodesDraggable:k,transform:M,snapGrid:P,snapToGrid:j,selectNodesOnDrag:$,onNodeDragStart:O,onSelectionDragStart:V,unselectNodesAndEdges:z}=t();f=!0,(!$||!I)&&!_&&b&&(H.get(b)?.selected||z()),I&&$&&b&&e?.(b);const W=yt(L.sourceEvent,{transform:M,snapGrid:P,snapToGrid:j,containerBounds:u});if(i=W,a=If(H,k,W,b),a.size>0&&(n||O||!b&&V)){const[Y,Z]=In({nodeId:b,dragItems:a,nodeLookup:H});n?.(L.sourceEvent,a,Y,Z),O?.(L.sourceEvent,Y,Z),b||V?.(L.sourceEvent,Z)}}const T=hi().clickDistance(C).on("start",L=>{const{domNode:H,nodeDragThreshold:_,transform:k,snapGrid:M,snapToGrid:P}=t();u=H?.getBoundingClientRect()||null,p=!1,g=!1,v=L.sourceEvent,_===0&&B(L),i=yt(L.sourceEvent,{transform:k,snapGrid:M,snapToGrid:P,containerBounds:u}),l=me(L.sourceEvent,u)}).on("drag",L=>{const{autoPanOnNodeDrag:H,transform:_,snapGrid:k,snapToGrid:M,nodeDragThreshold:P,nodeLookup:j}=t(),$=yt(L.sourceEvent,{transform:_,snapGrid:k,snapToGrid:M,containerBounds:u});if(v=L.sourceEvent,(L.sourceEvent.type==="touchmove"&&L.sourceEvent.touches.length>1||b&&!j.has(b))&&(p=!0),!p){if(!c&&H&&f&&(c=!0,A()),!f){const O=me(L.sourceEvent,u),V=O.x-l.x,z=O.y-l.y;Math.sqrt(V*V+z*z)>P&&B(L)}(i.x!==$.xSnapped||i.y!==$.ySnapped)&&a&&f&&(l=me(L.sourceEvent,u),E($))}}).on("end",L=>{if(!f||p){p&&a.size>0&&t().updateNodePositions(a,!1);return}if(c=!1,f=!1,cancelAnimationFrame(s),a.size>0){const{nodeLookup:H,updateNodePositions:_,onNodeDragStop:k,onSelectionDragStop:M}=t();if(g&&(_(a,!1),g=!1),r||k||!b&&M){const[P,j]=In({nodeId:b,dragItems:a,nodeLookup:H,dragging:!1});r?.(L.sourceEvent,a,P,j),k?.(L.sourceEvent,P,j),b||M?.(L.sourceEvent,j)}}}).filter(L=>{const H=L.target;return!L.button&&(!S||!ar(H,`.${S}`,y))&&(!m||ar(H,m,y))});d.call(T)}function x(){d?.on(".drag",null)}return{update:w,destroy:x}}function Tf(e,t,n){const o=[],r={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const i of t.values())rn(r,Et(i))>0&&o.push(i);return o}const Af=250;function Pf(e,t,n,o){let r=[],i=1/0;const s=Tf(e,n,t+Af);for(const a of s){const c=[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]];for(const l of c){if(o.nodeId===l.nodeId&&o.type===l.type&&o.id===l.id)continue;const{x:u,y:f}=qe(a,l,l.position,!0),d=Math.sqrt(Math.pow(u-e.x,2)+Math.pow(f-e.y,2));d>t||(d<i?(r=[{...l,x:u,y:f}],i=d):d===i&&r.push({...l,x:u,y:f}))}}if(!r.length)return null;if(r.length>1){const a=o.type==="source"?"target":"source";return r.find(c=>c.type===a)??r[0]}return r[0]}function Qi(e,t,n,o,r,i=!1){const s=o.get(e);if(!s)return null;const a=r==="strict"?s.internals.handleBounds?.[t]:[...s.internals.handleBounds?.source??[],...s.internals.handleBounds?.target??[]],c=(n?a?.find(l=>l.id===n):a?.[0])??null;return c&&i?{...c,...qe(s,c,c.position,!0)}:c}function Ji(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function Df(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const es=()=>!0;function jf(e,{connectionMode:t,connectionRadius:n,handleId:o,nodeId:r,edgeUpdaterType:i,isTarget:s,domNode:a,nodeLookup:c,lib:l,autoPanOnConnect:u,flowId:f,panBy:d,cancelConnection:p,onConnectStart:g,onConnect:v,onConnectEnd:w,isValidConnection:x=es,onReconnectEnd:S,updateConnection:m,getTransform:y,getFromHandle:I,autoPanSpeed:b,dragThreshold:C=1,handleDomNode:E}){const A=Bi(e.target);let B=0,T;const{x:L,y:H}=me(e),_=Ji(i,E),k=a?.getBoundingClientRect();let M=!1;if(!k||!_)return;const P=Qi(r,_,o,c,t);if(!P)return;let j=me(e,k),$=!1,O=null,V=!1,z=null;function W(){if(!u||!k)return;const[Q,G]=ho(j,k,b);d({x:Q,y:G}),B=requestAnimationFrame(W)}const Y={...P,nodeId:r,type:_,position:P.position},Z=c.get(r);let R={inProgress:!0,isValid:null,from:qe(Z,Y,X.Left,!0),fromHandle:Y,fromPosition:Y.position,fromNode:Z,to:j,toHandle:null,toPosition:Uo[Y.position],toNode:null,pointer:j};function D(){M=!0,m(R),g?.(e,{nodeId:r,handleId:o,handleType:_})}C===0&&D();function F(Q){if(!M){const{x:ce,y:Ne}=me(Q),ve=ce-L,be=Ne-H;if(!(ve*ve+be*be>C*C))return;D()}if(!I()||!Y){U(Q);return}const G=y();j=me(Q,k),T=Pf(Pt(j,G,!1,[1,1]),n,c,Y),$||(W(),$=!0);const q=ts(Q,{handle:T,connectionMode:t,fromNodeId:r,fromHandleId:o,fromType:s?"target":"source",isValidConnection:x,doc:A,lib:l,flowId:f,nodeLookup:c});z=q.handleDomNode,O=q.connection,V=Df(!!T,q.isValid);const ee=c.get(r),ne=ee?qe(ee,Y,X.Left,!0):R.from,oe={...R,from:ne,isValid:V,to:q.toHandle&&V?ct({x:q.toHandle.x,y:q.toHandle.y},G):j,toHandle:q.toHandle,toPosition:V&&q.toHandle?q.toHandle.position:Uo[Y.position],toNode:q.toHandle?c.get(q.toHandle.nodeId):null,pointer:j};m(oe),R=oe}function U(Q){if(!("touches"in Q&&Q.touches.length>0)){if(M){(T||z)&&O&&V&&v?.(O);const{inProgress:G,...q}=R,ee={...q,toPosition:R.toHandle?R.toPosition:null};w?.(Q,ee),i&&S?.(Q,ee)}p(),cancelAnimationFrame(B),$=!1,V=!1,O=null,z=null,A.removeEventListener("mousemove",F),A.removeEventListener("mouseup",U),A.removeEventListener("touchmove",F),A.removeEventListener("touchend",U)}}A.addEventListener("mousemove",F),A.addEventListener("mouseup",U),A.addEventListener("touchmove",F),A.addEventListener("touchend",U)}function ts(e,{handle:t,connectionMode:n,fromNodeId:o,fromHandleId:r,fromType:i,doc:s,lib:a,flowId:c,isValidConnection:l=es,nodeLookup:u}){const f=i==="target",d=t?s.querySelector(`.${a}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:g}=me(e),v=s.elementFromPoint(p,g),w=v?.classList.contains(`${a}-flow__handle`)?v:d,x={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const S=Ji(void 0,w),m=w.getAttribute("data-nodeid"),y=w.getAttribute("data-handleid"),I=w.classList.contains("connectable"),b=w.classList.contains("connectableend");if(!m||!S)return x;const C={source:f?m:o,sourceHandle:f?y:r,target:f?o:m,targetHandle:f?r:y};x.connection=C;const A=I&&b&&(n===Ze.Strict?f&&S==="source"||!f&&S==="target":m!==o||y!==r);x.isValid=A&&l(C),x.toHandle=Qi(m,S,y,u,n,!0)}return x}const Kn={onPointerDown:jf,isValid:ts};function $f({domNode:e,panZoom:t,getTransform:n,getViewScale:o}){const r=ue(e);function i({translateExtent:a,width:c,height:l,zoomStep:u=1,pannable:f=!0,zoomable:d=!0,inversePan:p=!1}){const g=m=>{if(m.sourceEvent.type!=="wheel"||!t)return;const y=n(),I=m.sourceEvent.ctrlKey&&Nt()?10:1,b=-m.sourceEvent.deltaY*(m.sourceEvent.deltaMode===1?.05:m.sourceEvent.deltaMode?1:.002)*u,C=y[2]*Math.pow(2,b*I);t.scaleTo(C)};let v=[0,0];const w=m=>{(m.sourceEvent.type==="mousedown"||m.sourceEvent.type==="touchstart")&&(v=[m.sourceEvent.clientX??m.sourceEvent.touches[0].clientX,m.sourceEvent.clientY??m.sourceEvent.touches[0].clientY])},x=m=>{const y=n();if(m.sourceEvent.type!=="mousemove"&&m.sourceEvent.type!=="touchmove"||!t)return;const I=[m.sourceEvent.clientX??m.sourceEvent.touches[0].clientX,m.sourceEvent.clientY??m.sourceEvent.touches[0].clientY],b=[I[0]-v[0],I[1]-v[1]];v=I;const C=o()*Math.max(y[2],Math.log(y[2]))*(p?-1:1),E={x:y[0]-b[0]*C,y:y[1]-b[1]*C},A=[[0,0],[c,l]];t.setViewportConstrained({x:E.x,y:E.y,zoom:y[2]},A,a)},S=ki().on("start",w).on("zoom",f?x:null).on("zoom.wheel",d?g:null);r.call(S,{})}function s(){r.on("zoom",null)}return{update:i,destroy:s,pointer:he}}const pn=e=>({x:e.x,y:e.y,zoom:e.k}),kn=({x:e,y:t,zoom:n})=>dn.translate(e,t).scale(n),$e=(e,t)=>e.target.closest(`.${t}`),ns=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rf=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Mn=(e,t=0,n=Rf,o=()=>{})=>{const r=typeof t=="number"&&t>0;return r||o(),r?e.transition().duration(t).ease(n).on("end",o):e},os=e=>{const t=e.ctrlKey&&Nt()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Hf({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:o,panOnScrollMode:r,panOnScrollSpeed:i,zoomOnPinch:s,onPanZoomStart:a,onPanZoom:c,onPanZoomEnd:l}){return u=>{if($e(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(u.ctrlKey&&s){const w=he(u),x=os(u),S=f*Math.pow(2,x);o.scaleTo(n,S,w,u);return}const d=u.deltaMode===1?20:1;let p=r===Ye.Vertical?0:u.deltaX*d,g=r===Ye.Horizontal?0:u.deltaY*d;!Nt()&&u.shiftKey&&r!==Ye.Vertical&&(p=u.deltaY*d,g=0),o.translateBy(n,-(p/f)*i,-(g/f)*i,{internal:!0});const v=pn(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?c?.(u,v):(e.isPanScrolling=!0,a?.(u,v)),e.panScrollTimeout=setTimeout(()=>{l?.(u,v),e.isPanScrolling=!1},150)}}function Lf({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(o,r){const i=o.type==="wheel",s=!t&&i&&!o.ctrlKey,a=$e(o,e);if(o.ctrlKey&&i&&a&&o.preventDefault(),s||a)return null;o.preventDefault(),n.call(this,o,r)}}function Of({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return o=>{if(o.sourceEvent?.internal)return;const r=pn(o.transform);e.mouseButton=o.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=r,o.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(o.sourceEvent,r)}}function zf({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:o,onPanZoom:r}){return i=>{e.usedRightMouseButton=!!(n&&ns(t,e.mouseButton??0)),i.sourceEvent?.sync||o([i.transform.x,i.transform.y,i.transform.k]),r&&!i.sourceEvent?.internal&&r?.(i.sourceEvent,pn(i.transform))}}function Bf({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:o,onPanZoomEnd:r,onPaneContextMenu:i}){return s=>{if(!s.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,i&&ns(t,e.mouseButton??0)&&!e.usedRightMouseButton&&s.sourceEvent&&i(s.sourceEvent),e.usedRightMouseButton=!1,o(!1),r)){const a=pn(s.transform);e.prevViewport=a,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{r?.(s.sourceEvent,a)},n?150:0)}}}function Vf({panActivationKeyPressed:e,zoomActivationKeyPressed:t,zoomOnScroll:n,zoomOnPinch:o,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:s,userSelectionActive:a,noWheelClassName:c,noPanClassName:l,lib:u,connectionInProgress:f}){return d=>{const p=t||n,g=o&&d.ctrlKey,v=d.type==="wheel";if(d.button===1&&d.type==="mousedown"&&($e(d,`${u}-flow__node`)||$e(d,`${u}-flow__edge`)||$e(d,`${u}-flow__selection`)||$e(d,`${u}-flow__nodesselection`)))return!0;if(!r&&!p&&!i&&!s&&!o||a||f&&!v||$e(d,c)&&v||$e(d,l)&&(!v||i&&v&&!t)||!o&&d.ctrlKey&&v)return!1;if(!o&&d.type==="touchstart"&&d.touches?.length>1)return d.preventDefault(),!1;if(!p&&!i&&!g&&v||!r&&(d.type==="mousedown"||d.type==="touchstart")||Array.isArray(r)&&!r.includes(d.button)&&d.type==="mousedown")return!1;const w=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||v||e)&&w}}function Ff({domNode:e,minZoom:t,maxZoom:n,translateExtent:o,viewport:r,onPanZoom:i,onPanZoomStart:s,onPanZoomEnd:a,onDraggingChange:c}){const l={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect();let f=[[0,0],[u.width,u.height]];(typeof ResizeObserver<"u"?new ResizeObserver(H=>{const _=H[0];_&&(f=[[0,0],[_.contentRect.width,_.contentRect.height]])}):null)?.observe(e);const p=ki().extent(()=>f).scaleExtent([t,n]).translateExtent(o),g=ue(e).call(p);y({x:r.x,y:r.y,zoom:at(r.zoom,t,n)},[[0,0],[u.width,u.height]],o);const v=g.on("wheel.zoom"),w=g.on("dblclick.zoom");p.wheelDelta(os);async function x(H,_){return g?new Promise(k=>{p?.interpolate(_?.interpolate==="linear"?mt:Yt).transform(Mn(g,_?.duration,_?.ease,()=>k(!0)),H)}):!1}function S({noWheelClassName:H,noPanClassName:_,onPaneContextMenu:k,userSelectionActive:M,panOnScroll:P,panOnDrag:j,panOnScrollMode:$,panOnScrollSpeed:O,preventScrolling:V,zoomOnPinch:z,zoomOnScroll:W,zoomOnDoubleClick:Y,panActivationKeyPressed:Z=!1,zoomActivationKeyPressed:J,lib:R,onTransformChange:D,connectionInProgress:F,paneClickDistance:U,selectionOnDrag:Q}){M&&!l.isZoomingOrPanning&&m();const G=P&&!J&&!M;p.clickDistance(Q?1/0:!ge(U)||U<0?0:U);const q=G?Hf({zoomPanValues:l,noWheelClassName:H,d3Selection:g,d3Zoom:p,panOnScrollMode:$,panOnScrollSpeed:O,zoomOnPinch:z,onPanZoomStart:s,onPanZoom:i,onPanZoomEnd:a}):Lf({noWheelClassName:H,preventScrolling:V,d3ZoomHandler:v});g.on("wheel.zoom",q,{passive:!1});const ee=Of({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:s});p.on("start",ee);const ne=zf({zoomPanValues:l,panOnDrag:j,onPaneContextMenu:!!k,onPanZoom:i,onTransformChange:D});p.on("zoom",ne);const oe=Bf({zoomPanValues:l,panOnDrag:j,panOnScroll:P,onPaneContextMenu:k,onPanZoomEnd:a,onDraggingChange:c});p.on("end",oe);const ce=Vf({panActivationKeyPressed:Z,zoomActivationKeyPressed:J,panOnDrag:j,zoomOnScroll:W,panOnScroll:P,zoomOnDoubleClick:Y,zoomOnPinch:z,userSelectionActive:M,noPanClassName:_,noWheelClassName:H,lib:R,connectionInProgress:F});p.filter(ce),Y?g.on("dblclick.zoom",w):g.on("dblclick.zoom",null)}function m(){p.on("zoom",null)}async function y(H,_,k){const M=kn(H),P=p?.constrain()(M,_,k);return P&&await x(P),P}async function I(H,_){const k=kn(H);return await x(k,_),k}function b(H){if(g){const _=kn(H),k=g.property("__zoom");(k.k!==H.zoom||k.x!==H.x||k.y!==H.y)&&p?.transform(g,_,null,{sync:!0})}}function C(){const H=g?Ii(g.node()):{x:0,y:0,k:1};return{x:H.x,y:H.y,zoom:H.k}}async function E(H,_){return g?new Promise(k=>{p?.interpolate(_?.interpolate==="linear"?mt:Yt).scaleTo(Mn(g,_?.duration,_?.ease,()=>k(!0)),H)}):!1}async function A(H,_){return g?new Promise(k=>{p?.interpolate(_?.interpolate==="linear"?mt:Yt).scaleBy(Mn(g,_?.duration,_?.ease,()=>k(!0)),H)}):!1}function B(H){p?.scaleExtent(H)}function T(H){p?.translateExtent(H)}function L(H){const _=!ge(H)||H<0?0:H;p?.clickDistance(_)}return{update:S,destroy:m,setViewport:I,setViewportConstrained:y,getViewport:C,scaleTo:E,scaleBy:A,setScaleExtent:B,setTranslateExtent:T,syncViewport:b,setClickDistance:L}}var lt;(function(e){e.Line="line",e.Handle="handle"})(lt||(lt={}));function Yf({width:e,prevWidth:t,height:n,prevHeight:o,affectsX:r,affectsY:i}){const s=e-t,a=n-o,c=[s>0?1:s<0?-1:0,a>0?1:a<0?-1:0];return s&&r&&(c[0]=c[0]*-1),a&&i&&(c[1]=c[1]*-1),c}function cr(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),o=e.includes("left"),r=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:o,affectsY:r}}function De(e,t){return Math.max(0,t-e)}function je(e,t){return Math.max(0,e-t)}function Ot(e,t,n){return Math.max(0,t-e,e-n)}function lr(e,t){return e?!t:t}function Xf(e,t,n,o,r,i,s,a){let{affectsX:c,affectsY:l}=t;const{isHorizontal:u,isVertical:f}=t,d=u&&f,{xSnapped:p,ySnapped:g}=n,{minWidth:v,maxWidth:w,minHeight:x,maxHeight:S}=o,{x:m,y,width:I,height:b,aspectRatio:C}=e;let E=Math.floor(u?p-e.pointerX:0),A=Math.floor(f?g-e.pointerY:0);const B=I+(c?-E:E),T=b+(l?-A:A),L=-i[0]*I,H=-i[1]*b;let _=Ot(B,v,w),k=Ot(T,x,S);if(s){let j=0,$=0;c&&E<0?j=De(m+E+L,s[0][0]):!c&&E>0&&(j=je(m+B+L,s[1][0])),l&&A<0?$=De(y+A+H,s[0][1]):!l&&A>0&&($=je(y+T+H,s[1][1])),_=Math.max(_,j),k=Math.max(k,$)}if(a){let j=0,$=0;c&&E>0?j=je(m+E,a[0][0]):!c&&E<0&&(j=De(m+B,a[1][0])),l&&A>0?$=je(y+A,a[0][1]):!l&&A<0&&($=De(y+T,a[1][1])),_=Math.max(_,j),k=Math.max(k,$)}if(r){if(u){const j=Ot(B/C,x,S)*C;if(_=Math.max(_,j),s){let $=0;!c&&!l||c&&!l&&d?$=je(y+H+B/C,s[1][1])*C:$=De(y+H+(c?E:-E)/C,s[0][1])*C,_=Math.max(_,$)}if(a){let $=0;!c&&!l||c&&!l&&d?$=De(y+B/C,a[1][1])*C:$=je(y+(c?E:-E)/C,a[0][1])*C,_=Math.max(_,$)}}if(f){const j=Ot(T*C,v,w)/C;if(k=Math.max(k,j),s){let $=0;!c&&!l||l&&!c&&d?$=je(m+T*C+L,s[1][0])/C:$=De(m+(l?A:-A)*C+L,s[0][0])/C,k=Math.max(k,$)}if(a){let $=0;!c&&!l||l&&!c&&d?$=De(m+T*C,a[1][0])/C:$=je(m+(l?A:-A)*C,a[0][0])/C,k=Math.max(k,$)}}}A=A+(A<0?k:-k),E=E+(E<0?_:-_),r&&(d?B>T*C?A=(lr(c,l)?-E:E)/C:E=(lr(c,l)?-A:A)*C:u?(A=E/C,l=c):(E=A*C,c=l));const M=c?m+E:m,P=l?y+A:y;return{width:I+(c?-E:E),height:b+(l?-A:A),x:i[0]*E*(c?-1:1)+M,y:i[1]*A*(l?-1:1)+P}}const rs={width:0,height:0,x:0,y:0},Wf={...rs,pointerX:0,pointerY:0,aspectRatio:1};function Zf(e,t,n){const o=t.position.x+e.position.x,r=t.position.y+e.position.y,i=e.measured.width??0,s=e.measured.height??0,a=n[0]*i,c=n[1]*s;return[[o-a,r-c],[o+i-a,r+s-c]]}function Gf({domNode:e,nodeId:t,getStoreItems:n,onChange:o,onEnd:r}){const i=ue(e);let s={controlDirection:cr("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function a({controlPosition:l,boundaries:u,keepAspectRatio:f,resizeDirection:d,onResizeStart:p,onResize:g,onResizeEnd:v,shouldResize:w}){let x={...rs},S={...Wf};s={boundaries:u,resizeDirection:d,keepAspectRatio:f,controlDirection:cr(l)};let m,y=null,I=[],b,C,E,A=!1;const B=hi().on("start",T=>{const{nodeLookup:L,transform:H,snapGrid:_,snapToGrid:k,nodeOrigin:M,paneDomNode:P}=n();if(m=L.get(t),!m)return;y=P?.getBoundingClientRect()??null;const{xSnapped:j,ySnapped:$}=yt(T.sourceEvent,{transform:H,snapGrid:_,snapToGrid:k,containerBounds:y});x={width:m.measured.width??0,height:m.measured.height??0,x:m.position.x??0,y:m.position.y??0},S={...x,pointerX:j,pointerY:$,aspectRatio:x.width/x.height},b=void 0,C=Ue(m.extent)?m.extent:void 0,m.parentId&&(m.extent==="parent"||m.expandParent)&&(b=L.get(m.parentId)),b&&m.extent==="parent"&&(C=[[0,0],[b.measured.width,b.measured.height]]),I=[],E=void 0;for(const[O,V]of L)if(V.parentId===t&&(I.push({id:O,position:{...V.position},extent:V.extent}),V.extent==="parent"||V.expandParent)){const z=Zf(V,m,V.origin??M);E?E=[[Math.min(z[0][0],E[0][0]),Math.min(z[0][1],E[0][1])],[Math.max(z[1][0],E[1][0]),Math.max(z[1][1],E[1][1])]]:E=z}p?.(T,{...x})}).on("drag",T=>{const{transform:L,snapGrid:H,snapToGrid:_,nodeOrigin:k}=n(),M=yt(T.sourceEvent,{transform:L,snapGrid:H,snapToGrid:_,containerBounds:y}),P=[];if(!m)return;const{x:j,y:$,width:O,height:V}=x,z={},W=m.origin??k,{width:Y,height:Z,x:J,y:R}=Xf(S,s.controlDirection,M,s.boundaries,s.keepAspectRatio,W,C,E),D=Y!==O,F=Z!==V,U=J!==j&&D,Q=R!==$&&F;if(!U&&!Q&&!D&&!F)return;if((U||Q||W[0]===1||W[1]===1)&&(z.x=U?J:x.x,z.y=Q?R:x.y,x.x=z.x,x.y=z.y,I.length>0)){const ne=J-j,oe=R-$;for(const ce of I)ce.position={x:ce.position.x-ne+W[0]*(Y-O),y:ce.position.y-oe+W[1]*(Z-V)},P.push(ce)}if((D||F)&&(z.width=D&&(!s.resizeDirection||s.resizeDirection==="horizontal")?Y:x.width,z.height=F&&(!s.resizeDirection||s.resizeDirection==="vertical")?Z:x.height,x.width=z.width,x.height=z.height),b&&m.expandParent){const ne=W[0]*(z.width??0);z.x&&z.x<ne&&(x.x=ne,S.x=S.x-(z.x-ne));const oe=W[1]*(z.height??0);z.y&&z.y<oe&&(x.y=oe,S.y=S.y-(z.y-oe))}const G=Yf({width:x.width,prevWidth:O,height:x.height,prevHeight:V,affectsX:s.controlDirection.affectsX,affectsY:s.controlDirection.affectsY}),q={...x,direction:G};w?.(T,q)!==!1&&(A=!0,g?.(T,q),o(z,P))}).on("end",T=>{A&&(v?.(T,{...x}),r?.({...x}),A=!1)});i.call(B)}function c(){i.on(".drag",null)}return{update:a,destroy:c}}var Tn={exports:{}},An={},Pn={exports:{}},Dn={};var ur;function Uf(){if(ur)return Dn;ur=1;var e=Kr();function t(f,d){return f===d&&(f!==0||1/f===1/d)||f!==f&&d!==d}var n=typeof Object.is=="function"?Object.is:t,o=e.useState,r=e.useEffect,i=e.useLayoutEffect,s=e.useDebugValue;function a(f,d){var p=d(),g=o({inst:{value:p,getSnapshot:d}}),v=g[0].inst,w=g[1];return i(function(){v.value=p,v.getSnapshot=d,c(v)&&w({inst:v})},[f,p,d]),r(function(){return c(v)&&w({inst:v}),f(function(){c(v)&&w({inst:v})})},[f]),s(p),p}function c(f){var d=f.getSnapshot;f=f.value;try{var p=d();return!n(f,p)}catch{return!0}}function l(f,d){return d()}var u=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?l:a;return Dn.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:u,Dn}var dr;function qf(){return dr||(dr=1,Pn.exports=Uf()),Pn.exports}var fr;function Kf(){if(fr)return An;fr=1;var e=Kr(),t=qf();function n(l,u){return l===u&&(l!==0||1/l===1/u)||l!==l&&u!==u}var o=typeof Object.is=="function"?Object.is:n,r=t.useSyncExternalStore,i=e.useRef,s=e.useEffect,a=e.useMemo,c=e.useDebugValue;return An.useSyncExternalStoreWithSelector=function(l,u,f,d,p){var g=i(null);if(g.current===null){var v={hasValue:!1,value:null};g.current=v}else v=g.current;g=a(function(){function x(b){if(!S){if(S=!0,m=b,b=d(b),p!==void 0&&v.hasValue){var C=v.value;if(p(C,b))return y=C}return y=b}if(C=y,o(m,b))return C;var E=d(b);return p!==void 0&&p(C,E)?(m=b,C):(m=b,y=E)}var S=!1,m,y,I=f===void 0?null:f;return[function(){return x(u())},I===null?void 0:function(){return x(I())}]},[u,f,d,p]);var w=r(l,g[0],g[1]);return s(function(){v.hasValue=!0,v.value=w},[w]),c(w),w},An}var hr;function Qf(){return hr||(hr=1,Tn.exports=Kf()),Tn.exports}var Jf=Qf();const eh=Qa(Jf),th={},pr=e=>{let t;const n=new Set,o=(u,f)=>{const d=typeof u=="function"?u(t):u;if(!Object.is(d,t)){const p=t;t=f??(typeof d!="object"||d===null)?d:Object.assign({},t,d),n.forEach(g=>g(t,p))}},r=()=>t,c={setState:o,getState:r,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(th?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(o,r,c);return c},nh=e=>e?pr(e):pr,{useDebugValue:oh}=Ja,{useSyncExternalStoreWithSelector:rh}=eh,ih=e=>e;function is(e,t=ih,n){const o=rh(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return oh(o),o}const gr=(e,t)=>{const n=nh(e),o=(r,i=t)=>is(n,r,i);return Object.assign(o,n),o},sh=(e,t)=>e?gr(e,t):gr;function ie(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[o,r]of e)if(!Object.is(r,t.get(o)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const o of e)if(!t.has(o))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}const gn=N.createContext(null),ah=gn.Provider,ss=ye.error001("react");function te(e,t){const n=N.useContext(gn);if(n===null)throw new Error(ss);return is(n,e,t)}function re(){const e=N.useContext(gn);if(e===null)throw new Error(ss);return N.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const mr={display:"none"},ch={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},as="react-flow__node-desc",cs="react-flow__edge-desc",lh="react-flow__aria-live",uh=e=>e.ariaLiveMessage,dh=e=>e.ariaLabelConfig;function fh({rfId:e}){const t=te(uh);return h.jsx("div",{id:`${lh}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:ch,children:t})}function hh({rfId:e,disableKeyboardA11y:t}){const n=te(dh);return h.jsxs(h.Fragment,{children:[h.jsx("div",{id:`${as}-${e}`,style:mr,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),h.jsx("div",{id:`${cs}-${e}`,style:mr,children:n["edge.a11yDescription.default"]}),!t&&h.jsx(fh,{rfId:e})]})}const Ke=N.forwardRef(({position:e="top-left",children:t,className:n,style:o,...r},i)=>{const s=`${e}`.split("-");return h.jsx("div",{className:se(["react-flow__panel",n,...s]),style:o,ref:i,...r,children:t})});Ke.displayName="Panel";const yr="https://reactflow.dev?utm_source=attribution";function ph({proOptions:e,position:t="bottom-right"}){return N.useEffect(()=>{},[]),e?.hideAttribution?null:h.jsx(Ke,{position:t,className:"react-flow__attribution","data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: ${yr}`,children:h.jsx("a",{href:yr,target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const gh=e=>{const t=[],n=[];for(const[,o]of e.nodeLookup)o.selected&&t.push(o.internals.userNode);for(const[,o]of e.edgeLookup)o.selected&&n.push(o);return{selectedNodes:t,selectedEdges:n}},zt=e=>e.id;function mh(e,t){return ie(e.selectedNodes.map(zt),t.selectedNodes.map(zt))&&ie(e.selectedEdges.map(zt),t.selectedEdges.map(zt))}function yh({onSelectionChange:e}){const t=re(),{selectedNodes:n,selectedEdges:o}=te(gh,mh);return N.useEffect(()=>{const r={nodes:n,edges:o};e?.(r),t.getState().onSelectionChangeHandlers.forEach(i=>i(r))},[n,o,e]),null}const xh=e=>!!e.onSelectionChangeHandlers;function wh({onSelectionChange:e}){const t=te(xh);return e||t?h.jsx(yh,{onSelectionChange:e}):null}const ls=[0,0],vh={x:0,y:0,zoom:1},bh=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],xr=[...bh,"rfId"],_h=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),wr={translateExtent:_t,nodeOrigin:ls,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function Sh(e){const{setNodes:t,setEdges:n,setMinZoom:o,setMaxZoom:r,setTranslateExtent:i,setNodeExtent:s,reset:a,setDefaultNodesAndEdges:c}=te(_h,ie),l=re();N.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{u.current=wr,a()}),[]);const u=N.useRef(wr);return N.useEffect(()=>{for(const f of xr){const d=e[f],p=u.current[f];d!==p&&(typeof e[f]>"u"||(f==="nodes"?t(d):f==="edges"?n(d):f==="minZoom"?o(d):f==="maxZoom"?r(d):f==="translateExtent"?i(d):f==="nodeExtent"?s(d):f==="ariaLabelConfig"?l.setState({ariaLabelConfig:af(d)}):f==="fitView"?l.setState({fitViewQueued:d}):f==="fitViewOptions"?l.setState({fitViewOptions:d}):l.setState({[f]:d})))}u.current=e},xr.map(f=>e[f])),null}function vr(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Eh(e){const[t,n]=N.useState(e==="system"?null:e);return N.useEffect(()=>{if(e!=="system"){n(e);return}const o=vr(),r=()=>n(o?.matches?"dark":"light");return r(),o?.addEventListener("change",r),()=>{o?.removeEventListener("change",r)}},[e]),t!==null?t:vr()?.matches?"dark":"light"}const br=typeof document<"u"?document:null;function Ct(e=null,t={target:br,actInsideInputWithModifier:!0}){const[n,o]=N.useState(!1),r=N.useRef(!1),i=N.useRef(new Set([])),[s,a]=N.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace(/\+/g,`
1
+ import{m as Kr,n as Qa,R as Ja,f as N,j as h}from"./index-WbTkAEzk.js";import{u as ae,a as Q,r as ec,i as Vt,S as tc,f as nc,g as oc,b as rc,n as ic,c as sc,w as ac,d as cc,e as Qr,h as lc,l as uc,j as dc,k as fc,m as hc,o as Qe,p as pc,q as gc}from"./App-Bq_IUqRU.js";import{c as mc}from"./clipboard-DirTPLEi.js";import{A as yc}from"./AssetMediaLightbox-CxfO1QUc.js";import"./useAgentDialogFocus-CyM46tgI.js";function se(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,o;n<e.length;n++)(o=se(e[n]))!==""&&(t+=(t&&" ")+o);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var xc={value:()=>{}};function an(){for(var e=0,t=arguments.length,n={},o;e<t;++e){if(!(o=arguments[e]+"")||o in n||/[\s.]/.test(o))throw new Error("illegal type: "+o);n[o]=[]}return new Ft(n)}function Ft(e){this._=e}function wc(e,t){return e.trim().split(/^|\s+/).map(function(n){var o="",r=n.indexOf(".");if(r>=0&&(o=n.slice(r+1),n=n.slice(0,r)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:o}})}Ft.prototype=an.prototype={constructor:Ft,on:function(e,t){var n=this._,o=wc(e+"",n),r,i=-1,s=o.length;if(arguments.length<2){for(;++i<s;)if((r=(e=o[i]).type)&&(r=vc(n[r],e.name)))return r;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++i<s;)if(r=(e=o[i]).type)n[r]=Po(n[r],e.name,t);else if(t==null)for(r in n)n[r]=Po(n[r],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Ft(e)},call:function(e,t){if((r=arguments.length-2)>0)for(var n=new Array(r),o=0,r,i;o<r;++o)n[o]=arguments[o+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(i=this._[e],o=0,r=i.length;o<r;++o)i[o].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var o=this._[e],r=0,i=o.length;r<i;++r)o[r].value.apply(t,n)}};function vc(e,t){for(var n=0,o=e.length,r;n<o;++n)if((r=e[n]).name===t)return r.value}function Po(e,t,n){for(var o=0,r=e.length;o<r;++o)if(e[o].name===t){e[o]=xc,e=e.slice(0,o).concat(e.slice(o+1));break}return n!=null&&e.push({name:t,value:n}),e}var On="http://www.w3.org/1999/xhtml";const Do={svg:"http://www.w3.org/2000/svg",xhtml:On,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function cn(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Do.hasOwnProperty(t)?{space:Do[t],local:e}:e}function bc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===On&&t.documentElement.namespaceURI===On?t.createElement(e):t.createElementNS(n,e)}}function _c(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Jr(e){var t=cn(e);return(t.local?_c:bc)(t)}function Sc(){}function oo(e){return e==null?Sc:function(){return this.querySelector(e)}}function Ec(e){typeof e!="function"&&(e=oo(e));for(var t=this._groups,n=t.length,o=new Array(n),r=0;r<n;++r)for(var i=t[r],s=i.length,a=o[r]=new Array(s),c,l,u=0;u<s;++u)(c=i[u])&&(l=e.call(c,c.__data__,u,i))&&("__data__"in c&&(l.__data__=c.__data__),a[u]=l);return new de(o,this._parents)}function Nc(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Cc(){return[]}function ei(e){return e==null?Cc:function(){return this.querySelectorAll(e)}}function Ic(e){return function(){return Nc(e.apply(this,arguments))}}function kc(e){typeof e=="function"?e=Ic(e):e=ei(e);for(var t=this._groups,n=t.length,o=[],r=[],i=0;i<n;++i)for(var s=t[i],a=s.length,c,l=0;l<a;++l)(c=s[l])&&(o.push(e.call(c,c.__data__,l,s)),r.push(c));return new de(o,r)}function ti(e){return function(){return this.matches(e)}}function ni(e){return function(t){return t.matches(e)}}var Mc=Array.prototype.find;function Tc(e){return function(){return Mc.call(this.children,e)}}function Ac(){return this.firstElementChild}function Pc(e){return this.select(e==null?Ac:Tc(typeof e=="function"?e:ni(e)))}var Dc=Array.prototype.filter;function jc(){return Array.from(this.children)}function $c(e){return function(){return Dc.call(this.children,e)}}function Rc(e){return this.selectAll(e==null?jc:$c(typeof e=="function"?e:ni(e)))}function Hc(e){typeof e!="function"&&(e=ti(e));for(var t=this._groups,n=t.length,o=new Array(n),r=0;r<n;++r)for(var i=t[r],s=i.length,a=o[r]=[],c,l=0;l<s;++l)(c=i[l])&&e.call(c,c.__data__,l,i)&&a.push(c);return new de(o,this._parents)}function oi(e){return new Array(e.length)}function Lc(){return new de(this._enter||this._groups.map(oi),this._parents)}function Ut(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Ut.prototype={constructor:Ut,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Oc(e){return function(){return e}}function zc(e,t,n,o,r,i){for(var s=0,a,c=t.length,l=i.length;s<l;++s)(a=t[s])?(a.__data__=i[s],o[s]=a):n[s]=new Ut(e,i[s]);for(;s<c;++s)(a=t[s])&&(r[s]=a)}function Bc(e,t,n,o,r,i,s){var a,c,l=new Map,u=t.length,f=i.length,d=new Array(u),p;for(a=0;a<u;++a)(c=t[a])&&(d[a]=p=s.call(c,c.__data__,a,t)+"",l.has(p)?r[a]=c:l.set(p,c));for(a=0;a<f;++a)p=s.call(e,i[a],a,i)+"",(c=l.get(p))?(o[a]=c,c.__data__=i[a],l.delete(p)):n[a]=new Ut(e,i[a]);for(a=0;a<u;++a)(c=t[a])&&l.get(d[a])===c&&(r[a]=c)}function Vc(e){return e.__data__}function Fc(e,t){if(!arguments.length)return Array.from(this,Vc);var n=t?Bc:zc,o=this._parents,r=this._groups;typeof e!="function"&&(e=Oc(e));for(var i=r.length,s=new Array(i),a=new Array(i),c=new Array(i),l=0;l<i;++l){var u=o[l],f=r[l],d=f.length,p=Yc(e.call(u,u&&u.__data__,l,o)),g=p.length,v=a[l]=new Array(g),w=s[l]=new Array(g),x=c[l]=new Array(d);n(u,f,v,w,x,p,t);for(var S=0,m=0,y,I;S<g;++S)if(y=v[S]){for(S>=m&&(m=S+1);!(I=w[m])&&++m<g;);y._next=I||null}}return s=new de(s,o),s._enter=a,s._exit=c,s}function Yc(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Xc(){return new de(this._exit||this._groups.map(oi),this._parents)}function Wc(e,t,n){var o=this.enter(),r=this,i=this.exit();return typeof e=="function"?(o=e(o),o&&(o=o.selection())):o=o.append(e+""),t!=null&&(r=t(r),r&&(r=r.selection())),n==null?i.remove():n(i),o&&r?o.merge(r).order():r}function Zc(e){for(var t=e.selection?e.selection():e,n=this._groups,o=t._groups,r=n.length,i=o.length,s=Math.min(r,i),a=new Array(r),c=0;c<s;++c)for(var l=n[c],u=o[c],f=l.length,d=a[c]=new Array(f),p,g=0;g<f;++g)(p=l[g]||u[g])&&(d[g]=p);for(;c<r;++c)a[c]=n[c];return new de(a,this._parents)}function Gc(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var o=e[t],r=o.length-1,i=o[r],s;--r>=0;)(s=o[r])&&(i&&s.compareDocumentPosition(i)^4&&i.parentNode.insertBefore(s,i),i=s);return this}function Uc(e){e||(e=qc);function t(f,d){return f&&d?e(f.__data__,d.__data__):!f-!d}for(var n=this._groups,o=n.length,r=new Array(o),i=0;i<o;++i){for(var s=n[i],a=s.length,c=r[i]=new Array(a),l,u=0;u<a;++u)(l=s[u])&&(c[u]=l);c.sort(t)}return new de(r,this._parents).order()}function qc(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Kc(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Qc(){return Array.from(this)}function Jc(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var o=e[t],r=0,i=o.length;r<i;++r){var s=o[r];if(s)return s}return null}function el(){let e=0;for(const t of this)++e;return e}function tl(){return!this.node()}function nl(e){for(var t=this._groups,n=0,o=t.length;n<o;++n)for(var r=t[n],i=0,s=r.length,a;i<s;++i)(a=r[i])&&e.call(a,a.__data__,i,r);return this}function ol(e){return function(){this.removeAttribute(e)}}function rl(e){return function(){this.removeAttributeNS(e.space,e.local)}}function il(e,t){return function(){this.setAttribute(e,t)}}function sl(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function al(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function cl(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function ll(e,t){var n=cn(e);if(arguments.length<2){var o=this.node();return n.local?o.getAttributeNS(n.space,n.local):o.getAttribute(n)}return this.each((t==null?n.local?rl:ol:typeof t=="function"?n.local?cl:al:n.local?sl:il)(n,t))}function ri(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function ul(e){return function(){this.style.removeProperty(e)}}function dl(e,t,n){return function(){this.style.setProperty(e,t,n)}}function fl(e,t,n){return function(){var o=t.apply(this,arguments);o==null?this.style.removeProperty(e):this.style.setProperty(e,o,n)}}function hl(e,t,n){return arguments.length>1?this.each((t==null?ul:typeof t=="function"?fl:dl)(e,t,n??"")):it(this.node(),e)}function it(e,t){return e.style.getPropertyValue(t)||ri(e).getComputedStyle(e,null).getPropertyValue(t)}function pl(e){return function(){delete this[e]}}function gl(e,t){return function(){this[e]=t}}function ml(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function yl(e,t){return arguments.length>1?this.each((t==null?pl:typeof t=="function"?ml:gl)(e,t)):this.node()[e]}function ii(e){return e.trim().split(/^|\s+/)}function ro(e){return e.classList||new si(e)}function si(e){this._node=e,this._names=ii(e.getAttribute("class")||"")}si.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function ai(e,t){for(var n=ro(e),o=-1,r=t.length;++o<r;)n.add(t[o])}function ci(e,t){for(var n=ro(e),o=-1,r=t.length;++o<r;)n.remove(t[o])}function xl(e){return function(){ai(this,e)}}function wl(e){return function(){ci(this,e)}}function vl(e,t){return function(){(t.apply(this,arguments)?ai:ci)(this,e)}}function bl(e,t){var n=ii(e+"");if(arguments.length<2){for(var o=ro(this.node()),r=-1,i=n.length;++r<i;)if(!o.contains(n[r]))return!1;return!0}return this.each((typeof t=="function"?vl:t?xl:wl)(n,t))}function _l(){this.textContent=""}function Sl(e){return function(){this.textContent=e}}function El(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function Nl(e){return arguments.length?this.each(e==null?_l:(typeof e=="function"?El:Sl)(e)):this.node().textContent}function Cl(){this.innerHTML=""}function Il(e){return function(){this.innerHTML=e}}function kl(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function Ml(e){return arguments.length?this.each(e==null?Cl:(typeof e=="function"?kl:Il)(e)):this.node().innerHTML}function Tl(){this.nextSibling&&this.parentNode.appendChild(this)}function Al(){return this.each(Tl)}function Pl(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Dl(){return this.each(Pl)}function jl(e){var t=typeof e=="function"?e:Jr(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function $l(){return null}function Rl(e,t){var n=typeof e=="function"?e:Jr(e),o=t==null?$l:typeof t=="function"?t:oo(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),o.apply(this,arguments)||null)})}function Hl(){var e=this.parentNode;e&&e.removeChild(this)}function Ll(){return this.each(Hl)}function Ol(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function zl(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Bl(e){return this.select(e?zl:Ol)}function Vl(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Fl(e){return function(t){e.call(this,t,this.__data__)}}function Yl(e){return e.trim().split(/^|\s+/).map(function(t){var n="",o=t.indexOf(".");return o>=0&&(n=t.slice(o+1),t=t.slice(0,o)),{type:t,name:n}})}function Xl(e){return function(){var t=this.__on;if(t){for(var n=0,o=-1,r=t.length,i;n<r;++n)i=t[n],(!e.type||i.type===e.type)&&i.name===e.name?this.removeEventListener(i.type,i.listener,i.options):t[++o]=i;++o?t.length=o:delete this.__on}}}function Wl(e,t,n){return function(){var o=this.__on,r,i=Fl(t);if(o){for(var s=0,a=o.length;s<a;++s)if((r=o[s]).type===e.type&&r.name===e.name){this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=i,r.options=n),r.value=t;return}}this.addEventListener(e.type,i,n),r={type:e.type,name:e.name,value:t,listener:i,options:n},o?o.push(r):this.__on=[r]}}function Zl(e,t,n){var o=Yl(e+""),r,i=o.length,s;if(arguments.length<2){var a=this.node().__on;if(a){for(var c=0,l=a.length,u;c<l;++c)for(r=0,u=a[c];r<i;++r)if((s=o[r]).type===u.type&&s.name===u.name)return u.value}return}for(a=t?Wl:Xl,r=0;r<i;++r)this.each(a(o[r],t,n));return this}function li(e,t,n){var o=ri(e),r=o.CustomEvent;typeof r=="function"?r=new r(t,n):(r=o.document.createEvent("Event"),n?(r.initEvent(t,n.bubbles,n.cancelable),r.detail=n.detail):r.initEvent(t,!1,!1)),e.dispatchEvent(r)}function Gl(e,t){return function(){return li(this,e,t)}}function Ul(e,t){return function(){return li(this,e,t.apply(this,arguments))}}function ql(e,t){return this.each((typeof t=="function"?Ul:Gl)(e,t))}function*Kl(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var o=e[t],r=0,i=o.length,s;r<i;++r)(s=o[r])&&(yield s)}var ui=[null];function de(e,t){this._groups=e,this._parents=t}function It(){return new de([[document.documentElement]],ui)}function Ql(){return this}de.prototype=It.prototype={constructor:de,select:Ec,selectAll:kc,selectChild:Pc,selectChildren:Rc,filter:Hc,data:Fc,enter:Lc,exit:Xc,join:Wc,merge:Zc,selection:Ql,order:Gc,sort:Uc,call:Kc,nodes:Qc,node:Jc,size:el,empty:tl,each:nl,attr:ll,style:hl,property:yl,classed:bl,text:Nl,html:Ml,raise:Al,lower:Dl,append:jl,insert:Rl,remove:Ll,clone:Bl,datum:Vl,on:Zl,dispatch:ql,[Symbol.iterator]:Kl};function ue(e){return typeof e=="string"?new de([[document.querySelector(e)]],[document.documentElement]):new de([[e]],ui)}function Jl(e){let t;for(;t=e.sourceEvent;)e=t;return e}function he(e,t){if(e=Jl(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var o=n.createSVGPoint();return o.x=e.clientX,o.y=e.clientY,o=o.matrixTransform(t.getScreenCTM().inverse()),[o.x,o.y]}if(t.getBoundingClientRect){var r=t.getBoundingClientRect();return[e.clientX-r.left-t.clientLeft,e.clientY-r.top-t.clientTop]}}return[e.pageX,e.pageY]}const eu={passive:!1},xt={capture:!0,passive:!1};function Sn(e){e.stopImmediatePropagation()}function nt(e){e.preventDefault(),e.stopImmediatePropagation()}function di(e){var t=e.document.documentElement,n=ue(e).on("dragstart.drag",nt,xt);"onselectstart"in t?n.on("selectstart.drag",nt,xt):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function fi(e,t){var n=e.document.documentElement,o=ue(e).on("dragstart.drag",null);t&&(o.on("click.drag",nt,xt),setTimeout(function(){o.on("click.drag",null)},0)),"onselectstart"in n?o.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Dt=e=>()=>e;function zn(e,{sourceEvent:t,subject:n,target:o,identifier:r,active:i,x:s,y:a,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:o,enumerable:!0,configurable:!0},identifier:{value:r,enumerable:!0,configurable:!0},active:{value:i,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}zn.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function tu(e){return!e.ctrlKey&&!e.button}function nu(){return this.parentNode}function ou(e,t){return t??{x:e.x,y:e.y}}function ru(){return navigator.maxTouchPoints||"ontouchstart"in this}function hi(){var e=tu,t=nu,n=ou,o=ru,r={},i=an("start","drag","end"),s=0,a,c,l,u,f=0;function d(y){y.on("mousedown.drag",p).filter(o).on("touchstart.drag",w).on("touchmove.drag",x,eu).on("touchend.drag touchcancel.drag",S).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(y,I){if(!(u||!e.call(this,y,I))){var b=m(this,t.call(this,y,I),y,I,"mouse");b&&(ue(y.view).on("mousemove.drag",g,xt).on("mouseup.drag",v,xt),di(y.view),Sn(y),l=!1,a=y.clientX,c=y.clientY,b("start",y))}}function g(y){if(nt(y),!l){var I=y.clientX-a,b=y.clientY-c;l=I*I+b*b>f}r.mouse("drag",y)}function v(y){ue(y.view).on("mousemove.drag mouseup.drag",null),fi(y.view,l),nt(y),r.mouse("end",y)}function w(y,I){if(e.call(this,y,I)){var b=y.changedTouches,C=t.call(this,y,I),E=b.length,A,B;for(A=0;A<E;++A)(B=m(this,C,y,I,b[A].identifier,b[A]))&&(Sn(y),B("start",y,b[A]))}}function x(y){var I=y.changedTouches,b=I.length,C,E;for(C=0;C<b;++C)(E=r[I[C].identifier])&&(nt(y),E("drag",y,I[C]))}function S(y){var I=y.changedTouches,b=I.length,C,E;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),C=0;C<b;++C)(E=r[I[C].identifier])&&(Sn(y),E("end",y,I[C]))}function m(y,I,b,C,E,A){var B=i.copy(),T=he(A||b,I),L,H,_;if((_=n.call(y,new zn("beforestart",{sourceEvent:b,target:d,identifier:E,active:s,x:T[0],y:T[1],dx:0,dy:0,dispatch:B}),C))!=null)return L=_.x-T[0]||0,H=_.y-T[1]||0,function k(M,P,j){var $=T,z;switch(M){case"start":r[E]=k,z=s++;break;case"end":delete r[E],--s;case"drag":T=he(j||P,I),z=s;break}B.call(M,y,new zn(M,{sourceEvent:P,subject:_,target:d,identifier:E,active:z,x:T[0]+L,y:T[1]+H,dx:T[0]-$[0],dy:T[1]-$[1],dispatch:B}),C)}}return d.filter=function(y){return arguments.length?(e=typeof y=="function"?y:Dt(!!y),d):e},d.container=function(y){return arguments.length?(t=typeof y=="function"?y:Dt(y),d):t},d.subject=function(y){return arguments.length?(n=typeof y=="function"?y:Dt(y),d):n},d.touchable=function(y){return arguments.length?(o=typeof y=="function"?y:Dt(!!y),d):o},d.on=function(){var y=i.on.apply(i,arguments);return y===i?d:y},d.clickDistance=function(y){return arguments.length?(f=(y=+y)*y,d):Math.sqrt(f)},d}function io(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function pi(e,t){var n=Object.create(e.prototype);for(var o in t)n[o]=t[o];return n}function kt(){}var wt=.7,qt=1/wt,ot="\\s*([+-]?\\d+)\\s*",vt="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Se="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",iu=/^#([0-9a-f]{3,8})$/,su=new RegExp(`^rgb\\(${ot},${ot},${ot}\\)$`),au=new RegExp(`^rgb\\(${Se},${Se},${Se}\\)$`),cu=new RegExp(`^rgba\\(${ot},${ot},${ot},${vt}\\)$`),lu=new RegExp(`^rgba\\(${Se},${Se},${Se},${vt}\\)$`),uu=new RegExp(`^hsl\\(${vt},${Se},${Se}\\)$`),du=new RegExp(`^hsla\\(${vt},${Se},${Se},${vt}\\)$`),jo={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};io(kt,Xe,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:$o,formatHex:$o,formatHex8:fu,formatHsl:hu,formatRgb:Ro,toString:Ro});function $o(){return this.rgb().formatHex()}function fu(){return this.rgb().formatHex8()}function hu(){return gi(this).formatHsl()}function Ro(){return this.rgb().formatRgb()}function Xe(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=iu.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Ho(t):n===3?new le(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?jt(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?jt(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=su.exec(e))?new le(t[1],t[2],t[3],1):(t=au.exec(e))?new le(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=cu.exec(e))?jt(t[1],t[2],t[3],t[4]):(t=lu.exec(e))?jt(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=uu.exec(e))?zo(t[1],t[2]/100,t[3]/100,1):(t=du.exec(e))?zo(t[1],t[2]/100,t[3]/100,t[4]):jo.hasOwnProperty(e)?Ho(jo[e]):e==="transparent"?new le(NaN,NaN,NaN,0):null}function Ho(e){return new le(e>>16&255,e>>8&255,e&255,1)}function jt(e,t,n,o){return o<=0&&(e=t=n=NaN),new le(e,t,n,o)}function pu(e){return e instanceof kt||(e=Xe(e)),e?(e=e.rgb(),new le(e.r,e.g,e.b,e.opacity)):new le}function Bn(e,t,n,o){return arguments.length===1?pu(e):new le(e,t,n,o??1)}function le(e,t,n,o){this.r=+e,this.g=+t,this.b=+n,this.opacity=+o}io(le,Bn,pi(kt,{brighter(e){return e=e==null?qt:Math.pow(qt,e),new le(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?wt:Math.pow(wt,e),new le(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new le(Fe(this.r),Fe(this.g),Fe(this.b),Kt(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:Lo,formatHex:Lo,formatHex8:gu,formatRgb:Oo,toString:Oo}));function Lo(){return`#${Ve(this.r)}${Ve(this.g)}${Ve(this.b)}`}function gu(){return`#${Ve(this.r)}${Ve(this.g)}${Ve(this.b)}${Ve((isNaN(this.opacity)?1:this.opacity)*255)}`}function Oo(){const e=Kt(this.opacity);return`${e===1?"rgb(":"rgba("}${Fe(this.r)}, ${Fe(this.g)}, ${Fe(this.b)}${e===1?")":`, ${e})`}`}function Kt(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Fe(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Ve(e){return e=Fe(e),(e<16?"0":"")+e.toString(16)}function zo(e,t,n,o){return o<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new pe(e,t,n,o)}function gi(e){if(e instanceof pe)return new pe(e.h,e.s,e.l,e.opacity);if(e instanceof kt||(e=Xe(e)),!e)return new pe;if(e instanceof pe)return e;e=e.rgb();var t=e.r/255,n=e.g/255,o=e.b/255,r=Math.min(t,n,o),i=Math.max(t,n,o),s=NaN,a=i-r,c=(i+r)/2;return a?(t===i?s=(n-o)/a+(n<o)*6:n===i?s=(o-t)/a+2:s=(t-n)/a+4,a/=c<.5?i+r:2-i-r,s*=60):a=c>0&&c<1?0:s,new pe(s,a,c,e.opacity)}function mu(e,t,n,o){return arguments.length===1?gi(e):new pe(e,t,n,o??1)}function pe(e,t,n,o){this.h=+e,this.s=+t,this.l=+n,this.opacity=+o}io(pe,mu,pi(kt,{brighter(e){return e=e==null?qt:Math.pow(qt,e),new pe(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?wt:Math.pow(wt,e),new pe(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,o=n+(n<.5?n:1-n)*t,r=2*n-o;return new le(En(e>=240?e-240:e+120,r,o),En(e,r,o),En(e<120?e+240:e-120,r,o),this.opacity)},clamp(){return new pe(Bo(this.h),$t(this.s),$t(this.l),Kt(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 e=Kt(this.opacity);return`${e===1?"hsl(":"hsla("}${Bo(this.h)}, ${$t(this.s)*100}%, ${$t(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Bo(e){return e=(e||0)%360,e<0?e+360:e}function $t(e){return Math.max(0,Math.min(1,e||0))}function En(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const so=e=>()=>e;function yu(e,t){return function(n){return e+n*t}}function xu(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(o){return Math.pow(e+o*t,n)}}function wu(e){return(e=+e)==1?mi:function(t,n){return n-t?xu(t,n,e):so(isNaN(t)?n:t)}}function mi(e,t){var n=t-e;return n?yu(e,n):so(isNaN(e)?t:e)}const Qt=(function e(t){var n=wu(t);function o(r,i){var s=n((r=Bn(r)).r,(i=Bn(i)).r),a=n(r.g,i.g),c=n(r.b,i.b),l=mi(r.opacity,i.opacity);return function(u){return r.r=s(u),r.g=a(u),r.b=c(u),r.opacity=l(u),r+""}}return o.gamma=e,o})(1);function vu(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,o=t.slice(),r;return function(i){for(r=0;r<n;++r)o[r]=e[r]*(1-i)+t[r]*i;return o}}function bu(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function _u(e,t){var n=t?t.length:0,o=e?Math.min(n,e.length):0,r=new Array(o),i=new Array(n),s;for(s=0;s<o;++s)r[s]=mt(e[s],t[s]);for(;s<n;++s)i[s]=t[s];return function(a){for(s=0;s<o;++s)i[s]=r[s](a);return i}}function Su(e,t){var n=new Date;return e=+e,t=+t,function(o){return n.setTime(e*(1-o)+t*o),n}}function _e(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Eu(e,t){var n={},o={},r;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(r in t)r in e?n[r]=mt(e[r],t[r]):o[r]=t[r];return function(i){for(r in n)o[r]=n[r](i);return o}}var Vn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Nn=new RegExp(Vn.source,"g");function Nu(e){return function(){return e}}function Cu(e){return function(t){return e(t)+""}}function yi(e,t){var n=Vn.lastIndex=Nn.lastIndex=0,o,r,i,s=-1,a=[],c=[];for(e=e+"",t=t+"";(o=Vn.exec(e))&&(r=Nn.exec(t));)(i=r.index)>n&&(i=t.slice(n,i),a[s]?a[s]+=i:a[++s]=i),(o=o[0])===(r=r[0])?a[s]?a[s]+=r:a[++s]=r:(a[++s]=null,c.push({i:s,x:_e(o,r)})),n=Nn.lastIndex;return n<t.length&&(i=t.slice(n),a[s]?a[s]+=i:a[++s]=i),a.length<2?c[0]?Cu(c[0].x):Nu(t):(t=c.length,function(l){for(var u=0,f;u<t;++u)a[(f=c[u]).i]=f.x(l);return a.join("")})}function mt(e,t){var n=typeof t,o;return t==null||n==="boolean"?so(t):(n==="number"?_e:n==="string"?(o=Xe(t))?(t=o,Qt):yi:t instanceof Xe?Qt:t instanceof Date?Su:bu(t)?vu:Array.isArray(t)?_u:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?Eu:_e)(e,t)}var Vo=180/Math.PI,Fn={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function xi(e,t,n,o,r,i){var s,a,c;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(c=e*n+t*o)&&(n-=e*c,o-=t*c),(a=Math.sqrt(n*n+o*o))&&(n/=a,o/=a,c/=a),e*o<t*n&&(e=-e,t=-t,c=-c,s=-s),{translateX:r,translateY:i,rotate:Math.atan2(t,e)*Vo,skewX:Math.atan(c)*Vo,scaleX:s,scaleY:a}}var Rt;function Iu(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Fn:xi(t.a,t.b,t.c,t.d,t.e,t.f)}function ku(e){return e==null||(Rt||(Rt=document.createElementNS("http://www.w3.org/2000/svg","g")),Rt.setAttribute("transform",e),!(e=Rt.transform.baseVal.consolidate()))?Fn:(e=e.matrix,xi(e.a,e.b,e.c,e.d,e.e,e.f))}function wi(e,t,n,o){function r(l){return l.length?l.pop()+" ":""}function i(l,u,f,d,p,g){if(l!==f||u!==d){var v=p.push("translate(",null,t,null,n);g.push({i:v-4,x:_e(l,f)},{i:v-2,x:_e(u,d)})}else(f||d)&&p.push("translate("+f+t+d+n)}function s(l,u,f,d){l!==u?(l-u>180?u+=360:u-l>180&&(l+=360),d.push({i:f.push(r(f)+"rotate(",null,o)-2,x:_e(l,u)})):u&&f.push(r(f)+"rotate("+u+o)}function a(l,u,f,d){l!==u?d.push({i:f.push(r(f)+"skewX(",null,o)-2,x:_e(l,u)}):u&&f.push(r(f)+"skewX("+u+o)}function c(l,u,f,d,p,g){if(l!==f||u!==d){var v=p.push(r(p)+"scale(",null,",",null,")");g.push({i:v-4,x:_e(l,f)},{i:v-2,x:_e(u,d)})}else(f!==1||d!==1)&&p.push(r(p)+"scale("+f+","+d+")")}return function(l,u){var f=[],d=[];return l=e(l),u=e(u),i(l.translateX,l.translateY,u.translateX,u.translateY,f,d),s(l.rotate,u.rotate,f,d),a(l.skewX,u.skewX,f,d),c(l.scaleX,l.scaleY,u.scaleX,u.scaleY,f,d),l=u=null,function(p){for(var g=-1,v=d.length,w;++g<v;)f[(w=d[g]).i]=w.x(p);return f.join("")}}}var Mu=wi(Iu,"px, ","px)","deg)"),Tu=wi(ku,", ",")",")"),Au=1e-12;function Fo(e){return((e=Math.exp(e))+1/e)/2}function Pu(e){return((e=Math.exp(e))-1/e)/2}function Du(e){return((e=Math.exp(2*e))-1)/(e+1)}const Yt=(function e(t,n,o){function r(i,s){var a=i[0],c=i[1],l=i[2],u=s[0],f=s[1],d=s[2],p=u-a,g=f-c,v=p*p+g*g,w,x;if(v<Au)x=Math.log(d/l)/t,w=function(C){return[a+C*p,c+C*g,l*Math.exp(t*C*x)]};else{var S=Math.sqrt(v),m=(d*d-l*l+o*v)/(2*l*n*S),y=(d*d-l*l-o*v)/(2*d*n*S),I=Math.log(Math.sqrt(m*m+1)-m),b=Math.log(Math.sqrt(y*y+1)-y);x=(b-I)/t,w=function(C){var E=C*x,A=Fo(I),B=l/(n*S)*(A*Du(t*E+I)-Pu(I));return[a+B*p,c+B*g,l*A/Fo(t*E+I)]}}return w.duration=x*1e3*t/Math.SQRT2,w}return r.rho=function(i){var s=Math.max(.001,+i),a=s*s,c=a*a;return e(s,a,c)},r})(Math.SQRT2,2,4);var st=0,pt=0,dt=0,vi=1e3,Jt,gt,en=0,We=0,ln=0,bt=typeof performance=="object"&&performance.now?performance:Date,bi=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function ao(){return We||(bi(ju),We=bt.now()+ln)}function ju(){We=0}function tn(){this._call=this._time=this._next=null}tn.prototype=_i.prototype={constructor:tn,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?ao():+n)+(t==null?0:+t),!this._next&&gt!==this&&(gt?gt._next=this:Jt=this,gt=this),this._call=e,this._time=n,Yn()},stop:function(){this._call&&(this._call=null,this._time=1/0,Yn())}};function _i(e,t,n){var o=new tn;return o.restart(e,t,n),o}function $u(){ao(),++st;for(var e=Jt,t;e;)(t=We-e._time)>=0&&e._call.call(void 0,t),e=e._next;--st}function Yo(){We=(en=bt.now())+ln,st=pt=0;try{$u()}finally{st=0,Hu(),We=0}}function Ru(){var e=bt.now(),t=e-en;t>vi&&(ln-=t,en=e)}function Hu(){for(var e,t=Jt,n,o=1/0;t;)t._call?(o>t._time&&(o=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Jt=n);gt=e,Yn(o)}function Yn(e){if(!st){pt&&(pt=clearTimeout(pt));var t=e-We;t>24?(e<1/0&&(pt=setTimeout(Yo,e-bt.now()-ln)),dt&&(dt=clearInterval(dt))):(dt||(en=bt.now(),dt=setInterval(Ru,vi)),st=1,bi(Yo))}}function Xo(e,t,n){var o=new tn;return t=t==null?0:+t,o.restart(r=>{o.stop(),e(r+t)},t,n),o}var Lu=an("start","end","cancel","interrupt"),Ou=[],Si=0,Wo=1,Xn=2,Xt=3,Zo=4,Wn=5,Wt=6;function un(e,t,n,o,r,i){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;zu(e,n,{name:t,index:o,group:r,on:Lu,tween:Ou,time:i.time,delay:i.delay,duration:i.duration,ease:i.ease,timer:null,state:Si})}function co(e,t){var n=xe(e,t);if(n.state>Si)throw new Error("too late; already scheduled");return n}function Ee(e,t){var n=xe(e,t);if(n.state>Xt)throw new Error("too late; already running");return n}function xe(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function zu(e,t,n){var o=e.__transition,r;o[t]=n,n.timer=_i(i,0,n.time);function i(l){n.state=Wo,n.timer.restart(s,n.delay,n.time),n.delay<=l&&s(l-n.delay)}function s(l){var u,f,d,p;if(n.state!==Wo)return c();for(u in o)if(p=o[u],p.name===n.name){if(p.state===Xt)return Xo(s);p.state===Zo?(p.state=Wt,p.timer.stop(),p.on.call("interrupt",e,e.__data__,p.index,p.group),delete o[u]):+u<t&&(p.state=Wt,p.timer.stop(),p.on.call("cancel",e,e.__data__,p.index,p.group),delete o[u])}if(Xo(function(){n.state===Xt&&(n.state=Zo,n.timer.restart(a,n.delay,n.time),a(l))}),n.state=Xn,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Xn){for(n.state=Xt,r=new Array(d=n.tween.length),u=0,f=-1;u<d;++u)(p=n.tween[u].value.call(e,e.__data__,n.index,n.group))&&(r[++f]=p);r.length=f+1}}function a(l){for(var u=l<n.duration?n.ease.call(null,l/n.duration):(n.timer.restart(c),n.state=Wn,1),f=-1,d=r.length;++f<d;)r[f].call(e,u);n.state===Wn&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=Wt,n.timer.stop(),delete o[t];for(var l in o)return;delete e.__transition}}function Zt(e,t){var n=e.__transition,o,r,i=!0,s;if(n){t=t==null?null:t+"";for(s in n){if((o=n[s]).name!==t){i=!1;continue}r=o.state>Xn&&o.state<Wn,o.state=Wt,o.timer.stop(),o.on.call(r?"interrupt":"cancel",e,e.__data__,o.index,o.group),delete n[s]}i&&delete e.__transition}}function Bu(e){return this.each(function(){Zt(this,e)})}function Vu(e,t){var n,o;return function(){var r=Ee(this,e),i=r.tween;if(i!==n){o=n=i;for(var s=0,a=o.length;s<a;++s)if(o[s].name===t){o=o.slice(),o.splice(s,1);break}}r.tween=o}}function Fu(e,t,n){var o,r;if(typeof n!="function")throw new Error;return function(){var i=Ee(this,e),s=i.tween;if(s!==o){r=(o=s).slice();for(var a={name:t,value:n},c=0,l=r.length;c<l;++c)if(r[c].name===t){r[c]=a;break}c===l&&r.push(a)}i.tween=r}}function Yu(e,t){var n=this._id;if(e+="",arguments.length<2){for(var o=xe(this.node(),n).tween,r=0,i=o.length,s;r<i;++r)if((s=o[r]).name===e)return s.value;return null}return this.each((t==null?Vu:Fu)(n,e,t))}function lo(e,t,n){var o=e._id;return e.each(function(){var r=Ee(this,o);(r.value||(r.value={}))[t]=n.apply(this,arguments)}),function(r){return xe(r,o).value[t]}}function Ei(e,t){var n;return(typeof t=="number"?_e:t instanceof Xe?Qt:(n=Xe(t))?(t=n,Qt):yi)(e,t)}function Xu(e){return function(){this.removeAttribute(e)}}function Wu(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Zu(e,t,n){var o,r=n+"",i;return function(){var s=this.getAttribute(e);return s===r?null:s===o?i:i=t(o=s,n)}}function Gu(e,t,n){var o,r=n+"",i;return function(){var s=this.getAttributeNS(e.space,e.local);return s===r?null:s===o?i:i=t(o=s,n)}}function Uu(e,t,n){var o,r,i;return function(){var s,a=n(this),c;return a==null?void this.removeAttribute(e):(s=this.getAttribute(e),c=a+"",s===c?null:s===o&&c===r?i:(r=c,i=t(o=s,a)))}}function qu(e,t,n){var o,r,i;return function(){var s,a=n(this),c;return a==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),c=a+"",s===c?null:s===o&&c===r?i:(r=c,i=t(o=s,a)))}}function Ku(e,t){var n=cn(e),o=n==="transform"?Tu:Ei;return this.attrTween(e,typeof t=="function"?(n.local?qu:Uu)(n,o,lo(this,"attr."+e,t)):t==null?(n.local?Wu:Xu)(n):(n.local?Gu:Zu)(n,o,t))}function Qu(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Ju(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function ed(e,t){var n,o;function r(){var i=t.apply(this,arguments);return i!==o&&(n=(o=i)&&Ju(e,i)),n}return r._value=t,r}function td(e,t){var n,o;function r(){var i=t.apply(this,arguments);return i!==o&&(n=(o=i)&&Qu(e,i)),n}return r._value=t,r}function nd(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var o=cn(e);return this.tween(n,(o.local?ed:td)(o,t))}function od(e,t){return function(){co(this,e).delay=+t.apply(this,arguments)}}function rd(e,t){return t=+t,function(){co(this,e).delay=t}}function id(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?od:rd)(t,e)):xe(this.node(),t).delay}function sd(e,t){return function(){Ee(this,e).duration=+t.apply(this,arguments)}}function ad(e,t){return t=+t,function(){Ee(this,e).duration=t}}function cd(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?sd:ad)(t,e)):xe(this.node(),t).duration}function ld(e,t){if(typeof t!="function")throw new Error;return function(){Ee(this,e).ease=t}}function ud(e){var t=this._id;return arguments.length?this.each(ld(t,e)):xe(this.node(),t).ease}function dd(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ee(this,e).ease=n}}function fd(e){if(typeof e!="function")throw new Error;return this.each(dd(this._id,e))}function hd(e){typeof e!="function"&&(e=ti(e));for(var t=this._groups,n=t.length,o=new Array(n),r=0;r<n;++r)for(var i=t[r],s=i.length,a=o[r]=[],c,l=0;l<s;++l)(c=i[l])&&e.call(c,c.__data__,l,i)&&a.push(c);return new Pe(o,this._parents,this._name,this._id)}function pd(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,o=t.length,r=n.length,i=Math.min(o,r),s=new Array(o),a=0;a<i;++a)for(var c=t[a],l=n[a],u=c.length,f=s[a]=new Array(u),d,p=0;p<u;++p)(d=c[p]||l[p])&&(f[p]=d);for(;a<o;++a)s[a]=t[a];return new Pe(s,this._parents,this._name,this._id)}function gd(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function md(e,t,n){var o,r,i=gd(t)?co:Ee;return function(){var s=i(this,e),a=s.on;a!==o&&(r=(o=a).copy()).on(t,n),s.on=r}}function yd(e,t){var n=this._id;return arguments.length<2?xe(this.node(),n).on.on(e):this.each(md(n,e,t))}function xd(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function wd(){return this.on("end.remove",xd(this._id))}function vd(e){var t=this._name,n=this._id;typeof e!="function"&&(e=oo(e));for(var o=this._groups,r=o.length,i=new Array(r),s=0;s<r;++s)for(var a=o[s],c=a.length,l=i[s]=new Array(c),u,f,d=0;d<c;++d)(u=a[d])&&(f=e.call(u,u.__data__,d,a))&&("__data__"in u&&(f.__data__=u.__data__),l[d]=f,un(l[d],t,n,d,l,xe(u,n)));return new Pe(i,this._parents,t,n)}function bd(e){var t=this._name,n=this._id;typeof e!="function"&&(e=ei(e));for(var o=this._groups,r=o.length,i=[],s=[],a=0;a<r;++a)for(var c=o[a],l=c.length,u,f=0;f<l;++f)if(u=c[f]){for(var d=e.call(u,u.__data__,f,c),p,g=xe(u,n),v=0,w=d.length;v<w;++v)(p=d[v])&&un(p,t,n,v,d,g);i.push(d),s.push(u)}return new Pe(i,s,t,n)}var _d=It.prototype.constructor;function Sd(){return new _d(this._groups,this._parents)}function Ed(e,t){var n,o,r;return function(){var i=it(this,e),s=(this.style.removeProperty(e),it(this,e));return i===s?null:i===n&&s===o?r:r=t(n=i,o=s)}}function Ni(e){return function(){this.style.removeProperty(e)}}function Nd(e,t,n){var o,r=n+"",i;return function(){var s=it(this,e);return s===r?null:s===o?i:i=t(o=s,n)}}function Cd(e,t,n){var o,r,i;return function(){var s=it(this,e),a=n(this),c=a+"";return a==null&&(c=a=(this.style.removeProperty(e),it(this,e))),s===c?null:s===o&&c===r?i:(r=c,i=t(o=s,a))}}function Id(e,t){var n,o,r,i="style."+t,s="end."+i,a;return function(){var c=Ee(this,e),l=c.on,u=c.value[i]==null?a||(a=Ni(t)):void 0;(l!==n||r!==u)&&(o=(n=l).copy()).on(s,r=u),c.on=o}}function kd(e,t,n){var o=(e+="")=="transform"?Mu:Ei;return t==null?this.styleTween(e,Ed(e,o)).on("end.style."+e,Ni(e)):typeof t=="function"?this.styleTween(e,Cd(e,o,lo(this,"style."+e,t))).each(Id(this._id,e)):this.styleTween(e,Nd(e,o,t),n).on("end.style."+e,null)}function Md(e,t,n){return function(o){this.style.setProperty(e,t.call(this,o),n)}}function Td(e,t,n){var o,r;function i(){var s=t.apply(this,arguments);return s!==r&&(o=(r=s)&&Md(e,s,n)),o}return i._value=t,i}function Ad(e,t,n){var o="style."+(e+="");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,Td(e,t,n??""))}function Pd(e){return function(){this.textContent=e}}function Dd(e){return function(){var t=e(this);this.textContent=t??""}}function jd(e){return this.tween("text",typeof e=="function"?Dd(lo(this,"text",e)):Pd(e==null?"":e+""))}function $d(e){return function(t){this.textContent=e.call(this,t)}}function Rd(e){var t,n;function o(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&$d(r)),t}return o._value=e,o}function Hd(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,Rd(e))}function Ld(){for(var e=this._name,t=this._id,n=Ci(),o=this._groups,r=o.length,i=0;i<r;++i)for(var s=o[i],a=s.length,c,l=0;l<a;++l)if(c=s[l]){var u=xe(c,t);un(c,e,n,l,s,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Pe(o,this._parents,e,n)}function Od(){var e,t,n=this,o=n._id,r=n.size();return new Promise(function(i,s){var a={value:s},c={value:function(){--r===0&&i()}};n.each(function(){var l=Ee(this,o),u=l.on;u!==e&&(t=(e=u).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(c)),l.on=t}),r===0&&i()})}var zd=0;function Pe(e,t,n,o){this._groups=e,this._parents=t,this._name=n,this._id=o}function Ci(){return++zd}var Me=It.prototype;Pe.prototype={constructor:Pe,select:vd,selectAll:bd,selectChild:Me.selectChild,selectChildren:Me.selectChildren,filter:hd,merge:pd,selection:Sd,transition:Ld,call:Me.call,nodes:Me.nodes,node:Me.node,size:Me.size,empty:Me.empty,each:Me.each,on:yd,attr:Ku,attrTween:nd,style:kd,styleTween:Ad,text:jd,textTween:Hd,remove:wd,tween:Yu,delay:id,duration:cd,ease:ud,easeVarying:fd,end:Od,[Symbol.iterator]:Me[Symbol.iterator]};function Bd(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Vd={time:null,delay:0,duration:250,ease:Bd};function Fd(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function Yd(e){var t,n;e instanceof Pe?(t=e._id,e=e._name):(t=Ci(),(n=Vd).time=ao(),e=e==null?null:e+"");for(var o=this._groups,r=o.length,i=0;i<r;++i)for(var s=o[i],a=s.length,c,l=0;l<a;++l)(c=s[l])&&un(c,e,t,l,s,n||Fd(c,t));return new Pe(o,this._parents,e,t)}It.prototype.interrupt=Bu;It.prototype.transition=Yd;const Ht=e=>()=>e;function Xd(e,{sourceEvent:t,target:n,transform:o,dispatch:r}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:o,enumerable:!0,configurable:!0},_:{value:r}})}function Te(e,t,n){this.k=e,this.x=t,this.y=n}Te.prototype={constructor:Te,scale:function(e){return e===1?this:new Te(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Te(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var dn=new Te(1,0,0);Ii.prototype=Te.prototype;function Ii(e){for(;!e.__zoom;)if(!(e=e.parentNode))return dn;return e.__zoom}function Cn(e){e.stopImmediatePropagation()}function ft(e){e.preventDefault(),e.stopImmediatePropagation()}function Wd(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Zd(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Go(){return this.__zoom||dn}function Gd(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Ud(){return navigator.maxTouchPoints||"ontouchstart"in this}function qd(e,t,n){var o=e.invertX(t[0][0])-n[0][0],r=e.invertX(t[1][0])-n[1][0],i=e.invertY(t[0][1])-n[0][1],s=e.invertY(t[1][1])-n[1][1];return e.translate(r>o?(o+r)/2:Math.min(0,o)||Math.max(0,r),s>i?(i+s)/2:Math.min(0,i)||Math.max(0,s))}function ki(){var e=Wd,t=Zd,n=qd,o=Gd,r=Ud,i=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],a=250,c=Yt,l=an("start","zoom","end"),u,f,d,p=500,g=150,v=0,w=10;function x(_){_.property("__zoom",Go).on("wheel.zoom",E,{passive:!1}).on("mousedown.zoom",A).on("dblclick.zoom",B).filter(r).on("touchstart.zoom",T).on("touchmove.zoom",L).on("touchend.zoom touchcancel.zoom",H).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}x.transform=function(_,k,M,P){var j=_.selection?_.selection():_;j.property("__zoom",Go),_!==j?I(_,k,M,P):j.interrupt().each(function(){b(this,arguments).event(P).start().zoom(null,typeof k=="function"?k.apply(this,arguments):k).end()})},x.scaleBy=function(_,k,M,P){x.scaleTo(_,function(){var j=this.__zoom.k,$=typeof k=="function"?k.apply(this,arguments):k;return j*$},M,P)},x.scaleTo=function(_,k,M,P){x.transform(_,function(){var j=t.apply(this,arguments),$=this.__zoom,z=M==null?y(j):typeof M=="function"?M.apply(this,arguments):M,O=$.invert(z),V=typeof k=="function"?k.apply(this,arguments):k;return n(m(S($,V),z,O),j,s)},M,P)},x.translateBy=function(_,k,M,P){x.transform(_,function(){return n(this.__zoom.translate(typeof k=="function"?k.apply(this,arguments):k,typeof M=="function"?M.apply(this,arguments):M),t.apply(this,arguments),s)},null,P)},x.translateTo=function(_,k,M,P,j){x.transform(_,function(){var $=t.apply(this,arguments),z=this.__zoom,O=P==null?y($):typeof P=="function"?P.apply(this,arguments):P;return n(dn.translate(O[0],O[1]).scale(z.k).translate(typeof k=="function"?-k.apply(this,arguments):-k,typeof M=="function"?-M.apply(this,arguments):-M),$,s)},P,j)};function S(_,k){return k=Math.max(i[0],Math.min(i[1],k)),k===_.k?_:new Te(k,_.x,_.y)}function m(_,k,M){var P=k[0]-M[0]*_.k,j=k[1]-M[1]*_.k;return P===_.x&&j===_.y?_:new Te(_.k,P,j)}function y(_){return[(+_[0][0]+ +_[1][0])/2,(+_[0][1]+ +_[1][1])/2]}function I(_,k,M,P){_.on("start.zoom",function(){b(this,arguments).event(P).start()}).on("interrupt.zoom end.zoom",function(){b(this,arguments).event(P).end()}).tween("zoom",function(){var j=this,$=arguments,z=b(j,$).event(P),O=t.apply(j,$),V=M==null?y(O):typeof M=="function"?M.apply(j,$):M,G=Math.max(O[1][0]-O[0][0],O[1][1]-O[0][1]),Y=j.__zoom,W=typeof k=="function"?k.apply(j,$):k,J=c(Y.invert(V).concat(G/Y.k),W.invert(V).concat(G/W.k));return function(R){if(R===1)R=W;else{var D=J(R),F=G/D[2];R=new Te(F,V[0]-D[0]*F,V[1]-D[1]*F)}z.zoom(null,R)}})}function b(_,k,M){return!M&&_.__zooming||new C(_,k)}function C(_,k){this.that=_,this.args=k,this.active=0,this.sourceEvent=null,this.extent=t.apply(_,k),this.taps=0}C.prototype={event:function(_){return _&&(this.sourceEvent=_),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(_,k){return this.mouse&&_!=="mouse"&&(this.mouse[1]=k.invert(this.mouse[0])),this.touch0&&_!=="touch"&&(this.touch0[1]=k.invert(this.touch0[0])),this.touch1&&_!=="touch"&&(this.touch1[1]=k.invert(this.touch1[0])),this.that.__zoom=k,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(_){var k=ue(this.that).datum();l.call(_,this.that,new Xd(_,{sourceEvent:this.sourceEvent,target:x,transform:this.that.__zoom,dispatch:l}),k)}};function E(_,...k){if(!e.apply(this,arguments))return;var M=b(this,k).event(_),P=this.__zoom,j=Math.max(i[0],Math.min(i[1],P.k*Math.pow(2,o.apply(this,arguments)))),$=he(_);if(M.wheel)(M.mouse[0][0]!==$[0]||M.mouse[0][1]!==$[1])&&(M.mouse[1]=P.invert(M.mouse[0]=$)),clearTimeout(M.wheel);else{if(P.k===j)return;M.mouse=[$,P.invert($)],Zt(this),M.start()}ft(_),M.wheel=setTimeout(z,g),M.zoom("mouse",n(m(S(P,j),M.mouse[0],M.mouse[1]),M.extent,s));function z(){M.wheel=null,M.end()}}function A(_,...k){if(d||!e.apply(this,arguments))return;var M=_.currentTarget,P=b(this,k,!0).event(_),j=ue(_.view).on("mousemove.zoom",V,!0).on("mouseup.zoom",G,!0),$=he(_,M),z=_.clientX,O=_.clientY;di(_.view),Cn(_),P.mouse=[$,this.__zoom.invert($)],Zt(this),P.start();function V(Y){if(ft(Y),!P.moved){var W=Y.clientX-z,J=Y.clientY-O;P.moved=W*W+J*J>v}P.event(Y).zoom("mouse",n(m(P.that.__zoom,P.mouse[0]=he(Y,M),P.mouse[1]),P.extent,s))}function G(Y){j.on("mousemove.zoom mouseup.zoom",null),fi(Y.view,P.moved),ft(Y),P.event(Y).end()}}function B(_,...k){if(e.apply(this,arguments)){var M=this.__zoom,P=he(_.changedTouches?_.changedTouches[0]:_,this),j=M.invert(P),$=M.k*(_.shiftKey?.5:2),z=n(m(S(M,$),P,j),t.apply(this,k),s);ft(_),a>0?ue(this).transition().duration(a).call(I,z,P,_):ue(this).call(x.transform,z,P,_)}}function T(_,...k){if(e.apply(this,arguments)){var M=_.touches,P=M.length,j=b(this,k,_.changedTouches.length===P).event(_),$,z,O,V;for(Cn(_),z=0;z<P;++z)O=M[z],V=he(O,this),V=[V,this.__zoom.invert(V),O.identifier],j.touch0?!j.touch1&&j.touch0[2]!==V[2]&&(j.touch1=V,j.taps=0):(j.touch0=V,$=!0,j.taps=1+!!u);u&&(u=clearTimeout(u)),$&&(j.taps<2&&(f=V[0],u=setTimeout(function(){u=null},p)),Zt(this),j.start())}}function L(_,...k){if(this.__zooming){var M=b(this,k).event(_),P=_.changedTouches,j=P.length,$,z,O,V;for(ft(_),$=0;$<j;++$)z=P[$],O=he(z,this),M.touch0&&M.touch0[2]===z.identifier?M.touch0[0]=O:M.touch1&&M.touch1[2]===z.identifier&&(M.touch1[0]=O);if(z=M.that.__zoom,M.touch1){var G=M.touch0[0],Y=M.touch0[1],W=M.touch1[0],J=M.touch1[1],R=(R=W[0]-G[0])*R+(R=W[1]-G[1])*R,D=(D=J[0]-Y[0])*D+(D=J[1]-Y[1])*D;z=S(z,Math.sqrt(R/D)),O=[(G[0]+W[0])/2,(G[1]+W[1])/2],V=[(Y[0]+J[0])/2,(Y[1]+J[1])/2]}else if(M.touch0)O=M.touch0[0],V=M.touch0[1];else return;M.zoom("touch",n(m(z,O,V),M.extent,s))}}function H(_,...k){if(this.__zooming){var M=b(this,k).event(_),P=_.changedTouches,j=P.length,$,z;for(Cn(_),d&&clearTimeout(d),d=setTimeout(function(){d=null},p),$=0;$<j;++$)z=P[$],M.touch0&&M.touch0[2]===z.identifier?delete M.touch0:M.touch1&&M.touch1[2]===z.identifier&&delete M.touch1;if(M.touch1&&!M.touch0&&(M.touch0=M.touch1,delete M.touch1),M.touch0)M.touch0[1]=this.__zoom.invert(M.touch0[0]);else if(M.end(),M.taps===2&&(z=he(z,this),Math.hypot(f[0]-z[0],f[1]-z[1])<w)){var O=ue(this).on("dblclick.zoom");O&&O.apply(this,arguments)}}}return x.wheelDelta=function(_){return arguments.length?(o=typeof _=="function"?_:Ht(+_),x):o},x.filter=function(_){return arguments.length?(e=typeof _=="function"?_:Ht(!!_),x):e},x.touchable=function(_){return arguments.length?(r=typeof _=="function"?_:Ht(!!_),x):r},x.extent=function(_){return arguments.length?(t=typeof _=="function"?_:Ht([[+_[0][0],+_[0][1]],[+_[1][0],+_[1][1]]]),x):t},x.scaleExtent=function(_){return arguments.length?(i[0]=+_[0],i[1]=+_[1],x):[i[0],i[1]]},x.translateExtent=function(_){return arguments.length?(s[0][0]=+_[0][0],s[1][0]=+_[1][0],s[0][1]=+_[0][1],s[1][1]=+_[1][1],x):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},x.constrain=function(_){return arguments.length?(n=_,x):n},x.duration=function(_){return arguments.length?(a=+_,x):a},x.interpolate=function(_){return arguments.length?(c=_,x):c},x.on=function(){var _=l.on.apply(l,arguments);return _===l?x:_},x.clickDistance=function(_){return arguments.length?(v=(_=+_)*_,x):Math.sqrt(v)},x.tapDistance=function(_){return arguments.length?(w=+_,x):w},x}const ye={error001:(e="react")=>`Seems like you have not used ${e==="svelte"?"SvelteFlowProvider":"ReactFlowProvider"} as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:o})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:o}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.",error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},_t=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Mi=["Enter"," ","Escape"],Ti={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Ze;(function(e){e.Strict="strict",e.Loose="loose"})(Ze||(Ze={}));var Ye;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Ye||(Ye={}));var St;(function(e){e.Partial="partial",e.Full="full"})(St||(St={}));const Ai={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Re;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Re||(Re={}));var nn;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(nn||(nn={}));var X;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(X||(X={}));const Uo={[X.Left]:X.Right,[X.Right]:X.Left,[X.Top]:X.Bottom,[X.Bottom]:X.Top},Pi=e=>!!e&&typeof e=="object"&&"id"in e&&"source"in e&&"target"in e,Kd=e=>!!e&&typeof e=="object"&&"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),uo=e=>!!e&&typeof e=="object"&&"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Mt=(e,t=[0,0])=>{const{width:n,height:o}=we(e),r=e.origin??t,i=n*r[0],s=o*r[1];return{x:e.position.x-i,y:e.position.y-s}},Qd=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};let n=!1;const o=e.reduce((r,i)=>{const s=typeof i=="string";let a=!t.nodeLookup&&!s?i:void 0;return t.nodeLookup&&(a=s?t.nodeLookup.get(i):uo(i)?i:t.nodeLookup.get(i.id)),a?(n=!0,fn(r,on(a,t.nodeOrigin))):r},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return n?hn(o):{x:0,y:0,width:0,height:0}},Tt=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},o=!1;return e.forEach(r=>{(t.filter===void 0||t.filter(r))&&(n=fn(n,on(r)),o=!0)}),o?hn(n):{x:0,y:0,width:0,height:0}},fo=(e,t,[n,o,r]=[0,0,1],i=!1,s=!1)=>{const a=(t.x-n)/r,c=(t.y-o)/r,l=t.width/r,u=t.height/r,f=[];for(const d of e.values()){const{measured:p,selectable:g=!0,hidden:v=!1}=d;if(s&&!g||v)continue;const w=p.width??d.width??d.initialWidth??0,x=p.height??d.height??d.initialHeight??0,{x:S,y:m}=d.internals.positionAbsolute,y=Ri(a,c,l,u,S,m,w,x),I=w*x,b=i&&y>0;(!d.internals.handleBounds||b||y>=I||d.dragging)&&f.push(d)}return f},Jd=(e,t)=>{const n=new Set;return e.forEach(o=>{n.add(o.id)}),t.filter(o=>n.has(o.source)||n.has(o.target))};function ef(e,t){const n=new Map,o=t?.nodes?new Set(t.nodes.map(r=>r.id)):null;return e.forEach(r=>{let i;if(t?.includeHiddenNodes){const{width:s,height:a}=we(r);i=s>0&&a>0}else i=!!(r.measured.width&&r.measured.height&&!r.hidden);i&&(!o||o.has(r.id))&&n.set(r.id,r)}),n}async function tf({nodes:e,width:t,height:n,panZoom:o,minZoom:r,maxZoom:i},s){if(e.size===0)return!0;const a=ef(e,s),c=Tt(a),l=po(c,t,n,s?.minZoom??r,s?.maxZoom??i,s?.padding??.1);return await o.setViewport(l,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),!0}function Di({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:o=[0,0],nodeExtent:r,onError:i}){const s=n.get(e),a=s.parentId?n.get(s.parentId):void 0,{x:c,y:l}=a?a.internals.positionAbsolute:{x:0,y:0},u=s.origin??o;let f=s.extent||r;if(s.extent==="parent"&&!s.expandParent)if(!a)i?.("005",ye.error005());else{const{width:p,height:g}=we(a);p&&g&&(f=[[c,l],[c+p,l+g]])}else a&&Ue(s.extent)&&(f=[[s.extent[0][0]+c,s.extent[0][1]+l],[s.extent[1][0]+c,s.extent[1][1]+l]]);const d=Ue(f)?Ge(t,f,s.measured):t;return(s.measured.width===void 0||s.measured.height===void 0)&&i?.("015",ye.error015()),{position:{x:d.x-c+(s.measured.width??0)*u[0],y:d.y-l+(s.measured.height??0)*u[1]},positionAbsolute:d}}async function nf({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:o,onBeforeDelete:r}){const i=new Set(e.map(d=>d.id)),s=[];for(const d of n){if(d.deletable===!1)continue;const p=i.has(d.id),g=!p&&d.parentId&&s.find(v=>v.id===d.parentId);(p||g)&&s.push(d)}const a=new Set(t.map(d=>d.id)),c=o.filter(d=>d.deletable!==!1),u=Jd(s,c);for(const d of c)a.has(d.id)&&!u.find(g=>g.id===d.id)&&u.push(d);if(!r)return{edges:u,nodes:s};const f=await r({nodes:s,edges:u});return typeof f=="boolean"?f?{edges:u,nodes:s}:{edges:[],nodes:[]}:f}const at=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Ge=(e={x:0,y:0},t,n)=>({x:at(e.x,t[0][0],t[1][0]-(n?.width??0)),y:at(e.y,t[0][1],t[1][1]-(n?.height??0))});function ji(e,t,n){const{width:o,height:r}=we(n),{x:i,y:s}=n.internals.positionAbsolute;return Ge(e,[[i,s],[i+o,s+r]],t)}const qo=(e,t,n)=>e<t?at(Math.abs(e-t),1,t)/t:e>n?-at(Math.abs(e-n),1,t)/t:0,ho=(e,t,n=15,o=40)=>{const r=qo(e.x,o,t.width-o)*n,i=qo(e.y,o,t.height-o)*n;return[r,i]},fn=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Zn=({x:e,y:t,width:n,height:o})=>({x:e,y:t,x2:e+n,y2:t+o}),hn=({x:e,y:t,x2:n,y2:o})=>({x:e,y:t,width:n-e,height:o-t}),Et=(e,t=[0,0])=>{const{x:n,y:o}=uo(e)?e.internals.positionAbsolute:Mt(e,t);return{x:n,y:o,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},on=(e,t=[0,0])=>{const{x:n,y:o}=uo(e)?e.internals.positionAbsolute:Mt(e,t);return{x:n,y:o,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:o+(e.measured?.height??e.height??e.initialHeight??0)}},$i=(e,t)=>hn(fn(Zn(e),Zn(t))),Ri=(e,t,n,o,r,i,s,a)=>{const c=Math.max(0,Math.min(e+n,r+s)-Math.max(e,r)),l=Math.max(0,Math.min(t+o,i+a)-Math.max(t,i));return Math.ceil(c*l)},rn=(e,t)=>Ri(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),Ko=e=>ge(e.width)&&ge(e.height)&&ge(e.x)&&ge(e.y),ge=e=>!isNaN(e)&&isFinite(e),Hi=(e,t)=>(n,o)=>{},At=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Pt=({x:e,y:t},[n,o,r],i=!1,s=[1,1])=>{const a={x:(e-n)/r,y:(t-o)/r};return i?At(a,s):a},ct=({x:e,y:t},[n,o,r])=>({x:e*r+n,y:t*r+o});function Je(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function of(e,t,n){if(typeof e=="string"||typeof e=="number"){const o=Je(e,n),r=Je(e,t);return{top:o,right:r,bottom:o,left:r,x:r*2,y:o*2}}if(typeof e=="object"){const o=Je(e.top??e.y??0,n),r=Je(e.bottom??e.y??0,n),i=Je(e.left??e.x??0,t),s=Je(e.right??e.x??0,t);return{top:o,right:s,bottom:r,left:i,x:i+s,y:o+r}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function rf(e,t,n,o,r,i){const{x:s,y:a}=ct(e,[t,n,o]),{x:c,y:l}=ct({x:e.x+e.width,y:e.y+e.height},[t,n,o]),u=r-c,f=i-l;return{left:Math.floor(s),top:Math.floor(a),right:Math.floor(u),bottom:Math.floor(f)}}const po=(e,t,n,o,r,i)=>{const s=of(i,t,n),a=(t-s.x)/e.width,c=(n-s.y)/e.height,l=Math.min(a,c),u=at(l,o,r),f=e.x+e.width/2,d=e.y+e.height/2,p=t/2-f*u,g=n/2-d*u,v=rf(e,p,g,u,t,n),w={left:Math.min(v.left-s.left,0),top:Math.min(v.top-s.top,0),right:Math.min(v.right-s.right,0),bottom:Math.min(v.bottom-s.bottom,0)};return{x:p-w.left+w.right,y:g-w.top+w.bottom,zoom:u}},Nt=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Ue(e){return e!=null&&e!=="parent"}function we(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function Li(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function Oi(e,t={width:0,height:0},n,o,r){const i={...e},s=o.get(n);if(s){const a=s.origin||r;i.x+=s.internals.positionAbsolute.x-(t.width??0)*a[0],i.y+=s.internals.positionAbsolute.y-(t.height??0)*a[1]}return i}function Qo(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function sf(){let e,t;return{promise:new Promise((o,r)=>{e=o,t=r}),resolve:e,reject:t}}function af(e){return{...Ti,...e||{}}}function zi(e){return e===null?null:e?"valid":"invalid"}function yt(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:o,containerBounds:r}){const{x:i,y:s}=me(e),a=Pt({x:i-(r?.left??0),y:s-(r?.top??0)},o),{x:c,y:l}=n?At(a,t):a;return{xSnapped:c,ySnapped:l,...a}}const go=e=>({width:e.offsetWidth,height:e.offsetHeight}),Bi=e=>e?.getRootNode?.()||window?.document,cf=["INPUT","SELECT","TEXTAREA"];function Vi(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:cf.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const Fi=e=>"clientX"in e,me=(e,t)=>{const n=Fi(e),o=n?e.clientX:e.touches?.[0].clientX,r=n?e.clientY:e.touches?.[0].clientY;return{x:o-(t?.left??0),y:r-(t?.top??0)}},Jo=(e,t,n,o,r)=>{const i=t.querySelectorAll(`.${e}`);return!i||!i.length?null:Array.from(i).map(s=>{const a=s.getBoundingClientRect();return{id:s.getAttribute("data-handleid"),type:e,nodeId:r,position:s.getAttribute("data-handlepos"),x:(a.left-n.left)/o,y:(a.top-n.top)/o,...go(s)}})};function Yi({sourceX:e,sourceY:t,targetX:n,targetY:o,sourceControlX:r,sourceControlY:i,targetControlX:s,targetControlY:a}){const c=e*.125+r*.375+s*.375+n*.125,l=t*.125+i*.375+a*.375+o*.125,u=Math.abs(c-e),f=Math.abs(l-t);return[c,l,u,f]}function Lt(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function er({pos:e,x1:t,y1:n,x2:o,y2:r,c:i}){switch(e){case X.Left:return[t-Lt(t-o,i),n];case X.Right:return[t+Lt(o-t,i),n];case X.Top:return[t,n-Lt(n-r,i)];case X.Bottom:return[t,n+Lt(r-n,i)]}}function Xi({sourceX:e,sourceY:t,sourcePosition:n=X.Bottom,targetX:o,targetY:r,targetPosition:i=X.Top,curvature:s=.25}){const[a,c]=er({pos:n,x1:e,y1:t,x2:o,y2:r,c:s}),[l,u]=er({pos:i,x1:o,y1:r,x2:e,y2:t,c:s}),[f,d,p,g]=Yi({sourceX:e,sourceY:t,targetX:o,targetY:r,sourceControlX:a,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${a},${c} ${l},${u} ${o},${r}`,f,d,p,g]}function Wi({sourceX:e,sourceY:t,targetX:n,targetY:o}){const r=Math.abs(n-e)/2,i=n<e?n+r:n-r,s=Math.abs(o-t)/2,a=o<t?o+s:o-s;return[i,a,r,s]}function lf({sourceNode:e,targetNode:t,selected:n=!1,zIndex:o=0,elevateOnSelect:r=!1,zIndexMode:i="basic"}){if(i==="manual")return o;const s=r&&n?o+1e3:o,a=Math.max(e.parentId||r&&e.selected?e.internals.z:0,t.parentId||r&&t.selected?t.internals.z:0);return s+a}function uf({sourceNode:e,targetNode:t,width:n,height:o,transform:r}){const i=fn(on(e),on(t));i.x===i.x2&&(i.x2+=1),i.y===i.y2&&(i.y2+=1);const s={x:-r[0]/r[2],y:-r[1]/r[2],width:n/r[2],height:o/r[2]};return rn(s,hn(i))>0}const df=({source:e,sourceHandle:t,target:n,targetHandle:o})=>`xy-edge__${e}${t||""}-${n}${o||""}`,ff=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),hf=(e,t,n={})=>{if(!e.source||!e.target)return n.onError?.("006",ye.error006()),t;const o=n.getEdgeId||df;let r;return Pi(e)?r={...e}:r={...e,id:o(e)},ff(r,t)?t:(r.sourceHandle===null&&delete r.sourceHandle,r.targetHandle===null&&delete r.targetHandle,t.concat(r))};function Zi({sourceX:e,sourceY:t,targetX:n,targetY:o}){const[r,i,s,a]=Wi({sourceX:e,sourceY:t,targetX:n,targetY:o});return[`M ${e},${t}L ${n},${o}`,r,i,s,a]}const tr={[X.Left]:{x:-1,y:0},[X.Right]:{x:1,y:0},[X.Top]:{x:0,y:-1},[X.Bottom]:{x:0,y:1}},pf=({source:e,sourcePosition:t=X.Bottom,target:n})=>t===X.Left||t===X.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},nr=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function gf({source:e,sourcePosition:t=X.Bottom,target:n,targetPosition:o=X.Top,center:r,offset:i,stepPosition:s}){const a=tr[t],c=tr[o],l={x:e.x+a.x*i,y:e.y+a.y*i},u={x:n.x+c.x*i,y:n.y+c.y*i},f=pf({source:l,sourcePosition:t,target:u}),d=f.x!==0?"x":"y",p=f[d];let g=[],v,w;const x={x:0,y:0},S={x:0,y:0},[,,m,y]=Wi({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(a[d]*c[d]===-1){d==="x"?(v=r.x??l.x+(u.x-l.x)*s,w=r.y??(l.y+u.y)/2):(v=r.x??(l.x+u.x)/2,w=r.y??l.y+(u.y-l.y)*s);const E=[{x:v,y:l.y},{x:v,y:u.y}],A=[{x:l.x,y:w},{x:u.x,y:w}];a[d]===p?g=d==="x"?E:A:g=d==="x"?A:E}else{const E=[{x:l.x,y:u.y}],A=[{x:u.x,y:l.y}];if(d==="x"?g=a.x===p?A:E:g=a.y===p?E:A,t===o){const _=Math.abs(e[d]-n[d]);if(_<=i){const k=Math.min(i-1,i-_);a[d]===p?x[d]=(l[d]>e[d]?-1:1)*k:S[d]=(u[d]>n[d]?-1:1)*k}}if(t!==o){const _=d==="x"?"y":"x",k=a[d]===c[_],M=l[_]>u[_],P=l[_]<u[_];(a[d]===1&&(!k&&M||k&&P)||a[d]!==1&&(!k&&P||k&&M))&&(g=d==="x"?E:A)}const B={x:l.x+x.x,y:l.y+x.y},T={x:u.x+S.x,y:u.y+S.y},L=Math.max(Math.abs(B.x-g[0].x),Math.abs(T.x-g[0].x)),H=Math.max(Math.abs(B.y-g[0].y),Math.abs(T.y-g[0].y));L>=H?(v=(B.x+T.x)/2,w=g[0].y):(v=g[0].x,w=(B.y+T.y)/2)}const I={x:l.x+x.x,y:l.y+x.y},b={x:u.x+S.x,y:u.y+S.y};return[[e,...I.x!==g[0].x||I.y!==g[0].y?[I]:[],...g,...b.x!==g[g.length-1].x||b.y!==g[g.length-1].y?[b]:[],n],v,w,m,y]}function mf(e,t,n,o){const r=Math.min(nr(e,t)/2,nr(t,n)/2,o),{x:i,y:s}=t;if(e.x===i&&i===n.x||e.y===s&&s===n.y)return`L${i} ${s}`;if(e.y===s){const l=e.x<n.x?-1:1,u=e.y<n.y?1:-1;return`L ${i+r*l},${s}Q ${i},${s} ${i},${s+r*u}`}const a=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${i},${s+r*c}Q ${i},${s} ${i+r*a},${s}`}function Gn({sourceX:e,sourceY:t,sourcePosition:n=X.Bottom,targetX:o,targetY:r,targetPosition:i=X.Top,borderRadius:s=5,centerX:a,centerY:c,offset:l=20,stepPosition:u=.5}){const[f,d,p,g,v]=gf({source:{x:e,y:t},sourcePosition:n,target:{x:o,y:r},targetPosition:i,center:{x:a,y:c},offset:l,stepPosition:u});let w=`M${f[0].x} ${f[0].y}`;for(let x=1;x<f.length-1;x++)w+=mf(f[x-1],f[x],f[x+1],s);return w+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[w,d,p,g,v]}function or(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function yf(e){const{sourceNode:t,targetNode:n}=e;if(!or(t)||!or(n))return null;const o=t.internals.handleBounds||rr(t.handles),r=n.internals.handleBounds||rr(n.handles),i=ir(o?.source??[],e.sourceHandle),s=ir(e.connectionMode===Ze.Strict?r?.target??[]:(r?.target??[]).concat(r?.source??[]),e.targetHandle);if(!i||!s)return e.onError?.("008",ye.error008(i?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const a=i?.position||X.Bottom,c=s?.position||X.Top,l=qe(t,i,a),u=qe(n,s,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:a,targetPosition:c}}function rr(e){if(!e)return null;const t=[],n=[];for(const o of e)o.width=o.width??1,o.height=o.height??1,o.type==="source"?t.push(o):o.type==="target"&&n.push(o);return{source:t,target:n}}function qe(e,t,n=X.Left,o=!1){const r=(t?.x??0)+e.internals.positionAbsolute.x,i=(t?.y??0)+e.internals.positionAbsolute.y,{width:s,height:a}=t??we(e);if(o)return{x:r+s/2,y:i+a/2};switch(t?.position??n){case X.Top:return{x:r+s/2,y:i};case X.Right:return{x:r+s,y:i+a/2};case X.Bottom:return{x:r+s/2,y:i+a};case X.Left:return{x:r,y:i+a/2}}}function ir(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function Un(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`:""}function xf(e,{id:t,defaultColor:n,defaultMarkerStart:o,defaultMarkerEnd:r}){const i=new Set;return e.reduce((s,a)=>([a.markerStart||o,a.markerEnd||r].forEach(c=>{if(c&&typeof c=="object"){const l=Un(c,t);i.has(l)||(s.push({id:l,color:c.color||n,...c}),i.add(l))}}),s),[]).sort((s,a)=>s.id.localeCompare(a.id))}const Gi=1e3,wf=10,mo={nodeOrigin:[0,0],nodeExtent:_t,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},vf={...mo,checkEquality:!0};function yo(e,t){const n={...e};for(const o in t)t[o]!==void 0&&(n[o]=t[o]);return n}function bf(e,t,n){const o=yo(mo,n);for(const r of e.values())if(r.parentId)wo(r,e,t,o);else{const i=Mt(r,o.nodeOrigin),s=Ue(r.extent)?r.extent:o.nodeExtent,a=Ge(i,s,we(r));r.internals.positionAbsolute=a}}function _f(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],o=[];for(const r of e.handles){const i={id:r.id,width:r.width??1,height:r.height??1,nodeId:e.id,x:r.x,y:r.y,position:r.position,type:r.type};r.type==="source"?n.push(i):r.type==="target"&&o.push(i)}return{source:n,target:o}}function xo(e){return e==="manual"}function qn(e,t,n,o={}){const r=yo(vf,o),i={i:0},s=new Map(t),a=r?.elevateNodesOnSelect&&!xo(r.zIndexMode)?Gi:0;let c=e.length>0,l=!1;t.clear(),n.clear();for(const u of e){let f=s.get(u.id);if(r.checkEquality&&u===f?.internals.userNode)t.set(u.id,f);else{const d=Mt(u,r.nodeOrigin),p=Ue(u.extent)?u.extent:r.nodeExtent,g=Ge(d,p,we(u));f={...r.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:g,handleBounds:_f(u,f),z:Ui(u,a,r.zIndexMode),userNode:u}},t.set(u.id,f)}(f.measured===void 0||f.measured.width===void 0||f.measured.height===void 0)&&!f.hidden&&(c=!1),u.parentId&&wo(f,t,n,o,i),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function Sf(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function wo(e,t,n,o,r){const{elevateNodesOnSelect:i,nodeOrigin:s,nodeExtent:a,zIndexMode:c}=yo(mo,o),l=e.parentId,u=t.get(l);if(!u){console.warn(`Parent node ${l} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Sf(e,n),r&&!u.parentId&&u.internals.rootParentIndex===void 0&&c==="auto"&&(u.internals.rootParentIndex=++r.i,u.internals.z=u.internals.z+r.i*wf),r&&u.internals.rootParentIndex!==void 0&&(r.i=u.internals.rootParentIndex);const f=i&&!xo(c)?Gi:0,{x:d,y:p,z:g}=Ef(e,u,s,a,f,c),{positionAbsolute:v}=e.internals,w=d!==v.x||p!==v.y;(w||g!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:d,y:p}:v,z:g}})}function Ui(e,t,n){const o=ge(e.zIndex)?e.zIndex:0;return xo(n)?o:o+(e.selected?t:0)}function Ef(e,t,n,o,r,i){const{x:s,y:a}=t.internals.positionAbsolute,c=we(e),l=Mt(e,n),u=Ue(e.extent)?Ge(l,e.extent,c):l;let f=Ge({x:s+u.x,y:a+u.y},o,c);e.extent==="parent"&&(f=ji(f,c,t));const d=Ui(e,r,i),p=t.internals.z??0;return{x:f.x,y:f.y,z:p>=d?p+1:d}}function vo(e,t,n,o=[0,0]){const r=[],i=new Map;for(const s of e){const a=t.get(s.parentId);if(!a)continue;const c=i.get(s.parentId)?.expandedRect??Et(a),l=$i(c,s.rect);i.set(s.parentId,{expandedRect:l,parent:a})}return i.size>0&&i.forEach(({expandedRect:s,parent:a},c)=>{const l=a.internals.positionAbsolute,u=we(a),f=a.origin??o,d=s.x<l.x?Math.round(Math.abs(l.x-s.x)):0,p=s.y<l.y?Math.round(Math.abs(l.y-s.y)):0,g=Math.max(u.width,Math.round(s.width)),v=Math.max(u.height,Math.round(s.height)),w=(g-u.width)*f[0],x=(v-u.height)*f[1];(d>0||p>0||w||x)&&(r.push({id:c,type:"position",position:{x:a.position.x-d+w,y:a.position.y-p+x}}),n.get(c)?.forEach(S=>{e.some(m=>m.id===S.id)||r.push({id:S.id,type:"position",position:{x:S.position.x+d,y:S.position.y+p}})})),(u.width<s.width||u.height<s.height||d||p)&&r.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(d?f[0]*d-w:0),height:v+(p?f[1]*p-x:0)}})}),r}function Nf(e,t,n,o,r,i,s){const a=o?.querySelector(".xyflow__viewport");let c=!1;if(!a)return{changes:[],updatedInternals:c};const l=[],u=window.getComputedStyle(a),{m22:f}=new window.DOMMatrixReadOnly(u.transform),d=[];for(const p of e.values()){const g=t.get(p.id);if(!g)continue;if(g.hidden){t.set(g.id,{...g,internals:{...g.internals,handleBounds:void 0}}),c=!0;continue}const v=go(p.nodeElement),w=g.measured.width!==v.width||g.measured.height!==v.height;if(!!(v.width&&v.height&&(w||!g.internals.handleBounds||p.force))){const S=p.nodeElement.getBoundingClientRect(),m=Ue(g.extent)?g.extent:i;let{positionAbsolute:y}=g.internals;if(g.parentId&&g.extent==="parent"){const b=t.get(g.parentId);b&&(y=ji(y,v,b))}else m&&(y=Ge(y,m,v));const I={...g,measured:v,internals:{...g.internals,positionAbsolute:y,handleBounds:{source:Jo("source",p.nodeElement,S,f,g.id),target:Jo("target",p.nodeElement,S,f,g.id)}}};t.set(g.id,I),g.parentId&&wo(I,t,n,{nodeOrigin:r,zIndexMode:s}),c=!0,w&&(l.push({id:g.id,type:"dimensions",dimensions:v}),g.expandParent&&g.parentId&&d.push({id:g.id,parentId:g.parentId,rect:Et(I,r)}))}}if(d.length>0){const p=vo(d,t,n,r);l.push(...p)}return{changes:l,updatedInternals:c}}async function Cf({delta:e,panZoom:t,transform:n,translateExtent:o,width:r,height:i}){if(!t||!e.x&&!e.y)return!1;const s=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[r,i]],o);return!!s&&(s.x!==n[0]||s.y!==n[1]||s.k!==n[2])}function sr(e,t,n,o,r,i){let s=r;const a=o.get(s)||new Map;o.set(s,a.set(n,t)),s=`${r}-${e}`;const c=o.get(s)||new Map;if(o.set(s,c.set(n,t)),i){s=`${r}-${e}-${i}`;const l=o.get(s)||new Map;o.set(s,l.set(n,t))}}function qi(e,t,n){e.clear(),t.clear();for(const o of n){const{source:r,target:i,sourceHandle:s=null,targetHandle:a=null}=o,c={edgeId:o.id,source:r,target:i,sourceHandle:s,targetHandle:a},l=`${r}-${s}--${i}-${a}`,u=`${i}-${a}--${r}-${s}`;sr("source",c,u,e,r,s),sr("target",c,l,e,i,a),t.set(o.id,o)}}function Ki(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:Ki(n,t):!1}function ar(e,t,n){let o=e;do{if(o?.matches?.(t))return!0;if(o===n)return!1;o=o?.parentElement}while(o);return!1}function If(e,t,n,o){const r=new Map;for(const[i,s]of e)if((s.selected||s.id===o)&&(!s.parentId||!Ki(s,e))&&(s.draggable||t&&typeof s.draggable>"u")){const a=e.get(i);a&&r.set(i,{id:i,position:a.position||{x:0,y:0},distance:{x:n.x-a.internals.positionAbsolute.x,y:n.y-a.internals.positionAbsolute.y},extent:a.extent,parentId:a.parentId,origin:a.origin,expandParent:a.expandParent,internals:{positionAbsolute:a.internals.positionAbsolute||{x:0,y:0}},measured:{width:a.measured.width??0,height:a.measured.height??0}})}return r}function In({nodeId:e,dragItems:t,nodeLookup:n,dragging:o=!0}){const r=[];for(const[s,a]of t){const c=n.get(s)?.internals.userNode;c&&r.push({...c,position:a.position,dragging:o})}if(!e)return[r[0],r];const i=n.get(e)?.internals.userNode;return[i?{...i,position:t.get(e)?.position||i.position,dragging:o}:r[0],r]}function kf({dragItems:e,snapGrid:t,x:n,y:o}){const r=e.values().next().value;if(!r)return null;const i={x:n-r.distance.x,y:o-r.distance.y},s=At(i,t);return{x:s.x-i.x,y:s.y-i.y}}function Mf({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:o,onDragStop:r}){let i={x:null,y:null},s=0,a=new Map,c=!1,l={x:0,y:0},u=null,f=!1,d=null,p=!1,g=!1,v=null;function w({noDragClassName:S,handleSelector:m,domNode:y,isSelectable:I,nodeId:b,nodeClickDistance:C=0}){d=ue(y);function E({x:L,y:H}){const{nodeLookup:_,nodeExtent:k,snapGrid:M,snapToGrid:P,nodeOrigin:j,onNodeDrag:$,onSelectionDrag:z,onError:O,updateNodePositions:V}=t();i={x:L,y:H};let G=!1;const Y=a.size>1,W=Y&&k?Zn(Tt(a)):null,J=Y&&P?kf({dragItems:a,snapGrid:M,x:L,y:H}):null;for(const[R,D]of a){if(!_.has(R))continue;let F={x:L-D.distance.x,y:H-D.distance.y};P&&(F=J?{x:Math.round(F.x+J.x),y:Math.round(F.y+J.y)}:At(F,M));let U=null;if(Y&&k&&!D.extent&&W){const{positionAbsolute:q}=D.internals,ee=q.x-W.x+k[0][0],te=q.x+D.measured.width-W.x2+k[1][0],oe=q.y-W.y+k[0][1],ce=q.y+D.measured.height-W.y2+k[1][1];U=[[ee,oe],[te,ce]]}const{position:K,positionAbsolute:Z}=Di({nodeId:R,nextPosition:F,nodeLookup:_,nodeExtent:U||k,nodeOrigin:j,onError:O});G=G||D.position.x!==K.x||D.position.y!==K.y,D.position=K,D.internals.positionAbsolute=Z}if(g=g||G,!!G&&(V(a,!0),v&&(o||$||!b&&z))){const[R,D]=In({nodeId:b,dragItems:a,nodeLookup:_});o?.(v,a,R,D),$?.(v,R,D),b||z?.(v,D)}}async function A(){if(!u)return;const{transform:L,panBy:H,autoPanSpeed:_,autoPanOnNodeDrag:k}=t();if(!k){c=!1,cancelAnimationFrame(s);return}const[M,P]=ho(l,u,_);(M!==0||P!==0)&&(i.x=(i.x??0)-M/L[2],i.y=(i.y??0)-P/L[2],await H({x:M,y:P})&&E(i)),s=requestAnimationFrame(A)}function B(L){const{nodeLookup:H,multiSelectionActive:_,nodesDraggable:k,transform:M,snapGrid:P,snapToGrid:j,selectNodesOnDrag:$,onNodeDragStart:z,onSelectionDragStart:O,unselectNodesAndEdges:V}=t();f=!0,(!$||!I)&&!_&&b&&(H.get(b)?.selected||V()),I&&$&&b&&e?.(b);const G=yt(L.sourceEvent,{transform:M,snapGrid:P,snapToGrid:j,containerBounds:u});if(i=G,a=If(H,k,G,b),a.size>0&&(n||z||!b&&O)){const[Y,W]=In({nodeId:b,dragItems:a,nodeLookup:H});n?.(L.sourceEvent,a,Y,W),z?.(L.sourceEvent,Y,W),b||O?.(L.sourceEvent,W)}}const T=hi().clickDistance(C).on("start",L=>{const{domNode:H,nodeDragThreshold:_,transform:k,snapGrid:M,snapToGrid:P}=t();u=H?.getBoundingClientRect()||null,p=!1,g=!1,v=L.sourceEvent,_===0&&B(L),i=yt(L.sourceEvent,{transform:k,snapGrid:M,snapToGrid:P,containerBounds:u}),l=me(L.sourceEvent,u)}).on("drag",L=>{const{autoPanOnNodeDrag:H,transform:_,snapGrid:k,snapToGrid:M,nodeDragThreshold:P,nodeLookup:j}=t(),$=yt(L.sourceEvent,{transform:_,snapGrid:k,snapToGrid:M,containerBounds:u});if(v=L.sourceEvent,(L.sourceEvent.type==="touchmove"&&L.sourceEvent.touches.length>1||b&&!j.has(b))&&(p=!0),!p){if(!c&&H&&f&&(c=!0,A()),!f){const z=me(L.sourceEvent,u),O=z.x-l.x,V=z.y-l.y;Math.sqrt(O*O+V*V)>P&&B(L)}(i.x!==$.xSnapped||i.y!==$.ySnapped)&&a&&f&&(l=me(L.sourceEvent,u),E($))}}).on("end",L=>{if(!f||p){p&&a.size>0&&t().updateNodePositions(a,!1);return}if(c=!1,f=!1,cancelAnimationFrame(s),a.size>0){const{nodeLookup:H,updateNodePositions:_,onNodeDragStop:k,onSelectionDragStop:M}=t();if(g&&(_(a,!1),g=!1),r||k||!b&&M){const[P,j]=In({nodeId:b,dragItems:a,nodeLookup:H,dragging:!1});r?.(L.sourceEvent,a,P,j),k?.(L.sourceEvent,P,j),b||M?.(L.sourceEvent,j)}}}).filter(L=>{const H=L.target;return!L.button&&(!S||!ar(H,`.${S}`,y))&&(!m||ar(H,m,y))});d.call(T)}function x(){d?.on(".drag",null)}return{update:w,destroy:x}}function Tf(e,t,n){const o=[],r={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const i of t.values())rn(r,Et(i))>0&&o.push(i);return o}const Af=250;function Pf(e,t,n,o){let r=[],i=1/0;const s=Tf(e,n,t+Af);for(const a of s){const c=[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]];for(const l of c){if(o.nodeId===l.nodeId&&o.type===l.type&&o.id===l.id)continue;const{x:u,y:f}=qe(a,l,l.position,!0),d=Math.sqrt(Math.pow(u-e.x,2)+Math.pow(f-e.y,2));d>t||(d<i?(r=[{...l,x:u,y:f}],i=d):d===i&&r.push({...l,x:u,y:f}))}}if(!r.length)return null;if(r.length>1){const a=o.type==="source"?"target":"source";return r.find(c=>c.type===a)??r[0]}return r[0]}function Qi(e,t,n,o,r,i=!1){const s=o.get(e);if(!s)return null;const a=r==="strict"?s.internals.handleBounds?.[t]:[...s.internals.handleBounds?.source??[],...s.internals.handleBounds?.target??[]],c=(n?a?.find(l=>l.id===n):a?.[0])??null;return c&&i?{...c,...qe(s,c,c.position,!0)}:c}function Ji(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function Df(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const es=()=>!0;function jf(e,{connectionMode:t,connectionRadius:n,handleId:o,nodeId:r,edgeUpdaterType:i,isTarget:s,domNode:a,nodeLookup:c,lib:l,autoPanOnConnect:u,flowId:f,panBy:d,cancelConnection:p,onConnectStart:g,onConnect:v,onConnectEnd:w,isValidConnection:x=es,onReconnectEnd:S,updateConnection:m,getTransform:y,getFromHandle:I,autoPanSpeed:b,dragThreshold:C=1,handleDomNode:E}){const A=Bi(e.target);let B=0,T;const{x:L,y:H}=me(e),_=Ji(i,E),k=a?.getBoundingClientRect();let M=!1;if(!k||!_)return;const P=Qi(r,_,o,c,t);if(!P)return;let j=me(e,k),$=!1,z=null,O=!1,V=null;function G(){if(!u||!k)return;const[K,Z]=ho(j,k,b);d({x:K,y:Z}),B=requestAnimationFrame(G)}const Y={...P,nodeId:r,type:_,position:P.position},W=c.get(r);let R={inProgress:!0,isValid:null,from:qe(W,Y,X.Left,!0),fromHandle:Y,fromPosition:Y.position,fromNode:W,to:j,toHandle:null,toPosition:Uo[Y.position],toNode:null,pointer:j};function D(){M=!0,m(R),g?.(e,{nodeId:r,handleId:o,handleType:_})}C===0&&D();function F(K){if(!M){const{x:ce,y:Ne}=me(K),ve=ce-L,be=Ne-H;if(!(ve*ve+be*be>C*C))return;D()}if(!I()||!Y){U(K);return}const Z=y();j=me(K,k),T=Pf(Pt(j,Z,!1,[1,1]),n,c,Y),$||(G(),$=!0);const q=ts(K,{handle:T,connectionMode:t,fromNodeId:r,fromHandleId:o,fromType:s?"target":"source",isValidConnection:x,doc:A,lib:l,flowId:f,nodeLookup:c});V=q.handleDomNode,z=q.connection,O=Df(!!T,q.isValid);const ee=c.get(r),te=ee?qe(ee,Y,X.Left,!0):R.from,oe={...R,from:te,isValid:O,to:q.toHandle&&O?ct({x:q.toHandle.x,y:q.toHandle.y},Z):j,toHandle:q.toHandle,toPosition:O&&q.toHandle?q.toHandle.position:Uo[Y.position],toNode:q.toHandle?c.get(q.toHandle.nodeId):null,pointer:j};m(oe),R=oe}function U(K){if(!("touches"in K&&K.touches.length>0)){if(M){(T||V)&&z&&O&&v?.(z);const{inProgress:Z,...q}=R,ee={...q,toPosition:R.toHandle?R.toPosition:null};w?.(K,ee),i&&S?.(K,ee)}p(),cancelAnimationFrame(B),$=!1,O=!1,z=null,V=null,A.removeEventListener("mousemove",F),A.removeEventListener("mouseup",U),A.removeEventListener("touchmove",F),A.removeEventListener("touchend",U)}}A.addEventListener("mousemove",F),A.addEventListener("mouseup",U),A.addEventListener("touchmove",F),A.addEventListener("touchend",U)}function ts(e,{handle:t,connectionMode:n,fromNodeId:o,fromHandleId:r,fromType:i,doc:s,lib:a,flowId:c,isValidConnection:l=es,nodeLookup:u}){const f=i==="target",d=t?s.querySelector(`.${a}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:g}=me(e),v=s.elementFromPoint(p,g),w=v?.classList.contains(`${a}-flow__handle`)?v:d,x={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const S=Ji(void 0,w),m=w.getAttribute("data-nodeid"),y=w.getAttribute("data-handleid"),I=w.classList.contains("connectable"),b=w.classList.contains("connectableend");if(!m||!S)return x;const C={source:f?m:o,sourceHandle:f?y:r,target:f?o:m,targetHandle:f?r:y};x.connection=C;const A=I&&b&&(n===Ze.Strict?f&&S==="source"||!f&&S==="target":m!==o||y!==r);x.isValid=A&&l(C),x.toHandle=Qi(m,S,y,u,n,!0)}return x}const Kn={onPointerDown:jf,isValid:ts};function $f({domNode:e,panZoom:t,getTransform:n,getViewScale:o}){const r=ue(e);function i({translateExtent:a,width:c,height:l,zoomStep:u=1,pannable:f=!0,zoomable:d=!0,inversePan:p=!1}){const g=m=>{if(m.sourceEvent.type!=="wheel"||!t)return;const y=n(),I=m.sourceEvent.ctrlKey&&Nt()?10:1,b=-m.sourceEvent.deltaY*(m.sourceEvent.deltaMode===1?.05:m.sourceEvent.deltaMode?1:.002)*u,C=y[2]*Math.pow(2,b*I);t.scaleTo(C)};let v=[0,0];const w=m=>{(m.sourceEvent.type==="mousedown"||m.sourceEvent.type==="touchstart")&&(v=[m.sourceEvent.clientX??m.sourceEvent.touches[0].clientX,m.sourceEvent.clientY??m.sourceEvent.touches[0].clientY])},x=m=>{const y=n();if(m.sourceEvent.type!=="mousemove"&&m.sourceEvent.type!=="touchmove"||!t)return;const I=[m.sourceEvent.clientX??m.sourceEvent.touches[0].clientX,m.sourceEvent.clientY??m.sourceEvent.touches[0].clientY],b=[I[0]-v[0],I[1]-v[1]];v=I;const C=o()*Math.max(y[2],Math.log(y[2]))*(p?-1:1),E={x:y[0]-b[0]*C,y:y[1]-b[1]*C},A=[[0,0],[c,l]];t.setViewportConstrained({x:E.x,y:E.y,zoom:y[2]},A,a)},S=ki().on("start",w).on("zoom",f?x:null).on("zoom.wheel",d?g:null);r.call(S,{})}function s(){r.on("zoom",null)}return{update:i,destroy:s,pointer:he}}const pn=e=>({x:e.x,y:e.y,zoom:e.k}),kn=({x:e,y:t,zoom:n})=>dn.translate(e,t).scale(n),$e=(e,t)=>e.target.closest(`.${t}`),ns=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Rf=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Mn=(e,t=0,n=Rf,o=()=>{})=>{const r=typeof t=="number"&&t>0;return r||o(),r?e.transition().duration(t).ease(n).on("end",o):e},os=e=>{const t=e.ctrlKey&&Nt()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Hf({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:o,panOnScrollMode:r,panOnScrollSpeed:i,zoomOnPinch:s,onPanZoomStart:a,onPanZoom:c,onPanZoomEnd:l}){return u=>{if($e(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(u.ctrlKey&&s){const w=he(u),x=os(u),S=f*Math.pow(2,x);o.scaleTo(n,S,w,u);return}const d=u.deltaMode===1?20:1;let p=r===Ye.Vertical?0:u.deltaX*d,g=r===Ye.Horizontal?0:u.deltaY*d;!Nt()&&u.shiftKey&&r!==Ye.Vertical&&(p=u.deltaY*d,g=0),o.translateBy(n,-(p/f)*i,-(g/f)*i,{internal:!0});const v=pn(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?c?.(u,v):(e.isPanScrolling=!0,a?.(u,v)),e.panScrollTimeout=setTimeout(()=>{l?.(u,v),e.isPanScrolling=!1},150)}}function Lf({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(o,r){const i=o.type==="wheel",s=!t&&i&&!o.ctrlKey,a=$e(o,e);if(o.ctrlKey&&i&&a&&o.preventDefault(),s||a)return null;o.preventDefault(),n.call(this,o,r)}}function Of({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return o=>{if(o.sourceEvent?.internal)return;const r=pn(o.transform);e.mouseButton=o.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=r,o.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(o.sourceEvent,r)}}function zf({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:o,onPanZoom:r}){return i=>{e.usedRightMouseButton=!!(n&&ns(t,e.mouseButton??0)),i.sourceEvent?.sync||o([i.transform.x,i.transform.y,i.transform.k]),r&&!i.sourceEvent?.internal&&r?.(i.sourceEvent,pn(i.transform))}}function Bf({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:o,onPanZoomEnd:r,onPaneContextMenu:i}){return s=>{if(!s.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,i&&ns(t,e.mouseButton??0)&&!e.usedRightMouseButton&&s.sourceEvent&&i(s.sourceEvent),e.usedRightMouseButton=!1,o(!1),r)){const a=pn(s.transform);e.prevViewport=a,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{r?.(s.sourceEvent,a)},n?150:0)}}}function Vf({panActivationKeyPressed:e,zoomActivationKeyPressed:t,zoomOnScroll:n,zoomOnPinch:o,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:s,userSelectionActive:a,noWheelClassName:c,noPanClassName:l,lib:u,connectionInProgress:f}){return d=>{const p=t||n,g=o&&d.ctrlKey,v=d.type==="wheel";if(d.button===1&&d.type==="mousedown"&&($e(d,`${u}-flow__node`)||$e(d,`${u}-flow__edge`)||$e(d,`${u}-flow__selection`)||$e(d,`${u}-flow__nodesselection`)))return!0;if(!r&&!p&&!i&&!s&&!o||a||f&&!v||$e(d,c)&&v||$e(d,l)&&(!v||i&&v&&!t)||!o&&d.ctrlKey&&v)return!1;if(!o&&d.type==="touchstart"&&d.touches?.length>1)return d.preventDefault(),!1;if(!p&&!i&&!g&&v||!r&&(d.type==="mousedown"||d.type==="touchstart")||Array.isArray(r)&&!r.includes(d.button)&&d.type==="mousedown")return!1;const w=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||v||e)&&w}}function Ff({domNode:e,minZoom:t,maxZoom:n,translateExtent:o,viewport:r,onPanZoom:i,onPanZoomStart:s,onPanZoomEnd:a,onDraggingChange:c}){const l={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect();let f=[[0,0],[u.width,u.height]];(typeof ResizeObserver<"u"?new ResizeObserver(H=>{const _=H[0];_&&(f=[[0,0],[_.contentRect.width,_.contentRect.height]])}):null)?.observe(e);const p=ki().extent(()=>f).scaleExtent([t,n]).translateExtent(o),g=ue(e).call(p);y({x:r.x,y:r.y,zoom:at(r.zoom,t,n)},[[0,0],[u.width,u.height]],o);const v=g.on("wheel.zoom"),w=g.on("dblclick.zoom");p.wheelDelta(os);async function x(H,_){return g?new Promise(k=>{p?.interpolate(_?.interpolate==="linear"?mt:Yt).transform(Mn(g,_?.duration,_?.ease,()=>k(!0)),H)}):!1}function S({noWheelClassName:H,noPanClassName:_,onPaneContextMenu:k,userSelectionActive:M,panOnScroll:P,panOnDrag:j,panOnScrollMode:$,panOnScrollSpeed:z,preventScrolling:O,zoomOnPinch:V,zoomOnScroll:G,zoomOnDoubleClick:Y,panActivationKeyPressed:W=!1,zoomActivationKeyPressed:J,lib:R,onTransformChange:D,connectionInProgress:F,paneClickDistance:U,selectionOnDrag:K}){M&&!l.isZoomingOrPanning&&m();const Z=P&&!J&&!M;p.clickDistance(K?1/0:!ge(U)||U<0?0:U);const q=Z?Hf({zoomPanValues:l,noWheelClassName:H,d3Selection:g,d3Zoom:p,panOnScrollMode:$,panOnScrollSpeed:z,zoomOnPinch:V,onPanZoomStart:s,onPanZoom:i,onPanZoomEnd:a}):Lf({noWheelClassName:H,preventScrolling:O,d3ZoomHandler:v});g.on("wheel.zoom",q,{passive:!1});const ee=Of({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:s});p.on("start",ee);const te=zf({zoomPanValues:l,panOnDrag:j,onPaneContextMenu:!!k,onPanZoom:i,onTransformChange:D});p.on("zoom",te);const oe=Bf({zoomPanValues:l,panOnDrag:j,panOnScroll:P,onPaneContextMenu:k,onPanZoomEnd:a,onDraggingChange:c});p.on("end",oe);const ce=Vf({panActivationKeyPressed:W,zoomActivationKeyPressed:J,panOnDrag:j,zoomOnScroll:G,panOnScroll:P,zoomOnDoubleClick:Y,zoomOnPinch:V,userSelectionActive:M,noPanClassName:_,noWheelClassName:H,lib:R,connectionInProgress:F});p.filter(ce),Y?g.on("dblclick.zoom",w):g.on("dblclick.zoom",null)}function m(){p.on("zoom",null)}async function y(H,_,k){const M=kn(H),P=p?.constrain()(M,_,k);return P&&await x(P),P}async function I(H,_){const k=kn(H);return await x(k,_),k}function b(H){if(g){const _=kn(H),k=g.property("__zoom");(k.k!==H.zoom||k.x!==H.x||k.y!==H.y)&&p?.transform(g,_,null,{sync:!0})}}function C(){const H=g?Ii(g.node()):{x:0,y:0,k:1};return{x:H.x,y:H.y,zoom:H.k}}async function E(H,_){return g?new Promise(k=>{p?.interpolate(_?.interpolate==="linear"?mt:Yt).scaleTo(Mn(g,_?.duration,_?.ease,()=>k(!0)),H)}):!1}async function A(H,_){return g?new Promise(k=>{p?.interpolate(_?.interpolate==="linear"?mt:Yt).scaleBy(Mn(g,_?.duration,_?.ease,()=>k(!0)),H)}):!1}function B(H){p?.scaleExtent(H)}function T(H){p?.translateExtent(H)}function L(H){const _=!ge(H)||H<0?0:H;p?.clickDistance(_)}return{update:S,destroy:m,setViewport:I,setViewportConstrained:y,getViewport:C,scaleTo:E,scaleBy:A,setScaleExtent:B,setTranslateExtent:T,syncViewport:b,setClickDistance:L}}var lt;(function(e){e.Line="line",e.Handle="handle"})(lt||(lt={}));function Yf({width:e,prevWidth:t,height:n,prevHeight:o,affectsX:r,affectsY:i}){const s=e-t,a=n-o,c=[s>0?1:s<0?-1:0,a>0?1:a<0?-1:0];return s&&r&&(c[0]=c[0]*-1),a&&i&&(c[1]=c[1]*-1),c}function cr(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),o=e.includes("left"),r=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:o,affectsY:r}}function De(e,t){return Math.max(0,t-e)}function je(e,t){return Math.max(0,e-t)}function Ot(e,t,n){return Math.max(0,t-e,e-n)}function lr(e,t){return e?!t:t}function Xf(e,t,n,o,r,i,s,a){let{affectsX:c,affectsY:l}=t;const{isHorizontal:u,isVertical:f}=t,d=u&&f,{xSnapped:p,ySnapped:g}=n,{minWidth:v,maxWidth:w,minHeight:x,maxHeight:S}=o,{x:m,y,width:I,height:b,aspectRatio:C}=e;let E=Math.floor(u?p-e.pointerX:0),A=Math.floor(f?g-e.pointerY:0);const B=I+(c?-E:E),T=b+(l?-A:A),L=-i[0]*I,H=-i[1]*b;let _=Ot(B,v,w),k=Ot(T,x,S);if(s){let j=0,$=0;c&&E<0?j=De(m+E+L,s[0][0]):!c&&E>0&&(j=je(m+B+L,s[1][0])),l&&A<0?$=De(y+A+H,s[0][1]):!l&&A>0&&($=je(y+T+H,s[1][1])),_=Math.max(_,j),k=Math.max(k,$)}if(a){let j=0,$=0;c&&E>0?j=je(m+E,a[0][0]):!c&&E<0&&(j=De(m+B,a[1][0])),l&&A>0?$=je(y+A,a[0][1]):!l&&A<0&&($=De(y+T,a[1][1])),_=Math.max(_,j),k=Math.max(k,$)}if(r){if(u){const j=Ot(B/C,x,S)*C;if(_=Math.max(_,j),s){let $=0;!c&&!l||c&&!l&&d?$=je(y+H+B/C,s[1][1])*C:$=De(y+H+(c?E:-E)/C,s[0][1])*C,_=Math.max(_,$)}if(a){let $=0;!c&&!l||c&&!l&&d?$=De(y+B/C,a[1][1])*C:$=je(y+(c?E:-E)/C,a[0][1])*C,_=Math.max(_,$)}}if(f){const j=Ot(T*C,v,w)/C;if(k=Math.max(k,j),s){let $=0;!c&&!l||l&&!c&&d?$=je(m+T*C+L,s[1][0])/C:$=De(m+(l?A:-A)*C+L,s[0][0])/C,k=Math.max(k,$)}if(a){let $=0;!c&&!l||l&&!c&&d?$=De(m+T*C,a[1][0])/C:$=je(m+(l?A:-A)*C,a[0][0])/C,k=Math.max(k,$)}}}A=A+(A<0?k:-k),E=E+(E<0?_:-_),r&&(d?B>T*C?A=(lr(c,l)?-E:E)/C:E=(lr(c,l)?-A:A)*C:u?(A=E/C,l=c):(E=A*C,c=l));const M=c?m+E:m,P=l?y+A:y;return{width:I+(c?-E:E),height:b+(l?-A:A),x:i[0]*E*(c?-1:1)+M,y:i[1]*A*(l?-1:1)+P}}const rs={width:0,height:0,x:0,y:0},Wf={...rs,pointerX:0,pointerY:0,aspectRatio:1};function Zf(e,t,n){const o=t.position.x+e.position.x,r=t.position.y+e.position.y,i=e.measured.width??0,s=e.measured.height??0,a=n[0]*i,c=n[1]*s;return[[o-a,r-c],[o+i-a,r+s-c]]}function Gf({domNode:e,nodeId:t,getStoreItems:n,onChange:o,onEnd:r}){const i=ue(e);let s={controlDirection:cr("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function a({controlPosition:l,boundaries:u,keepAspectRatio:f,resizeDirection:d,onResizeStart:p,onResize:g,onResizeEnd:v,shouldResize:w}){let x={...rs},S={...Wf};s={boundaries:u,resizeDirection:d,keepAspectRatio:f,controlDirection:cr(l)};let m,y=null,I=[],b,C,E;const A=hi().on("start",B=>{const{nodeLookup:T,transform:L,snapGrid:H,snapToGrid:_,nodeOrigin:k,paneDomNode:M}=n();if(m=T.get(t),!m)return;y=M?.getBoundingClientRect()??null;const{xSnapped:P,ySnapped:j}=yt(B.sourceEvent,{transform:L,snapGrid:H,snapToGrid:_,containerBounds:y});x={width:m.measured.width??0,height:m.measured.height??0,x:m.position.x??0,y:m.position.y??0},S={...x,pointerX:P,pointerY:j,aspectRatio:x.width/x.height},b=void 0,C=Ue(m.extent)?m.extent:void 0,m.parentId&&(m.extent==="parent"||m.expandParent)&&(b=T.get(m.parentId)),b&&m.extent==="parent"&&(C=[[0,0],[b.measured.width,b.measured.height]]),I=[],E=void 0;for(const[$,z]of T)if(z.parentId===t&&(I.push({id:$,position:{...z.position},extent:z.extent}),z.extent==="parent"||z.expandParent)){const O=Zf(z,m,z.origin??k);E?E=[[Math.min(O[0][0],E[0][0]),Math.min(O[0][1],E[0][1])],[Math.max(O[1][0],E[1][0]),Math.max(O[1][1],E[1][1])]]:E=O}p?.(B,{...x})}).on("drag",B=>{const{transform:T,snapGrid:L,snapToGrid:H,nodeOrigin:_}=n(),k=yt(B.sourceEvent,{transform:T,snapGrid:L,snapToGrid:H,containerBounds:y}),M=[];if(!m)return;const{x:P,y:j,width:$,height:z}=x,O={},V=m.origin??_,{width:G,height:Y,x:W,y:J}=Xf(S,s.controlDirection,k,s.boundaries,s.keepAspectRatio,V,C,E),R=G!==$,D=Y!==z,F=W!==P&&R,U=J!==j&&D;if(!F&&!U&&!R&&!D)return;const K={prevValues:{...x},startX:S.x,startY:S.y,childNodes:I.map(te=>({...te,position:{...te.position}}))};if((F||U||V[0]===1||V[1]===1)&&(O.x=F?W:x.x,O.y=U?J:x.y,x.x=O.x,x.y=O.y,I.length>0)){const te=W-P,oe=J-j;for(const ce of I)ce.position={x:ce.position.x-te+V[0]*(G-$),y:ce.position.y-oe+V[1]*(Y-z)},M.push(ce)}if((R||D)&&(O.width=R&&(!s.resizeDirection||s.resizeDirection==="horizontal")?G:x.width,O.height=D&&(!s.resizeDirection||s.resizeDirection==="vertical")?Y:x.height,x.width=O.width,x.height=O.height),b&&m.expandParent){const te=V[0]*(O.width??0);O.x&&O.x<te&&(x.x=te,S.x=S.x-(O.x-te));const oe=V[1]*(O.height??0);O.y&&O.y<oe&&(x.y=oe,S.y=S.y-(O.y-oe))}const Z=Yf({width:x.width,prevWidth:$,height:x.height,prevHeight:z,affectsX:s.controlDirection.affectsX,affectsY:s.controlDirection.affectsY}),q={...x,direction:Z};if(w?.(B,q)===!1){x=K.prevValues,S.x=K.startX,S.y=K.startY,I.forEach((te,oe)=>{te.position=K.childNodes[oe].position});return}g?.(B,q),o(O,M)}).on("end",B=>{v?.(B,{...x}),r?.({...x})});i.call(A)}function c(){i.on(".drag",null)}return{update:a,destroy:c}}var Tn={exports:{}},An={},Pn={exports:{}},Dn={};var ur;function Uf(){if(ur)return Dn;ur=1;var e=Kr();function t(f,d){return f===d&&(f!==0||1/f===1/d)||f!==f&&d!==d}var n=typeof Object.is=="function"?Object.is:t,o=e.useState,r=e.useEffect,i=e.useLayoutEffect,s=e.useDebugValue;function a(f,d){var p=d(),g=o({inst:{value:p,getSnapshot:d}}),v=g[0].inst,w=g[1];return i(function(){v.value=p,v.getSnapshot=d,c(v)&&w({inst:v})},[f,p,d]),r(function(){return c(v)&&w({inst:v}),f(function(){c(v)&&w({inst:v})})},[f]),s(p),p}function c(f){var d=f.getSnapshot;f=f.value;try{var p=d();return!n(f,p)}catch{return!0}}function l(f,d){return d()}var u=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?l:a;return Dn.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:u,Dn}var dr;function qf(){return dr||(dr=1,Pn.exports=Uf()),Pn.exports}var fr;function Kf(){if(fr)return An;fr=1;var e=Kr(),t=qf();function n(l,u){return l===u&&(l!==0||1/l===1/u)||l!==l&&u!==u}var o=typeof Object.is=="function"?Object.is:n,r=t.useSyncExternalStore,i=e.useRef,s=e.useEffect,a=e.useMemo,c=e.useDebugValue;return An.useSyncExternalStoreWithSelector=function(l,u,f,d,p){var g=i(null);if(g.current===null){var v={hasValue:!1,value:null};g.current=v}else v=g.current;g=a(function(){function x(b){if(!S){if(S=!0,m=b,b=d(b),p!==void 0&&v.hasValue){var C=v.value;if(p(C,b))return y=C}return y=b}if(C=y,o(m,b))return C;var E=d(b);return p!==void 0&&p(C,E)?(m=b,C):(m=b,y=E)}var S=!1,m,y,I=f===void 0?null:f;return[function(){return x(u())},I===null?void 0:function(){return x(I())}]},[u,f,d,p]);var w=r(l,g[0],g[1]);return s(function(){v.hasValue=!0,v.value=w},[w]),c(w),w},An}var hr;function Qf(){return hr||(hr=1,Tn.exports=Kf()),Tn.exports}var Jf=Qf();const eh=Qa(Jf),th={},pr=e=>{let t;const n=new Set,o=(u,f)=>{const d=typeof u=="function"?u(t):u;if(!Object.is(d,t)){const p=t;t=f??(typeof d!="object"||d===null)?d:Object.assign({},t,d),n.forEach(g=>g(t,p))}},r=()=>t,c={setState:o,getState:r,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(th?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},l=t=e(o,r,c);return c},nh=e=>e?pr(e):pr,{useDebugValue:oh}=Ja,{useSyncExternalStoreWithSelector:rh}=eh,ih=e=>e;function is(e,t=ih,n){const o=rh(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return oh(o),o}const gr=(e,t)=>{const n=nh(e),o=(r,i=t)=>is(n,r,i);return Object.assign(o,n),o},sh=(e,t)=>e?gr(e,t):gr;function ie(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[o,r]of e)if(!Object.is(r,t.get(o)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const o of e)if(!t.has(o))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}const gn=N.createContext(null),ah=gn.Provider,ss=ye.error001("react");function ne(e,t){const n=N.useContext(gn);if(n===null)throw new Error(ss);return is(n,e,t)}function re(){const e=N.useContext(gn);if(e===null)throw new Error(ss);return N.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const mr={display:"none"},ch={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},as="react-flow__node-desc",cs="react-flow__edge-desc",lh="react-flow__aria-live",uh=e=>e.ariaLiveMessage,dh=e=>e.ariaLabelConfig;function fh({rfId:e}){const t=ne(uh);return h.jsx("div",{id:`${lh}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:ch,children:t})}function hh({rfId:e,disableKeyboardA11y:t}){const n=ne(dh);return h.jsxs(h.Fragment,{children:[h.jsx("div",{id:`${as}-${e}`,style:mr,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),h.jsx("div",{id:`${cs}-${e}`,style:mr,children:n["edge.a11yDescription.default"]}),!t&&h.jsx(fh,{rfId:e})]})}const Ke=N.forwardRef(({position:e="top-left",children:t,className:n,style:o,...r},i)=>{const s=`${e}`.split("-");return h.jsx("div",{className:se(["react-flow__panel",n,...s]),style:o,ref:i,...r,children:t})});Ke.displayName="Panel";const yr="https://reactflow.dev?utm_source=attribution";function ph({proOptions:e,position:t="bottom-right"}){return N.useEffect(()=>{},[]),e?.hideAttribution?null:h.jsx(Ke,{position:t,className:"react-flow__attribution","data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: ${yr}`,children:h.jsx("a",{href:yr,target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const gh=e=>{const t=[],n=[];for(const[,o]of e.nodeLookup)o.selected&&t.push(o.internals.userNode);for(const[,o]of e.edgeLookup)o.selected&&n.push(o);return{selectedNodes:t,selectedEdges:n}},zt=e=>e.id;function mh(e,t){return ie(e.selectedNodes.map(zt),t.selectedNodes.map(zt))&&ie(e.selectedEdges.map(zt),t.selectedEdges.map(zt))}function yh({onSelectionChange:e}){const t=re(),{selectedNodes:n,selectedEdges:o}=ne(gh,mh);return N.useEffect(()=>{const r={nodes:n,edges:o};e?.(r),t.getState().onSelectionChangeHandlers.forEach(i=>i(r))},[n,o,e]),null}const xh=e=>!!e.onSelectionChangeHandlers;function wh({onSelectionChange:e}){const t=ne(xh);return e||t?h.jsx(yh,{onSelectionChange:e}):null}const ls=[0,0],vh={x:0,y:0,zoom:1},bh=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],xr=[...bh,"rfId"],_h=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),wr={translateExtent:_t,nodeOrigin:ls,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function Sh(e){const{setNodes:t,setEdges:n,setMinZoom:o,setMaxZoom:r,setTranslateExtent:i,setNodeExtent:s,reset:a,setDefaultNodesAndEdges:c}=ne(_h,ie),l=re();N.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{u.current=wr,a()}),[]);const u=N.useRef(wr);return N.useEffect(()=>{for(const f of xr){const d=e[f],p=u.current[f];d!==p&&(typeof e[f]>"u"||(f==="nodes"?t(d):f==="edges"?n(d):f==="minZoom"?o(d):f==="maxZoom"?r(d):f==="translateExtent"?i(d):f==="nodeExtent"?s(d):f==="ariaLabelConfig"?l.setState({ariaLabelConfig:af(d)}):f==="fitView"?l.setState({fitViewQueued:d}):f==="fitViewOptions"?l.setState({fitViewOptions:d}):l.setState({[f]:d})))}u.current=e},xr.map(f=>e[f])),null}function vr(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Eh(e){const[t,n]=N.useState(e==="system"?null:e);return N.useEffect(()=>{if(e!=="system"){n(e);return}const o=vr(),r=()=>n(o?.matches?"dark":"light");return r(),o?.addEventListener("change",r),()=>{o?.removeEventListener("change",r)}},[e]),t!==null?t:vr()?.matches?"dark":"light"}const br=typeof document<"u"?document:null;function Ct(e=null,t={target:br,actInsideInputWithModifier:!0}){const[n,o]=N.useState(!1),r=N.useRef(!1),i=N.useRef(new Set([])),[s,a]=N.useMemo(()=>{if(e!==null){const l=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace(/\+/g,`
2
2
  `).replace(`
3
3
 
4
4
  `,`
5
5
  +`).split(`
6
- `)),u=l.reduce((f,d)=>f.concat(...d),[]);return[l,u]}return[[],[]]},[e]);return N.useEffect(()=>{const c=t?.target??br,l=t?.actInsideInputWithModifier??!0;if(e!==null){const u=p=>{if(r.current=p.ctrlKey||p.metaKey||p.shiftKey||p.altKey,(!r.current||r.current&&!l)&&Vi(p))return!1;const v=Sr(p.code,a);if(i.current.add(p[v]),_r(s,i.current,!1)){const w=p.composedPath?.()?.[0]||p.target,x=w?.nodeName==="BUTTON"||w?.nodeName==="A";t.preventDefault!==!1&&(r.current||!x)&&p.preventDefault(),o(!0)}},f=p=>{const g=Sr(p.code,a);_r(s,i.current,!0)?(o(!1),i.current.clear()):i.current.delete(p[g]),p.key==="Meta"&&i.current.clear(),r.current=!1},d=()=>{i.current.clear(),o(!1)};return c?.addEventListener("keydown",u),c?.addEventListener("keyup",f),window.addEventListener("blur",d),window.addEventListener("contextmenu",d),()=>{c?.removeEventListener("keydown",u),c?.removeEventListener("keyup",f),window.removeEventListener("blur",d),window.removeEventListener("contextmenu",d)}}},[e,o]),n}function _r(e,t,n){return e.filter(o=>n||o.length===t.size).some(o=>o.every(r=>t.has(r)))}function Sr(e,t){return t.includes(e)?"code":"key"}const Nh=()=>{const e=re();return N.useMemo(()=>({zoomIn:async t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):!1},zoomOut:async t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):!1},zoomTo:async(t,n)=>{const{panZoom:o}=e.getState();return o?o.scaleTo(t,n):!1},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[o,r,i],panZoom:s}=e.getState();return s?(await s.setViewport({x:t.x??o,y:t.y??r,zoom:t.zoom??i},n),!0):!1},getViewport:()=>{const[t,n,o]=e.getState().transform;return{x:t,y:n,zoom:o}},setCenter:async(t,n,o)=>e.getState().setCenter(t,n,o),fitBounds:async(t,n)=>{const{width:o,height:r,minZoom:i,maxZoom:s,panZoom:a}=e.getState(),c=po(t,o,r,i,s,n?.padding??.1);return a?(await a.setViewport(c,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0):!1},screenToFlowPosition:(t,n={})=>{const{transform:o,snapGrid:r,snapToGrid:i,domNode:s}=e.getState();if(!s)return t;const{x:a,y:c}=s.getBoundingClientRect(),l={x:t.x-a,y:t.y-c},u=n.snapGrid??r,f=n.snapToGrid??i;return Pt(l,o,f,u)},flowToScreenPosition:t=>{const{transform:n,domNode:o}=e.getState();if(!o)return t;const{x:r,y:i}=o.getBoundingClientRect(),s=ct(t,n);return{x:s.x+r,y:s.y+i}}}),[])};function us(e,t){const n=[],o=new Map,r=[];for(const i of e)if(i.type==="add"){r.push(i);continue}else if(i.type==="remove"||i.type==="replace")o.set(i.id,[i]);else{const s=o.get(i.id);s?s.push(i):o.set(i.id,[i])}for(const i of t){const s=o.get(i.id);if(!s){n.push(i);continue}if(s[0].type==="remove")continue;if(s[0].type==="replace"){n.push({...s[0].item});continue}const a={...i};for(const c of s)Ch(c,a);n.push(a)}return r.length&&r.forEach(i=>{i.index!==void 0?n.splice(i.index,0,{...i.item}):n.push({...i.item})}),n}function Ch(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function ds(e,t){return us(e,t)}function fs(e,t){return us(e,t)}function Be(e,t){return{id:e,type:"select",selected:t}}function et(e,t=new Set,n=!1){const o=[];for(const[r,i]of e){const s=t.has(r);!(i.selected===void 0&&!s)&&i.selected!==s&&(n&&(i.selected=s),o.push(Be(i.id,s)))}return o}function Er({items:e=[],lookup:t}){const n=[],o=new Map(e.map(r=>[r.id,r]));for(const[r,i]of e.entries()){const s=t.get(i.id),a=s?.internals?.userNode??s;a!==void 0&&a!==i&&n.push({id:i.id,item:i,type:"replace"}),a===void 0&&n.push({item:i,type:"add",index:r})}for(const[r]of t)o.get(r)===void 0&&n.push({id:r,type:"remove"});return n}function Nr(e){return{id:e.id,type:"remove"}}const Ih=Hi();function kh(e,t,n={}){return hf(e,t,{...n,onError:n.onError??Ih})}const Cr=e=>Kd(e),Mh=e=>Pi(e);function hs(e){return N.forwardRef(e)}const ps=typeof window<"u"?N.useLayoutEffect:N.useEffect;function Ir(e){const[t,n]=N.useState(BigInt(0)),[o]=N.useState(()=>Th(()=>n(r=>r+BigInt(1))));return ps(()=>{const r=o.get();r.length&&(e(r),o.reset())},[t]),o}function Th(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const gs=N.createContext(null);function Ah({children:e}){const t=re(),n=N.useCallback(a=>{const{nodes:c=[],setNodes:l,hasDefaultNodes:u,onNodesChange:f,nodeLookup:d,fitViewQueued:p,onNodesChangeMiddlewareMap:g}=t.getState();let v=c;for(const x of a)v=typeof x=="function"?x(v):x;let w=Er({items:v,lookup:d});for(const x of g.values())w=x(w);u&&l(v),w.length>0?f?.(w):p&&window.requestAnimationFrame(()=>{const{fitViewQueued:x,nodes:S,setNodes:m}=t.getState();x&&m(S)})},[]),o=Ir(n),r=N.useCallback(a=>{const{edges:c=[],setEdges:l,hasDefaultEdges:u,onEdgesChange:f,edgeLookup:d}=t.getState();let p=c;for(const g of a)p=typeof g=="function"?g(p):g;u?l(p):f&&f(Er({items:p,lookup:d}))},[]),i=Ir(r),s=N.useMemo(()=>({nodeQueue:o,edgeQueue:i}),[]);return h.jsx(gs.Provider,{value:s,children:e})}function Ph(){const e=N.useContext(gs);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Dh=e=>!!e.panZoom;function mn(){const e=Nh(),t=re(),n=Ph(),o=te(Dh),r=N.useMemo(()=>{const i=f=>t.getState().nodeLookup.get(f),s=f=>{n.nodeQueue.push(f)},a=f=>{n.edgeQueue.push(f)},c=f=>{const{nodeLookup:d,nodeOrigin:p}=t.getState(),g=Cr(f)?f:d.get(f.id),v=g.parentId?Oi(g.position,g.measured,g.parentId,d,p):g.position,w={...g,position:v,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return Et(w)},l=(f,d,p={replace:!1})=>{s(g=>g.map(v=>{if(v.id===f){const w=typeof d=="function"?d(v):d;return p.replace&&Cr(w)?w:{...v,...w}}return v}))},u=(f,d,p={replace:!1})=>{a(g=>g.map(v=>{if(v.id===f){const w=typeof d=="function"?d(v):d;return p.replace&&Mh(w)?w:{...v,...w}}return v}))};return{getNodes:()=>t.getState().nodes.map(f=>({...f})),getNode:f=>i(f)?.internals.userNode,getInternalNode:i,getEdges:()=>{const{edges:f=[]}=t.getState();return f.map(d=>({...d}))},getEdge:f=>t.getState().edgeLookup.get(f),setNodes:s,setEdges:a,addNodes:f=>{const d=Array.isArray(f)?f:[f];n.nodeQueue.push(p=>[...p,...d])},addEdges:f=>{const d=Array.isArray(f)?f:[f];n.edgeQueue.push(p=>[...p,...d])},toObject:()=>{const{nodes:f=[],edges:d=[],transform:p}=t.getState(),[g,v,w]=p;return{nodes:f.map(x=>({...x})),edges:d.map(x=>({...x})),viewport:{x:g,y:v,zoom:w}}},deleteElements:async({nodes:f=[],edges:d=[]})=>{const{nodes:p,edges:g,onNodesDelete:v,onEdgesDelete:w,triggerNodeChanges:x,triggerEdgeChanges:S,onDelete:m,onBeforeDelete:y}=t.getState(),{nodes:I,edges:b}=await nf({nodesToRemove:f,edgesToRemove:d,nodes:p,edges:g,onBeforeDelete:y}),C=b.length>0,E=I.length>0;if(C){const A=b.map(Nr);w?.(b),S(A)}if(E){const A=I.map(Nr);v?.(I),x(A)}return(E||C)&&m?.({nodes:I,edges:b}),{deletedNodes:I,deletedEdges:b}},getIntersectingNodes:(f,d=!0,p)=>{const g=Ko(f),v=g?f:c(f),w=p!==void 0;return v?(p||t.getState().nodes).filter(x=>{const S=t.getState().nodeLookup.get(x.id);if(S&&!g&&(x.id===f.id||!S.internals.positionAbsolute))return!1;const m=Et(w?x:S),y=rn(m,v);return d&&y>0||y>=m.width*m.height||y>=v.width*v.height}):[]},isNodeIntersecting:(f,d,p=!0)=>{const v=Ko(f)?f:c(f);if(!v)return!1;const w=rn(v,d);return p&&w>0||w>=d.width*d.height||w>=v.width*v.height},updateNode:l,updateNodeData:(f,d,p={replace:!1})=>{l(f,g=>{const v=typeof d=="function"?d(g):d;return p.replace?{...g,data:v}:{...g,data:{...g.data,...v}}},p)},updateEdge:u,updateEdgeData:(f,d,p={replace:!1})=>{u(f,g=>{const v=typeof d=="function"?d(g):d;return p.replace?{...g,data:v}:{...g,data:{...g.data,...v}}},p)},getNodesBounds:f=>{const{nodeLookup:d,nodeOrigin:p}=t.getState();return Qd(f,{nodeLookup:d,nodeOrigin:p})},getHandleConnections:({type:f,id:d,nodeId:p})=>Array.from(t.getState().connectionLookup.get(`${p}-${f}${d?`-${d}`:""}`)?.values()??[]),getNodeConnections:({type:f,handleId:d,nodeId:p})=>Array.from(t.getState().connectionLookup.get(`${p}${f?d?`-${f}-${d}`:`-${f}`:""}`)?.values()??[]),fitView:async f=>{const d=t.getState().fitViewResolver??sf();return t.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:d}),n.nodeQueue.push(p=>[...p]),d.promise}}},[]);return N.useMemo(()=>({...r,...e,viewportInitialized:o}),[o])}const kr=e=>e.selected,jh=typeof window<"u"?window:void 0;function $h({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=re(),{deleteElements:o}=mn(),r=Ct(e,{actInsideInputWithModifier:!1}),i=Ct(t,{target:jh});N.useEffect(()=>{if(r){const{edges:s,nodes:a}=n.getState();o({nodes:a.filter(kr),edges:s.filter(kr)}),n.setState({nodesSelectionActive:!1})}},[r]),N.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])}function Rh(e){const t=re();N.useEffect(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const o=go(e.current);(o.height===0||o.width===0)&&t.getState().onError?.("004",ye.error004()),t.setState({width:o.width||500,height:o.height||500})};if(e.current){n(),window.addEventListener("resize",n);const o=new ResizeObserver(()=>n());return o.observe(e.current),()=>{window.removeEventListener("resize",n),o&&e.current&&o.unobserve(e.current)}}},[])}const yn={position:"absolute",width:"100%",height:"100%",top:0,left:0},Hh=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function Lh({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:o=!1,panActivationKeyPressed:r,panOnScrollSpeed:i=.5,panOnScrollMode:s=Ye.Free,zoomOnDoubleClick:a=!0,panOnDrag:c=!0,defaultViewport:l,translateExtent:u,minZoom:f,maxZoom:d,zoomActivationKeyCode:p,preventScrolling:g=!0,children:v,noWheelClassName:w,noPanClassName:x,onViewportChange:S,isControlledViewport:m,paneClickDistance:y,selectionOnDrag:I}){const b=re(),C=N.useRef(null),{userSelectionActive:E,lib:A,connectionInProgress:B}=te(Hh,ie),T=Ct(p),L=N.useRef();Rh(C);const H=N.useCallback(_=>{S?.({x:_[0],y:_[1],zoom:_[2]}),m||b.setState({transform:_})},[S,m]);return N.useEffect(()=>{if(C.current){L.current=Ff({domNode:C.current,minZoom:f,maxZoom:d,translateExtent:u,viewport:l,onDraggingChange:P=>b.setState(j=>j.paneDragging===P?j:{paneDragging:P}),onPanZoomStart:(P,j)=>{const{onViewportChangeStart:$,onMoveStart:O}=b.getState();O?.(P,j),$?.(j)},onPanZoom:(P,j)=>{const{onViewportChange:$,onMove:O}=b.getState();O?.(P,j),$?.(j)},onPanZoomEnd:(P,j)=>{const{onViewportChangeEnd:$,onMoveEnd:O}=b.getState();O?.(P,j),$?.(j)}});const{x:_,y:k,zoom:M}=L.current.getViewport();return b.setState({panZoom:L.current,transform:[_,k,M],domNode:C.current.closest(".react-flow")}),()=>{L.current?.destroy()}}},[]),N.useEffect(()=>{L.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:o,panActivationKeyPressed:r,panOnScrollSpeed:i,panOnScrollMode:s,zoomOnDoubleClick:a,panOnDrag:c,zoomActivationKeyPressed:T,preventScrolling:g,noPanClassName:x,userSelectionActive:E,noWheelClassName:w,lib:A,onTransformChange:H,connectionInProgress:B,selectionOnDrag:I,paneClickDistance:y})},[e,t,n,o,r,i,s,a,c,T,g,x,E,w,A,H,B,I,y]),h.jsx("div",{className:"react-flow__renderer",ref:C,style:yn,children:v})}const Oh=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function zh(){const{userSelectionActive:e,userSelectionRect:t}=te(Oh,ie);return e&&t?h.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const jn=(e,t)=>n=>{n.target===t.current&&e?.(n)},Bh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function Vh({isSelecting:e,selectionKeyPressed:t,selectionMode:n=St.Full,panOnDrag:o,autoPanOnSelection:r,paneClickDistance:i,selectionOnDrag:s,onSelectionStart:a,onSelectionEnd:c,onPaneClick:l,onPaneContextMenu:u,onPaneScroll:f,onPaneMouseEnter:d,onPaneMouseMove:p,onPaneMouseLeave:g,children:v}){const w=N.useRef(0),x=re(),{userSelectionActive:S,elementsSelectable:m,dragging:y,panBy:I,autoPanSpeed:b}=te(Bh,ie),C=m&&(e||S),E=N.useRef(null),A=N.useRef(),B=N.useRef(new Set),T=N.useRef(new Set),L=N.useRef(!1),H=N.useRef(!1),_=N.useRef({x:0,y:0}),k=N.useRef(!1),M=D=>{if(H.current||L.current||x.getState().connection.inProgress){H.current=!1,L.current=!1;return}l?.(D),x.getState().resetSelectedElements(),x.setState({nodesSelectionActive:!1})},P=D=>{if(Array.isArray(o)&&o?.includes(2)){D.preventDefault();return}u?.(D)},j=f?D=>f(D):void 0,$=D=>{H.current&&(D.stopPropagation(),H.current=!1)},O=D=>{if(D.pointerType==="touch"&&o!==!1&&!t)return;const{domNode:F,transform:U}=x.getState();if(A.current=F?.getBoundingClientRect(),!A.current)return;const Q=D.target===E.current;if(!Q&&!!D.target.closest(".nokey")||!e||!(s&&Q||t)||D.button!==0||!D.isPrimary)return;D.target?.setPointerCapture?.(D.pointerId),H.current=!1;const{x:ee,y:ne}=me(D.nativeEvent,A.current),oe=Pt({x:ee,y:ne},U);x.setState({userSelectionRect:{width:0,height:0,startX:oe.x,startY:oe.y,x:ee,y:ne}}),Q||(D.stopPropagation(),D.preventDefault())};function V(D,F){const{userSelectionRect:U}=x.getState();if(!U)return;const{transform:Q,nodeLookup:G,edgeLookup:q,connectionLookup:ee,triggerNodeChanges:ne,triggerEdgeChanges:oe,defaultEdgeOptions:ce}=x.getState(),Ne={x:U.startX,y:U.startY},{x:ve,y:be}=ct(Ne,Q),Ce={startX:Ne.x,startY:Ne.y,x:D<ve?D:ve,y:F<be?F:be,width:Math.abs(D-ve),height:Math.abs(F-be)},ut=B.current,Le=T.current;B.current=new Set(fo(G,Ce,Q,n===St.Partial,!0).map(fe=>fe.id)),T.current=new Set;const Oe=ce?.selectable??!0;for(const fe of B.current){const Ie=ee.get(fe);if(Ie)for(const{edgeId:ke}of Ie.values()){const ze=q.get(ke);ze&&(ze.selectable??Oe)&&T.current.add(ke)}}if(!Qo(ut,B.current)){const fe=et(G,B.current,!0);ne(fe)}if(!Qo(Le,T.current)){const fe=et(q,T.current);oe(fe)}x.setState({userSelectionRect:Ce,userSelectionActive:!0,nodesSelectionActive:!1})}function z(){if(!r||!A.current)return;const[D,F]=ho(_.current,A.current,b);I({x:D,y:F}).then(U=>{if(!H.current||!U){w.current=requestAnimationFrame(z);return}const{x:Q,y:G}=_.current;V(Q,G),w.current=requestAnimationFrame(z)})}const W=()=>{cancelAnimationFrame(w.current),w.current=0,k.current=!1};N.useEffect(()=>()=>W(),[]);const Y=D=>{const{userSelectionRect:F,transform:U,resetSelectedElements:Q}=x.getState();if(!A.current||!F)return;const{x:G,y:q}=me(D.nativeEvent,A.current);_.current={x:G,y:q};const ee=ct({x:F.startX,y:F.startY},U);if(!H.current){const ne=t?0:i;if(Math.hypot(G-ee.x,q-ee.y)<=ne)return;Q(),a?.(D)}H.current=!0,k.current||(z(),k.current=!0),V(G,q)},Z=D=>{if(!C){D.target===E.current&&x.getState().connection.inProgress&&(L.current=!0);return}D.button===0&&(D.target?.releasePointerCapture?.(D.pointerId),!S&&D.target===E.current&&x.getState().userSelectionRect&&M?.(D),x.setState({userSelectionActive:!1,userSelectionRect:null}),H.current&&(c?.(D),x.setState({nodesSelectionActive:B.current.size>0})),W())},J=D=>{D.target?.releasePointerCapture?.(D.pointerId),W()},R=o===!0||Array.isArray(o)&&o.includes(0);return h.jsxs("div",{className:se(["react-flow__pane",{draggable:R,dragging:y,selection:e}]),onClick:C?void 0:jn(M,E),onContextMenu:jn(P,E),onWheel:jn(j,E),onPointerEnter:C?void 0:d,onPointerMove:C?Y:p,onPointerUp:Z,onPointerCancel:C?J:void 0,onPointerDownCapture:C?O:void 0,onClickCapture:C?$:void 0,onPointerLeave:g,ref:E,style:yn,children:[v,h.jsx(zh,{})]})}function Qn({id:e,store:t,unselect:n=!1,nodeRef:o}){const{addSelectedNodes:r,unselectNodesAndEdges:i,multiSelectionActive:s,nodeLookup:a,onError:c}=t.getState(),l=a.get(e);if(!l){c?.("012",ye.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&s)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>o?.current?.blur())):r([e])}function ms({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:o,nodeId:r,isSelectable:i,nodeClickDistance:s}){const a=re(),[c,l]=N.useState(!1),u=N.useRef();return N.useEffect(()=>{if(!t)return u.current=Mf({getStoreItems:()=>a.getState(),onNodeMouseDown:f=>{Qn({id:f,store:a,nodeRef:e})},onDragStart:()=>{l(!0)},onDragStop:()=>{l(!1)}}),()=>{u.current?.destroy(),u.current=void 0}},[t,a,e]),N.useEffect(()=>{t||!e.current||!u.current||u.current.update({noDragClassName:n,handleSelector:o,domNode:e.current,isSelectable:i,nodeId:r,nodeClickDistance:s})},[n,o,t,i,e,r,s]),c}const Fh=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function ys(){const e=re();return N.useCallback(n=>{const{nodeExtent:o,snapToGrid:r,snapGrid:i,nodesDraggable:s,onError:a,updateNodePositions:c,nodeLookup:l,nodeOrigin:u}=e.getState(),f=new Map,d=Fh(s),p=r?i[0]:5,g=r?i[1]:5,v=n.direction.x*p*n.factor,w=n.direction.y*g*n.factor;for(const[,x]of l){if(!d(x))continue;let S={x:x.internals.positionAbsolute.x+v,y:x.internals.positionAbsolute.y+w};r&&(S=At(S,i));const{position:m,positionAbsolute:y}=Di({nodeId:x.id,nextPosition:S,nodeLookup:l,nodeExtent:o,nodeOrigin:u,onError:a});x.position=m,x.internals.positionAbsolute=y,f.set(x.id,x)}c(f)},[])}const bo=N.createContext(null),Yh=bo.Provider;bo.Consumer;const xs=()=>N.useContext(bo),Xh=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),ws=N.createContext(null);function Wh({children:e}){const t=te(Xh,ie);return h.jsx(ws.Provider,{value:t,children:e})}function Zh(){const e=N.useContext(ws);if(!e)throw new Error("useHandleConfig must be used within a HandleConfigProvider");return e}const Gh={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},Uh=(e,t,n)=>o=>{const{connectionClickStartHandle:r,connectionMode:i,connection:s}=o,{fromHandle:a,toHandle:c,isValid:l}=s;if(!a&&!r)return Gh;const u=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:a?.nodeId===e&&a?.id===t&&a?.type===n,connectingTo:u,clickConnecting:r?.nodeId===e&&r?.id===t&&r?.type===n,isPossibleEndHandle:i===Ze.Strict?a?.type!==n:e!==a?.nodeId||t!==a?.id,connectionInProcess:!!a,clickConnectionInProcess:!!r,valid:u&&l}};function qh({type:e="source",position:t=X.Top,isValidConnection:n,isConnectable:o=!0,isConnectableStart:r=!0,isConnectableEnd:i=!0,id:s,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:f,...d},p){const g=s||null,v=e==="target",w=re(),x=xs(),{connectOnClick:S,noPanClassName:m,rfId:y}=Zh(),{connectingFrom:I,connectingTo:b,clickConnecting:C,isPossibleEndHandle:E,connectionInProcess:A,clickConnectionInProcess:B,valid:T}=te(Uh(x,g,e),ie);x||w.getState().onError?.("010",ye.error010());const L=k=>{const{defaultEdgeOptions:M,onConnect:P,hasDefaultEdges:j}=w.getState(),$={...M,...k};if(j){const{edges:O,setEdges:V,onError:z}=w.getState();V(kh($,O,{onError:z}))}P?.($),a?.($)},H=k=>{if(!x)return;const M=Fi(k.nativeEvent);if(r&&(M&&k.button===0||!M)){const P=w.getState();Kn.onPointerDown(k.nativeEvent,{handleDomNode:k.currentTarget,autoPanOnConnect:P.autoPanOnConnect,connectionMode:P.connectionMode,connectionRadius:P.connectionRadius,domNode:P.domNode,nodeLookup:P.nodeLookup,lib:P.lib,isTarget:v,handleId:g,nodeId:x,flowId:P.rfId,panBy:P.panBy,cancelConnection:P.cancelConnection,onConnectStart:P.onConnectStart,onConnectEnd:(...j)=>w.getState().onConnectEnd?.(...j),updateConnection:P.updateConnection,onConnect:L,isValidConnection:n||((...j)=>w.getState().isValidConnection?.(...j)??!0),getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,autoPanSpeed:P.autoPanSpeed,dragThreshold:P.connectionDragThreshold})}M?u?.(k):f?.(k)},_=k=>{const{onClickConnectStart:M,onClickConnectEnd:P,connectionClickStartHandle:j,connectionMode:$,isValidConnection:O,lib:V,rfId:z,nodeLookup:W,connection:Y}=w.getState();if(!x||!j&&!r)return;if(!j){M?.(k.nativeEvent,{nodeId:x,handleId:g,handleType:e}),w.setState({connectionClickStartHandle:{nodeId:x,type:e,id:g}});return}const Z=Bi(k.target),J=n||O,{connection:R,isValid:D}=Kn.isValid(k.nativeEvent,{handle:{nodeId:x,id:g,type:e},connectionMode:$,fromNodeId:j.nodeId,fromHandleId:j.id||null,fromType:j.type,isValidConnection:J,flowId:z,doc:Z,lib:V,nodeLookup:W});D&&R&&L(R);const F=structuredClone(Y);delete F.inProgress,F.toPosition=F.toHandle?F.toHandle.position:null,P?.(k,F),w.setState({connectionClickStartHandle:null})};return h.jsx("div",{"data-handleid":g,"data-nodeid":x,"data-handlepos":t,"data-id":`${y}-${x}-${g}-${e}`,className:se(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",m,l,{source:!v,target:v,connectable:o,connectablestart:r,connectableend:i,clickconnecting:C,connectingfrom:I,connectingto:b,valid:T,connectionindicator:o&&(!A||E)&&(A||B?i:r)}]),onMouseDown:H,onTouchStart:H,onClick:S?_:void 0,ref:p,...d,children:c})}const He=N.memo(hs(qh));function Kh({data:e,isConnectable:t,sourcePosition:n=X.Bottom}){return h.jsxs(h.Fragment,{children:[e?.label,h.jsx(He,{type:"source",position:n,isConnectable:t})]})}function Qh({data:e,isConnectable:t,targetPosition:n=X.Top,sourcePosition:o=X.Bottom}){return h.jsxs(h.Fragment,{children:[h.jsx(He,{type:"target",position:n,isConnectable:t}),e?.label,h.jsx(He,{type:"source",position:o,isConnectable:t})]})}function Jh(){return null}function ep({data:e,isConnectable:t,targetPosition:n=X.Top}){return h.jsxs(h.Fragment,{children:[h.jsx(He,{type:"target",position:n,isConnectable:t}),e?.label]})}const sn={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Mr={input:Kh,default:Qh,output:ep,group:Jh};function tp(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}const np=e=>{const{width:t,height:n,x:o,y:r}=Tt(e.nodeLookup,{filter:i=>!!i.selected});return{width:ge(t)?t:null,height:ge(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${o}px,${r}px)`}};function op({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const o=re(),{width:r,height:i,transformString:s,userSelectionActive:a}=te(np,ie),c=ys(),l=N.useRef(null);N.useEffect(()=>{n||l.current?.focus({preventScroll:!0})},[n]);const u=!a&&r!==null&&i!==null;if(ms({nodeRef:l,disabled:!u}),!u)return null;const f=e?p=>{const g=o.getState().nodes.filter(v=>v.selected);e(p,g)}:void 0,d=p=>{Object.prototype.hasOwnProperty.call(sn,p.key)&&(p.preventDefault(),c({direction:sn[p.key],factor:p.shiftKey?4:1}))};return h.jsx("div",{className:se(["react-flow__nodesselection","react-flow__container",t]),style:{transform:s},children:h.jsx("div",{ref:l,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:n?void 0:-1,onKeyDown:n?void 0:d,style:{width:r,height:i}})})}const Tr=typeof window<"u"?window:void 0,rp=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function vs({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:r,onPaneContextMenu:i,onPaneScroll:s,paneClickDistance:a,deleteKeyCode:c,selectionKeyCode:l,selectionOnDrag:u,selectionMode:f,onSelectionStart:d,onSelectionEnd:p,multiSelectionKeyCode:g,panActivationKeyCode:v,zoomActivationKeyCode:w,elementsSelectable:x,zoomOnScroll:S,zoomOnPinch:m,panOnScroll:y,panOnScrollSpeed:I,panOnScrollMode:b,zoomOnDoubleClick:C,panOnDrag:E,autoPanOnSelection:A,defaultViewport:B,translateExtent:T,minZoom:L,maxZoom:H,preventScrolling:_,onSelectionContextMenu:k,noWheelClassName:M,noPanClassName:P,disableKeyboardA11y:j,onViewportChange:$,isControlledViewport:O}){const{nodesSelectionActive:V,userSelectionActive:z}=te(rp,ie),W=Ct(l,{target:Tr}),Y=Ct(v,{target:Tr}),Z=Y||E,J=Y||y,R=u&&Z!==!0,D=W||z||R;return $h({deleteKeyCode:c,multiSelectionKeyCode:g}),h.jsx(Lh,{onPaneContextMenu:i,elementsSelectable:x,zoomOnScroll:S,zoomOnPinch:m,panOnScroll:J,panActivationKeyPressed:Y,panOnScrollSpeed:I,panOnScrollMode:b,zoomOnDoubleClick:C,panOnDrag:!W&&Z,defaultViewport:B,translateExtent:T,minZoom:L,maxZoom:H,zoomActivationKeyCode:w,preventScrolling:_,noWheelClassName:M,noPanClassName:P,onViewportChange:$,isControlledViewport:O,paneClickDistance:a,selectionOnDrag:R,children:h.jsxs(Vh,{onSelectionStart:d,onSelectionEnd:p,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:r,onPaneContextMenu:i,onPaneScroll:s,panOnDrag:Z,autoPanOnSelection:A,isSelecting:!!D,selectionMode:f,selectionKeyPressed:W,paneClickDistance:a,selectionOnDrag:R,children:[e,V&&h.jsx(op,{onSelectionContextMenu:k,noPanClassName:P,disableKeyboardA11y:j})]})})}vs.displayName="FlowRenderer";const ip=N.memo(vs),sp=e=>t=>e?fo(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function ap(e){return te(N.useCallback(sp(e),[e]),ie)}const cp=e=>e.updateNodeInternals;function lp(){const e=te(cp),[t]=N.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const o=new Map;n.forEach(r=>{const i=r.target.getAttribute("data-id");o.set(i,{id:i,nodeElement:r.target,force:!0})}),e(o)}));return N.useEffect(()=>()=>{t?.disconnect()},[t]),t}function up({node:e,nodeType:t,hasDimensions:n,resizeObserver:o}){const r=re(),i=N.useRef(null),s=N.useRef(null),a=N.useRef(e.sourcePosition),c=N.useRef(e.targetPosition),l=N.useRef(t),u=n&&!!e.internals.handleBounds;return N.useEffect(()=>{i.current&&!e.hidden&&(!u||s.current!==i.current)&&(s.current&&o?.unobserve(s.current),o?.observe(i.current),s.current=i.current)},[u,e.hidden]),N.useEffect(()=>()=>{s.current&&(o?.unobserve(s.current),s.current=null)},[]),N.useEffect(()=>{if(i.current){const f=l.current!==t,d=a.current!==e.sourcePosition,p=c.current!==e.targetPosition;(f||d||p)&&(l.current=t,a.current=e.sourcePosition,c.current=e.targetPosition,r.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:i.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),i}function dp({id:e,onClick:t,onMouseEnter:n,onMouseMove:o,onMouseLeave:r,onContextMenu:i,onDoubleClick:s,nodesDraggable:a,elementsSelectable:c,nodesConnectable:l,nodesFocusable:u,resizeObserver:f,noDragClassName:d,noPanClassName:p,disableKeyboardA11y:g,rfId:v,nodeTypes:w,nodeClickDistance:x,onError:S}){const{node:m,internals:y,isParent:I}=te(D=>{const F=D.nodeLookup.get(e),U=D.parentLookup.has(e);return{node:F,internals:F.internals,isParent:U}},ie);let b=m.type||"default",C=w?.[b]||Mr[b];C===void 0&&(S?.("003",ye.error003(b)),b="default",C=w?.default||Mr.default);const E=!!(m.draggable||a&&typeof m.draggable>"u"),A=!!(m.selectable||c&&typeof m.selectable>"u"),B=!!(m.connectable||l&&typeof m.connectable>"u"),T=!!(m.focusable||u&&typeof m.focusable>"u"),L=re(),H=Li(m),_=up({node:m,nodeType:b,hasDimensions:H,resizeObserver:f}),k=ms({nodeRef:_,disabled:m.hidden||!E,noDragClassName:d,handleSelector:m.dragHandle,nodeId:e,isSelectable:A,nodeClickDistance:x}),M=ys();if(m.hidden)return null;const P=we(m),j=tp(m),$=A||E||t||n||o||r,O=n?D=>n(D,{...y.userNode}):void 0,V=o?D=>o(D,{...y.userNode}):void 0,z=r?D=>r(D,{...y.userNode}):void 0,W=i?D=>i(D,{...y.userNode}):void 0,Y=s?D=>s(D,{...y.userNode}):void 0,Z=D=>{const{selectNodesOnDrag:F,nodeDragThreshold:U}=L.getState();A&&(!F||!E||U>0)&&Qn({id:e,store:L,nodeRef:_}),t&&t(D,{...y.userNode})},J=D=>{if(!(Vi(D.nativeEvent)||g)){if(Mi.includes(D.key)&&A){const F=D.key==="Escape";Qn({id:e,store:L,unselect:F,nodeRef:_})}else if(E&&m.selected&&Object.prototype.hasOwnProperty.call(sn,D.key)){D.preventDefault();const{ariaLabelConfig:F}=L.getState();L.setState({ariaLiveMessage:F["node.a11yDescription.ariaLiveMessage"]({direction:D.key.replace("Arrow","").toLowerCase(),x:~~y.positionAbsolute.x,y:~~y.positionAbsolute.y})}),M({direction:sn[D.key],factor:D.shiftKey?4:1})}}},R=()=>{if(g||!_.current?.matches(":focus-visible"))return;const{transform:D,width:F,height:U,autoPanOnNodeFocus:Q,setCenter:G}=L.getState();if(!Q)return;fo(new Map([[e,m]]),{x:0,y:0,width:F,height:U},D,!0).length>0||G(m.position.x+P.width/2,m.position.y+P.height/2,{zoom:D[2]})};return h.jsx("div",{className:se(["react-flow__node",`react-flow__node-${b}`,{[p]:E},m.className,{selected:m.selected,selectable:A,parent:I,draggable:E,dragging:k}]),ref:_,style:{zIndex:y.z,transform:`translate(${y.positionAbsolute.x}px,${y.positionAbsolute.y}px)`,pointerEvents:$?"all":"none",visibility:H?"visible":"hidden",...m.style,...j},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:O,onMouseMove:V,onMouseLeave:z,onContextMenu:W,onClick:Z,onDoubleClick:Y,onKeyDown:T?J:void 0,tabIndex:T?0:void 0,onFocus:T?R:void 0,role:m.ariaRole??(T?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${as}-${v}`,"aria-label":m.ariaLabel,...m.domAttributes,children:h.jsx(Yh,{value:e,children:h.jsx(C,{id:e,data:m.data,type:b,positionAbsoluteX:y.positionAbsolute.x,positionAbsoluteY:y.positionAbsolute.y,selected:m.selected??!1,selectable:A,draggable:E,deletable:m.deletable??!0,isConnectable:B,sourcePosition:m.sourcePosition,targetPosition:m.targetPosition,dragging:k,dragHandle:m.dragHandle,zIndex:y.z,parentId:m.parentId,...P})})})}var fp=N.memo(dp);const hp=e=>({nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function bs(e){const{nodesConnectable:t,nodesFocusable:n,elementsSelectable:o,onError:r}=te(hp,ie),i=ap(e.onlyRenderVisibleElements),s=lp();return h.jsx("div",{className:"react-flow__nodes",style:yn,children:i.map(a=>h.jsx(fp,{id:a,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:s,nodesDraggable:e.nodesDraggable??!0,nodesConnectable:t,nodesFocusable:n,elementsSelectable:o,nodeClickDistance:e.nodeClickDistance,onError:r},a))})}bs.displayName="NodeRenderer";const pp=N.memo(bs);function gp(e){return te(N.useCallback(n=>{if(!e)return n.edges.map(r=>r.id);const o=[];if(n.width&&n.height)for(const r of n.edges){const i=n.nodeLookup.get(r.source),s=n.nodeLookup.get(r.target);i&&s&&uf({sourceNode:i,targetNode:s,width:n.width,height:n.height,transform:n.transform})&&o.push(r.id)}return o},[e]),ie)}const mp=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return h.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},yp=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return h.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Ar={[nn.Arrow]:mp,[nn.ArrowClosed]:yp};function xp(e){const t=re();return N.useMemo(()=>Object.prototype.hasOwnProperty.call(Ar,e)?Ar[e]:(t.getState().onError?.("009",ye.error009(e)),null),[e])}const wp=({id:e,type:t,color:n,width:o=12.5,height:r=12.5,markerUnits:i="strokeWidth",strokeWidth:s,orient:a="auto-start-reverse"})=>{const c=xp(t);return c?h.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${o}`,markerHeight:`${r}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0",children:h.jsx(c,{color:n,strokeWidth:s})}):null},_s=({defaultColor:e,rfId:t})=>{const n=te(i=>i.edges),o=te(i=>i.defaultEdgeOptions),r=N.useMemo(()=>xf(n,{id:t,defaultColor:e,defaultMarkerStart:o?.markerStart,defaultMarkerEnd:o?.markerEnd}),[n,o,t,e]);return r.length?h.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:h.jsx("defs",{children:r.map(i=>h.jsx(wp,{id:i.id,type:i.type,color:i.color,width:i.width,height:i.height,markerUnits:i.markerUnits,strokeWidth:i.strokeWidth,orient:i.orient},i.id))})}):null};_s.displayName="MarkerDefinitions";var vp=N.memo(_s);function Ss({x:e,y:t,label:n,labelStyle:o,labelShowBg:r=!0,labelBgStyle:i,labelBgPadding:s=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u}){const[f,d]=N.useState({x:1,y:0,width:0,height:0}),p=se(["react-flow__edge-textwrapper",l]),g=N.useRef(null);return N.useEffect(()=>{if(g.current){const v=g.current.getBBox();d({x:v.x,y:v.y,width:v.width,height:v.height})}},[n]),n?h.jsxs("g",{transform:`translate(${e-f.width/2} ${t-f.height/2})`,className:p,visibility:f.width?"visible":"hidden",...u,children:[r&&h.jsx("rect",{width:f.width+2*s[0],x:-s[0],y:-s[1],height:f.height+2*s[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),h.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:g,style:o,children:n}),c]}):null}Ss.displayName="EdgeText";const bp=N.memo(Ss);function xn({path:e,labelX:t,labelY:n,label:o,labelStyle:r,labelShowBg:i,labelBgStyle:s,labelBgPadding:a,labelBgBorderRadius:c,interactionWidth:l=20,...u}){return h.jsxs(h.Fragment,{children:[h.jsx("path",{...u,d:e,fill:"none",className:se(["react-flow__edge-path",u.className])}),l?h.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:l,className:"react-flow__edge-interaction"}):null,o&&ge(t)&&ge(n)?h.jsx(bp,{x:t,y:n,label:o,labelStyle:r,labelShowBg:i,labelBgStyle:s,labelBgPadding:a,labelBgBorderRadius:c}):null]})}function Pr({pos:e,x1:t,y1:n,x2:o,y2:r}){return e===X.Left||e===X.Right?[.5*(t+o),n]:[t,.5*(n+r)]}function Es({sourceX:e,sourceY:t,sourcePosition:n=X.Bottom,targetX:o,targetY:r,targetPosition:i=X.Top}){const[s,a]=Pr({pos:n,x1:e,y1:t,x2:o,y2:r}),[c,l]=Pr({pos:i,x1:o,y1:r,x2:e,y2:t}),[u,f,d,p]=Yi({sourceX:e,sourceY:t,targetX:o,targetY:r,sourceControlX:s,sourceControlY:a,targetControlX:c,targetControlY:l});return[`M${e},${t} C${s},${a} ${c},${l} ${o},${r}`,u,f,d,p]}function Ns(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:i,sourcePosition:s,targetPosition:a,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:f,labelBgPadding:d,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,interactionWidth:x})=>{const[S,m,y]=Es({sourceX:n,sourceY:o,sourcePosition:s,targetX:r,targetY:i,targetPosition:a}),I=e.isInternal?void 0:t;return h.jsx(xn,{id:I,path:S,labelX:m,labelY:y,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:f,labelBgPadding:d,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,interactionWidth:x})})}const _p=Ns({isInternal:!1}),Cs=Ns({isInternal:!0});_p.displayName="SimpleBezierEdge";Cs.displayName="SimpleBezierEdgeInternal";function Is(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:i,label:s,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:f,style:d,sourcePosition:p=X.Bottom,targetPosition:g=X.Top,markerEnd:v,markerStart:w,pathOptions:x,interactionWidth:S})=>{const[m,y,I]=Gn({sourceX:n,sourceY:o,sourcePosition:p,targetX:r,targetY:i,targetPosition:g,borderRadius:x?.borderRadius,offset:x?.offset,stepPosition:x?.stepPosition}),b=e.isInternal?void 0:t;return h.jsx(xn,{id:b,path:m,labelX:y,labelY:I,label:s,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:f,style:d,markerEnd:v,markerStart:w,interactionWidth:S})})}const ks=Is({isInternal:!1}),Ms=Is({isInternal:!0});ks.displayName="SmoothStepEdge";Ms.displayName="SmoothStepEdgeInternal";function Ts(e){return N.memo(({id:t,...n})=>{const o=e.isInternal?void 0:t;return h.jsx(ks,{...n,id:o,pathOptions:N.useMemo(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const Sp=Ts({isInternal:!1}),As=Ts({isInternal:!0});Sp.displayName="StepEdge";As.displayName="StepEdgeInternal";function Ps(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:i,label:s,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:f,style:d,markerEnd:p,markerStart:g,interactionWidth:v})=>{const[w,x,S]=Zi({sourceX:n,sourceY:o,targetX:r,targetY:i}),m=e.isInternal?void 0:t;return h.jsx(xn,{id:m,path:w,labelX:x,labelY:S,label:s,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:f,style:d,markerEnd:p,markerStart:g,interactionWidth:v})})}const Ep=Ps({isInternal:!1}),Ds=Ps({isInternal:!0});Ep.displayName="StraightEdge";Ds.displayName="StraightEdgeInternal";function js(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:i,sourcePosition:s=X.Bottom,targetPosition:a=X.Top,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:f,labelBgPadding:d,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,pathOptions:x,interactionWidth:S})=>{const[m,y,I]=Xi({sourceX:n,sourceY:o,sourcePosition:s,targetX:r,targetY:i,targetPosition:a,curvature:x?.curvature}),b=e.isInternal?void 0:t;return h.jsx(xn,{id:b,path:m,labelX:y,labelY:I,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:f,labelBgPadding:d,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,interactionWidth:S})})}const Np=js({isInternal:!1}),$s=js({isInternal:!0});Np.displayName="BezierEdge";$s.displayName="BezierEdgeInternal";const Dr={default:$s,straight:Ds,step:As,smoothstep:Ms,simplebezier:Cs},jr={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},Cp=(e,t,n)=>n===X.Left?e-t:n===X.Right?e+t:e,Ip=(e,t,n)=>n===X.Top?e-t:n===X.Bottom?e+t:e,$r="react-flow__edgeupdater";function Rr({position:e,centerX:t,centerY:n,radius:o=10,onMouseDown:r,onMouseEnter:i,onMouseOut:s,type:a}){return h.jsx("circle",{onMouseDown:r,onMouseEnter:i,onMouseOut:s,className:se([$r,`${$r}-${a}`]),cx:Cp(t,o,e),cy:Ip(n,o,e),r:o,stroke:"transparent",fill:"transparent"})}function kp({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:o,sourceY:r,targetX:i,targetY:s,sourcePosition:a,targetPosition:c,onReconnect:l,onReconnectStart:u,onReconnectEnd:f,setReconnecting:d,setUpdateHover:p}){const g=re(),v=(y,I)=>{if(y.button!==0)return;const{autoPanOnConnect:b,domNode:C,connectionMode:E,connectionRadius:A,lib:B,onConnectStart:T,cancelConnection:L,nodeLookup:H,rfId:_,panBy:k,updateConnection:M}=g.getState(),P=I.type==="target",j=(V,z)=>{d(!1),f?.(V,n,I.type,z)},$=V=>l?.(n,V),O=(V,z)=>{d(!0),u?.(y,n,I.type),T?.(V,z)};Kn.onPointerDown(y.nativeEvent,{autoPanOnConnect:b,connectionMode:E,connectionRadius:A,domNode:C,handleId:I.id,nodeId:I.nodeId,nodeLookup:H,isTarget:P,edgeUpdaterType:I.type,lib:B,flowId:_,cancelConnection:L,panBy:k,isValidConnection:(...V)=>g.getState().isValidConnection?.(...V)??!0,onConnect:$,onConnectStart:O,onConnectEnd:(...V)=>g.getState().onConnectEnd?.(...V),onReconnectEnd:j,updateConnection:M,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:y.currentTarget})},w=y=>v(y,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),x=y=>v(y,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),S=()=>p(!0),m=()=>p(!1);return h.jsxs(h.Fragment,{children:[(e===!0||e==="source")&&h.jsx(Rr,{position:a,centerX:o,centerY:r,radius:t,onMouseDown:w,onMouseEnter:S,onMouseOut:m,type:"source"}),(e===!0||e==="target")&&h.jsx(Rr,{position:c,centerX:i,centerY:s,radius:t,onMouseDown:x,onMouseEnter:S,onMouseOut:m,type:"target"})]})}function Mp({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:o,onClick:r,onDoubleClick:i,onContextMenu:s,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,reconnectRadius:u,onReconnect:f,onReconnectStart:d,onReconnectEnd:p,rfId:g,edgeTypes:v,noPanClassName:w,onError:x,disableKeyboardA11y:S}){let m=te(G=>G.edgeLookup.get(e));const y=te(G=>G.defaultEdgeOptions);m=y?{...y,...m}:m;let I=m.type||"default",b=v?.[I]||Dr[I];b===void 0&&(x?.("011",ye.error011(I)),I="default",b=v?.default||Dr.default);const C=!!(m.focusable||t&&typeof m.focusable>"u"),E=typeof f<"u"&&(m.reconnectable||n&&typeof m.reconnectable>"u"),A=!!(m.selectable||o&&typeof m.selectable>"u"),B=N.useRef(null),[T,L]=N.useState(!1),[H,_]=N.useState(!1),k=re(),{zIndex:M=m.zIndex,sourceX:P,sourceY:j,targetX:$,targetY:O,sourcePosition:V,targetPosition:z}=te(N.useCallback(G=>{const q=G.nodeLookup.get(m.source),ee=G.nodeLookup.get(m.target);if(!q||!ee)return jr;const ne=yf({id:e,sourceNode:q,targetNode:ee,sourceHandle:m.sourceHandle||null,targetHandle:m.targetHandle||null,connectionMode:G.connectionMode,onError:x}),oe=lf({selected:m.selected,zIndex:m.zIndex,sourceNode:q,targetNode:ee,elevateOnSelect:G.elevateEdgesOnSelect,zIndexMode:G.zIndexMode});return{...ne||jr,zIndex:oe}},[m.source,m.target,m.sourceHandle,m.targetHandle,m.selected,m.zIndex,x]),ie),W=N.useMemo(()=>m.markerStart?`url('#${Un(m.markerStart,g)}')`:void 0,[m.markerStart,g]),Y=N.useMemo(()=>m.markerEnd?`url('#${Un(m.markerEnd,g)}')`:void 0,[m.markerEnd,g]);if(m.hidden||P===null||j===null||$===null||O===null)return null;const Z=G=>{const{addSelectedEdges:q,unselectNodesAndEdges:ee,multiSelectionActive:ne}=k.getState();A&&(k.setState({nodesSelectionActive:!1}),m.selected&&ne?(ee({nodes:[],edges:[m]}),B.current?.blur()):q([e])),r&&r(G,m)},J=i?G=>{i(G,{...m})}:void 0,R=s?G=>{s(G,{...m})}:void 0,D=a?G=>{a(G,{...m})}:void 0,F=c?G=>{c(G,{...m})}:void 0,U=l?G=>{l(G,{...m})}:void 0,Q=G=>{if(!S&&Mi.includes(G.key)&&A){const{unselectNodesAndEdges:q,addSelectedEdges:ee}=k.getState();G.key==="Escape"?(B.current?.blur(),q({edges:[m]})):ee([e])}};return h.jsx("svg",{style:{zIndex:M},children:h.jsxs("g",{className:se(["react-flow__edge",`react-flow__edge-${I}`,m.className,w,{selected:m.selected,animated:m.animated,inactive:!A&&!r,updating:T,selectable:A}]),onClick:Z,onDoubleClick:J,onContextMenu:R,onMouseEnter:D,onMouseMove:F,onMouseLeave:U,onKeyDown:C?Q:void 0,tabIndex:C?0:void 0,role:m.ariaRole??(C?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":m.ariaLabel===null?void 0:m.ariaLabel||`Edge from ${m.source} to ${m.target}`,"aria-describedby":C?`${cs}-${g}`:void 0,ref:B,...m.domAttributes,children:[!H&&h.jsx(b,{id:e,source:m.source,target:m.target,type:m.type,selected:m.selected,animated:m.animated,selectable:A,deletable:m.deletable??!0,label:m.label,labelStyle:m.labelStyle,labelShowBg:m.labelShowBg,labelBgStyle:m.labelBgStyle,labelBgPadding:m.labelBgPadding,labelBgBorderRadius:m.labelBgBorderRadius,sourceX:P,sourceY:j,targetX:$,targetY:O,sourcePosition:V,targetPosition:z,data:m.data,style:m.style,sourceHandleId:m.sourceHandle,targetHandleId:m.targetHandle,markerStart:W,markerEnd:Y,pathOptions:"pathOptions"in m?m.pathOptions:void 0,interactionWidth:m.interactionWidth}),E&&h.jsx(kp,{edge:m,isReconnectable:E,reconnectRadius:u,onReconnect:f,onReconnectStart:d,onReconnectEnd:p,sourceX:P,sourceY:j,targetX:$,targetY:O,sourcePosition:V,targetPosition:z,setUpdateHover:L,setReconnecting:_})]})})}var Tp=N.memo(Mp);const Ap=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Rs({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:o,noPanClassName:r,onReconnect:i,onEdgeContextMenu:s,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,reconnectRadius:f,onEdgeDoubleClick:d,onReconnectStart:p,onReconnectEnd:g,disableKeyboardA11y:v}){const{edgesFocusable:w,edgesReconnectable:x,elementsSelectable:S,onError:m}=te(Ap,ie),y=gp(t);return h.jsxs("div",{className:"react-flow__edges",children:[h.jsx(vp,{defaultColor:e,rfId:n}),y.map(I=>h.jsx(Tp,{id:I,edgesFocusable:w,edgesReconnectable:x,elementsSelectable:S,noPanClassName:r,onReconnect:i,onContextMenu:s,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,reconnectRadius:f,onDoubleClick:d,onReconnectStart:p,onReconnectEnd:g,rfId:n,onError:m,edgeTypes:o,disableKeyboardA11y:v},I))]})}Rs.displayName="EdgeRenderer";const Pp=N.memo(Rs),Hr=e=>`translate(${e[0]}px,${e[1]}px) scale(${e[2]})`;function Dp({children:e}){const t=re(),n=N.useRef(null),[o]=N.useState(()=>t.getState().transform);return ps(()=>{let r=null;const i=()=>{const s=t.getState().transform;r&&s[0]===r[0]&&s[1]===r[1]&&s[2]===r[2]||(r=s,n.current&&(n.current.style.transform=Hr(s)))};return i(),t.subscribe(i)},[t]),h.jsx("div",{ref:n,className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:Hr(o)},children:e})}function jp(e){const t=mn(),n=N.useRef(!1);N.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const $p=e=>e.panZoom?.syncViewport;function Rp(e){const t=te($p),n=re();return N.useEffect(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function Hp(e){return e.connection.inProgress?{...e.connection,to:Pt(e.connection.to,e.transform)}:{...e.connection}}function Lp(e){return Hp}function Op(e){const t=Lp();return te(t,ie)}const zp=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function Bp({containerStyle:e,style:t,type:n,component:o}){const{nodesConnectable:r,width:i,height:s,isValid:a,inProgress:c}=te(zp,ie);return!(i&&r&&c)?null:h.jsx("svg",{style:e,width:i,height:s,className:"react-flow__connectionline react-flow__container",children:h.jsx("g",{className:se(["react-flow__connection",zi(a)]),children:h.jsx(Hs,{style:t,type:n,CustomComponent:o,isValid:a})})})}const Hs=({style:e,type:t=Re.Bezier,CustomComponent:n,isValid:o})=>{const{inProgress:r,from:i,fromNode:s,fromHandle:a,fromPosition:c,to:l,toNode:u,toHandle:f,toPosition:d,pointer:p}=Op();if(!r)return;if(n)return h.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:s,fromHandle:a,fromX:i.x,fromY:i.y,toX:l.x,toY:l.y,fromPosition:c,toPosition:d,connectionStatus:zi(o),toNode:u,toHandle:f,pointer:p});let g="";const v={sourceX:i.x,sourceY:i.y,sourcePosition:c,targetX:l.x,targetY:l.y,targetPosition:d};switch(t){case Re.Bezier:[g]=Xi(v);break;case Re.SimpleBezier:[g]=Es(v);break;case Re.Step:[g]=Gn({...v,borderRadius:0});break;case Re.SmoothStep:[g]=Gn(v);break;default:[g]=Zi(v)}return h.jsx("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};Hs.displayName="ConnectionLine";const Vp={};function Lr(e=Vp){N.useRef(e),re(),N.useEffect(()=>{},[e])}function Fp(){re(),N.useRef(!1),N.useEffect(()=>{},[])}function Ls({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:o,onEdgeClick:r,onNodeDoubleClick:i,onEdgeDoubleClick:s,onNodeMouseEnter:a,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,onSelectionContextMenu:f,onSelectionStart:d,onSelectionEnd:p,connectionLineType:g,connectionLineStyle:v,connectionLineComponent:w,connectionLineContainerStyle:x,selectionKeyCode:S,selectionOnDrag:m,selectionMode:y,multiSelectionKeyCode:I,panActivationKeyCode:b,zoomActivationKeyCode:C,deleteKeyCode:E,onlyRenderVisibleElements:A,elementsSelectable:B,defaultViewport:T,translateExtent:L,minZoom:H,maxZoom:_,preventScrolling:k,defaultMarkerColor:M,zoomOnScroll:P,zoomOnPinch:j,panOnScroll:$,panOnScrollSpeed:O,panOnScrollMode:V,zoomOnDoubleClick:z,panOnDrag:W,autoPanOnSelection:Y,onPaneClick:Z,onPaneMouseEnter:J,onPaneMouseMove:R,onPaneMouseLeave:D,onPaneScroll:F,onPaneContextMenu:U,paneClickDistance:Q,nodeClickDistance:G,onEdgeContextMenu:q,onEdgeMouseEnter:ee,onEdgeMouseMove:ne,onEdgeMouseLeave:oe,reconnectRadius:ce,onReconnect:Ne,onReconnectStart:ve,onReconnectEnd:be,noDragClassName:Ce,noWheelClassName:ut,noPanClassName:Le,disableKeyboardA11y:Oe,nodeExtent:fe,rfId:Ie,viewport:ke,onViewportChange:ze,nodesDraggable:vn}){return Lr(e),Lr(t),Fp(),jp(n),Rp(ke),h.jsx(ip,{onPaneClick:Z,onPaneMouseEnter:J,onPaneMouseMove:R,onPaneMouseLeave:D,onPaneContextMenu:U,onPaneScroll:F,paneClickDistance:Q,deleteKeyCode:E,selectionKeyCode:S,selectionOnDrag:m,selectionMode:y,onSelectionStart:d,onSelectionEnd:p,multiSelectionKeyCode:I,panActivationKeyCode:b,zoomActivationKeyCode:C,elementsSelectable:B,zoomOnScroll:P,zoomOnPinch:j,zoomOnDoubleClick:z,panOnScroll:$,panOnScrollSpeed:O,panOnScrollMode:V,panOnDrag:W,autoPanOnSelection:Y,defaultViewport:T,translateExtent:L,minZoom:H,maxZoom:_,onSelectionContextMenu:f,preventScrolling:k,noDragClassName:Ce,noWheelClassName:ut,noPanClassName:Le,disableKeyboardA11y:Oe,onViewportChange:ze,isControlledViewport:!!ke,children:h.jsxs(Dp,{children:[h.jsx(Pp,{edgeTypes:t,onEdgeClick:r,onEdgeDoubleClick:s,onReconnect:Ne,onReconnectStart:ve,onReconnectEnd:be,onlyRenderVisibleElements:A,onEdgeContextMenu:q,onEdgeMouseEnter:ee,onEdgeMouseMove:ne,onEdgeMouseLeave:oe,reconnectRadius:ce,defaultMarkerColor:M,noPanClassName:Le,disableKeyboardA11y:Oe,rfId:Ie}),h.jsx(Bp,{style:v,type:g,component:w,containerStyle:x}),h.jsx("div",{className:"react-flow__edgelabel-renderer"}),h.jsx(pp,{nodeTypes:e,onNodeClick:o,onNodeDoubleClick:i,onNodeMouseEnter:a,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,nodeClickDistance:G,onlyRenderVisibleElements:A,noPanClassName:Le,noDragClassName:Ce,disableKeyboardA11y:Oe,nodeExtent:fe,rfId:Ie,nodesDraggable:vn}),h.jsx("div",{className:"react-flow__viewport-portal"})]})})}Ls.displayName="GraphView";const Yp=N.memo(Ls),Xp=Hi(),Or=({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:r,height:i,fitView:s,fitViewOptions:a,minZoom:c=.5,maxZoom:l=2,nodeOrigin:u,nodeExtent:f,zIndexMode:d="basic"}={})=>{const p=new Map,g=new Map,v=new Map,w=new Map,x=o??t??[],S=n??e??[],m=u??[0,0],y=f??_t;qi(v,w,x);const{nodesInitialized:I}=qn(S,p,g,{nodeOrigin:m,nodeExtent:y,zIndexMode:d});let b=[0,0,1];if(s&&r&&i){const C=Tt(p,{filter:T=>!!((T.width||T.initialWidth)&&(T.height||T.initialHeight))}),{x:E,y:A,zoom:B}=po(C,r,i,c,l,a?.padding??.1);b=[E,A,B]}return{rfId:"1",width:r??0,height:i??0,transform:b,nodes:S,nodesInitialized:I,nodeLookup:p,parentLookup:g,edges:x,edgeLookup:w,connectionLookup:v,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:o!==void 0,panZoom:null,minZoom:c,maxZoom:l,translateExtent:_t,nodeExtent:y,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Ze.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:m,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:s??!1,fitViewOptions:a,fitViewResolver:null,connection:{...Ai},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Xp,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Ti,zIndexMode:d,defaultEdgeOptions:void 0,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map,onNodesDelete:void 0,onEdgesDelete:void 0,onDelete:void 0,onBeforeDelete:void 0,onViewportChangeStart:void 0,onViewportChange:void 0,onViewportChangeEnd:void 0,onNodeDragStart:void 0,onNodeDrag:void 0,onNodeDragStop:void 0,onSelectionDragStart:void 0,onSelectionDrag:void 0,onSelectionDragStop:void 0,onMoveStart:void 0,onMove:void 0,onMoveEnd:void 0,onConnect:void 0,onConnectStart:void 0,onConnectEnd:void 0,onClickConnectStart:void 0,onClickConnectEnd:void 0}},Wp=({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:r,height:i,fitView:s,fitViewOptions:a,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:f,zIndexMode:d})=>sh((p,g)=>{async function v(){const{nodeLookup:w,panZoom:x,fitViewOptions:S,fitViewResolver:m,width:y,height:I,minZoom:b,maxZoom:C}=g();x&&(await tf({nodes:w,width:y,height:I,panZoom:x,minZoom:b,maxZoom:C},S),m?.resolve(!0),p({fitViewResolver:null}))}return{...Or({nodes:e,edges:t,width:r,height:i,fitView:s,fitViewOptions:a,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:f,defaultNodes:n,defaultEdges:o,zIndexMode:d}),setNodes:w=>{const{nodeLookup:x,parentLookup:S,nodeOrigin:m,nodeExtent:y,elevateNodesOnSelect:I,fitViewQueued:b,zIndexMode:C,nodesSelectionActive:E}=g(),{nodesInitialized:A,hasSelectedNodes:B}=qn(w,x,S,{nodeOrigin:m,nodeExtent:y,elevateNodesOnSelect:I,checkEquality:!0,zIndexMode:C}),T=E&&B;b&&A?(v(),p({nodes:w,nodesInitialized:A,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:T})):p({nodes:w,nodesInitialized:A,nodesSelectionActive:T})},setEdges:w=>{const{connectionLookup:x,edgeLookup:S}=g();qi(x,S,w),p({edges:w})},setDefaultNodesAndEdges:(w,x)=>{if(w){const{setNodes:S}=g();S(w),p({hasDefaultNodes:!0})}if(x){const{setEdges:S}=g();S(x),p({hasDefaultEdges:!0})}},updateNodeInternals:w=>{const{triggerNodeChanges:x,nodeLookup:S,parentLookup:m,domNode:y,nodeOrigin:I,nodeExtent:b,debug:C,fitViewQueued:E,zIndexMode:A}=g(),{changes:B,updatedInternals:T}=Nf(w,S,m,y,I,b,A);T&&(bf(S,m,{nodeOrigin:I,nodeExtent:b,zIndexMode:A}),E?(v(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),B?.length>0&&(C&&console.log("React Flow: trigger node changes",B),x?.(B)))},updateNodePositions:(w,x=!1)=>{const S=[];let m=[];const{nodeLookup:y,triggerNodeChanges:I,connection:b,updateConnection:C,onNodesChangeMiddlewareMap:E}=g();for(const[A,B]of w){const T=y.get(A),L=!!(T?.expandParent&&T?.parentId&&B?.position),H={id:A,type:"position",position:L?{x:Math.max(0,B.position.x),y:Math.max(0,B.position.y)}:B.position,dragging:x};if(T&&b.inProgress&&b.fromNode.id===T.id){const _=qe(T,b.fromHandle,X.Left,!0);C({...b,from:_})}L&&T.parentId&&S.push({id:A,parentId:T.parentId,rect:{...B.internals.positionAbsolute,width:B.measured.width??0,height:B.measured.height??0}}),m.push(H)}if(S.length>0){const{parentLookup:A,nodeOrigin:B}=g(),T=vo(S,y,A,B);m.push(...T)}for(const A of E.values())m=A(m);I(m)},triggerNodeChanges:w=>{const{onNodesChange:x,setNodes:S,nodes:m,hasDefaultNodes:y,debug:I}=g();if(w?.length){if(y){const b=ds(w,m);S(b)}I&&console.log("React Flow: trigger node changes",w),x?.(w)}},triggerEdgeChanges:w=>{const{onEdgesChange:x,setEdges:S,edges:m,hasDefaultEdges:y,debug:I}=g();if(w?.length){if(y){const b=fs(w,m);S(b)}I&&console.log("React Flow: trigger edge changes",w),x?.(w)}},addSelectedNodes:w=>{const{multiSelectionActive:x,edgeLookup:S,nodeLookup:m,triggerNodeChanges:y,triggerEdgeChanges:I}=g();if(x){const b=w.map(C=>Be(C,!0));y(b);return}y(et(m,new Set([...w]),!0)),I(et(S))},addSelectedEdges:w=>{const{multiSelectionActive:x,edgeLookup:S,nodeLookup:m,triggerNodeChanges:y,triggerEdgeChanges:I}=g();if(x){const b=w.map(C=>Be(C,!0));I(b);return}I(et(S,new Set([...w]))),y(et(m,new Set,!0))},unselectNodesAndEdges:({nodes:w,edges:x}={})=>{const{edges:S,nodes:m,nodeLookup:y,triggerNodeChanges:I,triggerEdgeChanges:b}=g(),C=w||m,E=x||S,A=[];for(const T of C){if(!T.selected)continue;const L=y.get(T.id);L&&(L.selected=!1),A.push(Be(T.id,!1))}const B=[];for(const T of E)T.selected&&B.push(Be(T.id,!1));I(A),b(B)},setMinZoom:w=>{const{panZoom:x,maxZoom:S}=g();x?.setScaleExtent([w,S]),p({minZoom:w})},setMaxZoom:w=>{const{panZoom:x,minZoom:S}=g();x?.setScaleExtent([S,w]),p({maxZoom:w})},setTranslateExtent:w=>{g().panZoom?.setTranslateExtent(w),p({translateExtent:w})},resetSelectedElements:()=>{const{edges:w,nodes:x,triggerNodeChanges:S,triggerEdgeChanges:m,elementsSelectable:y}=g();if(!y)return;const I=x.reduce((C,E)=>E.selected?[...C,Be(E.id,!1)]:C,[]),b=w.reduce((C,E)=>E.selected?[...C,Be(E.id,!1)]:C,[]);S(I),m(b)},setNodeExtent:w=>{const{nodes:x,nodeLookup:S,parentLookup:m,nodeOrigin:y,elevateNodesOnSelect:I,nodeExtent:b,zIndexMode:C}=g();w[0][0]===b[0][0]&&w[0][1]===b[0][1]&&w[1][0]===b[1][0]&&w[1][1]===b[1][1]||(qn(x,S,m,{nodeOrigin:y,nodeExtent:w,elevateNodesOnSelect:I,checkEquality:!1,zIndexMode:C}),p({nodeExtent:w}))},panBy:w=>{const{transform:x,width:S,height:m,panZoom:y,translateExtent:I}=g();return Cf({delta:w,panZoom:y,transform:x,translateExtent:I,width:S,height:m})},setCenter:async(w,x,S)=>{const{width:m,height:y,maxZoom:I,panZoom:b}=g();if(!b)return!1;const C=typeof S?.zoom<"u"?S.zoom:I;return await b.setViewport({x:m/2-w*C,y:y/2-x*C,zoom:C},{duration:S?.duration,ease:S?.ease,interpolate:S?.interpolate}),!0},cancelConnection:()=>{p({connection:{...Ai}})},updateConnection:w=>{p({connection:w})},reset:()=>p({...Or()})}},Object.is);function Os({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:o,initialWidth:r,initialHeight:i,initialMinZoom:s,initialMaxZoom:a,initialFitViewOptions:c,fitView:l,nodeOrigin:u,nodeExtent:f,zIndexMode:d,children:p}){const[g]=N.useState(()=>Wp({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:r,height:i,fitView:l,minZoom:s,maxZoom:a,fitViewOptions:c,nodeOrigin:u,nodeExtent:f,zIndexMode:d}));return h.jsx(ah,{value:g,children:h.jsx(Ah,{children:h.jsx(Wh,{children:p})})})}function Zp({children:e,nodes:t,edges:n,defaultNodes:o,defaultEdges:r,width:i,height:s,fitView:a,fitViewOptions:c,minZoom:l,maxZoom:u,nodeOrigin:f,nodeExtent:d,zIndexMode:p}){return N.useContext(gn)?h.jsx(h.Fragment,{children:e}):h.jsx(Os,{initialNodes:t,initialEdges:n,defaultNodes:o,defaultEdges:r,initialWidth:i,initialHeight:s,fitView:a,initialFitViewOptions:c,initialMinZoom:l,initialMaxZoom:u,nodeOrigin:f,nodeExtent:d,zIndexMode:p,children:e})}const Gp={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function Up({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,className:r,nodeTypes:i,edgeTypes:s,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:f,onMoveEnd:d,onConnect:p,onConnectStart:g,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:x,onNodeMouseEnter:S,onNodeMouseMove:m,onNodeMouseLeave:y,onNodeContextMenu:I,onNodeDoubleClick:b,onNodeDragStart:C,onNodeDrag:E,onNodeDragStop:A,onNodesDelete:B,onEdgesDelete:T,onDelete:L,onSelectionChange:H,onSelectionDragStart:_,onSelectionDrag:k,onSelectionDragStop:M,onSelectionContextMenu:P,onSelectionStart:j,onSelectionEnd:$,onBeforeDelete:O,connectionMode:V,connectionLineType:z=Re.Bezier,connectionLineStyle:W,connectionLineComponent:Y,connectionLineContainerStyle:Z,deleteKeyCode:J="Backspace",selectionKeyCode:R="Shift",selectionOnDrag:D=!1,selectionMode:F=St.Full,panActivationKeyCode:U="Space",multiSelectionKeyCode:Q=Nt()?"Meta":"Control",zoomActivationKeyCode:G=Nt()?"Meta":"Control",snapToGrid:q,snapGrid:ee,onlyRenderVisibleElements:ne=!1,selectNodesOnDrag:oe,nodesDraggable:ce,autoPanOnNodeFocus:Ne,nodesConnectable:ve,nodesFocusable:be,nodeOrigin:Ce=ls,edgesFocusable:ut,edgesReconnectable:Le,elementsSelectable:Oe=!0,defaultViewport:fe=vh,minZoom:Ie=.5,maxZoom:ke=2,translateExtent:ze=_t,preventScrolling:vn=!0,nodeExtent:bn,defaultMarkerColor:Us="#b1b1b7",zoomOnScroll:qs=!0,zoomOnPinch:Ks=!0,panOnScroll:Qs=!1,panOnScrollSpeed:Js=.5,panOnScrollMode:ea=Ye.Free,zoomOnDoubleClick:ta=!0,panOnDrag:na=!0,onPaneClick:oa,onPaneMouseEnter:ra,onPaneMouseMove:ia,onPaneMouseLeave:sa,onPaneScroll:aa,onPaneContextMenu:ca,paneClickDistance:la=1,nodeClickDistance:ua=0,children:da,onReconnect:fa,onReconnectStart:ha,onReconnectEnd:pa,onEdgeContextMenu:ga,onEdgeDoubleClick:ma,onEdgeMouseEnter:ya,onEdgeMouseMove:xa,onEdgeMouseLeave:wa,reconnectRadius:va=10,onNodesChange:ba,onEdgesChange:_a,noDragClassName:Sa="nodrag",noWheelClassName:Ea="nowheel",noPanClassName:Eo="nopan",fitView:No,fitViewOptions:Co,connectOnClick:Na,attributionPosition:Ca,proOptions:Ia,defaultEdgeOptions:ka,elevateNodesOnSelect:Ma=!0,elevateEdgesOnSelect:Ta=!1,disableKeyboardA11y:Io=!1,autoPanOnConnect:Aa,autoPanOnNodeDrag:Pa,autoPanOnSelection:Da=!0,autoPanSpeed:ja,connectionRadius:$a,isValidConnection:Ra,onError:Ha,style:La,id:ko,nodeDragThreshold:Oa,connectionDragThreshold:za,viewport:Ba,onViewportChange:Va,width:Fa,height:Ya,colorMode:Xa="light",debug:Wa,onScroll:Mo,ariaLabelConfig:Za,zIndexMode:To="basic",...Ga},Ua){const _n=ko||"1",qa=Eh(Xa),Ka=N.useCallback(Ao=>{Ao.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),Mo?.(Ao)},[Mo]);return h.jsx("div",{"data-testid":"rf__wrapper",...Ga,onScroll:Ka,style:{...La,...Gp},ref:Ua,className:se(["react-flow",r,qa]),id:ko,role:"application",children:h.jsxs(Zp,{nodes:e,edges:t,width:Fa,height:Ya,fitView:No,fitViewOptions:Co,minZoom:Ie,maxZoom:ke,nodeOrigin:Ce,nodeExtent:bn,zIndexMode:To,children:[h.jsx(Sh,{nodes:e,edges:t,defaultNodes:n,defaultEdges:o,onConnect:p,onConnectStart:g,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:x,nodesDraggable:ce,autoPanOnNodeFocus:Ne,nodesConnectable:ve,nodesFocusable:be,edgesFocusable:ut,edgesReconnectable:Le,elementsSelectable:Oe,elevateNodesOnSelect:Ma,elevateEdgesOnSelect:Ta,minZoom:Ie,maxZoom:ke,nodeExtent:bn,onNodesChange:ba,onEdgesChange:_a,snapToGrid:q,snapGrid:ee,connectionMode:V,translateExtent:ze,connectOnClick:Na,defaultEdgeOptions:ka,fitView:No,fitViewOptions:Co,onNodesDelete:B,onEdgesDelete:T,onDelete:L,onNodeDragStart:C,onNodeDrag:E,onNodeDragStop:A,onSelectionDrag:k,onSelectionDragStart:_,onSelectionDragStop:M,onMove:u,onMoveStart:f,onMoveEnd:d,noPanClassName:Eo,nodeOrigin:Ce,rfId:_n,autoPanOnConnect:Aa,autoPanOnNodeDrag:Pa,autoPanSpeed:ja,onError:Ha,connectionRadius:$a,isValidConnection:Ra,selectNodesOnDrag:oe,nodeDragThreshold:Oa,connectionDragThreshold:za,onBeforeDelete:O,debug:Wa,ariaLabelConfig:Za,zIndexMode:To}),h.jsx(Yp,{onInit:l,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:S,onNodeMouseMove:m,onNodeMouseLeave:y,onNodeContextMenu:I,onNodeDoubleClick:b,nodeTypes:i,edgeTypes:s,connectionLineType:z,connectionLineStyle:W,connectionLineComponent:Y,connectionLineContainerStyle:Z,selectionKeyCode:R,selectionOnDrag:D,selectionMode:F,deleteKeyCode:J,multiSelectionKeyCode:Q,panActivationKeyCode:U,zoomActivationKeyCode:G,onlyRenderVisibleElements:ne,defaultViewport:fe,translateExtent:ze,minZoom:Ie,maxZoom:ke,preventScrolling:vn,zoomOnScroll:qs,zoomOnPinch:Ks,zoomOnDoubleClick:ta,panOnScroll:Qs,panOnScrollSpeed:Js,panOnScrollMode:ea,panOnDrag:na,autoPanOnSelection:Da,onPaneClick:oa,onPaneMouseEnter:ra,onPaneMouseMove:ia,onPaneMouseLeave:sa,onPaneScroll:aa,onPaneContextMenu:ca,paneClickDistance:la,nodeClickDistance:ua,onSelectionContextMenu:P,onSelectionStart:j,onSelectionEnd:$,onReconnect:fa,onReconnectStart:ha,onReconnectEnd:pa,onEdgeContextMenu:ga,onEdgeDoubleClick:ma,onEdgeMouseEnter:ya,onEdgeMouseMove:xa,onEdgeMouseLeave:wa,reconnectRadius:va,defaultMarkerColor:Us,noDragClassName:Sa,noWheelClassName:Ea,noPanClassName:Eo,rfId:_n,disableKeyboardA11y:Io,nodeExtent:bn,viewport:Ba,onViewportChange:Va,nodesDraggable:ce}),h.jsx(wh,{onSelectionChange:H}),da,h.jsx(ph,{proOptions:Ia,position:Ca}),h.jsx(hh,{rfId:_n,disableKeyboardA11y:Io})]})})}var qp=hs(Up);function Kp({dimensions:e,lineWidth:t,variant:n,className:o}){return h.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:se(["react-flow__background-pattern",n,o])})}function Qp({radius:e,className:t}){return h.jsx("circle",{cx:e,cy:e,r:e,className:se(["react-flow__background-pattern","dots",t])})}var Ae;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Ae||(Ae={}));const Jp={[Ae.Dots]:1,[Ae.Lines]:1,[Ae.Cross]:6},eg=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function zs({id:e,variant:t=Ae.Dots,gap:n=20,size:o,lineWidth:r=1,offset:i=0,color:s,bgColor:a,style:c,className:l,patternClassName:u}){const f=N.useRef(null),{transform:d,patternId:p}=te(eg,ie),g=o||Jp[t],v=t===Ae.Dots,w=t===Ae.Cross,x=Array.isArray(n)?n:[n,n],S=[x[0]*d[2]||1,x[1]*d[2]||1],m=g*d[2],y=Array.isArray(i)?i:[i,i],I=w?[m,m]:S,b=[y[0]*d[2]+I[0]/2,y[1]*d[2]+I[1]/2],C=`${p}${e||""}`;return h.jsxs("svg",{className:se(["react-flow__background",l]),style:{...c,...yn,"--xy-background-color-props":a,"--xy-background-pattern-color-props":s},ref:f,"data-testid":"rf__background",children:[h.jsx("pattern",{id:C,x:d[0]%S[0],y:d[1]%S[1],width:S[0],height:S[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`,children:v?h.jsx(Qp,{radius:m/2,className:u}):h.jsx(Kp,{dimensions:I,lineWidth:r,variant:t,className:u})}),h.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${C})`})]})}zs.displayName="Background";const tg=N.memo(zs);function ng(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:h.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function og(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:h.jsx("path",{d:"M0 0h32v4.2H0z"})})}function rg(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:h.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function ig(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:h.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function sg(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:h.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Bt({children:e,className:t,...n}){return h.jsx("button",{type:"button",className:se(["react-flow__controls-button",t]),...n,children:e})}const ag=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Bs({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:o=!0,fitViewOptions:r,onZoomIn:i,onZoomOut:s,onFitView:a,onInteractiveChange:c,className:l,children:u,position:f="bottom-left",orientation:d="vertical","aria-label":p}){const g=re(),{isInteractive:v,minZoomReached:w,maxZoomReached:x,ariaLabelConfig:S}=te(ag,ie),{zoomIn:m,zoomOut:y,fitView:I}=mn(),b=()=>{m(),i?.()},C=()=>{y(),s?.()},E=()=>{I(r),a?.()},A=()=>{g.setState({nodesDraggable:!v,nodesConnectable:!v,elementsSelectable:!v}),c?.(!v)},B=d==="horizontal"?"horizontal":"vertical";return h.jsxs(Ke,{className:se(["react-flow__controls",B,l]),position:f,style:e,"data-testid":"rf__controls","aria-label":p??S["controls.ariaLabel"],children:[t&&h.jsxs(h.Fragment,{children:[h.jsx(Bt,{onClick:b,className:"react-flow__controls-zoomin",title:S["controls.zoomIn.ariaLabel"],"aria-label":S["controls.zoomIn.ariaLabel"],disabled:x,children:h.jsx(ng,{})}),h.jsx(Bt,{onClick:C,className:"react-flow__controls-zoomout",title:S["controls.zoomOut.ariaLabel"],"aria-label":S["controls.zoomOut.ariaLabel"],disabled:w,children:h.jsx(og,{})})]}),n&&h.jsx(Bt,{className:"react-flow__controls-fitview",onClick:E,title:S["controls.fitView.ariaLabel"],"aria-label":S["controls.fitView.ariaLabel"],children:h.jsx(rg,{})}),o&&h.jsx(Bt,{className:"react-flow__controls-interactive",onClick:A,title:S["controls.interactive.ariaLabel"],"aria-label":S["controls.interactive.ariaLabel"],children:v?h.jsx(sg,{}):h.jsx(ig,{})}),u]})}Bs.displayName="Controls";const cg=N.memo(Bs);function lg({id:e,x:t,y:n,width:o,height:r,style:i,color:s,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:f,selected:d,onClick:p}){const{background:g,backgroundColor:v}=i||{},w=s||g||v;return h.jsx("rect",{className:se(["react-flow__minimap-node",{selected:d},l]),x:t,y:n,rx:u,ry:u,width:o,height:r,style:{fill:w,stroke:a,strokeWidth:c},shapeRendering:f,onClick:p?x=>p(x,e):void 0})}const ug=N.memo(lg),dg=e=>e.nodes.map(t=>t.id),$n=e=>e instanceof Function?e:()=>e;function fg({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:o=5,nodeStrokeWidth:r,nodeComponent:i=ug,onClick:s}){const a=te(dg,ie),c=$n(t),l=$n(e),u=$n(n),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return h.jsx(h.Fragment,{children:a.map(d=>h.jsx(pg,{id:d,nodeColorFunc:c,nodeStrokeColorFunc:l,nodeClassNameFunc:u,nodeBorderRadius:o,nodeStrokeWidth:r,NodeComponent:i,onClick:s,shapeRendering:f},d))})}function hg({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:o,nodeBorderRadius:r,nodeStrokeWidth:i,shapeRendering:s,NodeComponent:a,onClick:c}){const{node:l,x:u,y:f,width:d,height:p}=te(g=>{const v=g.nodeLookup.get(e);if(!v)return{node:void 0,x:0,y:0,width:0,height:0};const w=v.internals.userNode,{x,y:S}=v.internals.positionAbsolute,{width:m,height:y}=we(w);return{node:w,x,y:S,width:m,height:y}},ie);return!l||l.hidden||!Li(l)?null:h.jsx(a,{x:u,y:f,width:d,height:p,style:l.style,selected:!!l.selected,className:o(l),color:t(l),borderRadius:r,strokeColor:n(l),strokeWidth:i,shapeRendering:s,onClick:c,id:l.id})}const pg=N.memo(hg);var gg=N.memo(fg);const mg=200,yg=150,xg=e=>!e.hidden,wg=e=>{const t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};let n=!1;for(const o of e.nodeLookup.values())if(!o.hidden){n=!0;break}return{viewBB:t,boundingRect:n?$i(Tt(e.nodeLookup,{filter:xg}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},zr=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,vg=(e,t)=>zr(e.viewBB,t.viewBB)&&zr(e.boundingRect,t.boundingRect)&&e.rfId===t.rfId&&e.panZoom===t.panZoom&&e.translateExtent===t.translateExtent&&e.flowWidth===t.flowWidth&&e.flowHeight===t.flowHeight&&e.ariaLabelConfig===t.ariaLabelConfig,bg="react-flow__minimap-desc";function Vs({style:e,className:t,nodeStrokeColor:n,nodeColor:o,nodeClassName:r="",nodeBorderRadius:i=5,nodeStrokeWidth:s,nodeComponent:a,bgColor:c,maskColor:l,maskStrokeColor:u,maskStrokeWidth:f,position:d="bottom-right",onClick:p,onNodeClick:g,pannable:v=!1,zoomable:w=!1,ariaLabel:x,inversePan:S,zoomStep:m=1,offsetScale:y=5}){const I=re(),b=N.useRef(null),{boundingRect:C,panZoom:E,viewBB:A,rfId:B,translateExtent:T,flowWidth:L,flowHeight:H,ariaLabelConfig:_}=te(wg,vg),k=e?.width??mg,M=e?.height??yg,P=C.width/k,j=C.height/M,$=Math.max(P,j),O=$*k,V=$*M,z=y*$,W=C.x-(O-C.width)/2-z,Y=C.y-(V-C.height)/2-z,Z=O+z*2,J=V+z*2,R=`${bg}-${B}`,D=N.useRef(0),F=N.useRef();D.current=$,N.useEffect(()=>{const ee=I.getState().panZoom;if(b.current&&ee)return F.current=$f({domNode:b.current,panZoom:ee,getTransform:()=>I.getState().transform,getViewScale:()=>D.current}),()=>{F.current?.destroy()}},[E]),N.useEffect(()=>{F.current?.update({translateExtent:T,width:L,height:H,inversePan:S,pannable:v,zoomStep:m,zoomable:w})},[v,w,S,m,T,L,H]);const U=p?ee=>{const[ne,oe]=F.current?.pointer(ee)||[0,0];p(ee,{x:ne,y:oe})}:void 0,Q=N.useCallback((ee,ne)=>{const oe=I.getState().nodeLookup.get(ne).internals.userNode;g?.(ee,oe)},[g]),G=g?Q:void 0,q=x??_["minimap.ariaLabel"];return h.jsx(Ke,{position:d,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof l=="string"?l:void 0,"--xy-minimap-mask-stroke-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*$:void 0,"--xy-minimap-node-background-color-props":typeof o=="string"?o:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof s=="number"?s:void 0},className:se(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:h.jsxs("svg",{width:k,height:M,viewBox:`${W} ${Y} ${Z} ${J}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":R,ref:b,onClick:U,children:[q&&h.jsx("title",{id:R,children:q}),h.jsx(gg,{onClick:G,nodeColor:o,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:r,nodeStrokeWidth:s,nodeComponent:a}),h.jsx("path",{className:"react-flow__minimap-mask",d:`M${W-z},${Y-z}h${Z+z*2}v${J+z*2}h${-Z-z*2}z
7
- M${A.x},${A.y}h${A.width}v${A.height}h${-A.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}Vs.displayName="MiniMap";const _g=N.memo(Vs),Sg=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,Eg={[lt.Line]:"right",[lt.Handle]:"bottom-right"};function Ng({nodeId:e,position:t,variant:n=lt.Handle,className:o,style:r=void 0,children:i,color:s,minWidth:a=10,minHeight:c=10,maxWidth:l=Number.MAX_VALUE,maxHeight:u=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:d,autoScale:p=!0,shouldResize:g,onResizeStart:v,onResize:w,onResizeEnd:x}){const S=xs(),m=typeof e=="string"?e:S,y=re(),I=N.useRef(null),b=n===lt.Handle,C=te(N.useCallback(Sg(b&&p),[b,p]),ie),E=N.useRef(null),A=t??Eg[n];N.useEffect(()=>{if(!(!I.current||!m))return E.current||(E.current=Gf({domNode:I.current,nodeId:m,getStoreItems:()=>{const{nodeLookup:T,transform:L,snapGrid:H,snapToGrid:_,nodeOrigin:k,domNode:M}=y.getState();return{nodeLookup:T,transform:L,snapGrid:H,snapToGrid:_,nodeOrigin:k,paneDomNode:M}},onChange:(T,L)=>{const{triggerNodeChanges:H,nodeLookup:_,parentLookup:k,nodeOrigin:M}=y.getState(),P=[],j={x:T.x,y:T.y},$=_.get(m);if($&&$.expandParent&&$.parentId){const O=$.origin??M,V=T.width??$.measured.width??0,z=T.height??$.measured.height??0,W={id:$.id,parentId:$.parentId,rect:{width:V,height:z,...Oi({x:T.x??$.position.x,y:T.y??$.position.y},{width:V,height:z},$.parentId,_,O)}},Y=vo([W],_,k,M);P.push(...Y),j.x=T.x?Math.max(O[0]*V,T.x):void 0,j.y=T.y?Math.max(O[1]*z,T.y):void 0}if(j.x!==void 0&&j.y!==void 0){const O={id:m,type:"position",position:{...j}};P.push(O)}if(T.width!==void 0&&T.height!==void 0){const V={id:m,type:"dimensions",resizing:!0,setAttributes:d?d==="horizontal"?"width":"height":!0,dimensions:{width:T.width,height:T.height}};P.push(V)}for(const O of L){const V={...O,type:"position"};P.push(V)}H(P)},onEnd:({width:T,height:L})=>{const H={id:m,type:"dimensions",resizing:!1,dimensions:{width:T,height:L}};y.getState().triggerNodeChanges([H])}})),E.current.update({controlPosition:A,boundaries:{minWidth:a,minHeight:c,maxWidth:l,maxHeight:u},keepAspectRatio:f,resizeDirection:d,onResizeStart:v,onResize:w,onResizeEnd:x,shouldResize:g}),()=>{E.current?.destroy()}},[A,a,c,l,u,f,v,w,x,g]);const B=A.split("-");return h.jsx("div",{className:se(["react-flow__resize-control","nodrag",...B,n,o]),ref:I,style:{...r,scale:C,...s&&{[b?"backgroundColor":"borderColor"]:s}},children:i})}N.memo(Ng);function Cg({nodeId:e}){const{t}=ae(),n=K(r=>r.showToast),o=N.useCallback(async()=>{try{await mc(e),n(t("toast.metadataCopied"))}catch{n(t("toast.copyFailed"),!0)}},[e,n,t]);return h.jsxs("div",{className:"image-node__id",title:e,children:[h.jsx("span",{className:"image-node__id-text",children:e}),h.jsx("button",{type:"button",className:"image-node__id-copy nodrag",onClick:r=>{r.stopPropagation(),o()},title:t("node.copyId"),"aria-label":t("node.copyId"),children:h.jsxs("svg",{viewBox:"0 0 24 24",width:"11",height:"11","aria-hidden":"true",children:[h.jsx("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2",fill:"none",stroke:"currentColor",strokeWidth:"1.8"}),h.jsx("path",{d:"M5 15V5.5A1.5 1.5 0 0 1 6.5 4H15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})]})})]})}const Ig=new Set(["Escape","Tab"]);function Br(e){"key"in e&&Ig.has(e.key)||e.stopPropagation()}function kg({imageUrl:e,prompt:t}){const{t:n}=ae(),[o,r]=N.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsx("img",{src:e,alt:n("node.nodeImageAlt")}),h.jsx("button",{type:"button",className:"image-node__zoom nodrag",title:n("node.zoomImage"),"aria-label":n("node.zoomImage"),onClick:i=>{i.stopPropagation(),r(!0)},children:h.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16","aria-hidden":"true",children:[h.jsx("circle",{cx:"10.5",cy:"10.5",r:"6.5",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),h.jsx("path",{d:"M15.5 15.5 21 21M7.5 10.5h6M10.5 7.5v6",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})]})}),o?ec.createPortal(h.jsx("div",{className:"nokey",onClick:Br,onKeyDown:Br,children:h.jsx(yc,{item:{image:e,url:e,prompt:t,filename:e.replace(/^\/generated\//,""),mediaType:"image"},showAssetActions:!1,onClose:()=>r(!1)})}),document.body):null]})}const Rn=5,Gt=240,Mg=180,Tg=420,Vr=[{id:"top",position:X.Top},{id:"right",position:X.Right},{id:"bottom",position:X.Bottom},{id:"left",position:X.Left}];function Ag(e,t){const n=rc({model:e.model,provider:e.provider,mediaType:Vt(e.imageUrl)?"video":"image",videoContinuity:e.videoContinuity});return n.derivation?t(`provenance.${n.derivation}`):null}function Pg(e){const t=/^(\d+)x(\d+)$/.exec(e??"");if(!t)return Gt;const n=Number(t[1]),o=Number(t[2]);if(!Number.isFinite(n)||!Number.isFinite(o)||n<=0||o<=0)return Gt;const r=Gt*(n/o);return Math.round(Math.min(Tg,Math.max(Mg,r)))}function Dg({id:e,data:t,selected:n}){const{t:o}=ae(),r=t,i=K(R=>R.updateNodePrompt),s=K(R=>R.addNodeReferences),a=K(R=>R.addNodeReferenceFromUrl),c=K(R=>R.readDroppedImageMetadata),l=K(R=>R.removeNodeReference),u=K(R=>R.generateNode),f=K(R=>R.generateNodeInPlace),d=K(R=>R.generateNodeVariation),p=K(R=>R.animateImage),g=K(R=>R.addChildNode),v=K(R=>R.duplicateBranchRoot),w=K(R=>R.deleteNode),x=N.useRef(null),[S,m]=N.useState(!1),[y,I]=N.useState(!1),b=r.referenceImages??[],C=r.status==="pending"||r.status==="reconciling",E=!C&&b.length<Rn,A={"--node-preview-w":`${Pg(r.size)}px`,"--node-preview-h":`${Gt}px`},B=N.useCallback(R=>i(e,R.target.value),[e,i]),T=N.useCallback(()=>{u(e)},[e,u]),L=N.useCallback(()=>{f(e)},[e,f]),H=N.useCallback(()=>{d(e)},[e,d]),_=N.useCallback(()=>{r.status==="ready"&&g(e)},[e,r.status,g]),k=N.useCallback(()=>{if(r.status!=="ready"||!r.imageUrl||Vt(r.imageUrl))return;const R=r.imageUrl.replace(/^\/generated\//,"");p(R,r.prompt)},[r.status,r.imageUrl,r.prompt,p]),M=N.useCallback(()=>{v(e)},[e,v]),P=N.useCallback(()=>w(e),[e,w]),j=R=>{if(!R)return[];const D=[];for(const F of Array.from(R)){if(F.kind!=="file"||!F.type.startsWith("image/"))continue;const U=F.getAsFile();U&&D.push(U)}return D},$=async R=>{R.length!==0&&(R.length===1&&await c(R[0],e)||await s(e,R))},O=async R=>{R.preventDefault(),R.stopPropagation(),m(!1);const D=R.dataTransfer.getData("application/ima2-ref");if(D){if(!E)return;try{const U=JSON.parse(D),Q=U.url||U.image;Q&&a(e,Q,U.filename)}catch{}return}const F=Array.from(R.dataTransfer.files).filter(U=>U.type.startsWith("image/"));F.length===1&&await c(F[0],e)||E&&F.length>0&&s(e,F)},V=R=>{R.preventDefault(),R.stopPropagation(),E&&!S&&m(!0)},z=R=>{R.currentTarget.contains(R.relatedTarget)||m(!1)},W=R=>{const D=j(R.clipboardData?.items??null);if(D.length===0||(R.preventDefault(),R.stopPropagation(),!E))return;const F=Rn-b.length;s(e,D.slice(0,F))},Z=(()=>{switch(r.status){case"empty":return o("node.empty");case"pending":return o("node.pending");case"reconciling":return r.pendingPhase?o("node.reconcilingPhase",{phase:r.pendingPhase}):o("node.reconciling");case"ready":return[r.webSearchCalls?o("node.readyWithSearch",{elapsed:r.elapsed??"?",searches:r.webSearchCalls}):o("node.ready",{elapsed:r.elapsed??"?"}),r.video?.duration?`${r.video.duration}s`:null,r.video?.resolution??null,r.video?.aspectRatio??null,nc(r.reasoningEffort),oc(r.model,r.provider),Ag(r,o)].filter(Boolean).join(" · ");case"stale":return r.error?o("node.staleWithError",{error:r.error}):o("node.stale");case"asset-missing":return r.error?o("node.assetMissingWithError",{error:r.error}):o("node.assetMissing");case"error":return o("node.error",{error:r.errorInfo?.message??r.error??o("node.errorUnknown")});default:return""}})(),J=r.status==="error"&&r.errorInfo?.code!=="JOB_TRACKING_TIMEOUT"?r.errorInfo?.action??"retry":null;return h.jsxs("div",{className:`image-node image-node--${r.status}${n?" image-node--selected":""}`,style:A,children:[Vr.map(({id:R,position:D})=>h.jsx(He,{type:"target",id:`target-${R}`,position:D,className:`image-node__handle image-node__handle--target image-node__handle--${R}`},`target-${R}`)),h.jsx(Cg,{nodeId:e}),h.jsx("div",{className:"image-node__preview",children:r.imageUrl&&r.status!=="asset-missing"?Vt(r.imageUrl)?h.jsx("video",{src:r.imageUrl,controls:!0,loop:!0,playsInline:!0,muted:!0,className:"image-node__video nodrag"}):h.jsx(kg,{imageUrl:r.imageUrl,prompt:r.prompt||""}):C&&r.partialImageUrl?h.jsx("img",{className:"image-node__partial",src:r.partialImageUrl,alt:o("node.partialImageAlt")}):C?h.jsx("div",{className:"image-node__skeleton"}):r.status==="asset-missing"?h.jsx("div",{className:"image-node__placeholder",children:o("node.noAsset")}):r.status==="stale"?h.jsx("div",{className:"image-node__placeholder",children:o("node.stateStale")}):h.jsx("div",{className:"image-node__placeholder",children:o("node.noImage")})}),h.jsxs("div",{className:`image-node__composer nodrag${S?" is-dragging":""}`,onDrop:O,onDragOver:V,onDragLeave:z,onPaste:W,children:[b.length>0?h.jsx("div",{className:"image-node__refs",children:b.map((R,D)=>h.jsxs("div",{className:"image-node__ref-chip",title:o("node.refAlt",{n:D+1}),children:[h.jsx("img",{src:R,alt:o("node.refAlt",{n:D+1})}),h.jsx("button",{type:"button",className:"image-node__ref-remove",onClick:()=>l(e,D),disabled:C,"aria-label":o("node.removeRef",{n:D+1}),children:"×"})]},D))}):null,h.jsx("textarea",{className:"image-node__prompt",value:r.prompt,onChange:B,onKeyDown:R=>R.stopPropagation(),placeholder:r.parentServerNodeId?o("node.editPromptPlaceholder"):o("node.promptPlaceholder"),rows:2,disabled:C}),h.jsxs("div",{className:"image-node__composer-bar",children:[h.jsx("button",{type:"button",className:"image-node__attach",onClick:()=>E&&x.current?.click(),disabled:!E,title:r.parentServerNodeId?o("node.nodeRefsUsedWithParent"):o("node.attachRefTitle"),children:o("node.attachRef")}),S?h.jsx("span",{className:"image-node__drop-hint",children:o("node.dropRefs")}):b.length>0?h.jsxs("span",{className:"image-node__ref-count",children:[b.length,"/",Rn]}):null]}),h.jsx("input",{ref:x,type:"file",accept:"image/*",multiple:!0,hidden:!0,onChange:R=>{const D=Array.from(R.target.files??[]);D.length>0&&$(D),R.target.value=""}})]}),h.jsxs("div",{className:"image-node__footer nodrag",children:[h.jsx("span",{className:"image-node__status",title:r.errorInfo?.code?`${Z} [${r.errorInfo.code}]`:Z,children:Z}),J==="retry"?h.jsx("button",{type:"button",className:"image-node__retry",onClick:L,disabled:C,title:o("node.retryTitle"),children:o("node.retry")}):J==="auth"?h.jsx("span",{className:"image-node__error-cta",children:o("node.errorAuthCta")}):J==="fix-input"?h.jsx("span",{className:"image-node__error-cta",children:o("node.errorFixCta")}):null,h.jsxs("div",{className:"image-node__actions",children:[h.jsxs("div",{style:{position:"relative"},children:[h.jsx("button",{type:"button",onClick:()=>I(R=>!R),disabled:!r.prompt?.trim(),title:o("promptLibrary.saveTitle"),"aria-label":o("promptLibrary.saveTitle"),"aria-haspopup":"dialog","aria-expanded":y,children:h.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",width:"15",height:"15",children:h.jsx("path",{d:"M6.5 3.75h11a.75.75 0 0 1 .75.75v15.03a.5.5 0 0 1-.77.42L12 16.4l-5.48 3.55a.5.5 0 0 1-.77-.42V4.5a.75.75 0 0 1 .75-.75Z",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinejoin:"round"})})}),y&&h.jsx(tc,{text:r.prompt||"",onClose:()=>I(!1)})]}),r.status==="ready"?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",onClick:L,disabled:C,title:o("node.regenerateTitle"),"aria-label":o("node.regenerateTitle"),children:"↻"}),h.jsx("button",{type:"button",onClick:H,disabled:C,title:o("node.newVariationTitle"),"aria-label":o("node.newVariationTitle"),children:o("node.newVariation")}),!Vt(r.imageUrl)&&h.jsx("button",{type:"button",onClick:k,disabled:C,title:o("node.animateTitle",{fallback:"Animate"}),"aria-label":o("node.animateTitle",{fallback:"Animate"}),children:h.jsxs("svg",{viewBox:"0 0 24 24",width:"15",height:"15","aria-hidden":"true",children:[h.jsx("rect",{x:"3",y:"5.5",width:"18",height:"13",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6"}),h.jsx("path",{d:"M7.5 5.5v13M16.5 5.5v13M3 12h18",fill:"none",stroke:"currentColor",strokeWidth:"1.3"})]})})]}):h.jsx("button",{type:"button",className:"image-node__generate",onClick:T,disabled:C,title:o("node.generateTitle"),"aria-label":o("node.generateTitle"),children:o("node.generate")}),r.status==="ready"?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",onClick:_,title:o("node.addChildTitle"),"aria-label":o("node.addChildTitle"),children:o("node.addChild")}),h.jsx("button",{type:"button",onClick:M,title:o("node.duplicateBranchTitle"),"aria-label":o("node.duplicateBranchTitle"),children:o("node.duplicateBranch")})]}):null,h.jsx("button",{type:"button",onClick:P,className:"image-node__del",title:o("node.deleteTitle"),"aria-label":o("node.deleteTitle"),children:"×"})]})]}),Vr.map(({id:R,position:D})=>h.jsx(He,{type:"source",id:`source-${R}`,position:D,className:`image-node__handle image-node__handle--source image-node__handle--${R}`},`source-${R}`))]})}const jg=N.memo(Dg);function $g(){const{t:e}=ae(),t=K(S=>S.graphNodes),n=K(S=>S.graphEdges),o=K(S=>S.nodeSelectionMode),r=K(S=>S.nodeBatchRunning),i=K(S=>S.nodeBatchStopping),s=K(S=>S.toggleNodeSelectionMode),a=K(S=>S.selectAllGraphNodes),c=K(S=>S.clearNodeSelection),l=K(S=>S.runNodeBatch),u=K(S=>S.cancelNodeBatch),f=K(S=>S.disconnectEdges),d=t.filter(S=>S.selected).map(S=>S.id),p=n.filter(S=>S.selected).map(S=>S.id),g=new Set(d),v=t.filter(S=>g.has(S.id)&&S.type!=="elementReferenceNode"&&!ic(S)).length,w=sc(n,d).length,x=S=>{l(S)};return h.jsxs(Ke,{position:"top-center",className:"node-batch-bar nodrag",children:[h.jsx("button",{type:"button",onClick:s,"aria-pressed":o,children:e(o?"nodeBatch.selectionOn":"nodeBatch.selectionOff")}),h.jsx("button",{type:"button",onClick:a,disabled:t.length===0,children:e("nodeBatch.selectAll")}),p.length>0?h.jsx("button",{type:"button",className:"node-batch-bar__danger",onClick:()=>f(p),title:e("edge.disconnectTitle"),"aria-label":e("edge.disconnectTitle"),children:e("edge.disconnect")}):null,d.length>0?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"node-batch-bar__meta",children:e("nodeBatch.summary",{selected:d.length,missing:v,stale:w})}),h.jsx("button",{type:"button",onClick:()=>x("missing-only"),disabled:r,children:e("nodeBatch.generateMissing")}),h.jsx("button",{type:"button",onClick:()=>x("regenerate-all"),disabled:r,children:e("nodeBatch.regenerateSelected")}),r?h.jsx("button",{type:"button",onClick:u,disabled:i,children:e(i?"nodeBatch.stopping":"nodeBatch.stopRemaining")}):null,h.jsx("button",{type:"button",onClick:c,disabled:r,children:e("nodeBatch.clear")})]}):null]})}function Rg({data:e,selected:t}){const{t:n}=ae(),o=N.useCallback(()=>{e.elementId&&(e.onOpenAssets?e.onOpenAssets(e.elementId):window.dispatchEvent(new CustomEvent("ima2:open-assets-detail",{detail:{assetId:e.elementId}})))},[e]),r=e.elementName??n("nodeStudio.elementNode.untitled");return h.jsxs("div",{className:`element-reference-node${t?" is-selected":""}${e.missing?" is-missing":""}${e.compact?" is-compact":""}`,onDoubleClick:o,style:{"--element-thumb":e.thumbnailUrl?`url(${JSON.stringify(e.thumbnailUrl)})`:"none"},children:[h.jsx(He,{type:"source",id:"refs",position:X.Right,className:"element-reference-node__handle element-reference-node__handle--refs","aria-label":n("nodeStudio.elementNode.referencesOutput")}),h.jsx(He,{type:"source",id:"notes",position:X.Bottom,className:"element-reference-node__handle element-reference-node__handle--notes","aria-label":n("nodeStudio.elementNode.notesOutput")}),h.jsxs("div",{className:"element-reference-node__header",children:[h.jsx("span",{className:"element-reference-node__kind",children:n("nodeStudio.elementNode.kind")}),h.jsx("strong",{children:r})]}),h.jsxs("div",{className:"element-reference-node__body",children:[h.jsx("div",{className:"element-reference-node__thumbnail","aria-hidden":"true"}),e.compact?null:h.jsxs("div",{children:[h.jsx("span",{className:"element-reference-node__ref-count",children:n(e.refCount===1?"nodeStudio.elementNode.referenceCountOne":"nodeStudio.elementNode.referenceCount",{count:e.refCount})}),e.notesPreview?h.jsx("p",{children:e.notesPreview}):null]})]}),e.missing?h.jsx("p",{className:"element-reference-node__warning",role:"alert",children:n("nodeStudio.elementNode.missing")}):null]})}const Hg=N.memo(Rg);function Hn({title:e,description:t,action:n,disabled:o,onClick:r}){return h.jsxs("button",{type:"button",className:"node-empty-state__choice",disabled:o,onClick:r,children:[h.jsx("span",{className:"node-empty-state__choice-title",children:e}),h.jsx("span",{className:"node-empty-state__choice-description",children:t}),h.jsx("span",{className:"node-empty-state__choice-action",children:n})]})}function Lg({hasRecentGraph:e,onStartBlank:t,onOpenTemplates:n,onResumeRecent:o}){const{t:r}=ae();return h.jsxs("section",{className:"node-empty-state","aria-labelledby":"node-empty-state-title",children:[h.jsxs("div",{className:"node-empty-state__intro",children:[h.jsx("p",{className:"node-empty-state__eyebrow",children:r("nodeStudio.name")}),h.jsx("h2",{id:"node-empty-state-title",children:r("nodeStudio.empty.title")}),h.jsx("p",{children:r("nodeStudio.empty.description")})]}),h.jsxs("div",{className:"node-empty-state__choices",children:[h.jsx(Hn,{title:r("nodeStudio.empty.blankTitle"),description:r("nodeStudio.empty.blankDescription"),action:r("nodeStudio.empty.blankAction"),onClick:t}),h.jsx(Hn,{title:r("nodeStudio.empty.templateTitle"),description:r("nodeStudio.empty.templateDescription"),action:r("nodeStudio.empty.templateAction"),onClick:n}),h.jsx(Hn,{title:r("nodeStudio.empty.recentTitle"),description:r(e?"nodeStudio.empty.recentDescription":"nodeStudio.empty.recentUnavailable"),action:r("nodeStudio.empty.recentAction"),disabled:!e,onClick:()=>{o()}})]})]})}const Jn=["oauth","api","grok","gemini-api"];function Fr(e,t){return{id:`variant-${e+1}`,label:t,provider:Jn[e%Jn.length],model:"",size:""}}function Og(e){return{id:e.id,label:e.label.trim(),provider:e.provider,settingsPatch:{...e.model.trim()?{model:e.model.trim()}:{},...e.size.trim()?{size:e.size.trim()}:{}}}}function zg({sourceLabel:e,onApply:t,onClose:n}){const{t:o}=ae(),[r,i]=N.useState(()=>[0,1].map(f=>Fr(f,o("nodeStudio.branch.defaultVariant",{index:f+1})))),s=N.useRef(2),a=(f,d)=>{i(p=>p.map((g,v)=>v===f?{...g,...d}:g))},c=f=>i(d=>d.filter((p,g)=>g!==f)),l=()=>i(f=>{if(f.length>=4)return f;const d=s.current++,p=Fr(d,o("nodeStudio.branch.defaultVariant",{index:d+1}));return[...f,p]}),u=()=>t(r.map(Og));return h.jsxs("section",{className:"node-template-picker",role:"document",children:[h.jsxs("header",{children:[h.jsxs("div",{children:[h.jsx("p",{className:"node-template-picker__eyebrow",children:o("nodeStudio.branch.eyebrow")}),h.jsx("h2",{id:"node-branch-dialog-title",children:o("nodeStudio.branch.title")}),h.jsx("p",{children:e})]}),h.jsx("button",{type:"button","aria-label":o("nodeStudio.branch.close"),onClick:n,children:"×"})]}),h.jsx("div",{className:"node-template-picker__sections",children:r.map((f,d)=>h.jsxs("fieldset",{className:"node-template-picker__card",children:[h.jsx("legend",{children:o("nodeStudio.branch.variantLegend",{index:d+1})}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:o("nodeStudio.branch.label")}),h.jsx("input",{autoFocus:d===0,value:f.label,onChange:p=>a(d,{label:p.target.value})})]}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:o("nodeStudio.branch.provider")}),h.jsx("select",{value:f.provider,onChange:p=>a(d,{provider:p.target.value}),children:Jn.map(p=>h.jsx("option",{value:p,children:p},p))})]}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:o("nodeStudio.branch.modelOverride")}),h.jsx("input",{value:f.model,onChange:p=>a(d,{model:p.target.value}),placeholder:o("nodeStudio.branch.currentModel")})]}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:o("nodeStudio.branch.sizeOverride")}),h.jsx("input",{value:f.size,onChange:p=>a(d,{size:p.target.value}),placeholder:o("nodeStudio.branch.currentSize")})]}),h.jsx("button",{type:"button",disabled:r.length<=2,onClick:()=>c(d),children:o("nodeStudio.branch.remove")})]},f.id))}),h.jsxs("footer",{children:[h.jsx("button",{type:"button",disabled:r.length>=4,onClick:l,children:o("nodeStudio.branch.add")}),h.jsx("span",{}),h.jsx("button",{type:"button",onClick:n,children:o("nodeStudio.branch.cancel")}),h.jsx("button",{type:"button",className:"node-template-picker__copy",disabled:r.some(f=>!f.label.trim()),onClick:u,children:o("nodeStudio.branch.create")})]})]})}const Bg={prompt:["prompt","element-notes"],image:["image","images","mask","element-refs","any-media"],images:["images","element-refs","any-media"],video:["video","any-media"],mask:["mask","any-media"],"element-refs":["image","images","element-refs","any-media"],"element-notes":["prompt","element-notes"],settings:["settings"],"any-media":["image","images","video","mask","any-media"]};function eo(e,t){const n=t.equivalentHandleIds??[t.handleId];return typeof e=="string"&&n.includes(e)}function Vg(e,t,n){return n.some(o=>o.source===e.nodeId&&o.target===t.nodeId&&eo(o.sourceHandle,e)&&eo(o.targetHandle,t))}function Fg(e,t){return t.some(n=>n.target===e.nodeId&&eo(n.targetHandle,e))}function Fs(e,t){return Bg[e].includes(t)}function Ys(e,t,n){return e.direction!=="output"||t.direction!=="input"?{allowed:!1,reason:"SAME_DIRECTION"}:e.nodeId===t.nodeId?{allowed:!1,reason:"SELF_EDGE"}:Vg(e,t,n.edges)?{allowed:!1,reason:"DUPLICATE_EDGE"}:Fs(e.type,t.type)?ac(n.edges,e.nodeId,t.nodeId)?{allowed:!1,reason:"CYCLE"}:!t.acceptsMany&&Fg(t,n.edges)?{allowed:!1,reason:"CARDINALITY"}:{allowed:!0}:{allowed:!1,reason:"TYPE_MISMATCH"}}const Yg={input:"nodeStudio.palette.categories.input",generate:"nodeStudio.palette.categories.generate",transform:"nodeStudio.palette.categories.transform",reference:"nodeStudio.palette.categories.reference",output:"nodeStudio.palette.categories.output"},ht=["input","generate","transform","reference","output"];function tt(e,t,n){const o=`nodeStudio.commands.${t.type}.${n}`,r=e(o);return r===o?t[n]:r}function Xg(e,t){const n=`nodeStudio.portTypes.${t}`,o=e(n);return o===n?t:o}function Wg(e,t,n){const o=t.toLocaleLowerCase(),r=tt(n,e,"label").toLocaleLowerCase();return r.startsWith(o)?0:r.includes(o)?1:e.keywords.some(i=>i.toLocaleLowerCase().includes(o))?2:tt(n,e,"description").toLocaleLowerCase().includes(o)?3:-1}function Zg(e,t){return t?t.direction==="output"&&e.inputPorts.some(n=>Fs(t.type,n.type)):!0}function Gg({open:e,anchor:t,sourcePort:n,commands:o,recentCommandTypes:r=[],onInsert:i,onClose:s}){const{t:a}=ae(),c=N.useId(),l=N.useRef(null),[u,f]=N.useState(""),[d,p]=N.useState(0),g=N.useMemo(()=>o.filter(b=>Zg(b,n)).map(b=>({command:b,score:Wg(b,u,a)})).filter(b=>!u||b.score>=0).sort((b,C)=>b.score-C.score||tt(a,b.command,"label").localeCompare(tt(a,C.command,"label"))).map(b=>b.command),[o,u,n,a]),v=u?g:[...r.map(b=>g.find(C=>C.type===b)).filter(b=>!!b).slice(0,5),...g.filter(b=>!r.includes(b.type))],w=N.useMemo(()=>ht.flatMap(b=>v.filter(C=>C.category===b)),[v]);if(N.useEffect(()=>{e&&(f(""),p(0),requestAnimationFrame(()=>l.current?.focus()))},[e]),N.useEffect(()=>{p(b=>Math.min(b,Math.max(0,w.length-1)))},[w.length]),!e)return null;const x=()=>{const b=w[d];b&&i(b)},S=b=>{if(b.stopPropagation(),b.key==="Escape")b.preventDefault(),s();else if(b.key==="ArrowDown")b.preventDefault(),p(C=>(C+1)%Math.max(1,w.length));else if(b.key==="ArrowUp")b.preventDefault(),p(C=>(C-1+w.length)%Math.max(1,w.length));else if(b.key==="Home")b.preventDefault(),p(0);else if(b.key==="End")b.preventDefault(),p(Math.max(0,w.length-1));else if(b.key==="Enter")b.preventDefault(),x();else if(b.key==="Tab"){b.preventDefault();const C=w[d]?.category,E=ht.indexOf(C??"input"),A=ht.slice(E+1).concat(ht.slice(0,E)).find(B=>B!==C&&w.some(T=>T.category===B));A&&p(w.findIndex(B=>B.category===A))}else(b.metaKey||b.ctrlKey)&&b.key==="Backspace"&&(b.preventDefault(),f(""))},m=n?Xg(a,n.type):null,y=Math.max(8,Math.min(t.clientX,window.innerWidth-372)),I=Math.max(8,Math.min(t.clientY,window.innerHeight-220));return h.jsxs("section",{className:"node-command-palette",style:{left:y,top:I},"aria-label":a("nodeStudio.palette.ariaLabel"),children:[h.jsx("input",{ref:l,className:"node-command-palette__search",value:u,onChange:b=>f(b.target.value),onKeyDown:S,placeholder:m?a("nodeStudio.palette.compatiblePlaceholder",{portType:m}):a("nodeStudio.palette.searchPlaceholder"),"aria-controls":c,"aria-activedescendant":w[d]?`${c}-${w[d].type}`:void 0}),m?h.jsx("p",{className:"node-command-palette__filter",children:a("nodeStudio.palette.filter",{portType:m})}):null,w.length===0?h.jsx("p",{className:"node-command-palette__empty",children:m?a("nodeStudio.palette.emptyCompatible",{portType:m}):a("nodeStudio.palette.emptySearch")}):h.jsx("div",{className:"node-command-palette__list",id:c,role:"listbox","aria-label":a("nodeStudio.palette.commandsAria"),children:ht.map(b=>{const C=w.filter(E=>E.category===b);return C.length?h.jsxs("section",{children:[h.jsx("h3",{children:a(Yg[b])}),C.map(E=>{const A=w.indexOf(E);return h.jsxs("button",{id:`${c}-${E.type}`,type:"button",role:"option","aria-selected":A===d,className:A===d?"is-active":"",onPointerEnter:()=>p(A),onClick:()=>i(E),children:[h.jsx("span",{children:tt(a,E,"label")}),h.jsx("small",{children:tt(a,E,"description")})]},E.type)})]},b):null})})]})}const to="application/ima2-node-element";function _o(e){return{clientId:e,serverNodeId:null,parentServerNodeId:null,prompt:"",imageUrl:null,status:"empty",pendingRequestId:null,pendingPhase:null}}function Xs(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function Ug(e){const t=Xs(e.data),n=t.nodeType==="element-reference";return{...e,id:e.id,type:n?"elementReferenceNode":"imageNode",position:e.position??{x:0,y:0},data:{..._o(e.id),...t,clientId:e.id,status:t.status==="ready"?"ready":"empty",pendingRequestId:null,pendingPhase:null}}}function qg(e){return{...e,id:e.id,source:e.source,target:e.target,sourceHandle:e.sourceHandle==="output"?"source-right":e.sourceHandle,targetHandle:e.targetHandle==="input"?"target-left":e.targetHandle}}function Kg(e){return{nodes:e.nodes.map(Ug),edges:e.edges.map(qg)}}function Ws(e,t){const n=new Set(e.map(o=>o.id));return n.size!==e.length||new Set(t.map(o=>o.id)).size!==t.length||t.some(o=>!n.has(o.source)||!n.has(o.target))||lc(e,t)?!1:e.every(o=>o.type!=="elementReferenceNode"||Xs(o.data).nodeType==="element-reference")}function wn(e){if(!Ws(e.nodes,e.edges))return!1;K.getState().recordGraphHistory(`commit-${e.reason}`);const t=cc(e.nodes,e.edges);return K.setState({graphNodes:t,graphEdges:e.edges}),K.getState().scheduleGraphSave(),!0}function Qg(e,t){if(t.createdNodeIds.length===0||t.createdEdgeIds.length===0)return{ok:!1};const n={nodes:[...e.nodes,...t.nodes],edges:[...e.edges,...t.edges]};return Ws(n.nodes,n.edges)?{ok:!0,graph:n}:{ok:!1}}function Jg(e){const t=Qr(),n={id:t,type:"imageNode",position:e.position,data:_o(t)};if(!e.sourcePort)return{nodes:[...e.graph.nodes,n],edges:e.graph.edges};const o={id:`${e.sourcePort.nodeId}:${e.sourcePort.handleId}->${t}:target-left`,source:e.sourcePort.nodeId,target:t,sourceHandle:e.sourcePort.handleId,targetHandle:"target-left"};return{nodes:[...e.graph.nodes,n],edges:[...e.graph.edges,o]}}function em(e){try{const t=JSON.parse(e);return t.version===1&&t.assetKind==="element"&&typeof t.elementId=="string"&&t.elementId.length>0?t:null}catch{return null}}function tm(e){const t=e.metadata?.refs,n=Array.isArray(t)?t.find(o=>typeof o=="string"&&o.length>0):null;return n?`/generated/${n.split("/").map(encodeURIComponent).join("/")}`:null}function nm(e,t){if(e.kind!=="element")return null;const n=Array.isArray(e.metadata?.refs)?e.metadata.refs:[],o=Qr();return{id:o,type:"elementReferenceNode",position:t,data:{..._o(o),nodeType:"element-reference",elementId:e.id,elementName:e.name,thumbnailUrl:tm(e),refCount:n.length,notesPreview:e.notes??"",revision:e.updatedAt,missing:!1}}}function om(e){return{version:1,assetKind:"element",elementId:e}}function rm(e,t){e.dataTransfer.effectAllowed="copy",e.dataTransfer.setData(to,JSON.stringify(om(t.id)))}function im({disabled:e=!1,onAdd:t}){const{t:n}=ae(),[o,r]=N.useState([]),[i,s]=N.useState("loading");return N.useEffect(()=>{let a=!0;return(async()=>{try{const c=await uc();a&&(r(c),s("ready"))}catch{a&&s("error")}})(),()=>{a=!1}},[]),h.jsxs("aside",{className:"node-element-tray","aria-label":n("nodeStudio.elements.ariaLabel"),children:[h.jsxs("header",{children:[h.jsx("strong",{children:n("nodeStudio.elements.title")}),h.jsx("span",{children:n("nodeStudio.elements.hint")})]}),i==="loading"?h.jsx("p",{role:"status",children:n("nodeStudio.elements.loading")}):null,i==="error"?h.jsx("p",{role:"alert",children:n("nodeStudio.elements.loadError")}):null,i==="ready"&&o.length===0?h.jsx("p",{children:n("nodeStudio.elements.empty")}):null,h.jsx("div",{className:"node-element-tray__list",children:o.map(a=>{const c=dc(a);return h.jsxs("article",{className:"node-element-tray__item",draggable:!e,onDragStart:l=>rm(l,a),children:[c?h.jsx("img",{src:`/generated/${c.split("/").map(encodeURIComponent).join("/")}`,alt:""}):h.jsx("span",{className:"node-element-tray__placeholder","aria-hidden":"true"}),h.jsx("span",{title:a.name,children:a.name}),h.jsx("button",{type:"button",disabled:e,onClick:()=>{t(a)},children:n("nodeStudio.elements.addToCanvas")})]},a.id)})})]})}function sm(e,t){const n=t.toLocaleLowerCase();return[e.name,...e.tags].some(o=>o.toLocaleLowerCase().includes(n))}function am({template:e}){const{t}=ae(),n=e.preview??[];return h.jsx("div",{className:"node-template-picker__preview","aria-label":t("nodeStudio.templates.previewAria",{name:e.name}),children:n.length?n.map(o=>h.jsx("span",{className:"node-template-picker__preview-node",style:{left:`${o.x}%`,top:`${o.y}%`},children:o.label},o.id)):h.jsx("span",{className:"node-template-picker__preview-empty",children:t(e.nodeCount===1?"nodeStudio.templates.nodeCountOne":"nodeStudio.templates.nodeCount",{count:e.nodeCount})})})}function Yr({template:e,selected:t,onSelect:n,onRename:o,onDelete:r,onExport:i}){const{t:s}=ae(),a=e.source==="user"&&(o||r);return h.jsxs("article",{className:`node-template-picker__card${t?" is-selected":""}`,children:[h.jsxs("button",{type:"button",className:"node-template-picker__card-main",onClick:n,onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),n())},"aria-pressed":t,children:[h.jsx(am,{template:e}),h.jsxs("span",{className:"node-template-picker__card-copy",children:[h.jsx("strong",{children:e.name}),h.jsx("span",{children:e.description}),h.jsxs("small",{children:[s(e.nodeCount===1?"nodeStudio.templates.nodeCountOne":"nodeStudio.templates.nodeCount",{count:e.nodeCount})," · ",s(e.terminalCount===1?"nodeStudio.templates.outputCountOne":"nodeStudio.templates.outputCount",{count:e.terminalCount})]})]})]}),h.jsx("div",{className:"node-template-picker__tags",children:e.tags.map(c=>h.jsx("span",{children:c},c))}),i||a?h.jsxs("div",{className:"node-template-picker__card-actions",children:[i?h.jsx("button",{type:"button",onClick:i,children:s("nodeStudio.templates.export")}):null,e.source==="user"&&o?h.jsx("button",{type:"button",onClick:o,children:s("nodeStudio.templates.rename")}):null,e.source==="user"&&r?h.jsx("button",{type:"button",onClick:r,children:s("nodeStudio.templates.delete")}):null]}):null]})}function cm({templates:e,loading:t=!1,error:n=null,onCopy:o,onClose:r,onRename:i,onDelete:s,onExport:a,onImport:c,importError:l=null}){const{t:u}=ae(),f=N.useRef(null),[d,p]=N.useState(""),[g,v]=N.useState(null),w=N.useMemo(()=>e.filter(E=>sm(E,d)),[d,e]),x=w.find(E=>E.id===g)??null,S=w.filter(E=>E.source==="seed"),m=w.filter(E=>E.source==="user"),y=()=>{x&&o(x)},I=E=>{const A=E.target.files?.[0];E.target.value="",A&&c?.(A)},b=E=>a?()=>a(E):void 0,C=E=>{window.confirm(u("nodeStudio.templates.deleteConfirm",{name:E.name}))&&s?.(E)};return h.jsxs("section",{className:"node-template-picker",role:"dialog","aria-modal":"true","aria-labelledby":"node-template-picker-title",children:[h.jsxs("header",{children:[h.jsxs("div",{children:[h.jsx("p",{className:"node-template-picker__eyebrow",children:u("nodeStudio.name")}),h.jsx("h2",{id:"node-template-picker-title",children:u("nodeStudio.templates.title")})]}),h.jsx("button",{type:"button","aria-label":u("nodeStudio.templates.close"),onClick:r,children:"×"})]}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:u("nodeStudio.templates.searchLabel")}),h.jsx("input",{autoFocus:!0,value:d,onChange:E=>p(E.target.value),placeholder:u("nodeStudio.templates.searchPlaceholder")})]}),t?h.jsx("p",{className:"node-template-picker__state",role:"status",children:u("nodeStudio.templates.loading")}):null,n?h.jsx("p",{className:"node-template-picker__state is-error",role:"alert",children:n}):null,!t&&!n&&w.length===0?h.jsx("p",{className:"node-template-picker__state",children:u("nodeStudio.templates.empty",{query:d})}):null,!t&&!n?h.jsxs("div",{className:"node-template-picker__sections",children:[S.length?h.jsxs("section",{children:[h.jsx("h3",{children:u("nodeStudio.templates.starter")}),h.jsx("div",{className:"node-template-picker__grid",children:S.map(E=>h.jsx(Yr,{template:E,selected:E.id===g,onSelect:()=>v(E.id),onExport:b(E)},E.id))})]}):null,m.length?h.jsxs("section",{children:[h.jsx("h3",{children:u("nodeStudio.templates.yours")}),h.jsx("div",{className:"node-template-picker__grid",children:m.map(E=>h.jsx(Yr,{template:E,selected:E.id===g,onSelect:()=>v(E.id),onRename:i?()=>i(E):void 0,onDelete:s?()=>C(E):void 0,onExport:b(E)},E.id))})]}):null]}):null,l?h.jsx("p",{className:"node-template-picker__state is-error",role:"alert",children:l}):null,h.jsxs("footer",{children:[c?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",title:u("nodeStudio.templates.importHint"),onClick:()=>f.current?.click(),children:u("nodeStudio.templates.import")}),h.jsx("input",{ref:f,type:"file",accept:"application/json,.json",hidden:!0,onChange:I,"aria-label":u("nodeStudio.templates.import")})]}):null,h.jsx("button",{type:"button",onClick:r,children:u("nodeStudio.templates.cancel")}),h.jsx("button",{type:"button",className:"node-template-picker__copy",disabled:!x,onClick:y,children:u("nodeStudio.templates.copy")})]})]})}function Xr({children:e,onClose:t}){const n=fc(!0,t);return h.jsx("div",{ref:n,className:"node-studio-dialog-backdrop",onPointerDown:o=>{o.target===o.currentTarget&&t()},children:e})}function lm({studio:e,graphEmpty:t,disabled:n,onAddRoot:o}){const{t:r}=ae();return h.jsxs(h.Fragment,{children:[h.jsxs(Ke,{position:"top-right",className:"node-studio-toolbar",children:[h.jsx("button",{type:"button",disabled:n,onClick:o,children:r("nodeStudio.toolbar.addImage")}),h.jsx("button",{type:"button",disabled:n,onClick:e.openTemplates,children:r("nodeStudio.toolbar.templates")}),h.jsx("button",{type:"button",disabled:n||t,onClick:e.saveTemplate,children:r("nodeStudio.toolbar.saveTemplate")}),h.jsx("button",{type:"button",disabled:n||!e.selectedSource,onClick:e.openBranch,children:r("nodeStudio.toolbar.branch")})]}),h.jsx(Ke,{position:"top-left",className:"node-studio-element-panel",children:h.jsx(im,{disabled:n,onAdd:e.addElement})}),h.jsx(Gg,{open:!!e.palette,anchor:e.palette?.anchor??{clientX:0,clientY:0},sourcePort:e.palette?.sourcePort,commands:e.commands,onInsert:e.insertCommand,onClose:e.closePalette}),e.templateOpen?h.jsx(Xr,{onClose:e.closeOverlays,children:h.jsx(cm,{templates:e.templates,loading:e.templateLoading,error:e.templateError,importError:e.importError,onCopy:e.copyTemplate,onRename:e.renameTemplate,onDelete:e.removeTemplate,onExport:e.exportTemplate,onImport:e.importTemplate,onClose:e.closeOverlays})}):null,e.branchOpen&&e.selectedSource?h.jsx(Xr,{onClose:e.closeOverlays,children:h.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"node-branch-dialog-title",children:h.jsx(zg,{sourceLabel:e.selectedSource.data.prompt||e.selectedSource.id,onApply:e.applyBranch,onClose:e.closeOverlays})})}):null,h.jsx("div",{className:"node-studio-status",role:"status","aria-live":"polite","aria-atomic":"true",children:e.status})]})}const um=[{type:"image-generate",label:"Image generation",description:"Add an image node to the workflow.",category:"generate",keywords:["image","generate","prompt"],inputPorts:[{id:"image-input",type:"image"}],outputPorts:[{id:"image-output",type:"image"}],createData:()=>({})}];function Zs(e){return e instanceof HTMLElement&&e.matches("input, textarea, select, [contenteditable=true]")}function dm(e,t){return e===t||e instanceof HTMLElement&&e.classList.contains("react-flow__pane")}function fm(e,t,n){return Zs(e.target)||!dm(e.target,t)?!1:e.key==="/"||e.key===" "&&n}function hm(e){return Zs(e.target)||!(e.metaKey||e.ctrlKey)||e.altKey||e.key!=="z"&&e.key!=="Z"?null:e.shiftKey?"redo":"undo"}function pm(e){const t=e?.getBoundingClientRect();return t?{clientX:t.left+t.width/2,clientY:t.top+Math.min(180,t.height/2)}:{clientX:320,clientY:180}}const gm=320,mm=420;function Ln(){return{nodes:[],edges:[],createdNodeIds:[],createdEdgeIds:[]}}function ym(e){return new Set(e.map(t=>t.id)).size===e.length}function no(e,t){let n=1,o=e;for(;t.has(o);)o=`${e}-${n++}`;return t.add(o),o}function xm(e){return JSON.parse(JSON.stringify(e))}function wm(e,t,n,o){const r=(t-.5)*gm;return{x:Math.max(0,...o.nodes.map(s=>s.position.x))+mm,y:e.position.y+r}}function Wr(e,t,n,o,r){const i={...xm(e.data),...r?n.settingsPatch:{},clientId:t,serverNodeId:null,parentServerNodeId:null,pendingRequestId:null,pendingPhase:null,status:"empty"};return r&&n.provider&&(i.provider=n.provider),{...e,id:t,position:o,data:i}}function Zr(e,t,n,o){const r=no(`${t}:${e.sourceHandle??"auto"}->${n}:${e.targetHandle??"auto"}`,o);return{...e,id:r,source:t,target:n}}function vm(e){const t=e.graph.nodes.find(i=>i.id===e.sourceNodeId),n=e.graph.edges.find(i=>i.source===e.sourceNodeId),o=n&&e.graph.nodes.find(i=>i.id===n.target),r=o?e.graph.edges.filter(i=>i.target===o.id):[];return t&&o&&r.length>0?{generator:o,inputEdges:r}:null}function bm(e){if(e.variants.length<2||e.variants.length>4||!ym(e.variants))return Ln();const t=vm(e);if(!t)return Ln();const n=new Set(e.graph.nodes.map(c=>c.id)),o=new Set(e.graph.edges.map(c=>c.id)),r=e.graph.edges.find(c=>c.source===t.generator.id),i=r&&e.graph.nodes.find(c=>c.id===r.target);if(r&&!i)return Ln();const s=[],a=[];for(const[c,l]of e.variants.entries()){const u=no(`${t.generator.id}-branch-${l.id}`,n),f=wm(t.generator,c,e.axis,e.graph),d=Wr(t.generator,u,l,f,!0);s.push(d);for(const p of t.inputEdges)a.push(Zr(p,p.source,u,o));if(i&&r){const p=no(`${i.id}-branch-${l.id}`,n),g={x:f.x+i.position.x-t.generator.position.x,y:f.y+i.position.y-t.generator.position.y},v=Wr(i,p,l,g,!1);s.push(v),a.push(Zr(r,u,p,o))}}return{nodes:s,edges:a,createdNodeIds:s.map(c=>c.id),createdEdgeIds:a.map(c=>c.id)}}function _m(e){const{t}=ae(),[n,o]=N.useState(!1),r=N.useMemo(()=>{const s=e.nodes.filter(a=>a.selected&&a.type==="imageNode");return s.length===1&&e.edges.some(a=>a.source===s[0].id)?s[0]:null},[e.edges,e.nodes]),i=N.useCallback(s=>{if(!r){e.showToast(t("nodeStudio.branch.selectSourceError"),!0);return}const a=bm({graph:{nodes:e.nodes,edges:e.edges},sourceNodeId:r.id,variants:s,axis:"horizontal"}),c=Qg({nodes:e.nodes,edges:e.edges},a);if(!c.ok||!wn({...c.graph,reason:"branch"})){e.showToast(t("nodeStudio.branch.applyError"),!0);return}o(!1),e.restoreFocus(),requestAnimationFrame(()=>{e.fitView({padding:.16,duration:180})})},[e,r,t]);return{branchOpen:n,selectedSource:r,setBranchOpen:o,applyBranch:i}}const Gr=["target-top","target-right","target-bottom","target-left"],Ur=["source-top","source-right","source-bottom","source-left"],Sm=[...Gr.map(e=>({nodeType:"imageNode",flowHandleId:e,logicalPortId:"image-input",direction:"input",type:"image",acceptsMany:!0,equivalentHandleIds:Gr})),...Ur.map(e=>({nodeType:"imageNode",flowHandleId:e,logicalPortId:"image-output",direction:"output",type:"image",acceptsMany:!0,equivalentHandleIds:Ur})),{nodeType:"elementReferenceNode",flowHandleId:"refs",logicalPortId:"element-refs-output",direction:"output",type:"element-refs",acceptsMany:!0,equivalentHandleIds:["refs"]},{nodeType:"elementReferenceNode",flowHandleId:"notes",logicalPortId:"element-notes-output",direction:"output",type:"element-notes",acceptsMany:!0,equivalentHandleIds:["notes"]}];function rt(e,t,n){if(!t)return null;const o=e.type==="elementReferenceNode"?"elementReferenceNode":e.type==="imageNode"?"imageNode":null;if(!o)return null;const r=Sm.find(i=>i.nodeType===o&&i.flowHandleId===t&&i.direction===n);return r?{nodeId:e.id,handleId:r.flowHandleId,logicalPortId:r.logicalPortId,equivalentHandleIds:r.equivalentHandleIds,direction:r.direction,type:r.type,acceptsMany:r.acceptsMany}:null}const qr="source-",Em="target-";function Gs(e,t){const n=e.targetHandle;if(!n?.startsWith(qr))return e;const o=t.find(i=>i.id===e.target);if(!o||o.type!=="imageNode")return e;const r=Em+n.slice(qr.length);return rt(o,r,"input")?{...e,targetHandle:r}:e}function Nm(e,t,n){const o=Gs(e,t),r=t.find(c=>c.id===o.source),i=t.find(c=>c.id===o.target);if(!r||!i)return!1;const s=rt(r,o.sourceHandle,"output"),a=rt(i,o.targetHandle,"input");return!s||!a?!1:Ys(s,a,{edges:n}).allowed}function Cm(e){return"changedTouches"in e?{clientX:e.changedTouches[0].clientX,clientY:e.changedTouches[0].clientY}:{clientX:e.clientX,clientY:e.clientY}}function Im(e){const[t,n]=N.useState(null),o=N.useCallback(a=>Nm(a,e.nodes,e.edges),[e]),r=N.useCallback(a=>{const c=Gs(a,e.nodes),l=e.nodes.find(g=>g.id===c.source),u=e.nodes.find(g=>g.id===c.target),f=l?rt(l,c.sourceHandle,"output"):null,d=u?rt(u,c.targetHandle,"input"):null;if(!f||!d){e.surfaceReason("UNKNOWN_PORT");return}const p=Ys(f,d,{nodes:e.nodes,edges:e.edges});if(!p.allowed){e.surfaceReason(p.reason);return}e.connectNodes(c.source,c.target,c.sourceHandle,c.targetHandle)},[e]),i=N.useCallback((a,c)=>{if(c.isValid||c.toNode||c.toHandle)return;const l=c.fromNode?e.nodes.find(f=>f.id===c.fromNode?.id):null,u=l?rt(l,c.fromHandle?.id,"output"):null;if(!u){e.surfaceReason("UNKNOWN_PORT");return}n({anchor:Cm(a),sourcePort:u})},[e]),s=N.useCallback(a=>{if(a.type!=="image-generate"||!t)return;const c=e.screenToFlowPosition({x:t.anchor.clientX,y:t.anchor.clientY}),l=Jg({graph:{nodes:e.nodes,edges:e.edges},position:c,sourcePort:t.sourcePort});if(!wn({...l,reason:"palette"})){e.surfaceReason("UNKNOWN_PORT");return}n(null),e.restoreFocus()},[e,t]);return{palette:t,setPalette:n,onConnect:r,onConnectEnd:i,insertCommand:s,isValidConnection:o}}function km(e){const{t}=ae(),n=N.useCallback(async(s,a)=>{try{const c=await hc(s),l=nm(c.asset,a);if(!l){e.showToast(t("nodeStudio.elementController.onlyElements"),!0);return}const u={nodes:[...e.nodes,l],edges:e.edges};wn({...u,reason:"element-drop"})||e.showToast(t("nodeStudio.elementController.invalid"),!0)}catch{e.showToast(t("nodeStudio.elementController.addError"),!0)}},[e,t]),o=N.useCallback(async s=>{const a=e.wrapperRef.current?.getBoundingClientRect(),c=a?{x:a.left+a.width/2,y:a.top+a.height/2}:{x:320,y:240};try{await n(s.id,e.screenToFlowPosition(c))}catch{e.showToast(t("nodeStudio.elementController.addError"),!0)}},[n,e,t]),r=N.useCallback(async s=>{s.preventDefault();const a=em(s.dataTransfer.getData(to));if(a)try{await n(a.elementId,e.screenToFlowPosition({x:s.clientX,y:s.clientY}))}catch{e.showToast(t("nodeStudio.elementController.addError"),!0)}},[n,e,t]),i=N.useCallback(s=>{s.dataTransfer.types.includes(to)&&(s.preventDefault(),s.dataTransfer.dropEffect="copy")},[]);return{addElement:o,onDropElement:r,onDragOver:i}}function Mm(e){return`${e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[Đđ]/g,"d").replace(/[^a-zA-Z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase().slice(0,80).replace(/-+$/g,"")||"template"}.ima2-template.json`}const So={"Content-Type":"application/json"};async function Tm(){try{return(await Qe("/api/node-templates")).templates}catch(e){throw e instanceof Error?e:new Error(String(e))}}async function Am(e){try{return(await Qe("/api/node-templates",{method:"POST",headers:So,body:JSON.stringify(e)})).template}catch(t){throw t instanceof Error?t:new Error(String(t))}}async function Pm(e){try{return(await Qe(`/api/node-templates/${encodeURIComponent(e)}/instantiate`,{method:"POST"})).graph}catch(t){throw t instanceof Error?t:new Error(String(t))}}async function Dm(e,t){try{return(await Qe(`/api/node-templates/${encodeURIComponent(e)}`,{method:"PATCH",headers:So,body:JSON.stringify({name:t})})).template}catch(n){throw n instanceof Error?n:new Error(String(n))}}async function jm(e){try{await Qe(`/api/node-templates/${encodeURIComponent(e)}`,{method:"DELETE"})}catch(t){throw t instanceof Error?t:new Error(String(t))}}const $m=2*1024*1024;async function Rm(e){return Qe(`/api/node-templates/${encodeURIComponent(e)}/export`)}async function Hm(e){return(await Qe("/api/node-templates/import",{method:"POST",headers:So,body:e})).template}function Lm(e){const{t}=ae(),[n,o]=N.useState(!1),[r,i]=N.useState(!1),[s,a]=N.useState(null),[c,l]=N.useState(null),[u,f]=N.useState([]),d=N.useCallback(async()=>{o(!0),i(!0),a(null),l(null);try{f(await Tm())}catch{a(t("nodeStudio.templates.loadError"))}finally{i(!1)}},[t]),p=N.useCallback(async g=>{if(!(e.nodes.length>0&&!window.confirm(t("nodeStudio.templates.replaceConfirm")))){i(!0),a(null);try{const v=Kg(await Pm(g.id));if(!wn({...v,reason:"template"})){a(t("nodeStudio.templates.invalidGraph"));return}o(!1),e.restoreFocus(),requestAnimationFrame(()=>{e.fitView({padding:.16,duration:180})})}catch{a(t("nodeStudio.templates.copyError"))}finally{i(!1)}}},[e,t]);return{templateOpen:n,templateLoading:r,templateError:s,importError:c,templates:u,setTemplateOpen:o,openTemplates:d,copyTemplate:p,setters:{setTemplates:f,setTemplateError:a,setImportError:l}}}function Om(e,t){const n=URL.createObjectURL(new Blob([t],{type:"application/json"})),o=document.createElement("a");o.href=n,o.download=e,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e3)}function zm(e,t){switch(t){case"TEMPLATE_FILE_KIND":case"TEMPLATE_FILE_INVALID":return e("nodeStudio.templates.importNotTemplate");case"TEMPLATE_FILE_VERSION":return e("nodeStudio.templates.importNewerVersion");case"TEMPLATE_FILE_TOO_LARGE":return e("nodeStudio.templates.importTooLarge");case"INVALID_TEMPLATE_GRAPH":return e("nodeStudio.templates.importInvalidGraph");case"INVALID_TEMPLATE_NAME":return e("nodeStudio.templates.importBadName");default:return e("nodeStudio.templates.importError")}}function Bm(e,t){const{t:n}=ae(),o=N.useCallback(async()=>{const c=window.prompt(n("nodeStudio.templates.namePrompt"));if(c?.trim())try{const l=await Am({name:c.trim(),graph:{nodes:e.nodes,edges:e.edges}});t.setTemplates(u=>[...u.filter(f=>f.id!==l.id),l]),e.showToast(n("nodeStudio.templates.saved"))}catch{e.showToast(n("nodeStudio.templates.saveError"),!0)}},[e,t,n]),r=N.useCallback(async c=>{const l=window.prompt(n("nodeStudio.templates.renamePrompt"),c.name);if(l?.trim())try{const u=await Dm(c.id,l.trim());t.setTemplates(f=>f.map(d=>d.id===u.id?u:d))}catch{t.setTemplateError(n("nodeStudio.templates.renameError"))}},[t,n]),i=N.useCallback(async c=>{try{await jm(c.id),t.setTemplates(l=>l.filter(u=>u.id!==c.id))}catch{t.setTemplateError(n("nodeStudio.templates.deleteError"))}},[t,n]),s=N.useCallback(async c=>{try{const l=await Rm(c.id);Om(Mm(c.name),JSON.stringify(l,null,2)),e.showToast(n("nodeStudio.templates.exported",{name:c.name}))}catch{e.showToast(n("nodeStudio.templates.exportError"),!0)}},[e,n]),a=N.useCallback(async c=>{if(c.size>$m){t.setImportError(n("nodeStudio.templates.importTooLarge"));return}try{const l=await Hm(await c.text());t.setTemplates(u=>[l,...u.filter(f=>f.id!==l.id)]),t.setImportError(null),e.showToast(n("nodeStudio.templates.imported",{name:l.name}))}catch(l){t.setImportError(zm(n,l?.code))}},[e,t,n]);return{saveTemplate:o,renameTemplate:r,removeTemplate:i,exportTemplate:s,importTemplate:a}}const Vm={SAME_DIRECTION:"nodeStudio.compatibility.sameDirection",TYPE_MISMATCH:"nodeStudio.compatibility.typeMismatch",CARDINALITY:"nodeStudio.compatibility.cardinality",SELF_EDGE:"nodeStudio.compatibility.selfEdge",DUPLICATE_EDGE:"nodeStudio.compatibility.duplicateEdge",CYCLE:"nodeStudio.compatibility.cycle",UNKNOWN_PORT:"nodeStudio.compatibility.unknownPort"};function Fm(e){const{t}=ae(),n=K(T=>T.graphNodes),o=K(T=>T.graphEdges),r=K(T=>T.sessions),i=K(T=>T.activeSessionId),s=K(T=>T.switchSession),a=K(T=>T.connectNodes),c=K(T=>T.undoGraph),l=K(T=>T.redoGraph),u=K(T=>T.showToast),{fitView:f,screenToFlowPosition:d}=mn(),[p,g]=N.useState(""),v=N.useCallback(()=>requestAnimationFrame(()=>e.current?.focus()),[e]),w=N.useCallback(T=>{const L=t(Vm[T]);g(L),u(L,!0)},[u,t]),x={nodes:n,edges:o,fitView:f,restoreFocus:v,showToast:u},S=Lm(x),m=Bm(x,S.setters),y=Im({nodes:n,edges:o,connectNodes:a,screenToFlowPosition:d,surfaceReason:w,restoreFocus:v}),I=_m(x),b=km({nodes:n,edges:o,wrapperRef:e,screenToFlowPosition:d,showToast:u}),C=N.useMemo(()=>r.filter(T=>T.id!==i&&T.nodeCount>0).sort((T,L)=>L.updatedAt-T.updatedAt)[0]??null,[i,r]),E=N.useCallback(()=>{y.setPalette(null),S.setTemplateOpen(!1),I.setBranchOpen(!1),v()},[I.setBranchOpen,y.setPalette,v,S.setTemplateOpen]),A=N.useCallback(T=>{const L=hm(T);if(L){(L==="undo"?c():l())&&(T.preventDefault(),u(t(L==="undo"?"graph.undone":"graph.redone")));return}if(T.key==="Escape"&&(y.palette||S.templateOpen||I.branchOpen)){T.preventDefault(),E();return}fm(T,e.current,n.length===0)&&(T.preventDefault(),y.setPalette({anchor:pm(e.current)}))},[I.branchOpen,E,y.palette,y.setPalette,n.length,l,u,t,S.templateOpen,c,e]),B=N.useCallback(async()=>{if(C)try{await s(C.id)}catch{u(t("nodeStudio.empty.resumeError"),!0)}},[C,u,s,t]);return{commands:um,...y,...I,...b,...S,status:p,hasRecentGraph:!!C,onKeyDown:A,resumeRecent:B,closeOverlays:E,closePalette:E,openTemplates:()=>{S.openTemplates()},saveTemplate:()=>{m.saveTemplate()},copyTemplate:S.copyTemplate,renameTemplate:T=>{m.renameTemplate(T)},removeTemplate:T=>{m.removeTemplate(T)},exportTemplate:T=>{m.exportTemplate(T)},importTemplate:T=>{m.importTemplate(T)},openBranch:()=>I.setBranchOpen(!0)}}function Ym(){const{t:e}=ae(),t=pc(),n=K(y=>y.graphNodes),o=K(y=>y.graphEdges),r=K(y=>y.setGraphNodes),i=K(y=>y.setGraphEdges),s=K(y=>y.disconnectEdges),a=K(y=>y.addRootNode),c=K(y=>y.deleteNodes),l=K(y=>y.nodeSelectionMode),u=K(y=>y.selectNodeGraph),f=K(y=>y.sessionLoading),d=N.useRef(null),p=Fm(d),g=N.useMemo(()=>({imageNode:jg,elementReferenceNode:Hg}),[]),v=N.useMemo(()=>{const y=gc(n,o),I=new Map,b=new Set(y.map(E=>E.id));for(const E of y)I.set(E.target,(I.get(E.target)??0)+1);const C=new Set;return o.map(E=>{if(!b.has(E.id))return E;const A=!C.has(E.target);return C.add(E.target),(I.get(E.target)??0)<2?E:{...E,label:e(A?"edge.roleBase":"edge.roleRef"),labelBgPadding:[6,3],labelBgStyle:{fill:A?"var(--accent)":"var(--surface-2)"},labelStyle:{fill:A?"var(--accent-ink)":"var(--text)",fontSize:11,fontWeight:600},style:A?E.style:{...E.style,strokeDasharray:"6 4"}}})},[o,n,e]),w=N.useCallback(y=>r(ds(y,n)),[n,r]),x=N.useCallback(y=>{const I=y.filter(b=>b.type==="remove").map(b=>b.id);if(I.length>0){if(l)return;s(I);return}i(fs(y,o))},[s,o,l,i]),S=N.useCallback(y=>c(y.map(I=>I.id)),[c]),m=N.useCallback((y,I)=>{l&&(y.preventDefault(),u(I.id,y.metaKey||y.ctrlKey))},[l,u]);return h.jsxs("main",{className:`node-canvas${n.length===0?" node-canvas--empty":""}`,ref:d,tabIndex:0,onKeyDown:p.onKeyDown,children:[f&&h.jsx("div",{className:"node-canvas__loading",children:e("nodeCanvas.loading")}),h.jsxs(qp,{nodes:n,edges:v,onNodesChange:w,onEdgesChange:x,onConnect:p.onConnect,onConnectEnd:p.onConnectEnd,isValidConnection:p.isValidConnection,onDragOver:p.onDragOver,onDrop:p.onDropElement,onNodesDelete:S,onNodeClick:m,nodeTypes:g,connectionMode:Ze.Loose,connectionRadius:32,selectionOnDrag:l,multiSelectionKeyCode:l?null:void 0,panOnDrag:l?[2]:!0,fitView:!0,deleteKeyCode:l?null:["Delete","Backspace"],proOptions:{hideAttribution:!0},children:[n.length===0?h.jsx("div",{className:"node-studio-empty-overlay",children:h.jsx(Lg,{hasRecentGraph:p.hasRecentGraph,onStartBlank:()=>{f||a()},onOpenTemplates:p.openTemplates,onResumeRecent:p.resumeRecent})}):null,n.length>0?h.jsx($g,{}):null,h.jsx(lm,{studio:p,graphEmpty:n.length===0,disabled:f,onAddRoot:()=>a()}),h.jsx(tg,{gap:24,size:1.6,color:"var(--node-canvas-grid)",variant:Ae.Dots}),h.jsx(cg,{className:"node-canvas__controls"}),!t&&h.jsx(_g,{pannable:!0,zoomable:!0,maskColor:"var(--minimap-mask)",nodeColor:"var(--minimap-node-fill)",nodeStrokeColor:"var(--minimap-node-stroke)",style:{background:"var(--minimap-bg)",border:"1px solid var(--minimap-border)"}})]}),n.length>0?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",className:"node-canvas__add-root",onClick:()=>a(),title:e("nodeCanvas.addRootTitle"),children:"+"}),h.jsx("div",{className:"node-canvas__hint",children:e("nodeCanvas.hint")})]}):null]})}function qm(){return h.jsx(Os,{children:h.jsx(Ym,{})})}export{qm as NodeCanvas};
6
+ `)),u=l.reduce((f,d)=>f.concat(...d),[]);return[l,u]}return[[],[]]},[e]);return N.useEffect(()=>{const c=t?.target??br,l=t?.actInsideInputWithModifier??!0;if(e!==null){const u=p=>{if(r.current=p.ctrlKey||p.metaKey||p.shiftKey||p.altKey,(!r.current||r.current&&!l)&&Vi(p))return!1;const v=Sr(p.code,a);if(i.current.add(p[v]),_r(s,i.current,!1)){const w=p.composedPath?.()?.[0]||p.target,x=w?.nodeName==="BUTTON"||w?.nodeName==="A";t.preventDefault!==!1&&(r.current||!x)&&p.preventDefault(),o(!0)}},f=p=>{const g=Sr(p.code,a);_r(s,i.current,!0)?(o(!1),i.current.clear()):i.current.delete(p[g]),p.key==="Meta"&&i.current.clear(),r.current=!1},d=()=>{i.current.clear(),o(!1)};return c?.addEventListener("keydown",u),c?.addEventListener("keyup",f),window.addEventListener("blur",d),window.addEventListener("contextmenu",d),()=>{c?.removeEventListener("keydown",u),c?.removeEventListener("keyup",f),window.removeEventListener("blur",d),window.removeEventListener("contextmenu",d)}}},[e,o]),n}function _r(e,t,n){return e.filter(o=>n||o.length===t.size).some(o=>o.every(r=>t.has(r)))}function Sr(e,t){return t.includes(e)?"code":"key"}const Nh=()=>{const e=re();return N.useMemo(()=>({zoomIn:async t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):!1},zoomOut:async t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):!1},zoomTo:async(t,n)=>{const{panZoom:o}=e.getState();return o?o.scaleTo(t,n):!1},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[o,r,i],panZoom:s}=e.getState();return s?(await s.setViewport({x:t.x??o,y:t.y??r,zoom:t.zoom??i},n),!0):!1},getViewport:()=>{const[t,n,o]=e.getState().transform;return{x:t,y:n,zoom:o}},setCenter:async(t,n,o)=>e.getState().setCenter(t,n,o),fitBounds:async(t,n)=>{const{width:o,height:r,minZoom:i,maxZoom:s,panZoom:a}=e.getState(),c=po(t,o,r,i,s,n?.padding??.1);return a?(await a.setViewport(c,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0):!1},screenToFlowPosition:(t,n={})=>{const{transform:o,snapGrid:r,snapToGrid:i,domNode:s}=e.getState();if(!s)return t;const{x:a,y:c}=s.getBoundingClientRect(),l={x:t.x-a,y:t.y-c},u=n.snapGrid??r,f=n.snapToGrid??i;return Pt(l,o,f,u)},flowToScreenPosition:t=>{const{transform:n,domNode:o}=e.getState();if(!o)return t;const{x:r,y:i}=o.getBoundingClientRect(),s=ct(t,n);return{x:s.x+r,y:s.y+i}}}),[])};function us(e,t){const n=[],o=new Map,r=[];for(const i of e)if(i.type==="add"){r.push(i);continue}else if(i.type==="remove"||i.type==="replace")o.set(i.id,[i]);else{const s=o.get(i.id);s?s.push(i):o.set(i.id,[i])}for(const i of t){const s=o.get(i.id);if(!s){n.push(i);continue}if(s[0].type==="remove")continue;if(s[0].type==="replace"){n.push({...s[0].item});continue}const a={...i};for(const c of s)Ch(c,a);n.push(a)}return r.length&&r.forEach(i=>{i.index!==void 0?n.splice(i.index,0,{...i.item}):n.push({...i.item})}),n}function Ch(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function ds(e,t){return us(e,t)}function fs(e,t){return us(e,t)}function Be(e,t){return{id:e,type:"select",selected:t}}function et(e,t=new Set,n=!1){const o=[];for(const[r,i]of e){const s=t.has(r);!(i.selected===void 0&&!s)&&i.selected!==s&&(n&&(i.selected=s),o.push(Be(i.id,s)))}return o}function Er({items:e=[],lookup:t}){const n=[],o=new Map(e.map(r=>[r.id,r]));for(const[r,i]of e.entries()){const s=t.get(i.id),a=s?.internals?.userNode??s;a!==void 0&&a!==i&&n.push({id:i.id,item:i,type:"replace"}),a===void 0&&n.push({item:i,type:"add",index:r})}for(const[r]of t)o.get(r)===void 0&&n.push({id:r,type:"remove"});return n}function Nr(e){return{id:e.id,type:"remove"}}const Ih=Hi();function kh(e,t,n={}){return hf(e,t,{...n,onError:n.onError??Ih})}const Cr=e=>Kd(e),Mh=e=>Pi(e);function hs(e){return N.forwardRef(e)}const ps=typeof window<"u"?N.useLayoutEffect:N.useEffect;function Ir(e){const[t,n]=N.useState(BigInt(0)),[o]=N.useState(()=>Th(()=>n(r=>r+BigInt(1))));return ps(()=>{const r=o.get();r.length&&(e(r),o.reset())},[t]),o}function Th(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const gs=N.createContext(null);function Ah({children:e}){const t=re(),n=N.useCallback(a=>{const{nodes:c=[],setNodes:l,hasDefaultNodes:u,onNodesChange:f,nodeLookup:d,fitViewQueued:p,onNodesChangeMiddlewareMap:g}=t.getState();let v=c;for(const x of a)v=typeof x=="function"?x(v):x;let w=Er({items:v,lookup:d});for(const x of g.values())w=x(w);u&&l(v),w.length>0?f?.(w):p&&window.requestAnimationFrame(()=>{const{fitViewQueued:x,nodes:S,setNodes:m}=t.getState();x&&m(S)})},[]),o=Ir(n),r=N.useCallback(a=>{const{edges:c=[],setEdges:l,hasDefaultEdges:u,onEdgesChange:f,edgeLookup:d}=t.getState();let p=c;for(const g of a)p=typeof g=="function"?g(p):g;u?l(p):f&&f(Er({items:p,lookup:d}))},[]),i=Ir(r),s=N.useMemo(()=>({nodeQueue:o,edgeQueue:i}),[]);return h.jsx(gs.Provider,{value:s,children:e})}function Ph(){const e=N.useContext(gs);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Dh=e=>!!e.panZoom;function mn(){const e=Nh(),t=re(),n=Ph(),o=ne(Dh),r=N.useMemo(()=>{const i=f=>t.getState().nodeLookup.get(f),s=f=>{n.nodeQueue.push(f)},a=f=>{n.edgeQueue.push(f)},c=f=>{const{nodeLookup:d,nodeOrigin:p}=t.getState(),g=Cr(f)?f:d.get(f.id),v=g.parentId?Oi(g.position,g.measured,g.parentId,d,p):g.position,w={...g,position:v,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return Et(w)},l=(f,d,p={replace:!1})=>{s(g=>g.map(v=>{if(v.id===f){const w=typeof d=="function"?d(v):d;return p.replace&&Cr(w)?w:{...v,...w}}return v}))},u=(f,d,p={replace:!1})=>{a(g=>g.map(v=>{if(v.id===f){const w=typeof d=="function"?d(v):d;return p.replace&&Mh(w)?w:{...v,...w}}return v}))};return{getNodes:()=>t.getState().nodes.map(f=>({...f})),getNode:f=>i(f)?.internals.userNode,getInternalNode:i,getEdges:()=>{const{edges:f=[]}=t.getState();return f.map(d=>({...d}))},getEdge:f=>t.getState().edgeLookup.get(f),setNodes:s,setEdges:a,addNodes:f=>{const d=Array.isArray(f)?f:[f];n.nodeQueue.push(p=>[...p,...d])},addEdges:f=>{const d=Array.isArray(f)?f:[f];n.edgeQueue.push(p=>[...p,...d])},toObject:()=>{const{nodes:f=[],edges:d=[],transform:p}=t.getState(),[g,v,w]=p;return{nodes:f.map(x=>({...x})),edges:d.map(x=>({...x})),viewport:{x:g,y:v,zoom:w}}},deleteElements:async({nodes:f=[],edges:d=[]})=>{const{nodes:p,edges:g,onNodesDelete:v,onEdgesDelete:w,triggerNodeChanges:x,triggerEdgeChanges:S,onDelete:m,onBeforeDelete:y}=t.getState(),{nodes:I,edges:b}=await nf({nodesToRemove:f,edgesToRemove:d,nodes:p,edges:g,onBeforeDelete:y}),C=b.length>0,E=I.length>0;if(C){const A=b.map(Nr);w?.(b),S(A)}if(E){const A=I.map(Nr);v?.(I),x(A)}return(E||C)&&m?.({nodes:I,edges:b}),{deletedNodes:I,deletedEdges:b}},getIntersectingNodes:(f,d=!0,p)=>{const g=Ko(f),v=g?f:c(f),w=p!==void 0;return v?(p||t.getState().nodes).filter(x=>{const S=t.getState().nodeLookup.get(x.id);if(S&&!g&&(x.id===f.id||!S.internals.positionAbsolute))return!1;const m=Et(w?x:S),y=rn(m,v);return d&&y>0||y>=m.width*m.height||y>=v.width*v.height}):[]},isNodeIntersecting:(f,d,p=!0)=>{const v=Ko(f)?f:c(f);if(!v)return!1;const w=rn(v,d);return p&&w>0||w>=d.width*d.height||w>=v.width*v.height},updateNode:l,updateNodeData:(f,d,p={replace:!1})=>{l(f,g=>{const v=typeof d=="function"?d(g):d;return p.replace?{...g,data:v}:{...g,data:{...g.data,...v}}},p)},updateEdge:u,updateEdgeData:(f,d,p={replace:!1})=>{u(f,g=>{const v=typeof d=="function"?d(g):d;return p.replace?{...g,data:v}:{...g,data:{...g.data,...v}}},p)},getNodesBounds:f=>{const{nodeLookup:d,nodeOrigin:p}=t.getState();return Qd(f,{nodeLookup:d,nodeOrigin:p})},getHandleConnections:({type:f,id:d,nodeId:p})=>Array.from(t.getState().connectionLookup.get(`${p}-${f}${d?`-${d}`:""}`)?.values()??[]),getNodeConnections:({type:f,handleId:d,nodeId:p})=>Array.from(t.getState().connectionLookup.get(`${p}${f?d?`-${f}-${d}`:`-${f}`:""}`)?.values()??[]),fitView:async f=>{const d=t.getState().fitViewResolver??sf();return t.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:d}),n.nodeQueue.push(p=>[...p]),d.promise}}},[]);return N.useMemo(()=>({...r,...e,viewportInitialized:o}),[o])}const kr=e=>e.selected,jh=typeof window<"u"?window:void 0;function $h({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=re(),{deleteElements:o}=mn(),r=Ct(e,{actInsideInputWithModifier:!1}),i=Ct(t,{target:jh});N.useEffect(()=>{if(r){const{edges:s,nodes:a}=n.getState();o({nodes:a.filter(kr),edges:s.filter(kr)}),n.setState({nodesSelectionActive:!1})}},[r]),N.useEffect(()=>{n.setState({multiSelectionActive:i})},[i])}function Rh(e){const t=re();N.useEffect(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const o=go(e.current);(o.height===0||o.width===0)&&t.getState().onError?.("004",ye.error004()),t.setState({width:o.width||500,height:o.height||500})};if(e.current){n(),window.addEventListener("resize",n);const o=new ResizeObserver(()=>n());return o.observe(e.current),()=>{window.removeEventListener("resize",n),o&&e.current&&o.unobserve(e.current)}}},[])}const yn={position:"absolute",width:"100%",height:"100%",top:0,left:0},Hh=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function Lh({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:o=!1,panActivationKeyPressed:r,panOnScrollSpeed:i=.5,panOnScrollMode:s=Ye.Free,zoomOnDoubleClick:a=!0,panOnDrag:c=!0,defaultViewport:l,translateExtent:u,minZoom:f,maxZoom:d,zoomActivationKeyCode:p,preventScrolling:g=!0,children:v,noWheelClassName:w,noPanClassName:x,onViewportChange:S,isControlledViewport:m,paneClickDistance:y,selectionOnDrag:I}){const b=re(),C=N.useRef(null),{userSelectionActive:E,lib:A,connectionInProgress:B}=ne(Hh,ie),T=Ct(p),L=N.useRef();Rh(C);const H=N.useCallback(_=>{S?.({x:_[0],y:_[1],zoom:_[2]}),m||b.setState({transform:_})},[S,m]);return N.useEffect(()=>{if(C.current){L.current=Ff({domNode:C.current,minZoom:f,maxZoom:d,translateExtent:u,viewport:l,onDraggingChange:P=>b.setState(j=>j.paneDragging===P?j:{paneDragging:P}),onPanZoomStart:(P,j)=>{const{onViewportChangeStart:$,onMoveStart:z}=b.getState();z?.(P,j),$?.(j)},onPanZoom:(P,j)=>{const{onViewportChange:$,onMove:z}=b.getState();z?.(P,j),$?.(j)},onPanZoomEnd:(P,j)=>{const{onViewportChangeEnd:$,onMoveEnd:z}=b.getState();z?.(P,j),$?.(j)}});const{x:_,y:k,zoom:M}=L.current.getViewport();return b.setState({panZoom:L.current,transform:[_,k,M],domNode:C.current.closest(".react-flow")}),()=>{L.current?.destroy()}}},[]),N.useEffect(()=>{L.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:o,panActivationKeyPressed:r,panOnScrollSpeed:i,panOnScrollMode:s,zoomOnDoubleClick:a,panOnDrag:c,zoomActivationKeyPressed:T,preventScrolling:g,noPanClassName:x,userSelectionActive:E,noWheelClassName:w,lib:A,onTransformChange:H,connectionInProgress:B,selectionOnDrag:I,paneClickDistance:y})},[e,t,n,o,r,i,s,a,c,T,g,x,E,w,A,H,B,I,y]),h.jsx("div",{className:"react-flow__renderer",ref:C,style:yn,children:v})}const Oh=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function zh(){const{userSelectionActive:e,userSelectionRect:t}=ne(Oh,ie);return e&&t?h.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const jn=(e,t)=>n=>{n.target===t.current&&e?.(n)},Bh=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function Vh({isSelecting:e,selectionKeyPressed:t,selectionMode:n=St.Full,panOnDrag:o,autoPanOnSelection:r,paneClickDistance:i,selectionOnDrag:s,onSelectionStart:a,onSelectionEnd:c,onPaneClick:l,onPaneContextMenu:u,onPaneScroll:f,onPaneMouseEnter:d,onPaneMouseMove:p,onPaneMouseLeave:g,children:v}){const w=N.useRef(0),x=re(),{userSelectionActive:S,elementsSelectable:m,dragging:y,panBy:I,autoPanSpeed:b}=ne(Bh,ie),C=m&&(e||S),E=N.useRef(null),A=N.useRef(),B=N.useRef(new Set),T=N.useRef(new Set),L=N.useRef(!1),H=N.useRef(!1),_=N.useRef({x:0,y:0}),k=N.useRef(!1),M=D=>{if(H.current||L.current||x.getState().connection.inProgress){H.current=!1,L.current=!1;return}l?.(D),x.getState().resetSelectedElements(),x.setState({nodesSelectionActive:!1})},P=D=>{if(Array.isArray(o)&&o?.includes(2)){D.preventDefault();return}u?.(D)},j=f?D=>f(D):void 0,$=D=>{H.current&&(D.stopPropagation(),H.current=!1)},z=D=>{if(D.pointerType==="touch"&&o!==!1&&!t)return;const{domNode:F,transform:U}=x.getState();if(A.current=F?.getBoundingClientRect(),!A.current)return;const K=D.target===E.current;if(!K&&!!D.target.closest(".nokey")||!e||!(s&&K||t)||D.button!==0||!D.isPrimary)return;D.target?.setPointerCapture?.(D.pointerId),H.current=!1;const{x:ee,y:te}=me(D.nativeEvent,A.current),oe=Pt({x:ee,y:te},U);x.setState({userSelectionRect:{width:0,height:0,startX:oe.x,startY:oe.y,x:ee,y:te}}),K||(D.stopPropagation(),D.preventDefault())};function O(D,F){const{userSelectionRect:U}=x.getState();if(!U)return;const{transform:K,nodeLookup:Z,edgeLookup:q,connectionLookup:ee,triggerNodeChanges:te,triggerEdgeChanges:oe,defaultEdgeOptions:ce}=x.getState(),Ne={x:U.startX,y:U.startY},{x:ve,y:be}=ct(Ne,K),Ce={startX:Ne.x,startY:Ne.y,x:D<ve?D:ve,y:F<be?F:be,width:Math.abs(D-ve),height:Math.abs(F-be)},ut=B.current,Le=T.current;B.current=new Set(fo(Z,Ce,K,n===St.Partial,!0).map(fe=>fe.id)),T.current=new Set;const Oe=ce?.selectable??!0;for(const fe of B.current){const Ie=ee.get(fe);if(Ie)for(const{edgeId:ke}of Ie.values()){const ze=q.get(ke);ze&&(ze.selectable??Oe)&&T.current.add(ke)}}if(!Qo(ut,B.current)){const fe=et(Z,B.current,!0);te(fe)}if(!Qo(Le,T.current)){const fe=et(q,T.current);oe(fe)}x.setState({userSelectionRect:Ce,userSelectionActive:!0,nodesSelectionActive:!1})}function V(){if(!r||!A.current)return;const[D,F]=ho(_.current,A.current,b);I({x:D,y:F}).then(U=>{if(!H.current||!U){w.current=requestAnimationFrame(V);return}const{x:K,y:Z}=_.current;O(K,Z),w.current=requestAnimationFrame(V)})}const G=()=>{cancelAnimationFrame(w.current),w.current=0,k.current=!1};N.useEffect(()=>()=>G(),[]);const Y=D=>{const{userSelectionRect:F,transform:U,resetSelectedElements:K}=x.getState();if(!A.current||!F)return;const{x:Z,y:q}=me(D.nativeEvent,A.current);_.current={x:Z,y:q};const ee=ct({x:F.startX,y:F.startY},U);if(!H.current){const te=t?0:i;if(Math.hypot(Z-ee.x,q-ee.y)<=te)return;K(),a?.(D)}H.current=!0,k.current||(V(),k.current=!0),O(Z,q)},W=D=>{if(!C){D.target===E.current&&x.getState().connection.inProgress&&(L.current=!0);return}D.button===0&&(D.target?.releasePointerCapture?.(D.pointerId),!S&&D.target===E.current&&x.getState().userSelectionRect&&M?.(D),x.setState({userSelectionActive:!1,userSelectionRect:null}),H.current&&(c?.(D),x.setState({nodesSelectionActive:B.current.size>0})),G())},J=D=>{D.target?.releasePointerCapture?.(D.pointerId),G()},R=o===!0||Array.isArray(o)&&o.includes(0);return h.jsxs("div",{className:se(["react-flow__pane",{draggable:R,dragging:y,selection:e}]),onClick:C?void 0:jn(M,E),onContextMenu:jn(P,E),onWheel:jn(j,E),onPointerEnter:C?void 0:d,onPointerMove:C?Y:p,onPointerUp:W,onPointerCancel:C?J:void 0,onPointerDownCapture:C?z:void 0,onClickCapture:C?$:void 0,onPointerLeave:g,ref:E,style:yn,children:[v,h.jsx(zh,{})]})}function Qn({id:e,store:t,unselect:n=!1,nodeRef:o}){const{addSelectedNodes:r,unselectNodesAndEdges:i,multiSelectionActive:s,nodeLookup:a,onError:c}=t.getState(),l=a.get(e);if(!l){c?.("012",ye.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&s)&&(i({nodes:[l],edges:[]}),requestAnimationFrame(()=>o?.current?.blur())):r([e])}function ms({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:o,nodeId:r,isSelectable:i,nodeClickDistance:s}){const a=re(),[c,l]=N.useState(!1),u=N.useRef();return N.useEffect(()=>{if(!t)return u.current=Mf({getStoreItems:()=>a.getState(),onNodeMouseDown:f=>{Qn({id:f,store:a,nodeRef:e})},onDragStart:()=>{l(!0)},onDragStop:()=>{l(!1)}}),()=>{u.current?.destroy(),u.current=void 0}},[t,a,e]),N.useEffect(()=>{t||!e.current||!u.current||u.current.update({noDragClassName:n,handleSelector:o,domNode:e.current,isSelectable:i,nodeId:r,nodeClickDistance:s})},[n,o,t,i,e,r,s]),c}const Fh=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function ys(){const e=re();return N.useCallback(n=>{const{nodeExtent:o,snapToGrid:r,snapGrid:i,nodesDraggable:s,onError:a,updateNodePositions:c,nodeLookup:l,nodeOrigin:u}=e.getState(),f=new Map,d=Fh(s),p=r?i[0]:5,g=r?i[1]:5,v=n.direction.x*p*n.factor,w=n.direction.y*g*n.factor;for(const[,x]of l){if(!d(x))continue;let S={x:x.internals.positionAbsolute.x+v,y:x.internals.positionAbsolute.y+w};r&&(S=At(S,i));const{position:m,positionAbsolute:y}=Di({nodeId:x.id,nextPosition:S,nodeLookup:l,nodeExtent:o,nodeOrigin:u,onError:a});x.position=m,x.internals.positionAbsolute=y,f.set(x.id,x)}c(f)},[])}const bo=N.createContext(null),Yh=bo.Provider;bo.Consumer;const xs=()=>N.useContext(bo),Xh=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),ws=N.createContext(null);function Wh({children:e}){const t=ne(Xh,ie);return h.jsx(ws.Provider,{value:t,children:e})}function Zh(){const e=N.useContext(ws);if(!e)throw new Error("useHandleConfig must be used within a HandleConfigProvider");return e}const Gh={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},Uh=(e,t,n)=>o=>{const{connectionClickStartHandle:r,connectionMode:i,connection:s}=o,{fromHandle:a,toHandle:c,isValid:l}=s;if(!a&&!r)return Gh;const u=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:a?.nodeId===e&&a?.id===t&&a?.type===n,connectingTo:u,clickConnecting:r?.nodeId===e&&r?.id===t&&r?.type===n,isPossibleEndHandle:i===Ze.Strict?a?.type!==n:e!==a?.nodeId||t!==a?.id,connectionInProcess:!!a,clickConnectionInProcess:!!r,valid:u&&l}};function qh({type:e="source",position:t=X.Top,isValidConnection:n,isConnectable:o=!0,isConnectableStart:r=!0,isConnectableEnd:i=!0,id:s,onConnect:a,children:c,className:l,onMouseDown:u,onTouchStart:f,...d},p){const g=s||null,v=e==="target",w=re(),x=xs(),{connectOnClick:S,noPanClassName:m,rfId:y}=Zh(),{connectingFrom:I,connectingTo:b,clickConnecting:C,isPossibleEndHandle:E,connectionInProcess:A,clickConnectionInProcess:B,valid:T}=ne(Uh(x,g,e),ie);x||w.getState().onError?.("010",ye.error010());const L=k=>{const{defaultEdgeOptions:M,onConnect:P,hasDefaultEdges:j}=w.getState(),$={...M,...k};if(j){const{edges:z,setEdges:O,onError:V}=w.getState();O(kh($,z,{onError:V}))}P?.($),a?.($)},H=k=>{if(!x)return;const M=Fi(k.nativeEvent);if(r&&(M&&k.button===0||!M)){const P=w.getState();Kn.onPointerDown(k.nativeEvent,{handleDomNode:k.currentTarget,autoPanOnConnect:P.autoPanOnConnect,connectionMode:P.connectionMode,connectionRadius:P.connectionRadius,domNode:P.domNode,nodeLookup:P.nodeLookup,lib:P.lib,isTarget:v,handleId:g,nodeId:x,flowId:P.rfId,panBy:P.panBy,cancelConnection:P.cancelConnection,onConnectStart:P.onConnectStart,onConnectEnd:(...j)=>w.getState().onConnectEnd?.(...j),updateConnection:P.updateConnection,onConnect:L,isValidConnection:n||((...j)=>w.getState().isValidConnection?.(...j)??!0),getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,autoPanSpeed:P.autoPanSpeed,dragThreshold:P.connectionDragThreshold})}M?u?.(k):f?.(k)},_=k=>{const{onClickConnectStart:M,onClickConnectEnd:P,connectionClickStartHandle:j,connectionMode:$,isValidConnection:z,lib:O,rfId:V,nodeLookup:G,connection:Y}=w.getState();if(!x||!j&&!r)return;if(!j){M?.(k.nativeEvent,{nodeId:x,handleId:g,handleType:e}),w.setState({connectionClickStartHandle:{nodeId:x,type:e,id:g}});return}const W=Bi(k.target),J=n||z,{connection:R,isValid:D}=Kn.isValid(k.nativeEvent,{handle:{nodeId:x,id:g,type:e},connectionMode:$,fromNodeId:j.nodeId,fromHandleId:j.id||null,fromType:j.type,isValidConnection:J,flowId:V,doc:W,lib:O,nodeLookup:G});D&&R&&L(R);const F=structuredClone(Y);delete F.inProgress,F.toPosition=F.toHandle?F.toHandle.position:null,P?.(k,F),w.setState({connectionClickStartHandle:null})};return h.jsx("div",{"data-handleid":g,"data-nodeid":x,"data-handlepos":t,"data-id":`${y}-${x}-${g}-${e}`,className:se(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",m,l,{source:!v,target:v,connectable:o,connectablestart:r,connectableend:i,clickconnecting:C,connectingfrom:I,connectingto:b,valid:T,connectionindicator:o&&(!A||E)&&(A||B?i:r)}]),onMouseDown:H,onTouchStart:H,onClick:S?_:void 0,ref:p,...d,children:c})}const He=N.memo(hs(qh));function Kh({data:e,isConnectable:t,sourcePosition:n=X.Bottom}){return h.jsxs(h.Fragment,{children:[e?.label,h.jsx(He,{type:"source",position:n,isConnectable:t})]})}function Qh({data:e,isConnectable:t,targetPosition:n=X.Top,sourcePosition:o=X.Bottom}){return h.jsxs(h.Fragment,{children:[h.jsx(He,{type:"target",position:n,isConnectable:t}),e?.label,h.jsx(He,{type:"source",position:o,isConnectable:t})]})}function Jh(){return null}function ep({data:e,isConnectable:t,targetPosition:n=X.Top}){return h.jsxs(h.Fragment,{children:[h.jsx(He,{type:"target",position:n,isConnectable:t}),e?.label]})}const sn={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Mr={input:Kh,default:Qh,output:ep,group:Jh};function tp(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}const np=e=>{const{width:t,height:n,x:o,y:r}=Tt(e.nodeLookup,{filter:i=>!!i.selected});return{width:ge(t)?t:null,height:ge(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${o}px,${r}px)`}};function op({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const o=re(),{width:r,height:i,transformString:s,userSelectionActive:a}=ne(np,ie),c=ys(),l=N.useRef(null);N.useEffect(()=>{n||l.current?.focus({preventScroll:!0})},[n]);const u=!a&&r!==null&&i!==null;if(ms({nodeRef:l,disabled:!u}),!u)return null;const f=e?p=>{const g=o.getState().nodes.filter(v=>v.selected);e(p,g)}:void 0,d=p=>{Object.prototype.hasOwnProperty.call(sn,p.key)&&(p.preventDefault(),c({direction:sn[p.key],factor:p.shiftKey?4:1}))};return h.jsx("div",{className:se(["react-flow__nodesselection","react-flow__container",t]),style:{transform:s},children:h.jsx("div",{ref:l,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:n?void 0:-1,onKeyDown:n?void 0:d,style:{width:r,height:i}})})}const Tr=typeof window<"u"?window:void 0,rp=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function vs({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:r,onPaneContextMenu:i,onPaneScroll:s,paneClickDistance:a,deleteKeyCode:c,selectionKeyCode:l,selectionOnDrag:u,selectionMode:f,onSelectionStart:d,onSelectionEnd:p,multiSelectionKeyCode:g,panActivationKeyCode:v,zoomActivationKeyCode:w,elementsSelectable:x,zoomOnScroll:S,zoomOnPinch:m,panOnScroll:y,panOnScrollSpeed:I,panOnScrollMode:b,zoomOnDoubleClick:C,panOnDrag:E,autoPanOnSelection:A,defaultViewport:B,translateExtent:T,minZoom:L,maxZoom:H,preventScrolling:_,onSelectionContextMenu:k,noWheelClassName:M,noPanClassName:P,disableKeyboardA11y:j,onViewportChange:$,isControlledViewport:z}){const{nodesSelectionActive:O,userSelectionActive:V}=ne(rp,ie),G=Ct(l,{target:Tr}),Y=Ct(v,{target:Tr}),W=Y||E,J=Y||y,R=u&&W!==!0,D=G||V||R;return $h({deleteKeyCode:c,multiSelectionKeyCode:g}),h.jsx(Lh,{onPaneContextMenu:i,elementsSelectable:x,zoomOnScroll:S,zoomOnPinch:m,panOnScroll:J,panActivationKeyPressed:Y,panOnScrollSpeed:I,panOnScrollMode:b,zoomOnDoubleClick:C,panOnDrag:!G&&W,defaultViewport:B,translateExtent:T,minZoom:L,maxZoom:H,zoomActivationKeyCode:w,preventScrolling:_,noWheelClassName:M,noPanClassName:P,onViewportChange:$,isControlledViewport:z,paneClickDistance:a,selectionOnDrag:R,children:h.jsxs(Vh,{onSelectionStart:d,onSelectionEnd:p,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:r,onPaneContextMenu:i,onPaneScroll:s,panOnDrag:W,autoPanOnSelection:A,isSelecting:!!D,selectionMode:f,selectionKeyPressed:G,paneClickDistance:a,selectionOnDrag:R,children:[e,O&&h.jsx(op,{onSelectionContextMenu:k,noPanClassName:P,disableKeyboardA11y:j})]})})}vs.displayName="FlowRenderer";const ip=N.memo(vs),sp=e=>t=>e?fo(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function ap(e){return ne(N.useCallback(sp(e),[e]),ie)}const cp=e=>e.updateNodeInternals;function lp(){const e=ne(cp),[t]=N.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const o=new Map;n.forEach(r=>{const i=r.target.getAttribute("data-id");o.set(i,{id:i,nodeElement:r.target,force:!0})}),e(o)}));return N.useEffect(()=>()=>{t?.disconnect()},[t]),t}function up({node:e,nodeType:t,hasDimensions:n,resizeObserver:o}){const r=re(),i=N.useRef(null),s=N.useRef(null),a=N.useRef(e.sourcePosition),c=N.useRef(e.targetPosition),l=N.useRef(t),u=n&&!!e.internals.handleBounds;return N.useEffect(()=>{i.current&&!e.hidden&&(!u||s.current!==i.current)&&(s.current&&o?.unobserve(s.current),o?.observe(i.current),s.current=i.current)},[u,e.hidden]),N.useEffect(()=>()=>{s.current&&(o?.unobserve(s.current),s.current=null)},[]),N.useEffect(()=>{if(i.current){const f=l.current!==t,d=a.current!==e.sourcePosition,p=c.current!==e.targetPosition;(f||d||p)&&(l.current=t,a.current=e.sourcePosition,c.current=e.targetPosition,r.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:i.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),i}function dp({id:e,onClick:t,onMouseEnter:n,onMouseMove:o,onMouseLeave:r,onContextMenu:i,onDoubleClick:s,nodesDraggable:a,elementsSelectable:c,nodesConnectable:l,nodesFocusable:u,resizeObserver:f,noDragClassName:d,noPanClassName:p,disableKeyboardA11y:g,rfId:v,nodeTypes:w,nodeClickDistance:x,onError:S}){const{node:m,internals:y,isParent:I}=ne(D=>{const F=D.nodeLookup.get(e),U=D.parentLookup.has(e);return{node:F,internals:F.internals,isParent:U}},ie);let b=m.type||"default",C=w?.[b]||Mr[b];C===void 0&&(S?.("003",ye.error003(b)),b="default",C=w?.default||Mr.default);const E=!!(m.draggable||a&&typeof m.draggable>"u"),A=!!(m.selectable||c&&typeof m.selectable>"u"),B=!!(m.connectable||l&&typeof m.connectable>"u"),T=!!(m.focusable||u&&typeof m.focusable>"u"),L=re(),H=Li(m),_=up({node:m,nodeType:b,hasDimensions:H,resizeObserver:f}),k=ms({nodeRef:_,disabled:m.hidden||!E,noDragClassName:d,handleSelector:m.dragHandle,nodeId:e,isSelectable:A,nodeClickDistance:x}),M=ys();if(m.hidden)return null;const P=we(m),j=tp(m),$=A||E||t||n||o||r,z=n?D=>n(D,{...y.userNode}):void 0,O=o?D=>o(D,{...y.userNode}):void 0,V=r?D=>r(D,{...y.userNode}):void 0,G=i?D=>i(D,{...y.userNode}):void 0,Y=s?D=>s(D,{...y.userNode}):void 0,W=D=>{const{selectNodesOnDrag:F,nodeDragThreshold:U}=L.getState();A&&(!F||!E||U>0)&&Qn({id:e,store:L,nodeRef:_}),t&&t(D,{...y.userNode})},J=D=>{if(!(Vi(D.nativeEvent)||g)){if(Mi.includes(D.key)&&A){const F=D.key==="Escape";Qn({id:e,store:L,unselect:F,nodeRef:_})}else if(E&&m.selected&&Object.prototype.hasOwnProperty.call(sn,D.key)){D.preventDefault();const{ariaLabelConfig:F}=L.getState();L.setState({ariaLiveMessage:F["node.a11yDescription.ariaLiveMessage"]({direction:D.key.replace("Arrow","").toLowerCase(),x:~~y.positionAbsolute.x,y:~~y.positionAbsolute.y})}),M({direction:sn[D.key],factor:D.shiftKey?4:1})}}},R=()=>{if(g||!_.current?.matches(":focus-visible"))return;const{transform:D,width:F,height:U,autoPanOnNodeFocus:K,setCenter:Z}=L.getState();if(!K)return;fo(new Map([[e,m]]),{x:0,y:0,width:F,height:U},D,!0).length>0||Z(m.position.x+P.width/2,m.position.y+P.height/2,{zoom:D[2]})};return h.jsx("div",{className:se(["react-flow__node",`react-flow__node-${b}`,{[p]:E},m.className,{selected:m.selected,selectable:A,parent:I,draggable:E,dragging:k}]),ref:_,style:{zIndex:y.z,transform:`translate(${y.positionAbsolute.x}px,${y.positionAbsolute.y}px)`,pointerEvents:$?"all":"none",visibility:H?"visible":"hidden",...m.style,...j},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:z,onMouseMove:O,onMouseLeave:V,onContextMenu:G,onClick:W,onDoubleClick:Y,onKeyDown:T?J:void 0,tabIndex:T?0:void 0,onFocus:T?R:void 0,role:m.ariaRole??(T?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${as}-${v}`,"aria-label":m.ariaLabel,...m.domAttributes,children:h.jsx(Yh,{value:e,children:h.jsx(C,{id:e,data:m.data,type:b,positionAbsoluteX:y.positionAbsolute.x,positionAbsoluteY:y.positionAbsolute.y,selected:m.selected??!1,selectable:A,draggable:E,deletable:m.deletable??!0,isConnectable:B,sourcePosition:m.sourcePosition,targetPosition:m.targetPosition,dragging:k,dragHandle:m.dragHandle,zIndex:y.z,parentId:m.parentId,...P})})})}var fp=N.memo(dp);const hp=e=>({nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function bs(e){const{nodesConnectable:t,nodesFocusable:n,elementsSelectable:o,onError:r}=ne(hp,ie),i=ap(e.onlyRenderVisibleElements),s=lp();return h.jsx("div",{className:"react-flow__nodes",style:yn,children:i.map(a=>h.jsx(fp,{id:a,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:s,nodesDraggable:e.nodesDraggable??!0,nodesConnectable:t,nodesFocusable:n,elementsSelectable:o,nodeClickDistance:e.nodeClickDistance,onError:r},a))})}bs.displayName="NodeRenderer";const pp=N.memo(bs);function gp(e){return ne(N.useCallback(n=>{if(!e)return n.edges.map(r=>r.id);const o=[];if(n.width&&n.height)for(const r of n.edges){const i=n.nodeLookup.get(r.source),s=n.nodeLookup.get(r.target);i&&s&&uf({sourceNode:i,targetNode:s,width:n.width,height:n.height,transform:n.transform})&&o.push(r.id)}return o},[e]),ie)}const mp=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return h.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},yp=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return h.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Ar={[nn.Arrow]:mp,[nn.ArrowClosed]:yp};function xp(e){const t=re();return N.useMemo(()=>Object.prototype.hasOwnProperty.call(Ar,e)?Ar[e]:(t.getState().onError?.("009",ye.error009(e)),null),[e])}const wp=({id:e,type:t,color:n,width:o=12.5,height:r=12.5,markerUnits:i="strokeWidth",strokeWidth:s,orient:a="auto-start-reverse"})=>{const c=xp(t);return c?h.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${o}`,markerHeight:`${r}`,viewBox:"-10 -10 20 20",markerUnits:i,orient:a,refX:"0",refY:"0",children:h.jsx(c,{color:n,strokeWidth:s})}):null},_s=({defaultColor:e,rfId:t})=>{const n=ne(i=>i.edges),o=ne(i=>i.defaultEdgeOptions),r=N.useMemo(()=>xf(n,{id:t,defaultColor:e,defaultMarkerStart:o?.markerStart,defaultMarkerEnd:o?.markerEnd}),[n,o,t,e]);return r.length?h.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:h.jsx("defs",{children:r.map(i=>h.jsx(wp,{id:i.id,type:i.type,color:i.color,width:i.width,height:i.height,markerUnits:i.markerUnits,strokeWidth:i.strokeWidth,orient:i.orient},i.id))})}):null};_s.displayName="MarkerDefinitions";var vp=N.memo(_s);function Ss({x:e,y:t,label:n,labelStyle:o,labelShowBg:r=!0,labelBgStyle:i,labelBgPadding:s=[2,4],labelBgBorderRadius:a=2,children:c,className:l,...u}){const[f,d]=N.useState({x:1,y:0,width:0,height:0}),p=se(["react-flow__edge-textwrapper",l]),g=N.useRef(null);return N.useEffect(()=>{if(g.current){const v=g.current.getBBox();d({x:v.x,y:v.y,width:v.width,height:v.height})}},[n]),n?h.jsxs("g",{transform:`translate(${e-f.width/2} ${t-f.height/2})`,className:p,visibility:f.width?"visible":"hidden",...u,children:[r&&h.jsx("rect",{width:f.width+2*s[0],x:-s[0],y:-s[1],height:f.height+2*s[1],className:"react-flow__edge-textbg",style:i,rx:a,ry:a}),h.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:g,style:o,children:n}),c]}):null}Ss.displayName="EdgeText";const bp=N.memo(Ss);function xn({path:e,labelX:t,labelY:n,label:o,labelStyle:r,labelShowBg:i,labelBgStyle:s,labelBgPadding:a,labelBgBorderRadius:c,interactionWidth:l=20,...u}){return h.jsxs(h.Fragment,{children:[h.jsx("path",{...u,d:e,fill:"none",className:se(["react-flow__edge-path",u.className])}),l?h.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:l,className:"react-flow__edge-interaction"}):null,o&&ge(t)&&ge(n)?h.jsx(bp,{x:t,y:n,label:o,labelStyle:r,labelShowBg:i,labelBgStyle:s,labelBgPadding:a,labelBgBorderRadius:c}):null]})}function Pr({pos:e,x1:t,y1:n,x2:o,y2:r}){return e===X.Left||e===X.Right?[.5*(t+o),n]:[t,.5*(n+r)]}function Es({sourceX:e,sourceY:t,sourcePosition:n=X.Bottom,targetX:o,targetY:r,targetPosition:i=X.Top}){const[s,a]=Pr({pos:n,x1:e,y1:t,x2:o,y2:r}),[c,l]=Pr({pos:i,x1:o,y1:r,x2:e,y2:t}),[u,f,d,p]=Yi({sourceX:e,sourceY:t,targetX:o,targetY:r,sourceControlX:s,sourceControlY:a,targetControlX:c,targetControlY:l});return[`M${e},${t} C${s},${a} ${c},${l} ${o},${r}`,u,f,d,p]}function Ns(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:i,sourcePosition:s,targetPosition:a,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:f,labelBgPadding:d,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,interactionWidth:x})=>{const[S,m,y]=Es({sourceX:n,sourceY:o,sourcePosition:s,targetX:r,targetY:i,targetPosition:a}),I=e.isInternal?void 0:t;return h.jsx(xn,{id:I,path:S,labelX:m,labelY:y,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:f,labelBgPadding:d,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,interactionWidth:x})})}const _p=Ns({isInternal:!1}),Cs=Ns({isInternal:!0});_p.displayName="SimpleBezierEdge";Cs.displayName="SimpleBezierEdgeInternal";function Is(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:i,label:s,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:f,style:d,sourcePosition:p=X.Bottom,targetPosition:g=X.Top,markerEnd:v,markerStart:w,pathOptions:x,interactionWidth:S})=>{const[m,y,I]=Gn({sourceX:n,sourceY:o,sourcePosition:p,targetX:r,targetY:i,targetPosition:g,borderRadius:x?.borderRadius,offset:x?.offset,stepPosition:x?.stepPosition}),b=e.isInternal?void 0:t;return h.jsx(xn,{id:b,path:m,labelX:y,labelY:I,label:s,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:f,style:d,markerEnd:v,markerStart:w,interactionWidth:S})})}const ks=Is({isInternal:!1}),Ms=Is({isInternal:!0});ks.displayName="SmoothStepEdge";Ms.displayName="SmoothStepEdgeInternal";function Ts(e){return N.memo(({id:t,...n})=>{const o=e.isInternal?void 0:t;return h.jsx(ks,{...n,id:o,pathOptions:N.useMemo(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const Sp=Ts({isInternal:!1}),As=Ts({isInternal:!0});Sp.displayName="StepEdge";As.displayName="StepEdgeInternal";function Ps(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:i,label:s,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:f,style:d,markerEnd:p,markerStart:g,interactionWidth:v})=>{const[w,x,S]=Zi({sourceX:n,sourceY:o,targetX:r,targetY:i}),m=e.isInternal?void 0:t;return h.jsx(xn,{id:m,path:w,labelX:x,labelY:S,label:s,labelStyle:a,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:f,style:d,markerEnd:p,markerStart:g,interactionWidth:v})})}const Ep=Ps({isInternal:!1}),Ds=Ps({isInternal:!0});Ep.displayName="StraightEdge";Ds.displayName="StraightEdgeInternal";function js(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:i,sourcePosition:s=X.Bottom,targetPosition:a=X.Top,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:f,labelBgPadding:d,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,pathOptions:x,interactionWidth:S})=>{const[m,y,I]=Xi({sourceX:n,sourceY:o,sourcePosition:s,targetX:r,targetY:i,targetPosition:a,curvature:x?.curvature}),b=e.isInternal?void 0:t;return h.jsx(xn,{id:b,path:m,labelX:y,labelY:I,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:f,labelBgPadding:d,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,interactionWidth:S})})}const Np=js({isInternal:!1}),$s=js({isInternal:!0});Np.displayName="BezierEdge";$s.displayName="BezierEdgeInternal";const Dr={default:$s,straight:Ds,step:As,smoothstep:Ms,simplebezier:Cs},jr={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},Cp=(e,t,n)=>n===X.Left?e-t:n===X.Right?e+t:e,Ip=(e,t,n)=>n===X.Top?e-t:n===X.Bottom?e+t:e,$r="react-flow__edgeupdater";function Rr({position:e,centerX:t,centerY:n,radius:o=10,onMouseDown:r,onMouseEnter:i,onMouseOut:s,type:a}){return h.jsx("circle",{onMouseDown:r,onMouseEnter:i,onMouseOut:s,className:se([$r,`${$r}-${a}`]),cx:Cp(t,o,e),cy:Ip(n,o,e),r:o,stroke:"transparent",fill:"transparent"})}function kp({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:o,sourceY:r,targetX:i,targetY:s,sourcePosition:a,targetPosition:c,onReconnect:l,onReconnectStart:u,onReconnectEnd:f,setReconnecting:d,setUpdateHover:p}){const g=re(),v=(y,I)=>{if(y.button!==0)return;const{autoPanOnConnect:b,domNode:C,connectionMode:E,connectionRadius:A,lib:B,onConnectStart:T,cancelConnection:L,nodeLookup:H,rfId:_,panBy:k,updateConnection:M}=g.getState(),P=I.type==="target",j=(O,V)=>{d(!1),f?.(O,n,I.type,V)},$=O=>l?.(n,O),z=(O,V)=>{d(!0),u?.(y,n,I.type),T?.(O,V)};Kn.onPointerDown(y.nativeEvent,{autoPanOnConnect:b,connectionMode:E,connectionRadius:A,domNode:C,handleId:I.id,nodeId:I.nodeId,nodeLookup:H,isTarget:P,edgeUpdaterType:I.type,lib:B,flowId:_,cancelConnection:L,panBy:k,isValidConnection:(...O)=>g.getState().isValidConnection?.(...O)??!0,onConnect:$,onConnectStart:z,onConnectEnd:(...O)=>g.getState().onConnectEnd?.(...O),onReconnectEnd:j,updateConnection:M,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:y.currentTarget})},w=y=>v(y,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),x=y=>v(y,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),S=()=>p(!0),m=()=>p(!1);return h.jsxs(h.Fragment,{children:[(e===!0||e==="source")&&h.jsx(Rr,{position:a,centerX:o,centerY:r,radius:t,onMouseDown:w,onMouseEnter:S,onMouseOut:m,type:"source"}),(e===!0||e==="target")&&h.jsx(Rr,{position:c,centerX:i,centerY:s,radius:t,onMouseDown:x,onMouseEnter:S,onMouseOut:m,type:"target"})]})}function Mp({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:o,onClick:r,onDoubleClick:i,onContextMenu:s,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,reconnectRadius:u,onReconnect:f,onReconnectStart:d,onReconnectEnd:p,rfId:g,edgeTypes:v,noPanClassName:w,onError:x,disableKeyboardA11y:S}){let m=ne(Z=>Z.edgeLookup.get(e));const y=ne(Z=>Z.defaultEdgeOptions);m=y?{...y,...m}:m;let I=m.type||"default",b=v?.[I]||Dr[I];b===void 0&&(x?.("011",ye.error011(I)),I="default",b=v?.default||Dr.default);const C=!!(m.focusable||t&&typeof m.focusable>"u"),E=typeof f<"u"&&(m.reconnectable||n&&typeof m.reconnectable>"u"),A=!!(m.selectable||o&&typeof m.selectable>"u"),B=N.useRef(null),[T,L]=N.useState(!1),[H,_]=N.useState(!1),k=re(),{zIndex:M=m.zIndex,sourceX:P,sourceY:j,targetX:$,targetY:z,sourcePosition:O,targetPosition:V}=ne(N.useCallback(Z=>{const q=Z.nodeLookup.get(m.source),ee=Z.nodeLookup.get(m.target);if(!q||!ee)return jr;const te=yf({id:e,sourceNode:q,targetNode:ee,sourceHandle:m.sourceHandle||null,targetHandle:m.targetHandle||null,connectionMode:Z.connectionMode,onError:x}),oe=lf({selected:m.selected,zIndex:m.zIndex,sourceNode:q,targetNode:ee,elevateOnSelect:Z.elevateEdgesOnSelect,zIndexMode:Z.zIndexMode});return{...te||jr,zIndex:oe}},[m.source,m.target,m.sourceHandle,m.targetHandle,m.selected,m.zIndex,x]),ie),G=N.useMemo(()=>m.markerStart?`url('#${Un(m.markerStart,g)}')`:void 0,[m.markerStart,g]),Y=N.useMemo(()=>m.markerEnd?`url('#${Un(m.markerEnd,g)}')`:void 0,[m.markerEnd,g]);if(m.hidden||P===null||j===null||$===null||z===null)return null;const W=Z=>{const{addSelectedEdges:q,unselectNodesAndEdges:ee,multiSelectionActive:te}=k.getState();A&&(k.setState({nodesSelectionActive:!1}),m.selected&&te?(ee({nodes:[],edges:[m]}),B.current?.blur()):q([e])),r&&r(Z,m)},J=i?Z=>{i(Z,{...m})}:void 0,R=s?Z=>{s(Z,{...m})}:void 0,D=a?Z=>{a(Z,{...m})}:void 0,F=c?Z=>{c(Z,{...m})}:void 0,U=l?Z=>{l(Z,{...m})}:void 0,K=Z=>{if(!S&&Mi.includes(Z.key)&&A){const{unselectNodesAndEdges:q,addSelectedEdges:ee}=k.getState();Z.key==="Escape"?(B.current?.blur(),q({edges:[m]})):ee([e])}};return h.jsx("svg",{style:{zIndex:M},children:h.jsxs("g",{className:se(["react-flow__edge",`react-flow__edge-${I}`,m.className,w,{selected:m.selected,animated:m.animated,inactive:!A&&!r,updating:T,selectable:A}]),onClick:W,onDoubleClick:J,onContextMenu:R,onMouseEnter:D,onMouseMove:F,onMouseLeave:U,onKeyDown:C?K:void 0,tabIndex:C?0:void 0,role:m.ariaRole??(C?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":m.ariaLabel===null?void 0:m.ariaLabel||`Edge from ${m.source} to ${m.target}`,"aria-describedby":C?`${cs}-${g}`:void 0,ref:B,...m.domAttributes,children:[!H&&h.jsx(b,{id:e,source:m.source,target:m.target,type:m.type,selected:m.selected,animated:m.animated,selectable:A,deletable:m.deletable??!0,label:m.label,labelStyle:m.labelStyle,labelShowBg:m.labelShowBg,labelBgStyle:m.labelBgStyle,labelBgPadding:m.labelBgPadding,labelBgBorderRadius:m.labelBgBorderRadius,sourceX:P,sourceY:j,targetX:$,targetY:z,sourcePosition:O,targetPosition:V,data:m.data,style:m.style,sourceHandleId:m.sourceHandle,targetHandleId:m.targetHandle,markerStart:G,markerEnd:Y,pathOptions:"pathOptions"in m?m.pathOptions:void 0,interactionWidth:m.interactionWidth}),E&&h.jsx(kp,{edge:m,isReconnectable:E,reconnectRadius:u,onReconnect:f,onReconnectStart:d,onReconnectEnd:p,sourceX:P,sourceY:j,targetX:$,targetY:z,sourcePosition:O,targetPosition:V,setUpdateHover:L,setReconnecting:_})]})})}var Tp=N.memo(Mp);const Ap=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Rs({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:o,noPanClassName:r,onReconnect:i,onEdgeContextMenu:s,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,reconnectRadius:f,onEdgeDoubleClick:d,onReconnectStart:p,onReconnectEnd:g,disableKeyboardA11y:v}){const{edgesFocusable:w,edgesReconnectable:x,elementsSelectable:S,onError:m}=ne(Ap,ie),y=gp(t);return h.jsxs("div",{className:"react-flow__edges",children:[h.jsx(vp,{defaultColor:e,rfId:n}),y.map(I=>h.jsx(Tp,{id:I,edgesFocusable:w,edgesReconnectable:x,elementsSelectable:S,noPanClassName:r,onReconnect:i,onContextMenu:s,onMouseEnter:a,onMouseMove:c,onMouseLeave:l,onClick:u,reconnectRadius:f,onDoubleClick:d,onReconnectStart:p,onReconnectEnd:g,rfId:n,onError:m,edgeTypes:o,disableKeyboardA11y:v},I))]})}Rs.displayName="EdgeRenderer";const Pp=N.memo(Rs),Hr=e=>`translate(${e[0]}px,${e[1]}px) scale(${e[2]})`;function Dp({children:e}){const t=re(),n=N.useRef(null),[o]=N.useState(()=>t.getState().transform);return ps(()=>{let r=null;const i=()=>{const s=t.getState().transform;r&&s[0]===r[0]&&s[1]===r[1]&&s[2]===r[2]||(r=s,n.current&&(n.current.style.transform=Hr(s)))};return i(),t.subscribe(i)},[t]),h.jsx("div",{ref:n,className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:Hr(o)},children:e})}function jp(e){const t=mn(),n=N.useRef(!1);N.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const $p=e=>e.panZoom?.syncViewport;function Rp(e){const t=ne($p),n=re();return N.useEffect(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function Hp(e){return e.connection.inProgress?{...e.connection,to:Pt(e.connection.to,e.transform)}:{...e.connection}}function Lp(e){return Hp}function Op(e){const t=Lp();return ne(t,ie)}const zp=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function Bp({containerStyle:e,style:t,type:n,component:o}){const{nodesConnectable:r,width:i,height:s,isValid:a,inProgress:c}=ne(zp,ie);return!(i&&r&&c)?null:h.jsx("svg",{style:e,width:i,height:s,className:"react-flow__connectionline react-flow__container",children:h.jsx("g",{className:se(["react-flow__connection",zi(a)]),children:h.jsx(Hs,{style:t,type:n,CustomComponent:o,isValid:a})})})}const Hs=({style:e,type:t=Re.Bezier,CustomComponent:n,isValid:o})=>{const{inProgress:r,from:i,fromNode:s,fromHandle:a,fromPosition:c,to:l,toNode:u,toHandle:f,toPosition:d,pointer:p}=Op();if(!r)return;if(n)return h.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:s,fromHandle:a,fromX:i.x,fromY:i.y,toX:l.x,toY:l.y,fromPosition:c,toPosition:d,connectionStatus:zi(o),toNode:u,toHandle:f,pointer:p});let g="";const v={sourceX:i.x,sourceY:i.y,sourcePosition:c,targetX:l.x,targetY:l.y,targetPosition:d};switch(t){case Re.Bezier:[g]=Xi(v);break;case Re.SimpleBezier:[g]=Es(v);break;case Re.Step:[g]=Gn({...v,borderRadius:0});break;case Re.SmoothStep:[g]=Gn(v);break;default:[g]=Zi(v)}return h.jsx("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};Hs.displayName="ConnectionLine";const Vp={};function Lr(e=Vp){N.useRef(e),re(),N.useEffect(()=>{},[e])}function Fp(){re(),N.useRef(!1),N.useEffect(()=>{},[])}function Ls({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:o,onEdgeClick:r,onNodeDoubleClick:i,onEdgeDoubleClick:s,onNodeMouseEnter:a,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,onSelectionContextMenu:f,onSelectionStart:d,onSelectionEnd:p,connectionLineType:g,connectionLineStyle:v,connectionLineComponent:w,connectionLineContainerStyle:x,selectionKeyCode:S,selectionOnDrag:m,selectionMode:y,multiSelectionKeyCode:I,panActivationKeyCode:b,zoomActivationKeyCode:C,deleteKeyCode:E,onlyRenderVisibleElements:A,elementsSelectable:B,defaultViewport:T,translateExtent:L,minZoom:H,maxZoom:_,preventScrolling:k,defaultMarkerColor:M,zoomOnScroll:P,zoomOnPinch:j,panOnScroll:$,panOnScrollSpeed:z,panOnScrollMode:O,zoomOnDoubleClick:V,panOnDrag:G,autoPanOnSelection:Y,onPaneClick:W,onPaneMouseEnter:J,onPaneMouseMove:R,onPaneMouseLeave:D,onPaneScroll:F,onPaneContextMenu:U,paneClickDistance:K,nodeClickDistance:Z,onEdgeContextMenu:q,onEdgeMouseEnter:ee,onEdgeMouseMove:te,onEdgeMouseLeave:oe,reconnectRadius:ce,onReconnect:Ne,onReconnectStart:ve,onReconnectEnd:be,noDragClassName:Ce,noWheelClassName:ut,noPanClassName:Le,disableKeyboardA11y:Oe,nodeExtent:fe,rfId:Ie,viewport:ke,onViewportChange:ze,nodesDraggable:vn}){return Lr(e),Lr(t),Fp(),jp(n),Rp(ke),h.jsx(ip,{onPaneClick:W,onPaneMouseEnter:J,onPaneMouseMove:R,onPaneMouseLeave:D,onPaneContextMenu:U,onPaneScroll:F,paneClickDistance:K,deleteKeyCode:E,selectionKeyCode:S,selectionOnDrag:m,selectionMode:y,onSelectionStart:d,onSelectionEnd:p,multiSelectionKeyCode:I,panActivationKeyCode:b,zoomActivationKeyCode:C,elementsSelectable:B,zoomOnScroll:P,zoomOnPinch:j,zoomOnDoubleClick:V,panOnScroll:$,panOnScrollSpeed:z,panOnScrollMode:O,panOnDrag:G,autoPanOnSelection:Y,defaultViewport:T,translateExtent:L,minZoom:H,maxZoom:_,onSelectionContextMenu:f,preventScrolling:k,noDragClassName:Ce,noWheelClassName:ut,noPanClassName:Le,disableKeyboardA11y:Oe,onViewportChange:ze,isControlledViewport:!!ke,children:h.jsxs(Dp,{children:[h.jsx(Pp,{edgeTypes:t,onEdgeClick:r,onEdgeDoubleClick:s,onReconnect:Ne,onReconnectStart:ve,onReconnectEnd:be,onlyRenderVisibleElements:A,onEdgeContextMenu:q,onEdgeMouseEnter:ee,onEdgeMouseMove:te,onEdgeMouseLeave:oe,reconnectRadius:ce,defaultMarkerColor:M,noPanClassName:Le,disableKeyboardA11y:Oe,rfId:Ie}),h.jsx(Bp,{style:v,type:g,component:w,containerStyle:x}),h.jsx("div",{className:"react-flow__edgelabel-renderer"}),h.jsx(pp,{nodeTypes:e,onNodeClick:o,onNodeDoubleClick:i,onNodeMouseEnter:a,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,nodeClickDistance:Z,onlyRenderVisibleElements:A,noPanClassName:Le,noDragClassName:Ce,disableKeyboardA11y:Oe,nodeExtent:fe,rfId:Ie,nodesDraggable:vn}),h.jsx("div",{className:"react-flow__viewport-portal"})]})})}Ls.displayName="GraphView";const Yp=N.memo(Ls),Xp=Hi(),Or=({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:r,height:i,fitView:s,fitViewOptions:a,minZoom:c=.5,maxZoom:l=2,nodeOrigin:u,nodeExtent:f,zIndexMode:d="basic"}={})=>{const p=new Map,g=new Map,v=new Map,w=new Map,x=o??t??[],S=n??e??[],m=u??[0,0],y=f??_t;qi(v,w,x);const{nodesInitialized:I}=qn(S,p,g,{nodeOrigin:m,nodeExtent:y,zIndexMode:d});let b=[0,0,1];if(s&&r&&i){const C=Tt(p,{filter:T=>!!((T.width||T.initialWidth)&&(T.height||T.initialHeight))}),{x:E,y:A,zoom:B}=po(C,r,i,c,l,a?.padding??.1);b=[E,A,B]}return{rfId:"1",width:r??0,height:i??0,transform:b,nodes:S,nodesInitialized:I,nodeLookup:p,parentLookup:g,edges:x,edgeLookup:w,connectionLookup:v,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:o!==void 0,panZoom:null,minZoom:c,maxZoom:l,translateExtent:_t,nodeExtent:y,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Ze.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:m,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:s??!1,fitViewOptions:a,fitViewResolver:null,connection:{...Ai},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Xp,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Ti,zIndexMode:d,defaultEdgeOptions:void 0,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map,onNodesDelete:void 0,onEdgesDelete:void 0,onDelete:void 0,onBeforeDelete:void 0,onViewportChangeStart:void 0,onViewportChange:void 0,onViewportChangeEnd:void 0,onNodeDragStart:void 0,onNodeDrag:void 0,onNodeDragStop:void 0,onSelectionDragStart:void 0,onSelectionDrag:void 0,onSelectionDragStop:void 0,onMoveStart:void 0,onMove:void 0,onMoveEnd:void 0,onConnect:void 0,onConnectStart:void 0,onConnectEnd:void 0,onClickConnectStart:void 0,onClickConnectEnd:void 0}},Wp=({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:r,height:i,fitView:s,fitViewOptions:a,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:f,zIndexMode:d})=>sh((p,g)=>{async function v(){const{nodeLookup:w,panZoom:x,fitViewOptions:S,fitViewResolver:m,width:y,height:I,minZoom:b,maxZoom:C}=g();x&&(await tf({nodes:w,width:y,height:I,panZoom:x,minZoom:b,maxZoom:C},S),m?.resolve(!0),p({fitViewResolver:null}))}return{...Or({nodes:e,edges:t,width:r,height:i,fitView:s,fitViewOptions:a,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:f,defaultNodes:n,defaultEdges:o,zIndexMode:d}),setNodes:w=>{const{nodeLookup:x,parentLookup:S,nodeOrigin:m,nodeExtent:y,elevateNodesOnSelect:I,fitViewQueued:b,zIndexMode:C,nodesSelectionActive:E}=g(),{nodesInitialized:A,hasSelectedNodes:B}=qn(w,x,S,{nodeOrigin:m,nodeExtent:y,elevateNodesOnSelect:I,checkEquality:!0,zIndexMode:C}),T=E&&B;b&&A?(v(),p({nodes:w,nodesInitialized:A,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:T})):p({nodes:w,nodesInitialized:A,nodesSelectionActive:T})},setEdges:w=>{const{connectionLookup:x,edgeLookup:S}=g();qi(x,S,w),p({edges:w})},setDefaultNodesAndEdges:(w,x)=>{if(w){const{setNodes:S}=g();S(w),p({hasDefaultNodes:!0})}if(x){const{setEdges:S}=g();S(x),p({hasDefaultEdges:!0})}},updateNodeInternals:w=>{const{triggerNodeChanges:x,nodeLookup:S,parentLookup:m,domNode:y,nodeOrigin:I,nodeExtent:b,debug:C,fitViewQueued:E,zIndexMode:A}=g(),{changes:B,updatedInternals:T}=Nf(w,S,m,y,I,b,A);T&&(bf(S,m,{nodeOrigin:I,nodeExtent:b,zIndexMode:A}),E?(v(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),B?.length>0&&(C&&console.log("React Flow: trigger node changes",B),x?.(B)))},updateNodePositions:(w,x=!1)=>{const S=[];let m=[];const{nodeLookup:y,triggerNodeChanges:I,connection:b,updateConnection:C,onNodesChangeMiddlewareMap:E}=g();for(const[A,B]of w){const T=y.get(A),L=!!(T?.expandParent&&T?.parentId&&B?.position),H={id:A,type:"position",position:L?{x:Math.max(0,B.position.x),y:Math.max(0,B.position.y)}:B.position,dragging:x};if(T&&b.inProgress&&b.fromNode.id===T.id){const _=qe(T,b.fromHandle,X.Left,!0);C({...b,from:_})}L&&T.parentId&&S.push({id:A,parentId:T.parentId,rect:{...B.internals.positionAbsolute,width:B.measured.width??0,height:B.measured.height??0}}),m.push(H)}if(S.length>0){const{parentLookup:A,nodeOrigin:B}=g(),T=vo(S,y,A,B);m.push(...T)}for(const A of E.values())m=A(m);I(m)},triggerNodeChanges:w=>{const{onNodesChange:x,setNodes:S,nodes:m,hasDefaultNodes:y,debug:I}=g();if(w?.length){if(y){const b=ds(w,m);S(b)}I&&console.log("React Flow: trigger node changes",w),x?.(w)}},triggerEdgeChanges:w=>{const{onEdgesChange:x,setEdges:S,edges:m,hasDefaultEdges:y,debug:I}=g();if(w?.length){if(y){const b=fs(w,m);S(b)}I&&console.log("React Flow: trigger edge changes",w),x?.(w)}},addSelectedNodes:w=>{const{multiSelectionActive:x,edgeLookup:S,nodeLookup:m,triggerNodeChanges:y,triggerEdgeChanges:I}=g();if(x){const b=w.map(C=>Be(C,!0));y(b);return}y(et(m,new Set([...w]),!0)),I(et(S))},addSelectedEdges:w=>{const{multiSelectionActive:x,edgeLookup:S,nodeLookup:m,triggerNodeChanges:y,triggerEdgeChanges:I}=g();if(x){const b=w.map(C=>Be(C,!0));I(b);return}I(et(S,new Set([...w]))),y(et(m,new Set,!0))},unselectNodesAndEdges:({nodes:w,edges:x}={})=>{const{edges:S,nodes:m,nodeLookup:y,triggerNodeChanges:I,triggerEdgeChanges:b}=g(),C=w||m,E=x||S,A=[];for(const T of C){if(!T.selected)continue;const L=y.get(T.id);L&&(L.selected=!1),A.push(Be(T.id,!1))}const B=[];for(const T of E)T.selected&&B.push(Be(T.id,!1));I(A),b(B)},setMinZoom:w=>{const{panZoom:x,maxZoom:S}=g();x?.setScaleExtent([w,S]),p({minZoom:w})},setMaxZoom:w=>{const{panZoom:x,minZoom:S}=g();x?.setScaleExtent([S,w]),p({maxZoom:w})},setTranslateExtent:w=>{g().panZoom?.setTranslateExtent(w),p({translateExtent:w})},resetSelectedElements:()=>{const{edges:w,nodes:x,triggerNodeChanges:S,triggerEdgeChanges:m,elementsSelectable:y}=g();if(!y)return;const I=x.reduce((C,E)=>E.selected?[...C,Be(E.id,!1)]:C,[]),b=w.reduce((C,E)=>E.selected?[...C,Be(E.id,!1)]:C,[]);S(I),m(b)},setNodeExtent:w=>{const{nodes:x,nodeLookup:S,parentLookup:m,nodeOrigin:y,elevateNodesOnSelect:I,nodeExtent:b,zIndexMode:C}=g();w[0][0]===b[0][0]&&w[0][1]===b[0][1]&&w[1][0]===b[1][0]&&w[1][1]===b[1][1]||(qn(x,S,m,{nodeOrigin:y,nodeExtent:w,elevateNodesOnSelect:I,checkEquality:!1,zIndexMode:C}),p({nodeExtent:w}))},panBy:w=>{const{transform:x,width:S,height:m,panZoom:y,translateExtent:I}=g();return Cf({delta:w,panZoom:y,transform:x,translateExtent:I,width:S,height:m})},setCenter:async(w,x,S)=>{const{width:m,height:y,maxZoom:I,panZoom:b}=g();if(!b)return!1;const C=typeof S?.zoom<"u"?S.zoom:I;return await b.setViewport({x:m/2-w*C,y:y/2-x*C,zoom:C},{duration:S?.duration,ease:S?.ease,interpolate:S?.interpolate}),!0},cancelConnection:()=>{p({connection:{...Ai}})},updateConnection:w=>{p({connection:w})},reset:()=>p({...Or()})}},Object.is);function Os({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:o,initialWidth:r,initialHeight:i,initialMinZoom:s,initialMaxZoom:a,initialFitViewOptions:c,fitView:l,nodeOrigin:u,nodeExtent:f,zIndexMode:d,children:p}){const[g]=N.useState(()=>Wp({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:r,height:i,fitView:l,minZoom:s,maxZoom:a,fitViewOptions:c,nodeOrigin:u,nodeExtent:f,zIndexMode:d}));return h.jsx(ah,{value:g,children:h.jsx(Ah,{children:h.jsx(Wh,{children:p})})})}function Zp({children:e,nodes:t,edges:n,defaultNodes:o,defaultEdges:r,width:i,height:s,fitView:a,fitViewOptions:c,minZoom:l,maxZoom:u,nodeOrigin:f,nodeExtent:d,zIndexMode:p}){return N.useContext(gn)?h.jsx(h.Fragment,{children:e}):h.jsx(Os,{initialNodes:t,initialEdges:n,defaultNodes:o,defaultEdges:r,initialWidth:i,initialHeight:s,fitView:a,initialFitViewOptions:c,initialMinZoom:l,initialMaxZoom:u,nodeOrigin:f,nodeExtent:d,zIndexMode:p,children:e})}const Gp={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function Up({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,className:r,nodeTypes:i,edgeTypes:s,onNodeClick:a,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:f,onMoveEnd:d,onConnect:p,onConnectStart:g,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:x,onNodeMouseEnter:S,onNodeMouseMove:m,onNodeMouseLeave:y,onNodeContextMenu:I,onNodeDoubleClick:b,onNodeDragStart:C,onNodeDrag:E,onNodeDragStop:A,onNodesDelete:B,onEdgesDelete:T,onDelete:L,onSelectionChange:H,onSelectionDragStart:_,onSelectionDrag:k,onSelectionDragStop:M,onSelectionContextMenu:P,onSelectionStart:j,onSelectionEnd:$,onBeforeDelete:z,connectionMode:O,connectionLineType:V=Re.Bezier,connectionLineStyle:G,connectionLineComponent:Y,connectionLineContainerStyle:W,deleteKeyCode:J="Backspace",selectionKeyCode:R="Shift",selectionOnDrag:D=!1,selectionMode:F=St.Full,panActivationKeyCode:U="Space",multiSelectionKeyCode:K=Nt()?"Meta":"Control",zoomActivationKeyCode:Z=Nt()?"Meta":"Control",snapToGrid:q,snapGrid:ee,onlyRenderVisibleElements:te=!1,selectNodesOnDrag:oe,nodesDraggable:ce,autoPanOnNodeFocus:Ne,nodesConnectable:ve,nodesFocusable:be,nodeOrigin:Ce=ls,edgesFocusable:ut,edgesReconnectable:Le,elementsSelectable:Oe=!0,defaultViewport:fe=vh,minZoom:Ie=.5,maxZoom:ke=2,translateExtent:ze=_t,preventScrolling:vn=!0,nodeExtent:bn,defaultMarkerColor:Us="#b1b1b7",zoomOnScroll:qs=!0,zoomOnPinch:Ks=!0,panOnScroll:Qs=!1,panOnScrollSpeed:Js=.5,panOnScrollMode:ea=Ye.Free,zoomOnDoubleClick:ta=!0,panOnDrag:na=!0,onPaneClick:oa,onPaneMouseEnter:ra,onPaneMouseMove:ia,onPaneMouseLeave:sa,onPaneScroll:aa,onPaneContextMenu:ca,paneClickDistance:la=1,nodeClickDistance:ua=0,children:da,onReconnect:fa,onReconnectStart:ha,onReconnectEnd:pa,onEdgeContextMenu:ga,onEdgeDoubleClick:ma,onEdgeMouseEnter:ya,onEdgeMouseMove:xa,onEdgeMouseLeave:wa,reconnectRadius:va=10,onNodesChange:ba,onEdgesChange:_a,noDragClassName:Sa="nodrag",noWheelClassName:Ea="nowheel",noPanClassName:Eo="nopan",fitView:No,fitViewOptions:Co,connectOnClick:Na,attributionPosition:Ca,proOptions:Ia,defaultEdgeOptions:ka,elevateNodesOnSelect:Ma=!0,elevateEdgesOnSelect:Ta=!1,disableKeyboardA11y:Io=!1,autoPanOnConnect:Aa,autoPanOnNodeDrag:Pa,autoPanOnSelection:Da=!0,autoPanSpeed:ja,connectionRadius:$a,isValidConnection:Ra,onError:Ha,style:La,id:ko,nodeDragThreshold:Oa,connectionDragThreshold:za,viewport:Ba,onViewportChange:Va,width:Fa,height:Ya,colorMode:Xa="light",debug:Wa,onScroll:Mo,ariaLabelConfig:Za,zIndexMode:To="basic",...Ga},Ua){const _n=ko||"1",qa=Eh(Xa),Ka=N.useCallback(Ao=>{Ao.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),Mo?.(Ao)},[Mo]);return h.jsx("div",{"data-testid":"rf__wrapper",...Ga,onScroll:Ka,style:{...La,...Gp},ref:Ua,className:se(["react-flow",r,qa]),id:ko,role:"application",children:h.jsxs(Zp,{nodes:e,edges:t,width:Fa,height:Ya,fitView:No,fitViewOptions:Co,minZoom:Ie,maxZoom:ke,nodeOrigin:Ce,nodeExtent:bn,zIndexMode:To,children:[h.jsx(Sh,{nodes:e,edges:t,defaultNodes:n,defaultEdges:o,onConnect:p,onConnectStart:g,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:x,nodesDraggable:ce,autoPanOnNodeFocus:Ne,nodesConnectable:ve,nodesFocusable:be,edgesFocusable:ut,edgesReconnectable:Le,elementsSelectable:Oe,elevateNodesOnSelect:Ma,elevateEdgesOnSelect:Ta,minZoom:Ie,maxZoom:ke,nodeExtent:bn,onNodesChange:ba,onEdgesChange:_a,snapToGrid:q,snapGrid:ee,connectionMode:O,translateExtent:ze,connectOnClick:Na,defaultEdgeOptions:ka,fitView:No,fitViewOptions:Co,onNodesDelete:B,onEdgesDelete:T,onDelete:L,onNodeDragStart:C,onNodeDrag:E,onNodeDragStop:A,onSelectionDrag:k,onSelectionDragStart:_,onSelectionDragStop:M,onMove:u,onMoveStart:f,onMoveEnd:d,noPanClassName:Eo,nodeOrigin:Ce,rfId:_n,autoPanOnConnect:Aa,autoPanOnNodeDrag:Pa,autoPanSpeed:ja,onError:Ha,connectionRadius:$a,isValidConnection:Ra,selectNodesOnDrag:oe,nodeDragThreshold:Oa,connectionDragThreshold:za,onBeforeDelete:z,debug:Wa,ariaLabelConfig:Za,zIndexMode:To}),h.jsx(Yp,{onInit:l,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:S,onNodeMouseMove:m,onNodeMouseLeave:y,onNodeContextMenu:I,onNodeDoubleClick:b,nodeTypes:i,edgeTypes:s,connectionLineType:V,connectionLineStyle:G,connectionLineComponent:Y,connectionLineContainerStyle:W,selectionKeyCode:R,selectionOnDrag:D,selectionMode:F,deleteKeyCode:J,multiSelectionKeyCode:K,panActivationKeyCode:U,zoomActivationKeyCode:Z,onlyRenderVisibleElements:te,defaultViewport:fe,translateExtent:ze,minZoom:Ie,maxZoom:ke,preventScrolling:vn,zoomOnScroll:qs,zoomOnPinch:Ks,zoomOnDoubleClick:ta,panOnScroll:Qs,panOnScrollSpeed:Js,panOnScrollMode:ea,panOnDrag:na,autoPanOnSelection:Da,onPaneClick:oa,onPaneMouseEnter:ra,onPaneMouseMove:ia,onPaneMouseLeave:sa,onPaneScroll:aa,onPaneContextMenu:ca,paneClickDistance:la,nodeClickDistance:ua,onSelectionContextMenu:P,onSelectionStart:j,onSelectionEnd:$,onReconnect:fa,onReconnectStart:ha,onReconnectEnd:pa,onEdgeContextMenu:ga,onEdgeDoubleClick:ma,onEdgeMouseEnter:ya,onEdgeMouseMove:xa,onEdgeMouseLeave:wa,reconnectRadius:va,defaultMarkerColor:Us,noDragClassName:Sa,noWheelClassName:Ea,noPanClassName:Eo,rfId:_n,disableKeyboardA11y:Io,nodeExtent:bn,viewport:Ba,onViewportChange:Va,nodesDraggable:ce}),h.jsx(wh,{onSelectionChange:H}),da,h.jsx(ph,{proOptions:Ia,position:Ca}),h.jsx(hh,{rfId:_n,disableKeyboardA11y:Io})]})})}var qp=hs(Up);function Kp({dimensions:e,lineWidth:t,variant:n,className:o}){return h.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:se(["react-flow__background-pattern",n,o])})}function Qp({radius:e,className:t}){return h.jsx("circle",{cx:e,cy:e,r:e,className:se(["react-flow__background-pattern","dots",t])})}var Ae;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Ae||(Ae={}));const Jp={[Ae.Dots]:1,[Ae.Lines]:1,[Ae.Cross]:6},eg=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function zs({id:e,variant:t=Ae.Dots,gap:n=20,size:o,lineWidth:r=1,offset:i=0,color:s,bgColor:a,style:c,className:l,patternClassName:u}){const f=N.useRef(null),{transform:d,patternId:p}=ne(eg,ie),g=o||Jp[t],v=t===Ae.Dots,w=t===Ae.Cross,x=Array.isArray(n)?n:[n,n],S=[x[0]*d[2]||1,x[1]*d[2]||1],m=g*d[2],y=Array.isArray(i)?i:[i,i],I=w?[m,m]:S,b=[y[0]*d[2]+I[0]/2,y[1]*d[2]+I[1]/2],C=`${p}${e||""}`;return h.jsxs("svg",{className:se(["react-flow__background",l]),style:{...c,...yn,"--xy-background-color-props":a,"--xy-background-pattern-color-props":s},ref:f,"data-testid":"rf__background",children:[h.jsx("pattern",{id:C,x:d[0]%S[0],y:d[1]%S[1],width:S[0],height:S[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${b[0]},-${b[1]})`,children:v?h.jsx(Qp,{radius:m/2,className:u}):h.jsx(Kp,{dimensions:I,lineWidth:r,variant:t,className:u})}),h.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${C})`})]})}zs.displayName="Background";const tg=N.memo(zs);function ng(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:h.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function og(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:h.jsx("path",{d:"M0 0h32v4.2H0z"})})}function rg(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:h.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function ig(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:h.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function sg(){return h.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:h.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Bt({children:e,className:t,...n}){return h.jsx("button",{type:"button",className:se(["react-flow__controls-button",t]),...n,children:e})}const ag=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Bs({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:o=!0,fitViewOptions:r,onZoomIn:i,onZoomOut:s,onFitView:a,onInteractiveChange:c,className:l,children:u,position:f="bottom-left",orientation:d="vertical","aria-label":p}){const g=re(),{isInteractive:v,minZoomReached:w,maxZoomReached:x,ariaLabelConfig:S}=ne(ag,ie),{zoomIn:m,zoomOut:y,fitView:I}=mn(),b=()=>{m(),i?.()},C=()=>{y(),s?.()},E=()=>{I(r),a?.()},A=()=>{g.setState({nodesDraggable:!v,nodesConnectable:!v,elementsSelectable:!v}),c?.(!v)},B=d==="horizontal"?"horizontal":"vertical";return h.jsxs(Ke,{className:se(["react-flow__controls",B,l]),position:f,style:e,"data-testid":"rf__controls","aria-label":p??S["controls.ariaLabel"],children:[t&&h.jsxs(h.Fragment,{children:[h.jsx(Bt,{onClick:b,className:"react-flow__controls-zoomin",title:S["controls.zoomIn.ariaLabel"],"aria-label":S["controls.zoomIn.ariaLabel"],disabled:x,children:h.jsx(ng,{})}),h.jsx(Bt,{onClick:C,className:"react-flow__controls-zoomout",title:S["controls.zoomOut.ariaLabel"],"aria-label":S["controls.zoomOut.ariaLabel"],disabled:w,children:h.jsx(og,{})})]}),n&&h.jsx(Bt,{className:"react-flow__controls-fitview",onClick:E,title:S["controls.fitView.ariaLabel"],"aria-label":S["controls.fitView.ariaLabel"],children:h.jsx(rg,{})}),o&&h.jsx(Bt,{className:"react-flow__controls-interactive",onClick:A,title:S["controls.interactive.ariaLabel"],"aria-label":S["controls.interactive.ariaLabel"],children:v?h.jsx(sg,{}):h.jsx(ig,{})}),u]})}Bs.displayName="Controls";const cg=N.memo(Bs);function lg({id:e,x:t,y:n,width:o,height:r,style:i,color:s,strokeColor:a,strokeWidth:c,className:l,borderRadius:u,shapeRendering:f,selected:d,onClick:p}){const{background:g,backgroundColor:v}=i||{},w=s||g||v;return h.jsx("rect",{className:se(["react-flow__minimap-node",{selected:d},l]),x:t,y:n,rx:u,ry:u,width:o,height:r,style:{fill:w,stroke:a,strokeWidth:c},shapeRendering:f,onClick:p?x=>p(x,e):void 0})}const ug=N.memo(lg),dg=e=>e.nodes.map(t=>t.id),$n=e=>e instanceof Function?e:()=>e;function fg({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:o=5,nodeStrokeWidth:r,nodeComponent:i=ug,onClick:s}){const a=ne(dg,ie),c=$n(t),l=$n(e),u=$n(n),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return h.jsx(h.Fragment,{children:a.map(d=>h.jsx(pg,{id:d,nodeColorFunc:c,nodeStrokeColorFunc:l,nodeClassNameFunc:u,nodeBorderRadius:o,nodeStrokeWidth:r,NodeComponent:i,onClick:s,shapeRendering:f},d))})}function hg({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:o,nodeBorderRadius:r,nodeStrokeWidth:i,shapeRendering:s,NodeComponent:a,onClick:c}){const{node:l,x:u,y:f,width:d,height:p}=ne(g=>{const v=g.nodeLookup.get(e);if(!v)return{node:void 0,x:0,y:0,width:0,height:0};const w=v.internals.userNode,{x,y:S}=v.internals.positionAbsolute,{width:m,height:y}=we(w);return{node:w,x,y:S,width:m,height:y}},ie);return!l||l.hidden||!Li(l)?null:h.jsx(a,{x:u,y:f,width:d,height:p,style:l.style,selected:!!l.selected,className:o(l),color:t(l),borderRadius:r,strokeColor:n(l),strokeWidth:i,shapeRendering:s,onClick:c,id:l.id})}const pg=N.memo(hg);var gg=N.memo(fg);const mg=200,yg=150,xg=e=>!e.hidden,wg=e=>{const t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};let n=!1;for(const o of e.nodeLookup.values())if(!o.hidden){n=!0;break}return{viewBB:t,boundingRect:n?$i(Tt(e.nodeLookup,{filter:xg}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},zr=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,vg=(e,t)=>zr(e.viewBB,t.viewBB)&&zr(e.boundingRect,t.boundingRect)&&e.rfId===t.rfId&&e.panZoom===t.panZoom&&e.translateExtent===t.translateExtent&&e.flowWidth===t.flowWidth&&e.flowHeight===t.flowHeight&&e.ariaLabelConfig===t.ariaLabelConfig,bg="react-flow__minimap-desc";function Vs({style:e,className:t,nodeStrokeColor:n,nodeColor:o,nodeClassName:r="",nodeBorderRadius:i=5,nodeStrokeWidth:s,nodeComponent:a,bgColor:c,maskColor:l,maskStrokeColor:u,maskStrokeWidth:f,position:d="bottom-right",onClick:p,onNodeClick:g,pannable:v=!1,zoomable:w=!1,ariaLabel:x,inversePan:S,zoomStep:m=1,offsetScale:y=5}){const I=re(),b=N.useRef(null),{boundingRect:C,panZoom:E,viewBB:A,rfId:B,translateExtent:T,flowWidth:L,flowHeight:H,ariaLabelConfig:_}=ne(wg,vg),k=e?.width??mg,M=e?.height??yg,P=C.width/k,j=C.height/M,$=Math.max(P,j),z=$*k,O=$*M,V=y*$,G=C.x-(z-C.width)/2-V,Y=C.y-(O-C.height)/2-V,W=z+V*2,J=O+V*2,R=`${bg}-${B}`,D=N.useRef(0),F=N.useRef();D.current=$,N.useEffect(()=>{const ee=I.getState().panZoom;if(b.current&&ee)return F.current=$f({domNode:b.current,panZoom:ee,getTransform:()=>I.getState().transform,getViewScale:()=>D.current}),()=>{F.current?.destroy()}},[E]),N.useEffect(()=>{F.current?.update({translateExtent:T,width:L,height:H,inversePan:S,pannable:v,zoomStep:m,zoomable:w})},[v,w,S,m,T,L,H]);const U=p?ee=>{const[te,oe]=F.current?.pointer(ee)||[0,0];p(ee,{x:te,y:oe})}:void 0,K=N.useCallback((ee,te)=>{const oe=I.getState().nodeLookup.get(te).internals.userNode;g?.(ee,oe)},[g]),Z=g?K:void 0,q=x??_["minimap.ariaLabel"];return h.jsx(Ke,{position:d,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof l=="string"?l:void 0,"--xy-minimap-mask-stroke-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*$:void 0,"--xy-minimap-node-background-color-props":typeof o=="string"?o:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof s=="number"?s:void 0},className:se(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:h.jsxs("svg",{width:k,height:M,viewBox:`${G} ${Y} ${W} ${J}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":R,ref:b,onClick:U,children:[q&&h.jsx("title",{id:R,children:q}),h.jsx(gg,{onClick:Z,nodeColor:o,nodeStrokeColor:n,nodeBorderRadius:i,nodeClassName:r,nodeStrokeWidth:s,nodeComponent:a}),h.jsx("path",{className:"react-flow__minimap-mask",d:`M${G-V},${Y-V}h${W+V*2}v${J+V*2}h${-W-V*2}z
7
+ M${A.x},${A.y}h${A.width}v${A.height}h${-A.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}Vs.displayName="MiniMap";const _g=N.memo(Vs),Sg=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,Eg={[lt.Line]:"right",[lt.Handle]:"bottom-right"};function Ng({nodeId:e,position:t,variant:n=lt.Handle,className:o,style:r=void 0,children:i,color:s,minWidth:a=10,minHeight:c=10,maxWidth:l=Number.MAX_VALUE,maxHeight:u=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:d,autoScale:p=!0,shouldResize:g,onResizeStart:v,onResize:w,onResizeEnd:x}){const S=xs(),m=typeof e=="string"?e:S,y=re(),I=N.useRef(null),b=n===lt.Handle,C=ne(N.useCallback(Sg(b&&p),[b,p]),ie),E=N.useRef(null),A=t??Eg[n];N.useEffect(()=>{if(!(!I.current||!m))return E.current||(E.current=Gf({domNode:I.current,nodeId:m,getStoreItems:()=>{const{nodeLookup:T,transform:L,snapGrid:H,snapToGrid:_,nodeOrigin:k,domNode:M}=y.getState();return{nodeLookup:T,transform:L,snapGrid:H,snapToGrid:_,nodeOrigin:k,paneDomNode:M}},onChange:(T,L)=>{const{triggerNodeChanges:H,nodeLookup:_,parentLookup:k,nodeOrigin:M}=y.getState(),P=[],j={x:T.x,y:T.y},$=_.get(m);if($&&$.expandParent&&$.parentId){const z=$.origin??M,O=T.width??$.measured.width??0,V=T.height??$.measured.height??0,G={id:$.id,parentId:$.parentId,rect:{width:O,height:V,...Oi({x:T.x??$.position.x,y:T.y??$.position.y},{width:O,height:V},$.parentId,_,z)}},Y=vo([G],_,k,M);P.push(...Y),j.x=T.x?Math.max(z[0]*O,T.x):void 0,j.y=T.y?Math.max(z[1]*V,T.y):void 0}if(j.x!==void 0&&j.y!==void 0){const z={id:m,type:"position",position:{...j}};P.push(z)}if(T.width!==void 0&&T.height!==void 0){const O={id:m,type:"dimensions",resizing:!0,setAttributes:d?d==="horizontal"?"width":"height":!0,dimensions:{width:T.width,height:T.height}};P.push(O)}for(const z of L){const O={...z,type:"position"};P.push(O)}H(P)},onEnd:({width:T,height:L})=>{const H={id:m,type:"dimensions",resizing:!1,dimensions:{width:T,height:L}};y.getState().triggerNodeChanges([H])}})),E.current.update({controlPosition:A,boundaries:{minWidth:a,minHeight:c,maxWidth:l,maxHeight:u},keepAspectRatio:f,resizeDirection:d,onResizeStart:v,onResize:w,onResizeEnd:x,shouldResize:g}),()=>{E.current?.destroy()}},[A,a,c,l,u,f,v,w,x,g]);const B=A.split("-");return h.jsx("div",{className:se(["react-flow__resize-control","nodrag",...B,n,o]),ref:I,style:{...r,scale:C,...s&&{[b?"backgroundColor":"borderColor"]:s}},children:i})}N.memo(Ng);function Cg({nodeId:e}){const{t}=ae(),n=Q(r=>r.showToast),o=N.useCallback(async()=>{try{await mc(e),n(t("toast.metadataCopied"))}catch{n(t("toast.copyFailed"),!0)}},[e,n,t]);return h.jsxs("div",{className:"image-node__id",title:e,children:[h.jsx("span",{className:"image-node__id-text",children:e}),h.jsx("button",{type:"button",className:"image-node__id-copy nodrag",onClick:r=>{r.stopPropagation(),o()},title:t("node.copyId"),"aria-label":t("node.copyId"),children:h.jsxs("svg",{viewBox:"0 0 24 24",width:"11",height:"11","aria-hidden":"true",children:[h.jsx("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2",fill:"none",stroke:"currentColor",strokeWidth:"1.8"}),h.jsx("path",{d:"M5 15V5.5A1.5 1.5 0 0 1 6.5 4H15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})]})})]})}const Ig=new Set(["Escape","Tab"]);function Br(e){"key"in e&&Ig.has(e.key)||e.stopPropagation()}function kg({imageUrl:e,prompt:t}){const{t:n}=ae(),[o,r]=N.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsx("img",{src:e,alt:n("node.nodeImageAlt")}),h.jsx("button",{type:"button",className:"image-node__zoom nodrag",title:n("node.zoomImage"),"aria-label":n("node.zoomImage"),onClick:i=>{i.stopPropagation(),r(!0)},children:h.jsxs("svg",{viewBox:"0 0 24 24",width:"16",height:"16","aria-hidden":"true",children:[h.jsx("circle",{cx:"10.5",cy:"10.5",r:"6.5",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),h.jsx("path",{d:"M15.5 15.5 21 21M7.5 10.5h6M10.5 7.5v6",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round"})]})}),o?ec.createPortal(h.jsx("div",{className:"nokey",onClick:Br,onKeyDown:Br,children:h.jsx(yc,{item:{image:e,url:e,prompt:t,filename:e.replace(/^\/generated\//,""),mediaType:"image"},showAssetActions:!1,onClose:()=>r(!1)})}),document.body):null]})}const Rn=5,Gt=240,Mg=180,Tg=420,Vr=[{id:"top",position:X.Top},{id:"right",position:X.Right},{id:"bottom",position:X.Bottom},{id:"left",position:X.Left}];function Ag(e,t){const n=rc({model:e.model,provider:e.provider,mediaType:Vt(e.imageUrl)?"video":"image",videoContinuity:e.videoContinuity});return n.derivation?t(`provenance.${n.derivation}`):null}function Pg(e){const t=/^(\d+)x(\d+)$/.exec(e??"");if(!t)return Gt;const n=Number(t[1]),o=Number(t[2]);if(!Number.isFinite(n)||!Number.isFinite(o)||n<=0||o<=0)return Gt;const r=Gt*(n/o);return Math.round(Math.min(Tg,Math.max(Mg,r)))}function Dg({id:e,data:t,selected:n}){const{t:o}=ae(),r=t,i=Q(R=>R.updateNodePrompt),s=Q(R=>R.addNodeReferences),a=Q(R=>R.addNodeReferenceFromUrl),c=Q(R=>R.readDroppedImageMetadata),l=Q(R=>R.removeNodeReference),u=Q(R=>R.generateNode),f=Q(R=>R.generateNodeInPlace),d=Q(R=>R.generateNodeVariation),p=Q(R=>R.animateImage),g=Q(R=>R.addChildNode),v=Q(R=>R.duplicateBranchRoot),w=Q(R=>R.deleteNode),x=N.useRef(null),[S,m]=N.useState(!1),[y,I]=N.useState(!1),b=r.referenceImages??[],C=r.status==="pending"||r.status==="reconciling",E=!C&&b.length<Rn,A={"--node-preview-w":`${Pg(r.size)}px`,"--node-preview-h":`${Gt}px`},B=N.useCallback(R=>i(e,R.target.value),[e,i]),T=N.useCallback(()=>{u(e)},[e,u]),L=N.useCallback(()=>{f(e)},[e,f]),H=N.useCallback(()=>{d(e)},[e,d]),_=N.useCallback(()=>{r.status==="ready"&&g(e)},[e,r.status,g]),k=N.useCallback(()=>{if(r.status!=="ready"||!r.imageUrl||Vt(r.imageUrl))return;const R=r.imageUrl.replace(/^\/generated\//,"");p(R,r.prompt)},[r.status,r.imageUrl,r.prompt,p]),M=N.useCallback(()=>{v(e)},[e,v]),P=N.useCallback(()=>w(e),[e,w]),j=R=>{if(!R)return[];const D=[];for(const F of Array.from(R)){if(F.kind!=="file"||!F.type.startsWith("image/"))continue;const U=F.getAsFile();U&&D.push(U)}return D},$=async R=>{R.length!==0&&(R.length===1&&await c(R[0],e)||await s(e,R))},z=async R=>{R.preventDefault(),R.stopPropagation(),m(!1);const D=R.dataTransfer.getData("application/ima2-ref");if(D){if(!E)return;try{const U=JSON.parse(D),K=U.url||U.image;K&&a(e,K,U.filename)}catch{}return}const F=Array.from(R.dataTransfer.files).filter(U=>U.type.startsWith("image/"));F.length===1&&await c(F[0],e)||E&&F.length>0&&s(e,F)},O=R=>{R.preventDefault(),R.stopPropagation(),E&&!S&&m(!0)},V=R=>{R.currentTarget.contains(R.relatedTarget)||m(!1)},G=R=>{const D=j(R.clipboardData?.items??null);if(D.length===0||(R.preventDefault(),R.stopPropagation(),!E))return;const F=Rn-b.length;s(e,D.slice(0,F))},W=(()=>{switch(r.status){case"empty":return o("node.empty");case"pending":return o("node.pending");case"reconciling":return r.pendingPhase?o("node.reconcilingPhase",{phase:r.pendingPhase}):o("node.reconciling");case"ready":return[r.webSearchCalls?o("node.readyWithSearch",{elapsed:r.elapsed??"?",searches:r.webSearchCalls}):o("node.ready",{elapsed:r.elapsed??"?"}),r.video?.duration?`${r.video.duration}s`:null,r.video?.resolution??null,r.video?.aspectRatio??null,nc(r.reasoningEffort),oc(r.model,r.provider),Ag(r,o)].filter(Boolean).join(" · ");case"stale":return r.error?o("node.staleWithError",{error:r.error}):o("node.stale");case"asset-missing":return r.error?o("node.assetMissingWithError",{error:r.error}):o("node.assetMissing");case"error":return o("node.error",{error:r.errorInfo?.message??r.error??o("node.errorUnknown")});default:return""}})(),J=r.status==="error"&&r.errorInfo?.code!=="JOB_TRACKING_TIMEOUT"?r.errorInfo?.action??"retry":null;return h.jsxs("div",{className:`image-node image-node--${r.status}${n?" image-node--selected":""}`,style:A,children:[Vr.map(({id:R,position:D})=>h.jsx(He,{type:"target",id:`target-${R}`,position:D,className:`image-node__handle image-node__handle--target image-node__handle--${R}`},`target-${R}`)),h.jsx(Cg,{nodeId:e}),h.jsx("div",{className:"image-node__preview",children:r.imageUrl&&r.status!=="asset-missing"?Vt(r.imageUrl)?h.jsx("video",{src:r.imageUrl,controls:!0,loop:!0,playsInline:!0,muted:!0,className:"image-node__video nodrag"}):h.jsx(kg,{imageUrl:r.imageUrl,prompt:r.prompt||""}):C&&r.partialImageUrl?h.jsx("img",{className:"image-node__partial",src:r.partialImageUrl,alt:o("node.partialImageAlt")}):C?h.jsx("div",{className:"image-node__skeleton"}):r.status==="asset-missing"?h.jsx("div",{className:"image-node__placeholder",children:o("node.noAsset")}):r.status==="stale"?h.jsx("div",{className:"image-node__placeholder",children:o("node.stateStale")}):h.jsx("div",{className:"image-node__placeholder",children:o("node.noImage")})}),h.jsxs("div",{className:`image-node__composer nodrag${S?" is-dragging":""}`,onDrop:z,onDragOver:O,onDragLeave:V,onPaste:G,children:[b.length>0?h.jsx("div",{className:"image-node__refs",children:b.map((R,D)=>h.jsxs("div",{className:"image-node__ref-chip",title:o("node.refAlt",{n:D+1}),children:[h.jsx("img",{src:R,alt:o("node.refAlt",{n:D+1})}),h.jsx("button",{type:"button",className:"image-node__ref-remove",onClick:()=>l(e,D),disabled:C,"aria-label":o("node.removeRef",{n:D+1}),children:"×"})]},D))}):null,h.jsx("textarea",{className:"image-node__prompt",value:r.prompt,onChange:B,onKeyDown:R=>R.stopPropagation(),placeholder:r.parentServerNodeId?o("node.editPromptPlaceholder"):o("node.promptPlaceholder"),rows:2,disabled:C}),h.jsxs("div",{className:"image-node__composer-bar",children:[h.jsx("button",{type:"button",className:"image-node__attach",onClick:()=>E&&x.current?.click(),disabled:!E,title:r.parentServerNodeId?o("node.nodeRefsUsedWithParent"):o("node.attachRefTitle"),children:o("node.attachRef")}),S?h.jsx("span",{className:"image-node__drop-hint",children:o("node.dropRefs")}):b.length>0?h.jsxs("span",{className:"image-node__ref-count",children:[b.length,"/",Rn]}):null]}),h.jsx("input",{ref:x,type:"file",accept:"image/*",multiple:!0,hidden:!0,onChange:R=>{const D=Array.from(R.target.files??[]);D.length>0&&$(D),R.target.value=""}})]}),h.jsxs("div",{className:"image-node__footer nodrag",children:[h.jsx("span",{className:"image-node__status",title:r.errorInfo?.code?`${W} [${r.errorInfo.code}]`:W,children:W}),J==="retry"?h.jsx("button",{type:"button",className:"image-node__retry",onClick:L,disabled:C,title:o("node.retryTitle"),children:o("node.retry")}):J==="auth"?h.jsx("span",{className:"image-node__error-cta",children:o("node.errorAuthCta")}):J==="fix-input"?h.jsx("span",{className:"image-node__error-cta",children:o("node.errorFixCta")}):null,h.jsxs("div",{className:"image-node__actions",children:[h.jsxs("div",{style:{position:"relative"},children:[h.jsx("button",{type:"button",onClick:()=>I(R=>!R),disabled:!r.prompt?.trim(),title:o("promptLibrary.saveTitle"),"aria-label":o("promptLibrary.saveTitle"),"aria-haspopup":"dialog","aria-expanded":y,children:h.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",width:"15",height:"15",children:h.jsx("path",{d:"M6.5 3.75h11a.75.75 0 0 1 .75.75v15.03a.5.5 0 0 1-.77.42L12 16.4l-5.48 3.55a.5.5 0 0 1-.77-.42V4.5a.75.75 0 0 1 .75-.75Z",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinejoin:"round"})})}),y&&h.jsx(tc,{text:r.prompt||"",onClose:()=>I(!1)})]}),r.status==="ready"?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",onClick:L,disabled:C,title:o("node.regenerateTitle"),"aria-label":o("node.regenerateTitle"),children:"↻"}),h.jsx("button",{type:"button",onClick:H,disabled:C,title:o("node.newVariationTitle"),"aria-label":o("node.newVariationTitle"),children:o("node.newVariation")}),!Vt(r.imageUrl)&&h.jsx("button",{type:"button",onClick:k,disabled:C,title:o("node.animateTitle",{fallback:"Animate"}),"aria-label":o("node.animateTitle",{fallback:"Animate"}),children:h.jsxs("svg",{viewBox:"0 0 24 24",width:"15",height:"15","aria-hidden":"true",children:[h.jsx("rect",{x:"3",y:"5.5",width:"18",height:"13",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6"}),h.jsx("path",{d:"M7.5 5.5v13M16.5 5.5v13M3 12h18",fill:"none",stroke:"currentColor",strokeWidth:"1.3"})]})})]}):h.jsx("button",{type:"button",className:"image-node__generate",onClick:T,disabled:C,title:o("node.generateTitle"),"aria-label":o("node.generateTitle"),children:o("node.generate")}),r.status==="ready"?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",onClick:_,title:o("node.addChildTitle"),"aria-label":o("node.addChildTitle"),children:o("node.addChild")}),h.jsx("button",{type:"button",onClick:M,title:o("node.duplicateBranchTitle"),"aria-label":o("node.duplicateBranchTitle"),children:o("node.duplicateBranch")})]}):null,h.jsx("button",{type:"button",onClick:P,className:"image-node__del",title:o("node.deleteTitle"),"aria-label":o("node.deleteTitle"),children:"×"})]})]}),Vr.map(({id:R,position:D})=>h.jsx(He,{type:"source",id:`source-${R}`,position:D,className:`image-node__handle image-node__handle--source image-node__handle--${R}`},`source-${R}`))]})}const jg=N.memo(Dg);function $g(){const{t:e}=ae(),t=Q(S=>S.graphNodes),n=Q(S=>S.graphEdges),o=Q(S=>S.nodeSelectionMode),r=Q(S=>S.nodeBatchRunning),i=Q(S=>S.nodeBatchStopping),s=Q(S=>S.toggleNodeSelectionMode),a=Q(S=>S.selectAllGraphNodes),c=Q(S=>S.clearNodeSelection),l=Q(S=>S.runNodeBatch),u=Q(S=>S.cancelNodeBatch),f=Q(S=>S.disconnectEdges),d=t.filter(S=>S.selected).map(S=>S.id),p=n.filter(S=>S.selected).map(S=>S.id),g=new Set(d),v=t.filter(S=>g.has(S.id)&&S.type!=="elementReferenceNode"&&!ic(S)).length,w=sc(n,d).length,x=S=>{l(S)};return h.jsxs(Ke,{position:"top-center",className:"node-batch-bar nodrag",children:[h.jsx("button",{type:"button",onClick:s,"aria-pressed":o,children:e(o?"nodeBatch.selectionOn":"nodeBatch.selectionOff")}),h.jsx("button",{type:"button",onClick:a,disabled:t.length===0,children:e("nodeBatch.selectAll")}),p.length>0?h.jsx("button",{type:"button",className:"node-batch-bar__danger",onClick:()=>f(p),title:e("edge.disconnectTitle"),"aria-label":e("edge.disconnectTitle"),children:e("edge.disconnect")}):null,d.length>0?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"node-batch-bar__meta",children:e("nodeBatch.summary",{selected:d.length,missing:v,stale:w})}),h.jsx("button",{type:"button",onClick:()=>x("missing-only"),disabled:r,children:e("nodeBatch.generateMissing")}),h.jsx("button",{type:"button",onClick:()=>x("regenerate-all"),disabled:r,children:e("nodeBatch.regenerateSelected")}),r?h.jsx("button",{type:"button",onClick:u,disabled:i,children:e(i?"nodeBatch.stopping":"nodeBatch.stopRemaining")}):null,h.jsx("button",{type:"button",onClick:c,disabled:r,children:e("nodeBatch.clear")})]}):null]})}function Rg({data:e,selected:t}){const{t:n}=ae(),o=N.useCallback(()=>{e.elementId&&(e.onOpenAssets?e.onOpenAssets(e.elementId):window.dispatchEvent(new CustomEvent("ima2:open-assets-detail",{detail:{assetId:e.elementId}})))},[e]),r=e.elementName??n("nodeStudio.elementNode.untitled");return h.jsxs("div",{className:`element-reference-node${t?" is-selected":""}${e.missing?" is-missing":""}${e.compact?" is-compact":""}`,onDoubleClick:o,style:{"--element-thumb":e.thumbnailUrl?`url(${JSON.stringify(e.thumbnailUrl)})`:"none"},children:[h.jsx(He,{type:"source",id:"refs",position:X.Right,className:"element-reference-node__handle element-reference-node__handle--refs","aria-label":n("nodeStudio.elementNode.referencesOutput")}),h.jsx(He,{type:"source",id:"notes",position:X.Bottom,className:"element-reference-node__handle element-reference-node__handle--notes","aria-label":n("nodeStudio.elementNode.notesOutput")}),h.jsxs("div",{className:"element-reference-node__header",children:[h.jsx("span",{className:"element-reference-node__kind",children:n("nodeStudio.elementNode.kind")}),h.jsx("strong",{children:r})]}),h.jsxs("div",{className:"element-reference-node__body",children:[h.jsx("div",{className:"element-reference-node__thumbnail","aria-hidden":"true"}),e.compact?null:h.jsxs("div",{children:[h.jsx("span",{className:"element-reference-node__ref-count",children:n(e.refCount===1?"nodeStudio.elementNode.referenceCountOne":"nodeStudio.elementNode.referenceCount",{count:e.refCount})}),e.notesPreview?h.jsx("p",{children:e.notesPreview}):null]})]}),e.missing?h.jsx("p",{className:"element-reference-node__warning",role:"alert",children:n("nodeStudio.elementNode.missing")}):null]})}const Hg=N.memo(Rg);function Hn({title:e,description:t,action:n,disabled:o,onClick:r}){return h.jsxs("button",{type:"button",className:"node-empty-state__choice",disabled:o,onClick:r,children:[h.jsx("span",{className:"node-empty-state__choice-title",children:e}),h.jsx("span",{className:"node-empty-state__choice-description",children:t}),h.jsx("span",{className:"node-empty-state__choice-action",children:n})]})}function Lg({hasRecentGraph:e,onStartBlank:t,onOpenTemplates:n,onResumeRecent:o}){const{t:r}=ae();return h.jsxs("section",{className:"node-empty-state","aria-labelledby":"node-empty-state-title",children:[h.jsxs("div",{className:"node-empty-state__intro",children:[h.jsx("p",{className:"node-empty-state__eyebrow",children:r("nodeStudio.name")}),h.jsx("h2",{id:"node-empty-state-title",children:r("nodeStudio.empty.title")}),h.jsx("p",{children:r("nodeStudio.empty.description")})]}),h.jsxs("div",{className:"node-empty-state__choices",children:[h.jsx(Hn,{title:r("nodeStudio.empty.blankTitle"),description:r("nodeStudio.empty.blankDescription"),action:r("nodeStudio.empty.blankAction"),onClick:t}),h.jsx(Hn,{title:r("nodeStudio.empty.templateTitle"),description:r("nodeStudio.empty.templateDescription"),action:r("nodeStudio.empty.templateAction"),onClick:n}),h.jsx(Hn,{title:r("nodeStudio.empty.recentTitle"),description:r(e?"nodeStudio.empty.recentDescription":"nodeStudio.empty.recentUnavailable"),action:r("nodeStudio.empty.recentAction"),disabled:!e,onClick:()=>{o()}})]})]})}const Jn=["oauth","api","grok","gemini-api"];function Fr(e,t){return{id:`variant-${e+1}`,label:t,provider:Jn[e%Jn.length],model:"",size:""}}function Og(e){return{id:e.id,label:e.label.trim(),provider:e.provider,settingsPatch:{...e.model.trim()?{model:e.model.trim()}:{},...e.size.trim()?{size:e.size.trim()}:{}}}}function zg({sourceLabel:e,onApply:t,onClose:n}){const{t:o}=ae(),[r,i]=N.useState(()=>[0,1].map(f=>Fr(f,o("nodeStudio.branch.defaultVariant",{index:f+1})))),s=N.useRef(2),a=(f,d)=>{i(p=>p.map((g,v)=>v===f?{...g,...d}:g))},c=f=>i(d=>d.filter((p,g)=>g!==f)),l=()=>i(f=>{if(f.length>=4)return f;const d=s.current++,p=Fr(d,o("nodeStudio.branch.defaultVariant",{index:d+1}));return[...f,p]}),u=()=>t(r.map(Og));return h.jsxs("section",{className:"node-template-picker",role:"document",children:[h.jsxs("header",{children:[h.jsxs("div",{children:[h.jsx("p",{className:"node-template-picker__eyebrow",children:o("nodeStudio.branch.eyebrow")}),h.jsx("h2",{id:"node-branch-dialog-title",children:o("nodeStudio.branch.title")}),h.jsx("p",{children:e})]}),h.jsx("button",{type:"button","aria-label":o("nodeStudio.branch.close"),onClick:n,children:"×"})]}),h.jsx("div",{className:"node-template-picker__sections",children:r.map((f,d)=>h.jsxs("fieldset",{className:"node-template-picker__card",children:[h.jsx("legend",{children:o("nodeStudio.branch.variantLegend",{index:d+1})}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:o("nodeStudio.branch.label")}),h.jsx("input",{autoFocus:d===0,value:f.label,onChange:p=>a(d,{label:p.target.value})})]}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:o("nodeStudio.branch.provider")}),h.jsx("select",{value:f.provider,onChange:p=>a(d,{provider:p.target.value}),children:Jn.map(p=>h.jsx("option",{value:p,children:p},p))})]}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:o("nodeStudio.branch.modelOverride")}),h.jsx("input",{value:f.model,onChange:p=>a(d,{model:p.target.value}),placeholder:o("nodeStudio.branch.currentModel")})]}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:o("nodeStudio.branch.sizeOverride")}),h.jsx("input",{value:f.size,onChange:p=>a(d,{size:p.target.value}),placeholder:o("nodeStudio.branch.currentSize")})]}),h.jsx("button",{type:"button",disabled:r.length<=2,onClick:()=>c(d),children:o("nodeStudio.branch.remove")})]},f.id))}),h.jsxs("footer",{children:[h.jsx("button",{type:"button",disabled:r.length>=4,onClick:l,children:o("nodeStudio.branch.add")}),h.jsx("span",{}),h.jsx("button",{type:"button",onClick:n,children:o("nodeStudio.branch.cancel")}),h.jsx("button",{type:"button",className:"node-template-picker__copy",disabled:r.some(f=>!f.label.trim()),onClick:u,children:o("nodeStudio.branch.create")})]})]})}const Bg={prompt:["prompt","element-notes"],image:["image","images","mask","element-refs","any-media"],images:["images","element-refs","any-media"],video:["video","any-media"],mask:["mask","any-media"],"element-refs":["image","images","element-refs","any-media"],"element-notes":["prompt","element-notes"],settings:["settings"],"any-media":["image","images","video","mask","any-media"]};function eo(e,t){const n=t.equivalentHandleIds??[t.handleId];return typeof e=="string"&&n.includes(e)}function Vg(e,t,n){return n.some(o=>o.source===e.nodeId&&o.target===t.nodeId&&eo(o.sourceHandle,e)&&eo(o.targetHandle,t))}function Fg(e,t){return t.some(n=>n.target===e.nodeId&&eo(n.targetHandle,e))}function Fs(e,t){return Bg[e].includes(t)}function Ys(e,t,n){return e.direction!=="output"||t.direction!=="input"?{allowed:!1,reason:"SAME_DIRECTION"}:e.nodeId===t.nodeId?{allowed:!1,reason:"SELF_EDGE"}:Vg(e,t,n.edges)?{allowed:!1,reason:"DUPLICATE_EDGE"}:Fs(e.type,t.type)?ac(n.edges,e.nodeId,t.nodeId)?{allowed:!1,reason:"CYCLE"}:!t.acceptsMany&&Fg(t,n.edges)?{allowed:!1,reason:"CARDINALITY"}:{allowed:!0}:{allowed:!1,reason:"TYPE_MISMATCH"}}const Yg={input:"nodeStudio.palette.categories.input",generate:"nodeStudio.palette.categories.generate",transform:"nodeStudio.palette.categories.transform",reference:"nodeStudio.palette.categories.reference",output:"nodeStudio.palette.categories.output"},ht=["input","generate","transform","reference","output"];function tt(e,t,n){const o=`nodeStudio.commands.${t.type}.${n}`,r=e(o);return r===o?t[n]:r}function Xg(e,t){const n=`nodeStudio.portTypes.${t}`,o=e(n);return o===n?t:o}function Wg(e,t,n){const o=t.toLocaleLowerCase(),r=tt(n,e,"label").toLocaleLowerCase();return r.startsWith(o)?0:r.includes(o)?1:e.keywords.some(i=>i.toLocaleLowerCase().includes(o))?2:tt(n,e,"description").toLocaleLowerCase().includes(o)?3:-1}function Zg(e,t){return t?t.direction==="output"&&e.inputPorts.some(n=>Fs(t.type,n.type)):!0}function Gg({open:e,anchor:t,sourcePort:n,commands:o,recentCommandTypes:r=[],onInsert:i,onClose:s}){const{t:a}=ae(),c=N.useId(),l=N.useRef(null),[u,f]=N.useState(""),[d,p]=N.useState(0),g=N.useMemo(()=>o.filter(b=>Zg(b,n)).map(b=>({command:b,score:Wg(b,u,a)})).filter(b=>!u||b.score>=0).sort((b,C)=>b.score-C.score||tt(a,b.command,"label").localeCompare(tt(a,C.command,"label"))).map(b=>b.command),[o,u,n,a]),v=u?g:[...r.map(b=>g.find(C=>C.type===b)).filter(b=>!!b).slice(0,5),...g.filter(b=>!r.includes(b.type))],w=N.useMemo(()=>ht.flatMap(b=>v.filter(C=>C.category===b)),[v]);if(N.useEffect(()=>{e&&(f(""),p(0),requestAnimationFrame(()=>l.current?.focus()))},[e]),N.useEffect(()=>{p(b=>Math.min(b,Math.max(0,w.length-1)))},[w.length]),!e)return null;const x=()=>{const b=w[d];b&&i(b)},S=b=>{if(b.stopPropagation(),b.key==="Escape")b.preventDefault(),s();else if(b.key==="ArrowDown")b.preventDefault(),p(C=>(C+1)%Math.max(1,w.length));else if(b.key==="ArrowUp")b.preventDefault(),p(C=>(C-1+w.length)%Math.max(1,w.length));else if(b.key==="Home")b.preventDefault(),p(0);else if(b.key==="End")b.preventDefault(),p(Math.max(0,w.length-1));else if(b.key==="Enter")b.preventDefault(),x();else if(b.key==="Tab"){b.preventDefault();const C=w[d]?.category,E=ht.indexOf(C??"input"),A=ht.slice(E+1).concat(ht.slice(0,E)).find(B=>B!==C&&w.some(T=>T.category===B));A&&p(w.findIndex(B=>B.category===A))}else(b.metaKey||b.ctrlKey)&&b.key==="Backspace"&&(b.preventDefault(),f(""))},m=n?Xg(a,n.type):null,y=Math.max(8,Math.min(t.clientX,window.innerWidth-372)),I=Math.max(8,Math.min(t.clientY,window.innerHeight-220));return h.jsxs("section",{className:"node-command-palette",style:{left:y,top:I},"aria-label":a("nodeStudio.palette.ariaLabel"),children:[h.jsx("input",{ref:l,className:"node-command-palette__search",value:u,onChange:b=>f(b.target.value),onKeyDown:S,placeholder:m?a("nodeStudio.palette.compatiblePlaceholder",{portType:m}):a("nodeStudio.palette.searchPlaceholder"),"aria-controls":c,"aria-activedescendant":w[d]?`${c}-${w[d].type}`:void 0}),m?h.jsx("p",{className:"node-command-palette__filter",children:a("nodeStudio.palette.filter",{portType:m})}):null,w.length===0?h.jsx("p",{className:"node-command-palette__empty",children:m?a("nodeStudio.palette.emptyCompatible",{portType:m}):a("nodeStudio.palette.emptySearch")}):h.jsx("div",{className:"node-command-palette__list",id:c,role:"listbox","aria-label":a("nodeStudio.palette.commandsAria"),children:ht.map(b=>{const C=w.filter(E=>E.category===b);return C.length?h.jsxs("section",{children:[h.jsx("h3",{children:a(Yg[b])}),C.map(E=>{const A=w.indexOf(E);return h.jsxs("button",{id:`${c}-${E.type}`,type:"button",role:"option","aria-selected":A===d,className:A===d?"is-active":"",onPointerEnter:()=>p(A),onClick:()=>i(E),children:[h.jsx("span",{children:tt(a,E,"label")}),h.jsx("small",{children:tt(a,E,"description")})]},E.type)})]},b):null})})]})}const to="application/ima2-node-element";function _o(e){return{clientId:e,serverNodeId:null,parentServerNodeId:null,prompt:"",imageUrl:null,status:"empty",pendingRequestId:null,pendingPhase:null}}function Xs(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function Ug(e){const t=Xs(e.data),n=t.nodeType==="element-reference";return{...e,id:e.id,type:n?"elementReferenceNode":"imageNode",position:e.position??{x:0,y:0},data:{..._o(e.id),...t,clientId:e.id,status:t.status==="ready"?"ready":"empty",pendingRequestId:null,pendingPhase:null}}}function qg(e){return{...e,id:e.id,source:e.source,target:e.target,sourceHandle:e.sourceHandle==="output"?"source-right":e.sourceHandle,targetHandle:e.targetHandle==="input"?"target-left":e.targetHandle}}function Kg(e){return{nodes:e.nodes.map(Ug),edges:e.edges.map(qg)}}function Ws(e,t){const n=new Set(e.map(o=>o.id));return n.size!==e.length||new Set(t.map(o=>o.id)).size!==t.length||t.some(o=>!n.has(o.source)||!n.has(o.target))||lc(e,t)?!1:e.every(o=>o.type!=="elementReferenceNode"||Xs(o.data).nodeType==="element-reference")}function wn(e){if(!Ws(e.nodes,e.edges))return!1;Q.getState().recordGraphHistory(`commit-${e.reason}`);const t=cc(e.nodes,e.edges);return Q.setState({graphNodes:t,graphEdges:e.edges}),Q.getState().scheduleGraphSave(),!0}function Qg(e,t){if(t.createdNodeIds.length===0||t.createdEdgeIds.length===0)return{ok:!1};const n={nodes:[...e.nodes,...t.nodes],edges:[...e.edges,...t.edges]};return Ws(n.nodes,n.edges)?{ok:!0,graph:n}:{ok:!1}}function Jg(e){const t=Qr(),n={id:t,type:"imageNode",position:e.position,data:_o(t)};if(!e.sourcePort)return{nodes:[...e.graph.nodes,n],edges:e.graph.edges};const o={id:`${e.sourcePort.nodeId}:${e.sourcePort.handleId}->${t}:target-left`,source:e.sourcePort.nodeId,target:t,sourceHandle:e.sourcePort.handleId,targetHandle:"target-left"};return{nodes:[...e.graph.nodes,n],edges:[...e.graph.edges,o]}}function em(e){try{const t=JSON.parse(e);return t.version===1&&t.assetKind==="element"&&typeof t.elementId=="string"&&t.elementId.length>0?t:null}catch{return null}}function tm(e){const t=e.metadata?.refs,n=Array.isArray(t)?t.find(o=>typeof o=="string"&&o.length>0):null;return n?`/generated/${n.split("/").map(encodeURIComponent).join("/")}`:null}function nm(e,t){if(e.kind!=="element")return null;const n=Array.isArray(e.metadata?.refs)?e.metadata.refs:[],o=Qr();return{id:o,type:"elementReferenceNode",position:t,data:{..._o(o),nodeType:"element-reference",elementId:e.id,elementName:e.name,thumbnailUrl:tm(e),refCount:n.length,notesPreview:e.notes??"",revision:e.updatedAt,missing:!1}}}function om(e){return{version:1,assetKind:"element",elementId:e}}function rm(e,t){e.dataTransfer.effectAllowed="copy",e.dataTransfer.setData(to,JSON.stringify(om(t.id)))}function im({disabled:e=!1,onAdd:t}){const{t:n}=ae(),[o,r]=N.useState([]),[i,s]=N.useState("loading");return N.useEffect(()=>{let a=!0;return(async()=>{try{const c=await uc();a&&(r(c),s("ready"))}catch{a&&s("error")}})(),()=>{a=!1}},[]),h.jsxs("aside",{className:"node-element-tray","aria-label":n("nodeStudio.elements.ariaLabel"),children:[h.jsxs("header",{children:[h.jsx("strong",{children:n("nodeStudio.elements.title")}),h.jsx("span",{children:n("nodeStudio.elements.hint")})]}),i==="loading"?h.jsx("p",{role:"status",children:n("nodeStudio.elements.loading")}):null,i==="error"?h.jsx("p",{role:"alert",children:n("nodeStudio.elements.loadError")}):null,i==="ready"&&o.length===0?h.jsx("p",{children:n("nodeStudio.elements.empty")}):null,h.jsx("div",{className:"node-element-tray__list",children:o.map(a=>{const c=dc(a);return h.jsxs("article",{className:"node-element-tray__item",draggable:!e,onDragStart:l=>rm(l,a),children:[c?h.jsx("img",{src:`/generated/${c.split("/").map(encodeURIComponent).join("/")}`,alt:""}):h.jsx("span",{className:"node-element-tray__placeholder","aria-hidden":"true"}),h.jsx("span",{title:a.name,children:a.name}),h.jsx("button",{type:"button",disabled:e,onClick:()=>{t(a)},children:n("nodeStudio.elements.addToCanvas")})]},a.id)})})]})}function sm(e,t){const n=t.toLocaleLowerCase();return[e.name,...e.tags].some(o=>o.toLocaleLowerCase().includes(n))}function am({template:e}){const{t}=ae(),n=e.preview??[];return h.jsx("div",{className:"node-template-picker__preview","aria-label":t("nodeStudio.templates.previewAria",{name:e.name}),children:n.length?n.map(o=>h.jsx("span",{className:"node-template-picker__preview-node",style:{left:`${o.x}%`,top:`${o.y}%`},children:o.label},o.id)):h.jsx("span",{className:"node-template-picker__preview-empty",children:t(e.nodeCount===1?"nodeStudio.templates.nodeCountOne":"nodeStudio.templates.nodeCount",{count:e.nodeCount})})})}function Yr({template:e,selected:t,onSelect:n,onRename:o,onDelete:r,onExport:i}){const{t:s}=ae(),a=e.source==="user"&&(o||r);return h.jsxs("article",{className:`node-template-picker__card${t?" is-selected":""}`,children:[h.jsxs("button",{type:"button",className:"node-template-picker__card-main",onClick:n,onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),n())},"aria-pressed":t,children:[h.jsx(am,{template:e}),h.jsxs("span",{className:"node-template-picker__card-copy",children:[h.jsx("strong",{children:e.name}),h.jsx("span",{children:e.description}),h.jsxs("small",{children:[s(e.nodeCount===1?"nodeStudio.templates.nodeCountOne":"nodeStudio.templates.nodeCount",{count:e.nodeCount})," · ",s(e.terminalCount===1?"nodeStudio.templates.outputCountOne":"nodeStudio.templates.outputCount",{count:e.terminalCount})]})]})]}),h.jsx("div",{className:"node-template-picker__tags",children:e.tags.map(c=>h.jsx("span",{children:c},c))}),i||a?h.jsxs("div",{className:"node-template-picker__card-actions",children:[i?h.jsx("button",{type:"button",onClick:i,children:s("nodeStudio.templates.export")}):null,e.source==="user"&&o?h.jsx("button",{type:"button",onClick:o,children:s("nodeStudio.templates.rename")}):null,e.source==="user"&&r?h.jsx("button",{type:"button",onClick:r,children:s("nodeStudio.templates.delete")}):null]}):null]})}function cm({templates:e,loading:t=!1,error:n=null,onCopy:o,onClose:r,onRename:i,onDelete:s,onExport:a,onImport:c,importError:l=null}){const{t:u}=ae(),f=N.useRef(null),[d,p]=N.useState(""),[g,v]=N.useState(null),w=N.useMemo(()=>e.filter(E=>sm(E,d)),[d,e]),x=w.find(E=>E.id===g)??null,S=w.filter(E=>E.source==="seed"),m=w.filter(E=>E.source==="user"),y=()=>{x&&o(x)},I=E=>{const A=E.target.files?.[0];E.target.value="",A&&c?.(A)},b=E=>a?()=>a(E):void 0,C=E=>{window.confirm(u("nodeStudio.templates.deleteConfirm",{name:E.name}))&&s?.(E)};return h.jsxs("section",{className:"node-template-picker",role:"dialog","aria-modal":"true","aria-labelledby":"node-template-picker-title",children:[h.jsxs("header",{children:[h.jsxs("div",{children:[h.jsx("p",{className:"node-template-picker__eyebrow",children:u("nodeStudio.name")}),h.jsx("h2",{id:"node-template-picker-title",children:u("nodeStudio.templates.title")})]}),h.jsx("button",{type:"button","aria-label":u("nodeStudio.templates.close"),onClick:r,children:"×"})]}),h.jsxs("label",{className:"node-template-picker__search",children:[h.jsx("span",{children:u("nodeStudio.templates.searchLabel")}),h.jsx("input",{autoFocus:!0,value:d,onChange:E=>p(E.target.value),placeholder:u("nodeStudio.templates.searchPlaceholder")})]}),t?h.jsx("p",{className:"node-template-picker__state",role:"status",children:u("nodeStudio.templates.loading")}):null,n?h.jsx("p",{className:"node-template-picker__state is-error",role:"alert",children:n}):null,!t&&!n&&w.length===0?h.jsx("p",{className:"node-template-picker__state",children:u("nodeStudio.templates.empty",{query:d})}):null,!t&&!n?h.jsxs("div",{className:"node-template-picker__sections",children:[S.length?h.jsxs("section",{children:[h.jsx("h3",{children:u("nodeStudio.templates.starter")}),h.jsx("div",{className:"node-template-picker__grid",children:S.map(E=>h.jsx(Yr,{template:E,selected:E.id===g,onSelect:()=>v(E.id),onExport:b(E)},E.id))})]}):null,m.length?h.jsxs("section",{children:[h.jsx("h3",{children:u("nodeStudio.templates.yours")}),h.jsx("div",{className:"node-template-picker__grid",children:m.map(E=>h.jsx(Yr,{template:E,selected:E.id===g,onSelect:()=>v(E.id),onRename:i?()=>i(E):void 0,onDelete:s?()=>C(E):void 0,onExport:b(E)},E.id))})]}):null]}):null,l?h.jsx("p",{className:"node-template-picker__state is-error",role:"alert",children:l}):null,h.jsxs("footer",{children:[c?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",title:u("nodeStudio.templates.importHint"),onClick:()=>f.current?.click(),children:u("nodeStudio.templates.import")}),h.jsx("input",{ref:f,type:"file",accept:"application/json,.json",hidden:!0,onChange:I,"aria-label":u("nodeStudio.templates.import")})]}):null,h.jsx("button",{type:"button",onClick:r,children:u("nodeStudio.templates.cancel")}),h.jsx("button",{type:"button",className:"node-template-picker__copy",disabled:!x,onClick:y,children:u("nodeStudio.templates.copy")})]})]})}function Xr({children:e,onClose:t}){const n=fc(!0,t);return h.jsx("div",{ref:n,className:"node-studio-dialog-backdrop",onPointerDown:o=>{o.target===o.currentTarget&&t()},children:e})}function lm({studio:e,graphEmpty:t,disabled:n,onAddRoot:o}){const{t:r}=ae();return h.jsxs(h.Fragment,{children:[h.jsxs(Ke,{position:"top-right",className:"node-studio-toolbar",children:[h.jsx("button",{type:"button",disabled:n,onClick:o,children:r("nodeStudio.toolbar.addImage")}),h.jsx("button",{type:"button",disabled:n,onClick:e.openTemplates,children:r("nodeStudio.toolbar.templates")}),h.jsx("button",{type:"button",disabled:n||t,onClick:e.saveTemplate,children:r("nodeStudio.toolbar.saveTemplate")}),h.jsx("button",{type:"button",disabled:n||!e.selectedSource,onClick:e.openBranch,children:r("nodeStudio.toolbar.branch")})]}),h.jsx(Ke,{position:"top-left",className:"node-studio-element-panel",children:h.jsx(im,{disabled:n,onAdd:e.addElement})}),h.jsx(Gg,{open:!!e.palette,anchor:e.palette?.anchor??{clientX:0,clientY:0},sourcePort:e.palette?.sourcePort,commands:e.commands,onInsert:e.insertCommand,onClose:e.closePalette}),e.templateOpen?h.jsx(Xr,{onClose:e.closeOverlays,children:h.jsx(cm,{templates:e.templates,loading:e.templateLoading,error:e.templateError,importError:e.importError,onCopy:e.copyTemplate,onRename:e.renameTemplate,onDelete:e.removeTemplate,onExport:e.exportTemplate,onImport:e.importTemplate,onClose:e.closeOverlays})}):null,e.branchOpen&&e.selectedSource?h.jsx(Xr,{onClose:e.closeOverlays,children:h.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"node-branch-dialog-title",children:h.jsx(zg,{sourceLabel:e.selectedSource.data.prompt||e.selectedSource.id,onApply:e.applyBranch,onClose:e.closeOverlays})})}):null,h.jsx("div",{className:"node-studio-status",role:"status","aria-live":"polite","aria-atomic":"true",children:e.status})]})}const um=[{type:"image-generate",label:"Image generation",description:"Add an image node to the workflow.",category:"generate",keywords:["image","generate","prompt"],inputPorts:[{id:"image-input",type:"image"}],outputPorts:[{id:"image-output",type:"image"}],createData:()=>({})}];function Zs(e){return e instanceof HTMLElement&&e.matches("input, textarea, select, [contenteditable=true]")}function dm(e,t){return e===t||e instanceof HTMLElement&&e.classList.contains("react-flow__pane")}function fm(e,t,n){return Zs(e.target)||!dm(e.target,t)?!1:e.key==="/"||e.key===" "&&n}function hm(e){return Zs(e.target)||!(e.metaKey||e.ctrlKey)||e.altKey||e.key!=="z"&&e.key!=="Z"?null:e.shiftKey?"redo":"undo"}function pm(e){const t=e?.getBoundingClientRect();return t?{clientX:t.left+t.width/2,clientY:t.top+Math.min(180,t.height/2)}:{clientX:320,clientY:180}}const gm=320,mm=420;function Ln(){return{nodes:[],edges:[],createdNodeIds:[],createdEdgeIds:[]}}function ym(e){return new Set(e.map(t=>t.id)).size===e.length}function no(e,t){let n=1,o=e;for(;t.has(o);)o=`${e}-${n++}`;return t.add(o),o}function xm(e){return JSON.parse(JSON.stringify(e))}function wm(e,t,n,o){const r=(t-.5)*gm;return{x:Math.max(0,...o.nodes.map(s=>s.position.x))+mm,y:e.position.y+r}}function Wr(e,t,n,o,r){const i={...xm(e.data),...r?n.settingsPatch:{},clientId:t,serverNodeId:null,parentServerNodeId:null,pendingRequestId:null,pendingPhase:null,status:"empty"};return r&&n.provider&&(i.provider=n.provider),{...e,id:t,position:o,data:i}}function Zr(e,t,n,o){const r=no(`${t}:${e.sourceHandle??"auto"}->${n}:${e.targetHandle??"auto"}`,o);return{...e,id:r,source:t,target:n}}function vm(e){const t=e.graph.nodes.find(i=>i.id===e.sourceNodeId),n=e.graph.edges.find(i=>i.source===e.sourceNodeId),o=n&&e.graph.nodes.find(i=>i.id===n.target),r=o?e.graph.edges.filter(i=>i.target===o.id):[];return t&&o&&r.length>0?{generator:o,inputEdges:r}:null}function bm(e){if(e.variants.length<2||e.variants.length>4||!ym(e.variants))return Ln();const t=vm(e);if(!t)return Ln();const n=new Set(e.graph.nodes.map(c=>c.id)),o=new Set(e.graph.edges.map(c=>c.id)),r=e.graph.edges.find(c=>c.source===t.generator.id),i=r&&e.graph.nodes.find(c=>c.id===r.target);if(r&&!i)return Ln();const s=[],a=[];for(const[c,l]of e.variants.entries()){const u=no(`${t.generator.id}-branch-${l.id}`,n),f=wm(t.generator,c,e.axis,e.graph),d=Wr(t.generator,u,l,f,!0);s.push(d);for(const p of t.inputEdges)a.push(Zr(p,p.source,u,o));if(i&&r){const p=no(`${i.id}-branch-${l.id}`,n),g={x:f.x+i.position.x-t.generator.position.x,y:f.y+i.position.y-t.generator.position.y},v=Wr(i,p,l,g,!1);s.push(v),a.push(Zr(r,u,p,o))}}return{nodes:s,edges:a,createdNodeIds:s.map(c=>c.id),createdEdgeIds:a.map(c=>c.id)}}function _m(e){const{t}=ae(),[n,o]=N.useState(!1),r=N.useMemo(()=>{const s=e.nodes.filter(a=>a.selected&&a.type==="imageNode");return s.length===1&&e.edges.some(a=>a.source===s[0].id)?s[0]:null},[e.edges,e.nodes]),i=N.useCallback(s=>{if(!r){e.showToast(t("nodeStudio.branch.selectSourceError"),!0);return}const a=bm({graph:{nodes:e.nodes,edges:e.edges},sourceNodeId:r.id,variants:s,axis:"horizontal"}),c=Qg({nodes:e.nodes,edges:e.edges},a);if(!c.ok||!wn({...c.graph,reason:"branch"})){e.showToast(t("nodeStudio.branch.applyError"),!0);return}o(!1),e.restoreFocus(),requestAnimationFrame(()=>{e.fitView({padding:.16,duration:180})})},[e,r,t]);return{branchOpen:n,selectedSource:r,setBranchOpen:o,applyBranch:i}}const Gr=["target-top","target-right","target-bottom","target-left"],Ur=["source-top","source-right","source-bottom","source-left"],Sm=[...Gr.map(e=>({nodeType:"imageNode",flowHandleId:e,logicalPortId:"image-input",direction:"input",type:"image",acceptsMany:!0,equivalentHandleIds:Gr})),...Ur.map(e=>({nodeType:"imageNode",flowHandleId:e,logicalPortId:"image-output",direction:"output",type:"image",acceptsMany:!0,equivalentHandleIds:Ur})),{nodeType:"elementReferenceNode",flowHandleId:"refs",logicalPortId:"element-refs-output",direction:"output",type:"element-refs",acceptsMany:!0,equivalentHandleIds:["refs"]},{nodeType:"elementReferenceNode",flowHandleId:"notes",logicalPortId:"element-notes-output",direction:"output",type:"element-notes",acceptsMany:!0,equivalentHandleIds:["notes"]}];function rt(e,t,n){if(!t)return null;const o=e.type==="elementReferenceNode"?"elementReferenceNode":e.type==="imageNode"?"imageNode":null;if(!o)return null;const r=Sm.find(i=>i.nodeType===o&&i.flowHandleId===t&&i.direction===n);return r?{nodeId:e.id,handleId:r.flowHandleId,logicalPortId:r.logicalPortId,equivalentHandleIds:r.equivalentHandleIds,direction:r.direction,type:r.type,acceptsMany:r.acceptsMany}:null}const qr="source-",Em="target-";function Gs(e,t){const n=e.targetHandle;if(!n?.startsWith(qr))return e;const o=t.find(i=>i.id===e.target);if(!o||o.type!=="imageNode")return e;const r=Em+n.slice(qr.length);return rt(o,r,"input")?{...e,targetHandle:r}:e}function Nm(e,t,n){const o=Gs(e,t),r=t.find(c=>c.id===o.source),i=t.find(c=>c.id===o.target);if(!r||!i)return!1;const s=rt(r,o.sourceHandle,"output"),a=rt(i,o.targetHandle,"input");return!s||!a?!1:Ys(s,a,{edges:n}).allowed}function Cm(e){return"changedTouches"in e?{clientX:e.changedTouches[0].clientX,clientY:e.changedTouches[0].clientY}:{clientX:e.clientX,clientY:e.clientY}}function Im(e){const[t,n]=N.useState(null),o=N.useCallback(a=>Nm(a,e.nodes,e.edges),[e]),r=N.useCallback(a=>{const c=Gs(a,e.nodes),l=e.nodes.find(g=>g.id===c.source),u=e.nodes.find(g=>g.id===c.target),f=l?rt(l,c.sourceHandle,"output"):null,d=u?rt(u,c.targetHandle,"input"):null;if(!f||!d){e.surfaceReason("UNKNOWN_PORT");return}const p=Ys(f,d,{nodes:e.nodes,edges:e.edges});if(!p.allowed){e.surfaceReason(p.reason);return}e.connectNodes(c.source,c.target,c.sourceHandle,c.targetHandle)},[e]),i=N.useCallback((a,c)=>{if(c.isValid||c.toNode||c.toHandle)return;const l=c.fromNode?e.nodes.find(f=>f.id===c.fromNode?.id):null,u=l?rt(l,c.fromHandle?.id,"output"):null;if(!u){e.surfaceReason("UNKNOWN_PORT");return}n({anchor:Cm(a),sourcePort:u})},[e]),s=N.useCallback(a=>{if(a.type!=="image-generate"||!t)return;const c=e.screenToFlowPosition({x:t.anchor.clientX,y:t.anchor.clientY}),l=Jg({graph:{nodes:e.nodes,edges:e.edges},position:c,sourcePort:t.sourcePort});if(!wn({...l,reason:"palette"})){e.surfaceReason("UNKNOWN_PORT");return}n(null),e.restoreFocus()},[e,t]);return{palette:t,setPalette:n,onConnect:r,onConnectEnd:i,insertCommand:s,isValidConnection:o}}function km(e){const{t}=ae(),n=N.useCallback(async(s,a)=>{try{const c=await hc(s),l=nm(c.asset,a);if(!l){e.showToast(t("nodeStudio.elementController.onlyElements"),!0);return}const u={nodes:[...e.nodes,l],edges:e.edges};wn({...u,reason:"element-drop"})||e.showToast(t("nodeStudio.elementController.invalid"),!0)}catch{e.showToast(t("nodeStudio.elementController.addError"),!0)}},[e,t]),o=N.useCallback(async s=>{const a=e.wrapperRef.current?.getBoundingClientRect(),c=a?{x:a.left+a.width/2,y:a.top+a.height/2}:{x:320,y:240};try{await n(s.id,e.screenToFlowPosition(c))}catch{e.showToast(t("nodeStudio.elementController.addError"),!0)}},[n,e,t]),r=N.useCallback(async s=>{s.preventDefault();const a=em(s.dataTransfer.getData(to));if(a)try{await n(a.elementId,e.screenToFlowPosition({x:s.clientX,y:s.clientY}))}catch{e.showToast(t("nodeStudio.elementController.addError"),!0)}},[n,e,t]),i=N.useCallback(s=>{s.dataTransfer.types.includes(to)&&(s.preventDefault(),s.dataTransfer.dropEffect="copy")},[]);return{addElement:o,onDropElement:r,onDragOver:i}}function Mm(e){return`${e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[Đđ]/g,"d").replace(/[^a-zA-Z0-9]+/g,"-").replace(/^-+|-+$/g,"").toLowerCase().slice(0,80).replace(/-+$/g,"")||"template"}.ima2-template.json`}const So={"Content-Type":"application/json"};async function Tm(){try{return(await Qe("/api/node-templates")).templates}catch(e){throw e instanceof Error?e:new Error(String(e))}}async function Am(e){try{return(await Qe("/api/node-templates",{method:"POST",headers:So,body:JSON.stringify(e)})).template}catch(t){throw t instanceof Error?t:new Error(String(t))}}async function Pm(e){try{return(await Qe(`/api/node-templates/${encodeURIComponent(e)}/instantiate`,{method:"POST"})).graph}catch(t){throw t instanceof Error?t:new Error(String(t))}}async function Dm(e,t){try{return(await Qe(`/api/node-templates/${encodeURIComponent(e)}`,{method:"PATCH",headers:So,body:JSON.stringify({name:t})})).template}catch(n){throw n instanceof Error?n:new Error(String(n))}}async function jm(e){try{await Qe(`/api/node-templates/${encodeURIComponent(e)}`,{method:"DELETE"})}catch(t){throw t instanceof Error?t:new Error(String(t))}}const $m=2*1024*1024;async function Rm(e){return Qe(`/api/node-templates/${encodeURIComponent(e)}/export`)}async function Hm(e){return(await Qe("/api/node-templates/import",{method:"POST",headers:So,body:e})).template}function Lm(e){const{t}=ae(),[n,o]=N.useState(!1),[r,i]=N.useState(!1),[s,a]=N.useState(null),[c,l]=N.useState(null),[u,f]=N.useState([]),d=N.useCallback(async()=>{o(!0),i(!0),a(null),l(null);try{f(await Tm())}catch{a(t("nodeStudio.templates.loadError"))}finally{i(!1)}},[t]),p=N.useCallback(async g=>{if(!(e.nodes.length>0&&!window.confirm(t("nodeStudio.templates.replaceConfirm")))){i(!0),a(null);try{const v=Kg(await Pm(g.id));if(!wn({...v,reason:"template"})){a(t("nodeStudio.templates.invalidGraph"));return}o(!1),e.restoreFocus(),requestAnimationFrame(()=>{e.fitView({padding:.16,duration:180})})}catch{a(t("nodeStudio.templates.copyError"))}finally{i(!1)}}},[e,t]);return{templateOpen:n,templateLoading:r,templateError:s,importError:c,templates:u,setTemplateOpen:o,openTemplates:d,copyTemplate:p,setters:{setTemplates:f,setTemplateError:a,setImportError:l}}}function Om(e,t){const n=URL.createObjectURL(new Blob([t],{type:"application/json"})),o=document.createElement("a");o.href=n,o.download=e,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e3)}function zm(e,t){switch(t){case"TEMPLATE_FILE_KIND":case"TEMPLATE_FILE_INVALID":return e("nodeStudio.templates.importNotTemplate");case"TEMPLATE_FILE_VERSION":return e("nodeStudio.templates.importNewerVersion");case"TEMPLATE_FILE_TOO_LARGE":return e("nodeStudio.templates.importTooLarge");case"INVALID_TEMPLATE_GRAPH":return e("nodeStudio.templates.importInvalidGraph");case"INVALID_TEMPLATE_NAME":return e("nodeStudio.templates.importBadName");default:return e("nodeStudio.templates.importError")}}function Bm(e,t){const{t:n}=ae(),o=N.useCallback(async()=>{const c=window.prompt(n("nodeStudio.templates.namePrompt"));if(c?.trim())try{const l=await Am({name:c.trim(),graph:{nodes:e.nodes,edges:e.edges}});t.setTemplates(u=>[...u.filter(f=>f.id!==l.id),l]),e.showToast(n("nodeStudio.templates.saved"))}catch{e.showToast(n("nodeStudio.templates.saveError"),!0)}},[e,t,n]),r=N.useCallback(async c=>{const l=window.prompt(n("nodeStudio.templates.renamePrompt"),c.name);if(l?.trim())try{const u=await Dm(c.id,l.trim());t.setTemplates(f=>f.map(d=>d.id===u.id?u:d))}catch{t.setTemplateError(n("nodeStudio.templates.renameError"))}},[t,n]),i=N.useCallback(async c=>{try{await jm(c.id),t.setTemplates(l=>l.filter(u=>u.id!==c.id))}catch{t.setTemplateError(n("nodeStudio.templates.deleteError"))}},[t,n]),s=N.useCallback(async c=>{try{const l=await Rm(c.id);Om(Mm(c.name),JSON.stringify(l,null,2)),e.showToast(n("nodeStudio.templates.exported",{name:c.name}))}catch{e.showToast(n("nodeStudio.templates.exportError"),!0)}},[e,n]),a=N.useCallback(async c=>{if(c.size>$m){t.setImportError(n("nodeStudio.templates.importTooLarge"));return}try{const l=await Hm(await c.text());t.setTemplates(u=>[l,...u.filter(f=>f.id!==l.id)]),t.setImportError(null),e.showToast(n("nodeStudio.templates.imported",{name:l.name}))}catch(l){t.setImportError(zm(n,l?.code))}},[e,t,n]);return{saveTemplate:o,renameTemplate:r,removeTemplate:i,exportTemplate:s,importTemplate:a}}const Vm={SAME_DIRECTION:"nodeStudio.compatibility.sameDirection",TYPE_MISMATCH:"nodeStudio.compatibility.typeMismatch",CARDINALITY:"nodeStudio.compatibility.cardinality",SELF_EDGE:"nodeStudio.compatibility.selfEdge",DUPLICATE_EDGE:"nodeStudio.compatibility.duplicateEdge",CYCLE:"nodeStudio.compatibility.cycle",UNKNOWN_PORT:"nodeStudio.compatibility.unknownPort"};function Fm(e){const{t}=ae(),n=Q(T=>T.graphNodes),o=Q(T=>T.graphEdges),r=Q(T=>T.sessions),i=Q(T=>T.activeSessionId),s=Q(T=>T.switchSession),a=Q(T=>T.connectNodes),c=Q(T=>T.undoGraph),l=Q(T=>T.redoGraph),u=Q(T=>T.showToast),{fitView:f,screenToFlowPosition:d}=mn(),[p,g]=N.useState(""),v=N.useCallback(()=>requestAnimationFrame(()=>e.current?.focus()),[e]),w=N.useCallback(T=>{const L=t(Vm[T]);g(L),u(L,!0)},[u,t]),x={nodes:n,edges:o,fitView:f,restoreFocus:v,showToast:u},S=Lm(x),m=Bm(x,S.setters),y=Im({nodes:n,edges:o,connectNodes:a,screenToFlowPosition:d,surfaceReason:w,restoreFocus:v}),I=_m(x),b=km({nodes:n,edges:o,wrapperRef:e,screenToFlowPosition:d,showToast:u}),C=N.useMemo(()=>r.filter(T=>T.id!==i&&T.nodeCount>0).sort((T,L)=>L.updatedAt-T.updatedAt)[0]??null,[i,r]),E=N.useCallback(()=>{y.setPalette(null),S.setTemplateOpen(!1),I.setBranchOpen(!1),v()},[I.setBranchOpen,y.setPalette,v,S.setTemplateOpen]),A=N.useCallback(T=>{const L=hm(T);if(L){(L==="undo"?c():l())&&(T.preventDefault(),u(t(L==="undo"?"graph.undone":"graph.redone")));return}if(T.key==="Escape"&&(y.palette||S.templateOpen||I.branchOpen)){T.preventDefault(),E();return}fm(T,e.current,n.length===0)&&(T.preventDefault(),y.setPalette({anchor:pm(e.current)}))},[I.branchOpen,E,y.palette,y.setPalette,n.length,l,u,t,S.templateOpen,c,e]),B=N.useCallback(async()=>{if(C)try{await s(C.id)}catch{u(t("nodeStudio.empty.resumeError"),!0)}},[C,u,s,t]);return{commands:um,...y,...I,...b,...S,status:p,hasRecentGraph:!!C,onKeyDown:A,resumeRecent:B,closeOverlays:E,closePalette:E,openTemplates:()=>{S.openTemplates()},saveTemplate:()=>{m.saveTemplate()},copyTemplate:S.copyTemplate,renameTemplate:T=>{m.renameTemplate(T)},removeTemplate:T=>{m.removeTemplate(T)},exportTemplate:T=>{m.exportTemplate(T)},importTemplate:T=>{m.importTemplate(T)},openBranch:()=>I.setBranchOpen(!0)}}function Ym(){const{t:e}=ae(),t=pc(),n=Q(y=>y.graphNodes),o=Q(y=>y.graphEdges),r=Q(y=>y.setGraphNodes),i=Q(y=>y.setGraphEdges),s=Q(y=>y.disconnectEdges),a=Q(y=>y.addRootNode),c=Q(y=>y.deleteNodes),l=Q(y=>y.nodeSelectionMode),u=Q(y=>y.selectNodeGraph),f=Q(y=>y.sessionLoading),d=N.useRef(null),p=Fm(d),g=N.useMemo(()=>({imageNode:jg,elementReferenceNode:Hg}),[]),v=N.useMemo(()=>{const y=gc(n,o),I=new Map,b=new Set(y.map(E=>E.id));for(const E of y)I.set(E.target,(I.get(E.target)??0)+1);const C=new Set;return o.map(E=>{if(!b.has(E.id))return E;const A=!C.has(E.target);return C.add(E.target),(I.get(E.target)??0)<2?E:{...E,label:e(A?"edge.roleBase":"edge.roleRef"),labelBgPadding:[6,3],labelBgStyle:{fill:A?"var(--accent)":"var(--surface-2)"},labelStyle:{fill:A?"var(--accent-ink)":"var(--text)",fontSize:11,fontWeight:600},style:A?E.style:{...E.style,strokeDasharray:"6 4"}}})},[o,n,e]),w=N.useCallback(y=>r(ds(y,n)),[n,r]),x=N.useCallback(y=>{const I=y.filter(b=>b.type==="remove").map(b=>b.id);if(I.length>0){if(l)return;s(I);return}i(fs(y,o))},[s,o,l,i]),S=N.useCallback(y=>c(y.map(I=>I.id)),[c]),m=N.useCallback((y,I)=>{l&&(y.preventDefault(),u(I.id,y.metaKey||y.ctrlKey))},[l,u]);return h.jsxs("main",{className:`node-canvas${n.length===0?" node-canvas--empty":""}`,ref:d,tabIndex:0,onKeyDown:p.onKeyDown,children:[f&&h.jsx("div",{className:"node-canvas__loading",children:e("nodeCanvas.loading")}),h.jsxs(qp,{nodes:n,edges:v,onNodesChange:w,onEdgesChange:x,onConnect:p.onConnect,onConnectEnd:p.onConnectEnd,isValidConnection:p.isValidConnection,onDragOver:p.onDragOver,onDrop:p.onDropElement,onNodesDelete:S,onNodeClick:m,nodeTypes:g,connectionMode:Ze.Loose,connectionRadius:32,selectionOnDrag:l,multiSelectionKeyCode:l?null:void 0,panOnDrag:l?[2]:!0,fitView:!0,deleteKeyCode:l?null:["Delete","Backspace"],proOptions:{hideAttribution:!0},children:[n.length===0?h.jsx("div",{className:"node-studio-empty-overlay",children:h.jsx(Lg,{hasRecentGraph:p.hasRecentGraph,onStartBlank:()=>{f||a()},onOpenTemplates:p.openTemplates,onResumeRecent:p.resumeRecent})}):null,n.length>0?h.jsx($g,{}):null,h.jsx(lm,{studio:p,graphEmpty:n.length===0,disabled:f,onAddRoot:()=>a()}),h.jsx(tg,{gap:24,size:1.6,color:"var(--node-canvas-grid)",variant:Ae.Dots}),h.jsx(cg,{className:"node-canvas__controls"}),!t&&h.jsx(_g,{pannable:!0,zoomable:!0,maskColor:"var(--minimap-mask)",nodeColor:"var(--minimap-node-fill)",nodeStrokeColor:"var(--minimap-node-stroke)",style:{background:"var(--minimap-bg)",border:"1px solid var(--minimap-border)"}})]}),n.length>0?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",className:"node-canvas__add-root",onClick:()=>a(),title:e("nodeCanvas.addRootTitle"),children:"+"}),h.jsx("div",{className:"node-canvas__hint",children:e("nodeCanvas.hint")})]}):null]})}function qm(){return h.jsx(Os,{children:h.jsx(Ym,{})})}export{qm as NodeCanvas};