koppler 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,7 @@ It helps most when you work on one app (a mobile app, a front end, one API) and
11
11
 
12
12
  <picture>
13
13
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/evan-mcgeek/koppler/main/docs/images/board-dark.png">
14
- <img alt="The Koppler canvas: a mobile app and a web shop cabled to a local Orders API, which calls a local Payments API, with its database tunnel and queue; every app running" src="https://raw.githubusercontent.com/evan-mcgeek/koppler/main/docs/images/board-light.png">
14
+ <img alt="One feature, Checkout, worked on across four apps: the mobile app and web shop cabled to a local Orders API, which calls a local Payments API; each runs its feature/checkout branch, Orders API has a database tunnel and a local SQS queue, two apps carry a note for the agent, and everything runs" src="https://raw.githubusercontent.com/evan-mcgeek/koppler/main/docs/images/board-light.png">
15
15
  </picture>
16
16
 
17
17
  ## How it works
@@ -26,7 +26,7 @@ It helps most when you work on one app (a mobile app, a front end, one API) and
26
26
 
27
27
  <picture>
28
28
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/evan-mcgeek/koppler/main/docs/images/review-dark.png">
29
- <img alt="The review before a Run: the apps that start, with their branches, what keeps calling the deployed QA environment, and the tunnel that opens" src="https://raw.githubusercontent.com/evan-mcgeek/koppler/main/docs/images/review-light.png" width="520">
29
+ <img alt="The review before a Run on QA: the four apps that start on feature/checkout with their notes for the agent, what keeps calling deployed QA, and the tunnel that opens" src="https://raw.githubusercontent.com/evan-mcgeek/koppler/main/docs/images/review-light.png" width="520">
30
30
  </picture>
31
31
 
32
32
  ## Install
package/dist/.built CHANGED
@@ -1 +1 @@
1
- 2026-10-15T20:30:45.638Z
1
+ 2026-10-15T21:20:55.838Z
@@ -1,6 +1,6 @@
1
1
  (function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=Array.isArray,t=Array.prototype.indexOf,n=Array.prototype.includes,r=Array.from,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyDescriptors,s=Object.prototype,c=Array.prototype,l=Object.getPrototypeOf,u=Object.isExtensible;function d(e){return typeof e==`function`}var f=()=>{};function p(e){return typeof e?.then==`function`}function m(e){return e()}function h(e){for(var t=0;t<e.length;t++)e[t]()}function g(){var e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function _(e,t,n=!1){return e===void 0?n?t():t:e}function v(e,t){if(Array.isArray(e))return e;if(t===void 0||!(Symbol.iterator in e))return Array.from(e);let n=[];for(let r of e)if(n.push(r),n.length===t)break;return n}function y(e,t){var n={};for(var r in e)t.includes(r)||(n[r]=e[r]);for(var i of Object.getOwnPropertySymbols(e))Object.propertyIsEnumerable.call(e,i)&&!t.includes(i)&&(n[i]=e[i]);return n}var b=1<<24,x=1024,S=2048,C=4096,w=8192,ee=16384,T=32768,te=1<<25,E=65536,ne=1<<19,re=1<<20,ie=1<<25,ae=1<<21,oe=1<<22,se=1<<23,ce=Symbol(`$state`),le=Symbol(`component`),ue=Symbol(`legacy props`),de=Symbol(``),fe=Symbol(`attributes`),pe=Symbol(`class`),me=Symbol(`style`),he=Symbol(`text`),ge=Symbol(`form reset`),_e=new class extends Error{name=`StaleReactionError`;message="The reaction that called `getAbortSignal()` was re-run or destroyed"},ve=!!globalThis.document?.contentType&&globalThis.document.contentType.includes(`xml`),ye={},be=Symbol(`uninitialized`),xe=`http://www.w3.org/1999/xhtml`,Se=`http://www.w3.org/2000/svg`;function Ce(){console.warn(`https://svelte.dev/e/derived_inert`)}function we(e){console.warn(`https://svelte.dev/e/hydration_mismatch`)}function Te(){console.warn(`https://svelte.dev/e/select_multiple_invalid_value`)}function Ee(){console.warn(`https://svelte.dev/e/svelte_boundary_reset_noop`)}var D=!1;function De(e){D=e}var Oe;function ke(e){if(e===null)throw we(),ye;return Oe=e}function Ae(){return ke(wn(Oe))}function O(e){if(D){if(wn(Oe)!==null)throw we(),ye;Oe=e}}function je(e=1){if(D){for(var t=e,n=Oe;t--;)n=wn(n);Oe=n}}function Me(e=!0){for(var t=0,n=Oe;;){if(n.nodeType===8){var r=n.data;if(r===`]`){if(t===0)return n;--t}else(r===`[`||r===`[!`||r[0]===`[`&&!isNaN(Number(r.slice(1))))&&(t+=1)}var i=wn(n);e&&n.remove(),n=i}}function Ne(e){if(!e||e.nodeType!==8)throw we(),ye;return e.data}function Pe(e){return e===this.v}function Fe(e,t){return e==e?e!==t||typeof e==`object`&&!!e||typeof e==`function`:t==t}function Ie(e){return!Fe(e,this.v)}function Le(e){throw Error(`https://svelte.dev/e/lifecycle_outside_component`)}function Re(){throw Error(`https://svelte.dev/e/async_derived_orphan`)}function ze(e,t,n){throw Error(`https://svelte.dev/e/each_key_duplicate`)}function Be(e){throw Error(`https://svelte.dev/e/effect_in_teardown`)}function Ve(){throw Error(`https://svelte.dev/e/effect_in_unowned_derived`)}function He(e){throw Error(`https://svelte.dev/e/effect_orphan`)}function Ue(){throw Error(`https://svelte.dev/e/effect_update_depth_exceeded`)}function We(e){throw Error(`https://svelte.dev/e/props_invalid_value`)}function Ge(){throw Error(`https://svelte.dev/e/state_descriptors_fixed`)}function Ke(){throw Error(`https://svelte.dev/e/state_prototype_fixed`)}function qe(){throw Error(`https://svelte.dev/e/state_unsafe_mutation`)}function Je(){throw Error(`https://svelte.dev/e/svelte_boundary_reset_onerror`)}var Ye=!1;function Xe(){Ye=!0}var Ze=[];function Qe(e,t=!1,n=!1){return $e(e,new Map,``,Ze,null,n)}function $e(t,n,r,i,a=null,o=!1){if(typeof t==`object`&&t){var c=n.get(t);if(c!==void 0)return c;if(t instanceof Map)return new Map(t);if(t instanceof Set)return new Set(t);if(e(t)){var u=Array(t.length);n.set(t,u),a!==null&&n.set(a,u);for(var d=0;d<t.length;d+=1){var f=t[d];d in t&&(u[d]=$e(f,n,r,i,null,o))}return u}if(l(t)===s){u={},n.set(t,u),a!==null&&n.set(a,u);for(var p of Object.keys(t))u[p]=$e(t[p],n,r,i,null,o);return u}if(t instanceof Date)return t.getTime(),structuredClone(t);if(typeof t.toJSON==`function`&&!o)return $e(t.toJSON(),n,r,i,t)}if(t instanceof EventTarget)return t;try{return structuredClone(t)}catch{return t}}function et(e){let t=e.p;for(;t!==null&&t.c===null;)t=t.p;return t?.c??null}function tt(e,t){return e===null&&Le(t),e.c??=new Map(et(e)||void 0)}var nt=null;function rt(e){nt=e}function it(e){return tt(nt,`getContext`).get(e)}function at(e,t){return tt(nt,`setContext`).set(e,t),t}function ot(e){return tt(nt,`hasContext`).has(e)}function k(e,t=!1,n){nt={p:nt,i:!1,c:null,e:null,s:e,x:null,r:ur,l:Ye&&!t?{s:null,u:null,$:[]}:null}}function A(e){var t=nt,n=t.e;if(n!==null){t.e=null;for(var r of n)Ln(r)}return e!==void 0&&(t.x=e),t.i=!0,nt=t.p,st(e)}function st(e={}){return i(e,le,{value:!0}),e}function ct(){return!Ye||nt!==null&&nt.l===null}var lt=[];function ut(){var e=lt;lt=[],h(e)}function dt(e){if(lt.length===0&&!Vt){var t=lt;queueMicrotask(()=>{t===lt&&ut()})}lt.push(e)}function ft(){for(;lt.length>0;)ut()}var pt=~(S|C|x);function mt(e,t){e.f=e.f&pt|t}function ht(e){e.f&512||e.deps===null?mt(e,x):mt(e,C)}function gt(e,t,n){e.f&2048?t.add(e):e.f&4096&&n.add(e),mt(e,x)}function _t(e,t){if(t){let t=document.body;e.autofocus=!0,dt(()=>{document.activeElement===t&&e.focus()})}}function vt(e){D&&Cn(e)!==null&&Tn(e)}var yt=!1;function bt(){yt||(yt=!0,document.addEventListener(`reset`,e=>{Promise.resolve().then(()=>{if(!e.defaultPrevented)for(let t of e.target.elements)t[ge]?.()})},{capture:!0}))}function xt(e){var t=sr,n=ur;lr(null),dr(null);try{return e()}finally{lr(t),dr(n)}}function St(e,t,n,r=n){e.addEventListener(t,()=>xt(n));let i=e[ge];e[ge]=i?()=>{i(),r(!0)}:()=>r(!0),bt()}function Ct(e,t,n,r){let i=ct()?Dt:At;var a=e.filter(e=>!e.settled),o=t.map(i);if(n.length===0&&a.length===0){r(o);return}var s=ur,c=wt(),l=a.length===1?a[0].promise:a.length>1?Promise.all(a.map(e=>e.promise)):null;function u(e){if(!(s.f&16384)){c();try{r([...o,...e])}catch(e){An(e,s)}Tt()}}var d=Et();if(n.length===0){l.then(()=>u([])).finally(d);return}function f(){Promise.all(n.map(e=>kt(e))).then(u).catch(e=>An(e,s)).finally(d)}l?l.then(()=>{s.f&16384?d():(c(),f(),Tt())}):f()}function wt(){var e=ur,t=sr,n=nt,r=Lt;return function(i=!0){dr(e),lr(t),rt(n),i&&!(e.f&16384)&&(r?.activate(),r?.apply())}}function Tt(e=!0){dr(null),lr(null),rt(null),e&&Lt?.deactivate()}function Et(){var e=ur,t=e.b,n=Lt,r=!!t?.is_rendered();return t?.update_pending_count(1,n),n.increment(r,e),()=>{t?.update_pending_count(-1,n),n.decrement(r,e)}}function Dt(e){var t=2|S;return ur!==null&&(ur.f|=ne),{ctx:nt,deps:null,effects:null,equals:Pe,f:t,fn:e,reactions:null,rv:0,v:be,wv:0,parent:ur,ac:null}}var Ot=Symbol(`obsolete`);function kt(e,t,n){let r=ur;r===null&&Re();var i=void 0,a=an(be),o=!sr,s=new Set;return Hn(()=>{var t=ur,n=g();i=n.promise;try{Promise.resolve(e()).then(n.resolve,e=>{e!==_e&&n.reject(e)}).finally(Tt)}catch(e){n.reject(e),Tt()}var c=Lt;if(o){if(t.f&32768)var l=Et();if(r.b?.is_rendered())c.async_deriveds.get(t)?.reject(Ot);else for(let e of s.values())e.reject(Ot);s.add(n),c.async_deriveds.set(t,n)}let u=(e,t=void 0)=>{l?.(),s.delete(n),t!==Ot&&(c.activate(),t?(a.f|=se,ln(a,t)):(a.f&8388608&&(a.f^=se),ln(a,e)),c.deactivate())};n.promise.then(u,e=>u(null,e||`unknown`))}),Fn(()=>{for(let e of s)e.reject(Ot)}),new Promise(e=>{function t(n){function r(){n===i?e(a):t(i)}n.then(r,r)}t(i)})}function j(e){let t=Dt(e);return pr(t),t}function At(e){let t=Dt(e);return t.equals=Ie,t}function jt(e){var t=e.effects;if(t!==null){e.effects=null;for(var n=0;n<t.length;n+=1)Xn(t[n])}}function Mt(e){var t,n=ur,r=e.parent;if(!ar&&r!==null&&e.v!==be&&r.f&24576)return Ce(),e.v;dr(r);try{jt(e),t=Tr(e)}finally{dr(n)}return t}function Nt(e){var t=Mt(e);!e.equals(t)&&(e.wv=Sr(),(!Lt?.is_fork||e.deps===null)&&(Lt===null?e.v=t:(Lt.capture(e,t,!0),Rt?.capture(e,t,!0)),e.deps===null))?mt(e,x):ar||(zt===null?ht(e):(Pn()||Lt?.is_fork)&&zt.set(e,t))}function Pt(e){if(e.effects!==null)for(let t of e.effects)(t.teardown||t.ac)&&(t.teardown?.(),t.ac!==null&&xt(()=>{t.ac.abort(_e),t.ac=null}),t.fn!==null&&(t.teardown=f),Or(t,0),Jn(t))}function Ft(e){if(e.effects!==null)for(let t of e.effects)t.teardown&&t.fn!==null&&kr(t)}var It=null,Lt=null,Rt=null,zt=null,Bt=null,Vt=!1,Ht=!1,Ut=null,Wt=null,Gt=0,Kt=1,qt=class e{id=Kt++;#e=!1;linked=!0;#t=null;#n=null;async_deriveds=new Map;current=new Map;previous=new Map;#r=new Set;#i=new Set;#a=0;#o=new Map;#s=null;#c=[];#l=[];#u=new Set;#d=new Set;#f=new Map;#p=new Set;is_fork=!1;#m=!1;constructor(){It===null?It=this:(It.#n=this,this.#t=It),It=this}#h(){if(this.is_fork)return!0;for(let n of this.#o.keys()){for(var e=n,t=!1;e.parent!==null;){if(this.#f.has(e)){t=!0;break}e=e.parent}if(!t)return!0}return!1}skip_effect(e){this.#f.has(e)||this.#f.set(e,{d:[],m:[]}),this.#p.delete(e)}unskip_effect(e,t=e=>this.schedule(e)){var n=this.#f.get(e);if(n){this.#f.delete(e);for(var r of n.d)mt(r,S),t(r);for(r of n.m)mt(r,C),t(r)}this.#p.add(e)}#g(){var e=[];for(let i of this.#c)if(!(i.f&16384||!(i.f&6144))){for(var t=i,n=!1;t.parent!==null;){t=t.parent;var r=t.f;if(r&96){if(!(r&1024)){n=!0;break}t.f^=x}}n||e.push(t)}return this.#c=[],e}#_(){this.#e=!0;for(let e of this.#u)this.#d.delete(e),mt(e,S),this.schedule(e);for(let e of this.#d)mt(e,C),this.schedule(e);this.apply();for(var t=Ut=[],n=[],r=Wt=[];this.#c.length>0;){Gt++>1e3&&(this.#S(),Yt());for(let e of this.#g())try{this.#v(e,t,n)}catch(t){throw en(e),this.#h()||this.discard(),t}}if(Lt=null,r.length>0){var i=e.ensure();for(let e of r)i.schedule(e)}if(Ut=null,Wt=null,this.#h()){this.#x(n),this.#x(t);for(let[e,t]of this.#f)$t(e,t);r.length>0&&Lt.#_();return}let a=this.#y();if(a)this.#x(n),this.#x(t),a.#b(this);else{this.#u.clear(),this.#d.clear();for(let e of this.#r)e(this);this.#r.clear(),Rt=this,Zt(n),Zt(t),Rt=null,this.#s?.resolve();var o=Lt;if(this.#a===0&&(this.#c.length===0||o!==null)&&this.#S(),this.#c.length>0){if(o!==null){for(let e of this.#c)o.#c.push(e);this.#c=[]}else o=this}o!==null&&(nn.clear(),o.#_())}}#v(e,t,n){e.f^=x;for(var r=e.first;r!==null;){var i=r.f,a=!!(i&96);if(!(a&&i&1024||i&8192||this.#f.has(r))&&r.fn!==null){a?r.f^=x:i&4?t.push(r):Cr(r)&&(i&16&&this.#d.add(r),kr(r));var o=r.first;if(o!==null){r=o;continue}}for(;r!==null;){var s=r.next;if(s!==null){r=s;break}r=r.parent}}}#y(){for(var e=this.#t;e!==null;){if(!e.is_fork){for(let[t,[,n]]of this.current)if(e.current.has(t)&&!n)return e}e=e.#t}return null}#b(e){for(let[t,n]of e.current)!this.previous.has(t)&&e.previous.has(t)&&this.previous.set(t,e.previous.get(t)),this.current.set(t,n);for(let[t,n]of e.async_deriveds){let e=this.async_deriveds.get(t);e&&n.promise.then(e.resolve).catch(e.reject)}e.async_deriveds.clear(),this.transfer_effects(e.#u,e.#d);let t=e=>{var n=e.reactions;if(n!==null&&!(e.f&2&&!(e.f&6144)))for(let e of n){var r=e.f;if(r&2)t(e);else{var i=e;r&4194320&&!this.async_deriveds.has(i)&&(this.#d.delete(i),mt(i,S),this.schedule(i))}}};for(let e of this.current.keys())t(e);this.oncommit(()=>e.discard()),e.#S(),Lt=this,this.#_()}#x(e){for(var t=0;t<e.length;t+=1)gt(e[t],this.#u,this.#d)}capture(e,t,n=!1){e.v!==be&&!this.previous.has(e)&&this.previous.set(e,e.v),e.f&8388608||(this.current.set(e,[t,n]),zt?.set(e,t)),this.is_fork||(e.v=t)}activate(){Lt=this}deactivate(){Lt=null,zt=null}flush(){try{Ht=!0,Lt=this,this.#_()}finally{Gt=0,Bt=null,Ut=null,Wt=null,Ht=!1,Lt=null,zt=null,nn.clear()}}discard(){for(let e of this.#i)e(this);this.#i.clear();for(let e of this.async_deriveds.values())e.reject(Ot);this.#S(),this.#s?.resolve()}register_created_effect(e){this.#l.push(e)}increment(e,t){if(this.#a+=1,e){let e=this.#o.get(t)??0;this.#o.set(t,e+1)}}decrement(e,t){if(--this.#a,e){let e=this.#o.get(t)??0;e===1?this.#o.delete(t):this.#o.set(t,e-1)}this.#m||(this.#m=!0,dt(()=>{this.#m=!1,this.linked&&this.flush()}))}transfer_effects(e,t){for(let t of e)this.#u.add(t);for(let e of t)this.#d.add(e);e.clear(),t.clear()}oncommit(e){this.#r.add(e)}ondiscard(e){this.#i.add(e)}settled(){return(this.#s??=g()).promise}static ensure(){if(Lt===null){let t=Lt=new e;!Ht&&!Vt&&dt(()=>{t.#e||t.flush()})}return Lt}apply(){zt=null}schedule(e){Bt=e,e.b?.is_pending&&e.f&16777228&&!(e.f&32768)?e.b.defer_effect(e):this.#c.push(e)}#S(){if(this.linked){var e=this.#t,t=this.#n;e===null||(e.#n=t),t===null?It=e:t.#t=e,this.linked=!1}}};function Jt(e){var t=Vt,n=Rt;Rt=null,Vt=!0;try{var r;for(e&&(Jt(),r=e());;){if(ft(),Lt===null)return r;Lt.flush()}}finally{Vt=t,Rt=n}}function Yt(){try{Ue()}catch(e){An(e,Bt)}}var Xt=null;function Zt(e){var t=e.length;if(t!==0){for(var n=0;n<t;){var r=e[n++];if(!(r.f&24576)&&Cr(r)&&(Xt=new Set,kr(r),r.deps===null&&r.first===null&&r.nodes===null&&r.teardown===null&&r.ac===null&&Qn(r),Xt?.size>0)){nn.clear();for(let e of Xt){if(e.f&24576)continue;let t=[e],n=e.parent;for(;n!==null;)Xt.has(n)&&(Xt.delete(n),t.push(n)),n=n.parent;for(let e=t.length-1;e>=0;e--){let n=t[e];n.f&24576||kr(n)}}Xt.clear()}}Xt=null}}function Qt(e){Lt.schedule(e)}function $t(e,t){if(!(e.f&32&&e.f&1024)){e.f&2048?t.d.push(e):e.f&4096&&t.m.push(e),mt(e,x);for(var n=e.first;n!==null;)$t(n,t),n=n.next}}function en(e){mt(e,x);for(var t=e.first;t!==null;)en(t),t=t.next}var tn=new Set,nn=new Map,rn=!1;function an(e,t){return{f:0,v:e,reactions:null,equals:Pe,rv:0,wv:0}}function M(e,t){let n=an(e,t);return pr(n),n}function on(e,t=!1,n=!0){let r=an(e);return t||(r.equals=Ie),Ye&&n&&nt!==null&&nt.l!==null&&(nt.l.s??=[]).push(r),r}function N(e,t,n=!1){return sr!==null&&(!cr||sr.f&131072)&&ct()&&sr.f&4325394&&(fr===null||!fr.has(e))&&qe(),ln(e,n?pn(t):t,Wt)}var sn=null,cn=0;function ln(e,t,n=null){if(!e.equals(t)){ar?nn.set(e,t):nn.has(e)||nn.set(e,e.v);var r=qt.ensure();if(r.capture(e,t),e.f&2){let t=e;e.f&2048&&Mt(t),zt===null&&ht(t)}e.wv=Sr(),sn=null,cn=0,fn(e,S,n),sn=null,ct()&&ur!==null&&ur.f&1024&&!(ur.f&96)&&(gr===null?_r([e]):gr.push(e)),!r.is_fork&&tn.size>0&&!rn&&un()}return t}function un(){rn=!1;for(let e of tn){e.f&1024&&mt(e,C);let t;try{t=Cr(e)}catch{t=!0}t&&kr(e)}tn.clear()}function dn(e){N(e,e.v+1)}function fn(e,t,n){var r=e.reactions;if(r!==null){var i=ct(),a=r.length;if(cn+=a,cn>1e5&&sn===null&&(sn=new Set),sn!==null){if(sn.has(e))return;sn.add(e)}for(var o=0;o<a;o++){var s=r[o],c=s.f;if(i||s!==ur){var l=(c&S)===0;if(l&&mt(s,t),c&131072)tn.add(s);else if(c&2){var u=s;zt?.delete(u),fn(u,C,n)}else if(l){var d=s;c&16&&Xt!==null&&Xt.add(d),n===null?Qt(d):n.push(d)}}}}}function pn(t){if(typeof t!=`object`||!t||ce in t||le in t)return t;let n=l(t);if(n!==s&&n!==c)return t;var r=new Map,i=e(t),o=M(0),u=null,d=br,f=e=>{if(br===d)return e();var t=sr,n=br;lr(null),xr(d);var r=e();return lr(t),xr(n),r};return i&&r.set(`length`,M(t.length,u)),new Proxy(t,{defineProperty(e,t,n){(!(`value`in n)||n.configurable===!1||n.enumerable===!1||n.writable===!1)&&Ge();var i=r.get(t);return i===void 0?f(()=>{var e=M(n.value,u);return r.set(t,e),e}):N(i,n.value,!0),!0},deleteProperty(e,t){var n=r.get(t);if(n===void 0){if(t in e){let e=f(()=>M(be,u));r.set(t,e),dn(o)}}else N(n,be),dn(o);return!0},get(e,n,i){if(n===ce)return t;var o=r.get(n),s=n in e;if(o===void 0&&(!s||a(e,n)?.writable)&&(o=f(()=>M(pn(s?e[n]:be),u)),r.set(n,o)),o!==void 0){var c=z(o);return c===be?void 0:c}return Reflect.get(e,n,i)},getOwnPropertyDescriptor(e,t){this.has?.(e,t);var n=Reflect.getOwnPropertyDescriptor(e,t),i=r.get(t);if(i!==void 0){var a=z(i);if(a===be)return;if(n&&`value`in n)n.value=a;else return{enumerable:!0,configurable:!0,value:a,writable:!0}}return n},has(e,t){if(t===ce)return!0;var n=r.get(t),i=n!==void 0&&n.v!==be||Reflect.has(e,t);return(n!==void 0||ur!==null&&(!i||a(e,t)?.writable))&&(n===void 0&&(n=f(()=>M(i?pn(e[t]):be,u)),r.set(t,n)),z(n)===be)?!1:i},set(e,t,n,s){var c=r.get(t),l=t in e;if(i&&t===`length`)for(var d=n;d<c.v;d+=1){var p=r.get(d+``);p===void 0?d in e&&(p=f(()=>M(be,u)),r.set(d+``,p)):N(p,be)}if(c===void 0)(!l||a(e,t)?.writable)&&(c=f(()=>M(void 0,u)),N(c,pn(n)),r.set(t,c));else{l=c.v!==be;var m=f(()=>pn(n));N(c,m)}var h=Reflect.getOwnPropertyDescriptor(e,t);if(h?.set&&h.set.call(s,n),!l){if(i&&typeof t==`string`){var g=r.get(`length`),_=Number(t);Number.isInteger(_)&&_>=g.v&&N(g,_+1)}dn(o)}return!0},ownKeys(e){z(o);var t=Reflect.ownKeys(e).filter(e=>{var t=r.get(e);return t===void 0||t.v!==be});for(var[n,i]of r)i.v!==be&&!(n in e)&&t.push(n);return t},setPrototypeOf(){Ke()}})}function mn(e){try{if(typeof e==`object`&&e&&ce in e)return e[ce]}catch{}return e}function hn(e,t){return Object.is(mn(e),mn(t))}var gn,_n,vn,yn,bn;function xn(){if(gn===void 0){gn=window,_n=document,vn=/Firefox/.test(navigator.userAgent);var e=Element.prototype,t=Node.prototype,n=Text.prototype;yn=a(t,`firstChild`).get,bn=a(t,`nextSibling`).get,u(e)&&(e[pe]=void 0,e[fe]=null,e[me]=void 0,e.__e=void 0),u(n)&&(n[he]=void 0)}}function Sn(e=``){return document.createTextNode(e)}function Cn(e){return yn.call(e)}function wn(e){return bn.call(e)}function P(e,t){if(!D)return Cn(e);var n=Cn(Oe);if(n===null)n=Oe.appendChild(Sn());else if(t&&n.nodeType!==3){var r=Sn();return n?.before(r),ke(r),r}return t&&On(n),ke(n),n}function F(e,t=!1){if(!D){var n=Cn(e);return n instanceof Comment&&n.data===``?wn(n):n}if(t){if(Oe?.nodeType!==3){var r=Sn();return Oe?.before(r),ke(r),r}On(Oe)}return Oe}function I(e,t=!1){if(!D)return Cn(e);var n=P(e,t);return O(e),n}function L(e,t=1,n=!1){let r=D?Oe:e;for(var i;t--;)i=r,r=wn(r);if(!D)return r;if(n){if(r?.nodeType!==3){var a=Sn();return r===null?i?.after(a):r.before(a),ke(a),a}On(r)}return ke(r),r}function Tn(e){e.textContent=``}function En(){return!1}function Dn(e,t,n){return t==null||t===`http://www.w3.org/1999/xhtml`?n?document.createElement(e,{is:n}):document.createElement(e):n?document.createElementNS(t,e,{is:n}):document.createElementNS(t,e)}function On(e){if(e.nodeValue.length<65536)return;let t=e.nextSibling;for(;t!==null&&t.nodeType===3;)t.remove(),e.nodeValue+=t.nodeValue,t=e.nextSibling}function kn(e){var t=ur;if(t===null)return sr.f|=se,e;if(!(t.f&32768)&&!(t.f&4))throw e;An(e,t)}function An(e,t){if(e===ye)throw e;if(!(t!==null&&t.f&16384)){for(;t!==null;){if(t.f&128&&!(t.f&33570816)){if(!(t.f&32768))throw e;try{t.b.error(e);return}catch(t){e=t}}t=t.parent}throw e}}function jn(e){ur===null&&(sr===null&&He(e),Ve()),ar&&Be(e)}function Mn(e,t){var n=t.last;n===null?t.last=t.first=e:(n.next=e,e.prev=n,t.last=e)}function Nn(e,t){var n=ur;n!==null&&n.f&8192&&(e|=w);var r={ctx:nt,deps:null,nodes:null,f:e|S|512,first:null,fn:t,last:null,next:null,parent:n,b:n&&n.b,prev:null,teardown:null,wv:0,ac:null};Lt?.register_created_effect(r);var i=r;if(e&4)Ut===null?qt.ensure().schedule(r):Ut.push(r);else if(t!==null){try{kr(r)}catch(e){throw Xn(r),e}i.deps===null&&i.teardown===null&&i.nodes===null&&i.first===i.last&&!(i.f&524288)&&(i=i.first,e&16&&e&65536&&i!==null&&(i.f|=E))}if(i!==null&&(i.parent=n,n!==null&&Mn(i,n),sr!==null&&sr.f&2&&!(e&64))){var a=sr;(a.effects??=[]).push(i)}return r}function Pn(){return sr!==null&&!cr}function Fn(e){let t=Nn(8,null);return mt(t,x),t.teardown=e,t}function In(e){jn(`$effect`);var t=ur.f;if(!sr&&t&32&&nt!==null&&!nt.i){var n=nt;(n.e??=[]).push(e)}else return Ln(e)}function Ln(e){return Nn(4|re,e)}function Rn(e){return jn(`$effect.pre`),Nn(8|re,e)}function zn(e){qt.ensure();let t=Nn(64|ne,e);return()=>{Xn(t)}}function Bn(e){qt.ensure();let t=Nn(64|ne,e);return(e={})=>new Promise(n=>{e.outro?$n(t,()=>{Xn(t),n(void 0)}):(Xn(t),n(void 0))})}function Vn(e){return Nn(4,e)}function Hn(e){return Nn(oe|ne,e)}function Un(e,t=0){return Nn(8|t,e)}function R(e,t=[],n=[],r=[]){Ct(r,t,n,t=>{Nn(8,()=>{e(...t.map(z))})})}function Wn(e,t=0){return Nn(16|t,e)}function Gn(e,t=0){return Nn(b|t,e)}function Kn(e){return Nn(32|ne,e)}function qn(e){var t=e.teardown;if(t!==null){let n=ar,r=sr;or(!0),lr(null);try{t.call(null)}catch(t){An(t,e.parent)}finally{or(n),lr(r)}}}function Jn(e,t=!1){var n=e.first;for(e.first=e.last=null;n!==null;){let e=n.ac;e!==null&&xt(()=>{e.abort(_e)});var r=n.next;n.f&64?n.parent=null:Xn(n,t),n=r}}function Yn(e){for(var t=e.first;t!==null;){var n=t.next;t.f&32||Xn(t),t=n}}function Xn(e,t=!0){var n=!1;(t||e.f&262144)&&e.nodes!==null&&e.nodes.end!==null&&(Zn(e.nodes.start,e.nodes.end),n=!0),e.f|=te,Jn(e,t&&!n),Or(e,0);var r=e.nodes&&e.nodes.t;if(r!==null)for(let e of r)e.stop();qn(e),e.f^=te,e.f|=ee;var i=e.parent;i!==null&&i.first!==null&&Qn(e),e.next=e.prev=e.teardown=e.ctx=e.deps=e.fn=e.nodes=e.ac=e.b=null}function Zn(e,t){for(;e!==null;){var n=e===t?null:wn(e);e.remove(),e=n}}function Qn(e){var t=e.parent,n=e.prev,r=e.next;n!==null&&(n.next=r),r!==null&&(r.prev=n),t!==null&&(t.first===e&&(t.first=r),t.last===e&&(t.last=n))}function $n(e,t,n=!0){var r=[];e.f|=256,er(e,r,!0);var i=()=>{n&&Xn(e),t&&t()},a=r.length;if(a>0){var o=()=>--a||i();for(var s of r)s.out(o)}else i()}function er(e,t,n){if(!(e.f&8192)){e.f^=w;var r=e.nodes&&e.nodes.t;if(r!==null)for(let e of r)(e.is_global||n)&&t.push(e);for(var i=e.first;i!==null;){var a=i.next;if(!(i.f&64)){var o=!!(i.f&65536)||!!(i.f&32)&&!!(e.f&16);er(i,t,o?n:!1)}i=a}}}function tr(e){e.f&=-257,nr(e,!0)}function nr(e,t){if(!(e.f&256)&&e.f&8192){e.f^=w,e.f&1024||(mt(e,S),qt.ensure().schedule(e));for(var n=e.first;n!==null;){var r=n.next,i=!!(n.f&65536)||!!(n.f&32);nr(n,i?t:!1),n=r}var a=e.nodes&&e.nodes.t;if(a!==null)for(let e of a)(e.is_global||t)&&e.in()}}function rr(e,t){if(e.nodes)for(var n=e.nodes.start,r=e.nodes.end;n!==null;){var i=n===r?null:wn(n);t.append(n),n=i}}var ir=null,ar=!1;function or(e){ar=e}var sr=null,cr=!1;function lr(e){sr=e}var ur=null;function dr(e){ur=e}var fr=null;function pr(e){sr!==null&&(sr.f&2097152||sr.f&2)&&(fr??=new Set).add(e)}var mr=null,hr=0,gr=null;function _r(e){gr=e}var vr=1,yr=0,br=yr;function xr(e){br=e}function Sr(){return++vr}function Cr(e){var t=e.f;if(t&2048)return!0;if(t&4096){for(var n=e.deps,r=n.length,i=0;i<r;i++){var a=n[i];if(Cr(a)&&Nt(a),a.wv>e.wv)return!0}t&512&&zt===null&&mt(e,x)}return!1}function wr(e,t,n=!0){var r=e.reactions;if(r!==null&&!(fr!==null&&fr.has(e)))for(var i=0;i<r.length;i++){var a=r[i];a.f&2?wr(a,t,!1):t===a&&(n?mt(a,S):a.f&1024&&mt(a,C),Qt(a))}}function Tr(e){var t=mr,n=hr,r=gr,i=sr,a=fr,o=nt,s=cr,c=br,l=e.f;mr=null,hr=0,gr=null,sr=l&96?null:e,fr=null,rt(e.ctx),cr=!1,br=++yr,e.ac!==null&&(xt(()=>{e.ac.abort(_e)}),e.ac=null);try{e.f|=ae;var u=e.fn,d=u();e.f|=T;var f=Er(e);if(ct()&&gr!==null&&!cr&&f!==null&&!(e.f&6146))for(var p=0;p<gr.length;p++)wr(gr[p],e);if(i!==null&&i!==e){if(yr++,i.deps!==null)for(let e=0;e<n;e+=1)i.deps[e].rv=yr;if(t!==null)for(let e of t)e.rv=yr;gr!==null&&(r===null?r=gr:r.push(...gr))}return e.f&8388608&&(e.f^=se),d}catch(t){return Er(e),kn(t)}finally{e.f^=ae,mr=t,hr=n,gr=r,sr=i,fr=a,rt(o),cr=s,br=c}}function Er(e){var t=e.deps,n=Lt?.is_fork;if(mr!==null){var r;if(n||Or(e,hr),t!==null&&hr>0)for(t.length=hr+mr.length,r=0;r<mr.length;r++)t[hr+r]=mr[r];else e.deps=t=mr;if(Pn()&&e.f&512)for(r=hr;r<t.length;r++)(t[r].reactions??=[]).push(e)}else!n&&t!==null&&hr<t.length&&(Or(e,hr),t.length=hr);return t}function Dr(e,r){let i=r.reactions;if(i!==null){var a=t.call(i,e);if(a!==-1){var o=i.length-1;o===0?i=r.reactions=null:(i[a]=i[o],i.pop())}}if(i===null&&r.f&2&&(mr===null||!n.call(mr,r))){var s=r;s.f&512&&(s.f^=512),s.v!==be&&ht(s),s.ac!==null&&xt(()=>{s.ac.abort(_e),s.ac=null,mt(s,S)}),Pt(s),Or(s,0)}}function Or(e,t){var n=e.deps;if(n!==null)for(var r=t;r<n.length;r++)Dr(e,n[r])}function kr(e){var t=e.f;if(!(t&16384)){mt(e,x);var n=ur;ur=e;try{t&16777232?Yn(e):Jn(e),qn(e);var r=Tr(e);e.teardown=typeof r==`function`?r:null,e.wv=vr}finally{ur=n}}}async function Ar(){await Promise.resolve(),Jt()}function z(e){var t=!!(e.f&2);if(ir?.add(e),sr!==null&&!cr&&!(ur!==null&&ur.f&16384)&&(fr===null||!fr.has(e))){var r=sr.deps;if(sr.f&2097152)e.rv<yr&&(e.rv=yr,mr===null&&r!==null&&r[hr]===e?hr++:mr===null?mr=[e]:mr.push(e));else{sr.deps??=[],n.call(sr.deps,e)||sr.deps.push(e);var i=e.reactions;i===null?e.reactions=[sr]:n.call(i,sr)||i.push(sr)}}if(ar&&nn.has(e))return nn.get(e);if(t){var a=e;if(ar){var o=a.v;return(!(a.f&1024)&&a.reactions!==null||Mr(a))&&(o=Mt(a)),nn.set(a,o),o}var s=!(a.f&512)&&!cr&&sr!==null&&!!(sr.f&512),c=(a.f&T)===0;Cr(a)&&(s&&(a.f|=512),Nt(a)),s&&!c&&(Ft(a),jr(a))}if(zt?.has(e))return zt.get(e);if(e.f&8388608)throw e.v;return e.v}function jr(e){if(e.f|=512,e.deps!==null)for(let r of e.deps){var t=r.reactions;t===null?r.reactions=[e]:n.call(t,e)||t.push(e),r.f&2&&!(r.f&512)&&(Ft(r),jr(r))}}function Mr(e){if(e.v===be)return!0;if(e.deps===null)return!1;for(let t of e.deps)if(nn.has(t)||t.f&2&&Mr(t))return!0;return!1}function Nr(e){var t=cr;try{return cr=!0,e()}finally{cr=t}}function Pr(e){if(!(typeof e!=`object`||!e||e instanceof EventTarget)){if(ce in e)Fr(e);else if(!Array.isArray(e))for(let t in e){let n=e[t];typeof n==`object`&&n&&ce in n&&Fr(n)}}}function Fr(e,t=new Set){if(typeof e==`object`&&e&&!(e instanceof EventTarget)&&!t.has(e)){t.add(e),e instanceof Date&&e.getTime();for(let n in e)try{Fr(e[n],t)}catch{}let n=l(e);if(n!==Object.prototype&&n!==Array.prototype&&n!==Map.prototype&&n!==Set.prototype&&n!==Date.prototype){let t=o(n);for(let n in t){let r=t[n].get;if(r)try{r.call(e)}catch{}}}}}function Ir(e){return e.endsWith(`capture`)&&e!==`gotpointercapture`&&e!==`lostpointercapture`}var Lr=[`beforeinput`,`click`,`change`,`dblclick`,`contextmenu`,`focusin`,`focusout`,`input`,`keydown`,`keyup`,`mousedown`,`mousemove`,`mouseout`,`mouseover`,`mouseup`,`pointerdown`,`pointermove`,`pointerout`,`pointerover`,`pointerup`,`touchend`,`touchmove`,`touchstart`];function Rr(e){return Lr.includes(e)}var zr=`allowfullscreen.async.autofocus.autoplay.checked.controls.default.disabled.formnovalidate.indeterminate.inert.ismap.loop.multiple.muted.nomodule.novalidate.open.playsinline.readonly.required.reversed.seamless.selected.webkitdirectory.defer.disablepictureinpicture.disableremoteplayback`.split(`.`),Br={formnovalidate:`formNoValidate`,ismap:`isMap`,nomodule:`noModule`,playsinline:`playsInline`,readonly:`readOnly`,defaultvalue:`defaultValue`,defaultchecked:`defaultChecked`,srcobject:`srcObject`,novalidate:`noValidate`,allowfullscreen:`allowFullscreen`,disablepictureinpicture:`disablePictureInPicture`,disableremoteplayback:`disableRemotePlayback`};function Vr(e){return e=e.toLowerCase(),Br[e]??e}[...zr];var Hr=[`touchstart`,`touchmove`];function Ur(e){return Hr.includes(e)}var Wr=[`textarea`,`script`,`style`,`title`];function Gr(e){return Wr.includes(e)}var Kr=Symbol(`events`),qr=new Set,Jr=new Set;function Yr(e,t,n,r={}){function i(e){if(r.capture||ei.call(t,e),!e.cancelBubble)return xt(()=>n?.call(this,e))}return e.startsWith(`pointer`)||e.startsWith(`touch`)||e===`wheel`?(i.__removed=!1,dt(()=>{i.__removed||t.addEventListener(e,i,r)})):t.addEventListener(e,i,r),i}function Xr(e,t,n,r={}){var i=Yr(t,e,n,r);return()=>{i.__removed=!0,e.removeEventListener(t,i,r)}}function B(e,t,n,r,i){var a={capture:r,passive:i},o=Yr(e,t,n,a);(t===document.body||t===window||t===document||t instanceof HTMLMediaElement)&&Fn(()=>{o.__removed=!0,t.removeEventListener(e,o,a)})}function V(e,t,n){(t[Kr]??={})[e]=n}function Zr(e){for(var t=0;t<e.length;t++)qr.add(e[t]);for(var n of Jr)n(e)}var Qr=null,$r=!1;function ei(e){var t=this,n=t.ownerDocument,r=e.type,a=e.composedPath?.()||[],o=a[0]||e.target;Qr=e,$r||($r=!0,setTimeout(()=>{$r=!1,Qr=null}));var s=0,c=Qr===e&&e[Kr];if(c){var l=a.indexOf(c);if(l!==-1&&(t===document||t===window)){e[Kr]=t;return}var u=a.indexOf(t);if(u===-1)return;l<=u&&(s=l)}if(o=a[s]||e.target,o!==t){i(e,`currentTarget`,{configurable:!0,get(){return o||n}});var d=sr,f=ur;lr(null),dr(null);try{for(var p,m=[];o!==null&&o!==t;){try{var h=o[Kr]?.[r];h!=null&&(!o.disabled||e.target===o)&&h.call(o,e)}catch(e){p?m.push(e):p=e}if(e.cancelBubble)break;s++,o=s<a.length?a[s]:null}if(p){for(let e of m)queueMicrotask(()=>{throw e});throw p}}finally{e[Kr]=t,delete e.currentTarget,lr(d),dr(f)}}}var ti=globalThis?.window?.trustedTypes&&globalThis.window.trustedTypes.createPolicy(`svelte-trusted-html`,{createHTML:e=>e});function ni(e){return ti?.createHTML(e)??e}function ri(e){var t=Dn(`template`);return t.innerHTML=ni(e.replaceAll(`<!>`,`<!---->`)),t.content}function ii(e,t){var n=ur;n.nodes===null&&(n.nodes={start:e,end:t,a:null,t:null})}function H(e,t){var n=!!(t&1),r=!!(t&2),i,a=!e.startsWith(`<!>`);return()=>{if(D)return ii(Oe,null),Oe;i===void 0&&(i=ri(a?e:`<!>`+e),n||(i=Cn(i)));var t=r||vn?document.importNode(i,!0):i.cloneNode(!0);if(n){var o=Cn(t),s=t.lastChild;ii(o,s)}else ii(t,t);return t}}function ai(e,t,n=`svg`){var r=!e.startsWith(`<!>`),i=!!(t&1),a=`<${n}>${r?e:`<!>`+e}</${n}>`,o;return()=>{if(D)return ii(Oe,null),Oe;if(!o){var e=Cn(ri(a));if(i)for(o=document.createDocumentFragment();Cn(e);)o.appendChild(Cn(e));else o=Cn(e)}var t=o.cloneNode(!0);if(i){var n=Cn(t),r=t.lastChild;ii(n,r)}else ii(t,t);return t}}function oi(e,t){return ai(e,t,`svg`)}function si(e=``){if(!D){var t=Sn(e+``);return ii(t,t),t}var n=Oe;return n.nodeType===3?On(n):(n.before(n=Sn()),ke(n)),ii(n,n),n}function ci(){if(D)return ii(Oe,null),Oe;var e=document.createDocumentFragment(),t=document.createComment(``),n=Sn();return e.append(t,n),ii(t,n),e}function U(e,t){if(D){var n=ur;(!(n.f&32768)||n.nodes.end===null)&&(n.nodes.end=Oe),Ae()}else e!==null&&e.before(t)}function li(){if(D&&Oe&&Oe.nodeType===8&&Oe.textContent?.startsWith(`$`)){let e=Oe.textContent.substring(1);return Ae(),e}return(window.__svelte??={}).uid??=1,`c${window.__svelte.uid++}`}function ui(e){let t=0,n=an(0),r;return()=>{Pn()&&(z(n),Un(()=>(t===0&&(r=Nr(()=>e(()=>dn(n)))),t+=1,()=>{dt(()=>{--t,t===0&&(r?.(),r=void 0,dn(n))})})))}}var di=E|ne;function fi(e,t,n,r){new pi(e,t,n,r)}var pi=class{parent;is_pending=!1;transform_error;#e;#t=D?Oe:null;#n;#r;#i;#a=null;#o=null;#s=null;#c=null;#l=0;#u=0;#d=!1;#f=new Set;#p=new Set;#m=null;#h=ui(()=>(this.#m=an(this.#l),()=>{this.#m=null}));constructor(e,t,n,r){this.#e=e,this.#n=t,this.#r=e=>{var t=ur;t.b=this,t.f|=128,n(e)},this.parent=ur.b,this.transform_error=r??this.parent?.transform_error??(e=>e),this.#i=Wn(()=>{if(D){let e=Ne(this.#t);Ae();let t=e===`[!`;if(e.startsWith(`[?`)){let t=JSON.parse(e.slice(2));this.#_(t)}else t?this.#b():this.#g()}else this.#x()},di),D&&(this.#e=Oe)}#g(){try{this.#a=Kn(()=>this.#r(this.#e))}catch(e){this.error(e)}}#_(e){let t=this.#n.failed,{reset:n,invoke_onerror:r}=this.#v(e);dt(r),t&&(this.#s=Kn(()=>{t(this.#e,()=>e,()=>n)}))}#v(e){var t=!1,n=!1;let r=()=>{this.#y()||(t?Ee():(t=!0,n&&Je(),this.#s!==null&&$n(this.#s,()=>{this.#s=null}),this.#C(()=>{this.#x()})))};return{reset:r,invoke_onerror:()=>{if(!this.#y())try{n=!0,this.#n.onerror?.(e,r),n=!1}catch(e){An(e,this.#i&&this.#i.parent)}}}}#y(){return(this.#i.f&(ee|te))!==0}#b(){let e=this.#n.pending;e&&(this.is_pending=!0,this.#o=Kn(()=>e(this.#e)),dt(()=>{if(!this.#y()){var e=this.#c=document.createDocumentFragment(),t=Sn(),n=!1;e.append(t),this.#a=this.#C(()=>{try{return Kn(()=>this.#r(t))}catch(e){try{this.error(e),n=!0}catch(e){An(e,this.#i.parent)}return null}}),this.#a===null?(this.#c=null,n&&this.#S(Lt)):this.#u===0&&(this.#e.before(e),this.#c=null,$n(this.#o,()=>{this.#o=null}),this.#S(Lt))}}))}#x(){try{if(this.is_pending=this.has_pending_snippet(),this.#u=0,this.#l=0,this.#a=Kn(()=>{this.#r(this.#e)}),this.#u>0){var e=this.#c=document.createDocumentFragment();rr(this.#a,e);let t=this.#n.pending;this.#o=Kn(()=>t(this.#e))}else this.#S(Lt)}catch(e){this.error(e)}}#S(e){this.is_pending=!1,e.transfer_effects(this.#f,this.#p)}defer_effect(e){gt(e,this.#f,this.#p)}is_rendered(){return!this.is_pending&&(!this.parent||this.parent.is_rendered())}has_pending_snippet(){return!!this.#n.pending}#C(e){var t=ur,n=sr,r=nt;dr(this.#i),lr(this.#i),rt(this.#i.ctx);try{return qt.ensure(),e()}finally{dr(t),lr(n),rt(r)}}#w(e,t){this.has_pending_snippet()?(this.#u+=e,this.#u===0&&(this.#S(t),this.#o&&$n(this.#o,()=>{this.#o=null}),this.#c&&=(this.#e.before(this.#c),null))):this.parent&&this.parent.#w(e,t)}update_pending_count(e,t){this.#w(e,t),this.#l+=e,!(!this.#m||this.#d)&&(this.#d=!0,dt(()=>{this.#d=!1,this.#m&&ln(this.#m,this.#l)}))}get_effect_pending(){return this.#h(),z(this.#m)}error(e){if(e===ye||!this.#n.onerror&&!this.#n.failed)throw e;Lt?.is_fork?(this.#a&&Lt.skip_effect(this.#a),this.#o&&Lt.skip_effect(this.#o),this.#s&&Lt.skip_effect(this.#s),Lt.oncommit(()=>{this.#y()||this.#T(e)})):this.#T(e)}#T(e){this.#a&&=(Xn(this.#a),null),this.#o&&=(Xn(this.#o),null),this.#s&&=(Xn(this.#s),null),D&&(ke(this.#t),je(),ke(Me()));let t=this.#n.failed,n=e=>{if(this.#y())return;let{reset:n,invoke_onerror:r}=this.#v(e);r(),t&&!this.#y()&&(this.#s=this.#C(()=>{try{return Kn(()=>{var r=ur;r.b=this,r.f|=128,t(this.#e,()=>e,()=>n)})}catch(e){return An(e,this.#i.parent),null}}))};dt(()=>{if(!this.#y()){var t;try{t=this.transform_error(e)}catch(e){An(e,this.#i&&this.#i.parent);return}typeof t==`object`&&t&&typeof t.then==`function`?t.then(n,e=>An(e,this.#i&&this.#i.parent)):n(t)}})}};function W(e,t){var n=t==null?``:typeof t==`object`?`${t}`:t;n!==(e[he]??=e.nodeValue)&&(e[he]=n,e.nodeValue=`${n}`)}function mi(e,t){return gi(e,t)}var hi=new Map;function gi(e,{target:t,anchor:n,props:i={},events:a,context:o,intro:s=!0,transformError:c}){xn();var l=void 0,u=Bn(()=>{var s=n??t.appendChild(Sn());fi(s,{pending:()=>{}},t=>{k({});var n=nt;if(o&&(n.c=o),a&&(i.$$events=a),D&&ii(t,null),l=e(t,i)||st(),D&&(ur.nodes.end=Oe,Oe===null||Oe.nodeType!==8||Oe.data!==`]`))throw we(),ye;A()},c);var u=new Set,d=e=>{for(var n=0;n<e.length;n++){var r=e[n];if(!u.has(r)){u.add(r);var i=Ur(r);for(let e of[t,document]){var a=hi.get(e);a===void 0&&(a=new Map,hi.set(e,a));var o=a.get(r);o===void 0?(e.addEventListener(r,ei,{passive:i}),a.set(r,1)):a.set(r,o+1)}}}};return d(r(qr)),Jr.add(d),()=>{for(var e of u)for(let n of[t,document]){var r=hi.get(n),i=r.get(e);--i==0?(n.removeEventListener(e,ei),r.delete(e),r.size===0&&hi.delete(n)):r.set(e,i)}Jr.delete(d),s!==n&&s.parentNode?.removeChild(s)}});return _i.set(l,u),l}var _i=new WeakMap,vi=class{anchor;#e=new Map;#t=new Map;#n=new Map;#r=new Set;#i=!0;constructor(e,t=!0){this.anchor=e,this.#i=t}#a=e=>{if(this.#e.has(e)){var t=this.#e.get(e),n=this.#t.get(t);if(n)tr(n),this.#r.delete(t);else{var r=this.#n.get(t);r&&(tr(r.effect),this.#t.set(t,r.effect),this.#n.delete(t),r.fragment.lastChild.remove(),this.anchor.before(r.fragment),n=r.effect)}for(let[t,n]of this.#e){if(this.#e.delete(t),t===e)break;let r=this.#n.get(n);r&&(Xn(r.effect),this.#n.delete(n))}for(let[e,r]of this.#t){if(e===t||this.#r.has(e))continue;let i=()=>{if(Array.from(this.#e.values()).includes(e)){var t=document.createDocumentFragment();rr(r,t),t.append(Sn()),this.#n.set(e,{effect:r,fragment:t})}else Xn(r);this.#r.delete(e),this.#t.delete(e)};this.#i||!n?(this.#r.add(e),$n(r,i,!1)):i()}}};#o=e=>{this.#e.delete(e);let t=Array.from(this.#e.values());for(let[e,n]of this.#n)t.includes(e)||(Xn(n.effect),this.#n.delete(e))};ensure(e,t){var n=Lt,r=En();if(t&&!this.#t.has(e)&&!this.#n.has(e)){if(r){var i=document.createDocumentFragment(),a=Sn();i.append(a),this.#n.set(e,{effect:Kn(()=>t(a)),fragment:i})}else this.#t.set(e,Kn(()=>t(this.anchor)))}if(this.#e.set(n,e),r){for(let[t,r]of this.#t)t===e?n.unskip_effect(r):n.skip_effect(r);for(let[t,r]of this.#n)t===e?n.unskip_effect(r.effect):n.skip_effect(r.effect);n.oncommit(this.#a),n.ondiscard(this.#o)}else D&&(this.anchor=Oe),this.#a(n)}},yi=0,bi=1,xi=2;function Si(e,t,n,r,i){D&&Ae();var a=ct(),o=be,s=a?an(o):on(o,!1,!1),c=a?an(o):on(o,!1,!1),l=new vi(e);Wn(()=>{var a=Lt,o=t(),u=!1;let d=D&&p(o)===(e.data===`[!`);if(d&&(ke(Me()),De(!1)),p(o)){var f=wt(),m=!1;let e=e=>{if(!u){m=!0,f(!1),Lt===a&&a.deactivate(),qt.ensure();try{e()}finally{Tt(!1),Vt||Jt()}}};o.then(t=>{e(()=>{ln(s,t),l.ensure(bi,r&&(e=>r(e,s)))})},t=>{e(()=>{if(ln(c,t),l.ensure(xi,i&&(e=>i(e,c))),!i)throw c.v})}),D?l.ensure(yi,n):dt(()=>{m||e(()=>{l.ensure(yi,n)})})}else ln(s,o),l.ensure(bi,r&&(e=>r(e,s)));return d&&De(!0),()=>{u=!0}})}function G(e,t,n=!1){var r;D&&(r=Oe,Ae());var i=new vi(e),a=n?E:0;function o(e,t){if(D){var n=Ne(r);if(e!==parseInt(n.substring(1))){var a=Me();ke(a),i.anchor=a,De(!1),i.ensure(e,t),De(!0);return}}i.ensure(e,t)}Wn(()=>{var e=!1;t((t,n=0)=>{e=!0,o(n,t)}),e||o(-1,null)},a)}var Ci=Symbol(`NaN`);function wi(e,t,n){D&&Ae();var r=new vi(e),i=!ct();Wn(()=>{var e=t();e!==e&&(e=Ci),i&&typeof e==`object`&&e&&(e={}),r.ensure(e,n)})}function Ti(e,t){D&&ke(Cn(e)),Un(()=>{var n=t();for(var r in n){var i=n[r];i==null||i===``?e.style.removeProperty(r):e.style.setProperty(r,i)}})}function Ei(e,t){return t}function Di(e,t,n){for(var i=[],a=t.length,o,s=t.length,c=0;c<a;c++){let n=t[c];$n(n,()=>{if(o){if(o.pending.delete(n),o.done.add(n),o.pending.size===0){var t=e.outrogroups;Oi(e,r(o.done)),t.delete(o),t.size===0&&(e.outrogroups=null)}}else--s},!1)}if(s===0){var l=i.length===0&&n!==null&&e.pending.size===0;if(l){var u=n,d=u.parentNode;Tn(d),d.append(u),e.items.clear()}Oi(e,t,!l)}else o={pending:new Set(t),done:new Set},(e.outrogroups??=new Set).add(o)}function Oi(e,t,n=!0){var r;if(e.pending.size>0){r=new Set;for(let t of e.pending.values())for(let n of t)r.add(e.items.get(n).e)}for(var i=0;i<t.length;i++){var a=t[i];r?.has(a)?(a.f|=ie,rr(a,document.createDocumentFragment())):Xn(t[i],n)}}var ki;function K(t,n,i,a,o,s=null){var c=t,l=new Map;if(n&4){var u=t;c=D?ke(Cn(u)):u.appendChild(Sn())}D&&Ae();var d=null,f=At(()=>{var t=i();return e(t)?t:t==null?[]:r(t)}),p=new Map,m=!0;function h(e){if(!(_.effect.f&16384)){_.pending.delete(e);var t=z(f);_.fallback=d,ji(_,t,c,n,a),d!==null&&(t.length===0?d.f&33554432?(d.f^=ie,Ni(d,null,c)):tr(d):$n(d,()=>{d=null}))}}function g(e){_.pending.delete(e)}var _={effect:Wn(()=>{var e=z(f),t=e.length;let r=!1;D&&Ne(c)===`[!`!=(t===0)&&(c=Me(),ke(c),De(!1),r=!0);for(var u=new Set,_=Lt,v=En(),y=0;y<t;y+=1){D&&Oe.nodeType===8&&Oe.data===`]`&&(c=Oe,r=!0,De(!1));var b=e[y],x=a(b,y),S=m?null:l.get(x);S?(S.v&&ln(S.v,b),S.i&&ln(S.i,y),v&&_.unskip_effect(S.e)):(S=Mi(l,m?c:ki??=Sn(),b,x,y,o,n,i),m||(S.e.f|=ie),l.set(x,S)),u.add(x)}if(t===0&&s&&!d&&(m?d=Kn(()=>s(c)):(d=Kn(()=>s(ki??=Sn())),d.f|=ie)),t>u.size&&ze(``,``,``),D&&t>0&&ke(Me()),!m){if(p.set(_,u),v){for(let[e,t]of l)u.has(e)||_.skip_effect(t.e);_.oncommit(h),_.ondiscard(g)}else h(_)}r&&De(!0),z(f)}),flags:n,items:l,pending:p,outrogroups:null,fallback:d};m=!1,D&&(c=Oe)}function Ai(e){for(;e!==null&&!(e.f&32);)e=e.next;return e}function ji(e,t,n,i,a){var o=!!(i&8),s=t.length,c=e.items,l=Ai(e.effect.first),u,d=null,f,p=[],m=[],h,g,_,v;if(o)for(v=0;v<s;v+=1)h=t[v],g=a(h,v),_=c.get(g).e,_.f&33554432||(_.nodes?.a?.measure(),(f??=new Set).add(_));for(v=0;v<s;v+=1){if(h=t[v],g=a(h,v),_=c.get(g).e,e.outrogroups!==null)for(let t of e.outrogroups)t.pending.delete(_),t.done.delete(_);if(_.f&8192&&(tr(_),o&&(_.nodes?.a?.unfix(),(f??=new Set).delete(_))),_.f&33554432){if(_.f^=ie,_===l)Ni(_,null,n);else{var y=d?d.next:l;_===e.effect.last&&(e.effect.last=_.prev),_.prev&&(_.prev.next=_.next),_.next&&(_.next.prev=_.prev),Pi(e,d,_),Pi(e,_,y),Ni(_,y,n),d=_,p=[],m=[],l=Ai(d.next);continue}}if(_!==l){if(u!==void 0&&u.has(_)){if(p.length<m.length){var b=m[0],x;d=b.prev;var S=p[0],C=p[p.length-1];for(x=0;x<p.length;x+=1)Ni(p[x],b,n);for(x=0;x<m.length;x+=1)u.delete(m[x]);Pi(e,S.prev,C.next),Pi(e,d,S),Pi(e,C,b),l=b,d=C,--v,p=[],m=[]}else u.delete(_),Ni(_,l,n),Pi(e,_.prev,_.next),Pi(e,_,d===null?e.effect.first:d.next),Pi(e,d,_),d=_;continue}for(p=[],m=[];l!==null&&l!==_;)(u??=new Set).add(l),m.push(l),l=Ai(l.next);if(l===null)continue}_.f&33554432||p.push(_),d=_,l=Ai(_.next)}if(e.outrogroups!==null){for(let t of e.outrogroups)t.pending.size===0&&(Oi(e,r(t.done)),e.outrogroups?.delete(t));e.outrogroups.size===0&&(e.outrogroups=null)}if(l!==null||u!==void 0){var w=[];if(u!==void 0)for(_ of u)_.f&8192||w.push(_);for(;l!==null;)!(l.f&8192)&&l!==e.fallback&&w.push(l),l=Ai(l.next);var ee=w.length;if(ee>0){var T=i&4&&s===0?n:null;if(o){for(v=0;v<ee;v+=1)w[v].nodes?.a?.measure();for(v=0;v<ee;v+=1)w[v].nodes?.a?.fix()}Di(e,w,T)}}o&&dt(()=>{if(f!==void 0)for(_ of f)_.nodes?.a?.apply()})}function Mi(e,t,n,r,i,a,o,s){var c=o&1?o&16?an(n):on(n,!1,!1):null,l=o&2?an(i):null;return{v:c,i:l,e:Kn(()=>(a(t,c??n,l??i,s),()=>{e.delete(r)}))}}function Ni(e,t,n){if(e.nodes)for(var r=e.nodes.start,i=e.nodes.end,a=t&&!(t.f&33554432)?t.nodes.start:n;r!==null;){var o=wn(r);if(a.before(r),r===i)return;r=o}}function Pi(e,t,n){t===null?e.effect.first=n:t.next=n,n===null?e.effect.last=t:n.prev=t}function Fi(e,t,...n){var r=new vi(e);Wn(()=>{let e=t()??null;r.ensure(e,e&&(t=>e(t,...n)))},E)}function Ii(e,t,n){var r;D&&(r=Oe,Ae());var i=new vi(e);Wn(()=>{var e=t()??null;if(D&&Ne(r)===`[`!=(e!==null)){var a=Me();ke(a),i.anchor=a,De(!1),i.ensure(e,e&&(t=>n(t,e))),De(!0)}else i.ensure(e,e&&(t=>n(t,e)))},E)}function Li(e,t,n,r,i,a){let o=D;D&&Ae();var s=null;D&&Oe.nodeType===1&&(s=Oe,Ae());var c=D?Oe:e,l=new vi(c,!1);Wn(()=>{let e=t()||null;var a=i?i():n||e===`svg`?Se:void 0;if(e===null)l.ensure(null,null);else return l.ensure(e,t=>{if(e){var n=D;if(s=D?s:Dn(e,a),ii(s,s),r){var i=null;D&&Gr(e)&&s.append(i=document.createComment(``));var o=D?Cn(s):s.appendChild(Sn());D&&(o===null?De(!1):ke(o)),r(s,o),i?.remove()}ur.nodes.end=s,n||t.before(s)}D&&ke(t)}),()=>{}},E),Fn(()=>{}),o&&(De(!0),ke(c))}function Ri(e,t,n){Vn(()=>{var r=Nr(()=>t(e,n?.())||{});if(n&&r?.update){var i=!1,a={};Un(()=>{var e=n();Pr(e),i&&Fe(a,e)&&(a=e,r.update(e))}),i=!0}if(r?.destroy)return()=>r.destroy()})}function zi(e,t){var n=void 0,r;Gn(()=>{n!==(n=t())&&(r&&=(Xn(r),null),n&&(r=Kn(()=>{Vn(()=>n(e))})))})}function Bi(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`){if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=Bi(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n)}return r}function Vi(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=Bi(e))&&(r&&(r+=` `),r+=t);return r}function Hi(e){return typeof e==`object`?Vi(e):e??``}var Ui=[...`
2
2
  \r\f\xA0\v`];function Wi(e,t,n){var r=e==null?``:``+e;if(t&&(r=r?r+` `+t:t),n){for(var i of Object.keys(n))if(n[i])r=r?r+` `+i:i;else if(r.length)for(var a=i.length,o=0;(o=r.indexOf(i,o))>=0;){var s=o+a;(o===0||Ui.includes(r[o-1]))&&(s===r.length||Ui.includes(r[s]))?r=(o===0?``:r.substring(0,o))+r.substring(s+1):o=s}}return r===``?null:r}function Gi(e,t=!1){var n=t?` !important;`:`;`,r=``;for(var i of Object.keys(e)){var a=e[i];a!=null&&a!==``&&(r+=` `+i+`: `+a+n)}return r}function Ki(e){return e[0]!==`-`||e[1]!==`-`?e.toLowerCase():e}function qi(e,t){if(t){var n=``,r,i;if(Array.isArray(t)?(r=t[0],i=t[1]):r=t,e){e=String(e).replaceAll(/\/\*.*?\*\//g,``).trim();var a=!1,o=0,s=!1,c=[];r&&c.push(...Object.keys(r).map(Ki)),i&&c.push(...Object.keys(i).map(Ki));var l=0,u=-1;let t=e.length;for(var d=0;d<t;d++){var f=e[d];if(s?f===`/`&&e[d-1]===`*`&&(s=!1):a?a===f&&(a=!1):f===`/`&&e[d+1]===`*`?s=!0:f===`"`||f===`'`?a=f:f===`(`?o++:f===`)`&&o--,!s&&a===!1&&o===0){if(f===`:`&&u===-1)u=d;else if(f===`;`||d===t-1){if(u!==-1){var p=Ki(e.substring(l,u).trim());if(!c.includes(p)){f!==`;`&&d++;var m=e.substring(l,d).trim();n+=` `+m+`;`}}l=d+1,u=-1}}}}return r&&(n+=Gi(r)),i&&(n+=Gi(i,!0)),n=n.trim(),n===``?null:n}return e==null?null:String(e)}function Ji(e,t,n,r,i,a){var o=e[pe];if(D||o!==n||o===void 0){var s=Wi(n,r,a);(!D||s!==e.getAttribute(`class`))&&(s==null?e.removeAttribute(`class`):t?e.className=s:e.setAttribute(`class`,s)),e[pe]=n}else if(a&&i!==a)for(var c in a){var l=!!a[c];(i==null||l!==!!i[c])&&e.classList.toggle(c,l)}return a}function Yi(e,t={},n,r){for(var i in n){var a=n[i];t[i]!==a&&(n[i]==null?e.style.removeProperty(i):e.style.setProperty(i,a,r))}}function Xi(e,t,n,r){var i=e[me];if(D||i!==t){var a=qi(t,r);(!D||a!==e.getAttribute(`style`))&&(a==null?e.removeAttribute(`style`):e.style.cssText=a),e[me]=t}else r&&(Array.isArray(r)?(Yi(e,n?.[0],r[0]),Yi(e,n?.[1],r[1],`important`)):Yi(e,n,r));return r}function Zi(e,t){t?e.hasAttribute(`selected`)||e.setAttribute(`selected`,``):e.removeAttribute(`selected`)}function Qi(e,t){var n=!(`__defaultValue`in e);(n||e.__defaultValue!==t)&&(e.__defaultValue=t,$i(e,!n||`__value`in e))}function $i(t,n){var r=t.__defaultValue,i=t.multiple,a=i?r??[]:null;if(!i||e(a)){var o=t.selectedIndex,s=n&&i?new Set(t.selectedOptions):null;for(var c of t.options){var l=ra(c);Zi(c,i?a.includes(l):hn(l,r))}if(n){if(s!==null)for(c of t.options){var u=s.has(c);c.selected!==u&&(c.selected=u)}else t.selectedIndex!==o&&(t.selectedIndex=o)}}}function ea(t,n,r=!1){if(t.multiple){if(n==null)return;if(!e(n))return Te();for(var i of t.options)i.selected=n.includes(ra(i))}else{for(i of t.options)if(hn(ra(i),n)){i.selected=!0;return}(!r||n!==void 0)&&(t.selectedIndex=-1)}}function ta(e){var t=new MutationObserver(t=>{t.every(ia)||(`__defaultValue`in e&&$i(e,!1),`__value`in e&&ea(e,e.__value))});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`]}),Fn(()=>{t.disconnect()})}function na(e,t,n=t){var r=new WeakSet,i=!0;St(e,`change`,t=>{var i=t?`[selected]`:`:checked`,a;if(e.multiple)a=[].map.call(e.querySelectorAll(i),ra);else{var o=e.querySelector(i)??e.querySelector(`option:not([disabled])`);a=o&&ra(o)}n(a),e.__value=a,Lt!==null&&r.add(Lt)}),Vn(()=>{var a=t();if(e===document.activeElement){var o=Lt;if(r.has(o))return}if(ea(e,a,i),i&&a===void 0){var s=e.querySelector(`:checked`);s!==null&&(a=ra(s),n(a))}e.__value=a,i=!1})}function ra(e){return`__value`in e?e.__value:e.value}function ia(e){if(e.target.closest(`selectedcontent`)!==null)return!0;if(e.type===`childList`){var t=[...e.addedNodes,...e.removedNodes];return t.length>0&&t.every(e=>e.nodeName===`SELECTEDCONTENT`)}return!1}var aa=Symbol(`class`),oa=Symbol(`style`),sa=Symbol(`is custom element`),ca=Symbol(`is html`),la=ve?`link`:`LINK`,ua=ve?`input`:`INPUT`,da=ve?`option`:`OPTION`,fa=ve?`select`:`SELECT`,pa=ve?`progress`:`PROGRESS`;function ma(e){if(D){var t=!1,n=()=>{if(!t){if(t=!0,e.hasAttribute(`value`)){var n=e.value;q(e,`value`,null),e.value=n}if(e.hasAttribute(`checked`)){var r=e.checked;q(e,`checked`,null),e.checked=r}}};e[ge]=n,dt(n),bt()}}function ha(e,t){var n=ya(e);n.value!==(n.value=t??void 0)&&(e.value!==t||t===0&&e.nodeName===pa)&&(e.value=t??``)}function ga(e,t){var n=ya(e);n.checked!==(n.checked=t??void 0)&&(e.checked=t)}function q(e,t,n,r){var i=ya(e);D&&(i[t]=e.getAttribute(t),t===`src`||t===`srcset`||t===`href`&&e.nodeName===la)||i[t]!==(i[t]=n)&&(t===`loading`&&(e[de]=n),n==null?e.removeAttribute(t):typeof n!=`string`&&xa(e).has(t)?e[t]=n:e.setAttribute(t,n))}function _a(e,t,n,r,i=!1,a=!1){D&&i&&e.nodeName===ua&&(`defaultValue`in n||`defaultChecked`in n||ma(e));var o=ya(e),s=o[sa],c=!o[ca];let l=D&&s;l&&De(!1);var u=t||{},d=e.nodeName===da,f=e.nodeName===fa;try{for(var p in t)!(p in n)&&p[0]+p[1]!==`$$`&&(n[p]=null);n.class?n.class=Hi(n.class):(r||n[aa])&&(n.class=null),n[oa]&&(n.style??=null);var m=xa(e);if(e.nodeName===ua&&`type`in n&&(`value`in n||`__value`in n)){var h=n.type;(h!==u.type||h===void 0&&e.hasAttribute(`type`))&&(u.type=h,q(e,`type`,h,a))}for(let i in n){let l=n[i];if(d&&i===`value`&&l==null)e.value=e.__value=``,u[i]=l;else if(i===`class`)Ji(e,e.namespaceURI===`http://www.w3.org/1999/xhtml`,l,r,t?.[aa],n[aa]),u[i]=l,u[aa]=n[aa];else if(i===`style`)Xi(e,l,t?.[oa],n[oa]),u[i]=l,u[oa]=n[oa];else{var g=u[i];if(l!==g||l===void 0&&e.hasAttribute(i)){u[i]=l;var _=i[0]+i[1];if(_!==`$$`){if(_===`on`){let t={},n=`$$`+i,r=i.slice(2);var v=Rr(r);if(Ir(r)&&(r=r.slice(0,-7),t.capture=!0),!v&&g){if(l!=null)continue;e.removeEventListener(r,u[n],t),u[n]=null}if(v)V(r,e,l),Zr([r]);else if(l!=null){function a(e){u[i].call(this,e)}u[n]=Yr(r,e,a,t)}}else if(i===`style`)q(e,i,l);else if(i===`autofocus`)_t(e,!!l);else if(!s&&(i===`__value`||i===`value`&&l!=null))e.__value=l,(g==null||e.value!==l||l===0&&e.nodeName===pa)&&(e.value=l);else if(i===`selected`&&d)Zi(e,l);else{var y=i;c||(y=Vr(y));var b=y===`defaultValue`||y===`defaultChecked`;if(f&&y===`defaultValue`)continue;if(l==null&&!s&&!b){if(o[i]=null,y===`value`||y===`checked`){let n=e,r=t===void 0;if(y===`value`){let e=n.defaultValue;n.removeAttribute(y),n.defaultValue=e,n.value=n.__value=r?e:null}else{let e=n.defaultChecked;n.removeAttribute(y),n.defaultChecked=e,n.checked=r?e:!1}}else e.removeAttribute(i)}else b||(s||typeof l!=`string`)&&m.has(y)?(e[y]=l,y in o&&(o[y]=be)):typeof l!=`function`&&q(e,y,l,a)}}}}}}finally{l&&De(!0)}return u}function va(e,t,n=[],r=[],i=[],a,o=!1,s=!1){Ct(i,n,r,n=>{var r=void 0,i={},c=e.nodeName===fa,l=!1;if(Gn(()=>{var u=t(...n.map(z)),d=_a(e,r,u,a,o,s);if(l&&c){var f=e;`defaultValue`in u&&Qi(f,u.defaultValue),`value`in u&&ea(f,u.value)}for(let e of Object.getOwnPropertySymbols(i))u[e]||Xn(i[e]);for(let t of Object.getOwnPropertySymbols(u)){var p=u[t];t.description===`@attach`&&(!r||p!==r[t])&&(i[t]&&Xn(i[t]),i[t]=Kn(()=>zi(e,()=>p))),d[t]=p}r=d}),c){var u=e;Vn(()=>{var e=r;`defaultValue`in e&&Qi(u,e.defaultValue),ea(u,e.value,!0),ta(u)})}l=!0})}function ya(e){return e[fe]??={[sa]:e.nodeName.includes(`-`),[ca]:e.namespaceURI===xe}}var ba=new Map;function xa(e){var t=e.getAttribute(`is`)||e.nodeName,n=ba.get(t);if(n)return n;ba.set(t,n=new Set);for(var r,i=e,a=Element.prototype;a!==i;){for(var s in r=o(i),r)r[s].set&&s!==`innerHTML`&&s!==`textContent`&&s!==`innerText`&&n.add(s);i=l(i)}return n}function Sa(e,t,n=t){var r=new WeakSet;St(e,`input`,async i=>{var a=i?e.defaultValue:e.value;if(a=Da(e)?Oa(a):a,n(a),Lt!==null&&r.add(Lt),await Ar(),a!==(a=t())){var o=e.selectionStart,s=e.selectionEnd,c=e.value.length;if(e.value=a??``,s!==null){var l=e.value.length;o===s&&s===c&&l>c?(e.selectionStart=l,e.selectionEnd=l):(e.selectionStart=o,e.selectionEnd=Math.min(s,l))}}}),(D&&e.defaultValue!==e.value||Nr(t)==null&&e.value)&&(n(Da(e)?Oa(e.value):e.value),Lt!==null&&r.add(Lt)),Un(()=>{var n=t();if(e===document.activeElement){var i=Lt;if(r.has(i))return}Da(e)&&n===Oa(e.value)||(e.type!==`date`||n||e.value)&&n!==e.value&&(e.value=n??``)})}var Ca=new Set;function wa(e,t,n,r,i=r){var a=n.getAttribute(`type`)===`checkbox`,o=e;let s=!1;if(t!==null)for(var c of t)o=o[c]??=[];o.push(n),St(n,`change`,()=>{var e=n.__value;a&&(e=Ea(o,e,n.checked)),i(e)},()=>i(a?[]:null)),Un(()=>{var e=r();D&&n.defaultChecked!==n.checked?s=!0:a?(e||=[],n.checked=e.includes(n.__value)):n.checked=hn(n.__value,e)}),Fn(()=>{var e=o.indexOf(n);e!==-1&&o.splice(e,1)}),Ca.has(o)||(Ca.add(o),dt(()=>{o.sort((e,t)=>e.compareDocumentPosition(t)===4?-1:1),Ca.delete(o)})),dt(()=>{if(s){var e=a?Ea(o,e,n.checked):o.find(e=>e.checked)?.__value;i(e)}})}function Ta(e,t,n=t){St(e,`change`,t=>{n(t?e.defaultChecked:e.checked)}),(D&&e.defaultChecked!==e.checked||Nr(t)==null)&&n(e.checked),Un(()=>{e.checked=!!t()})}function Ea(e,t,n){for(var r=new Set,i=0;i<e.length;i+=1)e[i].checked&&r.add(e[i].__value);return n||r.delete(t),Array.from(r)}function Da(e){var t=e.type;return t===`number`||t===`range`}function Oa(e){return e===``?null:+e}var ka=new class e{#e=new WeakMap;#t;#n;static entries=new WeakMap;constructor(e){this.#n=e}observe(e,t){var n=this.#e.get(e)||new Set;return n.add(t),this.#e.set(e,n),this.#r().observe(e,this.#n),()=>{var n=this.#e.get(e);n.delete(t),n.size===0&&(this.#e.delete(e),this.#t.unobserve(e))}}#r(){return this.#t??=new ResizeObserver(t=>{for(var n of t){e.entries.set(n.target,n);for(var r of this.#e.get(n.target)||[])r(n)}})}}({box:`border-box`});function Aa(e,t,n){var r=ka.observe(e,()=>n(e[t]));Vn(()=>(Nr(()=>n(e[t])),r))}function ja(e,t){return e===t||e?.[ce]===t}function Ma(e=st(),t,n,r){var i=nt.r,a=ur;return Vn(()=>{var o,s;return Un(()=>{o=s,s=r?.()||[],Nr(()=>{ja(n(...s),e)||(t(e,...s),o&&ja(n(...o),e)&&t(null,...o))})}),()=>{let r=a;for(;r!==i&&r.parent!==null&&r.parent.f&33554432;)r=r.parent;let o=()=>{s&&ja(n(...s),e)&&t(null,...s)},c=r.teardown;r.teardown=()=>{o(),c?.()}}}),e}function Na(e,t,n,r,i){var a=()=>{r(n[e])};n.addEventListener(t,a),i?Un(()=>{n[e]=i()}):a(),(n===document.body||n===window||n===document)&&Fn(()=>{n.removeEventListener(t,a)})}function Pa(e=!1){let t=nt,n=t.l.u;if(!n)return;let r=()=>Pr(t.s);if(e){let e=0,n={},i=Dt(()=>{let r=!1,i=t.s;for(let e in i)i[e]!==n[e]&&(n[e]=i[e],r=!0);return r&&e++,e});r=()=>z(i)}n.b.length&&Rn(()=>{Fa(t,r),h(n.b)}),In(()=>{let e=Nr(()=>n.m.map(m));return()=>{for(let t of e)typeof t==`function`&&t()}}),n.a.length&&In(()=>{Fa(t,r),h(n.a)})}function Fa(e,t){if(e.l.s)for(let t of e.l.s)z(t);t()}var Ia=!1;function La(e){var t=Ia;try{return Ia=!1,[e(),Ia]}finally{Ia=t}}var Ra={get(e,t){if(!e.exclude.has(t))return e.props[t]},set(e,t){return!1},getOwnPropertyDescriptor(e,t){if(!e.exclude.has(t)&&t in e.props)return{enumerable:!0,configurable:!0,value:e.props[t]}},has(e,t){return!e.exclude.has(t)&&t in e.props},ownKeys(e){return Reflect.ownKeys(e.props).filter(t=>!e.exclude.has(t))}};function J(e,t,n){return new Proxy({props:e,exclude:t},Ra)}var za={get(e,t){let n=e.props.length;for(;n--;){let r=e.props[n];if(d(r)&&(r=r()),typeof r==`object`&&r&&t in r)return r[t]}},set(e,t,n){let r=e.props.length;for(;r--;){let i=e.props[r];d(i)&&(i=i());let o=a(i,t);if(o&&o.set)return o.set(n),!0}return!1},getOwnPropertyDescriptor(e,t){let n=e.props.length;for(;n--;){let r=e.props[n];if(d(r)&&(r=r()),typeof r==`object`&&r&&t in r){let e=a(r,t);return e&&!e.configurable&&(e.configurable=!0),e}}},has(e,t){if(t===ce||t===ue)return!1;for(let n of e.props)if(d(n)&&(n=n()),n!=null&&t in n)return!0;return!1},ownKeys(e){let t=[];for(let n of e.props)if(d(n)&&(n=n()),n){for(let e in n)t.includes(e)||t.push(e);for(let e of Object.getOwnPropertySymbols(n))t.includes(e)||t.push(e)}return t}};function Ba(...e){return new Proxy({props:e},za)}function Y(e,t,n,r){var i=!Ye||!!(n&2),o=!!(n&8),s=!!(n&16),c=r,l=!0,u=void 0,d=()=>s&&i?(u??=Dt(r),z(u)):(l&&(l=!1,c=s?Nr(r):r),c);let f;if(o){var p=ce in e||ue in e;f=a(e,t)?.set??(p&&t in e?n=>e[t]=n:void 0)}var m,h=!1;o?[m,h]=La(()=>e[t]):m=e[t],m===void 0&&r!==void 0&&(m=d(),f&&(i&&We(t),f(m)));var g=i?()=>{var n=e[t];return n===void 0?d():(l=!0,n)}:()=>{var n=e[t];return n!==void 0&&(c=void 0),n===void 0?c:n};if(i&&!(n&4))return g;if(f){var _=e.$$legacy;return(function(e,t){return arguments.length>0?((!i||!t||_||h)&&f(t?g():e),e):g()})}var v=!1,y=(n&1?Dt:At)(()=>(v=!1,g()));o&&z(y);var b=ur;return(function(e,t){if(arguments.length>0){let n=t?z(y):i&&o?pn(e):e;return N(y,n),v=!0,c!==void 0&&(c=n),e}return ar&&v||b.f&16384?y.v:z(y)})}function Va(e){nt===null&&Le(`onMount`),Ye&&nt.l!==null?Ua(nt).m.push(e):In(()=>{let t=Nr(e);if(typeof t==`function`)return t})}function Ha(e){nt===null&&Le(`onDestroy`),Va(()=>()=>Nr(e))}function Ua(e){var t=e.l;return t.u??={a:[],b:[],m:[]}}typeof window<`u`&&((window.__svelte??={}).v??=new Set).add(`5`);function X(e,t){let n=Y(t,`size`,3,16),r=Y(t,`filled`,3,!1);var i=ci(),a=F(i);{let e=j(()=>r()?`currentColor`:`none`),i=j(()=>t.label?`img`:void 0),o=j(()=>t.label?void 0:`true`);Ii(a,()=>t.of,(r,a)=>{a(r,{get size(){return n()},strokeWidth:1.5,absoluteStrokeWidth:!0,get fill(){return z(e)},get role(){return z(i)},get"aria-label"(){return t.label},get"aria-hidden"(){return z(o)}})})}U(e,i)}var Wa={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":2,"stroke-linecap":`round`,"stroke-linejoin":`round`},Ga=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim();function Ka(e){return e!=null}function qa(e,t={}){let n=t.attributeNames??{},r=e=>n[e]??e,i=e.size??e.width??Wa.width,a=e.size??e.height??Wa.height,o=e.aliases?.filter(e=>typeof e==`string`&&e.trim()!==``).map(e=>`lucide-${e}`)??[],s=[...e.name?[`lucide-${e.name}`]:[],...o],c=t.className?.split(` `).filter(Boolean)??[],l=t.includeDefaultClasses===!1?Ga(...c):Ga(`lucide`,...s,...c),u=t.absoluteStrokeWidth?Number(t.strokeWidth??Wa[`stroke-width`])*Number(e.size??e.width??Wa.width)/Number(t.size??t.width??Wa.width):t.strokeWidth??Wa[`stroke-width`];return[`svg`,{...Object.entries(Wa).reduce((e,[t,n])=>(e[r(t)]=n,e),{}),...`color`in t&&t.color&&{[r(`stroke`)]:t.color},...`size`in t&&Ka(t.size)&&{[r(`width`)]:t.size,[r(`height`)]:t.size},...`width`in t&&Ka(t.width)&&{[r(`width`)]:t.width},...`height`in t&&Ka(t.height)&&{[r(`height`)]:t.height},[r(`stroke-width`)]:u,...l&&{[r(`class`)]:l},[r(`viewBox`)]:`0 0 ${i} ${a}`,...t.hasA11yProp===!1?{[r(`aria-hidden`)]:`true`}:{},...`attributes`in t&&t.attributes},e.node.map(e=>{let[n,i,a]=e,o=t.nonScalingStroke?{[r(`vector-effect`)]:`non-scaling-stroke`,...i}:i;return a?[n,o,a]:[n,o]})]}var Ja=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},Ya=Symbol(`lucide-context`),Xa=()=>it(Ya),Za=new Set([`$$slots`,`$$events`,`$$legacy`,`color`,`size`,`width`,`height`,`strokeWidth`,`absoluteStrokeWidth`,`nonScalingStroke`,`iconNode`,`icon`,`class`,`children`]),Qa=oi(`<svg><!><!></svg>`);function $a(e,t){k(t,!0);let n=Xa()??{},r=Y(t,`color`,19,()=>n.color??`currentColor`),i=Y(t,`size`,19,()=>n.size??24),a=Y(t,`width`,19,i),o=Y(t,`height`,19,i),s=Y(t,`strokeWidth`,19,()=>n.strokeWidth??2),c=Y(t,`absoluteStrokeWidth`,19,()=>n.absoluteStrokeWidth??!1),l=Y(t,`nonScalingStroke`,19,()=>n.nonScalingStroke??!1),u=Y(t,`iconNode`,19,()=>[]),d=Y(t,`icon`,19,()=>({node:u(),aliases:[],size:24})),p=J(t,Za),m=j(()=>!!t.children||Ja(p)),h=j(()=>qa(d(),{color:r(),width:a(),height:o(),strokeWidth:s(),absoluteStrokeWidth:c(),nonScalingStroke:l(),className:Ga(`lucide-icon`,n.class),hasA11yProp:z(m),attributes:p})),g=j(()=>v(z(h),3)),y=j(()=>z(g)[1]),b=j(()=>_(z(g)[2],()=>[],!0)),x=j(()=>({...z(y),class:[...z(y).class.split(` `),t.class]}));var S=Qa();va(S,()=>({...z(x)}));var C=P(S);K(C,17,()=>z(b),Ei,(e,t)=>{var n=j(()=>v(z(t),2));let r=()=>z(n)[0],i=()=>z(n)[1];var a=ci();Li(F(a),r,!0,(e,t)=>{va(e,()=>({...i()}))}),U(e,a)}),Fi(L(C),()=>t.children??f),O(S),U(e,S),A()}var eo=new Set([`$$slots`,`$$events`,`$$legacy`]);function to(e,t){let n=J(t,eo),r={name:`x`,size:24,node:[[`path`,{d:`M18 6 6 18`}],[`path`,{d:`m6 6 12 12`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}var no=new Set([`$$slots`,`$$events`,`$$legacy`]);function ro(e,t){let n=J(t,no),r={name:`database`,size:24,node:[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}var io=new Set([`$$slots`,`$$events`,`$$legacy`]);function ao(e,t){let n=J(t,io),r={name:`download`,size:24,node:[[`path`,{d:`M12 15V3`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}],[`path`,{d:`m7 10 5 5 5-5`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}var oo=new Set([`$$slots`,`$$events`,`$$legacy`]);function so(e,t){let n=J(t,oo),r={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}var co=new Set([`$$slots`,`$$events`,`$$legacy`]);function lo(e,t){let n=J(t,co),r={name:`refresh-cw`,size:24,node:[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`}],[`path`,{d:`M21 3v5h-5`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`}],[`path`,{d:`M8 16H3v5`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}var uo=new Set([`$$slots`,`$$events`,`$$legacy`]);function fo(e,t){let n=J(t,uo),r={name:`sprout`,size:24,node:[[`path`,{d:`M14 9.536V7a4 4 0 0 1 4-4h1.5a.5.5 0 0 1 .5.5V5a4 4 0 0 1-4 4 4 4 0 0 0-4 4c0 2 1 3 1 5a5 5 0 0 1-1 3`}],[`path`,{d:`M4 9a5 5 0 0 1 8 4 5 5 0 0 1-8-4`}],[`path`,{d:`M5 21h14`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}var po=new Set([`$$slots`,`$$events`,`$$legacy`]);function mo(e,t){let n=J(t,po),r={name:`square-terminal`,size:24,node:[[`path`,{d:`m7 11 2-2-2-2`}],[`path`,{d:`M11 13h4`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`}]],aliases:[`terminal-square`]};$a(e,Ba(()=>n,{get icon(){return r}}))}var ho=new Set([`$$slots`,`$$events`,`$$legacy`]);function go(e,t){let n=J(t,ho),r={name:`trash`,size:24,node:[[`path`,{d:`M10 11v6`}],[`path`,{d:`M14 11v6`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`}],[`path`,{d:`M3 6h18`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`}]],aliases:[`trash-2`]};$a(e,Ba(()=>n,{get icon(){return r}}))}var _o=new Set([`$$slots`,`$$events`,`$$legacy`]);function vo(e,t){let n=J(t,_o),r={name:`upload`,size:24,node:[[`path`,{d:`M12 3v12`}],[`path`,{d:`m17 8-5-5-5 5`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}var yo=e=>typeof e==`object`&&!!e&&!Array.isArray(e),bo=/\{\{\s*([a-z0-9-]+)\.([A-Za-z]\w*)\s*\}\}/g,xo=/^\{\{\s*([a-z0-9-]+)\.([A-Za-z]\w*)\s*\}\}$/,So=e=>typeof e==`string`&&!e.includes(`{{`)||typeof e==`number`||typeof e==`boolean`;function Co(e){let t=(r,i,a)=>{let o=`${r}.${i}`,s=Object.hasOwn(e,r)?e[r]:void 0;if(!yo(s)||a.includes(o))return;if(Object.hasOwn(s,i)){let e=n(s[i],[...a,o]);return So(e)?e:void 0}if(i!==`port`&&i!==`host`)return;let c=t(r,`url`,[...a,o]);if(typeof c!=`string`||!URL.canParse(c))return;let{port:l,hostname:u}=new URL(c);return i===`host`?u:Number(l)||void 0},n=(e,r)=>{if(typeof e==`string`){let n=xo.exec(e);return n?t(n[1]??``,n[2]??``,r)??e:e.replace(bo,(e,n,i)=>{let a=t(n,i,r);return a===void 0?e:String(a)})}return Array.isArray(e)?e.map(e=>n(e,r)):yo(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,n(t,r)])):e};return n}function wo(e){return!yo(e)||!yo(e.apps)?e:Co(e.apps)(e,[])}var To=80,Eo=90,Do=(e,t)=>e[t];function Oo(e,t){let n=e.map(e=>[...e]),r=[],i={};n.forEach((e,t)=>{for(let n of e)i[n]=t});for(let e of t){let t=Do(i,e.from)<=Do(i,e.to),a=t?e.to:e.from,o=t?e.from:e.to;if(i[o]!==i[a]){for(let t=Do(i,o)+1;t<Do(i,a);t++){let a=`~${e.from}>${e.to}:${String(t)}`;i[a]=t,n[t]?.push(a),r.push([o,a]),o=a}r.push([o,a])}}return{rows:n,links:r,row:i}}var ko=e=>{let t={};for(let n of e)n.forEach((e,n)=>t[e]=n);return t};function Ao(e,t,n){let r=ko(e),i=0;return t.forEach(([e,a],o)=>{for(let[s,c]of t.slice(o+1))n[e]===n[s]&&(Do(r,e)-Do(r,s))*(Do(r,a)-Do(r,c))<0&&i++}),i}function jo(e,t){let{rows:n,links:r,row:i}=Oo(e,t),a={};for(let[e,t]of r)(a[e]??=[]).push(t),(a[t]??=[]).push(e);let o=n.map(e=>[...e]),s=Ao(n,r,i);for(let e=0;e<12&&s;e++){let t=e%2==0,c=t?n.map((e,t)=>t).slice(1):n.map((e,t)=>n.length-2-t).filter(e=>e>=0);for(let e of c){let r=ko(n),o=n=>{let o=(a[n]??[]).filter(n=>i[n]===e+(t?-1:1));return o.length?o.reduce((e,t)=>e+Do(r,t),0)/o.length:Do(r,n)};n[e]?.sort((e,t)=>o(e)-o(t))}let l=Ao(n,r,i);l<s&&(s=l,o=n.map(e=>[...e]))}return e.forEach((e,t)=>{e.splice(0,e.length,...(o[t]??[]).filter(e=>!e.startsWith(`~`)))}),s}function Mo(e,t){let n=Object.fromEntries(e.map(e=>[e,[]]));for(let{from:e,to:r}of t)e in n&&r in n&&e!==r&&n[e]?.push(r);let r=e=>{let t=[e];for(let e=0;e<t.length;e++)for(let r of n[t[e]??``]??[])t.includes(r)||t.push(r);return t.length},i=new Set(Object.values(n).flat()),a=[...e.filter(e=>!i.has(e)).sort((e,t)=>r(t)-r(e)),...[...e].sort((e,t)=>r(t)-r(e))],o=Object.fromEntries(e.map(e=>[e,[]])),s=[],c={},l=e=>{c[e]=`open`;for(let t of n[e]??[])c[t]!==`open`&&(o[e]?.push(t),c[t]||l(t));c[e]=`done`,s.push(e)};for(let e of a)c[e]||l(e);let u=[...s].reverse(),d=Object.fromEntries(e.map(e=>[e,0]));for(let e of u)for(let t of o[e]??[])d[t]=Math.max(Do(d,t),Do(d,e)+1);for(let e of s){let t=(o[e]??[]).map(e=>Do(d,e));t.length&&(d[e]=Math.max(Do(d,e),Math.min(...t)-1))}return d}function No(e,t,n,r,i,a){let o={};e.forEach((e,t)=>{for(let n of e)o[n]=t});let s={};for(let{from:e,to:n}of t)e in o&&n in o&&o[e]!==o[n]&&((s[e]??=[]).push(n),(s[n]??=[]).push(e));let c=Object.fromEntries(Object.keys(o).map(e=>[e,Do(n,e)+a(e)]));for(let t=0,n=1/0;t<500&&n>.01;t++){n=0;for(let o of t%2?[...e].reverse():e){let e=[];o.forEach((t,n)=>{let s=o[n-1];e.push(s===void 0?0:(e[n-1]??0)+r(s)-a(s)+i+a(t))});let t=[];o.forEach((n,r)=>{let i=s[n]??[],a=i.length||.001,o=i.length?i.reduce((e,t)=>e+Do(c,t),0)/i.length:Do(c,n);for(t.push({sum:(o-(e[r]??0))*a,weight:a,count:1});;){let e=t.at(-1),n=t.at(-2);if(!e||!n||n.sum/n.weight<=e.sum/e.weight)break;t.pop(),n.sum+=e.sum,n.weight+=e.weight,n.count+=e.count}});let l=0;for(let r of t)for(let t=0;t<r.count;t++,l++){let t=o[l]??``,i=r.sum/r.weight+(e[l]??0);n=Math.max(n,Math.abs(i-Do(c,t))),c[t]=i}}}for(let e of Object.keys(c))n[e]=Do(c,e)-a(e)}function Po(e,t,n,r=`down`,i=!1,{pad:a,tight:o=!1,anchor:s}={pad:0}){let c=Mo(e,t),l=[];for(let t of e)(l[Do(c,t)]??=[]).push(t);let u=l.filter(Boolean);if(jo(u,t.filter(({from:e,to:t})=>e in c&&t in c&&e!==t)),i)for(let e of u)e.reverse();let d=Object.fromEntries(e.map(e=>[e,n(e)])),f=o?.6:1,p=r===`down`,m=p?`w`:`h`,h=p?`h`:`w`,g=p?To*f:Eo*.6*f,_=p?Eo*f:To*1.6*f,v=e=>e.reduce((e,t)=>e+Do(d,t)[m],0)+g*(e.length-1),y=Math.max(...u.map(v)),b={},x={},S=a+40;for(let e of u){let t=a+40+(y-v(e))/2;for(let n of e)b[n]=t,x[n]=S,t+=Do(d,n)[m]+g;S+=Math.max(...e.map(e=>Do(d,e)[h]))+_}No(u,t,b,e=>Do(d,e)[m],g,e=>s?.(e)??Do(d,e)[m]/2);let C=Math.min(...Object.values(b)),w={};for(let t of e){let e=Math.round(Do(b,t)-C+a+40);w[t]=p?{x:e,y:Do(x,t)}:{x:Do(x,t),y:e}}return w}function Fo(e,t,n,r,i={}){let a=t=>{let n=Do(e,t),{w:i,h:a}=r(t);return{...n,w:i,h:a,cx:n.x+i/2,cy:n.y+a/2}},o=a(t.from),s=a(t.to),c=Math.max(s.x-(o.x+o.w),o.x-(s.x+s.w)),l=Math.max(s.y-(o.y+o.h),o.y-(s.y+s.h)),u=s.cy>o.cy?{fromSide:`bottom`,toSide:`top`}:{fromSide:`top`,toSide:`bottom`},d=s.cx>=o.cx?{fromSide:`right`,toSide:`left`}:{fromSide:`left`,toSide:`right`},[f,p]=l>c||l===c&&n===`down`?[u,d]:[d,u],m=e=>i[t.from]!==e.fromSide&&i[t.to]!==e.toSide;return m(f)||!m(p)?f:p}function Io(e,t){let n=e=>[...e].sort((e,t)=>e[0]-t[0]).reduce((e,[t,n])=>{let r=e.at(-1);return r&&t<=r[1]?r[1]=Math.max(r[1],n):e.push([t,n]),e},[]),r=n(e),i=n(t).flatMap(([e,t])=>{let n=[],i=e;for(let[e,a]of r)a<=i||e>=t||(e>i&&n.push([i,e]),i=Math.max(i,a));return i<t&&n.push([i,t]),n});return{show:e=>e-i.reduce((t,[n,r])=>t+Math.max(0,Math.min(e,r)-n),0),back:e=>{let t=0;for(let[n,r]of i){if(e<n-t)break;t+=r-n}return e+t}}}var Lo={top:[0,-1],right:[1,0],bottom:[0,1],left:[-1,0]},Ro={top:`bottom`,bottom:`top`,left:`right`,right:`left`},zo=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n)),Bo=(e,t,n)=>t?{x:e.x+Lo[t][0]*n,y:e.y+Lo[t][1]*n}:e,Vo=({x:e,y:t})=>`${String(e)},${String(t)}`,Ho=({x:e,y:t,w:n,h:r},i)=>({top:{x:e+n/2,y:t},right:{x:e+n,y:t+r/2},bottom:{x:e+n/2,y:t+r},left:{x:e,y:t+r/2}})[i];function Uo(e,t,n,r){let i=zo(Math.hypot(n.x-e.x,n.y-e.y)*.4,30,140);return[e,Bo(e,t,i),Bo(n,r,i),n]}function Wo(e,t,n,r){let[,i,a]=Uo(e,t,n,r);return`M${Vo(e)} C${Vo(i)} ${Vo(a)} ${Vo(n)}`}function Go(e,t,n,r,i){let a=Bo(e,t,40),o=[a,...i,Bo(n,r,40)],s=`M${Vo(e)} L${Vo(a)}`;for(let t=0;t<o.length-1;t++){let r=o[t-1]??e,i=o[t]??e,a=o[t+1]??n,c=o[t+2]??n,l={x:i.x+(a.x-r.x)/6,y:i.y+(a.y-r.y)/6},u={x:a.x-(c.x-i.x)/6,y:a.y-(c.y-i.y)/6};s+=` C${Vo(l)} ${Vo(u)} ${Vo(a)}`}return`${s} L${Vo(n)}`}var Ko=e=>e===`left`||e===`right`,qo=e=>[[`from`,e.from,e.fromSide,e.to],[`to`,e.to,e.toSide,e.from]];function Jo(e){let t=new Map;return e.forEach((e,n)=>{for(let[r,i,a,o]of qo(e)){let s=`${i}|${a}`,c=t.get(s)??[];c.push({cable:e,index:n,end:r,side:a,id:i,other:o}),t.set(s,c)}}),t}var Yo=(e,t)=>t>1?Math.min(26,(e-48)/(t-1)):0,Xo=e=>e.every(t=>t.other===e[0]?.other)&&e.every(({cable:e,end:t,side:n})=>(t===`from`?e.toSide:e.fromSide)===Ro[n])?e[0]?.other:void 0;function Zo(e,t){for(let n of Jo(e).values()){let[{id:e,side:r}={id:``,side:`top`}]=n,i=Ko(r)?`y`:`x`,a=e=>i===`x`?e.w:e.h,o=e=>e[i]+a(e)/2,s=t(e),c=Xo(n),l;if(c){let e=Math.max(s[i],t(c)[i]),r=Math.min(s[i]+a(s),t(c)[i]+a(t(c))),u=Math.min(Yo(a(s),n.length),Yo(a(t(c)),n.length));r-e>=u*(n.length-1)+32&&(l=Math.round((e+r)/2-o(s)))}let u=Ho(s,r),[d,f]=Lo[r],p=({cable:e,end:n,other:r})=>{let a=Ho(t(r),n===`from`?e.toSide:e.fromSide),[o,s]=[a.x-u.x,a.y-u.y];return Math.atan2(i===`x`?o:s,o*d+s*f)};n.sort((e,n)=>p(e)-p(n)||o(t(e.other))-o(t(n.other))).forEach(({cable:e,end:t},n)=>{e[`${t}Slot`]=n,l?e[`${t}Shift`]=l:t===`from`?delete e.fromShift:delete e.toShift})}}function Qo(e,{cardOf:t,coveredBelow:n}){let r={},i=[];for(let a of Jo(e).values()){let[{id:e,side:o}={id:``,side:`top`}]=a,s=t(e);if(!s)continue;let c=Ko(o)?`y`:`x`,l=e=>c===`x`?e.w:e.h,u=l(s),d=a.length;a.sort((e,t)=>(e.cable[`${e.end}Slot`]??1/0)-(t.cable[`${t.end}Slot`]??1/0)||e.index-t.index);let{covered:f,atRight:p}=o===`bottom`&&n?.(e)||{covered:0,atRight:!1},m=f&&u-f>=56?u-f:0,h=m?p?m/2-u/2:f+m/2-u/2:0,g=d>1?Math.min(26,((m||u)-(m?20:48))/(d-1)):0,_=h;if(!h){let e=t(Xo(a)??``);e&&(g=Math.min(g,Yo(l(e),d)));let n=a.map(({cable:e,end:t})=>e[`${t}Shift`]).find(e=>e!==void 0)??0,r=Math.max(0,u/2-16-(d-1)/2*g);_=zo(n,-r,r)}a.forEach(({index:e,end:t},n)=>{r[`${String(e)}|${t}`]=_+(n-(d-1)/2)*g}),d===1&&!_&&i.push({id:e,side:o})}return{offset:r,onPort:i}}var $o=[[`cli`,`Koppler`],[`ide`,`Your IDE`]],es={tool:`docker`,fix:`Install a Docker runtime (Docker Desktop or Colima)`},ts={tool:`npm`,fix:`Comes with Node`},ns={dotnet:{label:`.NET`,runIn:$o,serves:!0,needs:[{tool:`dotnet`,fix:`Install the .NET SDK the repo targets`}]},flutter:{label:`Flutter`,runIn:$o,serves:!1,platforms:[[`ios`,`iOS simulator`],[`android`,`Android emulator`],[`phone`,`Phone`]],needs:[{tool:`fvm`,fix:`brew tap leoafarias/fvm && brew install fvm`}]},node:{label:`Node`,runIn:$o,serves:!0,needs:[ts]},web:{label:`Web`,runIn:$o,serves:!1,browser:!0,needs:[ts]},lambda:{label:`Lambda`,runIn:$o,serves:!0,needs:[es,{tool:`aws`,fix:`brew install awscli`}]},sam:{label:`AWS SAM`,runIn:$o,serves:!0,needs:[es,{tool:`sam`,fix:`brew install aws-sam-cli (or: uv tool install aws-sam-cli)`}]},other:{label:`Other`,runIn:$o,serves:!0}},rs=(e,t)=>e.read(t)??``,is=(e,t)=>t.map(t=>rs(e,t)).join(`
3
- `).toLowerCase(),as=(e,t)=>t?` ${e}${String(t)}`:``,os=e=>is(e,[`pyproject.toml`,`requirements.txt`,`Pipfile`]);function ss(e){return e.has(`uv.lock`)?`uv run `:e.has(`poetry.lock`)?`poetry run `:e.has(`Pipfile`)?`pipenv run `:e.has(`.venv/bin/python`)?`.venv/bin/`:``}var cs=e=>/spring-boot|springframework\.boot/.test(is(e,[`pom.xml`,`build.gradle`,`build.gradle.kts`])),ls=e=>[`compose.yaml`,`compose.yml`,`docker-compose.yml`,`docker-compose.yaml`].find(t=>e.has(t)),us={reactnative:{label:`React Native`,color:[`#087EA4`,`#58C4DC`],serves:!1,platforms:[[`ios`,`iOS simulator`],[`android`,`Android emulator`]],detect:e=>/"(expo|react-native)"\s*:/.test(rs(e,`package.json`)),start:(e,{platform:t=`ios`})=>/"expo"\s*:/.test(rs(e,`package.json`))?`npx expo start --${t}`:`npx react-native run-${t}`},go:{label:`Go`,color:[`#00758D`,`#5AD1E6`],detect:e=>e.has(`go.mod`),start:e=>{if(e.has(`main.go`))return`go run .`;let t=e.list(`cmd`);return t.length===1?`go run ./cmd/${t[0]??``}`:null}},rust:{label:`Rust`,color:[`#A0522D`,`#E8A27C`],detect:e=>e.has(`Cargo.toml`),start:()=>`cargo run`},java:{label:`Java / Kotlin`,color:[`#B0562B`,`#F0975F`],detect:e=>e.has(`pom.xml`)||e.has(`build.gradle`)||e.has(`build.gradle.kts`),port:e=>cs(e)?8080:null,start:e=>e.has(`pom.xml`)?cs(e)?`${e.has(`mvnw`)?`./mvnw`:`mvn`} spring-boot:run`:null:`${e.has(`gradlew`)?`./gradlew`:`gradle`} ${cs(e)?`bootRun`:`run`}`},python:{label:`Python`,color:[`#2F6F9F`,`#7FB8E6`],detect:e=>[`manage.py`,`pyproject.toml`,`requirements.txt`,`Pipfile`].some(t=>e.has(t)),port:e=>{let t=os(e);return e.has(`manage.py`)||/fastapi|uvicorn/.test(t)?8e3:t.includes(`flask`)?5e3:null},start:(e,{port:t})=>{let n=ss(e),r=os(e);if(e.has(`manage.py`))return`${n}python manage.py runserver${as(``,t)}`;if(/fastapi|uvicorn/.test(r)){let r=[`main.py`,`app/main.py`,`src/main.py`].find(t=>e.has(t))?.replace(/\.py$/,``).replace(/\//g,`.`);return r?`${n}uvicorn ${r}:app --reload${as(`--port `,t)}`:null}return r.includes(`flask`)?`${n}flask run${as(`--port `,t)}`:null}},ruby:{label:`Ruby`,color:[`#B3261E`,`#F28B82`],detect:e=>e.has(`Gemfile`),port:e=>e.has(`config/application.rb`)?3e3:null,start:(e,{port:t})=>e.has(`config/application.rb`)?`bin/rails server${as(`-p `,t)}`:null},php:{label:`PHP`,color:[`#6C5FC7`,`#A99FF5`],detect:e=>e.has(`artisan`)||e.has(`composer.json`),port:e=>e.has(`artisan`)?8e3:null,start:(e,{port:t})=>e.has(`artisan`)?`php artisan serve${as(`--port=`,t)}`:null},compose:{label:`Docker Compose`,color:[`#1D63ED`,`#7AA7FF`],detect:e=>!!ls(e),port:e=>Number(/["'\s-](\d{2,5}):\d{2,5}["'\s]/.exec(rs(e,ls(e)??``))?.[1])||null,start:()=>`docker compose up`,stop:`docker compose down`}};for(let[e,t]of Object.entries(us))ns[e]={label:t.label,runIn:$o,serves:t.serves!==!1,...t.platforms&&{platforms:t.platforms},...t.color&&{color:t.color}};Object.keys(ns);var ds={kinds:ns,recipes:us,custom:[]},fs=new WeakMap;function ps(e){let t=e?.kinds;if(typeof t!=`object`||!t)return ds;let n=fs.get(t);if(n)return n;let r={kinds:{...ns},recipes:{...us},custom:[]};for(let[e,n]of Object.entries(t)){if(!/^[a-z0-9-]{1,32}$/.test(e)||Object.hasOwn(ns,e)||typeof n!=`object`||!n)continue;let t=n,i=[t.detect??[]].flat().filter(e=>typeof e==`string`),a=typeof t.label==`string`&&t.label?t.label:e;r.recipes[e]={label:a,detect:e=>i.length>0&&i.every(t=>e.has(t)),port:()=>Number(t.port)||null,start:()=>typeof t.start==`string`&&t.start?t.start:null},r.kinds[e]={label:a,runIn:$o,serves:t.serves!==!1,custom:!0},r.custom.push(e)}return fs.set(t,r),r}var ms=e=>ps(e).kinds;function hs(e,t){let n=e?.kind,r=ms(t);return n!==void 0&&Object.hasOwn(r,n)&&r[n]||{label:n??`App`,runIn:$o,serves:!0}}var gs=e=>typeof e==`string`?e:``,_s=e=>({branch:e?.branch||``,run:e?.run||`cli`,...e?.platform&&{platform:e.platform},...gs(e?.note)&&{note:gs(e?.note)},...e?.tunnels===!1&&{tunnels:!1},...e?.queues===!0&&{queues:!0},...gs(e?.changes)&&{changes:gs(e?.changes)},...Array.isArray(e?.libraries)&&e.libraries.length>0&&{libraries:e.libraries.map(String).sort()},...e?.restart===!0&&{restart:!0},...e?.watch===!0&&{watch:!0}}),vs=e=>e?.run===`mock`?{branch:``,run:`mock`,...e.restart===!0&&{restart:!0}}:_s(e);function ys(e){let t=e?.nodes??{},n=Array.isArray(t)?t.map(e=>[e.id,e]):Object.entries(t),r=Object.fromEntries(n.filter(([e])=>typeof e==`string`).map(([e,t])=>[e,vs(t)])),i=(Array.isArray(e?.edges)?e.edges:[]).filter(e=>!!e&&Object.hasOwn(r,e.from)&&Object.hasOwn(r,e.to)).map(e=>({from:e.from,to:e.to})),a=Object.fromEntries(Object.entries(e?.queues??{}).flatMap(([e,t])=>t===`local`?[[e,`local`]]:[]));return{env:e?.env??null,nodes:r,edges:i,queues:a}}var bs=(e,t)=>e.edges.filter(e=>e.from===t).map(e=>e.to).sort(),xs=e=>e.toUpperCase(),Ss=e=>({ide:`your IDE`,cli:`the command line`,mock:`a mock`})[e];function Cs(e,t,n,r,i){let a=t.nodes[e],o=n.nodes[e];if(!a||!o)return[];let s=e=>i.name?.(e)??e,c=[];o.restart&&c.push(`you asked to restart it`),r&&c.push(`the environment changes from ${xs(r.from)} to ${xs(r.to)}`),a.branch!==o.branch&&a.run!==`mock`&&o.run!==`mock`&&c.push(`its branch changes from ${a.branch||i.current?.(e)||`the current one`} to ${o.branch||`the current one`}`),a.run!==o.run&&c.push(`it moves from ${Ss(a.run)} to ${Ss(o.run)}`),(a.platform??``)!==(o.platform??``)&&o.run===`cli`&&c.push(`its device changes to ${String(o.platform)}`);let l=bs(t,e),u=bs(n,e);for(let e of u.filter(e=>!l.includes(e)))c.push(`it starts calling your local ${s(e)}`);for(let e of l.filter(e=>!u.includes(e)))c.push(`it goes back to the deployed ${s(e)}`);(a.note??``)!==(o.note??``)&&c.push(`its note changed`);let d=a.libraries??[],f=o.libraries??[];for(let e of f.filter(e=>!d.includes(e)))c.push(`it uses your local ${e}`);for(let e of d.filter(e=>!f.includes(e)))c.push(`it goes back to the published ${e}`);let p=(e,t,n)=>t.queues===!0&&Object.hasOwn(e.queues,n);for(let r of i.queuesOf?.(e)??[])p(t,a,r)!==p(n,o,r)&&c.push(`it moves to the ${p(n,o,r)?`local`:`deployed`} ${r} queue`);return c}function ws(e,t,n={}){let r=ys(e),i=ys(t),a=n.strays??[],o=r.env&&i.env&&r.env!==i.env&&Object.keys(r.nodes).length>0?{from:r.env,to:i.env}:null,s=[],c=[],l=[],u=[];for(let[e,t]of Object.entries(i.nodes))if(!Object.hasOwn(r.nodes,e)){let r=n.startedOn?.(e)===i.env&&bs(i,e).length===0&&!t.note&&!t.branch;a.includes(e)?r?u.push({id:e,why:[`you started it with koppler run`]}):c.push({id:e,why:[`it is running, but not from a run Koppler recorded`]}):s.push({id:e,why:[]})}else if(n.running?.(e)===!1&&t.run!==`ide`)s.push({id:e,why:[`it was started before but is not running now`]});else{let t=Cs(e,r,i,o,n);(t.length>0?c:u).push({id:e,why:t})}for(let e of[...Object.keys(r.nodes),...a])!Object.hasOwn(i.nodes,e)&&!l.some(t=>t.id===e)&&l.push({id:e,why:[]});let d=s.length+c.length+l.length===0;return{env:i.env,envChange:o,starts:s,restarts:c,stops:l,keeps:u,nothing:d}}var Ts=[[`starts`,`START`],[`restarts`,`RESTART`],[`stops`,`STOP AND REVERT`],[`keeps`,`KEEP RUNNING`]];function Es(e,t={}){let n=e=>t.name?.(e)??e,r=e=>n(e.id)+(e.why.length>0?` (${e.why.join(`; `)})`:``),i=Ts.filter(([t])=>e[t].length>0).map(([t,n])=>`${n}: ${e[t].map(r).join(`, `)}`);return i.length>0?i:[`NOTHING TO CHANGE`]}var Ds=[`sqs`,`kafka`];function Os(e,t){let n=e?.apps?.[t];return[...new Set([...Object.keys(n?.publishes??{}),...Object.keys(n?.reads??{})])]}function ks(e){let t=e?.envs??[],n=e?.protected;return Array.isArray(n)?t.filter(e=>n.includes(e)):t.slice(1)}var As=(e,t)=>ks(e).includes(t),js=[[`valkey`,`Cache (Valkey)`],[`redis`,`Cache (Redis)`],[`aurora`,`Database (Aurora)`],[`postgres`,`Database (Postgres)`],[`mysql`,`Database (MySQL)`],[`mongo`,`Database (MongoDB)`],[`db`,`Database`],[`rds`,`Database`]];function Ms(e){if(e.what)return e.what;let t=(e.tunnel??``).toLowerCase(),n=t.split(/[.-]/);return js.find(([e])=>n.includes(e)||e.length>3&&t.includes(e))?.[1]??`Tunnel`}function Ns(e){let t=new Map;for(let n of e){let e=`${n.tunnel}:${String(n.port)}`,r=t.get(e)??{host:n.tunnel,port:n.port,original:n.port,bind:`localhost`,apps:[],envs:{},what:Ms(n),connectsAs:n.connectsAs};r.apps.includes(n.app)||r.apps.push(n.app),n.env&&(r.envs[n.app]=n.env),t.set(e,r)}return[...t.values()]}function Ps(e,t=[]){let n=Ns(e),r=new Set([...t,...n.map(e=>e.port)]),i=e=>e.apps.every(t=>e.envs[t]),a=2;for(let e of new Set(n.map(e=>e.original))){let t=n.filter(t=>t.original===e);t.sort((e,t)=>Number(i(e))-Number(i(t)));for(let n of t.slice(1))if(i(n)){let t=e+2;for(;r.has(t);)t++;r.add(t),n.port=t,n.settings=n.apps.map(e=>({app:e,env:n.envs[e]??``,value:`localhost:${String(t)}`}))}else n.bind=`127.0.0.${String(a++)}`,n.needsAlias=!0}return n}function Fs(e,t=e=>e){let n=e=>e.what===`Tunnel`?`tunnel`:`${e.what.replace(/ \(.*\)$/,``).toLowerCase()} tunnel`,r=e=>`${e.apps.map(t).join(` and `)}'s ${n(e)}`;return e.flatMap(i=>{let a=e.filter(e=>e!==i&&e.original===i.original).map(r).join(` and `),o=String(i.port);return i.settings?[`${r(i)} moves from port ${String(i.original)} to ${o}, to make room for ${a}.`]:i.needsAlias?[`${r(i)} keeps port ${o} on its own address, ${i.bind}, next to ${a}. Needs a one-time sudo step.`]:i.apps.length>1?[`${i.apps.map(t).join(` and `)} share one ${n(i)} on port ${o}.`]:[]})}var Is=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Ls={0:e=>({...e,nodes:Object.fromEntries(Object.entries(e.nodes).map(([e,t])=>[e,{run:`cli`,...t}]))})};function Rs(e){if(!Is(e))return{error:`It is not a preset.`};let{name:t,nodes:n,edges:r,version:i}=e;if(typeof t!=`string`||!t.trim())return{error:`It has no name.`};if(!Is(n)||Object.keys(n).length===0)return{error:`It has no apps.`};let a=typeof i==`number`&&Number.isInteger(i)&&i>=0?i:0;if(a>1)return{error:`It was saved by a newer Koppler (${`preset format ${String(a)}, this one reads up to 1`}). Update Koppler.`};let o={...e,name:t,nodes:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,Is(t)?t:{}])),edges:Array.isArray(r)?r:[]};for(let e=a;e<1;e++)o={...Ls[e]?.(o)??o,version:e+1};return{preset:o,migratedFrom:a<1?a:null}}function zs(e,t,n,r,i){let a=n.runIn(e),o=n.platforms(e),s=typeof t.run==`string`?t.run:``,c=a.includes(s)?s:a.includes(`cli`)?`cli`:a[0]??`cli`;s&&c!==s&&i.push(`${r} cannot run in "${s}", using ${c}`);let l={run:c},u=typeof t.platform==`string`?t.platform:``,d=o[0];d!==void 0&&c===`cli`&&(l.platform=o.includes(u)?u:d,u&&l.platform!==u&&i.push(`${r} has no "${u}" platform, using ${l.platform}`));let f=typeof t.branch==`string`?t.branch.trim():``;if(f){l.branch=f;let t=n.branches(e);t&&!t.includes(f)&&i.push(`${r} has no branch ${f} in your clone (fetch it first)`)}return typeof t.note==`string`&&t.note.trim()&&(l.note=t.note),t.tunnels===!1&&(l.tunnels=!1),t.queues===!0&&(l.queues=!0),t.watch===!0&&(l.watch=!0),l}var Bs=e=>Is(e)&&typeof e.from==`string`&&typeof e.to==`string`;function Vs(e,t){let n=Rs(e);if(n.error!==void 0)return{error:n.error};let r=n.preset,i=[],a=e=>t.name?.(e)??e;(!Is(e)||!Number.isInteger(e.version))&&i.push(`it had no version, read as the oldest format`);let o=Object.keys(r.nodes),s=o.filter(e=>!t.known(e)),c=o.filter(e=>t.known(e)&&!t.cloned(e)),l=o.filter(e=>t.known(e)&&t.cloned(e));if(l.length===0)return{error:s.length===o.length?`None of its apps are in this stack (${s.join(`, `)}).`:`None of its apps are cloned here (${c.join(`, `)}).`};s.length>0&&i.push(`not in this stack: ${s.join(`, `)}`),c.length>0&&i.push(`not cloned: ${c.map(a).join(`, `)}`);let u=Object.fromEntries(l.map(e=>[e,zs(e,r.nodes[e]??{},t,a(e),i)])),d=[],f=0;for(let e of r.edges.filter(Bs)){let{from:n,to:r}=e;!Object.hasOwn(u,n)||!Object.hasOwn(u,r)?t.known(n)&&t.known(r)&&f++:d.some(e=>e.from===n&&e.to===r)||(t.canCall(n,r)?d.push({from:n,to:r}):i.push(`${a(n)} does not call ${a(r)}, cable left out`))}f>0&&i.push(`${String(f)} ${f===1?`cable`:`cables`} left out with their apps`),n.migratedFrom!==null&&n.migratedFrom>0&&i.push(`updated from preset format ${String(n.migratedFrom)}`);let p={name:r.name.trim().slice(0,80),version:1,nodes:u,edges:d};return r.source&&(p.source=r.source),{preset:p,notes:i}}var Hs=e=>Is(e)&&typeof e.x==`number`&&typeof e.y==`number`,Us=e=>t=>e.from===t.from&&e.to===t.to;function Ws(e,t){let n=new Set(t.remove??[]),r=e=>Object.fromEntries(Object.entries(e).filter(([e])=>!n.has(e))),i=r(e.nodes),a=Is(e.layout)?e.layout:void 0,o=r(Is(a?.nodes)?a.nodes:{}),s=Object.values(o).filter(Hs),c=Math.min(...s.map(e=>e.y));for(let e of t.add??[])i[e]||(i[e]={run:`cli`},s.length&&(o[e]={x:Math.max(...s.map(e=>e.x))+340,y:c},c+=240));for(let[e,n]of Object.entries(t.branch??{}))i[e]&&(i[e]={...i[e],branch:n});for(let[e,n]of Object.entries(t.note??{})){let{note:t,...r}=i[e]??{};i[e]&&(i[e]=n.trim()?{...r,note:n}:r)}let l=e.edges.filter(Bs).filter(e=>!n.has(e.from)&&!n.has(e.to)&&!(t.uncable??[]).some(Us(e)));for(let e of t.cable??[])l.some(Us(e))||l.push({from:e.from,to:e.to});if(!a||t.arrange){let{layout:t,...n}=e;return{...n,nodes:i,edges:l}}let u=new Set(l.map(e=>`${e.from}>${e.to}`)),d=Object.fromEntries(Object.entries(Is(a.sides)?a.sides:{}).filter(([e])=>u.has(e)));return{...e,nodes:i,edges:l,layout:{...a,nodes:o,sides:d}}}function Gs(e,t=e=>e,n=!1){let r=(e=[])=>e.map(t).join(`, `),i=(e=[])=>e.map(e=>`${t(e.from)} to ${t(e.to)}`).join(`, `);return[e.add?.length&&`${n?`add`:`added`} ${r(e.add)}`,e.remove?.length&&`${n?`remove`:`removed`} ${r(e.remove)}`,e.cable?.length&&`${n?`cable`:`cabled`} ${i(e.cable)}`,e.uncable?.length&&`${n?`take the cable off`:`took the cable off`} ${i(e.uncable)}`,...Object.entries(e.branch??{}).map(([e,r])=>`${n?`put `:``}${t(e)} on ${r}`),...Object.entries(e.note??{}).map(([e,r])=>r.trim()?`${n?`add `:``}a note on ${t(e)}`:`${n?`take the `:`no `}note${n?` off `:` on `}${t(e)}`),e.arrange&&(n?`lay it out afresh`:`arranged`)].filter(Boolean).join(`; `)}async function Ks(e){try{let t=await fetch(`data/${e}.json`);return t.ok?await t.json():null}catch{return null}}async function qs(){let[e,t,n]=await Promise.all([Ks(`registry`),Ks(`local`),Ks(`state`)]);return e?{stack:e,clones:t?.apps??{},roots:t?.roots??[],saved:n}:null}async function Js(e,t={},n=!1){let r=location.pathname.split(`/`)[2]??``;try{return await fetch(`/${e}?token=${encodeURIComponent(r)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t),keepalive:n})}catch{return null}}var Ys=async(e,t=!1)=>!!(await Js(`state`,e,t))?.ok;async function Xs(e,t={}){let n=await Js(e,t);return n?await n.json().catch(()=>({error:`The canvas server answered ${String(n.status)}.`})):{error:`Could not reach the canvas server.`}}var Zs=()=>Ks(`repos`),Qs={cli:`Koppler`,ide:`Me`,mock:`Mock`},$s=.6,ec=[[`down`,!1],[`right`,!1],[`down`,!0],[`right`,!0]],tc=e=>`tunnel:${e.host}:${String(e.original)}`,nc={w:230,h:58,gap:40},rc=[`bottom`,`right`,`left`,`top`],ic=8,ac=24,oc=44,sc={w:300,h:240,gap:32},cc=(e,t,n)=>({id:`${e}>${t}`,source:e,target:t,type:`cable`,data:n}),lc=e=>e.selected?{...e,selected:!1}:e,Z=new class{#e=M(``);get stack(){return z(this.#e)}set stack(e){N(this.#e,e,!0)}#t=M(``);get dir(){return z(this.#t)}set dir(e){N(this.#t,e,!0)}#n=M(!1);get setup(){return z(this.#n)}set setup(e){N(this.#n,e,!0)}#r=M([]);get known(){return z(this.#r)}set known(e){N(this.#r,e)}#i=M(``);get env(){return z(this.#i)}set env(e){N(this.#i,e,!0)}#a=M([]);get nodes(){return z(this.#a)}set nodes(e){N(this.#a,e)}#o=[];#s=j(()=>{let e=this.nodes;return e.length===this.#o.length&&e.every((e,t)=>e.id===this.#o[t]?.id&&e.data===this.#o[t].data)||(this.#o=e),this.#o});get cards(){return z(this.#s)}set cards(e){N(this.#s,e)}#c=M([]);get edges(){return z(this.#c)}set edges(e){N(this.#c,e)}#l=M(null);get hovered(){return z(this.#l)}set hovered(e){N(this.#l,e)}#u=M([]);#d=j(()=>z(this.#u).includes(this.env));get protected(){return z(this.#d)}set protected(e){N(this.#d,e)}toFlow=e=>e;zoom=()=>1;#f=j(()=>this.edges.map(e=>({from:e.source,to:e.target,...e.data})));get cables(){return z(this.#f)}set cables(e){N(this.#f,e)}#p=M([]);get infra(){return z(this.#p)}set infra(e){N(this.#p,e)}#m=M({});get queues(){return z(this.#m)}set queues(e){N(this.#m,e)}#h=M({});get hiddenQueues(){return z(this.#h)}set hiddenQueues(e){N(this.#h,e)}#g=M({});get hiddenOutside(){return z(this.#g)}set hiddenOutside(e){N(this.#g,e)}#_=M([]);get pinned(){return z(this.#_)}set pinned(e){N(this.#_,e)}pin(e){this.pinned.includes(e)||(this.pinned=[...this.pinned,e])}unpin(e){this.pinned=this.pinned.filter(t=>t!==e)}#v=j(()=>new Map(this.infra.map(({id:e,position:t,measured:n})=>[e,{...this.shown(t,e),w:n?.width??nc.w,h:n?.height??nc.h}])));get infraBoxes(){return z(this.#v)}set infraBoxes(e){N(this.#v,e)}#y=M(!1);get present(){return z(this.#y)}set present(e){N(this.#y,e,!0)}entering=!1;#b=M(!1);get brief(){return z(this.#b)}set brief(e){N(this.#b,e,!0)}#x=j(()=>{if(!this.brief||this.live||this.present)return;let e=this.nodes.filter(e=>e.selected);return e.length===1?e[0]:void 0});get panelCard(){return z(this.#x)}set panelCard(e){N(this.#x,e)}#S=M({});get fullHeights(){return z(this.#S)}set fullHeights(e){N(this.#S,e)}#C=j(()=>new Map([...this.nodes,...this.infra].map(({id:e,measured:t})=>{let n=t?.height??0,r=this.fullHeights[e]??0;return[e,this.brief&&n&&r>n?(r-n)/2:0]})));#w(e=(e,t)=>t.y){let t=[],n=[];for(let{id:r,position:i,measured:a}of[...this.nodes,...this.infra]){let o=a?.height;if(!o)continue;let s=e(r,i),c=z(this.#C).get(r)??0;t.push([s+c,s+c+o]);let l=this.fullHeights[r]??0;c&&n.push([s,s+c]),l>o&&n.push([s+c+o,s+l])}return Io(this.brief?t:[],this.brief?n:[])}#T=Io([],[]);#E=null;#D=()=>[...this.nodes,...this.infra].map(({id:e,position:t,measured:n})=>`${e} ${String(t.x)} ${String(t.y)} ${String(n?.height??0)}`).join(`|`);#O=j(()=>{let e=this.#D();return[...this.nodes,...this.infra].some(e=>e.dragging)||this.brief&&this.#E===e||(this.#E=null,this.#T=this.#w()),this.#T});get squeezed(){return z(this.#O)}set squeezed(e){N(this.#O,e)}shown=(e,t=``)=>({x:e.x,y:this.squeezed.show(e.y+(z(this.#C).get(t)??0))});stored=(e,t=``)=>({x:e.x,y:this.squeezed.back(e.y)-(z(this.#C).get(t)??0)});dropped(e,t){let n=z(this.#C).get(e)??0,r=this.squeezed.back(t.y)-n;if(this.brief)return{x:t.x,y:r};for(let i=0;i<4;i++)r=this.#w((t,n)=>t===e?r:n.y).back(t.y)-n;return{x:t.x,y:r}}#k=j(()=>new Map(this.nodes.flatMap(({id:e,position:t,measured:n})=>n?.width&&n.height?[[e,{...this.shown(t,e),w:n.width,h:n.height}]]:[])));get boxes(){return z(this.#k)}set boxes(e){N(this.#k,e)}#A=M();#j=M([]);get unplaced(){return z(this.#j)}set unplaced(e){N(this.#j,e)}#M(e){return this.nodes.some(t=>t.id===e&&t.data.run===`mock`)}tunnelsOf(e){if(this.#M(e))return[];let t=z(this.#A)?.apps[e];return((this.env===this.envs[0]?void 0:t?.envs?.[this.env]?.prereqs)??t?.prereqs??[]).flatMap(e=>{let{tunnel:t,port:n}=e;return t&&n&&Number.isInteger(n)&&n<65536?[{...e,tunnel:t,port:n}]:[]})}tunnelPath(e,t){let n=z(this.#A)?.apps[e],r=this.env===this.envs[0]?void 0:n?.envs?.[this.env]?.prereqs,i=(r??n?.prereqs??[]).findIndex(e=>e.tunnel===t);return`apps.${e}.${r?`envs.${this.env}.`:``}prereqs[${String(i)}]`}#N=j(()=>Ps(this.cards.filter(e=>!e.data.hideTunnels).flatMap(({id:e})=>this.tunnelsOf(e).map(t=>({app:e,tunnel:t.tunnel,port:t.port,env:t.env,what:Ms(t),connectsAs:t.connectsAs}))),this.cards.flatMap(({id:e})=>{let t=Number(new URL(z(this.#A)?.apps[e]?.url??`http://none`).port);return t?[t]:[]})));get plan(){return z(this.#N)}set plan(e){N(this.#N,e)}ledBy(e){return[...this.plan.filter(t=>t.apps[0]===e).map(tc),...this.boardQueues.filter(t=>this.#R(t)===e).map(e=>`queue:${e.id}`)]}#P=j(()=>new Set(this.cards.map(e=>e.id)));#F=j(()=>new Set(this.cards.filter(e=>e.data.showQueues).map(e=>e.id)));commandsOf(e){return Object.entries(z(this.#A)?.apps[e]?.commands??{}).filter(([,e])=>(e.show??`both`)!==`cli`)}#I(e){return!!z(this.#A)?.apps[e]?.outside}#L=j(()=>{let e=z(this.#A)?.apps??{};return Object.entries(z(this.#A)?.queues??{}).flatMap(([t,n])=>{let r=n=>Object.keys(e).filter(r=>Object.hasOwn(e[r]?.[n]??{},t)&&(z(this.#F).has(r)||this.#I(r))),[i,a]=[r(`publishes`),r(`reads`)];return!this.hiddenQueues[t]&&[...i,...a].some(e=>z(this.#F).has(e))?[{id:t,queue:n,pubs:i,reads:a}]:[]})});get boardQueues(){return z(this.#L)}set boardQueues(e){N(this.#L,e)}ownedBy(e){let t=t=>[...t.pubs,...t.reads].filter(e=>z(this.#P).has(e)||this.#I(e)&&!this.hiddenOutside[e]).every(t=>t===e);return this.ledBy(e).filter(e=>e.startsWith(`tunnel:`)||this.boardQueues.some(n=>`queue:${n.id}`===e&&t(n)))}#R(e){return[...e.pubs,...e.reads].find(e=>z(this.#P).has(e))}queueName(e){return z(this.#A)?.queues?.[e]?.name??e}switchesOver(e){if(this.#M(e))return!1;let t=this.cards.find(t=>t.id===e)?.data.branch,n=this.app(e);return!!(t&&n?.current&&t!==n.current&&n.dirty)}localLibraries(e){let t=this.cards.find(t=>t.id===e)?.data.libraries??[],n=this.app(e)?.libraries??[];return t.filter(e=>n.some(t=>t.name===e))}borrowsTunnels(e){if(this.env===this.envs[0])return!1;let t=z(this.#A)?.apps[e],n=t?.envs?.[this.env]?.prereqs??[],r=this.cards.find(t=>t.id===e)?.data.hideTunnels;return[`sso`,`signIn`,`tunnel`,`hosts`].some(e=>(t?.prereqs??[]).some(t=>t[e])&&!n.some(t=>t[e])&&!(e!==`sso`&&e!==`signIn`&&r))}queuesOf(e){return this.#M(e)?[]:Os(z(this.#A),e).filter(e=>z(this.#A)?.queues?.[e])}#z=j(()=>{let e=e=>this.#I(e)?`outside:${e}`:e;return[...this.boardQueues.flatMap(({id:t,pubs:n,reads:r})=>[...n.map(n=>({from:e(n),to:`queue:${t}`,queue:t})),...r.map(n=>({from:`queue:${t}`,to:e(n),queue:t}))]),...this.cards.flatMap(({id:e})=>Object.keys(z(this.#A)?.apps[e]?.consumes??{}).filter(e=>this.#I(e)).map(t=>({from:e,to:`outside:${t}`}))),...Object.entries(z(this.#A)?.apps??{}).flatMap(([e,t])=>this.#I(e)?Object.keys(t.consumes??{}).filter(e=>this.cards.some(t=>t.id===e)).map(t=>({from:`outside:${e}`,to:t})):[])]});get flows(){return z(this.#z)}set flows(e){N(this.#z,e)}infraSide(e){let t=new Set(this.cables.flatMap(t=>[t.from===e&&t.fromSide,t.to===e&&t.toSide]));return rc.find(e=>!t.has(e))??`bottom`}deployedCalls(e){return this.#M(e)?[]:(this.app(e)?.calls??[]).flatMap(t=>{let n=this.app(t);return n&&!n.outside&&!this.edges.some(n=>n.id===`${e}>${t}`)?[n]:[]})}callLocally(e,t){this.add(t),this.nodes.some(e=>e.id===t)&&this.connect(e,t)}setQueue(e,t){let{[e]:n,...r}=this.queues;this.queues=t?{...r,[e]:`local`}:r,this.syncInfra()}showQueues(e,t){let n=Object.entries(this.hiddenQueues).filter(([t])=>!e.includes(t));this.hiddenQueues=Object.fromEntries(t?n:[...n,...e.map(e=>[e,!0])])}#B=j(()=>this.plan.flatMap(e=>e.apps.map(t=>({from:t,to:tc(e),tunnel:e}))));get links(){return z(this.#B)}set links(e){N(this.#B,e)}#V=j(()=>{let e=[...this.nodes,...this.infra].filter(e=>e.selected),t=this.edges.filter(e=>e.selected),[n]=e,[r]=t;if(e.length===1&&!t.length&&n){let e=[n.id];for(let{from:t,to:r}of[...this.cables,...this.links,...this.flows])(t===n.id||r===n.id)&&e.push(t,r);return{id:n.id,near:e}}return!e.length&&t.length===1&&r?{id:null,cable:[r.source,r.target],near:[r.source,r.target]}:null});get focus(){return z(this.#V)}set focus(e){N(this.#V,e)}dimmed=e=>!!this.focus&&!this.focus.near.includes(e);lit=(e,t)=>{let n=this.focus;return n?n.cable?n.cable[0]===e&&n.cable[1]===t:e===n.id||t===n.id:!1};dimmedLink=(e,t)=>!!this.focus&&!this.lit(e,t);#H(e){let t=this.boxes.get(e),n=this.ledBy(e).flatMap(e=>this.infraBoxes.get(e)??[]).filter(e=>t&&e.y>t.y&&e.x<t.x+t.w&&e.x+e.w>t.x);return{covered:n.length?Math.max(...n.map(e=>e.w+12)):0,atRight:!!t&&!!n.length&&n.every(e=>Math.abs(e.x+e.w-t.x-t.w)<2)}}#U=j(()=>Qo(this.cables,{cardOf:e=>this.boxes.get(e),coveredBelow:e=>this.#H(e)}));get ends(){return z(this.#U)}set ends(e){N(this.#U,e)}#W(e,t,n=this.boxes.get(e)??{w:260,h:200},r=!1,i){let a=this.nodes.find(t=>t.id===e),o=new Set(r?this.ownedBy(e):this.ledBy(e));if(!a||!o.size)return t;let s={...a.position,...n},c=i??this.infraSide(e),l=c===`bottom`?s.y+s.h+nc.gap/2:c===`top`?s.y-nc.gap/2:s.y;return t.map(e=>{if(!o.has(e.id))return e;let t=this.infraBoxes.get(e.id)??nc;c===`top`&&(l-=t.h);let n=c===`right`?s.x+s.w+nc.gap:c===`left`?s.x-nc.gap-t.w:s.x,r={...e,position:{x:n,y:l}};return l+=c===`top`?-nc.gap/2:t.h+nc.gap/2,r})}syncInfra(e={}){let t=new Map(this.infra.map(e=>[e.id,e])),n=[],r=this.plan.map(r=>{let i=tc(r),a=t.get(i);!a&&!e[i]&&n.push(r.apps[0]??``);let o=r.apps.flatMap(e=>this.tunnelsOf(e)).find(e=>e.tunnel===r.host)?.note;return{...a,id:i,type:`tunnel`,deletable:!1,position:a?.position??e[i]??{x:0,y:0},data:{what:r.what,local:`${r.bind}:${String(r.port)}`,moved:!!r.settings||!!r.needsAlias,host:r.host,about:[r.settings?`Moved from port ${String(r.original)} so it does not clash with another tunnel on the board.`:``,r.needsAlias?`Keeps port ${String(r.port)} on its own loopback address, ${r.bind}, so it does not clash (needs sudo once).`:``,typeof o==`string`?o:``].filter(Boolean),apps:r.apps,settings:this.tunnelPath(r.apps[0]??``,r.host)}}}),i=this.env.toUpperCase(),a=e=>z(this.#A)?.apps[e]?.name??e,o=this.boardQueues.map(r=>{let o=`queue:${r.id}`,s=t.get(o),c=this.#R(r);!s&&!e[o]&&c&&n.push(c);let l=Ds.includes(r.queue.type),u=l&&this.queues[r.id]===`local`,d=r.reads.filter(e=>z(this.#P).has(e)).map(a),f=!u&&d.length?d.join(` and `):``;return{...s,id:o,type:`queue`,deletable:!1,position:s?.position??e[o]??{x:0,y:0},data:{queue:r.id,name:r.queue.name,kind:r.queue.type.toUpperCase(),can:l,local:u,shares:f?`Your local ${f} reads the ${i} queue`:``,about:[r.queue.envs?.[this.env]?.queue??r.queue.queue??r.id,f?`It takes messages the deployed ${i} reader would get. Switch to Local to give your run its own copy.`:``].filter(Boolean)}}}),s=[...new Set([...this.flows.flatMap(e=>[e.from,e.to]),...this.pinned.filter(e=>this.#I(e)).map(e=>`outside:${e}`)])].filter(e=>e.startsWith(`outside:`)&&!this.hiddenOutside[e.slice(8)]).map(n=>{let r=z(this.#A)?.apps[n.slice(8)],o=t.get(n),s=this.env===this.envs[0]?void 0:r?.envs?.[this.env]?.deployedUrl,c=typeof s==`string`?s:r?.deployedUrl??``,l=URL.canParse(c)?new URL(c).hostname:``,u=typeof r?.outside==`string`?`: ${r.outside.replace(/\.+$/,``)}`:``;return{...o,id:n,type:`outside`,deletable:!1,position:o?.position??e[n]??{x:0,y:0},data:{name:r?.name??n.slice(8),where:l?`${i}: ${l}`:`Outside, never runs`,about:[`${r?.name??n.slice(8)} does not run on this Mac${u}. Koppler cannot check calls to it.`,l?`The ${i} board uses ${c}.`:``,...this.flows.filter(e=>e.from===n).map(e=>`It sends to the deployed ${a(e.to)}, not to your local one.`)].filter(Boolean)}}}),c=[...r,...o,...s];for(let e of n)c=this.#W(e,c);for(let n of s.filter(n=>!t.has(n.id)&&!e[n.id])){let e=this.#G(n.id,c);c=c.map(t=>t.id===n.id?{...t,position:e}:t)}this.infra=c,this.unplaced=[...new Set([...this.unplaced,...n])]}#G(e,t,n=e=>this.boxes.get(e)??{w:260,h:200}){let r=nc,i=i=>{let a=t.find(t=>t.id===i&&(t.id===e||t.position.x||t.position.y)),o=this.nodes.find(e=>e.id===i);return a?{...a.position,...this.infraBoxes.get(i)??r}:o&&{...o.position,...n(i)}},a=this.flows.flatMap(t=>{let n=t.from===e?t.to:t.to===e?t.from:void 0,r=n===void 0?void 0:i(n);return r?[{at:r,before:t.to===e}]:[]}),o=[...this.nodes.map(e=>i(e.id)),...t.filter(t=>t.id!==e).map(e=>i(e.id))],s=e=>o.every(t=>!t||e.x+r.w+16<=t.x||t.x+t.w+16<=e.x||e.y+r.h+16<=t.y||t.y+t.h+16<=e.y),[c]=a;if(!c)return{x:40,y:40};let{at:l,before:u}=c,d=u?[l.x+l.w+80,l.x-r.w-80]:[l.x-r.w-80,l.x+l.w+80],f=[{x:d[0]??0,y:l.y},{x:d[1]??0,y:l.y},{x:l.x,y:l.y+l.h+40},{x:l.x,y:l.y-r.h-40},...Array.from({length:9},(e,t)=>({x:d[0]??0,y:l.y+(t+1)*(r.h+24)}))];return f.find(s)??f[0]??{x:40,y:40}}settle(){let e=e=>e.every(e=>e.measured?.width);if(!this.unplaced.length||!e(this.nodes)||!e(this.infra))return;let t=this.infra;for(let e of this.unplaced)t=this.#W(e,t);this.unplaced=[],this.infra=t}pushed(e,t,n,r){let i=new Set(this.ledBy(e));return r.map(e=>i.has(e.id)&&e.position.y>=t?{...e,position:{x:e.position.x,y:e.position.y+n}}:e)}followed(e,t,n){let r=new Set(this.ownedBy(e));return n.map(e=>r.has(e.id)&&!e.selected&&!e.dragging?{...e,position:{x:e.position.x+t.x,y:e.position.y+t.y}}:e)}hideTunnel(e){let t=this.infra.find(t=>t.id===e),n=new Set(t?.type===`tunnel`?t.data.apps:[]);this.nodes=this.nodes.map(e=>n.has(e.id)?{...e,data:{...e.data,hideTunnels:!0}}:e)}flowNodes(){return[...this.nodes,...this.infra].map(e=>{let t=this.shown(e.position,e.id);return this.#K.set(e.id,t),{...e,position:t}})}#K=new Map;#q={};fromFlow(e,t,n){let r=new Map([...this.nodes,...this.infra].map(e=>[e.id,e])),i=[],a=e.map(e=>{let t=r.get(e.id),n=e.dragging||t?.dragging?{...e,position:e.type===`app`?this.#J(e.id,e.position,i):this.#Y(e.id,e.position,i)}:e;if(t?.dragging&&!n.dragging)return{...n,position:this.dropped(n.id,n.position)};let a=t&&(this.#K.get(t.id)??this.shown(t.position,t.id));return t&&a?.x===n.position.x&&a.y===n.position.y?{...n,position:t.position}:{...n,position:this.stored(n.position,n.id)}}),o=e.every(e=>!e.dragging)?[]:i;o.join()!==this.snapped.join()&&(this.snapped=o);let s=new Map(this.nodes.map(e=>[e.id,e.position])),c={},l=a.filter(e=>e.type!==`app`),u=a.filter(e=>e.type===`app`);for(let{id:e,measured:r}of u){let i=this.#q[e],a=r?.height;a&&(this.#q[e]={brief:t,height:a});let o=n&&i?.brief===t&&a?a-i.height:0;o&&(c[e]={bottom:i?.height??0,by:o});let s=this.boxes.get(e);if(o&&s){let t=e=>!!e&&e.y>=s.y+(i?.height??0)&&e.x<s.x+s.w&&s.x<e.x+e.w;for(let n of u.filter(n=>n.id!==e&&t(this.boxes.get(n.id))))l=this.followed(n.id,{x:0,y:o},l);u=u.map(n=>n.id!==e&&t(this.boxes.get(n.id))?{...n,position:{x:n.position.x,y:n.position.y+o}}:n)}}for(let{id:e,position:t}of u){let n=c[e];n&&(l=this.pushed(e,t.y+n.bottom,n.by,l));let r=s.get(e);r&&(r.x!==t.x||r.y!==t.y)&&(l=this.followed(e,{x:t.x-r.x,y:t.y-r.y},l))}return this.nodes=u,this.infra=l,this.brief&&e.some(e=>e.dragging||r.get(e.id)?.dragging)&&(this.#E=this.#D()),Object.keys(c).length>0}#J(e,t,n){let r=this.boxes.get(e);if(!r)return t;let i=ic/(this.view?.zoom??1),a={...r,x:t.x,y:t.y},o=(e,t,n)=>{let r=this.cables[e];if(!r)return;let i=r[`${t}Side`],a=Ho(n,i),o=this.ends.offset[`${String(e)}|${t}`]??0;return{side:i,at:Lo[i][0]===0?{...a,x:a.x+o}:{...a,y:a.y+o}}},s,c;this.cables.forEach((t,n)=>{let r=t.from===e?`from`:t.to===e?`to`:null;if(!r||t.from===t.to)return;let l=r===`from`?`to`:`from`,u=this.boxes.get(t[l]);if(!u||this.nodes.some(e=>e.id===t[l]&&e.dragging))return;let d=o(n,r,a),f=o(n,l,u);if(!d||!f)return;let p=Lo[d.side][0]!==0,m=p?f.at.y-d.at.y:f.at.x-d.at.x,h={by:m,cable:`${t.from}>${t.to}`};Math.abs(m)>i||(p&&(!c||Math.abs(m)<Math.abs(c.by))&&(c=h),!p&&(!s||Math.abs(m)<Math.abs(s.by))&&(s=h))});let l=new Set(this.ownedBy(e)),u=[...this.links.filter(t=>t.from===e).map(e=>e.to),...this.flows.flatMap(t=>t.from===e?[t.to]:t.to===e?[t.from]:[])].filter(e=>!l.has(e));for(let t of new Set(u)){let n=this.infraBoxes.get(t);if(!n||this.infra.some(e=>e.id===t&&e.dragging))continue;let r=Math.max(n.x-(a.x+a.w),a.x-(n.x+n.w)),o=Math.max(n.y-(a.y+a.h),a.y-(n.y+n.h))>=r,l=o?n.x+n.w/2-(a.x+a.w/2):n.y+n.h/2-(a.y+a.h/2);if(Math.abs(l)>i)continue;let u={by:l,cable:`${e}>${t}`};o&&(!s||Math.abs(l)<Math.abs(s.by))&&(s=u),!o&&(!c||Math.abs(l)<Math.abs(c.by))&&(c=u)}let d=s?.by??0,f=c?.by??0;for(let e of[s,c])e&&n.push(e.cable,e.cable.split(`>`).reverse().join(`>`));return{x:t.x+d,y:t.y+f}}#Y(e,t,n){let r=this.infraBoxes.get(e);if(!r)return t;let i=ic/(this.view?.zoom??1),a={...r,x:t.x,y:t.y},o=[...this.links.filter(t=>t.to===e).map(e=>e.from),...this.flows.flatMap(t=>t.from===e?[t.to]:t.to===e?[t.from]:[])],s,c;for(let e of new Set(o)){let t=this.boxes.get(e)??this.infraBoxes.get(e);if(!t||[...this.nodes,...this.infra].some(t=>t.id===e&&t.dragging))continue;let n=Math.max(t.x-(a.x+a.w),a.x-(t.x+t.w)),r=Math.max(t.y-(a.y+a.h),a.y-(t.y+t.h))>=n,o=r?t.x+t.w/2-(a.x+a.w/2):t.y+t.h/2-(a.y+a.h/2);if(Math.abs(o)>i)continue;let l=r?s:c;l&&Math.abs(l.by)<=Math.abs(o)||(r?s={by:o,partner:e}:c={by:o,partner:e})}for(let t of[s,c])t&&n.push(`${t.partner}>${e}`,`${e}>${t.partner}`);return{x:a.x+(s?.by??0),y:a.y+(c?.by??0)}}#X=M([]);get snapped(){return z(this.#X)}set snapped(e){N(this.#X,e)}#Z=M();get view(){return z(this.#Z)}set view(e){N(this.#Z,e)}#Q=M(!1);get unsaved(){return z(this.#Q)}set unsaved(e){N(this.#Q,e,!0)}#$={};#ee=M(!1);get live(){return z(this.#ee)}set live(e){N(this.#ee,e,!0)}#te=``;#ne={};goLive(){this.live||=(this.commit(),this.#ne=this.saved(),this.#te=this.content(),!0)}goEdit(){this.live&&=(this.setContent(this.#te),!1)}content(){return JSON.stringify({name:this.name,nodes:this.nodes.map(({id:e,type:t,position:n,data:r})=>({id:e,type:t,position:n,data:r})),infra:this.infra.map(({id:e,position:t})=>({id:e,position:t})),queues:this.queues,hiddenQueues:this.hiddenQueues,hiddenOutside:this.hiddenOutside,pinned:this.pinned,edges:this.edges.map(({id:e,source:t,target:n,type:r,data:i})=>({id:e,source:t,target:n,type:r,data:i}))})}setContent(e){let{name:t,nodes:n,edges:r,infra:i,queues:a,hiddenQueues:o,hiddenOutside:s,pinned:c}=JSON.parse(e);this.name=t,this.pinned=c,this.nodes=n,this.edges=r,this.queues=a,this.hiddenQueues=o,this.hiddenOutside=s,this.syncInfra(Object.fromEntries(i.map(({id:e,position:t})=>[e,t]))),this.infra=this.infra.map(e=>({...e,position:i.find(t=>t.id===e.id)?.position??e.position}))}#re=M(null);get name(){return z(this.#re)}set name(e){N(this.#re,e,!0)}#ie=M([]);get own(){return z(this.#ie)}set own(e){N(this.#ie,e)}get team(){return z(this.#A)?.presets??[]}#ae=M(null);get opened(){return z(this.#ae)}set opened(e){N(this.#ae,e,!0)}#oe(){let e=e=>this.app(e);return{known:t=>!!e(t),cloned:t=>!!e(t)?.cloned,name:t=>e(t)?.name??t,canCall:(t,n)=>!e(t)?.outside&&!!e(n)&&!e(n)?.outside&&!!e(n)?.answers,runIn:t=>(e(t)?.runIn??[]).map(([e])=>e),platforms:t=>(e(t)?.platforms??[]).map(([e])=>e),branches:t=>{let n=e(t)?.branches??[];return n.length&&n.length<300?n:null}}}#se(e){return{name:e,version:1,nodes:Object.fromEntries(this.nodes.map(({id:e,data:t})=>[e,{run:t.run,...t.platform&&{platform:t.platform},...t.branch&&{branch:t.branch},...t.note&&{note:t.note},...t.hideTunnels&&{tunnels:!1},...t.showQueues&&this.queuesOf(e).length>0&&{queues:!0},...t.watch&&t.run===`cli`&&{watch:!0}}])),edges:this.edges.map(({source:e,target:t})=>({from:e,to:t})),...this.pinned.length&&{outside:this.pinned}}}#ce(){let e=e=>Object.fromEntries(e.map(({id:e,position:t})=>[e,{x:Math.round(t.x),y:Math.round(t.y)}]));return{nodes:e(this.nodes),infra:e(this.infra),sides:Object.fromEntries(this.edges.map(({id:e,data:t})=>[e,[t.fromSide,t.toSide,null,null,t.fromSlot??null,t.toSlot??null,t.points??null,t.fromShift??null,t.toShift??null]]))}}#le(){let e=e=>{let t={...this.own.find(t=>t.name===e),...this.#se(e),layout:this.#ce()},n=this.own.some(t=>t.name===e)?this.own.map(n=>n.name===e?t:n):[...this.own,t];JSON.stringify(n)!==JSON.stringify(this.own)&&(this.own=n),this.name!==e&&(this.name=e)};if(this.own.some(e=>e.name===this.name)){e(this.name??``);return}if(!this.nodes.length||this.scratch&&this.nodes.length<2)return;this.scratch=!1;let t=this.team.find(e=>e.name===this.name),n=e=>JSON.stringify([e.nodes,e.edges.map(e=>`${e.from}>${e.to}`).sort()]),r=t&&Vs(t,this.#oe()).preset;if(t&&r&&n(this.#se(t.name))===n(r))return;let i=t&&this.own.find(e=>e.name===`${t.name} (local)`||e.name===`${t.name} (mine)`),a=this.nodes[0]?.data.name??`Untitled`,o=this.nodes.length>1?`${a} + ${String(this.nodes.length-1)}`:a;e(i?.name??this.uniqueName(t?`${t.name} (local)`:this.name||o))}uniqueName(e){let t=new Set([...this.team,...this.own].map(e=>e.name)),n=e;for(let r=2;t.has(n);r++)n=`${e} (${String(r)})`;return n}#ue=M([]);get trash(){return z(this.#ue)}set trash(e){N(this.#ue,e)}#de=M([]);get recent(){return z(this.#de)}set recent(e){N(this.#de,e)}rename(e){let t=e.trim().slice(0,80),n=this.name;return this.own.some(e=>e.name===n)?t?t===n?null:[...this.team,...this.own].some(e=>e.name===t)?`A board is already called ${t}. Pick another name.`:(this.own=this.own.map(e=>e.name===n?{...e,name:t}:e),this.name=t,null):`Give the board a name first.`:`Only a board of your own can be renamed.`}duplicate(){if(!this.nodes.length)return;this.#le();let e=this.nodes[0]?.data.name??`Untitled`,t=this.uniqueName(`${this.name??e} copy`);this.own=[...this.own,{...this.#se(t),layout:this.#ce()}],this.name=t}deleteBoard(e){let t=this.own.find(t=>t.name===e);t&&(this.own=this.own.filter(e=>e!==t),this.trash=[{...t,deleted:new Date().toISOString()},...this.trash].slice(0,20),this.name===e&&this.newBoard())}restore(e){let{deleted:t,...n}=e,r={...n,name:this.uniqueName(e.name)};this.trash=this.trash.filter(t=>t!==e),this.own=[...this.own,r],this.nodes.length||this.openBoard(r)}importBoards(e,t){let n=e?.presets,r=(Array.isArray(e)?e:Array.isArray(n)?n:[e]).map(e=>Rs(e)),i=r.flatMap(e=>e.preset?[{...e.preset,name:e.preset.name.trim().slice(0,80),source:t}]:[]),[a]=i;if(!a)return{error:r[0]?.error??`No board found in it.`};let o=Vs(a,this.#oe());if(o.error!==void 0)return{error:o.error};let s=[...new Map(i.map(e=>[e.name,e])).values()];this.own=[...this.own.filter(e=>!s.some(t=>t.name===e.name)),...s];let c=this.openBoard(a);return c.error===void 0?{notes:c.notes,name:a.name}:c}forTeam(e){let{layout:t,outside:n}=e;return{...JSON.parse(this.asShared(e)),...t?{layout:t}:{},...n?{outside:n}:{}}}keptForTeam(e,t){let n=[...z(this.#A)?.presets??[]];n[e]=t,z(this.#A)&&N(this.#A,{...z(this.#A),presets:n})}asShared(e){let{name:t,nodes:n,edges:r}=e;return JSON.stringify({name:t,version:Rs(e).preset?.version??1,nodes:n,edges:r},null,2)}#fe=M([]);get dismissed(){return z(this.#fe)}set dismissed(e){N(this.#fe,e)}#pe=M(!1);get scratch(){return z(this.#pe)}set scratch(e){N(this.#pe,e,!0)}alone(e){let t=[...this.own,...this.team].find(e=>e.name===this.name);return this.newBoard(),this.scratch=!0,this.add(e),this.opened=`fit`,t}newBoard(){this.scratch=!1,this.dismissed=[],this.name=null,this.nodes=[],this.edges=[],this.queues={},this.hiddenQueues={},this.hiddenOutside={},this.pinned=[]}openBoard(e){if(!Object.keys(e.nodes).length)return this.newBoard(),this.name=e.name,{notes:[]};let t=Vs(e,this.#oe());if(t.error!==void 0)return{error:t.error};let{preset:n,notes:r}=t,i=e.layout??{},a=e=>{let{x:t,y:n}=i.nodes?.[e]??{};return typeof t==`number`&&typeof n==`number`&&Number.isFinite(t)&&Number.isFinite(n)?{x:t,y:n}:null},o=Object.keys(n.nodes),s=o.every(a);this.scratch=!1,this.dismissed=[],this.recent=[{name:n.name,at:new Date().toISOString()},...this.recent.filter(e=>e.name!==n.name)].slice(0,20),this.name=n.name,this.queues={},this.hiddenQueues={},this.hiddenOutside={},this.pinned=Array.isArray(e.outside)?e.outside.filter(e=>typeof e==`string`):[],this.infra=this.infra.map(lc),this.nodes=o.flatMap(e=>{let t=this.app(e),r=n.nodes[e];if(!t||!r)return[];let i={...r,hideTunnels:r.tunnels===!1,showQueues:r.queues===!0};return[this.#ve(t,s&&a(e)||{x:0,y:0},i)]});let c=Object.fromEntries(this.nodes.map(({id:e,position:t})=>[e,t])),l=e=>typeof e==`string`&&e in Lo,u=(e,t)=>Number.isInteger(t)?{[e]:t}:{},d=(e,t)=>typeof t==`number`&&Number.isFinite(t)?{[e]:t}:{};return this.edges=n.edges.map(({from:e,to:t})=>{let[n,r,,,a,o,f,p,m]=i.sides?.[`${e}>${t}`]??[];return!s||!l(n)||!l(r)?cc(e,t,Fo(c,{from:e,to:t},`down`,()=>({w:260,h:160}))):cc(e,t,{fromSide:n,toSide:r,...u(`fromSlot`,a),...u(`toSlot`,o),...d(`fromShift`,p),...d(`toShift`,m),...Array.isArray(f)&&{points:f}})}),this.infra=[],this.syncInfra(s?i.infra??{}:{}),this.opened=s?`fit`:`arrange`,{notes:r}}clear(){this.nodes=[],this.edges=[]}#me=M([]);get apps(){return z(this.#me)}set apps(e){N(this.#me,e)}#he=j(()=>new Map(this.apps.map(e=>[e.id,e])));app=e=>z(this.#he).get(e);nameOf=e=>z(this.#he).get(e)?.name??e;#ge=M([]);get envs(){return z(this.#ge)}set envs(e){N(this.#ge,e)}#_e=M([]);get roots(){return z(this.#_e)}set roots(e){N(this.#_e,e)}area=()=>new DOMRect;show=()=>void 0;#ve(e,t,n={}){let{id:r,name:i,kind:a,kindLabel:o,runIn:s,platforms:c}=e,l=s.some(([e])=>e===n.run)?n.run:s[0]?.[0],u=c.some(([e])=>e===n.platform)?n.platform:c[0]?.[0];return{id:r,type:`app`,position:t,data:{name:i,kind:a,kindLabel:o,...n.hideTunnels===!0&&{hideTunnels:!0},...n.showQueues===!0&&{showQueues:!0},...n.watch===!0&&{watch:!0},...(n.changes===`take-along`||n.changes===`set-aside`)&&{changes:n.changes},...Array.isArray(n.libraries)&&{libraries:n.libraries.filter(e=>typeof e==`string`)},branch:n.branch??``,run:l??`cli`,...u&&{platform:u},note:n.note??``}}}async reload(){this.commit(),await Ys(this.saved());let e=await qs();e&&this.open(e)}open({stack:e,clones:t,roots:n,saved:r}){let i=wo(e);N(this.#A,i),N(this.#u,i.envs.filter(e=>As(i,e))),this.stack=i.name??``,this.dir=(i.source??``).replace(/\/stack\.json$/,``),this.setup=!!i.setup,this.known=i.stacks??[],this.envs=i.envs,this.env=r?.env??i.envs[0]??``,this.roots=n,this.apps=Object.entries(i.apps).map(([e,n])=>({id:e,name:n.name,kind:n.kind,kindLabel:hs(n,i).label,slug:n.slug??``,cloned:!!t[e],calls:[...new Set([...Object.keys(n.consumes??{}),...Object.keys(i.found?.[e]??{})])],known:Object.keys(n.consumes??{}),answers:hs(n,i).serves||Object.entries(i.apps).some(([t,n])=>t!==e&&(n.consumes?.[e]??i.found?.[t]?.[e])),serves:!!n.url,runIn:[...hs(n,i).runIn,...n.mock?.length?[[`mock`,`Mock`]]:[]],platforms:hs(n,i).platforms??[],current:t[e]?.branch??``,branches:t[e]?.branches??[],dirty:t[e]?.dirty??0,libraries:(t[e]?.libraries??[]).map(({name:e,path:t})=>({name:e,path:t})),...n.outside&&{outside:typeof n.outside==`string`?n.outside:`an outside system`}})),this.nodes=this.apps.flatMap(e=>{let t=r?.nodes?.[e.id];return t?[this.#ve(e,{x:t.x,y:t.y},t)]:[]}),this.fullHeights=Object.fromEntries(Object.entries(r?.nodes??{}).flatMap(([e,t])=>typeof t?.full==`number`&&t.full>0?[[e,t.full]]:[]));let a=new Set(this.nodes.map(({id:e})=>e));this.edges=(r?.edges??[]).filter(({from:e,to:t})=>a.has(e)&&a.has(t)).map(({from:e,to:t,fromSide:n,toSide:r,...i})=>cc(e,t,{fromSide:n??`right`,toSide:r??`left`,...i})),this.#$=r??{},this.name=typeof r?.preset==`string`?r.preset:null,this.own=Array.isArray(r?.presets)?r.presets:[],this.scratch=r?.scratch===!0,this.dismissed=Array.isArray(r?.dismissed)?r.dismissed:[],this.trash=Array.isArray(r?.trash)?r.trash:[],this.recent=Array.isArray(r?.recent)?r.recent:[],this.infra=[],this.queues=r?.queues??{},this.hiddenQueues=r?.hiddenQueues??{},this.hiddenOutside=r?.hiddenOutside??{},this.pinned=Array.isArray(r?.outside)?r.outside:[],this.syncInfra(r?.infra??{});let{zoom:o,pan:s}=r??{};this.view=o&&s?{x:s.x,y:s.y,zoom:o}:void 0}commit(){!this.live&&!this.nodes.some(e=>e.dragging)&&this.#le()}get changes(){return[z(this.#A),this.live,this.env,this.name,this.scratch,this.view,this.nodes,this.edges,this.infra,this.own,this.trash,this.recent,this.dismissed,this.fullHeights,this.queues,this.hiddenQueues,this.hiddenOutside,this.pinned]}saved(){if(this.live)return{...this.#ne,env:this.env};let e=this.#$.nodes??{};return{mode:`auto`,...this.#$,preset:this.name,presets:this.own,trash:this.trash,recent:this.recent,scratch:this.scratch||void 0,dismissed:this.dismissed.length?this.dismissed:void 0,env:this.env,...this.view&&{zoom:this.view.zoom,pan:{x:this.view.x,y:this.view.y}},nodes:Object.fromEntries(this.nodes.map(({id:t,position:n,data:{branch:r,run:i,platform:a,note:o,hideTunnels:s,showQueues:c,watch:l,changes:u,libraries:d}})=>[t,{...e[t],x:Math.round(n.x),y:Math.round(n.y),branch:r,run:i,...a&&{platform:a},note:o,hideTunnels:s?!0:void 0,showQueues:c?!0:void 0,watch:l?!0:void 0,changes:u,libraries:d?.length?d:void 0,full:this.fullHeights[t]}])),edges:this.edges.map(({source:e,target:t,data:n})=>({from:e,to:t,...n})),queues:this.queues,hiddenQueues:this.hiddenQueues,hiddenOutside:Object.keys(this.hiddenOutside).length?this.hiddenOutside:void 0,outside:this.pinned.length?this.pinned:void 0,infra:Object.fromEntries(this.infra.map(({id:e,position:t})=>[e,{x:Math.round(t.x),y:Math.round(t.y)}]))}}add(e,t){let n=this.app(e);if(!n||n.outside||!n.cloned||this.nodes.some(t=>t.id===e))return;if(t){let e=this.toFlow(t);this.#ye(this.#ve(n,this.stored({x:e.x-sc.w/2,y:e.y-22})));return}let r=this.area(),i=this.toFlow({x:r.left,y:r.top}),a=this.toFlow({x:r.right,y:r.bottom}),o=this.nodes.map(({id:e,position:t})=>this.boxes.get(e)??{...this.shown(t,e),w:sc.w,h:sc.h}),s=(e,t)=>o.every(n=>e+sc.w+sc.gap<=n.x||n.x+n.w+sc.gap<=e||t+sc.h+sc.gap<=n.y||n.y+n.h+sc.gap<=t),c=(e,t,n)=>Array.from({length:Math.max(0,Math.floor((t-n-e-40)/40)+1)},(t,n)=>e+40+n*40),l=(e,t)=>e-t,u=(e,t)=>[...new Set([...e,...t])],d=u(o.map(e=>e.y).sort(l),c(i.y,a.y,sc.h)).filter(e=>e>=i.y&&e+sc.h<=a.y),f=u(o.map(e=>e.x+e.w+sc.gap).sort(l),c(i.x,a.x,sc.w)).filter(e=>e>=i.x&&e+sc.w<=a.x),p;for(let e of d)if(p=f.filter(t=>s(t,e)).map(t=>({x:t,y:e}))[0],p)break;let m=this.nodes.length*32;this.#ye(this.#ve(n,this.stored(p??{x:i.x+48+m,y:i.y+48+m})))}selectAll(){let e=e=>e.selected?e:{...e,selected:!0};this.nodes=this.nodes.map(e),this.infra=this.infra.map(e),this.edges=this.edges.map(lc)}pick(e){let t=t=>!!t.selected==(t.id===e)?t:{...t,selected:t.id===e};this.infra=this.infra.map(t),this.edges=this.edges.map(lc),this.nodes=this.nodes.map(t)}#ye(e){this.infra=this.infra.map(lc),this.edges=this.edges.map(lc),this.nodes=[...this.nodes.map(lc),{...e,selected:!0}]}showOutside(e,t){let{[e]:n,...r}=this.hiddenOutside;this.hiddenOutside=t?r:{...r,[e]:!0},t?this.pin(e):this.unpin(e),this.syncInfra()}set(e,t){this.nodes=this.nodes.map(n=>n.id===e?{...n,data:{...n.data,...t}}:n)}cablesOf(e){let t=e=>this.app(e),n=this.cards.flatMap(n=>n.id===e?[]:t(n.id)??[]),r=n.filter(t=>this.edges.some(n=>n.id===`${e}>${t.id}`)),i=n.filter(e=>!r.includes(e)),a=i.filter(n=>t(e)?.calls.includes(n.id)),o=i.filter(t=>!t.outside&&t.answers&&!t.calls.includes(e));return{can:a.length?a:o,wired:r}}uncabled(e){return this.cards.length>1&&!this.edges.some(t=>t.source===e||t.target===e)}connect(e,t){let n=cc(e,t,Fo(Object.fromEntries(this.nodes.map(({id:e,position:t})=>[e,t])),{from:e,to:t},`down`,e=>this.boxes.get(e)??{w:260,h:160}));this.edges=[...this.edges.filter(e=>e.id!==n.id),n]}cut(e,t){this.edges=this.edges.filter(n=>n.id!==`${e}>${t}`)}remove(e){this.nodes=this.nodes.filter(t=>t.id!==e),this.edges=this.edges.filter(t=>t.source!==e&&t.target!==e)}edit(e,t,n=!1){if(this.name!==e){let r=this.own.find(t=>t.name===e)??this.team.find(t=>t.name===e)??(n?{name:e,version:1,nodes:{},edges:[]}:void 0);if(!r)return!1;let i={...Ws(r,t),name:e};if(JSON.stringify(i)===JSON.stringify(r))return!1;let a=this.own.some(t=>t.name===e);return this.own=a?this.own.map(t=>t.name===e?i:t):[...this.own,i],!0}let r=this.content(),i=e=>this.cards.some(t=>t.id===e);for(let e of t.remove??[])this.remove(e);for(let e of t.add??[])this.add(e);for(let[e,n]of Object.entries(t.branch??{}))this.set(e,{branch:n});for(let[e,n]of Object.entries(t.note??{}))this.set(e,{note:n});for(let{from:e,to:n}of t.uncable??[])this.cut(e,n);for(let{from:e,to:n}of t.cable??[])i(e)&&i(n)&&!this.edges.some(t=>t.id===`${e}>${n}`)&&this.connect(e,n);return t.arrange&&(this.opened=`arrange`),this.content()!==r||!!t.arrange}#be={key:``,version:0};arrange(e=e=>this.boxes.get(e)??{w:260,h:160}){let t=()=>JSON.stringify(this.nodes.map(({id:e,position:t})=>[e,t.x,t.y])),n=t(),r=n===this.#be.key?this.#be.version+1:0;for(let i=0;i<ec.length;i++,r++){let[i,a]=ec[r%ec.length]??ec[0];if(this.#xe(e,i,a),t()!==n)break}this.#be={key:t(),version:r}}#xe(e,t,n){let r=this.cables.map(({from:e,to:t})=>({from:e,to:t})),i=e=>t===`down`&&r.some(t=>t.from===e)?`right`:`bottom`,a=n=>{let i=this.ledBy(n).filter(e=>this.ownedBy(n).includes(e)).map(e=>this.infraBoxes.get(e)??nc),{w:a,h:o}=e(n);if(!i.length)return{w:a,h:o};let s=i.reduce((e,t)=>e+t.h+nc.gap/2,0),c=Math.max(...i.map(e=>e.w));return t===`down`&&r.some(e=>e.from===n)?{w:a+nc.gap+c,h:Math.max(o,s)}:{w:Math.max(a,c),h:o+s}},o=new Map(this.nodes.flatMap(e=>this.ownedBy(e.id).map(t=>[t,e.id]))),s=this.infra.filter(e=>e.type!==`tunnel`&&!o.has(e.id)).map(e=>e.id),c=e=>s.includes(e)||this.cards.some(t=>t.id===e),l=e=>o.get(e)??e,u=this.flows.map(({from:e,to:t})=>({from:l(e),to:l(t)})).filter(({from:e,to:t})=>e!==t&&c(e)&&c(t)),d=Po([...this.nodes.map(e=>e.id),...s],[...r,...u],e=>s.includes(e)?this.infraBoxes.get(e)??{w:220,h:70}:a(e),t,n,{pad:ac,anchor:n=>s.includes(n)?void 0:t===`down`?e(n).w/2:oc/2}),f=Object.fromEntries(this.nodes.filter(e=>this.ownedBy(e.id).length).map(e=>[e.id,i(e.id)])),p=r.map(n=>({...n,...Fo(d,n,t,e,f)}));Zo(p,t=>({...d[t]??{x:0,y:0},...e(t)})),this.nodes=this.nodes.map(e=>({...e,position:d[e.id]??e.position})),this.edges=p.map(({from:e,to:t,...n})=>cc(e,t,n));let m=this.infra.map(e=>{let t=d[e.id];return t?{...e,position:t}:e});for(let t of this.nodes)m=this.#W(t.id,m,e(t.id),!0,f[t.id]);this.infra=m}},uc={waiting:`Waiting`,building:`Building`,running:`Running`,unhealthy:`Unhealthy`,exited:`Exited`,"failed-to-start":`Failed to start`,"secret-missing":`Secret missing`},dc={waiting:e=>e||`Waiting.`,building:e=>`Building. ${e}`,running:()=>``,unhealthy:e=>`Unhealthy: ${e}`,exited:e=>`Exited. ${e}`,"failed-to-start":e=>`Failed to start: ${e}`,"secret-missing":e=>`Secret missing: ${e}. Set it under Credentials.`},Q=new class{#e=M(null);get status(){return z(this.#e)}set status(e){N(this.#e,e)}#t=M(!1);get asked(){return z(this.#t)}set asked(e){N(this.#t,e,!0)}#n;#r=``;watch(){let e=!1,t=async()=>{if(!(document.hidden||e)){e=!0;try{let e=await fetch(`data/status.json`),t=e.ok?await e.text():this.#r;t!==this.#r&&(this.#r=t,this.status=JSON.parse(t))}catch{}e=!1,this.asked||requestAnimationFrame(()=>requestAnimationFrame(()=>this.asked=!0))}};t(),clearInterval(this.#n),this.#n=setInterval(()=>void t(),1500)}sent(e){let{live:t,progress:n}=this.status??{},r=!t?.env||t.env===Z.env;return!!t?.nodes?.[e]&&r||!!n?.apps?.includes(e)&&n.env===Z.env}#i(e){return this.sent(e)?this.status?.apps?.[e]:void 0}up(e){let t=this.#i(e);return t?t.running?t.running.length>0:t.listening??null:null}state(e){let t=this.#i(e);if(t?.state)return t.state;if(!this.sent(e)||this.up(e))return null;let n=(this.status?.secrets?.[e]?.[Z.env]??[]).filter(e=>!e.stored).map(e=>e.name);return n.length?{state:`secret-missing`,detail:n.join(`, `)}:null}stateSaid(e){let t=this.state(e);return t?dc[t.state](t.detail).trim():``}about(e){let t=this.#i(e);if(t?.running)return this.where(e);if(t?.listening===void 0)return``;let n=String(t.port??``);return t.listening?`Running on port ${n}`:`Nothing is listening on port ${n}`}where(e){let t=this.#i(e);if(!t?.running){let n=this.status?.apps?.[e],r=n?.running?n.running.length>0:n?.listening===!0,i=(this.status?.live?.env??``).toUpperCase();return!t&&r&&this.status?.live?.nodes?.[e]?`Running for your ${i} board, not this one. Run switches it.`:``}let[n]=t.running;if(!n)return`Not running on a simulator or device`;let r={ios:`iOS simulator`,android:`Android`}[n.platform]??n.platform,i=n.source?`, started from ${n.source===`ide`?`your IDE`:`Koppler`}`:``,a=t.running.length>1?`, and ${String(t.running.length-1)} more`:``;return`Running on ${n.device} (${r})${n.flavor?`, ${n.flavor}`:``}${i}${a}`}steps(e){let t=this.#i(e)?.steps??[],n=this.up(e);return n===!0?t.map(e=>(e.label===`Start`||e.label===`Check`)&&(e.state===`user`||e.state===`todo`)?{label:e.label,state:`done`,detail:`Running.`}:e):n===!1?t.map(e=>e.label===`Check`&&e.state===`done`?{...e,state:`todo`,detail:`Not running right now.`}:e):t}hasLog(e){return!!this.status?.apps?.[e]?.logTail}tail(e){return this.status?.apps?.[e]?.logTail??``}tunnel(e,t){return t.some(e=>this.sent(e))?this.status?.ports?.[e]:void 0}};function fc(e){let t=t=>e.find(e=>e.state===t),[n,r,i]=[t(`failed`),t(`user`),t(`todo`)];return n?[`failed`,`Failed: ${n.label}`]:r?[`user`,`Waiting on you: ${r.label}`]:i?[`todo`,`Next: ${i.label}`]:[`done`,`All steps done`]}var pc=(e,t)=>Js(e,t,!0),mc=e=>{if(e.matches(`.svelte-flow__pane`))return`the empty board`;let t=e.matches(`input[type="radio"], input[type="checkbox"]`)&&e.closest(`label`)||e.closest(`button, a, [role="button"], [role="option"], [role="radio"], [role="menuitem"], label, input, select, summary, .svelte-flow__node, .svelte-flow__edge`)||e,n=t instanceof HTMLInputElement||t instanceof HTMLSelectElement?t.labels?.[0]:null,r=(t.getAttribute(`aria-label`)??t.getAttribute(`title`)??(n??t).textContent).replace(/\s+/g,` `).trim().slice(0,80),i=t.closest(`.svelte-flow__node, .svelte-flow__edge`)?.getAttribute(`data-id`)??``;return`${t.tagName.toLowerCase()}${r?` "${r}"`:``}${i?` in ${i}`:``}`},hc=e=>!!e.closest(`[type="password"], [data-secret]`),gc=new class{#e=M(!1);#t=[];#n;get forced(){return!!Q.status?.dev}get on(){return z(this.#e)||this.forced}set on(e){N(this.#e,e,!0);try{localStorage.setItem(`koppler-debug`,e?`on`:`off`)}catch{}e&&this.note(`debug`,`Debug log on`)}note(e,t,n){if(!this.on)return;let r={apps:Z.nodes.length,cables:Z.edges.length,view:Z.live?`live`:`edit`,env:Z.env,zoom:Math.round((Z.view?.zoom??1)*100)/100};this.#t.push({at:new Date().toISOString(),kind:e,what:t,...n&&{detail:n.slice(0,300)},board:r}),clearTimeout(this.#n),this.#n=setTimeout(()=>{this.flush()},1500)}flush(){let e=this.#t.splice(0);e.length&&pc(`debug-log`,{entries:e})}async read(){return this.flush(),await new Promise(e=>setTimeout(e,300)),(await fetch(`temp/debug.jsonl?${String(Date.now())}`).then(e=>e.ok?e.text():``).catch(()=>``)).trim().split(`
3
+ `).toLowerCase(),as=(e,t)=>t?` ${e}${String(t)}`:``,os=e=>is(e,[`pyproject.toml`,`requirements.txt`,`Pipfile`]);function ss(e){return e.has(`uv.lock`)?`uv run `:e.has(`poetry.lock`)?`poetry run `:e.has(`Pipfile`)?`pipenv run `:e.has(`.venv/bin/python`)?`.venv/bin/`:``}var cs=e=>/spring-boot|springframework\.boot/.test(is(e,[`pom.xml`,`build.gradle`,`build.gradle.kts`])),ls=e=>[`compose.yaml`,`compose.yml`,`docker-compose.yml`,`docker-compose.yaml`].find(t=>e.has(t)),us={reactnative:{label:`React Native`,color:[`#087EA4`,`#58C4DC`],serves:!1,platforms:[[`ios`,`iOS simulator`],[`android`,`Android emulator`]],detect:e=>/"(expo|react-native)"\s*:/.test(rs(e,`package.json`)),start:(e,{platform:t=`ios`})=>/"expo"\s*:/.test(rs(e,`package.json`))?`npx expo start --${t}`:`npx react-native run-${t}`},go:{label:`Go`,color:[`#00758D`,`#5AD1E6`],detect:e=>e.has(`go.mod`),start:e=>{if(e.has(`main.go`))return`go run .`;let t=e.list(`cmd`);return t.length===1?`go run ./cmd/${t[0]??``}`:null}},rust:{label:`Rust`,color:[`#A0522D`,`#E8A27C`],detect:e=>e.has(`Cargo.toml`),start:()=>`cargo run`},java:{label:`Java / Kotlin`,color:[`#B0562B`,`#F0975F`],detect:e=>e.has(`pom.xml`)||e.has(`build.gradle`)||e.has(`build.gradle.kts`),port:e=>cs(e)?8080:null,start:e=>e.has(`pom.xml`)?cs(e)?`${e.has(`mvnw`)?`./mvnw`:`mvn`} spring-boot:run`:null:`${e.has(`gradlew`)?`./gradlew`:`gradle`} ${cs(e)?`bootRun`:`run`}`},python:{label:`Python`,color:[`#2F6F9F`,`#7FB8E6`],detect:e=>[`manage.py`,`pyproject.toml`,`requirements.txt`,`Pipfile`].some(t=>e.has(t)),port:e=>{let t=os(e);return e.has(`manage.py`)||/fastapi|uvicorn/.test(t)?8e3:t.includes(`flask`)?5e3:null},start:(e,{port:t})=>{let n=ss(e),r=os(e);if(e.has(`manage.py`))return`${n}python manage.py runserver${as(``,t)}`;if(/fastapi|uvicorn/.test(r)){let r=[`main.py`,`app/main.py`,`src/main.py`].find(t=>e.has(t))?.replace(/\.py$/,``).replace(/\//g,`.`);return r?`${n}uvicorn ${r}:app --reload${as(`--port `,t)}`:null}return r.includes(`flask`)?`${n}flask run${as(`--port `,t)}`:null}},ruby:{label:`Ruby`,color:[`#B3261E`,`#F28B82`],detect:e=>e.has(`Gemfile`),port:e=>e.has(`config/application.rb`)?3e3:null,start:(e,{port:t})=>e.has(`config/application.rb`)?`bin/rails server${as(`-p `,t)}`:null},php:{label:`PHP`,color:[`#6C5FC7`,`#A99FF5`],detect:e=>e.has(`artisan`)||e.has(`composer.json`),port:e=>e.has(`artisan`)?8e3:null,start:(e,{port:t})=>e.has(`artisan`)?`php artisan serve${as(`--port=`,t)}`:null},compose:{label:`Docker Compose`,color:[`#1D63ED`,`#7AA7FF`],detect:e=>!!ls(e),port:e=>Number(/["'\s-](\d{2,5}):\d{2,5}["'\s]/.exec(rs(e,ls(e)??``))?.[1])||null,start:()=>`docker compose up`,stop:`docker compose down`}};for(let[e,t]of Object.entries(us))ns[e]={label:t.label,runIn:$o,serves:t.serves!==!1,...t.platforms&&{platforms:t.platforms},...t.color&&{color:t.color}};Object.keys(ns);var ds={kinds:ns,recipes:us,custom:[]},fs=new WeakMap;function ps(e){let t=e?.kinds;if(typeof t!=`object`||!t)return ds;let n=fs.get(t);if(n)return n;let r={kinds:{...ns},recipes:{...us},custom:[]};for(let[e,n]of Object.entries(t)){if(!/^[a-z0-9-]{1,32}$/.test(e)||Object.hasOwn(ns,e)||typeof n!=`object`||!n)continue;let t=n,i=[t.detect??[]].flat().filter(e=>typeof e==`string`),a=typeof t.label==`string`&&t.label?t.label:e;r.recipes[e]={label:a,detect:e=>i.length>0&&i.every(t=>e.has(t)),port:()=>Number(t.port)||null,start:()=>typeof t.start==`string`&&t.start?t.start:null},r.kinds[e]={label:a,runIn:$o,serves:t.serves!==!1,custom:!0},r.custom.push(e)}return fs.set(t,r),r}var ms=e=>ps(e).kinds;function hs(e,t){let n=e?.kind,r=ms(t);return n!==void 0&&Object.hasOwn(r,n)&&r[n]||{label:n??`App`,runIn:$o,serves:!0}}var gs=e=>typeof e==`string`?e:``,_s=e=>({branch:e?.branch||``,run:e?.run||`cli`,...e?.platform&&{platform:e.platform},...gs(e?.note)&&{note:gs(e?.note)},...e?.tunnels===!1&&{tunnels:!1},...e?.queues===!0&&{queues:!0},...gs(e?.changes)&&{changes:gs(e?.changes)},...Array.isArray(e?.libraries)&&e.libraries.length>0&&{libraries:e.libraries.map(String).sort()},...e?.restart===!0&&{restart:!0},...e?.watch===!0&&{watch:!0}}),vs=e=>e?.run===`mock`?{branch:``,run:`mock`,...e.restart===!0&&{restart:!0}}:_s(e);function ys(e){let t=e?.nodes??{},n=Array.isArray(t)?t.map(e=>[e.id,e]):Object.entries(t),r=Object.fromEntries(n.filter(([e])=>typeof e==`string`).map(([e,t])=>[e,vs(t)])),i=(Array.isArray(e?.edges)?e.edges:[]).filter(e=>!!e&&Object.hasOwn(r,e.from)&&Object.hasOwn(r,e.to)).map(e=>({from:e.from,to:e.to})),a=Object.fromEntries(Object.entries(e?.queues??{}).flatMap(([e,t])=>t===`local`?[[e,`local`]]:[]));return{env:e?.env??null,nodes:r,edges:i,queues:a}}var bs=(e,t)=>e.edges.filter(e=>e.from===t).map(e=>e.to).sort(),xs=e=>e.toUpperCase(),Ss=e=>({ide:`your IDE`,cli:`the command line`,mock:`a mock`})[e];function Cs(e,t,n,r,i){let a=t.nodes[e],o=n.nodes[e];if(!a||!o)return[];let s=e=>i.name?.(e)??e,c=[];o.restart&&c.push(`you asked to restart it`),r&&c.push(`the environment changes from ${xs(r.from)} to ${xs(r.to)}`),a.branch!==o.branch&&a.run!==`mock`&&o.run!==`mock`&&c.push(`its branch changes from ${a.branch||i.current?.(e)||`the current one`} to ${o.branch||`the current one`}`),a.run!==o.run&&c.push(`it moves from ${Ss(a.run)} to ${Ss(o.run)}`),(a.platform??``)!==(o.platform??``)&&o.run===`cli`&&c.push(`its device changes to ${String(o.platform)}`);let l=bs(t,e),u=bs(n,e);for(let e of u.filter(e=>!l.includes(e)))c.push(`it starts calling your local ${s(e)}`);for(let e of l.filter(e=>!u.includes(e)))c.push(`it goes back to the deployed ${s(e)}`);(a.note??``)!==(o.note??``)&&c.push(`its note changed`);let d=a.libraries??[],f=o.libraries??[];for(let e of f.filter(e=>!d.includes(e)))c.push(`it uses your local ${e}`);for(let e of d.filter(e=>!f.includes(e)))c.push(`it goes back to the published ${e}`);let p=(e,t,n)=>t.queues===!0&&Object.hasOwn(e.queues,n);for(let r of i.queuesOf?.(e)??[])p(t,a,r)!==p(n,o,r)&&c.push(`it moves to the ${p(n,o,r)?`local`:`deployed`} ${r} queue`);return c}function ws(e,t,n={}){let r=ys(e),i=ys(t),a=n.strays??[],o=r.env&&i.env&&r.env!==i.env&&Object.keys(r.nodes).length>0?{from:r.env,to:i.env}:null,s=[],c=[],l=[],u=[];for(let[e,t]of Object.entries(i.nodes))if(!Object.hasOwn(r.nodes,e)){let r=n.startedOn?.(e)===i.env&&bs(i,e).length===0&&!t.note&&!t.branch;a.includes(e)?r?u.push({id:e,why:[`you started it with koppler run`]}):c.push({id:e,why:[`it is running, but not from a run Koppler recorded`]}):s.push({id:e,why:[]})}else if(n.running?.(e)===!1&&t.run!==`ide`)s.push({id:e,why:[`it was started before but is not running now`]});else{let t=Cs(e,r,i,o,n);(t.length>0?c:u).push({id:e,why:t})}for(let e of[...Object.keys(r.nodes),...a])!Object.hasOwn(i.nodes,e)&&!l.some(t=>t.id===e)&&l.push({id:e,why:[]});let d=s.length+c.length+l.length===0;return{env:i.env,envChange:o,starts:s,restarts:c,stops:l,keeps:u,nothing:d}}var Ts=[[`starts`,`START`],[`restarts`,`RESTART`],[`stops`,`STOP AND REVERT`],[`keeps`,`KEEP RUNNING`]];function Es(e,t={}){let n=e=>t.name?.(e)??e,r=e=>n(e.id)+(e.why.length>0?` (${e.why.join(`; `)})`:``),i=Ts.filter(([t])=>e[t].length>0).map(([t,n])=>`${n}: ${e[t].map(r).join(`, `)}`);return i.length>0?i:[`NOTHING TO CHANGE`]}var Ds=[`sqs`,`kafka`];function Os(e,t){let n=e?.apps?.[t];return[...new Set([...Object.keys(n?.publishes??{}),...Object.keys(n?.reads??{})])]}function ks(e){let t=e?.envs??[],n=e?.protected;return Array.isArray(n)?t.filter(e=>n.includes(e)):t.slice(1)}var As=(e,t)=>ks(e).includes(t),js=[[`valkey`,`Cache (Valkey)`],[`redis`,`Cache (Redis)`],[`aurora`,`Database (Aurora)`],[`postgres`,`Database (Postgres)`],[`mysql`,`Database (MySQL)`],[`mongo`,`Database (MongoDB)`],[`db`,`Database`],[`rds`,`Database`]];function Ms(e){if(e.what)return e.what;let t=(e.tunnel??``).toLowerCase(),n=t.split(/[.-]/);return js.find(([e])=>n.includes(e)||e.length>3&&t.includes(e))?.[1]??`Tunnel`}function Ns(e){let t=new Map;for(let n of e){let e=`${n.tunnel}:${String(n.port)}`,r=t.get(e)??{host:n.tunnel,port:n.port,original:n.port,bind:`localhost`,apps:[],envs:{},what:Ms(n),connectsAs:n.connectsAs};r.apps.includes(n.app)||r.apps.push(n.app),n.env&&(r.envs[n.app]=n.env),t.set(e,r)}return[...t.values()]}function Ps(e,t=[]){let n=Ns(e),r=new Set([...t,...n.map(e=>e.port)]),i=e=>e.apps.every(t=>e.envs[t]),a=2;for(let e of new Set(n.map(e=>e.original))){let t=n.filter(t=>t.original===e);t.sort((e,t)=>Number(i(e))-Number(i(t)));for(let n of t.slice(1))if(i(n)){let t=e+2;for(;r.has(t);)t++;r.add(t),n.port=t,n.settings=n.apps.map(e=>({app:e,env:n.envs[e]??``,value:`localhost:${String(t)}`}))}else n.bind=`127.0.0.${String(a++)}`,n.needsAlias=!0}return n}function Fs(e,t=e=>e){let n=e=>e.what===`Tunnel`?`tunnel`:`${e.what.replace(/ \(.*\)$/,``).toLowerCase()} tunnel`,r=e=>`${e.apps.map(t).join(` and `)}'s ${n(e)}`;return e.flatMap(i=>{let a=e.filter(e=>e!==i&&e.original===i.original).map(r).join(` and `),o=String(i.port);return i.settings?[`${r(i)} moves from port ${String(i.original)} to ${o}, to make room for ${a}.`]:i.needsAlias?[`${r(i)} keeps port ${o} on its own address, ${i.bind}, next to ${a}. Needs a one-time sudo step.`]:i.apps.length>1?[`${i.apps.map(t).join(` and `)} share one ${n(i)} on port ${o}.`]:[]})}var Is=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Ls={0:e=>({...e,nodes:Object.fromEntries(Object.entries(e.nodes).map(([e,t])=>[e,{run:`cli`,...t}]))})};function Rs(e){if(!Is(e))return{error:`It is not a preset.`};let{name:t,nodes:n,edges:r,version:i}=e;if(typeof t!=`string`||!t.trim())return{error:`It has no name.`};if(!Is(n)||Object.keys(n).length===0)return{error:`It has no apps.`};let a=typeof i==`number`&&Number.isInteger(i)&&i>=0?i:0;if(a>1)return{error:`It was saved by a newer Koppler (${`preset format ${String(a)}, this one reads up to 1`}). Update Koppler.`};let o={...e,name:t,nodes:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,Is(t)?t:{}])),edges:Array.isArray(r)?r:[]};for(let e=a;e<1;e++)o={...Ls[e]?.(o)??o,version:e+1};return{preset:o,migratedFrom:a<1?a:null}}function zs(e,t,n,r,i){let a=n.runIn(e),o=n.platforms(e),s=typeof t.run==`string`?t.run:``,c=a.includes(s)?s:a.includes(`cli`)?`cli`:a[0]??`cli`;s&&c!==s&&i.push(`${r} cannot run in "${s}", using ${c}`);let l={run:c},u=typeof t.platform==`string`?t.platform:``,d=o[0];d!==void 0&&c===`cli`&&(l.platform=o.includes(u)?u:d,u&&l.platform!==u&&i.push(`${r} has no "${u}" platform, using ${l.platform}`));let f=typeof t.branch==`string`?t.branch.trim():``;if(f){l.branch=f;let t=n.branches(e);t&&!t.includes(f)&&i.push(`${r} has no branch ${f} in your clone (fetch it first)`)}return typeof t.note==`string`&&t.note.trim()&&(l.note=t.note),t.tunnels===!1&&(l.tunnels=!1),t.queues===!0&&(l.queues=!0),t.watch===!0&&(l.watch=!0),l}var Bs=e=>Is(e)&&typeof e.from==`string`&&typeof e.to==`string`;function Vs(e,t){let n=Rs(e);if(n.error!==void 0)return{error:n.error};let r=n.preset,i=[],a=e=>t.name?.(e)??e;(!Is(e)||!Number.isInteger(e.version))&&i.push(`it had no version, read as the oldest format`);let o=Object.keys(r.nodes),s=o.filter(e=>!t.known(e)),c=o.filter(e=>t.known(e)&&!t.cloned(e)),l=o.filter(e=>t.known(e)&&t.cloned(e));if(l.length===0)return{error:s.length===o.length?`None of its apps are in this stack (${s.join(`, `)}).`:`None of its apps are cloned here (${c.join(`, `)}).`};s.length>0&&i.push(`not in this stack: ${s.join(`, `)}`),c.length>0&&i.push(`not cloned: ${c.map(a).join(`, `)}`);let u=Object.fromEntries(l.map(e=>[e,zs(e,r.nodes[e]??{},t,a(e),i)])),d=[],f=0;for(let e of r.edges.filter(Bs)){let{from:n,to:r}=e;!Object.hasOwn(u,n)||!Object.hasOwn(u,r)?t.known(n)&&t.known(r)&&f++:d.some(e=>e.from===n&&e.to===r)||(t.canCall(n,r)?d.push({from:n,to:r}):i.push(`${a(n)} does not call ${a(r)}, cable left out`))}f>0&&i.push(`${String(f)} ${f===1?`cable`:`cables`} left out with their apps`),n.migratedFrom!==null&&n.migratedFrom>0&&i.push(`updated from preset format ${String(n.migratedFrom)}`);let p={name:r.name.trim().slice(0,80),version:1,nodes:u,edges:d};return r.source&&(p.source=r.source),{preset:p,notes:i}}var Hs=e=>Is(e)&&typeof e.x==`number`&&typeof e.y==`number`,Us=e=>t=>e.from===t.from&&e.to===t.to;function Ws(e,t){let n=new Set(t.remove??[]),r=e=>Object.fromEntries(Object.entries(e).filter(([e])=>!n.has(e))),i=r(e.nodes),a=Is(e.layout)?e.layout:void 0,o=r(Is(a?.nodes)?a.nodes:{}),s=Object.values(o).filter(Hs),c=Math.min(...s.map(e=>e.y));for(let e of t.add??[])i[e]||(i[e]={run:`cli`},s.length&&(o[e]={x:Math.max(...s.map(e=>e.x))+340,y:c},c+=240));for(let[e,n]of Object.entries(t.branch??{}))i[e]&&(i[e]={...i[e],branch:n});for(let[e,n]of Object.entries(t.note??{})){let{note:t,...r}=i[e]??{};i[e]&&(i[e]=n.trim()?{...r,note:n}:r)}let l=e.edges.filter(Bs).filter(e=>!n.has(e.from)&&!n.has(e.to)&&!(t.uncable??[]).some(Us(e)));for(let e of t.cable??[])l.some(Us(e))||l.push({from:e.from,to:e.to});if(!a||t.arrange){let{layout:t,...n}=e;return{...n,nodes:i,edges:l}}let u=new Set(l.map(e=>`${e.from}>${e.to}`)),d=Object.fromEntries(Object.entries(Is(a.sides)?a.sides:{}).filter(([e])=>u.has(e)));return{...e,nodes:i,edges:l,layout:{...a,nodes:o,sides:d}}}function Gs(e,t=e=>e,n=!1){let r=(e=[])=>e.map(t).join(`, `),i=(e=[])=>e.map(e=>`${t(e.from)} to ${t(e.to)}`).join(`, `);return[e.add?.length&&`${n?`add`:`added`} ${r(e.add)}`,e.remove?.length&&`${n?`remove`:`removed`} ${r(e.remove)}`,e.cable?.length&&`${n?`cable`:`cabled`} ${i(e.cable)}`,e.uncable?.length&&`${n?`take the cable off`:`took the cable off`} ${i(e.uncable)}`,...Object.entries(e.branch??{}).map(([e,r])=>`${n?`put `:``}${t(e)} on ${r}`),...Object.entries(e.note??{}).map(([e,r])=>r.trim()?`${n?`add `:``}a note on ${t(e)}`:`${n?`take the `:`no `}note${n?` off `:` on `}${t(e)}`),e.arrange&&(n?`lay it out afresh`:`arranged`)].filter(Boolean).join(`; `)}async function Ks(e){try{let t=await fetch(`data/${e}.json`);return t.ok?await t.json():null}catch{return null}}async function qs(){let[e,t,n]=await Promise.all([Ks(`registry`),Ks(`local`),Ks(`state`)]);return e?{stack:e,clones:t?.apps??{},roots:t?.roots??[],saved:n}:null}async function Js(e,t={},n=!1){let r=location.pathname.split(`/`)[2]??``;try{return await fetch(`/${e}?token=${encodeURIComponent(r)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t),keepalive:n})}catch{return null}}var Ys=async(e,t=!1)=>!!(await Js(`state`,e,t))?.ok;async function Xs(e,t={}){let n=await Js(e,t);return n?await n.json().catch(()=>({error:`The canvas server answered ${String(n.status)}.`})):{error:`Could not reach the canvas server.`}}var Zs=()=>Ks(`repos`),Qs={cli:`Koppler`,ide:`Me`,mock:`Mock`},$s=.6,ec=[[`down`,!1],[`right`,!1],[`down`,!0],[`right`,!0]],tc=e=>`tunnel:${e.host}:${String(e.original)}`,nc={w:230,h:58,gap:40},rc=[`bottom`,`right`,`left`,`top`],ic=8,ac=24,oc=44,sc={w:300,h:240,gap:32},cc=(e,t,n)=>({id:`${e}>${t}`,source:e,target:t,type:`cable`,data:n}),lc=e=>e.selected?{...e,selected:!1}:e,Z=new class{#e=M(``);get stack(){return z(this.#e)}set stack(e){N(this.#e,e,!0)}#t=M(``);get dir(){return z(this.#t)}set dir(e){N(this.#t,e,!0)}#n=M(!1);get setup(){return z(this.#n)}set setup(e){N(this.#n,e,!0)}#r=M([]);get known(){return z(this.#r)}set known(e){N(this.#r,e)}#i=M(``);get env(){return z(this.#i)}set env(e){N(this.#i,e,!0)}#a=M([]);get nodes(){return z(this.#a)}set nodes(e){N(this.#a,e)}#o=[];#s=j(()=>{let e=this.nodes;return e.length===this.#o.length&&e.every((e,t)=>e.id===this.#o[t]?.id&&e.data===this.#o[t].data)||(this.#o=e),this.#o});get cards(){return z(this.#s)}set cards(e){N(this.#s,e)}#c=M([]);get edges(){return z(this.#c)}set edges(e){N(this.#c,e)}#l=M(null);get hovered(){return z(this.#l)}set hovered(e){N(this.#l,e)}#u=M([]);#d=j(()=>z(this.#u).includes(this.env));get protected(){return z(this.#d)}set protected(e){N(this.#d,e)}toFlow=e=>e;zoom=()=>1;#f=j(()=>this.edges.map(e=>({from:e.source,to:e.target,...e.data})));get cables(){return z(this.#f)}set cables(e){N(this.#f,e)}#p=M([]);get infra(){return z(this.#p)}set infra(e){N(this.#p,e)}#m=M({});get queues(){return z(this.#m)}set queues(e){N(this.#m,e)}#h=M({});get hiddenQueues(){return z(this.#h)}set hiddenQueues(e){N(this.#h,e)}#g=M({});get hiddenOutside(){return z(this.#g)}set hiddenOutside(e){N(this.#g,e)}#_=M([]);get pinned(){return z(this.#_)}set pinned(e){N(this.#_,e)}pin(e){this.pinned.includes(e)||(this.pinned=[...this.pinned,e])}unpin(e){this.pinned=this.pinned.filter(t=>t!==e)}#v=j(()=>new Map(this.infra.map(({id:e,position:t,measured:n})=>[e,{...this.shown(t,e),w:n?.width??nc.w,h:n?.height??nc.h}])));get infraBoxes(){return z(this.#v)}set infraBoxes(e){N(this.#v,e)}#y=M(!1);get present(){return z(this.#y)}set present(e){N(this.#y,e,!0)}entering=!1;#b=M(!1);get brief(){return z(this.#b)}set brief(e){N(this.#b,e,!0)}#x=j(()=>{if(!this.brief||this.live||this.present)return;let e=this.nodes.filter(e=>e.selected);return e.length===1?e[0]:void 0});get panelCard(){return z(this.#x)}set panelCard(e){N(this.#x,e)}#S=M({});get fullHeights(){return z(this.#S)}set fullHeights(e){N(this.#S,e)}#C=j(()=>new Map([...this.nodes,...this.infra].map(({id:e,measured:t})=>{let n=t?.height??0,r=this.fullHeights[e]??0;return[e,this.brief&&n&&r>n?(r-n)/2:0]})));#w(e=(e,t)=>t.y){let t=[],n=[];for(let{id:r,position:i,measured:a}of[...this.nodes,...this.infra]){let o=a?.height;if(!o)continue;let s=e(r,i),c=z(this.#C).get(r)??0;t.push([s+c,s+c+o]);let l=this.fullHeights[r]??0;c&&n.push([s,s+c]),l>o&&n.push([s+c+o,s+l])}return Io(this.brief?t:[],this.brief?n:[])}#T=Io([],[]);#E=null;#D=()=>[...this.nodes,...this.infra].map(({id:e,position:t,measured:n})=>`${e} ${String(t.x)} ${String(t.y)} ${String(n?.height??0)}`).join(`|`);#O=j(()=>{let e=this.#D();return[...this.nodes,...this.infra].some(e=>e.dragging)||this.brief&&this.#E===e||(this.#E=null,this.#T=this.#w()),this.#T});get squeezed(){return z(this.#O)}set squeezed(e){N(this.#O,e)}shown=(e,t=``)=>({x:e.x,y:this.squeezed.show(e.y+(z(this.#C).get(t)??0))});stored=(e,t=``)=>({x:e.x,y:this.squeezed.back(e.y)-(z(this.#C).get(t)??0)});dropped(e,t){let n=z(this.#C).get(e)??0,r=this.squeezed.back(t.y)-n;if(this.brief)return{x:t.x,y:r};for(let i=0;i<4;i++)r=this.#w((t,n)=>t===e?r:n.y).back(t.y)-n;return{x:t.x,y:r}}#k=j(()=>new Map(this.nodes.flatMap(({id:e,position:t,measured:n})=>n?.width&&n.height?[[e,{...this.shown(t,e),w:n.width,h:n.height}]]:[])));get boxes(){return z(this.#k)}set boxes(e){N(this.#k,e)}#A=M();#j=M([]);get unplaced(){return z(this.#j)}set unplaced(e){N(this.#j,e)}#M(e){return this.nodes.some(t=>t.id===e&&t.data.run===`mock`)}tunnelsOf(e){if(this.#M(e))return[];let t=z(this.#A)?.apps[e];return((this.env===this.envs[0]?void 0:t?.envs?.[this.env]?.prereqs)??t?.prereqs??[]).flatMap(e=>{let{tunnel:t,port:n}=e;return t&&n&&Number.isInteger(n)&&n<65536?[{...e,tunnel:t,port:n}]:[]})}tunnelPath(e,t){let n=z(this.#A)?.apps[e],r=this.env===this.envs[0]?void 0:n?.envs?.[this.env]?.prereqs,i=(r??n?.prereqs??[]).findIndex(e=>e.tunnel===t);return`apps.${e}.${r?`envs.${this.env}.`:``}prereqs[${String(i)}]`}#N=j(()=>Ps(this.cards.filter(e=>!e.data.hideTunnels).flatMap(({id:e})=>this.tunnelsOf(e).map(t=>({app:e,tunnel:t.tunnel,port:t.port,env:t.env,what:Ms(t),connectsAs:t.connectsAs}))),this.cards.flatMap(({id:e})=>{let t=Number(new URL(z(this.#A)?.apps[e]?.url??`http://none`).port);return t?[t]:[]})));get plan(){return z(this.#N)}set plan(e){N(this.#N,e)}ledBy(e){return[...this.plan.filter(t=>t.apps[0]===e).map(tc),...this.boardQueues.filter(t=>this.#R(t)===e).map(e=>`queue:${e.id}`)]}#P=j(()=>new Set(this.cards.map(e=>e.id)));#F=j(()=>new Set(this.cards.filter(e=>e.data.showQueues).map(e=>e.id)));commandsOf(e){return Object.entries(z(this.#A)?.apps[e]?.commands??{}).filter(([,e])=>(e.show??`both`)!==`cli`)}#I(e){return!!z(this.#A)?.apps[e]?.outside}#L=j(()=>{let e=z(this.#A)?.apps??{};return Object.entries(z(this.#A)?.queues??{}).flatMap(([t,n])=>{let r=n=>Object.keys(e).filter(r=>Object.hasOwn(e[r]?.[n]??{},t)&&(z(this.#F).has(r)||this.#I(r))),[i,a]=[r(`publishes`),r(`reads`)];return!this.hiddenQueues[t]&&[...i,...a].some(e=>z(this.#F).has(e))?[{id:t,queue:n,pubs:i,reads:a}]:[]})});get boardQueues(){return z(this.#L)}set boardQueues(e){N(this.#L,e)}ownedBy(e){let t=t=>[...t.pubs,...t.reads].filter(e=>z(this.#P).has(e)||this.#I(e)&&!this.hiddenOutside[e]).every(t=>t===e);return this.ledBy(e).filter(e=>e.startsWith(`tunnel:`)||this.boardQueues.some(n=>`queue:${n.id}`===e&&t(n)))}#R(e){return[...e.pubs,...e.reads].find(e=>z(this.#P).has(e))}queueName(e){return z(this.#A)?.queues?.[e]?.name??e}switchesOver(e){if(this.#M(e))return!1;let t=this.cards.find(t=>t.id===e)?.data.branch,n=this.app(e);return!!(t&&n?.current&&t!==n.current&&n.dirty)}localLibraries(e){let t=this.cards.find(t=>t.id===e)?.data.libraries??[],n=this.app(e)?.libraries??[];return t.filter(e=>n.some(t=>t.name===e))}borrowsTunnels(e){if(this.env===this.envs[0])return!1;let t=z(this.#A)?.apps[e],n=t?.envs?.[this.env]?.prereqs??[],r=this.cards.find(t=>t.id===e)?.data.hideTunnels;return[`sso`,`signIn`,`tunnel`,`hosts`].some(e=>(t?.prereqs??[]).some(t=>t[e])&&!n.some(t=>t[e])&&!(e!==`sso`&&e!==`signIn`&&r))}queuesOf(e){return this.#M(e)?[]:Os(z(this.#A),e).filter(e=>z(this.#A)?.queues?.[e])}#z=j(()=>{let e=e=>this.#I(e)?`outside:${e}`:e;return[...this.boardQueues.flatMap(({id:t,pubs:n,reads:r})=>[...n.map(n=>({from:e(n),to:`queue:${t}`,queue:t})),...r.map(n=>({from:`queue:${t}`,to:e(n),queue:t}))]),...this.cards.flatMap(({id:e})=>Object.keys(z(this.#A)?.apps[e]?.consumes??{}).filter(e=>this.#I(e)).map(t=>({from:e,to:`outside:${t}`}))),...Object.entries(z(this.#A)?.apps??{}).flatMap(([e,t])=>this.#I(e)?Object.keys(t.consumes??{}).filter(e=>this.cards.some(t=>t.id===e)).map(t=>({from:`outside:${e}`,to:t})):[])]});get flows(){return z(this.#z)}set flows(e){N(this.#z,e)}infraSide(e){let t=new Set(this.cables.flatMap(t=>[t.from===e&&t.fromSide,t.to===e&&t.toSide]));return rc.find(e=>!t.has(e))??`bottom`}deployedCalls(e){return this.#M(e)?[]:(this.app(e)?.calls??[]).flatMap(t=>{let n=this.app(t);return n&&!n.outside&&!this.edges.some(n=>n.id===`${e}>${t}`)?[n]:[]})}callLocally(e,t){this.add(t),this.nodes.some(e=>e.id===t)&&this.connect(e,t)}setQueue(e,t){let{[e]:n,...r}=this.queues;this.queues=t?{...r,[e]:`local`}:r,this.syncInfra()}showQueues(e,t){let n=Object.entries(this.hiddenQueues).filter(([t])=>!e.includes(t));this.hiddenQueues=Object.fromEntries(t?n:[...n,...e.map(e=>[e,!0])])}#B=j(()=>this.plan.flatMap(e=>e.apps.map(t=>({from:t,to:tc(e),tunnel:e}))));get links(){return z(this.#B)}set links(e){N(this.#B,e)}#V=j(()=>{let e=[...this.nodes,...this.infra].filter(e=>e.selected),t=this.edges.filter(e=>e.selected),[n]=e,[r]=t;if(e.length===1&&!t.length&&n){let e=[n.id];for(let{from:t,to:r}of[...this.cables,...this.links,...this.flows])(t===n.id||r===n.id)&&e.push(t,r);return{id:n.id,near:e}}return!e.length&&t.length===1&&r?{id:null,cable:[r.source,r.target],near:[r.source,r.target]}:null});get focus(){return z(this.#V)}set focus(e){N(this.#V,e)}dimmed=e=>!!this.focus&&!this.focus.near.includes(e);lit=(e,t)=>{let n=this.focus;return n?n.cable?n.cable[0]===e&&n.cable[1]===t:e===n.id||t===n.id:!1};dimmedLink=(e,t)=>!!this.focus&&!this.lit(e,t);#H(e){let t=this.boxes.get(e),n=this.ledBy(e).flatMap(e=>this.infraBoxes.get(e)??[]).filter(e=>t&&e.y>t.y&&e.x<t.x+t.w&&e.x+e.w>t.x);return{covered:n.length?Math.max(...n.map(e=>e.w+12)):0,atRight:!!t&&!!n.length&&n.every(e=>Math.abs(e.x+e.w-t.x-t.w)<2)}}#U=j(()=>Qo(this.cables,{cardOf:e=>this.boxes.get(e),coveredBelow:e=>this.#H(e)}));get ends(){return z(this.#U)}set ends(e){N(this.#U,e)}#W(e,t,n=this.boxes.get(e)??{w:260,h:200},r=!1,i){let a=this.nodes.find(t=>t.id===e),o=new Set(r?this.ownedBy(e):this.ledBy(e));if(!a||!o.size)return t;let s={...a.position,...n},c=i??this.infraSide(e),l=c===`bottom`?s.y+s.h+nc.gap/2:c===`top`?s.y-nc.gap/2:s.y;return t.map(e=>{if(!o.has(e.id))return e;let t=this.infraBoxes.get(e.id)??nc;c===`top`&&(l-=t.h);let n=c===`right`?s.x+s.w+nc.gap:c===`left`?s.x-nc.gap-t.w:s.x,r={...e,position:{x:n,y:l}};return l+=c===`top`?-nc.gap/2:t.h+nc.gap/2,r})}#G(e,t){let n=t;for(let{id:t,position:r,measured:i}of e){let e=Math.max(i?.height??0,this.brief?this.fullHeights[t]??0:0),a=i?.width;if(!e||!a)continue;let o=new Set(this.ownedBy(t)),s=new Set(this.ledBy(t)),c=n.filter(e=>{let t=this.infraBoxes.get(e.id)?.w??nc.w;return s.has(e.id)&&e.position.y>=r.y&&e.position.x<r.x+a&&r.x<e.position.x+t}).sort((e,t)=>e.position.y-t.position.y),l=r.y+e,u=-1/0,d={};for(let e of c){let t=o.has(e.id)?l+nc.gap/2:-1/0,n=e.position.y>=Math.max(u,t)?e.position.y:Math.max(u+nc.gap/2,t);n!==e.position.y&&(d[e.id]=n),u=n+(this.infraBoxes.get(e.id)?.h??nc.h)}Object.keys(d).length&&(n=n.map(e=>{let t=d[e.id];return t===void 0?e:{...e,position:{x:e.position.x,y:t}}}))}return n}syncInfra(e={}){let t=new Map(this.infra.map(e=>[e.id,e])),n=[],r=this.plan.map(r=>{let i=tc(r),a=t.get(i);!a&&!e[i]&&n.push(r.apps[0]??``);let o=r.apps.flatMap(e=>this.tunnelsOf(e)).find(e=>e.tunnel===r.host)?.note;return{...a,id:i,type:`tunnel`,deletable:!1,position:a?.position??e[i]??{x:0,y:0},data:{what:r.what,local:`${r.bind}:${String(r.port)}`,moved:!!r.settings||!!r.needsAlias,host:r.host,about:[r.settings?`Moved from port ${String(r.original)} so it does not clash with another tunnel on the board.`:``,r.needsAlias?`Keeps port ${String(r.port)} on its own loopback address, ${r.bind}, so it does not clash (needs sudo once).`:``,typeof o==`string`?o:``].filter(Boolean),apps:r.apps,settings:this.tunnelPath(r.apps[0]??``,r.host)}}}),i=this.env.toUpperCase(),a=e=>z(this.#A)?.apps[e]?.name??e,o=this.boardQueues.map(r=>{let o=`queue:${r.id}`,s=t.get(o),c=this.#R(r);!s&&!e[o]&&c&&n.push(c);let l=Ds.includes(r.queue.type),u=l&&this.queues[r.id]===`local`,d=r.reads.filter(e=>z(this.#P).has(e)).map(a),f=!u&&d.length?d.join(` and `):``;return{...s,id:o,type:`queue`,deletable:!1,position:s?.position??e[o]??{x:0,y:0},data:{queue:r.id,name:r.queue.name,kind:r.queue.type.toUpperCase(),can:l,local:u,shares:f?`Your local ${f} reads the ${i} queue`:``,about:[r.queue.envs?.[this.env]?.queue??r.queue.queue??r.id,f?`It takes messages the deployed ${i} reader would get. Switch to Local to give your run its own copy.`:``].filter(Boolean)}}}),s=[...new Set([...this.flows.flatMap(e=>[e.from,e.to]),...this.pinned.filter(e=>this.#I(e)).map(e=>`outside:${e}`)])].filter(e=>e.startsWith(`outside:`)&&!this.hiddenOutside[e.slice(8)]).map(n=>{let r=z(this.#A)?.apps[n.slice(8)],o=t.get(n),s=this.env===this.envs[0]?void 0:r?.envs?.[this.env]?.deployedUrl,c=typeof s==`string`?s:r?.deployedUrl??``,l=URL.canParse(c)?new URL(c).hostname:``,u=typeof r?.outside==`string`?`: ${r.outside.replace(/\.+$/,``)}`:``;return{...o,id:n,type:`outside`,deletable:!1,position:o?.position??e[n]??{x:0,y:0},data:{name:r?.name??n.slice(8),where:l?`${i}: ${l}`:`Outside, never runs`,about:[`${r?.name??n.slice(8)} does not run on this Mac${u}. Koppler cannot check calls to it.`,l?`The ${i} board uses ${c}.`:``,...this.flows.filter(e=>e.from===n).map(e=>`It sends to the deployed ${a(e.to)}, not to your local one.`)].filter(Boolean)}}}),c=[...r,...o,...s];for(let e of n)c=this.#W(e,c);for(let n of s.filter(n=>!t.has(n.id)&&!e[n.id])){let e=this.#K(n.id,c);c=c.map(t=>t.id===n.id?{...t,position:e}:t)}this.infra=c,this.unplaced=[...new Set([...this.unplaced,...n])]}#K(e,t,n=e=>this.boxes.get(e)??{w:260,h:200}){let r=nc,i=i=>{let a=t.find(t=>t.id===i&&(t.id===e||t.position.x||t.position.y)),o=this.nodes.find(e=>e.id===i);return a?{...a.position,...this.infraBoxes.get(i)??r}:o&&{...o.position,...n(i)}},a=this.flows.flatMap(t=>{let n=t.from===e?t.to:t.to===e?t.from:void 0,r=n===void 0?void 0:i(n);return r?[{at:r,before:t.to===e}]:[]}),o=[...this.nodes.map(e=>i(e.id)),...t.filter(t=>t.id!==e).map(e=>i(e.id))],s=e=>o.every(t=>!t||e.x+r.w+16<=t.x||t.x+t.w+16<=e.x||e.y+r.h+16<=t.y||t.y+t.h+16<=e.y),[c]=a;if(!c)return{x:40,y:40};let{at:l,before:u}=c,d=u?[l.x+l.w+80,l.x-r.w-80]:[l.x-r.w-80,l.x+l.w+80],f=[{x:d[0]??0,y:l.y},{x:d[1]??0,y:l.y},{x:l.x,y:l.y+l.h+40},{x:l.x,y:l.y-r.h-40},...Array.from({length:9},(e,t)=>({x:d[0]??0,y:l.y+(t+1)*(r.h+24)}))];return f.find(s)??f[0]??{x:40,y:40}}settle(){let e=e=>e.every(e=>e.measured?.width);if(!this.unplaced.length||!e(this.nodes)||!e(this.infra))return;let t=this.infra;for(let e of this.unplaced)t=this.#W(e,t);this.unplaced=[],this.infra=t}pushed(e,t,n,r){let i=new Set(this.ledBy(e));return r.map(e=>i.has(e.id)&&e.position.y>=t?{...e,position:{x:e.position.x,y:e.position.y+n}}:e)}followed(e,t,n){let r=new Set(this.ownedBy(e));return n.map(e=>r.has(e.id)&&!e.selected&&!e.dragging?{...e,position:{x:e.position.x+t.x,y:e.position.y+t.y}}:e)}hideTunnel(e){let t=this.infra.find(t=>t.id===e),n=new Set(t?.type===`tunnel`?t.data.apps:[]);this.nodes=this.nodes.map(e=>n.has(e.id)?{...e,data:{...e.data,hideTunnels:!0}}:e)}flowNodes(){return[...this.nodes,...this.infra].map(e=>{let t=this.shown(e.position,e.id);return this.#q.set(e.id,t),{...e,position:t}})}#q=new Map;#J={};fromFlow(e,t,n){let r=new Map([...this.nodes,...this.infra].map(e=>[e.id,e])),i=[],a=e.map(e=>{let t=r.get(e.id),n=e.dragging||t?.dragging?{...e,position:e.type===`app`?this.#Y(e.id,e.position,i):this.#X(e.id,e.position,i)}:e;if(t?.dragging&&!n.dragging)return{...n,position:this.dropped(n.id,n.position)};let a=t&&(this.#q.get(t.id)??this.shown(t.position,t.id));return t&&a?.x===n.position.x&&a.y===n.position.y?{...n,position:t.position}:{...n,position:this.stored(n.position,n.id)}}),o=e.every(e=>!e.dragging)?[]:i;o.join()!==this.snapped.join()&&(this.snapped=o);let s=new Map(this.nodes.map(e=>[e.id,e.position])),c={},l=[],u=a.filter(e=>e.type!==`app`),d=a.filter(e=>e.type===`app`);for(let{id:e,measured:r}of d){let i=this.#J[e],a=r?.height;a&&(this.#J[e]={brief:t,height:a}),a&&a!==i?.height&&l.push(e);let o=n&&i?.brief===t&&a?a-i.height:0;o&&(c[e]={bottom:i?.height??0,by:o});let s=this.boxes.get(e);if(o&&s){let t=e=>!!e&&e.y>=s.y+(i?.height??0)&&e.x<s.x+s.w&&s.x<e.x+e.w;for(let n of d.filter(n=>n.id!==e&&t(this.boxes.get(n.id))))u=this.followed(n.id,{x:0,y:o},u);d=d.map(n=>n.id!==e&&t(this.boxes.get(n.id))?{...n,position:{x:n.position.x,y:n.position.y+o}}:n)}}for(let{id:e,position:t}of d){let n=c[e];n&&(u=this.pushed(e,t.y+n.bottom,n.by,u));let r=s.get(e);r&&(r.x!==t.x||r.y!==t.y)&&(u=this.followed(e,{x:t.x-r.x,y:t.y-r.y},u))}return u=this.#G(d.filter(e=>l.includes(e.id)),u),this.nodes=d,this.infra=u,this.brief&&e.some(e=>e.dragging||r.get(e.id)?.dragging)&&(this.#E=this.#D()),Object.keys(c).length>0}#Y(e,t,n){let r=this.boxes.get(e);if(!r)return t;let i=ic/(this.view?.zoom??1),a={...r,x:t.x,y:t.y},o=(e,t,n)=>{let r=this.cables[e];if(!r)return;let i=r[`${t}Side`],a=Ho(n,i),o=this.ends.offset[`${String(e)}|${t}`]??0;return{side:i,at:Lo[i][0]===0?{...a,x:a.x+o}:{...a,y:a.y+o}}},s,c;this.cables.forEach((t,n)=>{let r=t.from===e?`from`:t.to===e?`to`:null;if(!r||t.from===t.to)return;let l=r===`from`?`to`:`from`,u=this.boxes.get(t[l]);if(!u||this.nodes.some(e=>e.id===t[l]&&e.dragging))return;let d=o(n,r,a),f=o(n,l,u);if(!d||!f)return;let p=Lo[d.side][0]!==0,m=p?f.at.y-d.at.y:f.at.x-d.at.x,h={by:m,cable:`${t.from}>${t.to}`};Math.abs(m)>i||(p&&(!c||Math.abs(m)<Math.abs(c.by))&&(c=h),!p&&(!s||Math.abs(m)<Math.abs(s.by))&&(s=h))});let l=new Set(this.ownedBy(e)),u=[...this.links.filter(t=>t.from===e).map(e=>e.to),...this.flows.flatMap(t=>t.from===e?[t.to]:t.to===e?[t.from]:[])].filter(e=>!l.has(e));for(let t of new Set(u)){let n=this.infraBoxes.get(t);if(!n||this.infra.some(e=>e.id===t&&e.dragging))continue;let r=Math.max(n.x-(a.x+a.w),a.x-(n.x+n.w)),o=Math.max(n.y-(a.y+a.h),a.y-(n.y+n.h))>=r,l=o?n.x+n.w/2-(a.x+a.w/2):n.y+n.h/2-(a.y+a.h/2);if(Math.abs(l)>i)continue;let u={by:l,cable:`${e}>${t}`};o&&(!s||Math.abs(l)<Math.abs(s.by))&&(s=u),!o&&(!c||Math.abs(l)<Math.abs(c.by))&&(c=u)}let d=s?.by??0,f=c?.by??0;for(let e of[s,c])e&&n.push(e.cable,e.cable.split(`>`).reverse().join(`>`));return{x:t.x+d,y:t.y+f}}#X(e,t,n){let r=this.infraBoxes.get(e);if(!r)return t;let i=ic/(this.view?.zoom??1),a={...r,x:t.x,y:t.y},o=[...this.links.filter(t=>t.to===e).map(e=>e.from),...this.flows.flatMap(t=>t.from===e?[t.to]:t.to===e?[t.from]:[])],s,c;for(let e of new Set(o)){let t=this.boxes.get(e)??this.infraBoxes.get(e);if(!t||[...this.nodes,...this.infra].some(t=>t.id===e&&t.dragging))continue;let n=Math.max(t.x-(a.x+a.w),a.x-(t.x+t.w)),r=Math.max(t.y-(a.y+a.h),a.y-(t.y+t.h))>=n,o=r?t.x+t.w/2-(a.x+a.w/2):t.y+t.h/2-(a.y+a.h/2);if(Math.abs(o)>i)continue;let l=r?s:c;l&&Math.abs(l.by)<=Math.abs(o)||(r?s={by:o,partner:e}:c={by:o,partner:e})}for(let t of[s,c])t&&n.push(`${t.partner}>${e}`,`${e}>${t.partner}`);return{x:a.x+(s?.by??0),y:a.y+(c?.by??0)}}#Z=M([]);get snapped(){return z(this.#Z)}set snapped(e){N(this.#Z,e)}#Q=M();get view(){return z(this.#Q)}set view(e){N(this.#Q,e)}#$=M(!1);get unsaved(){return z(this.#$)}set unsaved(e){N(this.#$,e,!0)}#ee={};#te=M(!1);get live(){return z(this.#te)}set live(e){N(this.#te,e,!0)}#ne=``;#re={};goLive(){this.live||=(this.commit(),this.#re=this.saved(),this.#ne=this.content(),!0)}goEdit(){this.live&&=(this.setContent(this.#ne),!1)}content(){return JSON.stringify({name:this.name,nodes:this.nodes.map(({id:e,type:t,position:n,data:r})=>({id:e,type:t,position:n,data:r})),infra:this.infra.map(({id:e,position:t})=>({id:e,position:t})),queues:this.queues,hiddenQueues:this.hiddenQueues,hiddenOutside:this.hiddenOutside,pinned:this.pinned,edges:this.edges.map(({id:e,source:t,target:n,type:r,data:i})=>({id:e,source:t,target:n,type:r,data:i}))})}setContent(e){let{name:t,nodes:n,edges:r,infra:i,queues:a,hiddenQueues:o,hiddenOutside:s,pinned:c}=JSON.parse(e);this.name=t,this.pinned=c,this.nodes=n,this.edges=r,this.queues=a,this.hiddenQueues=o,this.hiddenOutside=s,this.syncInfra(Object.fromEntries(i.map(({id:e,position:t})=>[e,t]))),this.infra=this.infra.map(e=>({...e,position:i.find(t=>t.id===e.id)?.position??e.position}))}#ie=M(null);get name(){return z(this.#ie)}set name(e){N(this.#ie,e,!0)}#ae=M([]);get own(){return z(this.#ae)}set own(e){N(this.#ae,e)}get team(){return z(this.#A)?.presets??[]}#oe=M(null);get opened(){return z(this.#oe)}set opened(e){N(this.#oe,e,!0)}#se(){let e=e=>this.app(e);return{known:t=>!!e(t),cloned:t=>!!e(t)?.cloned,name:t=>e(t)?.name??t,canCall:(t,n)=>!e(t)?.outside&&!!e(n)&&!e(n)?.outside&&!!e(n)?.answers,runIn:t=>(e(t)?.runIn??[]).map(([e])=>e),platforms:t=>(e(t)?.platforms??[]).map(([e])=>e),branches:t=>{let n=e(t)?.branches??[];return n.length&&n.length<300?n:null}}}#ce(e){return{name:e,version:1,nodes:Object.fromEntries(this.nodes.map(({id:e,data:t})=>[e,{run:t.run,...t.platform&&{platform:t.platform},...t.branch&&{branch:t.branch},...t.note&&{note:t.note},...t.hideTunnels&&{tunnels:!1},...t.showQueues&&this.queuesOf(e).length>0&&{queues:!0},...t.watch&&t.run===`cli`&&{watch:!0}}])),edges:this.edges.map(({source:e,target:t})=>({from:e,to:t})),...this.pinned.length&&{outside:this.pinned}}}#le(){let e=e=>Object.fromEntries(e.map(({id:e,position:t})=>[e,{x:Math.round(t.x),y:Math.round(t.y)}]));return{nodes:e(this.nodes),infra:e(this.infra),sides:Object.fromEntries(this.edges.map(({id:e,data:t})=>[e,[t.fromSide,t.toSide,null,null,t.fromSlot??null,t.toSlot??null,t.points??null,t.fromShift??null,t.toShift??null]]))}}#ue(){let e=e=>{let t={...this.own.find(t=>t.name===e),...this.#ce(e),layout:this.#le()},n=this.own.some(t=>t.name===e)?this.own.map(n=>n.name===e?t:n):[...this.own,t];JSON.stringify(n)!==JSON.stringify(this.own)&&(this.own=n),this.name!==e&&(this.name=e)};if(this.own.some(e=>e.name===this.name)){e(this.name??``);return}if(!this.nodes.length||this.scratch&&this.nodes.length<2)return;this.scratch=!1;let t=this.team.find(e=>e.name===this.name),n=e=>JSON.stringify([e.nodes,e.edges.map(e=>`${e.from}>${e.to}`).sort()]),r=t&&Vs(t,this.#se()).preset;if(t&&r&&n(this.#ce(t.name))===n(r))return;let i=t&&this.own.find(e=>e.name===`${t.name} (local)`||e.name===`${t.name} (mine)`),a=this.nodes[0]?.data.name??`Untitled`,o=this.nodes.length>1?`${a} + ${String(this.nodes.length-1)}`:a;e(i?.name??this.uniqueName(t?`${t.name} (local)`:this.name||o))}uniqueName(e){let t=new Set([...this.team,...this.own].map(e=>e.name)),n=e;for(let r=2;t.has(n);r++)n=`${e} (${String(r)})`;return n}#de=M([]);get trash(){return z(this.#de)}set trash(e){N(this.#de,e)}#fe=M([]);get recent(){return z(this.#fe)}set recent(e){N(this.#fe,e)}rename(e){let t=e.trim().slice(0,80),n=this.name;return this.own.some(e=>e.name===n)?t?t===n?null:[...this.team,...this.own].some(e=>e.name===t)?`A board is already called ${t}. Pick another name.`:(this.own=this.own.map(e=>e.name===n?{...e,name:t}:e),this.name=t,null):`Give the board a name first.`:`Only a board of your own can be renamed.`}duplicate(){if(!this.nodes.length)return;this.#ue();let e=this.nodes[0]?.data.name??`Untitled`,t=this.uniqueName(`${this.name??e} copy`);this.own=[...this.own,{...this.#ce(t),layout:this.#le()}],this.name=t}deleteBoard(e){let t=this.own.find(t=>t.name===e);t&&(this.own=this.own.filter(e=>e!==t),this.trash=[{...t,deleted:new Date().toISOString()},...this.trash].slice(0,20),this.name===e&&this.newBoard())}restore(e){let{deleted:t,...n}=e,r={...n,name:this.uniqueName(e.name)};this.trash=this.trash.filter(t=>t!==e),this.own=[...this.own,r],this.nodes.length||this.openBoard(r)}importBoards(e,t){let n=e?.presets,r=(Array.isArray(e)?e:Array.isArray(n)?n:[e]).map(e=>Rs(e)),i=r.flatMap(e=>e.preset?[{...e.preset,name:e.preset.name.trim().slice(0,80),source:t}]:[]),[a]=i;if(!a)return{error:r[0]?.error??`No board found in it.`};let o=Vs(a,this.#se());if(o.error!==void 0)return{error:o.error};let s=[...new Map(i.map(e=>[e.name,e])).values()];this.own=[...this.own.filter(e=>!s.some(t=>t.name===e.name)),...s];let c=this.openBoard(a);return c.error===void 0?{notes:c.notes,name:a.name}:c}forTeam(e){let{layout:t,outside:n}=e;return{...JSON.parse(this.asShared(e)),...t?{layout:t}:{},...n?{outside:n}:{}}}keptForTeam(e,t){let n=[...z(this.#A)?.presets??[]];n[e]=t,z(this.#A)&&N(this.#A,{...z(this.#A),presets:n})}asShared(e){let{name:t,nodes:n,edges:r}=e;return JSON.stringify({name:t,version:Rs(e).preset?.version??1,nodes:n,edges:r},null,2)}#pe=M([]);get dismissed(){return z(this.#pe)}set dismissed(e){N(this.#pe,e)}#me=M(!1);get scratch(){return z(this.#me)}set scratch(e){N(this.#me,e,!0)}alone(e){let t=[...this.own,...this.team].find(e=>e.name===this.name);return this.newBoard(),this.scratch=!0,this.add(e),this.opened=`fit`,t}newBoard(){this.scratch=!1,this.dismissed=[],this.name=null,this.nodes=[],this.edges=[],this.queues={},this.hiddenQueues={},this.hiddenOutside={},this.pinned=[]}openBoard(e){if(!Object.keys(e.nodes).length)return this.newBoard(),this.name=e.name,{notes:[]};let t=Vs(e,this.#se());if(t.error!==void 0)return{error:t.error};let{preset:n,notes:r}=t,i=e.layout??{},a=e=>{let{x:t,y:n}=i.nodes?.[e]??{};return typeof t==`number`&&typeof n==`number`&&Number.isFinite(t)&&Number.isFinite(n)?{x:t,y:n}:null},o=Object.keys(n.nodes),s=o.every(a);this.scratch=!1,this.dismissed=[],this.recent=[{name:n.name,at:new Date().toISOString()},...this.recent.filter(e=>e.name!==n.name)].slice(0,20),this.name=n.name,this.queues={},this.hiddenQueues={},this.hiddenOutside={},this.pinned=Array.isArray(e.outside)?e.outside.filter(e=>typeof e==`string`):[],this.infra=this.infra.map(lc),this.nodes=o.flatMap(e=>{let t=this.app(e),r=n.nodes[e];if(!t||!r)return[];let i={...r,hideTunnels:r.tunnels===!1,showQueues:r.queues===!0};return[this.#ye(t,s&&a(e)||{x:0,y:0},i)]});let c=Object.fromEntries(this.nodes.map(({id:e,position:t})=>[e,t])),l=e=>typeof e==`string`&&e in Lo,u=(e,t)=>Number.isInteger(t)?{[e]:t}:{},d=(e,t)=>typeof t==`number`&&Number.isFinite(t)?{[e]:t}:{};return this.edges=n.edges.map(({from:e,to:t})=>{let[n,r,,,a,o,f,p,m]=i.sides?.[`${e}>${t}`]??[];return!s||!l(n)||!l(r)?cc(e,t,Fo(c,{from:e,to:t},`down`,()=>({w:260,h:160}))):cc(e,t,{fromSide:n,toSide:r,...u(`fromSlot`,a),...u(`toSlot`,o),...d(`fromShift`,p),...d(`toShift`,m),...Array.isArray(f)&&{points:f}})}),this.infra=[],this.syncInfra(s?i.infra??{}:{}),this.opened=s?`fit`:`arrange`,{notes:r}}clear(){this.nodes=[],this.edges=[]}#he=M([]);get apps(){return z(this.#he)}set apps(e){N(this.#he,e)}#ge=j(()=>new Map(this.apps.map(e=>[e.id,e])));app=e=>z(this.#ge).get(e);nameOf=e=>z(this.#ge).get(e)?.name??e;#_e=M([]);get envs(){return z(this.#_e)}set envs(e){N(this.#_e,e)}#ve=M([]);get roots(){return z(this.#ve)}set roots(e){N(this.#ve,e)}area=()=>new DOMRect;show=()=>void 0;#ye(e,t,n={}){let{id:r,name:i,kind:a,kindLabel:o,runIn:s,platforms:c}=e,l=s.some(([e])=>e===n.run)?n.run:s[0]?.[0],u=c.some(([e])=>e===n.platform)?n.platform:c[0]?.[0];return{id:r,type:`app`,position:t,data:{name:i,kind:a,kindLabel:o,...n.hideTunnels===!0&&{hideTunnels:!0},...n.showQueues===!0&&{showQueues:!0},...n.watch===!0&&{watch:!0},...(n.changes===`take-along`||n.changes===`set-aside`)&&{changes:n.changes},...Array.isArray(n.libraries)&&{libraries:n.libraries.filter(e=>typeof e==`string`)},branch:n.branch??``,run:l??`cli`,...u&&{platform:u},note:n.note??``}}}async reload(){this.commit(),await Ys(this.saved());let e=await qs();e&&this.open(e)}open({stack:e,clones:t,roots:n,saved:r}){let i=wo(e);N(this.#A,i),N(this.#u,i.envs.filter(e=>As(i,e))),this.stack=i.name??``,this.dir=(i.source??``).replace(/\/stack\.json$/,``),this.setup=!!i.setup,this.known=i.stacks??[],this.envs=i.envs,this.env=r?.env??i.envs[0]??``,this.roots=n,this.apps=Object.entries(i.apps).map(([e,n])=>({id:e,name:n.name,kind:n.kind,kindLabel:hs(n,i).label,slug:n.slug??``,cloned:!!t[e],calls:[...new Set([...Object.keys(n.consumes??{}),...Object.keys(i.found?.[e]??{})])],known:Object.keys(n.consumes??{}),answers:hs(n,i).serves||Object.entries(i.apps).some(([t,n])=>t!==e&&(n.consumes?.[e]??i.found?.[t]?.[e])),serves:!!n.url,runIn:[...hs(n,i).runIn,...n.mock?.length?[[`mock`,`Mock`]]:[]],platforms:hs(n,i).platforms??[],current:t[e]?.branch??``,branches:t[e]?.branches??[],dirty:t[e]?.dirty??0,libraries:(t[e]?.libraries??[]).map(({name:e,path:t})=>({name:e,path:t})),...n.outside&&{outside:typeof n.outside==`string`?n.outside:`an outside system`}})),this.nodes=this.apps.flatMap(e=>{let t=r?.nodes?.[e.id];return t?[this.#ye(e,{x:t.x,y:t.y},t)]:[]}),this.fullHeights=Object.fromEntries(Object.entries(r?.nodes??{}).flatMap(([e,t])=>typeof t?.full==`number`&&t.full>0?[[e,t.full]]:[]));let a=new Set(this.nodes.map(({id:e})=>e));this.edges=(r?.edges??[]).filter(({from:e,to:t})=>a.has(e)&&a.has(t)).map(({from:e,to:t,fromSide:n,toSide:r,...i})=>cc(e,t,{fromSide:n??`right`,toSide:r??`left`,...i})),this.#ee=r??{},this.name=typeof r?.preset==`string`?r.preset:null,this.own=Array.isArray(r?.presets)?r.presets:[],this.scratch=r?.scratch===!0,this.dismissed=Array.isArray(r?.dismissed)?r.dismissed:[],this.trash=Array.isArray(r?.trash)?r.trash:[],this.recent=Array.isArray(r?.recent)?r.recent:[],this.infra=[],this.queues=r?.queues??{},this.hiddenQueues=r?.hiddenQueues??{},this.hiddenOutside=r?.hiddenOutside??{},this.pinned=Array.isArray(r?.outside)?r.outside:[],this.syncInfra(r?.infra??{});let{zoom:o,pan:s}=r??{};this.view=o&&s?{x:s.x,y:s.y,zoom:o}:void 0}commit(){!this.live&&!this.nodes.some(e=>e.dragging)&&this.#ue()}get changes(){return[z(this.#A),this.live,this.env,this.name,this.scratch,this.view,this.nodes,this.edges,this.infra,this.own,this.trash,this.recent,this.dismissed,this.fullHeights,this.queues,this.hiddenQueues,this.hiddenOutside,this.pinned]}saved(){if(this.live)return{...this.#re,env:this.env};let e=this.#ee.nodes??{};return{mode:`auto`,...this.#ee,preset:this.name,presets:this.own,trash:this.trash,recent:this.recent,scratch:this.scratch||void 0,dismissed:this.dismissed.length?this.dismissed:void 0,env:this.env,...this.view&&{zoom:this.view.zoom,pan:{x:this.view.x,y:this.view.y}},nodes:Object.fromEntries(this.nodes.map(({id:t,position:n,data:{branch:r,run:i,platform:a,note:o,hideTunnels:s,showQueues:c,watch:l,changes:u,libraries:d}})=>[t,{...e[t],x:Math.round(n.x),y:Math.round(n.y),branch:r,run:i,...a&&{platform:a},note:o,hideTunnels:s?!0:void 0,showQueues:c?!0:void 0,watch:l?!0:void 0,changes:u,libraries:d?.length?d:void 0,full:this.fullHeights[t]}])),edges:this.edges.map(({source:e,target:t,data:n})=>({from:e,to:t,...n})),queues:this.queues,hiddenQueues:this.hiddenQueues,hiddenOutside:Object.keys(this.hiddenOutside).length?this.hiddenOutside:void 0,outside:this.pinned.length?this.pinned:void 0,infra:Object.fromEntries(this.infra.map(({id:e,position:t})=>[e,{x:Math.round(t.x),y:Math.round(t.y)}]))}}add(e,t){let n=this.app(e);if(!n||n.outside||!n.cloned||this.nodes.some(t=>t.id===e))return;if(t){let e=this.toFlow(t);this.#be(this.#ye(n,this.stored({x:e.x-sc.w/2,y:e.y-22})));return}let r=this.area(),i=this.toFlow({x:r.left,y:r.top}),a=this.toFlow({x:r.right,y:r.bottom}),o=this.nodes.map(({id:e,position:t})=>this.boxes.get(e)??{...this.shown(t,e),w:sc.w,h:sc.h}),s=(e,t)=>o.every(n=>e+sc.w+sc.gap<=n.x||n.x+n.w+sc.gap<=e||t+sc.h+sc.gap<=n.y||n.y+n.h+sc.gap<=t),c=(e,t,n)=>Array.from({length:Math.max(0,Math.floor((t-n-e-40)/40)+1)},(t,n)=>e+40+n*40),l=(e,t)=>e-t,u=(e,t)=>[...new Set([...e,...t])],d=u(o.map(e=>e.y).sort(l),c(i.y,a.y,sc.h)).filter(e=>e>=i.y&&e+sc.h<=a.y),f=u(o.map(e=>e.x+e.w+sc.gap).sort(l),c(i.x,a.x,sc.w)).filter(e=>e>=i.x&&e+sc.w<=a.x),p;for(let e of d)if(p=f.filter(t=>s(t,e)).map(t=>({x:t,y:e}))[0],p)break;let m=this.nodes.length*32;this.#be(this.#ye(n,this.stored(p??{x:i.x+48+m,y:i.y+48+m})))}selectAll(){let e=e=>e.selected?e:{...e,selected:!0};this.nodes=this.nodes.map(e),this.infra=this.infra.map(e),this.edges=this.edges.map(lc)}pick(e){let t=t=>!!t.selected==(t.id===e)?t:{...t,selected:t.id===e};this.infra=this.infra.map(t),this.edges=this.edges.map(lc),this.nodes=this.nodes.map(t)}#be(e){this.infra=this.infra.map(lc),this.edges=this.edges.map(lc),this.nodes=[...this.nodes.map(lc),{...e,selected:!0}]}showOutside(e,t){let{[e]:n,...r}=this.hiddenOutside;this.hiddenOutside=t?r:{...r,[e]:!0},t?this.pin(e):this.unpin(e),this.syncInfra()}set(e,t){this.nodes=this.nodes.map(n=>n.id===e?{...n,data:{...n.data,...t}}:n)}cablesOf(e){let t=e=>this.app(e),n=this.cards.flatMap(n=>n.id===e?[]:t(n.id)??[]),r=n.filter(t=>this.edges.some(n=>n.id===`${e}>${t.id}`)),i=n.filter(e=>!r.includes(e)),a=i.filter(n=>t(e)?.calls.includes(n.id)),o=i.filter(t=>!t.outside&&t.answers&&!t.calls.includes(e));return{can:a.length?a:o,wired:r}}uncabled(e){return this.cards.length>1&&!this.edges.some(t=>t.source===e||t.target===e)}connect(e,t){let n=cc(e,t,Fo(Object.fromEntries(this.nodes.map(({id:e,position:t})=>[e,t])),{from:e,to:t},`down`,e=>this.boxes.get(e)??{w:260,h:160}));this.edges=[...this.edges.filter(e=>e.id!==n.id),n]}cut(e,t){this.edges=this.edges.filter(n=>n.id!==`${e}>${t}`)}remove(e){this.nodes=this.nodes.filter(t=>t.id!==e),this.edges=this.edges.filter(t=>t.source!==e&&t.target!==e)}edit(e,t,n=!1){if(this.name!==e){let r=this.own.find(t=>t.name===e)??this.team.find(t=>t.name===e)??(n?{name:e,version:1,nodes:{},edges:[]}:void 0);if(!r)return!1;let i={...Ws(r,t),name:e};if(JSON.stringify(i)===JSON.stringify(r))return!1;let a=this.own.some(t=>t.name===e);return this.own=a?this.own.map(t=>t.name===e?i:t):[...this.own,i],!0}let r=this.content(),i=e=>this.cards.some(t=>t.id===e);for(let e of t.remove??[])this.remove(e);for(let e of t.add??[])this.add(e);for(let[e,n]of Object.entries(t.branch??{}))this.set(e,{branch:n});for(let[e,n]of Object.entries(t.note??{}))this.set(e,{note:n});for(let{from:e,to:n}of t.uncable??[])this.cut(e,n);for(let{from:e,to:n}of t.cable??[])i(e)&&i(n)&&!this.edges.some(t=>t.id===`${e}>${n}`)&&this.connect(e,n);return t.arrange&&(this.opened=`arrange`),this.content()!==r||!!t.arrange}#xe={key:``,version:0};arrange(e=e=>this.boxes.get(e)??{w:260,h:160}){let t=()=>JSON.stringify(this.nodes.map(({id:e,position:t})=>[e,t.x,t.y])),n=t(),r=n===this.#xe.key?this.#xe.version+1:0;for(let i=0;i<ec.length;i++,r++){let[i,a]=ec[r%ec.length]??ec[0];if(this.#Se(e,i,a),t()!==n)break}this.#xe={key:t(),version:r}}#Se(e,t,n){let r=this.cables.map(({from:e,to:t})=>({from:e,to:t})),i=e=>t===`down`&&r.some(t=>t.from===e)?`right`:`bottom`,a=n=>{let i=this.ledBy(n).filter(e=>this.ownedBy(n).includes(e)).map(e=>this.infraBoxes.get(e)??nc),{w:a,h:o}=e(n);if(!i.length)return{w:a,h:o};let s=i.reduce((e,t)=>e+t.h+nc.gap/2,0),c=Math.max(...i.map(e=>e.w));return t===`down`&&r.some(e=>e.from===n)?{w:a+nc.gap+c,h:Math.max(o,s)}:{w:Math.max(a,c),h:o+s}},o=new Map(this.nodes.flatMap(e=>this.ownedBy(e.id).map(t=>[t,e.id]))),s=this.infra.filter(e=>e.type!==`tunnel`&&!o.has(e.id)).map(e=>e.id),c=e=>s.includes(e)||this.cards.some(t=>t.id===e),l=e=>o.get(e)??e,u=this.flows.map(({from:e,to:t})=>({from:l(e),to:l(t)})).filter(({from:e,to:t})=>e!==t&&c(e)&&c(t)),d=Po([...this.nodes.map(e=>e.id),...s],[...r,...u],e=>s.includes(e)?this.infraBoxes.get(e)??{w:220,h:70}:a(e),t,n,{pad:ac,anchor:n=>s.includes(n)?void 0:t===`down`?e(n).w/2:oc/2}),f=Object.fromEntries(this.nodes.filter(e=>this.ownedBy(e.id).length).map(e=>[e.id,i(e.id)])),p=r.map(n=>({...n,...Fo(d,n,t,e,f)}));Zo(p,t=>({...d[t]??{x:0,y:0},...e(t)})),this.nodes=this.nodes.map(e=>({...e,position:d[e.id]??e.position})),this.edges=p.map(({from:e,to:t,...n})=>cc(e,t,n));let m=this.infra.map(e=>{let t=d[e.id];return t?{...e,position:t}:e});for(let t of this.nodes)m=this.#W(t.id,m,e(t.id),!0,f[t.id]);this.infra=m}},uc={waiting:`Waiting`,building:`Building`,running:`Running`,unhealthy:`Unhealthy`,exited:`Exited`,"failed-to-start":`Failed to start`,"secret-missing":`Secret missing`},dc={waiting:e=>e||`Waiting.`,building:e=>`Building. ${e}`,running:()=>``,unhealthy:e=>`Unhealthy: ${e}`,exited:e=>`Exited. ${e}`,"failed-to-start":e=>`Failed to start: ${e}`,"secret-missing":e=>`Secret missing: ${e}. Set it under Credentials.`},Q=new class{#e=M(null);get status(){return z(this.#e)}set status(e){N(this.#e,e)}#t=M(!1);get asked(){return z(this.#t)}set asked(e){N(this.#t,e,!0)}#n;#r=``;watch(){let e=!1,t=async()=>{if(!(document.hidden||e)){e=!0;try{let e=await fetch(`data/status.json`),t=e.ok?await e.text():this.#r;t!==this.#r&&(this.#r=t,this.status=JSON.parse(t))}catch{}e=!1,this.asked||requestAnimationFrame(()=>requestAnimationFrame(()=>this.asked=!0))}};t(),clearInterval(this.#n),this.#n=setInterval(()=>void t(),1500)}sent(e){let{live:t,progress:n}=this.status??{},r=!t?.env||t.env===Z.env;return!!t?.nodes?.[e]&&r||!!n?.apps?.includes(e)&&n.env===Z.env}#i(e){return this.sent(e)?this.status?.apps?.[e]:void 0}up(e){let t=this.#i(e);return t?t.running?t.running.length>0:t.listening??null:null}state(e){let t=this.#i(e);if(t?.state)return t.state;if(!this.sent(e)||this.up(e))return null;let n=(this.status?.secrets?.[e]?.[Z.env]??[]).filter(e=>!e.stored).map(e=>e.name);return n.length?{state:`secret-missing`,detail:n.join(`, `)}:null}stateSaid(e){let t=this.state(e);return t?dc[t.state](t.detail).trim():``}about(e){let t=this.#i(e);if(t?.running)return this.where(e);if(t?.listening===void 0)return``;let n=String(t.port??``);return t.listening?`Running on port ${n}`:`Nothing is listening on port ${n}`}where(e){let t=this.#i(e);if(!t?.running){let n=this.status?.apps?.[e],r=n?.running?n.running.length>0:n?.listening===!0,i=(this.status?.live?.env??``).toUpperCase();return!t&&r&&this.status?.live?.nodes?.[e]?`Running for your ${i} board, not this one. Run switches it.`:``}let[n]=t.running;if(!n)return`Not running on a simulator or device`;let r={ios:`iOS simulator`,android:`Android`}[n.platform]??n.platform,i=n.source?`, started from ${n.source===`ide`?`your IDE`:`Koppler`}`:``,a=t.running.length>1?`, and ${String(t.running.length-1)} more`:``;return`Running on ${n.device} (${r})${n.flavor?`, ${n.flavor}`:``}${i}${a}`}steps(e){let t=this.#i(e)?.steps??[],n=this.up(e);return n===!0?t.map(e=>(e.label===`Start`||e.label===`Check`)&&(e.state===`user`||e.state===`todo`)?{label:e.label,state:`done`,detail:`Running.`}:e):n===!1?t.map(e=>e.label===`Check`&&e.state===`done`?{...e,state:`todo`,detail:`Not running right now.`}:e):t}hasLog(e){return!!this.status?.apps?.[e]?.logTail}tail(e){return this.status?.apps?.[e]?.logTail??``}tunnel(e,t){return t.some(e=>this.sent(e))?this.status?.ports?.[e]:void 0}};function fc(e){let t=t=>e.find(e=>e.state===t),[n,r,i]=[t(`failed`),t(`user`),t(`todo`)];return n?[`failed`,`Failed: ${n.label}`]:r?[`user`,`Waiting on you: ${r.label}`]:i?[`todo`,`Next: ${i.label}`]:[`done`,`All steps done`]}var pc=(e,t)=>Js(e,t,!0),mc=e=>{if(e.matches(`.svelte-flow__pane`))return`the empty board`;let t=e.matches(`input[type="radio"], input[type="checkbox"]`)&&e.closest(`label`)||e.closest(`button, a, [role="button"], [role="option"], [role="radio"], [role="menuitem"], label, input, select, summary, .svelte-flow__node, .svelte-flow__edge`)||e,n=t instanceof HTMLInputElement||t instanceof HTMLSelectElement?t.labels?.[0]:null,r=(t.getAttribute(`aria-label`)??t.getAttribute(`title`)??(n??t).textContent).replace(/\s+/g,` `).trim().slice(0,80),i=t.closest(`.svelte-flow__node, .svelte-flow__edge`)?.getAttribute(`data-id`)??``;return`${t.tagName.toLowerCase()}${r?` "${r}"`:``}${i?` in ${i}`:``}`},hc=e=>!!e.closest(`[type="password"], [data-secret]`),gc=new class{#e=M(!1);#t=[];#n;get forced(){return!!Q.status?.dev}get on(){return z(this.#e)||this.forced}set on(e){N(this.#e,e,!0);try{localStorage.setItem(`koppler-debug`,e?`on`:`off`)}catch{}e&&this.note(`debug`,`Debug log on`)}note(e,t,n){if(!this.on)return;let r={apps:Z.nodes.length,cables:Z.edges.length,view:Z.live?`live`:`edit`,env:Z.env,zoom:Math.round((Z.view?.zoom??1)*100)/100};this.#t.push({at:new Date().toISOString(),kind:e,what:t,...n&&{detail:n.slice(0,300)},board:r}),clearTimeout(this.#n),this.#n=setTimeout(()=>{this.flush()},1500)}flush(){let e=this.#t.splice(0);e.length&&pc(`debug-log`,{entries:e})}async read(){return this.flush(),await new Promise(e=>setTimeout(e,300)),(await fetch(`temp/debug.jsonl?${String(Date.now())}`).then(e=>e.ok?e.text():``).catch(()=>``)).trim().split(`
4
4
  `).slice(-300).join(`
5
5
  `)}clear(){this.#t=[],pc(`debug-clear`,{})}watch(){try{N(this.#e,localStorage.getItem(`koppler-debug`)===`on`)}catch{}let e={capture:!0};addEventListener(`click`,e=>{e.target instanceof Element&&!hc(e.target)&&this.note(`click`,mc(e.target))},e),addEventListener(`change`,e=>{let t=e.target;if(!(t instanceof Element)||hc(t))return;let n=t instanceof HTMLInputElement&&t.type===`checkbox`?String(t.checked):t instanceof HTMLSelectElement||t instanceof HTMLInputElement&&t.type===`radio`?t.value:`(typed)`;this.note(`change`,mc(t),n)},e),addEventListener(`keydown`,e=>{let t=e.target instanceof Element&&!!e.target.closest(`input:not([type="radio"]):not([type="checkbox"]), textarea, select, [contenteditable]`);if(!e.metaKey&&!e.ctrlKey&&t||e.key.length>12)return;let n=[e.metaKey&&`Cmd`,e.ctrlKey&&`Ctrl`,e.shiftKey&&`Shift`,e.altKey&&`Alt`,e.key];this.note(`key`,n.filter(Boolean).join(`+`))},e),addEventListener(`error`,e=>{this.note(`error`,e.message||`page error`,e.filename?`${e.filename.split(`/`).pop()??``}:${String(e.lineno)}`:``)}),addEventListener(`unhandledrejection`,e=>{let t=e.reason,n=t instanceof Error?t.message:typeof t==`string`?t:``;this.note(`error`,n||`unhandled rejection`)}),addEventListener(`pagehide`,()=>{this.flush()})}},$=new class{#e=M(null);get now(){return z(this.#e)}set now(e){N(this.#e,e)}#t;show(e,t=`message`,n){clearTimeout(this.#t),gc.note(t,e),this.now={text:e,warning:t===`warning`,...n&&{action:n}},t!==`warning`&&(this.#t=setTimeout(()=>this.now=null,n?7e3:2600))}hide(){clearTimeout(this.#t),this.now=null}},_c={play:so,database:ro,sprout:fo,refresh:lo,trash:go,terminal:mo,upload:vo,download:ao};async function vc(e,t={}){let n=await Xs(`app-command`,{app:e.app,command:e.key,args:t});return`error`in n?n.error:($.show(`${e.command.label} started on ${e.appName}. The inbox says when it ends.`),null)}async function yc(e,t=!1){let n=await Xs(`open-terminal`,{app:e,env:Z.env,query:t});`error`in n?$.show(n.error,`warning`):$.show(t?`psql opens in a Terminal window.`:`A terminal opens in ${Z.nameOf(e)}'s clone.`)}var bc=H(`<p class="ask svelte-gr1w3a"> </p>`),xc=H(`<span class="opt svelte-gr1w3a">optional</span>`),Sc=H(`<option> </option>`),Cc=H(`<select class="svelte-gr1w3a"></select>`),wc=H(`<input class="svelte-gr1w3a"/>`),Tc=H(`<label class="svelte-gr1w3a"><span> <!></span> <!></label>`),Ec=H(`<button class="x svelte-gr1w3a" type="button" aria-label="Close"><!></button> <h2 id="command-title" class="svelte-gr1w3a"> </h2> <!> <form class="svelte-gr1w3a"><!> <p class="error svelte-gr1w3a" role="alert"> </p> <div class="acts svelte-gr1w3a"><button type="button" class="svelte-gr1w3a">Cancel</button> <button type="submit"> </button></div></form>`,1),Dc=H(`<dialog aria-labelledby="command-title" class="svelte-gr1w3a"><!></dialog>`);function Oc(e,t){k(t,!0);let n=M(void 0),r=M(null),i=M(pn({})),a=M(``),o=M(!1);function s(e){N(r,e),N(i,Object.fromEntries((e.command.args??[]).map(e=>[e.name,e.choices?.[0]??``])),!0),N(a,``),z(n)?.showModal()}let c=async e=>{e.preventDefault(),z(r)&&(N(o,!0),N(a,await vc(z(r),z(i))??``,!0),N(o,!1),z(a)||z(n)?.close())};var l={open:s},u=Dc(),d=P(u),f=e=>{let t=j(()=>z(r));var s=Ec(),l=F(s);X(P(l),{get of(){return to},size:14}),O(l);var u=L(l,2),d=I(u),f=L(u,2),p=e=>{var n=bc(),r=I(n,!0);R(()=>W(r,z(t).command.confirm)),U(e,n)};G(f,e=>{z(t).command.confirm&&e(p)});var m=L(f,2),h=P(m);K(h,17,()=>z(t).command.args??[],e=>e.name,(e,t)=>{var n=Tc(),r=P(n),a=P(r,!0),o=L(a),s=e=>{U(e,xc())};G(o,e=>{z(t).required||e(s)}),O(r);var c=L(r,2),l=e=>{var n=Cc();K(n,20,()=>z(t).choices??[],e=>e,(e,t)=>{var n=Sc(),r=I(n,!0),i={};R(()=>{W(r,t),i!==(i=t)&&(n.value=(n.__value=i)??``)}),U(e,n)}),O(n),ta(n),na(n,()=>z(i)[z(t).name],e=>z(i)[z(t).name]=e),U(e,n)},u=e=>{var n=wc();ma(n),R(()=>{n.required=!!z(t).required,q(n,`inputmode`,z(t).type===`number`?`decimal`:void 0),q(n,`pattern`,z(t).type===`number`?`-?\\d+(\\.\\d+)?`:void 0)}),Sa(n,()=>z(i)[z(t).name],e=>z(i)[z(t).name]=e),U(e,n)};G(c,e=>{z(t).type===`choice`?e(l):e(u,-1)}),O(n),R(()=>W(a,z(t).label??z(t).name)),U(e,n)});var g=L(h,2),_=I(g,!0),v=L(g,2),y=P(v),b=L(y,2);let x;var S=I(b,!0);O(v),O(m),R(()=>{W(d,`${z(t).command.label??``} on ${z(t).appName??``}`),W(_,z(a)),x=Ji(b,1,`go svelte-gr1w3a`,null,x,{danger:!!z(t).command.confirm}),b.disabled=z(o),W(S,z(t).command.label)}),V(`click`,l,()=>z(n)?.close()),B(`submit`,m,c),V(`click`,y,()=>z(n)?.close()),U(e,s)};return G(d,e=>{z(r)&&e(f)}),O(u),Ma(u,e=>N(n,e),()=>z(n)),U(e,u),A(l)}Zr([`click`]);var kc=new Set([`$$slots`,`$$events`,`$$legacy`]);function Ac(e,t){let n=J(t,kc),r={name:`panel-left`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}],[`path`,{d:`M9 3v18`}]],aliases:[`sidebar`]};$a(e,Ba(()=>n,{get icon(){return r}}))}var jc=new Set([`$$slots`,`$$events`,`$$legacy`]);function Mc(e,t){let n=J(t,jc),r={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}var Nc=new Set([`$$slots`,`$$events`,`$$legacy`]);function Pc(e,t){let n=J(t,Nc),r={name:`settings`,size:24,node:[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`}],[`circle`,{cx:`12`,cy:`12`,r:`3`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}function Fc(e,t){let n=Y(t,`size`,3,14);X(e,{get of(){return Pc},get size(){return n()}})}var Ic=H(`<span class="cmd nodrag nopan svelte-1mrkr86"><code class="svelte-1mrkr86"> </code> <button type="button" title="Copy this command" class="svelte-1mrkr86"> </button></span>`);function Lc(e,t){k(t,!0);let n=M(!1),r=async()=>{await navigator.clipboard.writeText(t.command).then(()=>!0,()=>!1)?(N(n,!0),setTimeout(()=>N(n,!1),1500)):$.show(`Copy is blocked here. Select the command and copy it.`,`warning`)};var i=Ic(),a=P(i),o=I(a,!0),s=L(a,2),c=I(s,!0);O(i),R(()=>{W(o,t.command),q(s,`aria-label`,t.label),W(c,z(n)?`Copied`:`Copy`)}),V(`click`,s,r),U(e,i),A()}Zr([`click`]);var Rc={value:()=>{}};function zc(){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 Bc(n)}function Bc(e){this._=e}function Vc(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}})}Bc.prototype=zc.prototype={constructor:Bc,on:function(e,t){var n=this._,r=Vc(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=Hc(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]=Uc(n[i],e.name,t);else if(t==null)for(i in n)n[i]=Uc(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 Bc(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 Hc(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function Uc(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=Rc,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var Wc={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 Gc(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),Wc.hasOwnProperty(t)?{space:Wc[t],local:e}:e}function Kc(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 qc(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Jc(e){var t=Gc(e);return(t.local?qc:Kc)(t)}function Yc(){}function Xc(e){return e==null?Yc:function(){return this.querySelector(e)}}function Zc(e){typeof e!=`function`&&(e=Xc(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 zu(r,this._parents)}function Qc(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function $c(){return[]}function el(e){return e==null?$c:function(){return this.querySelectorAll(e)}}function tl(e){return function(){return Qc(e.apply(this,arguments))}}function nl(e){e=typeof e==`function`?tl(e):el(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 zu(r,i)}function rl(e){return function(){return this.matches(e)}}function il(e){return function(t){return t.matches(e)}}var al=Array.prototype.find;function ol(e){return function(){return al.call(this.children,e)}}function sl(){return this.firstElementChild}function cl(e){return this.select(e==null?sl:ol(typeof e==`function`?e:il(e)))}var ll=Array.prototype.filter;function ul(){return Array.from(this.children)}function dl(e){return function(){return ll.call(this.children,e)}}function fl(e){return this.selectAll(e==null?ul:dl(typeof e==`function`?e:il(e)))}function pl(e){typeof e!=`function`&&(e=rl(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 zu(r,this._parents)}function ml(e){return Array(e.length)}function hl(){return new zu(this._enter||this._groups.map(ml),this._parents)}function gl(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}gl.prototype={constructor:gl,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 _l(e){return function(){return e}}function vl(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 gl(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function yl(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 gl(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function bl(e){return e.__data__}function xl(e,t){if(!arguments.length)return Array.from(this,bl);var n=t?yl:vl,r=this._parents,i=this._groups;typeof e!=`function`&&(e=_l(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=Sl(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 zu(o,r),o._enter=s,o._exit=c,o}function Sl(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function Cl(){return new zu(this._exit||this._groups.map(ml),this._parents)}function wl(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 Tl(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 zu(s,this._parents)}function El(){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 Dl(e){e||=Ol;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 zu(i,this._parents).order()}function Ol(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function kl(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Al(){return Array.from(this)}function jl(){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 Ml(){let e=0;for(let t of this)++e;return e}function Nl(){return!this.node()}function Pl(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 Fl(e){return function(){this.removeAttribute(e)}}function Il(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Ll(e,t){return function(){this.setAttribute(e,t)}}function Rl(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function zl(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Bl(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 Vl(e,t){var n=Gc(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?Il:Fl:typeof t==`function`?n.local?Bl:zl:n.local?Rl:Ll)(n,t))}function Hl(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Ul(e){return function(){this.style.removeProperty(e)}}function Wl(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Gl(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function Kl(e,t,n){return arguments.length>1?this.each((t==null?Ul:typeof t==`function`?Gl:Wl)(e,t,n??``)):ql(this.node(),e)}function ql(e,t){return e.style.getPropertyValue(t)||Hl(e).getComputedStyle(e,null).getPropertyValue(t)}function Jl(e){return function(){delete this[e]}}function Yl(e,t){return function(){this[e]=t}}function Xl(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Zl(e,t){return arguments.length>1?this.each((t==null?Jl:typeof t==`function`?Xl:Yl)(e,t)):this.node()[e]}function Ql(e){return e.trim().split(/^|\s+/)}function $l(e){return e.classList||new eu(e)}function eu(e){this._node=e,this._names=Ql(e.getAttribute(`class`)||``)}eu.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 tu(e,t){for(var n=$l(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function nu(e,t){for(var n=$l(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function ru(e){return function(){tu(this,e)}}function iu(e){return function(){nu(this,e)}}function au(e,t){return function(){(t.apply(this,arguments)?tu:nu)(this,e)}}function ou(e,t){var n=Ql(e+``);if(arguments.length<2){for(var r=$l(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?au:t?ru:iu)(n,t))}function su(){this.textContent=``}function cu(e){return function(){this.textContent=e}}function lu(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function uu(e){return arguments.length?this.each(e==null?su:(typeof e==`function`?lu:cu)(e)):this.node().textContent}function du(){this.innerHTML=``}function fu(e){return function(){this.innerHTML=e}}function pu(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function mu(e){return arguments.length?this.each(e==null?du:(typeof e==`function`?pu:fu)(e)):this.node().innerHTML}function hu(){this.nextSibling&&this.parentNode.appendChild(this)}function gu(){return this.each(hu)}function _u(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function vu(){return this.each(_u)}function yu(e){var t=typeof e==`function`?e:Jc(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function bu(){return null}function xu(e,t){var n=typeof e==`function`?e:Jc(e),r=t==null?bu:typeof t==`function`?t:Xc(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Su(){var e=this.parentNode;e&&e.removeChild(this)}function Cu(){return this.each(Su)}function wu(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Tu(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Eu(e){return this.select(e?Tu:wu)}function Du(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function Ou(e){return function(t){e.call(this,t,this.__data__)}}function ku(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 Au(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 ju(e,t,n){return function(){var r=this.__on,i,a=Ou(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 Mu(e,t,n){var r=ku(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?ju:Au,i=0;i<a;++i)this.each(s(r[i],t,n));return this}}function Nu(e,t,n){var r=Hl(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 Pu(e,t){return function(){return Nu(this,e,t)}}function Fu(e,t){return function(){return Nu(this,e,t.apply(this,arguments))}}function Iu(e,t){return this.each((typeof t==`function`?Fu:Pu)(e,t))}function*Lu(){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 Ru=[null];function zu(e,t){this._groups=e,this._parents=t}function Bu(){return new zu([[document.documentElement]],Ru)}function Vu(){return this}zu.prototype=Bu.prototype={constructor:zu,select:Zc,selectAll:nl,selectChild:cl,selectChildren:fl,filter:pl,data:xl,enter:hl,exit:Cl,join:wl,merge:Tl,selection:Vu,order:El,sort:Dl,call:kl,nodes:Al,node:jl,size:Ml,empty:Nl,each:Pl,attr:Vl,style:Kl,property:Zl,classed:ou,text:uu,html:mu,raise:gu,lower:vu,append:yu,insert:xu,remove:Cu,clone:Eu,datum:Du,on:Mu,dispatch:Iu,[Symbol.iterator]:Lu};function Hu(e){return typeof e==`string`?new zu([[document.querySelector(e)]],[document.documentElement]):new zu([[e]],Ru)}function Uu(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Wu(e,t){if(e=Uu(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 Gu={passive:!1},Ku={capture:!0,passive:!1};function qu(e){e.stopImmediatePropagation()}function Ju(e){e.preventDefault(),e.stopImmediatePropagation()}function Yu(e){var t=e.document.documentElement,n=Hu(e).on(`dragstart.drag`,Ju,Ku);`onselectstart`in t?n.on(`selectstart.drag`,Ju,Ku):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect=`none`)}function Xu(e,t){var n=e.document.documentElement,r=Hu(e).on(`dragstart.drag`,null);t&&(r.on(`click.drag`,Ju,Ku),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 Zu=e=>()=>e;function Qu(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}})}Qu.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function $u(e){return!e.ctrlKey&&!e.button}function ed(){return this.parentNode}function td(e,t){return t??{x:e.x,y:e.y}}function nd(){return navigator.maxTouchPoints||`ontouchstart`in this}function rd(){var e=$u,t=ed,n=td,r=nd,i={},a=zc(`start`,`drag`,`end`),o=0,s,c,l,u,d=0;function f(e){e.on(`mousedown.drag`,p).filter(r).on(`touchstart.drag`,g).on(`touchmove.drag`,_,Gu).on(`touchend.drag touchcancel.drag`,v).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=y(this,t.call(this,n,r),n,r,`mouse`);i&&(Hu(n.view).on(`mousemove.drag`,m,Ku).on(`mouseup.drag`,h,Ku),Yu(n.view),qu(n),l=!1,s=n.clientX,c=n.clientY,i(`start`,n))}}function m(e){if(Ju(e),!l){var t=e.clientX-s,n=e.clientY-c;l=t*t+n*n>d}i.mouse(`drag`,e)}function h(e){Hu(e.view).on(`mousemove.drag mouseup.drag`,null),Xu(e.view,l),Ju(e),i.mouse(`end`,e)}function g(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=y(this,a,n,r,i[s].identifier,i[s]))&&(qu(n),c(`start`,n,i[s]))}function _(e){for(var t=e.changedTouches,n=t.length,r=0,a;r<n;++r)(a=i[t[r].identifier])&&(Ju(e),a(`drag`,e,t[r]))}function v(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])&&(qu(e),a(`end`,e,t[r]))}function y(e,t,r,s,c,l){var u=a.copy(),d=Wu(l||r,t),p,m,h;if((h=n.call(e,new Qu(`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=Wu(l||a,t),_=o}u.call(r,e,new Qu(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:Zu(!!t),f):e},f.container=function(e){return arguments.length?(t=typeof e==`function`?e:Zu(e),f):t},f.subject=function(e){return arguments.length?(n=typeof e==`function`?e:Zu(e),f):n},f.touchable=function(e){return arguments.length?(r=typeof e==`function`?e:Zu(!!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 id(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function ad(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function od(){}var sd=.7,cd=1/sd,ld=`\\s*([+-]?\\d+)\\s*`,ud=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,dd=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,fd=/^#([0-9a-f]{3,8})$/,pd=RegExp(`^rgb\\(${ld},${ld},${ld}\\)$`),md=RegExp(`^rgb\\(${dd},${dd},${dd}\\)$`),hd=RegExp(`^rgba\\(${ld},${ld},${ld},${ud}\\)$`),gd=RegExp(`^rgba\\(${dd},${dd},${dd},${ud}\\)$`),_d=RegExp(`^hsl\\(${ud},${dd},${dd}\\)$`),vd=RegExp(`^hsla\\(${ud},${dd},${dd},${ud}\\)$`),yd={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};id(od,wd,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:bd,formatHex:bd,formatHex8:xd,formatHsl:Sd,formatRgb:Cd,toString:Cd});function bd(){return this.rgb().formatHex()}function xd(){return this.rgb().formatHex8()}function Sd(){return Ld(this).formatHsl()}function Cd(){return this.rgb().formatRgb()}function wd(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=fd.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Td(t):n===3?new kd(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Ed(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Ed(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=pd.exec(e))?new kd(t[1],t[2],t[3],1):(t=md.exec(e))?new kd(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=hd.exec(e))?Ed(t[1],t[2],t[3],t[4]):(t=gd.exec(e))?Ed(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=_d.exec(e))?Id(t[1],t[2]/100,t[3]/100,1):(t=vd.exec(e))?Id(t[1],t[2]/100,t[3]/100,t[4]):yd.hasOwnProperty(e)?Td(yd[e]):e===`transparent`?new kd(NaN,NaN,NaN,0):null}function Td(e){return new kd(e>>16&255,e>>8&255,e&255,1)}function Ed(e,t,n,r){return r<=0&&(e=t=n=NaN),new kd(e,t,n,r)}function Dd(e){return e instanceof od||(e=wd(e)),e?(e=e.rgb(),new kd(e.r,e.g,e.b,e.opacity)):new kd}function Od(e,t,n,r){return arguments.length===1?Dd(e):new kd(e,t,n,r??1)}function kd(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}id(kd,Od,ad(od,{brighter(e){return e=e==null?cd:cd**+e,new kd(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?sd:sd**+e,new kd(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new kd(Pd(this.r),Pd(this.g),Pd(this.b),Nd(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:Ad,formatHex:Ad,formatHex8:jd,formatRgb:Md,toString:Md}));function Ad(){return`#${Fd(this.r)}${Fd(this.g)}${Fd(this.b)}`}function jd(){return`#${Fd(this.r)}${Fd(this.g)}${Fd(this.b)}${Fd((isNaN(this.opacity)?1:this.opacity)*255)}`}function Md(){let e=Nd(this.opacity);return`${e===1?`rgb(`:`rgba(`}${Pd(this.r)}, ${Pd(this.g)}, ${Pd(this.b)}${e===1?`)`:`, ${e})`}`}function Nd(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Pd(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Fd(e){return e=Pd(e),(e<16?`0`:``)+e.toString(16)}function Id(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new zd(e,t,n,r)}function Ld(e){if(e instanceof zd)return new zd(e.h,e.s,e.l,e.opacity);if(e instanceof od||(e=wd(e)),!e)return new zd;if(e instanceof zd)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 zd(o,s,c,e.opacity)}function Rd(e,t,n,r){return arguments.length===1?Ld(e):new zd(e,t,n,r??1)}function zd(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}id(zd,Rd,ad(od,{brighter(e){return e=e==null?cd:cd**+e,new zd(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?sd:sd**+e,new zd(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 kd(Hd(e>=240?e-240:e+120,i,r),Hd(e,i,r),Hd(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new zd(Bd(this.h),Vd(this.s),Vd(this.l),Nd(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=Nd(this.opacity);return`${e===1?`hsl(`:`hsla(`}${Bd(this.h)}, ${Vd(this.s)*100}%, ${Vd(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function Bd(e){return e=(e||0)%360,e<0?e+360:e}function Vd(e){return Math.max(0,Math.min(1,e||0))}function Hd(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 Ud=e=>()=>e;function Wd(e,t){return function(n){return e+n*t}}function Gd(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function Kd(e){return(e=+e)==1?qd:function(t,n){return n-t?Gd(t,n,e):Ud(isNaN(t)?n:t)}}function qd(e,t){var n=t-e;return n?Wd(e,n):Ud(isNaN(e)?t:e)}var Jd=(function e(t){var n=Kd(t);function r(e,t){var r=n((e=Od(e)).r,(t=Od(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=qd(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 Yd(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 Xd(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Zd(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]=sf(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 Qd(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function $d(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function ef(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]=sf(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var tf=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,nf=new RegExp(tf.source,`g`);function rf(e){return function(){return e}}function af(e){return function(t){return e(t)+``}}function of(e,t){var n=tf.lastIndex=nf.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=tf.exec(e))&&(i=nf.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:$d(r,i)})),n=nf.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?af(c[0].x):rf(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 sf(e,t){var n=typeof t,r;return t==null||n===`boolean`?Ud(t):(n===`number`?$d:n===`string`?(r=wd(t))?(t=r,Jd):of:t instanceof wd?Jd:t instanceof Date?Qd:Xd(t)?Yd:Array.isArray(t)?Zd:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?ef:$d)(e,t)}var cf=180/Math.PI,lf={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function uf(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)*cf,skewX:Math.atan(c)*cf,scaleX:o,scaleY:s}}var df;function ff(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?lf:uf(t.a,t.b,t.c,t.d,t.e,t.f)}function pf(e){return e==null||(df||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),df.setAttribute(`transform`,e),!(e=df.transform.baseVal.consolidate()))?lf:(e=e.matrix,uf(e.a,e.b,e.c,e.d,e.e,e.f))}function mf(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:$d(e,i)},{i:c-2,x:$d(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:$d(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:$d(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:$d(e,n)},{i:s-2,x:$d(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 hf=mf(ff,`px, `,`px)`,`deg)`),gf=mf(pf,`, `,`)`,`)`),_f=1e-12;function vf(e){return((e=Math.exp(e))+1/e)/2}function yf(e){return((e=Math.exp(e))-1/e)/2}function bf(e){return((e=Math.exp(2*e))-1)/(e+1)}var xf=(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<_f)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=vf(y),c=s/(n*g)*(i*bf(t*r+y)-yf(y));return[a+c*d,o+c*f,s*i/vf(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),Sf=0,Cf=0,wf=0,Tf=1e3,Ef,Df,Of=0,kf=0,Af=0,jf=typeof performance==`object`&&performance.now?performance:Date,Mf=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Nf(){return kf||=(Mf(Pf),jf.now()+Af)}function Pf(){kf=0}function Ff(){this._call=this._time=this._next=null}Ff.prototype=If.prototype={constructor:Ff,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?Nf():+n)+(t==null?0:+t),!this._next&&Df!==this&&(Df?Df._next=this:Ef=this,Df=this),this._call=e,this._time=n,Vf()},stop:function(){this._call&&(this._call=null,this._time=1/0,Vf())}};function If(e,t,n){var r=new Ff;return r.restart(e,t,n),r}function Lf(){Nf(),++Sf;for(var e=Ef,t;e;)(t=kf-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Sf}function Rf(){kf=(Of=jf.now())+Af,Sf=Cf=0;try{Lf()}finally{Sf=0,Bf(),kf=0}}function zf(){var e=jf.now(),t=e-Of;t>Tf&&(Af-=t,Of=e)}function Bf(){for(var e,t=Ef,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:Ef=n);Df=e,Vf(r)}function Vf(e){Sf||(Cf&&=clearTimeout(Cf),e-kf>24?(e<1/0&&(Cf=setTimeout(Rf,e-jf.now()-Af)),wf&&=clearInterval(wf)):(wf||=(Of=jf.now(),setInterval(zf,Tf)),Sf=1,Mf(Rf)))}function Hf(e,t,n){var r=new Ff;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var Uf=zc(`start`,`end`,`cancel`,`interrupt`),Wf=[];function Gf(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Yf(e,n,{name:t,index:r,group:i,on:Uf,tween:Wf,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function Kf(e,t){var n=Jf(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function qf(e,t){var n=Jf(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function Jf(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function Yf(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=If(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 Hf(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(Hf(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 Xf(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 Zf(e){return this.each(function(){Xf(this,e)})}function Qf(e,t){var n,r;return function(){var i=qf(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 $f(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=qf(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 ep(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=Jf(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?Qf:$f)(n,e,t))}function tp(e,t,n){var r=e._id;return e.each(function(){var e=qf(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return Jf(e,r).value[t]}}function np(e,t){var n;return(typeof t==`number`?$d:t instanceof wd?Jd:(n=wd(t))?(t=n,Jd):of)(e,t)}function rp(e){return function(){this.removeAttribute(e)}}function ip(e){return function(){this.removeAttributeNS(e.space,e.local)}}function ap(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 op(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 sp(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 cp(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 lp(e,t){var n=Gc(e),r=n===`transform`?gf:np;return this.attrTween(e,typeof t==`function`?(n.local?cp:sp)(n,r,tp(this,`attr.`+e,t)):t==null?(n.local?ip:rp)(n):(n.local?op:ap)(n,r,t))}function up(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function dp(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function fp(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&dp(e,i)),n}return i._value=t,i}function pp(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&up(e,i)),n}return i._value=t,i}function mp(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=Gc(e);return this.tween(n,(r.local?fp:pp)(r,t))}function hp(e,t){return function(){Kf(this,e).delay=+t.apply(this,arguments)}}function gp(e,t){return t=+t,function(){Kf(this,e).delay=t}}function _p(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?hp:gp)(t,e)):Jf(this.node(),t).delay}function vp(e,t){return function(){qf(this,e).duration=+t.apply(this,arguments)}}function yp(e,t){return t=+t,function(){qf(this,e).duration=t}}function bp(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?vp:yp)(t,e)):Jf(this.node(),t).duration}function xp(e,t){if(typeof t!=`function`)throw Error();return function(){qf(this,e).ease=t}}function Sp(e){var t=this._id;return arguments.length?this.each(xp(t,e)):Jf(this.node(),t).ease}function Cp(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();qf(this,e).ease=n}}function wp(e){if(typeof e!=`function`)throw Error();return this.each(Cp(this._id,e))}function Tp(e){typeof e!=`function`&&(e=rl(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 em(r,this._parents,this._name,this._id)}function Ep(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 em(o,this._parents,this._name,this._id)}function Dp(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 Op(e,t,n){var r,i,a=Dp(t)?Kf:qf;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function kp(e,t){var n=this._id;return arguments.length<2?Jf(this.node(),n).on.on(e):this.each(Op(n,e,t))}function Ap(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function jp(){return this.on(`end.remove`,Ap(this._id))}function Mp(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=Xc(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,Gf(l[f],t,n,f,l,Jf(u,n)));return new em(a,this._parents,t,n)}function Np(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=el(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=Jf(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&Gf(p,t,n,h,f,m);a.push(f),o.push(u)}return new em(a,o,t,n)}var Pp=Bu.prototype.constructor;function Fp(){return new Pp(this._groups,this._parents)}function Ip(e,t){var n,r,i;return function(){var a=ql(this,e),o=(this.style.removeProperty(e),ql(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function Lp(e){return function(){this.style.removeProperty(e)}}function Rp(e,t,n){var r,i=n+``,a;return function(){var o=ql(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function zp(e,t,n){var r,i,a;return function(){var o=ql(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),ql(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function Bp(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=qf(this,e),l=c.on,u=c.value[a]==null?s||=Lp(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function Vp(e,t,n){var r=(e+=``)==`transform`?hf:np;return t==null?this.styleTween(e,Ip(e,r)).on(`end.style.`+e,Lp(e)):typeof t==`function`?this.styleTween(e,zp(e,r,tp(this,`style.`+e,t))).each(Bp(this._id,e)):this.styleTween(e,Rp(e,r,t),n).on(`end.style.`+e,null)}function Hp(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Up(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&Hp(e,a,n)),r}return a._value=t,a}function Wp(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,Up(e,t,n??``))}function Gp(e){return function(){this.textContent=e}}function Kp(e){return function(){var t=e(this);this.textContent=t??``}}function qp(e){return this.tween(`text`,typeof e==`function`?Kp(tp(this,`text`,e)):Gp(e==null?``:e+``))}function Jp(e){return function(t){this.textContent=e.call(this,t)}}function Yp(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&Jp(r)),t}return r._value=e,r}function Xp(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,Yp(e))}function Zp(){for(var e=this._name,t=this._id,n=tm(),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=Jf(c,t);Gf(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new em(r,this._parents,e,n)}function Qp(){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=qf(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 $p=0;function em(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function tm(){return++$p}var nm=Bu.prototype;em.prototype={constructor:em,select:Mp,selectAll:Np,selectChild:nm.selectChild,selectChildren:nm.selectChildren,filter:Tp,merge:Ep,selection:Fp,transition:Zp,call:nm.call,nodes:nm.nodes,node:nm.node,size:nm.size,empty:nm.empty,each:nm.each,on:kp,attr:lp,attrTween:mp,style:Vp,styleTween:Wp,text:qp,textTween:Xp,remove:jp,tween:ep,delay:_p,duration:bp,ease:Sp,easeVarying:wp,end:Qp,[Symbol.iterator]:nm[Symbol.iterator]};function rm(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var im={time:null,delay:0,duration:250,ease:rm};function am(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function om(e){var t,n;e instanceof em?(t=e._id,e=e._name):(t=tm(),(n=im).time=Nf(),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])&&Gf(c,e,t,l,o,n||am(c,t));return new em(r,this._parents,e,t)}Bu.prototype.interrupt=Zf,Bu.prototype.transition=om;var sm=e=>()=>e;function cm(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 lm(e,t,n){this.k=e,this.x=t,this.y=n}lm.prototype={constructor:lm,scale:function(e){return e===1?this:new lm(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new lm(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 um=new lm(1,0,0);dm.prototype=lm.prototype;function dm(e){for(;!e.__zoom;)if(!(e=e.parentNode))return um;return e.__zoom}function fm(e){e.stopImmediatePropagation()}function pm(e){e.preventDefault(),e.stopImmediatePropagation()}function mm(e){return(!e.ctrlKey||e.type===`wheel`)&&!e.button}function hm(){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 gm(){return this.__zoom||um}function _m(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function vm(){return navigator.maxTouchPoints||`ontouchstart`in this}function ym(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 bm(){var e=mm,t=hm,n=ym,r=_m,i=vm,a=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],s=250,c=xf,l=zc(`start`,`zoom`,`end`),u,d,f,p=500,m=150,h=0,g=10;function _(e){e.property(`__zoom`,gm).on(`wheel.zoom`,w,{passive:!1}).on(`mousedown.zoom`,ee).on(`dblclick.zoom`,T).filter(i).on(`touchstart.zoom`,te).on(`touchmove.zoom`,E).on(`touchend.zoom touchcancel.zoom`,ne).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}_.transform=function(e,t,n,r){var i=e.selection?e.selection():e;i.property(`__zoom`,gm),e===i?i.interrupt().each(function(){S(this,arguments).event(r).start().zoom(null,typeof t==`function`?t.apply(this,arguments):t).end()}):x(e,t,n,r)},_.scaleBy=function(e,t,n,r){_.scaleTo(e,function(){return this.__zoom.k*(typeof t==`function`?t.apply(this,arguments):t)},n,r)},_.scaleTo=function(e,r,i,a){_.transform(e,function(){var e=t.apply(this,arguments),a=this.__zoom,s=i==null?b(e):typeof i==`function`?i.apply(this,arguments):i,c=a.invert(s),l=typeof r==`function`?r.apply(this,arguments):r;return n(y(v(a,l),s,c),e,o)},i,a)},_.translateBy=function(e,r,i,a){_.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)},_.translateTo=function(e,r,i,a,s){_.transform(e,function(){var e=t.apply(this,arguments),s=this.__zoom,c=a==null?b(e):typeof a==`function`?a.apply(this,arguments):a;return n(um.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 v(e,t){return t=Math.max(a[0],Math.min(a[1],t)),t===e.k?e:new lm(t,e.x,e.y)}function y(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 lm(e.k,r,i)}function b(e){return[(+e[0][0]+ +e[1][0])/2,(+e[0][1]+ +e[1][1])/2]}function x(e,n,r,i){e.on(`start.zoom`,function(){S(this,arguments).event(i).start()}).on(`interrupt.zoom end.zoom`,function(){S(this,arguments).event(i).end()}).tween(`zoom`,function(){var e=this,a=arguments,o=S(e,a).event(i),s=t.apply(e,a),l=r==null?b(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 lm(n,l[0]-t[0]*n,l[1]-t[1]*n)}o.zoom(null,e)}})}function S(e,t,n){return!n&&e.__zooming||new C(e,t)}function C(e,n){this.that=e,this.args=n,this.active=0,this.sourceEvent=null,this.extent=t.apply(e,n),this.taps=0}C.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=Hu(this.that).datum();l.call(e,this.that,new cm(e,{sourceEvent:this.sourceEvent,target:_,type:e,transform:this.that.__zoom,dispatch:l}),t)}};function w(t,...i){if(!e.apply(this,arguments))return;var s=S(this,i).event(t),c=this.__zoom,l=Math.max(a[0],Math.min(a[1],c.k*2**r.apply(this,arguments))),u=Wu(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)],Xf(this),s.start();pm(t),s.wheel=setTimeout(d,m),s.zoom(`mouse`,n(y(v(c,l),s.mouse[0],s.mouse[1]),s.extent,o));function d(){s.wheel=null,s.end()}}function ee(t,...r){if(f||!e.apply(this,arguments))return;var i=t.currentTarget,a=S(this,r,!0).event(t),s=Hu(t.view).on(`mousemove.zoom`,d,!0).on(`mouseup.zoom`,p,!0),c=Wu(t,i),l=t.clientX,u=t.clientY;Yu(t.view),fm(t),a.mouse=[c,this.__zoom.invert(c)],Xf(this),a.start();function d(e){if(pm(e),!a.moved){var t=e.clientX-l,r=e.clientY-u;a.moved=t*t+r*r>h}a.event(e).zoom(`mouse`,n(y(a.that.__zoom,a.mouse[0]=Wu(e,i),a.mouse[1]),a.extent,o))}function p(e){s.on(`mousemove.zoom mouseup.zoom`,null),Xu(e.view,a.moved),pm(e),a.event(e).end()}}function T(r,...i){if(e.apply(this,arguments)){var a=this.__zoom,c=Wu(r.changedTouches?r.changedTouches[0]:r,this),l=a.invert(c),u=a.k*(r.shiftKey?.5:2),d=n(y(v(a,u),c,l),t.apply(this,i),o);pm(r),s>0?Hu(this).transition().duration(s).call(x,d,c,r):Hu(this).call(_.transform,d,c,r)}}function te(t,...n){if(e.apply(this,arguments)){var r=t.touches,i=r.length,a=S(this,n,t.changedTouches.length===i).event(t),o,s,c,l;for(fm(t),s=0;s<i;++s)c=r[s],l=Wu(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)),Xf(this),a.start())}}function E(e,...t){if(this.__zooming){var r=S(this,t).event(e),i=e.changedTouches,a=i.length,s,c,l,u;for(pm(e),s=0;s<a;++s)c=i[s],l=Wu(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=v(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(y(c,l,u),r.extent,o))}}function ne(e,...t){if(this.__zooming){var n=S(this,t).event(e),r=e.changedTouches,i=r.length,a,o;for(fm(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=Wu(o,this),Math.hypot(d[0]-o[0],d[1]-o[1])<g)){var s=Hu(this).on(`dblclick.zoom`);s&&s.apply(this,arguments)}}}return _.wheelDelta=function(e){return arguments.length?(r=typeof e==`function`?e:sm(+e),_):r},_.filter=function(t){return arguments.length?(e=typeof t==`function`?t:sm(!!t),_):e},_.touchable=function(e){return arguments.length?(i=typeof e==`function`?e:sm(!!e),_):i},_.extent=function(e){return arguments.length?(t=typeof e==`function`?e:sm([[+e[0][0],+e[0][1]],[+e[1][0],+e[1][1]]]),_):t},_.scaleExtent=function(e){return arguments.length?(a[0]=+e[0],a[1]=+e[1],_):[a[0],a[1]]},_.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],_):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},_.constrain=function(e){return arguments.length?(n=e,_):n},_.duration=function(e){return arguments.length?(s=+e,_):s},_.interpolate=function(e){return arguments.length?(c=e,_):c},_.on=function(){var e=l.on.apply(l,arguments);return e===l?_:e},_.clickDistance=function(e){return arguments.length?(h=(e=+e)*e,_):Math.sqrt(h)},_.tapDistance=function(e){return arguments.length?(g=+e,_):g},_}var xm={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.`},Sm=[[-1/0,-1/0],[1/0,1/0]],Cm=[`Enter`,` `,`Escape`],wm={"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`},Tm;(function(e){e.Strict=`strict`,e.Loose=`loose`})(Tm||={});var Em;(function(e){e.Free=`free`,e.Vertical=`vertical`,e.Horizontal=`horizontal`})(Em||={});var Dm;(function(e){e.Partial=`partial`,e.Full=`full`})(Dm||={});var Om={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null},km;(function(e){e.Bezier=`default`,e.Straight=`straight`,e.Step=`step`,e.SmoothStep=`smoothstep`,e.SimpleBezier=`simplebezier`})(km||={});var Am;(function(e){e.Arrow=`arrow`,e.ArrowClosed=`arrowclosed`})(Am||={});var jm;(function(e){e.Left=`left`,e.Top=`top`,e.Right=`right`,e.Bottom=`bottom`})(jm||={});var Mm={[jm.Left]:jm.Right,[jm.Right]:jm.Left,[jm.Top]:jm.Bottom,[jm.Bottom]:jm.Top},Nm=e=>!!e&&typeof e==`object`&&`id`in e&&`source`in e&&`target`in e,Pm=e=>!!e&&typeof e==`object`&&`id`in e&&`position`in e&&!(`source`in e)&&!(`target`in e),Fm=e=>!!e&&typeof e==`object`&&`id`in e&&`internals`in e&&!(`source`in e)&&!(`target`in e),Im=(e,t=[0,0])=>{let{width:n,height:r}=gh(e),i=e.origin??t,a=n*i[0],o=r*i[1];return{x:e.position.x-a,y:e.position.y-o}},Lm=(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):Fm(r)?r:t.nodeLookup.get(r.id)),a?(n=!0,Xm(e,eh(a,t.nodeOrigin))):e},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return n?Qm(r):{x:0,y:0,width:0,height:0}},Rm=(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=Xm(n,eh(e)),r=!0)}),r?Qm(n):{x:0,y:0,width:0,height:0}},zm=(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=nh(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},Bm=(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 Vm(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}=gh(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 Hm({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:a},o){if(e.size===0)return!0;let s=ph(Rm(Vm(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 Um({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`,xm.error005());else{let{width:e,height:t}=gh(s);e&&t&&(d=[[c,l],[c+e,l+t]])}}else s&&hh(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=hh(d)?Km(t,d,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&a?.(`015`,xm.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 Wm({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=Bm(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 Gm=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Km=(e={x:0,y:0},t,n)=>({x:Gm(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Gm(e.y,t[0][1],t[1][1]-(n?.height??0))});function qm(e,t,n){let{width:r,height:i}=gh(n),{x:a,y:o}=n.internals.positionAbsolute;return Km(e,[[a,o],[a+r,o+i]],t)}var Jm=(e,t,n)=>e<t?Gm(Math.abs(e-t),1,t)/t:e>n?-Gm(Math.abs(e-n),1,t)/t:0,Ym=(e,t,n=15,r=40)=>[Jm(e.x,r,t.width-r)*n,Jm(e.y,r,t.height-r)*n],Xm=(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)}),Zm=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),Qm=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),$m=(e,t=[0,0])=>{let{x:n,y:r}=Fm(e)?e.internals.positionAbsolute:Im(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}},eh=(e,t=[0,0])=>{let{x:n,y:r}=Fm(e)?e.internals.positionAbsolute:Im(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)}},th=(e,t)=>Qm(Xm(Zm(e),Zm(t))),nh=(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)},rh=(e,t)=>nh(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),ih=e=>ah(e.width)&&ah(e.height)&&ah(e.x)&&ah(e.y),ah=e=>!isNaN(e)&&isFinite(e),oh=(e,t)=>(e,t)=>{},sh=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),ch=({x:e,y:t},[n,r,i],a=!1,o=[1,1])=>{let s={x:(e-n)/i,y:(t-r)/i};return a?sh(s,o):s},lh=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function uh(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 dh(e,t,n){if(typeof e==`string`||typeof e==`number`){let r=uh(e,n),i=uh(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e==`object`){let r=uh(e.top??e.y??0,n),i=uh(e.bottom??e.y??0,n),a=uh(e.left??e.x??0,t),o=uh(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 fh(e,t,n,r,i,a){let{x:o,y:s}=lh(e,[t,n,r]),{x:c,y:l}=lh({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 ph=(e,t,n,r,i,a)=>{let o=dh(a,t,n),s=(t-o.x)/e.width,c=(n-o.y)/e.height,l=Gm(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=fh(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}},mh=()=>typeof navigator<`u`&&navigator?.userAgent?.indexOf(`Mac`)>=0;function hh(e){return e!=null&&e!==`parent`}function gh(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function _h(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function vh(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 yh(e){return{...wm,...e||{}}}function bh(e,t){if(!e&&!t)return!0;if(!e||!t||e.size!==t.size)return!1;if(!e.size&&!t.size)return!0;for(let n of e.keys())if(!t.has(n))return!1;return!0}function xh(e,t,n){if(!n)return;let r=[];e.forEach((e,n)=>{t?.has(n)||r.push(e)}),r.length&&n(r)}function Sh(e){return e===null?null:e?`valid`:`invalid`}function Ch(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){let{x:a,y:o}=kh(e),s=ch({x:a-(i?.left??0),y:o-(i?.top??0)},r),{x:c,y:l}=n?sh(s,t):s;return{xSnapped:c,ySnapped:l,...s}}var wh=e=>({width:e.offsetWidth,height:e.offsetHeight}),Th=e=>e?.getRootNode?.()||window?.document,Eh=[`INPUT`,`SELECT`,`TEXTAREA`];function Dh(e){let t=e.composedPath?.()?.[0]||e.target;return t?.nodeType===1?Eh.includes(t.nodeName)||t.hasAttribute(`contenteditable`)||!!t.closest(`.nokey`):!1}var Oh=e=>`clientX`in e,kh=(e,t)=>{let n=Oh(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)}},Ah=(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,...wh(t)}})};function jh({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 Mh(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Nh({pos:e,x1:t,y1:n,x2:r,y2:i,c:a}){switch(e){case jm.Left:return[t-Mh(t-r,a),n];case jm.Right:return[t+Mh(r-t,a),n];case jm.Top:return[t,n-Mh(n-i,a)];case jm.Bottom:return[t,n+Mh(i-n,a)]}}function Ph({sourceX:e,sourceY:t,sourcePosition:n=jm.Bottom,targetX:r,targetY:i,targetPosition:a=jm.Top,curvature:o=.25}){let[s,c]=Nh({pos:n,x1:e,y1:t,x2:r,y2:i,c:o}),[l,u]=Nh({pos:a,x1:r,y1:i,x2:e,y2:t,c:o}),[d,f,p,m]=jh({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 Fh({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 Ih({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 Lh({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){let a=Xm(eh(e),eh(t));return a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1),rh({x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]},Qm(a))>0}var Rh=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||``}-${n}${r||``}`,zh=(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)),Bh=(e,t,n={})=>{if(!e.source||!e.target)return n.onError?.(`006`,xm.error006()),t;let r=n.getEdgeId||Rh,i;return i=Nm(e)?{...e}:{...e,id:r(e)},zh(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function Vh({sourceX:e,sourceY:t,targetX:n,targetY:r}){let[i,a,o,s]=Fh({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,a,o,s]}var Hh={[jm.Left]:{x:-1,y:0},[jm.Right]:{x:1,y:0},[jm.Top]:{x:0,y:-1},[jm.Bottom]:{x:0,y:1}},Uh=({source:e,sourcePosition:t=jm.Bottom,target:n})=>t===jm.Left||t===jm.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},Wh=(e,t)=>Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2);function Gh({source:e,sourcePosition:t=jm.Bottom,target:n,targetPosition:r=jm.Top,center:i,offset:a,stepPosition:o}){let s=Hh[t],c=Hh[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=Uh({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]=Fh({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 Kh(e,t,n,r){let i=Math.min(Wh(e,t)/2,Wh(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 qh({sourceX:e,sourceY:t,sourcePosition:n=jm.Bottom,targetX:r,targetY:i,targetPosition:a=jm.Top,borderRadius:o=5,centerX:s,centerY:c,offset:l=20,stepPosition:u=.5}){let[d,f,p,m,h]=Gh({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+=Kh(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 Jh(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Yh(e){let{sourceNode:t,targetNode:n}=e;if(!Jh(t)||!Jh(n))return null;let r=t.internals.handleBounds||Xh(t.handles),i=n.internals.handleBounds||Xh(n.handles),a=Qh(r?.source??[],e.sourceHandle),o=Qh(e.connectionMode===Tm.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!a||!o)return e.onError?.(`008`,xm.error008(a?`target`:`source`,{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;let s=a?.position||jm.Bottom,c=o?.position||jm.Top,l=Zh(t,a,s),u=Zh(n,o,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:s,targetPosition:c}}function Xh(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 Zh(e,t,n=jm.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??gh(e);if(r)return{x:i+o/2,y:a+s/2};switch(t?.position??n){case jm.Top:return{x:i+o/2,y:a};case jm.Right:return{x:i+o,y:a+s/2};case jm.Bottom:return{x:i+o/2,y:a+s};case jm.Left:return{x:i,y:a+s/2}}}function Qh(e,t){return e&&(t?e.find(e=>e.id===t):e[0])||null}function $h(e,t){return e?typeof e==`string`?e:`${t?`${t}__`:``}${Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`&`)}`:``}function eg(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=$h(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))}function tg(e,t,n,r,i){let a=.5;i===`start`?a=0:i===`end`&&(a=1);let o=[(e.x+e.width*a)*t.zoom+t.x,e.y*t.zoom+t.y-r],s=[-100*a,-100];switch(n){case jm.Right:o=[(e.x+e.width)*t.zoom+t.x+r,(e.y+e.height*a)*t.zoom+t.y],s=[0,-100*a];break;case jm.Bottom:o[1]=(e.y+e.height)*t.zoom+t.y+r,s[1]=0;break;case jm.Left:o=[e.x*t.zoom+t.x-r,(e.y+e.height*a)*t.zoom+t.y],s=[-100,-100*a]}return`translate(${o[0]}px, ${o[1]}px) translate(${s[0]}%, ${s[1]}%)`}var ng=1e3,rg=10,ig={nodeOrigin:[0,0],nodeExtent:Sm,elevateNodesOnSelect:!0,zIndexMode:`basic`,defaults:{}},ag={...ig,checkEquality:!0};function og(e,t){let n={...e};for(let e in t)t[e]!==void 0&&(n[e]=t[e]);return n}function sg(e,t,n){let r=og(ig,n);for(let n of e.values())if(n.parentId)fg(n,e,t,r);else{let e=Km(Im(n,r.nodeOrigin),hh(n.extent)?n.extent:r.nodeExtent,gh(n));n.internals.positionAbsolute=e}}function cg(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 lg(e){return e===`manual`}function ug(e,t,n,r={}){let i=og(ag,r),a={i:0},o=new Map(t),s=i?.elevateNodesOnSelect&&!lg(i.zIndexMode)?ng: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=Km(Im(u,i.nodeOrigin),hh(u.extent)?u.extent:i.nodeExtent,gh(u));e={...i.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:n,handleBounds:cg(u,e),z:pg(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&&fg(e,t,n,r,a),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function dg(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 fg(e,t,n,r,i){let{elevateNodesOnSelect:a,nodeOrigin:o,nodeExtent:s,zIndexMode:c}=og(ig,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}dg(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*rg),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);let{x:d,y:f,z:p}=mg(e,u,o,s,a&&!lg(c)?ng: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 pg(e,t,n){let r=ah(e.zIndex)?e.zIndex:0;return lg(n)?r:r+(e.selected?t:0)}function mg(e,t,n,r,i,a){let{x:o,y:s}=t.internals.positionAbsolute,c=gh(e),l=Im(e,n),u=hh(e.extent)?Km(l,e.extent,c):l,d=Km({x:o+u.x,y:s+u.y},r,c);e.extent===`parent`&&(d=qm(d,c,t));let f=pg(e,i,a),p=t.internals.z??0;return{x:d.x,y:d.y,z:p>=f?p+1:f}}function hg(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=th(a.get(n.parentId)?.expandedRect??$m(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=gh(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 gg(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=wh(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=hh(e.extent)?e.extent:a,{positionAbsolute:h}=e.internals;if(e.parentId&&e.extent===`parent`){let n=t.get(e.parentId);n&&(h=qm(h,s,n))}else m&&(h=Km(h,m,s));let g={...e,measured:s,internals:{...e.internals,positionAbsolute:h,handleBounds:{source:Ah(`source`,r.nodeElement,p,d,e.id),target:Ah(`target`,r.nodeElement,p,d,e.id)}}};t.set(e.id,g),e.parentId&&fg(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:$m(g,i)}))}}if(f.length>0){let e=hg(f,t,n,i);l.push(...e)}return{changes:l,updatedInternals:c}}async function _g({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 vg(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 yg(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}`;vg(`source`,s,`${i}-${o}--${n}-${a}`,e,n,a),vg(`target`,s,c,e,i,o),t.set(r.id,r)}}function bg(e,t){if(!e.parentId)return!1;let n=t.get(e.parentId);return n?n.selected?!0:bg(n,t):!1}function xg(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 Sg(e,t,n,r){let i=new Map;for(let[a,o]of e)if((o.selected||o.id===r)&&(!o.parentId||!bg(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 Cg({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 wg({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=sh(a,t);return{x:o.x-a.x,y:o.y-a.y}}function Tg({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=Hu(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?Zm(Rm(s)):null,x=v&&l?wg({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)}:sh(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}=Um({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]=Cg({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]=Ym(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=Ch(r.sourceEvent,{transform:l,snapGrid:f,snapToGrid:p,containerBounds:u});if(a=v,s=Sg(i,c,v,b),s.size>0&&(n||h||!b&&g)){let[e,t]=Cg({nodeId:b,dragItems:s,nodeLookup:i});n?.(r.sourceEvent,s,e,t),h?.(r.sourceEvent,e,t),b||g?.(r.sourceEvent,t)}}let ee=rd().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=Ch(e.sourceEvent,{transform:i,snapGrid:o,snapToGrid:s,containerBounds:u}),l=kh(e.sourceEvent,u)}).on(`drag`,e=>{let{autoPanOnNodeDrag:n,transform:r,snapGrid:i,snapToGrid:o,nodeDragThreshold:f,nodeLookup:m}=t(),g=Ch(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=kh(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=kh(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]=Cg({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||!xg(t,`.${g}`,v))&&(!_||xg(t,_,v))});f.call(ee)}function _(){f?.on(`.drag`,null)}return{update:g,destroy:_}}function Eg(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())rh(i,$m(e))>0&&r.push(e);return r}var Dg=250;function Og(e,t,n,r){let i=[],a=1/0,o=Eg(e,n,t+Dg);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}=Zh(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 kg(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,...Zh(o,c,c.position,!0)}:c}function Ag(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function jg(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}var Mg=()=>!0;function Ng(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:_=Mg,onReconnectEnd:v,updateConnection:y,getTransform:b,getFromHandle:x,autoPanSpeed:S,dragThreshold:C=1,handleDomNode:w}){let ee=Th(e.target),T=0,te,{x:E,y:ne}=kh(e),re=Ag(a,w),ie=s?.getBoundingClientRect(),ae=!1;if(!ie||!re)return;let oe=kg(i,re,r,c,t);if(!oe)return;let se=kh(e,ie),ce=!1,le=null,ue=!1,de=null;function fe(){if(!u||!ie)return;let[e,t]=Ym(se,ie,S);f({x:e,y:t}),T=requestAnimationFrame(fe)}let pe={...oe,nodeId:i,type:re,position:oe.position},me=c.get(i),he={inProgress:!0,isValid:null,from:Zh(me,pe,jm.Left,!0),fromHandle:pe,fromPosition:pe.position,fromNode:me,to:se,toHandle:null,toPosition:Mm[pe.position],toNode:null,pointer:se};function ge(){ae=!0,y(he),m?.(e,{nodeId:i,handleId:r,handleType:re})}C===0&&ge();function _e(e){if(!ae){let{x:t,y:n}=kh(e),r=t-E,i=n-ne;if(!(r*r+i*i>C*C))return;ge()}if(!x()||!pe){ve(e);return}let a=b();se=kh(e,ie),te=Og(ch(se,a,!1,[1,1]),n,c,pe),ce||=(fe(),!0);let s=Pg(e,{handle:te,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:o?`target`:`source`,isValidConnection:_,doc:ee,lib:l,flowId:d,nodeLookup:c});de=s.handleDomNode,le=s.connection,ue=jg(!!te,s.isValid);let u=c.get(i),f=u?Zh(u,pe,jm.Left,!0):he.from,p={...he,from:f,isValid:ue,to:s.toHandle&&ue?lh({x:s.toHandle.x,y:s.toHandle.y},a):se,toHandle:s.toHandle,toPosition:ue&&s.toHandle?s.toHandle.position:Mm[pe.position],toNode:s.toHandle?c.get(s.toHandle.nodeId):null,pointer:se};y(p),he=p}function ve(e){if(!(`touches`in e&&e.touches.length>0)){if(ae){(te||de)&&le&&ue&&h?.(le);let{inProgress:t,...n}=he,r={...n,toPosition:he.toHandle?he.toPosition:null};g?.(e,r),a&&v?.(e,r)}p(),cancelAnimationFrame(T),ce=!1,ue=!1,le=null,de=null,ee.removeEventListener(`mousemove`,_e),ee.removeEventListener(`mouseup`,ve),ee.removeEventListener(`touchmove`,_e),ee.removeEventListener(`touchend`,ve)}}ee.addEventListener(`mousemove`,_e),ee.addEventListener(`mouseup`,ve),ee.addEventListener(`touchmove`,_e),ee.addEventListener(`touchend`,ve)}function Pg(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=Mg,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}=kh(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=Ag(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===Tm.Strict?d&&e===`source`||!d&&e===`target`:t!==r||a!==i)&&l(c),_.toHandle=kg(t,e,a,u,n,!0)}return _}var Fg={onPointerDown:Ng,isValid:Pg};function Ig({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){let i=Hu(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&&mh()?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=bm().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:Wu}}var Lg=e=>({x:e.x,y:e.y,zoom:e.k}),Rg=({x:e,y:t,zoom:n})=>um.translate(e,t).scale(n),zg=(e,t)=>e.target.closest(`.${t}`),Bg=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Vg=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Hg=(e,t=0,n=Vg,r=()=>{})=>{let i=typeof t==`number`&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on(`end`,r):e},Ug=e=>{let t=e.ctrlKey&&mh()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Wg({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:a,zoomOnPinch:o,onPanZoomStart:s,onPanZoom:c,onPanZoomEnd:l}){return u=>{if(zg(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=Wu(u),t=d*2**Ug(u);r.scaleTo(n,t,e,u);return}let f=u.deltaMode===1?20:1,p=i===Em.Vertical?0:u.deltaX*f,m=i===Em.Horizontal?0:u.deltaY*f;!mh()&&u.shiftKey&&i!==Em.Vertical&&(p=u.deltaY*f,m=0),r.translateBy(n,-(p/d)*a,-(m/d)*a,{internal:!0});let h=Lg(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 Gg({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){let a=r.type===`wheel`,o=!t&&a&&!r.ctrlKey,s=zg(r,e);if(r.ctrlKey&&a&&s&&r.preventDefault(),o||s)return null;r.preventDefault(),n.call(this,r,i)}}function Kg({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;let i=Lg(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 qg({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return a=>{e.usedRightMouseButton=!!(n&&Bg(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),i&&!a.sourceEvent?.internal&&i?.(a.sourceEvent,Lg(a.transform))}}function Jg({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:a}){return o=>{if(!o.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&Bg(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&a(o.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){let t=Lg(o.transform);e.prevViewport=t,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(o.sourceEvent,t)},n?150:0)}}}function Yg({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`&&(zg(f,`${u}-flow__node`)||zg(f,`${u}-flow__edge`)||zg(f,`${u}-flow__selection`)||zg(f,`${u}-flow__nodesselection`)))return!0;if(!i&&!p&&!a&&!o&&!r||s||d&&!h||zg(f,c)&&h||zg(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 Xg({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=bm().extent(()=>d).scaleExtent([t,n]).translateExtent(r),p=Hu(e).call(f);y({x:i.x,y:i.y,zoom:Gm(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);let m=p.on(`wheel.zoom`),h=p.on(`dblclick.zoom`);f.wheelDelta(Ug);async function g(e,t){return p?new Promise(n=>{f?.interpolate(t?.interpolate===`linear`?sf:xf).transform(Hg(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:ee,connectionInProgress:T,paneClickDistance:te,selectionOnDrag:E}){r&&!l.isZoomingOrPanning&&v();let ne=i&&!C&&!r;f.clickDistance(E?1/0:!ah(te)||te<0?0:te);let re=ne?Wg({zoomPanValues:l,noWheelClassName:e,d3Selection:p,d3Zoom:f,panOnScrollMode:d,panOnScrollSpeed:g,zoomOnPinch:y,onPanZoomStart:o,onPanZoom:a,onPanZoomEnd:s}):Gg({noWheelClassName:e,preventScrolling:_,d3ZoomHandler:m});p.on(`wheel.zoom`,re,{passive:!1});let ie=Kg({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:o});f.on(`start`,ie);let ae=qg({zoomPanValues:l,panOnDrag:u,onPaneContextMenu:!!n,onPanZoom:a,onTransformChange:ee});f.on(`zoom`,ae);let oe=Jg({zoomPanValues:l,panOnDrag:u,panOnScroll:i,onPaneContextMenu:n,onPanZoomEnd:s,onDraggingChange:c});f.on(`end`,oe);let se=Yg({panActivationKeyPressed:S,zoomActivationKeyPressed:C,panOnDrag:u,zoomOnScroll:b,panOnScroll:i,zoomOnDoubleClick:x,zoomOnPinch:y,userSelectionActive:r,noPanClassName:t,noWheelClassName:e,lib:w,connectionInProgress:T});f.filter(se),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=Rg(e),i=f?.constrain()(r,t,n);return i&&await g(i),i}async function b(e,t){let n=Rg(e);return await g(n,t),n}function x(e){if(p){let t=Rg(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?dm(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`?sf:xf).scaleTo(Hg(p,t?.duration,t?.ease,()=>n(!0)),e)}):!1}async function w(e,t){return p?new Promise(n=>{f?.interpolate(t?.interpolate===`linear`?sf:xf).scaleBy(Hg(p,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function ee(e){f?.scaleExtent(e)}function T(e){f?.translateExtent(e)}function te(e){let t=!ah(e)||e<0?0:e;f?.clickDistance(t)}return{update:_,destroy:v,setViewport:b,setViewportConstrained:y,getViewport:S,scaleTo:C,scaleBy:w,setScaleExtent:ee,setTranslateExtent:T,syncViewport:x,setClickDistance:te}}var Zg;(function(e){e.Line=`line`,e.Handle=`handle`})(Zg||={});var Qg=oh(`Svelte Flow`,`https://svelteflow.dev/`);function $g(e,t,n={}){return Bh(e,t,{...n,onError:n.onError??Qg})}function e_(){let e={};return[t=>{if(t&&!ot(e))throw Error(t);return it(e)},t=>at(e,t)]}var[t_,n_]=e_(),[r_,i_]=e_(),[a_,o_]=e_(),s_=new Set([`$$slots`,`$$events`,`$$legacy`,`id`,`type`,`position`,`style`,`class`,`isConnectable`,`isConnectableStart`,`isConnectableEnd`,`isValidConnection`,`onconnect`,`ondisconnect`,`children`]),c_=H(`<div><!></div>`);function l_(e,t){k(t,!0);let n=Y(t,`id`,3,null),r=Y(t,`type`,3,`source`),i=Y(t,`position`,19,()=>jm.Top),a=Y(t,`isConnectableStart`,3,!0),o=Y(t,`isConnectableEnd`,3,!0),s=J(t,s_),c=t_(`Handle must be used within a Custom Node component`),l=r_(`Handle must be used within a Custom Node component`),u=j(()=>r()===`target`),d=j(()=>t.isConnectable===void 0?l.value:t.isConnectable),p=Q_(),m=j(()=>p.ariaLabelConfig),h=null;Rn(()=>{if(t.onconnect||t.ondisconnect){p.edges;let e=p.connectionLookup.get(`${c}-${r()}${n()?`-${n()}`:``}`);if(h&&!bh(e,h)){let n=e??new Map;xh(h,n,t.ondisconnect),xh(n,h,t.onconnect)}h=new Map(e)}});let g=j(()=>{if(!p.connection.inProgress)return[!1,!1,!1,!1,null];let{fromHandle:e,toHandle:t,isValid:i}=p.connection,a=e&&e.nodeId===c&&e.type===r()&&e.id===n(),o=t&&t.nodeId===c&&t.type===r()&&t.id===n();return[!0,a,o,p.connectionMode===Tm.Strict?e?.type!==r():c!==e?.nodeId||n()!==e?.id,o&&i]}),_=j(()=>v(z(g),5)),y=j(()=>z(_)[0]),b=j(()=>z(_)[1]),x=j(()=>z(_)[2]),S=j(()=>z(_)[3]),C=j(()=>z(_)[4]);function w(e){let t=p.onbeforeconnect?p.onbeforeconnect(e):e;t&&(p.addEdge(t),p.onconnect?.(e))}function ee(e){let r=Oh(e);e.currentTarget&&(r&&e.button===0||!r)&&Fg.onPointerDown(e,{handleId:n(),nodeId:c,isTarget:z(u),connectionRadius:p.connectionRadius,domNode:p.domNode,nodeLookup:p.nodeLookup,connectionMode:p.connectionMode,lib:`svelte`,autoPanOnConnect:p.autoPanOnConnect,autoPanSpeed:p.autoPanSpeed,flowId:p.flowId,isValidConnection:t.isValidConnection||((...e)=>p.isValidConnection?.(...e)??!0),updateConnection:p.updateConnection,cancelConnection:p.cancelConnection,panBy:p.panBy,onConnect:w,onConnectStart:p.onconnectstart,onConnectEnd:(...e)=>p.onconnectend?.(...e),getTransform:()=>[p.viewport.x,p.viewport.y,p.viewport.zoom],getFromHandle:()=>p.connection.fromHandle,dragThreshold:p.connectionDragThreshold,handleDomNode:e.currentTarget})}function T(e){if(!c||!p.clickConnectStartHandle&&!a())return;if(!p.clickConnectStartHandle){p.onclickconnectstart?.(e,{nodeId:c,handleId:n(),handleType:r()}),p.clickConnectStartHandle={nodeId:c,type:r(),id:n()};return}let i=Th(e.target),o=t.isValidConnection??p.isValidConnection,{connectionMode:s,clickConnectStartHandle:l,flowId:u,nodeLookup:d}=p,{connection:f,isValid:m}=Fg.isValid(e,{handle:{nodeId:c,id:n(),type:r()},connectionMode:s,fromNodeId:l.nodeId,fromHandleId:l.id??null,fromType:l.type,isValidConnection:o,flowId:u,doc:i,lib:`svelte`,nodeLookup:d});m&&f&&w(f);let h=structuredClone(Qe(p.connection));delete h.inProgress,h.toPosition=h.toHandle?h.toHandle.position:null,p.onclickconnectend?.(e,h),p.clickConnectStartHandle=null}var te=c_(),E=()=>{};va(te,()=>({"data-handleid":n(),"data-nodeid":c,"data-handlepos":i(),"data-id":`${p.flowId??``}-${c??``}-${n()??`null`??``}-${r()??``}`,class:[`svelte-flow__handle`,`svelte-flow__handle-${i()}`,p.noDragClass,p.noPanClass,i(),t.class],onmousedown:ee,ontouchstart:ee,onclick:p.clickConnect?T:void 0,onkeypress:E,style:t.style,role:`button`,"aria-label":z(m)[`handle.ariaLabel`],tabindex:`-1`,...s,[aa]:{valid:z(C),connectingto:z(x),connectingfrom:z(b),source:!z(u),target:z(u),connectablestart:a(),connectableend:o(),connectable:z(d),connectionindicator:z(d)&&(!z(y)||z(S))&&(z(y)||p.clickConnectStartHandle?o():a())}})),Fi(P(te),()=>t.children??f),O(te),U(e,te),A()}var u_=H(`<!> <!>`,1);function d_(e,t){k(t,!0);let n=Y(t,`targetPosition`,19,()=>jm.Top),r=Y(t,`sourcePosition`,19,()=>jm.Bottom);var i=u_(),a=F(i);l_(a,{type:`target`,get position(){return n()}});var o=L(a);l_(L(o),{type:`source`,get position(){return r()}}),R(()=>W(o,` ${t.data?.label??``} `)),U(e,i),A()}var f_=H(` <!>`,1);function p_(e,t){k(t,!0);let n=Y(t,`data`,19,()=>({label:`Node`})),r=Y(t,`sourcePosition`,19,()=>jm.Bottom);je();var i=f_(),a=F(i);l_(L(a),{type:`source`,get position(){return r()}}),R(()=>W(a,`${n()?.label??``} `)),U(e,i),A()}var m_=H(` <!>`,1);function h_(e,t){k(t,!0);let n=Y(t,`data`,19,()=>({label:`Node`})),r=Y(t,`targetPosition`,19,()=>jm.Top);je();var i=m_(),a=F(i);l_(L(a),{type:`target`,get position(){return r()}}),R(()=>W(a,`${n()?.label??``} `)),U(e,i),A()}function g_(e,t){}function __(e,t,n){if(!n||!t)return;let r=n===`root`?t:t.querySelector(`.svelte-flow__${n}`);r&&r.appendChild(e)}function v_(e,t){let n=j(Q_),r=j(()=>z(n).domNode),i;return z(r)?__(e,z(r),t):i=zn(()=>{In(()=>{__(e,z(r),t),i?.()})}),{async update(t){__(e,z(r),t)},destroy(){e.parentNode&&e.parentNode.removeChild(e),i?.()}}}function y_(){let e=M(typeof window>`u`);if(z(e)){let t=zn(()=>{In(()=>{N(e,!1),t?.()})})}return{get value(){return z(e)}}}var b_=e=>Pm(e),x_=e=>Nm(e);function S_(e){return e===void 0?void 0:`${e}px`}var C_={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},w_=new Set([`$$slots`,`$$events`,`$$legacy`,`x`,`y`,`width`,`height`,`selectEdgeOnClick`,`transparent`,`class`,`children`]),T_=H(`<div><!></div>`);function E_(e,t){k(t,!0);let n=Y(t,`x`,3,0),r=Y(t,`y`,3,0),i=Y(t,`selectEdgeOnClick`,3,!1),a=Y(t,`transparent`,3,!1),o=J(t,w_),s=Q_(),c=a_(`EdgeLabel must be used within a Custom Edge component`),l=j(()=>s.visible.edges.get(c)?.zIndex);var u=T_(),d=()=>{i()&&c&&s.handleEdgeSelection(c)};va(u,(e,s,c)=>({class:[`svelte-flow__edge-label`,{transparent:a()},t.class],tabindex:`-1`,onclick:d,...o,[oa]:{display:e,cursor:i()?`pointer`:void 0,transform:`translate(-50%, -50%) translate(${n()??``}px,${r()??``}px)`,"pointer-events":`all`,width:s,height:c,"z-index":z(l)}}),[()=>y_().value?`none`:void 0,()=>S_(t.width),()=>S_(t.height)],void 0,void 0,`svelte-1wg91mu`),Fi(P(u),()=>t.children??f),O(u),Ri(u,(e,t)=>v_?.(e,t),()=>`edge-labels`),U(e,u),A()}var D_=new Set([`$$slots`,`$$events`,`$$legacy`,`id`,`path`,`label`,`labelX`,`labelY`,`labelStyle`,`markerStart`,`markerEnd`,`style`,`interactionWidth`,`class`]),O_=oi(`<path></path>`),k_=oi(`<path fill="none"></path><!><!>`,1);function A_(e,t){let n=Y(t,`interactionWidth`,3,20),r=J(t,D_);var i=k_(),a=F(i),o=L(a),s=e=>{var i=O_();va(i,()=>({d:t.path,"stroke-opacity":0,"stroke-width":n(),fill:`none`,class:`svelte-flow__edge-interaction`,...r})),U(e,i)};G(o,e=>{n()>0&&e(s)});var c=L(o),l=e=>{E_(e,{get x(){return t.labelX},get y(){return t.labelY},get style(){return t.labelStyle},selectEdgeOnClick:!0,children:(e,n)=>{je();var r=si();R(()=>W(r,t.label)),U(e,r)},$$slots:{default:!0}})};G(c,e=>{t.label&&e(l)}),R(()=>{q(a,`id`,t.id),q(a,`d`,t.path),Ji(a,0,Hi([`svelte-flow__edge-path`,t.class])),q(a,`marker-start`,t.markerStart),q(a,`marker-end`,t.markerEnd),Xi(a,t.style)}),U(e,i)}function j_(e,t){k(t,!0);let n=j(()=>Ph({sourceX:t.sourceX,sourceY:t.sourceY,targetX:t.targetX,targetY:t.targetY,sourcePosition:t.sourcePosition,targetPosition:t.targetPosition,curvature:t.pathOptions?.curvature})),r=j(()=>v(z(n),3)),i=j(()=>z(r)[0]),a=j(()=>z(r)[1]),o=j(()=>z(r)[2]);A_(e,{get id(){return t.id},get path(){return z(i)},get labelX(){return z(a)},get labelY(){return z(o)},get label(){return t.label},get labelStyle(){return t.labelStyle},get markerStart(){return t.markerStart},get markerEnd(){return t.markerEnd},get interactionWidth(){return t.interactionWidth},get style(){return t.style}}),A()}function M_(e,t){k(t,!0);let n=j(()=>qh({sourceX:t.sourceX,sourceY:t.sourceY,targetX:t.targetX,targetY:t.targetY,sourcePosition:t.sourcePosition,targetPosition:t.targetPosition})),r=j(()=>v(z(n),3)),i=j(()=>z(r)[0]),a=j(()=>z(r)[1]),o=j(()=>z(r)[2]);A_(e,{get path(){return z(i)},get labelX(){return z(a)},get labelY(){return z(o)},get label(){return t.label},get labelStyle(){return t.labelStyle},get markerStart(){return t.markerStart},get markerEnd(){return t.markerEnd},get interactionWidth(){return t.interactionWidth},get style(){return t.style}}),A()}function N_(e,t){k(t,!0);let n=j(()=>Vh({sourceX:t.sourceX,sourceY:t.sourceY,targetX:t.targetX,targetY:t.targetY})),r=j(()=>v(z(n),3)),i=j(()=>z(r)[0]),a=j(()=>z(r)[1]),o=j(()=>z(r)[2]);A_(e,{get path(){return z(i)},get labelX(){return z(a)},get labelY(){return z(o)},get label(){return t.label},get labelStyle(){return t.labelStyle},get markerStart(){return t.markerStart},get markerEnd(){return t.markerEnd},get interactionWidth(){return t.interactionWidth},get style(){return t.style}}),A()}function P_(e,t){k(t,!0);let n=j(()=>qh({sourceX:t.sourceX,sourceY:t.sourceY,targetX:t.targetX,targetY:t.targetY,sourcePosition:t.sourcePosition,targetPosition:t.targetPosition,borderRadius:0})),r=j(()=>v(z(n),3)),i=j(()=>z(r)[0]),a=j(()=>z(r)[1]),o=j(()=>z(r)[2]);A_(e,{get path(){return z(i)},get labelX(){return z(a)},get labelY(){return z(o)},get label(){return t.label},get labelStyle(){return t.labelStyle},get markerStart(){return t.markerStart},get markerEnd(){return t.markerEnd},get interactionWidth(){return t.interactionWidth},get style(){return t.style}}),A()}var F_=[`forEach`,`isDisjointFrom`,`isSubsetOf`,`isSupersetOf`],I_=[`difference`,`intersection`,`symmetricDifference`,`union`],L_=!1,R_=class e extends Set{#e=new Map;#t=M(0);#n=M(0);#r=br||-1;constructor(e){if(super(),e){for(var t of e)super.add(t);this.#n.v=super.size}L_||this.#a()}#i(e){return br===this.#r?M(e):an(e)}#a(){L_=!0;var t=e.prototype,n=Set.prototype;for(let e of F_)t[e]=function(...t){return z(this.#t),n[e].apply(this,t)};for(let r of I_)t[r]=function(...t){z(this.#t);var i=n[r].apply(this,t);return new e(i)}}has(e){var t=super.has(e),n=this.#e,r=n.get(e);if(r===void 0){if(!t)return z(this.#t),!1;r=this.#i(!0),n.set(e,r)}return z(r),t}add(e){return super.has(e)||(super.add(e),N(this.#n,super.size),dn(this.#t)),this}delete(e){var t=super.delete(e),n=this.#e,r=n.get(e);return r!==void 0&&(n.delete(e),N(r,!1)),t&&(N(this.#n,super.size),dn(this.#t)),t}clear(){if(super.size!==0){super.clear();var e=this.#e;for(var t of e.values())N(t,!1);e.clear(),N(this.#n,0),dn(this.#t)}}keys(){return this.values()}values(){return z(this.#t),super.values()}entries(){return z(this.#t),super.entries()}[Symbol.iterator](){return this.keys()}get size(){return z(this.#n)}},z_=class extends Map{#e=new Map;#t=M(0);#n=M(0);#r=br||-1;constructor(e){if(super(),e){for(var[t,n]of e)super.set(t,n);this.#n.v=super.size}}#i(e){return br===this.#r?M(e):an(e)}has(e){var t=this.#e,n=t.get(e);if(n===void 0){if(super.has(e))n=this.#i(0),t.set(e,n);else return z(this.#t),!1}return z(n),!0}forEach(e,t){this.#a(),super.forEach(e,t)}get(e){var t=this.#e,n=t.get(e);if(n===void 0){if(super.has(e))n=this.#i(0),t.set(e,n);else{z(this.#t);return}}return z(n),super.get(e)}getOrInsert(e,t){return super.has(e)||this.set(e,t),this.get(e)}getOrInsertComputed(e,t){return super.has(e)||this.set(e,t(e)),this.get(e)}set(e,t){var n=this.#e,r=n.get(e),i=super.get(e),a=super.set(e,t),o=this.#t;if(r===void 0)r=this.#i(0),n.set(e,r),N(this.#n,super.size),dn(o);else if(i!==t){dn(r);var s=o.reactions===null?null:new Set(o.reactions);(s===null||!r.reactions?.every(e=>s.has(e)))&&dn(o)}return a}delete(e){var t=this.#e,n=t.get(e),r=super.delete(e);return n!==void 0&&(t.delete(e),N(n,-1)),r&&(N(this.#n,super.size),dn(this.#t)),r}clear(){if(super.size!==0){super.clear();var e=this.#e;N(this.#n,0);for(var t of e.values())N(t,-1);dn(this.#t),e.clear()}}#a(){z(this.#t);var e=this.#e;if(this.#n.v!==e.size){for(var t of super.keys())if(!e.has(t)){var n=this.#i(0);e.set(t,n)}}for([,n]of this.#e)z(n)}keys(){return z(this.#t),super.keys()}values(){return this.#a(),super.values()}entries(){return this.#a(),super.entries()}[Symbol.iterator](){return this.entries()}get size(){return z(this.#n),super.size}},B_=class{#e;#t;constructor(e,t){this.#e=e,this.#t=ui(t)}get current(){return this.#t(),this.#e()}},V_=/\(.+\)/,H_=new Set([`all`,`print`,`screen`,`and`,`or`,`not`,`only`]),U_=class extends B_{constructor(e,t){let n=V_.test(e)||e.split(/[\s,]+/).some(e=>H_.has(e.trim()))?e:`(${e})`,r=window.matchMedia(n);super(()=>r.matches,e=>Xr(r,`change`,e))}};function W_(e,t,n,r){let i=new Map;return zm(e,{x:0,y:0,width:n,height:r},t,!0).forEach(e=>{i.set(e.id,e)}),i}function G_(e){let{edges:t,defaultEdgeOptions:n,nodeLookup:r,previousEdges:i,connectionMode:a,onerror:o,onlyRenderVisible:s,elevateEdgesOnSelect:c,zIndexMode:l}=e,u=new Map;for(let d of t){let t=r.get(d.source),f=r.get(d.target);if(!t||!f||t.hidden||f.hidden)continue;if(s){let{visibleNodes:n,transform:r,width:i,height:a}=e;if(Lh({sourceNode:t,targetNode:f,width:i,height:a,transform:r}))n.set(t.id,t),n.set(f.id,f);else continue}let p=i.get(d.id);if(p&&d===p.edge&&t==p.sourceNode&&f==p.targetNode){u.set(d.id,p);continue}let m=Yh({id:d.id,sourceNode:t,targetNode:f,sourceHandle:d.sourceHandle||null,targetHandle:d.targetHandle||null,connectionMode:a,onError:o});m&&u.set(d.id,{...n,...d,...m,zIndex:Ih({selected:d.selected,zIndex:d.zIndex??n.zIndex,sourceNode:t,targetNode:f,elevateOnSelect:c,zIndexMode:l}),sourceNode:t,targetNode:f,edge:d})}return u}var K_=oh(`Svelte Flow`,`https://svelteflow.dev/`),q_={input:p_,output:h_,default:d_,group:g_},J_={straight:N_,smoothstep:M_,default:j_,step:P_};function Y_(e,t,n,r,i,a){return t&&!n&&r&&i?ph(Rm(a,{filter:e=>!(!e.width&&!e.initialWidth||!e.height&&!e.initialHeight)}),r,i,.5,2,.1):n??{x:0,y:0,zoom:1}}function X_(e){class t{#e=j(()=>e.props.id??`1`);get flowId(){return z(this.#e)}set flowId(e){N(this.#e,e)}#t=M(null);get domNode(){return z(this.#t)}set domNode(e){N(this.#t,e)}#n=M(null);get panZoom(){return z(this.#n)}set panZoom(e){N(this.#n,e)}#r=M(e.width??0);get width(){return z(this.#r)}set width(e){N(this.#r,e)}#i=M(e.height??0);get height(){return z(this.#i)}set height(e){N(this.#i,e)}#a=M(e.props.zIndexMode??`basic`);get zIndexMode(){return z(this.#a)}set zIndexMode(e){N(this.#a,e)}#o=j(()=>{let{nodesInitialized:t}=ug(e.nodes,this.nodeLookup,this.parentLookup,{nodeExtent:this.nodeExtent,nodeOrigin:this.nodeOrigin,elevateNodesOnSelect:e.props.elevateNodesOnSelect??!0,checkEquality:!0,zIndexMode:this.zIndexMode});return this.fitViewQueued&&t&&(this.fitViewOptions?.duration?this.resolveFitView():queueMicrotask(()=>{this.resolveFitView()})),t});get nodesInitialized(){return z(this.#o)}set nodesInitialized(e){N(this.#o,e)}#s=j(()=>this.panZoom!==null);get viewportInitialized(){return z(this.#s)}set viewportInitialized(e){N(this.#s,e)}#c=j(()=>(yg(this.connectionLookup,this.edgeLookup,e.edges),e.edges));get _edges(){return z(this.#c)}set _edges(e){N(this.#c,e)}get nodes(){return this.nodesInitialized,e.nodes}set nodes(t){e.nodes=t}get edges(){return this._edges}set edges(t){e.edges=t}_prevSelectedNodes=[];_prevSelectedNodeIds=new Set;#l=j(()=>{let e=this._prevSelectedNodeIds.size,t=new Set,n=this.nodes.filter(e=>(e.selected&&(t.add(e.id),this._prevSelectedNodeIds.delete(e.id)),e.selected));return(e!==t.size||this._prevSelectedNodeIds.size>0)&&(this._prevSelectedNodes=n),this._prevSelectedNodeIds=t,this._prevSelectedNodes});get selectedNodes(){return z(this.#l)}set selectedNodes(e){N(this.#l,e)}_prevSelectedEdges=[];_prevSelectedEdgeIds=new Set;#u=j(()=>{let e=this._prevSelectedEdgeIds.size,t=new Set,n=this.edges.filter(e=>(e.selected&&(t.add(e.id),this._prevSelectedEdgeIds.delete(e.id)),e.selected));return(e!==t.size||this._prevSelectedEdgeIds.size>0)&&(this._prevSelectedEdges=n),this._prevSelectedEdgeIds=t,this._prevSelectedEdges});get selectedEdges(){return z(this.#u)}set selectedEdges(e){N(this.#u,e)}selectionChangeHandlers=new Map;nodeLookup=new Map;parentLookup=new Map;connectionLookup=new Map;edgeLookup=new Map;_prevVisibleEdges=new Map;#d=j(()=>{let{nodes:t,_edges:n,_prevVisibleEdges:r,nodeLookup:i,connectionMode:a,onerror:o,onlyRenderVisibleElements:s,defaultEdgeOptions:c,zIndexMode:l}=this,u,d,f={edges:n,defaultEdgeOptions:c,previousEdges:r,nodeLookup:i,connectionMode:a,elevateEdgesOnSelect:e.props.elevateEdgesOnSelect??!0,zIndexMode:l,onerror:o};if(s){let{viewport:e,width:t,height:n}=this,r=[e.x,e.y,e.zoom];u=W_(i,r,t,n),d=G_({...f,onlyRenderVisible:!0,visibleNodes:u,transform:r,width:t,height:n})}else u=this.nodeLookup,d=G_(f);return this._prevVisibleEdges=d,{nodes:u,edges:d}});get visible(){return z(this.#d)}set visible(e){N(this.#d,e)}#f=j(()=>e.props.nodesDraggable??!0);get nodesDraggable(){return z(this.#f)}set nodesDraggable(e){N(this.#f,e)}#p=j(()=>e.props.nodesConnectable??!0);get nodesConnectable(){return z(this.#p)}set nodesConnectable(e){N(this.#p,e)}#m=j(()=>e.props.elementsSelectable??!0);get elementsSelectable(){return z(this.#m)}set elementsSelectable(e){N(this.#m,e)}#h=j(()=>e.props.nodesFocusable??!0);get nodesFocusable(){return z(this.#h)}set nodesFocusable(e){N(this.#h,e)}#g=j(()=>e.props.edgesFocusable??!0);get edgesFocusable(){return z(this.#g)}set edgesFocusable(e){N(this.#g,e)}#_=j(()=>e.props.disableKeyboardA11y??!1);get disableKeyboardA11y(){return z(this.#_)}set disableKeyboardA11y(e){N(this.#_,e)}#v=j(()=>e.props.minZoom??.5);get minZoom(){return z(this.#v)}set minZoom(e){N(this.#v,e)}#y=j(()=>e.props.maxZoom??2);get maxZoom(){return z(this.#y)}set maxZoom(e){N(this.#y,e)}#b=j(()=>e.props.nodeOrigin??[0,0]);get nodeOrigin(){return z(this.#b)}set nodeOrigin(e){N(this.#b,e)}#x=j(()=>e.props.nodeExtent??Sm);get nodeExtent(){return z(this.#x)}set nodeExtent(e){N(this.#x,e)}#S=j(()=>e.props.translateExtent??Sm);get translateExtent(){return z(this.#S)}set translateExtent(e){N(this.#S,e)}#C=j(()=>e.props.defaultEdgeOptions??{});get defaultEdgeOptions(){return z(this.#C)}set defaultEdgeOptions(e){N(this.#C,e)}#w=j(()=>e.props.nodeDragThreshold??1);get nodeDragThreshold(){return z(this.#w)}set nodeDragThreshold(e){N(this.#w,e)}#T=j(()=>e.props.autoPanOnNodeDrag??!0);get autoPanOnNodeDrag(){return z(this.#T)}set autoPanOnNodeDrag(e){N(this.#T,e)}#E=j(()=>e.props.autoPanOnConnect??!0);get autoPanOnConnect(){return z(this.#E)}set autoPanOnConnect(e){N(this.#E,e)}#D=j(()=>e.props.autoPanOnNodeFocus??!0);get autoPanOnNodeFocus(){return z(this.#D)}set autoPanOnNodeFocus(e){N(this.#D,e)}#O=j(()=>e.props.autoPanSpeed??15);get autoPanSpeed(){return z(this.#O)}set autoPanSpeed(e){N(this.#O,e)}#k=j(()=>e.props.connectionDragThreshold??1);get connectionDragThreshold(){return z(this.#k)}set connectionDragThreshold(e){N(this.#k,e)}fitViewQueued=e.props.fitView??!1;fitViewOptions=e.props.fitViewOptions;fitViewResolver=null;#A=j(()=>e.props.snapGrid??null);get snapGrid(){return z(this.#A)}set snapGrid(e){N(this.#A,e)}#j=M(!1);get dragging(){return z(this.#j)}set dragging(e){N(this.#j,e)}#M=M(null);get selectionRect(){return z(this.#M)}set selectionRect(e){N(this.#M,e)}#N=M(!1);get selectionKeyPressed(){return z(this.#N)}set selectionKeyPressed(e){N(this.#N,e)}#P=M(!1);get multiselectionKeyPressed(){return z(this.#P)}set multiselectionKeyPressed(e){N(this.#P,e)}#F=M(!1);get deleteKeyPressed(){return z(this.#F)}set deleteKeyPressed(e){N(this.#F,e)}#I=M(!1);get panActivationKeyPressed(){return z(this.#I)}set panActivationKeyPressed(e){N(this.#I,e)}#L=M(!1);get zoomActivationKeyPressed(){return z(this.#L)}set zoomActivationKeyPressed(e){N(this.#L,e)}#R=M(null);get selectionRectMode(){return z(this.#R)}set selectionRectMode(e){N(this.#R,e)}#z=M(``);get ariaLiveMessage(){return z(this.#z)}set ariaLiveMessage(e){N(this.#z,e)}#B=j(()=>e.props.selectionMode??Dm.Partial);get selectionMode(){return z(this.#B)}set selectionMode(e){N(this.#B,e)}#V=j(()=>({...q_,...e.props.nodeTypes}));get nodeTypes(){return z(this.#V)}set nodeTypes(e){N(this.#V,e)}#H=j(()=>({...J_,...e.props.edgeTypes}));get edgeTypes(){return z(this.#H)}set edgeTypes(e){N(this.#H,e)}#U=j(()=>e.props.noPanClass??`nopan`);get noPanClass(){return z(this.#U)}set noPanClass(e){N(this.#U,e)}#W=j(()=>e.props.noDragClass??`nodrag`);get noDragClass(){return z(this.#W)}set noDragClass(e){N(this.#W,e)}#G=j(()=>e.props.noWheelClass??`nowheel`);get noWheelClass(){return z(this.#G)}set noWheelClass(e){N(this.#G,e)}#K=j(()=>yh(e.props.ariaLabelConfig));get ariaLabelConfig(){return z(this.#K)}set ariaLabelConfig(e){N(this.#K,e)}#q=M(Y_(this.nodesInitialized,e.props.fitView,e.props.initialViewport,this.width,this.height,this.nodeLookup));get _viewport(){return z(this.#q)}set _viewport(e){N(this.#q,e)}get viewport(){return e.viewport??this._viewport}set viewport(t){e.viewport&&=t,this._viewport=t}#J=M(Om);get _connection(){return z(this.#J)}set _connection(e){N(this.#J,e)}#Y=j(()=>this._connection.inProgress?{...this._connection,to:ch(this._connection.to,[this.viewport.x,this.viewport.y,this.viewport.zoom])}:this._connection);get connection(){return z(this.#Y)}set connection(e){N(this.#Y,e)}#X=j(()=>e.props.connectionMode??Tm.Strict);get connectionMode(){return z(this.#X)}set connectionMode(e){N(this.#X,e)}#Z=j(()=>e.props.connectionRadius??20);get connectionRadius(){return z(this.#Z)}set connectionRadius(e){N(this.#Z,e)}#Q=j(()=>e.props.isValidConnection??(()=>!0));get isValidConnection(){return z(this.#Q)}set isValidConnection(e){N(this.#Q,e)}#$=j(()=>e.props.selectNodesOnDrag??!0);get selectNodesOnDrag(){return z(this.#$)}set selectNodesOnDrag(e){N(this.#$,e)}#ee=j(()=>e.props.defaultMarkerColor===void 0?`#b1b1b7`:e.props.defaultMarkerColor);get defaultMarkerColor(){return z(this.#ee)}set defaultMarkerColor(e){N(this.#ee,e)}#te=j(()=>eg(e.edges,{defaultColor:this.defaultMarkerColor,id:this.flowId,defaultMarkerStart:this.defaultEdgeOptions.markerStart,defaultMarkerEnd:this.defaultEdgeOptions.markerEnd}));get markers(){return z(this.#te)}set markers(e){N(this.#te,e)}#ne=j(()=>e.props.onlyRenderVisibleElements??!1);get onlyRenderVisibleElements(){return z(this.#ne)}set onlyRenderVisibleElements(e){N(this.#ne,e)}#re=j(()=>e.props.onflowerror??K_);get onerror(){return z(this.#re)}set onerror(e){N(this.#re,e)}#ie=j(()=>e.props.ondelete);get ondelete(){return z(this.#ie)}set ondelete(e){N(this.#ie,e)}#ae=j(()=>e.props.onbeforedelete);get onbeforedelete(){return z(this.#ae)}set onbeforedelete(e){N(this.#ae,e)}#oe=j(()=>e.props.onbeforeconnect);get onbeforeconnect(){return z(this.#oe)}set onbeforeconnect(e){N(this.#oe,e)}#se=j(()=>e.props.onconnect);get onconnect(){return z(this.#se)}set onconnect(e){N(this.#se,e)}#ce=j(()=>e.props.onconnectstart);get onconnectstart(){return z(this.#ce)}set onconnectstart(e){N(this.#ce,e)}#le=j(()=>e.props.onconnectend);get onconnectend(){return z(this.#le)}set onconnectend(e){N(this.#le,e)}#ue=j(()=>e.props.onbeforereconnect);get onbeforereconnect(){return z(this.#ue)}set onbeforereconnect(e){N(this.#ue,e)}#de=j(()=>e.props.onreconnect);get onreconnect(){return z(this.#de)}set onreconnect(e){N(this.#de,e)}#fe=j(()=>e.props.onreconnectstart);get onreconnectstart(){return z(this.#fe)}set onreconnectstart(e){N(this.#fe,e)}#pe=j(()=>e.props.onreconnectend);get onreconnectend(){return z(this.#pe)}set onreconnectend(e){N(this.#pe,e)}#me=j(()=>e.props.clickConnect??!0);get clickConnect(){return z(this.#me)}set clickConnect(e){N(this.#me,e)}#he=j(()=>e.props.onclickconnectstart);get onclickconnectstart(){return z(this.#he)}set onclickconnectstart(e){N(this.#he,e)}#ge=j(()=>e.props.onclickconnectend);get onclickconnectend(){return z(this.#ge)}set onclickconnectend(e){N(this.#ge,e)}#_e=M(null);get clickConnectStartHandle(){return z(this.#_e)}set clickConnectStartHandle(e){N(this.#_e,e)}#ve=j(()=>e.props.onselectiondrag);get onselectiondrag(){return z(this.#ve)}set onselectiondrag(e){N(this.#ve,e)}#ye=j(()=>e.props.onselectiondragstart);get onselectiondragstart(){return z(this.#ye)}set onselectiondragstart(e){N(this.#ye,e)}#be=j(()=>e.props.onselectiondragstop);get onselectiondragstop(){return z(this.#be)}set onselectiondragstop(e){N(this.#be,e)}resolveFitView=async()=>{this.panZoom&&(await Hm({nodes:this.nodeLookup,width:this.width,height:this.height,panZoom:this.panZoom,minZoom:this.minZoom,maxZoom:this.maxZoom},this.fitViewOptions),this.fitViewResolver?.resolve(!0),this.fitViewQueued=!1,this.fitViewOptions=void 0,this.fitViewResolver=null)};_prefersDark=new U_(`(prefers-color-scheme: dark)`,e.props.colorModeSSR===`dark`);#xe=j(()=>e.props.colorMode===`system`?this._prefersDark.current?`dark`:`light`:e.props.colorMode??`light`);get colorMode(){return z(this.#xe)}set colorMode(e){N(this.#xe,e)}constructor(){}resetStoreValues(){this.dragging=!1,this.selectionRect=null,this.selectionRectMode=null,this.selectionKeyPressed=!1,this.multiselectionKeyPressed=!1,this.deleteKeyPressed=!1,this.panActivationKeyPressed=!1,this.zoomActivationKeyPressed=!1,this._connection=Om,this.clickConnectStartHandle=null,this.viewport=e.props.initialViewport??{x:0,y:0,zoom:1},this.ariaLiveMessage=``}}return new t}var Z_=xm.error001(`svelte`);function Q_(){let e=it($_);if(!e)throw Error(Z_);return e.getStore()}var $_=Symbol();function ev(e){let t=X_(e);function n(e){t.nodeTypes={...q_,...e}}function r(e){t.edgeTypes={...J_,...e}}function i(e){t.edges=$g(e,t.edges,{onError:t.onerror})}let a=(e,n=!1)=>{t.nodes=t.nodes.map(r=>{if(t.connection.inProgress&&t.connection.fromNode.id===r.id){let e=t.nodeLookup.get(r.id);e&&(t.connection={...t.connection,from:Zh(e,t.connection.fromHandle,jm.Left,!0)})}let i=e.get(r.id);return i?{...r,position:i.position,dragging:n}:r})};function o(e){let{changes:n,updatedInternals:r}=gg(e,t.nodeLookup,t.parentLookup,t.domNode,t.nodeOrigin,t.nodeExtent,t.zIndexMode);if(!r)return;sg(t.nodeLookup,t.parentLookup,{nodeOrigin:t.nodeOrigin,nodeExtent:t.nodeExtent,zIndexMode:t.zIndexMode}),t.fitViewQueued&&t.resolveFitView();let i=new Map;for(let e of n){let n=t.nodeLookup.get(e.id)?.internals.userNode;if(!n)continue;let r={...n};switch(e.type){case`dimensions`:{let t={...r.measured,...e.dimensions};e.setAttributes&&(r.width=e.dimensions?.width??r.width,r.height=e.dimensions?.height??r.height),r.measured=t;break}case`position`:r.position=e.position??r.position}i.set(e.id,r)}t.nodes=t.nodes.map(e=>i.get(e.id)??e)}function s(e){let n=t.fitViewResolver??Promise.withResolvers();return t.fitViewQueued=!0,t.fitViewOptions=e,t.fitViewResolver=n,t.nodes=[...t.nodes],n.promise}async function c(e,n,r){let i=r?.zoom===void 0?t.maxZoom:r.zoom,a=t.panZoom;return a?(await a.setViewport({x:t.width/2-e*i,y:t.height/2-n*i,zoom:i},{duration:r?.duration,ease:r?.ease,interpolate:r?.interpolate}),!0):!1}async function l(e,n){let r=t.panZoom;return r?r.scaleBy(e,n):!1}async function u(e){return l(1.2,e)}function d(e){return l(1/1.2,e)}function f(e){let n=t.panZoom;n&&(n.setScaleExtent([e,t.maxZoom]),t.minZoom=e)}function p(e){let n=t.panZoom;n&&(n.setScaleExtent([t.minZoom,e]),t.maxZoom=e)}function m(e){let n=t.panZoom;n&&(n.setTranslateExtent(e),t.translateExtent=e)}function h(e,t=null){let n=!1,r=e.map(e=>(!t||t.has(e.id))&&e.selected?(n=!0,{...e,selected:!1}):e);return[n,r]}function g(e){let n=e?.nodes?new Set(e.nodes.map(e=>e.id)):null,[r,i]=h(t.nodes,n);r&&(t.nodes=i);let a=e?.edges?new Set(e.edges.map(e=>e.id)):null,[o,s]=h(t.edges,a);o&&(t.edges=s)}function _(e){let n=t.multiselectionKeyPressed;t.nodes=t.nodes.map(t=>{let r=e.includes(t.id),i=n&&t.selected||r;return!!t.selected===i?t:{...t,selected:i}}),n||g({nodes:[]})}function v(e){let n=t.multiselectionKeyPressed;t.edges=t.edges.map(t=>{let r=e.includes(t.id),i=n&&t.selected||r;return!!t.selected===i?t:{...t,selected:i}}),n||g({edges:[]})}function y(e,n,r){let i=t.nodeLookup.get(e);i?(t.selectionRect=null,t.selectionRectMode=null,i.selected?(n||i.selected&&t.multiselectionKeyPressed)&&(g({nodes:[i.internals.userNode],edges:[]}),requestAnimationFrame(()=>r?.blur())):_([e])):t.onerror(`012`,xm.error012(e))}function b(e){let n=t.edgeLookup.get(e);n?(n.selectable||t.elementsSelectable&&n.selectable===void 0)&&(t.selectionRect=null,t.selectionRectMode=null,n.selected?n.selected&&t.multiselectionKeyPressed&&g({nodes:[],edges:[n]}):v([e])):t.onerror(`016`,xm.error016(e))}function x(e,n){let{nodeExtent:r,snapGrid:i,nodeOrigin:o,nodeLookup:s,nodesDraggable:c,onerror:l}=t,u=new Map,d=i?.[0]??5,f=i?.[1]??5,p=e.x*d*n,m=e.y*f*n;for(let e of s.values()){if(!(e.selected&&(e.draggable||c&&e.draggable===void 0)))continue;let t={x:e.internals.positionAbsolute.x+p,y:e.internals.positionAbsolute.y+m};i&&(t=sh(t,i));let{position:n,positionAbsolute:a}=Um({nodeId:e.id,nextPosition:t,nodeLookup:s,nodeExtent:r,nodeOrigin:o,onError:l});e.position=n,e.internals.positionAbsolute=a,u.set(e.id,e)}a(u)}function S(e){return _g({delta:e,panZoom:t.panZoom,transform:[t.viewport.x,t.viewport.y,t.viewport.zoom],translateExtent:t.translateExtent,width:t.width,height:t.height})}let C=e=>{t._connection={...e}};function w(){t._connection=Om}function ee(){t.resetStoreValues(),g()}return Object.assign(t,{setNodeTypes:n,setEdgeTypes:r,addEdge:i,updateNodePositions:a,updateNodeInternals:o,zoomIn:u,zoomOut:d,fitView:s,setCenter:c,setMinZoom:f,setMaxZoom:p,setTranslateExtent:m,unselectNodesAndEdges:g,addSelectedNodes:_,addSelectedEdges:v,handleNodeSelection:y,handleEdgeSelection:b,moveSelectedNodes:x,panBy:S,updateConnection:C,cancelConnection:w,reset:ee})}function tv(e,t){let{minZoom:n,maxZoom:r,initialViewport:i,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:s,translateExtent:c,setPanZoomInstance:l,onDraggingChange:u,onTransformChange:d}=t,f=Xg({domNode:e,minZoom:n,maxZoom:r,translateExtent:c,viewport:i,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:s,onDraggingChange:u}),p=f.getViewport();return(i.x!==p.x||i.y!==p.y||i.zoom!==p.zoom)&&d([p.x,p.y,p.zoom]),l(f),f.update(t),{update(e){f.update(e)}}}var nv=H(`<div class="svelte-flow__zoom svelte-flow__container"><!></div>`);function rv(e,t){k(t,!0);let n=Y(t,`store`,15),r=j(()=>n().panActivationKeyPressed||t.panOnDrag),i=j(()=>n().panActivationKeyPressed||t.panOnScroll),{viewport:a}=n(),o=!1;In(()=>{!o&&n().viewportInitialized&&(t.oninit?.(),o=!0)});var s=nv();Fi(P(s),()=>t.children),O(s),Ri(s,(e,t)=>tv?.(e,t),()=>({viewport:n().viewport,minZoom:n().minZoom,maxZoom:n().maxZoom,initialViewport:a,onDraggingChange:e=>{n(n().dragging=e,!0)},setPanZoomInstance:e=>{n(n().panZoom=e,!0)},onPanZoomStart:t.onmovestart,onPanZoom:t.onmove,onPanZoomEnd:t.onmoveend,zoomOnScroll:t.zoomOnScroll,zoomOnDoubleClick:t.zoomOnDoubleClick,zoomOnPinch:t.zoomOnPinch,panOnScroll:z(i),panOnDrag:z(r),panOnScrollSpeed:t.panOnScrollSpeed,panOnScrollMode:t.panOnScrollMode,panActivationKeyPressed:n().panActivationKeyPressed,zoomActivationKeyPressed:n().zoomActivationKeyPressed,preventScrolling:typeof t.preventScrolling!=`boolean`||t.preventScrolling,noPanClassName:n().noPanClass,noWheelClassName:n().noWheelClass,userSelectionActive:!!n().selectionRect,translateExtent:n().translateExtent,lib:`svelte`,paneClickDistance:t.paneClickDistance,selectionOnDrag:t.selectionOnDrag,onTransformChange:e=>{n(n().viewport={x:e[0],y:e[1],zoom:e[2]},!0)},connectionInProgress:n().connection.inProgress})),U(e,s),A()}function iv(e,t){return n=>{n.target===t&&e?.(n)}}function av(e){return t=>{let n=e.has(t.id);return!!t.selected===n?t:{...t,selected:n}}}function ov(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}var sv=H(`<div><!></div>`);function cv(e,t){k(t,!0);let n=Y(t,`store`,15),r=Y(t,`panOnDrag`,3,!0),i=Y(t,`paneClickDistance`,3,1),a=Y(t,`autoPanOnSelection`,3,!0),o,s=null,c=!1,l=new Set,u=new Set,d=j(()=>n().panActivationKeyPressed||r()),f=j(()=>n().selectionKeyPressed||!!n().selectionRect||t.selectionOnDrag&&z(d)!==!0),p=j(()=>n().elementsSelectable&&(z(f)||n().selectionRectMode===`user`)),m=!1,h=0,g={x:0,y:0},_=!1;function v(e){if(e.pointerType===`touch`&&z(d)!==!1&&!n().selectionKeyPressed||(s=o?.getBoundingClientRect(),!s))return;let r=e.target===o,i=!r&&!!e.target.closest(`.nokey`),a=t.selectionOnDrag&&r||n().selectionKeyPressed;if(i||!z(f)||!a||e.button!==0||!e.isPrimary)return;e.target?.setPointerCapture?.(e.pointerId),m=!1,_=!1;let{x:c,y:l}=kh(e,s),u=ch({x:c,y:l},[n().viewport.x,n().viewport.y,n().viewport.zoom]);n(n().selectionRect={width:0,height:0,startX:u.x,startY:u.y,x:c,y:l},!0),r||(e.stopPropagation(),e.preventDefault())}function y(e,t){if(n().selectionRect?.startX===void 0||n().selectionRect.startY===void 0)return;let r={x:n().selectionRect?.startX,y:n().selectionRect?.startY},i=lh(r,[n().viewport.x,n().viewport.y,n().viewport.zoom]),a={startX:r.x,startY:r.y,x:e<i.x?e:i.x,y:t<i.y?t:i.y,width:Math.abs(e-i.x),height:Math.abs(t-i.y)},o=l,s=u;l=new Set(zm(n().nodeLookup,a,[n().viewport.x,n().viewport.y,n().viewport.zoom],n().selectionMode===Dm.Partial,!0).map(e=>e.id));let c=n().defaultEdgeOptions.selectable??!0;u=new Set;for(let e of l){let t=n().connectionLookup.get(e);if(t)for(let{edgeId:e}of t.values()){let t=n().edgeLookup.get(e);t&&(t.selectable??c)&&u.add(e)}}ov(o,l)||n(n().nodes=n().nodes.map(av(l)),!0),ov(s,u)||n(n().edges=n().edges.map(av(u)),!0),n(n().selectionRectMode=`user`,!0),n(n().selectionRect=a,!0)}function b(){if(!a()||!s)return;let[e,t]=Ym(g,s,n().autoPanSpeed);n().panBy({x:e,y:t}).then(e=>{!m||!e||y(g.x,g.y),h=requestAnimationFrame(b)})}function x(){cancelAnimationFrame(h),h=0,_=!1}Ha(()=>{typeof window<`u`&&x()});function S(e){if(!z(f)||!s||!n().selectionRect)return;let r=kh(e,s);g={x:r.x,y:r.y};let a=lh({x:n().selectionRect.startX,y:n().selectionRect.startY},[n().viewport.x,n().viewport.y,n().viewport.zoom]);if(!m){let o=n().selectionKeyPressed?0:i();if(Math.hypot(r.x-a.x,r.y-a.y)<=o)return;n().unselectNodesAndEdges(),t.onselectionstart?.(e)}m=!0,_||=(b(),!0),y(r.x,r.y)}function C(e){z(p)?e.button===0&&(e.target?.releasePointerCapture?.(e.pointerId),!m&&e.target===o&&te?.(e),n(n().selectionRect=null,!0),m&&n(n().selectionRectMode=l.size>0?`nodes`:null,!0),m&&t.onselectionend?.(e),x()):e.target===o&&n().connection.inProgress&&(c=!0)}function w(e){e.target?.releasePointerCapture?.(e.pointerId),x()}let ee=e=>{Array.isArray(z(d))&&z(d).includes(2)?e.preventDefault():t.onpanecontextmenu?.({event:e})},T=e=>{m&&=(e.stopPropagation(),!1)};function te(e){m||n().connection.inProgress||c?(m=!1,c=!1):(t.onpaneclick?.({event:e}),n().unselectNodesAndEdges(),n(n().selectionRectMode=null,!0),n(n().selectionRect=null,!0))}var E=sv();let ne;var re=j(()=>z(p)?void 0:iv(te,o)),ie=j(()=>iv(ee,o));Fi(P(E),()=>t.children),O(E),Ma(E,e=>o=e,()=>o),R(e=>ne=Ji(E,1,`svelte-flow__pane svelte-flow__container`,null,ne,{draggable:e,dragging:n().dragging,selection:z(f)}),[()=>r()===!0||Array.isArray(r())&&r().includes(0)]),V(`click`,E,function(...e){z(re)?.apply(this,e)}),B(`pointerdown`,E,function(...e){(z(p)?v:void 0)?.apply(this,e)},!0),V(`pointermove`,E,function(...e){(z(p)?S:void 0)?.apply(this,e)}),V(`pointerup`,E,C),B(`pointercancel`,E,function(...e){(z(p)?w:void 0)?.apply(this,e)}),V(`contextmenu`,E,function(...e){z(ie)?.apply(this,e)}),B(`click`,E,function(...e){(z(p)?T:void 0)?.apply(this,e)},!0),U(e,E),A()}Zr([`click`,`pointermove`,`pointerup`,`contextmenu`]);var lv=H(`<div class="svelte-flow__viewport xyflow__viewport svelte-flow__container"><!></div>`);function uv(e,t){k(t,!0);var n=lv();let r;Fi(P(n),()=>t.children),O(n),R(()=>r=Xi(n,``,r,{transform:`translate(${t.store.viewport.x??``}px, ${t.store.viewport.y??``}px) scale(${t.store.viewport.zoom??``})`})),U(e,n),A()}function dv(e,t){let{store:n,onDrag:r,onDragStart:i,onDragStop:a,onNodeMouseDown:o}=t,s=Tg({onDrag:r,onDragStart:i,onDragStop:a,onNodeMouseDown:o,getStoreItems:()=>{let{snapGrid:e,viewport:t}=n;return{nodes:n.nodes,nodeLookup:n.nodeLookup,edges:n.edges,nodeExtent:n.nodeExtent,snapGrid:e||[0,0],snapToGrid:!!e,nodeOrigin:n.nodeOrigin,multiSelectionActive:n.multiselectionKeyPressed,domNode:n.domNode,transform:[t.x,t.y,t.zoom],autoPanOnNodeDrag:n.autoPanOnNodeDrag,nodesDraggable:n.nodesDraggable,selectNodesOnDrag:n.selectNodesOnDrag,nodeDragThreshold:n.nodeDragThreshold,unselectNodesAndEdges:n.unselectNodesAndEdges,updateNodePositions:n.updateNodePositions,onSelectionDrag:n.onselectiondrag,onSelectionDragStart:n.onselectiondragstart,onSelectionDragStop:n.onselectiondragstop,panBy:n.panBy}}});function c(e,t){t.disabled?s.destroy():s.update({domNode:e,noDragClassName:t.noDragClass,handleSelector:t.handleSelector,nodeId:t.nodeId,isSelectable:t.isSelectable,nodeClickDistance:t.nodeClickDistance})}return c(e,t),{update(t){c(e,t)},destroy(){s.destroy()}}}var fv=H(`<div aria-live="assertive" aria-atomic="true" class="a11y-live-msg svelte-13pq11u"> </div>`),pv=H(`<div class="a11y-hidden svelte-13pq11u"> </div> <div class="a11y-hidden svelte-13pq11u"> </div> <!>`,1);function mv(e,t){k(t,!0);var n=pv(),r=F(n),i=I(r,!0),a=L(r,2),o=I(a,!0),s=L(a,2),c=e=>{var n=fv(),r=I(n,!0);R(()=>{q(n,`id`,`${_v}-${t.store.flowId}`),W(r,t.store.ariaLiveMessage)}),U(e,n)};G(s,e=>{t.store.disableKeyboardA11y||e(c)}),R(()=>{q(r,`id`,`${hv}-${t.store.flowId}`),W(i,t.store.disableKeyboardA11y?t.store.ariaLabelConfig[`node.a11yDescription.default`]:t.store.ariaLabelConfig[`node.a11yDescription.keyboardDisabled`]),q(a,`id`,`${gv}-${t.store.flowId}`),W(o,t.store.ariaLabelConfig[`edge.a11yDescription.default`])}),U(e,n),A()}var hv=`svelte-flow__node-desc`,gv=`svelte-flow__edge-desc`,_v=`svelte-flow__aria-live`,vv=H(`<div><!></div>`);function yv(e,t){k(t,!0);let n=Y(t,`store`,15),r=j(()=>_(t.node.data,()=>({}),!0)),i=j(()=>_(t.node.selected,!1)),a=j(()=>t.node.draggable),o=j(()=>t.node.selectable),s=j(()=>_(t.node.deletable,!0)),c=j(()=>t.node.connectable),l=j(()=>t.node.focusable),u=j(()=>_(t.node.hidden,!1)),d=j(()=>_(t.node.dragging,!1)),f=j(()=>_(t.node.style,``)),p=j(()=>t.node.class),m=j(()=>_(t.node.type,`default`)),h=j(()=>t.node.parentId),g=j(()=>t.node.sourcePosition),v=j(()=>t.node.targetPosition),y=j(()=>_(t.node.measured,()=>({width:0,height:0}),!0).width),b=j(()=>_(t.node.measured,()=>({width:0,height:0}),!0).height),x=j(()=>t.node.initialWidth),S=j(()=>t.node.initialHeight),C=j(()=>t.node.width),w=j(()=>t.node.height),ee=j(()=>t.node.dragHandle),T=j(()=>_(t.node.internals.z,0)),te=j(()=>t.node.internals.positionAbsolute.x),E=j(()=>t.node.internals.positionAbsolute.y),ne=j(()=>t.node.internals.userNode),{id:re}=t.node,ie=j(()=>z(a)??n().nodesDraggable),ae=j(()=>z(o)??n().elementsSelectable),oe=j(()=>z(c)??n().nodesConnectable),se=j(()=>_h(t.node)),ce=j(()=>!!t.node.internals.handleBounds),le=j(()=>z(se)&&z(ce)),ue=j(()=>z(l)??n().nodesFocusable);function de(e){return n().parentLookup.has(e)}let fe=j(()=>de(re)),pe=M(null),me=null,he=z(m),ge=z(g),_e=z(v),ve=j(()=>n().nodeTypes[z(m)]??d_),ye=j(()=>n().ariaLabelConfig);n_(re),i_({get value(){return z(oe)}});let be=j(()=>{let e=z(y)===void 0?z(C)??z(x):z(C),t=z(b)===void 0?z(w)??z(S):z(w);if(e!==void 0||t!==void 0||z(f)!==void 0)return`${z(f)};${e?`width:${S_(e)};`:``}${t?`height:${S_(t)};`:``}`});In(()=>{(z(m)!==he||z(g)!==ge||z(v)!==_e)&&z(pe)!==null&&requestAnimationFrame(()=>{z(pe)!==null&&n().updateNodeInternals(new Map([[re,{id:re,nodeElement:z(pe),force:!0}]]))}),he=z(m),ge=z(g),_e=z(v)}),In(()=>{t.resizeObserver&&(!z(le)||z(pe)!==me)&&(me&&t.resizeObserver.unobserve(me),z(pe)&&t.resizeObserver.observe(z(pe)),me=z(pe))}),Ha(()=>{me&&t.resizeObserver?.unobserve(me)});function xe(e){z(ae)&&(!n().selectNodesOnDrag||!z(ie)||n().nodeDragThreshold>0)&&n().handleNodeSelection(re),t.onnodeclick?.({node:z(ne),event:e})}function Se(e){if(!(Dh(e)||n().disableKeyboardA11y)){if(Cm.includes(e.key)&&z(ae)){let t=e.key===`Escape`;n().handleNodeSelection(re,t,z(pe))}else z(ie)&&t.node.selected&&Object.prototype.hasOwnProperty.call(C_,e.key)&&(e.preventDefault(),n(n().ariaLiveMessage=z(ye)[`node.a11yDescription.ariaLiveMessage`]({direction:e.key.replace(`Arrow`,``).toLowerCase(),x:~~t.node.internals.positionAbsolute.x,y:~~t.node.internals.positionAbsolute.y}),!0),n().moveSelectedNodes(C_[e.key],e.shiftKey?4:1))}}let Ce=()=>{if(n().disableKeyboardA11y||!n().autoPanOnNodeFocus||!z(pe)?.matches(`:focus-visible`))return;let{width:e,height:r,viewport:i}=n();zm(new Map([[re,t.node]]),{x:0,y:0,width:e,height:r},[i.x,i.y,i.zoom],!0).length>0||n().setCenter(t.node.position.x+(t.node.measured.width??0)/2,t.node.position.y+(t.node.measured.height??0)/2,{zoom:i.zoom})};var we=ci(),Te=F(we),Ee=e=>{var a=vv();va(a,()=>({"data-id":re,class:[`svelte-flow__node`,`svelte-flow__node-${z(m)}`,z(p)],style:z(be),onclick:xe,onpointerenter:t.onnodepointerenter?e=>t.onnodepointerenter({node:z(ne),event:e}):void 0,onpointerleave:t.onnodepointerleave?e=>t.onnodepointerleave({node:z(ne),event:e}):void 0,onpointermove:t.onnodepointermove?e=>t.onnodepointermove({node:z(ne),event:e}):void 0,oncontextmenu:t.onnodecontextmenu?e=>t.onnodecontextmenu({node:z(ne),event:e}):void 0,onkeydown:z(ue)?Se:void 0,onfocus:z(ue)?Ce:void 0,tabIndex:z(ue)?0:void 0,role:t.node.ariaRole??(z(ue)?`group`:void 0),"aria-label":t.node.ariaLabel,"aria-roledescription":`node`,"aria-describedby":n().disableKeyboardA11y?void 0:`${hv}-${n().flowId}`,...t.node.domAttributes,[aa]:{dragging:z(d),selected:z(i),draggable:z(ie),connectable:z(oe),selectable:z(ae),nopan:z(ie),parent:z(fe)},[oa]:{"z-index":z(T),transform:`translate(${z(te)??``}px, ${z(E)??``}px)`,visibility:z(se)?`visible`:`hidden`}})),Ii(P(a),()=>z(ve),(e,t)=>{t(e,{get data(){return z(r)},get id(){return re},get selected(){return z(i)},get selectable(){return z(ae)},get deletable(){return z(s)},get sourcePosition(){return z(g)},get targetPosition(){return z(v)},get zIndex(){return z(T)},get dragging(){return z(d)},get draggable(){return z(ie)},get dragHandle(){return z(ee)},get parentId(){return z(h)},get type(){return z(m)},get isConnectable(){return z(oe)},get positionAbsoluteX(){return z(te)},get positionAbsoluteY(){return z(E)},get width(){return z(C)},get height(){return z(w)}})}),O(a),Ri(a,(e,t)=>dv?.(e,t),()=>({nodeId:re,isSelectable:z(ae),disabled:!z(ie),handleSelector:z(ee),noDragClass:n().noDragClass,nodeClickDistance:t.nodeClickDistance,onNodeMouseDown:n().handleNodeSelection,onDrag:(e,n,r,i)=>{t.onnodedrag?.({event:e,targetNode:r,nodes:i})},onDragStart:(e,n,r,i)=>{t.onnodedragstart?.({event:e,targetNode:r,nodes:i})},onDragStop:(e,n,r,i)=>{t.onnodedragstop?.({event:e,targetNode:r,nodes:i})},store:n()})),Ma(a,e=>N(pe,e),()=>z(pe)),U(e,a)};G(Te,e=>{z(u)||e(Ee)}),U(e,we),A()}var bv=H(`<div class="svelte-flow__nodes"></div>`);function xv(e,t){k(t,!0);let n=Y(t,`store`,15),r=typeof ResizeObserver>`u`?null:new ResizeObserver(e=>{let t=new Map;e.forEach(e=>{let n=e.target.getAttribute(`data-id`);t.set(n,{id:n,nodeElement:e.target,force:!0})}),n().updateNodeInternals(t)});Ha(()=>{r?.disconnect()});var i=bv();K(i,21,()=>n().visible.nodes.values(),e=>e.id,(e,i)=>{yv(e,{get node(){return z(i)},get resizeObserver(){return r},get nodeClickDistance(){return t.nodeClickDistance},get onnodeclick(){return t.onnodeclick},get onnodepointerenter(){return t.onnodepointerenter},get onnodepointermove(){return t.onnodepointermove},get onnodepointerleave(){return t.onnodepointerleave},get onnodedrag(){return t.onnodedrag},get onnodedragstart(){return t.onnodedragstart},get onnodedragstop(){return t.onnodedragstop},get onnodecontextmenu(){return t.onnodecontextmenu},get store(){return n()},set store(e){n(e)}})}),O(i),U(e,i),A()}var Sv=oi(`<svg class="svelte-flow__edge-wrapper"><g><!></g></svg>`);function Cv(e,t){k(t,!0);let n=j(()=>t.edge.id),r=j(()=>t.edge.source),i=j(()=>t.edge.target),a=j(()=>t.edge.sourceX),o=j(()=>t.edge.sourceY),s=j(()=>t.edge.targetX),c=j(()=>t.edge.targetY),l=j(()=>t.edge.sourcePosition),u=j(()=>t.edge.targetPosition),d=j(()=>_(t.edge.animated,!1)),f=j(()=>_(t.edge.selected,!1)),p=j(()=>t.edge.label),m=j(()=>t.edge.labelStyle),h=j(()=>_(t.edge.data,()=>({}),!0)),g=j(()=>t.edge.style),v=j(()=>t.edge.interactionWidth),y=j(()=>_(t.edge.type,`default`)),b=j(()=>t.edge.sourceHandle),x=j(()=>t.edge.targetHandle),S=j(()=>t.edge.markerStart),C=j(()=>t.edge.markerEnd),w=j(()=>t.edge.selectable),ee=j(()=>t.edge.focusable),T=j(()=>_(t.edge.deletable,!0)),te=j(()=>t.edge.hidden),E=j(()=>t.edge.zIndex),ne=j(()=>t.edge.class),re=j(()=>t.edge.ariaLabel);o_(z(n));let ie=null,ae=j(()=>z(w)??t.store.elementsSelectable),oe=j(()=>z(ee)??t.store.edgesFocusable),se=j(()=>t.store.edgeTypes[z(y)]??j_),ce=j(()=>z(S)?`url('#${$h(z(S),t.store.flowId)}')`:void 0),le=j(()=>z(C)?`url('#${$h(z(C),t.store.flowId)}')`:void 0);function ue(e){let r=t.store.edgeLookup.get(z(n));r&&(z(ae)&&t.store.handleEdgeSelection(z(n)),t.onedgeclick?.({event:e,edge:r}))}function de(e,r){let i=t.store.edgeLookup.get(z(n));i&&r({event:e,edge:i})}function fe(e){if(!t.store.disableKeyboardA11y&&Cm.includes(e.key)&&z(ae)){let{unselectNodesAndEdges:r,addSelectedEdges:i}=t.store;e.key===`Escape`?(ie?.blur(),r({edges:[t.edge]})):i([z(n)])}}var pe=ci(),me=F(pe),he=e=>{var _=Sv();let S;var C=P(_);va(C,()=>({class:[`svelte-flow__edge`,z(ne)],"data-id":z(n),onclick:ue,oncontextmenu:t.onedgecontextmenu?e=>{de(e,t.onedgecontextmenu)}:void 0,onpointerenter:t.onedgepointerenter?e=>{de(e,t.onedgepointerenter)}:void 0,onpointerleave:t.onedgepointerleave?e=>{de(e,t.onedgepointerleave)}:void 0,"aria-label":z(re)===null?void 0:z(re)?z(re):`Edge from ${z(r)} to ${z(i)}`,"aria-describedby":z(oe)?`${gv}-${t.store.flowId}`:void 0,role:t.edge.ariaRole??(z(oe)?`group`:`img`),"aria-roledescription":`edge`,onkeydown:z(oe)?fe:void 0,tabindex:z(oe)?0:void 0,...t.edge.domAttributes,[aa]:{animated:z(d),selected:z(f),selectable:z(ae)}})),Ii(P(C),()=>z(se),(e,t)=>{t(e,{get id(){return z(n)},get source(){return z(r)},get target(){return z(i)},get sourceX(){return z(a)},get sourceY(){return z(o)},get targetX(){return z(s)},get targetY(){return z(c)},get sourcePosition(){return z(l)},get targetPosition(){return z(u)},get animated(){return z(d)},get selected(){return z(f)},get label(){return z(p)},get labelStyle(){return z(m)},get data(){return z(h)},get style(){return z(g)},get interactionWidth(){return z(v)},get selectable(){return z(ae)},get deletable(){return z(T)},get type(){return z(y)},get sourceHandleId(){return z(b)},get targetHandleId(){return z(x)},get markerStart(){return z(ce)},get markerEnd(){return z(le)}})}),O(C),Ma(C,e=>ie=e,()=>ie),O(_),R(()=>S=Xi(_,``,S,{"z-index":z(E)})),U(e,_)};G(me,e=>{z(te)||e(he)}),U(e,pe),A()}Xe();var wv=oi(`<defs></defs>`);function Tv(e,t){k(t,!1);let n=Q_();Pa();var r=wv();K(r,5,()=>n.markers,e=>e.id,(e,t)=>{kv(e,Ba(()=>z(t)))}),O(r),U(e,r),A()}var Ev=oi(`<polyline class="arrow" fill="none" stroke-linecap="round" stroke-linejoin="round" points="-5,-4 0,0 -5,4"></polyline>`),Dv=oi(`<polyline class="arrowclosed" stroke-linecap="round" stroke-linejoin="round" points="-5,-4 0,0 -5,4 -5,-4"></polyline>`),Ov=oi(`<marker class="svelte-flow__arrowhead" viewBox="-10 -10 20 20" refX="0" refY="0"><!></marker>`);function kv(e,t){k(t,!0);let n=Y(t,`width`,3,12.5),r=Y(t,`height`,3,12.5),i=Y(t,`markerUnits`,3,`strokeWidth`),a=Y(t,`orient`,3,`auto-start-reverse`),o=Y(t,`color`,3,`none`);var s=Ov(),c=P(s),l=e=>{var n=Ev();let r;R(()=>{q(n,`stroke-width`,t.strokeWidth),r=Xi(n,``,r,{stroke:o()})}),U(e,n)},u=e=>{var n=Dv();let r;R(()=>{q(n,`stroke-width`,t.strokeWidth),r=Xi(n,``,r,{stroke:o(),fill:o()})}),U(e,n)};G(c,e=>{t.type===Am.Arrow?e(l):t.type===Am.ArrowClosed&&e(u,1)}),O(s),R(()=>{q(s,`id`,t.id),q(s,`markerWidth`,`${n()}`),q(s,`markerHeight`,`${r()}`),q(s,`markerUnits`,i()),q(s,`orient`,a())}),U(e,s),A()}var Av=H(`<div class="svelte-flow__edges"><svg class="svelte-flow__marker"><!></svg> <!></div>`);function jv(e,t){k(t,!0);let n=Y(t,`store`,15);var r=Av(),i=P(r);Tv(P(i),{}),O(i),K(L(i,2),17,()=>n().visible.edges.values(),e=>e.id,(e,r)=>{Cv(e,{get edge(){return z(r)},get onedgeclick(){return t.onedgeclick},get onedgecontextmenu(){return t.onedgecontextmenu},get onedgepointerenter(){return t.onedgepointerenter},get onedgepointerleave(){return t.onedgepointerleave},get store(){return n()},set store(e){n(e)}})}),O(r),U(e,r),A()}var Mv=H(`<div class="svelte-flow__selection svelte-1vr3gfi"></div>`);function Nv(e,t){k(t,!0);let n=Y(t,`x`,3,0),r=Y(t,`y`,3,0),i=Y(t,`width`,3,0),a=Y(t,`height`,3,0),o=Y(t,`isVisible`,3,!0);var s=ci(),c=F(s),l=e=>{var t=Mv();let o;R((e,i)=>o=Xi(t,``,o,{width:e,height:i,transform:`translate(${n()}px, ${r()}px)`}),[()=>typeof i()==`string`?i():S_(i()),()=>typeof a()==`string`?a():S_(a())]),U(e,t)};G(c,e=>{o()&&e(l)}),U(e,s),A()}var Pv=H(`<div><!></div>`);function Fv(e,t){k(t,!0);let n=M(void 0);In(()=>{t.store.disableKeyboardA11y||z(n)?.focus({preventScroll:!0})});let r=j(()=>{if(t.store.selectionRectMode===`nodes`){t.store.nodes;let e=Rm(t.store.nodeLookup,{filter:e=>!!e.selected});if(e.width>0&&e.height>0)return e}return null});function i(e){let n=t.store.nodes.filter(e=>e.selected);t.onselectioncontextmenu?.({nodes:n,event:e})}function a(e){let n=t.store.nodes.filter(e=>e.selected);t.onselectionclick?.({nodes:n,event:e})}function o(e){Object.prototype.hasOwnProperty.call(C_,e.key)&&(e.preventDefault(),t.store.moveSelectedNodes(C_[e.key],e.shiftKey?4:1))}var s=ci(),c=F(s),l=e=>{var s=Pv();let c;Nv(P(s),{width:`100%`,height:`100%`,x:0,y:0}),O(s),Ri(s,(e,t)=>dv?.(e,t),()=>({disabled:!1,store:t.store,onDrag:(e,n,r,i)=>{t.onnodedrag?.({event:e,targetNode:null,nodes:i})},onDragStart:(e,n,r,i)=>{t.onnodedragstart?.({event:e,targetNode:null,nodes:i})},onDragStop:(e,n,r,i)=>{t.onnodedragstop?.({event:e,targetNode:null,nodes:i})}})),Ma(s,e=>N(n,e),()=>z(n)),R((e,n)=>{Ji(s,1,Hi([`svelte-flow__selection-wrapper`,t.store.noPanClass]),`svelte-sf2y5e`),q(s,`role`,t.store.disableKeyboardA11y?void 0:`button`),q(s,`tabindex`,t.store.disableKeyboardA11y?void 0:-1),c=Xi(s,``,c,{width:e,height:n,transform:`translate(${z(r).x??``}px, ${z(r).y??``}px)`})},[()=>S_(z(r).width),()=>S_(z(r).height)]),V(`contextmenu`,s,i),V(`click`,s,a),V(`keydown`,s,function(...e){(t.store.disableKeyboardA11y?void 0:o)?.apply(this,e)}),U(e,s)},u=j(()=>t.store.selectionRectMode===`nodes`&&z(r)&&ah(z(r).x)&&ah(z(r).y));G(c,e=>{z(u)&&e(l)}),U(e,s),A()}Zr([`contextmenu`,`click`,`keydown`]);function Iv(e){switch(e){case`none`:return 0;case`ctrl`:return 8;case`shift`:return 4;case`alt`:return 2;case`meta`:return 1}}function Lv(e,t){let{enabled:n=!0,trigger:r,type:i=`keydown`}=t;function a(t){let n=Array.isArray(r)?r:[r],i=[t.metaKey,t.altKey,t.shiftKey,t.ctrlKey].reduce((e,t,n)=>t?e|1<<n:e,0);for(let r of n){let n={preventDefault:!1,enabled:!0,...r},{modifier:a,key:o,code:s,callback:c,preventDefault:l,enabled:u}=n;if(!o&&!s&&console.warn("[svelte-put/shortcut] Trigger should have either `key` or `code`, a trigger missing both was detected! Check your configuration"),u&&(o||s)){if(s&&t.code!==s||o&&t.key!==o)continue;if(a===null||a===!1){if(i!==0)continue}else if(a!==void 0&&a?.[0]?.length>0){let e=Array.isArray(a)?a:[a],t=!1;for(let n of e)if((Array.isArray(n)?n:[n]).reduce((e,t)=>e|Iv(t),0)===i){t=!0;break}if(!t)continue}l&&t.preventDefault();let r={node:e,trigger:n,originalEvent:t};e.dispatchEvent(new CustomEvent(`shortcut`,{detail:r})),c?.(r)}}}let o;return n&&(o=Xr(e,i,a)),{update:t=>{let{enabled:s=!0,type:c=`keydown`}=t;n&&(!s||i!==c)?o?.():!n&&s&&(o=Xr(e,c,a)),n=s,i=c,r=t.trigger},destroy:()=>{o?.()}}}function Rv(){let e=j(Q_),t=t=>{let n=b_(t)?t:z(e).nodeLookup.get(t.id),r=n.parentId?vh(n.position,n.measured,n.parentId,z(e).nodeLookup,z(e).nodeOrigin):n.position;return $m({...n,position:r,width:n.measured?.width??n.width,height:n.measured?.height??n.height})};function n(t,n,r={replace:!1}){z(e).nodes=Nr(()=>z(e).nodes).map(e=>{if(e.id===t){let t=typeof n==`function`?n(e):n;return r?.replace&&b_(t)?t:{...e,...t}}return e})}function r(t,n,r={replace:!1}){z(e).edges=Nr(()=>z(e).edges).map(e=>{if(e.id===t){let t=typeof n==`function`?n(e):n;return r.replace&&x_(t)?t:{...e,...t}}return e})}let i=t=>z(e).nodeLookup.get(t);return{zoomIn:z(e).zoomIn,zoomOut:z(e).zoomOut,getInternalNode:i,getNode:e=>i(e)?.internals.userNode,getNodes:t=>t===void 0?z(e).nodes:zv(z(e).nodeLookup,t),getEdge:t=>z(e).edgeLookup.get(t),getEdges:t=>t===void 0?z(e).edges:zv(z(e).edgeLookup,t),setZoom:async(t,n)=>{let r=z(e).panZoom;return r?r.scaleTo(t,n):!1},getZoom:()=>z(e).viewport.zoom,setViewport:async(t,n)=>{let r=z(e).viewport;return z(e).panZoom?(await z(e).panZoom.setViewport({x:t.x??r.x,y:t.y??r.y,zoom:t.zoom??r.zoom},n),!0):!1},getViewport:()=>Qe(z(e).viewport),setCenter:async(t,n,r)=>z(e).setCenter(t,n,r),fitView:t=>z(e).fitView(t),fitBounds:async(t,n)=>{if(!z(e).panZoom)return!1;let r=ph(t,z(e).width,z(e).height,z(e).minZoom,z(e).maxZoom,n?.padding??.1);return await z(e).panZoom.setViewport(r,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0},getIntersectingNodes:(n,r=!0,i)=>{let a=ih(n),o=a?n:t(n);return o?(i||z(e).nodes).filter(t=>{let i=z(e).nodeLookup.get(t.id);if(!i||!a&&t.id===n.id)return!1;let s=$m(i),c=rh(s,o);return r&&c>0||c>=s.width*s.height||c>=o.width*o.height}):[]},isNodeIntersecting:(e,n,r=!0)=>{let i=ih(e)?e:t(e);if(!i)return!1;let a=rh(i,n);return r&&a>0||a>=n.width*n.height||a>=i.width*i.height},deleteElements:async({nodes:t=[],edges:n=[]})=>{let{nodes:r,edges:i}=await Wm({nodesToRemove:t,edgesToRemove:n,nodes:z(e).nodes,edges:z(e).edges,onBeforeDelete:z(e).onbeforedelete});return r&&(z(e).nodes=Nr(()=>z(e).nodes).filter(e=>!r.some(({id:t})=>t===e.id))),i&&(z(e).edges=Nr(()=>z(e).edges).filter(e=>!i.some(({id:t})=>t===e.id))),(r.length>0||i.length>0)&&z(e).ondelete?.({nodes:r,edges:i}),{deletedNodes:r,deletedEdges:i}},screenToFlowPosition:(t,n={snapToGrid:!0})=>{if(!z(e).domNode)return t;let r=n.snapToGrid?z(e).snapGrid:!1,{x:i,y:a,zoom:o}=z(e).viewport,{x:s,y:c}=z(e).domNode.getBoundingClientRect();return ch({x:t.x-s,y:t.y-c},[i,a,o],r!==null,r||[1,1])},flowToScreenPosition:t=>{if(!z(e).domNode)return t;let{x:n,y:r,zoom:i}=z(e).viewport,{x:a,y:o}=z(e).domNode.getBoundingClientRect(),s=lh(t,[n,r,i]);return{x:s.x+a,y:s.y+o}},toObject:()=>structuredClone({nodes:[...z(e).nodes],edges:[...z(e).edges],viewport:{...z(e).viewport}}),updateNode:n,updateNodeData:(t,r,i)=>{let a=z(e).nodeLookup.get(t)?.internals.userNode;if(!a)return;let o=typeof r==`function`?r(a):r;n(t,e=>({...e,data:i?.replace?o:{...e.data,...o}}))},updateEdge:r,getNodesBounds:t=>Lm(t,{nodeLookup:z(e).nodeLookup,nodeOrigin:z(e).nodeOrigin}),getHandleConnections:({type:t,id:n,nodeId:r})=>Array.from(z(e).connectionLookup.get(`${r}-${t}-${n??null}`)?.values()??[])}}function zv(e,t){let n=[];for(let r of t){let t=e.get(r);if(t){let e=`internals`in t?t.internals?.userNode:t;n.push(e)}}return n}function Bv(e,t){k(t,!0);let n=Y(t,`store`,15),r=Y(t,`selectionKey`,3,`Shift`),i=Y(t,`multiSelectionKey`,19,()=>mh()?`Meta`:`Control`),a=Y(t,`deleteKey`,3,`Backspace`),o=Y(t,`panActivationKey`,3,` `),s=Y(t,`zoomActivationKey`,19,()=>mh()?`Meta`:`Control`),{deleteElements:c}=Rv();function l(e){return typeof e==`object`&&!!e}function u(e){return l(e)&&e.modifier||[]}function d(e){return e==null?``:l(e)?e.key:e}function f(e,t){return(Array.isArray(e)?e:[e]).map(e=>{let n=d(e);return{key:n,modifier:u(e),enabled:n!==null,callback:t}})}function p(){n(n().selectionRect=null,!0),n(n().selectionKeyPressed=!1,!0),n(n().multiselectionKeyPressed=!1,!0),n(n().deleteKeyPressed=!1,!0),n(n().panActivationKeyPressed=!1,!0),n(n().zoomActivationKeyPressed=!1,!0)}function m(){let e=n().nodes.filter(e=>e.selected),t=n().edges.filter(e=>e.selected);c({nodes:e,edges:t})}B(`blur`,gn,p),B(`contextmenu`,gn,p),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(r(),()=>n(n().selectionKeyPressed=!0,!0)),type:`keydown`})),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(r(),()=>n(n().selectionKeyPressed=!1,!0)),type:`keyup`})),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(i(),()=>{n(n().multiselectionKeyPressed=!0,!0)}),type:`keydown`})),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(i(),()=>n(n().multiselectionKeyPressed=!1,!0)),type:`keyup`})),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(a(),e=>{!(e.originalEvent.ctrlKey||e.originalEvent.metaKey||e.originalEvent.shiftKey)&&!Dh(e.originalEvent)&&(n(n().deleteKeyPressed=!0,!0),m())}),type:`keydown`})),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(a(),()=>n(n().deleteKeyPressed=!1,!0)),type:`keyup`})),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(o(),()=>n(n().panActivationKeyPressed=!0,!0)),type:`keydown`})),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(o(),()=>n(n().panActivationKeyPressed=!1,!0)),type:`keyup`})),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(s(),()=>n(n().zoomActivationKeyPressed=!0,!0)),type:`keydown`})),Ri(gn,(e,t)=>Lv?.(e,t),()=>({trigger:f(s(),()=>n(n().zoomActivationKeyPressed=!1,!0)),type:`keyup`})),A()}var Vv=oi(`<path fill="none" class="svelte-flow__connection-path"></path>`),Hv=oi(`<svg class="svelte-flow__connectionline"><g><!></g></svg>`);function Uv(e,t){k(t,!0);let n=j(()=>{if(!t.store.connection.inProgress)return``;let e={sourceX:t.store.connection.from.x,sourceY:t.store.connection.from.y,sourcePosition:t.store.connection.fromPosition,targetX:t.store.connection.to.x,targetY:t.store.connection.to.y,targetPosition:t.store.connection.toPosition};switch(t.type){case km.Bezier:{let[t]=Ph(e);return t}case km.Straight:{let[t]=Vh(e);return t}case km.Step:case km.SmoothStep:{let[n]=qh({...e,borderRadius:t.type===km.Step?0:void 0});return n}}});var r=ci(),i=F(r),a=e=>{var r=Hv(),i=P(r),a=P(i),o=e=>{var n=ci();Ii(F(n),()=>t.LineComponent,(e,t)=>{t(e,{})}),U(e,n)},s=e=>{var r=Vv();R(()=>{q(r,`d`,z(n)),Xi(r,t.style)}),U(e,r)};G(a,e=>{t.LineComponent?e(o):e(s,-1)}),O(i),O(r),R(e=>{q(r,`width`,t.store.width),q(r,`height`,t.store.height),Xi(r,t.containerStyle),Ji(i,0,e)},[()=>Hi([`svelte-flow__connection`,Sh(t.store.connection.isValid)])]),U(e,r)};G(i,e=>{t.store.connection.inProgress&&e(a)}),U(e,r),A()}var Wv=new Set([`$$slots`,`$$events`,`$$legacy`,`position`,`style`,`class`,`children`]),Gv=H(`<div><!></div>`);function Kv(e,t){k(t,!0);let n=Y(t,`position`,3,`top-right`),r=J(t,Wv),i=j(()=>`${n()}`.split(`-`));var a=Gv();va(a,e=>({class:e,style:t.style,...r}),[()=>[`svelte-flow__panel`,t.class,...z(i)]]),Fi(P(a),()=>t.children??f),O(a),U(e,a),A()}var qv=H(`<a target="_blank" rel="noopener noreferrer" aria-label="Svelte Flow attribution">Svelte Flow</a>`);function Jv(e,t){k(t,!0);let n=Y(t,`position`,3,`bottom-right`),r=`https://svelteflow.dev?utm_source=attribution`;var i=ci(),a=F(i),o=e=>{{let t=j(()=>`Please only hide this attribution when you are subscribed to Svelte Flow Pro: ${r}`);Kv(e,{get position(){return n()},class:`svelte-flow__attribution`,get"data-message"(){return z(t)},children:(e,t)=>{var n=qv();R(()=>q(n,`href`,r)),U(e,n)},$$slots:{default:!0}})}};G(a,e=>{t.proOptions?.hideAttribution||e(o)}),U(e,i),A()}var Yv=H(`<div><!></div>`);function Xv(e,t){k(t,!0);let n=Y(t,`domNode`,15),r=Y(t,`clientWidth`,15),i=Y(t,`clientHeight`,15),a=j(()=>t.rest.class),o=j(()=>y(t.rest,`id.class.nodeTypes.edgeTypes.colorMode.isValidConnection.onmove.onmovestart.onmoveend.onflowerror.ondelete.onbeforedelete.onbeforeconnect.onconnect.onconnectstart.onconnectend.onbeforereconnect.onreconnect.onreconnectstart.onreconnectend.onclickconnectstart.onclickconnectend.oninit.onselectionchange.onselectiondragstart.onselectiondrag.onselectiondragstop.onselectionstart.onselectionend.clickConnect.fitView.fitViewOptions.nodeOrigin.nodeDragThreshold.connectionDragThreshold.minZoom.maxZoom.initialViewport.connectionRadius.connectionMode.selectionMode.selectNodesOnDrag.snapGrid.defaultMarkerColor.translateExtent.nodeExtent.onlyRenderVisibleElements.autoPanOnConnect.autoPanOnNodeDrag.colorModeSSR.defaultEdgeOptions.elevateNodesOnSelect.elevateEdgesOnSelect.nodesDraggable.autoPanOnNodeFocus.nodesConnectable.elementsSelectable.nodesFocusable.edgesFocusable.disableKeyboardA11y.noDragClass.noPanClass.noWheelClass.ariaLabelConfig.autoPanSpeed.panOnScrollSpeed.zIndexMode.autoPanOnSelection`.split(`.`)));function s(e){e.currentTarget.scrollTo({top:0,left:0,behavior:`auto`}),t.rest.onscroll&&t.rest.onscroll(e)}var c=Yv();va(c,(e,n)=>({class:[`svelte-flow`,`svelte-flow__container`,t.colorMode,z(a)],"data-testid":`svelte-flow__wrapper`,role:`application`,onscroll:s,...z(o),[oa]:{width:e,height:n}}),[()=>S_(t.width),()=>S_(t.height)],void 0,void 0,`svelte-mkap6j`),Fi(P(c),()=>t.children??f),O(c),Ma(c,e=>n(e),()=>n()),Aa(c,`clientHeight`,i),Aa(c,`clientWidth`,r),U(e,c),A()}var Zv=new Set(`$$slots.$$events.$$legacy.width.height.proOptions.selectionKey.deleteKey.panActivationKey.multiSelectionKey.zoomActivationKey.paneClickDistance.nodeClickDistance.onmovestart.onmoveend.onmove.oninit.onnodeclick.onnodecontextmenu.onnodedrag.onnodedragstart.onnodedragstop.onnodepointerenter.onnodepointermove.onnodepointerleave.onselectionclick.onselectioncontextmenu.onselectionstart.onselectionend.onedgeclick.onedgecontextmenu.onedgepointerenter.onedgepointerleave.onpaneclick.onpanecontextmenu.panOnScrollMode.preventScrolling.zoomOnScroll.zoomOnDoubleClick.zoomOnPinch.panOnScroll.panOnScrollSpeed.panOnDrag.selectionOnDrag.autoPanOnSelection.connectionLineComponent.connectionLineStyle.connectionLineContainerStyle.connectionLineType.attributionPosition.children.nodes.edges.viewport`.split(`.`)),Qv=H(`<div class="svelte-flow__viewport-back svelte-flow__container"></div> <!> <div class="svelte-flow__edge-labels svelte-flow__container"></div> <!> <!> <!> <div class="svelte-flow__viewport-front svelte-flow__container"></div>`,1),$v=H(`<!> <!>`,1),ey=H(`<!> <!> <!> <!> <!>`,1);function ty(e,t){k(t,!0);let n=Y(t,`paneClickDistance`,3,1),r=Y(t,`nodeClickDistance`,3,1),i=Y(t,`panOnScrollMode`,19,()=>Em.Free),a=Y(t,`preventScrolling`,3,!0),o=Y(t,`zoomOnScroll`,3,!0),s=Y(t,`zoomOnDoubleClick`,3,!0),c=Y(t,`zoomOnPinch`,3,!0),l=Y(t,`panOnScroll`,3,!1),u=Y(t,`panOnScrollSpeed`,3,.5),d=Y(t,`panOnDrag`,3,!0),p=Y(t,`selectionOnDrag`,3,!1),m=Y(t,`autoPanOnSelection`,3,!0),h=Y(t,`connectionLineType`,19,()=>km.Bezier),g=Y(t,`nodes`,31,()=>pn([])),_=Y(t,`edges`,31,()=>pn([])),v=Y(t,`viewport`,15,void 0),y=J(t,Zv),b=ev({props:y,width:t.width,height:t.height,get nodes(){return g()},set nodes(e){g(e)},get edges(){return _()},set edges(e){_(e)},get viewport(){return v()},set viewport(e){v(e)}}),x=it($_);x&&x.setStore&&x.setStore(b),at($_,{provider:!1,getStore(){return b}}),In(()=>{let e={nodes:b.selectedNodes,edges:b.selectedEdges};Nr(()=>t.onselectionchange)?.(e);for(let t of b.selectionChangeHandlers.values())t(e)}),Ha(()=>{x?.setStore(ev({width:0,height:0,nodes:[],edges:[],props:{}}))}),Xv(e,{get colorMode(){return b.colorMode},get width(){return t.width},get height(){return t.height},get rest(){return y},get domNode(){return b.domNode},set domNode(e){b.domNode=e},get clientWidth(){return b.width},set clientWidth(e){b.width=e},get clientHeight(){return b.height},set clientHeight(e){b.height=e},children:(e,g)=>{var _=ey(),v=F(_);Bv(v,{get selectionKey(){return t.selectionKey},get deleteKey(){return t.deleteKey},get panActivationKey(){return t.panActivationKey},get multiSelectionKey(){return t.multiSelectionKey},get zoomActivationKey(){return t.zoomActivationKey},get store(){return b},set store(e){b=e}});var y=L(v,2);rv(y,{get panOnScrollMode(){return i()},get preventScrolling(){return a()},get zoomOnScroll(){return o()},get zoomOnDoubleClick(){return s()},get zoomOnPinch(){return c()},get panOnScroll(){return l()},get panOnScrollSpeed(){return u()},get panOnDrag(){return d()},get paneClickDistance(){return n()},get selectionOnDrag(){return p()},get onmovestart(){return t.onmovestart},get onmove(){return t.onmove},get onmoveend(){return t.onmoveend},get oninit(){return t.oninit},get store(){return b},set store(e){b=e},children:(e,i)=>{cv(e,{get onpaneclick(){return t.onpaneclick},get onpanecontextmenu(){return t.onpanecontextmenu},get onselectionstart(){return t.onselectionstart},get onselectionend(){return t.onselectionend},get panOnDrag(){return d()},get paneClickDistance(){return n()},get selectionOnDrag(){return p()},get autoPanOnSelection(){return m()},get store(){return b},set store(e){b=e},children:(e,n)=>{var i=$v(),a=F(i);uv(a,{get store(){return b},set store(e){b=e},children:(e,n)=>{var i=Qv(),a=L(F(i),2);jv(a,{get onedgeclick(){return t.onedgeclick},get onedgecontextmenu(){return t.onedgecontextmenu},get onedgepointerenter(){return t.onedgepointerenter},get onedgepointerleave(){return t.onedgepointerleave},get store(){return b},set store(e){b=e}});var o=L(a,4);Uv(o,{get type(){return h()},get LineComponent(){return t.connectionLineComponent},get containerStyle(){return t.connectionLineContainerStyle},get style(){return t.connectionLineStyle},get store(){return b},set store(e){b=e}});var s=L(o,2);xv(s,{get nodeClickDistance(){return r()},get onnodeclick(){return t.onnodeclick},get onnodecontextmenu(){return t.onnodecontextmenu},get onnodepointerenter(){return t.onnodepointerenter},get onnodepointermove(){return t.onnodepointermove},get onnodepointerleave(){return t.onnodepointerleave},get onnodedrag(){return t.onnodedrag},get onnodedragstart(){return t.onnodedragstart},get onnodedragstop(){return t.onnodedragstop},get store(){return b},set store(e){b=e}}),Fv(L(s,2),{get onselectionclick(){return t.onselectionclick},get onselectioncontextmenu(){return t.onselectioncontextmenu},get onnodedrag(){return t.onnodedrag},get onnodedragstart(){return t.onnodedragstart},get onnodedragstop(){return t.onnodedragstop},get store(){return b},set store(e){b=e}}),je(2),U(e,i)},$$slots:{default:!0}});var o=L(a,2);{let e=j(()=>!!(b.selectionRect&&b.selectionRectMode===`user`)),t=j(()=>b.selectionRect?.width),n=j(()=>b.selectionRect?.height),r=j(()=>b.selectionRect?.x),i=j(()=>b.selectionRect?.y);Nv(o,{get isVisible(){return z(e)},get width(){return z(t)},get height(){return z(n)},get x(){return z(r)},get y(){return z(i)}})}U(e,i)},$$slots:{default:!0}})},$$slots:{default:!0}});var x=L(y,2);Jv(x,{get proOptions(){return t.proOptions},get position(){return t.attributionPosition}});var S=L(x,2);mv(S,{get store(){return b}}),Fi(L(S,2),()=>t.children??f),U(e,_)},$$slots:{default:!0}}),A()}function ny(e,t){k(t,!0);let n=M(ev({props:{},nodes:[],edges:[]}));at($_,{provider:!0,getStore(){return z(n)},setStore:e=>{N(n,e)}}),Ha(()=>{z(n).reset()});var r=ci();Fi(F(r),()=>t.children??f),U(e,r),A()}var ry=new Set([`$$slots`,`$$events`,`$$legacy`,`target`,`children`]),iy=H(`<div><!></div>`);function ay(e,t){k(t,!0);let n=Y(t,`target`,3,`front`),r=J(t,ry);var i=iy();va(i,e=>({...r,[oa]:{display:e}}),[()=>y_().value?`none`:void 0]),Fi(P(i),()=>t.children??f),O(i),Ri(i,(e,t)=>v_?.(e,t),()=>`viewport-${n()}`),U(e,i),A()}var oy;(function(e){e.Lines=`lines`,e.Dots=`dots`,e.Cross=`cross`})(oy||={});var sy=oi(`<circle></circle>`);function cy(e,t){var n=sy();R(()=>{q(n,`cx`,t.radius),q(n,`cy`,t.radius),q(n,`r`,t.radius),Ji(n,0,Hi([`svelte-flow__background-pattern`,`dots`,t.class]))}),U(e,n)}var ly=oi(`<path></path>`);function uy(e,t){k(t,!0);var n=ly();R(()=>{q(n,`stroke-width`,t.lineWidth),q(n,`d`,`M${t.dimensions[0]/2} 0 V${t.dimensions[1]} M0 ${t.dimensions[1]/2} H${t.dimensions[0]}`),Ji(n,0,Hi([`svelte-flow__background-pattern`,t.variant,t.class]))}),U(e,n),A()}var dy={[oy.Dots]:1,[oy.Lines]:1,[oy.Cross]:6},fy=oi(`<svg data-testid="svelte-flow__background"><pattern patternUnits="userSpaceOnUse"><!></pattern><rect x="0" y="0" width="100%" height="100%"></rect></svg>`);function py(e,t){k(t,!0);let n=Y(t,`variant`,19,()=>oy.Dots),r=Y(t,`gap`,3,20),i=Y(t,`lineWidth`,3,1),a=j(Q_),o=j(()=>n()===oy.Dots),s=j(()=>n()===oy.Cross),c=j(()=>Array.isArray(r())?r():[r(),r()]),l=j(()=>`background-pattern-${z(a).flowId}-${t.id??``}`),u=j(()=>[z(c)[0]*z(a).viewport.zoom||1,z(c)[1]*z(a).viewport.zoom||1]),d=j(()=>(t.size??dy[n()])*z(a).viewport.zoom),f=j(()=>z(s)?[z(d),z(d)]:z(u)),p=j(()=>z(o)?[z(d)/2,z(d)/2]:[z(f)[0]/2,z(f)[1]/2]);var m=fy();let h;var g=P(m),_=P(g),v=e=>{{let n=j(()=>z(d)/2);cy(e,{get radius(){return z(n)},get class(){return t.patternClass}})}},y=e=>{uy(e,{get dimensions(){return z(f)},get variant(){return n()},get lineWidth(){return i()},get class(){return t.patternClass}})};G(_,e=>{z(o)?e(v):e(y,-1)}),O(g);var b=L(g);O(m),R(()=>{Ji(m,0,Hi([`svelte-flow__background`,`svelte-flow__container`,t.class])),h=Xi(m,``,h,{"--xy-background-color-props":t.bgColor,"--xy-background-pattern-color-props":t.patternColor}),q(g,`id`,z(l)),q(g,`x`,z(a).viewport.x%z(u)[0]),q(g,`y`,z(a).viewport.y%z(u)[1]),q(g,`width`,z(u)[0]),q(g,`height`,z(u)[1]),q(g,`patternTransform`,`translate(-${z(p)[0]},-${z(p)[1]})`),q(b,`fill`,`url(#${z(l)})`)}),U(e,m),A()}function my(e){let t=j(Q_),n=j(()=>z(t).nodeLookup),r=j(()=>z(t).nodes),i=j(()=>(z(r),z(n).get(e)));return{get current(){return z(i)}}}var hy=oi(`<rect></rect>`);function gy(e,t){k(t,!0);let n=Y(t,`borderRadius`,3,5),r=Y(t,`strokeWidth`,3,2),i=j(()=>my(t.id)),a=j(()=>{if(!z(i).current)return{width:0,height:0,x:0,y:0};let{width:e,height:n}=gh(z(i).current);return{width:t.width??e,height:t.height??n,x:t.x??z(i).current.internals.positionAbsolute.x,y:t.y??z(i).current.internals.positionAbsolute.y}}),o=j(()=>z(a).width),s=j(()=>z(a).height),c=j(()=>z(a).x),l=j(()=>z(a).y);var u=ci(),d=F(u),f=e=>{let i=j(()=>t.nodeComponent);var a=ci();Ii(F(a),()=>z(i),(e,i)=>{i(e,{get id(){return t.id},get x(){return z(c)},get y(){return z(l)},get width(){return z(o)},get height(){return z(s)},get borderRadius(){return n()},get class(){return t.class},get color(){return t.color},get shapeRendering(){return t.shapeRendering},get strokeColor(){return t.strokeColor},get strokeWidth(){return r()},get selected(){return t.selected}})}),U(e,a)},p=e=>{var i=hy();let a,u;R(()=>{a=Ji(i,0,Hi([`svelte-flow__minimap-node`,t.class]),null,a,{selected:t.selected}),q(i,`x`,z(c)),q(i,`y`,z(l)),q(i,`rx`,n()),q(i,`ry`,n()),q(i,`width`,z(o)),q(i,`height`,z(s)),q(i,`shape-rendering`,t.shapeRendering),u=Xi(i,``,u,{fill:t.color,stroke:t.strokeColor,"stroke-width":r()})}),U(e,i)};G(d,e=>{t.nodeComponent?e(f):e(p,-1)}),U(e,u),A()}function _y(e,t){let n=Ig({domNode:e,panZoom:t.panZoom,getTransform:()=>{let{viewport:e}=t.store;return[e.x,e.y,e.zoom]},getViewScale:t.getViewScale});n.update({translateExtent:t.translateExtent,width:t.width,height:t.height,inversePan:t.inversePan,zoomStep:t.zoomStep,pannable:t.pannable,zoomable:t.zoomable});function r(e){n.update({translateExtent:e.translateExtent,width:e.width,height:e.height,inversePan:e.inversePan,zoomStep:e.zoomStep,pannable:e.pannable,zoomable:e.zoomable})}return{update:r,destroy(){n.destroy()}}}var vy=e=>e instanceof Function?e:()=>e,yy=new Set([`$$slots`,`$$events`,`$$legacy`,`position`,`ariaLabel`,`nodeStrokeColor`,`nodeColor`,`nodeClass`,`nodeBorderRadius`,`nodeStrokeWidth`,`nodeComponent`,`bgColor`,`maskColor`,`maskStrokeColor`,`maskStrokeWidth`,`width`,`height`,`pannable`,`zoomable`,`inversePan`,`zoomStep`,`class`]),by=oi(`<title> </title>`),xy=oi(`<svg class="svelte-flow__minimap-svg" role="img"><!><!><path class="svelte-flow__minimap-mask" fill-rule="evenodd" pointer-events="none"></path></svg>`),Sy=H(`<svelte-css-wrapper style="display: contents"><!></svelte-css-wrapper>`,1);function Cy(e,t){k(t,!0);let n=Y(t,`position`,3,`bottom-right`),r=Y(t,`nodeStrokeColor`,3,`transparent`),i=Y(t,`nodeClass`,3,``),a=Y(t,`nodeBorderRadius`,3,5),o=Y(t,`nodeStrokeWidth`,3,2),s=Y(t,`width`,3,200),c=Y(t,`height`,3,150),l=Y(t,`pannable`,3,!0),u=Y(t,`zoomable`,3,!0),d=J(t,yy),f=j(Q_),p=j(()=>z(f).ariaLabelConfig),m=typeof window>`u`||window.chrome?`crispEdges`:`geometricPrecision`,h=j(()=>`svelte-flow__minimap-desc-${z(f).flowId}`),g=j(()=>({x:-z(f).viewport.x/z(f).viewport.zoom,y:-z(f).viewport.y/z(f).viewport.zoom,width:z(f).width/z(f).viewport.zoom,height:z(f).height/z(f).viewport.zoom})),_=j(()=>z(f).nodes.some(e=>!e.hidden)),v=j(()=>z(_)?th(Rm(z(f).nodeLookup,{filter:e=>!e.hidden}),z(g)):z(g)),y=j(()=>z(v).width/s()),b=j(()=>z(v).height/c()),x=j(()=>Math.max(z(y),z(b))),S=j(()=>z(x)*s()),C=j(()=>z(x)*c()),w=j(()=>5*z(x)),ee=j(()=>z(v).x-(z(S)-z(v).width)/2-z(w)),T=j(()=>z(v).y-(z(C)-z(v).height)/2-z(w)),te=j(()=>z(S)+z(w)*2),E=j(()=>z(C)+z(w)*2),ne=()=>z(x);var re=Sy(),ie=F(re);{let e=j(()=>[`svelte-flow__minimap`,t.class]);Ti(ie,()=>({"--xy-minimap-background-color-props":t.bgColor})),Kv(ie.lastChild,Ba({get position(){return n()},get class(){return z(e)},"data-testid":`svelte-flow__minimap`},()=>d,{children:(e,n)=>{var d=ci(),_=F(d),v=e=>{var n=xy();let d;var _=P(n),v=e=>{var n=by(),r=I(n,!0);R(()=>{q(n,`id`,z(h)),W(r,t.ariaLabel??z(p)[`minimap.ariaLabel`])}),U(e,n)};G(_,e=>{(t.ariaLabel??z(p)[`minimap.ariaLabel`])&&e(v)});var y=L(_);K(y,17,()=>z(f).nodes,e=>e.id,(e,n)=>{let s=j(()=>z(f).nodeLookup.get(z(n).id));var c=ci(),l=F(c),u=e=>{{let c=j(()=>t.nodeColor===void 0?void 0:vy(t.nodeColor)(z(n))),l=j(()=>vy(r())(z(n))),u=j(()=>vy(i())(z(n)));gy(e,{get id(){return z(s).id},get selected(){return z(s).selected},get nodeComponent(){return t.nodeComponent},get color(){return z(c)},get borderRadius(){return a()},get strokeColor(){return z(l)},get strokeWidth(){return o()},get shapeRendering(){return m},get class(){return z(u)}})}},d=j(()=>z(s)&&_h(z(s))&&!z(s).hidden);G(l,e=>{z(d)&&e(u)}),U(e,c)});var b=L(y);O(n),Ri(n,(e,t)=>_y?.(e,t),()=>({store:z(f),panZoom:z(f).panZoom,getViewScale:ne,translateExtent:z(f).translateExtent,width:z(f).width,height:z(f).height,inversePan:t.inversePan,zoomStep:t.zoomStep,pannable:l(),zoomable:u()})),R(()=>{q(n,`width`,s()),q(n,`height`,c()),q(n,`viewBox`,`${z(ee)??``} ${z(T)??``} ${z(te)??``} ${z(E)??``}`),q(n,`aria-labelledby`,z(h)),d=Xi(n,``,d,{"--xy-minimap-mask-background-color-props":t.maskColor,"--xy-minimap-mask-stroke-color-props":t.maskStrokeColor,"--xy-minimap-mask-stroke-width-props":t.maskStrokeWidth?t.maskStrokeWidth*z(x):void 0}),q(b,`d`,`M${z(ee)-z(w)},${z(T)-z(w)}h${z(te)+z(w)*2}v${z(E)+z(w)*2}h${-z(te)-z(w)*2}z
6
6
  M${z(g).x??``},${z(g).y??``}h${z(g).width??``}v${z(g).height??``}h${-z(g).width}z`)}),U(e,n)};G(_,e=>{z(f).panZoom&&e(v)}),U(e,d)},$$slots:{default:!0}})),O(ie)}U(e,re),A()}var wy=new Set([`$$slots`,`$$events`,`$$legacy`,`nodeId`,`position`,`align`,`offset`,`isVisible`,`children`]),Ty=H(`<div><!></div>`);function Ey(e,t){k(t,!0);let n=Y(t,`position`,19,()=>jm.Top),r=Y(t,`align`,3,`center`),i=Y(t,`offset`,3,10),a=J(t,wy),o=Q_(),{getNodesBounds:s}=Rv(),c=t_(),l=j(()=>(o.nodes,(Array.isArray(t.nodeId)?t.nodeId:[t.nodeId??c]).reduce((e,t)=>{if(!t)throw Error(`Either pass a nodeId or use within a Custom Node component`);let n=o.nodeLookup.get(t);return n&&e.push(n),e},[]))),u=j(()=>{let e=s(z(l));return e?tg(e,o.viewport,n(),i(),r()):``}),d=j(()=>z(l).length===0?1:Math.max(...z(l).map(e=>(e.internals.z||5)+1))),p=j(()=>o.nodes.filter(e=>e.selected).length),m=j(()=>typeof t.isVisible==`boolean`?t.isVisible:z(l).length===1&&z(l)[0].selected&&z(p)===1);var h=ci(),g=F(h),_=e=>{var n=Ty();va(n,(e,t)=>({class:`svelte-flow__node-toolbar`,"data-id":e,...a,[oa]:{display:t,position:`absolute`,transform:z(u),"z-index":z(d)}}),[()=>z(l).reduce((e,t)=>`${e}${t.id} `,``).trim(),()=>y_().value?`none`:void 0]),Fi(P(n),()=>t.children??f),O(n),Ri(n,(e,t)=>v_?.(e,t),()=>`root`),U(e,n)};G(g,e=>{o.domNode&&z(m)&&z(l)&&e(_)}),U(e,h),A()}function Dy(){let e=j(Q_);return{get current(){return z(e).viewport},set current(t){z(e).viewport=t},update(t){z(e).viewport=t(z(e).viewport)},set(t){z(e).viewport=t}}}var Oy=new Set([`$$slots`,`$$events`,`$$legacy`]);function ky(e,t){let n=J(t,Oy),r={name:`plug`,size:24,node:[[`path`,{d:`M12 22v-5`}],[`path`,{d:`M15 8V2`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`}],[`path`,{d:`M9 8V2`}]]};$a(e,Ba(()=>n,{get icon(){return r}}))}var Ay=new class{#e=M(!1);get open(){return z(this.#e)}set open(e){N(this.#e,e,!0)}#t=M(pn({}));#n=M(!1);#r=new Set;#i=!1;#a=``;#o=j(()=>[...Q.status?.messages??[]].reverse().map(e=>({...e,answered:z(this.#t)[e.id]??e.answered??null})).filter(e=>!z(this.#n)||e.kind===`question`&&!e.answered));get messages(){return z(this.#o)}set messages(e){N(this.#o,e)}#s=j(()=>this.messages.find(e=>e.kind===`question`&&e.choices?.length&&!e.answered));get question(){return z(this.#s)}set question(e){N(this.#s,e)}follow(){if(Q.status){for(let e of this.messages)this.#r.has(e.id)||(this.#r.add(e.id),this.#i&&(e.kind===`question`&&!e.answered?this.open=!0:e.from===`koppler`&&!e.answered?(this.open=!0,this.#a=e.id):$.show(`Agent: ${e.title}`,e.kind===`failure`?`warning`:`message`,{label:`Open`,run:()=>this.open=!0})));this.#i=!0,this.#a&&this.messages.find(e=>e.id===this.#a)?.answered&&(this.#a=``,this.question||(this.open=!1)),z(this.#n)&&!(Q.status.messages??[]).some(e=>!(e.kind===`question`&&!e.answered))&&N(this.#n,!1)}}async answer(e,t){let n=e.choices?.find(e=>e.id===t.choice),r=n?`${n.label}${t.text?`. ${t.text}`:``}`:t.text??``,i=await Js(`prompt`,{tag:`koppler-reply`,text:`Answer to your question "${e.title}"${e.run?` (run ${e.run})`:``}: ${r}`,data:{message:e.id,...t}});i?.ok?(z(this.#t)[e.id]={at:new Date().toISOString(),...t,via:`canvas`},(Q.status?.agent?.state??`none`)===`none`&&$.show(`Answer saved. The agent gets it when one connects.`)):$.show(i?.status===409?`That question was already answered.`:`Could not send the answer.`,`warning`)}async dismiss(e){let t=await Js(`message-dismiss`,{id:e.id});!t?.ok&&t?.status!==409?$.show(`Could not dismiss it.`,`warning`):z(this.#t)[e.id]={at:new Date().toISOString(),via:`dismissed`}}get waiting(){return[...Q.status?.waiting??[]].reverse().filter(e=>!z(this.#c).includes(e.key))}#c=M(pn([]));async drop(e){let t=await Js(`prompt-drop`,{key:e});t?.ok||t?.status===409?N(this.#c,[...z(this.#c),e],!0):$.show(`Could not drop it.`,`warning`)}async clear(){(await Js(`messages-clear`,{}))?.ok?(N(this.#n,!0),this.question&&$.show(`Cleared. The open question stays.`)):$.show(`Could not clear the messages.`,`warning`)}},jy=H(`<button class="how svelte-ssy1qy" type="button" aria-label="How to connect an agent" title="How to connect an agent" aria-haspopup="dialog"><!></button>`),My=H(`<button class="agent svelte-ssy1qy" type="button"><span class="dot svelte-ssy1qy" aria-hidden="true"></span><span class="words svelte-ssy1qy"> </span></button> <!> <div class="connect svelte-ssy1qy" popover="" role="dialog"><h2 class="svelte-ssy1qy">Connect an agent</h2> <p class="svelte-ssy1qy">Koppler starts and stops a confirmed run by itself. The agent is needed for what it cannot do alone: manual
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>Koppler</title>
7
7
  <script src="./theme.js"></script>
8
- <script type="module" crossorigin src="./assets/index-CSzjiE0H.js"></script>
8
+ <script type="module" crossorigin src="./assets/index-C3Zy4K9N.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="./assets/index-DntXDvS8.css">
10
10
  </head>
11
11
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koppler",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Run the part of your stack you need locally, wired together, while the rest keeps calling a deployed environment.",
5
5
  "license": "MIT",
6
6
  "author": "Ivan Yanowsky",
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5