vendor: 9,379 bytes, line 1
1import{r as $i,g as lu,R as du,a as N,j as d}from"./motion-CMvrp_gs.js";import{D as Vo}from"./Dialog-B52UwJP5.js";import{b as rt,a as fu,x as hu,u as pu,n as gu,o as mu,v as yu,aF as xu,aE as wu,ap as vu,c as _u,z as bu,h as ns,b5 as Su,aD as Nu,L as Eu}from"./index-DkaRDxJ3.js";import{B as $e,a as Cu}from"./PageChrome-pWXXPDlV.js";import{I as He}from"./Icon-how9BNfN.js";import{I as dn}from"./fields-DoXwaz_J.js";import{u as Ti}from"./useIsPhone-nhVa0UBk.js";import{t as ku}from"./tokens-D9d0xwpt.js";import{D as zn,a as Mu,M as os,b as ju,d as tn,n as rs,e as Ln,f as Fo,g as Bn,c as nt,s as uo}from"./sam2PointObjects-BGWL8tXG.js";import{v as Iu,e as Pu,V as Ru,B as Au}from"./pickedFiles-DiBQe8vx.js";import{H as $u,M as Tu}from"./MaskReviewExtras-DIelsItu.js";import{M as Di}from"./Menu-Ca3t9YLs.js";import{T as Du}from"./TextField-CFVEw7Qm.js";import{a as Ou}from"./Switch-WuPnucMX.js";import{i as Hu}from"./runTiming-BtFNs5_r.js";import{S as zu}from"./SegmentedControl-B_Hj2R4K.js";/* empty css */function we(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=we(e[n]))!==""&&(t+=(t&&" ")+o);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var Lu={value:()=>{}};function So(){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 no(n)}function no(e){this._=e}function Bu(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}})}no.prototype=So.prototype={constructor:no,on:function(e,t){var n=this._,o=Bu(e+"",n),r,s=-1,i=o.length;if(arguments.length<2){for(;++s<i;)if((r=(e=o[s]).type)&&(r=Vu(n[r],e.name)))return r;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++s<i;)if(r=(e=o[s]).type)n[r]=ss(n[r],e.name,t);else if(t==null)for(r in n)n[r]=ss(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 no(e)},call:function(e,t){if((r=arguments.length-2)>0)for(var n=new Array(r),o=0,r,s;o<r;++o)n[o]=arguments[o+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(s=this._[e],o=0,r=s.length;o<r;++o)s[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,s=o.length;r<s;++r)o[r].value.apply(t,n)}};function Vu(e,t){for(var n=0,o=e.length,r;n<o;++n)if((r=e[n]).name===t)return r.value}function ss(e,t,n){for(var o=0,r=e.length;o<r;++o)if(e[o].name===t){e[o]=Lu,e=e.slice(0,o).concat(e.slice(o+1));break}return n!=null&&e.push({name:t,value:n}),e}var ur="http://www.w3.org/1999/xhtml";const is={svg:"http://www.w3.org/2000/svg",xhtml:ur,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function No(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),is.hasOwnProperty(t)?{space:is[t],local:e}:e}function Fu(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===ur&&t.documentElement.namespaceURI===ur?t.createElement(e):t.createElementNS(n,e)}}function Uu(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Oi(e){var t=No(e);return(t.local?Uu:Fu)(t)}function Wu(){}function Cr(e){return e==null?Wu:function(){return this.querySelector(e)}}function Xu(e){typeof e!="function"&&(e=Cr(e));for(var t=this._groups,n=t.length,o=new Array(n),r=0;r<n;++r)for(var s=t[r],i=s.length,a=o[r]=new Array(i),c,u,l=0;l<i;++l)(c=s[l])&&(u=e.call(c,c.__data__,l,s))&&("__data__"in c&&(u.__data__=c.__data__),a[l]=u);return new Me(o,this._parents)}function Yu(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Zu(){return[]}function Hi(e){return e==null?Zu:function(){return this.querySelectorAll(e)}}function Gu(e){return function(){return Yu(e.apply(this,arguments))}}function Ku(e){typeof e=="function"?e=Gu(e):e=Hi(e);for(var t=this._groups,n=t.length,o=[],r=[],s=0;s<n;++s)for(var i=t[s],a=i.length,c,u=0;u<a;++u)(c=i[u])&&(o.push(e.call(c,c.__data__,u,i)),r.push(c));return new Me(o,r)}function zi(e){return function(){return this.matches(e)}}function Li(e){return function(t){return t.matches(e)}}var qu=Array.prototype.find;function Qu(e){return function(){return qu.call(this.children,e)}}function Ju(){return this.firstElementChild}function el(e){return this.select(e==null?Ju:Qu(typeof e=="function"?e:Li(e)))}var tl=Array.prototype.filter;function nl(){return Array.from(this.children)}function ol(e){return function(){return tl.call(this.children,e)}}function rl(e){return this.selectAll(e==null?nl:ol(typeof e=="function"?e:Li(e)))}function sl(e){typeof e!="function"&&(e=zi(e));for(var t=this._groups,n=t.length,o=new Array(n),r=0;r<n;++r)for(var s=t[r],i=s.length,a=o[r]=[],c,u=0;u<i;++u)(c=s[u])&&e.call(c,c.__data__,u,s)&&a.push(c);return new Me(o,this._parents)}function Bi(e){return new Array(e.length)}function il(){return new Me(this._enter||this._groups.map(Bi),this._parents)}function lo(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}lo.prototype={constructor:lo,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 al(e){return function(){return e}}function cl(e,t,n,o,r,s){for(var i=0,a,c=t.length,u=s.length;i<u;++i)(a=t[i])?(a.__data__=s[i],o[i]=a):n[i]=new lo(e,s[i]);for(;i<c;++i)(a=t[i])&&(r[i]=a)}function ul(e,t,n,o,r,s,i){var a,c,u=new Map,l=t.length,f=s.length,h=new Array(l),p;for(a=0;a<l;++a)(c=t[a])&&(h[a]=p=i.call(c,c.__data__,a,t)+"",u.has(p)?r[a]=c:u.set(p,c));for(a=0;a<f;++a)p=i.call(e,s[a],a,s)+"",(c=u.get(p))?(o[a]=c,c.__data__=s[a],u.delete(p)):n[a]=new lo(e,s[a]);for(a=0;a<l;++a)(c=t[a])&&u.get(h[a])===c&&(r[a]=c)}function ll(e){return e.__data__}function dl(e,t){if(!arguments.length)return Array.from(this,ll);var n=t?ul:cl,o=this._parents,r=this._groups;typeof e!="function"&&(e=al(e));for(var s=r.length,i=new Array(s),a=new Array(s),c=new Array(s),u=0;u<s;++u){var l=o[u],f=r[u],h=f.length,p=fl(e.call(l,l&&l.__data__,u,o)),g=p.length,v=a[u]=new Array(g),x=i[u]=new Array(g),y=c[u]=new Array(h);n(l,f,v,x,y,p,t);for(var S=0,m=0,w,k;S<g;++S)if(w=v[S]){for(S>=m&&(m=S+1);!(k=x[m])&&++m<g;);w._next=k||null}}return i=new Me(i,o),i._enter=a,i._exit=c,i}function fl(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function hl(){return new Me(this._exit||this._groups.map(Bi),this._parents)}function pl(e,t,n){var o=this.enter(),r=this,s=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?s.remove():n(s),o&&r?o.merge(r).order():r}function gl(e){for(var t=e.selection?e.selection():e,n=this._groups,o=t._groups,r=n.length,s=o.length,i=Math.min(r,s),a=new Array(r),c=0;c<i;++c)for(var u=n[c],l=o[c],f=u.length,h=a[c]=new Array(f),p,g=0;g<f;++g)(p=u[g]||l[g])&&(h[g]=p);for(;c<r;++c)a[c]=n[c];return new Me(a,this._parents)}function ml(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var o=e[t],r=o.length-1,s=o[r],i;--r>=0;)(i=o[r])&&(s&&i.compareDocumentPosition(s)^4&&s.parentNode.insertBefore(i,s),s=i);return this}function yl(e){e||(e=xl);function t(f,h){return f&&h?e(f.__data__,h.__data__):!f-!h}for(var n=this._groups,o=n.length,r=new Array(o),s=0;s<o;++s){for(var i=n[s],a=i.length,c=r[s]=new Array(a),u,l=0;l<a;++l)(u=i[l])&&(c[l]=u);c.sort(t)}return new Me(r,this._parents).order()}function xl(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function wl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function vl(){return Array.from(this)}function _l(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var o=e[t],r=0,s=o.length;r<s;++r){var i=o[r];if(i)return i}return null}function bl(){let e=0;for(const t of this)++e;return e}function Sl(){return!this.node()}function Nl(e){for(var t=this._groups,n=0,o=t.length;n<o;++n)for(var r=t[n],s=0,i=r.length,a;s<i;++s)(a=r[s])&&e.call(a,a.__data__,s,r);return this}function El(e){return function(){this.removeAttribute(e)}}function Cl(e){return function(){this.removeAttributeNS(e.space,e.local)}}function kl(e,t){return function(){this.setAttribute(e,t)}}function Ml(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function jl(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Il(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 Pl(e,t){var n=No(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?Cl:El:typeof t=="function"?n.local?Il:jl:n.local?Ml:kl)(n,t))}function Vi(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Rl(e){return function(){this.style.removeProperty(e)}}function Al(e,t,n){return function(){this.style.setProperty(e,t,n)}}
vendor: 4,404 bytes, line 1
1function $l(e,t,n){return function(){var o=t.apply(this,arguments);o==null?this.style.removeProperty(e):this.style.setProperty(e,o,n)}}function Tl(e,t,n){return arguments.length>1?this.each((t==null?Rl:typeof t=="function"?$l:Al)(e,t,n??"")):Ut(this.node(),e)}function Ut(e,t){return e.style.getPropertyValue(t)||Vi(e).getComputedStyle(e,null).getPropertyValue(t)}function Dl(e){return function(){delete this[e]}}function Ol(e,t){return function(){this[e]=t}}function Hl(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function zl(e,t){return arguments.length>1?this.each((t==null?Dl:typeof t=="function"?Hl:Ol)(e,t)):this.node()[e]}function Fi(e){return e.trim().split(/^|\s+/)}function kr(e){return e.classList||new Ui(e)}function Ui(e){this._node=e,this._names=Fi(e.getAttribute("class")||"")}Ui.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 Wi(e,t){for(var n=kr(e),o=-1,r=t.length;++o<r;)n.add(t[o])}function Xi(e,t){for(var n=kr(e),o=-1,r=t.length;++o<r;)n.remove(t[o])}function Ll(e){return function(){Wi(this,e)}}function Bl(e){return function(){Xi(this,e)}}function Vl(e,t){return function(){(t.apply(this,arguments)?Wi:Xi)(this,e)}}function Fl(e,t){var n=Fi(e+"");if(arguments.length<2){for(var o=kr(this.node()),r=-1,s=n.length;++r<s;)if(!o.contains(n[r]))return!1;return!0}return this.each((typeof t=="function"?Vl:t?Ll:Bl)(n,t))}function Ul(){this.textContent=""}function Wl(e){return function(){this.textContent=e}}function Xl(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function Yl(e){return arguments.length?this.each(e==null?Ul:(typeof e=="function"?Xl:Wl)(e)):this.node().textContent}function Zl(){this.innerHTML=""}function Gl(e){return function(){this.innerHTML=e}}function Kl(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function ql(e){return arguments.length?this.each(e==null?Zl:(typeof e=="function"?Kl:Gl)(e)):this.node().innerHTML}function Ql(){this.nextSibling&&this.parentNode.appendChild(this)}function Jl(){return this.each(Ql)}function ed(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function td(){return this.each(ed)}function nd(e){var t=typeof e=="function"?e:Oi(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function od(){return null}function rd(e,t){var n=typeof e=="function"?e:Oi(e),o=t==null?od:typeof t=="function"?t:Cr(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),o.apply(this,arguments)||null)})}function sd(){var e=this.parentNode;e&&e.removeChild(this)}function id(){return this.each(sd)}function ad(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function cd(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function ud(e){return this.select(e?cd:ad)}function ld(e){return arguments.length?this.property("__data__",e):this.node().__data__}function dd(e){return function(t){e.call(this,t,this.__data__)}}function fd(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 hd(e){return function(){var t=this.__on;if(t){for(var n=0,o=-1,r=t.length,s;n<r;++n)s=t[n],(!e.type||s.type===e.type)&&s.name===e.name?this.removeEventListener(s.type,s.listener,s.options):t[++o]=s;++o?t.length=o:delete this.__on}}}function pd(e,t,n){return function(){var o=this.__on,r,s=dd(t);if(o){for(var i=0,a=o.length;i<a;++i)if((r=o[i]).type===e.type&&r.name===e.name){this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=s,r.options=n),r.value=t;return}}this.addEventListener(e.type,s,n),r={type:e.type,name:e.name,value:t,listener:s,options:n},o?o.push(r):this.__on=[r]}}function gd(e,t,n){var o=fd(e+""),r,s=o.length,i;if(arguments.length<2){var a=this.node().__on;if(a){for(var c=0,u=a.length,l;c<u;++c)for(r=0,l=a[c];r<s;++r)if((i=o[r]).type===l.type&&i.name===l.name)return l.value}return}for(a=t?pd:hd,r=0;r<s;++r)this.each(a(o[r],t,n));return this}
vendor: 5,443 bytes, line 1
1function Yi(e,t,n){var o=Vi(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 md(e,t){return function(){return Yi(this,e,t)}}function yd(e,t){return function(){return Yi(this,e,t.apply(this,arguments))}}function xd(e,t){return this.each((typeof t=="function"?yd:md)(e,t))}function*wd(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var o=e[t],r=0,s=o.length,i;r<s;++r)(i=o[r])&&(yield i)}var Zi=[null];function Me(e,t){this._groups=e,this._parents=t}function _n(){return new Me([[document.documentElement]],Zi)}function vd(){return this}Me.prototype=_n.prototype={constructor:Me,select:Xu,selectAll:Ku,selectChild:el,selectChildren:rl,filter:sl,data:dl,enter:il,exit:hl,join:pl,merge:gl,selection:vd,order:ml,sort:yl,call:wl,nodes:vl,node:_l,size:bl,empty:Sl,each:Nl,attr:Pl,style:Tl,property:zl,classed:Fl,text:Yl,html:ql,raise:Jl,lower:td,append:nd,insert:rd,remove:id,clone:ud,datum:ld,on:gd,dispatch:xd,[Symbol.iterator]:wd};function ke(e){return typeof e=="string"?new Me([[document.querySelector(e)]],[document.documentElement]):new Me([[e]],Zi)}function _d(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Ae(e,t){if(e=_d(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 bd={passive:!1},fn={capture:!0,passive:!1};function Uo(e){e.stopImmediatePropagation()}function Vt(e){e.preventDefault(),e.stopImmediatePropagation()}function Gi(e){var t=e.document.documentElement,n=ke(e).on("dragstart.drag",Vt,fn);"onselectstart"in t?n.on("selectstart.drag",Vt,fn):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Ki(e,t){var n=e.document.documentElement,o=ke(e).on("dragstart.drag",null);t&&(o.on("click.drag",Vt,fn),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 Vn=e=>()=>e;function lr(e,{sourceEvent:t,subject:n,target:o,identifier:r,active:s,x:i,y:a,dx:c,dy:u,dispatch:l}){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:s,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:l}})}lr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Sd(e){return!e.ctrlKey&&!e.button}function Nd(){return this.parentNode}function Ed(e,t){return t??{x:e.x,y:e.y}}function Cd(){return navigator.maxTouchPoints||"ontouchstart"in this}function qi(){var e=Sd,t=Nd,n=Ed,o=Cd,r={},s=So("start","drag","end"),i=0,a,c,u,l,f=0;function h(w){w.on("mousedown.drag",p).filter(o).on("touchstart.drag",x).on("touchmove.drag",y,bd).on("touchend.drag touchcancel.drag",S).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(w,k){if(!(l||!e.call(this,w,k))){var C=m(this,t.call(this,w,k),w,k,"mouse");C&&(ke(w.view).on("mousemove.drag",g,fn).on("mouseup.drag",v,fn),Gi(w.view),Uo(w),u=!1,a=w.clientX,c=w.clientY,C("start",w))}}function g(w){if(Vt(w),!u){var k=w.clientX-a,C=w.clientY-c;u=k*k+C*C>f}r.mouse("drag",w)}function v(w){ke(w.view).on("mousemove.drag mouseup.drag",null),Ki(w.view,u),Vt(w),r.mouse("end",w)}function x(w,k){if(e.call(this,w,k)){var C=w.changedTouches,j=t.call(this,w,k),M=C.length,A,L;for(A=0;A<M;++A)(L=m(this,j,w,k,C[A].identifier,C[A]))&&(Uo(w),L("start",w,C[A]))}}function y(w){var k=w.changedTouches,C=k.length,j,M;for(j=0;j<C;++j)(M=r[k[j].identifier])&&(Vt(w),M("drag",w,k[j]))}function S(w){var k=w.changedTouches,C=k.length,j,M;for(l&&clearTimeout(l),l=setTimeout(function(){l=null},500),j=0;j<C;++j)(M=r[k[j].identifier])&&(Uo(w),M("end",w,k[j]))}function m(w,k,C,j,M,A){var L=s.copy(),$=Ae(A||C,k),H,D,_;if((_=n.call(w,new lr("beforestart",{sourceEvent:C,target:h,identifier:M,active:i,x:$[0],y:$[1],dx:0,dy:0,dispatch:L}),j))!=null)return H=_.x-$[0]||0,D=_.y-$[1]||0,function E(b,I,P){var T=$,U;switch(b){case"start":r[M]=E,U=i++;break;case"end":delete r[M],--i;case"drag":$=Ae(P||I,k),U=i;break}L.call(b,w,new lr(b,{sourceEvent:I,subject:_,target:h,identifier:M,active:U,x:$[0]+H,y:$[1]+D,dx:$[0]-T[0],dy:$[1]-T[1],dispatch:L}),j)}}return h.filter=function(w){return arguments.length?(e=typeof w=="function"?w:Vn(!!w),h):e},h.container=function(w){return arguments.length?(t=typeof w=="function"?w:Vn(w),h):t},h.subject=function(w){return arguments.length?(n=typeof w=="function"?w:Vn(w),h):n},h.touchable=function(w){return arguments.length?(o=typeof w=="function"?w:Vn(!!w),h):o},h.on=function(){var w=s.on.apply(s,arguments);return w===s?h:w},h.clickDistance=function(w){return arguments.length?(f=(w=+w)*w,h):Math.sqrt(f)},h}function Mr(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Qi(e,t){var n=Object.create(e.prototype);
vendor: 7,444 bytes, line 1
1for(var o in t)n[o]=t[o];return n}function bn(){}var hn=.7,fo=1/hn,Ft="\\s*([+-]?\\d+)\\s*",pn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Ue="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",kd=/^#([0-9a-f]{3,8})$/,Md=new RegExp(`^rgb\\(${Ft},${Ft},${Ft}\\)$`),jd=new RegExp(`^rgb\\(${Ue},${Ue},${Ue}\\)$`),Id=new RegExp(`^rgba\\(${Ft},${Ft},${Ft},${pn}\\)$`),Pd=new RegExp(`^rgba\\(${Ue},${Ue},${Ue},${pn}\\)$`),Rd=new RegExp(`^hsl\\(${pn},${Ue},${Ue}\\)$`),Ad=new RegExp(`^hsla\\(${pn},${Ue},${Ue},${pn}\\)$`),as={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};Mr(bn,_t,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:cs,formatHex:cs,formatHex8:$d,formatHsl:Td,formatRgb:us,toString:us});function cs(){return this.rgb().formatHex()}function $d(){return this.rgb().formatHex8()}function Td(){return Ji(this).formatHsl()}function us(){return this.rgb().formatRgb()}function _t(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=kd.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?ls(t):n===3?new Ee(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Fn(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Fn(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=Md.exec(e))?new Ee(t[1],t[2],t[3],1):(t=jd.exec(e))?new Ee(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Id.exec(e))?Fn(t[1],t[2],t[3],t[4]):(t=Pd.exec(e))?Fn(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Rd.exec(e))?hs(t[1],t[2]/100,t[3]/100,1):(t=Ad.exec(e))?hs(t[1],t[2]/100,t[3]/100,t[4]):as.hasOwnProperty(e)?ls(as[e]):e==="transparent"?new Ee(NaN,NaN,NaN,0):null}function ls(e){return new Ee(e>>16&255,e>>8&255,e&255,1)}function Fn(e,t,n,o){return o<=0&&(e=t=n=NaN),new Ee(e,t,n,o)}function Dd(e){return e instanceof bn||(e=_t(e)),e?(e=e.rgb(),new Ee(e.r,e.g,e.b,e.opacity)):new Ee}function dr(e,t,n,o){return arguments.length===1?Dd(e):new Ee(e,t,n,o??1)}function Ee(e,t,n,o){this.r=+e,this.g=+t,this.b=+n,this.opacity=+o}Mr(Ee,dr,Qi(bn,{brighter(e){return e=e==null?fo:Math.pow(fo,e),new Ee(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?hn:Math.pow(hn,e),new Ee(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ee(wt(this.r),wt(this.g),wt(this.b),ho(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:ds,formatHex:ds,formatHex8:Od,formatRgb:fs,toString:fs}));function ds(){return`#${xt(this.r)}${xt(this.g)}${xt(this.b)}`}function Od(){return`#${xt(this.r)}${xt(this.g)}${xt(this.b)}${xt((isNaN(this.opacity)?1:this.opacity)*255)}`}function fs(){const e=ho(this.opacity);return`${e===1?"rgb(":"rgba("}${wt(this.r)}, ${wt(this.g)}, ${wt(this.b)}${e===1?")":`, ${e})`}`}function ho(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function wt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function xt(e){return e=wt(e),(e<16?"0":"")+e.toString(16)}function hs(e,t,n,o){return o<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Te(e,t,n,o)}function Ji(e){if(e instanceof Te)return new Te(e.h,e.s,e.l,e.opacity);if(e instanceof bn||(e=_t(e)),!e)return new Te;if(e instanceof Te)return e;e=e.rgb();var t=e.r/255,n=e.g/255,o=e.b/255,r=Math.min(t,n,o),s=Math.max(t,n,o),i=NaN,a=s-r,c=(s+r)/2;return a?(t===s?i=(n-o)/a+(n<o)*6:n===s?i=(o-t)/a+2:i=(t-n)/a+4,a/=c<.5?s+r:2-s-r,i*=60):a=c>0&&c<1?0:i,new Te(i,a,c,e.opacity)}function Hd(e,t,n,o){return arguments.length===1?Ji(e):new Te(e,t,n,o??1)}function Te(e,t,n,o){this.h=+e,this.s=+t,this.l=+n,this.opacity=+o}Mr(Te,Hd,Qi(bn,{brighter(e){return e=e==null?fo:Math.pow(fo,e),new Te(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?hn:Math.pow(hn,e),new Te(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 Ee(Wo(e>=240?e-240:e+120,r,o),Wo(e,r,o),Wo(e<120?e+240:e-120,r,o),this.opacity)},clamp(){return new Te(ps(this.h),Un(this.s),Un(this.l),ho(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=ho(this.opacity);return`${e===1?"hsl(":"hsla("}${ps(this.h)}, ${Un(this.s)*100}%, ${Un(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ps(e){return e=(e||0)%360,e<0?e+360:e}function Un(e){return Math.max(0,Math.min(1,e||0))}function Wo(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 jr=e=>()=>e;function zd(e,t){return function(n){return e+n*t}}function Ld(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 Bd(e){return(e=+e)==1?ea:function(t,n){return n-t?Ld(t,n,e):jr(isNaN(t)?n:t)}}function ea(e,t){var n=t-e;
vendor: 11,764 bytes, line 1
1return n?zd(e,n):jr(isNaN(e)?t:e)}const po=(function e(t){var n=Bd(t);function o(r,s){var i=n((r=dr(r)).r,(s=dr(s)).r),a=n(r.g,s.g),c=n(r.b,s.b),u=ea(r.opacity,s.opacity);return function(l){return r.r=i(l),r.g=a(l),r.b=c(l),r.opacity=u(l),r+""}}return o.gamma=e,o})(1);function Vd(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,o=t.slice(),r;return function(s){for(r=0;r<n;++r)o[r]=e[r]*(1-s)+t[r]*s;return o}}function Fd(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Ud(e,t){var n=t?t.length:0,o=e?Math.min(n,e.length):0,r=new Array(o),s=new Array(n),i;for(i=0;i<o;++i)r[i]=un(e[i],t[i]);for(;i<n;++i)s[i]=t[i];return function(a){for(i=0;i<o;++i)s[i]=r[i](a);return s}}function Wd(e,t){var n=new Date;return e=+e,t=+t,function(o){return n.setTime(e*(1-o)+t*o),n}}function Ve(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Xd(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]=un(e[r],t[r]):o[r]=t[r];return function(s){for(r in n)o[r]=n[r](s);return o}}var fr=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Xo=new RegExp(fr.source,"g");function Yd(e){return function(){return e}}function Zd(e){return function(t){return e(t)+""}}function ta(e,t){var n=fr.lastIndex=Xo.lastIndex=0,o,r,s,i=-1,a=[],c=[];for(e=e+"",t=t+"";(o=fr.exec(e))&&(r=Xo.exec(t));)(s=r.index)>n&&(s=t.slice(n,s),a[i]?a[i]+=s:a[++i]=s),(o=o[0])===(r=r[0])?a[i]?a[i]+=r:a[++i]=r:(a[++i]=null,c.push({i,x:Ve(o,r)})),n=Xo.lastIndex;return n<t.length&&(s=t.slice(n),a[i]?a[i]+=s:a[++i]=s),a.length<2?c[0]?Zd(c[0].x):Yd(t):(t=c.length,function(u){for(var l=0,f;l<t;++l)a[(f=c[l]).i]=f.x(u);return a.join("")})}function un(e,t){var n=typeof t,o;return t==null||n==="boolean"?jr(t):(n==="number"?Ve:n==="string"?(o=_t(t))?(t=o,po):ta:t instanceof _t?po:t instanceof Date?Wd:Fd(t)?Vd:Array.isArray(t)?Ud:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?Xd:Ve)(e,t)}var gs=180/Math.PI,hr={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function na(e,t,n,o,r,s){var i,a,c;return(i=Math.sqrt(e*e+t*t))&&(e/=i,t/=i),(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,i=-i),{translateX:r,translateY:s,rotate:Math.atan2(t,e)*gs,skewX:Math.atan(c)*gs,scaleX:i,scaleY:a}}var Wn;function Gd(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?hr:na(t.a,t.b,t.c,t.d,t.e,t.f)}function Kd(e){return e==null||(Wn||(Wn=document.createElementNS("http://www.w3.org/2000/svg","g")),Wn.setAttribute("transform",e),!(e=Wn.transform.baseVal.consolidate()))?hr:(e=e.matrix,na(e.a,e.b,e.c,e.d,e.e,e.f))}function oa(e,t,n,o){function r(u){return u.length?u.pop()+" ":""}function s(u,l,f,h,p,g){if(u!==f||l!==h){var v=p.push("translate(",null,t,null,n);g.push({i:v-4,x:Ve(u,f)},{i:v-2,x:Ve(l,h)})}else(f||h)&&p.push("translate("+f+t+h+n)}function i(u,l,f,h){u!==l?(u-l>180?l+=360:l-u>180&&(u+=360),h.push({i:f.push(r(f)+"rotate(",null,o)-2,x:Ve(u,l)})):l&&f.push(r(f)+"rotate("+l+o)}function a(u,l,f,h){u!==l?h.push({i:f.push(r(f)+"skewX(",null,o)-2,x:Ve(u,l)}):l&&f.push(r(f)+"skewX("+l+o)}function c(u,l,f,h,p,g){if(u!==f||l!==h){var v=p.push(r(p)+"scale(",null,",",null,")");g.push({i:v-4,x:Ve(u,f)},{i:v-2,x:Ve(l,h)})}else(f!==1||h!==1)&&p.push(r(p)+"scale("+f+","+h+")")}return function(u,l){var f=[],h=[];return u=e(u),l=e(l),s(u.translateX,u.translateY,l.translateX,l.translateY,f,h),i(u.rotate,l.rotate,f,h),a(u.skewX,l.skewX,f,h),c(u.scaleX,u.scaleY,l.scaleX,l.scaleY,f,h),u=l=null,function(p){for(var g=-1,v=h.length,x;++g<v;)f[(x=h[g]).i]=x.x(p);return f.join("")}}}var qd=oa(Gd,"px, ","px)","deg)"),Qd=oa(Kd,", ",")",")"),Jd=1e-12;function ms(e){return((e=Math.exp(e))+1/e)/2}function ef(e){return((e=Math.exp(e))-1/e)/2}function tf(e){return((e=Math.exp(2*e))-1)/(e+1)}const oo=(function e(t,n,o){function r(s,i){var a=s[0],c=s[1],u=s[2],l=i[0],f=i[1],h=i[2],p=l-a,g=f-c,v=p*p+g*g,x,y;if(v<Jd)y=Math.log(h/u)/t,x=function(j){return[a+j*p,c+j*g,u*Math.exp(t*j*y)]};else{var S=Math.sqrt(v),m=(h*h-u*u+o*v)/(2*u*n*S),w=(h*h-u*u-o*v)/(2*h*n*S),k=Math.log(Math.sqrt(m*m+1)-m),C=Math.log(Math.sqrt(w*w+1)-w);y=(C-k)/t,x=function(j){var M=j*y,A=ms(k),L=u/(n*S)*(A*tf(t*M+k)-ef(k));return[a+L*p,c+L*g,u*A/ms(t*M+k)]}}return x.duration=y*1e3*t/Math.SQRT2,x}return r.rho=function(s){var i=Math.max(.001,+s),a=i*i,c=a*a;return e(i,a,c)},r})(Math.SQRT2,2,4);var Wt=0,sn=0,nn=0,ra=1e3,go,an,mo=0,bt=0,Eo=0,gn=typeof performance=="object"&&performance.now?performance:Date,sa=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Ir(){return bt||(sa(nf),bt=gn.now()+Eo)}function nf(){bt=0}function yo(){this._call=this._time=this._next=null}yo.prototype=ia.prototype={constructor:yo,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Ir():+n)+(t==null?0:+t),!this._next&&an!==this&&(an?an._next=this:go=this,an=this),this._call=e,this._time=n,pr()},stop:function(){this._call&&(this._call=null,this._time=1/0,pr())}};function ia(e,t,n){var o=new yo;return o.restart(e,t,n),o}function of(){Ir(),++Wt;for(var e=go,t;e;)(t=bt-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Wt}function ys(){bt=(mo=gn.now())+Eo,Wt=sn=0;try{of()}finally{Wt=0,sf(),bt=0}}function rf(){var e=gn.now(),t=e-mo;t>ra&&(Eo-=t,mo=e)}function sf(){for(var e,t=go,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:go=n);an=e,pr(o)}function pr(e){if(!Wt){sn&&(sn=clearTimeout(sn));var t=e-bt;t>24?(e<1/0&&(sn=setTimeout(ys,e-gn.now()-Eo)),nn&&(nn=clearInterval(nn))):(nn||(mo=gn.now(),nn=setInterval(rf,ra)),Wt=1,sa(ys))}}function xs(e,t,n){var o=new yo;return t=t==null?0:+t,o.restart(r=>{o.stop(),e(r+t)},t,n),o}var af=So("start","end","cancel","interrupt"),cf=[],aa=0,ws=1,gr=2,ro=3,vs=4,mr=5,so=6;function Co(e,t,n,o,r,s){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;uf(e,n,{name:t,index:o,group:r,on:af,tween:cf,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:aa})}function Pr(e,t){var n=Le(e,t);if(n.state>aa)throw new Error("too late; already scheduled");return n}function Xe(e,t){var n=Le(e,t);if(n.state>ro)throw new Error("too late; already running");return n}function Le(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function uf(e,t,n){var o=e.__transition,r;o[t]=n,n.timer=ia(s,0,n.time);function s(u){n.state=ws,n.timer.restart(i,n.delay,n.time),n.delay<=u&&i(u-n.delay)}function i(u){var l,f,h,p;if(n.state!==ws)return c();for(l in o)if(p=o[l],p.name===n.name){if(p.state===ro)return xs(i);p.state===vs?(p.state=so,p.timer.stop(),p.on.call("interrupt",e,e.__data__,p.index,p.group),delete o[l]):+l<t&&(p.state=so,p.timer.stop(),p.on.call("cancel",e,e.__data__,p.index,p.group),delete o[l])}if(xs(function(){n.state===ro&&(n.state=vs,n.timer.restart(a,n.delay,n.time),a(u))}),n.state=gr,n.on.call("start",e,e.__data__,n.index,n.group),n.state===gr){for(n.state=ro,r=new Array(h=n.tween.length),l=0,f=-1;l<h;++l)(p=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(r[++f]=p);r.length=f+1}}function a(u){for(var l=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(c),n.state=mr,1),f=-1,h=r.length;++f<h;)r[f].call(e,l);n.state===mr&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=so,n.timer.stop(),delete o[t];for(var u in o)return;delete e.__transition}}function io(e,t){var n=e.__transition,o,r,s=!0,i;if(n){t=t==null?null:t+"";for(i in n){if((o=n[i]).name!==t){s=!1;continue}r=o.state>gr&&o.state<mr,o.state=so,o.timer.stop(),o.on.call(r?"interrupt":"cancel",e,e.__data__,o.index,o.group),delete n[i]}s&&delete e.__transition}}function lf(e){return this.each(function(){io(this,e)})}function df(e,t){var n,o;return function(){var r=Xe(this,e),s=r.tween;if(s!==n){o=n=s;for(var i=0,a=o.length;i<a;++i)if(o[i].name===t){o=o.slice(),o.splice(i,1);break}}r.tween=o}}function ff(e,t,n){var o,r;if(typeof n!="function")throw new Error;return function(){var s=Xe(this,e),i=s.tween;if(i!==o){r=(o=i).slice();for(var a={name:t,value:n},c=0,u=r.length;c<u;++c)if(r[c].name===t){r[c]=a;break}c===u&&r.push(a)}s.tween=r}}function hf(e,t){var n=this._id;if(e+="",arguments.length<2){for(var o=Le(this.node(),n).tween,r=0,s=o.length,i;r<s;++r)if((i=o[r]).name===e)return i.value;return null}return this.each((t==null?df:ff)(n,e,t))}function Rr(e,t,n){var o=e._id;return e.each(function(){var r=Xe(this,o);(r.value||(r.value={}))[t]=n.apply(this,arguments)}),function(r){return Le(r,o).value[t]}}function ca(e,t){var n;return(typeof t=="number"?Ve:t instanceof _t?po:(n=_t(t))?(t=n,po):ta)(e,t)}function pf(e){return function(){this.removeAttribute(e)}}function gf(e){return function(){this.removeAttributeNS(e.space,e.local)}}function mf(e,t,n){var o,r=n+"",s;return function(){var i=this.getAttribute(e);return i===r?null:i===o?s:s=t(o=i,n)}}function yf(e,t,n){var o,r=n+"",s;return function(){var i=this.getAttributeNS(e.space,e.local);return i===r?null:i===o?s:s=t(o=i,n)}}function xf(e,t,n){var o,r,s;return function(){var i,a=n(this),c;return a==null?void this.removeAttribute(e):(i=this.getAttribute(e),c=a+"",i===c?null:i===o&&c===r?s:(r=c,s=t(o=i,a)))}}function wf(e,t,n){var o,r,s;return function(){var i,a=n(this),c;return a==null?void this.removeAttributeNS(e.space,e.local):(i=this.getAttributeNS(e.space,e.local),c=a+"",i===c?null:i===o&&c===r?s:(r=c,s=t(o=i,a)))}}function vf(e,t){var n=No(e),o=n==="transform"?Qd:ca;return this.attrTween(e,typeof t=="function"?(n.local?wf:xf)(n,o,Rr(this,"attr."+e,t)):t==null?(n.local?gf:pf)(n):(n.local?yf:mf)(n,o,t))}function _f(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function bf(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Sf(e,t){var n,o;function r(){var s=t.apply(this,arguments);return s!==o&&(n=(o=s)&&bf(e,s)),n}return r._value=t,r}function Nf(e,t){var n,o;function r(){var s=t.apply(this,arguments);return s!==o&&(n=(o=s)&&_f(e,s)),n}return r._value=t,r}function Ef(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=No(e);return this.tween(n,(o.local?Sf:Nf)(o,t))}function Cf(e,t){return function(){Pr(this,e).delay=+t.apply(this,arguments)}}function kf(e,t){return t=+t,function(){Pr(this,e).delay=t}}function Mf(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Cf:kf)(t,e)):Le(this.node(),t).delay}function jf(e,t){return function(){Xe(this,e).duration=+t.apply(this,arguments)}}function If(e,t){return t=+t,function(){Xe(this,e).duration=t}}function Pf(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?jf:If)(t,e)):Le(this.node(),t).duration}function Rf(e,t){if(typeof t!="function")throw new Error;return function(){Xe(this,e).ease=t}}function Af(e){var t=this._id;return arguments.length?this.each(Rf(t,e)):Le(this.node(),t).ease}function $f(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Xe(this,e).ease=n}}function Tf(e){if(typeof e!="function")throw new Error;return this.each($f(this._id,e))}function Df(e){typeof e!="function"&&(e=zi(e));for(var t=this._groups,n=t.length,o=new Array(n),r=0;r<n;++r)for(var s=t[r],i=s.length,a=o[r]=[],c,u=0;u<i;++u)(c=s[u])&&e.call(c,c.__data__,u,s)&&a.push(c);return new ot(o,this._parents,this._name,this._id)}function Of(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,o=t.length,r=n.length,s=Math.min(o,r),i=new Array(o),a=0;a<s;++a)for(var c=t[a],u=n[a],l=c.length,f=i[a]=new Array(l),h,p=0;p<l;
vendor: 4,075 bytes, line 1
1++p)(h=c[p]||u[p])&&(f[p]=h);for(;a<o;++a)i[a]=t[a];return new ot(i,this._parents,this._name,this._id)}function Hf(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 zf(e,t,n){var o,r,s=Hf(t)?Pr:Xe;return function(){var i=s(this,e),a=i.on;a!==o&&(r=(o=a).copy()).on(t,n),i.on=r}}function Lf(e,t){var n=this._id;return arguments.length<2?Le(this.node(),n).on.on(e):this.each(zf(n,e,t))}function Bf(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Vf(){return this.on("end.remove",Bf(this._id))}function Ff(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Cr(e));for(var o=this._groups,r=o.length,s=new Array(r),i=0;i<r;++i)for(var a=o[i],c=a.length,u=s[i]=new Array(c),l,f,h=0;h<c;++h)(l=a[h])&&(f=e.call(l,l.__data__,h,a))&&("__data__"in l&&(f.__data__=l.__data__),u[h]=f,Co(u[h],t,n,h,u,Le(l,n)));return new ot(s,this._parents,t,n)}function Uf(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Hi(e));for(var o=this._groups,r=o.length,s=[],i=[],a=0;a<r;++a)for(var c=o[a],u=c.length,l,f=0;f<u;++f)if(l=c[f]){for(var h=e.call(l,l.__data__,f,c),p,g=Le(l,n),v=0,x=h.length;v<x;++v)(p=h[v])&&Co(p,t,n,v,h,g);s.push(h),i.push(l)}return new ot(s,i,t,n)}var Wf=_n.prototype.constructor;function Xf(){return new Wf(this._groups,this._parents)}function Yf(e,t){var n,o,r;return function(){var s=Ut(this,e),i=(this.style.removeProperty(e),Ut(this,e));return s===i?null:s===n&&i===o?r:r=t(n=s,o=i)}}function ua(e){return function(){this.style.removeProperty(e)}}function Zf(e,t,n){var o,r=n+"",s;return function(){var i=Ut(this,e);return i===r?null:i===o?s:s=t(o=i,n)}}function Gf(e,t,n){var o,r,s;return function(){var i=Ut(this,e),a=n(this),c=a+"";return a==null&&(c=a=(this.style.removeProperty(e),Ut(this,e))),i===c?null:i===o&&c===r?s:(r=c,s=t(o=i,a))}}function Kf(e,t){var n,o,r,s="style."+t,i="end."+s,a;return function(){var c=Xe(this,e),u=c.on,l=c.value[s]==null?a||(a=ua(t)):void 0;(u!==n||r!==l)&&(o=(n=u).copy()).on(i,r=l),c.on=o}}function qf(e,t,n){var o=(e+="")=="transform"?qd:ca;return t==null?this.styleTween(e,Yf(e,o)).on("end.style."+e,ua(e)):typeof t=="function"?this.styleTween(e,Gf(e,o,Rr(this,"style."+e,t))).each(Kf(this._id,e)):this.styleTween(e,Zf(e,o,t),n).on("end.style."+e,null)}function Qf(e,t,n){return function(o){this.style.setProperty(e,t.call(this,o),n)}}function Jf(e,t,n){var o,r;function s(){var i=t.apply(this,arguments);return i!==r&&(o=(r=i)&&Qf(e,i,n)),o}return s._value=t,s}function eh(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,Jf(e,t,n??""))}function th(e){return function(){this.textContent=e}}function nh(e){return function(){var t=e(this);this.textContent=t??""}}function oh(e){return this.tween("text",typeof e=="function"?nh(Rr(this,"text",e)):th(e==null?"":e+""))}function rh(e){return function(t){this.textContent=e.call(this,t)}}function sh(e){var t,n;function o(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&rh(r)),t}return o._value=e,o}function ih(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,sh(e))}function ah(){for(var e=this._name,t=this._id,n=la(),o=this._groups,r=o.length,s=0;s<r;++s)for(var i=o[s],a=i.length,c,u=0;u<a;++u)if(c=i[u]){var l=Le(c,t);Co(c,e,n,u,i,{time:l.time+l.delay+l.duration,delay:0,duration:l.duration,ease:l.ease})}return new ot(o,this._parents,e,n)}function ch(){var e,t,n=this,o=n._id,r=n.size();return new Promise(function(s,i){var a={value:i},c={value:function(){--r===0&&s()}};n.each(function(){var u=Xe(this,o),l=u.on;l!==e&&(t=(e=l).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(c)),u.on=t}),r===0&&s()})}var uh=0;function ot(e,t,n,o){this._groups=e,this._parents=t,this._name=n,this._id=o}function la(){return++uh}var et=_n.prototype;
vendor: 11,307 bytes, line 1
1ot.prototype={constructor:ot,select:Ff,selectAll:Uf,selectChild:et.selectChild,selectChildren:et.selectChildren,filter:Df,merge:Of,selection:Xf,transition:ah,call:et.call,nodes:et.nodes,node:et.node,size:et.size,empty:et.empty,each:et.each,on:Lf,attr:vf,attrTween:Ef,style:qf,styleTween:eh,text:oh,textTween:ih,remove:Vf,tween:hf,delay:Mf,duration:Pf,ease:Af,easeVarying:Tf,end:ch,[Symbol.iterator]:et[Symbol.iterator]};function lh(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var dh={time:null,delay:0,duration:250,ease:lh};function fh(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 hh(e){var t,n;e instanceof ot?(t=e._id,e=e._name):(t=la(),(n=dh).time=Ir(),e=e==null?null:e+"");for(var o=this._groups,r=o.length,s=0;s<r;++s)for(var i=o[s],a=i.length,c,u=0;u<a;++u)(c=i[u])&&Co(c,e,t,u,i,n||fh(c,t));return new ot(o,this._parents,e,t)}_n.prototype.interrupt=lf;_n.prototype.transition=hh;const Xn=e=>()=>e;function ph(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 tt(e,t,n){this.k=e,this.x=t,this.y=n}tt.prototype={constructor:tt,scale:function(e){return e===1?this:new tt(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new tt(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 ko=new tt(1,0,0);da.prototype=tt.prototype;function da(e){for(;!e.__zoom;)if(!(e=e.parentNode))return ko;return e.__zoom}function Yo(e){e.stopImmediatePropagation()}function on(e){e.preventDefault(),e.stopImmediatePropagation()}function gh(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function mh(){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 _s(){return this.__zoom||ko}function yh(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function xh(){return navigator.maxTouchPoints||"ontouchstart"in this}function wh(e,t,n){var o=e.invertX(t[0][0])-n[0][0],r=e.invertX(t[1][0])-n[1][0],s=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(r>o?(o+r)/2:Math.min(0,o)||Math.max(0,r),i>s?(s+i)/2:Math.min(0,s)||Math.max(0,i))}function fa(){var e=gh,t=mh,n=wh,o=yh,r=xh,s=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],a=250,c=oo,u=So("start","zoom","end"),l,f,h,p=500,g=150,v=0,x=10;function y(_){_.property("__zoom",_s).on("wheel.zoom",M,{passive:!1}).on("mousedown.zoom",A).on("dblclick.zoom",L).filter(r).on("touchstart.zoom",$).on("touchmove.zoom",H).on("touchend.zoom touchcancel.zoom",D).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}y.transform=function(_,E,b,I){var P=_.selection?_.selection():_;P.property("__zoom",_s),_!==P?k(_,E,b,I):P.interrupt().each(function(){C(this,arguments).event(I).start().zoom(null,typeof E=="function"?E.apply(this,arguments):E).end()})},y.scaleBy=function(_,E,b,I){y.scaleTo(_,function(){var P=this.__zoom.k,T=typeof E=="function"?E.apply(this,arguments):E;return P*T},b,I)},y.scaleTo=function(_,E,b,I){y.transform(_,function(){var P=t.apply(this,arguments),T=this.__zoom,U=b==null?w(P):typeof b=="function"?b.apply(this,arguments):b,z=T.invert(U),V=typeof E=="function"?E.apply(this,arguments):E;return n(m(S(T,V),U,z),P,i)},b,I)},y.translateBy=function(_,E,b,I){y.transform(_,function(){return n(this.__zoom.translate(typeof E=="function"?E.apply(this,arguments):E,typeof b=="function"?b.apply(this,arguments):b),t.apply(this,arguments),i)},null,I)},y.translateTo=function(_,E,b,I,P){y.transform(_,function(){var T=t.apply(this,arguments),U=this.__zoom,z=I==null?w(T):typeof I=="function"?I.apply(this,arguments):I;return n(ko.translate(z[0],z[1]).scale(U.k).translate(typeof E=="function"?-E.apply(this,arguments):-E,typeof b=="function"?-b.apply(this,arguments):-b),T,i)},I,P)};function S(_,E){return E=Math.max(s[0],Math.min(s[1],E)),E===_.k?_:new tt(E,_.x,_.y)}function m(_,E,b){var I=E[0]-b[0]*_.k,P=E[1]-b[1]*_.k;return I===_.x&&P===_.y?_:new tt(_.k,I,P)}function w(_){return[(+_[0][0]+ +_[1][0])/2,(+_[0][1]+ +_[1][1])/2]}function k(_,E,b,I){_.on("start.zoom",function(){C(this,arguments).event(I).start()}).on("interrupt.zoom end.zoom",function(){C(this,arguments).event(I).end()}).tween("zoom",function(){var P=this,T=arguments,U=C(P,T).event(I),z=t.apply(P,T),V=b==null?w(z):typeof b=="function"?b.apply(P,T):b,K=Math.max(z[1][0]-z[0][0],z[1][1]-z[0][1]),q=P.__zoom,oe=typeof E=="function"?E.apply(P,T):E,se=c(q.invert(V).concat(K/q.k),oe.invert(V).concat(K/oe.k));return function(te){if(te===1)te=oe;else{var B=se(te),O=K/B[2];te=new tt(O,V[0]-B[0]*O,V[1]-B[1]*O)}U.zoom(null,te)}})}function C(_,E,b){return!b&&_.__zooming||new j(_,E)}function j(_,E){this.that=_,this.args=E,this.active=0,this.sourceEvent=null,this.extent=t.apply(_,E),this.taps=0}j.prototype={event:function(_){return _&&(this.sourceEvent=_),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(_,E){return this.mouse&&_!=="mouse"&&(this.mouse[1]=E.invert(this.mouse[0])),this.touch0&&_!=="touch"&&(this.touch0[1]=E.invert(this.touch0[0])),this.touch1&&_!=="touch"&&(this.touch1[1]=E.invert(this.touch1[0])),this.that.__zoom=E,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(_){var E=ke(this.that).datum();u.call(_,this.that,new ph(_,{sourceEvent:this.sourceEvent,target:y,transform:this.that.__zoom,dispatch:u}),E)}};function M(_,...E){if(!e.apply(this,arguments))return;var b=C(this,E).event(_),I=this.__zoom,P=Math.max(s[0],Math.min(s[1],I.k*Math.pow(2,o.apply(this,arguments)))),T=Ae(_);if(b.wheel)(b.mouse[0][0]!==T[0]||b.mouse[0][1]!==T[1])&&(b.mouse[1]=I.invert(b.mouse[0]=T)),clearTimeout(b.wheel);else{if(I.k===P)return;b.mouse=[T,I.invert(T)],io(this),b.start()}on(_),b.wheel=setTimeout(U,g),b.zoom("mouse",n(m(S(I,P),b.mouse[0],b.mouse[1]),b.extent,i));function U(){b.wheel=null,b.end()}}function A(_,...E){if(h||!e.apply(this,arguments))return;var b=_.currentTarget,I=C(this,E,!0).event(_),P=ke(_.view).on("mousemove.zoom",V,!0).on("mouseup.zoom",K,!0),T=Ae(_,b),U=_.clientX,z=_.clientY;Gi(_.view),Yo(_),I.mouse=[T,this.__zoom.invert(T)],io(this),I.start();function V(q){if(on(q),!I.moved){var oe=q.clientX-U,se=q.clientY-z;I.moved=oe*oe+se*se>v}I.event(q).zoom("mouse",n(m(I.that.__zoom,I.mouse[0]=Ae(q,b),I.mouse[1]),I.extent,i))}function K(q){P.on("mousemove.zoom mouseup.zoom",null),Ki(q.view,I.moved),on(q),I.event(q).end()}}function L(_,...E){if(e.apply(this,arguments)){var b=this.__zoom,I=Ae(_.changedTouches?_.changedTouches[0]:_,this),P=b.invert(I),T=b.k*(_.shiftKey?.5:2),U=n(m(S(b,T),I,P),t.apply(this,E),i);on(_),a>0?ke(this).transition().duration(a).call(k,U,I,_):ke(this).call(y.transform,U,I,_)}}function $(_,...E){if(e.apply(this,arguments)){var b=_.touches,I=b.length,P=C(this,E,_.changedTouches.length===I).event(_),T,U,z,V;for(Yo(_),U=0;U<I;++U)z=b[U],V=Ae(z,this),V=[V,this.__zoom.invert(V),z.identifier],P.touch0?!P.touch1&&P.touch0[2]!==V[2]&&(P.touch1=V,P.taps=0):(P.touch0=V,T=!0,P.taps=1+!!l);l&&(l=clearTimeout(l)),T&&(P.taps<2&&(f=V[0],l=setTimeout(function(){l=null},p)),io(this),P.start())}}function H(_,...E){if(this.__zooming){var b=C(this,E).event(_),I=_.changedTouches,P=I.length,T,U,z,V;for(on(_),T=0;T<P;++T)U=I[T],z=Ae(U,this),b.touch0&&b.touch0[2]===U.identifier?b.touch0[0]=z:b.touch1&&b.touch1[2]===U.identifier&&(b.touch1[0]=z);if(U=b.that.__zoom,b.touch1){var K=b.touch0[0],q=b.touch0[1],oe=b.touch1[0],se=b.touch1[1],te=(te=oe[0]-K[0])*te+(te=oe[1]-K[1])*te,B=(B=se[0]-q[0])*B+(B=se[1]-q[1])*B;U=S(U,Math.sqrt(te/B)),z=[(K[0]+oe[0])/2,(K[1]+oe[1])/2],V=[(q[0]+se[0])/2,(q[1]+se[1])/2]}else if(b.touch0)z=b.touch0[0],V=b.touch0[1];else return;b.zoom("touch",n(m(U,z,V),b.extent,i))}}function D(_,...E){if(this.__zooming){var b=C(this,E).event(_),I=_.changedTouches,P=I.length,T,U;for(Yo(_),h&&clearTimeout(h),h=setTimeout(function(){h=null},p),T=0;T<P;++T)U=I[T],b.touch0&&b.touch0[2]===U.identifier?delete b.touch0:b.touch1&&b.touch1[2]===U.identifier&&delete b.touch1;if(b.touch1&&!b.touch0&&(b.touch0=b.touch1,delete b.touch1),b.touch0)b.touch0[1]=this.__zoom.invert(b.touch0[0]);else if(b.end(),b.taps===2&&(U=Ae(U,this),Math.hypot(f[0]-U[0],f[1]-U[1])<x)){var z=ke(this).on("dblclick.zoom");z&&z.apply(this,arguments)}}}return y.wheelDelta=function(_){return arguments.length?(o=typeof _=="function"?_:Xn(+_),y):o},y.filter=function(_){return arguments.length?(e=typeof _=="function"?_:Xn(!!_),y):e},y.touchable=function(_){return arguments.length?(r=typeof _=="function"?_:Xn(!!_),y):r},y.extent=function(_){return arguments.length?(t=typeof _=="function"?_:Xn([[+_[0][0],+_[0][1]],[+_[1][0],+_[1][1]]]),y):t},y.scaleExtent=function(_){return arguments.length?(s[0]=+_[0],s[1]=+_[1],y):[s[0],s[1]]},y.translateExtent=function(_){return arguments.length?(i[0][0]=+_[0][0],i[1][0]=+_[1][0],i[0][1]=+_[0][1],i[1][1]=+_[1][1],y):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},y.constrain=function(_){return arguments.length?(n=_,y):n},y.duration=function(_){return arguments.length?(a=+_,y):a},y.interpolate=function(_){return arguments.length?(c=_,y):c},y.on=function(){var _=u.on.apply(u,arguments);return _===u?y:_},y.clickDistance=function(_){return arguments.length?(v=(_=+_)*_,y):Math.sqrt(v)},y.tapDistance=function(_){return arguments.length?(x=+_,y):x},y}const ze={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=>
1`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.`},mn=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ha=["Enter"," ","Escape"],pa={"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 Xt;(function(e){e.Strict="strict",e.Loose="loose"})(Xt||(Xt={}));var vt;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(vt||(vt={}));var yn;(function(e){e.Partial="partial",e.Full="full"})(yn||(yn={}));const ga={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var ft;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(ft||(ft={}));var xo;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(xo||(xo={}));var ne;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ne||(ne={}));const bs={[ne.Left]:ne.Right,[ne.Right]:ne.Left,[ne.Top]:ne.Bottom,[ne.Bottom]:ne.Top};function ma(e){return e===null?null:e?"valid":"invalid"}const ya=e=>!!e&&typeof e=="object"&&"id"in e&&"source"in e&&"target"in e,vh=e=>!!e&&typeof e=="object"&&"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Ar=e=>!!e&&typeof e=="object"&&"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Sn=(e,t=[0,0])=>{const{width:n,height:o}=Ye(e),r=e.origin??t,s=n*r[0],i=o*r[1];return{x:e.position.x-s,y:e.position.y-i}},_h=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((o,r)=>{const s=typeof r=="string";let i=!t.nodeLookup&&!s?r:void 0;t.nodeLookup&&(i=s?t.nodeLookup.get(r):Ar(r)?r:t.nodeLookup.get(r.id));const a=i?wo(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Mo(o,a)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return jo(n)},Nn=(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=Mo(n,wo(r)),o=!0)}),o?jo(n):{x:0,y:0,width:0,height:0}},$r=(e,t,[n,o,r]=[0,0,1],s=!1,i=!1)=>{const a=(t.x-n)/r,c=(t.y-o)/r,u=t.width/r,l=t.height/r,f=[];for(const h of e.values()){const{measured:p,selectable:g=!0,hidden:v=!1}=h;if(i&&!g||v)continue;const x=p.width??h.width??h.initialWidth??0,y=p.height??h.height??h.initialHeight??0,{x:S,y:m}=h.internals.positionAbsolute,w=_a(a,c,u,l,S,m,x,y),k=x*y,C=s&&w>0;(!h.internals.handleBounds||C||w>=k||h.dragging)&&f.push(h)}return f},bh=(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 Sh(e,t){const n=new Map,o=t?.nodes?new Set(t.nodes.map(r=>r.id)):null;return e.forEach(r=>{let s;if(t?.includeHiddenNodes){const{width:i,height:a}=Ye(r);s=i>0&&a>0}else s=!!(r.measured.width&&r.measured.height&&!r.hidden);s&&(!o||o.has(r.id))&&n.set(r.id,r)}),n}
1async function Nh({nodes:e,width:t,height:n,panZoom:o,minZoom:r,maxZoom:s},i){if(e.size===0)return!0;const a=Sh(e,i),c=Nn(a),u=Dr(c,t,n,i?.minZoom??r,i?.maxZoom??s,i?.padding??.1);return await o.setViewport(u,{duration:i?.duration,ease:i?.ease,interpolate:i?.interpolate}),!0}function xa({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:o=[0,0],nodeExtent:r,onError:s}){const i=n.get(e),a=i.parentId?n.get(i.parentId):void 0,{x:c,y:u}=a?a.internals.positionAbsolute:{x:0,y:0},l=i.origin??o;let f=i.extent||r;if(i.extent==="parent"&&!i.expandParent)if(!a)s?.("005",ze.error005());else{const p=a.measured.width,g=a.measured.height;p&&g&&(f=[[c,u],[c+p,u+g]])}else a&&Nt(i.extent)&&(f=[[i.extent[0][0]+c,i.extent[0][1]+u],[i.extent[1][0]+c,i.extent[1][1]+u]]);const h=Nt(f)?St(t,f,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&s?.("015",ze.error015()),{position:{x:h.x-c+(i.measured.width??0)*l[0],y:h.y-u+(i.measured.height??0)*l[1]},positionAbsolute:h}}async function Eh({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:o,onBeforeDelete:r}){const s=new Set(e.map(h=>h.id)),i=[];for(const h of n){if(h.deletable===!1)continue;const p=s.has(h.id),g=!p&&h.parentId&&i.find(v=>v.id===h.parentId);(p||g)&&i.push(h)}const a=new Set(t.map(h=>h.id)),c=o.filter(h=>h.deletable!==!1),l=bh(i,c);for(const h of c)a.has(h.id)&&!l.find(g=>g.id===h.id)&&l.push(h);if(!r)return{edges:l,nodes:i};const f=await r({nodes:i,edges:l});return typeof f=="boolean"?f?{edges:l,nodes:i}:{edges:[],nodes:[]}:f}const Yt=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),St=(e={x:0,y:0},t,n)=>({x:Yt(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Yt(e.y,t[0][1],t[1][1]-(n?.height??0))});function wa(e,t,n){const{width:o,height:r}=Ye(n),{x:s,y:i}=n.internals.positionAbsolute;return St(e,[[s,i],[s+o,i+r]],t)}const Ss=(e,t,n)=>e<t?Yt(Math.abs(e-t),1,t)/t:e>n?-Yt(Math.abs(e-n),1,t)/t:0,Tr=(e,t,n=15,o=40)=>{const r=Ss(e.x,o,t.width-o)*n,s=Ss(e.y,o,t.height-o)*n;return[r,s]},Mo=(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)}),yr=({x:e,y:t,width:n,height:o})=>({x:e,y:t,x2:e+n,y2:t+o}),jo=({x:e,y:t,x2:n,y2:o})=>({x:e,y:t,width:n-e,height:o-t}),xn=(e,t=[0,0])=>{const{x:n,y:o}=Ar(e)?e.internals.positionAbsolute:Sn(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}},wo=(e,t=[0,0])=>{const{x:n,y:o}=Ar(e)?e.internals.positionAbsolute:Sn(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)}},va=(e,t)=>jo(Mo(yr(e),yr(t))),_a=(e,t,n,o,r,s,i,a)=>{const c=Math.max(0,Math.min(e+n,r+i)-Math.max(e,r)),u=Math.max(0,Math.min(t+o,s+a)-Math.max(t,s));return Math.ceil(c*u)},vo=(e,t)=>_a(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),Ns=e=>De(e.width)&&De(e.height)&&De(e.x)&&De(e.y),De=e=>!isNaN(e)&&isFinite(e),ba=(e,t)=>(n,o)=>{},En=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Cn=({x:e,y:t},[n,o,r],s=!1,i=[1,1])=>{const a={x:(e-n)/r,y:(t-o)/r};return s?En(a,i):a},Zt=({x:e,y:t},[n,o,r])=>({x:e*r+n,y:t*r+o});function Ot(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 Ch(e,t,n){if(typeof e=="string"||typeof e=="number"){const o=Ot(e,n),r=Ot(e,t);return{top:o,right:r,bottom:o,left:r,x:r*2,y:o*2}}if(typeof e=="object"){const o=Ot(e.top??e.y??0,n),r=Ot(e.bottom??e.y??0,n),s=Ot(e.left??e.x??0,t),i=Ot(e.right??e.x??0,t);return{top:o,right:i,bottom:r,left:s,x:s+i,y:o+r}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function kh(e,t,n,o,r,s){const{x:i,y:a}=Zt(e,[t,n,o]),{x:c,y:u}=Zt({x:e.x+e.width,y:e.y+e.height},[t,n,o]),l=r-c,f=s-u;return{left:Math.floor(i),top:Math.floor(a),right:Math.floor(l),bottom:Math.floor(f)}}const Dr=(e,t,n,o,r,s)=>{const i=Ch(s,t,n),a=(t-i.x)/e.width,c=(n-i.y)/e.height,u=Math.min(a,c
1),l=Yt(u,o,r),f=e.x+e.width/2,h=e.y+e.height/2,p=t/2-f*l,g=n/2-h*l,v=kh(e,p,g,l,t,n),x={left:Math.min(v.left-i.left,0),top:Math.min(v.top-i.top,0),right:Math.min(v.right-i.right,0),bottom:Math.min(v.bottom-i.bottom,0)};return{x:p-x.left+x.right,y:g-x.top+x.bottom,zoom:l}},wn=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Nt(e){return e!=null&&e!=="parent"}function Ye(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function Sa(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function Na(e,t={width:0,height:0},n,o,r){const s={...e},i=o.get(n);if(i){const a=i.origin||r;s.x+=i.internals.positionAbsolute.x-(t.width??0)*a[0],s.y+=i.internals.positionAbsolute.y-(t.height??0)*a[1]}return s}function Es(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Mh(){let e,t;return{promise:new Promise((o,r)=>{e=o,t=r}),resolve:e,reject:t}}function jh(e){return{...pa,...e||{}}}function ln(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:o,containerBounds:r}){const{x:s,y:i}=Oe(e),a=Cn({x:s-(r?.left??0),y:i-(r?.top??0)},o),{x:c,y:u}=n?En(a,t):a;return{xSnapped:c,ySnapped:u,...a}}const Or=e=>({width:e.offsetWidth,height:e.offsetHeight}),Ea=e=>e?.getRootNode?.()||window?.document,Ih=["INPUT","SELECT","TEXTAREA"];function Ca(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:Ih.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".
1nokey")}const ka=e=>"clientX"in e,Oe=(e,t)=>{const n=ka(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)}},Cs=(e,t,n,o,r)=>{const s=t.querySelectorAll(`.${e}`);return!s||!s.length?null:Array.from(s).map(i=>{const a=i.getBoundingClientRect();return{id:i.getAttribute("data-handleid"),type:e,nodeId:r,position:i.getAttribute("data-handlepos"),x:(a.left-n.left)/o,y:(a.top-n.top)/o,...Or(i)}})};function Ma({sourceX:e,sourceY:t,targetX:n,targetY:o,sourceControlX:r,sourceControlY:s,targetControlX:i,targetControlY:a}){const c=e*.125+r*.375+i*.375+n*.125,u=t*.125+s*.375+a*.375+o*.125,l=Math.abs(c-e),f=Math.abs(u-t);return[c,u,l,f]}function Yn(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function ks({pos:e,x1:t,y1:n,x2:o,y2:r,c:s}){switch(e){case ne.Left:return[t-Yn(t-o,s),n];case ne.Right:return[t+Yn(o-t,s),n];case ne.Top:return[t,n-Yn(n-r,s)];case ne.Bottom:return[t,n+Yn(r-n,s)]}}function ja({sourceX:e,sourceY:t,sourcePosition:n=ne.Bottom,targetX:o,targetY:r,targetPosition:s=ne.Top,curvature:i=.25}){const[a,c]=ks({pos:n,x1:e,y1:t,x2:o,y2:r,c:i}),[u,l]=ks({pos:s,x1:o,y1:r,x2:e,y2:t,c:i}),[f,h,p,g]=Ma({sourceX:e,sourceY:t,targetX:o,targetY:r,sourceControlX:a,sourceControlY:c,targetControlX:u,targetControlY:l});return[`M${e},${t} C${a},${c} ${u},${l} ${o},${r}`,f,h,p,g]}function Ia({sourceX:e,sourceY:t,targetX:n,targetY:o}){const r=Math.abs(n-e)/2,s=n<e?n+r:n-r,i=Math.abs(o-t)/2,a=o<t?o+i:o-i;return[s,a,r,i]}function Ph({sourceNode:e,targetNode:t,selected:n=!1,zIndex:o=0,elevateOnSelect:r=!1,zIndexMode:s="basic"}){if(s==="manual")return o;const i=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 i+a}function Rh({sourceNode:e,targetNode:t,width:n,height:o,transform:r}){const s=Mo(wo(e),wo(t));s.x===s.x2&&(s.x2+=1),s.y===s.y2&&(s.y2+=1);const i={x:-r[0]/r[2],y:-r[1]/r[2],width:n/r[2],height:o/r[2]};return vo(i,jo(s))>0}const Ah=({source:e,sourceHandle:t,target:n,targetHandle:o})=>`xy-edge__${e}${t||""}-${n}${o||""}`,$h=(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)),Th=(e,t,n={})=>{if(!e.source||!e.target)return n.onError?.("006",ze.error006()),t;const o=n.getEdgeId||Ah;let r;return ya(e)?r={...e}:r={...e,id:o(e)},$h(r,t)?t:(r.sourceHandle===null&&delete r.sourceHandle,r.targetHandle===null&&delete r.targetHandle,t.concat(r))};function Pa({sourceX:e,sourceY:t,targetX:n,targetY:o}){const[r,s,i,a]=Ia({sourceX:e,sourceY:t,targetX:n,targetY:o});return[`M ${e},${t}L ${n},${o}`,r,s,i,a]}const Ms={[ne.Left]:{x:-1,y:0},[ne.Right]:{x:1,y:0},[ne.Top]:{x:0,y:-1},[ne.Bottom]:{x:0,y:1}},Dh=({source:e,sourcePosition:t=ne.Bottom,target:n})=>t===ne.Left||t===ne.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},js=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Oh({source:e,sourcePosition:t=ne.Bottom,target:n,targetPosition:o=ne.Top,center:r,offset:s,stepPosition:i}){const a=Ms[t],c=Ms[o],u={x:e.x+a.x*s,y:e.y+a.y*s},l={x:n.x+c.x*s,y:n.y+c.y*s},f=Dh({source:u,sourcePosition:t,target:l}),h=f.x!==0?"x":"y",p=f[h];let g=[],v,x;const y={x:0,y:0},S={x:0,y:0},[,,m,w]=Ia({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(a[h]*c[h]===-1){h==="x"?(v=r.x??u.x+(l.x-u.x)*i,x=r.y??(u.y+l.y)/2):(v=r.x??(u.x+l.x)/2,x=r.y??u.y+(l.y-u.y)*i);const M=[{x:v,y:u.y},{x:v,y:l.y}],A=[{x:u.x,y:x},{x:l.x,y:x}];a[h]===p?g=h==="x"?M:A:g=h==="x"?A:M}else{const M=[{x:u.x,y:l.y}],A=[{x:l.x,y:u.y}];if(h==="x"?g=a.x===p?A:M:g=a.y===p?M:A,t===o){const _=Math.abs(e[h]-n[h]);if(_<=s){const E=Math.min(s-1,s-_);a[h]===p?y[h]=(u[h]>e[h]?-1:1)*E:S[h]=(l[h]>n[h]?-1:1)*E}}if(t!==o){const _=h==="x"?"y":"x",E=a[h]===c[_],b=u[_]>l[_],I=u[_]<l[_];(a[h]===1&&(!E&&b||E&&I)||a[h]!==1&&(!E&&I||E&&b))&&(g=h==="x"?M:A)}const L={x:u.x+y.x,y:u.y+y.y},$={x:l.x+S.x,y:l.y+S.y},H=Math.max(Math.abs(L.x-g[0].x),Math.abs($.x-g[0].x)),D=Math.max(Math.abs(L.y-g[0].y),Math.abs($.y-g[0].y));H>=D?(v=(L.x+$.x)/2,x=g[0].y):(v=g[0].x,x=(L.y+$.y)/2)}const k={x:u.x+y.x,y:u.y+y.y},C={x:l.x+S.x,y:l.y+S.y};return[[e,...k.x!==g[0].x||k.y!==g[0].y?[k]:[],...g,...C.x!==g[g.length-1].x||C.y!==g[g.length-1].y?[C]:[],n],v,x,m,w]}function Hh(e,t,n,o){const r=Math.min(js(e,t)/2,js(t,n)/2,o),{x:s,y:i}=t;if(e.x===s&&s===n.x||e.y===i&&i===n.y)return`L${s} ${i}`;if(e.y===i){const u=e.x<n.x?-1:1,l=e.y<n.y?1:-1;return`L ${s+r*u},${i}Q ${s},${i} ${s},${i+r*l}`}const a=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${s},${i+r*c}Q ${s},${i} ${s+r*a},${i}`}function xr({sourceX:e,sourceY:t,sourcePosition:n=ne.Bottom,targetX:o,targetY:r,targetPosition:s=ne.Top,borderRadius:i=5,centerX:a,centerY:c,offset:u=20,stepPosition:l=.5}){const[f,h,p,g,v]=Oh({source:{x:e,y:t},sourcePosition:n,target:{x:o,y:r},targetPosition:s,center:{x:a,y:c},offset:u,stepPosition:l});let x=`M${f[0].x} ${f[0].y}`;for(let y=1;y<f.length-1;y++)x+=Hh(f[y-1],f[y],f[y+1],i);
1return x+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[x,h,p,g,v]}function Is(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function zh(e){const{sourceNode:t,targetNode:n}=e;if(!Is(t)||!Is(n))return null;const o=t.internals.handleBounds||Ps(t.handles),r=n.internals.handleBounds||Ps(n.handles),s=Rs(o?.source??[],e.sourceHandle),i=Rs(e.connectionMode===Xt.Strict?r?.target??[]:(r?.target??[]).concat(r?.source??[]),e.targetHandle);if(!s||!i)return e.onError?.("008",ze.error008(s?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const a=s?.position||ne.Bottom,c=i?.position||ne.Top,u=Et(t,s,a),l=Et(n,i,c);return{sourceX:u.x,sourceY:u.y,targetX:l.x,targetY:l.y,sourcePosition:a,targetPosition:c}}function Ps(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 Et(e,t,n=ne.Left,o=!1){const r=(t?.x??0)+e.internals.positionAbsolute.x,s=(t?.y??0)+e.internals.positionAbsolute.y,{width:i,height:a}=t??Ye(e);if(o)return{x:r+i/2,y:s+a/2};switch(t?.position??n){case ne.Top:return{x:r+i/2,y:s};case ne.Right:return{x:r+i,y:s+a/2};case ne.Bottom:return{x:r+i/2,y:s+a};case ne.Left:return{x:r,y:s+a/2}}}function Rs(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function wr(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(o=>`${o}=${e[o]}`).join("&")}`:""}function Lh(e,{id:t,defaultColor:n,defaultMarkerStart:o,defaultMarkerEnd:r}){const s=new Set;return e.reduce((i,a)=>([a.markerStart||o,a.markerEnd||r].forEach(c=>{if(c&&typeof c=="object"){const u=wr(c,t);s.has(u)||(i.push({id:u,color:c.color||n,...c}),s.add(u))}}),i),[]).sort((i,a)=>i.id.localeCompare(a.id))}const Ra=1e3,Bh=10,Hr={nodeOrigin:[0,0],nodeExtent:mn,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Vh={...Hr,checkEquality:!0};function zr(e,t){const n={...e};for(const o in t)t[o]!==void 0&&(n[o]=t[o]);return n}function Fh(e,t,n){const o=zr(Hr,n);for(const r of e.values())if(r.parentId)Br(r,e,t,o);else{const s=Sn(r,o.nodeOrigin),i=Nt(r.extent)?r.extent:o.nodeExtent,a=St(s,i,Ye(r));r.internals.positionAbsolute=a}}function Uh(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],o=[];for(const r of e.handles){const s={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(s):r.type==="target"&&o.push(s)}return{source:n,target:o}}function Lr(e){return e==="manual"}function vr(e,t,n,o={}){const r=zr(Vh,o),s={i:0},i=new Map(t),a=r?.elevateNodesOnSelect&&!Lr(r.zIndexMode)?Ra:0;let c=e.length>0,u=!1;t.clear(),n.clear();for(const l of e){let f=i.get(l.id);if(r.checkEquality&&l===f?.internals.userNode)t.set(l.id,f);else{const h=Sn(l,r.nodeOrigin),p=Nt(l.extent)?l.extent:r.nodeExtent,g=St(h,p,Ye(l));f={...r.defaults,...l,measured:{width:l.measured?.width,height:l.measured?.height},internals:{positionAbsolute:g,handleBounds:Uh(l,f),z:Aa(l,a,r.zIndexMode),userNode:l}},t.set(l.id,f)}(f.measured===void 0||f.measured.width===void 0||f.measured.height===void 0)&&!f.hidden&&(c=!1),l.parentId&&Br(f,t,n,o,s),u||=l.selected??!1}return{nodesInitialized:c,hasSelectedNodes:u}}function Wh(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 Br(e,t,n,o,r){const{elevateNodesOnSelect:s,nodeOrigin:i,nodeExtent:a,zIndexMode:c}=zr(Hr,o),u=e.parentId,l=t.get(u);if(!l){console.warn(`Parent node ${u} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Wh(e,n),r&&!l.parentId&&l.internals.rootParentIndex===void 0&&c==="auto"&&(l.internals.rootParentIndex=++r.i,l.internals.z=l.internals.z+r.i*Bh),r&&l.internals.rootParentIndex!==void 0&&(r.i=l.internals.rootParentIndex);const f=s&&!Lr(c)?Ra:0,{x:h,y:p,z:g}=Xh(e,l,i,a,f,c),{positionAbsolute:v}=e.internals,x=h!==v.x||p!==v.y;(x||g!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:x?{x:h,y:p}:v,z:g}})}function Aa(e,t,n){const o=De(e.zIndex)?e.zIndex:0;return Lr(n)?o:o+(e.selected?t:0)}function Xh(e,t,n,o,r,s){const{x:i,y:a}=t.internals.positionAbsolute,c=Ye(e),u=Sn(e,n),l=Nt(e.extent)?St(u,e.extent,c):u;let f=St({x:i+l.x,y:a+l.y},o,c);e.extent==="parent"&&(f=wa(f,c,t));const h=Aa(e,r,s),p=t.internals.z??0;return{x:f.x,y:f.y,z:p>=h?p+1:h}}function Vr(e,t,n,o=[0,0]){const r=[],s=new Map;for(const i of e){const a=t.get(i.parentId);if(!a)continue;const c=s.get(i.parentId)?.expandedRect??xn(a),u=va(c,i.rect);s.set(i.parentId,{expandedRect:u,parent:a})}return s.size>
10&&s.forEach(({expandedRect:i,parent:a},c)=>{const u=a.internals.positionAbsolute,l=Ye(a),f=a.origin??o,h=i.x<u.x?Math.round(Math.abs(u.x-i.x)):0,p=i.y<u.y?Math.round(Math.abs(u.y-i.y)):0,g=Math.max(l.width,Math.round(i.width)),v=Math.max(l.height,Math.round(i.height)),x=(g-l.width)*f[0],y=(v-l.height)*f[1];(h>0||p>0||x||y)&&(r.push({id:c,type:"position",position:{x:a.position.x-h+x,y:a.position.y-p+y}}),n.get(c)?.forEach(S=>{e.some(m=>m.id===S.id)||r.push({id:S.id,type:"position",position:{x:S.position.x+h,y:S.position.y+p}})})),(l.width<i.width||l.height<i.height||h||p)&&r.push({id:c,type:"dimensions",setAttributes:!0,dimensions:{width:g+(h?f[0]*h-x:0),height:v+(p?f[1]*p-y:0)}})}),r}function Yh(e,t,n,o,r,s,i){const a=o?.querySelector(".xyflow__viewport");let c=!1;if(!a)return{changes:[],updatedInternals:c};const u=[],l=window.getComputedStyle(a),{m22:f}=new window.DOMMatrixReadOnly(l.transform),h=[];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=Or(p.nodeElement),x=g.measured.width!==v.width||g.measured.height!==v.height;if(!!(v.width&&v.height&&(x||!g.internals.handleBounds||p.force))){const S=p.nodeElement.getBoundingClientRect(),m=Nt(g.extent)?g.extent:s;let{positionAbsolute:w}=g.internals;if(g.parentId&&g.extent==="parent"){const C=t.get(g.parentId);C&&(w=wa(w,v,C))}else m&&(w=St(w,m,v));const k={...g,measured:v,internals:{...g.internals,positionAbsolute:w,handleBounds:{source:Cs("source",p.nodeElement,S,f,g.id),target:Cs("target",p.nodeElement,S,f,g.id)}}};t.set(g.id,k),g.parentId&&Br(k,t,n,{nodeOrigin:r,zIndexMode:i}),c=!0,x&&(u.push({id:g.id,type:"dimensions",dimensions:v}),g.expandParent&&g.parentId&&h.push({id:g.id,parentId:g.parentId,rect:xn(k,r)}))}}if(h.length>0){const p=Vr(h,t,n,r);u.push(...p)}return{changes:u,updatedInternals:c}}async function Zh({delta:e,panZoom:t,transform:n,translateExtent:o,width:r,height:s}){if(!t||!e.x&&!e.y)return!1;const i=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[r,s]],o);return!!i&&(i.x!==n[0]||i.y!==n[1]||i.k!==n[2])}function As(e,t,n,o,r,s){let i=r;const a=o.get(i)||new Map;o.set(i,a.set(n,t)),i=`${r}-${e}`;const c=o.get(i)||new Map;if(o.set(i,c.set(n,t)),s){i=`${r}-${e}-${s}`;const u=o.get(i)||new Map;o.set(i,u.set(n,t))}}function $a(e,t,n){e.clear(),t.clear();for(const o of n){const{source:r,target:s,sourceHandle:i=null,targetHandle:a=null}=o,c={edgeId:o.id,source:r,target:s,sourceHandle:i,targetHandle:a},u=`${r}-${i}--${s}-${a}`,l=`${s}-${a}--${r}-${i}`;As("source",c,l,e,r,i),As("target",c,u,e,s,a),t.set(o.id,o)}}function Ta(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:Ta(n,t):!1}function $s(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 Gh(e,t,n,o){const r=new Map;for(const[s,i]of e)if((i.selected||i.id===o)&&(!i.parentId||!Ta(i,e))&&(i.draggable||t&&typeof i.draggable>"u")){const a=e.get(s);a&&r.set(s,{id:s,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 Zo({nodeId:e,dragItems:t,nodeLookup:n,dragging:o=!0}){const r=[];for(const[i,a]of t){const c=n.get(i)?.internals.userNode;c&&r.push({...c,position:a.position,dragging:o})}if(!e)return[r[0],r];const s=n.get(e)?.internals.userNode;return[s?{...s,position:t.get(e)?.position||s.position,dragging:o}:r[0],r]}function Kh({dragItems:e,snapGrid:t,x:n,y:o}){const r=e.values().next().value;if(!r)return null;const s={x:n-r.distance.x,y:o-r.distance.y},i=En(s,t);return{x:i.x-s.x,y:i.y-s.y}}function qh({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:o,onDragStop:r}){let s={x:null,y:null},i=0,a=new Map,c=!1,u={x:0,y:0},l=null,f=!1,h=null,p=!1,g=!1,v=null;function x({noDragClassName:S,handleSelector:m,domNode:w,isSelectable:k,nodeId:C,nodeClickDistance:j=0}){h=ke(w);function M({x:H,y:D}
1){const{nodeLookup:_,nodeExtent:E,snapGrid:b,snapToGrid:I,nodeOrigin:P,onNodeDrag:T,onSelectionDrag:U,onError:z,updateNodePositions:V}=t();s={x:H,y:D};let K=!1;const q=a.size>1,oe=q&&E?yr(Nn(a)):null,se=q&&I?Kh({dragItems:a,snapGrid:b,x:H,y:D}):null;for(const[te,B]of a){if(!_.has(te))continue;let O={x:H-B.distance.x,y:D-B.distance.y};I&&(O=se?{x:Math.round(O.x+se.x),y:Math.round(O.y+se.y)}:En(O,b));let Y=null;if(q&&E&&!B.extent&&oe){const{positionAbsolute:Q}=B.internals,re=Q.x-oe.x+E[0][0],ae=Q.x+B.measured.width-oe.x2+E[1][0],fe=Q.y-oe.y+E[0][1],he=Q.y+B.measured.height-oe.y2+E[1][1];Y=[[re,fe],[ae,he]]}const{position:W,positionAbsolute:G}=xa({nodeId:te,nextPosition:O,nodeLookup:_,nodeExtent:Y||E,nodeOrigin:P,onError:z});K=K||B.position.x!==W.x||B.position.y!==W.y,B.position=W,B.internals.positionAbsolute=G}if(g=g||K,!!K&&(V(a,!0),v&&(o||T||!C&&U))){const[te,B]=Zo({nodeId:C,dragItems:a,nodeLookup:_});o?.(v,a,te,B),T?.(v,te,B),C||U?.(v,B)}}async function A(){if(!l)return;const{transform:H,panBy:D,autoPanSpeed:_,autoPanOnNodeDrag:E}=t();if(!E){c=!1,cancelAnimationFrame(i);return}const[b,I]=Tr(u,l,_);(b!==0||I!==0)&&(s.x=(s.x??0)-b/H[2],s.y=(s.y??0)-I/H[2],await D({x:b,y:I})&&M(s)),i=requestAnimationFrame(A)}function L(H){const{nodeLookup:D,multiSelectionActive:_,nodesDraggable:E,transform:b,snapGrid:I,snapToGrid:P,selectNodesOnDrag:T,onNodeDragStart:U,onSelectionDragStart:z,unselectNodesAndEdges:V}=t();f=!0,(!T||!k)&&!_&&C&&(D.get(C)?.selected||V()),k&&T&&C&&e?.(C);const K=ln(H.sourceEvent,{transform:b,snapGrid:I,snapToGrid:P,containerBounds:l});if(s=K,a=Gh(D,E,K,C),a.size>0&&(n||U||!C&&z)){const[q,oe]=Zo({nodeId:C,dragItems:a,nodeLookup:D});n?.(H.sourceEvent,a,q,oe),U?.(H.sourceEvent,q,oe),C||z?.(H.sourceEvent,oe)}}const $=qi().clickDistance(j).on("start",H=>{const{domNode:D,nodeDragThreshold:_,transform:E,snapGrid:b,snapToGrid:I}=t();l=D?.getBoundingClientRect()||null,p=!1,g=!1,v=H.sourceEvent,_===0&&L(H),s=ln(H.sourceEvent,{transform:E,snapGrid:b,snapToGrid:I,containerBounds:l}),u=Oe(H.sourceEvent,l)}).on("drag",H=>
1{const{autoPanOnNodeDrag:D,transform:_,snapGrid:E,snapToGrid:b,nodeDragThreshold:I,nodeLookup:P}=t(),T=ln(H.sourceEvent,{transform:_,snapGrid:E,snapToGrid:b,containerBounds:l});if(v=H.sourceEvent,(H.sourceEvent.type==="touchmove"&&H.sourceEvent.touches.length>1||C&&!P.has(C))&&(p=!0),!p){if(!c&&D&&f&&(c=!0,A()),!f){const U=Oe(H.sourceEvent,l),z=U.x-u.x,V=U.y-u.y;Math.sqrt(z*z+V*V)>I&&L(H)}(s.x!==T.xSnapped||s.y!==T.ySnapped)&&a&&f&&(u=Oe(H.sourceEvent,l),M(T))}}).on("end",H=>{if(!f||p){p&&a.size>0&&t().updateNodePositions(a,!1);return}if(c=!1,f=!1,cancelAnimationFrame(i),a.size>0){const{nodeLookup:D,updateNodePositions:_,onNodeDragStop:E,onSelectionDragStop:b}=t();if(g&&(_(a,!1),g=!1),r||E||!C&&b){const[I,P]=Zo({nodeId:C,dragItems:a,nodeLookup:D,dragging:!1});r?.(H.sourceEvent,a,I,P),E?.(H.sourceEvent,I,P),C||b?.(H.sourceEvent,P)}}}).filter(H=>{const D=H.target;return!H.button&&(!S||!$s(D,`.${S}`,w))&&(!m||$s(D,m,w))});h.call($)}function y(){h?.on(".drag",null)}return{update:x,destroy:y}}function Qh(e,t,n){const o=[],r={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const s of t.values())vo(r,xn(s))>0&&o.push(s);return o}const Jh=250;function ep(e,t,n,o){let r=[],s=1/0;const i=Qh(e,n,t+Jh);for(const a of i){const c=[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]];for(const u of c){if(o.nodeId===u.nodeId&&o.type===u.type&&o.id===u.id)continue;const{x:l,y:f}=Et(a,u,u.position,!0),h=Math.sqrt(Math.pow(l-e.x,2)+Math.pow(f-e.y,2));h>t||(h<s?(r=[{...u,x:l,y:f}],s=h):h===s&&r.push({...u,x:l,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 Da(e,t,n,o,r,s=!1){const i=o.get(e);if(!i)return null;const a=r==="strict"?i.internals.handleBounds?.[t]:[...i.internals.handleBounds?.source??[],...i.internals.handleBounds?.target??[]],c=(n?a?.find(u=>u.id===n):a?.[0])??null;return c&&s?{...c,...Et(i,c,c.position,!0)}:c}function Oa(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function tp(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const Ha=()=>!0;function np(e,{connectionMode:t,connectionRadius:n,handleId:o,nodeId:r,edgeUpdaterType:s,isTarget:i,domNode:a,nodeLookup:c,lib:u,autoPanOnConnect:l,flowId:f,panBy:h,cancelConnection:p,onConnectStart:g,onConnect:v,onConnectEnd:x,isValidConnection:y=Ha,onReconnectEnd:S,updateConnection:m,getTransform:w,getFromHandle:k,autoPanSpeed:C,dragThreshold:j=1,handleDomNode:M}){const A=Ea(e.target);let L=0,$;const{x:H,y:D}=Oe(e),_=Oa(s,M),E=a?.getBoundingClientRect();let b=!1;if(!E||!_)return;const I=Da(r,_,o,c,t);if(!I)return;let P=Oe(e,E),T=!1,U=null,z=!1,V=null;function K(){if(!l||!E)return;const[W,G]=Tr(P,E,C);h({x:W,y:G}),L=requestAnimationFrame(K)}const q={...I,nodeId:r,type:_,position:I.position},oe=c.get(r);let te={inProgress:!0,isValid:null,from:Et(oe,q,ne.Left,!0),fromHandle:q,fromPosition:q.position,fromNode:oe,to:P,toHandle:null,toPosition:bs[q.position],toNode:null,pointer:P};function B(){b=!0,m(te),g?.(e,{nodeId:r,handleId:o,handleType:_})}j===0&&B();function O(W){if(!b){const{x:he,y:de}=Oe(W),je=he-H,ve=de-D;if(!(je*je+ve*ve>j*j))return;B()}if(!k()||!q){Y(W);return}const G=w();P=Oe(W,E),$=ep(Cn(P,G,!1,[1,1]),n,c,q),T||(K(),T=!0);const Q=za(W,{handle:$,connectionMode:t,fromNodeId:r,fromHandleId:o,fromType:i?"target":"source",isValidConnection:y,doc:A,lib:u,flowId:f,nodeLookup:c});V=Q.handleDomNode,U=Q.connection,z=tp(!!$,Q.isValid);const re=c.get(r),ae=re?Et(re,q,ne.Left,!0):te.from,fe={...te,from:ae,isValid:z,to:Q.toHandle&&z?Zt({x:Q.toHandle.x,y:Q.toHandle.y},G):P,toHandle:Q.toHandle,toPosition:z&&Q.toHandle?Q.toHandle.position:bs[q.position],toNode:Q.toHandle?c.get(Q.toHandle.nodeId):null,pointer:P};m(fe),te=fe}function Y(W){if(!("touches"in W&&W.touches.length>0)){if(b){($||V)&&U&&z&&v?.(U);const{inProgress:G,...Q}=te,re={...Q,toPosition:te.toHandle?te.toPosition:null};x?.(W,re),s&&S?.(W,re)}p(),cancelAnimationFrame(L),T=!1,z=!1,U=null,V=null,A.removeEventListener("mousemove",O),A.removeEventListener("mouseup",Y),A.removeEventListener("touchmove",O),A.removeEventListener("touchend",Y)}}A.addEventListener("mousemove",O),A.addEventListener("mouseup",Y),A.addEventListener("touchmove",O),A.addEventListener("touchend",Y)}function za(e,{handle:t,connectionMode:n,fromNodeId:o,fromHandleId:r,fromType:s,doc:i,lib:a,flowId:c,isValidConnection:u=Ha,nodeLookup:l}){const f=s==="target",h=t?i.querySelector(`.${a}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:g}=Oe(e),v=i.elementFromPoint(p,g),x=v?.classList.contains(`${a}
1-flow__handle`)?v:h,y={handleDomNode:x,isValid:!1,connection:null,toHandle:null};if(x){const S=Oa(void 0,x),m=x.getAttribute("data-nodeid"),w=x.getAttribute("data-handleid"),k=x.classList.contains("connectable"),C=x.classList.contains("connectableend");if(!m||!S)return y;const j={source:f?m:o,sourceHandle:f?w:r,target:f?o:m,targetHandle:f?r:w};y.connection=j;const A=k&&C&&(n===Xt.Strict?f&&S==="source"||!f&&S==="target":m!==o||w!==r);y.isValid=A&&u(j),y.toHandle=Da(m,S,w,l,n,!0)}return y}const _r={onPointerDown:np,isValid:za};function op({domNode:e,panZoom:t,getTransform:n,getViewScale:o}){const r=ke(e);function s({translateExtent:a,width:c,height:u,zoomStep:l=1,pannable:f=!0,zoomable:h=!0,inversePan:p=!1}){const g=m=>{if(m.sourceEvent.type!=="wheel"||!t)return;const w=n(),k=m.sourceEvent.ctrlKey&&wn()?10:1,C=-m.sourceEvent.deltaY*(m.sourceEvent.deltaMode===1?.05:m.sourceEvent.deltaMode?1:.002)*l,j=w[2]*Math.pow(2,C*k);t.scaleTo(j)};let v=[0,0];const x=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])},y=m=>{const w=n();if(m.sourceEvent.type!=="mousemove"&&m.sourceEvent.type!=="touchmove"||!t)return;const k=[m.sourceEvent.clientX??m.sourceEvent.touches[0].clientX,m.sourceEvent.clientY??m.sourceEvent.touches[0].clientY],C=[k[0]-v[0],k[1]-v[1]];v=k;const j=o()*Math.max(w[2],Math.log(w[2]))*(p?-1:1),M={x:w[0]-C[0]*j,y:w[1]-C[1]*j},A=[[0,0],[c,u]];t.setViewportConstrained({x:M.x,y:M.y,zoom:w[2]},A,a)},S=fa().on("start",x).on("zoom",f?y:null).on("zoom.wheel",h?g:null);r.call(S,{})}function i(){r.on("zoom",null)}return{update:s,destroy:i,pointer:Ae}}const Io=e=>({x:e.x,y:e.y,zoom:e.k}),Go=({x:e,y:t,zoom:n})=>ko.translate(e,t).scale(n),zt=(e,t)=>e.target.closest(`.${t}`),La=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),rp=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Ko=(e,t=0,n=rp,o=()=>{})=>{const r=typeof t=="number"&&t>0;return r||o(),r?e.transition().duration(t).ease(n).on("end",o):e},Ba=e=>{const t=e.ctrlKey&&wn()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function sp({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:o,panOnScrollMode:r,panOnScrollSpeed:s,zoomOnPinch:i,onPanZoomStart:a,onPanZoom:c,onPanZoomEnd:u}){return l=>{if(zt(l,t))return l.ctrlKey&&l.preventDefault(),!1;l.preventDefault(),l.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(l.ctrlKey&&i){const x=Ae(l),y=Ba(l),S=f*Math.pow(2,y);o.scaleTo(n,S,x,l);return}const h=l.deltaMode===1?20:1;let p=r===vt.Vertical?0:l.deltaX*h,g=r===vt.Horizontal?0:l.deltaY*h;!wn()&&l.shiftKey&&r!==vt.Vertical&&(p=l.deltaY*h,g=0),o.translateBy(n,-(p/f)*s,-(g/f)*s,{internal:!0});const v=Io(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?c?.(l,v):(e.isPanScrolling=!0,a?.(l,v)),e.panScrollTimeout=setTimeout(()=>{u?.(l,v),e.isPanScrolling=!1},150)}}function ip({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(o,r){const s=o.type==="wheel",i=!t&&s&&!o.ctrlKey,a=zt(o,e);if(o.ctrlKey&&s&&a&&o.preventDefault(),i||a)return null;o.preventDefault(),n.call(this,o,r)}}function ap({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return o=>{if(o.sourceEvent?.internal)return;const r=Io(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 cp({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:o,onPanZoom:r}){return s=>{e.usedRightMouseButton=!!(n&&La(t,e.mouseButton??0)),s.sourceEvent?.sync||o([s.transform.x,s.transform.y,s.transform.k]),r&&!s.sourceEvent?.internal&&r?.(s.sourceEvent,Io(s.transform))}}function up({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:o,onPanZoomEnd:r,onPaneContextMenu:s}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,s&&La(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&s(i.sourceEvent),e.usedRightMouseButton=!1,o(!1),r)){const a=Io(i.transform);e.prevViewport=a,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{r?.(i.sourceEvent,a)},n?150:0)}}}function lp({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:o,panOnScroll:r,zoomOnDoubleClick:s,userSelectionActive:i,noWheelClassName:a,noPanClassName:c,lib:u,connectionInProgress:l}){return f=>{const h=e||t,p=n&&f.ctrlKey,g=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(zt(f,`${u}-flow__node`)||zt(f,`${u}-flow__edge`)))return!0;
1if(!o&&!h&&!r&&!s&&!n||i||l&&!g||zt(f,a)&&g||zt(f,c)&&(!g||r&&g&&!e)||!n&&f.ctrlKey&&g)return!1;if(!n&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!h&&!r&&!p&&g||!o&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(o)&&!o.includes(f.button)&&f.type==="mousedown")return!1;const v=Array.isArray(o)&&o.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||g)&&v}}function dp({domNode:e,minZoom:t,maxZoom:n,translateExtent:o,viewport:r,onPanZoom:s,onPanZoomStart:i,onPanZoomEnd:a,onDraggingChange:c}){const u={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},l=e.getBoundingClientRect();let f=[[0,0],[l.width,l.height]];(typeof ResizeObserver<"u"?new ResizeObserver(D=>{const _=D[0];_&&(f=[[0,0],[_.contentRect.width,_.contentRect.height]])}):null)?.observe(e);const p=fa().extent(()=>f).scaleExtent([t,n]).translateExtent(o),g=ke(e).call(p);w({x:r.x,y:r.y,zoom:Yt(r.zoom,t,n)},[[0,0],[l.width,l.height]],o);const v=g.on("wheel.zoom"),x=g.on("dblclick.zoom");p.wheelDelta(Ba);async function y(D,_){return g?new Promise(E=>{p?.interpolate(_?.interpolate==="linear"?un:oo).transform(Ko(g,_?.duration,_?.ease,()=>E(!0)),D)}):!1}function S({noWheelClassName:D,noPanClassName:_,onPaneContextMenu:E,userSelectionActive:b,panOnScroll:I,panOnDrag:P,panOnScrollMode:T,panOnScrollSpeed:U,preventScrolling:z,zoomOnPinch:V,zoomOnScroll:K,zoomOnDoubleClick:q,zoomActivationKeyPressed:oe,lib:se,onTransformChange:te,connectionInProgress:B,paneClickDistance:O,selectionOnDrag:Y}){b&&!u.isZoomingOrPanning&&m();const W=I&&!oe&&!b;p.clickDistance(Y?1/0:!De(O)||O<0?0:O);const G=W?sp({zoomPanValues:u,noWheelClassName:D,d3Selection:g,d3Zoom:p,panOnScrollMode:T,panOnScrollSpeed:U,zoomOnPinch:V,onPanZoomStart:i,onPanZoom:s,onPanZoomEnd:a}):ip({noWheelClassName:D,preventScrolling:z,d3ZoomHandler:v});g.on("wheel.zoom",G,{passive:!1});const Q=ap({zoomPanValues:u,onDraggingChange:c,onPanZoomStart:i});p.on("start",Q);const re=cp({zoomPanValues:u,panOnDrag:P,onPaneContextMenu:!!E,onPanZoom:s,onTransformChange:te});p.on("zoom",re);const ae=up({zoomPanValues:u,panOnDrag:P,panOnScroll:I,onPaneContextMenu:E,onPanZoomEnd:a,onDraggingChange:c});p.on("end",ae);const fe=lp({zoomActivationKeyPressed:oe,panOnDrag:P,zoomOnScroll:K,panOnScroll:I,zoomOnDoubleClick:q,zoomOnPinch:V,userSelectionActive:b,noPanClassName:_,noWheelClassName:D,lib:se,connectionInProgress:B});p.filter(fe),q?g.on("dblclick.zoom",x):g.on("dblclick.zoom",null)}function m(){p.on("zoom",null)}async function w(D,_,E){const b=Go(D),I=p?.constrain()(b,_,E);return I&&await y(I),I}async function k(D,_){const E=Go(D);return await y(E,_),E}function C(D){if(g){const _=Go(D),E=g.property("__zoom");(E.k!==D.zoom||E.x!==D.x||E.y!==D.y)&&p?.transform(g,_,null,{sync:!0})}}function j(){const D=g?da(g.node()):{x:0,y:0,k:1};return{x:D.x,y:D.y,zoom:D.k}}async function M(D,_){return g?new Promise(E=>{p?.interpolate(_?.interpolate==="linear"?un:oo).scaleTo(Ko(g,_?.duration,_?.ease,()=>E(!0)),D)}):!1}async function A(D,_){return g?new Promise(E=>{p?.interpolate(_?.interpolate==="linear"?un:oo).scaleBy(Ko(g,_?.duration,_?.ease,()=>E(!0)),D)}):!1}function L(D){p?.scaleExtent(D)}function $(D){p?.translateExtent(D)}function H(D){const _=!De(D)||D<0?0:D;p?.clickDistance(_)}return{update:S,destroy:m,setViewport:k,setViewportConstrained:w,getViewport:j,scaleTo:M,scaleBy:A,setScaleExtent:L,setTranslateExtent:$,syncViewport:C,setClickDistance:H}}var Gt;(function(e){e.Line="line",e.Handle="handle"})(Gt||(Gt={}));function fp({width:e,prevWidth:t,height:n,prevHeight:o,affectsX:r,affectsY:s}){const i=e-t,a=n-o,c=[i>0?1:i<0?-1:0,a>0?1:a<0?-1:0];return i&&r&&(c[0]=c[0]*-1),a&&s&&(c[1]=c[1]*-1),c}function Ts(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 ct(e,t){return Math.max(0,t-e)}function ut(e,t){return Math.max(0,e-t)}function Zn(e,t,n){return Math.max(0,t-e,e-n)}function Ds(e,t){return e?!t:t}function hp(e,t,n,o,r,s,i,a){let{affectsX:c,affectsY:u}=t;const{isHorizontal:l,isVertical:f}=t,h=l&&f,{xSnapped:p,ySnapped:g}=n,{minWidth:v,maxWidth:x,minHeight:y,maxHeight:S}
1=o,{x:m,y:w,width:k,height:C,aspectRatio:j}=e;let M=Math.floor(l?p-e.pointerX:0),A=Math.floor(f?g-e.pointerY:0);const L=k+(c?-M:M),$=C+(u?-A:A),H=-s[0]*k,D=-s[1]*C;let _=Zn(L,v,x),E=Zn($,y,S);if(i){let P=0,T=0;c&&M<0?P=ct(m+M+H,i[0][0]):!c&&M>0&&(P=ut(m+L+H,i[1][0])),u&&A<0?T=ct(w+A+D,i[0][1]):!u&&A>0&&(T=ut(w+$+D,i[1][1])),_=Math.max(_,P),E=Math.max(E,T)}if(a){let P=0,T=0;c&&M>0?P=ut(m+M,a[0][0]):!c&&M<0&&(P=ct(m+L,a[1][0])),u&&A>0?T=ut(w+A,a[0][1]):!u&&A<0&&(T=ct(w+$,a[1][1])),_=Math.max(_,P),E=Math.max(E,T)}if(r){if(l){const P=Zn(L/j,y,S)*j;if(_=Math.max(_,P),i){let T=0;!c&&!u||c&&!u&&h?T=ut(w+D+L/j,i[1][1])*j:T=ct(w+D+(c?M:-M)/j,i[0][1])*j,_=Math.max(_,T)}if(a){let T=0;!c&&!u||c&&!u&&h?T=ct(w+L/j,a[1][1])*j:T=ut(w+(c?M:-M)/j,a[0][1])*j,_=Math.max(_,T)}}if(f){const P=Zn($*j,v,x)/j;if(E=Math.max(E,P),i){let T=0;!c&&!u||u&&!c&&h?T=ut(m+$*j+H,i[1][0])/j:T=ct(m+(u?A:-A)*j+H,i[0][0])/j,E=Math.max(E,T)}if(a){let T=0;!c&&!u||u&&!c&&h?T=ct(m+$*j,a[1][0])/j:T=ut(m+(u?A:-A)*j,a[0][0])/j,E=Math.max(E,T)}}}A=A+(A<0?E:-E),M=M+(M<0?_:-_),r&&(h?L>$*j?A=(Ds(c,u)?-M:M)/j:M=(Ds(c,u)?-A:A)*j:l?(A=M/j,u=c):(M=A*j,c=u));const b=c?m+M:m,I=u?w+A:w;return{width:k+(c?-M:M),height:C+(u?-A:A),x:s[0]*M*(c?-1:1)+b,y:s[1]*A*(u?-1:1)+I}}const Va={width:0,height:0,x:0,y:0},pp={...Va,pointerX:0,pointerY:0,aspectRatio:1};function gp(e,t,n){const o=t.position.x+e.position.x,r=t.position.y+e.position.y,s=e.measured.width??0,i=e.measured.height??0,a=n[0]*s,c=n[1]*i;return[[o-a,r-c],[o+s-a,r+i-c]]}function mp({domNode:e,nodeId:t,getStoreItems:n,onChange:o,onEnd:r}){const s=ke(e);let i={controlDirection:Ts("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function a({controlPosition:u,boundaries:l,keepAspectRatio:f,resizeDirection:h,onResizeStart:p,onResize:g,onResizeEnd:v,shouldResize:x}){let y={...Va},S={...pp};i={boundaries:l,resizeDirection:h,keepAspectRatio:f,controlDirection:Ts(u)};let m,w=null,k=[],C,j,M,A=!1;const L=qi().on("start",$=>{const{nodeLookup:H,transform:D,snapGrid:_,snapToGrid:E,nodeOrigin:b,paneDomNode:I}=n();if(m=H.get(t),!m)return;w=I?.getBoundingClientRect()??null;const{xSnapped:P,ySnapped:T}=ln($.sourceEvent,{transform:D,snapGrid:_,snapToGrid:E,containerBounds:w});y={width:m.measured.width??0,height:m.measured.height??0,x:m.position.x??0,y:m.position.y??0},S={...y,pointerX:P,pointerY:T,aspectRatio:y.width/y.height},C=void 0,j=Nt(m.extent)?m.extent:void 0,m.parentId&&(m.extent==="parent"||m.expandParent)&&(C=H.get(m.parentId)),C&&m.extent==="parent"&&(j=[[0,0],[C.measured.width,C.measured.height]]),k=[],M=void 0;for(const[U,z]of H)if(z.parentId===t&&(k.push({id:U,position:{...z.position},extent:z.extent}),z.extent==="parent"||z.expandParent)){const V=gp(z,m,z.origin??b);M?M=[[Math.min(V[0][0],M[0][0]),Math.min(V[0][1],M[0][1])],[Math.max(V[1][0],M[1][0]),Math.max(V[1][1],M[1][1])]]:M=V}p?.($,{...y})}).on("drag",$=>{const{transform:H,snapGrid:D,snapToGrid:_,nodeOrigin:E}=n(),b=ln($.sourceEvent,{transform:H,snapGrid:D,snapToGrid:_,containerBounds:w}),I=[];if(!m)return;const{x:P,y:T,width:U,height:z}=y,V={},K=m.origin??E,{width:q,height:oe,x:se,y:te}=hp(S,i.controlDirection,b,i.boundaries,i.keepAspectRatio,K,j,M),B=q!==U,O=oe!==z,Y=se!==P&&B,W=te!==T&&O;if(!Y&&!W&&!B&&!O)return;if((Y||W||K[0]===1||K[1]===1)&&(V.x=Y?se:y.x,V.y=W?te:y.y,y.x=V.x,y.y=V.y,k.length>0)){const ae=se-P,fe=te-T;for(const he of k)he.position={x:he.position.x-ae+K[0]*(q-U),y:he.position.y-fe+K[1]*(oe-z)},I.push(he)}if((B||O)&&(V.width=B&&(!i.resizeDirection||i.resizeDirection==="horizontal")?q:y.width,V.height=O&&(!i.resizeDirection||i.resizeDirection==="vertical")?oe:y.height,y.width=V.width,y.height=V.height),C&&m.expandParent){const ae=K[0]*(V.width??0);V.x&&V.x<ae&&(y.x=ae,S.x=S.x-(V.x-ae));const fe=K[1]*(V.height??0);V.y&&V.y<fe&&(y.y=fe,S.y=S.y-(V.y-fe))}const G=fp({width:y.width,prevWidth:U,height:y.height,prevHeight:z,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),Q={...y,direction:G};x?.($,Q)!==!1&&(A=!0,g?.($,Q),o(V,I))}).on("end",$=>{A&&(v?.($,{...y}),r?.({...y}),A=!1)});s.call(L)}function c(){s.on(".drag",null)}return{update:a,destroy:c}}var qo={exports:{}},Qo={},Jo={exports:{}},er={};var Os;function yp(){if(Os)return er;Os=1;var e=$i();function t(f,h){return f===h&&(f!==0||1/f===1/h)||f!==f&&h!==h}var n=typeof Object.is=="function"?Object.is:t,o=e.useState,r=e.useEffect,s=e.useLayoutEffect,i=e.useDebugValue;function a(f,h){var p=h(),g=o({inst:{value:p,getSnapshot:h}}),v=g[0].inst,x=g[1];return s(function(){v.value=p,v.getSnapshot=h,c(v)&&x({inst:v})},[f,p,h]),r(function(){return c(v)&&x({inst:v}),f(function(){c(v)&&x({inst:v})})},[f]),i(p),p}function c(f){var h=f.getSnapshot;f=f.value;try{var p=h();return!n(f,p)}catch{return!0}}function u(f,h){return h()}var l=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?u:a;return er.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:l,er}var Hs;function xp(){return Hs||(Hs=1,Jo.exports=yp()),Jo.exports}var zs;function wp(){if(zs)return Qo;zs=1;var e=$i(),t=xp();function n(u,l){return u===l&&(u!==0||1/u===1/l)||u!==u&&l!==l}var o=typeof Object.is=="function"?Object.is:n,r=t.useSyncExternalStore,s=e.useRef,i=e.useEffect,a=e.useMemo,c=e.useDebugValue;
1return Qo.useSyncExternalStoreWithSelector=function(u,l,f,h,p){var g=s(null);if(g.current===null){var v={hasValue:!1,value:null};g.current=v}else v=g.current;g=a(function(){function y(C){if(!S){if(S=!0,m=C,C=h(C),p!==void 0&&v.hasValue){var j=v.value;if(p(j,C))return w=j}return w=C}if(j=w,o(m,C))return j;var M=h(C);return p!==void 0&&p(j,M)?(m=C,j):(m=C,w=M)}var S=!1,m,w,k=f===void 0?null:f;return[function(){return y(l())},k===null?void 0:function(){return y(k())}]},[l,f,h,p]);var x=r(u,g[0],g[1]);return i(function(){v.hasValue=!0,v.value=x},[x]),c(x),x},Qo}var Ls;function vp(){return Ls||(Ls=1,qo.exports=wp()),qo.exports}var _p=vp();const bp=lu(_p),Sp={},Bs=e=>{let t;const n=new Set,o=(l,f)=>{const h=typeof l=="function"?l(t):l;if(!Object.is(h,t)){const p=t;t=f??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(g=>g(t,p))}},r=()=>t,c={setState:o,getState:r,getInitialState:()=>u,subscribe:l=>(n.add(l),()=>n.delete(l)),destroy:()=>{(Sp?"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()}},u=t=e(o,r,c);return c},Np=e=>e?Bs(e):Bs,{useDebugValue:Ep}=du,{useSyncExternalStoreWithSelector:Cp}=bp,kp=e=>e;function Fa(e,t=kp,n){const o=Cp(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Ep(o),o}const Vs=(e,t)=>{const n=Np(e),o=(r,s=t)=>Fa(n,r,s);return Object.assign(o,n),o},Mp=(e,t)=>e?Vs(e,t):Vs;function ge(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 Po=N.createContext(null),jp=Po.Provider,Ua=ze.error001("react");function le(e,t){const n=N.useContext(Po);if(n===null)throw new Error(Ua);return Fa(n,e,t)}function pe(){const e=N.useContext(Po);if(e===null)throw new Error(Ua);return N.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const Fs={display:"none"},Ip={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Wa="react-flow__node-desc",Xa="react-flow__edge-desc",Pp="react-flow__aria-live",Rp=e=>e.ariaLiveMessage,Ap=e=>e.ariaLabelConfig;function $p({rfId:e}){const t=le(Rp);return d.jsx("div",{id:`${Pp}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Ip,children:t})}function Tp({rfId:e,disableKeyboardA11y:t}){const n=le(Ap);return d.jsxs(d.Fragment,{children:[d.jsx("div",{id:`${Wa}-${e}`,style:Fs,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),d.jsx("div",{id:`${Xa}-${e}`,style:Fs,children:n["edge.a11yDescription.default"]}),!t&&d.jsx($p,{rfId:e})]})}const Ro=N.forwardRef(({position:e="top-left",children:t,className:n,style:o,...r},s)=>{const i=`${e}`.split("-");return d.jsx("div",{className:we(["react-flow__panel",n,...i]),style:o,ref:s,...r,children:t})});Ro.displayName="Panel";const Us="https://reactflow.dev?utm_source=attribution";function Dp({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:d.jsx(Ro,{position:t,className:"react-flow__attribution","data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: ${Us}`,children:d.jsx("a",{href:Us,target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const Op=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}},Gn=e=>e.id;function Hp(e,t){return ge(e.selectedNodes.map(Gn),t.selectedNodes.map(Gn))&&ge(e.selectedEdges.map(Gn),t.selectedEdges.map(Gn))}function zp({onSelectionChange:e}){const t=pe(),{selectedNodes:n,selectedEdges:o}=le(Op,Hp);return N.useEffect(()=>{const r={nodes:n,edges:o};
1e?.(r),t.getState().onSelectionChangeHandlers.forEach(s=>s(r))},[n,o,e]),null}const Lp=e=>!!e.onSelectionChangeHandlers;function Bp({onSelectionChange:e}){const t=le(Lp);return e||t?d.jsx(zp,{onSelectionChange:e}):null}const Ya=[0,0],Vp={x:0,y:0,zoom:1},Fp=["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"],Ws=[...Fp,"rfId"],Up=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}),Xs={translateExtent:mn,nodeOrigin:Ya,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function Wp(e){const{setNodes:t,setEdges:n,setMinZoom:o,setMaxZoom:r,setTranslateExtent:s,setNodeExtent:i,reset:a,setDefaultNodesAndEdges:c}=le(Up,ge),u=pe();N.useEffect(()=>(c(e.defaultNodes,e.defaultEdges),()=>{l.current=Xs,a()}),[]);const l=N.useRef(Xs);return N.useEffect(()=>{for(const f of Ws){const h=e[f],p=l.current[f];h!==p&&(typeof e[f]>"u"||(f==="nodes"?t(h):f==="edges"?n(h):f==="minZoom"?o(h):f==="maxZoom"?r(h):f==="translateExtent"?s(h):f==="nodeExtent"?i(h):f==="ariaLabelConfig"?u.setState({ariaLabelConfig:jh(h)}):f==="fitView"?u.setState({fitViewQueued:h}):f==="fitViewOptions"?u.setState({fitViewOptions:h}):u.setState({[f]:h})))}l.current=e},Ws.map(f=>e[f])),null}function Ys(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Xp(e){const[t,n]=N.useState(e==="system"?null:e);return N.useEffect(()=>{if(e!=="system"){n(e);return}const o=Ys(),r=()=>n(o?.matches?"dark":"light");return r(),o?.addEventListener("change",r),()=>{o?.removeEventListener("change",r)}},[e]),t!==null?t:Ys()?.matches?"dark":"light"}const Zs=typeof document<"u"?document:null;function vn(e=null,t={target:Zs,actInsideInputWithModifier:!0}){const[n,o]=N.useState(!1),r=N.useRef(!1),s=N.useRef(new Set([])),[i,a]=N.useMemo(()=>{if(e!==null){const u=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",` 2`).replace(` 3 4`,` 5+`).split(` 6`)),l=u.reduce((f,h)=>f.concat(...h),[]);return[u,l]}return[[],[]]},[e]);return N.useEffect(()=>{const c=t?.target??Zs,u=t?.actInsideInputWithModifier??!0;if(e!==null){const l=p=>{if(r.current=p.ctrlKey||p.metaKey||p.shiftKey||p.altKey,(!r.current||r.current&&!u)&&Ca(p))return!1;const v=Ks(p.code,a);if(s.current.add(p[v]),Gs(i,s.current,!1)){const x=p.composedPath?.()?.[0]||p.target,y=x?.nodeName==="BUTTON"||x?.nodeName==="A";t.preventDefault!==!1&&(r.current||!y)&&p.preventDefault(),o(!0)}},f=p=>{const g=Ks(p.code,a);Gs(i,s.current,!0)?(o(!1),s.current.clear()):s.current.delete(p[g]),p.key==="Meta"&&s.current.clear(),r.current=!1},h=()=>{s.current.clear(),o(!1)};return c?.addEventListener("keydown",l),c?.addEventListener("keyup",f),window.addEventListener("blur",h),window.addEventListener("contextmenu",h),()=>{c?.removeEventListener("keydown",l),c?.removeEventListener("keyup",f),window.removeEventListener("blur",h),window.removeEventListener("contextmenu",h)}}},[e,o]),n}function Gs(e,t,n){return e.filter(o=>n||o.length===t.size).some(o=>o.every(r=>t.has(r)))}function Ks(e,t){return t.includes(e)?"code":"key"}const Yp=()=>{const e=pe();return N.useMemo(()=>({zoomIn:async t=>
6{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,s],panZoom:i}=e.getState();return i?(await i.setViewport({x:t.x??o,y:t.y??r,zoom:t.zoom??s},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:s,maxZoom:i,panZoom:a}=e.getState(),c=Dr(t,o,r,s,i,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:s,domNode:i}=e.getState();if(!i)return t;const{x:a,y:c}=i.getBoundingClientRect(),u={x:t.x-a,y:t.y-c},l=n.snapGrid??r,f=n.snapToGrid??s;return Cn(u,o,f,l)},flowToScreenPosition:t=>{const{transform:n,domNode:o}=e.getState();if(!o)return t;const{x:r,y:s}=o.getBoundingClientRect(),i=Zt(t,n);return{x:i.x+r,y:i.y+s}}}),[])};function Za(e,t){const n=[],o=new Map,r=[];for(const s of e)if(s.type==="add"){r.push(s);continue}else if(s.type==="remove"||s.type==="replace")o.set(s.id,[s]);else{const i=o.get(s.id);i?i.push(s):o.set(s.id,[s])}for(const s of t){const i=o.get(s.id);if(!i){n.push(s);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const a={...s};for(const c of i)Zp(c,a);n.push(a)}return r.length&&r.forEach(s=>{s.index!==void 0?n.splice(s.index,0,{...s.item}):n.push({...s.item})}),n}function Zp(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 Ga(e,t){return Za(e,t)}function Ka(e,t){return Za(e,t)}function yt(e,t){return{id:e,type:"select",selected:t}}function Lt(e,t=new Set,n=!1){const o=[];for(const[r,s]of e){const i=t.has(r);!(s.selected===void 0&&!i)&&s.selected!==i&&(n&&(s.selected=i),o.push(yt(s.id,i)))}return o}function qs({items:e=[],lookup:t}){const n=[],o=new Map(e.map(r=>[r.id,r]));for(const[r,s]of e.entries()){const i=t.get(s.id),a=i?.internals?.userNode??i;a!==void 0&&a!==s&&n.push({id:s.id,item:s,type:"replace"}),a===void 0&&n.push({item:s,type:"add",index:r})}for(const[r]of t)o.get(r)===void 0&&n.push({id:r,type:"remove"});return n}function Qs(e){return{id:e.id,type:"remove"}}const Gp=ba();function qa(e,t,n={}){return Th(e,t,{...n,onError:n.onError??Gp})}const Js=e=>vh(e),Kp=e=>ya(e);function Qa(e){return N.forwardRef(e)}const Ja=typeof window<"u"?N.useLayoutEffect:N.useEffect;function ei(e){const[t,n]=N.useState(BigInt(0)),[o]=N.useState(()=>qp(()=>n(r=>r+BigInt(1))));return Ja(()=>{const r=o.get();r.length&&(e(r),o.reset())},[t]),o}function qp(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const ec=N.createContext(null);function Qp({children:e}){const t=pe(),n=N.useCallback(a=>{const{nodes:c=[],setNodes:u,hasDefaultNodes:l,onNodesChange:f,nodeLookup:h,fitViewQueued:p,onNodesChangeMiddlewareMap:g}=t.getState();let v=c;for(const y of a)v=typeof y=="function"?y(v):y;let x=qs({items:v,lookup:h});for(const y of g.values())x=y(x);l&&u(v),x.length>0?f?.(x):p&&window.requestAnimationFrame(()=>{const{fitViewQueued:y,nodes:S,setNodes:m}=t.getState();y&&m(S)})},[]),o=ei(n),r=N.useCallback(a=>{const{edges:c=[],setEdges:u,hasDefaultEdges:l,onEdgesChange:f,edgeLookup:h}=t.getState();let p=c;for(const g of a)p=typeof g=="function"?g(p):g;l?u(p):f&&f(qs({items:p,lookup:h}))},[]),s=ei(r),i=N.useMemo(()=>({nodeQueue:o,edgeQueue:s}),[]);return d.jsx(ec.Provider,{value:i,children:e})}function Jp(){const e=N.useContext(ec);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const eg=e=>!!e.panZoom;function Fr(){const e=Yp(),t=pe(),n=Jp(),o=le(eg),r=N.useMemo(()=>{const s=f=>t.getState().nodeLookup.get(f),i=f=>{n.nodeQueue.push(f)},a=f=>{n.edgeQueue.push(f)},c=f=>{const{nodeLookup:h,nodeOrigin:p}=t.getState(),g=Js(f)?f:h.get(f.id),v=g.parentId?Na(g.position,g.measured,g.parentId,h,p):g.position,x={...g,position:v,width:g.measured?.width??g.width,height:g.measured?.height??g.height};return xn(x)},u=(f,h,p={replace:!1})=>{i(g=>g.map(v=>{if(v.id===f){const x=typeof h=="function"?h(v):h;return p.replace&&Js(x)?x:{...v,...x}}return v}))},l=(f,h,p={replace:!1})=>{a(g=>g.map(v=>{if(v.id===f){const x=typeof h=="function"?h(v):h;return p.replace&&Kp(x)?x:{...v,...x}}return v}))};return{getNodes:()=>t.getState().nodes.map(f=>({...f})),getNode:f=>s(f)?.internals.userNode,getInternalNode:s,getEdges:()=>{const{edges:f=[]}=t.getState();return f.map(h=>({...h}))},getEdge:f=>t.getState().edgeLookup.get(f),setNodes:i,setEdges:a,addNodes:f=>{const h=Array.isArray(f)?f:[f];n.nodeQueue.push(p=>[...p,...h])},addEdges:f=>{const h=Array.isArray(f)?f:[f];n.edgeQueue.push(p=>[...p,...h])},toObject:()=>{const{nodes:f=[],edges:h=[],transform:p}=t.getState(),[g,v,x]=p;return{nodes:f.map(y=>({...y})),edges:h.map(y=>({...y})),viewport:{x:g,y:v,zoom:x}}},deleteElements:async({nodes:f=[],edges:h=[]})=>{const{nodes:p,edges:g,onNodesDelete:v,onEdgesDelete:x,triggerNodeChanges:y,triggerEdgeChanges:S,onDelete:m,onBeforeDelete:w}=t.getState(),{nodes:k,edges:C}=await Eh({nodesToRemove:f,edgesToRemove:h,nodes:p,edges:g,onBeforeDelete:w}),j=C.length>0,M=k.length>0;if(j){const A=C.map(Qs);x?.(C),S(A)}if(M){const A=k.map(Qs);v?.(k),y(A)}return(M||j)&&m?.({nodes:k,edges:C}),{deletedNodes:k,deletedEdges:C}},getIntersectingNodes:(f,h=!0,p)=>{const g=Ns(f),v=g?f:c(f),x=p!==void 0;return v?(p||t.getState().nodes).filter(y=>{const S=t.getState().nodeLookup.get(y.id);if(S&&!g&&(y.id===f.id||!S.internals.positionAbsolute))return!1;const m=xn(x?y:S),w=vo(m,v);return h&&w>0||w>=m.width*m.height||w>=v.width*v.height}):[]},isNodeIntersecting:(f,h,p=!0)=>{const v=Ns(f)?f:c(f);if(!v)return!1;const x=vo(v,h);return p&&x>0||x>=h.width*h.height||x>=v.width*v.height},updateNode:u,updateNodeData:(f,h,p={replace:!1})=>{u(f,g=>{const v=typeof h=="function"?h(g):h;return p.replace?{...g,data:v}:{...g,data:{...g.data,...v}}},p)},updateEdge:l,updateEdgeData:(f,h,p={replace:!1})=>{l(f,g=>{const v=typeof h=="function"?h(g):h;return p.replace?{...g,data:v}:{...g,data:{...g.data,...v}}},p)}
6,getNodesBounds:f=>{const{nodeLookup:h,nodeOrigin:p}=t.getState();return _h(f,{nodeLookup:h,nodeOrigin:p})},getHandleConnections:({type:f,id:h,nodeId:p})=>Array.from(t.getState().connectionLookup.get(`${p}-${f}${h?`-${h}`:""}`)?.values()??[]),getNodeConnections:({type:f,handleId:h,nodeId:p})=>Array.from(t.getState().connectionLookup.get(`${p}${f?h?`-${f}-${h}`:`-${f}`:""}`)?.values()??[]),fitView:async f=>{const h=t.getState().fitViewResolver??Mh();return t.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:h}),n.nodeQueue.push(p=>[...p]),h.promise}}},[]);return N.useMemo(()=>({...r,...e,viewportInitialized:o}),[o])}const ti=e=>e.selected,tg=typeof window<"u"?window:void 0;function ng({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=pe(),{deleteElements:o}=Fr(),r=vn(e,{actInsideInputWithModifier:!1}),s=vn(t,{target:tg});N.useEffect(()=>{if(r){const{edges:i,nodes:a}=n.getState();o({nodes:a.filter(ti),edges:i.filter(ti)}),n.setState({nodesSelectionActive:!1})}},[r]),N.useEffect(()=>{n.setState({multiSelectionActive:s})},[s])}function og(e){const t=pe();N.useEffect(()=>{const n=()=>
6{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const o=Or(e.current);(o.height===0||o.width===0)&&t.getState().onError?.("004",ze.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 Ao={position:"absolute",width:"100%",height:"100%",top:0,left:0},rg=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function sg({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:o=!1,panOnScrollSpeed:r=.5,panOnScrollMode:s=vt.Free,zoomOnDoubleClick:i=!0,panOnDrag:a=!0,defaultViewport:c,translateExtent:u,minZoom:l,maxZoom:f,zoomActivationKeyCode:h,preventScrolling:p=!0,children:g,noWheelClassName:v,noPanClassName:x,onViewportChange:y,isControlledViewport:S,paneClickDistance:m,selectionOnDrag:w}){const k=pe(),C=N.useRef(null),{userSelectionActive:j,lib:M,connectionInProgress:A}=le(rg,ge),L=vn(h),$=N.useRef();og(C);const H=N.useCallback(D=>{y?.({x:D[0],y:D[1],zoom:D[2]}),S||k.setState({transform:D})},[y,S]);return N.useEffect(()=>{if(C.current){$.current=dp({domNode:C.current,minZoom:l,maxZoom:f,translateExtent:u,viewport:c,onDraggingChange:b=>k.setState(I=>I.paneDragging===b?I:{paneDragging:b}),onPanZoomStart:(b,I)=>{const{onViewportChangeStart:P,onMoveStart:T}=k.getState();T?.(b,I),P?.(I)},onPanZoom:(b,I)=>{const{onViewportChange:P,onMove:T}=k.getState();T?.(b,I),P?.(I)},onPanZoomEnd:(b,I)=>{const{onViewportChangeEnd:P,onMoveEnd:T}=k.getState();T?.(b,I),P?.(I)}});const{x:D,y:_,zoom:E}=$.current.getViewport();return k.setState({panZoom:$.current,transform:[D,_,E],domNode:C.current.closest(".react-flow")}),()=>{$.current?.destroy()}}},[]),N.useEffect(()=>{$.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:o,panOnScrollSpeed:r,panOnScrollMode:s,zoomOnDoubleClick:i,panOnDrag:a,zoomActivationKeyPressed:L,preventScrolling:p,noPanClassName:x,userSelectionActive:j,noWheelClassName:v,lib:M,onTransformChange:H,connectionInProgress:A,selectionOnDrag:w,paneClickDistance:m})},[e,t,n,o,r,s,i,a,L,p,x,j,v,M,H,A,w,m]),d.jsx("div",{className:"react-flow__renderer",ref:C,style:Ao,children:g})}const ig=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function ag(){const{userSelectionActive:e,userSelectionRect:t}=le(ig,ge);return e&&t?d.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 tr=(e,t)=>n=>{n.target===t.current&&e?.(n)},cg=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function ug({isSelecting:e,selectionKeyPressed:t,selectionMode:n=yn.Full,panOnDrag:o,autoPanOnSelection:r,paneClickDistance:s,selectionOnDrag:i,onSelectionStart:a,onSelectionEnd:c,onPaneClick:u,onPaneContextMenu:l,onPaneScroll:f,onPaneMouseEnter:h,onPaneMouseMove:p,onPaneMouseLeave:g,children:v}){const x=N.useRef(0),y=pe(),{userSelectionActive:S,elementsSelectable:m,dragging:w,panBy:k,autoPanSpeed:C}=le(cg,ge),j=m&&(e||S),M=N.useRef(null),A=N.useRef(),L=N.useRef(new Set),$=N.useRef(new Set),H=N.useRef(!1),D=N.useRef(!1),_=N.useRef({x:0,y:0}),E=N.useRef(!1),b=B=>{if(D.current||H.current||y.getState().connection.inProgress){D.current=!1,H.current=!1;return}u?.(B),y.getState().resetSelectedElements(),y.setState({nodesSelectionActive:!1})},I=B=>{if(Array.isArray(o)&&o?.includes(2)){B.preventDefault();return}l?.(B)},P=f?B=>f(B):void 0,T=B=>{D.current&&(B.stopPropagation(),D.current=!1)},U=B=>{const{domNode:O,transform:Y}=y.getState();if(A.current=O?.getBoundingClientRect(),!A.current)return;const W=B.target===M.current;if(!W&&!!B.target.closest(".nokey")||!e||!(i&&W||t)||B.button!==0||!B.isPrimary)return;B.target?.setPointerCapture?.(B.pointerId),D.current=!1;const{x:re,y:ae}=Oe(B.nativeEvent,A.current),fe=Cn({x:re,y:ae},Y);y.setState({userSelectionRect:{width:0,height:0,startX:fe.x,startY:fe.y,x:re,y:ae}}),W||(B.stopPropagation(),B.preventDefault())};function z(B,O){const{userSelectionRect:Y}=y.getState();if(!Y)return;const{transform:W,nodeLookup:G,edgeLookup:Q,connectionLookup:re,triggerNodeChanges:ae,triggerEdgeChanges:fe,defaultEdgeOptions:he}=y.getState(),de={x:Y.startX,y:Y.startY},{x:je,y:ve}=Zt(de,W),me={startX:de.x,startY:de.y,x:B<je?B:je,y:O<ve?O:ve,width:Math.abs(B-je),height:Math.abs(O-ve)}
6,pt=L.current,Re=$.current;L.current=new Set($r(G,me,W,n===yn.Partial,!0).map(be=>be.id)),$.current=new Set;const Ze=he?.selectable??!0;for(const be of L.current){const _e=re.get(be);if(_e)for(const{edgeId:Ie}of _e.values()){const Se=Q.get(Ie);Se&&(Se.selectable??Ze)&&$.current.add(Ie)}}if(!Es(pt,L.current)){const be=Lt(G,L.current,!0);ae(be)}if(!Es(Re,$.current)){const be=Lt(Q,$.current);fe(be)}y.setState({userSelectionRect:me,userSelectionActive:!0,nodesSelectionActive:!1})}function V(){if(!r||!A.current)return;const[B,O]=Tr(_.current,A.current,C);k({x:B,y:O}).then(Y=>{if(!D.current||!Y){x.current=requestAnimationFrame(V);return}const{x:W,y:G}=_.current;z(W,G),x.current=requestAnimationFrame(V)})}const K=()=>{cancelAnimationFrame(x.current),x.current=0,E.current=!1};N.useEffect(()=>()=>K(),[]);const q=B=>{const{userSelectionRect:O,transform:Y,resetSelectedElements:W}=y.getState();if(!A.current||!O)return;const{x:G,y:Q}=Oe(B.nativeEvent,A.current);_.current={x:G,y:Q};const re=Zt({x:O.startX,y:O.startY},Y);if(!D.current){const ae=t?0:s;if(Math.hypot(G-re.x,Q-re.y)<=ae)return;W(),a?.(B)}D.current=!0,E.current||(V(),E.current=!0),z(G,Q)},oe=B=>{if(!j){B.target===M.current&&y.getState().connection.inProgress&&(H.current=!0);return}B.button===0&&(B.target?.releasePointerCapture?.(B.pointerId),!S&&B.target===M.current&&y.getState().userSelectionRect&&b?.(B),y.setState({userSelectionActive:!1,userSelectionRect:null}),D.current&&(c?.(B),y.setState({nodesSelectionActive:L.current.size>0})),K())},se=B=>{B.target?.releasePointerCapture?.(B.pointerId),K()},te=o===!0||Array.isArray(o)&&o.includes(0);return d.jsxs("div",{className:we(["react-flow__pane",{draggable:te,dragging:w,selection:e}]),onClick:j?void 0:tr(b,M),onContextMenu:tr(I,M),onWheel:tr(P,M),onPointerEnter:j?void 0:h,onPointerMove:j?q:p,onPointerUp:oe,onPointerCancel:j?se:void 0,onPointerDownCapture:j?U:void 0,onClickCapture:j?T:void 0,onPointerLeave:g,ref:M,style:Ao,children:[v,d.jsx(ag,{})]})}function br({id:e,store:t,unselect:n=!1,nodeRef:o}){const{addSelectedNodes:r,unselectNodesAndEdges:s,multiSelectionActive:i,nodeLookup:a,onError:c}=t.getState(),u=a.get(e);if(!u){c?.("012",ze.error012(e));return}t.setState({nodesSelectionActive:!1}),u.selected?(n||u.selected&&i)&&(s({nodes:[u],edges:[]}),requestAnimationFrame(()=>o?.current?.blur())):r([e])}function tc({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:o,nodeId:r,isSelectable:s,nodeClickDistance:i}){const a=pe(),[c,u]=N.useState(!1),l=N.useRef();return N.useEffect(()=>{if(!t)return l.current=qh({getStoreItems:()=>a.getState(),onNodeMouseDown:f=>{br({id:f,store:a,nodeRef:e})},onDragStart:()=>{u(!0)},onDragStop:()=>{u(!1)}}),()=>{l.current?.destroy(),l.current=void 0}},[t,a,e]),N.useEffect(()=>{t||!e.current||!l.current||l.current.update({noDragClassName:n,handleSelector:o,domNode:e.current,isSelectable:s,nodeId:r,nodeClickDistance:i})},[n,o,t,s,e,r,i]),c}const lg=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function nc(){const e=pe();return N.useCallback(n=>{const{nodeExtent:o,snapToGrid:r,snapGrid:s,nodesDraggable:i,onError:a,updateNodePositions:c,nodeLookup:u,nodeOrigin:l}=e.getState(),f=new Map,h=lg(i),p=r?s[0]:5,g=r?s[1]:5,v=n.direction.x*p*n.factor,x=n.direction.y*g*n.factor;for(const[,y]of u){if(!h(y))continue;let S={x:y.internals.positionAbsolute.x+v,y:y.internals.positionAbsolute.y+x};r&&(S=En(S,s));const{position:m,positionAbsolute:w}=xa({nodeId:y.id,nextPosition:S,nodeLookup:u,nodeExtent:o,nodeOrigin:l,onError:a});y.position=m,y.internals.positionAbsolute=w,f.set(y.id,y)}c(f)},[])}const Ur=N.createContext(null),dg=Ur.Provider;Ur.Consumer;const oc=()=>N.useContext(Ur),fg=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),rc=N.createContext(null);function hg({children:e}){const t=le(fg,ge);return d.jsx(rc.Provider,{value:t,children:e})}function pg(){const e=N.useContext(rc);if(!e)throw new Error("useHandleConfig must be used within a HandleConfigProvider");return e}const gg={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},mg=(e,t,n)=>o=>{const{connectionClickStartHandle:r,connectionMode:s,connection:i}=o,{fromHandle:a,toHandle:c,isValid:u}=i;if(!a&&!r)return gg;const l=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:a?.nodeId===e&&a?.id===t&&a?.type===n,connectingTo:l,clickConnecting:r?.nodeId===e&&r?.id===t&&r?.type===n,isPossibleEndHandle:s===Xt.Strict?a?.type!==n:e!==a?.nodeId||t!==a?.id,connectionInProcess:!!a,clickConnectionInProcess:!!r,valid:l&&u}};function yg({type:e="source",position:t=ne.Top,isValidConnection:n,isConnectable:o=!0,isConnectableStart:r=!0,isConnectableEnd:s=!0,id:i,onConnect:a,children:c,className:u,onMouseDown:l,onTouchStart:f,...h},p){const g=i||null,v=e==="target",x=pe(),y=oc(),{connectOnClick:S,noPanClassName:m,rfId:w}=pg(),{connectingFrom:k,connectingTo:C,clickConnecting:j,isPossibleEndHandle:M,connectionInProcess:A,clickConnectionInProcess:L,valid:$}=le(mg(y,g,e),ge);y||x.getState().onError?.("010",ze.error010());const H=E=>{const{defaultEdgeOptions:b,onConnect:I,hasDefaultEdges:P}=x.getState(),T={...b,...E};if(P){const{edges:U,setEdges:z,onError:V}=x.getState();z(qa(T,U,{onError:V}))}I?.(T),a?.(T)},D=E=>{if(!y)return;const b=ka(E.nativeEvent);if(r&&(b&&E.button===0||!b)){const I=x.getState();
6_r.onPointerDown(E.nativeEvent,{handleDomNode:E.currentTarget,autoPanOnConnect:I.autoPanOnConnect,connectionMode:I.connectionMode,connectionRadius:I.connectionRadius,domNode:I.domNode,nodeLookup:I.nodeLookup,lib:I.lib,isTarget:v,handleId:g,nodeId:y,flowId:I.rfId,panBy:I.panBy,cancelConnection:I.cancelConnection,onConnectStart:I.onConnectStart,onConnectEnd:(...P)=>x.getState().onConnectEnd?.(...P),updateConnection:I.updateConnection,onConnect:H,isValidConnection:n||((...P)=>x.getState().isValidConnection?.(...P)??!0),getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,autoPanSpeed:I.autoPanSpeed,dragThreshold:I.connectionDragThreshold})}b?l?.(E):f?.(E)},_=E=>{const{onClickConnectStart:b,onClickConnectEnd:I,connectionClickStartHandle:P,connectionMode:T,isValidConnection:U,lib:z,rfId:V,nodeLookup:K,connection:q}=x.getState();if(!y||!P&&!r)return;if(!P){b?.(E.nativeEvent,{nodeId:y,handleId:g,handleType:e}),x.setState({connectionClickStartHandle:{nodeId:y,type:e,id:g}});return}const oe=Ea(E.target),se=n||U,{connection:te,isValid:B}=_r.isValid(E.nativeEvent,{handle:{nodeId:y,id:g,type:e},connectionMode:T,fromNodeId:P.nodeId,fromHandleId:P.id||null,fromType:P.type,isValidConnection:se,flowId:V,doc:oe,lib:z,nodeLookup:K});B&&te&&H(te);const O=structuredClone(q);delete O.inProgress,O.toPosition=O.toHandle?O.toHandle.position:null,I?.(E,O),x.setState({connectionClickStartHandle:null})};return d.jsx("div",{"data-handleid":g,"data-nodeid":y,"data-handlepos":t,"data-id":`${w}-${y}-${g}-${e}`,className:we(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",m,u,{source:!v,target:v,connectable:o,connectablestart:r,connectableend:s,clickconnecting:j,connectingfrom:k,connectingto:C,valid:$,connectionindicator:o&&(!A||M)&&(A||L?s:r)}]),onMouseDown:D,onTouchStart:D,onClick:S?_:void 0,ref:p,...h,children:c})}const Kt=N.memo(Qa(yg));function xg({data:e,isConnectable:t,sourcePosition:n=ne.Bottom}){return d.jsxs(d.Fragment,{children:[e?.label,d.jsx(Kt,{type:"source",position:n,isConnectable:t})]})}function wg({data:e,isConnectable:t,targetPosition:n=ne.Top,sourcePosition:o=ne.Bottom}){return d.jsxs(d.Fragment,{children:[d.jsx(Kt,{type:"target",position:n,isConnectable:t}),e?.label,d.jsx(Kt,{type:"source",position:o,isConnectable:t})]})}function vg(){return null}function _g({data:e,isConnectable:t,targetPosition:n=ne.Top}){return d.jsxs(d.Fragment,{children:[d.jsx(Kt,{type:"target",position:n,isConnectable:t}),e?.label]})}const _o={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},ni={input:xg,default:wg,output:_g,group:vg};function bg(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 Sg=e=>{const{width:t,height:n,x:o,y:r}=Nn(e.nodeLookup,{filter:s=>!!s.selected});return{width:De(t)?t:null,height:De(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 Ng({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const o=pe(),{width:r,height:s,transformString:i,userSelectionActive:a}=le(Sg,ge),c=nc(),u=N.useRef(null);N.useEffect(()=>{n||u.current?.focus({preventScroll:!0})},[n]);const l=!a&&r!==null&&s!==null;if(tc({nodeRef:u,disabled:!l}),!l)return null;const f=e?p=>{const g=o.getState().nodes.filter(v=>v.selected);e(p,g)}:void 0,h=p=>{Object.prototype.hasOwnProperty.call(_o,p.key)&&(p.preventDefault(),c({direction:_o[p.key],factor:p.shiftKey?4:1}))};return d.jsx("div",{className:we(["react-flow__nodesselection","react-flow__container",t]),style:{transform:i},children:d.jsx("div",{ref:u,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:n?void 0:-1,onKeyDown:n?void 0:h,style:{width:r,height:s}})})}const oi=typeof window<"u"?window:void 0,Eg=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function sc({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:r,onPaneContextMenu:s,onPaneScroll:i,paneClickDistance:a,deleteKeyCode:c,selectionKeyCode:u,selectionOnDrag:l,selectionMode:f,onSelectionStart:h,onSelectionEnd:p,multiSelectionKeyCode:g,panActivationKeyCode:v,zoomActivationKeyCode:x,elementsSelectable:y,zoomOnScroll:S,zoomOnPinch:m,panOnScroll:w,panOnScrollSpeed:k,panOnScrollMode:C,zoomOnDoubleClick:j,panOnDrag:M,autoPanOnSelection:A,defaultViewport:L,translateExtent:$,minZoom:H,maxZoom:D,preventScrolling:_,onSelectionContextMenu:E,noWheelClassName:b,noPanClassName:I,disableKeyboardA11y:P,onViewportChange:T,isControlledViewport:U}){const{nodesSelectionActive:z,userSelectionActive:V}=le(Eg,ge),K=vn(u,{target:oi}),q=vn(v,{target:oi}),oe=q||M,se=q||w,te=l&&oe!==!0,B=K||V||te;return ng({deleteKeyCode:c,multiSelectionKeyCode:g}),d.jsx(sg,{onPaneContextMenu:s,elementsSelectable:y,zoomOnScroll:S,zoomOnPinch:m,panOnScroll:se,panOnScrollSpeed:k,panOnScrollMode:C,zoomOnDoubleClick:j,panOnDrag:!K&&oe,defaultViewport:L,translateExtent:$,minZoom:H,maxZoom:D,zoomActivationKeyCode:x,preventScrolling:_,noWheelClassName:b,noPanClassName:I,onViewportChange:T,isControlledViewport:U,paneClickDistance:a,selectionOnDrag:te,children:d.jsxs(ug,{onSelectionStart:h,onSelectionEnd:p,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:o,onPaneMouseLeave:r,onPaneContextMenu:s,onPaneScroll:i,panOnDrag:oe,autoPanOnSelection:A,isSelecting:!!B,selectionMode:f,selectionKeyPressed:K,paneClickDistance:a,selectionOnDrag:te,children:[e,z&&d.jsx(Ng,{onSelectionContextMenu:E,noPanClassName:I,disableKeyboardA11y:P})]})})}sc.displayName="FlowRenderer";const Cg=N.memo(sc),kg=e=>t=>e?$r(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 Mg(e){return le(N.useCallback(kg(e),[e]),ge)}
6const jg=e=>e.updateNodeInternals;function Ig(){const e=le(jg),[t]=N.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const o=new Map;n.forEach(r=>{const s=r.target.getAttribute("data-id");o.set(s,{id:s,nodeElement:r.target,force:!0})}),e(o)}));return N.useEffect(()=>()=>{t?.disconnect()},[t]),t}function Pg({node:e,nodeType:t,hasDimensions:n,resizeObserver:o}){const r=pe(),s=N.useRef(null),i=N.useRef(null),a=N.useRef(e.sourcePosition),c=N.useRef(e.targetPosition),u=N.useRef(t),l=n&&!!e.internals.handleBounds;return N.useEffect(()=>{s.current&&!e.hidden&&(!l||i.current!==s.current)&&(i.current&&o?.unobserve(i.current),o?.observe(s.current),i.current=s.current)},[l,e.hidden]),N.useEffect(()=>()=>{i.current&&(o?.unobserve(i.current),i.current=null)},[]),N.useEffect(()=>{if(s.current){const f=u.current!==t,h=a.current!==e.sourcePosition,p=c.current!==e.targetPosition;(f||h||p)&&(u.current=t,a.current=e.sourcePosition,c.current=e.targetPosition,r.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:s.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),s}function Rg({id:e,onClick:t,onMouseEnter:n,onMouseMove:o,onMouseLeave:r,onContextMenu:s,onDoubleClick:i,nodesDraggable:a,elementsSelectable:c,nodesConnectable:u,nodesFocusable:l,resizeObserver:f,noDragClassName:h,noPanClassName:p,disableKeyboardA11y:g,rfId:v,nodeTypes:x,nodeClickDistance:y,onError:S}){const{node:m,internals:w,isParent:k}=le(B=>{const O=B.nodeLookup.get(e),Y=B.parentLookup.has(e);return{node:O,internals:O.internals,isParent:Y}},ge);let C=m.type||"default",j=x?.[C]||ni[C];j===void 0&&(S?.("003",ze.error003(C)),C="default",j=x?.default||ni.default);const M=!!(m.draggable||a&&typeof m.draggable>"u"),A=!!(m.selectable||c&&typeof m.selectable>"u"),L=!!(m.connectable||u&&typeof m.connectable>"u"),$=!!(m.focusable||l&&typeof m.focusable>"u"),H=pe(),D=Sa(m),_=Pg({node:m,nodeType:C,hasDimensions:D,resizeObserver:f}),E=tc({nodeRef:_,disabled:m.hidden||!M,noDragClassName:h,handleSelector:m.dragHandle,nodeId:e,isSelectable:A,nodeClickDistance:y}),b=nc();if(m.hidden)return null;const I=Ye(m),P=bg(m),T=A||M||t||n||o||r,U=n?B=>n(B,{...w.userNode}):void 0,z=o?B=>o(B,{...w.userNode}):void 0,V=r?B=>r(B,{...w.userNode}):void 0,K=s?B=>s(B,{...w.userNode}):void 0,q=i?B=>i(B,{...w.userNode}):void 0,oe=B=>{const{selectNodesOnDrag:O,nodeDragThreshold:Y}=H.getState();A&&(!O||!M||Y>0)&&br({id:e,store:H,nodeRef:_}),t&&t(B,{...w.userNode})},se=B=>{if(!(Ca(B.nativeEvent)||g)){if(ha.includes(B.key)&&A){const O=B.key==="Escape";br({id:e,store:H,unselect:O,nodeRef:_})}else if(M&&m.selected&&Object.prototype.hasOwnProperty.call(_o,B.key)){B.preventDefault();const{ariaLabelConfig:O}=H.getState();H.setState({ariaLiveMessage:O["node.a11yDescription.ariaLiveMessage"]({direction:B.key.replace("Arrow","").toLowerCase(),x:~~w.positionAbsolute.x,y:~~w.positionAbsolute.y})}),b({direction:_o[B.key],factor:B.shiftKey?4:1})}}},te=()=>{if(g||!_.current?.matches(":focus-visible"))return;const{transform:B,width:O,height:Y,autoPanOnNodeFocus:W,setCenter:G}=H.getState();if(!W)return;$r(new Map([[e,m]]),{x:0,y:0,width:O,height:Y},B,!0).length>0||G(m.position.x+I.width/2,m.position.y+I.height/2,{zoom:B[2]})};return d.jsx("div",{className:we(["react-flow__node",`react-flow__node-${C}`,{[p]:M},m.className,{selected:m.selected,selectable:A,parent:k,draggable:M,dragging:E}]),ref:_,style:{zIndex:w.z,transform:`translate(${w.positionAbsolute.x}px,${w.positionAbsolute.y}px)`,pointerEvents:T?"all":"none",visibility:D?"visible":"hidden",...m.style,...P},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:U,onMouseMove:z,onMouseLeave:V,onContextMenu:K,onClick:oe,onDoubleClick:q,onKeyDown:$?se:void 0,tabIndex:$?0:void 0,onFocus:$?te:void 0,role:m.ariaRole??($?"group":void 0),"aria-roledescription":"node","aria-describedby":g?void 0:`${Wa}-${v}`,"aria-label":m.ariaLabel,...m.domAttributes,children:d.jsx(dg,{value:e,children:d.jsx(j,{id:e,data:m.data,type:C,positionAbsoluteX:w.positionAbsolute.x,positionAbsoluteY:w.positionAbsolute.y,selected:m.selected??!1,selectable:A,draggable:M,deletable:m.deletable??!0,isConnectable:L,sourcePosition:m.sourcePosition,targetPosition:m.targetPosition,dragging:E,dragHandle:m.dragHandle,zIndex:w.z,parentId:m.parentId,...I})})})}var Ag=N.memo(Rg);const $g=e=>
6({nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function ic(e){const{nodesConnectable:t,nodesFocusable:n,elementsSelectable:o,onError:r}=le($g,ge),s=Mg(e.onlyRenderVisibleElements),i=Ig();return d.jsx("div",{className:"react-flow__nodes",style:Ao,children:s.map(a=>d.jsx(Ag,{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:i,nodesDraggable:e.nodesDraggable??!0,nodesConnectable:t,nodesFocusable:n,elementsSelectable:o,nodeClickDistance:e.nodeClickDistance,onError:r},a))})}ic.displayName="NodeRenderer";const Tg=N.memo(ic);function Dg(e){return le(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 s=n.nodeLookup.get(r.source),i=n.nodeLookup.get(r.target);s&&i&&Rh({sourceNode:s,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&o.push(r.id)}return o},[e]),ge)}const Og=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return d.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},Hg=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return d.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},ri={[xo.Arrow]:Og,[xo.ArrowClosed]:Hg};function zg(e){const t=pe();return N.useMemo(()=>Object.prototype.hasOwnProperty.call(ri,e)?ri[e]:(t.getState().onError?.("009",ze.error009(e)),null),[e])}const Lg=({id:e,type:t,color:n,width:o=12.5,height:r=12.5,markerUnits:s="strokeWidth",strokeWidth:i,orient:a="auto-start-reverse"})=>{const c=zg(t);return c?d.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${o}`,markerHeight:`${r}`,viewBox:"-10 -10 20 20",markerUnits:s,orient:a,refX:"0",refY:"0",children:d.jsx(c,{color:n,strokeWidth:i})}):null},ac=({defaultColor:e,rfId:t})=>{const n=le(s=>s.edges),o=le(s=>s.defaultEdgeOptions),r=N.useMemo(()=>Lh(n,{id:t,defaultColor:e,defaultMarkerStart:o?.markerStart,defaultMarkerEnd:o?.markerEnd}),[n,o,t,e]);return r.length?d.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:d.jsx("defs",{children:r.map(s=>d.jsx(Lg,{id:s.id,type:s.type,color:s.color,width:s.width,height:s.height,markerUnits:s.markerUnits,strokeWidth:s.strokeWidth,orient:s.orient},s.id))})}):null};ac.displayName="MarkerDefinitions";var Bg=N.memo(ac);function cc({x:e,y:t,label:n,labelStyle:o,labelShowBg:r=!0,labelBgStyle:s,labelBgPadding:i=[2,4],labelBgBorderRadius:a=2,children:c,className:u,...l}){const[f,h]=N.useState({x:1,y:0,width:0,height:0}),p=we(["react-flow__edge-textwrapper",u]),g=N.useRef(null);return N.useEffect(()=>{if(g.current){const v=g.current.getBBox();h({x:v.x,y:v.y,width:v.width,height:v.height})}},[n]),n?d.jsxs("g",{transform:`translate(${e-f.width/2} ${t-f.height/2})`,className:p,visibility:f.width?"visible":"hidden",...l,children:[r&&d.jsx("rect",{width:f.width+2*i[0],x:-i[0],y:-i[1],height:f.height+2*i[1],className:"react-flow__edge-textbg",style:s,rx:a,ry:a}),d.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:g,style:o,children:n}),c]}):null}cc.displayName="EdgeText";const Vg=N.memo(cc);function $o({path:e,labelX:t,labelY:n,label:o,labelStyle:r,labelShowBg:s,labelBgStyle:i,labelBgPadding:a,labelBgBorderRadius:c,interactionWidth:u=20,...l}){return d.jsxs(d.Fragment,{children:[d.jsx("path",{...l,d:e,fill:"none",className:we(["react-flow__edge-path",l.className])}),u?d.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:u,className:"react-flow__edge-interaction"}):null,o&&De(t)&&De(n)?d.jsx(Vg,{x:t,y:n,label:o,labelStyle:r,labelShowBg:s,labelBgStyle:i,labelBgPadding:a,labelBgBorderRadius:c}):null]})}function si({pos:e,x1:t,y1:n,x2:o,y2:r}){return e===ne.Left||e===ne.Right?[.5*(t+o),n]:[t,.5*(n+r)]}function uc({sourceX:e,sourceY:t,sourcePosition:n=ne.Bottom,targetX:o,targetY:r,targetPosition:s=ne.Top}){const[i,a]=si({pos:n,x1:e,y1:t,x2:o,y2:r}),[c,u]=si({pos:s,x1:o,y1:r,x2:e,y2:t}),[l,f,h,p]=Ma({sourceX:e,sourceY:t,targetX:o,targetY:r,sourceControlX:i,sourceControlY:a,targetControlX:c,targetControlY:u});return[`M${e},${t} C${i},${a} ${c},${u} ${o},${r}`,l,f,h,p]}function lc(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:s,sourcePosition:i,targetPosition:a,label:c,labelStyle:u,labelShowBg:l,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:x,interactionWidth:y})=>{const[S,m,w]=uc({sourceX:n,sourceY:o,sourcePosition:i,targetX:r,targetY:s,targetPosition:a}),k=e.isInternal?void 0:t;return d.jsx($o,{id:k,path:S,labelX:m,labelY:w,label:c,labelStyle:u,labelShowBg:l,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:x,interactionWidth:y})})}const Fg=lc({isInternal:!1}),dc=lc({isInternal:!0});Fg.displayName="SimpleBezierEdge";dc.displayName="SimpleBezierEdgeInternal";function fc(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:s,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:f,style:h,sourcePosition:p=ne.Bottom,targetPosition:g=ne.Top,markerEnd:v,markerStart:x,pathOptions:y,interactionWidth:S})=>{const[m,w,k]=xr({sourceX:n,sourceY:o,sourcePosition:p,targetX:r,targetY:s,targetPosition:g,borderRadius:y?.borderRadius,offset:y?.offset,stepPosition:y?.stepPosition}),C=e.isInternal?void 0:t;return d.jsx($o,{id:C,path:m,labelX:w,labelY:k,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:f,style:h,markerEnd:v,markerStart:x,interactionWidth:S})})}const hc=fc({isInternal:!1}),pc=fc({isInternal:!0});hc.displayName="SmoothStepEdge";pc.displayName="SmoothStepEdgeInternal";function gc(e){return N.memo(({id:t,...n})=>{const o=e.isInternal?void 0:t;return d.jsx(hc,{...n,id:o,pathOptions:N.useMemo(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const Ug=gc({isInternal:!1}),mc=gc({isInternal:!0});Ug.displayName="StepEdge";mc.displayName="StepEdgeInternal";function yc(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:s,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:f,style:h,markerEnd:p,markerStart:g,interactionWidth:v})=>{const[x,y,S]=Pa({sourceX:n,sourceY:o,targetX:r,targetY:s}),m=e.isInternal?void 0:t;return d.jsx($o,{id:m,path:x,labelX:y,labelY:S,label:i,labelStyle:a,labelShowBg:c,labelBgStyle:u,labelBgPadding:l,labelBgBorderRadius:f,style:h,markerEnd:p,markerStart:g,interactionWidth:v})})}const Wg=yc({isInternal:!1}),xc=yc({isInternal:!0});Wg.displayName="StraightEdge";xc.displayName="StraightEdgeInternal";function wc(e){return N.memo(({id:t,sourceX:n,sourceY:o,targetX:r,targetY:s,sourcePosition:i=ne.Bottom,targetPosition:a=ne.Top,label:c,labelStyle:u,labelShowBg:l,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:x,pathOptions:y,interactionWidth:S})=>{const[m,w,k]=ja({sourceX:n,sourceY:o,sourcePosition:i,targetX:r,targetY:s,targetPosition:a,curvature:y?.curvature}),C=e.isInternal?void 0:t;return d.jsx($o,{id:C,path:m,labelX:w,labelY:k,label:c,labelStyle:u,labelShowBg:l,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:x,interactionWidth:S})})}const Xg=wc({isInternal:!1}),vc=wc({isInternal:!0});Xg.displayName="BezierEdge";vc.displayName="BezierEdgeInternal";const ii={default:vc,straight:xc,step:mc,smoothstep:pc,simplebezier:dc},ai={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},Yg=(e,t,n)=>
6n===ne.Left?e-t:n===ne.Right?e+t:e,Zg=(e,t,n)=>n===ne.Top?e-t:n===ne.Bottom?e+t:e,ci="react-flow__edgeupdater";function ui({position:e,centerX:t,centerY:n,radius:o=10,onMouseDown:r,onMouseEnter:s,onMouseOut:i,type:a}){return d.jsx("circle",{onMouseDown:r,onMouseEnter:s,onMouseOut:i,className:we([ci,`${ci}-${a}`]),cx:Yg(t,o,e),cy:Zg(n,o,e),r:o,stroke:"transparent",fill:"transparent"})}function Gg({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:o,sourceY:r,targetX:s,targetY:i,sourcePosition:a,targetPosition:c,onReconnect:u,onReconnectStart:l,onReconnectEnd:f,setReconnecting:h,setUpdateHover:p}){const g=pe(),v=(w,k)=>{if(w.button!==0)return;const{autoPanOnConnect:C,domNode:j,connectionMode:M,connectionRadius:A,lib:L,onConnectStart:$,cancelConnection:H,nodeLookup:D,rfId:_,panBy:E,updateConnection:b}=g.getState(),I=k.type==="target",P=(z,V)=>{h(!1),f?.(z,n,k.type,V)},T=z=>u?.(n,z),U=(z,V)=>{h(!0),l?.(w,n,k.type),$?.(z,V)};_r.onPointerDown(w.nativeEvent,{autoPanOnConnect:C,connectionMode:M,connectionRadius:A,domNode:j,handleId:k.id,nodeId:k.nodeId,nodeLookup:D,isTarget:I,edgeUpdaterType:k.type,lib:L,flowId:_,cancelConnection:H,panBy:E,isValidConnection:(...z)=>g.getState().isValidConnection?.(...z)??!0,onConnect:T,onConnectStart:U,onConnectEnd:(...z)=>g.getState().onConnectEnd?.(...z),onReconnectEnd:P,updateConnection:b,getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,dragThreshold:g.getState().connectionDragThreshold,handleDomNode:w.currentTarget})},x=w=>v(w,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),y=w=>v(w,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),S=()=>p(!0),m=()=>p(!1);return d.jsxs(d.Fragment,{children:[(e===!0||e==="source")&&d.jsx(ui,{position:a,centerX:o,centerY:r,radius:t,onMouseDown:x,onMouseEnter:S,onMouseOut:m,type:"source"}),(e===!0||e==="target")&&d.jsx(ui,{position:c,centerX:s,centerY:i,radius:t,onMouseDown:y,onMouseEnter:S,onMouseOut:m,type:"target"})]})}function Kg({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:o,onClick:r,onDoubleClick:s,onContextMenu:i,onMouseEnter:a,onMouseMove:c,onMouseLeave:u,reconnectRadius:l,onReconnect:f,onReconnectStart:h,onReconnectEnd:p,rfId:g,edgeTypes:v,noPanClassName:x,onError:y,disableKeyboardA11y:S}){let m=le(G=>G.edgeLookup.get(e));const w=le(G=>G.defaultEdgeOptions);m=w?{...w,...m}:m;let k=m.type||"default",C=v?.[k]||ii[k];C===void 0&&(y?.("011",ze.error011(k)),k="default",C=v?.default||ii.default);const j=!!(m.focusable||t&&typeof m.focusable>"u"),M=typeof f<"u"&&(m.reconnectable||n&&typeof m.reconnectable>"u"),A=!!(m.selectable||o&&typeof m.selectable>"u"),L=N.useRef(null),[$,H]=N.useState(!1),[D,_]=N.useState(!1),E=pe(),{zIndex:b=m.zIndex,sourceX:I,sourceY:P,targetX:T,targetY:U,sourcePosition:z,targetPosition:V}=le(N.useCallback(G=>{const Q=G.nodeLookup.get(m.source),re=G.nodeLookup.get(m.target);if(!Q||!re)return ai;const ae=zh({id:e,sourceNode:Q,targetNode:re,sourceHandle:m.sourceHandle||null,targetHandle:m.targetHandle||null,connectionMode:G.connectionMode,onError:y}),fe=Ph({selected:m.selected,zIndex:m.zIndex,sourceNode:Q,targetNode:re,elevateOnSelect:G.elevateEdgesOnSelect,zIndexMode:G.zIndexMode});return{...ae||ai,zIndex:fe}},[m.source,m.target,m.sourceHandle,m.targetHandle,m.selected,m.zIndex]),ge),K=N.useMemo(()=>m.markerStart?`url('#${wr(m.markerStart,g)}')`:void 0,[m.markerStart,g]),q=N.useMemo(()=>m.markerEnd?`url('#${wr(m.markerEnd,g)}')`:void 0,[m.markerEnd,g]);if(m.hidden||I===null||P===null||T===null||U===null)return null;const oe=G=>{const{addSelectedEdges:Q,unselectNodesAndEdges:re,multiSelectionActive:ae}=E.getState();A&&(E.setState({nodesSelectionActive:!1}),m.selected&&ae?(re({nodes:[],edges:[m]}),L.current?.blur()):Q([e])),r&&r(G,m)},se=s?G=>{s(G,{...m})}:void 0,te=i?G=>{i(G,{...m})}:void 0,B=a?G=>{a(G,{...m})}:void 0,O=c?G=>{c(G,{...m})}:void 0,Y=u?G=>{u(G,{...m})}:void 0,W=G=>{if(!S&&ha.includes(G.key)&&A){const{unselectNodesAndEdges:Q,addSelectedEdges:re}=E.getState();G.key==="Escape"?(L.current?.blur(),Q({edges:[m]})):re([e])}};return d.jsx("svg",{style:{zIndex:b},children:d.jsxs("g",{className:we(["react-flow__edge",`react-flow__edge-${k}`,m.className,x,{selected:m.selected,animated:m.animated,inactive:!A&&!r,updating:$,selectable:A}]),onClick:oe,onDoubleClick:se,onContextMenu:te,onMouseEnter:B,onMouseMove:O,onMouseLeave:Y,onKeyDown:j?W:void 0,tabIndex:j?0:void 0,role:m.ariaRole??(j?"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":j?`${Xa}-${g}`:void 0,ref:L,...m.domAttributes,children:[!D&&d.jsx(C,{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:I,sourceY:P,targetX:T,targetY:U,sourcePosition:z,targetPosition:V,data:m.data,style:m.style,sourceHandleId:m.sourceHandle,targetHandleId:m.targetHandle,markerStart:K,markerEnd:q,pathOptions:"pathOptions"in m?m.pathOptions:void 0,interactionWidth:m.interactionWidth}),M&&d.jsx(Gg,{edge:m,isReconnectable:M,reconnectRadius:l,onReconnect:f,onReconnectStart:h,onReconnectEnd:p,sourceX:I,sourceY:P,targetX:T,targetY:U,sourcePosition:z,targetPosition:V,setUpdateHover:H,setReconnecting:_})]})})}var qg=N.memo(Kg);const Qg=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function _c({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:o,noPanClassName:r,onReconnect:s,onEdgeContextMenu:i,onEdgeMouseEnter:a,onEdgeMouseMove:c,onEdgeMouseLeave:u,onEdgeClick:l,reconnectRadius:f,onEdgeDoubleClick:h,onReconnectStart:p,onReconnectEnd:g,disableKeyboardA11y:v}){const{edgesFocusable:x,edgesReconnectable:y,elementsSelectable:S,onError:m}=le(Qg,ge),w=Dg(t);return d.jsxs("div",{className:"react-flow__edges",children:[d.jsx(Bg,{defaultColor:e,rfId:n}),w.map(k=>
6d.jsx(qg,{id:k,edgesFocusable:x,edgesReconnectable:y,elementsSelectable:S,noPanClassName:r,onReconnect:s,onContextMenu:i,onMouseEnter:a,onMouseMove:c,onMouseLeave:u,onClick:l,reconnectRadius:f,onDoubleClick:h,onReconnectStart:p,onReconnectEnd:g,rfId:n,onError:m,edgeTypes:o,disableKeyboardA11y:v},k))]})}_c.displayName="EdgeRenderer";const Jg=N.memo(_c),li=e=>`translate(${e[0]}px,${e[1]}px) scale(${e[2]})`;function em({children:e}){const t=pe(),n=N.useRef(null),[o]=N.useState(()=>t.getState().transform);return Ja(()=>{let r=null;const s=()=>{const i=t.getState().transform;r&&i[0]===r[0]&&i[1]===r[1]&&i[2]===r[2]||(r=i,n.current&&(n.current.style.transform=li(i)))};return s(),t.subscribe(s)},[t]),d.jsx("div",{ref:n,className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:li(o)},children:e})}function tm(e){const t=Fr(),n=N.useRef(!1);N.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const nm=e=>e.panZoom?.syncViewport;function om(e){const t=le(nm),n=pe();return N.useEffect(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function rm(e){return e.connection.inProgress?{...e.connection,to:Cn(e.connection.to,e.transform)}:{...e.connection}}function sm(e){return rm}function im(e){const t=sm();return le(t,ge)}const am=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function cm({containerStyle:e,style:t,type:n,component:o}){const{nodesConnectable:r,width:s,height:i,isValid:a,inProgress:c}=le(am,ge);return!(s&&r&&c)?null:d.jsx("svg",{style:e,width:s,height:i,className:"react-flow__connectionline react-flow__container",children:d.jsx("g",{className:we(["react-flow__connection",ma(a)]),children:d.jsx(bc,{style:t,type:n,CustomComponent:o,isValid:a})})})}const bc=({style:e,type:t=ft.Bezier,CustomComponent:n,isValid:o})=>{const{inProgress:r,from:s,fromNode:i,fromHandle:a,fromPosition:c,to:u,toNode:l,toHandle:f,toPosition:h,pointer:p}=im();if(!r)return;if(n)return d.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:i,fromHandle:a,fromX:s.x,fromY:s.y,toX:u.x,toY:u.y,fromPosition:c,toPosition:h,connectionStatus:ma(o),toNode:l,toHandle:f,pointer:p});let g="";const v={sourceX:s.x,sourceY:s.y,sourcePosition:c,targetX:u.x,targetY:u.y,targetPosition:h};switch(t){case ft.Bezier:[g]=ja(v);break;case ft.SimpleBezier:[g]=uc(v);break;case ft.Step:[g]=xr({...v,borderRadius:0});break;case ft.SmoothStep:[g]=xr(v);break;default:[g]=Pa(v)}return d.jsx("path",{d:g,fill:"none",className:"react-flow__connection-path",style:e})};bc.displayName="ConnectionLine";const um={};function di(e=um){N.useRef(e),pe(),N.useEffect(()=>{},[e])}function lm(){pe(),N.useRef(!1),N.useEffect(()=>{},[])}function Sc({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:o,onEdgeClick:r,onNodeDoubleClick:s,onEdgeDoubleClick:i,onNodeMouseEnter:a,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:l,onSelectionContextMenu:f,onSelectionStart:h,onSelectionEnd:p,connectionLineType:g,connectionLineStyle:v,connectionLineComponent:x,connectionLineContainerStyle:y,selectionKeyCode:S,selectionOnDrag:m,selectionMode:w,multiSelectionKeyCode:k,panActivationKeyCode:C,zoomActivationKeyCode:j,deleteKeyCode:M,onlyRenderVisibleElements:A,elementsSelectable:L,defaultViewport:$,translateExtent:H,minZoom:D,maxZoom:_,preventScrolling:E,defaultMarkerColor:b,zoomOnScroll:I,zoomOnPinch:P,panOnScroll:T,panOnScrollSpeed:U,panOnScrollMode:z,zoomOnDoubleClick:V,panOnDrag:K,autoPanOnSelection:q,onPaneClick:oe,onPaneMouseEnter:se,onPaneMouseMove:te,onPaneMouseLeave:B,onPaneScroll:O,onPaneContextMenu:Y,paneClickDistance:W,nodeClickDistance:G,onEdgeContextMenu:Q,onEdgeMouseEnter:re,onEdgeMouseMove:ae,onEdgeMouseLeave:fe,reconnectRadius:he,onReconnect:de,onReconnectStart:je,onReconnectEnd:ve,noDragClassName:me,noWheelClassName:pt,noPanClassName:Re,disableKeyboardA11y:Ze,nodeExtent:be,rfId:_e,viewport:Ie,onViewportChange:Se,nodesDraggable:st}){return di(e),di(t),lm(),tm(n),om(Ie),d.jsx(Cg,{onPaneClick:oe,onPaneMouseEnter:se,onPaneMouseMove:te,onPaneMouseLeave:B,onPaneContextMenu:Y,onPaneScroll:O,paneClickDistance:W,deleteKeyCode:M,selectionKeyCode:S,selectionOnDrag:m,selectionMode:w,onSelectionStart:h,onSelectionEnd:p,multiSelectionKeyCode:k,panActivationKeyCode:C,zoomActivationKeyCode:j,elementsSelectable:L,zoomOnScroll:I,zoomOnPinch:P,zoomOnDoubleClick:V,panOnScroll:T,panOnScrollSpeed:U,panOnScrollMode:z,panOnDrag:K,autoPanOnSelection:q,defaultViewport:$,translateExtent:H,minZoom:D,maxZoom:_,onSelectionContextMenu:f,preventScrolling:E,noDragClassName:me,noWheelClassName:pt,noPanClassName:Re,disableKeyboardA11y:Ze,onViewportChange:Se,isControlledViewport:!!Ie,children:d.jsxs(em,{children:[d.jsx(Jg,{edgeTypes:t,onEdgeClick:r,onEdgeDoubleClick:i,onReconnect:de,onReconnectStart:je,onReconnectEnd:ve,onlyRenderVisibleElements:A,onEdgeContextMenu:Q,onEdgeMouseEnter:re,onEdgeMouseMove:ae,onEdgeMouseLeave:fe,reconnectRadius:he,defaultMarkerColor:b,noPanClassName:Re,disableKeyboardA11y:Ze,rfId:_e}),d.jsx(cm,{style:v,type:g,component:x,containerStyle:y}),d.jsx("div",{className:"react-flow__edgelabel-renderer"}),d.jsx(Tg,{nodeTypes:e,onNodeClick:o,onNodeDoubleClick:s,onNodeMouseEnter:a,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:l,nodeClickDistance:G,onlyRenderVisibleElements:A,noPanClassName:Re,noDragClassName:me,disableKeyboardA11y:Ze,nodeExtent:be,rfId:_e,nodesDraggable:st}),d.jsx("div",{className:"react-flow__viewport-portal"})]})})}Sc.displayName="GraphView";const dm=N.memo(Sc),fm=ba(),fi=({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:r,height:s,fitView:i,fitViewOptions:a,minZoom:c=.5,maxZoom:u=2,nodeOrigin:l,nodeExtent:f,zIndexMode:h="basic"}={})=>{const p=new Map,g=new Map,v=new Map,x=new Map,y=o??t??[],S=n??e??[],m=l??[0,0],w=f??mn;$a(v,x,y);const{nodesInitialized:k}=vr(S,p,g,{nodeOrigin:m,nodeExtent:w,zIndexMode:h});let C=[0,0,1];if(i&&r&&s){const j=Nn(p,{filter:$=>!!(($.width||$.initialWidth)&&($.height||$.initialHeight))}),{x:M,y:A,zoom:L}=Dr(j,r,s,c,u,a?.padding??.1);C=[M,A,L]}return{rfId:"1",width:r??0,height:s??0,transform:C,nodes:S,nodesInitialized:k,nodeLookup:p,parentLookup:g,edges:y,edgeLookup:x,connectionLookup:v,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:o!==void 0,panZoom:null,minZoom:c,maxZoom:u,translateExtent:mn,nodeExtent:w,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Xt.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:m,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGri
6d:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:i??!1,fitViewOptions:a,fitViewResolver:null,connection:{...ga},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:fm,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:pa,zIndexMode:h,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},hm=({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:r,height:s,fitView:i,fitViewOptions:a,minZoom:c,maxZoom:u,nodeOrigin:l,nodeExtent:f,zIndexMode:h})=>Mp((p,g)=>{async function v(){const{nodeLookup:x,panZoom:y,fitViewOptions:S,fitViewResolver:m,width:w,height:k,minZoom:C,maxZoom:j}=g();y&&(await Nh({nodes:x,width:w,height:k,panZoom:y,minZoom:C,maxZoom:j},S),m?.resolve(!0),p({fitViewResolver:null}))}return{...fi({nodes:e,edges:t,width:r,height:s,fitView:i,fitViewOptions:a,minZoom:c,maxZoom:u,nodeOrigin:l,nodeExtent:f,defaultNodes:n,defaultEdges:o,zIndexMode:h}),setNodes:x=>{const{nodeLookup:y,parentLookup:S,nodeOrigin:m,elevateNodesOnSelect:w,fitViewQueued:k,zIndexMode:C,nodesSelectionActive:j}=g(),{nodesInitialized:M,hasSelectedNodes:A}=vr(x,y,S,{nodeOrigin:m,nodeExtent:f,elevateNodesOnSelect:w,checkEquality:!0,zIndexMode:C}),L=j&&A;k&&M?(v(),p({nodes:x,nodesInitialized:M,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:L})):p({nodes:x,nodesInitialized:M,nodesSelectionActive:L})},setEdges:x=>{const{connectionLookup:y,edgeLookup:S}=g();$a(y,S,x),p({edges:x})},setDefaultNodesAndEdges:(x,y)=>{if(x){const{setNodes:S}=g();S(x),p({hasDefaultNodes:!0})}if(y){const{setEdges:S}=g();S(y),p({hasDefaultEdges:!0})}},updateNodeInternals:x=>{const{triggerNodeChanges:y,nodeLookup:S,parentLookup:m,domNode:w,nodeOrigin:k,nodeExtent:C,debug:j,fitViewQueued:M,zIndexMode:A}=g(),{changes:L,updatedInternals:$}=Yh(x,S,m,w,k,C,A);$&&(Fh(S,m,{nodeOrigin:k,nodeExtent:C,zIndexMode:A}),M?(v(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),L?.length>0&&(j&&console.log("React Flow: trigger node changes",L),y?.(L)))},updateNodePositions:(x,y=!1)=>{const S=[];let m=[];const{nodeLookup:w,triggerNodeChanges:k,connection:C,updateConnection:j,onNodesChangeMiddlewareMap:M}=g();for(const[A,L]of x){const $=w.get(A),H=!!($?.expandParent&&$?.parentId&&L?.position),D={id:A,type:"position",position:H?{x:Math.max(0,L.position.x),y:Math.max(0,L.position.y)}:L.position,dragging:y};if($&&C.inProgress&&C.fromNode.id===$.id){const _=Et($,C.fromHandle,ne.Left,!0);j({...C,from:_})}H&&$.parentId&&S.push({id:A,parentId:$.parentId,rect:{...L.internals.positionAbsolute,width:L.measured.width??0,height:L.measured.height??0}}),m.push(D)}if(S.length>0){const{parentLookup:A,nodeOrigin:L}=g(),$=Vr(S,w,A,L);m.push(...$)}for(const A of M.values())m=A(m);k(m)},triggerNodeChanges:x=>{const{onNodesChange:y,setNodes:S,nodes:m,hasDefaultNodes:w,debug:k}=g();if(x?.length){if(w){const C=Ga(x,m);S(C)}k&&console.log("React Flow: trigger node changes",x),y?.(x)}},triggerEdgeChanges:x=>{const{onEdgesChange:y,setEdges:S,edges:m,hasDefaultEdges:w,debug:k}=g();if(x?.length){if(w){const C=Ka(x,m);S(C)}k&&console.log("React Flow: trigger edge changes",x),y?.(x)}},addSelectedNodes:x=>{const{multiSelectionActive:y,edgeLookup:S,nodeLookup:m,triggerNodeChanges:w,triggerEdgeChanges:k}=g();if(y){const C=x.map(j=>yt(j,!0));w(C);return}w(Lt(m,new Set([...x]),!0)),k(Lt(S))},addSelectedEdges:x=>{const{multiSelectionActive:y,edgeLookup:S,nodeLookup:m,triggerNodeChanges:w,triggerEdgeChanges:k}=g();if(y){const C=x.map(j=>yt(j,!0));k(C);return}k(Lt(S,new Set([...x]))),w(Lt(m,new Set,!0))},unselectNodesAndEdges:({nodes:x,edges:y}={})=>{const{edges:S,nodes:m,nodeLookup:w,triggerNodeChanges:k,triggerEdgeChanges:C}=g(),j=x||m,M=y||S,A=[];for(const $ of j){if(!$.selected)continue;const H=w.get($.id);H&&(H.selected=!1),A.push(yt($.id,!1))}const L=[];for(const $ of M)$.selected&&L.push(yt($.id,!1));k(A),C(L)},setMinZoom:x=>
6{const{panZoom:y,maxZoom:S}=g();y?.setScaleExtent([x,S]),p({minZoom:x})},setMaxZoom:x=>{const{panZoom:y,minZoom:S}=g();y?.setScaleExtent([S,x]),p({maxZoom:x})},setTranslateExtent:x=>{g().panZoom?.setTranslateExtent(x),p({translateExtent:x})},resetSelectedElements:()=>{const{edges:x,nodes:y,triggerNodeChanges:S,triggerEdgeChanges:m,elementsSelectable:w}=g();if(!w)return;const k=y.reduce((j,M)=>M.selected?[...j,yt(M.id,!1)]:j,[]),C=x.reduce((j,M)=>M.selected?[...j,yt(M.id,!1)]:j,[]);S(k),m(C)},setNodeExtent:x=>{const{nodes:y,nodeLookup:S,parentLookup:m,nodeOrigin:w,elevateNodesOnSelect:k,nodeExtent:C,zIndexMode:j}=g();x[0][0]===C[0][0]&&x[0][1]===C[0][1]&&x[1][0]===C[1][0]&&x[1][1]===C[1][1]||(vr(y,S,m,{nodeOrigin:w,nodeExtent:x,elevateNodesOnSelect:k,checkEquality:!1,zIndexMode:j}),p({nodeExtent:x}))},panBy:x=>{const{transform:y,width:S,height:m,panZoom:w,translateExtent:k}=g();return Zh({delta:x,panZoom:w,transform:y,translateExtent:k,width:S,height:m})},setCenter:async(x,y,S)=>{const{width:m,height:w,maxZoom:k,panZoom:C}=g();if(!C)return!1;const j=typeof S?.zoom<"u"?S.zoom:k;return await C.setViewport({x:m/2-x*j,y:w/2-y*j,zoom:j},{duration:S?.duration,ease:S?.ease,interpolate:S?.interpolate}),!0},cancelConnection:()=>{p({connection:{...ga}})},updateConnection:x=>{p({connection:x})},reset:()=>p({...fi()})}},Object.is);function pm({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:o,initialWidth:r,initialHeight:s,initialMinZoom:i,initialMaxZoom:a,initialFitViewOptions:c,fitView:u,nodeOrigin:l,nodeExtent:f,zIndexMode:h,children:p}){const[g]=N.useState(()=>hm({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,width:r,height:s,fitView:u,minZoom:i,maxZoom:a,fitViewOptions:c,nodeOrigin:l,nodeExtent:f,zIndexMode:h}));return d.jsx(jp,{value:g,children:d.jsx(Qp,{children:d.jsx(hg,{children:p})})})}function gm({children:e,nodes:t,edges:n,defaultNodes:o,defaultEdges:r,width:s,height:i,fitView:a,fitViewOptions:c,minZoom:u,maxZoom:l,nodeOrigin:f,nodeExtent:h,zIndexMode:p}){return N.useContext(Po)?d.jsx(d.Fragment,{children:e}):d.jsx(pm,{initialNodes:t,initialEdges:n,defaultNodes:o,defaultEdges:r,initialWidth:s,initialHeight:i,fitView:a,initialFitViewOptions:c,initialMinZoom:u,initialMaxZoom:l,nodeOrigin:f,nodeExtent:h,zIndexMode:p,children:e})}const mm={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function ym({nodes:e,edges:t,defaultNodes:n,defaultEdges:o,className:r,nodeTypes:s,edgeTypes:i,onNodeClick:a,onEdgeClick:c,onInit:u,onMove:l,onMoveStart:f,onMoveEnd:h,onConnect:p,onConnectStart:g,onConnectEnd:v,onClickConnectStart:x,onClickConnectEnd:y,onNodeMouseEnter:S,onNodeMouseMove:m,onNodeMouseLeave:w,onNodeContextMenu:k,onNodeDoubleClick:C,onNodeDragStart:j,onNodeDrag:M,onNodeDragStop:A,onNodesDelete:L,onEdgesDelete:$,onDelete:H,onSelectionChange:D,onSelectionDragStart:_,onSelectionDrag:E,onSelectionDragStop:b,onSelectionContextMenu:I,onSelectionStart:P,onSelectionEnd:T,onBeforeDelete:U,connectionMode:z,connectionLineType:V=ft.Bezier,connectionLineStyle:K,connectionLineComponent:q,connectionLineContainerStyle:oe,deleteKeyCode:se="Backspace",selectionKeyCode:te="Shift",selectionOnDrag:B=!1,selectionMode:O=yn.Full,panActivationKeyCode:Y="Space",multiSelectionKeyCode:W=wn()?"Meta":"Control",zoomActivationKeyCode:G=wn()?"Meta":"Control",snapToGrid:Q,snapGrid:re,onlyRenderVisibleElements:ae=!1,selectNodesOnDrag:fe,nodesDraggable:he,autoPanOnNodeFocus:de,nodesConnectable:je,nodesFocusable:ve,nodeOrigin:me=Ya,edgesFocusable:pt,edgesReconnectable:Re,elementsSelectable:Ze=!0,defaultViewport:be=Vp,minZoom:_e=.5,maxZoom:Ie=2,translateExtent:Se=mn,preventScrolling:st=!0,nodeExtent:Mn,defaultMarkerColor:Mt="#b1b1b7",zoomOnScroll:jt=!0,zoomOnPinch:jn=!0,panOnScroll:Ce=!1,panOnScrollSpeed:Ge=.5,panOnScrollMode:Ke=vt.Free,zoomOnDoubleClick:It=!0,panOnDrag:qe=!0,onPaneClick:Qe,onPaneMouseEnter:In,onPaneMouseMove:Pn,onPaneMouseLeave:Rn,onPaneScroll:it,onPaneContextMenu:An,paneClickDistance:Pt=1,nodeClickDistance:Rt=0,children:At,onReconnect:$t,onReconnectStart:Jt,onReconnectEnd:$n,onEdgeContextMenu:Tt,onEdgeDoubleClick:Dt,onEdgeMouseEnter:Do,onEdgeMouseMove:Oo,onEdgeMouseLeave:Ho,reconnectRadius:zo=10,onNodesChange:Tn,onEdgesChange:Dn,noDragClassName:On="nodrag",noWheelClassName:Hn="nowheel",noPanClassName:gt="nopan",fitView:R,fitViewOptions:F,connectOnClick:Z,attributionPosition:X,proOptions:ee,defaultEdgeOptions:J,elevateNodesOnSelect:ue=!0,elevateEdgesOnSelect:ce=!1,disableKeyboardA11y:ie=!1,autoPanOnConnect:Ne,autoPanOnNodeDrag:Je,autoPanOnSelection:mt=!0,autoPanSpeed:Lo,connectionRadius:en,isValidConnection:at,onError:Gc,style:Kc,id:
6Qr,nodeDragThreshold:qc,connectionDragThreshold:Qc,viewport:Jc,onViewportChange:eu,width:tu,height:nu,colorMode:ou="light",debug:ru,onScroll:Jr,ariaLabelConfig:su,zIndexMode:es="basic",...iu},au){const Bo=Qr||"1",cu=Xp(ou),uu=N.useCallback(ts=>{ts.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),Jr?.(ts)},[Jr]);return d.jsx("div",{"data-testid":"rf__wrapper",...iu,onScroll:uu,style:{...Kc,...mm},ref:au,className:we(["react-flow",r,cu]),id:Qr,role:"application",children:d.jsxs(gm,{nodes:e,edges:t,width:tu,height:nu,fitView:R,fitViewOptions:F,minZoom:_e,maxZoom:Ie,nodeOrigin:me,nodeExtent:Mn,zIndexMode:es,children:[d.jsx(Wp,{nodes:e,edges:t,defaultNodes:n,defaultEdges:o,onConnect:p,onConnectStart:g,onConnectEnd:v,onClickConnectStart:x,onClickConnectEnd:y,nodesDraggable:he,autoPanOnNodeFocus:de,nodesConnectable:je,nodesFocusable:ve,edgesFocusable:pt,edgesReconnectable:Re,elementsSelectable:Ze,elevateNodesOnSelect:ue,elevateEdgesOnSelect:ce,minZoom:_e,maxZoom:Ie,nodeExtent:Mn,onNodesChange:Tn,onEdgesChange:Dn,snapToGrid:Q,snapGrid:re,connectionMode:z,translateExtent:Se,connectOnClick:Z,defaultEdgeOptions:J,fitView:R,fitViewOptions:F,onNodesDelete:L,onEdgesDelete:$,onDelete:H,onNodeDragStart:j,onNodeDrag:M,onNodeDragStop:A,onSelectionDrag:E,onSelectionDragStart:_,onSelectionDragStop:b,onMove:l,onMoveStart:f,onMoveEnd:h,noPanClassName:gt,nodeOrigin:me,rfId:Bo,autoPanOnConnect:Ne,autoPanOnNodeDrag:Je,autoPanSpeed:Lo,onError:Gc,connectionRadius:en,isValidConnection:at,selectNodesOnDrag:fe,nodeDragThreshold:qc,connectionDragThreshold:Qc,onBeforeDelete:U,debug:ru,ariaLabelConfig:su,zIndexMode:es}),d.jsx(dm,{onInit:u,onNodeClick:a,onEdgeClick:c,onNodeMouseEnter:S,onNodeMouseMove:m,onNodeMouseLeave:w,onNodeContextMenu:k,onNodeDoubleClick:C,nodeTypes:s,edgeTypes:i,connectionLineType:V,connectionLineStyle:K,connectionLineComponent:q,connectionLineContainerStyle:oe,selectionKeyCode:te,selectionOnDrag:B,selectionMode:O,deleteKeyCode:se,multiSelectionKeyCode:W,panActivationKeyCode:Y,zoomActivationKeyCode:G,onlyRenderVisibleElements:ae,defaultViewport:be,translateExtent:Se,minZoom:_e,maxZoom:Ie,preventScrolling:st,zoomOnScroll:jt,zoomOnPinch:jn,zoomOnDoubleClick:It,panOnScroll:Ce,panOnScrollSpeed:Ge,panOnScrollMode:Ke,panOnDrag:qe,autoPanOnSelection:mt,onPaneClick:Qe,onPaneMouseEnter:In,onPaneMouseMove:Pn,onPaneMouseLeave:Rn,onPaneScroll:it,onPaneContextMenu:An,paneClickDistance:Pt,nodeClickDistance:Rt,onSelectionContextMenu:I,onSelectionStart:P,onSelectionEnd:T,onReconnect:$t,onReconnectStart:Jt,onReconnectEnd:$n,onEdgeContextMenu:Tt,onEdgeDoubleClick:Dt,onEdgeMouseEnter:Do,onEdgeMouseMove:Oo,onEdgeMouseLeave:Ho,reconnectRadius:zo,defaultMarkerColor:Mt,noDragClassName:On,noWheelClassName:Hn,noPanClassName:gt,rfId:Bo,disableKeyboardA11y:ie,nodeExtent:Mn,viewport:Jc,onViewportChange:eu,nodesDraggable:he}),d.jsx(Bp,{onSelectionChange:D}),At,d.jsx(Dp,{proOptions:ee,position:X}),d.jsx(Tp,{rfId:Bo,disableKeyboardA11y:ie})]})})}var xm=Qa(ym);function wm(){const e=pe();return N.useCallback(t=>{const{domNode:n,updateNodeInternals:o}=e.getState(),r=Array.isArray(t)?t:[t],s=new Map;r.forEach(i=>{const a=n?.querySelector(`.react-flow__node[data-id="${i}"]`);a&&s.set(i,{id:i,nodeElement:a,force:!0})}),requestAnimationFrame(()=>o(s,{triggerFitView:!1}))},[])}function vm(e){const[t,n]=N.useState(e),o=N.useCallback(r=>n(s=>Ga(r,s)),[]);return[t,n,o]}function _m(e){const[t,n]=N.useState(e),o=N.useCallback(r=>n(s=>Ka(r,s)),[]);return[t,n,o]}function bm({dimensions:e,lineWidth:t,variant:n,className:o}){return d.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:we(["react-flow__background-pattern",n,o])})}function Sm({radius:e,className:t}){return d.jsx("circle",{cx:e,cy:e,r:e,className:we(["react-flow__background-pattern","dots",t])})}var ht;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(ht||(ht={}));const Nm={[ht.Dots]:1,[ht.Lines]:1,[ht.Cross]:6},Em=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Nc({id:e,variant:t=ht.Dots,gap:n=20,size:o,lineWidth:r=1,offset:s=0,color:i,bgColor:a,style:c,className:u,patternClassName:l}){const f=N.useRef(null),{transform:h,patternId:p}=le(Em,ge),g=o||Nm[t],v=t===ht.Dots,x=t===ht.Cross,y=Array.isArray(n)?n:[n,n],S=[y[0]*h[2]||1,y[1]*h[2]||1],m=g*h[2],w=Array.isArray(s)?s:[s,s],k=x?[m,m]:S,C=[w[0]*h[2]||1+k[0]/2,w[1]*h[2]||1+k[1]/2],j=`${p}${e||""}`;return d.jsxs("svg",{className:we(["react-flow__background",u]),style:{...c,...Ao,"--xy-background-color-props":a,"--xy-background-pattern-color-props":i},ref:f,"data-testid":"rf__background",children:[d.jsx("pattern",{id:j,x:h[0]%S[0],y:h[1]%S[1],width:S[0],height:S[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${C[0]},-${C[1]})`,children:v?d.jsx(Sm,{radius:m/2,className:l}):d.jsx(bm,{dimensions:k,lineWidth:r,variant:t,className:l})}),d.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${j})`})]})}
6Nc.displayName="Background";const Cm=N.memo(Nc);function km(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:d.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function Mm(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:d.jsx("path",{d:"M0 0h32v4.2H0z"})})}function jm(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:d.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 Im(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:d.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 Pm(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:d.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 Kn({children:e,className:t,...n}){return d.jsx("button",{type:"button",className:we(["react-flow__controls-button",t]),...n,children:e})}const Rm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Ec({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:o=!0,fitViewOptions:r,onZoomIn:s,onZoomOut:i,onFitView:a,onInteractiveChange:c,className:u,children:l,position:f="bottom-left",orientation:h="vertical","aria-label":p}){const g=pe(),{isInteractive:v,minZoomReached:x,maxZoomReached:y,ariaLabelConfig:S}=le(Rm,ge),{zoomIn:m,zoomOut:w,fitView:k}=Fr(),C=()=>{m(),s?.()},j=()=>{w(),i?.()},M=()=>{k(r),a?.()},A=()=>{g.setState({nodesDraggable:!v,nodesConnectable:!v,elementsSelectable:!v}),c?.(!v)},L=h==="horizontal"?"horizontal":"vertical";return d.jsxs(Ro,{className:we(["react-flow__controls",L,u]),position:f,style:e,"data-testid":"rf__controls","aria-label":p??S["controls.ariaLabel"],children:[t&&d.jsxs(d.Fragment,{children:[d.jsx(Kn,{onClick:C,className:"react-flow__controls-zoomin",title:S["controls.zoomIn.ariaLabel"],"aria-label":S["controls.zoomIn.ariaLabel"],disabled:y,children:d.jsx(km,{})}),d.jsx(Kn,{onClick:j,className:"react-flow__controls-zoomout",title:S["controls.zoomOut.ariaLabel"],"aria-label":S["controls.zoomOut.ariaLabel"],disabled:x,children:d.jsx(Mm,{})})]}),n&&d.jsx(Kn,{className:"react-flow__controls-fitview",onClick:M,title:S["controls.fitView.ariaLabel"],"aria-label":S["controls.fitView.ariaLabel"],children:d.jsx(jm,{})}),o&&d.jsx(Kn,{className:"react-flow__controls-interactive",onClick:A,title:S["controls.interactive.ariaLabel"],"aria-label":S["controls.interactive.ariaLabel"],children:v?d.jsx(Pm,{}):d.jsx(Im,{})}),l]})}Ec.displayName="Controls";const Am=N.memo(Ec);function $m({id:e,x:t,y:n,width:o,height:r,style:s,color:i,strokeColor:a,strokeWidth:c,className:u,borderRadius:l,shapeRendering:f,selected:h,onClick:p}){const{background:g,backgroundColor:v}=s||{},x=i||g||v;return d.jsx("rect",{className:we(["react-flow__minimap-node",{selected:h},u]),x:t,y:n,rx:l,ry:l,width:o,height:r,style:{fill:x,stroke:a,strokeWidth:c},shapeRendering:f,onClick:p?y=>p(y,e):void 0})}const Tm=N.memo($m),Dm=e=>e.nodes.map(t=>
6t.id),nr=e=>e instanceof Function?e:()=>e;function Om({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:o=5,nodeStrokeWidth:r,nodeComponent:s=Tm,onClick:i}){const a=le(Dm,ge),c=nr(t),u=nr(e),l=nr(n),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return d.jsx(d.Fragment,{children:a.map(h=>d.jsx(zm,{id:h,nodeColorFunc:c,nodeStrokeColorFunc:u,nodeClassNameFunc:l,nodeBorderRadius:o,nodeStrokeWidth:r,NodeComponent:s,onClick:i,shapeRendering:f},h))})}function Hm({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:o,nodeBorderRadius:r,nodeStrokeWidth:s,shapeRendering:i,NodeComponent:a,onClick:c}){const{node:u,x:l,y:f,width:h,height:p}=le(g=>{const v=g.nodeLookup.get(e);if(!v)return{node:void 0,x:0,y:0,width:0,height:0};const x=v.internals.userNode,{x:y,y:S}=v.internals.positionAbsolute,{width:m,height:w}=Ye(x);return{node:x,x:y,y:S,width:m,height:w}},ge);return!u||u.hidden||!Sa(u)?null:d.jsx(a,{x:l,y:f,width:h,height:p,style:u.style,selected:!!u.selected,className:o(u),color:t(u),borderRadius:r,strokeColor:n(u),strokeWidth:s,shapeRendering:i,onClick:c,id:u.id})}const zm=N.memo(Hm);var Lm=N.memo(Om);const Bm=200,Vm=150,Fm=e=>!e.hidden,Um=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]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?va(Nn(e.nodeLookup,{filter:Fm}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},hi=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,Wm=(e,t)=>hi(e.viewBB,t.viewBB)&&hi(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,Xm="react-flow__minimap-desc";function Cc({style:e,className:t,nodeStrokeColor:n,nodeColor:o,nodeClassName:r="",nodeBorderRadius:s=5,nodeStrokeWidth:i,nodeComponent:a,bgColor:c,maskColor:u,maskStrokeColor:l,maskStrokeWidth:f,position:h="bottom-right",onClick:p,onNodeClick:g,pannable:v=!1,zoomable:x=!1,ariaLabel:y,inversePan:S,zoomStep:m=1,offsetScale:w=5}){const k=pe(),C=N.useRef(null),{boundingRect:j,viewBB:M,rfId:A,panZoom:L,translateExtent:$,flowWidth:H,flowHeight:D,ariaLabelConfig:_}=le(Um,Wm),E=e?.width??Bm,b=e?.height??Vm,I=j.width/E,P=j.height/b,T=Math.max(I,P),U=T*E,z=T*b,V=w*T,K=j.x-(U-j.width)/2-V,q=j.y-(z-j.height)/2-V,oe=U+V*2,se=z+V*2,te=`${Xm}-${A}`,B=N.useRef(0),O=N.useRef();B.current=T,N.useEffect(()=>{if(C.current&&L)return O.current=op({domNode:C.current,panZoom:L,getTransform:()=>k.getState().transform,getViewScale:()=>B.current}),()=>{O.current?.destroy()}},[L]),N.useEffect(()=>{O.current?.update({translateExtent:$,width:H,height:D,inversePan:S,pannable:v,zoomStep:m,zoomable:
6x})},[v,x,S,m,$,H,D]);const Y=p?Q=>{const[re,ae]=O.current?.pointer(Q)||[0,0];p(Q,{x:re,y:ae})}:void 0,W=g?N.useCallback((Q,re)=>{const ae=k.getState().nodeLookup.get(re).internals.userNode;g(Q,ae)},[]):void 0,G=y??_["minimap.ariaLabel"];return d.jsx(Ro,{position:h,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-stroke-color-props":typeof l=="string"?l:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*T: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 i=="number"?i:void 0},className:we(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:d.jsxs("svg",{width:E,height:b,viewBox:`${K} ${q} ${oe} ${se}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":te,ref:C,onClick:Y,children:[G&&d.jsx("title",{id:te,children:G}),d.jsx(Lm,{onClick:W,nodeColor:o,nodeStrokeColor:n,nodeBorderRadius:s,nodeClassName:r,nodeStrokeWidth:i,nodeComponent:a}),d.jsx("path",{className:"react-flow__minimap-mask",d:`M${K-V},${q-V}h${oe+V*2}v${se+V*2}h${-oe-V*2}z 7 M${M.x},${M.y}h${M.width}v${M.height}h${-M.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}Cc.displayName="MiniMap";const Ym=N.memo(Cc),Zm=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,Gm={[Gt.Line]:"right",[Gt.Handle]:"bottom-right"};function Km({nodeId:e,position:t,variant:n=Gt.Handle,className:o,style:r=void 0,children:s,color:i,minWidth:a=10,minHeight:c=10,maxWidth:u=Number.MAX_VALUE,maxHeight:l=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:h,autoScale:p=!0,shouldResize:g,onResizeStart:v,onResize:x,onResizeEnd:y}){const S=oc(),m=typeof e=="string"?e:S,w=pe(),k=N.useRef(null),C=n===Gt.Handle,j=le(N.useCallback(Zm(C&&p),[C,p]),ge),M=N.useRef(null),A=t??Gm[n];N.useEffect(()=>{if(!(!k.current||!m))return M.current||(M.current=mp({domNode:k.current,nodeId:m,getStoreItems:()=>{const{nodeLookup:$,transform:H,snapGrid:D,snapToGrid:_,nodeOrigin:E,domNode:b}
7=w.getState();return{nodeLookup:$,transform:H,snapGrid:D,snapToGrid:_,nodeOrigin:E,paneDomNode:b}},onChange:($,H)=>{const{triggerNodeChanges:D,nodeLookup:_,parentLookup:E,nodeOrigin:b}=w.getState(),I=[],P={x:$.x,y:$.y},T=_.get(m);if(T&&T.expandParent&&T.parentId){const U=T.origin??b,z=$.width??T.measured.width??0,V=$.height??T.measured.height??0,K={id:T.id,parentId:T.parentId,rect:{width:z,height:V,...Na({x:$.x??T.position.x,y:$.y??T.position.y},{width:z,height:V},T.parentId,_,U)}},q=Vr([K],_,E,b);I.push(...q),P.x=$.x?Math.max(U[0]*z,$.x):void 0,P.y=$.y?Math.max(U[1]*V,$.y):void 0}if(P.x!==void 0&&P.y!==void 0){const U={id:m,type:"position",position:{...P}};I.push(U)}if($.width!==void 0&&$.height!==void 0){const z={id:m,type:"dimensions",resizing:!0,setAttributes:h?h==="horizontal"?"width":"height":!0,dimensions:{width:$.width,height:$.height}};I.push(z)}for(const U of H){const z={...U,type:"position"};I.push(z)}D(I)},onEnd:({width:$,height:H})=>{const D={id:m,type:"dimensions",resizing:!1,dimensions:{width:$,height:H}};w.getState().triggerNodeChanges([D])}})),M.current.update({controlPosition:A,boundaries:{minWidth:a,minHeight:c,maxWidth:u,maxHeight:l},keepAspectRatio:f,resizeDirection:h,onResizeStart:v,onResize:x,onResizeEnd:y,shouldResize:g}),()=>{M.current?.destroy()}},[A,a,c,u,l,f,v,x,y,g]);const L=A.split("-");return d.jsx("div",{className:we(["react-flow__resize-control","nodrag",...L,n,o]),ref:k,style:{...r,scale:j,...i&&{[C?"backgroundColor":"borderColor"]:i}},children:s})}N.memo(Km);const qm=e=>rt("/surface/catalog",e),Qm=e=>rt("/surface/templates",e),Jm=e=>rt("/surface/workflows",e),e0=(e,t)=>rt("/surface/workflows",t,{body:e}),t0=(e,t,n)=>rt(`/surface/workflows/${e}`,n,{method:"PATCH",body:t}),n0=(e,t)=>rt("/surface/validate",t,{body:e}),o0=(e,t)=>rt("/surface/estimate",t,{body:e}),r0=(e,t)=>rt("/surface/submit",t,{body:e}),s0=(e,t,n)=>rt(`/surface/runs/${e}/rerun-node`,n,{body:t});function i0(e,t=null){const n=String(e||"").toUpperCase();return n?n==="AWAITING_PHASE_REVIEW"||n==="AWAITING_PREVIEW_SELECTION"?"Waiting":n==="SUCCESS"?"Done":["FAILED","FAILURE","ERROR"].includes(n)?"Didnât finish":n==="CANCEL_REQUESTED"?"Cancelling":t&&Hu({...t,status:n})?"Carrying on":["CANCELLED","CANCELED"].includes(n)?"Cancelled":["QUEUED","PENDING","HELD"].includes(n)?"Waiting to start":"Running":"Loading"}function kc({tabs:e,activeTabId:t,onActivate:n,onClose:o}){return d.jsx("div",{className:"surface-tabs",role:"tablist","aria-label":"Workflow runs",children:e.map(r=>d.jsxs("div",{className:`surface-tab${r.id===t?" active":""}`,children:[d.jsxs("button",{type:"button",role:"tab","aria-selected":r.id===t,onClick:()=>n(r.id),children:[d.jsx("span",{className:"surface-tab-label",children:r.label}),r.kind==="run"&&d.jsxs(d.Fragment,{children:[" ",d.jsx("span",{className:"surface-tab-state",children:r.loadFailed&&!r.status?"Didnât load":i0(r.status,{job_id:r.runId,waiting_since:r.waitingSince,result:r.result})})]})]}),r.kind==="run"&&d.jsx(dn,{icon:"close",label:`Close ${r.label}`,size:"compact",className:"surface-tab-close",onClick:()=>o(r.id)})]},r.id))})}function a0(e,t){const n=e.map(c=>c.id),o=new Map(n.map(c=>[c,0])),r=new Map(n.map(c=>[c,[]]));t.forEach(c=>{!o.has(c.source)||!o.has(c.target)||(o.set(c.target,o.get(c.target)+1),r.get(c.source).push(c.target))});const s=n.filter(c=>o.get(c)===0),i=[];for(;s.length>0;){const c=s.shift();
7i.push(c),r.get(c).forEach(u=>{o.set(u,o.get(u)-1),o.get(u)===0&&s.push(u)})}n.forEach(c=>{i.includes(c)||i.push(c)});const a=new Map(e.map(c=>[c.id,c]));return i.map(c=>a.get(c))}function c0({row:e}){const t=[...e.rerun?[{id:"rerun",label:`Rerun ${e.id}`,onSelect:e.rerun.onRerun,disabled:e.rerun.busy},{id:"rerun-after",label:`Rerun ${e.id} and downstream`,onSelect:e.rerun.onRerunAfter,disabled:e.rerun.busy}]:[],...e.downloads.map(o=>({id:`download-${o.label}`,label:`Download ${o.label}`,disabled:!o.url,onSelect:()=>window.open(o.url,"_blank","noopener")}))];if(t.length===0)return null;const n=`More actions for ${e.label}`;return d.jsx(Di,{label:n,items:t,trigger:o=>d.jsx(dn,{...o,icon:"more",label:n,size:"phone"})})}function u0({workflowName:e,onWorkflowNameChange:t,templates:n=[],workflows:o=[],onChooseTemplate:r,onChooseWorkflow:s,onSave:i,tabs:a,activeTabId:c,onActivateTab:u,onCloseTab:l,rows:f,statusText:h,errors:p=[],notice:g=null,phasedGeneration:v,onPhasedGenerationChange:x,onValidate:y,onEstimate:S,onRun:m}){const[w,k]=N.useState(null),C=w?.rowId?f.find(M=>M.id===w.rowId):null,j=(M,A)=>{M(A),k(null)};return d.jsxs("div",{className:"surface-phone",children:[d.jsxs("div",{className:"surface-phone__head",children:[d.jsx(Du,{label:"Workflow",value:e,onChange:M=>t(M.target.value),size:"phone"}),d.jsxs("div",{className:"surface-phone__head-actions",children:[d.jsx($e,{size:"phone",icon:"templates",onClick:()=>k("templates"),children:"Templates"}),d.jsx($e,{size:"phone",onClick:i,children:"Save"})]})]}),d.jsx(kc,{tabs:a,activeTabId:c,onActivate:u,onClose:l}),p.length>0&&d.jsx("ul",{className:"surface-phone__errors",role:"alert",children:p.map(M=>d.jsx("li",{children:M},M))}),g&&d.jsx("p",{className:"surface-phone__errors",role:"alert",children:g}),d.jsx("p",{className:"surface-phone__note",children:"Adding nodes and connecting them needs a larger screen."}),d.jsx("h2",{className:"surface-phone__nodes-title",children:"Nodes"}),d.jsx("ol",{className:"surface-phone__nodes","aria-label":"Workflow nodes",children:f.map(M=>d.jsxs("li",{className:`surface-phone__node${M.review?" is-waiting":""}`,children:[d.jsxs("div",{className:"surface-phone__row",children:[d.jsx("div",{className:"surface-phone__still","aria-hidden":"true",children:M.thumbnailUrl&&d.jsx("img",{src:M.thumbnailUrl,alt:""})}),d.jsxs("div",{className:"surface-phone__text",children:[d.jsx("h3",{className:"surface-phone__name",children:M.settings?d.jsx("button",{type:"button","aria-label":`${M.label} settings`,onClick:()=>k({rowId:M.id}),children:M.label}):M.label}),d.jsx("p",{className:"surface-phone__meta",children:M.waiting?"Waiting for your review":`${M.id}${M.meta?`, ${M.meta}`:""}`})]}),d.jsx(c0,{row:M})]}),M.review&&d.jsx("div",{className:"surface-phone__review",children:M.review})]},M.id))}),d.jsxs("div",{className:"surface-phone__bar",children:[h&&d.jsx("p",{className:"surface-phone__status","aria-live":"polite",children:h}),d.jsxs("div",{className:"surface-phone__bar-actions",children:[d.jsx(Di,{label:"More actions for the workflow",items:[{id:"validate",label:"Validate",onSelect:y},{id:"options",label:"Options",onSelect:()=>k("options")}],trigger:M=>d.jsx(dn,{...M,icon:"more",label:"More actions for the workflow",size:"phone"})}),d.jsx($e,{size:"phone",onClick:S,children:"Estimate"}),d.jsx($e,{variant:"primary",size:"phone",icon:"play",fullWidth:!0,onClick:m,children:"Run"})]})]}),w==="templates"&&d.jsxs(Vo,{title:"Templates",onClose:()=>k(null),sheet:!0,children:[d.jsx("ul",{className:"surface-phone__choices",children:n.map(M=>d.jsx("li",{children:d.jsx($e,{fullWidth:!0,size:"phone",onClick:()=>j(r,M),children:M.label})},M.id))}),o.length>0&&d.jsxs(d.Fragment,{children:[d.jsx("h3",{className:"surface-phone__choices-title",children:"Saved"}),d.jsx("ul",{className:"surface-phone__choices",children:o.slice(0,8).map(M=>d.jsx("li",{children:d.jsx($e,{fullWidth:!0,size:"phone",onClick:()=>j(s,M),children:M.name})},M.id))})]})]}),w==="options"&&d.jsx(Vo,{title:"Options",onClose:()=>k(null),sheet:!0,children:d.jsx(Ou,{label:"Phased Generation",checked:!!v,onChange:x,size:"phone"})}),C&&d.jsx(Vo,{title:C.label,onClose:()=>k(null),size:"full",className:"surface-phone__sheet",sheet:!0,children:C.settings})]})}const bo=24;function ye(e,t){const n=Number(e);return Number.isFinite(n)?n:t}function Mc({className:e="",label:t="Video preview"}){return d.jsx("div",{className:`surface-media-placeholder ${e}`.trim(),"aria-label":t,children:d.jsx("span",{className:"surface-video-glyph","aria-hidden":"true"})})}function Wr({sourceVideo:e,preprocessParams:t,value:n,onChange:o,sourceUrl:r="",coverUrl:s="",maskUrl:i="",maskIsColour:a=!1,fallbackFrameCount:c=null}){const u=N.useRef(null),l=N.useRef(null),f=N.useRef(null),[h,p]=N.useState(0),[g,v]=N.useState(null),[x,y]=N.useState(zn),[S,m]=N.useState([zn]),w=Ti(),[k,C]=N.useState("include"),j=ye(e?.fps,bo)||bo,M=Math.max(1,ye(e?.frame_count,ye(t?.frames,c||1))),A=Math.max(0,M-1),L=Array.isArray(n)?n:[],$=Array.from(new Set([...S,...Mu(L,x)])).sort((O,Y)=>O-Y).slice(0,os),H=ju(L,x),D=r||e?.source_video_url||"",_=s||e?.cover_image_url||"",E=Math.max(-1,Math.min(1,t?.crop_offset_x||0)),b=Math.max(-1,Math.min(1,t?.crop_offset_y||0)),I=`${50+E*50}% ${50+b*50}%`;N.useEffect(()=>{$.includes(x)||y($[0]||zn)},[x,$]);const P=O=>{[u.current,l.current].forEach(Y=>{Y&&Number.isFinite(Y.duration)&&(Y.currentTime=Math.min(Y.duration||0,O))})},T=O=>{const Y=Math.max(0,Math.min(A,Number(O)||0));p(Y),P(Y/j)};N.useEffect(()=>{const O=L.find(W=>W.label==="include");if(!O)return;const Y=`${O.frame||0}:${O.x}:${O.y}`;f.current!==Y&&(f.current=Y,T(O.frame||0))},[L]);const U=O=>
7{if(!D&&!_)return;O.preventDefault();const Y=O.currentTarget.getBoundingClientRect();if(!Y.width||!Y.height)return;const W=Math.max(0,Math.min(1,(O.clientX-Y.left)/Y.width)),G=Math.max(0,Math.min(1,(O.clientY-Y.top)/Y.height)),Q=O.button===2?"exclude":k;o([...L,{frame:h,x:W,y:G,label:Q,object_id:Bn(x)}])},z=(O,Y)=>{O.button===0&&(O.preventDefault(),O.stopPropagation(),o(L.filter((W,G)=>G!==Y)),v(null))},V=L.map((O,Y)=>({...O,index:Y,objectId:tn(O)})).filter(O=>Math.abs((O.frame||0)-h)<=0),K=$.length<os&&rs(L,$)!==null,q=$.length<=1&&H.total===0,oe=()=>{const O=rs(L,$);O!==null&&(m(Y=>Array.from(new Set([...Y,O])).sort((W,G)=>W-G)),y(O))},se=()=>{if(q)return;const O=Bn(x),Y=L.filter(re=>tn(re)!==O),W=Array.from(new Set(Y.map(tn))).sort((re,ae)=>re-ae),G=$.filter(re=>re!==O),Q=W[0]||G[0]||zn;o(Y),m(G.length?G:[Q]),y(Q)},te=()=>{const O=Bn(x),Y=L.map(tn).lastIndexOf(O);if(Y<0)return;const W=L.slice();W.splice(Y,1),o(W)},B=()=>{const O=Bn(x);o(L.filter(Y=>tn(Y)!==O))};return d.jsxs("div",{className:"surface-point-mask",children:[w&&d.jsx(zu,{label:"Point type",options:[{value:"include",label:"Include"},{value:"exclude",label:"Exclude"}],value:k,onChange:C,size:"phone"}),d.jsxs("div",{className:"surface-point-mask-stage","data-testid":"surface-point-stage",onMouseDown:U,onContextMenu:O=>O.preventDefault(),children:[D?d.jsx("video",{ref:u,className:"surface-point-mask-video",style:{objectPosition:I},src:D,muted:!0,playsInline:!0,preload:"metadata",onLoadedMetadata:()=>T(h)}):_?d.jsx("img",{className:"surface-point-mask-video",style:{objectPosition:I},src:_,alt:""}):d.jsx(Mc,{className:"surface-point-mask-placeholder",label:"Point input"}),i&&d.jsx("video",{ref:l,className:`surface-point-mask-video surface-point-mask-overlay${a?" is-colour-mask":""}`,src:i,muted:!0,playsInline:!0,preload:"metadata",onLoadedMetadata:()=>P(h/j)}),V.map((O,Y)=>d.jsx("button",{type:"button",className:`surface-point ${O.label==="exclude"?"exclude":"include"} ${O.objectId===x?"active-object":"inactive-object"} ${g===O.index?"removing":""}`,style:{left:`${O.x*100}%`,top:`${O.y*100}%`,...Fo(O.objectId)},onMouseEnter:()=>v(O.index),onMouseLeave:()=>v(null),onMouseDown:W=>z(W,O.index),title:`Remove ${O.label} point from ${Ln(O.objectId)}`,"aria-label":`Remove ${O.label} point from ${Ln(O.objectId)}`},`${O.index}-${O.frame}-${Y}-${O.x}-${O.y}`))]}),d.jsxs("div",{className:"surface-point-frame",children:[d.jsx("input",{type:"range",min:"0",max:A,step:"1",value:Math.min(h,A),onChange:O=>T(parseInt(O.target.value,10)),disabled:!D&&!_||A<=0,"aria-label":"Mask point frame"}),d.jsxs("span",{children:[Math.min(h,A)+1," / ",A+1]})]}),d.jsxs("div",{className:"surface-point-objects",role:"group","aria-label":"Mask objects",children:[$.map(O=>d.jsx("button",{type:"button",className:`sam2-object-chip${O===x?" active":""}`,style:Fo(O),onClick:()=>y(O),"aria-pressed":O===x,children:Ln(O)},O)),d.jsxs("button",{type:"button",onClick:oe,disabled:!K,"aria-label":"New Object",children:[d.jsx(He,{name:"plus",size:16}),"New"]}),d.jsx("button",{type:"button",className:"surface-point-remove",onClick:se,disabled:q,"aria-label":`Remove ${Ln(x)}`,children:d.jsx(He,{name:"minus",size:16})})]}),d.jsxs("div",{className:"surface-point-counts",style:Fo(x),children:[d.jsxs("span",{children:[H.include," include"]}),d.jsxs("span",{children:[H.exclude," exclude"]}),H.total>0&&d.jsx("button",{type:"button",onClick:te,children:"Undo"}),H.total>0&&d.jsx("button",{type:"button",onClick:B,children:"Clear"})]})]})}const Xr=5,Sr=["width","height","exact_output","output_width","output_height","frames","chunks","start_frame","crop_offset_x","crop_offset_y"],Pe="__surface_port_order",Ct=64,l0=8,pi=3840,gi=3840,xe=256,d0=121,f0=497,h0=3840*2176,mi="16 / 9",jc=new Set(["video","mask","foreground","background","conditioning","reference"]),p0=5e3,g0=1e4,rn="editor",Ic=new Set(["SUCCESS","FAILED","FAILURE","ERROR","CANCELLED","CANCELED"]),or="This kind of run canât open in the node editor.",Pc="AWAITING_PHASE_REVIEW",qt={phased_generation:!1},yi=["steps","cfg","stg","seed"],m0=[{id:"v1-baseline",label:"Baseline v1"},{id:"v2-ff05",label:"FF05 v2 - FFC"}],Rc=new Set(["sam3_mask","sam2_points_mask","generate_background","harmonise"]),rr={ltx_harmonisation:"harmoniser",ltx_backdrop:"backdrop",ltx_background_replace:"generative_world",ltx_
7scene_anchor:"scene_anchor"};function xi(e){const t=e?.result?.phase_review||e?.result_data?.phase_review;return t?{phase_review:t}:null}function lt(e,t){return t.reduce((n,o)=>(e?.[o]!==void 0&&e?.[o]!==null&&(n[o]=e[o]),n),{})}function dt(e,t,n){const o=(e.nodes||[]).find(r=>r.type===t);o&&(o.params={...o.params||{},...n})}function y0(e,t,n){const o=JSON.parse(JSON.stringify(e||{version:1,nodes:[],edges:[]})),r=t?.pipeline_params||{},s=r.compiled_pipeline_params||r;return dt(o,"source_video",{source_video_id:n,...lt(s,Sr)}),dt(o,"sam3_mask",lt(s,["mask_prompt_mode","additional_subjects","sam2_points","disable_held_object_suggestions"])),dt(o,"sam2_points_mask",lt(s,["sam2_points"])),dt(o,"canny",lt(s,["canny_edge_fraction","canny_low","canny_high","canny_conditioning_strength","conditioning_attention_strength"])),dt(o,"user_background",lt(s,["background_media_key"])),dt(o,"scene_anchor_reference",lt(s,["background_media_key","scene_anchor_image_strength"])),dt(o,"generate_background",lt(s,["prompt"])),dt(o,"harmonise",lt(s,["steps","cfg","stg","seed","harmonisation_lora","harmonisation_lora_first_chunk","harmonisation_lora_later_chunks","bulk_preview"])),s.phased_generation!==void 0&&(o.settings={...o.settings||{},phased_generation:!!s.phased_generation}),o}function ao(e){return(e?.key||"").split("/").pop()||""}function kn(e){const t=e?.url;return typeof t=="string"&&t.trim()?t.trim():""}function Ht(e,t){const n=new Set(Array.isArray(t)?t:[t]);return kn((e||[]).find(o=>n.has(ao(o))))}function wi(e,t){return t?kn((e||[]).find(n=>n.key===t)):""}function qn(e,t){const n=(e||[]).filter(o=>ao(o).startsWith(t)).sort((o,r)=>ao(o).localeCompare(ao(r),void 0,{numeric:!0}));return kn(n[0])}function Ac(e,t,n){switch(e?.type||e?.surfaceType){case"sam3_mask":case"sam2_points_mask":return{mask:Ht(t,["sam2_mask_overlay.mp4","sam3_masks.mp4","sam2_masks.mp4"])};case"matanyone_matte":return{foreground:Ht(t,"matting.mp4")};case"cleanplate":return{video:Ht(t,"cleanplate.mp4")};case"canny":return{canny:Ht(t,"canny.mp4")};case"generate_background":return{background:qn(t,"bg_")};case"qwen_text_background":case"qwen_edit_background":{const r=qn(t,`qwen_${e?.id||""}`)||qn(t,"qwen_");return{background:r,reference:r}}case"scene_anchor_reference":return{reference:Ht(t,["scene_anchor_first_frame.png","scene_anchor_reference.mp4"])||wi(t,e?.params?.background_media_key)};case"user_background":return{background:wi(t,e?.params?.background_media_key)};case"composite":return{video:qn(t,"composite_")};case"harmonise":return{video:Ht(t,"harmonised.mp4")||n?.result_video_url||""};default:return{}}}function Qt(e){return Object.fromEntries(Object.entries(e||{}).filter(([,t])=>typeof t=="string"&&t.trim()))}function vi(e){const t=typeof e=="string"?e.trim():"";if(!t)return"";try{const n=new URL(t,window.location?.origin||"http://surface.local");return decodeURIComponent(n.pathname||"").replace(/\/+/g,"/")}catch{return t.split("?")[0]}}function x0(e,t,n=!1){const o=Qt(e),r=Qt(t),s={...o};return Object.entries(r).forEach(([i,a])=>{if(!n&&o[i]&&vi(o[i])===vi(a)){s[i]=o[i];return}s[i]=a}),s}function w0(e,t){const n=Qt(e),o=Qt(t),r=new Set([...Object.keys(n),...Object.keys(o)]);for(const s of r)if(n[s]!==o[s])return!1;return!0}function Yr(e){return e?[e.surface_node_id||"",e.phase||"",e.iteration??"",e.created_at||""].join(":"):""}function v0(e){return e?.data?.surfaceType||e?.type||""}function $c(e,t=[]){if(!e)return null;if(e.surface_node_id)return e.surface_node_id;const o={segmentation:new Set(["sam3_mask","sam2_points_mask"]),background:new Set(["generate_background"]),harmonise:new Set(["harmonise"])}[e.phase]||new Set;return t.find(s=>o.has(v0(s)))?.id||null}function Qn(e,t){return kn((e?.artifacts||[]).find(n=>n.role===t))}function _0(e,t,n){return Object.fromEntries((e?.nodes||[]).map(o=>[o.id,Qt(Ac(o,t,n))]))}function b0(e,t){const n=$c(t,e?.nodes||[]);return n?{[n]:t}:{}}function S0(e,t,n,o=null){const r=$c(o,e),s=Yr(o);return e.map(i=>{const a=Qt(Ac(i.data,t,n)),c=!!(r&&i.id===r&&o),u=c&&i.data.phaseReviewKey===s?i.data.phaseReview:c?o:null,l=c?s:"",f=x0(i.data.outputUrls,a,c&&i.data.phaseReviewKey!==s);return i.data.phaseReview===u&&i.data.phaseReviewKey===l&&w0(i.data.outputUrls,f)?i:{...i,data:{...i.data,outputUrls:f,phaseReview:u,phaseReviewKey:l}}})}
7async function _i(e,t,n){if(!e||!n||String(t||"").toUpperCase()!==Pc)return null;try{return(await Nu(e,n))?.phase_review||null}catch{return null}}function bi(e){const t=typeof e=="string"?e.toUpperCase():"";return!!t&&!Ic.has(t)}function N0(e){return e?.surface_template_id||rr[e?.effective_pipeline_id]||rr[e?.surface_compiled_pipeline_id]||rr[e?.pipeline_id]||null}function sr(e){const n=(e?.nodes||[]).find(o=>o.type==="source_video")?.params?.source_video_id;return typeof n=="string"&&n.trim()?n.trim():""}function E0(e=[]){const n=e.find(o=>o.type==="source_video")?.params?.source_video_id;return typeof n=="string"&&n.trim()?n.trim():""}function kt(e,t){const n=E0(e);return(t||[]).find(o=>o.id===n)||null}function C0(e){if(e?.settings&&typeof e.settings=="object")return{...qt,...e.settings};const t=(e?.nodes||[]).find(n=>n.type==="output_video");return{...qt,phased_generation:!!t?.params?.phased_generation}}function To(e=[]){return e.find(t=>t.type==="preprocess")||e.find(t=>t.type==="source_video")||null}function cn(e){return e.map(t=>({id:t.id,type:t.data.surfaceType,position:t.position,params:t.data.params||{}}))}function Zr(e){const t=String(e||"").match(/(\d+)\s*x\s*(\d+)/i);return t?{width:Number(t[1]),height:Number(t[2])}:{width:null,height:null}}function Si(e){const t="surface-upload.mp4";return String(e||t).replace(/[^A-Za-z0-9._ -]/g,"_").replace(/\s+/g," ").trim()||t}function Ni(e,t){return!e||!Number.isFinite(e)?t:Math.min(t,Math.floor(e/Ct)*Ct)}function Ei(e,t){return!e||!Number.isFinite(e)?t:Math.min(t,Math.floor(e))}function Fe(e){return Math.max(xe,Math.ceil((Number(e)||xe)/Ct)*Ct)}function k0(e,t){return Fe(e)!==Number(e)||Fe(t)!==Number(t)}function Jn(e,t){const n=Math.floor(Math.max(xe,t)/2)*2,o=Math.floor((Number(e)||xe)/2)*2;return Math.max(xe,Math.min(o,n))}function Be(e){const t=Math.max(xe,Number(e)||xe);return Math.max(xe,Math.floor(h0/t/Ct)*Ct)}function Bt(e,t,n){return Math.max(t,Math.min(e,n))}function M0(e,t=!0){const n=t&&!!e.exact_output;return{width:n&&e.output_width||e.width,height:n&&e.output_height||e.height}}function eo(e,t,n,o=!0){if(!o)return{...e,exact_output:!1,width:t,height:n};const r=k0(t,n),s={...e,exact_output:r,width:r?Fe(t):t,height:r?Fe(n):n};return r&&(s.output_width=t,s.output_height=n),s}function j0(e,t,n){return e==null?ye(t.default,n):e===""?n:ye(e,n)}function I0(e,t,n,o,r){const i=(ye(e,n)-n)/r,a=t>0?Math.floor(i)+1:Math.ceil(i)-1;return Bt(n+a*r,n,o)}function Tc(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function Nr(e,t,n){const o=Tc(e.params?.[Pe])?.[n];if(!Array.isArray(o)||o.length===0)return t;const r=new Map(o.map((s,i)=>[s,i]));return t.slice().sort((s,i)=>{const a=r.has(s.key)?r.get(s.key):Number.MAX_SAFE_INTEGER,c=r.has(i.key)?r.get(i.key):Number.MAX_SAFE_INTEGER;return a!==c?a-c:t.indexOf(s)-t.indexOf(i)})}function P0(e,t,n){const o=e.map(i=>i.key),r=o.indexOf(t);if(r<0)return o;const[s]=o.splice(r,1);return o.splice(Bt(n,0,o.length),0,s),o}function Dc(e,t){return t.type==="bool"?!!(e??t.default):t.type==="string_list"?Array.isArray(e)?e.join(", "):"":t.type==="json"?typeof e=="string"?e:JSON.stringify(e??t.default??[],null,2):e??t.default??""}function co(e,t){if(t.type==="bool")return!!e;if(t.type==="int"){if(e==="")return"";const n=Number.parseInt(e,10);return Number.isNaN(n)?"":n}if(t.type==="float"){if(e==="")return"";const n=Number.parseFloat(e);return Number.isNaN(n)?"":n}if(t.type==="string_list")return e.split(",").map(n=>n.trim()).filter(Boolean);if(t.type==="json")try{return JSON.parse(e||"[]")}catch{return e}return e}function We(e){e.stopPropagation()}function ir(e){if(e<1)return`${e.toFixed(2)}s`;const t=Math.floor(e/60),n=(e-t*60).toFixed(1);return t>0?`${t}m${n}s`:`${n}s`}function Oc(e={}){const t=Math.max(1,ye(e.frames,121)),n=Math.max(1,ye(e.chunks,1));return t+(n-1)*Math.max(1,t-1)}function Gr({nodeId:e,param:t,value:n,onParamChange:o}){const r=Dc(n,t),s=t.type==="json"||t.key.includes("prompt")||t.key.includes("subjects");return t.key==="harmonisation_lora"||t.key==="harmonisation_lora_first_chunk"||t.key==="harmonisation_lora_later_chunks"?d.jsxs("label",{className:"surface-node-widget",children:[d.jsx("span",{children:t.label}),d.jsx("select",{value:r||t.default||"v1-baseline",onChange:i=>o(e,t.key,i.target.value),children:m0.map(i=>d.jsx("option",{value:i.id,children:i.label},i.id))})]}):t.type==="bool"?d.jsxs("label",{className:"surface-node-widget surface-node-checkbox",children:[d.jsx("input",{type:"checkbox",checked:!!r,onChange:i=>o(e,t.key,co(i.target.checked,t))}),d.jsx("span",{children:t.label})]}):d.jsxs("label",{className:"surface-node-widget",children:[d.jsx("span",{children:t.label}),s?d.jsx("textarea",{value:r,onChange:i=>o(e,t.key,co(i.target.value,t)),rows:t.type==="json"?4:3,spellCheck:t.key.includes("prompt")}):d.jsx("input",{type:"text",inputMode:t.type==="int"||t.type==="float"?"decimal":"text",value:r,onChange:i=>o(e,t.key,co(i.target.value,t))})]})}function to({nodeId:e,param:t,value:n,onParamChange:o,min:r,max:s,step:i,disabled:a=!1}){const c=Dc(n,t),u=j0(n,t,r),l=u<=r,f=u>=s,h=p=>{a||o(e,t.key,I0(u,p,r,s,i))};return d.jsxs("label",{className:`surface-node-widget surface-node-step
7per${a?" disabled":""}`,children:[d.jsx("span",{children:t.label}),d.jsxs("div",{className:"surface-stepper-control",children:[d.jsx("input",{type:"text",inputMode:"numeric",value:c,disabled:a,onChange:p=>{a||o(e,t.key,co(p.target.value,t))}}),d.jsxs("div",{className:"surface-stepper-buttons",children:[d.jsx("button",{type:"button",onClick:()=>h(-1),disabled:a||l,"aria-label":`${t.label} down`,children:d.jsx(He,{name:"chevronDown",size:16})}),d.jsx("button",{type:"button",onClick:()=>h(1),disabled:a||f,"aria-label":`${t.label} up`,children:d.jsx(He,{name:"chevronUp",size:16})})]})]})]})}function Kr(e){return/\.(png|jpe?g|webp)(?:[?#]|$)/i.test((e||"").split("?")[0])}function Hc(e,t,n){const o=e?.outputUrls?.[t.key]||e?.output_urls?.[t.key]||e?.artifacts?.[t.key]?.url||e?.output_artifacts?.[t.key]?.url;return typeof o=="string"&&o.trim()?o.trim():e.surfaceType==="source_video"&&t.artifact_type==="video"&&n?.source_video_url||""}function R0({data:e,outputs:t}){const n=t.filter(r=>jc.has(r.artifact_type));if(n.length===0)return null;const o=kt(e.graphNodes||[],e.sourceVideos||[]);return d.jsx("div",{className:"surface-output-previews nodrag nowheel",onPointerDown:We,children:n.map(r=>{const s=`${r.label} output`,i=e.surfaceType==="source_video"&&r.artifact_type==="video"&&o?.cover_image_url,a=Hc(e,r,o);return d.jsxs("div",{className:`surface-output-preview surface-output-preview-${r.artifact_type}`,children:[d.jsx("div",{className:"surface-node-output-label",children:r.label}),i?d.jsx("img",{className:"surface-output-preview-media",src:o.cover_image_url,alt:"","aria-label":s,style:{aspectRatio:mi}}):a?Kr(a)?d.jsx("img",{className:"surface-output-preview-media",src:a,alt:"","aria-label":s,style:{aspectRatio:mi}}):d.jsx("video",{className:"surface-output-preview-media",src:a,"aria-label":s,muted:!0,playsInline:!0,controls:!0,preload:"metadata"}):d.jsx(Mc,{className:"surface-output-preview-placeholder",label:s}),a?d.jsx("a",{className:"surface-output-download",href:a,download:!0,"aria-label":`Download ${r.label} output`,title:`Download ${r.label}`,onPointerDown:We,onClick:c=>c.stopPropagation(),children:d.jsx(He,{name:"download",size:18})}):d.jsx("button",{type:"button",className:"surface-output-download","aria-label":`Download ${r.label} output`,title:"Output downloads appear after this node has run.",disabled:!0,children:d.jsx(He,{name:"download",size:18})}),d.jsx("small",{children:Vc(e,r.artifact_type)})]},r.key)})})}function zc(e={}){const t=e.exact_output?ye(e.output_width,ye(e.width,1280)):ye(e.width,1280),n=e.exact_output?ye(e.output_height,ye(e.height,704)):ye(e.height,704);return{width:t,height:n}}function Lc(e=[]){const n=To(e)?.params||{},{width:o,height:r}=zc(n),s=Oc(n);return{width:o,height:r,frames:s}}function A0(e){const t=kt(e.graphNodes||[],e.sourceVideos||[]);if(!t)return"video";const n=["source video"];return t.resolution&&n.push(t.resolution),t.frame_count&&n.push(`${t.frame_count} frames`),t.fps&&n.push(`${Number(t.fps).toFixed(3)} fps`),n.join(", ")}function Bc(e){const t=Lc(e.graphNodes||[]);return`${t.width} Ã ${t.height}, ${t.frames} frames`}function Vc(e,t){return`${{video:"video",mask:"mask",foreground:"RGBA foreground",background:"background",conditioning:"conditioning"}[t]||t}, ${Bc(e)}`}function Er(e,t){return e.surfaceType==="source_video"&&t.artifact_type==="video"?`${t.label}: ${A0(e)}`:`${t.label}: ${Vc(e,t.artifact_type)}`}function Ci({data:e,handles:t,direction:n}){const o=t.length,[r,s]=N.useState(null),[i,a]=N.useState(null),c=(u,l,f)=>{const h=f.closest(".surface-node-ports");if(!h||o<=1)return;const p=Array.from(h.querySelectorAll(`.surface-port-${n}`)).map(y=>{const S=y.getBoundingClientRect();return S.top+S.height/2});if(p.length===0)return;const g=p.reduce((y,S,m)=>Math.abs(l-S)<Math.abs(l-p[y])?m:y,0),v=P0(t,u,g),x=Tc(e.params?.[Pe]);e.onParamChange?.(e.id,Pe,{...x,[n]:v})};return t.map((u,l)=>{const f=r===u.key,h=i===u.key;return d.jsx("span",{className:`surface-port-label surface-port-${n}${f?" armed":""}${h?" dragging":""}`,style:{gridRow:l+1},title:`${Er(e,u)}. Double-click, then drag up or down to reorder.`,onDoubleClick:p=>{p.preventDefault(),p.stopPropagation(),s(u.key)},onPointerDown:p=>{r!==u.key||o<=1||(p.preventDefault(),p.stopPropagation(),a(u.key),p.currentTarget.setPointerCapture(p.pointerId))},onPointerMove:p=>{i===u.key&&(p.preventDefault(),c(u.key,p.clientY,p.currentTarget))},onPointerUp:p=>{i===u.key&&c(u.key,p.clientY,p.currentTarget),a(null),s(null);try{p.currentTarget.releasePointerCapture(p.pointerId)}catch{}},onPointerCancel:()=>{a(null),s(null)},children:u.label},`${n}-${u.key}`)})}function $0({sourceVideo:e,params:t,onChangeStartFrame:n}){const o=N.useRef(null),[r,s]=N.useState(!1),i=ye(e?.fps,bo)||bo,a=ye(e?.duration_seconds,null)||(e?.frame_count?e.frame_count/i:null);if(!a)return d.jsx("p",{className:"surface-scrubber-empty",children:"Pick a source video to set a custom start frame."});const c=Oc(t),u=Math.min(c/i,a),l=Math.max(0,ye(t.start_frame,0)),f=l/i,h=Math.max(a-u,0),p=Math.min(f,h),g=a>0?p/a*100:0,v=a>0?u/a*100:100,x=w=>{const k=o.current;if(!k)return;const C=k.getBoundingClientRect(),j=(w-C.left)/C.width-v/200,A=Math.max(0,Math.min(1-v/100,j))*a;n(Math.round(A*i))},y=w=>{w.preventDefault(),s(!0),x(w.clientX),w.currentTarget.setPointerCapture(w.pointerId)},S=w=>{r&&x(w.clientX)},m=w=>{s(!1);try{w.currentTarget.releasePointerCapture(w.pointerId)}catch{}};return d.jsxs("div",{className:"surface-scrubber",children:[d.jsxs("div",{className:"surface-scrubber-head",children:[d.jsx("span",{children:"Start frame"}),d.jsxs("small",{children:[ir(p)," to ",ir(p+u)," of ",ir(a),", ","frame ",Math.round(p*i),", window ",c," frames"]})]}),d.jsx("div",{ref:o,className:`surface-scrubber-track${r?" dragging":""}`,onPointerDown:y,onPointerMove:S,onPointerUp:m,onPointerCancel:m,role:"slider","aria-label":"Start frame","aria-valuemin":0,"aria-valuemax":Math.round(h*i),"aria-valuenow":Math.round(p*i),tabIndex:0,onKeyDown:w=>{const k=w.shiftKey?Math.round(i):1,C=Math.round(h*i);w.key==="ArrowLeft"?(w.preventDefault(),n(Math.max(0,l-k))):w.key==="ArrowRight"&&(w.preventDefault(),n(Math.min(C,l+k)))},children:d.jsx("div",{className:"surface-scrubber-window",style:{left:`${g}%`,width:`${v}%`}})})]})}function T0({sourceVideo:e,params:t,onChange:n}){const o=N.useRef(null),[r,s]=N.useState(!1),i=Zr(e?.resolution),a=e?.cover_image_url,c=i.width,u=i.height,{width:l,height:f}=zc(t);if(!!!(a&&c&&u&&l&&f))return d.jsxs("div",{className:"surface-crop-scrubber",children:[d.jsx("div",{className:"surface-scrubber-head",children:d.jsx("span",{children:"Crop framing"})}),d.jsx("div",{className:"surface-crop-placeholder","aria-label":"Crop preview"})]});const p=c/u,g=l/f,v=Math.min(1,g/p),x=Math.min(1,p/g),y=1-v,S=1-x,m=Math.max(-1,Math.min(1,t.crop_offset_x||0)),w=Math.max(-1,Math.min(1,t.crop_offset_y||0)),k=y/2*(1+m),C=S/2*(1+w),j=(D,_)=>{const E=o.current;if(!E)return;const b=E.getBoundingClientRect(),I=(D-b.left)/b.width,P=(_-b.top)/b.height,T=I-v/2,U=P-x/2,z=y>0?Math.max(-1,Math.min(1,T/y*2-1)):0,V=S>0?Math.max(-1,Math.min(1,U/S*2-1)):0;n({x:y>0?Number(z.toFixed(3)):0,y:S>0?Number(V.toFixed(3)):0})},M=D=>{D.preventDefault(),s(!0),j(D.clientX,D.clientY),D.currentTarget.setPointerCapture(D.pointerId)},A=D=>{r&&j(D.clientX,D.clientY)},L=D=>{s(!1);try{D.currentTarget.releasePointerCapture(D.pointerId)}catch{}},$=y>.005?"horizontal":S>.005?"vertical":"none",H=$==="none"?`${l} Ã ${f} already matches source aspect`:`${l} Ã ${f} from ${c} Ã ${u}, drag to pan ${$}ly`;return d.jsxs("div",{className:"surface-crop-scrubber",children:[d.jsxs("div",{className:"surface-scrubber-head",children:[d.jsx("span",{children:"Crop framing"}),d.jsx("small",{children:H})]}),d.jsxs("div",{ref:o,className:`surface-crop-stage${r?" dragging":""}`,style:{aspectRatio:`${c} / ${u}`},onPointerDown:M,onPointerMove:A,onPointerUp:L,onPointerCancel:L,children:[d.jsx("img",{src:a,alt:"",className:"surface-crop-frame",draggable:!1}),d.jsx("div",{className:"surface-crop-dim",style:{clipPath:`polygon( 8 0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 0%, 9 ${k*100}% ${C*100}%, 10 ${k*100}% ${(C+x)*100}%, 11 ${(k+v)*100}% ${(C+x)*100}%, 12 ${(k+v)*100}% ${C*100}%, 13 ${k*100}% ${C*100}% 14 )`}}),d.jsx("div",{className:"surface-crop-window",style:{left:`${k*100}%`,top:`${C*100}%`,width:`${v*100}%`,height:`${x*100}%`}})]})]})}function ki({data:e,definition:t}){const n=e.params||{},o=e.graphNodes||[],r=kt(o,e.sourceVideos||[]),s=Zr(r?.resolution),i=Math.max(s.width||0,s.height||0)||null,a=Ni(i,pi),c=Ni(i,gi),u=Ei(i,pi),l=Ei(i,gi),f=new Map((t.params||[]).map(E=>[E.key,E])),h=f.has("exact_output"),p=f.get("frames"),g=f.get("width"),v=f.get("height"),x=f.get("chunks"),y=f.get("start_frame"),S=M0(n,h),m=ye(S.width,ye(g?.default,1280)),w=ye(S.height,ye(v?.default,704)),k=Math.min(a,Be(n.height)),C=Math.min(c,Be(n.width)),j=Math.min(u,Be(Fe(w))),M=Math.min(l,Be(Fe(m))),A=h?j:k,L=h?M:C,$=h?l0:Ct,H=E=>{const b={width:E.width,height:E.height};h&&(b.exact_output=E.exact_output),E.exact_output&&(b.output_width=E.output_width,b.output_height=E.output_height),e.onParamChange?.(e.id,b)},D=E=>{if(h){const P=Jn(E,Math.min(u,Be(Fe(w)))),T=Jn(w,Math.min(l,Be(Fe(P))));H(eo(n,P,T,h));return}const b=Bt(E,xe,Math.max(xe,k)),I=Bt(w,xe,Math.max(xe,Math.min(c,Be(b))));H(eo(n,b,I,h))},_=E=>{if(h){const P=Jn(E,Math.min(l,Be(Fe(m)))),T=Jn(m,Math.min(u,Be(Fe(P))));H(eo(n,T,P,h));return}const b=Bt(E,xe,Math.max(xe,C)),I=Bt(m,xe,Math.max(xe,Math.min(a,Be(b))));H(eo(n,I,b,h))};
14return d.jsxs("div",{className:"surface-node-controls nodrag nowheel",onPointerDown:We,children:[d.jsxs("div",{className:"surface-preprocess-grid",children:[p&&d.jsx(to,{nodeId:e.id,param:p,value:n.frames,onParamChange:e.onParamChange,min:9,max:f0,step:8}),Number(n.frames)>d0&&d.jsx("p",{className:"surface-frame-warning",role:"status",children:"Performance may degrade above 121 frames. Using chunked inputs with shorter frame windows may improve performance."}),x&&d.jsx(to,{nodeId:e.id,param:x,value:n.chunks,onParamChange:e.onParamChange,min:1,max:3,step:1}),g&&d.jsx(to,{nodeId:e.id,param:g,value:m,onParamChange:(E,b,I)=>D(I),min:xe,max:Math.max(xe,A),step:$}),v&&d.jsx(to,{nodeId:e.id,param:v,value:w,onParamChange:(E,b,I)=>_(I),min:xe,max:Math.max(xe,L),step:$}),y&&d.jsx(Gr,{nodeId:e.id,param:y,value:n.start_frame,onParamChange:e.onParamChange})]}),d.jsx($0,{sourceVideo:r,params:n,onChangeStartFrame:E=>e.onParamChange?.(e.id,"start_frame",E)}),d.jsx(T0,{sourceVideo:r,params:n,onChange:({x:E,y:b})=>{e.onParamChange?.(e.id,"crop_offset_x",E),e.onParamChange?.(e.id,"crop_offset_y",b)}})]})}function Fc({value:e,onChange:t}){const n=Array.isArray(e)?e:[],o=(s,i)=>{const a=n.slice();a[s]=i,t(a)},r=s=>{const i=n.slice();i.splice(s,1),t(i)};return d.jsxs("div",{className:"surface-subjects",children:[n.map((s,i)=>d.jsxs("div",{className:"surface-subject-row",children:[d.jsx("input",{value:s,maxLength:80,placeholder:"skateboard",onChange:a=>o(i,a.target.value)}),d.jsx("button",{type:"button",onClick:()=>r(i),"aria-label":`Remove subject ${i+1}`,children:"x"})]},i)),n.length<Xr&&d.jsx("button",{type:"button",className:"surface-subject-add",onClick:()=>t([...n,""]),children:"+ Add subject"})]})}function D0({data:e}){const t=e.params||{},n=t.mask_prompt_mode==="sam2_points"?"sam2_points":"sam3_text",o=e.graphNodes||[],r=kt(o,e.sourceVideos||[]),s=To(o)?.params||{},i=Array.isArray(t.sam2_points)?t.sam2_points:[],a=c=>e.onParamChange?.(e.id,"mask_prompt_mode",c);return d.jsxs("div",{className:"surface-node-controls nodrag nowheel",onPointerDown:We,children:[d.jsxs("div",{className:"surface-mask-head",children:[d.jsx("span",{children:"Segmentation Method"}),d.jsxs("div",{className:"surface-mask-tabs",role:"group","aria-label":"Segmentation Method",children:[d.jsx("button",{type:"button",className:n==="sam3_text"?"active":"","aria-pressed":n==="sam3_text",onClick:()=>a("sam3_text"),children:"Text"}),d.jsx("button",{type:"button",className:n==="sam2_points"?"active":"","aria-pressed":n==="sam2_points",onClick:()=>a("sam2_points"),children:"Points"})]})]}),n==="sam2_points"?d.jsxs(d.Fragment,{children:[d.jsx(Wr,{sourceVideo:r,preprocessParams:s,value:i,onChange:c=>e.onParamChange?.(e.id,"sam2_points",nt(c))}),i.length>0&&!uo(i)&&d.jsx("p",{className:"surface-mask-warning",children:"Each object needs at least one include point."})]}):d.jsx(Fc,{value:t.additional_subjects,onChange:c=>e.onParamChange?.(e.id,"additional_subjects",c)}),n==="sam3_text"&&d.jsxs("label",{className:"surface-node-widget surface-node-checkbox",children:[d.jsx("input",{type:"checkbox",checked:!!t.disable_held_object_suggestions,onChange:c=>e.onParamChange?.(e.id,"disable_held_object_suggestions",c.target.checked)}),d.jsx("span",{children:"Skip handheld object analysis"})]})]})}function O0({data:e}){const t=e.params||{},n=e.surfaceType==="scene_anchor_reference",o=e.uploadingBackgroundNodeId===e.id,r=typeof t.background_media_key=="string"?t.background_media_key:"",s=r.split("/").pop()||"",i=a=>{const c=a.target.files?.[0];a.target.value="",c&&e.onBackgroundUpload?.(e.id,c)};return d.jsxs("div",{className:"surface-node-controls nodrag nowheel",onPointerDown:We,children:[d.jsxs("label",{className:`surface-source-upload ${o?"is-uploading":""}`,children:[d.jsx(He,{name:"upload",size:18}),d.jsx("span",{children:o?"Uploading...":`Upload ${n?"reference":"background"}`}),d.jsx("input",{type:"file",accept:Au,onChange:i,disabled:o})]}),d.jsx("div",{className:`surface-background-media-status ${r?"has-media":""}`,children:r?s:`No ${n?"reference":"background"} selected`})]})}function Mi(e){return(e||[]).map(t=>
14String(t||"").trim()).filter(Boolean).slice(0,Xr)}function ji(e,t){const n=nt(e?.sam2_points||[]);return n.length>0?n:nt(t?.default_sam2_points||[])}function ar(e){return JSON.stringify(nt(e||[]))}function H0(e){return new Set(Array.isArray(e?.controls)?e.controls:[])}function qr(e){const t=Array.isArray(e?.editable_params)?e.editable_params.filter(n=>yi.includes(n)):[];return t.length>0?t:yi}function Uc(e,t){const n=new Map((e?.params||[]).map(r=>[r.key,r])),o={steps:{key:"steps",label:"Steps",type:"int",default:20},cfg:{key:"cfg",label:"CFG",type:"float",default:1},stg:{key:"stg",label:"STG",type:"float",default:0},seed:{key:"seed",label:"Seed",type:"int",default:42}}[t];return n.get(t)||o}function Ii(e,t){const n=e?.params||{};return Object.fromEntries(qr(t).map(o=>{const r=Uc(e?.definition,o);return[o,n[o]??r?.default??""]}))}function z0(e,t){const n={};return qr(t).forEach(o=>{const r=o==="cfg"||o==="stg"?Number.parseFloat(e[o]):Number.parseInt(e[o],10);Number.isFinite(r)&&(n[o]=r)}),n}function L0(e={}){const t={};return e.mask_prompt_mode!==void 0&&(t.mask_prompt_mode=e.mask_prompt_mode),e.sam2_points!==void 0&&(t.sam2_points=e.sam2_points),e.additional_subjects!==void 0&&(t.additional_subjects=e.additional_subjects),e.prompt!==void 0&&(t.prompt=e.prompt),e.surface_node_params&&typeof e.surface_node_params=="object"&&Object.assign(t,e.surface_node_params),t}function B0({review:e}){const t=e?.artifacts||[];
14return t.length===0?null:d.jsx("div",{className:"surface-phase-artifacts",children:t.map(n=>{const o=kn(n);return o?d.jsxs("div",{className:"surface-phase-artifact",children:[d.jsx("span",{children:n.label||n.role||"Artifact"}),Kr(o)||n.kind==="image"?d.jsx("img",{src:o,alt:""}):d.jsx("video",{src:o,muted:!0,playsInline:!0,controls:!0,preload:"metadata"})]},n.key||n.url||n.role):null})})}function V0({data:e,review:t,value:n,onChange:o}){const r=qr(t).map(s=>Uc(e.definition,s)).filter(Boolean);return r.length===0?null:d.jsx("div",{className:"surface-phase-harmonise-grid",children:r.map(s=>d.jsx(Gr,{nodeId:e.id,param:s,value:n[s.key],onParamChange:(i,a,c)=>o({...n,[a]:c})},s.key))})}function Wc({data:e}){const t=e.phaseReview,[n,o]=N.useState(()=>e.params?.additional_subjects||[]),[r,s]=N.useState(()=>ji(e.params,t)),[i,a]=N.useState(()=>ar(r)),[c,u]=N.useState(!1),[l,f]=N.useState(()=>e.params?.prompt||""),[h,p]=N.useState(()=>Ii(e,t)),[g,v]=N.useState(""),x=e.phaseReviewKey||"",y=N.useRef("");if(N.useEffect(()=>{const z=y.current;y.current=x,o(e.params?.additional_subjects||[]);const V=ji(e.params,t);s(V),a(ar(V)),z&&z!==x&&u(!1),f(e.params?.prompt||""),p(Ii(e,t)),v("")},[x]),!t)return null;const S=H0(t),m=kt(e.graphNodes||[],e.sourceVideos||[]),w=To(e.graphNodes||[])?.params||{},k=Lc(e.graphNodes||[]),C=Qn(t,"source")||m?.source_video_url||"",j=Qn(t,"mask_overlay"),M=Qn(t,"mask"),A=j||M,L=Qn(t,"matte"),$=e.phaseReviewBusy,H=t.phase==="segmentation"&&S.has("sam2_points"),D=t.selection_action==="remove"?"remove":"keep",_=Array.isArray(t.held_object_suggestions)?t.held_object_suggestions:[],E=nt(r),b=uo(E),I=H&&ar(E)!==i,P=()=>{if(!$){if(H){if(!b){v("Select at least one person or object before continuing.");return}if(I){v("Apply your selection changes by rerunning the mask before continuing.");return}if(!c){v(`Confirm that the matte contains everything you want to ${D}.`);return}}e.onPhaseContinue?.(e.phaseReviewJobId,H?{mask_confirmed:!0}:{})}},T=()=>{if($)return;const z={};if(t.phase==="harmonise"&&S.has("surface_node_params")){if(z.surface_node_params=z0(h,t),Object.keys(z.surface_node_params).length===0){v("Update at least one harmonisation setting before rerunning this stage.");return}}else if(S.has("prompt")){if(z.prompt=l.trim(),!z.prompt){v("Enter a prompt before rerunning this stage.");return}}else if(S.has("sam2_points")){const V=nt(r);if(!uo(V)){v("Add at least one include point for each SAM2 object before rerunning the mask.");return}z.mask_prompt_mode="sam2_points",z.sam2_points=V}else z.additional_subjects=Mi(n),z.mask_prompt_mode="sam3_text";v(""),u(!1),e.onPhaseRerun?.(z,e.phaseReviewJobId)},U=z=>{if($)return;const V=String(z?.label||"").trim();if(!V)return;const K=Mi([...n,V]);if(!K.some(q=>q.toLocaleLowerCase()===V.toLocaleLowerCase())){v(`A maximum of ${Xr} additional objects can be selected.`);return}o(K),u(!1),v(""),e.onPhaseRerun?.({additional_subjects:K,mask_prompt_mode:"sam3_text"},e.phaseReviewJobId)};return d.jsxs("div",{className:"surface-phase-review nodrag nowheel",onPointerDown:We,children:[d.jsx("div",{className:"surface-phase-review-head",children:d.jsx("strong",{children:t.label||"Review stage"})}),H&&d.jsx($u,{suggestions:_,selectedSubjects:n,onSelect:U,busy:!!$}),S.has("sam2_points")?d.jsx(Wr,{sourceVideo:m,preprocessParams:w,sourceUrl:C,maskUrl:A,maskIsColour:!!j,fallbackFrameCount:k.frames,value:r,onChange:z=>{s(nt(z)),u(!1),v("")}}):d.jsx(B0,{review:t}),H&&d.jsx(Tu,{url:L||M,soft:!!L,expert:!0}),S.has("prompt")&&d.jsxs("label",{className:"surface-node-widget surface-phase-prompt",children:[d.jsx("span",{children:"Prompt"}),d.jsx("textarea",{rows:3,value:l,maxLength:500,onChange:z=>f(z.target.value)})]}),S.has("additional_subjects")&&d.jsx(Fc,{value:n,onChange:o}),t.phase==="harmonise"&&S.has("surface_node_params")&&d.jsx(V0,{data:e,review:t,value:h,onChange:p}),H&&d.jsxs("div",{className:"surface-mask-decision",children:[d.jsxs("p",{children:[d.jsxs("strong",{children:["Largest person selected",D==="remove"?" for removal":"","."]})," ","Click a suggested handheld object or add a new object point to include it in the matte. Remove the default point to choose a different person."]}),d.jsx("span",{className:`surface-mask-state ${b?I?"is-pending":"is-ready":"is-blocked"}`,children:b?I?"Selection changed. Apply and rerun the mask to preview it.":"The highlighted mask is current and ready to confirm.":"Select at least one person or object. The mask cannot be empty."}),d.jsxs("label",{className:"surface-mask-confirm",children:[d.jsx("input",{type:"checkbox",checked:c,onChange:z=>u(z.target.checked),disabled:!!$||!b||I}),d.jsxs("span",{children:["I confirm the matte contains everything I want to ",D,"."]})]})]}),g&&d.jsx("p",{className:"surface-phase-error",children:g}
14),d.jsxs("div",{className:"surface-phase-actions",children:[d.jsx("button",{type:"button",onClick:T,disabled:!!$||H&&!b,children:$==="rerun"?"Rerunning...":H?"Apply & rerun":"Rerun stage"}),d.jsx("button",{type:"button",className:"surface-phase-primary",onClick:P,disabled:!!$||H&&(!b||I||!c),children:$==="continue"?"Continuing...":H?"Continue with matte":"Accept"})]})]})}function F0(e){return e==="source_video"?["source_video_id",...Sr,Pe]:e==="preprocess"?[...Sr,Pe]:e==="sam3_mask"?["mask_prompt_mode","additional_subjects","sam2_points","disable_held_object_suggestions",Pe]:e==="sam2_points_mask"?["sam2_points",Pe]:e==="output_video"?["phased_generation",Pe]:e==="user_background"||e==="scene_anchor_reference"?["background_media_key",Pe]:[Pe]}function Xc(e){const t=new Set(F0(e.surfaceType));return(e.definition?.params||[]).filter(n=>!t.has(n.key))}function Yc({data:e}){const t=e.definition||{inputs:[],outputs:[],params:[]},n=e.params||{},o=e.sourceVideos||[],r=!!e.phaseReview,s=o.find(l=>l.id===n.source_video_id),i=e.uploadingSourceNodeId===e.id,a=Xc(e),c=l=>{e.onParamChange?.(e.id,"source_video_id",l);const f=Object.fromEntries((t.params||[]).map(v=>[v.key,v.default])),h=Zr(o.find(v=>v.id===l)?.resolution),p=n.width??f.width,g=n.height??f.height;(h.height||0)>(h.width||0)&&f.width&&f.height&&p===f.width&&g===f.height&&(e.onParamChange?.(e.id,"width",f.height),e.onParamChange?.(e.id,"height",f.width))},u=l=>{const f=l.target.files?.[0];l.target.value="",f&&e.onSourceUpload?.(e.id,f)};return d.jsxs(d.Fragment,{children:[e.surfaceType==="source_video"&&d.jsxs("div",{className:"surface-node-controls nodrag nowheel",onPointerDown:We,children:[d.jsxs("label",{className:"surface-node-widget",children:[d.jsx("span",{children:"Open source video"}),d.jsxs("select",{value:n.source_video_id||"",onChange:l=>c(l.target.value),disabled:i,children:[d.jsx("option",{value:"",children:"Choose from My Videos..."}),o.map(l=>d.jsx("option",{value:l.id,children:l.original_filename},l.id))]})]}),d.jsxs("label",{className:`surface-source-upload ${i?"is-uploading":""}`,children:[d.jsx(He,{name:"upload",size:18}),d.jsx("span",{children:i?"Uploading...":"Upload new clip"}),d.jsx("input",{type:"file",accept:Ru,onChange:u,disabled:i})]}),s&&d.jsxs("div",{className:`surface-source-preview ${s.cover_image_url?"has-thumbnail":""}`.trim(),children:[s.cover_image_url&&d.jsx("img",{"data-testid":"surface-source-thumbnail",src:s.cover_image_url,alt:""}),d.jsx("span",{children:s.original_filename})]})]}),e.surfaceType==="source_video"&&d.jsx(ki,{data:e,definition:t}),e.surfaceType==="preprocess"&&d.jsx(ki,{data:e,definition:t}),!r&&e.surfaceType==="sam3_mask"&&d.jsx(D0,{data:e}),(e.surfaceType==="user_background"||e.surfaceType==="scene_anchor_reference")&&d.jsx(O0,{data:e}),!r&&e.surfaceType==="sam2_points_mask"&&d.jsx("div",{className:"surface-node-controls nodrag nowheel",onPointerDown:We,children:d.jsx(Wr,{sourceVideo:kt(e.graphNodes||[],e.sourceVideos||[]),preprocessParams:To(e.graphNodes||[])?.params||{},value:n.sam2_points,onChange:l=>e.onParamChange?.(e.id,"sam2_points",nt(l))})}),!r&&a.length>0&&d.jsx("div",{className:"surface-node-controls nodrag nowheel",onPointerDown:We,children:a.map(l=>d.jsx(Gr,{nodeId:e.id,param:l,value:n[l.key],onParamChange:e.onParamChange},l.key))})]})}function U0({data:e,selected:t}){const n=wm(),o=e.definition||{inputs:[],outputs:[]},r=e.params||{},s=Nr(e,o.inputs||[],"input"),i=Nr(e,o.outputs||[],"output"),a=Math.max(1,s.length),c=Math.max(1,i.length);N.useEffect(()=>{n(e.id)},[e.id,r[Pe],a,c,n]);const u=`surface-node surface-node-${e.surfaceType} ${t?"selected":""} ${e.phaseReview?"needs-review":""}`;return d.jsxs("div",{className:u.trim(),children:[d.jsxs("div",{className:"surface-node-header",children:[d.jsxs("div",{className:"surface-node-name",children:[d.jsx("div",{className:"surface-node-type",children:o.label||e.surfaceType}),d.jsx("div",{className:"surface-node-id",children:e.id})]}),e.onNodeRerun&&e.canRerunNodes&&Rc.has(e.surfaceType)&&d.jsxs("div",{className:"surface-node-rerun nodrag",onPointerDown:We,children:[d.jsx(dn,{icon:"play",label:`Rerun ${e.id}`,size:"compact",tone:"ink",title:"Rerun this node with its current settings (overwrites this run's output)",disabled:!!e.nodeRerunBusy,onClick:()=>e.onNodeRerun(e.id,e.params||{},!1)}),d.jsx(dn,{icon:"rerunAfter",label:`Rerun ${e.id} and downstream`,size:"compact",tone:"ink",title:"Rerun this node and all downstream nodes (overwrites this run's outputs)",disabled:!!e.nodeRerunBusy,onClick:()=>e.onNodeRerun(e.id,e.params||{},!0)})]})]}),d.jsxs("div",{className:"surface-node-ports",children:[s.map((l,f)=>d.jsx(Kt,{type:"target",id:l.key,position:ne.Left,style:{gridRow:f+1},title:Er(e,l)},l.key)),d.jsx(Ci,{data:e,handles:s,direction:"input"}),d.jsx(Ci,{data:e,handles:i,direction:"output"}),i.map((l,f)=>d.jsx(Kt,{type:"source",id:l.key,position:ne.Right,style:{gridRow:f+1},title:Er(e,l)},l.key))]}),d.jsxs("div",{className:"surface-node-body",children:[d.jsx(Yc,{data:e}),d.jsx(Wc,{data:e}),d.jsx(R0,{data:e,outputs:i})]})]})}const W0={surface:U0};function Pi({tab:e,size:t="compact"}){return d.jsx($e,{as:Eu,variant:"link",size:t,to:e.clipPath,state:{runId:e.runId},children:"Open the clip"})}function Zc(e,t,n,o,r,s,i,a,c,u,l,f,h=[],p={},g=null,v=""){return{id:e.id,surfaceType:e.type,params:e.params||{},outputUrls:p,phaseReview:g,phaseReviewKey:v,definition:t,sourceVideos:n,onParamChange:o,onSourceUpload:r,onBackgroun
14dUpload:s,onPhaseContinue:i,onPhaseRerun:a,phaseReviewBusy:c,phaseReviewJobId:u,uploadingSourceNodeId:l,uploadingBackgroundNodeId:f,graphNodes:h}}function Ri(e,t,n,o,r,s,i,a,c,u,l,f,h={},p={}){const g=(e?.nodes||[]).map(y=>{const S=t.get(y.type)||{},m=p[y.id]||null;return{id:y.id,type:"surface",position:y.position||{x:0,y:0},data:Zc(y,S,n,o,r,s,i,a,c,u,l,f,[],h[y.id]||{},m,Yr(m))}}),v=cn(g),x=(e?.edges||[]).map(y=>({id:y.id||`${y.source}-${y.target}`,source:y.source,target:y.target,sourceHandle:y.sourceHandle,targetHandle:y.targetHandle,animated:!1}));return{nodes:g.map(y=>({...y,data:{...y.data,graphNodes:v}})),edges:x,settings:C0(e)}}function X0(e,t,n=qt){return{version:1,settings:{...qt,...n||{}},nodes:e.map(o=>({id:o.id,type:o.data.surfaceType,position:o.position,params:o.data.params||{}})),edges:t.map(o=>({id:o.id,source:o.source,sourceHandle:o.sourceHandle,target:o.target,targetHandle:o.targetHandle}))}}function Y0(e,t,n,o){const r=t.find(u=>u.id===e.source),s=t.find(u=>u.id===e.target);if(!r||!s)return null;const i=n.get(r.data.surfaceType),a=n.get(s.data.surfaceType);if(!i||!a)return null;if(e.sourceHandle&&e.targetHandle)return e;const c=new Set(o.filter(u=>u.target===s.id).map(u=>u.targetHandle));for(const u of i.outputs||[])for(const l of a.inputs||[])if(!c.has(l.key)&&u.artifact_type===l.artifact_type)return{...e,sourceHandle:u.key,targetHandle:l.key};return null}function Ai(e){const t=[];for(const n of e?.nodes||[]){const o=n.params||{};if(!(n.type==="sam2_points_mask"||n.type==="sam3_mask"&&o.mask_prompt_mode==="sam2_points"))continue;const s=nt(o.sam2_points||[]);uo(s)||t.push(`${n.id} needs at least one include point for every SAM2 object.`)}return t}function cr(e){const t=e?.credits?.total;return typeof t!="number"?"Not estimated":`${t} credits`}const Z0=new Set(["source_video","preprocess","sam3_mask","sam2_points_mask","user_background","scene_anchor_reference"]),G0=new Set(["source_video","preprocess","user_background","scene_anchor_reference"]);function K0(e){return e.phaseReview&&!G0.has(e.surfaceType)?!1:Z0.has(e.surfaceType)||Xc(e).length>0}function q0(e){const t=e.data,n=t.definition||{},o=Nr(t,n.outputs||[],"output").filter(c=>jc.has(c.artifact_type)),r=kt(t.graphNodes||[],t.sourceVideos||[]),s=o.map(c=>({label:c.label,url:Hc(t,c,r)})),i=t.surfaceType==="source_video"?r?.cover_image_url:s.map(c=>c.url).find(c=>c&&Kr(c))||(t.phaseReview?r?.cover_image_url:null),a=!!(t.onNodeRerun&&t.canRerunNodes&&Rc.has(t.surfaceType));return{id:e.id,label:n.label||t.surfaceType,meta:o.length>0?Bc(t):"",waiting:!!t.phaseReview,thumbnailUrl:i||"",downloads:s,rerun:a?{busy:!!t.nodeRerunBusy,onRerun:()=>t.onNodeRerun(e.id,t.params||{},!1),onRerunAfter:()=>t.onNodeRerun(e.id,t.params||{},!0)}:null,review:t.phaseReview?d.jsx(Wc,{data:t}):null,settings:K0(t)?d.jsx(Yc,{data:t}):null}}function gy(){const{token:e,user:t}=fu(),n=!!(t?.is_internal||t?.studio_preferences?.experience==="vfx"),o=hu(),r=pu();Cu({title:"Node editor",back:{fromNav:!1}});const s=Ti(),[i,a]=N.useState([]),[c,u]=N.useState([]),[l,f]=N.useState([]),[h,p]=N.useState([]),[g,v]=N.useState(null),[x,y]=N.useState("Untitled workflow"),[S,m]=N.useState(null),[w,k]=N.useState(null),[C,j]=N.useState(!1),[M,A]=N.useState(""),[L,$]=N.useState([{id:rn,kind:"editor",label:"Editor"}]),[H,D]=N.useState(rn),_=N.useRef(new Map),[E,b]=N.useState(""),[I,P]=N.useState([]),[T,U]=N.useState(null),[z,V]=N.useState(null),[K,q]=N.useState(null),[oe,se]=N.useState(0),[te,B]=N.useState(qt),[O,Y]=N.useState(null),[W,G]=N.useState(null),[Q,re]=N.useState(null),[ae,fe]=N.useState(null),[he,de,je]=vm([]),[ve,me,pt]=_m([]),[Re,Ze]=N.useState(null),be=he.find(R=>R.data?.phaseReview)?.id||null;N.useEffect(()=>{if(!Re||!be)return;let R=requestAnimationFrame(()=>{R=requestAnimationFrame(()=>Re.fitView({nodes:[{id:be}],maxZoom:1,padding:.12}))});return()=>cancelAnimationFrame(R)},[Re,be,O]);const _e=N.useMemo(()=>new Map(i.map(R=>[R.type,R])),[i]),Ie=N.useMemo(()=>new URLSearchParams(o.search),[o.search]),Se=Ie.get("run_id"),st=Ie.get("video_id"),Mt=!!(Se&&st)?`${st}:${Se}`:"",jt=!!Mt&&Mt!==M,jn=!!te.phased_generation,Ce=N.useCallback((R,F,Z)=>{const X=F&&typeof F=="object"&&!Array.isArray(F)?F:{[F]:Z};de(ee=>{const J=ee.map(ce=>ce.id!==R?ce:{...ce,data:{...ce.data,params:{...ce.data.params||{},...X}}}),ue=cn(J);return J.map(ce=>({...ce,data:{...ce.data,graphNodes:ue}}))})},[de]),Ge=N.useCallback(async(R,F)=>{if(!e||!F)return;const Z=Si(F.name),X=Iu(F);V(R),P([]),b(`Uploading ${Z}...`);try{const ee=await gu({filename:Z},e),J=ee.fields["x-amz-meta-job-id"],ue=`uploads/${J}/${Z}`,ce=new FormData;for(const[Je,mt]of Object.entries(ee.fields))ce.append(Je,mt);ce.append("Content-Type",X),ce.append("file",F);const ie=await fetch(ee.url,{method:"POST",body:ce});if(!ie.ok)throw new Error(`Upload failed (${ie.status}): ${await ie.text().catch(()=>"")}`);b("Analysing source video...");const Ne=await mu({job_id:J,file_key:ue,original_filename:Z},e);p(Je=>[Ne,...Je.filter(mt=>mt.id!==Ne.id)]),Ce(R,"source_video_id",Ne.id),b(`Source video ready: ${Ne.original_filename||Z}.`)}catch(ee){b("Source upload failed."),P([ee.message])}finally{V(null)}},[e,Ce]),Ke=N.useCallback(async(R,F)=>{if(!e||!F)return;const Z=Si(F.name),X=Pu(F);q(R),P([]),b(`Uploading ${Z}...`);try{const ee=await yu({filename:Z,content_type:X},e),J=new FormData;for(const[ce,ie]of Object.entries(ee.fields||{}))J.append(ce,ie);Object.prototype.hasOwnProperty.call(ee.fields||{},"Content-Type")||J.append("Content-Type",X),J.append("file",F);const ue=await fetch(ee.url,{method:"POST",body:J});
14if(!ue.ok)throw new Error(`Background upload failed (${ue.status}): ${await ue.text().catch(()=>"")}`);Ce(R,"background_media_key",ee.background_media_key),b(`Background media ready: ${Z}.`)}catch(ee){b("Background upload failed."),P([ee.message])}finally{q(null)}},[e,Ce]),It=N.useCallback(()=>{de(R=>R.map(F=>F.data.phaseReview?{...F,data:{...F.data,phaseReview:null,phaseReviewKey:""}}:F))},[de]),qe=N.useCallback(async(R="",F={})=>{const Z=R||W?.jobId;if(!(!e||!Z||Q)){re("continue"),P([]);try{const X=await xu(Z,e,F);It(),G(ee=>ee&&ee.jobId===Z?{...ee,status:X?.status||"QUEUED"}:ee),b("Continuing workflow...")}catch(X){P([X.message||"Could not continue this stage."])}finally{re(null)}}},[It,W?.jobId,Q,e]),Qe=N.useCallback(async(R,F="")=>{const Z=F||W?.jobId;if(!(!e||!Z||Q)){re("rerun"),P([]);try{const X=await wu(Z,R,e),ee=L0(R);de(J=>{const ue=J.map(ie=>ie.data.phaseReview?{...ie,data:{...ie.data,params:{...ie.data.params||{},...ee},phaseReview:null,phaseReviewKey:""}}:ie),ce=cn(ue);return ue.map(ie=>({...ie,data:{...ie.data,graphNodes:ce}}))}),G(J=>J&&J.jobId===Z?{...J,status:X?.status||"QUEUED"}:J),b("Rerunning step...")}catch(X){P([X.message||"Could not rerun this stage."])}finally{re(null)}}},[W?.jobId,Q,de,e]),In=String(W?.status||"").toUpperCase(),Pn=!!W?.jobId&&(Ic.has(In)||In===Pc),Rn=N.useCallback(async(R,F,Z)=>{const X=W?.jobId;if(!(!e||!X||ae)){fe(R),P([]),b(Z?`Rerunning ${R} and downstream nodes...`:`Rerunning ${R}...`);try{const{[Pe]:ee,...J}=F||{},ue=await s0(X,{node_id:R,node_params:J,include_downstream:Z},e);It(),G(ce=>ce&&ce.jobId===X?{...ce,status:ue?.status||"QUEUED"}:ce)}catch(ee){b("Rerun failed."),P([ee.message||"Could not rerun this node."])}finally{fe(null)}}},[It,W?.jobId,ae,e]),it=N.useCallback((R,F={})=>{const Z=Ri(R,_e,h,Ce,Ge,Ke,qe,Qe,Q,F.loadedRun?.jobId||W?.jobId||"",z,K,F.nodeOutputUrls||{},F.nodePhaseReviews||{});de(Z.nodes),me(Z.edges),B(Z.settings),v(null),Object.prototype.hasOwnProperty.call(F,"templateId")&&m(F.templateId||null),Object.prototype.hasOwnProperty.call(F,"workflowId")&&k(F.workflowId||null),G(F.loadedRun||null),P([]),U(null),j(!1),b(""),se(X=>X+1)},[_e,me,de,h,Ce,Ge,Ke,qe,Qe,Q,W?.jobId,z,K]);N.useEffect(()=>{de(R=>{const F=cn(R);return R.map(Z=>({...Z,data:{...Z.data,definition:_e.get(Z.data.surfaceType)||Z.data.definition,sourceVideos:h,onParamChange:Ce,onSourceUpload:Ge,onBackgroundUpload:Ke,onPhaseContinue:qe,onPhaseRerun:Qe,onNodeRerun:Rn,nodeRerunBusy:ae,canRerunNodes:Pn,phaseReviewBusy:Q,phaseReviewJobId:W?.jobId||Z.data.phaseReviewJobId||"",uploadingSourceNodeId:z,uploadingBackgroundNodeId:K,graphNodes:F}}))})},[_e,de,h,Ce,Ge,Ke,qe,Qe,Rn,ae,Pn,Q,W?.jobId,z,K]),N.useEffect(()=>{if(!e||!n)return;let R=!1;return Promise.all([qm(e),Qm(e),Jm(e),vu(e)]).then(([F,Z,X,ee])=>{R||(a(F.nodes||[]),u(Z.templates||[]),f(X.workflows||[]),p(ee||[]))}).catch(F=>P([F.message])),()=>{R=!0}},[e,n]);const An=N.useCallback(async(R,F)=>{const X=(await _u(R,e)||[]).find(at=>at.job_id===F);if(!X)throw new Error("Workflow run not found for this video.");const ee=X.pipeline_params?.surface_graph?.graph,J=N0(X),ue=J?c.find(at=>at.id===J):null,ce=ee||ue?.graph;if(!ce){const at=new Error(or);throw at.unopenable={label:bu(X),status:X.status},at}const ie=y0(ce,X,R);let Ne=null;try{Ne=await ns(X.job_id,e)}catch{Ne=null}const Je=Ne?.status||X.status,mt=await _i(X.job_id,Je,e),Lo=Ne?.artifacts||[],en=X.surface_label||ue?.label||"Workflow run";return y(en),it(ie,{templateId:ee?X.surface_template_id||null:J,workflowId:X.surface_workflow_id||null,nodeOutputUrls:_0(ie,Lo,X),nodePhaseReviews:b0(ie,mt),loadedRun:{jobId:X.job_id,status:Je,resultVideoUrl:X.result_video_url||""}}),b(`Loaded ${en}.`),{label:en,status:Je,waitingSince:X.waiting_since??null,result:xi(X)}},[it,c,e]),Pt=N.useCallback(()=>{_.current.set(H,{nodes:he,edges:ve,workflowSettings:te,workflowName:x,activeTemplateId:S,activeWorkflowId:w,workflowDirty:C,loadedSurfaceRun:W,status:E,estimate:T})},[H,he,ve,te,x,S,w,C,W,E,T]),Rt=N.useCallback(R=>{de(R.nodes||[]),me(R.edges||[]),B(R.workflowSettings||qt),y(R.workflowName||"Untitled workflow"),m(R.activeTemplateId??null),k(R.activeWorkflowId??null),j(!!R.workflowDirty),G(R.loadedSurfaceRun||null),b(R.status||""),U(R.estimate||null),v(null),P([]),se(F=>F+1)},[me,de]),At=N.useCallback(async(R,F,Z)=>{P([]),b("Loading run...");try{const X=await An(Z,F);$(ee=>ee.map(J=>J.id===R?{...J,label:X.label,status:X.status,waitingSince:X.waitingSince,result:X.result}:J))}catch(X){if(de([]),me([]),y("Untitled workflow"),G(null),m(null),k(null),j(!1),X.unopenable){b(""),$(ee=>ee.map(J=>J.id===R?{...J,...X.unopenable,clipPath:`/dashboard/videos/${encodeURIComponent(Z)}`}:J));return}P([X.message||"Could not load workflow run."]),b("The run did not open."),$(ee=>ee.map(J=>J.id===R?{...J,loadFailed:!0}:J))}},[An,me,de]),$t=N.useCallback(R=>
14{if(R===H)return;Pt(),D(R);const F=_.current.get(R);if(F){Rt(F);return}const Z=L.find(X=>X.id===R);Z?.kind==="run"&&Z.runId&&Z.videoId&&At(Z.id,Z.runId,Z.videoId)},[At,H,Pt,Rt,L]),Jt=N.useCallback((R,F,Z,{preloaded:X=!1}={})=>{const ee=L.find(ue=>ue.kind==="run"&&ue.runId===R);if(ee){$t(ee.id);return}const J=`run_${R}`;Pt(),$(ue=>[...ue,{id:J,kind:"run",label:Z||"Workflow run",runId:R,videoId:F}]),D(J),X||At(J,R,F)},[At,$t,Pt,L]),$n=N.useCallback(R=>{_.current.delete(R),$(X=>X.filter(ee=>ee.id!==R));const F=L.find(X=>X.id===R);if(F?.kind==="run"&&F.runId===Se){const X=new URLSearchParams(o.search);X.delete("video_id"),X.delete("run_id");const ee=X.toString();r({pathname:o.pathname,search:ee?`?${ee}`:""},{replace:!0}),A("")}if(R!==H)return;D(rn);const Z=_.current.get(rn);Z?Rt(Z):(de([]),me([]),G(null),m(null),k(null),j(!1),b(""),P([]))},[H,Se,o.pathname,o.search,r,Rt,me,de,L]);if(N.useEffect(()=>{!e||!n||!jt||i.length===0||c.length===0||(A(Mt),Jt(Se,st,""))},[i.length,Mt,jt,Se,st,n,Jt,c.length,e]),N.useEffect(()=>{W?.jobId&&$(R=>R.map(F=>F.kind==="run"&&F.runId===W.jobId&&F.status!==W.status?{...F,status:W.status}:F))},[W?.jobId,W?.status]),N.useEffect(()=>{if(!e)return;const R=L.filter(ee=>ee.kind==="run"&&ee.id!==H&&ee.runId&&bi(ee.status||"QUEUED"));if(R.length===0)return;let F=!1;const Z=async()=>{for(const ee of R)try{const J=await Su(ee.runId,e);if(F||!J?.status)continue;$(ce=>ce.map(ie=>ie.id===ee.id&&ie.status!==J.status?{...ie,status:J.status,waitingSince:J.waiting_since??null,result:xi(J)}:ie));const ue=_.current.get(ee.id);ue?.loadedSurfaceRun&&_.current.set(ee.id,{...ue,loadedSurfaceRun:{...ue.loadedSurfaceRun,status:J.status}})}catch{}},X=window.setInterval(Z,g0);return()=>{F=!0,window.clearInterval(X)}},[H,L,e]),N.useEffect(()=>{if(!W||!e||!bi(W.status))return;let R=!1;const F=W.jobId,Z=W.resultVideoUrl,X=async()=>{try{const J=await ns(F,e),ue=J?.status||W.status,ce=await _i(F,ue,e);if(R)return;de(ie=>S0(ie,J?.artifacts||[],{result_video_url:Z},ce)),G(ie=>{if(!ie||ie.jobId!==F)return ie;const Ne=Yr(ce);return ie.status===ue&&ie.phaseReviewKey===Ne?ie:{...ie,status:ue,phaseReviewKey:Ne}}),ce&&b(`Review needed: ${ce.label||"Workflow step"}.`)}catch{}};X();const ee=window.setInterval(X,p0);return()=>{R=!0,window.clearInterval(ee)}},[W?.jobId,W?.resultVideoUrl,W?.status,de,e]),N.useEffect(()=>{if(jt||H!==rn||he.length>0||i.length===0||c.length===0)return;const R=c.find(F=>F.id==="generative_world")||c[0];if(R){y(R.label),m(R.id),k(null);const F=Ri(R.graph,_e,h,Ce,Ge,Ke,qe,Qe,Q,W?.jobId||"",z,K);de(F.nodes),me(F.edges),B(F.settings),j(!1),se(Z=>Z+1)}},[H,i.length,_e,jt,he.length,me,de,h,c,Ce,Ge,Ke,qe,Qe,Q,W?.jobId,z,K]),!n)return d.jsx("div",{className:"surface-view",children:d.jsx("p",{className:"surface-error",children:"Choose VFX in Studio settings to use the node editor."})});const Tt=()=>X0(he,ve,te),Dt=()=>{j(!0),m(null)},Do=R=>{(R||[]).some(F=>F.type==="remove")&&Dt(),je(R)},Oo=R=>{(R||[]).some(F=>F.type==="remove")&&Dt(),pt(R)},Ho=R=>{const F=Y0(R,he,_e,ve);if(!F){P(["Those nodes do not have a compatible free input/output connection."]);return}Dt(),me(Z=>qa({...F,id:`e-${F.source}-${F.target}-${Date.now()}`},Z))},zo=R=>{const F=he.filter(J=>J.data.surfaceType===R.type).length+1,Z=`${R.type}_${F}`,X=Object.fromEntries((R.params||[]).map(J=>[J.key,J.default])),ee={id:Z,type:R.type,params:X};Dt(),de(J=>{const ue=J.concat({id:Z,type:"surface",position:{x:140+J.length%4*320,y:140+Math.floor(J.length/4)*240},data:Zc(ee,R,h,Ce,Ge,Ke,qe,Qe,Q,W?.jobId||"",z,K)}),ce=cn(ue);return ue.map(ie=>({...ie,data:{...ie.data,graphNodes:ce}}))})},Tn=async()=>{b("Validating..."),P([]);const R=Tt(),F=sr(R),Z=Ai(R);if(Z.length>0)return P(Z),b("Graph needs changes."),!1;try{const X=await n0({graph:R,source_video_id:F||void 0},e);return P(X.errors||[]),U(X.estimate||null),b(X.valid?"Graph is valid.":"Graph needs changes."),X.valid}catch(X){return b("Validation failed."),P([X.message]),!1}},Dn=async()=>{b("Estimating..."),P([]);const R=Tt(),F=sr(R);try{const Z=await o0({graph:R,source_video_id:F||void 0},e);U(Z),b(`Estimate: ${cr(Z)}.`)}catch(Z){b("Estimate failed."),P([Z.message])}},On=async()=>{b("Saving..."),P([]);try{const R={name:x||"Untitled workflow",graph:Tt()},F=w?await t0(w,R,e):await e0(R,e);f(Z=>[F,...Z.filter(X=>X.id!==F.id)]),k(F.id),m(null),j(!1),y(F.name||x),b("Workflow saved.")}catch(R){b("Save failed."),P([R.message])}},Hn=async()=>{const R=Tt(),F=sr(R);if(!F){P(["Choose a source video in the Source Video node before running the graph."]);return}const Z=Ai(R);if(Z.length>0){P(Z),b("Graph needs changes.");return}if(C||!w&&!S){P(["Save this workflow before running it."]),b("Save workflow before running.");return}b("Submitting..."),P([]);try{const X=await r0({graph:R,source_video_id:F,...w?{workflow_id:w}:{},...!w&&S?{template_id:S}:{}
14,surface_label:x||"Untitled workflow"},e);Jt(X.job_id,F,x||"Workflow run",{preloaded:!0}),de(ee=>ee.map(J=>({...J,data:{...J.data,outputUrls:{},phaseReview:null,phaseReviewKey:""}}))),G({jobId:X.job_id,status:X.status||"QUEUED",resultVideoUrl:X.result_video_url||"",phaseReviewKey:""}),b("Workflow queued.")}catch(X){b("Submit failed."),P([X.message])}},gt=L.find(R=>R.id===H&&R.clipPath)||null;return s?d.jsx("div",{className:"surface-view surface-view--phone",children:d.jsx(u0,{workflowName:x,onWorkflowNameChange:y,templates:c,workflows:l,onChooseTemplate:R=>{y(R.label),it(R.graph,{templateId:R.id,workflowId:null})},onChooseWorkflow:R=>{y(R.name),it(R.graph,{templateId:null,workflowId:R.id})},onSave:On,tabs:L,activeTabId:H,onActivateTab:$t,onCloseTab:$n,rows:a0(he,ve).map(q0),statusText:E||cr(T),errors:I,notice:gt&&d.jsxs(d.Fragment,{children:[or," ",d.jsx(Pi,{tab:gt,size:"phone"})]}),phasedGeneration:jn,onPhasedGenerationChange:R=>B(F=>({...F,phased_generation:R})),onValidate:Tn,onEstimate:Dn,onRun:Hn})}):d.jsxs("div",{className:"surface-view",children:[d.jsxs("header",{className:"surface-header",children:[d.jsx("div",{className:"surface-heading",children:d.jsxs("label",{className:"surface-workflow-title",children:[d.jsx("span",{children:"Workflow"}),d.jsx("input",{value:x,onChange:R=>y(R.target.value)})]})}),d.jsxs("div",{className:"surface-actions",children:[d.jsx($e,{variant:"secondary",size:"compact",onClick:Tn,children:"Validate"}),d.jsx($e,{variant:"secondary",size:"compact",onClick:Dn,children:"Estimate"}),d.jsx($e,{variant:"secondary",size:"compact",onClick:On,children:"Save"}),d.jsxs("details",{className:"surface-run-dropdown",children:[d.jsx("summary",{"aria-label":"Run options",children:"Options"}),d.jsx("div",{className:"surface-run-dropdown-panel",children:d.jsxs("label",{className:"surface-workflow-setting surface-node-checkbox",children:[d.jsx("input",{type:"checkbox",checked:jn,onChange:R=>B(F=>({...F,phased_generation:R.target.checked}))}),d.jsx("span",{children:"Phased Generation"})]})})]}),d.jsx("p",{className:"surface-status","aria-live":"polite",children:E||cr(T)}),d.jsx($e,{variant:"primary",size:"compact",icon:"play",onClick:Hn,children:"Run"})]})]}),I.length>0&&d.jsx("div",{className:"surface-errors",role:"alert",children:I.map(R=>d.jsx("div",{children:R},R))}),gt&&d.jsxs("div",{className:"surface-errors",role:"alert",children:[d.jsx("div",{children:or}),d.jsx(Pi,{tab:gt})]}),d.jsx(kc,{tabs:L,activeTabId:H,onActivate:$t,onClose:$n}),d.jsxs("div",{className:"surface-shell",children:[d.jsxs("aside",{className:"surface-palette","aria-label":"Workflow tools",children:[d.jsxs("nav",{className:"surface-tool-rail",children:[d.jsxs("button",{type:"button",className:O==="templates"?"active":"","aria-label":"Open templates","aria-pressed":O==="templates",onClick:()=>Y(R=>R==="templates"?null:"templates"),children:[d.jsx(He,{name:"templates"}),d.jsx("span",{children:"Templates"})]}),d.jsxs("button",{type:"button",className:O==="nodes"?"active":"","aria-label":"Open nodes","aria-pressed":O==="nodes",onClick:()=>Y(R=>R==="nodes"?null:"nodes"),children:[d.jsx(He,{name:"nodes"}),d.jsx("span",{children:"Nodes"})]})]}),O&&d.jsxs("div",{className:"surface-palette-drawer",children:[O==="templates"&&d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Templates"}),c.map(R=>d.jsx("button",{type:"button",onClick:()=>{y(R.label),it(R.graph,{templateId:R.id,workflowId:null})},children:R.label},R.id)),l.length>0&&d.jsx("h2",{children:"Saved"}),l.slice(0,8).map(R=>d.jsx("button",{type:"button",onClick:()=>{y(R.name),it(R.graph,{templateId:null,workflowId:R.id})},children:R.name},R.id))]}),O==="nodes"&&d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Nodes"}),i.filter(R=>R.catalog_visible!==!1).map(R=>d.jsxs("button",{type:"button","aria-label":`Add ${R.label} node`,onClick:()=>zo(R),children:[d.jsx(He,{name:"plus",size:16}),R.label]},R.type))]})]})]}),d.jsx("div",{className:"surface-canvas",children:d.jsxs(xm,{nodes:he,edges:ve,nodeTypes:W0,onNodesChange:Do,onEdgesChange:Oo,onConnect:Ho,onSelectionChange:({nodes:R})=>v(R[0]?.id||null),onNodesDelete:R=>R.some(F=>F.id===g)&&v(null),deleteKeyCode:["Backspace","Delete"],fitView:!0,fitViewOptions:{padding:.18,maxZoom:.82},minZoom:.15,onInit:Ze,children:[d.jsx(Cm,{}),d.jsx(Ym,{pannable:!0,zoomable:!0,position:"bottom-right",maskStrokeWidth:1,nodeColor:R=>R.data?.phaseReview?ku("signal"):void 0}),d.jsx(Am,{position:"bottom-right"})]},oe)})]})]})}export{gy as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.