ledung 1.5.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ import{a as e,c as t,d as n,f as r,i,l as a,o,r as s,s as c,t as l,u}from"./index-DzZQ49cI.js";var d=r(u(),1),f=e();function p(e){if(typeof e==`string`||typeof e==`number`)return``+e;let t=``;if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=p(e[n]))!==``&&(t+=(t&&` `)+r);else for(let n in e)e[n]&&(t+=(t&&` `)+n);return t}var m={value:()=>{}};function h(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new g(n)}function g(e){this._=e}function _(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}g.prototype=h.prototype={constructor:g,on:function(e,t){var n=this._,r=_(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=v(n[i],e.name)))return i}else{if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=y(n[i],e.name,t);else if(t==null)for(i in n)n[i]=y(n[i],e.name,null);return this}},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new g(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function v(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function y(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=m,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var b={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function x(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),b.hasOwnProperty(t)?{space:b[t],local:e}:e}function S(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function C(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function w(e){var t=x(e);return(t.local?C:S)(t)}function T(){}function E(e){return e==null?T:function(){return this.querySelector(e)}}function D(e){typeof e!=`function`&&(e=E(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new Et(r,this._parents)}function O(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function k(){return[]}function A(e){return e==null?k:function(){return this.querySelectorAll(e)}}function j(e){return function(){return O(e.apply(this,arguments))}}function M(e){e=typeof e==`function`?j(e):A(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new Et(r,i)}function N(e){return function(){return this.matches(e)}}function P(e){return function(t){return t.matches(e)}}var F=Array.prototype.find;function I(e){return function(){return F.call(this.children,e)}}function L(){return this.firstElementChild}function R(e){return this.select(e==null?L:I(typeof e==`function`?e:P(e)))}var z=Array.prototype.filter;function B(){return Array.from(this.children)}function V(e){return function(){return z.call(this.children,e)}}function H(e){return this.selectAll(e==null?B:V(typeof e==`function`?e:P(e)))}function ee(e){typeof e!=`function`&&(e=N(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new Et(r,this._parents)}function te(e){return Array(e.length)}function ne(){return new Et(this._enter||this._groups.map(te),this._parents)}function re(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}re.prototype={constructor:re,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 ie(e){return function(){return e}}function ae(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new re(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function oe(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new re(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function se(e){return e.__data__}function ce(e,t){if(!arguments.length)return Array.from(this,se);var n=t?oe:ae,r=this._parents,i=this._groups;typeof e!=`function`&&(e=ie(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=le(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,y,b;_<m;++_)if(y=h[_]){for(_>=v&&(v=_+1);!(b=g[v])&&++v<m;);y._next=b||null}}return o=new Et(o,r),o._enter=s,o._exit=c,o}function le(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function ue(){return new Et(this._exit||this._groups.map(te),this._parents)}function de(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function fe(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new Et(s,this._parents)}function pe(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function me(e){e||=he;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new Et(i,this._parents).order()}function he(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function ge(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function _e(){return Array.from(this)}function ve(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function ye(){let e=0;for(let t of this)++e;return e}function be(){return!this.node()}function xe(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function Se(e){return function(){this.removeAttribute(e)}}function Ce(e){return function(){this.removeAttributeNS(e.space,e.local)}}function we(e,t){return function(){this.setAttribute(e,t)}}function Te(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Ee(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function De(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 Oe(e,t){var n=x(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?Ce:Se:typeof t==`function`?n.local?De:Ee:n.local?Te:we)(n,t))}function ke(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Ae(e){return function(){this.style.removeProperty(e)}}function je(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Me(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function Ne(e,t,n){return arguments.length>1?this.each((t==null?Ae:typeof t==`function`?Me:je)(e,t,n??``)):Pe(this.node(),e)}function Pe(e,t){return e.style.getPropertyValue(t)||ke(e).getComputedStyle(e,null).getPropertyValue(t)}function Fe(e){return function(){delete this[e]}}function Ie(e,t){return function(){this[e]=t}}function Le(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Re(e,t){return arguments.length>1?this.each((t==null?Fe:typeof t==`function`?Le:Ie)(e,t)):this.node()[e]}function ze(e){return e.trim().split(/^|\s+/)}function Be(e){return e.classList||new Ve(e)}function Ve(e){this._node=e,this._names=ze(e.getAttribute(`class`)||``)}Ve.prototype={add:function(e){this._names.indexOf(e)<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 He(e,t){for(var n=Be(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function Ue(e,t){for(var n=Be(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function We(e){return function(){He(this,e)}}function Ge(e){return function(){Ue(this,e)}}function Ke(e,t){return function(){(t.apply(this,arguments)?He:Ue)(this,e)}}function qe(e,t){var n=ze(e+``);if(arguments.length<2){for(var r=Be(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?Ke:t?We:Ge)(n,t))}function Je(){this.textContent=``}function Ye(e){return function(){this.textContent=e}}function Xe(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function Ze(e){return arguments.length?this.each(e==null?Je:(typeof e==`function`?Xe:Ye)(e)):this.node().textContent}function Qe(){this.innerHTML=``}function $e(e){return function(){this.innerHTML=e}}function et(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function tt(e){return arguments.length?this.each(e==null?Qe:(typeof e==`function`?et:$e)(e)):this.node().innerHTML}function nt(){this.nextSibling&&this.parentNode.appendChild(this)}function rt(){return this.each(nt)}function it(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function at(){return this.each(it)}function ot(e){var t=typeof e==`function`?e:w(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function st(){return null}function ct(e,t){var n=typeof e==`function`?e:w(e),r=t==null?st:typeof t==`function`?t:E(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function lt(){var e=this.parentNode;e&&e.removeChild(this)}function ut(){return this.each(lt)}function dt(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function ft(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function pt(e){return this.select(e?ft:dt)}function mt(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function ht(e){return function(t){e.call(this,t,this.__data__)}}function gt(e){return e.trim().split(/^|\s+/).map(function(e){var t=``,n=e.indexOf(`.`);return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function _t(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function vt(e,t,n){return function(){var r=this.__on,i,a=ht(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function yt(e,t,n){var r=gt(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}}else{for(s=t?vt:_t,i=0;i<a;++i)this.each(s(r[i],t,n));return this}}function bt(e,t,n){var r=ke(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function xt(e,t){return function(){return bt(this,e,t)}}function St(e,t){return function(){return bt(this,e,t.apply(this,arguments))}}function Ct(e,t){return this.each((typeof t==`function`?St:xt)(e,t))}function*wt(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var Tt=[null];function Et(e,t){this._groups=e,this._parents=t}function Dt(){return new Et([[document.documentElement]],Tt)}function Ot(){return this}Et.prototype=Dt.prototype={constructor:Et,select:D,selectAll:M,selectChild:R,selectChildren:H,filter:ee,data:ce,enter:ne,exit:ue,join:de,merge:fe,selection:Ot,order:pe,sort:me,call:ge,nodes:_e,node:ve,size:ye,empty:be,each:xe,attr:Oe,style:Ne,property:Re,classed:qe,text:Ze,html:tt,raise:rt,lower:at,append:ot,insert:ct,remove:ut,clone:pt,datum:mt,on:yt,dispatch:Ct,[Symbol.iterator]:wt};function kt(e){return typeof e==`string`?new Et([[document.querySelector(e)]],[document.documentElement]):new Et([[e]],Tt)}function At(e){let t;for(;t=e.sourceEvent;)e=t;return e}function jt(e,t){if(e=At(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}var Mt={passive:!1},Nt={capture:!0,passive:!1};function Pt(e){e.stopImmediatePropagation()}function Ft(e){e.preventDefault(),e.stopImmediatePropagation()}function It(e){var t=e.document.documentElement,n=kt(e).on(`dragstart.drag`,Ft,Nt);`onselectstart`in t?n.on(`selectstart.drag`,Ft,Nt):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect=`none`)}function Lt(e,t){var n=e.document.documentElement,r=kt(e).on(`dragstart.drag`,null);t&&(r.on(`click.drag`,Ft,Nt),setTimeout(function(){r.on(`click.drag`,null)},0)),`onselectstart`in n?r.on(`selectstart.drag`,null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}var Rt=e=>()=>e;function zt(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:a,x:o,y:s,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:s,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}zt.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Bt(e){return!e.ctrlKey&&!e.button}function Vt(){return this.parentNode}function Ht(e,t){return t??{x:e.x,y:e.y}}function Ut(){return navigator.maxTouchPoints||`ontouchstart`in this}function Wt(){var e=Bt,t=Vt,n=Ht,r=Ut,i={},a=h(`start`,`drag`,`end`),o=0,s,c,l,u,d=0;function f(e){e.on(`mousedown.drag`,p).filter(r).on(`touchstart.drag`,_).on(`touchmove.drag`,v,Mt).on(`touchend.drag touchcancel.drag`,y).style(`touch-action`,`none`).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}function p(n,r){if(!u&&e.call(this,n,r)){var i=b(this,t.call(this,n,r),n,r,`mouse`);i&&(kt(n.view).on(`mousemove.drag`,m,Nt).on(`mouseup.drag`,g,Nt),It(n.view),Pt(n),l=!1,s=n.clientX,c=n.clientY,i(`start`,n))}}function m(e){if(Ft(e),!l){var t=e.clientX-s,n=e.clientY-c;l=t*t+n*n>d}i.mouse(`drag`,e)}function g(e){kt(e.view).on(`mousemove.drag mouseup.drag`,null),Lt(e.view,l),Ft(e),i.mouse(`end`,e)}function _(n,r){if(e.call(this,n,r))for(var i=n.changedTouches,a=t.call(this,n,r),o=i.length,s=0,c;s<o;++s)(c=b(this,a,n,r,i[s].identifier,i[s]))&&(Pt(n),c(`start`,n,i[s]))}function v(e){for(var t=e.changedTouches,n=t.length,r=0,a;r<n;++r)(a=i[t[r].identifier])&&(Ft(e),a(`drag`,e,t[r]))}function y(e){var t=e.changedTouches,n=t.length,r,a;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),r=0;r<n;++r)(a=i[t[r].identifier])&&(Pt(e),a(`end`,e,t[r]))}function b(e,t,r,s,c,l){var u=a.copy(),d=jt(l||r,t),p,m,h;if((h=n.call(e,new zt(`beforestart`,{sourceEvent:r,target:f,identifier:c,active:o,x:d[0],y:d[1],dx:0,dy:0,dispatch:u}),s))!=null)return p=h.x-d[0]||0,m=h.y-d[1]||0,function n(r,a,l){var g=d,_;switch(r){case`start`:i[c]=n,_=o++;break;case`end`:delete i[c],--o;case`drag`:d=jt(l||a,t),_=o}u.call(r,e,new zt(r,{sourceEvent:a,subject:h,target:f,identifier:c,active:_,x:d[0]+p,y:d[1]+m,dx:d[0]-g[0],dy:d[1]-g[1],dispatch:u}),s)}}return f.filter=function(t){return arguments.length?(e=typeof t==`function`?t:Rt(!!t),f):e},f.container=function(e){return arguments.length?(t=typeof e==`function`?e:Rt(e),f):t},f.subject=function(e){return arguments.length?(n=typeof e==`function`?e:Rt(e),f):n},f.touchable=function(e){return arguments.length?(r=typeof e==`function`?e:Rt(!!e),f):r},f.on=function(){var e=a.on.apply(a,arguments);return e===a?f:e},f.clickDistance=function(e){return arguments.length?(d=(e=+e)*e,f):Math.sqrt(d)},f}function Gt(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Kt(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function qt(){}var Jt=.7,Yt=1/Jt,Xt=`\\s*([+-]?\\d+)\\s*`,Zt=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,Qt=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,$t=/^#([0-9a-f]{3,8})$/,en=RegExp(`^rgb\\(${Xt},${Xt},${Xt}\\)$`),tn=RegExp(`^rgb\\(${Qt},${Qt},${Qt}\\)$`),nn=RegExp(`^rgba\\(${Xt},${Xt},${Xt},${Zt}\\)$`),rn=RegExp(`^rgba\\(${Qt},${Qt},${Qt},${Zt}\\)$`),an=RegExp(`^hsl\\(${Zt},${Qt},${Qt}\\)$`),on=RegExp(`^hsla\\(${Zt},${Qt},${Qt},${Zt}\\)$`),sn={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};Gt(qt,fn,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:cn,formatHex:cn,formatHex8:ln,formatHsl:un,formatRgb:dn,toString:dn});function cn(){return this.rgb().formatHex()}function ln(){return this.rgb().formatHex8()}function un(){return Tn(this).formatHsl()}function dn(){return this.rgb().formatRgb()}function fn(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=$t.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?pn(t):n===3?new _n(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?mn(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?mn(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=en.exec(e))?new _n(t[1],t[2],t[3],1):(t=tn.exec(e))?new _n(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=nn.exec(e))?mn(t[1],t[2],t[3],t[4]):(t=rn.exec(e))?mn(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=an.exec(e))?wn(t[1],t[2]/100,t[3]/100,1):(t=on.exec(e))?wn(t[1],t[2]/100,t[3]/100,t[4]):sn.hasOwnProperty(e)?pn(sn[e]):e===`transparent`?new _n(NaN,NaN,NaN,0):null}function pn(e){return new _n(e>>16&255,e>>8&255,e&255,1)}function mn(e,t,n,r){return r<=0&&(e=t=n=NaN),new _n(e,t,n,r)}function hn(e){return e instanceof qt||(e=fn(e)),e?(e=e.rgb(),new _n(e.r,e.g,e.b,e.opacity)):new _n}function gn(e,t,n,r){return arguments.length===1?hn(e):new _n(e,t,n,r??1)}function _n(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Gt(_n,gn,Kt(qt,{brighter(e){return e=e==null?Yt:Yt**+e,new _n(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Jt:Jt**+e,new _n(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new _n(Sn(this.r),Sn(this.g),Sn(this.b),xn(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:vn,formatHex:vn,formatHex8:yn,formatRgb:bn,toString:bn}));function vn(){return`#${Cn(this.r)}${Cn(this.g)}${Cn(this.b)}`}function yn(){return`#${Cn(this.r)}${Cn(this.g)}${Cn(this.b)}${Cn((isNaN(this.opacity)?1:this.opacity)*255)}`}function bn(){let e=xn(this.opacity);return`${e===1?`rgb(`:`rgba(`}${Sn(this.r)}, ${Sn(this.g)}, ${Sn(this.b)}${e===1?`)`:`, ${e})`}`}function xn(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Sn(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Cn(e){return e=Sn(e),(e<16?`0`:``)+e.toString(16)}function wn(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Dn(e,t,n,r)}function Tn(e){if(e instanceof Dn)return new Dn(e.h,e.s,e.l,e.opacity);if(e instanceof qt||(e=fn(e)),!e)return new Dn;if(e instanceof Dn)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new Dn(o,s,c,e.opacity)}function En(e,t,n,r){return arguments.length===1?Tn(e):new Dn(e,t,n,r??1)}function Dn(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Gt(Dn,En,Kt(qt,{brighter(e){return e=e==null?Yt:Yt**+e,new Dn(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Jt:Jt**+e,new Dn(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,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new _n(An(e>=240?e-240:e+120,i,r),An(e,i,r),An(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new Dn(On(this.h),kn(this.s),kn(this.l),xn(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(){let e=xn(this.opacity);return`${e===1?`hsl(`:`hsla(`}${On(this.h)}, ${kn(this.s)*100}%, ${kn(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function On(e){return e=(e||0)%360,e<0?e+360:e}function kn(e){return Math.max(0,Math.min(1,e||0))}function An(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var jn=e=>()=>e;function Mn(e,t){return function(n){return e+n*t}}function Nn(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function Pn(e){return(e=+e)==1?Fn:function(t,n){return n-t?Nn(t,n,e):jn(isNaN(t)?n:t)}}function Fn(e,t){var n=t-e;return n?Mn(e,n):jn(isNaN(e)?t:e)}var In=(function e(t){var n=Pn(t);function r(e,t){var r=n((e=gn(e)).r,(t=gn(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=Fn(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function Ln(e,t){t||=[];var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=e[i]*(1-a)+t[i]*a;return r}}function Rn(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function zn(e,t){for(var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=Array(r),a=Array(n),o=0;o<r;++o)i[o]=Jn(e[o],t[o]);for(;o<n;++o)a[o]=t[o];return function(e){for(o=0;o<r;++o)a[o]=i[o](e);return a}}function Bn(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function Vn(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Hn(e,t){var n={},r={},i;for(i in(typeof e!=`object`||!e)&&(e={}),(typeof t!=`object`||!t)&&(t={}),t)i in e?n[i]=Jn(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var Un=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Wn=new RegExp(Un.source,`g`);function Gn(e){return function(){return e}}function Kn(e){return function(t){return e(t)+``}}function qn(e,t){var n=Un.lastIndex=Wn.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=Un.exec(e))&&(i=Wn.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:Vn(r,i)})),n=Wn.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?Kn(c[0].x):Gn(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}function Jn(e,t){var n=typeof t,r;return t==null||n===`boolean`?jn(t):(n===`number`?Vn:n===`string`?(r=fn(t))?(t=r,In):qn:t instanceof fn?In:t instanceof Date?Bn:Rn(t)?Ln:Array.isArray(t)?zn:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?Hn:Vn)(e,t)}var Yn=180/Math.PI,Xn={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Zn(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*Yn,skewX:Math.atan(c)*Yn,scaleX:o,scaleY:s}}var Qn;function $n(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?Xn:Zn(t.a,t.b,t.c,t.d,t.e,t.f)}function er(e){return e==null||(Qn||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),Qn.setAttribute(`transform`,e),!(e=Qn.transform.baseVal.consolidate()))?Xn:(e=e.matrix,Zn(e.a,e.b,e.c,e.d,e.e,e.f))}function tr(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:Vn(e,i)},{i:c-2,x:Vn(r,a)})}else(i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:Vn(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:Vn(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:Vn(e,n)},{i:s-2,x:Vn(t,r)})}else(n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var nr=tr($n,`px, `,`px)`,`deg)`),rr=tr(er,`, `,`)`,`)`),ir=1e-12;function ar(e){return((e=Math.exp(e))+1/e)/2}function or(e){return((e=Math.exp(e))-1/e)/2}function sr(e){return((e=Math.exp(2*e))-1)/(e+1)}var cr=(function e(t,n,r){function i(e,i){var a=e[0],o=e[1],s=e[2],c=i[0],l=i[1],u=i[2],d=c-a,f=l-o,p=d*d+f*f,m,h;if(p<ir)h=Math.log(u/s)/t,m=function(e){return[a+e*d,o+e*f,s*Math.exp(t*e*h)]};else{var g=Math.sqrt(p),_=(u*u-s*s+r*p)/(2*s*n*g),v=(u*u-s*s-r*p)/(2*u*n*g),y=Math.log(Math.sqrt(_*_+1)-_);h=(Math.log(Math.sqrt(v*v+1)-v)-y)/t,m=function(e){var r=e*h,i=ar(y),c=s/(n*g)*(i*sr(t*r+y)-or(y));return[a+c*d,o+c*f,s*i/ar(t*r+y)]}}return m.duration=h*1e3*t/Math.SQRT2,m}return i.rho=function(t){var n=Math.max(.001,+t),r=n*n;return e(n,r,r*r)},i})(Math.SQRT2,2,4),lr=0,ur=0,dr=0,fr=1e3,pr,mr,hr=0,gr=0,_r=0,vr=typeof performance==`object`&&performance.now?performance:Date,yr=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function br(){return gr||=(yr(xr),vr.now()+_r)}function xr(){gr=0}function Sr(){this._call=this._time=this._next=null}Sr.prototype=Cr.prototype={constructor:Sr,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?br():+n)+(t==null?0:+t),!this._next&&mr!==this&&(mr?mr._next=this:pr=this,mr=this),this._call=e,this._time=n,Or()},stop:function(){this._call&&(this._call=null,this._time=1/0,Or())}};function Cr(e,t,n){var r=new Sr;return r.restart(e,t,n),r}function wr(){br(),++lr;for(var e=pr,t;e;)(t=gr-e._time)>=0&&e._call.call(void 0,t),e=e._next;--lr}function Tr(){gr=(hr=vr.now())+_r,lr=ur=0;try{wr()}finally{lr=0,Dr(),gr=0}}function Er(){var e=vr.now(),t=e-hr;t>fr&&(_r-=t,hr=e)}function Dr(){for(var e,t=pr,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:pr=n);mr=e,Or(r)}function Or(e){lr||(ur&&=clearTimeout(ur),e-gr>24?(e<1/0&&(ur=setTimeout(Tr,e-vr.now()-_r)),dr&&=clearInterval(dr)):(dr||=(hr=vr.now(),setInterval(Er,fr)),lr=1,yr(Tr)))}function kr(e,t,n){var r=new Sr;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var Ar=h(`start`,`end`,`cancel`,`interrupt`),jr=[];function Mr(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Ir(e,n,{name:t,index:r,group:i,on:Ar,tween:jr,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function Nr(e,t){var n=Fr(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function Pr(e,t){var n=Fr(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function Fr(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function Ir(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Cr(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return kr(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(kr(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function Lr(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n)(r=n[o]).name===t?(i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]):a=!1;a&&delete e.__transition}}function Rr(e){return this.each(function(){Lr(this,e)})}function zr(e,t){var n,r;return function(){var i=Pr(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function Br(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=Pr(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function Vr(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=Fr(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?zr:Br)(n,e,t))}function Hr(e,t,n){var r=e._id;return e.each(function(){var e=Pr(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return Fr(e,r).value[t]}}function Ur(e,t){var n;return(typeof t==`number`?Vn:t instanceof fn?In:(n=fn(t))?(t=n,In):qn)(e,t)}function Wr(e){return function(){this.removeAttribute(e)}}function Gr(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Kr(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function qr(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function Jr(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function Yr(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function Xr(e,t){var n=x(e),r=n===`transform`?rr:Ur;return this.attrTween(e,typeof t==`function`?(n.local?Yr:Jr)(n,r,Hr(this,`attr.`+e,t)):t==null?(n.local?Gr:Wr)(n):(n.local?qr:Kr)(n,r,t))}function Zr(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Qr(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function $r(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Qr(e,i)),n}return i._value=t,i}function ei(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&Zr(e,i)),n}return i._value=t,i}function ti(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 Error();var r=x(e);return this.tween(n,(r.local?$r:ei)(r,t))}function ni(e,t){return function(){Nr(this,e).delay=+t.apply(this,arguments)}}function ri(e,t){return t=+t,function(){Nr(this,e).delay=t}}function ii(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?ni:ri)(t,e)):Fr(this.node(),t).delay}function ai(e,t){return function(){Pr(this,e).duration=+t.apply(this,arguments)}}function oi(e,t){return t=+t,function(){Pr(this,e).duration=t}}function si(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?ai:oi)(t,e)):Fr(this.node(),t).duration}function ci(e,t){if(typeof t!=`function`)throw Error();return function(){Pr(this,e).ease=t}}function li(e){var t=this._id;return arguments.length?this.each(ci(t,e)):Fr(this.node(),t).ease}function ui(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();Pr(this,e).ease=n}}function di(e){if(typeof e!=`function`)throw Error();return this.each(ui(this._id,e))}function fi(e){typeof e!=`function`&&(e=N(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new Vi(r,this._parents,this._name,this._id)}function pi(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new Vi(o,this._parents,this._name,this._id)}function mi(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function hi(e,t,n){var r,i,a=mi(t)?Nr:Pr;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function gi(e,t){var n=this._id;return arguments.length<2?Fr(this.node(),n).on.on(e):this.each(hi(n,e,t))}function _i(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function vi(){return this.on(`end.remove`,_i(this._id))}function yi(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=E(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,Mr(l[f],t,n,f,l,Fr(u,n)));return new Vi(a,this._parents,t,n)}function bi(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=A(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=Fr(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&Mr(p,t,n,h,f,m);a.push(f),o.push(u)}return new Vi(a,o,t,n)}var xi=Dt.prototype.constructor;function Si(){return new xi(this._groups,this._parents)}function Ci(e,t){var n,r,i;return function(){var a=Pe(this,e),o=(this.style.removeProperty(e),Pe(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function wi(e){return function(){this.style.removeProperty(e)}}function Ti(e,t,n){var r,i=n+``,a;return function(){var o=Pe(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function Ei(e,t,n){var r,i,a;return function(){var o=Pe(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),Pe(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function Di(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=Pr(this,e),l=c.on,u=c.value[a]==null?s||=wi(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function Oi(e,t,n){var r=(e+=``)==`transform`?nr:Ur;return t==null?this.styleTween(e,Ci(e,r)).on(`end.style.`+e,wi(e)):typeof t==`function`?this.styleTween(e,Ei(e,r,Hr(this,`style.`+e,t))).each(Di(this._id,e)):this.styleTween(e,Ti(e,r,t),n).on(`end.style.`+e,null)}function ki(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Ai(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&ki(e,a,n)),r}return a._value=t,a}function ji(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,Ai(e,t,n??``))}function Mi(e){return function(){this.textContent=e}}function Ni(e){return function(){var t=e(this);this.textContent=t??``}}function Pi(e){return this.tween(`text`,typeof e==`function`?Ni(Hr(this,`text`,e)):Mi(e==null?``:e+``))}function Fi(e){return function(t){this.textContent=e.call(this,t)}}function Ii(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&Fi(r)),t}return r._value=e,r}function Li(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 Error();return this.tween(t,Ii(e))}function Ri(){for(var e=this._name,t=this._id,n=Hi(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=Fr(c,t);Mr(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Vi(r,this._parents,e,n)}function zi(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=Pr(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var Bi=0;function Vi(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function Hi(){return++Bi}var Ui=Dt.prototype;Vi.prototype={constructor:Vi,select:yi,selectAll:bi,selectChild:Ui.selectChild,selectChildren:Ui.selectChildren,filter:fi,merge:pi,selection:Si,transition:Ri,call:Ui.call,nodes:Ui.nodes,node:Ui.node,size:Ui.size,empty:Ui.empty,each:Ui.each,on:gi,attr:Xr,attrTween:ti,style:Oi,styleTween:ji,text:Pi,textTween:Li,remove:vi,tween:Vr,delay:ii,duration:si,ease:li,easeVarying:di,end:zi,[Symbol.iterator]:Ui[Symbol.iterator]};function Wi(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Gi={time:null,delay:0,duration:250,ease:Wi};function Ki(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function qi(e){var t,n;e instanceof Vi?(t=e._id,e=e._name):(t=Hi(),(n=Gi).time=br(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&Mr(c,e,t,l,o,n||Ki(c,t));return new Vi(r,this._parents,e,t)}Dt.prototype.interrupt=Rr,Dt.prototype.transition=qi;var Ji=e=>()=>e;function Yi(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){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:r,enumerable:!0,configurable:!0},_:{value:i}})}function Xi(e,t,n){this.k=e,this.x=t,this.y=n}Xi.prototype={constructor:Xi,scale:function(e){return e===1?this:new Xi(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Xi(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 Zi=new Xi(1,0,0);Qi.prototype=Xi.prototype;function Qi(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Zi;return e.__zoom}function $i(e){e.stopImmediatePropagation()}function ea(e){e.preventDefault(),e.stopImmediatePropagation()}function ta(e){return(!e.ctrlKey||e.type===`wheel`)&&!e.button}function na(){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 ra(){return this.__zoom||Zi}function ia(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function aa(){return navigator.maxTouchPoints||`ontouchstart`in this}function oa(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function sa(){var e=ta,t=na,n=oa,r=ia,i=aa,a=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],s=250,c=cr,l=h(`start`,`zoom`,`end`),u,d,f,p=500,m=150,g=0,_=10;function v(e){e.property(`__zoom`,ra).on(`wheel.zoom`,T,{passive:!1}).on(`mousedown.zoom`,E).on(`dblclick.zoom`,D).filter(i).on(`touchstart.zoom`,O).on(`touchmove.zoom`,k).on(`touchend.zoom touchcancel.zoom`,A).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}v.transform=function(e,t,n,r){var i=e.selection?e.selection():e;i.property(`__zoom`,ra),e===i?i.interrupt().each(function(){C(this,arguments).event(r).start().zoom(null,typeof t==`function`?t.apply(this,arguments):t).end()}):S(e,t,n,r)},v.scaleBy=function(e,t,n,r){v.scaleTo(e,function(){return this.__zoom.k*(typeof t==`function`?t.apply(this,arguments):t)},n,r)},v.scaleTo=function(e,r,i,a){v.transform(e,function(){var e=t.apply(this,arguments),a=this.__zoom,s=i==null?x(e):typeof i==`function`?i.apply(this,arguments):i,c=a.invert(s),l=typeof r==`function`?r.apply(this,arguments):r;return n(b(y(a,l),s,c),e,o)},i,a)},v.translateBy=function(e,r,i,a){v.transform(e,function(){return n(this.__zoom.translate(typeof r==`function`?r.apply(this,arguments):r,typeof i==`function`?i.apply(this,arguments):i),t.apply(this,arguments),o)},null,a)},v.translateTo=function(e,r,i,a,s){v.transform(e,function(){var e=t.apply(this,arguments),s=this.__zoom,c=a==null?x(e):typeof a==`function`?a.apply(this,arguments):a;return n(Zi.translate(c[0],c[1]).scale(s.k).translate(typeof r==`function`?-r.apply(this,arguments):-r,typeof i==`function`?-i.apply(this,arguments):-i),e,o)},a,s)};function y(e,t){return t=Math.max(a[0],Math.min(a[1],t)),t===e.k?e:new Xi(t,e.x,e.y)}function b(e,t,n){var r=t[0]-n[0]*e.k,i=t[1]-n[1]*e.k;return r===e.x&&i===e.y?e:new Xi(e.k,r,i)}function x(e){return[(+e[0][0]+ +e[1][0])/2,(+e[0][1]+ +e[1][1])/2]}function S(e,n,r,i){e.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 e=this,a=arguments,o=C(e,a).event(i),s=t.apply(e,a),l=r==null?x(s):typeof r==`function`?r.apply(e,a):r,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),d=e.__zoom,f=typeof n==`function`?n.apply(e,a):n,p=c(d.invert(l).concat(u/d.k),f.invert(l).concat(u/f.k));return function(e){if(e===1)e=f;else{var t=p(e),n=u/t[2];e=new Xi(n,l[0]-t[0]*n,l[1]-t[1]*n)}o.zoom(null,e)}})}function C(e,t,n){return!n&&e.__zooming||new w(e,t)}function w(e,n){this.that=e,this.args=n,this.active=0,this.sourceEvent=null,this.extent=t.apply(e,n),this.taps=0}w.prototype={event:function(e){return e&&(this.sourceEvent=e),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit(`start`)),this},zoom:function(e,t){return this.mouse&&e!==`mouse`&&(this.mouse[1]=t.invert(this.mouse[0])),this.touch0&&e!==`touch`&&(this.touch0[1]=t.invert(this.touch0[0])),this.touch1&&e!==`touch`&&(this.touch1[1]=t.invert(this.touch1[0])),this.that.__zoom=t,this.emit(`zoom`),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit(`end`)),this},emit:function(e){var t=kt(this.that).datum();l.call(e,this.that,new Yi(e,{sourceEvent:this.sourceEvent,target:v,type:e,transform:this.that.__zoom,dispatch:l}),t)}};function T(t,...i){if(!e.apply(this,arguments))return;var s=C(this,i).event(t),c=this.__zoom,l=Math.max(a[0],Math.min(a[1],c.k*2**r.apply(this,arguments))),u=jt(t);if(s.wheel)(s.mouse[0][0]!==u[0]||s.mouse[0][1]!==u[1])&&(s.mouse[1]=c.invert(s.mouse[0]=u)),clearTimeout(s.wheel);else if(c.k===l)return;else s.mouse=[u,c.invert(u)],Lr(this),s.start();ea(t),s.wheel=setTimeout(d,m),s.zoom(`mouse`,n(b(y(c,l),s.mouse[0],s.mouse[1]),s.extent,o));function d(){s.wheel=null,s.end()}}function E(t,...r){if(f||!e.apply(this,arguments))return;var i=t.currentTarget,a=C(this,r,!0).event(t),s=kt(t.view).on(`mousemove.zoom`,d,!0).on(`mouseup.zoom`,p,!0),c=jt(t,i),l=t.clientX,u=t.clientY;It(t.view),$i(t),a.mouse=[c,this.__zoom.invert(c)],Lr(this),a.start();function d(e){if(ea(e),!a.moved){var t=e.clientX-l,r=e.clientY-u;a.moved=t*t+r*r>g}a.event(e).zoom(`mouse`,n(b(a.that.__zoom,a.mouse[0]=jt(e,i),a.mouse[1]),a.extent,o))}function p(e){s.on(`mousemove.zoom mouseup.zoom`,null),Lt(e.view,a.moved),ea(e),a.event(e).end()}}function D(r,...i){if(e.apply(this,arguments)){var a=this.__zoom,c=jt(r.changedTouches?r.changedTouches[0]:r,this),l=a.invert(c),u=a.k*(r.shiftKey?.5:2),d=n(b(y(a,u),c,l),t.apply(this,i),o);ea(r),s>0?kt(this).transition().duration(s).call(S,d,c,r):kt(this).call(v.transform,d,c,r)}}function O(t,...n){if(e.apply(this,arguments)){var r=t.touches,i=r.length,a=C(this,n,t.changedTouches.length===i).event(t),o,s,c,l;for($i(t),s=0;s<i;++s)c=r[s],l=jt(c,this),l=[l,this.__zoom.invert(l),c.identifier],a.touch0?!a.touch1&&a.touch0[2]!==l[2]&&(a.touch1=l,a.taps=0):(a.touch0=l,o=!0,a.taps=1+!!u);u&&=clearTimeout(u),o&&(a.taps<2&&(d=l[0],u=setTimeout(function(){u=null},p)),Lr(this),a.start())}}function k(e,...t){if(this.__zooming){var r=C(this,t).event(e),i=e.changedTouches,a=i.length,s,c,l,u;for(ea(e),s=0;s<a;++s)c=i[s],l=jt(c,this),r.touch0&&r.touch0[2]===c.identifier?r.touch0[0]=l:r.touch1&&r.touch1[2]===c.identifier&&(r.touch1[0]=l);if(c=r.that.__zoom,r.touch1){var d=r.touch0[0],f=r.touch0[1],p=r.touch1[0],m=r.touch1[1],h=(h=p[0]-d[0])*h+(h=p[1]-d[1])*h,g=(g=m[0]-f[0])*g+(g=m[1]-f[1])*g;c=y(c,Math.sqrt(h/g)),l=[(d[0]+p[0])/2,(d[1]+p[1])/2],u=[(f[0]+m[0])/2,(f[1]+m[1])/2]}else if(r.touch0)l=r.touch0[0],u=r.touch0[1];else return;r.zoom(`touch`,n(b(c,l,u),r.extent,o))}}function A(e,...t){if(this.__zooming){var n=C(this,t).event(e),r=e.changedTouches,i=r.length,a,o;for($i(e),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),a=0;a<i;++a)o=r[a],n.touch0&&n.touch0[2]===o.identifier?delete n.touch0:n.touch1&&n.touch1[2]===o.identifier&&delete n.touch1;if(n.touch1&&!n.touch0&&(n.touch0=n.touch1,delete n.touch1),n.touch0)n.touch0[1]=this.__zoom.invert(n.touch0[0]);else if(n.end(),n.taps===2&&(o=jt(o,this),Math.hypot(d[0]-o[0],d[1]-o[1])<_)){var s=kt(this).on(`dblclick.zoom`);s&&s.apply(this,arguments)}}}return v.wheelDelta=function(e){return arguments.length?(r=typeof e==`function`?e:Ji(+e),v):r},v.filter=function(t){return arguments.length?(e=typeof t==`function`?t:Ji(!!t),v):e},v.touchable=function(e){return arguments.length?(i=typeof e==`function`?e:Ji(!!e),v):i},v.extent=function(e){return arguments.length?(t=typeof e==`function`?e:Ji([[+e[0][0],+e[0][1]],[+e[1][0],+e[1][1]]]),v):t},v.scaleExtent=function(e){return arguments.length?(a[0]=+e[0],a[1]=+e[1],v):[a[0],a[1]]},v.translateExtent=function(e){return arguments.length?(o[0][0]=+e[0][0],o[1][0]=+e[1][0],o[0][1]=+e[0][1],o[1][1]=+e[1][1],v):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},v.constrain=function(e){return arguments.length?(n=e,v):n},v.duration=function(e){return arguments.length?(s=+e,v):s},v.interpolate=function(e){return arguments.length?(c=e,v):c},v.on=function(){var e=l.on.apply(l,arguments);return e===l?v:e},v.clickDistance=function(e){return arguments.length?(g=(e=+e)*e,v):Math.sqrt(g)},v.tapDistance=function(e){return arguments.length?(_=+e,v):_},v}var ca={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:r})=>`Couldn't create edge for ${e} handle id: "${e===`source`?n:r}", edge id: ${t}.`,error010:()=>`Handle: No node id found. Make sure to only use a Handle inside a custom Node.`,error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e=`react`)=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>`useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.`,error015:()=>`It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.`,error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},la=[[-1/0,-1/0],[1/0,1/0]],ua=[`Enter`,` `,`Escape`],da={"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`},fa;(function(e){e.Strict=`strict`,e.Loose=`loose`})(fa||={});var pa;(function(e){e.Free=`free`,e.Vertical=`vertical`,e.Horizontal=`horizontal`})(pa||={});var ma;(function(e){e.Partial=`partial`,e.Full=`full`})(ma||={});var ha={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null},ga;(function(e){e.Bezier=`default`,e.Straight=`straight`,e.Step=`step`,e.SmoothStep=`smoothstep`,e.SimpleBezier=`simplebezier`})(ga||={});var _a;(function(e){e.Arrow=`arrow`,e.ArrowClosed=`arrowclosed`})(_a||={});var U;(function(e){e.Left=`left`,e.Top=`top`,e.Right=`right`,e.Bottom=`bottom`})(U||={});var va={[U.Left]:U.Right,[U.Right]:U.Left,[U.Top]:U.Bottom,[U.Bottom]:U.Top},ya=e=>!!e&&typeof e==`object`&&`id`in e&&`source`in e&&`target`in e,ba=e=>!!e&&typeof e==`object`&&`id`in e&&`position`in e&&!(`source`in e)&&!(`target`in e),xa=e=>!!e&&typeof e==`object`&&`id`in e&&`internals`in e&&!(`source`in e)&&!(`target`in e),Sa=(e,t=[0,0])=>{let{width:n,height:r}=no(e),i=e.origin??t,a=n*i[0],o=r*i[1];return{x:e.position.x-a,y:e.position.y-o}},Ca=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};let n=!1,r=e.reduce((e,r)=>{let i=typeof r==`string`,a=!t.nodeLookup&&!i?r:void 0;return t.nodeLookup&&(a=i?t.nodeLookup.get(r):xa(r)?r:t.nodeLookup.get(r.id)),a?(n=!0,Ia(e,Ba(a,t.nodeOrigin))):e},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return n?Ra(r):{x:0,y:0,width:0,height:0}},wa=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(e=>{(t.filter===void 0||t.filter(e))&&(n=Ia(n,Ba(e)),r=!0)}),r?Ra(n):{x:0,y:0,width:0,height:0}},Ta=(e,t,[n,r,i]=[0,0,1],a=!1,o=!1)=>{let s=(t.x-n)/i,c=(t.y-r)/i,l=t.width/i,u=t.height/i,d=[];for(let t of e.values()){let{measured:e,selectable:n=!0,hidden:r=!1}=t;if(o&&!n||r)continue;let i=e.width??t.width??t.initialWidth??0,f=e.height??t.height??t.initialHeight??0,{x:p,y:m}=t.internals.positionAbsolute,h=Ha(s,c,l,u,p,m,i,f),g=i*f,_=a&&h>0;(!t.internals.handleBounds||_||h>=g||t.dragging)&&d.push(t)}return d},Ea=(e,t)=>{let n=new Set;return e.forEach(e=>{n.add(e.id)}),t.filter(e=>n.has(e.source)||n.has(e.target))};function Da(e,t){let n=new Map,r=t?.nodes?new Set(t.nodes.map(e=>e.id)):null;return e.forEach(e=>{let i;if(t?.includeHiddenNodes){let{width:t,height:n}=no(e);i=t>0&&n>0}else i=!!(e.measured.width&&e.measured.height&&!e.hidden);i&&(!r||r.has(e.id))&&n.set(e.id,e)}),n}async function Oa({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:a},o){if(e.size===0)return!0;let s=$a(wa(Da(e,o)),t,n,o?.minZoom??i,o?.maxZoom??a,o?.padding??.1);return await r.setViewport(s,{duration:o?.duration,ease:o?.ease,interpolate:o?.interpolate}),!0}function ka({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:i,onError:a}){let o=n.get(e),s=o.parentId?n.get(o.parentId):void 0,{x:c,y:l}=s?s.internals.positionAbsolute:{x:0,y:0},u=o.origin??r,d=o.extent||i;if(o.extent===`parent`&&!o.expandParent){if(!s)a?.(`005`,ca.error005());else{let{width:e,height:t}=no(s);e&&t&&(d=[[c,l],[c+e,l+t]])}}else s&&to(o.extent)&&(d=[[o.extent[0][0]+c,o.extent[0][1]+l],[o.extent[1][0]+c,o.extent[1][1]+l]]);let f=to(d)?Ma(t,d,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&a?.(`015`,ca.error015()),{position:{x:f.x-c+(o.measured.width??0)*u[0],y:f.y-l+(o.measured.height??0)*u[1]},positionAbsolute:f}}async function Aa({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){let a=new Set(e.map(e=>e.id)),o=[];for(let e of n){if(e.deletable===!1)continue;let t=a.has(e.id),n=!t&&e.parentId&&o.find(t=>t.id===e.parentId);(t||n)&&o.push(e)}let s=new Set(t.map(e=>e.id)),c=r.filter(e=>e.deletable!==!1),l=Ea(o,c);for(let e of c)s.has(e.id)&&!l.find(t=>t.id===e.id)&&l.push(e);if(!i)return{edges:l,nodes:o};let u=await i({nodes:o,edges:l});return typeof u==`boolean`?u?{edges:l,nodes:o}:{edges:[],nodes:[]}:u}var ja=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Ma=(e={x:0,y:0},t,n)=>({x:ja(e.x,t[0][0],t[1][0]-(n?.width??0)),y:ja(e.y,t[0][1],t[1][1]-(n?.height??0))});function Na(e,t,n){let{width:r,height:i}=no(n),{x:a,y:o}=n.internals.positionAbsolute;return Ma(e,[[a,o],[a+r,o+i]],t)}var Pa=(e,t,n)=>e<t?ja(Math.abs(e-t),1,t)/t:e>n?-ja(Math.abs(e-n),1,t)/t:0,Fa=(e,t,n=15,r=40)=>[Pa(e.x,r,t.width-r)*n,Pa(e.y,r,t.height-r)*n],Ia=(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)}),La=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),Ra=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),za=(e,t=[0,0])=>{let{x:n,y:r}=xa(e)?e.internals.positionAbsolute:Sa(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},Ba=(e,t=[0,0])=>{let{x:n,y:r}=xa(e)?e.internals.positionAbsolute:Sa(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},Va=(e,t)=>Ra(Ia(La(e),La(t))),Ha=(e,t,n,r,i,a,o,s)=>{let c=Math.max(0,Math.min(e+n,i+o)-Math.max(e,i)),l=Math.max(0,Math.min(t+r,a+s)-Math.max(t,a));return Math.ceil(c*l)},Ua=(e,t)=>Ha(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),Wa=e=>Ga(e.width)&&Ga(e.height)&&Ga(e.x)&&Ga(e.y),Ga=e=>!isNaN(e)&&isFinite(e),Ka=(e,t)=>(e,t)=>{},qa=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Ja=({x:e,y:t},[n,r,i],a=!1,o=[1,1])=>{let s={x:(e-n)/i,y:(t-r)/i};return a?qa(s,o):s},Ya=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function Xa(e,t){if(typeof e==`number`)return Math.floor((t-t/(1+e))*.5);if(typeof e==`string`&&e.endsWith(`px`)){let t=parseFloat(e);if(!Number.isNaN(t))return Math.floor(t)}if(typeof e==`string`&&e.endsWith(`%`)){let 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 Za(e,t,n){if(typeof e==`string`||typeof e==`number`){let r=Xa(e,n),i=Xa(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e==`object`){let r=Xa(e.top??e.y??0,n),i=Xa(e.bottom??e.y??0,n),a=Xa(e.left??e.x??0,t),o=Xa(e.right??e.x??0,t);return{top:r,right:o,bottom:i,left:a,x:a+o,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function Qa(e,t,n,r,i,a){let{x:o,y:s}=Ya(e,[t,n,r]),{x:c,y:l}=Ya({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-c,d=a-l;return{left:Math.floor(o),top:Math.floor(s),right:Math.floor(u),bottom:Math.floor(d)}}var $a=(e,t,n,r,i,a)=>{let o=Za(a,t,n),s=(t-o.x)/e.width,c=(n-o.y)/e.height,l=ja(Math.min(s,c),r,i),u=e.x+e.width/2,d=e.y+e.height/2,f=t/2-u*l,p=n/2-d*l,m=Qa(e,f,p,l,t,n),h={left:Math.min(m.left-o.left,0),top:Math.min(m.top-o.top,0),right:Math.min(m.right-o.right,0),bottom:Math.min(m.bottom-o.bottom,0)};return{x:f-h.left+h.right,y:p-h.top+h.bottom,zoom:l}},eo=()=>typeof navigator<`u`&&navigator?.userAgent?.indexOf(`Mac`)>=0;function to(e){return e!=null&&e!==`parent`}function no(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function ro(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function io(e,t={width:0,height:0},n,r,i){let a={...e},o=r.get(n);if(o){let e=o.origin||i;a.x+=o.internals.positionAbsolute.x-(t.width??0)*e[0],a.y+=o.internals.positionAbsolute.y-(t.height??0)*e[1]}return a}function ao(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function oo(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function so(e){return{...da,...e||{}}}function co(e){return e===null?null:e?`valid`:`invalid`}function lo(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){let{x:a,y:o}=go(e),s=Ja({x:a-(i?.left??0),y:o-(i?.top??0)},r),{x:c,y:l}=n?qa(s,t):s;return{xSnapped:c,ySnapped:l,...s}}var uo=e=>({width:e.offsetWidth,height:e.offsetHeight}),fo=e=>e?.getRootNode?.()||window?.document,po=[`INPUT`,`SELECT`,`TEXTAREA`];function mo(e){let t=e.composedPath?.()?.[0]||e.target;return t?.nodeType===1?po.includes(t.nodeName)||t.hasAttribute(`contenteditable`)||!!t.closest(`.nokey`):!1}var ho=e=>`clientX`in e,go=(e,t)=>{let n=ho(e),r=n?e.clientX:e.touches?.[0].clientX,i=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:i-(t?.top??0)}},_o=(e,t,n,r,i)=>{let a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...uo(t)}})};function vo({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:i,sourceControlY:a,targetControlX:o,targetControlY:s}){let c=e*.125+i*.375+o*.375+n*.125,l=t*.125+a*.375+s*.375+r*.125;return[c,l,Math.abs(c-e),Math.abs(l-t)]}function yo(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function bo({pos:e,x1:t,y1:n,x2:r,y2:i,c:a}){switch(e){case U.Left:return[t-yo(t-r,a),n];case U.Right:return[t+yo(r-t,a),n];case U.Top:return[t,n-yo(n-i,a)];case U.Bottom:return[t,n+yo(i-n,a)]}}function xo({sourceX:e,sourceY:t,sourcePosition:n=U.Bottom,targetX:r,targetY:i,targetPosition:a=U.Top,curvature:o=.25}){let[s,c]=bo({pos:n,x1:e,y1:t,x2:r,y2:i,c:o}),[l,u]=bo({pos:a,x1:r,y1:i,x2:e,y2:t,c:o}),[d,f,p,m]=vo({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:s,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${s},${c} ${l},${u} ${r},${i}`,d,f,p,m]}function So({sourceX:e,sourceY:t,targetX:n,targetY:r}){let i=Math.abs(n-e)/2,a=n<e?n+i:n-i,o=Math.abs(r-t)/2;return[a,r<t?r+o:r-o,i,o]}function Co({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:a=`basic`}){return a===`manual`?r:(i&&n?r+1e3:r)+Math.max(e.parentId||i&&e.selected?e.internals.z:0,t.parentId||i&&t.selected?t.internals.z:0)}function wo({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){let a=Ia(Ba(e),Ba(t));return a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1),Ua({x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]},Ra(a))>0}var To=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||``}-${n}${r||``}`,Eo=(e,t)=>t.some(t=>t.source===e.source&&t.target===e.target&&(t.sourceHandle===e.sourceHandle||!t.sourceHandle&&!e.sourceHandle)&&(t.targetHandle===e.targetHandle||!t.targetHandle&&!e.targetHandle)),Do=(e,t,n={})=>{if(!e.source||!e.target)return n.onError?.(`006`,ca.error006()),t;let r=n.getEdgeId||To,i;return i=ya(e)?{...e}:{...e,id:r(e)},Eo(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function Oo({sourceX:e,sourceY:t,targetX:n,targetY:r}){let[i,a,o,s]=So({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,a,o,s]}var ko={[U.Left]:{x:-1,y:0},[U.Right]:{x:1,y:0},[U.Top]:{x:0,y:-1},[U.Bottom]:{x:0,y:1}},Ao=({source:e,sourcePosition:t=U.Bottom,target:n})=>t===U.Left||t===U.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},jo=(e,t)=>Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2);function Mo({source:e,sourcePosition:t=U.Bottom,target:n,targetPosition:r=U.Top,center:i,offset:a,stepPosition:o}){let s=ko[t],c=ko[r],l={x:e.x+s.x*a,y:e.y+s.y*a},u={x:n.x+c.x*a,y:n.y+c.y*a},d=Ao({source:l,sourcePosition:t,target:u}),f=d.x===0?`y`:`x`,p=d[f],m=[],h,g,_={x:0,y:0},v={x:0,y:0},[,,y,b]=So({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(s[f]*c[f]===-1){f===`x`?(h=i.x??l.x+(u.x-l.x)*o,g=i.y??(l.y+u.y)/2):(h=i.x??(l.x+u.x)/2,g=i.y??l.y+(u.y-l.y)*o);let e=[{x:h,y:l.y},{x:h,y:u.y}],t=[{x:l.x,y:g},{x:u.x,y:g}];m=s[f]===p?f===`x`?e:t:f===`x`?t:e}else{let i=[{x:l.x,y:u.y}],o=[{x:u.x,y:l.y}];if(m=f===`x`?s.x===p?o:i:s.y===p?i:o,t===r){let t=Math.abs(e[f]-n[f]);if(t<=a){let r=Math.min(a-1,a-t);s[f]===p?_[f]=(l[f]>e[f]?-1:1)*r:v[f]=(u[f]>n[f]?-1:1)*r}}if(t!==r){let e=f===`x`?`y`:`x`,t=s[f]===c[e],n=l[e]>u[e],r=l[e]<u[e];(s[f]===1&&(!t&&n||t&&r)||s[f]!==1&&(!t&&r||t&&n))&&(m=f===`x`?i:o)}let d={x:l.x+_.x,y:l.y+_.y},y={x:u.x+v.x,y:u.y+v.y};Math.max(Math.abs(d.x-m[0].x),Math.abs(y.x-m[0].x))>=Math.max(Math.abs(d.y-m[0].y),Math.abs(y.y-m[0].y))?(h=(d.x+y.x)/2,g=m[0].y):(h=m[0].x,g=(d.y+y.y)/2)}let x={x:l.x+_.x,y:l.y+_.y},S={x:u.x+v.x,y:u.y+v.y};return[[e,...x.x!==m[0].x||x.y!==m[0].y?[x]:[],...m,...S.x!==m[m.length-1].x||S.y!==m[m.length-1].y?[S]:[],n],h,g,y,b]}function No(e,t,n,r){let i=Math.min(jo(e,t)/2,jo(t,n)/2,r),{x:a,y:o}=t;if(e.x===a&&a===n.x||e.y===o&&o===n.y)return`L${a} ${o}`;if(e.y===o){let t=e.x<n.x?-1:1,r=e.y<n.y?1:-1;return`L ${a+i*t},${o}Q ${a},${o} ${a},${o+i*r}`}let s=e.x<n.x?1:-1;return`L ${a},${o+i*(e.y<n.y?-1:1)}Q ${a},${o} ${a+i*s},${o}`}function Po({sourceX:e,sourceY:t,sourcePosition:n=U.Bottom,targetX:r,targetY:i,targetPosition:a=U.Top,borderRadius:o=5,centerX:s,centerY:c,offset:l=20,stepPosition:u=.5}){let[d,f,p,m,h]=Mo({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:a,center:{x:s,y:c},offset:l,stepPosition:u}),g=`M${d[0].x} ${d[0].y}`;for(let e=1;e<d.length-1;e++)g+=No(d[e-1],d[e],d[e+1],o);return g+=`L${d[d.length-1].x} ${d[d.length-1].y}`,[g,f,p,m,h]}function Fo(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Io(e){let{sourceNode:t,targetNode:n}=e;if(!Fo(t)||!Fo(n))return null;let r=t.internals.handleBounds||Lo(t.handles),i=n.internals.handleBounds||Lo(n.handles),a=zo(r?.source??[],e.sourceHandle),o=zo(e.connectionMode===fa.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!a||!o)return e.onError?.(`008`,ca.error008(a?`target`:`source`,{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;let s=a?.position||U.Bottom,c=o?.position||U.Top,l=Ro(t,a,s),u=Ro(n,o,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:s,targetPosition:c}}function Lo(e){if(!e)return null;let t=[],n=[];for(let r of e)r.width=r.width??1,r.height=r.height??1,r.type===`source`?t.push(r):r.type===`target`&&n.push(r);return{source:t,target:n}}function Ro(e,t,n=U.Left,r=!1){let i=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:o,height:s}=t??no(e);if(r)return{x:i+o/2,y:a+s/2};switch(t?.position??n){case U.Top:return{x:i+o/2,y:a};case U.Right:return{x:i+o,y:a+s/2};case U.Bottom:return{x:i+o/2,y:a+s};case U.Left:return{x:i,y:a+s/2}}}function zo(e,t){return e&&(t?e.find(e=>e.id===t):e[0])||null}function Bo(e,t){return e?typeof e==`string`?e:`${t?`${t}__`:``}${Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`&`)}`:``}function Vo(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:i}){let a=new Set;return e.reduce((e,o)=>([o.markerStart||r,o.markerEnd||i].forEach(r=>{if(r&&typeof r==`object`){let i=Bo(r,t);a.has(i)||(e.push({id:i,color:r.color||n,...r}),a.add(i))}}),e),[]).sort((e,t)=>e.id.localeCompare(t.id))}var Ho=1e3,Uo=10,Wo={nodeOrigin:[0,0],nodeExtent:la,elevateNodesOnSelect:!0,zIndexMode:`basic`,defaults:{}},Go={...Wo,checkEquality:!0};function Ko(e,t){let n={...e};for(let e in t)t[e]!==void 0&&(n[e]=t[e]);return n}function qo(e,t,n){let r=Ko(Wo,n);for(let n of e.values())if(n.parentId)Qo(n,e,t,r);else{let e=Ma(Sa(n,r.nodeOrigin),to(n.extent)?n.extent:r.nodeExtent,no(n));n.internals.positionAbsolute=e}}function Jo(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;let n=[],r=[];for(let t of e.handles){let i={id:t.id,width:t.width??1,height:t.height??1,nodeId:e.id,x:t.x,y:t.y,position:t.position,type:t.type};t.type===`source`?n.push(i):t.type===`target`&&r.push(i)}return{source:n,target:r}}function Yo(e){return e===`manual`}function Xo(e,t,n,r={}){let i=Ko(Go,r),a={i:0},o=new Map(t),s=i?.elevateNodesOnSelect&&!Yo(i.zIndexMode)?Ho:0,c=e.length>0,l=!1;t.clear(),n.clear();for(let u of e){let e=o.get(u.id);if(i.checkEquality&&u===e?.internals.userNode)t.set(u.id,e);else{let n=Ma(Sa(u,i.nodeOrigin),to(u.extent)?u.extent:i.nodeExtent,no(u));e={...i.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:n,handleBounds:Jo(u,e),z:$o(u,s,i.zIndexMode),userNode:u}},t.set(u.id,e)}(e.measured===void 0||e.measured.width===void 0||e.measured.height===void 0)&&!e.hidden&&(c=!1),u.parentId&&Qo(e,t,n,r,a),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function Zo(e,t){if(!e.parentId)return;let n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function Qo(e,t,n,r,i){let{elevateNodesOnSelect:a,nodeOrigin:o,nodeExtent:s,zIndexMode:c}=Ko(Wo,r),l=e.parentId,u=t.get(l);if(!u){console.warn(`Parent node ${l} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Zo(e,n),i&&!u.parentId&&u.internals.rootParentIndex===void 0&&c===`auto`&&(u.internals.rootParentIndex=++i.i,u.internals.z=u.internals.z+i.i*Uo),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);let{x:d,y:f,z:p}=es(e,u,o,s,a&&!Yo(c)?Ho:0,c),{positionAbsolute:m}=e.internals,h=d!==m.x||f!==m.y;(h||p!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:h?{x:d,y:f}:m,z:p}})}function $o(e,t,n){let r=Ga(e.zIndex)?e.zIndex:0;return Yo(n)?r:r+(e.selected?t:0)}function es(e,t,n,r,i,a){let{x:o,y:s}=t.internals.positionAbsolute,c=no(e),l=Sa(e,n),u=to(e.extent)?Ma(l,e.extent,c):l,d=Ma({x:o+u.x,y:s+u.y},r,c);e.extent===`parent`&&(d=Na(d,c,t));let f=$o(e,i,a),p=t.internals.z??0;return{x:d.x,y:d.y,z:p>=f?p+1:f}}function ts(e,t,n,r=[0,0]){let i=[],a=new Map;for(let n of e){let e=t.get(n.parentId);if(!e)continue;let r=Va(a.get(n.parentId)?.expandedRect??za(e),n.rect);a.set(n.parentId,{expandedRect:r,parent:e})}return a.size>0&&a.forEach(({expandedRect:t,parent:a},o)=>{let s=a.internals.positionAbsolute,c=no(a),l=a.origin??r,u=t.x<s.x?Math.round(Math.abs(s.x-t.x)):0,d=t.y<s.y?Math.round(Math.abs(s.y-t.y)):0,f=Math.max(c.width,Math.round(t.width)),p=Math.max(c.height,Math.round(t.height)),m=(f-c.width)*l[0],h=(p-c.height)*l[1];(u>0||d>0||m||h)&&(i.push({id:o,type:`position`,position:{x:a.position.x-u+m,y:a.position.y-d+h}}),n.get(o)?.forEach(t=>{e.some(e=>e.id===t.id)||i.push({id:t.id,type:`position`,position:{x:t.position.x+u,y:t.position.y+d}})})),(c.width<t.width||c.height<t.height||u||d)&&i.push({id:o,type:`dimensions`,setAttributes:!0,dimensions:{width:f+(u?l[0]*u-m:0),height:p+(d?l[1]*d-h:0)}})}),i}function ns(e,t,n,r,i,a,o){let s=r?.querySelector(`.xyflow__viewport`),c=!1;if(!s)return{changes:[],updatedInternals:c};let l=[],u=window.getComputedStyle(s),{m22:d}=new window.DOMMatrixReadOnly(u.transform),f=[];for(let r of e.values()){let e=t.get(r.id);if(!e)continue;if(e.hidden){t.set(e.id,{...e,internals:{...e.internals,handleBounds:void 0}}),c=!0;continue}let s=uo(r.nodeElement),u=e.measured.width!==s.width||e.measured.height!==s.height;if(s.width&&s.height&&(u||!e.internals.handleBounds||r.force)){let p=r.nodeElement.getBoundingClientRect(),m=to(e.extent)?e.extent:a,{positionAbsolute:h}=e.internals;if(e.parentId&&e.extent===`parent`){let n=t.get(e.parentId);n&&(h=Na(h,s,n))}else m&&(h=Ma(h,m,s));let g={...e,measured:s,internals:{...e.internals,positionAbsolute:h,handleBounds:{source:_o(`source`,r.nodeElement,p,d,e.id),target:_o(`target`,r.nodeElement,p,d,e.id)}}};t.set(e.id,g),e.parentId&&Qo(g,t,n,{nodeOrigin:i,zIndexMode:o}),c=!0,u&&(l.push({id:e.id,type:`dimensions`,dimensions:s}),e.expandParent&&e.parentId&&f.push({id:e.id,parentId:e.parentId,rect:za(g,i)}))}}if(f.length>0){let e=ts(f,t,n,i);l.push(...e)}return{changes:l,updatedInternals:c}}async function rs({delta:e,panZoom:t,transform:n,translateExtent:r,width:i,height:a}){if(!t||!e.x&&!e.y)return!1;let o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[i,a]],r);return!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2])}function is(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function as(e,t,n){e.clear(),t.clear();for(let r of n){let{source:n,target:i,sourceHandle:a=null,targetHandle:o=null}=r,s={edgeId:r.id,source:n,target:i,sourceHandle:a,targetHandle:o},c=`${n}-${a}--${i}-${o}`;is(`source`,s,`${i}-${o}--${n}-${a}`,e,n,a),is(`target`,s,c,e,i,o),t.set(r.id,r)}}function os(e,t){if(!e.parentId)return!1;let n=t.get(e.parentId);return n?n.selected?!0:os(n,t):!1}function ss(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function cs(e,t,n,r){let i=new Map;for(let[a,o]of e)if((o.selected||o.id===r)&&(!o.parentId||!os(o,e))&&(o.draggable||t&&o.draggable===void 0)){let t=e.get(a);t&&i.set(a,{id:a,position:t.position||{x:0,y:0},distance:{x:n.x-t.internals.positionAbsolute.x,y:n.y-t.internals.positionAbsolute.y},extent:t.extent,parentId:t.parentId,origin:t.origin,expandParent:t.expandParent,internals:{positionAbsolute:t.internals.positionAbsolute||{x:0,y:0}},measured:{width:t.measured.width??0,height:t.measured.height??0}})}return i}function ls({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){let i=[];for(let[e,a]of t){let t=n.get(e)?.internals.userNode;t&&i.push({...t,position:a.position,dragging:r})}if(!e)return[i[0],i];let a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:i[0],i]}function us({dragItems:e,snapGrid:t,x:n,y:r}){let i=e.values().next().value;if(!i)return null;let a={x:n-i.distance.x,y:r-i.distance.y},o=qa(a,t);return{x:o.x-a.x,y:o.y-a.y}}function ds({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:i}){let a={x:null,y:null},o=0,s=new Map,c=!1,l={x:0,y:0},u=null,d=!1,f=null,p=!1,m=!1,h=null;function g({noDragClassName:g,handleSelector:_,domNode:v,isSelectable:y,nodeId:b,nodeClickDistance:x=0}){f=kt(v);function S({x:e,y:n}){let{nodeLookup:i,nodeExtent:o,snapGrid:c,snapToGrid:l,nodeOrigin:u,onNodeDrag:d,onSelectionDrag:f,onError:p,updateNodePositions:g}=t();a={x:e,y:n};let _=!1,v=s.size>1,y=v&&o?La(wa(s)):null,x=v&&l?us({dragItems:s,snapGrid:c,x:e,y:n}):null;for(let[t,r]of s){if(!i.has(t))continue;let a={x:e-r.distance.x,y:n-r.distance.y};l&&(a=x?{x:Math.round(a.x+x.x),y:Math.round(a.y+x.y)}:qa(a,c));let s=null;if(v&&o&&!r.extent&&y){let{positionAbsolute:e}=r.internals,t=e.x-y.x+o[0][0],n=e.x+r.measured.width-y.x2+o[1][0],i=e.y-y.y+o[0][1],a=e.y+r.measured.height-y.y2+o[1][1];s=[[t,i],[n,a]]}let{position:d,positionAbsolute:f}=ka({nodeId:t,nextPosition:a,nodeLookup:i,nodeExtent:s||o,nodeOrigin:u,onError:p});_=_||r.position.x!==d.x||r.position.y!==d.y,r.position=d,r.internals.positionAbsolute=f}if(m||=_,_&&(g(s,!0),h&&(r||d||!b&&f))){let[e,t]=ls({nodeId:b,dragItems:s,nodeLookup:i});r?.(h,s,e,t),d?.(h,e,t),b||f?.(h,t)}}async function C(){if(!u)return;let{transform:e,panBy:n,autoPanSpeed:r,autoPanOnNodeDrag:i}=t();if(!i){c=!1,cancelAnimationFrame(o);return}let[s,d]=Fa(l,u,r);(s!==0||d!==0)&&(a.x=(a.x??0)-s/e[2],a.y=(a.y??0)-d/e[2],await n({x:s,y:d})&&S(a)),o=requestAnimationFrame(C)}function w(r){let{nodeLookup:i,multiSelectionActive:o,nodesDraggable:c,transform:l,snapGrid:f,snapToGrid:p,selectNodesOnDrag:m,onNodeDragStart:h,onSelectionDragStart:g,unselectNodesAndEdges:_}=t();d=!0,(!m||!y)&&!o&&b&&(i.get(b)?.selected||_()),y&&m&&b&&e?.(b);let v=lo(r.sourceEvent,{transform:l,snapGrid:f,snapToGrid:p,containerBounds:u});if(a=v,s=cs(i,c,v,b),s.size>0&&(n||h||!b&&g)){let[e,t]=ls({nodeId:b,dragItems:s,nodeLookup:i});n?.(r.sourceEvent,s,e,t),h?.(r.sourceEvent,e,t),b||g?.(r.sourceEvent,t)}}let T=Wt().clickDistance(x).on(`start`,e=>{let{domNode:n,nodeDragThreshold:r,transform:i,snapGrid:o,snapToGrid:s}=t();u=n?.getBoundingClientRect()||null,p=!1,m=!1,h=e.sourceEvent,r===0&&w(e),a=lo(e.sourceEvent,{transform:i,snapGrid:o,snapToGrid:s,containerBounds:u}),l=go(e.sourceEvent,u)}).on(`drag`,e=>{let{autoPanOnNodeDrag:n,transform:r,snapGrid:i,snapToGrid:o,nodeDragThreshold:f,nodeLookup:m}=t(),g=lo(e.sourceEvent,{transform:r,snapGrid:i,snapToGrid:o,containerBounds:u});if(h=e.sourceEvent,(e.sourceEvent.type===`touchmove`&&e.sourceEvent.touches.length>1||b&&!m.has(b))&&(p=!0),!p){if(!c&&n&&d&&(c=!0,C()),!d){let t=go(e.sourceEvent,u),n=t.x-l.x,r=t.y-l.y;Math.sqrt(n*n+r*r)>f&&w(e)}(a.x!==g.xSnapped||a.y!==g.ySnapped)&&s&&d&&(l=go(e.sourceEvent,u),S(g))}}).on(`end`,e=>{if(!d||p)p&&s.size>0&&t().updateNodePositions(s,!1);else if(c=!1,d=!1,cancelAnimationFrame(o),s.size>0){let{nodeLookup:n,updateNodePositions:r,onNodeDragStop:a,onSelectionDragStop:o}=t();if(m&&=(r(s,!1),!1),i||a||!b&&o){let[t,r]=ls({nodeId:b,dragItems:s,nodeLookup:n,dragging:!1});i?.(e.sourceEvent,s,t,r),a?.(e.sourceEvent,t,r),b||o?.(e.sourceEvent,r)}}}).filter(e=>{let t=e.target;return!e.button&&(!g||!ss(t,`.${g}`,v))&&(!_||ss(t,_,v))});f.call(T)}function _(){f?.on(`.drag`,null)}return{update:g,destroy:_}}function fs(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())Ua(i,za(e))>0&&r.push(e);return r}var ps=250;function ms(e,t,n,r){let i=[],a=1/0,o=fs(e,n,t+ps);for(let n of o){let o=[...n.internals.handleBounds?.source??[],...n.internals.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=Ro(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function hs(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===`strict`?o.internals.handleBounds?.[t]:[...o.internals.handleBounds?.source??[],...o.internals.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...Ro(o,c,c.position,!0)}:c}function gs(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function _s(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}var vs=()=>!0;function ys(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:a,isTarget:o,domNode:s,nodeLookup:c,lib:l,autoPanOnConnect:u,flowId:d,panBy:f,cancelConnection:p,onConnectStart:m,onConnect:h,onConnectEnd:g,isValidConnection:_=vs,onReconnectEnd:v,updateConnection:y,getTransform:b,getFromHandle:x,autoPanSpeed:S,dragThreshold:C=1,handleDomNode:w}){let T=fo(e.target),E=0,D,{x:O,y:k}=go(e),A=gs(a,w),j=s?.getBoundingClientRect(),M=!1;if(!j||!A)return;let N=hs(i,A,r,c,t);if(!N)return;let P=go(e,j),F=!1,I=null,L=!1,R=null;function z(){if(!u||!j)return;let[e,t]=Fa(P,j,S);f({x:e,y:t}),E=requestAnimationFrame(z)}let B={...N,nodeId:i,type:A,position:N.position},V=c.get(i),H={inProgress:!0,isValid:null,from:Ro(V,B,U.Left,!0),fromHandle:B,fromPosition:B.position,fromNode:V,to:P,toHandle:null,toPosition:va[B.position],toNode:null,pointer:P};function ee(){M=!0,y(H),m?.(e,{nodeId:i,handleId:r,handleType:A})}C===0&&ee();function te(e){if(!M){let{x:t,y:n}=go(e),r=t-O,i=n-k;if(!(r*r+i*i>C*C))return;ee()}if(!x()||!B){ne(e);return}let a=b();P=go(e,j),D=ms(Ja(P,a,!1,[1,1]),n,c,B),F||=(z(),!0);let s=bs(e,{handle:D,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:o?`target`:`source`,isValidConnection:_,doc:T,lib:l,flowId:d,nodeLookup:c});R=s.handleDomNode,I=s.connection,L=_s(!!D,s.isValid);let u=c.get(i),f=u?Ro(u,B,U.Left,!0):H.from,p={...H,from:f,isValid:L,to:s.toHandle&&L?Ya({x:s.toHandle.x,y:s.toHandle.y},a):P,toHandle:s.toHandle,toPosition:L&&s.toHandle?s.toHandle.position:va[B.position],toNode:s.toHandle?c.get(s.toHandle.nodeId):null,pointer:P};y(p),H=p}function ne(e){if(!(`touches`in e&&e.touches.length>0)){if(M){(D||R)&&I&&L&&h?.(I);let{inProgress:t,...n}=H,r={...n,toPosition:H.toHandle?H.toPosition:null};g?.(e,r),a&&v?.(e,r)}p(),cancelAnimationFrame(E),F=!1,L=!1,I=null,R=null,T.removeEventListener(`mousemove`,te),T.removeEventListener(`mouseup`,ne),T.removeEventListener(`touchmove`,te),T.removeEventListener(`touchend`,ne)}}T.addEventListener(`mousemove`,te),T.addEventListener(`mouseup`,ne),T.addEventListener(`touchmove`,te),T.addEventListener(`touchend`,ne)}function bs(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=vs,nodeLookup:u}){let d=a===`target`,f=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:m}=go(e),h=o.elementFromPoint(p,m),g=h?.classList.contains(`${s}-flow__handle`)?h:f,_={handleDomNode:g,isValid:!1,connection:null,toHandle:null};if(g){let e=gs(void 0,g),t=g.getAttribute(`data-nodeid`),a=g.getAttribute(`data-handleid`),o=g.classList.contains(`connectable`),s=g.classList.contains(`connectableend`);if(!t||!e)return _;let c={source:d?t:r,sourceHandle:d?a:i,target:d?r:t,targetHandle:d?i:a};_.connection=c,_.isValid=o&&s&&(n===fa.Strict?d&&e===`source`||!d&&e===`target`:t!==r||a!==i)&&l(c),_.toHandle=hs(t,e,a,u,n,!0)}return _}var xs={onPointerDown:ys,isValid:bs};function Ss({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){let i=kt(e);function a({translateExtent:e,width:a,height:o,zoomStep:s=1,pannable:c=!0,zoomable:l=!0,inversePan:u=!1}){let d=e=>{if(e.sourceEvent.type!==`wheel`||!t)return;let r=n(),i=e.sourceEvent.ctrlKey&&eo()?10:1,a=-e.sourceEvent.deltaY*(e.sourceEvent.deltaMode===1?.05:e.sourceEvent.deltaMode?1:.002)*s,o=r[2]*2**(a*i);t.scaleTo(o)},f=[0,0],p=sa().on(`start`,e=>{(e.sourceEvent.type===`mousedown`||e.sourceEvent.type===`touchstart`)&&(f=[e.sourceEvent.clientX??e.sourceEvent.touches[0].clientX,e.sourceEvent.clientY??e.sourceEvent.touches[0].clientY])}).on(`zoom`,c?i=>{let s=n();if(i.sourceEvent.type!==`mousemove`&&i.sourceEvent.type!==`touchmove`||!t)return;let c=[i.sourceEvent.clientX??i.sourceEvent.touches[0].clientX,i.sourceEvent.clientY??i.sourceEvent.touches[0].clientY],l=[c[0]-f[0],c[1]-f[1]];f=c;let d=r()*Math.max(s[2],Math.log(s[2]))*(u?-1:1),p={x:s[0]-l[0]*d,y:s[1]-l[1]*d},m=[[0,0],[a,o]];t.setViewportConstrained({x:p.x,y:p.y,zoom:s[2]},m,e)}:null).on(`zoom.wheel`,l?d:null);i.call(p,{})}function o(){i.on(`zoom`,null)}return{update:a,destroy:o,pointer:jt}}var Cs=e=>({x:e.x,y:e.y,zoom:e.k}),ws=({x:e,y:t,zoom:n})=>Zi.translate(e,t).scale(n),Ts=(e,t)=>e.target.closest(`.${t}`),Es=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Ds=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Os=(e,t=0,n=Ds,r=()=>{})=>{let i=typeof t==`number`&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on(`end`,r):e},ks=e=>{let t=e.ctrlKey&&eo()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function As({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:a,zoomOnPinch:o,onPanZoomStart:s,onPanZoom:c,onPanZoomEnd:l}){return u=>{if(Ts(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();let d=n.property(`__zoom`).k||1;if(u.ctrlKey&&o){let e=jt(u),t=d*2**ks(u);r.scaleTo(n,t,e,u);return}let f=u.deltaMode===1?20:1,p=i===pa.Vertical?0:u.deltaX*f,m=i===pa.Horizontal?0:u.deltaY*f;!eo()&&u.shiftKey&&i!==pa.Vertical&&(p=u.deltaY*f,m=0),r.translateBy(n,-(p/d)*a,-(m/d)*a,{internal:!0});let h=Cs(n.property(`__zoom`));clearTimeout(e.panScrollTimeout),e.isPanScrolling?c?.(u,h):(e.isPanScrolling=!0,s?.(u,h)),e.panScrollTimeout=setTimeout(()=>{l?.(u,h),e.isPanScrolling=!1},150)}}function js({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){let a=r.type===`wheel`,o=!t&&a&&!r.ctrlKey,s=Ts(r,e);if(r.ctrlKey&&a&&s&&r.preventDefault(),o||s)return null;r.preventDefault(),n.call(this,r,i)}}function Ms({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;let i=Cs(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type===`mousedown`&&t(!0),n&&n?.(r.sourceEvent,i)}}function Ns({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return a=>{e.usedRightMouseButton=!!(n&&Es(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),i&&!a.sourceEvent?.internal&&i?.(a.sourceEvent,Cs(a.transform))}}function Ps({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:a}){return o=>{if(!o.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&Es(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&a(o.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){let t=Cs(o.transform);e.prevViewport=t,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(o.sourceEvent,t)},n?150:0)}}}function Fs({panActivationKeyPressed:e,zoomActivationKeyPressed:t,zoomOnScroll:n,zoomOnPinch:r,panOnDrag:i,panOnScroll:a,zoomOnDoubleClick:o,userSelectionActive:s,noWheelClassName:c,noPanClassName:l,lib:u,connectionInProgress:d}){return f=>{let p=t||n,m=r&&f.ctrlKey,h=f.type===`wheel`;if(f.button===1&&f.type===`mousedown`&&(Ts(f,`${u}-flow__node`)||Ts(f,`${u}-flow__edge`)||Ts(f,`${u}-flow__selection`)||Ts(f,`${u}-flow__nodesselection`)))return!0;if(!i&&!p&&!a&&!o&&!r||s||d&&!h||Ts(f,c)&&h||Ts(f,l)&&(!h||a&&h&&!t)||!r&&f.ctrlKey&&h)return!1;if(!r&&f.type===`touchstart`&&f.touches?.length>1)return f.preventDefault(),!1;if(!p&&!a&&!m&&h||!i&&(f.type===`mousedown`||f.type===`touchstart`)||Array.isArray(i)&&!i.includes(f.button)&&f.type===`mousedown`)return!1;let g=Array.isArray(i)&&i.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||h||e)&&g}}function Is({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:i,onPanZoom:a,onPanZoomStart:o,onPanZoomEnd:s,onDraggingChange:c}){let l={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),d=[[0,0],[u.width,u.height]];(typeof ResizeObserver<`u`?new ResizeObserver(e=>{let t=e[0];t&&(d=[[0,0],[t.contentRect.width,t.contentRect.height]])}):null)?.observe(e);let f=sa().extent(()=>d).scaleExtent([t,n]).translateExtent(r),p=kt(e).call(f);y({x:i.x,y:i.y,zoom:ja(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);let m=p.on(`wheel.zoom`),h=p.on(`dblclick.zoom`);f.wheelDelta(ks);async function g(e,t){return p?new Promise(n=>{f?.interpolate(t?.interpolate===`linear`?Jn:cr).transform(Os(p,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function _({noWheelClassName:e,noPanClassName:t,onPaneContextMenu:n,userSelectionActive:r,panOnScroll:i,panOnDrag:u,panOnScrollMode:d,panOnScrollSpeed:g,preventScrolling:_,zoomOnPinch:y,zoomOnScroll:b,zoomOnDoubleClick:x,panActivationKeyPressed:S=!1,zoomActivationKeyPressed:C,lib:w,onTransformChange:T,connectionInProgress:E,paneClickDistance:D,selectionOnDrag:O}){r&&!l.isZoomingOrPanning&&v();let k=i&&!C&&!r;f.clickDistance(O?1/0:!Ga(D)||D<0?0:D);let A=k?As({zoomPanValues:l,noWheelClassName:e,d3Selection:p,d3Zoom:f,panOnScrollMode:d,panOnScrollSpeed:g,zoomOnPinch:y,onPanZoomStart:o,onPanZoom:a,onPanZoomEnd:s}):js({noWheelClassName:e,preventScrolling:_,d3ZoomHandler:m});p.on(`wheel.zoom`,A,{passive:!1});let j=Ms({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:o});f.on(`start`,j);let M=Ns({zoomPanValues:l,panOnDrag:u,onPaneContextMenu:!!n,onPanZoom:a,onTransformChange:T});f.on(`zoom`,M);let N=Ps({zoomPanValues:l,panOnDrag:u,panOnScroll:i,onPaneContextMenu:n,onPanZoomEnd:s,onDraggingChange:c});f.on(`end`,N);let P=Fs({panActivationKeyPressed:S,zoomActivationKeyPressed:C,panOnDrag:u,zoomOnScroll:b,panOnScroll:i,zoomOnDoubleClick:x,zoomOnPinch:y,userSelectionActive:r,noPanClassName:t,noWheelClassName:e,lib:w,connectionInProgress:E});f.filter(P),x?p.on(`dblclick.zoom`,h):p.on(`dblclick.zoom`,null)}function v(){f.on(`zoom`,null)}async function y(e,t,n){let r=ws(e),i=f?.constrain()(r,t,n);return i&&await g(i),i}async function b(e,t){let n=ws(e);return await g(n,t),n}function x(e){if(p){let t=ws(e),n=p.property(`__zoom`);(n.k!==e.zoom||n.x!==e.x||n.y!==e.y)&&f?.transform(p,t,null,{sync:!0})}}function S(){let e=p?Qi(p.node()):{x:0,y:0,k:1};return{x:e.x,y:e.y,zoom:e.k}}async function C(e,t){return p?new Promise(n=>{f?.interpolate(t?.interpolate===`linear`?Jn:cr).scaleTo(Os(p,t?.duration,t?.ease,()=>n(!0)),e)}):!1}async function w(e,t){return p?new Promise(n=>{f?.interpolate(t?.interpolate===`linear`?Jn:cr).scaleBy(Os(p,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function T(e){f?.scaleExtent(e)}function E(e){f?.translateExtent(e)}function D(e){let t=!Ga(e)||e<0?0:e;f?.clickDistance(t)}return{update:_,destroy:v,setViewport:b,setViewportConstrained:y,getViewport:S,scaleTo:C,scaleBy:w,setScaleExtent:T,setTranslateExtent:E,syncViewport:x,setClickDistance:D}}var Ls;(function(e){e.Line=`line`,e.Handle=`handle`})(Ls||={});var Rs=[`top-left`,`top-right`,`bottom-left`,`bottom-right`],zs=[`top`,`right`,`bottom`,`left`];function Bs({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:i,affectsY:a}){let o=e-t,s=n-r,c=[o>0?1:o<0?-1:0,s>0?1:s<0?-1:0];return o&&i&&(c[0]*=-1),s&&a&&(c[1]*=-1),c}function Vs(e){return{isHorizontal:e.includes(`right`)||e.includes(`left`),isVertical:e.includes(`bottom`)||e.includes(`top`),affectsX:e.includes(`left`),affectsY:e.includes(`top`)}}function Hs(e,t){return Math.max(0,t-e)}function Us(e,t){return Math.max(0,e-t)}function Ws(e,t,n){return Math.max(0,t-e,e-n)}function Gs(e,t){return e?!t:t}function Ks(e,t,n,r,i,a,o,s){let{affectsX:c,affectsY:l}=t,{isHorizontal:u,isVertical:d}=t,f=u&&d,{xSnapped:p,ySnapped:m}=n,{minWidth:h,maxWidth:g,minHeight:_,maxHeight:v}=r,{x:y,y:b,width:x,height:S,aspectRatio:C}=e,w=Math.floor(u?p-e.pointerX:0),T=Math.floor(d?m-e.pointerY:0),E=x+(c?-w:w),D=S+(l?-T:T),O=-a[0]*x,k=-a[1]*S,A=Ws(E,h,g),j=Ws(D,_,v);if(o){let e=0,t=0;c&&w<0?e=Hs(y+w+O,o[0][0]):!c&&w>0&&(e=Us(y+E+O,o[1][0])),l&&T<0?t=Hs(b+T+k,o[0][1]):!l&&T>0&&(t=Us(b+D+k,o[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(s){let e=0,t=0;c&&w>0?e=Us(y+w,s[0][0]):!c&&w<0&&(e=Hs(y+E,s[1][0])),l&&T>0?t=Us(b+T,s[0][1]):!l&&T<0&&(t=Hs(b+D,s[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(i){if(u){let e=Ws(E/C,_,v)*C;if(A=Math.max(A,e),o){let e=0;e=!c&&!l||c&&!l&&f?Us(b+k+E/C,o[1][1])*C:Hs(b+k+(c?w:-w)/C,o[0][1])*C,A=Math.max(A,e)}if(s){let e=0;e=!c&&!l||c&&!l&&f?Hs(b+E/C,s[1][1])*C:Us(b+(c?w:-w)/C,s[0][1])*C,A=Math.max(A,e)}}if(d){let e=Ws(D*C,h,g)/C;if(j=Math.max(j,e),o){let e=0;e=!c&&!l||l&&!c&&f?Us(y+D*C+O,o[1][0])/C:Hs(y+(l?T:-T)*C+O,o[0][0])/C,j=Math.max(j,e)}if(s){let e=0;e=!c&&!l||l&&!c&&f?Hs(y+D*C,s[1][0])/C:Us(y+(l?T:-T)*C,s[0][0])/C,j=Math.max(j,e)}}}T+=T<0?j:-j,w+=w<0?A:-A,i&&(f?E>D*C?T=(Gs(c,l)?-w:w)/C:w=(Gs(c,l)?-T:T)*C:u?(T=w/C,l=c):(w=T*C,c=l));let M=c?y+w:y,N=l?b+T:b;return{width:x+(c?-w:w),height:S+(l?-T:T),x:a[0]*w*(c?-1:1)+M,y:a[1]*T*(l?-1:1)+N}}var qs={width:0,height:0,x:0,y:0},Js={...qs,pointerX:0,pointerY:0,aspectRatio:1};function Ys(e,t,n){let r=t.position.x+e.position.x,i=t.position.y+e.position.y,a=e.measured.width??0,o=e.measured.height??0,s=n[0]*a,c=n[1]*o;return[[r-s,i-c],[r+a-s,i+o-c]]}function Xs({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){let a=kt(e),o={controlDirection:Vs(`bottom-right`),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function s({controlPosition:e,boundaries:s,keepAspectRatio:c,resizeDirection:l,onResizeStart:u,onResize:d,onResizeEnd:f,shouldResize:p}){let m={...qs},h={...Js};o={boundaries:s,resizeDirection:l,keepAspectRatio:c,controlDirection:Vs(e)};let g,_=null,v=[],y,b,x,S=Wt().on(`start`,e=>{let{nodeLookup:r,transform:i,snapGrid:a,snapToGrid:o,nodeOrigin:s,paneDomNode:c}=n();if(g=r.get(t),!g)return;_=c?.getBoundingClientRect()??null;let{xSnapped:l,ySnapped:d}=lo(e.sourceEvent,{transform:i,snapGrid:a,snapToGrid:o,containerBounds:_});m={width:g.measured.width??0,height:g.measured.height??0,x:g.position.x??0,y:g.position.y??0},h={...m,pointerX:l,pointerY:d,aspectRatio:m.width/m.height},y=void 0,b=to(g.extent)?g.extent:void 0,g.parentId&&(g.extent===`parent`||g.expandParent)&&(y=r.get(g.parentId)),y&&g.extent===`parent`&&(b=[[0,0],[y.measured.width,y.measured.height]]),v=[],x=void 0;for(let[e,n]of r)if(n.parentId===t&&(v.push({id:e,position:{...n.position},extent:n.extent}),n.extent===`parent`||n.expandParent)){let e=Ys(n,g,n.origin??s);x=x?[[Math.min(e[0][0],x[0][0]),Math.min(e[0][1],x[0][1])],[Math.max(e[1][0],x[1][0]),Math.max(e[1][1],x[1][1])]]:e}u?.(e,{...m})}).on(`drag`,e=>{let{transform:t,snapGrid:i,snapToGrid:a,nodeOrigin:s}=n(),c=lo(e.sourceEvent,{transform:t,snapGrid:i,snapToGrid:a,containerBounds:_}),l=[];if(!g)return;let{x:u,y:f,width:S,height:C}=m,w={},T=g.origin??s,{width:E,height:D,x:O,y:k}=Ks(h,o.controlDirection,c,o.boundaries,o.keepAspectRatio,T,b,x),A=E!==S,j=D!==C,M=O!==u&&A,N=k!==f&&j;if(!M&&!N&&!A&&!j)return;let P={prevValues:{...m},startX:h.x,startY:h.y,childNodes:v.map(e=>({...e,position:{...e.position}}))};if((M||N||T[0]===1||T[1]===1)&&(w.x=M?O:m.x,w.y=N?k:m.y,m.x=w.x,m.y=w.y,v.length>0)){let e=O-u,t=k-f;for(let n of v)n.position={x:n.position.x-e+T[0]*(E-S),y:n.position.y-t+T[1]*(D-C)},l.push(n)}if((A||j)&&(w.width=A&&(!o.resizeDirection||o.resizeDirection===`horizontal`)?E:m.width,w.height=j&&(!o.resizeDirection||o.resizeDirection===`vertical`)?D:m.height,m.width=w.width,m.height=w.height),y&&g.expandParent){let e=T[0]*(w.width??0);w.x&&w.x<e&&(m.x=e,h.x-=w.x-e);let t=T[1]*(w.height??0);w.y&&w.y<t&&(m.y=t,h.y-=w.y-t)}let F=Bs({width:m.width,prevWidth:S,height:m.height,prevHeight:C,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),I={...m,direction:F};p?.(e,I)===!1?(m=P.prevValues,h.x=P.startX,h.y=P.startY,v.forEach((e,t)=>{e.position=P.childNodes[t].position})):(d?.(e,I),r(w,l))}).on(`end`,e=>{f?.(e,{...m}),i?.({...m})});a.call(S)}function c(){a.on(`.drag`,null)}return{update:s,destroy:c}}var Zs=n((e=>{var t=u();function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var r=typeof Object.is==`function`?Object.is:n,i=t.useState,a=t.useEffect,o=t.useLayoutEffect,s=t.useDebugValue;function c(e,t){var n=t(),r=i({inst:{value:n,getSnapshot:t}}),c=r[0].inst,u=r[1];return o(function(){c.value=n,c.getSnapshot=t,l(c)&&u({inst:c})},[e,n,t]),a(function(){return l(c)&&u({inst:c}),e(function(){l(c)&&u({inst:c})})},[e]),s(n),n}function l(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:c;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),Qs=n(((e,t)=>{t.exports=Zs()})),$s=n((e=>{var t=u(),n=Qs();function r(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:r,a=n.useSyncExternalStore,o=t.useRef,s=t.useEffect,c=t.useMemo,l=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,u){var d=o(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=c(function(){function e(e){if(!a){if(a=!0,o=e,e=r(e),u!==void 0&&f.hasValue){var t=f.value;if(u(t,e))return s=t}return s=e}if(t=s,i(o,e))return t;var n=r(e);return u!==void 0&&u(t,n)?(o=e,t):(o=e,s=n)}var a=!1,o,s,c=n===void 0?null:n;return[function(){return e(t())},c===null?void 0:function(){return e(c())}]},[t,n,r,u]);var p=a(e,d[0],d[1]);return s(function(){f.hasValue=!0,f.value=p},[p]),l(p),p}})),ec=r(n(((e,t)=>{t.exports=$s()}))(),1),tc=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e)),destroy:()=>{n.clear()}},o=t=e(r,i,a);return a},nc=e=>e?tc(e):tc,{useDebugValue:rc}=d.default,{useSyncExternalStoreWithSelector:ic}=ec.default,ac=e=>e;function oc(e,t=ac,n){let r=ic(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return rc(r),r}var sc=(e,t)=>{let n=nc(e),r=(e,r=t)=>oc(n,e,r);return Object.assign(r,n),r},cc=(e,t)=>e?sc(e,t):sc;function W(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var lc=a(),uc=(0,d.createContext)(null),dc=uc.Provider,fc=ca.error001(`react`);function G(e,t){let n=(0,d.useContext)(uc);if(n===null)throw Error(fc);return oc(n,e,t)}function K(){let e=(0,d.useContext)(uc);if(e===null)throw Error(fc);return(0,d.useMemo)(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}var pc={display:`none`},mc={position:`absolute`,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0px, 0px, 0px, 0px)`,clipPath:`inset(100%)`},hc=`react-flow__node-desc`,gc=`react-flow__edge-desc`,_c=`react-flow__aria-live`,vc=e=>e.ariaLiveMessage,yc=e=>e.ariaLabelConfig;function bc({rfId:e}){let t=G(vc);return(0,f.jsx)(`div`,{id:`${_c}-${e}`,"aria-live":`assertive`,"aria-atomic":`true`,style:mc,children:t})}function xc({rfId:e,disableKeyboardA11y:t}){let n=G(yc);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{id:`${hc}-${e}`,style:pc,children:t?n[`node.a11yDescription.default`]:n[`node.a11yDescription.keyboardDisabled`]}),(0,f.jsx)(`div`,{id:`${gc}-${e}`,style:pc,children:n[`edge.a11yDescription.default`]}),!t&&(0,f.jsx)(bc,{rfId:e})]})}var Sc=(0,d.forwardRef)(({position:e=`top-left`,children:t,className:n,style:r,...i},a)=>{let o=`${e}`.split(`-`);return(0,f.jsx)(`div`,{className:p([`react-flow__panel`,n,...o]),style:r,ref:a,...i,children:t})});Sc.displayName=`Panel`;var Cc=`https://reactflow.dev?utm_source=attribution`;function wc({proOptions:e,position:t=`bottom-right`}){return(0,d.useEffect)(()=>{},[]),e?.hideAttribution?null:(0,f.jsx)(Sc,{position:t,className:`react-flow__attribution`,"data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: ${Cc}`,children:(0,f.jsx)(`a`,{href:Cc,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`React Flow attribution`,children:`React Flow`})})}var Tc=e=>{let t=[],n=[];for(let[,n]of e.nodeLookup)n.selected&&t.push(n.internals.userNode);for(let[,t]of e.edgeLookup)t.selected&&n.push(t);return{selectedNodes:t,selectedEdges:n}},Ec=e=>e.id;function Dc(e,t){return W(e.selectedNodes.map(Ec),t.selectedNodes.map(Ec))&&W(e.selectedEdges.map(Ec),t.selectedEdges.map(Ec))}function Oc({onSelectionChange:e}){let t=K(),{selectedNodes:n,selectedEdges:r}=G(Tc,Dc);return(0,d.useEffect)(()=>{let i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(e=>e(i))},[n,r,e]),null}var kc=e=>!!e.onSelectionChangeHandlers;function Ac({onSelectionChange:e}){let t=G(kc);return e||t?(0,f.jsx)(Oc,{onSelectionChange:e}):null}var jc=[0,0],Mc={x:0,y:0,zoom:1},Nc=[...`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`.split(`.`),`rfId`],Pc=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}),Fc={translateExtent:la,nodeOrigin:jc,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:`nopan`,rfId:`1`};function Ic(e){let{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:a,setNodeExtent:o,reset:s,setDefaultNodesAndEdges:c}=G(Pc,W),l=K();(0,d.useEffect)(()=>(c(e.defaultNodes,e.defaultEdges),()=>{u.current=Fc,s()}),[]);let u=(0,d.useRef)(Fc);return(0,d.useEffect)(()=>{for(let s of Nc){let c=e[s];c!==u.current[s]&&e[s]!==void 0&&(s===`nodes`?t(c):s===`edges`?n(c):s===`minZoom`?r(c):s===`maxZoom`?i(c):s===`translateExtent`?a(c):s===`nodeExtent`?o(c):s===`ariaLabelConfig`?l.setState({ariaLabelConfig:so(c)}):s===`fitView`?l.setState({fitViewQueued:c}):s===`fitViewOptions`?l.setState({fitViewOptions:c}):l.setState({[s]:c}))}u.current=e},Nc.map(t=>e[t])),null}function Lc(){return typeof window>`u`||!window.matchMedia?null:window.matchMedia(`(prefers-color-scheme: dark)`)}function Rc(e){let[t,n]=(0,d.useState)(e===`system`?null:e);return(0,d.useEffect)(()=>{if(e!==`system`){n(e);return}let t=Lc(),r=()=>n(t?.matches?`dark`:`light`);return r(),t?.addEventListener(`change`,r),()=>{t?.removeEventListener(`change`,r)}},[e]),t===null?Lc()?.matches?`dark`:`light`:t}var zc=typeof document<`u`?document:null;function Bc(e=null,t={target:zc,actInsideInputWithModifier:!0}){let[n,r]=(0,d.useState)(!1),i=(0,d.useRef)(!1),a=(0,d.useRef)(new Set([])),[o,s]=(0,d.useMemo)(()=>{if(e!==null){let t=(Array.isArray(e)?e:[e]).filter(e=>typeof e==`string`).map(e=>e.replace(/\+/g,`
2
+ `).replace(`
3
+
4
+ `,`
5
+ +`).split(`
6
+ `));return[t,t.reduce((e,t)=>e.concat(...t),[])]}return[[],[]]},[e]);return(0,d.useEffect)(()=>{let n=t?.target??zc,c=t?.actInsideInputWithModifier??!0;if(e!==null){let e=e=>{if(i.current=e.ctrlKey||e.metaKey||e.shiftKey||e.altKey,(!i.current||i.current&&!c)&&mo(e))return!1;let n=Hc(e.code,s);if(a.current.add(e[n]),Vc(o,a.current,!1)){let n=e.composedPath?.()?.[0]||e.target,a=n?.nodeName===`BUTTON`||n?.nodeName===`A`;t.preventDefault!==!1&&(i.current||!a)&&e.preventDefault(),r(!0)}},l=e=>{let t=Hc(e.code,s);Vc(o,a.current,!0)?(r(!1),a.current.clear()):a.current.delete(e[t]),e.key===`Meta`&&a.current.clear(),i.current=!1},u=()=>{a.current.clear(),r(!1)};return n?.addEventListener(`keydown`,e),n?.addEventListener(`keyup`,l),window.addEventListener(`blur`,u),window.addEventListener(`contextmenu`,u),()=>{n?.removeEventListener(`keydown`,e),n?.removeEventListener(`keyup`,l),window.removeEventListener(`blur`,u),window.removeEventListener(`contextmenu`,u)}}},[e,r]),n}function Vc(e,t,n){return e.filter(e=>n||e.length===t.size).some(e=>e.every(e=>t.has(e)))}function Hc(e,t){return t.includes(e)?`code`:`key`}var Uc=()=>{let e=K();return(0,d.useMemo)(()=>({zoomIn:async t=>{let{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):!1},zoomOut:async t=>{let{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):!1},zoomTo:async(t,n)=>{let{panZoom:r}=e.getState();return r?r.scaleTo(t,n):!1},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{let{transform:[r,i,a],panZoom:o}=e.getState();return o?(await o.setViewport({x:t.x??r,y:t.y??i,zoom:t.zoom??a},n),!0):!1},getViewport:()=>{let[t,n,r]=e.getState().transform;return{x:t,y:n,zoom:r}},setCenter:async(t,n,r)=>e.getState().setCenter(t,n,r),fitBounds:async(t,n)=>{let{width:r,height:i,minZoom:a,maxZoom:o,panZoom:s}=e.getState(),c=$a(t,r,i,a,o,n?.padding??.1);return s?(await s.setViewport(c,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0):!1},screenToFlowPosition:(t,n={})=>{let{transform:r,snapGrid:i,snapToGrid:a,domNode:o}=e.getState();if(!o)return t;let{x:s,y:c}=o.getBoundingClientRect(),l={x:t.x-s,y:t.y-c},u=n.snapGrid??i;return Ja(l,r,n.snapToGrid??a,u)},flowToScreenPosition:t=>{let{transform:n,domNode:r}=e.getState();if(!r)return t;let{x:i,y:a}=r.getBoundingClientRect(),o=Ya(t,n);return{x:o.x+i,y:o.y+a}}}),[])};function Wc(e,t){let n=[],r=new Map,i=[];for(let t of e)if(t.type===`add`){i.push(t);continue}else if(t.type===`remove`||t.type===`replace`)r.set(t.id,[t]);else{let e=r.get(t.id);e?e.push(t):r.set(t.id,[t])}for(let e of t){let t=r.get(e.id);if(!t){n.push(e);continue}if(t[0].type===`remove`)continue;if(t[0].type===`replace`){n.push({...t[0].item});continue}let i={...e};for(let e of t)Gc(e,i);n.push(i)}return i.length&&i.forEach(e=>{e.index===void 0?n.push({...e.item}):n.splice(e.index,0,{...e.item})}),n}function Gc(e,t){switch(e.type){case`select`:t.selected=e.selected;break;case`position`:e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case`dimensions`:e.dimensions!==void 0&&(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)}}function Kc(e,t){return Wc(e,t)}function qc(e,t){return Wc(e,t)}function Jc(e,t){return{id:e,type:`select`,selected:t}}function Yc(e,t=new Set,n=!1){let r=[];for(let[i,a]of e){let e=t.has(i);(a.selected!==void 0||e)&&a.selected!==e&&(n&&(a.selected=e),r.push(Jc(a.id,e)))}return r}function Xc({items:e=[],lookup:t}){let n=[],r=new Map(e.map(e=>[e.id,e]));for(let[r,i]of e.entries()){let e=t.get(i.id),a=e?.internals?.userNode??e;a!==void 0&&a!==i&&n.push({id:i.id,item:i,type:`replace`}),a===void 0&&n.push({item:i,type:`add`,index:r})}for(let[e]of t)r.get(e)===void 0&&n.push({id:e,type:`remove`});return n}function Zc(e){return{id:e.id,type:`remove`}}var Qc=Ka(`React Flow`,`https://reactflow.dev/`);function $c(e,t,n={}){return Do(e,t,{...n,onError:n.onError??Qc})}var el=e=>ba(e),tl=e=>ya(e);function nl(e){return(0,d.forwardRef)(e)}var rl=typeof window<`u`?d.useLayoutEffect:d.useEffect;function il(e){let[t,n]=(0,d.useState)(BigInt(0)),[r]=(0,d.useState)(()=>al(()=>n(e=>e+BigInt(1))));return rl(()=>{let t=r.get();t.length&&(e(t),r.reset())},[t]),r}function al(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}var ol=(0,d.createContext)(null);function sl({children:e}){let t=K(),n=il((0,d.useCallback)(e=>{let{nodes:n=[],setNodes:r,hasDefaultNodes:i,onNodesChange:a,nodeLookup:o,fitViewQueued:s,onNodesChangeMiddlewareMap:c}=t.getState(),l=n;for(let t of e)l=typeof t==`function`?t(l):t;let u=Xc({items:l,lookup:o});for(let e of c.values())u=e(u);i&&r(l),u.length>0?a?.(u):s&&window.requestAnimationFrame(()=>{let{fitViewQueued:e,nodes:n,setNodes:r}=t.getState();e&&r(n)})},[])),r=il((0,d.useCallback)(e=>{let{edges:n=[],setEdges:r,hasDefaultEdges:i,onEdgesChange:a,edgeLookup:o}=t.getState(),s=n;for(let t of e)s=typeof t==`function`?t(s):t;i?r(s):a&&a(Xc({items:s,lookup:o}))},[])),i=(0,d.useMemo)(()=>({nodeQueue:n,edgeQueue:r}),[]);return(0,f.jsx)(ol.Provider,{value:i,children:e})}function cl(){let e=(0,d.useContext)(ol);if(!e)throw Error(`useBatchContext must be used within a BatchProvider`);return e}var ll=e=>!!e.panZoom;function ul(){let e=Uc(),t=K(),n=cl(),r=G(ll),i=(0,d.useMemo)(()=>{let e=e=>t.getState().nodeLookup.get(e),r=e=>{n.nodeQueue.push(e)},i=e=>{n.edgeQueue.push(e)},a=e=>{let{nodeLookup:n,nodeOrigin:r}=t.getState(),i=el(e)?e:n.get(e.id),a=i.parentId?io(i.position,i.measured,i.parentId,n,r):i.position;return za({...i,position:a,width:i.measured?.width??i.width,height:i.measured?.height??i.height})},o=(e,t,n={replace:!1})=>{r(r=>r.map(r=>{if(r.id===e){let e=typeof t==`function`?t(r):t;return n.replace&&el(e)?e:{...r,...e}}return r}))},s=(e,t,n={replace:!1})=>{i(r=>r.map(r=>{if(r.id===e){let e=typeof t==`function`?t(r):t;return n.replace&&tl(e)?e:{...r,...e}}return r}))};return{getNodes:()=>t.getState().nodes.map(e=>({...e})),getNode:t=>e(t)?.internals.userNode,getInternalNode:e,getEdges:()=>{let{edges:e=[]}=t.getState();return e.map(e=>({...e}))},getEdge:e=>t.getState().edgeLookup.get(e),setNodes:r,setEdges:i,addNodes:e=>{let t=Array.isArray(e)?e:[e];n.nodeQueue.push(e=>[...e,...t])},addEdges:e=>{let t=Array.isArray(e)?e:[e];n.edgeQueue.push(e=>[...e,...t])},toObject:()=>{let{nodes:e=[],edges:n=[],transform:r}=t.getState(),[i,a,o]=r;return{nodes:e.map(e=>({...e})),edges:n.map(e=>({...e})),viewport:{x:i,y:a,zoom:o}}},deleteElements:async({nodes:e=[],edges:n=[]})=>{let{nodes:r,edges:i,onNodesDelete:a,onEdgesDelete:o,triggerNodeChanges:s,triggerEdgeChanges:c,onDelete:l,onBeforeDelete:u}=t.getState(),{nodes:d,edges:f}=await Aa({nodesToRemove:e,edgesToRemove:n,nodes:r,edges:i,onBeforeDelete:u}),p=f.length>0,m=d.length>0;if(p){let e=f.map(Zc);o?.(f),c(e)}if(m){let e=d.map(Zc);a?.(d),s(e)}return(m||p)&&l?.({nodes:d,edges:f}),{deletedNodes:d,deletedEdges:f}},getIntersectingNodes:(e,n=!0,r)=>{let i=Wa(e),o=i?e:a(e),s=r!==void 0;return o?(r||t.getState().nodes).filter(r=>{let a=t.getState().nodeLookup.get(r.id);if(a&&!i&&(r.id===e.id||!a.internals.positionAbsolute))return!1;let c=za(s?r:a),l=Ua(c,o);return n&&l>0||l>=c.width*c.height||l>=o.width*o.height}):[]},isNodeIntersecting:(e,t,n=!0)=>{let r=Wa(e)?e:a(e);if(!r)return!1;let i=Ua(r,t);return n&&i>0||i>=t.width*t.height||i>=r.width*r.height},updateNode:o,updateNodeData:(e,t,n={replace:!1})=>{o(e,e=>{let r=typeof t==`function`?t(e):t;return n.replace?{...e,data:r}:{...e,data:{...e.data,...r}}},n)},updateEdge:s,updateEdgeData:(e,t,n={replace:!1})=>{s(e,e=>{let r=typeof t==`function`?t(e):t;return n.replace?{...e,data:r}:{...e,data:{...e.data,...r}}},n)},getNodesBounds:e=>{let{nodeLookup:n,nodeOrigin:r}=t.getState();return Ca(e,{nodeLookup:n,nodeOrigin:r})},getHandleConnections:({type:e,id:n,nodeId:r})=>Array.from(t.getState().connectionLookup.get(`${r}-${e}${n?`-${n}`:``}`)?.values()??[]),getNodeConnections:({type:e,handleId:n,nodeId:r})=>Array.from(t.getState().connectionLookup.get(`${r}${e?n?`-${e}-${n}`:`-${e}`:``}`)?.values()??[]),fitView:async e=>{let r=t.getState().fitViewResolver??oo();return t.setState({fitViewQueued:!0,fitViewOptions:e,fitViewResolver:r}),n.nodeQueue.push(e=>[...e]),r.promise}}},[]);return(0,d.useMemo)(()=>({...i,...e,viewportInitialized:r}),[r])}var dl=e=>e.selected,fl=typeof window<`u`?window:void 0;function pl({deleteKeyCode:e,multiSelectionKeyCode:t}){let n=K(),{deleteElements:r}=ul(),i=Bc(e,{actInsideInputWithModifier:!1}),a=Bc(t,{target:fl});(0,d.useEffect)(()=>{if(i){let{edges:e,nodes:t}=n.getState();r({nodes:t.filter(dl),edges:e.filter(dl)}),n.setState({nodesSelectionActive:!1})}},[i]),(0,d.useEffect)(()=>{n.setState({multiSelectionActive:a})},[a])}function ml(e){let t=K();(0,d.useEffect)(()=>{let n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;let n=uo(e.current);(n.height===0||n.width===0)&&t.getState().onError?.(`004`,ca.error004()),t.setState({width:n.width||500,height:n.height||500})};if(e.current){n(),window.addEventListener(`resize`,n);let t=new ResizeObserver(()=>n());return t.observe(e.current),()=>{window.removeEventListener(`resize`,n),t&&e.current&&t.unobserve(e.current)}}},[])}var hl={position:`absolute`,width:`100%`,height:`100%`,top:0,left:0},gl=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function _l({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:r=!1,panActivationKeyPressed:i,panOnScrollSpeed:a=.5,panOnScrollMode:o=pa.Free,zoomOnDoubleClick:s=!0,panOnDrag:c=!0,defaultViewport:l,translateExtent:u,minZoom:p,maxZoom:m,zoomActivationKeyCode:h,preventScrolling:g=!0,children:_,noWheelClassName:v,noPanClassName:y,onViewportChange:b,isControlledViewport:x,paneClickDistance:S,selectionOnDrag:C}){let w=K(),T=(0,d.useRef)(null),{userSelectionActive:E,lib:D,connectionInProgress:O}=G(gl,W),k=Bc(h),A=(0,d.useRef)();ml(T);let j=(0,d.useCallback)(e=>{b?.({x:e[0],y:e[1],zoom:e[2]}),x||w.setState({transform:e})},[b,x]);return(0,d.useEffect)(()=>{if(T.current){A.current=Is({domNode:T.current,minZoom:p,maxZoom:m,translateExtent:u,viewport:l,onDraggingChange:e=>w.setState(t=>t.paneDragging===e?t:{paneDragging:e}),onPanZoomStart:(e,t)=>{let{onViewportChangeStart:n,onMoveStart:r}=w.getState();r?.(e,t),n?.(t)},onPanZoom:(e,t)=>{let{onViewportChange:n,onMove:r}=w.getState();r?.(e,t),n?.(t)},onPanZoomEnd:(e,t)=>{let{onViewportChangeEnd:n,onMoveEnd:r}=w.getState();r?.(e,t),n?.(t)}});let{x:e,y:t,zoom:n}=A.current.getViewport();return w.setState({panZoom:A.current,transform:[e,t,n],domNode:T.current.closest(`.react-flow`)}),()=>{A.current?.destroy()}}},[]),(0,d.useEffect)(()=>{A.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:r,panActivationKeyPressed:i,panOnScrollSpeed:a,panOnScrollMode:o,zoomOnDoubleClick:s,panOnDrag:c,zoomActivationKeyPressed:k,preventScrolling:g,noPanClassName:y,userSelectionActive:E,noWheelClassName:v,lib:D,onTransformChange:j,connectionInProgress:O,selectionOnDrag:C,paneClickDistance:S})},[e,t,n,r,i,a,o,s,c,k,g,y,E,v,D,j,O,C,S]),(0,f.jsx)(`div`,{className:`react-flow__renderer`,ref:T,style:hl,children:_})}var vl=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function yl(){let{userSelectionActive:e,userSelectionRect:t}=G(vl,W);return e&&t?(0,f.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}var bl=(e,t)=>n=>{n.target===t.current&&e?.(n)},xl=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function Sl({isSelecting:e,selectionKeyPressed:t,selectionMode:n=ma.Full,panOnDrag:r,autoPanOnSelection:i,paneClickDistance:a,selectionOnDrag:o,onSelectionStart:s,onSelectionEnd:c,onPaneClick:l,onPaneContextMenu:u,onPaneScroll:m,onPaneMouseEnter:h,onPaneMouseMove:g,onPaneMouseLeave:_,children:v}){let y=(0,d.useRef)(0),b=K(),{userSelectionActive:x,elementsSelectable:S,dragging:C,panBy:w,autoPanSpeed:T}=G(xl,W),E=S&&(e||x),D=(0,d.useRef)(null),O=(0,d.useRef)(),k=(0,d.useRef)(new Set),A=(0,d.useRef)(new Set),j=(0,d.useRef)(!1),M=(0,d.useRef)(!1),N=(0,d.useRef)({x:0,y:0}),P=(0,d.useRef)(!1),F=e=>{M.current||j.current||b.getState().connection.inProgress?(M.current=!1,j.current=!1):(l?.(e),b.getState().resetSelectedElements(),b.setState({nodesSelectionActive:!1}))},I=e=>{Array.isArray(r)&&r?.includes(2)?e.preventDefault():u?.(e)},L=m?e=>m(e):void 0,R=e=>{M.current&&=(e.stopPropagation(),!1)},z=n=>{if(n.pointerType===`touch`&&r!==!1&&!t)return;let{domNode:i,transform:a}=b.getState();if(O.current=i?.getBoundingClientRect(),!O.current)return;let s=n.target===D.current;if(!s&&n.target.closest(`.nokey`)||!e||!(o&&s||t)||n.button!==0||!n.isPrimary)return;n.target?.setPointerCapture?.(n.pointerId),M.current=!1;let{x:c,y:l}=go(n.nativeEvent,O.current),u=Ja({x:c,y:l},a);b.setState({userSelectionRect:{width:0,height:0,startX:u.x,startY:u.y,x:c,y:l}}),s||(n.stopPropagation(),n.preventDefault())};function B(e,t){let{userSelectionRect:r}=b.getState();if(!r)return;let{transform:i,nodeLookup:a,edgeLookup:o,connectionLookup:s,triggerNodeChanges:c,triggerEdgeChanges:l,defaultEdgeOptions:u}=b.getState(),d={x:r.startX,y:r.startY},{x:f,y:p}=Ya(d,i),m={startX:d.x,startY:d.y,x:e<f?e:f,y:t<p?t:p,width:Math.abs(e-f),height:Math.abs(t-p)},h=k.current,g=A.current;k.current=new Set(Ta(a,m,i,n===ma.Partial,!0).map(e=>e.id)),A.current=new Set;let _=u?.selectable??!0;for(let e of k.current){let t=s.get(e);if(t)for(let{edgeId:e}of t.values()){let t=o.get(e);t&&(t.selectable??_)&&A.current.add(e)}}ao(h,k.current)||c(Yc(a,k.current,!0)),ao(g,A.current)||l(Yc(o,A.current)),b.setState({userSelectionRect:m,userSelectionActive:!0,nodesSelectionActive:!1})}function V(){if(!i||!O.current)return;let[e,t]=Fa(N.current,O.current,T);w({x:e,y:t}).then(e=>{if(!M.current||!e){y.current=requestAnimationFrame(V);return}let{x:t,y:n}=N.current;B(t,n),y.current=requestAnimationFrame(V)})}let H=()=>{cancelAnimationFrame(y.current),y.current=0,P.current=!1};(0,d.useEffect)(()=>()=>H(),[]);let ee=e=>{let{userSelectionRect:n,transform:r,resetSelectedElements:i}=b.getState();if(!O.current||!n)return;let{x:o,y:c}=go(e.nativeEvent,O.current);N.current={x:o,y:c};let l=Ya({x:n.startX,y:n.startY},r);if(!M.current){let n=t?0:a;if(Math.hypot(o-l.x,c-l.y)<=n)return;i(),s?.(e)}M.current=!0,P.current||=(V(),!0),B(o,c)},te=e=>{E?e.button===0&&(e.target?.releasePointerCapture?.(e.pointerId),!x&&e.target===D.current&&b.getState().userSelectionRect&&F?.(e),b.setState({userSelectionActive:!1,userSelectionRect:null}),M.current&&(c?.(e),b.setState({nodesSelectionActive:k.current.size>0})),H()):e.target===D.current&&b.getState().connection.inProgress&&(j.current=!0)},ne=e=>{e.target?.releasePointerCapture?.(e.pointerId),H()},re=r===!0||Array.isArray(r)&&r.includes(0);return(0,f.jsxs)(`div`,{className:p([`react-flow__pane`,{draggable:re,dragging:C,selection:e}]),onClick:E?void 0:bl(F,D),onContextMenu:bl(I,D),onWheel:bl(L,D),onPointerEnter:E?void 0:h,onPointerMove:E?ee:g,onPointerUp:te,onPointerCancel:E?ne:void 0,onPointerDownCapture:E?z:void 0,onClickCapture:E?R:void 0,onPointerLeave:_,ref:D,style:hl,children:[v,(0,f.jsx)(yl,{})]})}function Cl({id:e,store:t,unselect:n=!1,nodeRef:r}){let{addSelectedNodes:i,unselectNodesAndEdges:a,multiSelectionActive:o,nodeLookup:s,onError:c}=t.getState(),l=s.get(e);l?(t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(a({nodes:[l],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])):c?.(`012`,ca.error012(e))}function wl({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:i,isSelectable:a,nodeClickDistance:o}){let s=K(),[c,l]=(0,d.useState)(!1),u=(0,d.useRef)();return(0,d.useEffect)(()=>{if(!t)return u.current=ds({getStoreItems:()=>s.getState(),onNodeMouseDown:t=>{Cl({id:t,store:s,nodeRef:e})},onDragStart:()=>{l(!0)},onDragStop:()=>{l(!1)}}),()=>{u.current?.destroy(),u.current=void 0}},[t,s,e]),(0,d.useEffect)(()=>{!t&&e.current&&u.current&&u.current.update({noDragClassName:n,handleSelector:r,domNode:e.current,isSelectable:a,nodeId:i,nodeClickDistance:o})},[n,r,t,a,e,i,o]),c}var Tl=e=>t=>t.selected&&(t.draggable||e&&t.draggable===void 0);function El(){let e=K();return(0,d.useCallback)(t=>{let{nodeExtent:n,snapToGrid:r,snapGrid:i,nodesDraggable:a,onError:o,updateNodePositions:s,nodeLookup:c,nodeOrigin:l}=e.getState(),u=new Map,d=Tl(a),f=r?i[0]:5,p=r?i[1]:5,m=t.direction.x*f*t.factor,h=t.direction.y*p*t.factor;for(let[,e]of c){if(!d(e))continue;let t={x:e.internals.positionAbsolute.x+m,y:e.internals.positionAbsolute.y+h};r&&(t=qa(t,i));let{position:a,positionAbsolute:s}=ka({nodeId:e.id,nextPosition:t,nodeLookup:c,nodeExtent:n,nodeOrigin:l,onError:o});e.position=a,e.internals.positionAbsolute=s,u.set(e.id,e)}s(u)},[])}var Dl=(0,d.createContext)(null),Ol=Dl.Provider;Dl.Consumer;var kl=()=>(0,d.useContext)(Dl),Al=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),jl=(0,d.createContext)(null);function Ml({children:e}){let t=G(Al,W);return(0,f.jsx)(jl.Provider,{value:t,children:e})}function Nl(){let e=(0,d.useContext)(jl);if(!e)throw Error(`useHandleConfig must be used within a HandleConfigProvider`);return e}var Pl={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},Fl=(e,t,n)=>r=>{let{connectionClickStartHandle:i,connectionMode:a,connection:o}=r,{fromHandle:s,toHandle:c,isValid:l}=o;if(!s&&!i)return Pl;let u=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:s?.nodeId===e&&s?.id===t&&s?.type===n,connectingTo:u,clickConnecting:i?.nodeId===e&&i?.id===t&&i?.type===n,isPossibleEndHandle:a===fa.Strict?s?.type!==n:e!==s?.nodeId||t!==s?.id,connectionInProcess:!!s,clickConnectionInProcess:!!i,valid:u&&l}};function Il({type:e=`source`,position:t=U.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:a=!0,id:o,onConnect:s,children:c,className:l,onMouseDown:u,onTouchStart:d,...m},h){let g=o||null,_=e===`target`,v=K(),y=kl(),{connectOnClick:b,noPanClassName:x,rfId:S}=Nl(),{connectingFrom:C,connectingTo:w,clickConnecting:T,isPossibleEndHandle:E,connectionInProcess:D,clickConnectionInProcess:O,valid:k}=G(Fl(y,g,e),W);y||v.getState().onError?.(`010`,ca.error010());let A=e=>{let{defaultEdgeOptions:t,onConnect:n,hasDefaultEdges:r}=v.getState(),i={...t,...e};if(r){let{edges:e,setEdges:t,onError:n}=v.getState();t($c(i,e,{onError:n}))}n?.(i),s?.(i)},j=e=>{if(!y)return;let t=ho(e.nativeEvent);if(i&&(t&&e.button===0||!t)){let t=v.getState();xs.onPointerDown(e.nativeEvent,{handleDomNode:e.currentTarget,autoPanOnConnect:t.autoPanOnConnect,connectionMode:t.connectionMode,connectionRadius:t.connectionRadius,domNode:t.domNode,nodeLookup:t.nodeLookup,lib:t.lib,isTarget:_,handleId:g,nodeId:y,flowId:t.rfId,panBy:t.panBy,cancelConnection:t.cancelConnection,onConnectStart:t.onConnectStart,onConnectEnd:(...e)=>v.getState().onConnectEnd?.(...e),updateConnection:t.updateConnection,onConnect:A,isValidConnection:n||((...e)=>v.getState().isValidConnection?.(...e)??!0),getTransform:()=>v.getState().transform,getFromHandle:()=>v.getState().connection.fromHandle,autoPanSpeed:t.autoPanSpeed,dragThreshold:t.connectionDragThreshold})}t?u?.(e):d?.(e)};return(0,f.jsx)(`div`,{"data-handleid":g,"data-nodeid":y,"data-handlepos":t,"data-id":`${S}-${y}-${g}-${e}`,className:p([`react-flow__handle`,`react-flow__handle-${t}`,`nodrag`,x,l,{source:!_,target:_,connectable:r,connectablestart:i,connectableend:a,clickconnecting:T,connectingfrom:C,connectingto:w,valid:k,connectionindicator:r&&(!D||E)&&(D||O?a:i)}]),onMouseDown:j,onTouchStart:j,onClick:b?t=>{let{onClickConnectStart:r,onClickConnectEnd:a,connectionClickStartHandle:o,connectionMode:s,isValidConnection:c,lib:l,rfId:u,nodeLookup:d,connection:f}=v.getState();if(!y||!o&&!i)return;if(!o){r?.(t.nativeEvent,{nodeId:y,handleId:g,handleType:e}),v.setState({connectionClickStartHandle:{nodeId:y,type:e,id:g}});return}let p=fo(t.target),m=n||c,{connection:h,isValid:_}=xs.isValid(t.nativeEvent,{handle:{nodeId:y,id:g,type:e},connectionMode:s,fromNodeId:o.nodeId,fromHandleId:o.id||null,fromType:o.type,isValidConnection:m,flowId:u,doc:p,lib:l,nodeLookup:d});_&&h&&A(h);let b=structuredClone(f);delete b.inProgress,b.toPosition=b.toHandle?b.toHandle.position:null,a?.(t,b),v.setState({connectionClickStartHandle:null})}:void 0,ref:h,...m,children:c})}var Ll=(0,d.memo)(nl(Il));function Rl({data:e,isConnectable:t,sourcePosition:n=U.Bottom}){return(0,f.jsxs)(f.Fragment,{children:[e?.label,(0,f.jsx)(Ll,{type:`source`,position:n,isConnectable:t})]})}function zl({data:e,isConnectable:t,targetPosition:n=U.Top,sourcePosition:r=U.Bottom}){return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(Ll,{type:`target`,position:n,isConnectable:t}),e?.label,(0,f.jsx)(Ll,{type:`source`,position:r,isConnectable:t})]})}function Bl(){return null}function Vl({data:e,isConnectable:t,targetPosition:n=U.Top}){return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(Ll,{type:`target`,position:n,isConnectable:t}),e?.label]})}var Hl={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Ul={input:Rl,default:zl,output:Vl,group:Bl};function Wl(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}}var Gl=e=>{let{width:t,height:n,x:r,y:i}=wa(e.nodeLookup,{filter:e=>!!e.selected});return{width:Ga(t)?t:null,height:Ga(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${i}px)`}};function Kl({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){let r=K(),{width:i,height:a,transformString:o,userSelectionActive:s}=G(Gl,W),c=El(),l=(0,d.useRef)(null);(0,d.useEffect)(()=>{n||l.current?.focus({preventScroll:!0})},[n]);let u=!s&&i!==null&&a!==null;if(wl({nodeRef:l,disabled:!u}),!u)return null;let m=e?t=>{e(t,r.getState().nodes.filter(e=>e.selected))}:void 0;return(0,f.jsx)(`div`,{className:p([`react-flow__nodesselection`,`react-flow__container`,t]),style:{transform:o},children:(0,f.jsx)(`div`,{ref:l,className:`react-flow__nodesselection-rect`,onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:e=>{Object.prototype.hasOwnProperty.call(Hl,e.key)&&(e.preventDefault(),c({direction:Hl[e.key],factor:e.shiftKey?4:1}))},style:{width:i,height:a}})})}var ql=typeof window<`u`?window:void 0,Jl=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Yl({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:a,onPaneScroll:o,paneClickDistance:s,deleteKeyCode:c,selectionKeyCode:l,selectionOnDrag:u,selectionMode:d,onSelectionStart:p,onSelectionEnd:m,multiSelectionKeyCode:h,panActivationKeyCode:g,zoomActivationKeyCode:_,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:b,panOnScroll:x,panOnScrollSpeed:S,panOnScrollMode:C,zoomOnDoubleClick:w,panOnDrag:T,autoPanOnSelection:E,defaultViewport:D,translateExtent:O,minZoom:k,maxZoom:A,preventScrolling:j,onSelectionContextMenu:M,noWheelClassName:N,noPanClassName:P,disableKeyboardA11y:F,onViewportChange:I,isControlledViewport:L}){let{nodesSelectionActive:R,userSelectionActive:z}=G(Jl,W),B=Bc(l,{target:ql}),V=Bc(g,{target:ql}),H=V||T,ee=V||x,te=u&&H!==!0,ne=B||z||te;return pl({deleteKeyCode:c,multiSelectionKeyCode:h}),(0,f.jsx)(_l,{onPaneContextMenu:a,elementsSelectable:v,zoomOnScroll:y,zoomOnPinch:b,panOnScroll:ee,panActivationKeyPressed:V,panOnScrollSpeed:S,panOnScrollMode:C,zoomOnDoubleClick:w,panOnDrag:!B&&H,defaultViewport:D,translateExtent:O,minZoom:k,maxZoom:A,zoomActivationKeyCode:_,preventScrolling:j,noWheelClassName:N,noPanClassName:P,onViewportChange:I,isControlledViewport:L,paneClickDistance:s,selectionOnDrag:te,children:(0,f.jsxs)(Sl,{onSelectionStart:p,onSelectionEnd:m,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:a,onPaneScroll:o,panOnDrag:H,autoPanOnSelection:E,isSelecting:!!ne,selectionMode:d,selectionKeyPressed:B,paneClickDistance:s,selectionOnDrag:te,children:[e,R&&(0,f.jsx)(Kl,{onSelectionContextMenu:M,noPanClassName:P,disableKeyboardA11y:F})]})})}Yl.displayName=`FlowRenderer`;var Xl=(0,d.memo)(Yl),Zl=e=>t=>e?Ta(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(e=>e.id):Array.from(t.nodeLookup.keys());function Ql(e){return G((0,d.useCallback)(Zl(e),[e]),W)}var $l=e=>e.updateNodeInternals;function eu(){let e=G($l),[t]=(0,d.useState)(()=>typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{let n=new Map;t.forEach(e=>{let t=e.target.getAttribute(`data-id`);n.set(t,{id:t,nodeElement:e.target,force:!0})}),e(n)}));return(0,d.useEffect)(()=>()=>{t?.disconnect()},[t]),t}function tu({node:e,nodeType:t,hasDimensions:n,resizeObserver:r}){let i=K(),a=(0,d.useRef)(null),o=(0,d.useRef)(null),s=(0,d.useRef)(e.sourcePosition),c=(0,d.useRef)(e.targetPosition),l=(0,d.useRef)(t),u=n&&!!e.internals.handleBounds;return(0,d.useEffect)(()=>{a.current&&!e.hidden&&(!u||o.current!==a.current)&&(o.current&&r?.unobserve(o.current),r?.observe(a.current),o.current=a.current)},[u,e.hidden]),(0,d.useEffect)(()=>()=>{o.current&&=(r?.unobserve(o.current),null)},[]),(0,d.useEffect)(()=>{if(a.current){let n=l.current!==t,r=s.current!==e.sourcePosition,o=c.current!==e.targetPosition;(n||r||o)&&(l.current=t,s.current=e.sourcePosition,c.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:a.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),a}function nu({id:e,onClick:t,onMouseEnter:n,onMouseMove:r,onMouseLeave:i,onContextMenu:a,onDoubleClick:o,nodesDraggable:s,elementsSelectable:c,nodesConnectable:l,nodesFocusable:u,resizeObserver:d,noDragClassName:m,noPanClassName:h,disableKeyboardA11y:g,rfId:_,nodeTypes:v,nodeClickDistance:y,onError:b}){let{node:x,internals:S,isParent:C}=G(t=>{let n=t.nodeLookup.get(e),r=t.parentLookup.has(e);return{node:n,internals:n.internals,isParent:r}},W),w=x.type||`default`,T=v?.[w]||Ul[w];T===void 0&&(b?.(`003`,ca.error003(w)),w=`default`,T=v?.default||Ul.default);let E=!!(x.draggable||s&&x.draggable===void 0),D=!!(x.selectable||c&&x.selectable===void 0),O=!!(x.connectable||l&&x.connectable===void 0),k=!!(x.focusable||u&&x.focusable===void 0),A=K(),j=ro(x),M=tu({node:x,nodeType:w,hasDimensions:j,resizeObserver:d}),N=wl({nodeRef:M,disabled:x.hidden||!E,noDragClassName:m,handleSelector:x.dragHandle,nodeId:e,isSelectable:D,nodeClickDistance:y}),P=El();if(x.hidden)return null;let F=no(x),I=Wl(x),L=D||E||t||n||r||i,R=n?e=>n(e,{...S.userNode}):void 0,z=r?e=>r(e,{...S.userNode}):void 0,B=i?e=>i(e,{...S.userNode}):void 0,V=a?e=>a(e,{...S.userNode}):void 0,H=o?e=>o(e,{...S.userNode}):void 0,ee=n=>{let{selectNodesOnDrag:r,nodeDragThreshold:i}=A.getState();D&&(!r||!E||i>0)&&Cl({id:e,store:A,nodeRef:M}),t&&t(n,{...S.userNode})},te=t=>{if(!(mo(t.nativeEvent)||g)){if(ua.includes(t.key)&&D){let n=t.key===`Escape`;Cl({id:e,store:A,unselect:n,nodeRef:M})}else if(E&&x.selected&&Object.prototype.hasOwnProperty.call(Hl,t.key)){t.preventDefault();let{ariaLabelConfig:e}=A.getState();A.setState({ariaLiveMessage:e[`node.a11yDescription.ariaLiveMessage`]({direction:t.key.replace(`Arrow`,``).toLowerCase(),x:~~S.positionAbsolute.x,y:~~S.positionAbsolute.y})}),P({direction:Hl[t.key],factor:t.shiftKey?4:1})}}},ne=()=>{if(g||!M.current?.matches(`:focus-visible`))return;let{transform:t,width:n,height:r,autoPanOnNodeFocus:i,setCenter:a}=A.getState();i&&(Ta(new Map([[e,x]]),{x:0,y:0,width:n,height:r},t,!0).length>0||a(x.position.x+F.width/2,x.position.y+F.height/2,{zoom:t[2]}))};return(0,f.jsx)(`div`,{className:p([`react-flow__node`,`react-flow__node-${w}`,{[h]:E},x.className,{selected:x.selected,selectable:D,parent:C,draggable:E,dragging:N}]),ref:M,style:{zIndex:S.z,transform:`translate(${S.positionAbsolute.x}px,${S.positionAbsolute.y}px)`,pointerEvents:L?`all`:`none`,visibility:j?`visible`:`hidden`,...x.style,...I},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:R,onMouseMove:z,onMouseLeave:B,onContextMenu:V,onClick:ee,onDoubleClick:H,onKeyDown:k?te:void 0,tabIndex:k?0:void 0,onFocus:k?ne:void 0,role:x.ariaRole??(k?`group`:void 0),"aria-roledescription":`node`,"aria-describedby":g?void 0:`${hc}-${_}`,"aria-label":x.ariaLabel,...x.domAttributes,children:(0,f.jsx)(Ol,{value:e,children:(0,f.jsx)(T,{id:e,data:x.data,type:w,positionAbsoluteX:S.positionAbsolute.x,positionAbsoluteY:S.positionAbsolute.y,selected:x.selected??!1,selectable:D,draggable:E,deletable:x.deletable??!0,isConnectable:O,sourcePosition:x.sourcePosition,targetPosition:x.targetPosition,dragging:N,dragHandle:x.dragHandle,zIndex:S.z,parentId:x.parentId,...F})})})}var ru=(0,d.memo)(nu),iu=e=>({nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function au(e){let{nodesConnectable:t,nodesFocusable:n,elementsSelectable:r,onError:i}=G(iu,W),a=Ql(e.onlyRenderVisibleElements),o=eu();return(0,f.jsx)(`div`,{className:`react-flow__nodes`,style:hl,children:a.map(a=>(0,f.jsx)(ru,{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:o,nodesDraggable:e.nodesDraggable??!0,nodesConnectable:t,nodesFocusable:n,elementsSelectable:r,nodeClickDistance:e.nodeClickDistance,onError:i},a))})}au.displayName=`NodeRenderer`;var ou=(0,d.memo)(au);function su(e){return G((0,d.useCallback)(t=>{if(!e)return t.edges.map(e=>e.id);let n=[];if(t.width&&t.height)for(let e of t.edges){let r=t.nodeLookup.get(e.source),i=t.nodeLookup.get(e.target);r&&i&&wo({sourceNode:r,targetNode:i,width:t.width,height:t.height,transform:t.transform})&&n.push(e.id)}return n},[e]),W)}var cu=({color:e=`none`,strokeWidth:t=1})=>{let n={strokeWidth:t,...e&&{stroke:e}};return(0,f.jsx)(`polyline`,{className:`arrow`,style:n,strokeLinecap:`round`,fill:`none`,strokeLinejoin:`round`,points:`-5,-4 0,0 -5,4`})},lu=({color:e=`none`,strokeWidth:t=1})=>{let n={strokeWidth:t,...e&&{stroke:e,fill:e}};return(0,f.jsx)(`polyline`,{className:`arrowclosed`,style:n,strokeLinecap:`round`,strokeLinejoin:`round`,points:`-5,-4 0,0 -5,4 -5,-4`})},uu={[_a.Arrow]:cu,[_a.ArrowClosed]:lu};function du(e){let t=K();return(0,d.useMemo)(()=>Object.prototype.hasOwnProperty.call(uu,e)?uu[e]:(t.getState().onError?.(`009`,ca.error009(e)),null),[e])}var fu=({id:e,type:t,color:n,width:r=12.5,height:i=12.5,markerUnits:a=`strokeWidth`,strokeWidth:o,orient:s=`auto-start-reverse`})=>{let c=du(t);return c?(0,f.jsx)(`marker`,{className:`react-flow__arrowhead`,id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:`-10 -10 20 20`,markerUnits:a,orient:s,refX:`0`,refY:`0`,children:(0,f.jsx)(c,{color:n,strokeWidth:o})}):null},pu=({defaultColor:e,rfId:t})=>{let n=G(e=>e.edges),r=G(e=>e.defaultEdgeOptions),i=(0,d.useMemo)(()=>Vo(n,{id:t,defaultColor:e,defaultMarkerStart:r?.markerStart,defaultMarkerEnd:r?.markerEnd}),[n,r,t,e]);return i.length?(0,f.jsx)(`svg`,{className:`react-flow__marker`,"aria-hidden":`true`,children:(0,f.jsx)(`defs`,{children:i.map(e=>(0,f.jsx)(fu,{id:e.id,type:e.type,color:e.color,width:e.width,height:e.height,markerUnits:e.markerUnits,strokeWidth:e.strokeWidth,orient:e.orient},e.id))})}):null};pu.displayName=`MarkerDefinitions`;var mu=(0,d.memo)(pu);function hu({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:a,labelBgPadding:o=[2,4],labelBgBorderRadius:s=2,children:c,className:l,...u}){let[m,h]=(0,d.useState)({x:1,y:0,width:0,height:0}),g=p([`react-flow__edge-textwrapper`,l]),_=(0,d.useRef)(null);return(0,d.useEffect)(()=>{if(_.current){let e=_.current.getBBox();h({x:e.x,y:e.y,width:e.width,height:e.height})}},[n]),n?(0,f.jsxs)(`g`,{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:g,visibility:m.width?`visible`:`hidden`,...u,children:[i&&(0,f.jsx)(`rect`,{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:`react-flow__edge-textbg`,style:a,rx:s,ry:s}),(0,f.jsx)(`text`,{className:`react-flow__edge-text`,y:m.height/2,dy:`0.3em`,ref:_,style:r,children:n}),c]}):null}hu.displayName=`EdgeText`;var gu=(0,d.memo)(hu);function _u({path:e,labelX:t,labelY:n,label:r,labelStyle:i,labelShowBg:a,labelBgStyle:o,labelBgPadding:s,labelBgBorderRadius:c,interactionWidth:l=20,...u}){return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`path`,{...u,d:e,fill:`none`,className:p([`react-flow__edge-path`,u.className])}),l?(0,f.jsx)(`path`,{d:e,fill:`none`,strokeOpacity:0,strokeWidth:l,className:`react-flow__edge-interaction`}):null,r&&Ga(t)&&Ga(n)?(0,f.jsx)(gu,{x:t,y:n,label:r,labelStyle:i,labelShowBg:a,labelBgStyle:o,labelBgPadding:s,labelBgBorderRadius:c}):null]})}function vu({pos:e,x1:t,y1:n,x2:r,y2:i}){return e===U.Left||e===U.Right?[.5*(t+r),n]:[t,.5*(n+i)]}function yu({sourceX:e,sourceY:t,sourcePosition:n=U.Bottom,targetX:r,targetY:i,targetPosition:a=U.Top}){let[o,s]=vu({pos:n,x1:e,y1:t,x2:r,y2:i}),[c,l]=vu({pos:a,x1:r,y1:i,x2:e,y2:t}),[u,d,f,p]=vo({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:o,sourceControlY:s,targetControlX:c,targetControlY:l});return[`M${e},${t} C${o},${s} ${c},${l} ${r},${i}`,u,d,f,p]}function bu(e){return(0,d.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o,targetPosition:s,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:m,style:h,markerEnd:g,markerStart:_,interactionWidth:v})=>{let[y,b,x]=yu({sourceX:n,sourceY:r,sourcePosition:o,targetX:i,targetY:a,targetPosition:s}),S=e.isInternal?void 0:t;return(0,f.jsx)(_u,{id:S,path:y,labelX:b,labelY:x,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:m,style:h,markerEnd:g,markerStart:_,interactionWidth:v})})}var xu=bu({isInternal:!1}),Su=bu({isInternal:!0});xu.displayName=`SimpleBezierEdge`,Su.displayName=`SimpleBezierEdgeInternal`;function Cu(e){return(0,d.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:p,sourcePosition:m=U.Bottom,targetPosition:h=U.Top,markerEnd:g,markerStart:_,pathOptions:v,interactionWidth:y})=>{let[b,x,S]=Po({sourceX:n,sourceY:r,sourcePosition:m,targetX:i,targetY:a,targetPosition:h,borderRadius:v?.borderRadius,offset:v?.offset,stepPosition:v?.stepPosition}),C=e.isInternal?void 0:t;return(0,f.jsx)(_u,{id:C,path:b,labelX:x,labelY:S,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:p,markerEnd:g,markerStart:_,interactionWidth:y})})}var wu=Cu({isInternal:!1}),Tu=Cu({isInternal:!0});wu.displayName=`SmoothStepEdge`,Tu.displayName=`SmoothStepEdgeInternal`;function Eu(e){return(0,d.memo)(({id:t,...n})=>{let r=e.isInternal?void 0:t;return(0,f.jsx)(wu,{...n,id:r,pathOptions:(0,d.useMemo)(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}var Du=Eu({isInternal:!1}),Ou=Eu({isInternal:!0});Du.displayName=`StepEdge`,Ou.displayName=`StepEdgeInternal`;function ku(e){return(0,d.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:p,markerEnd:m,markerStart:h,interactionWidth:g})=>{let[_,v,y]=Oo({sourceX:n,sourceY:r,targetX:i,targetY:a}),b=e.isInternal?void 0:t;return(0,f.jsx)(_u,{id:b,path:_,labelX:v,labelY:y,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:p,markerEnd:m,markerStart:h,interactionWidth:g})})}var Au=ku({isInternal:!1}),ju=ku({isInternal:!0});Au.displayName=`StraightEdge`,ju.displayName=`StraightEdgeInternal`;function Mu(e){return(0,d.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o=U.Bottom,targetPosition:s=U.Top,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:m,style:h,markerEnd:g,markerStart:_,pathOptions:v,interactionWidth:y})=>{let[b,x,S]=xo({sourceX:n,sourceY:r,sourcePosition:o,targetX:i,targetY:a,targetPosition:s,curvature:v?.curvature}),C=e.isInternal?void 0:t;return(0,f.jsx)(_u,{id:C,path:b,labelX:x,labelY:S,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:p,labelBgBorderRadius:m,style:h,markerEnd:g,markerStart:_,interactionWidth:y})})}var Nu=Mu({isInternal:!1}),Pu=Mu({isInternal:!0});Nu.displayName=`BezierEdge`,Pu.displayName=`BezierEdgeInternal`;var Fu={default:Pu,straight:ju,step:Ou,smoothstep:Tu,simplebezier:Su},Iu={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},Lu=(e,t,n)=>n===U.Left?e-t:n===U.Right?e+t:e,Ru=(e,t,n)=>n===U.Top?e-t:n===U.Bottom?e+t:e,zu=`react-flow__edgeupdater`;function Bu({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:i,onMouseEnter:a,onMouseOut:o,type:s}){return(0,f.jsx)(`circle`,{onMouseDown:i,onMouseEnter:a,onMouseOut:o,className:p([zu,`${zu}-${s}`]),cx:Lu(t,r,e),cy:Ru(n,r,e),r,stroke:`transparent`,fill:`transparent`})}function Vu({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:r,sourceY:i,targetX:a,targetY:o,sourcePosition:s,targetPosition:c,onReconnect:l,onReconnectStart:u,onReconnectEnd:d,setReconnecting:p,setUpdateHover:m}){let h=K(),g=(e,t)=>{if(e.button!==0)return;let{autoPanOnConnect:r,domNode:i,connectionMode:a,connectionRadius:o,lib:s,onConnectStart:c,cancelConnection:f,nodeLookup:m,rfId:g,panBy:_,updateConnection:v}=h.getState(),y=t.type===`target`;xs.onPointerDown(e.nativeEvent,{autoPanOnConnect:r,connectionMode:a,connectionRadius:o,domNode:i,handleId:t.id,nodeId:t.nodeId,nodeLookup:m,isTarget:y,edgeUpdaterType:t.type,lib:s,flowId:g,cancelConnection:f,panBy:_,isValidConnection:(...e)=>h.getState().isValidConnection?.(...e)??!0,onConnect:e=>l?.(n,e),onConnectStart:(r,i)=>{p(!0),u?.(e,n,t.type),c?.(r,i)},onConnectEnd:(...e)=>h.getState().onConnectEnd?.(...e),onReconnectEnd:(e,r)=>{p(!1),d?.(e,n,t.type,r)},updateConnection:v,getTransform:()=>h.getState().transform,getFromHandle:()=>h.getState().connection.fromHandle,dragThreshold:h.getState().connectionDragThreshold,handleDomNode:e.currentTarget})},_=e=>g(e,{nodeId:n.target,id:n.targetHandle??null,type:`target`}),v=e=>g(e,{nodeId:n.source,id:n.sourceHandle??null,type:`source`}),y=()=>m(!0),b=()=>m(!1);return(0,f.jsxs)(f.Fragment,{children:[(e===!0||e===`source`)&&(0,f.jsx)(Bu,{position:s,centerX:r,centerY:i,radius:t,onMouseDown:_,onMouseEnter:y,onMouseOut:b,type:`source`}),(e===!0||e===`target`)&&(0,f.jsx)(Bu,{position:c,centerX:a,centerY:o,radius:t,onMouseDown:v,onMouseEnter:y,onMouseOut:b,type:`target`})]})}function Hu({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:r,onClick:i,onDoubleClick:a,onContextMenu:o,onMouseEnter:s,onMouseMove:c,onMouseLeave:l,reconnectRadius:u,onReconnect:m,onReconnectStart:h,onReconnectEnd:g,rfId:_,edgeTypes:v,noPanClassName:y,onError:b,disableKeyboardA11y:x}){let S=G(t=>t.edgeLookup.get(e)),C=G(e=>e.defaultEdgeOptions);S=C?{...C,...S}:S;let w=S.type||`default`,T=v?.[w]||Fu[w];T===void 0&&(b?.(`011`,ca.error011(w)),w=`default`,T=v?.default||Fu.default);let E=!!(S.focusable||t&&S.focusable===void 0),D=m!==void 0&&(S.reconnectable||n&&S.reconnectable===void 0),O=!!(S.selectable||r&&S.selectable===void 0),k=(0,d.useRef)(null),[A,j]=(0,d.useState)(!1),[M,N]=(0,d.useState)(!1),P=K(),{zIndex:F=S.zIndex,sourceX:I,sourceY:L,targetX:R,targetY:z,sourcePosition:B,targetPosition:V}=G((0,d.useCallback)(t=>{let n=t.nodeLookup.get(S.source),r=t.nodeLookup.get(S.target);if(!n||!r)return Iu;let i=Io({id:e,sourceNode:n,targetNode:r,sourceHandle:S.sourceHandle||null,targetHandle:S.targetHandle||null,connectionMode:t.connectionMode,onError:b}),a=Co({selected:S.selected,zIndex:S.zIndex,sourceNode:n,targetNode:r,elevateOnSelect:t.elevateEdgesOnSelect,zIndexMode:t.zIndexMode});return{...i||Iu,zIndex:a}},[S.source,S.target,S.sourceHandle,S.targetHandle,S.selected,S.zIndex,b]),W),H=(0,d.useMemo)(()=>S.markerStart?`url('#${Bo(S.markerStart,_)}')`:void 0,[S.markerStart,_]),ee=(0,d.useMemo)(()=>S.markerEnd?`url('#${Bo(S.markerEnd,_)}')`:void 0,[S.markerEnd,_]);if(S.hidden||I===null||L===null||R===null||z===null)return null;let te=t=>{let{addSelectedEdges:n,unselectNodesAndEdges:r,multiSelectionActive:a}=P.getState();O&&(P.setState({nodesSelectionActive:!1}),S.selected&&a?(r({nodes:[],edges:[S]}),k.current?.blur()):n([e])),i&&i(t,S)},ne=a?e=>{a(e,{...S})}:void 0,re=o?e=>{o(e,{...S})}:void 0,ie=s?e=>{s(e,{...S})}:void 0,ae=c?e=>{c(e,{...S})}:void 0,oe=l?e=>{l(e,{...S})}:void 0;return(0,f.jsx)(`svg`,{style:{zIndex:F},children:(0,f.jsxs)(`g`,{className:p([`react-flow__edge`,`react-flow__edge-${w}`,S.className,y,{selected:S.selected,animated:S.animated,inactive:!O&&!i,updating:A,selectable:O}]),onClick:te,onDoubleClick:ne,onContextMenu:re,onMouseEnter:ie,onMouseMove:ae,onMouseLeave:oe,onKeyDown:E?t=>{if(!x&&ua.includes(t.key)&&O){let{unselectNodesAndEdges:n,addSelectedEdges:r}=P.getState();t.key===`Escape`?(k.current?.blur(),n({edges:[S]})):r([e])}}:void 0,tabIndex:E?0:void 0,role:S.ariaRole??(E?`group`:`img`),"aria-roledescription":`edge`,"data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":S.ariaLabel===null?void 0:S.ariaLabel||`Edge from ${S.source} to ${S.target}`,"aria-describedby":E?`${gc}-${_}`:void 0,ref:k,...S.domAttributes,children:[!M&&(0,f.jsx)(T,{id:e,source:S.source,target:S.target,type:S.type,selected:S.selected,animated:S.animated,selectable:O,deletable:S.deletable??!0,label:S.label,labelStyle:S.labelStyle,labelShowBg:S.labelShowBg,labelBgStyle:S.labelBgStyle,labelBgPadding:S.labelBgPadding,labelBgBorderRadius:S.labelBgBorderRadius,sourceX:I,sourceY:L,targetX:R,targetY:z,sourcePosition:B,targetPosition:V,data:S.data,style:S.style,sourceHandleId:S.sourceHandle,targetHandleId:S.targetHandle,markerStart:H,markerEnd:ee,pathOptions:`pathOptions`in S?S.pathOptions:void 0,interactionWidth:S.interactionWidth}),D&&(0,f.jsx)(Vu,{edge:S,isReconnectable:D,reconnectRadius:u,onReconnect:m,onReconnectStart:h,onReconnectEnd:g,sourceX:I,sourceY:L,targetX:R,targetY:z,sourcePosition:B,targetPosition:V,setUpdateHover:j,setReconnecting:N})]})})}var Uu=(0,d.memo)(Hu),Wu=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Gu({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:r,noPanClassName:i,onReconnect:a,onEdgeContextMenu:o,onEdgeMouseEnter:s,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,reconnectRadius:d,onEdgeDoubleClick:p,onReconnectStart:m,onReconnectEnd:h,disableKeyboardA11y:g}){let{edgesFocusable:_,edgesReconnectable:v,elementsSelectable:y,onError:b}=G(Wu,W),x=su(t);return(0,f.jsxs)(`div`,{className:`react-flow__edges`,children:[(0,f.jsx)(mu,{defaultColor:e,rfId:n}),x.map(e=>(0,f.jsx)(Uu,{id:e,edgesFocusable:_,edgesReconnectable:v,elementsSelectable:y,noPanClassName:i,onReconnect:a,onContextMenu:o,onMouseEnter:s,onMouseMove:c,onMouseLeave:l,onClick:u,reconnectRadius:d,onDoubleClick:p,onReconnectStart:m,onReconnectEnd:h,rfId:n,onError:b,edgeTypes:r,disableKeyboardA11y:g},e))]})}Gu.displayName=`EdgeRenderer`;var Ku=(0,d.memo)(Gu),qu=e=>`translate(${e[0]}px,${e[1]}px) scale(${e[2]})`;function Ju({children:e}){let t=K(),n=(0,d.useRef)(null),[r]=(0,d.useState)(()=>t.getState().transform);return rl(()=>{let e=null,r=()=>{let r=t.getState().transform;e&&r[0]===e[0]&&r[1]===e[1]&&r[2]===e[2]||(e=r,n.current&&(n.current.style.transform=qu(r)))};return r(),t.subscribe(r)},[t]),(0,f.jsx)(`div`,{ref:n,className:`react-flow__viewport xyflow__viewport react-flow__container`,style:{transform:qu(r)},children:e})}function Yu(e){let t=ul(),n=(0,d.useRef)(!1);(0,d.useEffect)(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}var Xu=e=>e.panZoom?.syncViewport;function Zu(e){let t=G(Xu),n=K();return(0,d.useEffect)(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function Qu(e){return e.connection.inProgress?{...e.connection,to:Ja(e.connection.to,e.transform)}:{...e.connection}}function $u(e){return e?t=>e(Qu(t)):Qu}function ed(e){return G($u(e),W)}var td=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function nd({containerStyle:e,style:t,type:n,component:r}){let{nodesConnectable:i,width:a,height:o,isValid:s,inProgress:c}=G(td,W);return a&&i&&c?(0,f.jsx)(`svg`,{style:e,width:a,height:o,className:`react-flow__connectionline react-flow__container`,children:(0,f.jsx)(`g`,{className:p([`react-flow__connection`,co(s)]),children:(0,f.jsx)(rd,{style:t,type:n,CustomComponent:r,isValid:s})})}):null}var rd=({style:e,type:t=ga.Bezier,CustomComponent:n,isValid:r})=>{let{inProgress:i,from:a,fromNode:o,fromHandle:s,fromPosition:c,to:l,toNode:u,toHandle:d,toPosition:p,pointer:m}=ed();if(!i)return;if(n)return(0,f.jsx)(n,{connectionLineType:t,connectionLineStyle:e,fromNode:o,fromHandle:s,fromX:a.x,fromY:a.y,toX:l.x,toY:l.y,fromPosition:c,toPosition:p,connectionStatus:co(r),toNode:u,toHandle:d,pointer:m});let h=``,g={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:l.x,targetY:l.y,targetPosition:p};switch(t){case ga.Bezier:[h]=xo(g);break;case ga.SimpleBezier:[h]=yu(g);break;case ga.Step:[h]=Po({...g,borderRadius:0});break;case ga.SmoothStep:[h]=Po(g);break;default:[h]=Oo(g)}return(0,f.jsx)(`path`,{d:h,fill:`none`,className:`react-flow__connection-path`,style:e})};rd.displayName=`ConnectionLine`;var id={};function ad(e=id){(0,d.useRef)(e),K(),(0,d.useEffect)(()=>{},[e])}function od(){K(),(0,d.useRef)(!1),(0,d.useEffect)(()=>{},[])}function sd({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:a,onEdgeDoubleClick:o,onNodeMouseEnter:s,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,onSelectionContextMenu:d,onSelectionStart:p,onSelectionEnd:m,connectionLineType:h,connectionLineStyle:g,connectionLineComponent:_,connectionLineContainerStyle:v,selectionKeyCode:y,selectionOnDrag:b,selectionMode:x,multiSelectionKeyCode:S,panActivationKeyCode:C,zoomActivationKeyCode:w,deleteKeyCode:T,onlyRenderVisibleElements:E,elementsSelectable:D,defaultViewport:O,translateExtent:k,minZoom:A,maxZoom:j,preventScrolling:M,defaultMarkerColor:N,zoomOnScroll:P,zoomOnPinch:F,panOnScroll:I,panOnScrollSpeed:L,panOnScrollMode:R,zoomOnDoubleClick:z,panOnDrag:B,autoPanOnSelection:V,onPaneClick:H,onPaneMouseEnter:ee,onPaneMouseMove:te,onPaneMouseLeave:ne,onPaneScroll:re,onPaneContextMenu:ie,paneClickDistance:ae,nodeClickDistance:oe,onEdgeContextMenu:se,onEdgeMouseEnter:ce,onEdgeMouseMove:le,onEdgeMouseLeave:ue,reconnectRadius:de,onReconnect:fe,onReconnectStart:pe,onReconnectEnd:me,noDragClassName:he,noWheelClassName:ge,noPanClassName:_e,disableKeyboardA11y:ve,nodeExtent:ye,rfId:be,viewport:xe,onViewportChange:Se,nodesDraggable:Ce}){return ad(e),ad(t),od(),Yu(n),Zu(xe),(0,f.jsx)(Xl,{onPaneClick:H,onPaneMouseEnter:ee,onPaneMouseMove:te,onPaneMouseLeave:ne,onPaneContextMenu:ie,onPaneScroll:re,paneClickDistance:ae,deleteKeyCode:T,selectionKeyCode:y,selectionOnDrag:b,selectionMode:x,onSelectionStart:p,onSelectionEnd:m,multiSelectionKeyCode:S,panActivationKeyCode:C,zoomActivationKeyCode:w,elementsSelectable:D,zoomOnScroll:P,zoomOnPinch:F,zoomOnDoubleClick:z,panOnScroll:I,panOnScrollSpeed:L,panOnScrollMode:R,panOnDrag:B,autoPanOnSelection:V,defaultViewport:O,translateExtent:k,minZoom:A,maxZoom:j,onSelectionContextMenu:d,preventScrolling:M,noDragClassName:he,noWheelClassName:ge,noPanClassName:_e,disableKeyboardA11y:ve,onViewportChange:Se,isControlledViewport:!!xe,children:(0,f.jsxs)(Ju,{children:[(0,f.jsx)(Ku,{edgeTypes:t,onEdgeClick:i,onEdgeDoubleClick:o,onReconnect:fe,onReconnectStart:pe,onReconnectEnd:me,onlyRenderVisibleElements:E,onEdgeContextMenu:se,onEdgeMouseEnter:ce,onEdgeMouseMove:le,onEdgeMouseLeave:ue,reconnectRadius:de,defaultMarkerColor:N,noPanClassName:_e,disableKeyboardA11y:ve,rfId:be}),(0,f.jsx)(nd,{style:g,type:h,component:_,containerStyle:v}),(0,f.jsx)(`div`,{className:`react-flow__edgelabel-renderer`}),(0,f.jsx)(ou,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:a,onNodeMouseEnter:s,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,nodeClickDistance:oe,onlyRenderVisibleElements:E,noPanClassName:_e,noDragClassName:he,disableKeyboardA11y:ve,nodeExtent:ye,rfId:be,nodesDraggable:Ce}),(0,f.jsx)(`div`,{className:`react-flow__viewport-portal`})]})})}sd.displayName=`GraphView`;var cd=(0,d.memo)(sd),ld=Ka(`React Flow`,`https://reactflow.dev/`),ud=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c=.5,maxZoom:l=2,nodeOrigin:u,nodeExtent:d,zIndexMode:f=`basic`}={})=>{let p=new Map,m=new Map,h=new Map,g=new Map,_=r??t??[],v=n??e??[],y=u??[0,0],b=d??la;as(h,g,_);let{nodesInitialized:x}=Xo(v,p,m,{nodeOrigin:y,nodeExtent:b,zIndexMode:f}),S=[0,0,1];if(o&&i&&a){let{x:e,y:t,zoom:n}=$a(wa(p,{filter:e=>!(!e.width&&!e.initialWidth||!e.height&&!e.initialHeight)}),i,a,c,l,s?.padding??.1);S=[e,t,n]}return{rfId:`1`,width:i??0,height:a??0,transform:S,nodes:v,nodesInitialized:x,nodeLookup:p,parentLookup:m,edges:_,edgeLookup:g,connectionLookup:h,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:l,translateExtent:la,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:fa.Strict,domNode:null,paneDragging:!1,noPanClassName:`nopan`,nodeOrigin:y,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:o??!1,fitViewOptions:s,fitViewResolver:null,connection:{...ha},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:``,autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:ld,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:`react`,debug:!1,ariaLabelConfig:da,zIndexMode:f,defaultEdgeOptions:void 0,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map,onNodesDelete:void 0,onEdgesDelete:void 0,onDelete:void 0,onBeforeDelete:void 0,onViewportChangeStart:void 0,onViewportChange:void 0,onViewportChangeEnd:void 0,onNodeDragStart:void 0,onNodeDrag:void 0,onNodeDragStop:void 0,onSelectionDragStart:void 0,onSelectionDrag:void 0,onSelectionDragStop:void 0,onMoveStart:void 0,onMove:void 0,onMoveEnd:void 0,onConnect:void 0,onConnectStart:void 0,onConnectEnd:void 0,onClickConnectStart:void 0,onClickConnectEnd:void 0}},dd=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:d,zIndexMode:f})=>cc((p,m)=>{async function h(){let{nodeLookup:e,panZoom:t,fitViewOptions:n,fitViewResolver:r,width:i,height:a,minZoom:o,maxZoom:s}=m();t&&(await Oa({nodes:e,width:i,height:a,panZoom:t,minZoom:o,maxZoom:s},n),r?.resolve(!0),p({fitViewResolver:null}))}return{...ud({nodes:e,edges:t,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:d,defaultNodes:n,defaultEdges:r,zIndexMode:f}),setNodes:e=>{let{nodeLookup:t,parentLookup:n,nodeOrigin:r,nodeExtent:i,elevateNodesOnSelect:a,fitViewQueued:o,zIndexMode:s,nodesSelectionActive:c}=m(),{nodesInitialized:l,hasSelectedNodes:u}=Xo(e,t,n,{nodeOrigin:r,nodeExtent:i,elevateNodesOnSelect:a,checkEquality:!0,zIndexMode:s}),d=c&&u;o&&l?(h(),p({nodes:e,nodesInitialized:l,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:d})):p({nodes:e,nodesInitialized:l,nodesSelectionActive:d})},setEdges:e=>{let{connectionLookup:t,edgeLookup:n}=m();as(t,n,e),p({edges:e})},setDefaultNodesAndEdges:(e,t)=>{if(e){let{setNodes:t}=m();t(e),p({hasDefaultNodes:!0})}if(t){let{setEdges:e}=m();e(t),p({hasDefaultEdges:!0})}},updateNodeInternals:e=>{let{triggerNodeChanges:t,nodeLookup:n,parentLookup:r,domNode:i,nodeOrigin:a,nodeExtent:o,debug:s,fitViewQueued:c,zIndexMode:l}=m(),{changes:u,updatedInternals:d}=ns(e,n,r,i,a,o,l);d&&(qo(n,r,{nodeOrigin:a,nodeExtent:o,zIndexMode:l}),c?(h(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),u?.length>0&&(s&&console.log(`React Flow: trigger node changes`,u),t?.(u)))},updateNodePositions:(e,t=!1)=>{let n=[],r=[],{nodeLookup:i,triggerNodeChanges:a,connection:o,updateConnection:s,onNodesChangeMiddlewareMap:c}=m();for(let[a,c]of e){let e=i.get(a),l=!!(e?.expandParent&&e?.parentId&&c?.position),u={id:a,type:`position`,position:l?{x:Math.max(0,c.position.x),y:Math.max(0,c.position.y)}:c.position,dragging:t};if(e&&o.inProgress&&o.fromNode.id===e.id){let t=Ro(e,o.fromHandle,U.Left,!0);s({...o,from:t})}l&&e.parentId&&n.push({id:a,parentId:e.parentId,rect:{...c.internals.positionAbsolute,width:c.measured.width??0,height:c.measured.height??0}}),r.push(u)}if(n.length>0){let{parentLookup:e,nodeOrigin:t}=m(),a=ts(n,i,e,t);r.push(...a)}for(let e of c.values())r=e(r);a(r)},triggerNodeChanges:e=>{let{onNodesChange:t,setNodes:n,nodes:r,hasDefaultNodes:i,debug:a}=m();e?.length&&(i&&n(Kc(e,r)),a&&console.log(`React Flow: trigger node changes`,e),t?.(e))},triggerEdgeChanges:e=>{let{onEdgesChange:t,setEdges:n,edges:r,hasDefaultEdges:i,debug:a}=m();e?.length&&(i&&n(qc(e,r)),a&&console.log(`React Flow: trigger edge changes`,e),t?.(e))},addSelectedNodes:e=>{let{multiSelectionActive:t,edgeLookup:n,nodeLookup:r,triggerNodeChanges:i,triggerEdgeChanges:a}=m();t?i(e.map(e=>Jc(e,!0))):(i(Yc(r,new Set([...e]),!0)),a(Yc(n)))},addSelectedEdges:e=>{let{multiSelectionActive:t,edgeLookup:n,nodeLookup:r,triggerNodeChanges:i,triggerEdgeChanges:a}=m();t?a(e.map(e=>Jc(e,!0))):(a(Yc(n,new Set([...e]))),i(Yc(r,new Set,!0)))},unselectNodesAndEdges:({nodes:e,edges:t}={})=>{let{edges:n,nodes:r,nodeLookup:i,triggerNodeChanges:a,triggerEdgeChanges:o}=m(),s=e||r,c=t||n,l=[];for(let e of s){if(!e.selected)continue;let t=i.get(e.id);t&&(t.selected=!1),l.push(Jc(e.id,!1))}let u=[];for(let e of c)e.selected&&u.push(Jc(e.id,!1));a(l),o(u)},setMinZoom:e=>{let{panZoom:t,maxZoom:n}=m();t?.setScaleExtent([e,n]),p({minZoom:e})},setMaxZoom:e=>{let{panZoom:t,minZoom:n}=m();t?.setScaleExtent([n,e]),p({maxZoom:e})},setTranslateExtent:e=>{m().panZoom?.setTranslateExtent(e),p({translateExtent:e})},resetSelectedElements:()=>{let{edges:e,nodes:t,triggerNodeChanges:n,triggerEdgeChanges:r,elementsSelectable:i}=m();if(!i)return;let a=t.reduce((e,t)=>t.selected?[...e,Jc(t.id,!1)]:e,[]),o=e.reduce((e,t)=>t.selected?[...e,Jc(t.id,!1)]:e,[]);n(a),r(o)},setNodeExtent:e=>{let{nodes:t,nodeLookup:n,parentLookup:r,nodeOrigin:i,elevateNodesOnSelect:a,nodeExtent:o,zIndexMode:s}=m();(e[0][0]!==o[0][0]||e[0][1]!==o[0][1]||e[1][0]!==o[1][0]||e[1][1]!==o[1][1])&&(Xo(t,n,r,{nodeOrigin:i,nodeExtent:e,elevateNodesOnSelect:a,checkEquality:!1,zIndexMode:s}),p({nodeExtent:e}))},panBy:e=>{let{transform:t,width:n,height:r,panZoom:i,translateExtent:a}=m();return rs({delta:e,panZoom:i,transform:t,translateExtent:a,width:n,height:r})},setCenter:async(e,t,n)=>{let{width:r,height:i,maxZoom:a,panZoom:o}=m();if(!o)return!1;let s=n?.zoom===void 0?a:n.zoom;return await o.setViewport({x:r/2-e*s,y:i/2-t*s,zoom:s},{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0},cancelConnection:()=>{p({connection:{...ha}})},updateConnection:e=>{p({connection:e})},reset:()=>p({...ud()})}},Object.is);function fd({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:r,initialWidth:i,initialHeight:a,initialMinZoom:o,initialMaxZoom:s,initialFitViewOptions:c,fitView:l,nodeOrigin:u,nodeExtent:p,zIndexMode:m,children:h}){let[g]=(0,d.useState)(()=>dd({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:l,minZoom:o,maxZoom:s,fitViewOptions:c,nodeOrigin:u,nodeExtent:p,zIndexMode:m}));return(0,f.jsx)(dc,{value:g,children:(0,f.jsx)(sl,{children:(0,f.jsx)(Ml,{children:h})})})}function pd({children:e,nodes:t,edges:n,defaultNodes:r,defaultEdges:i,width:a,height:o,fitView:s,fitViewOptions:c,minZoom:l,maxZoom:u,nodeOrigin:p,nodeExtent:m,zIndexMode:h}){return(0,d.useContext)(uc)?(0,f.jsx)(f.Fragment,{children:e}):(0,f.jsx)(fd,{initialNodes:t,initialEdges:n,defaultNodes:r,defaultEdges:i,initialWidth:a,initialHeight:o,fitView:s,initialFitViewOptions:c,initialMinZoom:l,initialMaxZoom:u,nodeOrigin:p,nodeExtent:m,zIndexMode:h,children:e})}var md={width:`100%`,height:`100%`,overflow:`hidden`,position:`relative`,zIndex:0};function hd({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:i,nodeTypes:a,edgeTypes:o,onNodeClick:s,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:m,onMoveEnd:h,onConnect:g,onConnectStart:_,onConnectEnd:v,onClickConnectStart:y,onClickConnectEnd:b,onNodeMouseEnter:x,onNodeMouseMove:S,onNodeMouseLeave:C,onNodeContextMenu:w,onNodeDoubleClick:T,onNodeDragStart:E,onNodeDrag:D,onNodeDragStop:O,onNodesDelete:k,onEdgesDelete:A,onDelete:j,onSelectionChange:M,onSelectionDragStart:N,onSelectionDrag:P,onSelectionDragStop:F,onSelectionContextMenu:I,onSelectionStart:L,onSelectionEnd:R,onBeforeDelete:z,connectionMode:B,connectionLineType:V=ga.Bezier,connectionLineStyle:H,connectionLineComponent:ee,connectionLineContainerStyle:te,deleteKeyCode:ne=`Backspace`,selectionKeyCode:re=`Shift`,selectionOnDrag:ie=!1,selectionMode:ae=ma.Full,panActivationKeyCode:oe=`Space`,multiSelectionKeyCode:se=eo()?`Meta`:`Control`,zoomActivationKeyCode:ce=eo()?`Meta`:`Control`,snapToGrid:le,snapGrid:ue,onlyRenderVisibleElements:de=!1,selectNodesOnDrag:fe,nodesDraggable:pe,autoPanOnNodeFocus:me,nodesConnectable:he,nodesFocusable:ge,nodeOrigin:_e=jc,edgesFocusable:ve,edgesReconnectable:ye,elementsSelectable:be=!0,defaultViewport:xe=Mc,minZoom:Se=.5,maxZoom:Ce=2,translateExtent:we=la,preventScrolling:Te=!0,nodeExtent:Ee,defaultMarkerColor:De=`#b1b1b7`,zoomOnScroll:Oe=!0,zoomOnPinch:ke=!0,panOnScroll:Ae=!1,panOnScrollSpeed:je=.5,panOnScrollMode:Me=pa.Free,zoomOnDoubleClick:Ne=!0,panOnDrag:Pe=!0,onPaneClick:Fe,onPaneMouseEnter:Ie,onPaneMouseMove:Le,onPaneMouseLeave:Re,onPaneScroll:ze,onPaneContextMenu:Be,paneClickDistance:Ve=1,nodeClickDistance:He=0,children:Ue,onReconnect:We,onReconnectStart:Ge,onReconnectEnd:Ke,onEdgeContextMenu:qe,onEdgeDoubleClick:Je,onEdgeMouseEnter:Ye,onEdgeMouseMove:Xe,onEdgeMouseLeave:Ze,reconnectRadius:Qe=10,onNodesChange:$e,onEdgesChange:et,noDragClassName:tt=`nodrag`,noWheelClassName:nt=`nowheel`,noPanClassName:rt=`nopan`,fitView:it,fitViewOptions:at,connectOnClick:ot,attributionPosition:st,proOptions:ct,defaultEdgeOptions:lt,elevateNodesOnSelect:ut=!0,elevateEdgesOnSelect:dt=!1,disableKeyboardA11y:ft=!1,autoPanOnConnect:pt,autoPanOnNodeDrag:mt,autoPanOnSelection:ht=!0,autoPanSpeed:gt,connectionRadius:_t,isValidConnection:vt,onError:yt,style:bt,id:xt,nodeDragThreshold:St,connectionDragThreshold:Ct,viewport:wt,onViewportChange:Tt,width:Et,height:Dt,colorMode:Ot=`light`,debug:kt,onScroll:At,ariaLabelConfig:jt,zIndexMode:Mt=`basic`,...Nt},Pt){let Ft=xt||`1`,It=Rc(Ot),Lt=(0,d.useCallback)(e=>{e.currentTarget.scrollTo({top:0,left:0,behavior:`instant`}),At?.(e)},[At]);return(0,f.jsx)(`div`,{"data-testid":`rf__wrapper`,...Nt,onScroll:Lt,style:{...bt,...md},ref:Pt,className:p([`react-flow`,i,It]),id:xt,role:`application`,children:(0,f.jsxs)(pd,{nodes:e,edges:t,width:Et,height:Dt,fitView:it,fitViewOptions:at,minZoom:Se,maxZoom:Ce,nodeOrigin:_e,nodeExtent:Ee,zIndexMode:Mt,children:[(0,f.jsx)(Ic,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:g,onConnectStart:_,onConnectEnd:v,onClickConnectStart:y,onClickConnectEnd:b,nodesDraggable:pe,autoPanOnNodeFocus:me,nodesConnectable:he,nodesFocusable:ge,edgesFocusable:ve,edgesReconnectable:ye,elementsSelectable:be,elevateNodesOnSelect:ut,elevateEdgesOnSelect:dt,minZoom:Se,maxZoom:Ce,nodeExtent:Ee,onNodesChange:$e,onEdgesChange:et,snapToGrid:le,snapGrid:ue,connectionMode:B,translateExtent:we,connectOnClick:ot,defaultEdgeOptions:lt,fitView:it,fitViewOptions:at,onNodesDelete:k,onEdgesDelete:A,onDelete:j,onNodeDragStart:E,onNodeDrag:D,onNodeDragStop:O,onSelectionDrag:P,onSelectionDragStart:N,onSelectionDragStop:F,onMove:u,onMoveStart:m,onMoveEnd:h,noPanClassName:rt,nodeOrigin:_e,rfId:Ft,autoPanOnConnect:pt,autoPanOnNodeDrag:mt,autoPanSpeed:gt,onError:yt,connectionRadius:_t,isValidConnection:vt,selectNodesOnDrag:fe,nodeDragThreshold:St,connectionDragThreshold:Ct,onBeforeDelete:z,debug:kt,ariaLabelConfig:jt,zIndexMode:Mt}),(0,f.jsx)(cd,{onInit:l,onNodeClick:s,onEdgeClick:c,onNodeMouseEnter:x,onNodeMouseMove:S,onNodeMouseLeave:C,onNodeContextMenu:w,onNodeDoubleClick:T,nodeTypes:a,edgeTypes:o,connectionLineType:V,connectionLineStyle:H,connectionLineComponent:ee,connectionLineContainerStyle:te,selectionKeyCode:re,selectionOnDrag:ie,selectionMode:ae,deleteKeyCode:ne,multiSelectionKeyCode:se,panActivationKeyCode:oe,zoomActivationKeyCode:ce,onlyRenderVisibleElements:de,defaultViewport:xe,translateExtent:we,minZoom:Se,maxZoom:Ce,preventScrolling:Te,zoomOnScroll:Oe,zoomOnPinch:ke,zoomOnDoubleClick:Ne,panOnScroll:Ae,panOnScrollSpeed:je,panOnScrollMode:Me,panOnDrag:Pe,autoPanOnSelection:ht,onPaneClick:Fe,onPaneMouseEnter:Ie,onPaneMouseMove:Le,onPaneMouseLeave:Re,onPaneScroll:ze,onPaneContextMenu:Be,paneClickDistance:Ve,nodeClickDistance:He,onSelectionContextMenu:I,onSelectionStart:L,onSelectionEnd:R,onReconnect:We,onReconnectStart:Ge,onReconnectEnd:Ke,onEdgeContextMenu:qe,onEdgeDoubleClick:Je,onEdgeMouseEnter:Ye,onEdgeMouseMove:Xe,onEdgeMouseLeave:Ze,reconnectRadius:Qe,defaultMarkerColor:De,noDragClassName:tt,noWheelClassName:nt,noPanClassName:rt,rfId:Ft,disableKeyboardA11y:ft,nodeExtent:Ee,viewport:wt,onViewportChange:Tt,nodesDraggable:pe}),(0,f.jsx)(Ac,{onSelectionChange:M}),Ue,(0,f.jsx)(wc,{proOptions:ct,position:st}),(0,f.jsx)(xc,{rfId:Ft,disableKeyboardA11y:ft})]})})}var gd=nl(hd),_d=e=>e.domNode?.querySelector(`.react-flow__edgelabel-renderer`);function vd({children:e}){let t=G(_d);return t?(0,lc.createPortal)(e,t):null}ca.error014();function yd(e){return G((0,d.useCallback)(t=>t.nodeLookup.get(e),[e]),W)}function bd({dimensions:e,lineWidth:t,variant:n,className:r}){return(0,f.jsx)(`path`,{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:p([`react-flow__background-pattern`,n,r])})}function xd({radius:e,className:t}){return(0,f.jsx)(`circle`,{cx:e,cy:e,r:e,className:p([`react-flow__background-pattern`,`dots`,t])})}var Sd;(function(e){e.Lines=`lines`,e.Dots=`dots`,e.Cross=`cross`})(Sd||={});var Cd={[Sd.Dots]:1,[Sd.Lines]:1,[Sd.Cross]:6},wd=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Td({id:e,variant:t=Sd.Dots,gap:n=20,size:r,lineWidth:i=1,offset:a=0,color:o,bgColor:s,style:c,className:l,patternClassName:u}){let m=(0,d.useRef)(null),{transform:h,patternId:g}=G(wd,W),_=r||Cd[t],v=t===Sd.Dots,y=t===Sd.Cross,b=Array.isArray(n)?n:[n,n],x=[b[0]*h[2]||1,b[1]*h[2]||1],S=_*h[2],C=Array.isArray(a)?a:[a,a],w=y?[S,S]:x,T=[C[0]*h[2]+w[0]/2,C[1]*h[2]+w[1]/2],E=`${g}${e||``}`;return(0,f.jsxs)(`svg`,{className:p([`react-flow__background`,l]),style:{...c,...hl,"--xy-background-color-props":s,"--xy-background-pattern-color-props":o},ref:m,"data-testid":`rf__background`,children:[(0,f.jsx)(`pattern`,{id:E,x:h[0]%x[0],y:h[1]%x[1],width:x[0],height:x[1],patternUnits:`userSpaceOnUse`,patternTransform:`translate(-${T[0]},-${T[1]})`,children:v?(0,f.jsx)(xd,{radius:S/2,className:u}):(0,f.jsx)(bd,{dimensions:w,lineWidth:i,variant:t,className:u})}),(0,f.jsx)(`rect`,{x:`0`,y:`0`,width:`100%`,height:`100%`,fill:`url(#${E})`})]})}Td.displayName=`Background`;var Ed=(0,d.memo)(Td);function Dd(){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 32`,children:(0,f.jsx)(`path`,{d:`M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z`})})}function Od(){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 5`,children:(0,f.jsx)(`path`,{d:`M0 0h32v4.2H0z`})})}function kd(){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 30`,children:(0,f.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 Ad(){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 25 32`,children:(0,f.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 jd(){return(0,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 25 32`,children:(0,f.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 Md({children:e,className:t,...n}){return(0,f.jsx)(`button`,{type:`button`,className:p([`react-flow__controls-button`,t]),...n,children:e})}var Nd=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Pd({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:a,onZoomOut:o,onFitView:s,onInteractiveChange:c,className:l,children:u,position:d=`bottom-left`,orientation:m=`vertical`,"aria-label":h}){let g=K(),{isInteractive:_,minZoomReached:v,maxZoomReached:y,ariaLabelConfig:b}=G(Nd,W),{zoomIn:x,zoomOut:S,fitView:C}=ul();return(0,f.jsxs)(Sc,{className:p([`react-flow__controls`,m===`horizontal`?`horizontal`:`vertical`,l]),position:d,style:e,"data-testid":`rf__controls`,"aria-label":h??b[`controls.ariaLabel`],children:[t&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(Md,{onClick:()=>{x(),a?.()},className:`react-flow__controls-zoomin`,title:b[`controls.zoomIn.ariaLabel`],"aria-label":b[`controls.zoomIn.ariaLabel`],disabled:y,children:(0,f.jsx)(Dd,{})}),(0,f.jsx)(Md,{onClick:()=>{S(),o?.()},className:`react-flow__controls-zoomout`,title:b[`controls.zoomOut.ariaLabel`],"aria-label":b[`controls.zoomOut.ariaLabel`],disabled:v,children:(0,f.jsx)(Od,{})})]}),n&&(0,f.jsx)(Md,{className:`react-flow__controls-fitview`,onClick:()=>{C(i),s?.()},title:b[`controls.fitView.ariaLabel`],"aria-label":b[`controls.fitView.ariaLabel`],children:(0,f.jsx)(kd,{})}),r&&(0,f.jsx)(Md,{className:`react-flow__controls-interactive`,onClick:()=>{g.setState({nodesDraggable:!_,nodesConnectable:!_,elementsSelectable:!_}),c?.(!_)},title:b[`controls.interactive.ariaLabel`],"aria-label":b[`controls.interactive.ariaLabel`],children:_?(0,f.jsx)(jd,{}):(0,f.jsx)(Ad,{})}),u]})}Pd.displayName=`Controls`;var Fd=(0,d.memo)(Pd);function Id({id:e,x:t,y:n,width:r,height:i,style:a,color:o,strokeColor:s,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,selected:m,onClick:h}){let{background:g,backgroundColor:_}=a||{},v=o||g||_;return(0,f.jsx)(`rect`,{className:p([`react-flow__minimap-node`,{selected:m},l]),x:t,y:n,rx:u,ry:u,width:r,height:i,style:{fill:v,stroke:s,strokeWidth:c},shapeRendering:d,onClick:h?t=>h(t,e):void 0})}var Ld=(0,d.memo)(Id),Rd=e=>e.nodes.map(e=>e.id),zd=e=>e instanceof Function?e:()=>e;function Bd({nodeStrokeColor:e,nodeColor:t,nodeClassName:n=``,nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:a=Ld,onClick:o}){let s=G(Rd,W),c=zd(t),l=zd(e),u=zd(n),d=typeof window>`u`||window.chrome?`crispEdges`:`geometricPrecision`;return(0,f.jsx)(f.Fragment,{children:s.map(e=>(0,f.jsx)(Hd,{id:e,nodeColorFunc:c,nodeStrokeColorFunc:l,nodeClassNameFunc:u,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:a,onClick:o,shapeRendering:d},e))})}function Vd({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:a,shapeRendering:o,NodeComponent:s,onClick:c}){let{node:l,x:u,y:d,width:p,height:m}=G(t=>{let n=t.nodeLookup.get(e);if(!n)return{node:void 0,x:0,y:0,width:0,height:0};let r=n.internals.userNode,{x:i,y:a}=n.internals.positionAbsolute,{width:o,height:s}=no(r);return{node:r,x:i,y:a,width:o,height:s}},W);return!l||l.hidden||!ro(l)?null:(0,f.jsx)(s,{x:u,y:d,width:p,height:m,style:l.style,selected:!!l.selected,className:r(l),color:t(l),borderRadius:i,strokeColor:n(l),strokeWidth:a,shapeRendering:o,onClick:c,id:l.id})}var Hd=(0,d.memo)(Vd),Ud=(0,d.memo)(Bd),Wd=200,Gd=150,Kd=e=>!e.hidden,qd=e=>{let 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]},n=!1;for(let t of e.nodeLookup.values())if(!t.hidden){n=!0;break}return{viewBB:t,boundingRect:n?Va(wa(e.nodeLookup,{filter:Kd}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},Jd=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,Yd=(e,t)=>Jd(e.viewBB,t.viewBB)&&Jd(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,Xd=`react-flow__minimap-desc`;function Zd({style:e,className:t,nodeStrokeColor:n,nodeColor:r,nodeClassName:i=``,nodeBorderRadius:a=5,nodeStrokeWidth:o,nodeComponent:s,bgColor:c,maskColor:l,maskStrokeColor:u,maskStrokeWidth:m,position:h=`bottom-right`,onClick:g,onNodeClick:_,pannable:v=!1,zoomable:y=!1,ariaLabel:b,inversePan:x,zoomStep:S=1,offsetScale:C=5}){let w=K(),T=(0,d.useRef)(null),{boundingRect:E,panZoom:D,viewBB:O,rfId:k,translateExtent:A,flowWidth:j,flowHeight:M,ariaLabelConfig:N}=G(qd,Yd),P=e?.width??Wd,F=e?.height??Gd,I=E.width/P,L=E.height/F,R=Math.max(I,L),z=R*P,B=R*F,V=C*R,H=E.x-(z-E.width)/2-V,ee=E.y-(B-E.height)/2-V,te=z+V*2,ne=B+V*2,re=`${Xd}-${k}`,ie=(0,d.useRef)(0),ae=(0,d.useRef)();ie.current=R,(0,d.useEffect)(()=>{let e=w.getState().panZoom;if(T.current&&e)return ae.current=Ss({domNode:T.current,panZoom:e,getTransform:()=>w.getState().transform,getViewScale:()=>ie.current}),()=>{ae.current?.destroy()}},[D]),(0,d.useEffect)(()=>{ae.current?.update({translateExtent:A,width:j,height:M,inversePan:x,pannable:v,zoomStep:S,zoomable:y})},[v,y,x,S,A,j,M]);let oe=g?e=>{let[t,n]=ae.current?.pointer(e)||[0,0];g(e,{x:t,y:n})}:void 0,se=(0,d.useCallback)((e,t)=>{let n=w.getState().nodeLookup.get(t).internals.userNode;_?.(e,n)},[_]),ce=_?se:void 0,le=b??N[`minimap.ariaLabel`];return(0,f.jsx)(Sc,{position:h,style:{...e,"--xy-minimap-background-color-props":typeof c==`string`?c:void 0,"--xy-minimap-mask-background-color-props":typeof l==`string`?l:void 0,"--xy-minimap-mask-stroke-color-props":typeof u==`string`?u:void 0,"--xy-minimap-mask-stroke-width-props":typeof m==`number`?m*R:void 0,"--xy-minimap-node-background-color-props":typeof r==`string`?r:void 0,"--xy-minimap-node-stroke-color-props":typeof n==`string`?n:void 0,"--xy-minimap-node-stroke-width-props":typeof o==`number`?o:void 0},className:p([`react-flow__minimap`,t]),"data-testid":`rf__minimap`,children:(0,f.jsxs)(`svg`,{width:P,height:F,viewBox:`${H} ${ee} ${te} ${ne}`,className:`react-flow__minimap-svg`,role:`img`,"aria-labelledby":re,ref:T,onClick:oe,children:[le&&(0,f.jsx)(`title`,{id:re,children:le}),(0,f.jsx)(Ud,{onClick:ce,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:i,nodeStrokeWidth:o,nodeComponent:s}),(0,f.jsx)(`path`,{className:`react-flow__minimap-mask`,d:`M${H-V},${ee-V}h${te+V*2}v${ne+V*2}h${-te-V*2}z
7
+ M${O.x},${O.y}h${O.width}v${O.height}h${-O.width}z`,fillRule:`evenodd`,pointerEvents:`none`})]})})}Zd.displayName=`MiniMap`;var Qd=(0,d.memo)(Zd),$d=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,ef={[Ls.Line]:`right`,[Ls.Handle]:`bottom-right`};function tf({nodeId:e,position:t,variant:n=Ls.Handle,className:r,style:i=void 0,children:a,color:o,minWidth:s=10,minHeight:c=10,maxWidth:l=Number.MAX_VALUE,maxHeight:u=Number.MAX_VALUE,keepAspectRatio:m=!1,resizeDirection:h,autoScale:g=!0,shouldResize:_,onResizeStart:v,onResize:y,onResizeEnd:b}){let x=kl(),S=typeof e==`string`?e:x,C=K(),w=(0,d.useRef)(null),T=n===Ls.Handle,E=G((0,d.useCallback)($d(T&&g),[T,g]),W),D=(0,d.useRef)(null),O=t??ef[n];(0,d.useEffect)(()=>{if(w.current&&S)return D.current||=Xs({domNode:w.current,nodeId:S,getStoreItems:()=>{let{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,domNode:a}=C.getState();return{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,paneDomNode:a}},onChange:(e,t)=>{let{triggerNodeChanges:n,nodeLookup:r,parentLookup:i,nodeOrigin:a}=C.getState(),o=[],s={x:e.x,y:e.y},c=r.get(S);if(c&&c.expandParent&&c.parentId){let t=c.origin??a,n=e.width??c.measured.width??0,l=e.height??c.measured.height??0,u=ts([{id:c.id,parentId:c.parentId,rect:{width:n,height:l,...io({x:e.x??c.position.x,y:e.y??c.position.y},{width:n,height:l},c.parentId,r,t)}}],r,i,a);o.push(...u),s.x=e.x?Math.max(t[0]*n,e.x):void 0,s.y=e.y?Math.max(t[1]*l,e.y):void 0}if(s.x!==void 0&&s.y!==void 0){let e={id:S,type:`position`,position:{...s}};o.push(e)}if(e.width!==void 0&&e.height!==void 0){let t={id:S,type:`dimensions`,resizing:!0,setAttributes:h?h===`horizontal`?`width`:`height`:!0,dimensions:{width:e.width,height:e.height}};o.push(t)}for(let e of t){let t={...e,type:`position`};o.push(t)}n(o)},onEnd:({width:e,height:t})=>{let n={id:S,type:`dimensions`,resizing:!1,dimensions:{width:e,height:t}};C.getState().triggerNodeChanges([n])}}),D.current.update({controlPosition:O,boundaries:{minWidth:s,minHeight:c,maxWidth:l,maxHeight:u},keepAspectRatio:m,resizeDirection:h,onResizeStart:v,onResize:y,onResizeEnd:b,shouldResize:_}),()=>{D.current?.destroy()}},[O,s,c,l,u,m,v,y,b,_]);let k=O.split(`-`);return(0,f.jsx)(`div`,{className:p([`react-flow__resize-control`,`nodrag`,...k,n,r]),ref:w,style:{...i,scale:E,...o&&{[T?`backgroundColor`:`borderColor`]:o}},children:a})}var nf=(0,d.memo)(tf);function rf({nodeId:e,isVisible:t=!0,handleClassName:n,handleStyle:r,lineClassName:i,lineStyle:a,color:o,minWidth:s=10,minHeight:c=10,maxWidth:l=Number.MAX_VALUE,maxHeight:u=Number.MAX_VALUE,keepAspectRatio:d=!1,autoScale:p=!0,shouldResize:m,onResizeStart:h,onResize:g,onResizeEnd:_}){return t?(0,f.jsxs)(f.Fragment,{children:[zs.map(t=>(0,f.jsx)(nf,{className:i,style:a,nodeId:e,position:t,variant:Ls.Line,color:o,minWidth:s,minHeight:c,maxWidth:l,maxHeight:u,onResizeStart:h,keepAspectRatio:d,autoScale:p,shouldResize:m,onResize:g,onResizeEnd:_},t)),Rs.map(t=>(0,f.jsx)(nf,{className:n,style:r,nodeId:e,position:t,color:o,minWidth:s,minHeight:c,maxWidth:l,maxHeight:u,onResizeStart:h,keepAspectRatio:d,autoScale:p,shouldResize:m,onResize:g,onResizeEnd:_},t))]}):null}var af=`flow.json`,of=`flows`,sf=`main`,cf=/^flows\/([a-z0-9][a-z0-9-]{0,47})\.json$/,lf=e=>e===`main`?af:`${of}/${e}.json`,uf=`rules.md`,df=`manager.md`,ff=[`work`,`check`,`person`,`fork`,`join`,`timer`,`flow`],pf=[`manager`,`person`,`new-session`,`continue`],mf=[`work`,`check`],hf=[`start`,`done`,`brief`],gf=[`done`,`owner`,`report`,`ask-manager`];function _f(e){return`${e}${e%100>=11&&e%100<=13?`th`:{1:`st`,2:`nd`,3:`rd`}[e%10]??`th`}`}var vf=e=>e.times?`${e.word} (${_f(e.times)} time)`:e.word;function yf(e){let t=e.blocks.flatMap(e=>e.outcomes?.length?e.outcomes.filter(e=>e.end).map(e=>e.word):[e.title]),n=new Set;return t.filter(e=>{let t=bf(e);return!t||n.has(t)?!1:(n.add(t),!0)})}var bf=e=>e.trim().toLowerCase();function xf(e){return e.blocks.flatMap(e=>(e.outcomes??[]).flatMap((t,n)=>t.to===void 0?[]:[{from:e.id,to:t.to,word:t.word,...t.times?{times:t.times}:{},index:n}]))}function Sf(e){return[...new Set([...e.manager?[e.manager]:[],...e.blocks.flatMap(e=>[...e.brief?[e.brief]:[],...(e.substeps??[]).flatMap(e=>e.brief?[e.brief]:[])]),...e.overlays.map(e=>e.file)])]}var Cf=e=>e?.runs===`new-session`||e?.runs===`continue`,wf=/^(?:flow\.json|rules\.md|manager\.md|(?:briefs|overlays)\/(?!\.)[A-Za-z0-9_. -]{1,80}\.md|flows\/[a-z0-9][a-z0-9-]{0,47}\.json)$/,Tf=Object.defineProperty,Ef=(e,t,n)=>t in e?Tf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Df=(e,t)=>{for(var n in t)Tf(e,n,{get:t[n],enumerable:!0})},Of=(e,t,n)=>Ef(e,typeof t==`symbol`?t:t+``,n),kf={};Df(kf,{Graph:()=>mp,alg:()=>Hf});var Af=Object.defineProperty,jf=(e,t)=>{for(var n in t)Af(e,n,{get:t[n],enumerable:!0})},Mf=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected=`directed`in e?e.directed:!0,this._isMultigraph=`multigraph`in e&&e.multigraph,this._isCompound=`compound`in e&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[`\0`]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=typeof e==`function`?e:()=>e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(e=>{t===void 0?this.setNode(e):this.setNode(e,t)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=`\0`,this._children[e]={},this._children[`\0`][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=e=>this.removeEdge(this._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(e=>{this.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw Error(`Cannot set parent in a non-compound graph`);if(t===void 0)t=`\0`;else{t+=``;for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw Error(`Setting `+t+` as parent of `+e+` would create a cycle`);this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!==`\0`)return t}}children(e=`\0`){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e===`\0`)return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t),r=this.successors(e);if(r)for(let e of r)n.add(e);return Array.from(n.values())}}isLeaf(e){let t;return t=this.isDirected()?this.successors(e):this.neighbors(e),(t?.length??0)===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([n,r])=>{e(n)&&t.setNode(n,r)}),Object.values(this._edgeObjs).forEach(e=>{t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,this.edge(e))});let n={},r=e=>{let i=this.parent(e);return!i||t.hasNode(i)?(n[e]=i,i):i in n?n[i]:r(i)};return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,r(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=typeof e==`function`?e:()=>e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((e,n)=>(t===void 0?this.setEdge(e,n):this.setEdge(e,n,t),n)),this}setEdge(e,t,n,r){let i,a,o,s,c=!1;typeof e==`object`&&e&&`v`in e?(i=e.v,a=e.w,o=e.name,arguments.length===2&&(s=t,c=!0)):(i=e,a=t,o=r,arguments.length>2&&(s=n,c=!0)),i=``+i,a=``+a,o!==void 0&&(o=``+o);let l=Ff(this._isDirected,i,a,o);if(l in this._edgeLabels)return c&&(this._edgeLabels[l]=s),this;if(o!==void 0&&!this._isMultigraph)throw Error(`Cannot set a named edge when isMultigraph = false`);this.setNode(i),this.setNode(a),this._edgeLabels[l]=c?s:this._defaultEdgeLabelFn(i,a,o);let u=If(this._isDirected,i,a,o);return i=u.v,a=u.w,Object.freeze(u),this._edgeObjs[l]=u,Nf(this._preds[a],i),Nf(this._sucs[i],a),this._in[a][l]=u,this._out[i][l]=u,this._edgeCount++,this}edge(e,t,n){let r=arguments.length===1?Lf(this._isDirected,e):Ff(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof r!=`object`||!r?{label:r}:r}hasEdge(e,t,n){return(arguments.length===1?Lf(this._isDirected,e):Ff(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?Lf(this._isDirected,e):Ff(this._isDirected,e,t,n),i=this._edgeObjs[r];if(i){let e=i.v,t=i.w;delete this._edgeLabels[r],delete this._edgeObjs[r],Pf(this._preds[t],e),Pf(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(e=>e.v===t&&e.w===n||e.v===n&&e.w===t):r}};function Nf(e,t){e[t]?e[t]++:e[t]=1}function Pf(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function Ff(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}return i+``+a+``+(r===void 0?`\0`:r)}function If(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}let o={v:i,w:a};return r&&(o.name=r),o}function Lf(e,t){return Ff(e,t.v,t.w,t.name)}jf({},{read:()=>Vf,write:()=>Rf});function Rf(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:zf(e),edges:Bf(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function zf(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),i={v:t};return n!==void 0&&(i.value=n),r!==void 0&&(i.parent=r),i})}function Bf(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function Vf(e){let t=new Mf(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(e=>{t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(e=>{t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}var Hf={};jf(Hf,{CycleException:()=>rp,bellmanFord:()=>Wf,components:()=>Kf,dijkstra:()=>Yf,dijkstraAll:()=>Zf,findCycles:()=>$f,floydWarshall:()=>tp,isAcyclic:()=>ap,postorder:()=>lp,preorder:()=>up,prim:()=>dp,shortestPaths:()=>fp,tarjan:()=>Qf,topsort:()=>ip});var Uf=()=>1;function Wf(e,t,n,r){return Gf(e,String(t),n||Uf,r||function(t){return e.outEdges(t)??[]})}function Gf(e,t,n,r){let i={},a,o=0,s=e.nodes(),c=function(e){let t=i[e.v],r=i[e.w];if(!t||!r)return;let o=n(e);t.distance+o<r.distance&&(i[e.w]={distance:t.distance+o,predecessor:e.v},a=!0)},l=function(){s.forEach(function(e){r(e).forEach(function(t){let n=t.v===e?t.v:t.w,r=n===t.v?t.w:t.v;c({v:n,w:r})})})};s.forEach(function(e){i[e]={distance:e===t?0:1/0,predecessor:``}});let u=s.length;for(let e=1;e<u&&(a=!1,o++,l(),a);e++);if(o===u-1&&(a=!1,l(),a))throw Error(`The graph contains a negative weight cycle`);return i}function Kf(e){let t={},n=[],r;function i(n){var a,o;n in t||(t[n]=!0,r.push(n),(a=e.successors(n))==null||a.forEach(i),(o=e.predecessors(n))==null||o.forEach(i))}return e.nodes().forEach(function(e){r=[],i(e),r.length&&n.push(r)}),n}var qf=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw Error(`Queue underflow`);return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let e=this._arr,i=e.length;return n[r]=i,e.push({key:r,priority:t}),this._decrease(i),!0}return!1}removeMin(){if(this.size()===0)throw Error(`Queue underflow`);this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,i=e;n<t.length&&(i=t[n].priority<t[i].priority?n:i,r<t.length&&(i=t[r].priority<t[i].priority?r:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){let t=this._arr,n=t[e].priority,r;for(;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r}_swap(e,t){let n=this._arr,r=this._keyIndices,i=n[e],a=n[t];n[e]=a,n[t]=i,r[a.key]=e,r[i.key]=t}},Jf=()=>1;function Yf(e,t,n,r){return Xf(e,String(t),n||Jf,r||function(t){return e.outEdges(t)??[]})}function Xf(e,t,n,r){let i={},a=new qf,o,s,c=function(e){let t=e.v===o?e.w:e.v,r=i[t];if(!r)return;let c=n(e),l=s.distance+c;if(c<0)throw Error(`dijkstra does not allow negative edge weights. Bad edge: `+e+` Weight: `+c);l<r.distance&&(r.distance=l,r.predecessor=o,a.decrease(t,l))};for(e.nodes().forEach(function(e){let n=e===t?0:1/0;i[e]={distance:n,predecessor:``},a.add(e,n)});a.size()>0;){o=a.removeMin();let e=i[o];if(!e||e.distance===1/0)break;s=e,r(o).forEach(c)}return i}function Zf(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=Yf(e,i,t,n),r},{})}function Qf(e){let t=0,n=[],r={},i=[];function a(o){var s;let c=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),(s=e.successors(o))==null||s.forEach(function(e){if(e in r){let t=r[e];t!=null&&t.onStack&&(c.lowlink=Math.min(c.lowlink,t.index))}else{a(e);let t=r[e];t&&(c.lowlink=Math.min(c.lowlink,t.lowlink))}}),c.lowlink===c.index){let e=[],t;do{t=n.pop();let i=r[t];i&&(i.onStack=!1),e.push(t)}while(o!==t);i.push(e)}}return e.nodes().forEach(function(e){e in r||a(e)}),i}function $f(e){return Qf(e).filter(function(t){let n=t[0];return n?t.length>1||t.length===1&&(e.outEdges(n,n)??[]).length>0:!1})}var ep=()=>1;function tp(e,t,n){return np(e,t||ep,n||function(t){return e.outEdges(t)??[]})}function np(e,t,n){let r={},i=e.nodes();return i.forEach(function(e){let a={};r[e]=a,a[e]={distance:0,predecessor:``},i.forEach(function(t){e!==t&&(a[t]={distance:1/0,predecessor:``})}),n(e).forEach(function(n){let r=n.v===e?n.w:n.v,i=t(n);a[r]={distance:i,predecessor:e}})}),i.forEach(function(e){let t=r[e];t&&i.forEach(function(n){let a=r[n];a&&i.forEach(function(n){let r=a[e],i=t[n],o=a[n];if(r&&i&&o){let e=r.distance+i.distance;e<o.distance&&(o.distance=e,o.predecessor=i.predecessor)}})})}),r}var rp=class extends Error{constructor(e){super(e),this.name=`CycleException`}};function ip(e){let t={},n={},r=[];function i(a){var o;if(a in n)throw new rp;a in t||(n[a]=!0,t[a]=!0,(o=e.predecessors(a))==null||o.forEach(i),delete n[a],r.push(a))}if(e.sinks().forEach(i),Object.keys(t).length!==e.nodeCount())throw new rp;return r}function ap(e){try{ip(e)}catch(e){if(e instanceof rp)return!1;throw e}return!0}function op(e,t,n,r,i){Array.isArray(t)||(t=[t]);let a=(t=>(e.isDirected()?e.successors(t):e.neighbors(t))??[]),o={};return t.forEach(function(t){if(!e.hasNode(t))throw Error(`Graph does not have node: `+t);i=sp(e,t,n===`post`,o,a,r,i)}),i}function sp(e,t,n,r,i,a,o){return t in r||(r[t]=!0,n||(o=a(o,t)),i(t).forEach(function(t){o=sp(e,t,n,r,i,a,o)}),n&&(o=a(o,t))),o}function cp(e,t,n){return op(e,t,n,function(e,t){return e.push(t),e},[])}function lp(e,t){return cp(e,t,`post`)}function up(e,t){return cp(e,t,`pre`)}function dp(e,t){var n;let r=new Mf,i={},a=new qf,o;function s(e){let n=e.v===o?e.w:e.v,r=a.priority(n);if(r!==void 0){let s=t(e);s<r&&(i[n]=o,a.decrease(n,s))}}if(e.nodeCount()===0)return r;e.nodes().forEach(function(e){a.add(e,1/0),r.setNode(e)});let c=e.nodes()[0];c!==void 0&&a.decrease(c,0);let l=!1;for(;a.size()>0;){if(o=a.removeMin(),o in i)r.setEdge(o,i[o]);else{if(l)throw Error(`Input graph is not connected: `+e);l=!0}(n=e.nodeEdges(o))==null||n.forEach(s)}return r}function fp(e,t,n,r){return pp(e,t,n,r??(t=>e.outEdges(t)??[]))}function pp(e,t,n,r){if(n===void 0)return Yf(e,t,n,r);let i=!1,a=e.nodes();for(let o=0;o<a.length;o++){let s=a[o];if(s===void 0)continue;let c=r(s);for(let e=0;e<c.length;e++){let t=c[e];if(!t)continue;let r=t.v===s?t.v:t.w;n({v:r,w:r===t.v?t.w:t.v})<0&&(i=!0)}if(i)return Wf(e,t,n,r)}return Yf(e,t,n,r)}var mp=Mf;function hp(e,t,n,r){let i=r;for(;e.hasNode(i);)i=jp(r);return n.dummy=t,e.setNode(i,n),i}function gp(e){let t=new mp().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},i=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+i.weight,minlen:Math.max(r.minlen,i.minlen)})}),t}function _p(e){let t=new mp({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function vp(e,t){let n=e.x,r=e.y,i=t.x-n,a=t.y-r,o=e.width/2,s=e.height/2;if(!i&&!a)throw Error(`Not possible to find intersection inside of the rectangle`);let c,l;return Math.abs(a)*o>Math.abs(i)*s?(a<0&&(s=-s),c=s*i/a,l=s):(i<0&&(o=-o),c=o,l=o*a/i),{x:n+c,y:r+l}}function yp(e){let t=Mp(Ep(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),i=r.rank;i!==void 0&&(t[i]||(t[i]=[]),t[i][r.order]=n)}),t}function bp(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MAX_VALUE:n}),n=Tp(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,`rank`)&&(r.rank-=n)})}function xp(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>e!==void 0),n=Tp(Math.min,t),r=[];e.nodes().forEach(t=>{let i=e.node(t).rank-n;r[i]||(r[i]=[]),r[i].push(t)});let i=0,a=e.graph().nodeRankFactor;Array.from(r).forEach((t,n)=>{t===void 0&&n%a!==0?--i:t!==void 0&&i&&t.forEach(t=>e.node(t).rank+=i)})}function Sp(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),hp(e,`border`,i,t)}function Cp(e,t=wp){let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t);n.push(i)}return n}var wp=65535;function Tp(e,t){return t.length>wp?e(...Cp(t).map(t=>e(...t))):e(...t)}function Ep(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MIN_VALUE:n});return Tp(Math.max,t)}function Dp(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}function Op(e,t){let n=Date.now();try{return t()}finally{console.log(e+` time: `+(Date.now()-n)+`ms`)}}function kp(e,t){return t()}var Ap=0;function jp(e){return e+(``+ ++Ap)}function Mp(e,t,n=1){t??(t=e,e=0);let r=e=>e<t;n<0&&(r=e=>t<e);let i=[];for(let t=e;r(t);t+=n)i.push(t);return i}function Np(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function Pp(e,t){let n;return n=typeof t==`string`?e=>e[t]:t,Object.entries(e).reduce((e,[t,r])=>(e[t]=n(r,t),e),{})}function Fp(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}var Ip=`\0`;function Lp(e,t,n){if(!(e&&t&&n&&t.dummy===`edge`&&n.dummy===`edge`&&t.edgeObj&&n.edgeObj&&e[t.edgeObj.v]&&e[n.edgeObj.v]&&e[t.edgeObj.w]&&e[n.edgeObj.w]))return 0;let r=!0;t.edgeObj.w===n.edgeObj.w&&(r=!1);let i=r?e[t.edgeObj.v]?.rank??NaN:e[t.edgeObj.w]?.rank??NaN,a=Object.entries(e).find(e=>e[1].edgeObj?.v===t.edgeObj.v&&e[1].edgeObj?.w===t.edgeObj.w&&e[1].rank===i),o=Object.entries(e).find(e=>e[1].edgeObj?.v===n.edgeObj.v&&e[1].edgeObj?.w===n.edgeObj.w&&e[1].rank===i);if(!a||!o)return 0;let s=a[1].order??NaN,c=o[1].order??NaN;return isNaN(s-c)?0:s-c}var Rp=`3.1.1`,zp=class{constructor(){Of(this,`_sentinel`);let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Bp(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Bp(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,Vp)),n=n._prev;return`[`+e.join(`, `)+`]`}};function Bp(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Vp(e,t){if(e!==`_next`&&e!==`_prev`)return t}var Hp=zp,Up=()=>1;function Wp(e,t){if(e.nodeCount()<=1)return[];let n=qp(e,t||Up);return Gp(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function Gp(e,t,n){let r=[],i=t[t.length-1],a=t[0],o;for(;e.nodeCount();){for(;o=a.dequeue();)Kp(e,t,n,o);for(;o=i.dequeue();)Kp(e,t,n,o);if(e.nodeCount()){for(let i=t.length-2;i>0;--i)if(o=t[i]?.dequeue(),o){r=r.concat(Kp(e,t,n,o,!0)||[]);break}}}return r}function Kp(e,t,n,r,i){let a=[],o=i?a:void 0;return(e.inEdges(r.v)||[]).forEach(r=>{let o=e.edge(r),s=e.node(r.v);i&&a.push({v:r.v,w:r.w}),s.out-=o,Jp(t,n,s)}),(e.outEdges(r.v)||[]).forEach(r=>{let i=e.edge(r),a=r.w,o=e.node(a);o.in-=i,Jp(t,n,o)}),e.removeNode(r.v),o}function qp(e,t){let n=new mp,r=0,i=0;e.nodes().forEach(e=>{n.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let a=n.edge(e.v,e.w)||0,o=t(e),s=a+o;n.setEdge(e.v,e.w,s);let c=n.node(e.v),l=n.node(e.w);i=Math.max(i,c.out+=o),r=Math.max(r,l.in+=o)});let a=Yp(i+r+3).map(()=>new Hp),o=r+1;return n.nodes().forEach(e=>{Jp(a,o,n.node(e))}),{graph:n,buckets:a,zeroIdx:o}}function Jp(e,t,n){var r,i,a;n.out?n.in?(a=e[n.out-n.in+t])==null||a.enqueue(n):(i=e[e.length-1])==null||i.enqueue(n):(r=e[0])==null||r.enqueue(n)}function Yp(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function Xp(e,t){(e.graph().acyclicer===`greedy`?Wp(e,n(e)):Zp(e,t??null)).forEach(t=>{let n=e.edge(t);e.removeEdge(t),n.forwardName=t.name,n.reversed=!0,e.setEdge(t.w,t.v,n,jp(`rev`))});function n(e){return t=>e.edge(t).weight}}function Zp(e,t){let n=[],r={},i={};function a(t){Object.hasOwn(i,t)||(i[t]=!0,r[t]=!0,e.outEdges(t).forEach(e=>{Object.hasOwn(r,e.w)?n.push(e):a(e.w)}),delete r[t])}function o(a){var s;Object.hasOwn(i,a)||(i[a]=!0,r[a]=!0,(s=e.outEdges(a))==null||s.forEach(i=>{Object.hasOwn(r,i.w)||t.node(a)?.rank>t.node(i.w)?.rank&&$p(e,i.w,i)?n.push(i):o(i.w)}),delete r[a])}let s=a;return t&&typeof t.node==`function`&&(s=o),e.sources().forEach(s),e.nodes().forEach(s),n}function Qp(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}function $p(e,t,n){let r=new Set;function i(t){if(e.sources().includes(t))return!0;r.add(t);for(let a of e.inEdges(t)??[])if((a.v!==n.v||a.w!==n.w)&&!r.has(a.v)&&i(a.v))return!0;return!1}return i(t)}function em(e){e.graph().dummyChains=[],e.edges().forEach(t=>tm(e,t))}function tm(e,t){let n=t.v,r=e.node(n).rank,i=t.w,a=e.node(i).rank,o=t.name,s=e.edge(t),c=s.labelRank;if(a===r+1)return;e.removeEdge(t);let l,u,d=0;for(++r;r<a;++d,++r)s.points=[],u={width:0,height:0,edgeLabel:s,edgeObj:t,rank:r},l=hp(e,`edge`,u,`_d`),r===c&&(u.width=s.width,u.height=s.height,u.dummy=`edge-label`,u.labelpos=s.labelpos),e.setEdge(n,l,{weight:s.weight},o),d===0&&e.graph().dummyChains.push(l),n=l;e.setEdge(n,i,{weight:s.weight},o)}function nm(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,i;for(e.setEdge(n.edgeObj,r);n.dummy;)i=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy===`edge-label`&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=i,n=e.node(t)})}function rm(e){let t={};function n(r){let i=e.node(r);if(Object.hasOwn(t,r))return i.rank;t[r]=!0;let a=e.outEdges(r),o=a?a.map(t=>t==null?1/0:n(t.w)-e.edge(t).minlen):[],s=Tp(Math.min,o);return s===1/0&&(s=0),i.rank=s}e.sources().forEach(n)}function im(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var am=om;function om(e){let t=new mp({directed:!1}),n=e.nodes();if(n.length===0)throw Error(`Graph must have at least one node`);let r=n[0],i=e.nodeCount();t.setNode(r,{});let a,o;for(;sm(t,e)<i&&(a=cm(t,e),a);)o=t.hasNode(a.v)?im(e,a):-im(e,a),lm(t,e,o);return t}function sm(e,t){function n(r){let i=t.nodeEdges(r);i&&i.forEach(i=>{let a=i.v,o=r===a?i.w:a;!e.hasNode(o)&&!im(t,i)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function cm(e,t){return t.edges().reduce((n,r)=>{let i=1/0;return e.hasNode(r.v)!==e.hasNode(r.w)&&(i=im(t,r)),i<n[0]?[i,r]:n},[1/0,null])[1]}function lm(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:um,postorder:dm}=Hf,fm=pm;pm.initLowLimValues=_m,pm.initCutValues=mm,pm.calcCutValue=gm,pm.leaveEdge=ym,pm.enterEdge=bm,pm.exchangeEdges=xm;function pm(e){e=gp(e),rm(e);let t=am(e);_m(t),mm(t,e);let n,r;for(;n=ym(t);)r=bm(t,e,n),xm(t,e,n,r)}function mm(e,t){let n=dm(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>hm(e,t,n))}function hm(e,t,n){let r=e.node(n).parent,i=e.edge(n,r);i.cutvalue=gm(e,t,n)}function gm(e,t,n){let r=e.node(n).parent,i=!0,a=t.edge(n,r),o=0;a||=(i=!1,t.edge(r,n)),o=a.weight;let s=t.nodeEdges(n);return s&&s.forEach(a=>{let s=a.v===n,c=s?a.w:a.v;if(c!==r){let r=s===i,l=t.edge(a).weight;if(o+=r?l:-l,Cm(e,n,c)){let t=e.edge(n,c).cutvalue;o+=r?-t:t}}}),o}function _m(e,t){arguments.length<2&&(t=e.nodes()[0]),vm(e,{},1,t)}function vm(e,t,n,r,i){let a=n,o=e.node(r);t[r]=!0;let s=e.neighbors(r);return s&&s.forEach(i=>{Object.hasOwn(t,i)||(n=vm(e,t,n,i,r))}),o.low=a,o.lim=n++,i?o.parent=i:delete o.parent,n}function ym(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function bm(e,t,n){let r=n.v,i=n.w;t.hasEdge(r,i)||(r=n.w,i=n.v);let a=e.node(r),o=e.node(i),s=a,c=!1;return a.lim>o.lim&&(s=o,c=!0),t.edges().filter(t=>c===wm(e,e.node(t.v),s)&&c!==wm(e,e.node(t.w),s)).reduce((e,n)=>im(t,n)<im(t,e)?n:e)}function xm(e,t,n,r){let i=n.v,a=n.w;e.removeEdge(i,a),e.setEdge(r.v,r.w,{}),_m(e),mm(e,t),Sm(e,t)}function Sm(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=um(e,[n]);r=r.slice(1),r.forEach(n=>{let r=e.node(n).parent,i=t.edge(n,r),a=!1;i||(i=t.edge(r,n),a=!0),t.node(n).rank=t.node(r).rank+(a?i.minlen:-i.minlen)})}function Cm(e,t,n){return e.hasEdge(t,n)}function wm(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Tm=Em;function Em(e){let t=e.graph().ranker;if(typeof t==`function`)return t(e);switch(t){case`network-simplex`:km(e);break;case`tight-tree`:Om(e);break;case`longest-path`:Dm(e);break;case`none`:break;default:km(e)}}var Dm=rm;function Om(e){rm(e),am(e)}function km(e){fm(e)}var Am=jm;function jm(e){let t=Nm(e),n=e.graph();Array.isArray(n.dummyChains)&&n.dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,a=Mm(e,t,i.v,i.w),o=a.path,s=a.lca,c=0,l=o[c],u=!0;for(;n!==i.w;){if(r=e.node(n),u){for(;(l=o[c])!==s&&e.node(l).maxRank<r.rank;)c++;l===s&&(u=!1)}if(!u){for(;c<o.length-1&&e.node(o[c+1]).minRank<=r.rank;)c++;l=o[c]}l!==void 0&&e.setParent(n,l),n=e.successors(n)[0]}})}function Mm(e,t,n,r){let i=[],a=[],o=Math.min(t[n].low,t[r].low),s=Math.max(t[n].lim,t[r].lim),c;c=n;do c=e.parent(c),i.push(c);while(c&&(t[c].low>o||s>t[c].lim));let l=c,u=r;for(;(u=e.parent(u))!==l;)a.push(u);return{path:i.concat(a.reverse()),lca:l}}function Nm(e){let t={},n=0;function r(i){let a=n;e.children(i).forEach(r),t[i]={low:a,lim:n++}}return e.children(Ip).forEach(r),t}function Pm(e){let t=hp(e,`root`,{},`_root`),n=Im(e),r=Object.values(n),i=Tp(Math.max,r)-1,a=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let o=Lm(e)+1;e.children(Ip).forEach(r=>{Fm(e,t,a,o,i,n,r)}),e.graph().nodeRankFactor=a}function Fm(e,t,n,r,i,a,o){let s=e.children(o);if(!s.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Sp(e,`_bt`),l=Sp(e,`_bb`),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,s.forEach(s=>{Fm(e,t,n,r,i,a,s);let u=e.node(s),d=u.borderTop?u.borderTop:s,f=u.borderBottom?u.borderBottom:s,p=u.borderTop?r:2*r,m=d===f?i-(a[o]??0)+1:1;e.setEdge(c,d,{weight:p,minlen:m,nestingEdge:!0}),e.setEdge(f,l,{weight:p,minlen:m,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:i+(a[o]??0)})}function Im(e){let t={};function n(r,i){let a=e.children(r);a&&a.length&&a.forEach(e=>n(e,i+1)),t[r]=i}return e.children(Ip).forEach(e=>n(e,1)),t}function Lm(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function Rm(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var zm=Bm;function Bm(e){function t(n){let r=e.children(n),i=e.node(n);if(r.length&&r.forEach(t),i&&Object.hasOwn(i,`minRank`)){i.borderLeft=[],i.borderRight=[];for(let t=i.minRank,r=i.maxRank+1;t<r;++t)Vm(e,`borderLeft`,`_bl`,n,i,t),Vm(e,`borderRight`,`_br`,n,i,t)}}e.children(Ip).forEach(t)}function Vm(e,t,n,r,i,a){let o={width:0,height:0,rank:a,borderType:t},s=i[t][a-1],c=hp(e,`border`,o,n);i[t][a]=c,e.setParent(c,r),s&&e.setEdge(s,c,{weight:1})}function Hm(e){let t=e.graph().rankdir?.toLowerCase();(t===`lr`||t===`rl`)&&Wm(e)}function Um(e){let t=e.graph().rankdir?.toLowerCase();(t===`bt`||t===`rl`)&&Km(e),(t===`lr`||t===`rl`)&&(Jm(e),Wm(e))}function Wm(e){e.nodes().forEach(t=>Gm(e.node(t))),e.edges().forEach(t=>Gm(e.edge(t)))}function Gm(e){let t=e.width;e.width=e.height,e.height=t}function Km(e){e.nodes().forEach(t=>qm(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(qm),Object.hasOwn(r,`y`)&&qm(r)})}function qm(e){e.y=-e.y}function Jm(e){e.nodes().forEach(t=>Ym(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(Ym),Object.hasOwn(r,`x`)&&Ym(r)})}function Ym(e){let t=e.x;e.x=e.y,e.y=t}function Xm(e,t=null){let n={},r=e.nodes().filter(t=>!e.children(t).length),i=r.map(t=>e.node(t).rank),a=Mp(Tp(Math.max,i)+1).map(()=>[]);function o(t){if(n[t])return;n[t]=!0;let r=e.node(t);a[r.rank].push(t);let i=e.successors(t);i&&[...i].sort((e,t)=>s(e,t)).forEach(o)}r.sort((t,n)=>e.node(t).rank-e.node(n).rank).forEach(o);function s(n,r){return Lp(t,e.node(n),e.node(r))}return a}function Zm(e,t){let n=0;for(let r=1;r<t.length;++r)n+=Qm(e,t[r-1],t[r]);return n}function Qm(e,t,n){let r=Fp(n,n.map((e,t)=>t)),i=t.flatMap(t=>{let n=e.outEdges(t);return n?n.map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos):[]}),a=1;for(;a<n.length;)a<<=1;let o=2*a-1;--a;let s=Array(o).fill(0),c=0;return i.forEach(e=>{let t=e.pos+a;s[t]+=e.weight;let n=0;for(;t>0;)t%2&&(n+=s[t+1]),t=t-1>>1,s[t]+=e.weight;c+=e.weight*n}),c}function $m(e,t=[]){return t.map(t=>{let n=e.inEdges(t);if(!n||!n.length)return{v:t};{let r=n.reduce((t,n)=>{let r=e.edge(n),i=e.node(n.v);return{sum:t.sum+r.weight*i.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}})}function eh(e,t){let n={};return e.forEach((e,t)=>{let r={indegree:0,in:[],out:[],vs:[e.v],i:t};e.barycenter!==void 0&&(r.barycenter=e.barycenter,r.weight=e.weight),n[e.v]=r}),t.edges().forEach(e=>{let t=n[e.v],r=n[e.w];t!==void 0&&r!==void 0&&(r.indegree++,t.out.push(r))}),th(Object.values(n).filter(e=>!e.indegree))}function th(e){let t=[];function n(e){return t=>{t.merged||(t.barycenter===void 0||e.barycenter===void 0||t.barycenter>=e.barycenter)&&nh(e,t)}}function r(t){return n=>{n.in.push(t),--n.indegree===0&&e.push(n)}}for(;e.length;){let i=e.pop();t.push(i),i.in.reverse().forEach(n(i)),i.out.forEach(r(i))}return t.filter(e=>!e.merged).map(e=>Np(e,[`vs`,`i`,`barycenter`,`weight`]))}function nh(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}function rh(e,t,n,r,i){let a={},o=null,s=null,c=i;typeof t==`boolean`?(c=t,a={}):t&&(a=t,o=n??null,s=r??null);let l=Dp(e,e=>Object.hasOwn(e,`barycenter`)),u=l.lhs,d=l.rhs.sort((e,t)=>t.i-e.i),f=[],p=0,m=0,h=0;u.sort(ah(s,o,!!c));for(let[e,t]of Object.entries(a)){let n=u.findIndex(t=>t.vs[0]===e);u.splice(n+1,0,t)}h=ih(f,d,h),u.forEach(e=>{h+=e.vs.length,f.push(e.vs),p+=e.barycenter*e.weight,m+=e.weight,h=ih(f,d,h)});let g={vs:f.flat(1)};return m&&(g.barycenter=p/m,g.weight=m),g}function ih(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function ah(e,t,n){return(r,i)=>{if(r.barycenter<i.barycenter)return-1;if(r.barycenter>i.barycenter)return 1;if(e&&(typeof r.vs[0]==`string`||typeof i.vs[0]==`string`)){let n=Lp(t,e.node(r.vs[0]),e.node(i.vs[0]));if(n!==0)return n}return n?i.i-r.i:r.i-i.i}}function oh(e,t,n,r,i){var a,o;let s=null,c=i;typeof r==`boolean`?(c=r,s=null):r!==void 0&&(s=r);let l=e.children(t),u=e.node(t),d=u?u.borderLeft:void 0,f=u?u.borderRight:void 0,p={};d&&(l=l.filter(e=>e!==d&&e!==f));let m=$m(e,l);m.forEach(t=>{if(e.children(t.v).length){let{result:r}=oh(e,t.v,n,s,c);p[t.v]=r,Object.hasOwn(r,`barycenter`)&&ch(t,r)}});let h=eh(m,n);sh(h,p);let g={},_=!1;for(let t=0;t<h.length;t++)for(let n=t+1;n<h.length;n++)if(h[t]&&h[n]&&(a=h[t])!=null&&a.barycenter&&(o=h[n])!=null&&o.barycenter&&h[t]?.barycenter===h[n].barycenter){let r=h[t]?.vs[0]??``,i=h[n]?.vs[0]??``,a=e.node(r),o=e.node(i);if(a.dummy===`edge`&&o.dummy===`edge`&&a.edgeObj?.v===o.edgeObj?.v&&a.edgeObj?.w===o.edgeObj?.w){if(a.edgeLabel.reversed){g[i]=h[t],h.splice(t,1),t--;break}g[r]=h[n],h.splice(n,1),n--}else _=!0}let v=rh(h,g,s,e,c);if(d&&f){v.vs=[d,v.vs,f].flat(1);let t=e.predecessors(d);if(t&&t.length){let n=e.node(t[0]),r=e.predecessors(f),i=e.node(r[0]);Object.hasOwn(v,`barycenter`)||(v.barycenter=0,v.weight=0),v.barycenter=(v.barycenter*v.weight+n.order+i.order)/(v.weight+2),v.weight+=2}}return Object.defineProperty(v,"result",{value:v,enumerable:!1,configurable:!0,writable:!0}),Object.defineProperty(v,"usedBias",{value:_,enumerable:!1,configurable:!0,writable:!0}),v}function sh(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}function ch(e,t){e.barycenter===void 0?(e.barycenter=t.barycenter,e.weight=t.weight):(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight)}function lh(e,t,n,r){r||=e.nodes();let i=uh(e),a=new mp({compound:!0}).setGraph({root:i}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let o=e.node(r),s=e.parent(r);if(o.rank===t||o.minRank<=t&&t<=o.maxRank){a.setNode(r),a.setParent(r,s||i);let c=e[n](r);c&&c.forEach(t=>{let n=t.v===r?t.w:t.v,i=a.edge(n,r),o=i===void 0?0:i.weight;a.setEdge(n,r,{weight:e.edge(t).weight+o})}),Object.hasOwn(o,`minRank`)&&a.setNode(r,{borderLeft:o.borderLeft[t],borderRight:o.borderRight[t]})}}),a}function uh(e){let t;for(;e.hasNode(t=jp(`_root`)););return t}function dh(e,t,n){let r={},i;n.forEach(n=>{let a=e.parent(n),o,s;for(;a;){if(o=e.parent(a),o?(s=r[o],r[o]=a):(s=i,i=a),s&&s!==a){t.setEdge(s,a);return}a=o}})}function fh(e,t={},n=null){if(typeof t.customOrder==`function`){t.customOrder(e,fh);return}let r=Ep(e),i=ph(e,Mp(1,r+1),`inEdges`),a=ph(e,Mp(r-1,-1,-1),`outEdges`),o=Xm(e,n);if(hh(e,o),t.disableOptimalOrderHeuristic)return;let s=1/0,c,l=t.constraints||[];for(let t=0,r=0;r<4;++t,++r){mh(t%2?i:a,t%4>=2,l,n),o=yp(e);let u=Zm(e,o);u<s?(r=0,c=Object.assign({},o),s=u):u===s&&(c=structuredClone(o))}hh(e,c)}function ph(e,t,n){let r=new Map,i=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(let t of e.nodes()){let n=e.node(t);if(typeof n.rank==`number`&&i(n.rank,t),typeof n.minRank==`number`&&typeof n.maxRank==`number`)for(let e=n.minRank;e<=n.maxRank;e++)e!==n.rank&&i(e,t)}return t.map(function(t){return lh(e,t,n,r.get(t)||[])})}function mh(e,t,n,r){let i=!0,a=new mp;e.forEach(function(e){n.forEach(e=>a.setEdge(e.left,e.right));let o=e.graph().root,{result:s,usedBias:c}=oh(e,o,a,r,i);t&&c&&(i=!i),s.vs.forEach((t,n)=>e.node(t).order=n),dh(e,a,s.vs)})}function hh(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function gh(e,t){let n={};function r(t,r){let i=0,a=0,o=t.length,s=r[r.length-1];return r.forEach((t,c)=>{let l=vh(e,t),u=l?e.node(l).order:o;(l||t===s)&&(r.slice(a,c+1).forEach(t=>{let r=e.predecessors(t);r&&r.forEach(r=>{let a=e.node(r),o=a.order;(o<i||u<o)&&!(a.dummy&&e.node(t).dummy)&&yh(n,r,t)})}),a=c+1,i=u)}),r}return t.length&&t.reduce(r),n}function _h(e,t){let n={};function r(t,r,i,a,o){Mp(r,i).forEach(r=>{let i=t[r];if(i!==void 0&&e.node(i).dummy){let t=e.predecessors(i);t&&t.forEach(t=>{if(t===void 0)return;let r=e.node(t);r.dummy&&(r.order<a||r.order>o)&&yh(n,t,i)})}})}function i(t,n){let i=-1,a=-1,o=0;return n.forEach((s,c)=>{if(e.node(s).dummy===`border`){let t=e.predecessors(s);if(t&&t.length){let s=t[0];if(s===void 0)return;a=e.node(s).order,r(n,o,c,i,a),o=c,i=a}}r(n,o,n.length,a,t.length)}),n}return t.length&&t.reduce(i),n}function vh(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}function yh(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];r||(e[t]=r={}),r[n]=!0}function bh(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];return r!==void 0&&Object.hasOwn(r,n)}function xh(e,t,n,r,i){let a={},o={},s={};return t.forEach(e=>{e.forEach((e,t)=>{a[e]=e,o[e]=e,s[e]=t})}),t.forEach(t=>{let c=-1,l=-1,u=!1,d=t,f=t.findIndex(t=>i?.includes(t)||Ah(t,e,i));f>0&&(d=[t[f],...t.slice(0,f),...t.slice(f+1)],u=!0),d.forEach(t=>{let d=r(t);if(d&&d.length){i!=null&&i.includes(t)&&(d=d.filter(t=>Ah(t,e,i)));let r=d.sort((e,t)=>{let n=s[e],r=s[t];return(n===void 0?0:n)-(r===void 0?0:r)}),f=(r.length-1)/2;for(let e=Math.floor(f),i=Math.ceil(f);e<=i;++e){let i=r[e];if(i===void 0)continue;let d=s[i];if(d!==void 0&&o[t]===t&&c<d&&s[i]!==l&&!bh(n,t,i)){let e=a[i];e!==void 0&&(o[i]=t,o[t]=a[t]=e,c=d,u&&=(c=-1,l=s[i]??-1,!1))}}}})}),{root:a,align:o}}function Sh(e,t,n,r,i=!1){let a={},o=Ch(e,t,n,i),s=i?`borderLeft`:`borderRight`;function c(e,t){let n=o.nodes().slice(),r={},i=n.pop();for(;i;){if(r[i])e(i);else{r[i]=!0,n.push(i);for(let e of t(i))n.push(e)}i=n.pop()}}function l(e){let t=o.inEdges(e);t?a[e]=t.reduce((e,t)=>{let n=a[t.v]??0,r=o.edge(t);return Math.max(e,n+(r===void 0?0:r))},0):a[e]=0}function u(t){let n=o.outEdges(t),r=1/0;n&&(r=n.reduce((e,t)=>{let n=a[t.w],r=o.edge(t);return Math.min(e,(n===void 0?0:n)-(r===void 0?0:r))},1/0));let i=e.node(t);r!==1/0&&i.borderType!==s&&(a[t]=Math.max(a[t]===void 0?0:a[t],r))}function d(e){return o.predecessors(e)||[]}function f(e){return o.successors(e)||[]}return c(l,d),c(u,f),Object.keys(r).forEach(e=>{let t=n[e];t!==void 0&&(a[e]=a[t]??0)}),a}function Ch(e,t,n,r){let i=new mp,a=e.graph(),o=Oh(a.nodesep,a.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let a=n[t];if(a!==void 0){if(i.setNode(a),r!==void 0){let s=n[r];if(s!==void 0){let n=i.edge(s,a);i.setEdge(s,a,Math.max(o(e,t,r),n||0))}}r=t}})}),i}function wh(e,t){return Object.values(t).reduce((t,n)=>{let r=-1/0,i=1/0;Object.entries(n).forEach(([t,n])=>{let a=kh(e,t)/2;r=Math.max(n+a,r),i=Math.min(n-a,i)});let a=r-i;return a<t[0]&&(t=[a,n]),t},[1/0,null])[1]}function Th(e,t){let n=Object.values(t),r=Tp(Math.min,n),i=Tp(Math.max,n);[`u`,`d`].forEach(n=>{[`l`,`r`].forEach(a=>{let o=n+a,s=e[o];if(!s||s===t)return;let c=Object.values(s),l=r-Tp(Math.min,c);a!==`l`&&(l=i-Tp(Math.max,c)),l&&(e[o]=Pp(s,e=>e+l))})})}function Eh(e,t=void 0){let n=e.ul;return n?Pp(n,(n,r)=>{if(t){let n=e[t.toLowerCase()];if(n&&n[r]!==void 0)return n[r]}let i=Object.values(e).map(e=>{let t=e[r];return t===void 0?0:t}).sort((e,t)=>e-t);return((i[1]??0)+(i[2]??0))/2}):{}}function Dh(e,t){let n=yp(e),r=Object.assign(gh(e,n),_h(e,n)),i={},a;return[`u`,`d`].forEach(o=>{a=o===`u`?n:Object.values(n).reverse(),[`l`,`r`].forEach(n=>{n===`r`&&(a=a.map(e=>Object.values(e).reverse()));let s=xh(e,a,r,t=>(o===`u`?e.predecessors(t):e.successors(t))||[],t),c=Sh(e,a,s.root,s.align,n===`r`);n===`r`&&(c=Pp(c,e=>-e)),i[o+n]=c})}),Th(i,wh(e,i)),Eh(i,e.graph().align)}function Oh(e,t,n){return(r,i,a)=>{let o=r.node(i),s=r.node(a),c=0,l;if(c+=o.width/2,Object.hasOwn(o,`labelpos`))switch(o.labelpos.toLowerCase()){case`l`:l=-o.width/2;break;case`r`:l=o.width/2}if(l&&(c+=n?l:-l),l=void 0,c+=(o.dummy?t:e)/2,c+=(s.dummy?t:e)/2,c+=s.width/2,Object.hasOwn(s,`labelpos`))switch(s.labelpos.toLowerCase()){case`l`:l=s.width/2;break;case`r`:l=-s.width/2}return l&&(c+=n?l:-l),c}}function kh(e,t){return e.node(t).width}function Ah(e,t,n){if(!n)return!1;let r=t.node(e)?.edgeObj;if(!r||t.node(e).edgeLabel.reversed)return!1;let i=n.indexOf(r?.v),a=n.indexOf(r?.w);return i!==-1&&a!==-1&&i===(a+1)%n.length||i===(a-1)%n.length}function jh(e,t){e=_p(e),Mh(e),Object.entries(Dh(e,t)).forEach(([t,n])=>e.node(t).x=n)}function Mh(e){let t=yp(e),n=e.graph(),r=n.ranksep,i=n.rankalign,a=0;t.forEach(t=>{let n=t.reduce((t,n)=>{let r=e.node(n).height??0;return t>r?t:r},0);t.forEach(t=>{let r=e.node(t);r.y=i===`top`?a+r.height/2:i===`bottom`?a+n-r.height/2:a+n/2}),a+=n+r})}var Nh=new WeakMap;function Ph(e,t={}){return Ih(e,kp,t),e}function Fh(e,t,n){let r=t;for(;r!==void 0;){let t=e.parent(r);if(t===n)return r;r=t}}function Ih(e,t,n){let r=e.nodes().filter(t=>e.children(t).length),i={};r.forEach(r=>{let a=e.node(r);if(a&&a.rankdir){let o=new mp({multigraph:!0,compound:!0});o.setGraph({rankdir:a.rankdir});let s=e.children(r);s.forEach(t=>{let n={...e.node(t)};o.setNode(t,n);let i=e.parent(t);i&&i!==r&&s.includes(i)&&o.setParent(t,i)});let c=new Set;e.edges().forEach(t=>{let n=Fh(e,t.v,r),i=Fh(e,t.w,r);if(n&&i&&n!==i){let r=`${n}\0${i}`;c.has(r)||(c.add(r),o.setEdge(n,i,{...e.edge(t)}))}}),Ih(o,t,n);let l=qh(o);Lh(l,t,n,null),Rh(o,l);let u=1/0,d=1/0,f=-1/0,p=-1/0;o.nodes().forEach(e=>{if(e===r)return;let t=o.node(e);t&&typeof t.x==`number`&&typeof t.y==`number`&&typeof t.width==`number`&&typeof t.height==`number`&&(u=Math.min(u,t.x-t.width/2),f=Math.max(f,t.x+t.width/2),d=Math.min(d,t.y-t.height/2),p=Math.max(p,t.y+t.height/2))}),(!isFinite(u)||!isFinite(d)||!isFinite(f)||!isFinite(p))&&(u=d=0,f=p=0);let m=f-u,h=p-d;i[r]={minX:u,minY:d,maxX:f,maxY:p,width:m,height:h,offsetX:u,offsetY:d},a._dagreClusterSubgraph=o}});let a=[],o=t=>{let n=[],r=(e.children(t)||[]).filter(e=>e!==t);for(;r.length>0;){let t=r.shift();n.push(t),(e.children(t)||[]).filter(e=>e!==t).forEach(e=>r.push(e))}return n},s=new Map;r.forEach(t=>{let n=e.node(t);n&&n.rankdir&&i[t]&&s.set(t,(e.children(t)||[]).filter(e=>e!==t))});let c=new Set([...s.values()].flat()),l=new Map;s.forEach((e,t)=>{c.has(t)||l.set(t,o(t))});let u=new Set([...l.values()].flat()),d=e=>{for(let[t,n]of l)if(n.includes(e))return t;return e},f=[];e.edges().forEach(t=>{(u.has(t.v)||u.has(t.w))&&f.push({edge:t,label:e.edge(t)})});let p=new Map;u.forEach(t=>{let n=e.parent(t);p.set(t,typeof n==`string`?n:void 0)}),l.forEach((t,n)=>{let r=e.node(n),o=[];t.forEach(t=>{let n=e.node(t);n&&(o.push({id:t,node:n,parent:p.get(t)}),e.removeNode(t))});let s=f.filter(({edge:e})=>t.includes(e.v)||t.includes(e.w)),c=i[n];r&&(a.push({clusterId:n,subgraph:r._dagreClusterSubgraph,bounds:c,children:t,removedNodes:o,removedEdges:s}),r.width=c.width,r.height=c.height)});let m=new Set;f.forEach(({edge:t,label:n})=>{let r=d(t.v),i=d(t.w);if(r!==i&&e.hasNode(r)&&e.hasNode(i)){let t=`${r}\0${i}`;m.has(t)||(m.add(t),e.setEdge(r,i,{...n,width:0,height:0}))}});let h=qh(e),g=Lh(h,t,n,Nh.get(e)??null);Nh.set(e,g),Rh(e,h),m.forEach(t=>{let n=t.indexOf(`\0`),r=t.slice(0,n),i=t.slice(n+1);e.hasEdge(r,i)&&e.removeEdge(r,i)}),a.forEach(({clusterId:t,subgraph:n,bounds:r,removedNodes:i,removedEdges:a})=>{let o=e.node(t),s=o?.x??0,c=o?.y??0,l=(r.minX+r.maxX)/2,u=(r.minY+r.maxY)/2;i.forEach(({id:t,node:n,parent:r})=>{e.setNode(t,n),r!==void 0&&e.setParent(t,r)}),a.forEach(({edge:t,label:n})=>{e.setEdge(t,n)}),n.nodes().forEach(r=>{if(r===t)return;let i=n.node(r),a=e.node(r);a&&i&&typeof i.x==`number`&&typeof i.y==`number`&&(a.x=s+(i.x-l),a.y=c+(i.y-u))}),delete o._dagreClusterSubgraph}),r.forEach(t=>{let n=e.node(t),r=i[t];if(n&&n.rankdir&&n._dagreClusterSubgraph&&r){let i=n._dagreClusterSubgraph,a=n.x??0,o=n.y??0,s=(r.minX+r.maxX)/2,c=(r.minY+r.maxY)/2;i.nodes().forEach(n=>{if(n===t)return;let r=i.node(n),l=e.node(n);if(l&&r&&typeof r.x==`number`&&typeof r.y==`number`){let e=r.x-s,t=r.y-c;l.x=a+e,l.y=o+t}}),delete n._dagreClusterSubgraph}})}function Lh(e,t,n,r=null){var i,a;let o=n?.useDynamic!==!1,s=o&&(i=r?.graph)!=null?i:null,c=o&&(a=r?.rawNodes)!=null?a:null;t(` makeSpaceForEdgeLabels`,()=>Jh(e)),t(` removeSelfEdges`,()=>rg(e)),t(` acyclic`,()=>Xp(e,s)),t(` nestingGraph.run`,()=>Pm(e)),t(` rank`,()=>Tm(_p(e))),t(` injectEdgeLabelProxies`,()=>Yh(e)),t(` removeEmptyRanks`,()=>xp(e)),t(` nestingGraph.cleanup`,()=>Rm(e)),t(` normalizeRanks`,()=>bp(e)),t(` assignRankMinMax`,()=>Xh(e)),t(` removeEdgeLabelProxies`,()=>Zh(e)),t(` normalize.run`,()=>em(e)),t(` parentDummyChains`,()=>Am(e)),t(` addBorderSegments`,()=>zm(e)),t(` order`,()=>fh(e,n,c)),t(` insertSelfEdges`,()=>ig(e)),t(` adjustCoordinateSystem`,()=>Hm(e)),t(` position`,()=>jh(e,n.corePath)),t(` positionSelfEdges`,()=>ag(e));let l=JSON.parse(JSON.stringify(e._nodes));return t(` removeBorderNodes`,()=>ng(e)),t(` normalize.undo`,()=>nm(e)),t(` fixupEdgeLabelCoords`,()=>eg(e)),t(` undoCoordinateSystem`,()=>Um(e)),t(` translateGraph`,()=>Qh(e)),t(` assignNodeIntersects`,()=>$h(e)),t(` reversePoints`,()=>tg(e)),t(` acyclic.undo`,()=>Qp(e)),{graph:e,rawNodes:l}}function Rh(e,t){e.nodes().forEach(n=>{let r=e.node(n),i=t.node(n);r&&(r.x=i.x,r.y=i.y,r.order=i.order,r.rank=i.rank,t.children(n).length&&(r.width=i.width,r.height=i.height))}),e.edges().forEach(n=>{let r=e.edge(n),i=t.edge(n);r.points=i.points,Object.hasOwn(i,`x`)&&(r.x=i.x,r.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var zh=[`nodesep`,`edgesep`,`ranksep`,`marginx`,`marginy`],Bh={ranksep:50,edgesep:20,nodesep:50,rankdir:`TB`,rankalign:`center`},Vh=[`acyclicer`,`ranker`,`rankdir`,`align`,`rankalign`],Hh=[`width`,`height`,`rank`],Uh={width:0,height:0},Wh=[`minlen`,`weight`,`width`,`height`,`labeloffset`],Gh={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:`r`},Kh=[`labelpos`];function qh(e){let t=new mp({multigraph:!0,compound:!0}),n=sg(e.graph());return t.setGraph(Object.assign({},Bh,og(n,zh),Np(n,Vh))),e.nodes().forEach(n=>{let r=og(sg(e.node(n)),Hh);Object.keys(Uh).forEach(e=>{r[e]===void 0&&(r[e]=Uh[e])}),t.setNode(n,r);let i=e.parent(n);i!==void 0&&t.setParent(n,i)}),e.edges().forEach(n=>{let r=sg(e.edge(n));t.setEdge(n,Object.assign({},Gh,og(r,Wh),Np(r,Kh)))}),t}function Jh(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,(r.labelpos??`r`).toLowerCase()!==`c`&&(t.rankdir===`TB`||t.rankdir===`BT`?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Yh(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v);hp(e,`edge-proxy`,{rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t},`_ep`)}})}function Xh(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Zh(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy===`edge-proxy`){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}function Qh(e){let t=1/0,n=0,r=1/0,i=0,a=e.graph(),o=a.marginx||0,s=a.marginy||0;function c(e){let a=e.x,o=e.y,s=e.width,c=e.height;t=Math.min(t,a-s/2),n=Math.max(n,a+s/2),r=Math.min(r,o-c/2),i=Math.max(i,o+c/2)}e.nodes().forEach(t=>c(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);Object.hasOwn(n,`x`)&&c(n)}),t-=o,r-=s,e.nodes().forEach(n=>{let i=e.node(n);i.x-=t,i.y-=r}),e.edges().forEach(n=>{let i=e.edge(n);i.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(i,`x`)&&(i.x-=t),Object.hasOwn(i,`y`)&&(i.y-=r)}),a.width=n-t+o,a.height=i-r+s}function $h(e){e.edges().forEach(t=>{if(t.v===t.w)return;let n=e.edge(t),r=e.node(t.v),i=e.node(t.w),a,o;n.points?(a=n.points[0],o=n.points[n.points.length-1]):(n.points=[],a=i,o=r),n.points.unshift(vp(r,a)),n.points.push(vp(i,o))})}function eg(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,`x`))switch((n.labelpos===`l`||n.labelpos===`r`)&&(n.width-=n.labeloffset),n.labelpos){case`l`:n.x-=n.width/2+n.labeloffset;break;case`r`:n.x+=n.width/2+n.labeloffset}})}function tg(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function ng(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),i=e.node(n.borderBottom),a=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-a.x),n.height=Math.abs(i.y-r.y),n.x=a.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy===`border`&&e.removeNode(t)})}function rg(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||=[],n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function ig(e){yp(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let i=e.node(t);typeof i.rank!=`number`&&(i.rank=0),i.order=r+n,(i.selfEdges||[]).forEach(t=>{hp(e,`selfedge`,{width:t.label.width,height:t.label.height,rank:i.rank,order:r+ ++n,e:t.e,edgeLabel:t.label},`_se`),(!Array.isArray(t.label.points)||t.label.points.length!==7)&&(t.label.points=[{x:0,y:-10},{x:0,y:-10},{x:0,y:0},{x:0,y:10},{x:0,y:10},{x:0,y:0},{x:0,y:0}])}),delete i.selfEdges})})}function ag(e){e.nodes().forEach(t=>{let n=e.node(t),r=e=>typeof e==`number`&&isFinite(e);if(n.dummy===`selfedge`){let i=n,a=e.node(i.e.v),o=r(a?.x)?a.x:0,s=r(a?.y)?a.y:0,c=r(a?.width)?a.width:0,l=r(a?.height)?a.height:0,u=r(n.x)?n.x:o,d=r(n.y)?n.y:s,f=c/2,p=l/2;i.edgeLabel.points=[{x:u+f,y:d-p},{x:u+f,y:d-p},{x:u,y:d},{x:u-f,y:d+p},{x:u-f,y:d+p},{x:u,y:d},{x:u,y:d}],i.edgeLabel.x=u,i.edgeLabel.y=d,e.setEdge(i.e,i.edgeLabel),e.removeNode(t)}else n&&Array.isArray(n.selfEdges)&&n.selfEdges.forEach(e=>{if(!Array.isArray(e.label.points)||e.label.points.length!==7){let t=r(n.x)?n.x:0,i=r(n.y)?n.y:0,a=r(n.width)?n.width:0,o=r(n.height)?n.height:0,s=a/2,c=o/2;e.label.points=[{x:t+s,y:i-c},{x:t+s,y:i-c},{x:t,y:i},{x:t-s,y:i+c},{x:t-s,y:i+c},{x:t,y:i},{x:t,y:i}]}})})}function og(e,t){return Pp(Np(e,t),Number)}function sg(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{typeof e==`string`&&(e=e.toLowerCase()),t[e]=n}),t}function cg(e){let t=yp(e),n=new mp({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{n.setNode(t,{label:t}),n.setParent(t,`layer`+e.node(t).rank)}),e.edges().forEach(e=>n.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let r=`layer`+t;n.setNode(r,{rank:`same`}),e.reduce((e,t)=>(n.setEdge(e,t,{style:`invis`}),t))}),n}var lg={graphlib:kf,version:Rp,layout:Ph,debug:cg,util:{time:Op,notime:kp}},ug=14,dg=8,fg=38,pg=4,mg=e=>e?.split(`/`).pop()?.replace(/\.md$/i,``);function hg(e,t=e=>e){switch(e.runs){case`manager`:return`manager`;case`person`:return`person`;case`new-session`:return`new session`;case`continue`:return e.continues?`continues ${t(e.continues)}`:`continues a session`;default:return e.kind===`person`?`person`:null}}var gg={start:`at the start`,done:`when done`,brief:`as the brief says`};function _g(e,t){return{done:`done`,owner:`✗ ${mg(e.brief)??(e.runs===`manager`?`the manager`:`the session`)} fixes`,report:`report`,"ask-manager":`ask the manager`}[t]}function vg(e,t){let n=[`subagent`,t.model,t.brief&&`${mg(t.brief)}.md`].filter(Boolean).join(` · `),r=t.outcomes?.length?t.outcomes.map(t=>`${vf(t)} → ${_g(e,t.to)}`).join(` · `):null;return{head:`↳ ${gg[t.when??`done`]}: ${t.title}`,detail:n,outcomes:r,note:t.kind===`check`?`the author reads this`:null}}function yg(e){let t=e.substeps??[],n=e.outcomes?.length?pg+18*e.outcomes.length:0;if(!t.length)return{width:210,height:78+n};let r=e=>Math.max(1,Math.ceil(e.length/fg));return{width:260,height:84+t.reduce((t,n)=>{let i=vg(e,n);return t+dg+ug*(r(i.head)+r(i.detail)+(i.outcomes?r(i.outcomes):0)+ +!!i.note)},0)+n}}var bg=e=>vf(e);function xg(e){let t=(t,n)=>{let r=new Set([t]),i=[t];for(;i.length;){let t=i.pop();for(let a of e)if(a.from===t){if(a.to===n)return!0;r.has(a.to)||(r.add(a.to),i.push(a.to))}}return!1};return new Set(e.filter(e=>e.index>0&&!e.times&&e.from!==e.to&&t(e.to,e.from)))}var Sg=e=>Math.ceil(e.length*6.3)+12;function Cg(e){let t={...e,blocks:e.blocks.filter((t,n)=>e.blocks.findIndex(e=>e.id===t.id)===n)},n=new lg.graphlib.Graph({multigraph:!0});n.setGraph({rankdir:`TB`,nodesep:70,edgesep:20,ranksep:56,marginx:10,marginy:10});let r=new Set(t.blocks.map(e=>e.id)),i=new Map(t.blocks.map(e=>[e.id,yg(e)]));for(let e of t.blocks)n.setNode(e.id,{...i.get(e.id)});let a=xf(t).filter(e=>r.has(e.from)&&r.has(e.to)),o=t.start&&r.has(t.start)?t.start:t.blocks[0].id,s=xg(a),c=a.map((e,t)=>{let n=e.times?`counted`:s.has(e)?`back`:`way`;return{from:e.from,to:e.to,word:e.word,index:e.index,...e.times?{times:e.times}:{},kind:n,id:`${e.from}-${e.index}-${e.to}-${t}`,text:bg(e),back:s.has(e)}}),l=e=>e.back?JSON.stringify([e.to,e.from,!0]):JSON.stringify([e.from,e.to,!1]);for(let e of c){if(e.from===e.to)continue;let[t,r]=JSON.parse(l(e));n.hasEdge(t,r,l(e))||n.setEdge(t,r,{},l(e))}try{lg.layout(n)}catch(e){console.warn(`Workflow layout failed; the blocks are stacked instead.`,e);let r=10;for(let e of t.blocks){let{width:t,height:a}=i.get(e.id);n.setNode(e.id,{width:t,height:a,x:10+t/2,y:r+a/2}),r+=a+56}for(let e of n.edges())n.setEdge(e,{})}let u=new Set(t.blocks.filter(e=>{let t=n.node(e.id),{width:r,height:a}=i.get(e.id);return e.at&&(Math.abs(e.at.x-(t.x-r/2))>1||Math.abs(e.at.y-(t.y-a/2))>1)}).map(e=>e.id)),d=t.blocks.flatMap((e,t)=>e.runs===`continue`&&e.continues&&e.continues!==e.id&&r.has(e.continues)?[{id:`continue-${e.continues}-${e.id}-${t}`,from:e.continues,to:e.id,kind:`continue`,text:`same session`,route:null}]:[]);return{start:o,blocks:t.blocks.map(e=>{let t=n.node(e.id),{width:r,height:a}=i.get(e.id);return{block:e,x:e.at?.x??t.x-r/2,y:e.at?.y??t.y-a/2,width:r,height:a}}),arrows:[...c.map(({back:e,...t})=>{if(t.from===t.to||u.has(t.from)||u.has(t.to))return{...t,route:null};let r=((e?n.edge(t.to,t.from,l({...t,back:!0})):n.edge(t.from,t.to,l({...t,back:!1})))?.points??[]).map(e=>({x:e.x,y:e.y}));return e&&r.reverse(),{...t,route:r.length>=2?r:null}}),...d]}}var wg=12;function Tg(e,t,n,r){if(n.length<2)return[e,...n];let i=n[0],a=n[1].y>i.y,o=1;if(a&&r!==void 0)for(;o<n.length-1&&n[o].y<=r+wg;)o++;let s=n[o],c=a&&r!==void 0?Math.max((i.y+s.y)/2,Math.min(r+wg,Math.max(r+3,s.y-6))):(i.y+s.y)/2,l=e.x+t;return[e,{x:l,y:e.y},{x:l,y:c},{x:s.x,y:c},...n.slice(o)]}function Eg(e,t=10){if(e.length<2)return``;let n=e=>Math.round(e*10)/10,r=`M ${n(e[0].x)} ${n(e[0].y)}`;for(let i=1;i<e.length-1;i++){let[a,o,s]=[e[i-1],e[i],e[i+1]],c=Math.min(t,Math.hypot(o.x-a.x,o.y-a.y)/2,Math.hypot(s.x-o.x,s.y-o.y)/2),l=(e,t)=>{let n=Math.hypot(t.x-e.x,t.y-e.y)||1;return{x:e.x+(t.x-e.x)/n*c,y:e.y+(t.y-e.y)/n*c}},u=l(o,a),d=l(o,s);r+=` L ${n(u.x)} ${n(u.y)} Q ${n(o.x)} ${n(o.y)} ${n(d.x)} ${n(d.y)}`}let i=e[e.length-1];return`${r} L ${n(i.x)} ${n(i.y)}`}function Dg(e){let t={way:0,counted:1,back:2,continue:3},n=e.arrows.filter(e=>e.kind!==`continue`).sort((e,n)=>t[e.kind]-t[n.kind]),r=[],i=[e.start];for(;i.length;){let e=i.shift();if(!r.includes(e)){r.push(e);for(let t of n)t.from===e&&i.push(t.to)}}let a=e=>r.includes(e)?r.indexOf(e):r.length;return[...e.blocks].sort((e,t)=>e.y-t.y||a(e.block.id)-a(t.block.id)||e.x-t.x)}function Og(e,t){let n=new Map,r=[...t].sort((e,t)=>e.size.width*e.size.height-t.size.width*t.size.height);for(let t of e){let e=t.x+t.width/2,i=t.y+t.height/2,a=r.find(t=>e>=t.at.x&&e<=t.at.x+t.size.width&&i>=t.at.y&&i<=t.at.y+t.size.height);a&&n.set(t.block.id,a)}return n}function kg(e,t){let n=t=>e.blocks.find(e=>e.block.id===t)?.block.title??t,r=(e.blocks.find(e=>e.block.id===t)?.block.outcomes??[]).filter(e=>e.end).map(e=>`${vf(e)} → ends the flow`);return[...e.arrows.filter(e=>e.from===t&&e.kind!==`continue`).map(e=>`${e.text} → ${n(e.to)}`),...r]}var Ag={work:`Work`,check:`Check`,person:`Person`,fork:`Fork`,join:`Join`,timer:`Timer`,flow:`Run flow`};function jg(e,t){if(e.kind!==`flow`)return null;if(e.flow===void 0)return`runs no flow yet`;let n=t?.(e.flow);return n===void 0?`runs "${e.flow}" (not a flow here)`:`runs ${n}`}function Mg(e,t){let n=[hg(e,t),e.model,e.profile&&`profile ${e.profile}`,e.ask&&(e.ask===`review`?`asks for a review`:`asks a question`),Ng(e)].filter(Boolean);return n.length?n.join(` · `):null}function Ng(e){return e.timer?`clock`in e.timer?e.timer.clock:`every ${e.timer.every} ${e.timer.of}`:null}var Pg=.7;function Fg(e,t,n,r,{padding:i=.15,minZoom:a=Pg}={}){if(!e.length||n<=0||r<=0)return{fit:!0};let o=Math.min(...e.map(e=>e.x)),s=Math.min(...e.map(e=>e.y)),c=Math.max(...e.map(e=>e.x+(e.width??210)))-o,l=Math.max(...e.map(e=>e.y+(e.height??78)))-s;if(Math.min(n/(c*(1+i)),r/(l*(1+i)))>=a)return{fit:!0};let u=a,d=t??{x:o,y:s};return{fit:!1,zoom:u,x:c*u*(1+i)<=n?(n-c*u)/2-o*u:n/2-(d.x+((`width`in d?d.width:void 0)??210)/2)*u,y:32-d.y*u}}function Ig(e,t,n=0){if(t===`t`)return{x:e.x+e.width/2,y:e.y};if(t?.startsWith(`l`))return{x:e.x,y:e.y+22};if(t?.startsWith(`r`))return{x:e.x+e.width,y:e.y+22};let r=/^o(\d+)$/.exec(t??``);return r?{x:e.x+e.width,y:e.y+e.height-6-18*(n-Number(r[1]))+9}:{x:e.x+e.width/2,y:e.y+e.height}}function Lg(e,t,n){return[`o${t}`,e===`back`?`rt`:`t`,16+10*Math.max(0,n-1-t)]}var Rg=18,zg=4;function Bg(e,t){let n=t.flatMap(t=>{if(!t.text)return[];let n=e.get(t.source),r=e.get(t.target);if(!n||!r)return[];let i=Ig(n,t.sourceHandle,t.pins),a=Ig(r,t.targetHandle),o={x:(i.x+a.x)/2,y:(i.y+a.y)/2};return[{id:t.id,x:o.x,y:o.y,w:Sg(t.text),h:Rg}]}).sort((e,t)=>e.y-t.y||e.x-t.x),r=[],i=[...e.values()].map(e=>({id:``,x:e.x+e.width/2,y:e.y+e.height/2,w:e.width,h:e.height})),a=(e,t)=>Math.abs(e.x-t.x)<(e.w+t.w)/2+zg&&Math.abs(e.y-t.y)<(e.h+t.h)/2+zg;for(let e of n){let t={...e};for(let e=0;e<50;e++){let e=r.find(e=>a(t,e))??i.find(e=>a(t,e));if(!e)break;t.y=e.y+(e.h+t.h)/2+zg}r.push(t)}return new Map(r.map(e=>[e.id,{x:e.x,y:e.y}]))}function Vg(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function Hg(e,t=`|`){return e.map(e=>p_(e)).join(t)}function Ug(e,t){return typeof t==`bigint`?t.toString():t}var Wg=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function Gg(e){return new Wg(e)}function Kg(e){return e==null}function qg(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function Jg(e,t){let n=e/t,r=Math.round(n),i=4*2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}function Yg(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Xg(e){let t=Object.getOwnPropertyDescriptor(e,`shape`);return t?.get?t.get.raw:t?.value}function Zg(e){return Xg(e._zod.def)??e._zod.def.shape}function Qg(e,t,n){Object.defineProperty(e,t,{get(){let e=n();return Yg(this,t,e),e},enumerable:!0,configurable:!0})}function $g(e,t,n){t in e?Yg(e,t,n):e[t]=n}function e_(e,t,n,r){let i=Zg(t);for(let a of n){let n=Object.getOwnPropertyDescriptor(i,a);n.enumerable&&(n.get?Qg(e,a,()=>{let e=t._zod.def.shape[a];return r?r(e,a):e}):$g(e,a,r?r(n.value,a):n.value))}}function t_(e,t){for(let n of Reflect.ownKeys(t)){let r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?Qg(e,n,()=>t[n]):$g(e,n,r.value))}}function n_(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function r_(e){return JSON.stringify(e)}function i_(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}var a_=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function o_(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var s_=Gg(()=>{if(nv.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function c_(e){if(o_(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return o_(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function l_(e){return c_(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var u_=new Set([`string`,`number`,`symbol`]);function d_(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function f_(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function q(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function p_(e){return typeof e==`bigint`?e.toString()+`n`:typeof e==`string`?`"${e}"`:`${e}`}function m_(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}var h_={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},g_={int64:[BigInt(`-9223372036854775808`),BigInt(`9223372036854775807`)],uint64:[BigInt(0),BigInt(`18446744073709551615`)]};function __(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);let i={};return e_(i,e,v_(e,t)),f_(e,n_(n,{shape:i,checks:[]}))}function v_(e,t){let n=Zg(e),r=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(n,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&r.push(e)}return r}function y_(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);let i=new Set(v_(e,t)),a={};return e_(a,e,Reflect.ownKeys(Zg(e)).filter(e=>!i.has(e))),f_(e,n_(n,{shape:a,checks:[]}))}function b_(e,t){if(!c_(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=Zg(e);for(let e of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return f_(e,n_(e._zod.def,{shape:x_(e,t)}))}function x_(e,t){let n={};return e_(n,e,Reflect.ownKeys(Zg(e))),t_(n,t),n}function S_(e,t){if(!c_(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return f_(e,n_(e._zod.def,{shape:x_(e,t)}))}function C_(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);let n={};return e_(n,e,Reflect.ownKeys(Zg(e))),e_(n,t,Reflect.ownKeys(Zg(t))),f_(e,n_(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function w_(e,t,n,r=`partial`){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${r}() cannot be used on object schemas containing refinements`);let a=n?new Set(v_(t,n)):void 0,o={};return e_(o,t,Reflect.ownKeys(Zg(t)),e&&((t,n)=>a&&!a.has(n)?t:new e({type:`optional`,innerType:t}))),f_(t,n_(t._zod.def,{shape:o,checks:[]}))}function T_(e,t,n){let r=n?new Set(v_(t,n)):void 0,i={};return e_(i,t,Reflect.ownKeys(Zg(t)),(t,n)=>r&&!r.has(n)?t:new e({type:`nonoptional`,innerType:t})),f_(t,n_(t._zod.def,{shape:i}))}function E_(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function D_(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function O_(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function k_(e){return typeof e==`string`?e:e?.message}function A_(e){let t=[];for(let n of e??[]){let e=n._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let r=e.maximum??e.length??e.size;r>=0&&t.push([r,n])}return t}function j_(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function M_(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:k_(e.inst?._zod.def?.error?.(e))??k_(a?.(e))??k_(t?.error?.(e))??k_(n.customError?.(e))??k_(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t!==`inst`&&t!==`schema`&&t!==`continue`&&t!==`input`&&t!==`__proto__`&&(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}var N_=/[\uD800-\uDBFF]/;function P_(e){let t=e.length;if(!N_.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function F_(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function I_(e){let t=typeof e;switch(t){case`number`:return Number.isNaN(e)?`nan`:`number`;case`object`:{if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=e;if(t&&Object.getPrototypeOf(t)!==Object.prototype&&`constructor`in t&&t.constructor)return t.constructor.name}}return t}function L_(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function R_(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):H_(e,n,r.value)}}function z_(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function B_(e,t,n){return z_(e,t,n,!1)}function V_(e,t){for(let n in e){let r=e[n];Object.defineProperty(t,n,{configurable:!0,enumerable:!0,get(){return z_(this,n,r(this))},set(e){z_(this,n,e)}})}return t}function H_(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:z_(this,t,n.bind(this))},set(e){z_(this,t,e)}})}function U_(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}var W_,G_=!1,K_={configurable:!0,get(){G_=!0}};function J(e,t,n){let r=Object.getPrototypeOf(e._zod);t in r&&W_!==e._zod?W_=void 0:(W_=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,K_);let e=G_;G_=!1;try{let r=n(this);return G_?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),G_||=e,r}catch(n){throw delete this[t],G_||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}}))}function q_(e,t,n,r){let i=U_(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}var J_=`~constantCatch`;function Y_(e){let t=()=>e;return t[J_]=!0,t}var X_,Z_={value:void 0,enumerable:!1},Q_=`captureStackTrace`in Error?Error:null;function $_(e){let t=Q_;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return Q_=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function Y(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=new Set}a.prototype=i;let o=n,s=o&&new WeakSet;function c(n,r){if(!n._zod){Z_.value=new a(r);try{Object.defineProperty(n,"_zod",Z_)}finally{Z_.value=void 0}}else if(n._zod.traits.has(e))return;if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),R_(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,"name",{value:e});function d(e){let t=r?.Parent?$_(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,"init",{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,"name",{value:e}),d}var ev=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},tv=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(X_=globalThis).__zod_globalConfig??(X_.__zod_globalConfig={});var nv=globalThis.__zod_globalConfig;function rv(e){return e&&Object.assign(nv,e),nv}function iv(){let e=this._zod;return e.message??=JSON.stringify(e.def,Ug,2),e.message}function av(e){this._zod.message=e}var ov={get:iv,set:av,enumerable:!0,configurable:!0},sv={value:void 0,enumerable:!1},cv=new WeakSet([Object.prototype,Error.prototype]),lv=(e,t)=>{e.name=`$ZodError`,sv.value=t,Object.defineProperty(e,"issues",sv),sv.value=void 0,Object.defineProperty(e,"message",ov);let n=Object.getPrototypeOf(e);cv.has(n)||(cv.add(n),Object.defineProperty(n,"toString",{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0})}}))},uv=Y(`$ZodError`,lv);Y(`$ZodError`,lv,void 0,{Parent:Error});function dv(e,t,n){return Object.prototype.hasOwnProperty.call(e,t)||(t===`__proto__`?Object.defineProperty(e,t,{value:n(),writable:!0,enumerable:!0,configurable:!0}):e[t]=n()),e[t]}function fv(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?dv(n,i.path[0],()=>[]).push(t(i)):r.push(t(i));return{formErrors:r,fieldErrors:n}}function pv(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i],o=i===e.length-1;if(n===`_errors`){o&&r._errors.push(t(a)),i++;continue}Object.prototype.hasOwnProperty.call(r,n)||Object.defineProperty(r,n,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let s=r[n];o&&s._errors.push(t(a)),r=s,i++}}}};return r(e),n}function mv(e,t){return{callee:t?.callee??e,Err:t?.Err}}var hv=e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new ev;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>M_(e,o,rv())));throw a_(n,a?.callee??t),n}return s.value};return t},gv=e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>M_(e,o,rv())));throw a_(n,a?.callee??t),n}return s.value};return t},_v=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new ev;return a.issues.length?vv(e,a.issues,i):{success:!0,data:a.value}};function vv(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>M_(e,n,rv()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}var yv=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?vv(e,a.issues,i):{success:!0,data:a.value}},bv=Symbol.for(`zod.compile.invalid`),xv=Symbol.for(`zod.compile.fallback`),Sv=((e,t,n)=>{let r=e._zod.bag.validator;if(r!==void 0){if(r(t)!==bv)return!0;if(r.definite===!0&&n===void 0)return!1}return Cv(e,t,n)});function Cv(e,t,n){let r=n?{...n,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},i=e._zod.bag.fallbackRun,a;if(i?(r[xv]=!0,a=i({value:t,issues:[]},r)):a=e._zod.run({value:t,issues:[]},r),a instanceof Promise)throw new ev;return a.issues.length===0}var wv=async(e,t,n)=>{let r=n?{...n,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},i=e._zod.run({value:t,issues:[]},r);return i instanceof Promise&&(i=await i),i.issues.length===0},Tv=e=>{let t=hv(e),n=(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return t(e,r,o,mv(n,a))};return n},Ev=e=>{let t=hv(e),n=(e,r,i,a)=>t(e,r,i,mv(n,a));return n},Dv=e=>{let t=gv(e),n=async(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return await t(e,r,o,mv(n,a))};return n},Ov=e=>{let t=gv(e),n=async(e,r,i,a)=>await t(e,r,i,mv(n,a));return n},kv=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return _v(e)(t,n,i)},Av=e=>(t,n,r)=>_v(e)(t,n,r),jv=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return yv(e)(t,n,i)},Mv=e=>async(t,n,r)=>yv(e)(t,n,r),Nv=/^[cC][0-9a-z]{6,}$/,Pv=/^[0-9a-z]+$/,Fv=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,Iv=/^[0-9a-vA-V]{20}$/,Lv=/^[A-Za-z0-9]{27}$/,Rv=/^[a-zA-Z0-9_-]{21}$/;function zv(e){return RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var Bv=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Vv=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Hv=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Uv=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Wv=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;function Gv(){return new RegExp(Wv,`u`)}var Kv=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,qv=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Jv=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Yv=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Xv=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Zv=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/,Qv=/^https?$/,$v=/^\+[1-9]\d{6,14}$/,ey=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;function ty(e){return RegExp(`^${e}$`)}var ny=ty(ey);function ry(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function iy(e){return RegExp(`^${ry(e)}$`)}function ay(e){let t=[`Z`];e.offset&&t.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let n=`${ry({precision:e.precision,seconds:!0})}(?:${t.join(`|`)})`,r=e.local?`${n}|${ry({precision:e.precision})}`:n;return RegExp(`^${ey}T(?:${r})$`)}var oy=/^[\s\S]{0,}$/,sy=/^-?\d+(?:\.\d+)?$/,cy=/^[^A-Z]*$/,ly=/^[^a-z]*$/,uy=Y(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),dy=e=>{let t=e.value;return!Kg(t)&&t.length!==void 0},fy={number:`number`,bigint:`bigint`,object:`date`},py=Y(`$ZodCheckLessThan`,(e,t)=>{uy.init(e,t);let n=fy[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:fy[typeof r.value]??n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),my=Y(`$ZodCheckGreaterThan`,(e,t)=>{uy.init(e,t);let n=fy[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:fy[typeof r.value]??n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),hy=Y(`$ZodCheckMultipleOf`,(e,t)=>{uy.init(e,t),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?t.value!==BigInt(0)&&n.value%t.value===BigInt(0):Jg(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),gy=Y(`$ZodCheckNumberFormat`,(e,t)=>{uy.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=h_[t.format];e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),_y=Y(`$ZodCheckMaxLength`,(e,t)=>{var n;uy.init(e,t),(n=e._zod.def).when??(n.when=dy),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>t.maximum?P_(r):i)<=t.maximum)return;let a=F_(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),vy=Y(`$ZodCheckMinLength`,(e,t)=>{var n;uy.init(e,t),(n=e._zod.def).when??(n.when=dy),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?P_(r):i)>=t.minimum)return;let a=F_(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),yy=Y(`$ZodCheckLengthEquals`,(e,t)=>{var n;uy.init(e,t),(n=e._zod.def).when??(n.when=dy),e._zod.check=n=>{let r=n.value,i=r.length,a=typeof r==`string`&&i>=t.length&&i<=t.length*2?P_(r):i;if(a===t.length)return;let o=F_(r),s=a>t.length;n.issues.push({origin:o,...s?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),by=Y(`$ZodCheckStringFormat`,(e,t)=>{var n,r;uy.init(e,t),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),xy=Y(`$ZodCheckRegex`,(e,t)=>{by.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Sy=Y(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=cy,by.init(e,t)}),Cy=Y(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=ly,by.init(e,t)}),wy=Y(`$ZodCheckIncludes`,(e,t)=>{uy.init(e,t);let n=d_(t.includes);t.pattern=new RegExp(typeof t.position==`number`?`^.{${t.position},}${n}`:n),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Ty=Y(`$ZodCheckStartsWith`,(e,t)=>{uy.init(e,t);let n=RegExp(`^${d_(t.prefix)}.*`);t.pattern??=n,e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Ey=Y(`$ZodCheckEndsWith`,(e,t)=>{uy.init(e,t);let n=RegExp(`.*${d_(t.suffix)}$`);t.pattern??=n,e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Dy=Y(`$ZodCheckOverwrite`,(e,t)=>{uy.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),Oy=class{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{--this.indent}}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
8
+ `).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.content??[``];return new e(...Object.keys(this.closed),`return function (${this.args.join(`, `)}) {\n${t.join(`
9
+ `)}\n};`)(...Object.values(this.closed))}},ky={major:4,minor:6,patch:7},X=Y(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=ky;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=E_(t),a;for(let o of n){if(o._zod.def.when){if(D_(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new ev;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(j_(t.issues,n,e),i||=E_(t,n))});else{if(t.issues.length===n)continue;j_(t.issues,n,e),i||=E_(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(E_(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new ev;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new ev;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get"~standard"(){return B_(this,`~standard`,My(this))},set"~standard"(e){z_(this,`~standard`,e)}}),Ay=(e,t)=>e.issues.length?{issues:e.issues.map(e=>M_(e,t,rv()))}:{value:e.value};async function jy(e,t){let n={async:!0};return Ay(await e._zod.run({value:t,issues:[]},n),n)}function My(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return Ay(r,n)}catch{}return jy(e,t)},vendor:`zod`,version:1}}var Ny=Y(`$ZodString`,(e,t)=>{X.init(e,t),e._zod.pattern=t.pattern??oy,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),Z=Y(`$ZodStringFormat`,(e,t)=>{by.init(e,t),Ny.init(e,t)}),Py=Y(`$ZodGUID`,(e,t)=>{t.pattern??=Vv,Z.init(e,t)}),Fy=Y(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=Hv(e)}else t.pattern??=Hv();Z.init(e,t)}),Iy=Y(`$ZodEmail`,(e,t)=>{t.pattern??=Uv,Z.init(e,t)});function Ly(e){try{return typeof URL<`u`&&typeof URL.canParse==`function`?URL.canParse(e):(new URL(e),!0)}catch{return!1}}function Ry(e,t){return!(`normalize`in t)&&!(`hostname`in t)&&!(`protocol`in t)?Ly(e)||2:zy(e,t)}function zy(e,t){if(!t.normalize&&t.protocol?.source===Qv.source&&!/^https?:\/\//i.test(e))return 1;try{if(typeof URL<`u`){let t=URL;if(typeof t.parse==`function`)return t.parse(e)??2}return new URL(e)}catch{return 2}}var By=/[\t\n\r]/g;function Vy(e){return e.replace(By,``)}function Hy(e,t){return t.lastIndex=0,t.test(e.hostname)}function Uy(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(`:`)?e.protocol.slice(0,-1):e.protocol)}var Wy=Y(`$ZodURL`,(e,t)=>{Z.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=Ry(r,t);if(i===1){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}if(i===2){n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort});return}if(i===!0){n.value=Vy(r);return}t.hostname&&!Hy(i,t.hostname)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort}),t.protocol&&!Uy(i,t.protocol)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort}),n.value=t.normalize?i.href:Vy(r);return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Gy=Y(`$ZodEmoji`,(e,t)=>{t.pattern??=Gv(),Z.init(e,t)}),Ky=Y(`$ZodNanoID`,(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??=t.length===void 0?Rv:zv(t.length),Z.init(e,t)}),qy=Y(`$ZodCUID`,(e,t)=>{t.pattern??=Nv,Z.init(e,t)}),Jy=Y(`$ZodCUID2`,(e,t)=>{t.pattern??=Pv,Z.init(e,t)}),Yy=Y(`$ZodULID`,(e,t)=>{t.pattern??=Fv,Z.init(e,t)}),Xy=Y(`$ZodXID`,(e,t)=>{t.pattern??=Iv,Z.init(e,t)}),Zy=Y(`$ZodKSUID`,(e,t)=>{t.pattern??=Lv,Z.init(e,t)}),Qy=Y(`$ZodISODateTime`,(e,t)=>{t.pattern??=ay(t),Z.init(e,t)}),$y=Y(`$ZodISODate`,(e,t)=>{t.pattern??=ny,Z.init(e,t)}),eb=Y(`$ZodISOTime`,(e,t)=>{t.pattern??=iy(t),Z.init(e,t)}),tb=Y(`$ZodISODuration`,(e,t)=>{t.pattern??=Bv,Z.init(e,t)}),nb=Y(`$ZodIPv4`,(e,t)=>{t.pattern??=Kv,Z.init(e,t)}),rb=/^[0-9a-fA-F:.]+$/;function ib(e){return rb.test(e)?Ly(`http://[${e}]`):!1}var ab=Y(`$ZodIPv6`,(e,t)=>{t.pattern??=qv,Z.init(e,t),e._zod.check=n=>{ib(n.value)||n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}),ob=Y(`$ZodCIDRv4`,(e,t)=>{t.pattern??=Jv,Z.init(e,t)});function sb(e){let t=e.split(`/`);if(t.length!==2)return!1;let[n,r]=t;if(!r)return!1;let i=Number(r);return`${i}`!==r||i<0||i>128?!1:ib(n)}var cb=Y(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Yv,Z.init(e,t),e._zod.check=n=>{sb(n.value)||n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}});function lb(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}var ub=/^[0-9a-zA-Z+/]*={0,2}$/,db=Y(`$ZodBase64`,(e,t)=>{t.pattern??=ub,Z.init(e,t),e._zod.check=n=>{lb(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}}),fb=/^[A-Za-z0-9_-]*$/;function pb(e){if(!fb.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return lb(t.padEnd(Math.ceil(t.length/4)*4,`=`))}var mb=Y(`$ZodBase64URL`,(e,t)=>{t.pattern??=fb,Z.init(e,t),e._zod.check=n=>{pb(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),hb=Y(`$ZodE164`,(e,t)=>{t.pattern??=$v,Z.init(e,t)});function gb(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}var _b=Y(`$ZodJWT`,(e,t)=>{Z.init(e,t),e._zod.check=n=>{gb(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),vb=Y(`$ZodNumber`,(e,t)=>{X.init(e,t),e._zod.pattern=sy,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),yb=Y(`$ZodNumberFormat`,(e,t)=>{gy.init(e,t),vb.init(e,t)}),bb=Y(`$ZodUnknown`,(e,t)=>{X.init(e,t),e._zod.parse=e=>e}),xb=Y(`$ZodNever`,(e,t)=>{X.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Sb(e,t){let n=A_(e._zod.def.checks);if(!n.length)return;let r=Math.min(...n.map(e=>e[0])),i=e._zod.parse;e._zod.parse=(n,a)=>{let o=t(n.value);if(o>r&&!a?.skipChecks&&a?.direction!==`backward`){for(let[t,r]of A_(e._zod.def.checks))if(o>t&&r._zod.def.when(n)){let t=n.issues.length;return r._zod.check(n),n.issues[t].continue=!1,j_(n.issues,t,e),n}}return i(n,a)}}var Cb=e=>Array.isArray(e)?e.length:-1;function wb(e,t,n){e.issues.length&&t.issues.push(...O_(n,e.issues)),t.value[n]=e.value}var Tb=Y(`$ZodArray`,(e,t)=>{X.init(e,t);let n=nv.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[],s=i?.abortEarly;for(let e=0;e<a.length;e++){let n=a[e],c=t.element._zod.run({value:n,issues:[]},i);if(c instanceof Promise)o.push(c.then(t=>wb(t,r,e)));else if(wb(c,r,e),s&&c.issues.length!==0&&E_(c))break}return o.length?Promise.all(o).then(()=>r):r},Sb(e,Cb)});function Eb(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(o||!s||i!==`optional`){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...O_(n,e.issues))}!o&&i===void 0?e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]}):e.value===void 0?(o||i===`defaulted`&&!s)&&(t.value[n]=void 0):t.value[n]=e.value}}var Db=[];function Ob(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:Db,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let a=m_(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function kb(e,t,n,r,i,a,o){let s=[],c=i.keySet,l=i.catchall._zod,u=l.def.type,d=l.optin,f=l.optout,p=0;for(let i in t){if(o&&n.issues.length!==p){if(E_(n,p))break;p=n.issues.length}if(c.has(i))continue;if(i===`__proto__`){u===`never`&&s.push(i);continue}if(u===`never`){s.push(i);continue}let a=l.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Eb(e,n,i,t,d,f))):Eb(a,n,i,t,d,f)}return s.length&&n.issues.push({code:`unrecognized_keys`,keys:s,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}var Ab=Y(`$ZodObject`,(e,t)=>{X.init(e,t);let n=Object.getOwnPropertyDescriptor(t,`shape`),r=n?.get?n.get.raw:t.shape??{};if(r){let e=()=>{let n={...r};return Object.defineProperty(t,"shape",{value:n}),e.raw=n,n};e.raw=r,Object.defineProperty(t,"shape",{get:e})}let i=Gg(()=>Ob(t));J(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||Yg(n,e,new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let a=o_,o=t.catchall,s,c=nv.memoizer;c?.attach(e),e._zod.parse=(t,n)=>{s??=i.value;let r=t.value;if(!a(r))return t.issues.push({expected:`object`,code:`invalid_type`,input:r,inst:e}),t;t.value=c?c.alloc(e,t,{},n):{};let l=[],u=s.shape,d=n?.abortEarly,f=t.issues.length;for(let e of s.allKeys){if(d&&t.issues.length!==f){if(E_(t,f))break;f=t.issues.length}if(e===`__proto__`)continue;let i=u[e],a=i._zod.optin,o=i._zod.optout,s=i._zod.run({value:r[e],issues:[]},n);s instanceof Promise?l.push(s.then(n=>Eb(n,t,e,r,a,o))):Eb(s,t,e,r,a,o)}return o?kb(l,r,t,n,i.value,e,d===!0):l.length?Promise.all(l).then(()=>t):t}}),jb=Y(`$ZodObjectJIT`,(e,t)=>{Ab.init(e,t);let n=e._zod.parse,r=Gg(()=>Ob(t)),i=nv.memoizer,a=t=>{let n=r.value,a=n.symbolKeys,o=new Oy([`payload`,`ctx`],{shape:t,inst:e,memo:i,syms:a}),s=e=>`shape[${e}]._zod.run({ value: input[${e}], issues: [] }, ctx)`,c=(e,t)=>`
10
+ let ${e}_ab = false;
11
+ for (let i = 0; i < ${e}.issues.length; i++) {
12
+ const iss = ${e}.issues[i];
13
+ iss.path = iss.path ? [${t}, ...iss.path] : [${t}];
14
+ payload.issues.push(iss);
15
+ if (iss.continue !== true) ${e}_ab = true;
16
+ }
17
+ if (${e}_ab && ctx && ctx.abortEarly) {
18
+ payload.value = newResult;
19
+ return payload;
20
+ }`;o.write(`const input = payload.value;`);let l=Object.create(null),u=0;for(let e of n.allKeys)l[e]=`key_${u++}`;o.write(i?`const newResult = memo.alloc(inst, payload, {}, ctx);`:`const newResult = {};`);for(let e of n.allKeys){if(e===`__proto__`)continue;let n=l[e],r=typeof e==`symbol`?`syms[${a.indexOf(e)}]`:r_(e),i=`${r} in input`,u=t[e],d=u?._zod?.optin,f=d!==void 0,p=u?._zod?.optout===`optional`;if(o.write(`const ${n} = ${s(r)};`),f&&p){let e=d===`optional`?`${n}_present`:`${n}.value !== undefined || ${n}_present`;o.write(`
21
+ const ${n}_present = ${i};
22
+ if (!${n}.issues.length || ${n}_present) {
23
+ if (${n}.issues.length) {${c(n,r)}
24
+ }
25
+
26
+ if (${e}) {
27
+ newResult[${r}] = ${n}.value;
28
+ }
29
+ }
30
+
31
+ `)}else f?(o.write(`
32
+ if (${n}.issues.length) {${c(n,r)}
33
+ }
34
+ `),d===`defaulted`?o.write(`newResult[${r}] = ${n}.value;`):o.write(`
35
+ if (${n}.value !== undefined || ${i}) {
36
+ newResult[${r}] = ${n}.value;
37
+ }
38
+ `)):o.write(`
39
+ const ${n}_present = ${i};
40
+ if (${n}.issues.length) {${c(n,r)}
41
+ }
42
+ if (!${n}_present && !${n}.issues.length) {
43
+ payload.issues.push({
44
+ code: "invalid_type",
45
+ expected: "nonoptional",
46
+ input: undefined,
47
+ path: [${r}]
48
+ });
49
+ if (ctx && ctx.abortEarly) {
50
+ payload.value = newResult;
51
+ return payload;
52
+ }
53
+ }
54
+
55
+ if (${n}_present) {
56
+ newResult[${r}] = ${n}.value;
57
+ }
58
+
59
+ `)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=o_,c=!nv.jitless,l=c&&s_.value,u=t.catchall,d;e._zod.parse=(i,f)=>{d??=r.value;let p=i.value;return s(p)?c&&l&&f?.async===!1&&f.jitless!==!0?(o||=a(t.shape),i=o(i,f),u?kb([],p,i,f,d,e,f?.abortEarly===!0):i):n(i,f):(i.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),i)}});function Mb(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!E_(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>M_(e,r,rv())))}),t)}var Nb=Y(`$ZodUnion`,(e,t)=>{X.init(e,t),J(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),J(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),J(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),J(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>qg(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>Mb(t,r,e,i)):Mb(o,r,e,i)}}),Pb=Y(`$ZodIntersection`,(e,t)=>{X.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Ib(e,t,n)):Ib(e,i,a)}});function Fb(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(c_(e)&&c_(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};Object.prototype.hasOwnProperty.call(i,`__proto__`)&&delete i.__proto__;for(let n of r){if(n===`__proto__`)continue;let r=Fb(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Fb(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Ib(e,t,n){let r=new Map,i,a=new Map,o=(e,t)=>{let n;if(e.code===`unrecognized_keys`&&!e.path?.length)i??=e,n=e.keys;else if(e.code===`invalid_key`&&e.origin===`record`&&e.path?.length===1){let t=String(e.path[0]);a.has(t)||a.set(t,e),n=[t]}else return!1;for(let e of n)r.has(e)||r.set(e,{}),r.get(e)[t]=!0;return!0};for(let n of t.issues)o(n,`l`)||e.issues.push(n);for(let t of n.issues)o(t,`r`)||e.issues.push(t);let s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length){let t=i?s.filter(e=>i.keys.includes(e)):[];t.length&&e.issues.push({...i,keys:t});for(let n of s)!t.includes(n)&&a.has(n)&&e.issues.push(a.get(n))}let c=Fb(t.value,n.value);if(!c.valid){if(E_(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}var Lb=Y(`$ZodEnum`,(e,t)=>{X.init(e,t);let n=Vg(t.entries),r=new Set(n);e._zod.values=r,J(e,`pattern`,e=>{let t=Vg(e.def.entries).filter(e=>u_.has(typeof e));return RegExp(t.length?`^(${t.map(e=>d_(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Rb=Y(`$ZodLiteral`,(e,t)=>{X.init(e,t);let n=new Set(t.values);e._zod.values=n,J(e,`pattern`,e=>{let t=e.def.values;return RegExp(t.length?`^(${t.map(e=>typeof e==`string`?d_(e):e?d_(e.toString()):String(e)).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),zb=Y(`$ZodTransform`,(e,t)=>{X.init(e,t),e._zod.optin=`optional`,nv.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new tv(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new ev;return n.value=i,n}});function Bb(e,t){return e.value=t.issues.length?void 0:t.value,e}var Vb=Y(`$ZodOptional`,(e,t)=>{X.init(e,t),J(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,J(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),J(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${qg(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>Bb(e,t)):Bb(e,r)}return t.innerType._zod.run(e,n)}}),Hb=Y(`$ZodExactOptional`,(e,t)=>{Vb.init(e,t),J(e,`values`,e=>e.def.innerType._zod.values),J(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Ub=Y(`$ZodNullable`,(e,t)=>{X.init(e,t),J(e,`optin`,e=>e.def.innerType._zod.optin),J(e,`optout`,e=>e.def.innerType._zod.optout),J(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${qg(t.source)}|null)$`):void 0}),J(e,`values`,e=>e.def.innerType._zod.values?new Set([...e.def.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Wb=Y(`$ZodDefault`,(e,t)=>{X.init(e,t),e._zod.optin=`defaulted`,J(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Gb(e,t)):Gb(r,t)}});function Gb(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var Kb=Y(`$ZodPrefault`,(e,t)=>{X.init(e,t),e._zod.optin=`defaulted`,J(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),qb=Y(`$ZodNonOptional`,(e,t)=>{X.init(e,t),J(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Jb(t,e)):Jb(i,e)}});function Jb(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function Yb(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>M_(e,r,rv()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}var Xb=Y(`$ZodCatch`,(e,t)=>{X.init(e,t),J(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),J(e,`optout`,e=>e.def.innerType._zod.optout),J(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(r=>Yb(e,r,t,n)):Yb(e,r,t,n)}}),Zb=Y(`$ZodPipe`,(e,t)=>{X.init(e,t),J(e,`values`,e=>e.def.in._zod.values),J(e,`optin`,e=>e.def.in._zod.optin),J(e,`optout`,e=>e.def.out._zod.optout),J(e,`propValues`,e=>e.def.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Qb(e,t.in,n)):Qb(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Qb(e,t.out,n)):Qb(r,t.out,n)}});function Qb(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}var $b=Y(`$ZodReadonly`,(e,t)=>{X.init(e,t),J(e,`propValues`,e=>e.def.innerType._zod.propValues),J(e,`values`,e=>e.def.innerType._zod.values),J(e,`optin`,e=>e.def.innerType?._zod?.optin),J(e,`optout`,e=>e.def.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(ex):ex(r)}});function ex(e){return e.memo||(e.value=Object.freeze(e.value)),e}var tx=Y(`$ZodCustom`,(e,t)=>{uy.init(e,t),X.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>nx(t,n,r,e));nx(i,n,r,e)}});function nx(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(L_(e))}}var rx=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}},ix=`~memo`,ax=[];function ox(e){return typeof e==`object`&&!!e}function sx(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}var cx=new WeakMap,lx=0,ux=1,dx=2;function fx(e,t,n){let r=cx.get(e);if(r!==void 0)return r?dx:lx;if(t.has(e))return dx;t.add(e);let i=lx,a=e=>{if(i!==dx&&e?._zod){let r=fx(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=lx;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?ux:o.value?._zod?fx(o.value,t,n):lx;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=Xg(c);s(e?o(e,!0):ux),a(c.catchall);break}case`array`:a(c.element);break;case`tuple`:for(let e of c.items)a(e);a(c.rest);break;case`record`:case`map`:a(c.keyType),a(c.valueType);break;case`set`:a(c.valueType);break;case`union`:for(let e of c.options)a(e);break;case`intersection`:a(c.left),a(c.right);break;case`optional`:case`nullable`:case`default`:case`prefault`:case`catch`:case`readonly`:case`nonoptional`:case`promise`:case`success`:a(c.innerType);break;case`pipe`:a(c.in),a(c.out);break;case`function`:a(c.input),a(c.output);break;case`lazy`:{let r=c._cachedInner??(n?e._zod.innerType:void 0);s(r?fx(r,t,!1):ux);break}case`template_literal`:case`string`:case`number`:case`int`:case`boolean`:case`bigint`:case`symbol`:case`undefined`:case`null`:case`void`:case`never`:case`any`:case`unknown`:case`date`:case`nan`:case`enum`:case`literal`:case`file`:case`transform`:case`custom`:break;default:for(let e in c){let t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.get)continue;let n=t.value;if(n&&typeof n==`object`){if(n._zod)a(n);else if(Array.isArray(n))for(let e of n)a(e)}}}return t.delete(e),px(e,i)}function px(e,t){return t!==ux&&cx.set(e,t===dx),t}function mx(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}var hx,gx=[],_x={alloc(e,t,n){let r=hx;if(!r)return n;hx=void 0;let i={value:n,issues:null};return r.set(t.value,i),gx.push(i),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,n=(e,n)=>{if(n.direction!==`backward`&&yx(n,e.value))throw new rx;return t(e,n)};e._zod.parse=n,e._zod.run===t&&(e._zod.run=n)})},attach(e){var t;let n,r=!1,i,a;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,o=(s,c)=>{if(n===void 0){let i=fx(e,new Set,!1);if(i===lx)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===dx||r?n=!0:r=!0}let l=s.value;if(!ox(l))return t(s,c);let u=c[ix];u||(u={buckets:new WeakMap,backEdges:void 0},c[ix]=u);let d;i===c?d=a:(d=mx(u,e),i=c,a=d);let f=d.get(l);if(f)return s.value=f.value,f.issues?f.issues.length&&s.issues.push(...sx(f.issues)):(s.memo=!0,u.backEdges??(u.backEdges=new WeakSet),u.backEdges.add(f.value)),s;hx=d;let p=gx.length,m=t(s,c);hx=void 0;let h=gx.length>p?gx.pop():void 0;return m instanceof Promise?m.then(e=>(h&&(h.issues=e.issues.length?sx(e.issues):ax),e)):(h&&(h.issues=m.issues.length?sx(m.issues):ax),m)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function vx(){return _x}function yx(e,t){let n=e[ix]?.backEdges;return n!==void 0&&ox(t)&&n.has(t)}var bx=()=>{let e={string:{unit:`characters`,verb:`to have`},file:{unit:`bytes`,verb:`to have`},array:{unit:`items`,verb:`to have`},set:{unit:`items`,verb:`to have`},map:{unit:`entries`,verb:`to have`}};function t(t){return e[t]??null}let n={regex:`input`,email:`email address`,url:`URL`,emoji:`emoji`,uuid:`UUID`,uuidv4:`UUIDv4`,uuidv6:`UUIDv6`,nanoid:`nanoid`,guid:`GUID`,cuid:`cuid`,cuid2:`cuid2`,ulid:`ULID`,xid:`XID`,ksuid:`KSUID`,datetime:`ISO datetime`,date:`ISO date`,time:`ISO time`,duration:`ISO duration`,ipv4:`IPv4 address`,ipv6:`IPv6 address`,mac:`MAC address`,cidrv4:`IPv4 range`,cidrv6:`IPv6 range`,base64:`base64-encoded string`,base64url:`base64url-encoded string`,json_string:`JSON string`,e164:`E.164 number`,currency_code:`currency code`,credit_card:`credit card number`,iban:`IBAN`,jwt:`JWT`,template_literal:`input`},r={nan:`NaN`};function i(e,t){return e===`number`&&typeof t==`number`&&!Number.isFinite(t)?String(t):r[e]??e}return e=>{switch(e.code){case`invalid_type`:return`Invalid input: expected ${i(e.expected)}, received ${i(I_(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${p_(e.values[0])}`:`Invalid option: expected one of ${Hg(e.values,`|`)}`;case`too_big`:{let n=e.exact?`exactly `:e.inclusive?`<=`:`<`,r=t(e.origin);return r?`Too big: expected ${e.origin??`value`} to have ${n}${e.maximum.toString()} ${r.unit??`elements`}`:`Too big: expected ${e.origin??`value`} to be ${n}${e.maximum.toString()}`}case`too_small`:{let n=e.exact?`exactly `:e.inclusive?`>=`:`>`,r=t(e.origin);return r?`Too small: expected ${e.origin} to have ${n}${e.minimum.toString()} ${r.unit}`:`Too small: expected ${e.origin} to be ${n}${e.minimum.toString()}`}case`invalid_format`:{let t=e;return t.format===`starts_with`?`Invalid string: must start with "${t.prefix}"`:t.format===`ends_with`?`Invalid string: must end with "${t.suffix}"`:t.format===`includes`?`Invalid string: must include "${t.includes}"`:t.format===`regex`?`Invalid string: must match pattern ${t.pattern}`:`Invalid ${n[t.format]??e.format}`}case`not_multiple_of`:return`Invalid number: must be a multiple of ${e.divisor}`;case`unrecognized_keys`:return`Unrecognized key${e.keys.length>1?`s`:``}: ${Hg(e.keys,`, `)}`;case`invalid_key`:return`Invalid key in ${e.origin}`;case`invalid_union`:return e.options&&Array.isArray(e.options)&&e.options.length>0?`Invalid discriminator value. Expected ${e.options.map(e=>`'${e}'`).join(` | `)}`:e.inclusive===!1?`Invalid input: more than one option matched`:`Invalid input`;case`invalid_element`:return`Invalid value in ${e.origin}`;default:return`Invalid input`}}};function xx(){return{localeError:bx()}}var Sx,Cx=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function wx(){return new Cx}(Sx=globalThis).__zod_globalRegistry??(Sx.__zod_globalRegistry=wx());var Tx=globalThis.__zod_globalRegistry;function Ex(e){return e.checks&&=[...e.checks],e}function Dx(e,t){return new e(Ex({type:`string`,...q(t)}))}function Ox(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...q(t)})}function kx(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...q(t)})}function Ax(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...q(t)})}function jx(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...q(t)})}function Mx(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...q(t)})}function Nx(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...q(t)})}function Px(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...q(t)})}function Fx(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...q(t)})}function Ix(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...q(t)})}function Lx(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...q(t)})}function Rx(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...q(t)})}function zx(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...q(t)})}function Bx(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...q(t)})}function Vx(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...q(t)})}function Hx(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...q(t)})}function Ux(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...q(t)})}function Wx(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...q(t)})}function Gx(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...q(t)})}function Kx(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...q(t)})}function qx(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...q(t)})}function Jx(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...q(t)})}function Yx(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...q(t)})}function Xx(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...q(t)})}function Zx(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...q(t)})}function Qx(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...q(t)})}function $x(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...q(t)})}function eS(e,t){return new e(Ex({type:`number`,checks:[],...q(t)}))}function tS(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...q(t)})}function nS(e){return new e({type:`unknown`})}function rS(e,t){return new e({type:`never`,...q(t)})}function iS(e,t){return new py({check:`less_than`,...q(t),value:e,inclusive:!1})}function aS(e,t){return new py({check:`less_than`,...q(t),value:e,inclusive:!0})}function oS(e,t){return new my({check:`greater_than`,...q(t),value:e,inclusive:!1})}function sS(e,t){return new my({check:`greater_than`,...q(t),value:e,inclusive:!0})}function cS(e,t){return new hy({check:`multiple_of`,...q(t),value:e})}function lS(e,t){return new _y({check:`max_length`,...q(t),maximum:e})}function uS(e,t){return new vy({check:`min_length`,...q(t),minimum:e})}function dS(e,t){return new yy({check:`length_equals`,...q(t),length:e})}function fS(e,t){return new xy({check:`string_format`,format:`regex`,...q(t),pattern:e})}function pS(e){return new Sy({check:`string_format`,format:`lowercase`,...q(e)})}function mS(e){return new Cy({check:`string_format`,format:`uppercase`,...q(e)})}function hS(e,t){return new wy({check:`string_format`,format:`includes`,...q(t),includes:e})}function gS(e,t){return new Ty({check:`string_format`,format:`starts_with`,...q(t),prefix:e})}function _S(e,t){return new Ey({check:`string_format`,format:`ends_with`,...q(t),suffix:e})}function vS(e){return new Dy({check:`overwrite`,tx:e})}function yS(e){return vS(t=>t.normalize(e))}function bS(){return vS(e=>e.trim())}function xS(){return vS(e=>e.toLowerCase())}function SS(){return vS(e=>e.toUpperCase())}function CS(){return vS(e=>i_(e))}function wS(e,t,n){return new e({type:`array`,element:t,...q(n)})}function TS(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...q(n)})}function ES(e,t){let n=DS(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(L_(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(L_(r))}},e(t.value,t)),t);return n}function DS(e,t){let n=new uy({check:`custom`,...q(t)});return n._zod.check=e,n}function OS(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&Yg(e,t,n[t]);return e}function kS(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??Tx,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function AS(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function jS(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,jS(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&OS(o.schema,c),t.io===`input`&&VS(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function MS(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function NS(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${MS(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+MS(a)}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
60
+
61
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0])a(n);else{if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}(e.metadataRegistry.get(n[0])?.id||r.cycle||r.count>1&&e.reused===`ref`)&&a(n)}}e.external&&(e.sharedDefsExtractedFor=e.external)}function PS(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;PS(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}var FS=new Set([`type`,`properties`,`required`,`additionalProperties`]),IS=[`oneOf`,`anyOf`];function LS(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function RS(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!FS.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??LS(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Yg(n,r,e.length===1?e[0]:RS(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=LS(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function zS(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of FS)if(t in e)return;let n=t.filter(e=>IS.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=RS(t);else{let e=n[0],i=IS.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>RS([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,OS(e,r))}function BS(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):OS(i,s),OS(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())PS(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])zS(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}OS(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Yg(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:US(t,`input`,e.processors),output:US(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function VS(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return VS(r.element,n);if(r.type===`set`)return VS(r.valueType,n);if(r.type===`lazy`)return VS(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return VS(r.innerType,n);if(r.type===`intersection`)return VS(r.left,n)||VS(r.right,n);if(r.type===`record`||r.type===`map`)return VS(r.keyType,n)||VS(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:VS(r.in,n)||VS(r.out,n);if(r.type===`object`){for(let e in r.shape)if(VS(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(VS(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(VS(e,n))return!0;return!!(r.rest&&VS(r.rest,n))}return!1}var HS=(e,t={})=>n=>{let r=kS({...n,processors:t});return jS(e,r),NS(r,e),BS(r,e)},US=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=kS({...i??{},target:a,io:t,processors:n});return jS(e,o),NS(o,e),BS(o,e)},WS=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},GS=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},KS=(e,t)=>{WS(e,`minimum`,t),GS(e,`maximum`,t)},qS=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},JS=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},YS=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},XS=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},ZS=(e,t)=>WS(e,`minimum`,t.minimum),QS=(e,t)=>GS(e,`maximum`,t.maximum),$S=e=>(t,n)=>{XS(t,n.format);let[r,i]=e[n.format];WS(t,`minimum`,r),GS(t,`maximum`,i)},eC={greater_than:(e,t)=>WS(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>GS(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>qS(e,t.value),number_format:$S(h_),bigint_format:$S(g_),min_length:ZS,max_length:QS,length_equals:(e,t)=>KS(e,t.length),min_size:ZS,max_size:QS,size_equals:(e,t)=>KS(e,t.size),string_format:(e,t)=>{XS(e,t.format),t.pattern&&JS(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>YS(e,t.mime)};function tC(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)eC[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&WS(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&WS(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&GS(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&GS(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&qS(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&YS(t,i.mime);for(let e of i.patterns??[])JS(t,e);return t}var nC={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},rC=new Map([[ub,Xv],[fb,Zv]]),iC=e=>rC.get(e)??e,aC=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=tC(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=nC[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(iC);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},oC=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=tC(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):AS(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},sC=(e,t,n,r)=>{n.not={}},cC=(e,t,n,r)=>{let i=e._zod.def,a=Vg(i.entries);a.length===0?n.not={}:(a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a)},lC=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(AS(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(AS(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},uC=(e,t,n,r)=>{AS(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},dC=(e,t,n,r)=>{AS(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},fC=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=tC(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=jS(a.element,t,{...r,path:[...r.path,`items`]})};function pC(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?pC(t.out):t.type===`catch`?pC(t.innerType):e._zod.optin}var mC=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&AS(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Yg(i.properties,e,jS(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?pC(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=jS(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},hC=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>jS(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},gC=(e,t,n,r)=>{let i=e._zod.def,a=jS(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=jS(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)},_C=(e,t,n,r)=>{let i=e._zod.def,a=jS(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},vC=(e,t,n,r)=>{let i=e._zod.def;jS(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},yC=Symbol();function bC(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(AS(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),yC):JSON.parse(o)}var xC=(e,t,n,r)=>{let i=e._zod.def;jS(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=bC(i.defaultValue,e,t,n,r);o!==yC&&(n.default=o)},SC=(e,t,n,r)=>{let i=e._zod.def;jS(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=bC(i.defaultValue,e,t,n,r);o!==yC&&(n._prefault=o)},CC=(e,t,n,r)=>{let i=e._zod.def;jS(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{AS(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},wC=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;jS(o,t,r);let s=t.seen.get(e);s.ref=o},TC=(e,t,n,r)=>{let i=e._zod.def;jS(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},EC=(e,t,n,r)=>{let i=e._zod.def;jS(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},DC=new WeakSet([Object.prototype,Error.prototype]);function OC(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}var kC=Y(`ZodError`,(e,t)=>{uv.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);DC.has(n)||(DC.add(n),OC(n,`format`,e=>t=>pv(e,t)),OC(n,`flatten`,e=>t=>fv(e,t)),OC(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Ug,2)}),OC(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Ug,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),AC=hv(kC),jC=gv(kC),MC=_v(kC),NC=yv(kC),PC=Tv(kC),FC=Ev(kC),IC=Dv(kC),LC=Ov(kC),RC=kv(kC),zC=Av(kC),BC=jv(kC),VC=Mv(kC);function HC(){nv.localeError||rv(xx())}function UC(){nv.memoizer||rv({memoizer:vx()})}var WC=Y(`ZodType`,(e,t)=>(HC(),X.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(n_(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return f_(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(iT(e,t))},superRefine(e,t){return this.check(aT(e,t))},overwrite(e){return this.check(vS(e))},optional(){return Bw(this)},exactOptional(){return Hw(this)},nullable(){return Ww(this)},nullish(){return Bw(Ww(this))},nonoptional(e){return Xw(this,e)},array(){return Ew(this)},or(e){return Aw([this,e])},and(e){return Mw(this,e)},transform(e){return eT(this,Rw(e))},default(e){return Kw(this,e)},prefault(e){return Jw(this,e)},catch(e){return Qw(this,e)},pipe(e){return eT(this,e)},readonly(){return nT(this)},describe(e){let t=this.clone();return Tx.add(t,{description:e}),t},meta(...e){if(e.length===0)return Tx.get(this);let t=this.clone();return Tx.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return B_(this,`~standard`,{...My(this),jsonSchema:{input:US(this,`input`),output:US(this,`output`)}})},set"~standard"(e){z_(this,`~standard`,e)},parse:function e(t,n){return AC(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await jC(this,t,n,{callee:e})},safeParse(e,t){return MC(this,e,t)},async safeParseAsync(e,t){return NC(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){z_(this,`spa`,e)},validate(e,t){return Sv(this,e,t)},validateAsync(e,t){return wv(this,e,t)},encode:function e(t,n){return PC(this,t,n,{callee:e})},decode:function e(t,n){return FC(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await IC(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await LC(this,t,n,{callee:e})},safeEncode(e,t){return RC(this,e,t)},safeDecode(e,t){return zC(this,e,t)},async safeEncodeAsync(e,t){return BC(this,e,t)},async safeDecodeAsync(e,t){return VC(this,e,t)},toJSONSchema(e){return HS(this,{})(e)},get description(){return Tx.get(this)?.description},get _def(){return this._zod.def}}),GC=Y(`_ZodString`,(e,t)=>{Ny.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>aC(e,t,n,r)},V_({format:e=>tC(e).format??null,minLength:e=>tC(e).minimum??null,maxLength:e=>tC(e).maximum??null},{regex(...e){return this.check(fS(...e))},includes(...e){return this.check(hS(...e))},startsWith(...e){return this.check(gS(...e))},endsWith(...e){return this.check(_S(...e))},min(...e){return this.check(uS(...e))},max(...e){return this.check(lS(...e))},length(...e){return this.check(dS(...e))},nonempty(...e){return this.check(uS(1,...e))},lowercase(e){return this.check(pS(e))},uppercase(e){return this.check(mS(e))},trim(){return this.check(bS())},normalize(...e){return this.check(yS(...e))},toLowerCase(){return this.check(xS())},toUpperCase(){return this.check(SS())},slugify(){return this.check(CS())}})),KC=Y(`ZodString`,(e,t)=>{Ny.init(e,t),GC.init(e,t)},{email(e){return this.check(Ox(QC,e))},url(e){return this.check(Px(tw,e))},jwt(e){return this.check(Yx(gw,e))},emoji(e){return this.check(Fx(nw,e))},guid(e){return this.check(kx($C,e))},uuid(e){return this.check(Ax(ew,e))},uuidv4(e){return this.check(jx(ew,e))},uuidv6(e){return this.check(Mx(ew,e))},uuidv7(e){return this.check(Nx(ew,e))},nanoid(e){return this.check(Ix(rw,e))},cuid(e){return this.check(Lx(iw,e))},cuid2(e){return this.check(Rx(aw,e))},ulid(e){return this.check(zx(ow,e))},base64(e){return this.check(Kx(pw,e))},base64url(e){return this.check(qx(mw,e))},xid(e){return this.check(Bx(sw,e))},ksuid(e){return this.check(Vx(cw,e))},ipv4(e){return this.check(Hx(lw,e))},ipv6(e){return this.check(Ux(uw,e))},cidrv4(e){return this.check(Wx(dw,e))},cidrv6(e){return this.check(Gx(fw,e))},e164(e){return this.check(Jx(hw,e))},datetime(e){return this.check(Xx(JC,e))},date(e){return this.check(Zx(YC,e))},time(e){return this.check(Qx(XC,e))},duration(e){return this.check($x(ZC,e))}});function qC(e){return Dx(KC,e)}var Q=Y(`ZodStringFormat`,(e,t)=>{Z.init(e,t),GC.init(e,t)}),JC=Y(`ZodISODateTime`,(e,t)=>{Qy.init(e,t),Q.init(e,t)}),YC=Y(`ZodISODate`,(e,t)=>{$y.init(e,t),Q.init(e,t)}),XC=Y(`ZodISOTime`,(e,t)=>{eb.init(e,t),Q.init(e,t)}),ZC=Y(`ZodISODuration`,(e,t)=>{tb.init(e,t),Q.init(e,t)}),QC=Y(`ZodEmail`,(e,t)=>{Iy.init(e,t),Q.init(e,t)}),$C=Y(`ZodGUID`,(e,t)=>{Py.init(e,t),Q.init(e,t)}),ew=Y(`ZodUUID`,(e,t)=>{Fy.init(e,t),Q.init(e,t)}),tw=Y(`ZodURL`,(e,t)=>{Wy.init(e,t),Q.init(e,t)}),nw=Y(`ZodEmoji`,(e,t)=>{Gy.init(e,t),Q.init(e,t)}),rw=Y(`ZodNanoID`,(e,t)=>{Ky.init(e,t),Q.init(e,t)}),iw=Y(`ZodCUID`,(e,t)=>{qy.init(e,t),Q.init(e,t)}),aw=Y(`ZodCUID2`,(e,t)=>{Jy.init(e,t),Q.init(e,t)}),ow=Y(`ZodULID`,(e,t)=>{Yy.init(e,t),Q.init(e,t)}),sw=Y(`ZodXID`,(e,t)=>{Xy.init(e,t),Q.init(e,t)}),cw=Y(`ZodKSUID`,(e,t)=>{Zy.init(e,t),Q.init(e,t)}),lw=Y(`ZodIPv4`,(e,t)=>{nb.init(e,t),Q.init(e,t)}),uw=Y(`ZodIPv6`,(e,t)=>{ab.init(e,t),Q.init(e,t)}),dw=Y(`ZodCIDRv4`,(e,t)=>{ob.init(e,t),Q.init(e,t)}),fw=Y(`ZodCIDRv6`,(e,t)=>{cb.init(e,t),Q.init(e,t)}),pw=Y(`ZodBase64`,(e,t)=>{db.init(e,t),Q.init(e,t)}),mw=Y(`ZodBase64URL`,(e,t)=>{mb.init(e,t),Q.init(e,t)}),hw=Y(`ZodE164`,(e,t)=>{hb.init(e,t),Q.init(e,t)}),gw=Y(`ZodJWT`,(e,t)=>{_b.init(e,t),Q.init(e,t)}),_w=Y(`ZodNumber`,(e,t)=>{vb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>oC(e,t,n,r),e.isFinite=!0},V_({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=tC(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=tC(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=tC(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>tC(e).format??null},{gt(e,t){return this.check(oS(e,t))},gte(e,t){return this.check(sS(e,t))},min(e,t){return this.check(sS(e,t))},lt(e,t){return this.check(iS(e,t))},lte(e,t){return this.check(aS(e,t))},max(e,t){return this.check(aS(e,t))},int(e){return this.check(bw(e))},safe(e){return this.check(bw(e))},positive(e){return this.check(oS(0,e))},nonnegative(e){return this.check(sS(0,e))},negative(e){return this.check(iS(0,e))},nonpositive(e){return this.check(aS(0,e))},multipleOf(e,t){return this.check(cS(e,t))},step(e,t){return this.check(cS(e,t))},finite(){return this}}));function vw(e){return eS(_w,e)}var yw=Y(`ZodNumberFormat`,(e,t)=>{yb.init(e,t),_w.init(e,t)});function bw(e){return tS(yw,e)}var xw=Y(`ZodUnknown`,(e,t)=>{bb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Sw(){return nS(xw)}var Cw=Y(`ZodNever`,(e,t)=>{xb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>sC(e,t,n,r)});function ww(e){return rS(Cw,e)}var Tw=Y(`ZodArray`,(e,t)=>{UC(),Tb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fC(e,t,n,r),e.element=t.element},{min(e,t){return this.check(uS(e,t))},nonempty(e){return this.check(uS(1,e))},max(e,t){return this.check(lS(e,t))},length(e,t){return this.check(dS(e,t))},unwrap(){return this.element}});function Ew(e,t){return wS(Tw,e,t)}var Dw=Y(`ZodObject`,(e,t)=>{UC(),jb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>mC(e,t,n,r),q_(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return Pw(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(n_(this._zod.def,{catchall:e}))},passthrough(){return this.clone(n_(this._zod.def,{catchall:Sw()}))},loose(){return this.clone(n_(this._zod.def,{catchall:Sw()}))},strict(){return this.clone(n_(this._zod.def,{catchall:ww()}))},strip(){return this.clone(n_(this._zod.def,{catchall:void 0}))},extend(e){return b_(this,e)},safeExtend(e){return S_(this,e)},merge(e){return C_(this,e)},pick(e){return __(this,e)},omit(e){return y_(this,e)},partial(...e){return w_(zw,this,e[0])},exactPartial(...e){return w_(Vw,this,e[0],`exactPartial`)},required(...e){return T_(Yw,this,e[0])}});function Ow(e,t){return new Dw({type:`object`,shape:e??{},...q(t)})}var kw=Y(`ZodUnion`,(e,t)=>{Nb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hC(e,t,n,r),e.options=t.options});function Aw(e,t){return new kw({type:`union`,options:e,...q(t)})}var jw=Y(`ZodIntersection`,(e,t)=>{Pb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>gC(e,t,n,r)});function Mw(e,t){return new jw({type:`intersection`,left:e,right:t})}var Nw=Y(`ZodEnum`,(e,t)=>{Lb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cC(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Nw({...t,checks:[],...q(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Nw({...t,checks:[],...q(r),entries:i})}});function Pw(e,t){return new Nw({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...q(t)})}var Fw=Y(`ZodLiteral`,(e,t)=>{Rb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>lC(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Iw(e,t){return new Fw({type:`literal`,values:Array.isArray(e)?e:[e],...q(t)})}var Lw=Y(`ZodTransform`,(e,t)=>{UC(),zb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>dC(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new tv(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(L_(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(L_(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Rw(e){return new Lw({type:`transform`,transform:e})}var zw=Y(`ZodOptional`,(e,t)=>{Vb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>EC(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Bw(e){return new zw({type:`optional`,innerType:e})}var Vw=Y(`ZodExactOptional`,(e,t)=>{Hb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>EC(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Hw(e){return new Vw({type:`optional`,innerType:e})}var Uw=Y(`ZodNullable`,(e,t)=>{Ub.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_C(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ww(e){return new Uw({type:`nullable`,innerType:e})}var Gw=Y(`ZodDefault`,(e,t)=>{Wb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>xC(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Kw(e,t){return new Gw({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():l_(t)}})}var qw=Y(`ZodPrefault`,(e,t)=>{Kb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>SC(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Jw(e,t){return new qw({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():l_(t)}})}var Yw=Y(`ZodNonOptional`,(e,t)=>{qb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vC(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Xw(e,t){return new Yw({type:`nonoptional`,innerType:e,...q(t)})}var Zw=Y(`ZodCatch`,(e,t)=>{Xb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>CC(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Qw(e,t){return new Zw({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Y_(t)})}var $w=Y(`ZodPipe`,(e,t)=>{Zb.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wC(e,t,n,r),e.in=t.in,e.out=t.out});function eT(e,t){return new $w({type:`pipe`,in:e,out:t})}var tT=Y(`ZodReadonly`,(e,t)=>{$b.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>TC(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function nT(e){return new tT({type:`readonly`,innerType:e})}var rT=Y(`ZodCustom`,(e,t)=>{tx.init(e,t),WC.init(e,t),e._zod.processJSONSchema=(t,n,r)=>uC(e,t,n,r)});function iT(e,t={}){return TS(rT,e,t)}function aT(e,t){return ES(e,t)}var oT=/^[a-z0-9][a-z0-9-]{0,47}$/,sT=qC().regex(oT,`is lower case letters, digits and "-" (at most 48), starting with a letter or digit`),cT=qC().max(200).regex(/^(?![\s\S]*(?:^|\/)\.{1,2}(?:\/|$))[A-Za-z0-9_. -]+(?:\/[A-Za-z0-9_. -]+)*$/,`is a path inside the workflow folder, such as briefs/review.md: no absolute path, "..", "\\" or drive`).refine(e=>/\.md$/i.test(e),`is a markdown file (.md)`),lT=e=>qC().max(e).refine(e=>e.trim().length>0,`is empty`),uT=qC().optional(),dT=Aw([Ow({every:vw().int().min(1).max(1e5),of:lT(40)}),Ow({clock:Pw([`hourly`,`daily`,`weekly`])})],{message:`is { "every": 30, "of": "merges" } or { "clock": "daily" } (hourly, daily or weekly)`}),fT=vw().int().min(1).max(100),pT=Ow({$comment:uT,word:lT(80),to:sT.optional(),times:fT.optional(),end:Iw(!0,{message:`is true (the outcome ends the flow) or left out`}).optional()}),mT=Ow({$comment:uT,word:lT(80),to:Pw(gf,{message:`is "done" (the block goes on), "owner" (the block's one fixes it, and it runs again), "report" (with the block's outcome) or "ask-manager"`}),times:fT.optional()}),hT=Ow({$comment:uT,id:sT,kind:Pw(mf,{message:`is "work" or "check": a subagent's piece of work, or its check of the block's work`}),title:lT(80),brief:cT.optional(),model:lT(80).optional(),when:Pw(hf,{message:`is "start", "done" (when the block's own work is done) or "brief" (where the brief says)`}).optional(),outcomes:Ew(mT).max(20).optional()}),gT=Ow({$comment:uT,id:sT,kind:Pw(ff,{message:`is one of ${ff.join(`, `)}`}),title:lT(80),runs:Pw(pf,{message:`is "manager", "person", "new-session" or "continue" (with "continues": the block whose session it is)`}).optional(),continues:sT.optional(),model:lT(80).optional(),profile:lT(48).optional(),brief:cT.optional(),substeps:Ew(hT).max(20).optional(),outcomes:Ew(pT).max(50).optional(),ask:Pw([`question`,`review`],{message:`is "question" (ask_user) or "review" (a review page)`}).optional(),timer:dT.optional(),flow:sT.optional(),at:Ow({x:vw().finite(),y:vw().finite()}).optional()}),_T=Ow({$comment:uT,id:sT,title:lT(80),file:cT,blocks:Ew(sT).min(1).max(200)}),vT=Ow({$comment:uT,id:sT,title:lT(80),colour:Pw(Object.keys(c),{message:`is one of the name colours: ${Object.keys(c).join(`, `)}`}).optional(),at:Ow({x:vw().finite(),y:vw().finite()}),size:Ow({width:vw().finite().min(40).max(1e5),height:vw().finite().min(40).max(1e5)})}),yT=Ow({$comment:uT,version:Iw(1,{message:`must be 1, the only version this Ledung knows`}),title:lT(120).optional(),start:sT.optional(),manager:cT.optional(),blocks:Ew(gT).min(1,`a flow needs at least one block`).max(200),overlays:Ew(_T).max(50).default([]),frames:Ew(vT).max(100).default([])});function bT(e,t){let n=[],r=e;for(let e of t){let t=r&&typeof r==`object`?r[e]:void 0,i=t&&typeof t==`object`&&typeof t.id==`string`?t.id:null;n.push(typeof e==`number`?i&&oT.test(i)?i:String(e+1):String(e)),r=t}return n.join(`.`)||`(top level)`}var xT={top:Object.keys(yT.shape),block:Object.keys(gT.shape),at:[`x`,`y`],timer:[`every`,`of`,`clock`],overlay:Object.keys(_T.shape),frame:Object.keys(vT.shape),size:[`width`,`height`],substep:Object.keys(hT.shape),outcome:Object.keys(pT.shape),substepOutcome:Object.keys(mT.shape)},ST={arrows:`was the list of arrows, and arrows are now each block's outcomes (question #1184): { "word": "Approved", "to": "merge" } in the "outcomes" of the block they leave. It is left out.`},CT={pass:`was the word that sends work on, and it is now an outcome (question #1184): { "word": "Approved", "to": "<the next block>" } in "outcomes". It is left out.`,fail:`was where a no goes, and it is now outcomes (question #1184): { "word": "Changes requested", "to": "fix" }, and for a round limit the same word with "times": 3 and where the 3rd one goes. It is left out.`,lock:`was a lock, and locks are gone (question #1183): the workflow guides, and what must always reach the person is a sensitive pattern or away mode. Take it out of flow.json; it is left out.`},wT={substeps:`can't be in a sub-step: a subagent starts no subagents of its own, so sub-steps don't nest; it is left out.`,runs:`can't be in a sub-step: a sub-step is a subagent of its block's one and owns no session; it is left out.`,continues:`can't be in a sub-step: a sub-step is a subagent of its block's one and owns no session; it is left out.`,profile:`can't be in a sub-step: a subagent starts with no session profile of its own; it is left out.`,pass:`was the word that says it is done, and it is now an outcome (question #1185): { "word": "No findings", "to": "done" }. It is left out.`,fail:`was what a no does, and it is now outcomes (question #1185): { "word": "Findings", "to": "owner" }, and { "word": "Findings", "times": 3, "to": "report" } for after the last round. It is left out.`};function TT(e){let t=[],n=(n,r,i,a={})=>{if(n&&typeof n==`object`&&!Array.isArray(n))for(let o of Object.keys(n))r.includes(o)||t.push({at:bT(e,[...i,o]),message:Object.hasOwn(a,o)?a[o]:`is not a field this Ledung knows (a typo, or written by a newer Ledung); it is left out.`})},r=t=>{let n=e[t];return Array.isArray(n)?n:[]},i=(e,t)=>{let n=e&&typeof e==`object`?e[t]:void 0;return Array.isArray(n)?n:[]};return n(e,xT.top,[],ST),r(`blocks`).forEach((e,t)=>{n(e,xT.block,[`blocks`,t],CT);for(let r of[`at`,`timer`])n(e?.[r],xT[r],[`blocks`,t,r]);i(e,`outcomes`).forEach((e,r)=>n(e,xT.outcome,[`blocks`,t,`outcomes`,r])),i(e,`substeps`).forEach((e,r)=>{n(e,xT.substep,[`blocks`,t,`substeps`,r],wT),i(e,`outcomes`).forEach((e,i)=>n(e,xT.substepOutcome,[`blocks`,t,`substeps`,r,`outcomes`,i]))})}),r(`overlays`).forEach((e,t)=>n(e,xT.overlay,[`overlays`,t])),r(`frames`).forEach((e,t)=>{n(e,xT.frame,[`frames`,t]);for(let r of[`at`,`size`])n(e?.[r],xT[r],[`frames`,t,r])}),t}function ET(e,t=af){let n;try{n=JSON.parse(e.replace(/^\uFEFF/,``))}catch(e){return{flow:null,problems:[{at:t,message:`is not valid JSON: ${e.message}`}]}}let r=yT.safeParse(n),i=TT(n);if(!r.success)return{flow:null,problems:[...r.error.issues.map(e=>({at:bT(n,e.path),message:e.message})),...i]};let{$comment:a,...o}=r.data,s=e=>e?.map(({$comment:e,...t})=>t),c=o.blocks.map(({$comment:e,outcomes:t,substeps:n,...r})=>({...r,...t?{outcomes:s(t)}:{},...n?{substeps:n.map(({$comment:e,outcomes:t,...n})=>({...n,...t?{outcomes:s(t)}:{}}))}:{}}));return{flow:{...o,blocks:c,overlays:o.overlays.map(({$comment:e,...t})=>t),frames:o.frames.map(({$comment:e,...t})=>t)},problems:i}}var DT=/(?:^|[^\w])(?:[A-Za-z]:[\\/]|\\\\[^\\\s]|\/(?:Users|home|root|mnt|Volumes)\/)/;function OT(e,t){let n=t.split(`
62
+ `),r=n.findIndex(e=>DT.test(e));return r<0?null:{at:`${e}:${r+1}`,message:`"${n[r].trim().slice(0,120)}" looks like a path on one computer; a workflow must work on any computer it is copied to.`}}function kT(e,t,n,r){let i=[],a=(e,t)=>i.push({at:e,message:t}),o=(e,t)=>i.push({at:e,message:t,hint:!0}),s=new Set;for(let t of e.blocks)s.has(t.id)&&a(`blocks.${t.id}`,`Two blocks have the id "${t.id}"; give each its own.`),s.add(t.id);let c=(e,t,n)=>{t!==void 0&&!s.has(t)&&a(e,`${n} "${t}", which is not a block in this flow.`)};c(`start`,e.start,`starts at`);let l=(e,t,n)=>{let r=new Set;for(let i of n){let n=vf(i);r.has(n)&&a(e,`Two outcomes of "${t}" are "${n}": give each its own word or count.`),r.add(n)}for(let r of n)r.times&&!n.some(e=>e.word===r.word&&!e.times)&&o(e,`"${t}" says only where "${vf(r)}" goes: say with a plain "${r.word}" where the other times go.`)},u=e.blocks.filter(e=>!e.outcomes?.length);for(let r of e.blocks){let e=`blocks.${r.id}`;(r.outcomes??[]).forEach((t,n)=>{t.end?t.to!==void 0&&a(`${e}.outcomes.${n+1}`,`"${vf(t)}" of "${r.title}" both ends the flow and leads to "${t.to}": take out "end" or "to".`):t.to===void 0?a(`${e}.outcomes.${n+1}`,`"${vf(t)}" of "${r.title}" leads nowhere yet: drag its pin to the block it leads to, or pick one in the block's panel.`):c(`${e}.outcomes.${n+1}`,t.to,`"${vf(t)}" leads to`)}),l(`${e}.outcomes`,r.title,r.outcomes??[]),!r.outcomes?.length&&u.length>1&&o(`${e}.outcomes`,`Where does "${r.title}" go next? It has no outcomes, so the work ends there; that is fine if it is meant to.`),Cf(r)&&!r.brief&&o(`${e}.brief`,`"${r.title}" runs as a session but has no brief: the brief says how its one acts (a builder, a reviewer).`),r.kind===`person`&&!r.ask&&a(e,`The person block "${r.title}" doesn't say what it asks: give "ask": "question" or "review".`),r.kind===`person`&&r.runs&&r.runs!==`person`&&a(`${e}.runs`,`A person block is a person's: take "runs" out, or make "${r.title}" a work or check block.`),(r.kind===`fork`||r.kind===`join`)&&r.runs&&a(`${e}.runs`,`A ${r.kind} only splits or joins the work; nobody runs it: take "runs" out.`),r.runs===`continue`&&r.continues===void 0&&a(`${e}.continues`,`"${r.title}" continues a session: say whose with "continues", the id of an earlier block that runs as a session.`),r.continues!==void 0&&r.runs!==`continue`&&a(`${e}.continues`,`"continues" is for a block that runs as "continue": take it out, or set "runs": "continue".`),r.substeps?.length&&r.runs!==`manager`&&!Cf(r)&&a(`${e}.substeps`,r.kind===`person`||r.runs===`person`?`A person starts no subagents: sub-steps go in a block the manager or a session runs.`:`Sub-steps are subagents of the one who runs "${r.title}": say who with "runs" (the manager, a new session or a continued one).`);let i=new Set;for(let n of r.substeps??[]){let o=`${e}.substeps.${n.id}`;i.has(n.id)&&a(o,`Two sub-steps of "${r.title}" have the id "${n.id}"; give each its own.`),i.add(n.id),n.brief&&!t(n.brief)&&a(`${o}.brief`,`The brief ${n.brief} is not in the workflow folder.`),l(`${o}.outcomes`,n.title,n.outcomes??[]);for(let e of n.outcomes??[])e.to===`owner`&&!e.times&&!(n.outcomes??[]).some(t=>t.word===e.word&&t.times&&t.to!==`owner`)&&a(`${o}.outcomes`,`"${n.title}" can go round for ever on "${e.word}": add "${e.word}" with a count ("times") and where it goes then (report, or ask the manager).`)}if(r.kind!==`person`&&r.ask&&a(`${e}.ask`,`Only a person block asks; take "ask" out or make the block a person block.`),r.kind===`flow`){r.flow===void 0&&a(`${e}.flow`,`The Run flow block "${r.title}" doesn't say which flow it runs: give "flow", the name of one of the project's flows.`);for(let t of[`runs`,`continues`,`model`,`profile`,`brief`,`substeps`])r[t]!==void 0&&a(`${e}.${t}`,`A Run flow block is done by the flow it runs: take "${t}" out of "${r.title}".`)}else r.flow!==void 0&&a(`${e}.flow`,`Only a Run flow block (kind "flow") runs a flow: take "flow" out, or make "${r.title}" one.`);r.kind===`timer`&&!r.timer&&a(e,`The timer block "${r.title}" doesn't say when it starts: give "timer", e.g. { "every": 30, "of": "merges" } or { "clock": "daily" }.`),r.kind!==`timer`&&r.timer&&a(`${e}.timer`,`Only a timer block has "timer".`),r.brief&&!t(r.brief)&&a(`${e}.brief`,`The brief ${r.brief} is not in the workflow folder.`),r.profile&&n&&!n.includes(r.profile)&&a(`${e}.profile`,`There is no session profile "${r.profile}" for this project (${n.length?`there are: ${n.join(`, `)}`:`it has none`}).`)}let d=new Set;for(let n of e.overlays){let e=`overlays.${n.id}`;d.has(n.id)&&a(e,`Two overlays have the id "${n.id}"; give each its own.`),d.add(n.id);for(let t of n.blocks)c(`${e}.blocks`,t,`amends`);t(n.file)||a(`${e}.file`,`The overlay's file ${n.file} is not in the workflow folder.`)}let f=new Set;for(let t of e.frames)f.has(t.id)&&a(`frames.${t.id}`,`Two frames have the id "${t.id}"; give each its own.`),f.add(t.id);e.manager&&!t(e.manager)&&a(`manager`,`The manager's file ${e.manager} is not in the workflow folder.`);let p=(e,t)=>{if(typeof e==`string`)DT.test(e)&&a(t,`"${e}" looks like a path on one computer; a workflow must work on any computer it is copied to.`);else if(Array.isArray(e))e.forEach((e,n)=>p(e,`${t}.${n+1}`));else if(e&&typeof e==`object`)for(let[n,r]of Object.entries(e))p(r,`${t}.${n}`)};for(let t of e.blocks)p({...t,id:void 0},`blocks.${t.id}`);e.title&&p(e.title,`title`),e.overlays.forEach(e=>p(e.title,`overlays.${e.id}.title`)),e.frames.forEach(e=>p(e.title,`frames.${e.id}.title`));let m=xf(e).filter(e=>s.has(e.from)&&s.has(e.to));for(let t of FT(e,m)){let n=e.blocks.find(e=>e.id===t);a(`blocks.${t}`,`No outcome leads to "${n.title}" from where work starts${e.start?` ("${e.start}")`:``}; connect it, or take it out.`)}for(let t of IT(e.blocks,m,r)){let n=t.map(t=>e.blocks.find(e=>e.id===t).title);a(`blocks.${t[0]}`,`${n.join(` → `)} can go round for ever: give an outcome in it a count ("times": where the 3rd one goes, say), or put a person block in it.`)}return i.push(...PT(e,m)),i}function AT(e){let t=new Map([...e.keys()].map(e=>[e,[]])),n=t=>e.get(t)?.title??t;for(let[r,i]of e){let a=e=>t.get(r).push(e);for(let t of i?.blocks??[]){if(t.kind!==`flow`||t.flow===void 0)continue;let i=`blocks.${t.id}`;if(!e.has(t.flow)){a({at:`${i}.flow`,message:`"${t.title}" runs the flow "${t.flow}", which the project doesn't have${t.flow===`main`?``:` (no flows/${t.flow}.json)`}.`});continue}let o=e.get(t.flow);if(!o||t.flow===r)continue;let s=yf(o),c=new Set(s.map(bf));(t.outcomes??[]).forEach((e,r)=>{e.word.trim()&&!c.has(bf(e.word))&&a({at:`${i}.outcomes.${r+1}`,message:`"${e.word}" is not a way "${n(t.flow)}" ends, so "${t.title}" never has it: it ends with ${s.length?s.map(e=>`"${e}"`).join(`, `):`nothing yet`}.`})});let l=new Set((t.outcomes??[]).map(e=>bf(e.word)));for(let e of s)l.has(bf(e))||a({at:`${i}.outcomes`,message:`"${n(t.flow)}" can end with "${e}": where does the work go after "${t.title}" then? Add it as an outcome.`,hint:!0})}}let r=new Map([...e].map(([t,n])=>[t,[...new Set((n?.blocks??[]).flatMap(t=>t.kind===`flow`&&t.flow!==void 0&&e.has(t.flow)?[t.flow]:[]))]])),i=(e,t)=>{let n=new Set,i=(t,a)=>{if(t===e)return a;if(n.has(t))return null;n.add(t);for(let e of r.get(t)??[]){let t=i(e,[...a,e]);if(t)return t}return null};return i(t,[e,t])};for(let[r,a]of e)for(let o of a?.blocks??[]){if(o.kind!==`flow`||o.flow===void 0||!e.has(o.flow))continue;let a=i(r,o.flow);a&&t.get(r).push({at:`blocks.${o.id}.flow`,message:a.length===2?`"${o.title}" runs "${n(r)}", the flow it is in: a flow can't run itself.`:`"${o.title}" runs a flow that runs this one again (${a.map(n).join(` → `)}): a flow can't run itself, also not through others.`})}return t}function jT(e){let t=new Map,n=(r,i)=>{if(t.has(r))return t.get(r);let a=e.get(r);if(!a||!a.blocks.length||i.has(r))return!1;i.add(r);let o=new Map(a.blocks.map(e=>[e.id,e])),s=e=>e.kind===`person`||e.kind===`flow`&&e.flow!==void 0&&n(e.flow,i),c=a.start&&o.has(a.start)?a.start:a.blocks[0].id,l=new Set,u=[c,...a.blocks.filter(e=>e.kind===`timer`).map(e=>e.id)],d=!1;for(;u.length&&!d;){let e=o.get(u.pop());if(e&&!l.has(e.id)&&(l.add(e.id),!s(e))){(!e.outcomes?.length||e.outcomes.some(e=>e.end||e.to===void 0||!o.has(e.to)))&&(d=!0);for(let t of e.outcomes??[])t.to!==void 0&&u.push(t.to)}}return i.delete(r),t.set(r,!d),!d};return new Set([...e.keys()].filter(e=>n(e,new Set)))}function MT(e,t){let n=new Map(e.blocks.map(e=>[e.id,e])),r=new Set;for(let e=n.get(t);e&&!r.has(e.id);e=e.continues===void 0?void 0:n.get(e.continues)){if(r.add(e.id),e.runs===`new-session`)return e.id;if(e.runs!==`continue`)return}}function NT(e,t){let n=new Map(e.blocks.map(e=>[e.id,e])),r=xf(e),i=new Set,a=new Set([t.id]),o=e=>{let t=n.get(e);if(t&&!a.has(e)){if(a.add(e),t.kind===`work`)i.add(e);else if(t.kind!==`flow`)for(let t of r)t.to===e&&o(t.from)}};for(let e of r)e.to===t.id&&o(e.from);let s=e=>{let n=new Set([e]),i=[e];for(;i.length;){let e=i.pop();for(let a of r)if(a.from===e){if(a.to===t.id)return!0;n.has(a.to)||(n.add(a.to),i.push(a.to))}}return!1};for(let e of t.outcomes??[])e.to!==void 0&&e.to!==t.id&&n.get(e.to)?.kind===`work`&&s(e.to)&&i.add(e.to);return[...i]}function PT(e,t){let n=[],r=new Map(e.blocks.map(e=>[e.id,e])),i=[e.start&&r.has(e.start)?e.start:e.blocks[0].id,...e.blocks.filter(e=>e.kind===`timer`).map(e=>e.id)],a=(e,n)=>{let r=new Set([n]),a=i.filter(e=>e!==n);for(;a.length;){let n=a.pop();if(n===e)return!0;if(!r.has(n)){r.add(n);for(let e of t)e.from===n&&!r.has(e.to)&&a.push(e.to)}}return!1},o=(e,n)=>{let r=new Set,i=[e];for(;i.length;){let e=i.pop();for(let a of t)if(!(a.from!==e||r.has(a.to))){if(a.to===n)return!0;r.add(a.to),i.push(a.to)}}return!1},s=(e,t)=>o(e,t)&&!a(t,e),c=e=>e.runs===`manager`?`as the manager`:e.runs===`person`||e.kind===`person`?`as a person's step`:`as nobody said`;for(let t of e.blocks){if(t.runs!==`continue`||t.continues===void 0)continue;let i=`blocks.${t.id}.continues`,a=r.get(t.continues);a?a.id===t.id?n.push({at:i,message:`"${t.title}" can't continue its own session: name the earlier block whose session takes this step.`}):Cf(a)?s(a.id,t.id)?MT(e,t.id)||n.push({at:i,message:`"${t.title}" continues sessions that only continue each other: one of them must run as a new session.`}):n.push({at:i,message:`"${a.title}" doesn't come before "${t.title}": work can get here without passing it, so there may be no session of it yet to continue.`}):n.push({at:i,message:`"${a.title}" runs ${c(a)}, not as a session, so "${t.title}" has no session of it to continue.`}):n.push({at:i,message:`continues "${t.continues}", which is not a block in this flow.`})}for(let t of e.blocks){if(t.kind!==`check`||t.runs!==`continue`)continue;let i=MT(e,t.id),a=i?NT(e,t).filter(t=>MT(e,t)===i):[];if(a.length){let e=a.map(e=>`"${r.get(e)?.title??e}"`).join(` and `);n.push({at:`blocks.${t.id}.continues`,message:`The check "${t.title}" would run in the session that did ${e}, the work it checks: run it as a new session. For the author to look over their own work, make it a check sub-step of that block.`})}}return n}function FT(e,t){let n=e.start&&e.blocks.some(t=>t.id===e.start)?e.start:e.blocks[0].id,r=new Set,i=[n,...e.blocks.filter(e=>e.kind===`timer`).map(e=>e.id)];for(;i.length;){let e=i.pop();if(!r.has(e)){r.add(e);for(let n of t)n.from===e&&i.push(n.to)}}return[...new Set(e.blocks.map(e=>e.id))].filter(e=>!r.has(e))}function IT(e,t,n){let r=new Set(e.filter(e=>e.kind===`person`||e.kind===`flow`&&e.flow!==void 0&&!!n?.has(e.flow)).map(e=>e.id)),i=new Set(e.flatMap(e=>(e.outcomes??[]).filter(e=>e.end&&e.times).map(t=>JSON.stringify([e.id,t.word])))),a=e=>i.has(JSON.stringify([e.from,e.word]))||t.some(t=>t.times&&t.from===e.from&&t.word===e.word&&t.to!==e.to),o=new Map;for(let e of t){if((e.times?t.some(t=>!t.times&&t.from===e.from&&t.word===e.word&&t.to===e.to)===!1:a(e))||r.has(e.from)||r.has(e.to))continue;let n=o.get(e.from);n?n.push(e.to):o.set(e.from,[e.to])}let s=new Map,c=new Map,l=[],u=new Set,d=[],f=0,p=e=>{s.set(e,f),c.set(e,f++),l.push(e),u.add(e);for(let t of o.get(e)??[])s.has(t)?u.has(t)&&c.set(e,Math.min(c.get(e),s.get(t))):(p(t),c.set(e,Math.min(c.get(e),c.get(t))));if(c.get(e)!==s.get(e))return;let t=[],n;do n=l.pop(),u.delete(n),t.push(n);while(n!==e);(t.length>1||(o.get(e)??[]).includes(e))&&d.push(t.reverse())};for(let t of e)s.has(t.id)||p(t.id);return d}var LT=e=>!!e&&typeof e==`object`&&!Array.isArray(e);function RT(e,t){return e===t?!0:Array.isArray(e)||Array.isArray(t)?Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>RT(e,t[n])):!LT(e)||!LT(t)?!1:[...new Set([...Object.keys(e),...Object.keys(t)].filter(n=>e[n]!==void 0||t[n]!==void 0))].every(n=>RT(e[n],t[n]))}function zT(e){if(!e.flow||e.raw===null)return null;let t;try{t=JSON.parse(e.raw.replace(/^/,``))}catch{return null}if(!LT(t))return null;let n=e.flow;return{base:{raw:t,rawText:e.raw,parsed:n,rules:e.rules,texts:e.texts,versions:e.versions,copy:e.source?.kind===`workflow`},draft:{...n.title===void 0?{}:{title:n.title},...n.start===void 0?{}:{start:n.start},...n.manager===void 0?{}:{manager:n.manager},blocks:n.blocks.map((e,t)=>({key:`b${t}`,block:e})),overlays:n.overlays.map((e,t)=>({key:`o${t}`,overlay:e})),frames:n.frames.map((e,t)=>({key:`f${t}`,frame:e})),rules:e.rules,texts:{...e.texts},seq:0}}}function BT(e,t){let n={raw:null,rawText:null,parsed:null,rules:null,texts:t?.texts??{},versions:t?.versions??{},copy:!1},r={blocks:[],overlays:[],frames:[],rules:null,texts:{...t?.texts??{}},seq:0};if(!e)return{base:n,draft:r};let i=[{id:`issue`,kind:`work`,title:`Issue`,runs:`manager`,outcomes:[{word:`Ready`,to:`build`}]},{id:`build`,kind:`work`,title:`Build`,runs:`new-session`,substeps:[{id:`self-review`,kind:`check`,title:`Self-review`,when:`done`,outcomes:[{word:`No findings`,to:`done`},{word:`Findings`,to:`owner`},{word:`Findings`,times:3,to:`report`}]}],outcomes:[{word:`PR opened`,to:`code-review`}]},{id:`code-review`,kind:`check`,title:`Code review`,runs:`new-session`,outcomes:[{word:`Approved`,to:`person`},{word:`Changes requested`,to:`fix`},{word:`Changes requested`,times:3,to:`person`}]},{id:`fix`,kind:`work`,title:`Fix`,runs:`continue`,continues:`build`,outcomes:[{word:`Fixed`,to:`code-review`}]},{id:`person`,kind:`person`,title:`Person`,runs:`person`,ask:`review`,outcomes:[{word:`Accepted`,to:`merge`},{word:`Changes needed`,to:`fix`}]},{id:`merge`,kind:`work`,title:`Merge`,runs:`manager`}];return{base:n,draft:{...r,title:`Our process`,start:`issue`,blocks:i.map((e,t)=>({key:`n${t}`,block:e})),seq:i.length}}}function VT(e){return{version:1,...e.title===void 0?{}:{title:e.title},...e.start===void 0?{}:{start:e.start},...e.manager===void 0?{}:{manager:e.manager},blocks:e.blocks.map(e=>e.block),overlays:e.overlays.map(e=>e.overlay),frames:e.frames.map(e=>e.frame)}}var HT=[`version`,`title`,`start`,`manager`],UT=[`id`,`kind`,`title`,`flow`,`runs`,`continues`,`model`,`profile`,`brief`,`ask`,`timer`,`substeps`,`outcomes`,`at`],WT=[`id`,`kind`,`title`,`brief`,`model`,`when`,`outcomes`],GT=[`word`,`to`,`times`,`end`],KT=[`id`,`title`,`file`,`blocks`],qT=[`id`,`title`,`colour`,`at`,`size`],JT={at:[`x`,`y`],timer:[`every`,`of`,`clock`],size:[`width`,`height`]},YT={outcomes:GT};function XT(e,t,n,r){if(!LT(e))return ZT(n,r);let i={...e},a=LT(t)?t:{};for(let t of r){let r=n[t];if(RT(a[t],r))continue;let o=e[t];if(r===void 0)delete i[t];else if(JT[t]&&LT(r))i[t]=XT(e[t],a[t],r,JT[t]);else if(YT[t]&&Array.isArray(r)){let e=Array.isArray(o)?o:[],n=Array.isArray(a[t])?a[t]:[],s=new Set,c=t=>{let r=n.findIndex((n,r)=>!s.has(r)&&r<e.length&&t(n));return r>=0&&s.add(r),r},l=r,u=l.map(e=>c(t=>RT(t,e)));i[t]=l.map((r,i)=>{let a=u[i]>=0?u[i]:c(e=>LT(e)&&e.word===r.word);return a>=0?XT(e[a],n[a],r,YT[t]):ZT(r,YT[t])})}else i[t]=r}return i}function ZT(e,t){let n={};for(let r of t){let t=e[r];t!==void 0&&(n[r]=JT[r]&&LT(t)?ZT(t,JT[r]):YT[r]&&Array.isArray(t)?t.map(e=>ZT(e,YT[r])):t)}return n}var QT=e=>e.subs??(e.block.substeps??[]).map((e,t)=>`r${t}`),$T=e=>e.outs??(e.block.outcomes??[]).map((e,t)=>`r${t}`);function eE(e,t,n,r,i){let a=Array.isArray(e)?e:[];return n.map((e,n)=>{let o=/^r(\d+)$/.exec(r[n]??``)?Number(r[n].slice(1)):-1;return o>=0&&o<a.length?XT(a[o],t?.[o],{...e},i):ZT({...e},i)})}function tE(e,t){let n=e.raw,r=e.parsed,i=e=>n&&Array.isArray(n[e])?n[e]:[],a=e=>/^[bof](\d+)$/.exec(e)&&n?Number(e.slice(1)):-1,o={version:1,title:t.title,start:t.start,manager:t.manager},s=n?XT(n,r,o,HT):ZT(o,HT);if(n&&!(`manager`in n)&&`manager`in s&&`blocks`in s){let{manager:e,...t}=s;s=Object.fromEntries(Object.entries(t).flatMap(([t,n])=>t===`blocks`?[[`manager`,e],[t,n]]:[[t,n]]))}s.blocks=t.blocks.map(e=>{let{key:t,block:n}=e,o=t.startsWith(`b`)?a(t):-1;if(o<0)return ZT({...n,substeps:n.substeps?.map(e=>ZT({...e},WT))},UT);let s=i(`blocks`)[o],c=r?.blocks[o],l=XT(s,c,{...n},UT),u=e=>LT(s)?s[e]:void 0;return n.substeps&&!RT(c?.substeps,n.substeps)&&(l.substeps=eE(u(`substeps`),c?.substeps,n.substeps,QT(e),WT)),n.outcomes&&!RT(c?.outcomes,n.outcomes)&&(l.outcomes=eE(u(`outcomes`),c?.outcomes,n.outcomes,$T(e),GT)),l});let c=t.overlays.map(({key:e,overlay:t})=>{let n=e.startsWith(`o`)?a(e):-1;return n>=0?XT(i(`overlays`)[n],r?.overlays[n],{...t},KT):ZT({...t},KT)});c.length||n&&`overlays`in n?s.overlays=c:delete s.overlays;let l=t.frames.map(({key:e,frame:t})=>{let n=e.startsWith(`f`)?a(e):-1;return n>=0?XT(i(`frames`)[n],r?.frames[n],{...t},qT):ZT({...t},qT)});return l.length||n&&`frames`in n?s.frames=l:delete s.frames,`${nE(n?s:{...ZT(s,HT),...Object.fromEntries([`blocks`,`overlays`,`frames`].filter(e=>e in s).map(e=>[e,s[e]]))})}\n`}function nE(e,t=``,n=0,r=150){let i=e=>{if(Array.isArray(e))return`[${e.map(i).join(`, `)}]`;if(LT(e)){let t=Object.entries(e).filter(([,e])=>e!==void 0).map(([e,t])=>`${JSON.stringify(e)}: ${i(t)}`);return t.length?`{ ${t.join(`, `)} }`:`{}`}return JSON.stringify(e)??`null`},a=i(e),o=`${t} `;return!(Array.isArray(e)&&e.some(LT)&&t.length<=2)&&t.length+n+a.length<=r||!(Array.isArray(e)?e.length:LT(e)&&Object.keys(e).length)?a:Array.isArray(e)?`[\n${e.map(e=>o+nE(e,o,0,r)).join(`,
63
+ `)}\n${t}]`:`{\n${Object.entries(e).filter(([,e])=>e!==void 0).map(([e,t])=>{let n=`${JSON.stringify(e)}: `;return`${o}${n}${nE(t,o,n.length,r)}`}).join(`,
64
+ `)}\n${t}}`}function rE(e){let t=[],{base:n,draft:r}=e.flows[0],i=e=>n.copy?null:n.versions[e]??null,a=e.flows.map(e=>({f:e,file:lf(e.name),text:tE(e.base,e.draft)})),o=new Set(a.flatMap(({text:e,file:t})=>{let n=ET(e,t).flow;return n?Sf(n):[]}));for(let[e,a]of Object.entries(r.texts)){if(!wf.test(e)||e===`flow.json`||cf.test(e))continue;let r=n.texts[e]===void 0?o.has(e):n.texts[e]!==a;(n.copy?o.has(e):r)&&t.push({path:e,text:a,base:i(e)})}r.rules!==null&&(n.rules!==null||r.rules!==``)&&(n.copy||r.rules!==n.rules)&&t.push({path:uf,text:r.rules,base:i(uf)});for(let{f:e,file:r,text:o}of[...a.slice(1),a[0]]){let a=!1;try{a=e.read===r&&!!e.base.raw&&RT(JSON.parse(o),e.base.raw)}catch{}(n.copy||!a)&&t.push({path:r,text:o,base:i(r)})}if(!n.copy){let r=new Set(a.map(e=>e.file));for(let i of e.read)!r.has(i)&&n.versions[i]&&t.push({path:i,remove:!0,base:n.versions[i]})}return t}function iE(e,t,n,r){if(!t.blocks.length)return[{at:`blocks`,message:`A flow needs at least one block: drag one from the left.`}];let i=ET(tE(e,t)),a=i.problems.map(e=>({...e,message:e.message.replace(/[Ii]t is left out\.$/,`the builder keeps it as it is.`)}));if(!i.flow)return a;let o=e=>t.texts[e]!==void 0,s=Sf(i.flow),c=[...t.rules===null?[]:[OT(uf,t.rules)],...s.map(e=>t.texts[e]===void 0?null:OT(e,t.texts[e]))];return[...a,...kT(i.flow,o,n,r),...c.filter(e=>e!==null)]}function aE(e,t){return!t.blocks.length||!ET(tE(e,t)).flow}function oE(e,t,n){let r=e.toLowerCase().normalize(`NFKD`).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40)||`block`,i=new Set(t.blocks.filter(e=>e.key!==n).map(e=>e.block.id));if(!i.has(r))return r;for(let e=2;;e++)if(!i.has(`${r}-${e}`))return`${r}-${e}`}var sE={work:`New step`,check:`New check`,person:`Person decides`,fork:`Fork`,join:`Join`,timer:`Timer`,flow:`Run flow`};function cE(e){let t=Cg(VT(e)),n=new Map(t.blocks.map(e=>[e.block,e])),r=new Map(t.blocks.map(e=>[e.block.id,e]));return e=>{let t=n.get(e);if(t)return{x:Math.round(t.x),y:Math.round(t.y)};let i=r.get(e.id);return{x:Math.round((i?.x??0)+40),y:Math.round((i?.y??0)+40)}}}function lE(e){if(e.blocks.every(e=>e.block.at))return e;let t=cE(e);return{...e,blocks:e.blocks.map(e=>e.block.at?e:{...e,block:{...e.block,at:t(e.block)}})}}function uE(e,t,n,r){let i=e.blocks.length?lE(e):e,a=sE[t],o={id:oE(a,i),kind:t,title:a,...t===`flow`&&r!==void 0?{flow:r}:{},...t===`work`||t===`check`?{runs:`new-session`}:{},...t===`person`?{runs:`person`,ask:`question`}:{},...t===`timer`?{timer:{clock:`daily`}}:{}},s=Math.max(-100,...i.blocks.map(e=>e.block.at?.y??0))+140;o.at={x:Math.round(n?.x??i.blocks[i.blocks.length-1]?.block.at?.x??0),y:Math.round(n?.y??s)};let c=`n${i.seq}`;return{draft:{...i,blocks:[...i.blocks,{key:c,block:o,autoId:!0}],seq:i.seq+1},key:c}}function dE(e,t,n){let r=e=>e===t?n:e;return{...e,...e.start===t?{start:n}:{},blocks:e.blocks.map(e=>{let r=e.block;return r.outcomes?.some(e=>e.to===t)&&(r={...r,outcomes:r.outcomes.map(e=>e.to===t?{...e,to:n}:e)}),r.continues===t&&(r={...r,continues:n}),r===e.block?e:{...e,block:r}}),overlays:e.overlays.map(e=>({...e,overlay:{...e.overlay,blocks:e.overlay.blocks.map(r)}}))}}function fE(e,t,n){let r=e.blocks.findIndex(e=>e.key===t);if(r<0)return e;let i=e.blocks[r],a={...i.block,...n};for(let e of Object.keys(n))n[e]===void 0&&delete a[e];let o=i.autoId&&n.id===void 0;o&&n.title!==void 0&&(a.id=oE(n.title,e,t)),n.id!==void 0&&(o=!1);let s={...e,blocks:e.blocks.map((e,n)=>n===r?{key:t,block:a,...o?{autoId:o}:{},...i.subs?{subs:i.subs}:{},...i.outs?{outs:i.outs}:{}}:e)};return a.id===i.block.id?s:dE(s,i.block.id,a.id)}function pE(e,t){let n=lE(e),r=new Set(n.blocks.filter(e=>t.includes(e.key)).map(e=>e.block.id)),i=n.blocks.filter(e=>!t.includes(e.key)).map(e=>{if(e.block.continues===void 0||!r.has(e.block.continues))return e;let{continues:t,...n}=e.block;return{...e,block:n}}),a={...n,...n.start&&r.has(n.start)?{start:void 0}:{},blocks:i,overlays:n.overlays.map(e=>{let t=e.overlay.blocks;return t.some(e=>!r.has(e))&&t.some(e=>r.has(e))?{...e,overlay:{...e.overlay,blocks:t.filter(e=>!r.has(e))}}:e})},o=e=>e.to!==void 0&&r.has(e.to);for(let e of i)a=mE(a,e.key,(e,t)=>[e.filter(e=>!o(e)),t.filter((t,n)=>!o(e[n]))]);return a}function mE(e,t,n){let r=!1,i=e.blocks.map(e=>{if(e.key!==t)return e;let i=e.block.outcomes??[],[a,o]=n([...i],[...$T(e)]);if(RT(a,i))return e;r=!0;let{outcomes:s,...c}=e.block;return{...e,block:a.length?{...c,outcomes:a}:c,outs:o}});return r?{...e,blocks:i}:e}function hE(e,t,n,r=``){let i=e.blocks.find(e=>e.key===t);if(!i)return{draft:e,index:-1};let a=lE(e),o=i.block.outcomes?.length??0;return{draft:{...mE(a,t,(e,t)=>[[...e,{word:r,...n===void 0?{}:{to:n}}],[...t,`n${a.seq}`]]),seq:a.seq+1},index:o}}function gE(e,t,n,r){let i=e.blocks.find(e=>e.key===t)?.block.outcomes?.[n];return!i||i.to===r?e:vE(lE(e),t,n,{to:r,end:void 0})}function _E(e,t,n){let r=e.blocks.find(e=>e.block.id===t);if(!r||t===n)return null;let i=hE(e,r.key,n);return{draft:i.draft,key:r.key,index:i.index}}function vE(e,t,n,r){return mE(e,t,(e,t)=>{let i=e[n];if(!i)return[e,t];let a={...i,...r};return a.times===void 0&&delete a.times,a.to===void 0&&delete a.to,a.end===void 0&&delete a.end,e[n]=a,[e,t]})}function yE(e,t,n){return mE(lE(e),t,(e,t)=>[e.filter((e,t)=>t!==n),t.filter((e,t)=>t!==n)])}function bE(e,t,n){let r=lE(e);return{...r,blocks:r.blocks.map(e=>e.key===t?{...e,block:{...e.block,at:{x:Math.round(n.x),y:Math.round(n.y)}}}:e)}}function xE(e){let t=new Map(e.frames.map(t=>[t.key,WE(e,t.frame)])),n={...e,blocks:e.blocks.map(e=>({...e,block:{...e.block,at:void 0}}))},r=cE(n),i={...e,blocks:n.blocks.map(e=>({...e,block:{...e.block,at:r(e.block)}}))};return{...i,frames:e.frames.map(e=>{let n=GE(i,t.get(e.key));return n?{...e,frame:{...e.frame,...n}}:e})}}function SE(e,t,n,r){let i=CE(t,n,r);return wf.test(i)?wE(e,i)?`${i} is already there: pick it from the list.`:{file:i}:`${i} is not a name a brief can have.`}function CE(e,t,n){let r=e=>e.trim().replace(/\.md$/i,``).toLowerCase().replace(/[^a-z0-9_.-]+/g,`-`).replace(/^[-.]+|[-.]+$/g,``).slice(0,76);return`${e}/${r(t)||r(n)||`brief`}.md`}var wE=(e,t)=>Object.keys(e.texts).find(e=>e.toLowerCase()===t.toLowerCase());function TE(e,t,n,r,i){let a=CE(t,n,r);if(!wf.test(a))return`${a} is not a name a brief can have.`;let o=new Set(Sf(VT(e)).map(e=>e.toLowerCase()));for(let t=1;t<1e3;t++){let n=t===1?a:a.replace(/\.md$/,`-${t}.md`);if(o.has(n.toLowerCase())||!wf.test(n))continue;let r=wE(e,n);return r?{file:r,texts:e.texts}:{file:n,texts:{...e.texts,[n]:`# ${i}\n\n`}}}return`${a} and the names after it are taken.`}function EE(e,t,n){let r=e.blocks.find(e=>e.key===t)?.block;if(!r)return e;let i=SE(e,`briefs`,n,r.id);return typeof i==`string`?i:fE({...e,texts:{...e.texts,[i.file]:`# ${r.title}\n\n`}},t,{brief:i.file})}function DE(e,t){let{manager:n,...r}=e;return t===void 0?r:{...r,manager:t}}function OE(e){let t=wE(e,df);return t?DE(e,t):DE({...e,texts:{...e.texts,[df]:`# Manager
65
+
66
+ What the manager does between steps:
67
+
68
+ `}},df)}function kE(e,t,n){let r=e.toLowerCase().normalize(`NFKD`).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40)||`sub-step`,i=new Set((t.substeps??[]).filter((e,t)=>t!==n).map(e=>e.id));if(!i.has(r))return r;for(let e=2;;e++)if(!i.has(`${r}-${e}`))return`${r}-${e}`}function AE(e,t,n){return{...e,blocks:e.blocks.map(e=>{if(e.key!==t)return e;let[r,i]=n([...e.block.substeps??[]],[...QT(e)]),{substeps:a,...o}=e.block;return{...e,block:r.length?{...o,substeps:r}:o,subs:i}})}}function jE(e,t,n=`check`){let r=e.blocks.find(e=>e.key===t);if(!r)return{draft:e,index:-1};let i=n===`check`?`Self-review`:`Sub-step`,a={id:kE(i,r.block),kind:n,title:i,when:`done`},o=r.block.substeps?.length??0;return{draft:{...AE(e,t,(t,n)=>[[...t,a],[...n,`n${e.seq}`]]),seq:e.seq+1},index:o}}function ME(e,t,n,r){let i=e.blocks.find(e=>e.key===t),a=i?.block.substeps?.[n];if(!i||!a)return e;let o={...a,...r};for(let e of Object.keys(r))r[e]===void 0&&delete o[e];return QT(i)[n]?.startsWith(`n`)&&r.title!==void 0&&r.id===void 0&&a.id===kE(a.title,i.block,n)&&(o.id=kE(r.title,i.block,n)),AE(e,t,(e,t)=>[e.map((e,t)=>t===n?o:e),t])}function NE(e,t,n,r){let i=n+r;return AE(e,t,(e,t)=>(i<0||i>=e.length||n<0||n>=e.length||([e[n],e[i]]=[e[i],e[n]],[t[n],t[i]]=[t[i],t[n]]),[e,t]))}function PE(e,t,n){return AE(e,t,(e,t)=>[e.filter((e,t)=>t!==n),t.filter((e,t)=>t!==n)])}function FE(e,t,n,r){let i=e.blocks.find(e=>e.key===t)?.block.substeps?.[n];if(!i)return e;let a=SE(e,`briefs`,r,i.id);return typeof a==`string`?a:ME({...e,texts:{...e.texts,[a.file]:`# ${i.title}\n\n`}},t,n,{brief:a.file})}function IE(e,t,n){let r=e.toLowerCase().normalize(`NFKD`).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40)||`overlay`,i=new Set(t.overlays.filter(e=>e.key!==n).map(e=>e.overlay.id));if(!i.has(r))return r;for(let e=2;;e++)if(!i.has(`${r}-${e}`))return`${r}-${e}`}function LE(e,t,n){if(!t.trim())return`An overlay needs a title.`;if(!n.length)return`An overlay amends at least one block: add a block first.`;let r=IE(t,e),i=TE(e,`overlays`,r,`overlay`,t);if(typeof i==`string`)return i;let a=`n${e.seq}`;return{draft:{...e,overlays:[...e.overlays,{key:a,overlay:{id:r,title:t,file:i.file,blocks:n}}],texts:i.texts,seq:e.seq+1},key:a}}function RE(e,t,n){let r=new Map(e.blocks.map((e,t)=>[e.block.id,t]));return{...e,overlays:e.overlays.map(e=>{if(e.key!==t)return e;let i={...e.overlay,...n};return n.blocks&&(i.blocks=[...new Set(n.blocks)].sort((e,t)=>(r.get(e)??1e9)-(r.get(t)??1e9))),{...e,overlay:i}})}}function zE(e,t,n){let r=e.overlays.find(e=>e.key===t)?.overlay;if(!r)return e;let i=r.blocks.includes(n);return i&&r.blocks.length===1?e:RE(e,t,{blocks:i?r.blocks.filter(e=>e!==n):[...r.blocks,n]})}function BE(e,t){return{...e,overlays:e.overlays.filter(e=>e.key!==t)}}function VE(e,t,n){let r=e.overlays.find(e=>e.key===t)?.overlay;if(!r)return e;let i=SE(e,`overlays`,n,r.id);return typeof i==`string`?i:RE({...e,texts:{...e.texts,[i.file]:`# ${r.title}\n\n`}},t,{file:i.file})}function HE(e){let t=new Map;for(let n of e)for(let e of n.blocks){let r=t.get(e);r?r.push(n.title):t.set(e,[n.title])}return t}function UE(e){let t=cE(e);return new Map(e.blocks.map(e=>[e.key,{...e.block.at??t(e.block),...yg(e.block)}]))}function WE(e,t){return[...UE(e)].filter(([,e])=>{let n=e.x+e.width/2,r=e.y+e.height/2;return n>=t.at.x&&n<=t.at.x+t.size.width&&r>=t.at.y&&r<=t.at.y+t.size.height}).map(([e])=>e)}function GE(e,t){let n=[...UE(e)].filter(([e])=>t.includes(e)).map(([,e])=>e);if(!n.length)return null;let r=Math.min(...n.map(e=>e.x))-24,i=Math.min(...n.map(e=>e.y))-24-28,a=Math.max(...n.map(e=>e.x+e.width))+24,o=Math.max(...n.map(e=>e.y+e.height))+24;return{at:{x:Math.round(r),y:Math.round(i)},size:{width:Math.round(a-r),height:Math.round(o-i)}}}function KE(e,t,n){let r=e.toLowerCase().normalize(`NFKD`).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40)||`frame`,i=new Set(t.frames.filter(e=>e.key!==n).map(e=>e.frame.id));if(!i.has(r))return r;for(let e=2;;e++)if(!i.has(`${r}-${e}`))return`${r}-${e}`}function qE(e,t,n){if(!t.trim())return`A frame needs a title.`;let r=e.blocks.length?lE(e):e,i=(`blocks`in n?GE(r,n.blocks):null)??{at:`at`in n?{x:Math.round(n.at.x),y:Math.round(n.at.y)}:{x:0,y:0},size:{width:420,height:260}},a=`n${r.seq}`;return{draft:{...r,frames:[...r.frames,{key:a,frame:{id:KE(t,r),title:t,...i}}],seq:r.seq+1},key:a}}function JE(e,t,n){return{...e,frames:e.frames.map(e=>{if(e.key!==t)return e;let r={...e.frame,...n};for(let e of Object.keys(n))n[e]===void 0&&delete r[e];return n.at&&(r.at={x:Math.round(n.at.x),y:Math.round(n.at.y)}),n.size&&(r.size={width:Math.round(Math.max(40,n.size.width)),height:Math.round(Math.max(40,n.size.height))}),RT(r,e.frame)?e:{...e,frame:r}})}}function YE(e,t){let n=e.frames.find(e=>e.key===t)?.frame;return n?e.frames.filter(e=>e.key!==t&&e.frame.at.x>=n.at.x&&e.frame.at.y>=n.at.y&&e.frame.at.x+e.frame.size.width<=n.at.x+n.size.width&&e.frame.at.y+e.frame.size.height<=n.at.y+n.size.height).map(e=>e.key):[]}function XE(e,t,n,r){let i=e.frames.find(e=>e.key===t)?.frame;if(!i)return e;let a=Math.round(n.x)-i.at.x,o=Math.round(n.y)-i.at.y;if(!a&&!o)return e;let s=lE(e),c=s.blocks.map(e=>r.blocks.includes(e.key)&&e.block.at?{...e,block:{...e.block,at:{x:e.block.at.x+a,y:e.block.at.y+o}}}:e),l=s.frames.map(e=>e.key===t||r.frames.includes(e.key)?{...e,frame:{...e.frame,at:{x:e.frame.at.x+a,y:e.frame.at.y+o}}}:e);return{...s,blocks:c,frames:l}}function ZE(e,t){return{...e,frames:e.frames.filter(e=>e.key!==t)}}var QE=ff;function $E(e,t){return{flows:[{key:`w0`,name:sf,read:e.rawText===null?null:af,base:e,draft:t}],read:[],seq:1}}function eD(e){let t=zT(e);if(!t)return null;let n=[];for(let[r,i]of e.flows.entries()){let a=zT({...e,flow:i.flow,raw:i.raw});if(!a)return null;n.push({key:`w${r+1}`,name:i.name,read:i.file,base:a.base,draft:{...a.draft,texts:t.draft.texts}})}return{flows:[{key:`w0`,name:sf,read:af,...t},...n],read:e.flows.map(e=>e.file),seq:e.flows.length+1}}function tD(e,t,n){let r=e.flows.find(e=>e.key===t);if(!r||r.draft===n)return e;let i=n.texts!==r.draft.texts||n.rules!==r.draft.rules;return{...e,flows:e.flows.map(e=>e.key===t?{...e,draft:n}:i?{...e,draft:{...e.draft,texts:n.texts,rules:n.rules}}:e)}}function nD(e,t,n){let r=e.toLowerCase().normalize(`NFKD`).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40)||`flow`,i=t.flows.find(e=>e.key===n)?.name,a=t.flows.flatMap(e=>e.draft.blocks.flatMap(e=>e.block.kind===`flow`&&e.block.flow!==void 0&&e.block.flow!==i?[e.block.flow]:[])),o=new Set([sf,...a,...t.flows.filter(e=>e.key!==n).map(e=>e.name)]);if(!o.has(r))return r;for(let e=2;;e++)if(!o.has(`${r}-${e}`))return`${r}-${e}`}function rD(e,t,n){return cf.test(`flows/${e}.json`)?e===`main`?`"${sf}" is the default flow's name.`:t.flows.some(t=>t.key!==n&&t.name===e)?`Another flow is "${e}" already.`:null:`Lower case letters, digits and "-" (at most 48), starting with a letter or digit.`}function iD(e,t){if(!t.trim())return`A flow needs a title.`;let n=e.flows[0],r={raw:null,rawText:null,parsed:null,rules:n.base.rules,texts:n.base.texts,versions:n.base.versions,copy:n.base.copy},i=uE({title:t,blocks:[],overlays:[],frames:[],rules:n.draft.rules,texts:n.draft.texts,seq:0},`work`,{x:0,y:0}).draft,a=`w${e.seq}`;return{ws:{...e,flows:[...e.flows,{key:a,name:nD(t,e),autoName:!0,read:null,base:r,draft:i}],seq:e.seq+1},key:a}}function aD(e,t,n,r=!1){let i=e.flows.find(e=>e.key===t);if(!i||i.key===e.flows[0].key||i.name===n&&!!i.autoName===r)return e;let a=e.flows.map(e=>{let a=e.draft;for(let t of e.draft.blocks)t.block.kind===`flow`&&t.block.flow===i.name&&(a=fE(a,t.key,{flow:n}));let o=a===e.draft?e:{...e,draft:a};if(e.key!==t)return o;let{autoName:s,...c}=o;return{...c,name:n,...r?{autoName:r}:{}}});return{...e,flows:a}}function oD(e,t,n){let r=e.flows.find(e=>e.key===t);if(!r)return e;let{title:i,...a}=r.draft,o=tD(e,t,n===void 0?a:{...a,title:n});return r.autoName&&n?.trim()?aD(o,t,nD(n,o,t),!0):o}function sD(e,t){return t===e.flows[0]?.key?e:{...e,flows:e.flows.filter(e=>e.key!==t)}}function cD(e,t){let n=e.flows.map(e=>({f:e,flow:e.draft.blocks.length?ET(tE(e.base,e.draft)).flow:null})),r=new Map(n.map(({f:e,flow:t})=>[e.name,t])),i=jT(r),a=n.map(({f:e,flow:n})=>({f:e,flow:n,own:iE(e.base,e.draft,t,i)})),o=AT(r);return new Map(a.map(({f:t,own:n,flow:r},i)=>[t.key,[...n,...i>0&&r?.manager!==void 0?[{at:`manager`,message:`The manager's file is named by the default flow for all flows: take it out of "${t.draft.title??t.name}".`}]:[],...e.flows.some(e=>e.key!==t.key&&e.name===t.name)?[{at:`name`,message:`Two flows are named "${t.name}": give each its own.`}]:[],...o.get(t.name)??[]]]))}function lD(e){return e.flows.some(e=>aE(e.base,e.draft))}function uD(e,t,n){let r=e.blocks.find(e=>e.key===t);if(!r)return e;let i=new Set((r.block.outcomes??[]).map(e=>e.word.trim().toLowerCase())),a=e;for(let e of n)i.has(e.trim().toLowerCase())||(a=hE(a,t,void 0,e).draft);return a}function dD(){let[e,t]=(0,d.useState)(()=>typeof matchMedia==`function`&&matchMedia(`(max-width: 760px)`).matches);return(0,d.useEffect)(()=>{if(typeof matchMedia!=`function`)return;let e=matchMedia(s),n=()=>t(e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}var fD={top:22};function pD({data:e}){let t=e.block,n=Mg(t,()=>e.continuesTitle??t.continues??``),r=yg(t),i=t.outcomes??[];return(0,f.jsxs)(`div`,{className:`flow-block kind-${t.kind}${e.selected?` selected`:``}${e.problem?` has-problem`:``}${e.marked?` marked`:``}`,style:{width:r.width,minHeight:r.height},title:e.hasBrief?`Open its brief`:`Show this block`,children:[(0,f.jsx)(Ll,{type:`target`,position:U.Top,id:`t`,className:`h-in`}),(0,f.jsx)(Ll,{type:`source`,position:U.Bottom,id:`b`,className:`h-pass`,title:`Drag to a block: a new outcome that leads there; its word is asked for`}),(0,f.jsx)(Ll,{type:`target`,position:U.Right,id:`rt`,className:`h-hidden`,style:fD}),(0,f.jsx)(Ll,{type:`source`,position:U.Right,id:`rs`,className:`h-hidden`,style:fD}),(0,f.jsx)(Ll,{type:`target`,position:U.Left,id:`lt`,className:`h-hidden`,style:fD}),(0,f.jsx)(Ll,{type:`source`,position:U.Left,id:`ls`,className:`h-hidden`,style:fD}),(0,f.jsxs)(`div`,{className:`flow-block-top`,children:[(0,f.jsxs)(`span`,{className:`flow-kind`,children:[e.start?`▶ `:``,Ag[t.kind]]}),e.onAddOutcome&&(0,f.jsx)(`button`,{className:`flow-add-pin nodrag`,onClick:t=>{t.stopPropagation(),e.onAddOutcome()},title:`Add an outcome: name it in the panel, then drag its pin to the block it leads to`,"aria-label":`Add an outcome to ${t.title}`,children:`+ outcome`})]}),(0,f.jsx)(`div`,{className:`flow-block-title`,children:t.title}),n&&(0,f.jsx)(`div`,{className:`flow-block-actor`,children:n}),e.runsFlow&&(0,f.jsxs)(`div`,{className:`flow-block-actor flow-block-runs`,children:[`▸ `,e.runsFlow]}),!!t.substeps?.length&&(0,f.jsx)(`ol`,{className:`flow-substeps`,children:t.substeps.map((e,n)=>{let r=vg(t,e);return(0,f.jsxs)(`li`,{className:`flow-substep kind-${e.kind}`,title:[r.head,r.detail,r.outcomes,r.note].filter(Boolean).join(` · `),children:[(0,f.jsx)(`span`,{className:`flow-substep-head`,children:r.head}),(0,f.jsx)(`span`,{className:`flow-substep-detail`,children:r.detail}),r.outcomes&&(0,f.jsx)(`span`,{className:`flow-substep-detail`,children:r.outcomes}),r.note&&(0,f.jsx)(`span`,{className:`flow-substep-note`,children:r.note})]},n)})}),(!!t.brief||!!e.overlays?.length)&&(0,f.jsxs)(`div`,{className:`flow-block-foot`,children:[t.brief&&(0,f.jsxs)(`span`,{className:`flow-block-brief${e.hasBrief?``:` missing`}`,children:[`📄 `,mg(t.brief),`.md`]}),!!e.overlays?.length&&(0,f.jsxs)(`span`,{className:`flow-block-overlays`,title:`Amended by ${e.overlays.join(`, `)}`,children:[`◇ `,e.overlays.length===1?`overlay`:`${e.overlays.length} overlays`]})]}),i.length>0&&(0,f.jsx)(`ol`,{className:`flow-pins`,"aria-label":`Outcomes`,children:i.map((t,n)=>{let r=t.word.trim()?vf(t):`(its word?)`;return(0,f.jsxs)(`li`,{className:`flow-pin${t.to===void 0&&!t.end?` loose`:``}${t.end?` ends`:``}${t.times?` counted`:``}${e.focusOutcome===n?` chosen`:``}`,title:t.end?`${r}: ends the flow`:t.to===void 0?`${r}: leads nowhere yet; drag its dot to a block`:r,children:[(0,f.jsx)(`span`,{className:`flow-pin-word`,children:r}),t.end&&(0,f.jsx)(`span`,{className:`flow-pin-end`,children:`■ end`}),(0,f.jsx)(Ll,{type:`source`,position:U.Right,id:`o${n}`,className:`h-pin`})]},n)})})]})}function mD(e){if(!e.colour)return;let t=c[e.colour];return{"--name-light":t.light,"--name-dark":t.dark}}function hD({data:e}){let t=e.frame;return(0,f.jsxs)(`div`,{className:`flow-frame${t.colour?` coloured`:``}${e.selected?` selected`:``}`,style:mD(t),children:[e.editable&&(0,f.jsx)(rf,{isVisible:!!e.selected,minWidth:120,minHeight:80,color:`var(--accent)`,onResize:(t,n)=>e.onResize?.(n),onResizeEnd:(t,n)=>e.onResizeEnd?.(n)}),(0,f.jsx)(`div`,{className:`flow-frame-title`,title:e.editable?`Drag to move the frame and the blocks in it; click to change it`:t.title,children:t.title})]})}var gD={block:pD,frame:hD};function _D({text:e,at:t}){return!e||!t?null:(0,f.jsx)(vd,{children:(0,f.jsx)(`div`,{className:`flow-edge-label`,style:{transform:`translate(-50%, -50%) translate(${t.x}px, ${t.y}px)`},children:e})})}function vD({id:e,source:t,data:n,markerEnd:r,interactionWidth:i,sourceX:a,sourceY:o}){let s=yd(t);if(!n)return null;let c=s?.measured.height===void 0?void 0:s.internals.positionAbsolute.y+s.measured.height;return(0,f.jsx)(_u,{id:e,path:Eg(Tg({x:a,y:o},n.offset,n.route,c)),markerEnd:r,interactionWidth:i})}function yD({id:e,data:t,markerEnd:n,interactionWidth:r,sourceX:i,sourceY:a,targetX:o,targetY:s,sourcePosition:c,targetPosition:l}){let[u,d,p]=Po({sourceX:i,sourceY:a,targetX:o,targetY:s,sourcePosition:c,targetPosition:l,...t?.offset?{offset:t.offset}:{}});return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(_u,{id:e,path:u,markerEnd:n,interactionWidth:r}),(0,f.jsx)(_D,{text:t?.text??null,at:t?.labelAt??{x:d,y:p}})]})}var bD={routed:vD,stepped:yD};function xD(e,t){let n=e.filter(e=>e.type===`block`),r=new Map(n.map(e=>[e.id,{...e.position,...yg(e.data.block)}])),i=new Map(n.map(e=>[e.id,e.data.block.outcomes?.length??0])),a=e=>e.data?.text??null,o=Bg(r,t.map(e=>({id:e.id,source:e.source,target:e.target,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle,text:a(e),pins:i.get(e.source)??0})));return t.map(e=>o.has(e.id)?{...e,data:{...e.data,labelAt:o.get(e.id)}}:e)}var SD={way:`var(--muted)`,back:`var(--muted)`,counted:`var(--warn-border)`,continue:`var(--accent)`};function CD(e,t){return e&&t&&t.x<e.x?[`ls`,`rt`]:[`rs`,`lt`]}function wD(e,t,n,r){let[i,a]=(0,d.useState)(null);return(0,d.useLayoutEffect)(()=>{if(i||!e.current)return;let{width:o,height:s}=e.current.getBoundingClientRect();a(Fg(t,n,o,s,r))}),i}function TD(){let[e,t]=(0,d.useState)({});return[e,e=>{let n=e.flatMap(e=>e.type===`dimensions`&&e.dimensions?[[e.id,e.dimensions]]:[]);return n.length&&t(e=>n.every(([t,n])=>e[t]?.width===n.width&&e[t]?.height===n.height)?e:{...e,...Object.fromEntries(n)}),e.filter(e=>e.type!==`dimensions`)}]}var ED={work:`var(--accent)`,check:`var(--s3)`,person:`var(--dot-waiting)`,timer:`var(--s7)`,fork:`var(--s5)`,join:`var(--s5)`};function DD({small:e=!1}){return(0,f.jsx)(Qd,{className:`flow-minimap`,pannable:!0,zoomable:!0,maskStrokeColor:`var(--accent)`,maskStrokeWidth:2,...e?{style:{width:120,height:90}}:{},nodeColor:e=>e.type===`frame`?`transparent`:ED[e.data.block.kind]??`var(--muted)`,nodeStrokeColor:e=>e.type===`frame`?`var(--border)`:`transparent`,nodeBorderRadius:4,ariaLabel:`Map of the whole flow`})}function OD(e,t,n={},r){return{id:e,type:`frame`,zIndex:n.selected?1e3:-1,dragHandle:`.flow-frame-title`,draggable:!!n.editable,connectable:!1,position:r?{x:r.x,y:r.y}:t.at,width:r?.width??t.size.width,height:r?.height??t.size.height,data:{frame:t,...n}}}function kD({flows:e,shown:t,onShow:n,children:r}){return e.length<2&&!r?null:(0,f.jsxs)(`div`,{className:`flow-tabs`,role:`tablist`,"aria-label":`Flows`,children:[e.map(e=>(0,f.jsxs)(`button`,{role:`tab`,"aria-selected":e.name===t,className:`flow-tab${e.name===t?` on`:``}`,onClick:()=>n(e.name),title:e.name===`main`?`${af}: the default flow`:`flows/${e.name}.json`,children:[e.title,e.bad>0&&(0,f.jsxs)(`span`,{className:`flow-tab-bad`,children:[`⚠ `,e.bad]})]},e.name)),r]})}var AD={work:`a step someone does`,check:`a yes or no`,person:`a person decides`,fork:`split into parallel work`,join:`wait for all of it`,timer:`starts on a count or clock`,flow:`another flow, its end the outcome`},jD={manager:`the manager`,person:`a person`,"new-session":`a new session`,continue:`an earlier block's session`},MD=[`opus`,`sonnet`,`haiku`,`fable`],ND=`application/x-ledung-block`,PD=`(end)`,FD=`frame`,ID=e=>`frame:${e}`,LD=e=>/^blocks\.([a-z0-9][a-z0-9-]*)/.exec(e.at)?.[1]??null;function RD({project:e,view:n,initial:r,shown:i,onShowFlow:a,onRenamedFlow:o,profiles:s,narrow:c,onCancel:u,onSaved:p}){let[m,h]=(0,d.useState)({past:[],present:r,future:[],group:null}),g=m.present,[_,v]=(0,d.useState)(()=>r.flows.find(e=>e.name===i)?.key??r.flows[0].key),y=g.flows.find(e=>e.key===_)??g.flows[0],b=y.draft,x=(e,t)=>h(n=>e===n.present?n:t&&t===n.group?{...n,present:e}:{past:[...n.past,n.present].slice(-200),present:e,future:[],group:t??null}),S=(e,t)=>x(tD(g,y.key,e),t&&`${y.key}:${t}`),C=()=>h(e=>e.past.length?{past:e.past.slice(0,-1),present:e.past[e.past.length-1],future:[e.present,...e.future],group:null}:e),w=()=>h(e=>e.future.length?{past:[...e.past,e.present],present:e.future[0],future:e.future.slice(1),group:null}:e),[T,E]=(0,d.useState)(null);(0,d.useEffect)(()=>{g.flows.some(e=>e.key===_)||(v(g.flows[0].key),E(null))},[g,_]);let[D,O]=(0,d.useState)(null),[k,A]=(0,d.useState)(!1),[j,M]=(0,d.useState)(null),[N,P]=(0,d.useState)(!0),F=(0,d.useMemo)(()=>cD(g,s),[g,s]),I=F.get(y.key)??[],L=(0,d.useMemo)(()=>I.filter(e=>!e.hint),[I]),R=(0,d.useMemo)(()=>I.filter(e=>e.hint),[I]),z=(0,d.useMemo)(()=>[...F.values()].reduce((e,t)=>e+t.filter(e=>!e.hint).length,0),[F]),B=(0,d.useMemo)(()=>rE(g),[g]),V=(0,d.useMemo)(()=>lD(g),[g]),H=B.length>0,ee=(0,d.useMemo)(()=>g.flows.map(e=>({name:e.name,title:e.draft.title??e.name,endings:e.draft.blocks.length?yf(VT(e.draft)):[]})),[g]),te=e=>{E(null),e!==y.name&&a(e)},ne=e=>{g.flows.some(t=>t.name===e)&&te(e)},[re,ie]=(0,d.useState)(null),ae=(0,d.useRef)(g);ae.current=g,(0,d.useEffect)(()=>{let e=ae.current.flows.find(e=>e.name===i)?.key??ae.current.flows[0].key;v(t=>(t!==e&&E(null),e)),ie(null),O(e=>e===`leave`?null:e)},[i]);let oe=(0,d.useRef)({key:y.key,name:y.name});(0,d.useEffect)(()=>{if(oe.current.key!==y.key){oe.current={key:y.key,name:y.name};return}if(oe.current.name===y.name)return;let e=oe.current.name,t=setTimeout(()=>{i===e&&o(y.name),oe.current={key:y.key,name:y.name}},400);return()=>clearTimeout(t)},[y.key,y.name,i]),(0,d.useEffect)(()=>{if(H)return l({project:e,ask:e=>{ie(()=>e),O(`leave`)}}),()=>l(null)},[H,e]);let se=T?.kind===`block`?b.blocks.find(e=>e.key===T.key)??null:null,ce=T?.kind===`manager`&&b.manager!==void 0,le=T?.kind===`overlay`?b.overlays.find(e=>e.key===T.key)??null:null,ue=T?.kind===`frame`?b.frames.find(e=>e.key===T.key)??null:null;(0,d.useEffect)(()=>{T&&!se&&!ce&&!le&&!ue&&E(null)},[T,se,ce,le,ue]);let de=()=>{if(!c){if(se)S(pE(b,[se.key]));else if(ue)S(ZE(b,ue.key));else return;E(null)}},fe=e=>{let t=lE(b).blocks.map(e=>({...e.block.at,height:yg(e.block).height})),n={x:Math.min(0,...t.map(e=>e.x)),y:Math.max(0,...t.map(e=>e.y+e.height))+60},r=qE(b,`New frame`,e?{at:e}:se?{blocks:[se.key]}:{at:n});typeof r!=`string`&&(S(r.draft),E({kind:`frame`,key:r.key}))},pe=(0,d.useRef)({undo:C,redo:w,removeSelected:de});pe.current={undo:C,redo:w,removeSelected:()=>!D&&de()},(0,d.useEffect)(()=>{let e=e=>{let t=e.target;if(t&&t.closest(`input, textarea, select, [contenteditable="true"]`))return;let n=!t||t===document.body||!!t.closest(`.react-flow`),r=e.ctrlKey||e.metaKey;r&&e.key.toLowerCase()===`z`?(e.preventDefault(),e.shiftKey?pe.current.redo():pe.current.undo()):r&&e.key.toLowerCase()===`y`?(e.preventDefault(),pe.current.redo()):(e.key===`Delete`||e.key===`Backspace`)&&n&&pe.current.removeSelected()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,d.useEffect)(()=>{if(!H)return;let e=e=>e.preventDefault();return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[H]);let me=async n=>{if(M(null),V){let e=g.flows.find(e=>!e.draft.blocks.length);M(e?`A flow needs at least one block before it can be saved ("${e.draft.title??e.name}").`:`A flow would not be a flow, so it can't be saved: fix the problems marked as the file's own (an empty title or word, an id that isn't lower case) in the flow whose tab has them.`)}else if(z&&!n)O(`save`);else{O(null),A(!0);try{p(await t.saveFlow(e,B),B.length,y.name)}catch(e){M(e.message)}finally{A(!1)}}},he=()=>{let e=r.flows.find(e=>e.key===y.key)?.name??`main`;e!==i&&o(e),u()},ge=()=>H?O(`leave`):he(),_e=n.saveTo??``,ve=(0,f.jsxs)(`div`,{className:`muted flow-where`,children:[`Saves into this project's own folder, `,(0,f.jsx)(`code`,{children:_e}),`; never into a shared workflow's folder.`,y.base.copy&&n.source?.workflow&&(0,f.jsxs)(f.Fragment,{children:[` This flow is the shared workflow "`,n.source.workflow,`"'s: saving makes a copy of it, with its other flows, briefs and rules, that counts for `,e,` from then on; the shared one is not changed.`]})]}),ye=L.length>0&&(0,f.jsxs)(`div`,{className:`flow-problems`,role:`status`,children:[(0,f.jsxs)(`button`,{className:`link`,onClick:()=>P(e=>!e),"aria-expanded":N,children:[(0,f.jsxs)(`strong`,{children:[L.length===1?`One problem`:`${L.length} problems`,` so far`]}),` `,N?`▾`:`▸`]}),N&&(0,f.jsx)(`ul`,{children:L.map((e,t)=>{let n=LD(e),r=n?b.blocks.find(e=>e.block.id===n):void 0;return(0,f.jsxs)(`li`,{children:[r?(0,f.jsx)(`button`,{className:`link`,onClick:()=>E({kind:`block`,key:r.key}),children:(0,f.jsx)(`code`,{children:e.at})}):(0,f.jsx)(`code`,{children:e.at}),` `,e.message]},t)})})]}),be=R.length>0&&(0,f.jsxs)(`details`,{className:`flow-hints`,children:[(0,f.jsx)(`summary`,{children:R.length===1?`One hint`:`${R.length} hints`}),(0,f.jsx)(`ul`,{children:R.map((e,t)=>{let n=LD(e),r=n?b.blocks.find(e=>e.block.id===n):void 0;return(0,f.jsxs)(`li`,{children:[r?(0,f.jsx)(`button`,{className:`link`,onClick:()=>E({kind:`block`,key:r.key}),children:(0,f.jsx)(`code`,{children:e.at})}):(0,f.jsx)(`code`,{children:e.at}),` `,e.message]},t)})})]}),xe=()=>E(null),Se=se?(0,f.jsx)(UD,{draft:b,entry:se,focus:T?.outcome,naming:T?.naming,profiles:s,narrow:c,commit:S,onDelete:de,onClose:xe,onSelect:E,choices:ee.filter(e=>e.name!==y.name),onOpenFlow:ne},`${y.key}:${se.key}`):ce?(0,f.jsx)(eO,{draft:b,narrow:c,commit:S,onClose:xe,onSelect:E}):le?(0,f.jsx)(tO,{draft:b,overlayKey:le.key,narrow:c,commit:S,onClose:xe}):ue?(0,f.jsx)(QD,{draft:b,frameKey:ue.key,narrow:c,commit:S,onClose:xe,onSelect:E},ue.key):(0,f.jsx)($D,{draft:b,commit:S,narrow:c,onSelect:E,ws:g,flow:y,commitWs:x,onDeleted:()=>{E(null),o(sf)}},y.key);return(0,f.jsxs)(`div`,{className:`page-view workflow-view flow-builder${c?` narrow`:``}`,children:[(0,f.jsxs)(`header`,{className:`session-head`,children:[(0,f.jsxs)(`div`,{className:`session-head-text`,children:[(0,f.jsxs)(`h2`,{children:[e,`: editing the workflow`,b.title?` · ${b.title}`:``]}),ve]}),(0,f.jsxs)(`div`,{className:`session-corner flow-tools`,children:[(0,f.jsx)(`button`,{className:`small`,onClick:C,disabled:!m.past.length,title:`Undo (Ctrl+Z)`,children:`↶ Undo`}),(0,f.jsx)(`button`,{className:`small`,onClick:w,disabled:!m.future.length,title:`Redo (Ctrl+Shift+Z)`,children:`↷ Redo`}),!c&&(0,f.jsx)(`button`,{className:`small`,onClick:()=>S(xE(b)),disabled:!b.blocks.length,title:`Lay the blocks out top to bottom`,children:`Auto-arrange`}),!c&&(0,f.jsx)(`button`,{className:`small`,onClick:de,disabled:!se&&!ue,title:`Delete the selected block or frame (Delete); an arrow is an outcome, taken out in its block's panel`,children:`Delete`}),(0,f.jsx)(`span`,{className:`flow-check-count${z?` bad`:``}`,title:g.flows.length>1?`In all the flows`:void 0,children:z?`⚠ ${z}`:`✓ No problems`}),(0,f.jsx)(`button`,{className:`small primary`,onClick:()=>me(!1),disabled:k||!H,title:H?`Write the files into the project folder`:`Nothing has changed`,children:k?`Saving…`:`Save`}),(0,f.jsx)(`button`,{className:`small`,onClick:ge,disabled:k,children:`Cancel`})]})]}),D===`save`&&(0,f.jsxs)(`div`,{className:`flow-confirm`,role:`alertdialog`,children:[(0,f.jsxs)(`span`,{children:[`The workflow has `,z===1?`a problem`:`${z} problems`,` (`,g.flows.length>1?`each listed under its flow's tab`:`listed below`,`). Save it as a draft anyway? It is saved as it is, and the problems show on the workflow page until they are fixed.`]}),(0,f.jsxs)(`span`,{className:`flow-confirm-buttons`,children:[(0,f.jsx)(`button`,{className:`small primary`,onClick:()=>me(!0),children:`Save anyway`}),(0,f.jsx)(`button`,{className:`small`,onClick:()=>O(null),children:`Keep editing`})]})]}),D===`leave`&&(0,f.jsxs)(`div`,{className:`flow-confirm`,role:`alertdialog`,children:[(0,f.jsx)(`span`,{children:`Leave without saving? The changes made here are lost.`}),(0,f.jsxs)(`span`,{className:`flow-confirm-buttons`,children:[(0,f.jsx)(`button`,{className:`small deny`,onClick:()=>re?re():he(),children:`Discard changes`}),(0,f.jsx)(`button`,{className:`small`,onClick:()=>{O(null),ie(null)},children:`Keep editing`})]})]}),j&&(0,f.jsxs)(`div`,{className:`flow-confirm flow-error`,role:`alert`,children:[(0,f.jsx)(`span`,{children:j}),(0,f.jsx)(`span`,{className:`flow-confirm-buttons`,children:(0,f.jsx)(`button`,{className:`small`,onClick:()=>M(null),children:`OK`})})]}),(0,f.jsx)(kD,{flows:g.flows.map(e=>({name:e.key,title:e.draft.title||e.name,bad:(F.get(e.key)??[]).filter(e=>!e.hint).length})),shown:y.key,onShow:e=>te(g.flows.find(t=>t.key===e)?.name??y.name),children:!c&&(0,f.jsx)(GD,{onAdd:e=>{let t=iD(g,e);return typeof t==`string`?t:(x(t.ws),te(t.ws.flows.find(e=>e.key===t.key).name),null)}})}),ye,be,c?(0,f.jsx)(`div`,{className:`flow-main`,children:T?(0,f.jsx)(`aside`,{className:`flow-panel`,children:Se}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(VD,{draft:b,problems:L,choices:ee,onSelect:e=>E({kind:`block`,key:e})}),(0,f.jsx)(`aside`,{className:`flow-panel`,children:Se})]})}):(0,f.jsxs)(`div`,{className:`flow-main flow-main-edit`,children:[(0,f.jsx)(zD,{onAdd:(e,t)=>{let n=uE(b,e,t,ee.find(e=>e.name!==y.name)?.name);S(n.draft),E({kind:`block`,key:n.key})},onFrame:()=>fe()}),(0,f.jsx)(fd,{children:(0,f.jsx)(BD,{draft:b,selection:T,problems:L,commit:S,onSelect:E,onFrame:fe,choices:ee},y.key)}),(0,f.jsx)(`aside`,{className:`flow-panel`,children:Se})]})]})}function zD({onAdd:e,onFrame:t}){return(0,f.jsxs)(`div`,{className:`flow-palette`,"aria-label":`Blocks`,children:[(0,f.jsx)(`div`,{className:`muted flow-palette-head`,children:`Drag onto the canvas`}),QE.map(t=>(0,f.jsxs)(`button`,{className:`flow-palette-item kind-${t}`,draggable:!0,onDragStart:e=>{e.dataTransfer.setData(ND,t),e.dataTransfer.effectAllowed=`copy`},onClick:()=>e(t),title:`Add a ${Ag[t].toLowerCase()} block (or drag it where it goes)`,children:[(0,f.jsx)(`span`,{className:`flow-kind`,children:Ag[t]}),(0,f.jsx)(`span`,{className:`flow-palette-hint`,children:AD[t]})]},t)),(0,f.jsxs)(`button`,{className:`flow-palette-item flow-palette-frame`,draggable:!0,onDragStart:e=>{e.dataTransfer.setData(ND,FD),e.dataTransfer.effectAllowed=`copy`},onClick:t,title:`Add a comment frame round the chosen block (or drag it where it goes)`,children:[(0,f.jsx)(`span`,{className:`flow-kind`,children:`Frame`}),(0,f.jsx)(`span`,{className:`flow-palette-hint`,children:`a titled group of blocks`})]}),(0,f.jsxs)(`div`,{className:`muted flow-palette-help`,children:[`Each `,(0,f.jsx)(`strong`,{children:`outcome`}),` is a pin on its block's right edge: drag the pin to the block it leads to. `,(0,f.jsx)(`strong`,{children:`+ outcome`}),` on a block names a new one. Dragging a block's `,(0,f.jsx)(`strong`,{children:`bottom`}),` dot to another block adds one too, and the panel asks for its word. A count ("× 3": where the 3rd one goes) is set in the panel.`]})]})}function BD({draft:e,selection:t,problems:n,commit:r,onSelect:i,onFrame:a,choices:o}){let s=e=>o.find(t=>t.name===e)?.title,c=ul(),l=(0,d.useRef)(null),[u,p]=(0,d.useState)({}),[m,h]=(0,d.useState)({}),g=(0,d.useRef)(null),[_,v]=TD(),y=(0,d.useMemo)(()=>e.blocks.length?Cg(VT(e)):null,[e]),b=(0,d.useMemo)(()=>new Set(n.map(LD).filter(e=>!!e)),[n]),x=e.start??e.blocks[0]?.block.id,S=(0,d.useMemo)(()=>HE(e.overlays.map(e=>e.overlay)),[e.overlays]),C=t?.kind===`overlay`?e.overlays.find(e=>e.key===t.key)?.overlay:void 0,w=new Map(y?.blocks.map(e=>[e.block,e])??[]),T=new Map;for(let t of e.blocks)T.has(t.block.id)||T.set(t.block.id,t.key);let E=new Map(e.blocks.map(e=>[e.key,e.block.id])),D=t=>e.blocks.find(e=>e.block.id===t)?.block.title??t,O=e=>t?.kind===`block`&&t.key===e.key&&t.outcome!==void 0&&t.outcome<(e.block.outcomes?.length??0)?t.outcome:void 0,k=e.blocks.map((n,r)=>{let a=w.get(n.block),o=O(n);return{id:n.key,type:`block`,..._[n.key]?{measured:_[n.key]}:{},position:u[n.key]??(a?{x:a.x,y:a.y}:n.block.at??{x:0,y:r*120}),data:{block:n.block,hasBrief:!!n.block.brief&&e.texts[n.block.brief]!==void 0,selected:t?.kind===`block`&&t.key===n.key,problem:b.has(n.block.id),start:n.block.id===x,overlays:S.get(n.block.id),marked:!!C?.blocks.includes(n.block.id),...n.block.continues?{continuesTitle:D(n.block.continues)}:{},...o===void 0?{}:{focusOutcome:o},runsFlow:jg(n.block,s),onAddOutcome:()=>i({kind:`block`,key:n.key,naming:Date.now()})}}}),A=[...e.frames.map(n=>OD(ID(n.key),n.frame,{editable:!0,selected:t?.kind===`frame`&&t.key===n.key,onResize:e=>h(t=>({...t,[n.key]:e})),onResizeEnd:t=>{r(JE(e,n.key,{at:{x:t.x,y:t.y},size:{width:t.width,height:t.height}})),h(({[n.key]:e,...t})=>t)}},m[n.key]??u[ID(n.key)])),...k],j=(e,t,n)=>y?.arrows.find(r=>r.kind!==`continue`&&r.from===e&&r.index===t&&r.to===n),M=new Map(k.map(e=>[e.id,e.position])),N=(e,t,n,r,i,a,o,s)=>{let c=T.get(t),l=T.get(n);if(!c||!l)return null;let[u,d,f]=i;return{id:e,source:c,target:l,sourceHandle:u,targetHandle:d,className:`flow-arrow arrow-${r}${o?` chosen`:``}`,interactionWidth:18,markerEnd:{type:_a.ArrowClosed,width:16,height:16,color:o?`var(--accent)`:SD[r]},...s&&f!==void 0?{type:`routed`,data:{route:s,offset:f}}:{type:`stepped`,data:{text:a,...f?{offset:f}:{}}}}},P=xD(A,[...e.blocks.filter(e=>T.get(e.block.id)===e.key).flatMap(e=>(e.block.outcomes??[]).map((n,r)=>{if(n.to===void 0)return null;let i=n.to===e.block.id?void 0:j(e.block.id,r,n.to),a=i?.kind??(n.times?`counted`:`way`),o=O(e),s=t?.kind===`block`&&t.key===e.key&&(o===void 0||o===r);return N(`out:${e.key}:${r}`,e.block.id,n.to,a,Lg(a,r,e.block.outcomes.length),null,s,i?.route)})),...e.blocks.flatMap(e=>{if(e.block.runs!==`continue`||!e.block.continues||e.block.continues===e.block.id)return[];let n=T.get(e.block.continues);return[N(`continue:${e.key}`,e.block.continues,e.block.id,`continue`,CD(n?M.get(n):void 0,M.get(e.key)),`same session`,t?.kind===`block`&&t.key===e.key)]})].filter(e=>e!==null)),F=(t,n,i)=>{let a=e.frames.find(e=>e.key===t)?.frame;if(!a)return;if(!g.current||g.current.key!==t){let n={blocks:WE(e,a),frames:YE(e,t)},r={...Object.fromEntries(n.blocks.map(e=>[e,M.get(e)??{x:0,y:0}])),...Object.fromEntries(n.frames.map(t=>[ID(t),e.frames.find(e=>e.key===t).frame.at]))};g.current={key:t,held:n,from:a.at,starts:r}}let o=g.current,s=n??u[ID(t)];if(i){s&&r(XE(e,t,s,o.held)),g.current=null,p(e=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==ID(t)&&!(e in o.starts))));return}if(!s)return;let c=s.x-o.from.x,l=s.y-o.from.y;p(e=>({...e,[ID(t)]:s,...Object.fromEntries(Object.entries(o.starts).map(([e,t])=>[e,{x:t.x+c,y:t.y+l}]))}))},I=t=>{let n=v(t);for(let t of n)if(t.type===`position`){if(t.id.startsWith(`frame:`))t.dragging===!0?F(t.id.slice(6),t.position,!1):t.dragging===!1&&F(t.id.slice(6),t.position,!0);else if(t.dragging&&t.position){let e=t.position;p(n=>({...n,[t.id]:e}))}else if(!t.dragging){let n=t.position??u[t.id];n&&r(bE(e,t.id,n)),p(e=>{let{[t.id]:n,...r}=e;return r})}}},L=t=>{let n=E.get(t.source),a=E.get(t.target);if(!n||!a)return;let o=/^o(\d+)$/.exec(t.sourceHandle??``);if(o){let n=Number(o[1]);r(gE(e,t.source,n,a)),i({kind:`block`,key:t.source,outcome:n});return}let s=_E(e,n,a);s&&(r(s.draft),i({kind:`block`,key:s.key,outcome:s.index}))},R=t=>{let n=t.dataTransfer.getData(ND);if(n===FD){t.preventDefault(),a(c.screenToFlowPosition({x:t.clientX,y:t.clientY}));return}if(!ff.includes(n))return;t.preventDefault();let o=c.screenToFlowPosition({x:t.clientX,y:t.clientY}),s=uE(e,n,{x:o.x-105,y:o.y-39});r(s.draft),i({kind:`block`,key:s.key})},z=wD(l,[...k.map(e=>({...e.position,...yg(e.data.block)})),...e.frames.map(e=>({...e.frame.at,...e.frame.size}))],k.find(e=>e.data.start)?.position,{padding:.2,minZoom:.5});return(0,f.jsxs)(`div`,{className:`flow-canvas`,ref:l,onDragOver:e=>{e.dataTransfer.types.includes(ND)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDrop:R,children:[!e.blocks.length&&(0,f.jsx)(`div`,{className:`flow-canvas-empty muted`,children:`Drag a block here from the left, or click one there.`}),z&&(0,f.jsxs)(gd,{nodes:A,edges:P,nodeTypes:gD,edgeTypes:bD,minZoom:.2,maxZoom:2,...z.fit?{fitView:!0,fitViewOptions:{padding:.2}}:{defaultViewport:z},nodesDraggable:!0,nodesConnectable:!0,elementsSelectable:!1,edgesFocusable:!1,deleteKeyCode:null,connectionRadius:40,isValidConnection:e=>e.source!==e.target&&!e.source.startsWith(`frame:`)&&!e.target.startsWith(`frame:`),onNodesChange:I,onConnect:L,onNodeClick:(e,t)=>i(t.type===`frame`?{kind:`frame`,key:t.id.slice(6)}:{kind:`block`,key:t.id}),onEdgeClick:(e,t)=>{let[n,r,a]=t.id.split(`:`);i({kind:`block`,key:r,...n===`out`?{outcome:Number(a)}:{}})},onPaneClick:()=>i(null),children:[(0,f.jsx)(Ed,{gap:24}),(0,f.jsx)(Fd,{showInteractive:!1}),!z.fit&&(0,f.jsx)(DD,{})]})]})}function VD({draft:e,problems:t,choices:n,onSelect:r}){let i=new Set(t.map(LD)),a=t=>e.blocks.find(e=>e.block.id===t)?.block.title??t,o=e=>n.find(t=>t.name===e)?.title;return(0,f.jsx)(`ol`,{className:`flow-list`,children:e.blocks.map(e=>(0,f.jsx)(`li`,{children:(0,f.jsxs)(`button`,{className:`flow-list-item kind-${e.block.kind}${i.has(e.block.id)?` has-problem`:``}`,onClick:()=>r(e.key),children:[(0,f.jsx)(`span`,{className:`flow-block-top`,children:(0,f.jsx)(`span`,{className:`flow-kind`,children:Ag[e.block.kind]})}),(0,f.jsx)(`span`,{className:`flow-block-title`,children:e.block.title}),Mg(e.block,a)&&(0,f.jsx)(`span`,{className:`flow-block-actor`,children:Mg(e.block,a)}),jg(e.block,o)&&(0,f.jsxs)(`span`,{className:`flow-block-actor flow-block-runs`,children:[`▸ `,jg(e.block,o)]}),!!e.block.substeps?.length&&(0,f.jsx)(`span`,{className:`flow-list-substep`,children:e.block.substeps.length===1?`one sub-step`:`${e.block.substeps.length} sub-steps`})]})},e.key))})}function $({label:e,children:t,hint:n}){return(0,f.jsxs)(`label`,{className:`flow-field`,children:[(0,f.jsx)(`span`,{className:`flow-field-label`,children:e}),t,n&&(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:n})]})}var HD=e=>e===``?void 0:e;function UD({draft:e,entry:t,focus:n,naming:r,profiles:i,narrow:a,commit:s,onDelete:c,onClose:l,onSelect:u,choices:p,onOpenFlow:m}){let h=t.block,g=o(),_=t.key,v=(t,n)=>s(fE(e,_,t),n&&`${n}:${_}`),y=e.blocks.filter(e=>e.key!==_),[b,x]=(0,d.useState)(h.id),[S,C]=(0,d.useState)(null);(0,d.useEffect)(()=>{x(h.id),C(null)},[h.id,_]);let w=()=>{b!==h.id&&(/^[a-z0-9][a-z0-9-]{0,47}$/.test(b)?y.some(e=>e.block.id===b)?C(`Another block is "${b}" already.`):(C(null),v({id:b})):C(`Lower case letters, digits and "-" (at most 48), starting with a letter or digit.`))},T=Object.keys(e.texts).filter(e=>e.startsWith(`briefs/`)).sort(),[E,D]=(0,d.useState)(``),[O,k]=(0,d.useState)(null),A=h.brief?e.texts[h.brief]:void 0,j=h.timer&&`every`in h.timer?`every`:`clock`,M=(e.start??e.blocks[0]?.block.id)===h.id,N=y.filter(e=>Cf(e.block));return(0,f.jsxs)(`div`,{className:`flow-panel-body flow-fields`,children:[(0,f.jsxs)(`div`,{className:`flow-panel-head`,children:[(0,f.jsx)(`h3`,{children:a?(0,f.jsx)(`button`,{className:`link`,onClick:l,children:`← All blocks`}):Ag[h.kind]}),!a&&(0,f.jsx)(`button`,{className:`small`,onClick:l,"aria-label":`Close the block`,children:`×`})]}),(0,f.jsx)($,{label:`Title`,children:(0,f.jsx)(`input`,{...g,value:h.title,onChange:e=>v({title:e.target.value},`title`)})}),(0,f.jsx)($,{label:`Id`,hint:S??(t.autoId?`Follows the title until you change it. Arrows use it.`:`Arrows use it; changing it changes them too.`),children:(0,f.jsx)(`input`,{...g,className:`mono`,value:b,onChange:e=>x(e.target.value),onBlur:w,onKeyDown:e=>e.key===`Enter`&&w(),"aria-invalid":!!S})}),(0,f.jsx)($,{label:`Kind`,children:(0,f.jsx)(`select`,{value:h.kind,onChange:e=>{let t=e.target.value,n=t===`person`?`person`:t===`fork`||t===`join`||t===`flow`?void 0:h.kind===`person`&&h.runs===`person`?`new-session`:h.runs,r=t===`flow`?{flow:h.flow??p[0]?.name,model:void 0,profile:void 0,brief:void 0,substeps:void 0}:{flow:void 0};v({kind:t,runs:n,...n===`continue`?{}:{continues:void 0},...t===`person`?{ask:h.ask??`question`}:{ask:void 0},...t===`timer`?{timer:h.timer??{clock:`daily`}}:{timer:void 0},...r})},children:ff.map(e=>(0,f.jsx)(`option`,{value:e,children:Ag[e]},e))})}),h.kind===`person`&&(0,f.jsx)($,{label:`Asks with`,children:(0,f.jsxs)(`select`,{value:h.ask??``,onChange:e=>v({ask:HD(e.target.value)}),children:[(0,f.jsx)(`option`,{value:``,children:`(not said)`}),(0,f.jsx)(`option`,{value:`question`,children:`a question (ask_user)`}),(0,f.jsx)(`option`,{value:`review`,children:`a review page`})]})}),h.kind===`timer`&&(0,f.jsxs)(`div`,{className:`flow-field-row`,children:[(0,f.jsx)($,{label:`Starts`,children:(0,f.jsxs)(`select`,{value:j,onChange:e=>v({timer:e.target.value===`every`?{every:30,of:`merges`}:{clock:`daily`}}),children:[(0,f.jsx)(`option`,{value:`clock`,children:`on the clock`}),(0,f.jsx)(`option`,{value:`every`,children:`after a count`})]})}),h.timer&&`clock`in h.timer&&(0,f.jsx)($,{label:`Every`,children:(0,f.jsx)(`select`,{value:h.timer.clock,onChange:e=>v({timer:{clock:e.target.value}}),children:[`hourly`,`daily`,`weekly`].map(e=>(0,f.jsx)(`option`,{value:e,children:e},e))})}),h.timer&&`every`in h.timer&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)($,{label:`Every`,children:(0,f.jsx)(`input`,{type:`number`,min:1,max:1e5,value:h.timer.every,onChange:e=>v({timer:{every:Math.min(1e5,Math.max(1,Math.floor(Number(e.target.value)||1))),of:h.timer.of}},`every`)})}),(0,f.jsx)($,{label:`Of`,children:(0,f.jsx)(`input`,{...g,value:h.timer.of,onChange:e=>v({timer:{every:h.timer.every,of:e.target.value}},`of`)})})]})]}),h.kind===`flow`&&(0,f.jsx)(WD,{draft:e,entry:t,choices:p,commit:s,onOpenFlow:m}),h.kind!==`fork`&&h.kind!==`join`&&h.kind!==`flow`&&(0,f.jsxs)(`div`,{className:`flow-field-row`,children:[(0,f.jsx)($,{label:`Runs as`,children:(0,f.jsxs)(`select`,{value:h.runs??``,disabled:h.kind===`person`,onChange:e=>{let t=HD(e.target.value);v({runs:t,continues:t===`continue`?h.continues??N[0]?.block.id:void 0})},children:[(0,f.jsx)(`option`,{value:``,children:`(not said)`}),Object.keys(jD).map(e=>(0,f.jsx)(`option`,{value:e,children:jD[e]},e))]})}),h.runs===`continue`&&(0,f.jsx)($,{label:`Whose`,children:(0,f.jsxs)(`select`,{value:h.continues??``,onChange:e=>v({continues:HD(e.target.value)}),children:[(0,f.jsx)(`option`,{value:``,children:`(not said)`}),N.map(e=>(0,f.jsx)(`option`,{value:e.block.id,children:e.block.title},e.key)),h.continues&&!N.some(e=>e.block.id===h.continues)&&(0,f.jsxs)(`option`,{value:h.continues,children:[h.continues,` (not a session)`]})]})})]}),h.kind!==`fork`&&h.kind!==`join`&&h.kind!==`flow`&&(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:h.runs===`continue`?`The session that did that block takes this step too: it knows the work.`:`Who does this step; its brief says how.`}),h.kind!==`flow`&&(0,f.jsxs)(`div`,{className:`flow-field-row`,children:[(0,f.jsx)($,{label:`Model`,children:(0,f.jsx)(`input`,{...g,list:`flow-models`,value:h.model??``,onChange:e=>v({model:HD(e.target.value)},`model`)})}),(0,f.jsx)(`datalist`,{id:`flow-models`,children:MD.map(e=>(0,f.jsx)(`option`,{value:e},e))}),(0,f.jsx)($,{label:`Profile`,children:(0,f.jsxs)(`select`,{value:h.profile??``,onChange:e=>v({profile:HD(e.target.value)}),children:[(0,f.jsx)(`option`,{value:``,children:`(none)`}),i.map(e=>(0,f.jsx)(`option`,{value:e,children:e},e)),h.profile&&!i.includes(h.profile)&&(0,f.jsxs)(`option`,{value:h.profile,children:[h.profile,` (not available here)`]})]})})]}),(0,f.jsx)(YD,{draft:e,entry:t,focus:n,naming:r,commit:s,onFocus:e=>u({kind:`block`,key:_,...e===void 0?{}:{outcome:e}})}),h.kind!==`flow`&&(0,f.jsxs)(`fieldset`,{className:`flow-fieldset`,children:[(0,f.jsx)(`legend`,{children:`Brief`}),(0,f.jsx)($,{label:`File`,children:(0,f.jsxs)(`select`,{value:h.brief??``,onChange:e=>v({brief:HD(e.target.value)}),children:[(0,f.jsx)(`option`,{value:``,children:`(no brief)`}),T.map(e=>(0,f.jsx)(`option`,{value:e,children:e},e)),h.brief&&!T.includes(h.brief)&&(0,f.jsxs)(`option`,{value:h.brief,children:[h.brief,A===void 0?` (missing)`:``]})]})}),(0,f.jsxs)(`div`,{className:`flow-field-row flow-new-brief`,children:[(0,f.jsx)(`input`,{...g,placeholder:`new-brief-name`,value:E,onChange:e=>{D(e.target.value),k(null)},"aria-label":`A new brief's name`}),(0,f.jsx)(`button`,{className:`small`,onClick:()=>{let t=EE(e,_,E||h.id);typeof t==`string`?k(t):(s(t),D(``))},children:`New brief`})]}),O&&(0,f.jsx)(`p`,{className:`flow-problem-inline`,children:O}),h.brief&&A!==void 0&&(0,f.jsx)($,{label:`Its text (${h.brief})`,hint:wf.test(h.brief)?`Markdown: what counts as done here, what to look for.`:`In a sub-folder: the builder edits briefs in briefs/ only.`,children:(0,f.jsx)(`textarea`,{...g,className:`mono`,rows:a?8:12,value:A,readOnly:!wf.test(h.brief),onChange:t=>s({...e,texts:{...e.texts,[h.brief]:t.target.value}},`brief:${h.brief}`)})})]}),h.kind!==`flow`&&(0,f.jsx)(XD,{draft:e,entry:t,narrow:a,commit:s}),(0,f.jsxs)(`label`,{className:`flow-check`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:M,disabled:M&&!e.start,onChange:t=>s({...e,start:t.target.checked?h.id:void 0})}),` Work starts here`,M&&!e.start?` (the first block, as no other is said)`:``]}),!a&&(0,f.jsx)(`button`,{className:`small`,onClick:()=>{let t=qE(e,`New frame`,{blocks:[_]});typeof t!=`string`&&(s(t.draft),u({kind:`frame`,key:t.key}))},title:`A titled, coloured frame round this block; drag its edges to take in more`,children:`Put a frame round it`}),!a&&(0,f.jsx)(`button`,{className:`small deny flow-delete`,onClick:c,children:`Delete this block`})]})}function WD({draft:e,entry:t,choices:n,commit:r,onOpenFlow:i}){let a=t.block,o=n.find(e=>e.name===a.flow),s=o?o.endings.filter(e=>!(a.outcomes??[]).some(t=>t.word.trim().toLowerCase()===e.trim().toLowerCase())):[];return(0,f.jsxs)(`fieldset`,{className:`flow-fieldset`,children:[(0,f.jsx)(`legend`,{children:`Runs`}),(0,f.jsx)($,{label:`The flow`,hint:`It starts that flow for a piece of work of its own and waits for it to end; the word it ends with is this block's outcome.`,children:(0,f.jsxs)(`select`,{value:a.flow??``,onChange:n=>r(fE(e,t.key,{flow:HD(n.target.value)})),children:[a.flow===void 0&&(0,f.jsx)(`option`,{value:``,children:`(none yet)`}),n.map(e=>(0,f.jsxs)(`option`,{value:e.name,children:[e.title,e.name===`main`?` (the default flow)`:``]},e.name)),a.flow!==void 0&&!o&&(0,f.jsxs)(`option`,{value:a.flow,children:[a.flow,` (not a flow here)`]})]})}),!n.length&&(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:`This project has no other flow yet: add one with "+ Flow" by the tabs.`}),o&&(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:o.endings.length?`"${o.title}" ends with ${o.endings.map(e=>`"${e}"`).join(`, `)}.`:`"${o.title}" has no end yet: every block of it leads on.`}),(0,f.jsxs)(`div`,{className:`flow-field-row flow-new-brief`,children:[o&&(0,f.jsxs)(`button`,{className:`small`,onClick:()=>i(o.name),children:[`Open "`,o.title,`"`]}),s.length>0&&(0,f.jsxs)(`button`,{className:`small`,onClick:()=>r(uD(e,t.key,s)),title:`An outcome for each, a pin to draw to where the work goes then`,children:[`Add its endings (`,s.length,`)`]})]})]})}function GD({onAdd:e}){let t=o(),[n,r]=(0,d.useState)(!1),[i,a]=(0,d.useState)(``),[s,c]=(0,d.useState)(null);if(!n)return(0,f.jsx)(`span`,{className:`flow-tab-add`,children:(0,f.jsx)(`button`,{className:`small`,onClick:()=>r(!0),title:`Add another flow: its own diagram, sharing the briefs and rules`,children:`+ Flow`})});let l=()=>{let t=e(i);c(t),t||(a(``),r(!1))};return(0,f.jsxs)(`span`,{className:`flow-tab-add`,children:[(0,f.jsx)(`input`,{...t,autoFocus:!0,placeholder:`Its title, e.g. Asset`,value:i,onChange:e=>{a(e.target.value),c(null)},onKeyDown:e=>{e.key===`Enter`?l():e.key===`Escape`&&r(!1)},"aria-label":`A new flow's title`,"aria-invalid":!!s,title:s??void 0}),(0,f.jsx)(`button`,{className:`small primary`,onClick:l,children:`Add`}),(0,f.jsx)(`button`,{className:`small`,onClick:()=>{r(!1),c(null)},"aria-label":`Don't add a flow`,children:`×`})]})}var KD={done:`when the block's work is done`,start:`as the block starts`,brief:`where the brief says`};function qD(e,t){let{times:n,...r}=e;return t===void 0?r:{...r,times:t}}function JD({times:e,onChange:t}){return(0,f.jsxs)(`label`,{className:`flow-outcome-times`,title:`On which time of this word it is taken instead (empty: every other time)`,children:[(0,f.jsx)(`span`,{className:`muted`,children:`×`}),(0,f.jsx)(`input`,{type:`number`,min:1,max:100,value:e??``,placeholder:`–`,"aria-label":`Its count`,onChange:e=>t(e.target.value===``?void 0:Math.min(100,Math.max(1,Math.floor(Number(e.target.value))||1)))})]})}function YD({draft:e,entry:t,focus:n,naming:r,commit:i,onFocus:a}){let s=o(),c=t.block,l=t.key,u=c.outcomes??[],p=$T(t),m=e.blocks.filter(e=>e.key!==l),h=(0,d.useRef)(null),g=(0,d.useRef)(null),[_,v]=(0,d.useState)(``);(0,d.useEffect)(()=>{h.current?.focus(),h.current?.select()},[n]),(0,d.useEffect)(()=>{r&&g.current?.focus()},[r]);let y=()=>{if(!_.trim())return g.current?.focus();i(hE(e,l,void 0,_).draft),v(``),a(void 0)};return(0,f.jsxs)(`fieldset`,{className:`flow-fieldset`,children:[(0,f.jsx)(`legend`,{children:c.kind===`person`?`Outcomes: the answers it offers`:`Outcomes`}),(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:`Where the work goes next, by its result. The manager reads the result against these words; Ledung counts each word for a piece of work, so a count ("× 3") sends the 3rd one elsewhere.`}),u.map((t,r)=>(0,f.jsxs)(`div`,{className:`flow-outcome-row`,children:[(0,f.jsx)(`input`,{...s,ref:r===n?h:void 0,value:t.word,placeholder:`its word, e.g. Approved`,"aria-label":`The outcome's word`,"aria-invalid":!t.word.trim(),onChange:t=>i(vE(e,l,r,{word:t.target.value}),`out-word:${l}:${p[r]}`)}),(0,f.jsx)(JD,{times:t.times,onChange:t=>i(vE(e,l,r,{times:t}),`out-times:${l}:${p[r]}`)}),(0,f.jsxs)(`select`,{value:t.end?PD:t.to??``,"aria-label":`Where it leads`,"aria-invalid":t.to===void 0&&!t.end,onChange:t=>i(vE(e,l,r,t.target.value===PD?{to:void 0,end:!0}:{to:HD(t.target.value),end:void 0})),children:[t.to===void 0&&!t.end&&(0,f.jsx)(`option`,{value:``,children:`→ nowhere yet: drag its pin`}),(0,f.jsx)(`option`,{value:PD,children:`■ ends the flow`}),m.map(e=>(0,f.jsxs)(`option`,{value:e.block.id,children:[`→ `,e.block.title]},e.key)),t.to===c.id&&(0,f.jsx)(`option`,{value:t.to,children:`→ this block (round to itself)`}),t.to!==void 0&&t.to!==c.id&&!m.some(e=>e.block.id===t.to)&&(0,f.jsxs)(`option`,{value:t.to,children:[`→ `,t.to,` (not a block)`]})]}),(0,f.jsx)(`button`,{className:`small deny`,onClick:()=>{i(yE(e,l,r)),n!==void 0&&a(void 0)},"aria-label":`Remove the outcome ${vf(t)}`,title:`Remove this outcome`,children:`×`}),t.times&&t.word.trim()&&(0,f.jsxs)(`span`,{className:`flow-outcome-name`,children:[`Shown as "`,vf(t),`"`]})]},p[r]??r)),(0,f.jsxs)(`div`,{className:`flow-field-row flow-new-brief${r?` naming`:``}`,children:[(0,f.jsx)(`input`,{...s,ref:g,placeholder:`Name a new one, e.g. Failed`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>e.key===`Enter`&&y(),"aria-label":`A new outcome's word`}),(0,f.jsx)(`button`,{className:`small`,onClick:y,children:`+ outcome`})]}),(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:m.length?`A new outcome is a pin on the block's right edge: drag it to the block it leads to, or pick that above.`:`Add another block to lead to.`}),!u.length&&(0,f.jsxs)(`span`,{className:`muted flow-field-hint`,children:[`No outcomes: the work ends here`,c.title.trim()?`, and the flow ends with "${c.title}"`:``,`.`]})]})}function XD({draft:e,entry:t,narrow:n,commit:r}){let i=o(),a=t.block,s=t.key,c=a.substeps??[],[l,u]=(0,d.useState)({}),[p,m]=(0,d.useState)(null),h=(n,i,a)=>r(ME(e,s,n,i),a&&`sub-${a}:${s}:${ZD(t,n)}`),g=(e,t,n)=>h(e,{outcomes:t.length?t:void 0},n),_=Object.keys(e.texts).filter(e=>e.startsWith(`briefs/`)).sort(),v=a.kind!==`person`&&a.kind!==`fork`&&a.kind!==`join`&&a.runs!==`person`;return(0,f.jsxs)(`fieldset`,{className:`flow-fieldset`,children:[(0,f.jsx)(`legend`,{children:`Sub-steps`}),(0,f.jsxs)(`span`,{className:`muted flow-field-hint`,children:[`Subagents `,a.runs===`manager`?`the manager`:`this block's session`,` starts, in this order; each returns to it. The block's outcome counts once those that run when it is done have passed.`]}),c.map((o,d)=>{let v=vg(a,o),y=o.brief?e.texts[o.brief]:void 0,b=ZD(t,d);return(0,f.jsxs)(`div`,{className:`flow-substep-edit`,children:[(0,f.jsxs)(`div`,{className:`flow-substep-edit-head`,children:[(0,f.jsxs)(`span`,{className:`flow-substep-edit-title`,children:[d+1,`. `,o.title]}),(0,f.jsxs)(`span`,{className:`flow-substep-edit-tools`,children:[(0,f.jsx)(`button`,{className:`small`,onClick:()=>r(NE(e,s,d,-1)),disabled:d===0,"aria-label":`Move ${o.title} earlier`,title:`Earlier`,children:`↑`}),(0,f.jsx)(`button`,{className:`small`,onClick:()=>r(NE(e,s,d,1)),disabled:d===c.length-1,"aria-label":`Move ${o.title} later`,title:`Later`,children:`↓`}),(0,f.jsx)(`button`,{className:`small deny`,onClick:()=>r(PE(e,s,d)),"aria-label":`Remove ${o.title}`,title:`Remove this sub-step`,children:`×`})]})]}),(0,f.jsxs)(`span`,{className:`muted flow-field-hint`,children:[v.head,` · `,v.detail]}),v.note&&(0,f.jsxs)(`span`,{className:`flow-substep-note`,children:[v.note,`: a check of this block's own work, so its findings go back to whoever did it.`]}),(0,f.jsxs)(`div`,{className:`flow-field-row`,children:[(0,f.jsx)($,{label:`Title`,children:(0,f.jsx)(`input`,{...i,value:o.title,onChange:e=>h(d,{title:e.target.value},`title`)})}),(0,f.jsx)($,{label:`Kind`,children:(0,f.jsxs)(`select`,{value:o.kind,onChange:e=>h(d,{kind:e.target.value}),children:[(0,f.jsx)(`option`,{value:`check`,children:`check`}),(0,f.jsx)(`option`,{value:`work`,children:`work`})]})})]}),(0,f.jsx)($,{label:`Runs`,children:(0,f.jsx)(`select`,{value:o.when??`done`,onChange:e=>h(d,{when:e.target.value}),children:hf.map(e=>(0,f.jsx)(`option`,{value:e,children:KD[e]},e))})}),(0,f.jsxs)(`div`,{className:`flow-field-row`,children:[(0,f.jsx)($,{label:`Brief`,children:(0,f.jsxs)(`select`,{value:o.brief??``,onChange:e=>h(d,{brief:HD(e.target.value)}),children:[(0,f.jsx)(`option`,{value:``,children:`(no brief)`}),_.map(e=>(0,f.jsx)(`option`,{value:e,children:e},e)),o.brief&&!_.includes(o.brief)&&(0,f.jsxs)(`option`,{value:o.brief,children:[o.brief,y===void 0?` (missing)`:``]})]})}),(0,f.jsx)($,{label:`Model`,children:(0,f.jsx)(`input`,{...i,list:`flow-models`,value:o.model??``,onChange:e=>h(d,{model:HD(e.target.value)},`model`)})})]}),(0,f.jsxs)(`div`,{className:`flow-field-row flow-new-brief`,children:[(0,f.jsx)(`input`,{...i,placeholder:`new-brief-name`,value:l[b]??``,onChange:e=>{u(t=>({...t,[b]:e.target.value})),m(null)},"aria-label":`A new brief's name for ${o.title}`}),(0,f.jsx)(`button`,{className:`small`,onClick:()=>{let t=FE(e,s,d,l[b]||o.id);typeof t==`string`?m({at:b,text:t}):(r(t),u(e=>({...e,[b]:``})))},children:`New brief`})]}),p?.at===b&&(0,f.jsx)(`p`,{className:`flow-problem-inline`,children:p.text}),o.brief&&y!==void 0&&wf.test(o.brief)&&(0,f.jsxs)(`details`,{className:`flow-substep-brief`,children:[(0,f.jsxs)(`summary`,{children:[`Its brief's text (`,o.brief,e.blocks.some(e=>e.block.brief===o.brief)?`, also a block's`:``,`)`]}),(0,f.jsx)(`textarea`,{...i,className:`mono`,rows:n?6:8,value:y,onChange:t=>r({...e,texts:{...e.texts,[o.brief]:t.target.value}},`brief:${o.brief}`)})]}),(0,f.jsx)(`div`,{className:`flow-field-label`,children:`Outcomes`}),(o.outcomes??[]).map((e,t)=>(0,f.jsxs)(`div`,{className:`flow-outcome-row`,children:[(0,f.jsx)(`input`,{...i,value:e.word,placeholder:`its word`,"aria-label":`The outcome's word`,onChange:e=>g(d,(o.outcomes??[]).map((n,r)=>r===t?{...n,word:e.target.value}:n),`out-word-${t}`)}),(0,f.jsx)(JD,{times:e.times,onChange:e=>g(d,(o.outcomes??[]).map((n,r)=>r===t?qD(n,e):n),`out-times-${t}`)}),(0,f.jsx)(`select`,{value:e.to,"aria-label":`Where it leads`,onChange:e=>g(d,(o.outcomes??[]).map((n,r)=>r===t?{...n,to:e.target.value}:n)),children:gf.map(e=>(0,f.jsx)(`option`,{value:e,children:_g(a,e)},e))}),(0,f.jsx)(`button`,{className:`small deny`,onClick:()=>g(d,(o.outcomes??[]).filter((e,n)=>n!==t)),"aria-label":`Remove the outcome ${vf(e)}`,title:`Remove this outcome`,children:`×`})]},t)),(0,f.jsx)(`div`,{children:(0,f.jsx)(`button`,{className:`small`,onClick:()=>g(d,[...o.outcomes??[],{word:``,to:`owner`}]),children:`Add an outcome`})}),(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:`"✗ … fixes" sends it back to this block's one, and the sub-step runs again; with a count ("× 3") the 3rd time goes elsewhere, to report or ask the manager.`})]},b)}),v?(0,f.jsxs)(`div`,{className:`flow-field-row flow-new-brief`,children:[(0,f.jsx)(`button`,{className:`small`,onClick:()=>r(jE(e,s,`check`).draft),children:`Add a check sub-step`}),(0,f.jsx)(`button`,{className:`small`,onClick:()=>r(jE(e,s,`work`).draft),children:`Add a work sub-step`})]}):(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:a.kind===`fork`||a.kind===`join`?`A fork or join starts no subagents.`:`A person starts no subagents: sub-steps go in a block the manager or a session runs.`})]})}var ZD=(e,t)=>QT(e)[t]??`r${t}`;function QD({draft:e,frameKey:t,narrow:n,commit:r,onClose:i,onSelect:a}){let s=o(),l=e.frames.find(e=>e.key===t)?.frame,u=(0,d.useRef)(null);if((0,d.useEffect)(()=>{l?.title===`New frame`&&u.current?.select()},[t]),!l)return null;let p=WE(e,l),m=GE(e,p);return(0,f.jsxs)(`div`,{className:`flow-panel-body flow-fields`,children:[(0,f.jsxs)(`div`,{className:`flow-panel-head`,children:[(0,f.jsx)(`h3`,{children:n?(0,f.jsx)(`button`,{className:`link`,onClick:i,children:`← The workflow`}):`Frame`}),!n&&(0,f.jsx)(`button`,{className:`small`,onClick:i,"aria-label":`Close the frame`,children:`×`})]}),(0,f.jsxs)(`span`,{className:`muted flow-field-hint`,children:[`A titled group drawn behind its blocks, for whoever reads the diagram; the flow and the manager pass it by.`,n?``:` Drag its title to move it with the blocks in it, its edges to resize it.`]}),(0,f.jsx)($,{label:`Title`,children:(0,f.jsx)(`input`,{...s,ref:u,value:l.title,onChange:n=>r(JE(e,t,{title:n.target.value}),`frame-title:${t}`),"aria-invalid":!l.title.trim()})}),(0,f.jsxs)(`fieldset`,{className:`flow-fieldset`,children:[(0,f.jsx)(`legend`,{children:`Colour`}),(0,f.jsxs)(`div`,{className:`flow-swatches`,role:`radiogroup`,"aria-label":`Its colour`,children:[(0,f.jsx)(`button`,{className:`flow-swatch none${l.colour?``:` on`}`,role:`radio`,"aria-checked":!l.colour,onClick:()=>r(JE(e,t,{colour:void 0})),title:`No colour`,children:`∅`}),Object.keys(c).map(n=>(0,f.jsx)(`button`,{className:`flow-swatch named${l.colour===n?` on`:``}`,role:`radio`,"aria-checked":l.colour===n,style:mD({...l,colour:n}),onClick:()=>r(JE(e,t,{colour:n})),title:c[n].label,"aria-label":c[n].label},n))]})]}),(0,f.jsx)(`p`,{className:`muted`,children:p.length?(0,f.jsxs)(f.Fragment,{children:[`Holds `,p.map((t,n)=>{let r=e.blocks.find(e=>e.key===t);return(0,f.jsxs)(`span`,{children:[n?`, `:``,(0,f.jsx)(`button`,{className:`link`,onClick:()=>a({kind:`block`,key:t}),children:r.block.title})]},t)}),`.`]}):`Holds no block yet: move it over some, or resize it round them.`}),!n&&m&&(0,f.jsx)(`button`,{className:`small`,onClick:()=>r(JE(e,t,m)),children:`Fit it round its blocks`}),(0,f.jsx)(`button`,{className:`small deny flow-delete`,onClick:()=>{r(ZE(e,t)),i()},children:`Delete this frame`}),(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:`Its blocks stay where they are.`})]})}function $D({draft:e,commit:t,narrow:n,onSelect:r,ws:i,flow:a,commitWs:s,onDeleted:c}){let l=o(),[u,p]=(0,d.useState)(``),[m,h]=(0,d.useState)(null),g=a.key===i.flows[0].key,[_,v]=(0,d.useState)(a.name),[y,b]=(0,d.useState)(null),[x,S]=(0,d.useState)(!1);(0,d.useEffect)(()=>{v(a.name),b(null)},[a.name]);let C=()=>{if(_===a.name)return;let e=rD(_,i,a.key);b(e),e||s(aD(i,a.key,_))},w=i.flows.flatMap(e=>e.draft.blocks.filter(e=>e.block.kind===`flow`&&e.block.flow===a.name).map(t=>`"${t.block.title}" in ${e.draft.title??e.name}`)),T=t=>e.blocks.find(e=>e.block.id===t)?.block.title??t,E=()=>{let n=LE(e,u,e.blocks.slice(0,1).map(e=>e.block.id));if(typeof n==`string`)return h(n);h(null),t(n.draft),p(``),r({kind:`overlay`,key:n.key})};return(0,f.jsxs)(`div`,{className:`flow-panel-body flow-fields`,children:[(0,f.jsx)(`h3`,{children:i.flows.length>1?g?`This flow, the default one`:`This flow`:`The workflow`}),(0,f.jsx)($,{label:`Title`,children:(0,f.jsx)(`input`,{...l,value:e.title??``,onChange:e=>s(oD(i,a.key,HD(e.target.value)),`${a.key}:flow-title`)})}),g?i.flows.length>1&&(0,f.jsxs)(`span`,{className:`muted flow-field-hint`,children:[`In `,`flow.json`,`: where work goes unless the manager or the person picks another flow. Run flow blocks name it "`,`main`,`".`]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)($,{label:`Name`,hint:y??`Its file is ${lf(a.name)}; Run flow blocks name it so, and changing it changes them too.${a.autoName?` Follows the title until you change it.`:``}`,children:(0,f.jsx)(`input`,{...l,className:`mono`,value:_,onChange:e=>v(e.target.value),onBlur:C,onKeyDown:e=>e.key===`Enter`&&C(),"aria-invalid":!!y})}),!n&&(x?(0,f.jsxs)(`div`,{className:`flow-confirm`,role:`alertdialog`,children:[(0,f.jsxs)(`span`,{children:[`Delete the flow "`,e.title??a.name,`"? Saving removes `,lf(a.name),w.length?`, and ${w.join(`, `)} will run a flow that isn't there`:``,`. Its briefs stay.`]}),(0,f.jsxs)(`span`,{className:`flow-confirm-buttons`,children:[(0,f.jsx)(`button`,{className:`small deny`,onClick:()=>{s(sD(i,a.key)),c()},children:`Delete it`}),(0,f.jsx)(`button`,{className:`small`,onClick:()=>S(!1),children:`Keep it`})]})]}):(0,f.jsx)(`button`,{className:`small deny flow-delete`,onClick:()=>S(!0),children:`Delete this flow`}))]}),(0,f.jsx)($,{label:`Standing rules (rules.md)`,hint:`Markdown every session of the project reads: rules that belong to no single step${i.flows.length>1?`; the same for every flow`:``}.`,children:(0,f.jsx)(`textarea`,{...l,className:`mono`,rows:n?10:16,value:e.rules??``,placeholder:e.rules===null?`No rules.md yet: what you write here is saved as one.`:void 0,onChange:n=>t({...e,rules:n.target.value},`rules`)})}),g?(0,f.jsxs)(`fieldset`,{className:`flow-fieldset`,children:[(0,f.jsx)(`legend`,{children:`The manager`}),(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:`Its standing procedures between steps (status briefs, sweeps, how it asks), in one file its instructions name. How a block's step is done is that block's brief.`}),e.manager===void 0?(0,f.jsx)(`div`,{className:`flow-field-row flow-new-brief`,children:(0,f.jsx)(`button`,{className:`small`,onClick:()=>{t(OE(e)),r({kind:`manager`,key:`manager`})},children:`Add the manager's file`})}):(0,f.jsxs)(`p`,{children:[(0,f.jsxs)(`button`,{className:`link`,onClick:()=>r({kind:`manager`,key:`manager`}),children:[`📋 `,e.manager]}),e.texts[e.manager]===void 0&&(0,f.jsx)(`span`,{className:`flow-problem-inline`,children:` (missing)`})]})]}):(0,f.jsx)(`p`,{className:`muted`,children:`The manager's file is the default flow's, for all flows: its tab has it.`}),(0,f.jsxs)(`fieldset`,{className:`flow-fieldset`,children:[(0,f.jsx)(`legend`,{children:`Overlays`}),(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:`Switchable additions that amend several blocks at once (e.g. "tests on Windows" for Build and Fix).`}),e.overlays.length>0&&(0,f.jsx)(`ul`,{className:`flow-roles`,children:e.overlays.map(({key:e,overlay:t})=>(0,f.jsxs)(`li`,{children:[(0,f.jsxs)(`button`,{className:`link`,onClick:()=>r({kind:`overlay`,key:e}),children:[`◇ `,t.title]}),(0,f.jsxs)(`span`,{className:`muted`,children:[` · amends `,t.blocks.map(T).join(`, `)]})]},e))}),(0,f.jsxs)(`div`,{className:`flow-field-row flow-new-brief`,children:[(0,f.jsx)(`input`,{...l,placeholder:`Tests on Windows`,value:u,onChange:e=>{p(e.target.value),h(null)},onKeyDown:e=>e.key===`Enter`&&E(),"aria-label":`A new overlay's title`}),(0,f.jsx)(`button`,{className:`small`,onClick:E,children:`Add an overlay`})]}),m&&(0,f.jsx)(`p`,{className:`flow-problem-inline`,children:m})]}),(0,f.jsxs)(`fieldset`,{className:`flow-fieldset`,children:[(0,f.jsx)(`legend`,{children:`Frames`}),(0,f.jsxs)(`span`,{className:`muted flow-field-hint`,children:[`Titled, coloured groups of blocks ("Planning", "Building"), drawn behind them.`,n?``:` Add one from the palette, or round a block from its panel.`]}),e.frames.length>0&&(0,f.jsx)(`ul`,{className:`flow-roles`,children:e.frames.map(({key:e,frame:t})=>(0,f.jsx)(`li`,{children:(0,f.jsxs)(`button`,{className:`link${t.colour?` named`:``}`,style:mD(t),onClick:()=>r({kind:`frame`,key:e}),children:[`▢ `,t.title]})},e))})]}),!n&&(0,f.jsx)(`p`,{className:`muted`,children:`Click a block or an arrow (one of its outcomes) to change it.`})]})}function eO({draft:e,narrow:t,commit:n,onClose:r,onSelect:i}){let a=o(),s=e.manager;if(s===void 0)return null;let c=[...new Set([df,...Object.keys(e.texts).filter(e=>e===`manager.md`||e.startsWith(`briefs/`))])].filter(t=>e.texts[t]!==void 0).sort(),l=e.texts[s],u=e.blocks.filter(e=>e.block.runs===`manager`);return(0,f.jsxs)(`div`,{className:`flow-panel-body flow-fields`,children:[(0,f.jsxs)(`div`,{className:`flow-panel-head`,children:[(0,f.jsx)(`h3`,{children:t?(0,f.jsx)(`button`,{className:`link`,onClick:r,children:`← The workflow`}):`The manager`}),!t&&(0,f.jsx)(`button`,{className:`small`,onClick:r,"aria-label":`Close the manager's file`,children:`×`})]}),(0,f.jsx)(`p`,{className:`muted`,children:u.length?(0,f.jsxs)(f.Fragment,{children:[`Runs `,u.map((e,t)=>(0,f.jsxs)(`span`,{children:[t?`, `:``,(0,f.jsx)(`button`,{className:`link`,onClick:()=>i({kind:`block`,key:e.key}),children:e.block.title})]},e.key)),` itself, and between steps does what this file says.`]}):`Runs no block itself: this file is what it does between steps.`}),(0,f.jsx)($,{label:`File`,children:(0,f.jsxs)(`select`,{value:s,onChange:t=>n(DE(e,t.target.value)),children:[c.map(e=>(0,f.jsx)(`option`,{value:e,children:e},e)),!c.includes(s)&&(0,f.jsxs)(`option`,{value:s,children:[s,l===void 0?` (missing)`:``]})]})}),s!==`manager.md`&&e.texts[`manager.md`]===void 0&&(0,f.jsxs)(`button`,{className:`small`,onClick:()=>n(OE(e)),children:[`New `,`manager.md`]}),l!==void 0&&(0,f.jsx)($,{label:`Its text (${s})`,hint:wf.test(s)?`Markdown: what the manager does between steps (status briefs, sweeps, the question format).`:`In a sub-folder: the builder edits manager.md and briefs/ only.`,children:(0,f.jsx)(`textarea`,{...a,className:`mono`,rows:t?10:16,value:l,readOnly:!wf.test(s),onChange:t=>n({...e,texts:{...e.texts,[s]:t.target.value}},`brief:${s}`)})}),(0,f.jsx)(`button`,{className:`small deny flow-delete`,onClick:()=>{n(DE(e,void 0)),r()},children:`Remove the manager's file from the flow`}),(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:`Removing it takes it out of the flow; the file stays in the folder.`})]})}function tO({draft:e,overlayKey:t,narrow:n,commit:r,onClose:i}){let a=o(),s=e.overlays.find(e=>e.key===t)?.overlay,[c,l]=(0,d.useState)(s?.id??``),[u,p]=(0,d.useState)(null),[m,h]=(0,d.useState)(``),[g,_]=(0,d.useState)(null);if((0,d.useEffect)(()=>{l(s?.id??``),p(null)},[s?.id,t]),!s)return null;let v=()=>{c!==s.id&&(/^[a-z0-9][a-z0-9-]{0,47}$/.test(c)?e.overlays.some(e=>e.key!==t&&e.overlay.id===c)?p(`Another overlay is "${c}" already.`):(p(null),r(RE(e,t,{id:c}))):p(`Lower case letters, digits and "-" (at most 48), starting with a letter or digit.`))},y=Object.keys(e.texts).filter(e=>e.startsWith(`overlays/`)).sort(),b=e.texts[s.file];return(0,f.jsxs)(`div`,{className:`flow-panel-body flow-fields`,children:[(0,f.jsxs)(`div`,{className:`flow-panel-head`,children:[(0,f.jsx)(`h3`,{children:n?(0,f.jsx)(`button`,{className:`link`,onClick:i,children:`← The workflow`}):`Overlay`}),!n&&(0,f.jsx)(`button`,{className:`small`,onClick:i,"aria-label":`Close the overlay`,children:`×`})]}),(0,f.jsx)($,{label:`Title`,children:(0,f.jsx)(`input`,{...a,value:s.title,onChange:n=>r(RE(e,t,{title:n.target.value}),`overlay-title:${t}`)})}),(0,f.jsx)($,{label:`Id`,hint:u??`Its name in flow.json.`,children:(0,f.jsx)(`input`,{...a,className:`mono`,value:c,onChange:e=>l(e.target.value),onBlur:v,onKeyDown:e=>e.key===`Enter`&&v(),"aria-invalid":!!u})}),(0,f.jsxs)(`fieldset`,{className:`flow-fieldset`,children:[(0,f.jsx)(`legend`,{children:`Amends`}),e.blocks.map(n=>{let i=s.blocks.includes(n.block.id),a=i&&s.blocks.length===1;return(0,f.jsxs)(`label`,{className:`flow-check`,title:a?`An overlay amends at least one block`:void 0,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:i,disabled:a,onChange:()=>r(zE(e,t,n.block.id))}),` `,n.block.title]},n.key)}),s.blocks.filter(t=>!e.blocks.some(e=>e.block.id===t)).map(e=>(0,f.jsxs)(`span`,{className:`flow-problem-inline`,children:[`"`,e,`" is not a block any more.`]},e))]}),(0,f.jsx)($,{label:`File`,children:(0,f.jsxs)(`select`,{value:s.file,onChange:n=>r(RE(e,t,{file:n.target.value})),children:[y.map(e=>(0,f.jsx)(`option`,{value:e,children:e},e)),!y.includes(s.file)&&(0,f.jsxs)(`option`,{value:s.file,children:[s.file,b===void 0?` (missing)`:``]})]})}),(0,f.jsxs)(`div`,{className:`flow-field-row flow-new-brief`,children:[(0,f.jsx)(`input`,{...a,placeholder:`new-overlay-name`,value:m,onChange:e=>{h(e.target.value),_(null)},"aria-label":`A new overlay file's name`}),(0,f.jsx)(`button`,{className:`small`,onClick:()=>{let n=VE(e,t,m||s.id);typeof n==`string`?_(n):(r(n),h(``))},children:`New file`})]}),g&&(0,f.jsx)(`p`,{className:`flow-problem-inline`,children:g}),b!==void 0&&(0,f.jsx)($,{label:`Its text (${s.file})`,hint:wf.test(s.file)?`Markdown: what changes in the blocks it amends when it is on.`:`In a sub-folder: the builder edits overlays in overlays/ only.`,children:(0,f.jsx)(`textarea`,{...a,className:`mono`,rows:n?8:12,value:b,readOnly:!wf.test(s.file),onChange:t=>r({...e,texts:{...e.texts,[s.file]:t.target.value}},`brief:${s.file}`)})}),(0,f.jsx)(`button`,{className:`small deny flow-delete`,onClick:()=>{r(BE(e,t)),i()},children:`Delete this overlay`}),(0,f.jsx)(`span`,{className:`muted flow-field-hint`,children:`Its file stays in the folder.`})]})}var nO=e=>t=>e.blocks.find(e=>e.id===t)?.title??t;function rO(e){return[{name:sf,file:af,flow:e.flow,raw:e.raw,problems:e.problems},...e.flows]}var iO=e=>t=>{let n=e.find(e=>e.name===t);return n?n.flow?.title??n.name:void 0};function aO({flow:e,layout:t,texts:n,selected:r,onSelect:i,narrow:a,flowTitle:o}){let s=HE(e.overlays),[c,l]=TD(),u=nO(e),p=new Map(t.blocks.map(e=>[e.block.id,e])),m=[...e.frames.map((e,t)=>OD(`frame:${t}`,e)),...t.blocks.map(({block:e,x:t,y:i})=>({id:e.id,type:`block`,position:{x:t,y:i},...c[e.id]?{measured:c[e.id]}:{},data:{block:e,hasBrief:!!e.brief&&n[e.brief]!==void 0,selected:e.id===r,overlays:s.get(e.id),runsFlow:jg(e,o),...e.continues?{continuesTitle:u(e.continues)}:{}}}))],h=xD(m,t.arrows.map(e=>{let[t,n,r]=e.kind===`continue`?CD(p.get(e.from),p.get(e.to)):Lg(e.kind,e.index??0,p.get(e.from)?.block.outcomes?.length??0);return{id:e.id,source:e.from,target:e.to,sourceHandle:t,targetHandle:n,className:`flow-arrow arrow-${e.kind}`,markerEnd:{type:_a.ArrowClosed,width:16,height:16,color:SD[e.kind]},...e.route&&r!==void 0?{type:`routed`,data:{route:e.route,offset:r}}:{type:`stepped`,data:{text:e.kind===`continue`?e.text:null,...r?{offset:r}:{}}}}})),g=(0,d.useRef)(null),_=e.start&&t.blocks.some(t=>t.block.id===e.start)?e.start:t.blocks[0]?.block.id,v=wD(g,[...t.blocks,...e.frames.map(e=>({...e.at,...e.size}))],t.blocks.find(e=>e.block.id===_));return(0,f.jsx)(`div`,{className:`flow-canvas`,ref:g,children:v&&(0,f.jsxs)(gd,{nodes:m,edges:h,nodeTypes:gD,edgeTypes:bD,minZoom:.2,maxZoom:2,...v.fit?{fitView:!0,fitViewOptions:{padding:.15}}:{defaultViewport:v},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,elementsSelectable:!1,onNodeClick:(e,t)=>t.type===`block`&&i(t.id),onNodesChange:l,children:[(0,f.jsx)(Ed,{gap:24}),!a&&(0,f.jsx)(Fd,{showInteractive:!1}),!v.fit&&(0,f.jsx)(DD,{small:a})]})})}function oO({flow:e,layout:t,texts:n,onSelect:r,flowTitle:i}){let a=nO(e),o=Og(t.blocks,e.frames),s=Dg(t);return(0,f.jsx)(`ol`,{className:`flow-list`,children:s.map(({block:e},c)=>(0,f.jsxs)(d.Fragment,{children:[o.get(e.id)&&o.get(e.id)!==o.get(s[c-1]?.block.id??``)&&(0,f.jsx)(`li`,{role:`presentation`,className:`flow-list-frame${o.get(e.id).colour?` coloured`:``}`,style:mD(o.get(e.id)),children:o.get(e.id).title}),(0,f.jsx)(`li`,{children:(0,f.jsxs)(`button`,{className:`flow-list-item kind-${e.kind}`,onClick:()=>r(e.id),children:[(0,f.jsx)(`span`,{className:`flow-block-top`,children:(0,f.jsx)(`span`,{className:`flow-kind`,children:Ag[e.kind]})}),(0,f.jsx)(`span`,{className:`flow-block-title`,children:e.title}),Mg(e,a)&&(0,f.jsx)(`span`,{className:`flow-block-actor`,children:Mg(e,a)}),jg(e,i)&&(0,f.jsxs)(`span`,{className:`flow-block-actor flow-block-runs`,children:[`▸ `,jg(e,i)]}),(e.substeps??[]).map((t,n)=>{let r=vg(e,t);return(0,f.jsxs)(`span`,{className:`flow-list-substep`,children:[r.head,` · `,r.detail,r.outcomes?` · ${r.outcomes}`:``,r.note?` · ${r.note}`:``]},`s${n}`)}),kg(t,e.id).map((e,t)=>(0,f.jsx)(`span`,{className:`flow-list-arrow`,children:e},t)),e.brief&&n[e.brief]!==void 0&&(0,f.jsxs)(`span`,{className:`flow-block-brief`,children:[`📄 `,e.brief.split(`/`).pop()]})]})})]},e.id))})}function sO({file:e,texts:t,open:n=!1}){let r=t[e];return r===void 0?(0,f.jsxs)(`p`,{className:`flow-problem-inline`,children:[`Its brief `,e,` is missing.`]}):(0,f.jsxs)(`details`,{className:`flow-overlay`,open:n,children:[(0,f.jsx)(`summary`,{className:`mono`,children:e}),(0,f.jsx)(i,{text:r})]})}function cO({block:e,flow:t,layout:n,texts:r,onBlock:i,onClose:a,flowTitle:o,onFlow:s}){let c=t.overlays.filter(t=>t.blocks.includes(e.id)),l=nO(t),u=t.blocks.filter(t=>t.runs===`continue`&&t.continues===e.id);return(0,f.jsxs)(`div`,{className:`flow-panel-body`,children:[(0,f.jsxs)(`div`,{className:`flow-panel-head`,children:[(0,f.jsx)(`h3`,{children:e.title}),(0,f.jsx)(`button`,{className:`small`,onClick:a,"aria-label":`Close the block`,children:`×`})]}),(0,f.jsxs)(`p`,{className:`muted`,children:[Ag[e.kind],Mg(e,l)?` · ${Mg(e,l)}`:``]}),e.kind===`flow`&&(e.flow!==void 0&&o(e.flow)!==void 0?(0,f.jsxs)(`p`,{children:[`Starts the flow `,(0,f.jsx)(`button`,{className:`link`,onClick:()=>s(e.flow),children:o(e.flow)}),` for a piece of work of its own and waits for it to end; the word it ends with is this block's outcome.`]}):(0,f.jsxs)(`p`,{className:`flow-problem-inline`,children:[jg(e,o),`.`]})),e.runs===`continue`&&e.continues&&(0,f.jsxs)(`p`,{className:`muted`,children:[`Runs in the session of `,(0,f.jsx)(`button`,{className:`link`,onClick:()=>i(e.continues),children:l(e.continues)}),`, which knows the work.`]}),u.length>0&&(0,f.jsxs)(`p`,{className:`muted`,children:[`Its session goes on in `,u.map((e,t)=>(0,f.jsxs)(`span`,{children:[t?`, `:``,(0,f.jsx)(`button`,{className:`link`,onClick:()=>i(e.id),children:e.title})]},e.id)),`.`]}),kg(n,e.id).length>0&&(0,f.jsx)(`ul`,{className:`flow-panel-arrows`,children:kg(n,e.id).map((e,t)=>(0,f.jsx)(`li`,{children:e},t))}),c.length>0&&(0,f.jsxs)(`p`,{className:`muted`,children:[`◇ Amended by `,c.map(e=>e.title).join(`, `),`.`]}),!!e.substeps?.length&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`h4`,{children:`Sub-steps`}),(0,f.jsxs)(`p`,{className:`muted flow-field-hint`,children:[`Subagents `,e.runs===`manager`?`the manager starts`:`this block's session starts`,`, in this order; the block's outcome counts once those that run when it is done are done.`]}),(0,f.jsx)(`ol`,{className:`flow-panel-substeps`,children:e.substeps.map((t,n)=>{let i=vg(e,t);return(0,f.jsxs)(`li`,{children:[(0,f.jsx)(`div`,{children:(0,f.jsx)(`strong`,{children:i.head})}),(0,f.jsx)(`div`,{className:`muted`,children:i.detail}),i.outcomes&&(0,f.jsx)(`div`,{className:`muted`,children:i.outcomes}),i.note&&(0,f.jsxs)(`div`,{className:`flow-substep-note`,children:[i.note,`: a check of the block's own work, so its findings go back to whoever did it.`]}),t.brief&&(0,f.jsx)(sO,{file:t.brief,texts:r})]},n)})})]}),e.brief?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`h4`,{children:`Brief`}),(0,f.jsx)(sO,{file:e.brief,texts:r,open:!0})]}):e.kind!==`flow`&&(0,f.jsx)(`p`,{className:`muted`,children:`No brief.`})]})}function lO({flow:e,texts:t,onClose:n}){let r=e.blocks.filter(e=>e.runs===`manager`);return(0,f.jsxs)(`div`,{className:`flow-panel-body`,children:[(0,f.jsxs)(`div`,{className:`flow-panel-head`,children:[(0,f.jsx)(`h3`,{children:`The manager`}),(0,f.jsx)(`button`,{className:`small`,onClick:n,"aria-label":`Close the manager's file`,children:`×`})]}),(0,f.jsxs)(`p`,{className:`muted`,children:[`What the manager does between steps`,r.length?`, and in ${r.map(e=>e.title).join(`, `)}, which it runs itself`:``,`. Its instructions name this file.`]}),e.manager&&(0,f.jsx)(sO,{file:e.manager,texts:t,open:!0})]})}function uO({view:e,onManager:t}){let n=rO(e),r=n.flatMap(e=>(e.flow?.overlays??[]).map(t=>({o:t,f:e.flow}))),a=n.length>1,o=e.flow?.manager;return(0,f.jsxs)(`div`,{className:`flow-panel-body`,children:[!/^\s*#\s/.test(e.rules??``)&&(0,f.jsx)(`h3`,{children:`Standing rules`}),e.rules==null?(0,f.jsx)(`p`,{className:`muted`,children:`No rules.md: no standing rules.`}):(0,f.jsx)(i,{text:e.rules}),o&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`h3`,{children:`The manager`}),(0,f.jsxs)(`p`,{className:`flow-role-link`,children:[(0,f.jsx)(`button`,{className:`link`,onClick:t,children:`📋 Its standing procedures between steps`}),e.texts[o]===void 0?(0,f.jsxs)(`span`,{className:`flow-problem-inline`,children:[` · `,o,` is missing`]}):(0,f.jsxs)(`span`,{className:`muted mono`,children:[` · `,o]})]})]}),r.length>0&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`h3`,{children:`Overlays`}),r.map(({o:t,f:n},r)=>(0,f.jsxs)(`details`,{className:`flow-overlay`,children:[(0,f.jsxs)(`summary`,{children:[t.title,` `,(0,f.jsxs)(`span`,{className:`muted`,children:[`· changes `,t.blocks.map(nO(n)).join(`, `),a?` in ${n.title??`its flow`}`:``]})]}),e.texts[t.file]===void 0?(0,f.jsxs)(`p`,{className:`flow-problem-inline`,children:[`Its file `,t.file,` is missing.`]}):(0,f.jsx)(i,{text:e.texts[t.file]})]},r))]})]})}function dO(e){if(!e.saveTo)return`Ledung can't write into this project's folder.`;if(e.source&&!e.flow)return`flow.json can't be read as a flow, so the builder can't open it: fix it by hand first (the problems above say what).`;let t=e.flows.find(e=>!e.flow);return t?`${t.file} can't be read as a flow, so the builder can't open the workflow: fix it by hand first (its tab's problems say what).`:null}function fO({project:e,profiles:n,onSettings:r,shownFlow:i,onShowFlow:a,onRenamedFlow:o}){let[s,c]=(0,d.useState)(null),[l,u]=(0,d.useState)(null),[p,m]=(0,d.useState)(null),[h,g]=(0,d.useState)(!1),_=e=>{m(e),g(!1)},v=()=>{g(!0),m(null)},y=dD(),[b,x]=(0,d.useState)(!1),[S,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(null),E=i??`main`;(0,d.useEffect)(()=>{let n=!0;return t.flow(e).then(e=>n&&c(e),e=>n&&u(e.message)),()=>{n=!1}},[e]);let D=(0,d.useMemo)(()=>s?rO(s):[],[s]),O=D.find(e=>e.name===E)??D[0],k=(0,d.useMemo)(()=>iO(D),[D]),A=e=>{_(null),e!==E&&a(e)};(0,d.useEffect)(()=>{_(null)},[E]);let j=s&&i!==null&&!D.some(e=>e.name===i)?i:null,M=O?.flow??null,N=(0,d.useMemo)(()=>M?Cg(M):null,[M]),P=M?.blocks.find(e=>e.id===p)??null,F=h&&!!s?.flow?.manager,I=!y||b,L=s?.source,R=s?dO(s):null,z=O?.problems.filter(e=>!e.hint)??[],B=O?.problems.filter(e=>e.hint)??[],V=e=>{let t=M?.blocks.find(t=>t.id===e);t?.kind===`flow`&&t.flow!==void 0&&k(t.flow)!==void 0?A(t.flow):_(e)};return s&&S?(0,f.jsx)(RD,{project:e,view:s,initial:S,shown:E,onShowFlow:a,onRenamedFlow:o,profiles:n,narrow:y,onCancel:()=>C(null),onSaved:(e,t,n)=>{c(e),C(null),n!==E&&o(n),_(null),T(`Saved ${t===1?`one change`:`${t} changes`} into ${e.saveTo??`the project`}.`)}}):(0,f.jsxs)(`div`,{className:`page-view workflow-view`,children:[(0,f.jsxs)(`header`,{className:`session-head`,children:[(0,f.jsxs)(`div`,{className:`session-head-text`,children:[(0,f.jsxs)(`h2`,{children:[e,`: workflow`,M?.title?` · ${M.title}`:``]}),L&&(0,f.jsxs)(`div`,{className:`muted mono`,children:[L.kind===`project`?`From the project's folder: `:`From the shared workflow "${L.workflow}": `,L.folder]})]}),(0,f.jsxs)(`div`,{className:`session-corner`,children:[s?.flow&&!R&&(0,f.jsx)(`button`,{className:`small`,onClick:()=>{let e=s&&eD(s);e&&(T(null),C(e))},title:y?`Change the blocks' words and the rules; drawing is for a computer`:`Draw and change the workflow`,children:`Edit`}),(0,f.jsx)(`button`,{className:`small`,onClick:r,children:`Project settings`})]})]}),l&&(0,f.jsx)(`div`,{className:`page-body`,children:(0,f.jsx)(`p`,{className:`flow-problem-inline`,children:l})}),!s&&!l&&(0,f.jsx)(`div`,{className:`page-body`,children:(0,f.jsx)(`p`,{className:`muted`,children:`Reading the workflow…`})}),w&&(0,f.jsxs)(`div`,{className:`flow-saved`,role:`status`,children:[w,` `,(0,f.jsx)(`button`,{className:`small`,onClick:()=>T(null),"aria-label":`Close`,children:`×`})]}),s&&(0,f.jsx)(kD,{flows:D.map(e=>({name:e.name,title:e.flow?.title??e.name,bad:e.problems.filter(e=>!e.hint).length})),shown:O?.name??`main`,onShow:A}),j&&(0,f.jsxs)(`p`,{className:`muted flow-note`,children:[`This project has no flow "`,(()=>{try{return decodeURIComponent(j)}catch{return j}})(),`"; showing `,D[0]?.flow?.title??`the default flow`,` instead.`]}),s&&z.length>0&&(0,f.jsxs)(`div`,{className:`flow-problems`,role:`alert`,children:[(0,f.jsxs)(`strong`,{children:[z.length===1?`One problem`:`${z.length} problems`,` in `,O&&O.name!==`main`?O.file:`the workflow files`,M?``:`, so there is nothing to draw`,`:`]}),(0,f.jsx)(`ul`,{children:z.map((e,t)=>(0,f.jsxs)(`li`,{children:[(0,f.jsx)(`code`,{children:e.at}),` `,e.message]},t))})]}),s&&B.length>0&&(0,f.jsxs)(`details`,{className:`flow-hints`,children:[(0,f.jsx)(`summary`,{children:B.length===1?`One hint`:`${B.length} hints`}),(0,f.jsx)(`ul`,{children:B.map((e,t)=>(0,f.jsxs)(`li`,{children:[(0,f.jsx)(`code`,{children:e.at}),` `,e.message]},t))})]}),s&&s.source&&R&&(0,f.jsx)(`p`,{className:`muted flow-note`,children:R}),s&&!s.source&&(0,f.jsxs)(`div`,{className:`page-body flow-empty`,children:[(0,f.jsxs)(`p`,{children:[e,` has no drawn workflow yet.`]}),R?(0,f.jsx)(`p`,{className:`muted`,children:R}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`flow-start`,children:[(0,f.jsxs)(`button`,{onClick:()=>{let e=BT(!0,s);C($E(e.base,e.draft))},children:[(0,f.jsx)(`strong`,{children:`Start a workflow`}),(0,f.jsx)(`span`,{className:`muted`,children:`from a starter: Issue → Build → Code review → Fix → Person → Merge`})]}),!y&&(0,f.jsxs)(`button`,{onClick:()=>{let e=BT(!1,s);C($E(e.base,e.draft))},children:[(0,f.jsx)(`strong`,{children:`Start from an empty canvas`}),(0,f.jsx)(`span`,{className:`muted`,children:`drag blocks on and connect them`})]})]}),y&&(0,f.jsx)(`p`,{className:`muted`,children:`Drawing a workflow from nothing is for a computer; on a phone the starter can be changed block by block.`}),(0,f.jsxs)(`p`,{className:`muted`,children:[`It is saved as files in `,(0,f.jsx)(`code`,{children:s.saveTo}),`, the project's own folder: `,(0,f.jsx)(`code`,{children:`flow.json`}),`, the standing rules in `,(0,f.jsx)(`code`,{children:`rules.md`}),`, the manager's in `,(0,f.jsx)(`code`,{children:`manager.md`}),` and the briefs, how each step is done, in `,(0,f.jsx)(`code`,{children:`briefs/`}),`, so a change shows in git like any other. The format is described in docs/steps/workflow-builder.md in Ledung's repository.`]})]})]}),s&&N&&(0,f.jsxs)(`div`,{className:`flow-main${(P||F)&&y?` block-open`:``}`,children:[(0,f.jsxs)(`div`,{className:`flow-drawing`,children:[y&&(0,f.jsxs)(`div`,{className:`flow-switch`,role:`group`,"aria-label":`Show as`,children:[(0,f.jsx)(`button`,{className:`small${I?``:` on`}`,"aria-pressed":!I,onClick:()=>x(!1),children:`List`}),(0,f.jsx)(`button`,{className:`small${I?` on`:``}`,"aria-pressed":I,onClick:()=>x(!0),children:`Diagram`})]}),I?(0,f.jsx)(aO,{flow:M,layout:N,texts:s.texts,selected:p,onSelect:V,narrow:y,flowTitle:k},`${s.project}:${O?.name}`):(0,f.jsx)(oO,{flow:M,layout:N,texts:s.texts,onSelect:V,flowTitle:k})]}),(0,f.jsx)(`aside`,{className:`flow-panel`,children:P?(0,f.jsx)(cO,{block:P,flow:M,layout:N,texts:s.texts,onBlock:_,onClose:()=>_(null),flowTitle:k,onFlow:A}):F?(0,f.jsx)(lO,{flow:s.flow,texts:s.texts,onClose:()=>g(!1)}):(0,f.jsx)(uO,{view:s,onManager:v})})]})]})}export{fO as WorkflowView};