@markgrafhq/markgraf-embed 0.1.4 → 0.1.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/dist/markgraf-embed.css +7 -0
- package/dist/markgraf-embed.js +14 -14
- package/package.json +1 -1
package/dist/markgraf-embed.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
`:return"\\n";case"\r":return"\\r";case" ":return"\\t";case"\v":return"\\v"}var i=r+1,o=i<t&&e[i]>="0"&&e[i]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+o})+'"'},zo=e=>e,Ae=zo("LT"),ze=zo("GT"),Oe=zo("EQ"),E=(e,t)=>({tag:e,_1:t}),T=E("Nothing"),Xt=e=>E("Just",e),vu=e=>{if(e.tag==="Nothing")return!0;if(e.tag==="Just")return!1;c()},Gc=e=>{if(e.tag==="Nothing")return!1;if(e.tag==="Just")return!0;c()},kt=(e,t)=>({tag:e,_1:t}),Mc=e=>kt("Right",e),Wc={map:e=>t=>{if(t.tag==="Left")return kt("Left",t._1);if(t.tag==="Right")return kt("Right",e(t._1));c()}},Tu={apply:e=>t=>{if(e.tag==="Left")return kt("Left",e._1);if(e.tag==="Right"){if(t.tag==="Left")return kt("Left",t._1);if(t.tag==="Right")return kt("Right",e._1(t._1))}c()},Functor0:()=>Wc},Ac={bind:e=>{if(e.tag==="Left"){const t=e._1;return n=>kt("Left",t)}if(e.tag==="Right"){const t=e._1;return n=>n(t)}c()},Apply0:()=>Tu},zc={pure:Mc,Apply0:()=>Tu},Bc={Applicative0:()=>zc,Bind1:()=>Ac},$c=e=>e,Qc={map:e=>t=>e(t)},wu={apply:e=>t=>e(t),Functor0:()=>Qc},qc={bind:e=>t=>t(e),Apply0:()=>wu},Hc={pure:$c,Apply0:()=>wu},un={Applicative0:()=>Hc,Bind1:()=>qc},Yc=function(e){return function(){return e}},Vc={apply:e=>t=>()=>{const n=e(),r=t();return bu.pure(n(r))()},Functor0:()=>Oc},bu={pure:Yc,Apply0:()=>Vc},Oc={map:e=>t=>()=>{const n=t();return e(n)}},or=(e,t)=>({tag:e,_1:t}),ku=e=>or("Loop",e),Fc={tailRecM:e=>{const t=n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="Loop"){r=e(u._1);continue}if(u.tag==="Done"){i=!1,o=u._1;continue}c()}return o};return n=>t(e(n))},Monad0:()=>un},Xc=(function(e){return function(t){return function(n){return function(){return e(t,n)}}}})(function(e,t){return t.push(e)}),Uc=(e,t)=>({tag:"Iterator",_1:e,_2:t}),Kc=e=>t=>n=>()=>{let r=!1;const i=t._2;for(;!r;){const o=i.value,u=t._1(o);if(u.tag==="Just"&&e(u._1)){n.push(u._1),t._2.value;const s=t._2.value;t._2.value=s+1|0;continue}r=!0}},Zc=e=>t=>()=>{let n=!1;const r=e._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=e._1(i);if(u.tag==="Just"){t(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}c()}},ir=function(e){return function(t){return function(n){for(var r=t,i=n.length,o=i-1;o>=0;o--)r=e(n[o])(r);return r}}},y=function(e){return function(t){return function(n){for(var r=t,i=n.length,o=0;o<i;o++)r=e(r)(n[o]);return r}}},jc=e=>{const t=e.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>t.apply(t.Functor0().map(s=>Nu)(o))(u)})(e.pure())},At={foldr:ir,foldl:y,foldMap:e=>{const t=e.mempty;return n=>At.foldr(r=>i=>e.Semigroup0().append(n(r))(i))(t)}},x=(e,t)=>({tag:"Tuple",_1:e,_2:t}),In=e=>t=>x(e,t),$r=e=>e._2,Qr=e=>e._1,Dt=function(e){return function(t){for(var n=t.length,r=Array(n),i=0;i<n;i++)r[i]=e(i)(t[i]);return r}};var Bo=function(e){return function(t){return e===t}};const tf=Bo,ef=Bo,$o=Bo,nf=function(e){return function(t){return function(n){if(t.length!==n.length)return!1;for(var r=0;r<t.length;r++)if(!e(t[r])(n[r]))return!1;return!0}}},Fe={eq:$o},rf={eq:ef},Qo={eq:tf};var qo=function(e){return function(t){return function(n){return function(r){return function(i){return r<i?e:r===i?t:n}}}}};const of=qo,uf=qo,k={compare:qo(Ae)(Oe)(ze),Eq0:()=>Fe},lt={compare:uf(Ae)(Oe)(ze),Eq0:()=>rf},ot={compare:of(Ae)(Oe)(ze),Eq0:()=>Qo},Lu=function(e){return e},sf=(function(){function e(i){return[i]}function t(i){return function(o){return[i,o]}}function n(i){return function(o){return function(u){return[i,o,u]}}}function r(i){return function(o){return i.concat(o)}}return function(i){return function(o){return function(u){return function(s){return function(a){function f(g,d){switch(d-g){case 0:return u([]);case 1:return o(e)(s(a[g]));case 2:return i(o(t)(s(a[g])))(s(a[g+1]));case 3:return i(i(o(n)(s(a[g])))(s(a[g+1])))(s(a[g+2]));default:var l=g+Math.floor((d-g)/4)*2;return i(o(r)(f(g,l)))(f(l,d))}}return f(0,a.length)}}}}}})(),af=e=>e,qr={traverse:e=>{const t=e.Apply0();return sf(t.apply)(t.Functor0().map)(e.pure)},sequence:e=>qr.traverse(e)(af),Functor0:()=>Ic,Foldable1:()=>At},qt=function(e,t){for(var n=e>t?-1:1,r=new Array(n*(t-e)+1),i=e,o=0;i!==t;)r[o++]=i,i+=n;return r[o]=i,r};var cf=function(e,t){if(e<1)return[];var n=new Array(e);return n.fill(t)},ff=function(e,t){for(var n=[],r=0,i=0;i<e;i++)n[r++]=t;return n};const gf=typeof Array.prototype.fill=="function"?cf:ff,bt=(function(){function e(i,o){this.head=i,this.tail=o}var t={};function n(i){return function(o){return new e(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==t;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(t)(o))}})(),Ht=function(e,t,n){return n.length===0?e({}):t(n[0])(n.slice(1))},_f=function(e,t,n,r){for(var i=0;i<r.length;i++){var o=n(r[i]);if(t(o))return o}return e},Dn=function(e,t,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return e(i);return t},df=function(e,t,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return e(i);return t},lf=function(e,t,n,r,i){if(n<0||n>i.length)return t;var o=i.slice();return o.splice(n,0,r),e(o)},Eu=function(e,t,n,r){if(n<0||n>=r.length)return t;var i=r.slice();return i.splice(n,1),e(i)},Gn=function(e,t,n,r,i){if(n<0||n>=i.length)return t;var o=i.slice();return o[n]=r,e(o)},le=function(e){return e.slice().reverse()},Te=function(e){if(e.length<=1e4)return Array.prototype.concat.apply([],e);for(var t=[],n=0,r=e.length;n<r;n++)for(var i=e[n],o=0,u=i.length;o<u;o++)t.push(i[o]);return t},at=function(e,t){return t.filter(e)},hf=(function(){function e(t,n,r,i,o,u){var s,a,f,g,d,l,_;for(s=o+(u-o>>1),s-o>1&&e(t,n,i,r,o,s),u-s>1&&e(t,n,i,r,s,u),a=o,f=s,g=o;a<s&&f<u;)d=i[a],l=i[f],_=n(t(d)(l)),_>0?(r[g++]=l,++f):(r[g++]=d,++a);for(;a<s;)r[g++]=i[a++];for(;f<u;)r[g++]=i[f++]}return function(t,n,r){var i;return r.length<2?r:(i=r.slice(0),e(t,n,i,r.slice(0),0,r.length),i)}})(),Gt=function(e,t,n){return n.slice(e,t)},ye=function(e,t,n){for(var r=t.length<n.length?t.length:n.length,i=new Array(r),o=0;o<r;o++)i[o]=e(t[o])(n[o]);return i},sn=function(e,t){for(var n=t.length,r=0;r<n;r++)if(e(t[r]))return!0;return!1},Cu=function(e,t){for(var n=t.length,r=0;r<n;r++)if(!e(t[r]))return!1;return!0},vt=e=>t=>hf(e,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;c()},t),pf=e=>t=>vt(n=>r=>e.compare(t(n))(t(r))),de=e=>t=>(()=>{const n=Xc(t);return()=>{const r=[...e];return n(r)(),r}})()(),mf=e=>{if(e.length===0)return e.length-1|0,T;const t=e.length-1|0;return t>=0&&t<e.length?E("Just",{init:Gt(0,e.length-1|0,e),last:e[t]}):T},yf=e=>t=>n=>e>=0&&e<n.length?Gn(Xt,T,e,t(n[e]),n):T,pn=e=>t=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<t.length){if(e(t[s])){i=s+1|0;continue}o=!1,u=E("Just",s);continue}o=!1,u=T}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:t}:{init:Gt(0,n._1,t),rest:Gt(n._1,t.length,t)};if(n.tag==="Nothing")return{init:t,rest:[]};c()},Mn=e=>t=>{const n=vt(r=>i=>e(r._2)(i._2))(Dt(In)(t));return 0<n.length?V($r)(pf(ot)(Qr)((()=>{const r=[n[0]];for(const i of n){const o=e((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;c()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},Jf=e=>t=>{const n=[],r=Uc(i=>i>=0&&i<t.length?E("Just",t[i]):T,{value:0});return Zc(r)(i=>()=>{const o=[];o.push(i),Kc(e(i))(r)(o)(),n.push(o)})(),n},ge=e=>t=>{const n=Dn(Xt,T,e,t);return n.tag==="Just"?E("Just",t[n._1]):T},Su=e=>t=>at(e,t),Be=e=>t=>n=>{const r=Dn(Xt,T,i=>e.eq(i)(t),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;c()},Pu=e=>t=>St(t)(e),Pt=e=>Pu(t=>{const n=e(t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];c()}),Ru=isFinite;function Nf(e,t,n,r){var i=parseFloat(e);return t(i)?n(i):r}const Iu=Math.abs,xf=Math.ceil,Ho=Math.cos,Du=Math.exp,Gu=Math.floor,Yo=function(e){return function(t){return Math.pow(e,t)}},Mu=Math.round,Vo=Math.sin,Wn=Math.sqrt,vf=function(e){return function(t){return function(n){return(n|0)===n?e(n):t}}},ct=function(e){return e},Tf=(function(e){return function(t){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?e(u):t}else return t}}}})(Xt)(T)(10),Wu=vf(Xt)(T),ur=e=>{if(!Ru(e))return 0;if(e>=ct(2147483647))return 2147483647;if(e<=ct(-2147483648))return-2147483648;const t=Wu(e);if(t.tag==="Nothing")return 0;if(t.tag==="Just")return t._1;c()},zt=(e,t,n)=>({tag:e,_1:t,_2:n}),Qt=zt("Nil"),Yt={foldr:e=>t=>{const n=Yt.foldl(i=>o=>e(o)(i))(t),r=(i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=zt("Cons",d._1,g),s=d._2;continue}c()}return f})(Qt);return i=>n(r(i))},foldl:e=>t=>n=>{let r=t,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=e(s)(a._1),i=a._2;continue}c()}return u},foldMap:e=>{const t=e.mempty;return n=>Yt.foldl(r=>{const i=e.Semigroup0().append(r);return o=>i(n(o))})(t)}},wf=function(e){return function(t){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);u.push(n(a));var f=r(a);if(e(f))return u;s=t(f)}}}}}}},bf=e=>{if(e.tag==="Just")return e._1;c()},kf={unfoldr1:wf(vu)(bf)(Qr)($r)},Lf=function(e){return function(t){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);if(e(a))return u;var f=t(a);u.push(n(f)),s=r(f)}}}}}}},Ef=e=>{if(e.tag==="Just")return e._1;c()},Ie={unfoldr:Lf(vu)(Ef)(Qr)($r),Unfoldable10:()=>kf},Ft=(e,t,n,r,i,o,u)=>({tag:e,_1:t,_2:n,_3:r,_4:i,_5:o,_6:u}),De=(e,t,n,r)=>({tag:e,_1:t,_2:n,_3:r}),Hr=(e,t,n)=>({tag:"Split",_1:e,_2:t,_3:n}),Au=(e,t,n)=>({tag:"SplitLast",_1:e,_2:t,_3:n}),$=Ft("Leaf"),mn=De("IterLeaf"),jt=(e,t,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return Ft("Node",1,1,e,t,n,r);if(r.tag==="Node")return Ft("Node",1+r._1|0,1+r._2|0,e,t,n,r);c()}if(n.tag==="Node"){if(r.tag==="Leaf")return Ft("Node",1+n._1|0,1+n._2|0,e,t,n,r);if(r.tag==="Node")return Ft("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,e,t,n,r)}c()},Je=(e,t,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?Ft("Node",1,1,e,t,$,$):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?jt(r._5._3,r._5._4,jt(e,t,n,r._5._5),jt(r._3,r._4,r._5._6,r._6)):jt(r._3,r._4,jt(e,t,n,r._5),r._6):jt(e,t,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?jt(r._5._3,r._5._4,jt(e,t,n,r._5._5),jt(r._3,r._4,r._5._6,r._6)):jt(r._3,r._4,jt(e,t,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?jt(n._6._3,n._6._4,jt(n._3,n._4,n._5,n._6._5),jt(e,t,n._6._6,r)):jt(n._3,n._4,n._5,jt(e,t,n._6,r)):jt(e,t,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?jt(n._6._3,n._6._4,jt(n._3,n._4,n._5,n._6._5),jt(e,t,n._6._6,r)):jt(n._3,n._4,n._5,jt(e,t,n._6,r)):jt(e,t,n,r);c()},An=(e,t,n)=>{if(n.tag==="Leaf")return Hr(T,$,$);if(n.tag==="Node"){const r=e(t)(n._3);if(r==="LT"){const i=An(e,t,n._5);return Hr(i._1,i._2,Je(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=An(e,t,n._6);return Hr(i._1,Je(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return Hr(E("Just",n._4),n._5,n._6)}c()},zu=(e,t,n,r)=>{if(r.tag==="Leaf")return Au(e,t,n);if(r.tag==="Node"){const i=zu(r._3,r._4,r._5,r._6);return Au(i._1,i._2,Je(e,t,n,i._3))}c()},sr=(e,t)=>{if(e.tag==="Leaf")return t;if(e.tag==="Node"){const n=zu(e._3,e._4,e._5,e._6);return Je(n._1,n._2,n._3,t)}c()},Xe=(e,t,n)=>{if(t.tag==="Leaf")return $;if(n.tag==="Leaf")return t;if(n.tag==="Node"){const r=An(e,n._3,t);return sr(Xe(e,r._2,n._5),Xe(e,r._3,n._6))}c()},Yr=(e,t,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return $;if(r.tag==="Node"){const i=An(e,r._3,n),o=Yr(e,t,i._2,r._5),u=Yr(e,t,i._3,r._6);if(i._1.tag==="Just")return Je(r._3,t(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return sr(o,u)}c()},Ne=(e,t,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=An(e,r._3,n),o=Ne(e,t,i._2,r._5),u=Ne(e,t,i._3,r._6);if(i._1.tag==="Just")return Je(r._3,t(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return Je(r._3,r._4,o,u)}c()},Cf=e=>t=>{const n=r=>{if(r.tag==="Leaf")return $;if(r.tag==="Node"){const i=t(r._3)(r._4);if(i.tag==="Just")return Je(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return sr(n(r._5),n(r._6))}c()};return n},yn=(e=>t=>n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="IterLeaf"){i=!1,o=t();continue}if(u.tag==="IterEmit"){i=!1,o=e(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){f=De("IterEmit",h._3,h._4,_),g=h._5;continue}f=De("IterEmit",h._3,h._4,De("IterNode",h._6,_)),g=h._5;continue}c()}return l})(u._2)(u._1);continue}c()}return o})((e,t,n)=>E("Just",x(x(e,t),n)))(e=>T),Tt=e=>t=>n=>r=>{const i=o=>{if(o.tag==="Leaf")return Ft("Node",1,1,n,r,$,$);if(o.tag==="Node"){const u=e.compare(n)(o._3);if(u==="LT")return Je(o._3,o._4,i(o._5),o._6);if(u==="GT")return Je(o._3,o._4,o._5,i(o._6));if(u==="EQ")return Ft("Node",o._1,o._2,n,t(o._4)(r),o._5,o._6)}c()};return i},Z=e=>t=>n=>{const r=i=>{if(i.tag==="Leaf")return Ft("Node",1,1,t,n,$,$);if(i.tag==="Node"){const o=e.compare(t)(i._3);if(o==="LT")return Je(i._3,i._4,r(i._5),i._6);if(o==="GT")return Je(i._3,i._4,i._5,r(i._6));if(o==="EQ")return Ft("Node",i._1,i._2,t,n,i._5,i._6)}c()};return r},te=e=>t=>t.foldl(n=>r=>Z(e)(r._1)(r._2)(n))($),ar=e=>t=>{const n=r=>{if(r.tag==="Leaf")return $;if(r.tag==="Node"){const i=e.compare(t)(r._3);if(i==="LT")return Je(r._3,r._4,n(r._5),r._6);if(i==="GT")return Je(r._3,r._4,r._5,n(r._6));if(i==="EQ")return sr(r._5,r._6)}c()};return n},Sf=e=>{const t=e.compare;return n=>r=>i=>{const o=An(t,r,i),u=n(o._1);if(u.tag==="Nothing")return sr(o._2,o._3);if(u.tag==="Just")return Je(r,u._1,o._2,o._3);c()}},Zt=function(e){return function(t){return e+t|0}},cr=function(e){return function(t){return e+t}},Oo=function(e){return function(t){if(t===0)return 0;var n=Math.abs(t);return(e%n+n)%n}},Pf=function(e){return function(t){return e+t}},se=function(e){return function(t){return e.length===0?t:t.length===0?e:e.concat(t)}},Rf={append:Pf},If={mempty:"",Semigroup0:()=>Rf};function Df(e,t,n){return e==null?t:n(e)}function Fo(e){return function(t){return function(n){return e.apply(n,[t])}}}const Gf=Fo(Number.prototype.toPrecision),Mf=Fo(Number.prototype.toFixed),Wf=Fo(Number.prototype.toExponential),fr=(e,t)=>({tag:e,_1:t}),gr=e=>t=>n=>{const r=ot.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=ot.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},_r=e=>{if(e.tag==="Precision")return Gf(e._1);if(e.tag==="Fixed")return Mf(e._1);if(e.tag==="Exponential")return Wf(e._1);c()},Bu=function(e){return function(){console.log(e)}};function $u(){return Date.now()}function Af(e){return function(){return e.getContext("2d")}}function zf(e){return function(){return e.width}}function Bf(e){return function(){return e.height}}function $f(e){return function(t){return function(){e.width=t}}}function Qf(e){return function(t){return function(){e.height=t}}}function Xo(e){return function(t){return function(){e.lineWidth=t}}}function qf(e){return function(t){return function(){e.fillStyle=t}}}function Hf(e){return function(t){return function(){e.strokeStyle=t}}}function Uo(e){return function(t){return function(){e.lineCap=t}}}function Ko(e){return function(t){return function(){e.lineJoin=t}}}function Yf(e){return function(t){return function(){e.globalCompositeOperation=t}}}function Vf(e){return function(t){return function(){e.globalAlpha=t}}}function Qu(e){return function(){e.beginPath()}}function Zo(e){return function(){e.stroke()}}function jo(e){return function(){e.fill()}}function Of(e){return function(){e.clip()}}function Ff(e){return function(t){return function(n){return function(){e.lineTo(t,n)}}}}function Xf(e){return function(t){return function(n){return function(){e.moveTo(t,n)}}}}function Uf(e){return function(){e.closePath()}}function Kf(e){return function(t){return function(){e.fillRect(t.x,t.y,t.width,t.height)}}}function Zf(e){return function(t){return function(){e.clearRect(t.x,t.y,t.width,t.height)}}}function ti(e){return function(t){return function(){e.scale(t.scaleX,t.scaleY)}}}function qu(e){return function(t){return function(){e.translate(t.translateX,t.translateY)}}}function jf(e){return function(t){return function(){e.textAlign=t}}}function tg(e){return function(t){return function(){e.textBaseline=t}}}function eg(e){return function(t){return function(){e.font=t}}}function ng(e){return function(t){return function(n){return function(r){return function(){e.fillText(t,n,r)}}}}}function dr(e){return function(){e.save()}}function lr(e){return function(){e.restore()}}function rg(e){return function(t){return function(){e.quadraticCurveTo(t.cpx,t.cpy,t.x,t.y)}}}function og(e){return function(t){return function(){e.bezierCurveTo(t.cp1x,t.cp1y,t.cp2x,t.cp2y,t.x,t.y)}}}const Hu=e=>e,ei=e=>e,ni=e=>e,ri=e=>e,Vr=e=>e,ig=Vr("BaselineTop"),ug=Vr("BaselineMiddle"),sg=Vr("BaselineAlphabetic"),ag=Vr("BaselineBottom"),cg=ri("AlignLeft"),fg=ri("AlignRight"),gg=ri("AlignCenter"),oi=ni("BevelJoin"),Or=ni("RoundJoin"),ii=ni("MiterJoin"),ui=ei("Round"),si=ei("Square"),ai=ei("Butt"),_g=Hu("SourceOver"),dg=Hu("Difference"),lg=e=>t=>tg(e)((()=>{if(t==="BaselineTop")return"top";if(t==="BaselineHanging")return"hanging";if(t==="BaselineMiddle")return"middle";if(t==="BaselineAlphabetic")return"alphabetic";if(t==="BaselineIdeographic")return"ideographic";if(t==="BaselineBottom")return"bottom";c()})()),hg=e=>t=>jf(e)((()=>{if(t==="AlignLeft")return"left";if(t==="AlignRight")return"right";if(t==="AlignCenter")return"center";if(t==="AlignStart")return"start";if(t==="AlignEnd")return"end";c()})()),Fr=e=>t=>{if(t==="BevelJoin")return Ko(e)("bevel");if(t==="RoundJoin")return Ko(e)("round");if(t==="MiterJoin")return Ko(e)("miter");c()},ci=e=>t=>{if(t==="Round")return Uo(e)("round");if(t==="Square")return Uo(e)("square");if(t==="Butt")return Uo(e)("butt");c()},Yu=e=>t=>Yf(e)((()=>{if(t==="SourceOver")return"source-over";if(t==="SourceIn")return"source-in";if(t==="SourceOut")return"source-out";if(t==="SourceAtop")return"source-atop";if(t==="DestinationOver")return"destination-over";if(t==="DestinationIn")return"destination-in";if(t==="DestinationOut")return"destination-out";if(t==="DestinationAtop")return"destination-atop";if(t==="Lighter")return"lighter";if(t==="Copy")return"copy";if(t==="Xor")return"xor";if(t==="Multiply")return"multiply";if(t==="Screen")return"screen";if(t==="Overlay")return"overlay";if(t==="Darken")return"darken";if(t==="Lighten")return"lighten";if(t==="ColorDodge")return"color-dodge";if(t==="ColorBurn")return"color-burn";if(t==="HardLight")return"hard-light";if(t==="SoftLight")return"soft-light";if(t==="Difference")return"difference";if(t==="Exclusion")return"exclusion";if(t==="Hue")return"hue";if(t==="Saturation")return"saturation";if(t==="Color")return"color";if(t==="Luminosity")return"luminosity";c()})()),ke={foldr:e=>t=>{const n=Yt.foldr(e)(t);return r=>n((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,zt("Cons",o._3,i(o._6,u)));c()};return i(r,Qt)})())}},Xr=e=>e,pg=e=>e,mg=Xr("Linear"),yg=Xr("EaseInOutQuad"),Jg=Xr("EaseOutExpo"),Ng=Xr("SpringBouncy"),hr=e=>t=>n=>{const r=Wn(1-t*t),i=e*r;return 1-Du(-t*e*n)*(Ho(i*n)+t/r*Vo(i*n))},xg=e=>{const t=lt.compare(0)(e),n=(()=>{if(t==="LT")return e;if(t==="EQ"||t==="GT")return 0;c()})(),r=lt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},fi=e=>t=>(()=>{if(e==="Linear")return pg;if(e==="EaseInQuad")return n=>n*n;if(e==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(e==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(e==="EaseInCubic")return n=>n*n*n;if(e==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(e==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(e==="EaseOutExpo")return n=>n>=1?1:1-Yo(2)(-10*n);if(e==="Spring")return n=>1-(1+6*n)*Du(-6*n);if(e==="SpringBouncy")return hr(6)(.7);c()})()(xg(t)),Vu=y(cr)(0),vg=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},Ou=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Fu=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Xu=e=>t=>{const n=ye(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,f=s.x-u.x;return Wn(f*f+a*a)})()}),e,Gt(1,e.length,e)),r=Vu(V(u=>u.len)(n)),i=vg(0)(r)(t*r),o=u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,N=Ht(J=>T,J=>v=>E("Just",{head:J,tail:v}),h);if(N.tag==="Nothing"){const J=e.length-1|0;if(J>=0&&J<e.length){l=!1,_=e[J];continue}l=!1,_=m;continue}if(N.tag==="Just"){if(p<=N._1.head.len){const J=N._1.head.len<=0?0:p/N._1.head.len;l=!1,_={x:N._1.head.a.x+(N._1.head.b.x-N._1.head.a.x)*J,y:N._1.head.a.y+(N._1.head.b.y-N._1.head.a.y)*J};continue}f=N._1.tail,g=p-N._1.head.len,d=m;continue}c()}return _};return 0<e.length?E("Just",o(n)(i)(e[0])):T},gi=e=>Vu(ye(t=>n=>{const r=n.y-t.y,i=n.x-t.x;return Wn(i*i+r*r)},e,Gt(1,e.length,e))),an=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),[...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._4,n(r._6,i)));c()};return St(bt(Yt.foldr,n(e.nodes,Qt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})(),...Te((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._4,n(r._6,i)));c()};return bt(Yt.foldr,n(e.edges,Qt))})()),...Te((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._4,n(r._6,i)));c()};return bt(Yt.foldr,n(e.chipExtras,Qt))})())]);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>i=>({minX:Ou(r.minX)(i.x),minY:Ou(r.minY)(i.y),maxX:Fu(r.maxX)(i.x),maxY:Fu(r.maxY)(i.y)}))({minX:t._1.head.x,minY:t._1.head.y,maxX:t._1.head.x,maxY:t._1.head.y})(t._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},pr=function(e){return function(t){if(e>=0&&e<t.length)return t.charAt(e);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},zn=function(e){return e.join("")},Uu=function(e){return e.split("")},_i=function(e){return e},Jn=function(e){return e.length},Ku=function(e){return function(t){return t.substr(0,e)}},mr=function(e){return function(t){return t.substring(e)}},Tg=function(e){return function(t){return{before:t.substring(0,e),after:t.substring(e)}}},wg=e=>t=>{const n=Tg(Jn(e))(t);return n.before===e?E("Just",n.after):T},bg=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},kg=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},Nn=e=>BigInt(e),Lg=e=>Number(e),Ur=e=>t=>e+t,Kr=e=>t=>e*t,di=e=>t=>e-t,Zu=0n,Zr=1n,ju=e=>t=>e^t,yr=e=>t=>e&t,li=e=>t=>e<<t,hi=e=>t=>e>>t,Eg=e=>t=>e==t,Cg=e=>t=>e===t?0:e>t?1:-1,Sg={eq:Eg},ts={compare:e=>t=>{const n=Cg(e)(t);return n===1?ze:n===0?Oe:Ae},Eq0:()=>Sg},Pg=bg(Xt)(T),Rg=kg(Xt)(T),Ig=e=>t=>Iu(e._1-t._1)+Iu(e._2-t._2),jr=e=>e,ae=jr("North"),ce=jr("South"),xn=jr("East"),vn=jr("West"),es=e=>e,ns=(e,t)=>({tag:e,_1:t}),rs=(e,t)=>({tag:e,_1:t}),pi=(e,t)=>({tag:e,_1:t}),Dg=pi("First"),Gg=es("Forward"),Mg=es("Backward"),Wg=te(k)(At),Ag=e=>ir(t=>n=>({nodes:Ne(k.compare,me,t.nodes,n.nodes),edges:Ne(k.compare,me,t.edges,n.edges)}))({nodes:$,edges:$})(e.keyframes),zg=e=>t=>({entering:{nodes:Xe(k.compare,t.nodes,e.nodes),edges:Xe(k.compare,t.edges,e.edges)},leaving:{nodes:Xe(k.compare,e.nodes,t.nodes),edges:Xe(k.compare,e.edges,t.edges)},surviving:{nodes:Yr(k.compare,me,e.nodes,t.nodes),edges:Yr(k.compare,me,e.edges,t.edges)}}),os=e=>e,mi=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},Tn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Bn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},$n=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},yi=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Bg=y(e=>t=>Z(k)(t)()(e))($),$g=y(e=>t=>Z(k)(t)()(e))($),Qg=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),is=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},us=te(k)(At),qg=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Hg=os("Hold"),Yg=os("Gap"),Vg=e=>t=>n=>{const r=n.center.y-t.center.y,i=n.center.x-t.center.x,o=Wn(i*i+r*r),u=n.zoom-t.zoom,s=u<0?-u:u;return mi(e.minTransition)(e.maxTransition)(Tn(e.panSpeed<=0?e.minTransition:o/e.panSpeed)(e.zoomSpeed<=0?e.minTransition:s/e.zoomSpeed))},Og=y(e=>t=>{const n=e.length-1|0;return n>=0&&n<e.length&&e[n]===t?e:de(e)(t)})([]),Ji=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>i=>({minX:Bn(r.minX)(i.x),minY:Bn(r.minY)(i.y),maxX:Tn(r.maxX)(i.x),maxY:Tn(r.maxY)(i.y)}))({minX:t._1.head.x,minY:t._1.head.y,maxX:t._1.head.x,maxY:t._1.head.y})(t._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},ss=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return T;if(t.tag==="Just")return E("Just",Ji(e));c()},Fg=e=>t=>n=>Bg(St(bt(ke.foldr,n))(r=>{const i=$n(r)(e);if(i.tag==="Just")return at(o=>!yi(o)(t),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];c()})),Xg=e=>t=>n=>{const r=fi(e.easing)(mi(0)(1)(n.endT<=n.startT?1:(t-n.startT)/(n.endT-n.startT)));return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*r,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*r},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*r}},Ug=e=>t=>n=>r=>{const i=(u,s)=>Bn(Vg(e)(u.toCam)(s.toCam))(u.endT-u.startT),o=y(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:E("Just",s)};if(u.pending.tag==="Just")return!(s.fromCam.zoom===s.toCam.zoom&&s.fromCam.center.x===s.toCam.center.x&&s.fromCam.center.y===s.toCam.center.y)||(()=>{const a=u.pending._1.toCam.center.x-s.toCam.center.x;return(a<0?-a<8:a<8)&&(()=>{const f=u.pending._1.toCam.center.y-s.toCam.center.y;return(f<0?-f<8:f<8)&&(()=>{const g=u.pending._1.toCam.zoom-s.toCam.zoom;return g<0?-g<.08:g<.08})()})()})()||i(u.pending._1,s)<=0?{acc:de(u.acc)(u.pending._1),pending:E("Just",s)}:{acc:de(de(u.acc)({...u.pending._1,endT:s.startT-i(u.pending._1,s)}))({startT:s.startT-i(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam}),pending:E("Just",s)};c()})({acc:[],pending:T})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return de(o.acc)(o.pending._1);c()},Kg=e=>e.kind.tag==="SendToken"?E("Just",x(e.kind._1.edge,{source:e.kind._1.from,target:e.kind._1.to})):T,Zg=e=>e.tag==="DataFlow"?Pt(Kg)(e._1.events):[],jg=e=>t=>$g(Pt(n=>yi(n._2.source)(t)||yi(n._2.target)(t)?E("Just",n._1):T)(Qg(e))),t_=e=>t=>{const n=r=>{const i=df(Xt,T,o=>o.kind==="Hold",r<1?[]:Gt(0,r,t));if(i.tag==="Just")return i._1>=0&&i._1<t.length?E("Just",t[i._1].cam):T;if(i.tag==="Nothing")return T;c()};return Dt(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.cam,toCam:i.cam};if(i.kind==="Gap")return{startT:i.startT,endT:i.endT,fromCam:(()=>{const o=n(r);if(o.tag==="Nothing")return e;if(o.tag==="Just")return o._1;c()})(),toCam:(()=>{const o=n(r),u=(()=>{if(o.tag==="Nothing")return e;if(o.tag==="Just")return o._1;c()})(),s=r+1|0,a=Dn(Xt,T,f=>f.kind==="Hold",s<1?t:Gt(s,t.length,t));if(a.tag==="Just"){const f=(r+1|0)+a._1|0;return f>=0&&f<t.length?t[f].cam:u}if(a.tag==="Nothing")return u;c()})()};c()})(t)},as={padding:24,easing:Jg,minZoom:.9,maxZoom:2.5,panSpeed:700,zoomSpeed:1.5,minTransition:.3,maxTransition:1.4},e_=e=>t=>n=>{const r=t.w+n*2,i=t.h+n*2,o=an(e);return r<=0||i<=0||o.w<=0||o.h<=0?1:Bn(o.w/r)(o.h/i)},Ni=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>i=>({minX:Bn(r.minX)(i.x),minY:Bn(r.minY)(i.y),maxX:Tn(r.maxX)(i.x+i.w),maxY:Tn(r.maxY)(i.y+i.h)}))({minX:t._1.head.x,minY:t._1.head.y,maxX:t._1.head.x+t._1.head.w,maxY:t._1.head.y+t._1.head.h})(t._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},cs=e=>t=>n=>{if(n.tag==="Leaf")return an(e);const r=jg(t)(n),i=[...Pt(o=>{const u=is(o)(e.nodes);return u.tag==="Just"?E("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})(bt(ke.foldr,Ne(k.compare,me,n,Fg(t)(n)(r)))),...Pt(o=>{const u=$n(o)(e.edges);return u.tag==="Just"?E("Just",Ji(u._1)):T})(bt(ke.foldr,r)),...Pt(o=>{const u=$n(o)(e.chipExtras);if(u.tag==="Just")return ss(u._1);if(u.tag==="Nothing")return T;c()})(bt(ke.foldr,r))];return i.length===0?an(e):Ni(i)},n_=e=>t=>n=>r=>{const i=[...Pt(o=>o)([(()=>{const o=$n(n)(e.edges);return o.tag==="Just"?E("Just",Ji(o._1)):T})(),(()=>{const o=$n(n)(e.chipExtras);if(o.tag==="Just")return ss(o._1);if(o.tag==="Nothing")return T;c()})()]),...(()=>{const o=$n(n)(t);if(o.tag==="Just")return Pt(u=>{const s=is(u)(e.nodes);return s.tag==="Just"?E("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):T})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})()];return i.length===0?cs(e)(t)(r):Ni(i)},r_=y(e=>t=>{const n=e.length-1|0,r=n>=0&&n<e.length?E("Just",e[n]):T;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&t.fromCam.zoom===t.toCam.zoom&&t.fromCam.center.x===t.toCam.center.x&&t.fromCam.center.y===t.toCam.center.y&&(()=>{const i=r._1.toCam.center.x-t.toCam.center.x;return(i<0?-i<8:i<8)&&(()=>{const o=r._1.toCam.center.y-t.toCam.center.y;return(o<0?-o<8:o<8)&&(()=>{const u=r._1.toCam.zoom-t.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?de((()=>{const i=e.length-1|0;return i<1?[]:Gt(0,i,e)})())({...r._1,endT:t.endT}):de(e)(t)})([]),fs=e=>t=>{const n=an(e),r=n.w/Tn(1e-4)(t.zoom),i=n.h/Tn(1e-4)(t.zoom);return{x:t.center.x-r/2,y:t.center.y-i/2,w:r,h:i}},o_=e=>Ne(k.compare,me,us(V(t=>x(t.id,{source:t.from.node,target:t.to.node}))(e.graph.edges)),us(St(e.scenes)(Zg))),xi=e=>t=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:mi(e.minZoom)(e.maxZoom)(e_(t)(n)(e.padding))}),i_=e=>t=>n=>r=>{const i=xi(e)(t)(an(t)),o=at(u=>u>=0&&u<=n,Og(vt(lt.compare)([0,n,...St(r)(u=>[u.startT,u.endT])])));return Ug(e)(t)(i)(r_(t_(i)(Pt(u=>{const s=(u._1+u._2)/2;if(u._2<=u._1)return T;const a=y(qg)(0)(V(g=>g.priority)(at(g=>g.startT<=s&&s<g.endT,r))),f=V(g=>g.bbox)(at(g=>g.priority===a,at(g=>g.startT<=s&&s<g.endT,r)));return f.length===0?E("Just",{kind:Yg,startT:u._1,endT:u._2,cam:i}):E("Just",{kind:Hg,startT:u._1,endT:u._2,cam:xi(e)(t)(Ni(f))})})(ye(In,o,Gt(1,o.length,o))))))},u_=e=>t=>n=>r=>{const i=ge(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return Xg(e)(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=xi(e)(t)(an(t));return 0<n.length?n[0].fromCam:u}c()};function Jr(e){return e.charCodeAt(0)}function gs(e){return String.fromCharCode(e)}const cn=function(e){return function(t){return function(n){return n.replace(new RegExp(e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),t)}}},vi=function(e){return function(t){return t.split(e)}},s_=function(e){return e.trim()},Ti=function(e){return function(t){return t.join(e)}};var a_=typeof Array.from=="function",c_=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",f_=typeof String.prototype.fromCodePoint=="function",g_=typeof String.prototype.codePointAt=="function";const __=function(e){return g_?function(t){return t.codePointAt(0)}:e},d_=function(e){return f_?String.fromCodePoint:e},l_=function(e){return function(t){return c_?function(n){for(var r="",i=n[Symbol.iterator](),o=0;o<t;++o){var u=i.next();if(u.done)return r;r+=u.value}return r}:e(t)}},h_=function(e){return function(t){return a_?function(n){return Array.from(n,t)}:e}},to=e=>{const t=Jn(e);if(t===0)return T;if(t===1)return E("Just",{head:Jr(pr(0)(e)),tail:""});const n=Jr(pr(1)(e)),r=Jr(pr(0)(e));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?E("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:mr(2)(e)}):E("Just",{head:r,tail:mr(1)(e)})},p_=e=>{const t=to(e);return t.tag==="Just"?E("Just",x(t._1.head,t._1.tail)):T},m_=e=>Ie.unfoldr(p_)(e),_s=__(e=>{const t=Jr(pr(0)(e));if(55296<=t&&t<=56319&&Jn(e)>1){const n=Jr(pr(1)(e));if(56320<=n&&n<=57343)return(((t-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return t}),wi=h_(m_)(_s),bi=e=>_i(e>=0&&e<=65535?gs(e):e<0?"\0":"\uFFFF"),y_=d_(e=>e<=65535?bi(e):bi(Rn(e-65536|0,1024)+55296|0)+bi(Oo(e-65536|0)(1024)+56320|0)),ds=e=>t=>{if(e<1)return"";const n=to(t);return n.tag==="Just"?y_(n._1.head)+ds(e-1|0)(n._1.tail):t},ie=l_(ds),J_=e=>t=>t===""?T:E("Just",_s(t)),eo=(e,t,n)=>({tag:e,_1:t,_2:n}),N_=()=>({tag:"ExtendFromSource"}),no=(e,t)=>({tag:e,_1:t}),ki=e=>e,ro=(e,t)=>({tag:e,_1:t}),Li=ro("NotYet"),ls=ro("Consumed"),x_=ki("FromSource"),hs=ki("FromTarget"),v_=ki("FromBoth"),ps=no("Hidden"),T_=no("Visible"),ms=N_(),ys=eo("Retracted"),w_=eo("Extended"),Ei=(e,t)=>({tag:e,_1:t}),Qn=(e,t,n)=>({tag:e,_1:t,_2:n}),Js=e=>e,wn=(e,t)=>({tag:e,_1:t}),qn=(e,t,n,r,i,o,u,s,a)=>({tag:e,_1:t,_2:n,_3:r,_4:i,_5:o,_6:u,_7:s,_8:a}),Ns=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},oo=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},fn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Nr=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},xs=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},vs=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Hn=(()=>{const e=Ie.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return E("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._3,n(r._6,i)));c()};return n(t,Qt)})())})(),b_=y(e=>t=>Z(k)(t)()(e))($),Ci=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},k_=te(k)(At),L_=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Si=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},E_=wn("NoKeyframes"),C_=e=>wn("DuplicateEventId",e),S_=e=>wn("UnknownEvent",e),Ts=Js("PlopIn"),P_=Js("PlopOut"),R_=e=>t=>Pt(n=>{if(n.target.tag==="NodeWindow"||n.target.tag==="EdgeWindow")return T;if(n.target.tag==="TokenWindow")return E("Just",{startT:n.startT,endT:n.endT,bbox:n_(e)(t)(n.target._2)($),priority:1});if(n.target.tag==="FillWindow")return E("Just",{startT:n.startT,endT:n.endT,bbox:cs(e)(t)(Ft("Node",1,1,n.target._2,void 0,$,$)),priority:1});c()}),I_=e=>t=>n=>r=>i=>{const o=ct(y(f=>g=>f+wi(g).length|0)(0)(n.labels))*e.tokenReadSecPerChar,u=f=>{const g=Ns(f)(t.nodes);if(g.tag==="Just")return{x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2};if(g.tag==="Nothing")return{x:0,y:0};c()},s=oo(n.edge)(t.edges),a=(()=>{if(s.tag==="Just"){const f=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return le(s._1);c()})(),g=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return le(s._1);c()})(),d=u(n.from),l=g.length-1|0;return(2*(()=>{const _=0<f.length?f[0]:u(n.from),h=_.x-d.x,p=_.y-d.y;return(h<0?-h:h)+(p<0?-p:p)})()+gi(s._1)+2*(()=>{const _=l>=0&&l<g.length?g[l]:u(n.to),h=u(n.to),p=h.x-_.x,m=h.y-_.y;return(p<0?-p:p)+(m<0?-m:m)})())/e.tokenSpeed}if(s.tag==="Nothing")return 0/e.tokenSpeed;c()})();return e.tokenSpeed<=0?e.minTokenDuration:fn(e.minTokenDuration)(fn(a)(o)/fn(.05)(1-r-i))},D_=e=>{if(e.event.kind.tag==="SendToken")return E("Just",{startT:e.startT,endT:e.endT,target:qn("TokenWindow",e.event.id,e.event.kind._1.edge,e.event.kind._1.direction,e.event.kind._1.from,e.event.kind._1.to,e.event.kind._1.labels,e.holdPre,e.holdPost)});if(e.event.kind.tag==="FillNodeWithoutTransition")return E("Just",{startT:e.startT,endT:e.endT,target:qn("FillWindow",e.event.id,e.event.kind._1.node,e.event.kind._1.labels)});c()},G_=e=>t=>n=>Pt(r=>{const i=Pt(o=>Ns(o)(e.nodes))(bt(ke.foldr,(()=>{if(r.scene.tag==="Structural")return Ne(k.compare,me,(()=>{const o=Nr(r.scene._1.from)(n);if(o.tag==="Nothing")return $;if(o.tag==="Just")return o._1.nodes;c()})(),(()=>{const o=Nr(r.scene._1.to)(n);if(o.tag==="Nothing")return $;if(o.tag==="Just")return o._1.nodes;c()})());if(r.scene.tag==="DataFlow"){const o=Nr(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return $;if(o.tag==="Just")return o._1.nodes}c()})()));return i.length===0?T:E("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=y(u=>s=>({minX:xs(u.minX)(s.x),minY:xs(u.minY)(s.y),maxX:fn(u.maxX)(s.x+s.w),maxY:fn(u.maxY)(s.y+s.h)}))(0<i.length?{minX:i[0].x,minY:i[0].y,maxX:i[0].x+i[0].w,maxY:i[0].y+i[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(Gt(1,i.length,i));return{x:o.minX,y:o.minY,w:o.maxX-o.minX,h:o.maxY-o.minY}})(),priority:0})}),M_=e=>t=>n=>{const r=oo(n)(e);if(r.tag==="Nothing")return hs;if(r.tag==="Just"){const i=vs(r._1.target)(t);return vs(r._1.source)(t)?i?v_:x_:hs}c()},W_=e=>t=>n=>r=>{const i=(()=>{if(r.event.when.tag==="First")return 0;if(r.event.when.tag==="At")return r.event.when._1;if(r.event.when.tag==="After"){const o=r.event.when._1,u=ge(s=>s.event.id===o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.endT;c()}if(r.event.when.tag==="With"){const o=r.event.when._1,u=ge(s=>s.event.id===o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.startT}c()})();return de(n)({startT:i,endT:(()=>{if(r.event.kind.tag==="SendToken")return i+I_(e)(t)(r.event.kind._1)(r.holdPre)(r.holdPost);if(r.event.kind.tag==="FillNodeWithoutTransition")return i+e.plop;c()})(),event:r.event,holdPre:r.holdPre,holdPost:r.holdPost})},Pi=e=>t=>{if(t<0)return Qn("AtKeyframe",e.initialKeyframe);if(t>=e.totalDuration){const r=e.spans.length-1|0;return r>=0&&r<e.spans.length?Qn("AtKeyframe",(()=>{if(e.spans[r].scene.tag==="Structural")return e.spans[r].scene._1.to;if(e.spans[r].scene.tag==="DataFlow")return e.spans[r].scene._1.keyframe;c()})()):Qn("AtKeyframe",e.initialKeyframe)}const n=ge(r=>t>=r.startT&&t<r.endT)(e.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Qn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Qn("AtKeyframe",n._1.scene._1.keyframe);c()}if(n.tag==="Nothing")return Qn("AtKeyframe",e.initialKeyframe);c()},A_=e=>{if(e.when.tag==="First")return[];if(e.when.tag==="At")return[];if(e.when.tag==="After")return[e.when._1];if(e.when.tag==="With")return[e.when._1];c()},ws={id:"",nodes:$,edges:$},z_=e=>t=>zg((()=>{const n=Nr(t.from)(e);if(n.tag==="Nothing")return ws;if(n.tag==="Just")return n._1;c()})())((()=>{const n=Nr(t.to)(e);if(n.tag==="Nothing")return ws;if(n.tag==="Just")return n._1;c()})()),Ri=e=>t=>n=>r=>{const i=oo(r)(n.edges);if(i.tag==="Just")return e<=0?t:fn(t)(gi(i._1)/e);if(i.tag==="Nothing")return t;c()},bs=e=>t=>n=>r=>i=>{const o=e.plop,u=z_(n)(i),s=V(_=>({startT:0,endT:0+Ri(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:qn("EdgeWindow",_,Ei("Extend",ms))}))(Hn(u.entering.edges)),a=V(_=>({startT:0,endT:o,target:qn("NodeWindow",_,Ts)}))(Hn(u.entering.nodes)),f=y(fn)(0)(V(_=>Ri(e.edgeSpeed)(e.minEdgeDuration)(t)(_))(Hn(u.leaving.edges))),g=_=>sn(h=>{const p=oo(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;c()},Hn(u.leaving.edges))?f:0,d=V(_=>({startT:g(_),endT:g(_)+e.plop,target:qn("NodeWindow",_,P_)}))(Hn(u.leaving.nodes)),l=V(_=>({startT:0,endT:Ri(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:qn("EdgeWindow",_,Ei("Retract",M_(r)(u.leaving.nodes)(_)))}))(Hn(u.leaving.edges));return{duration:(()=>{const _=vt(lt.compare)([...V(p=>p.endT)(l),...V(p=>p.endT)(d),...V(p=>p.endT)(a),...V(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+e.gap:e.gap})(),windows:[...l,...d,...a,...s]}},B_=e=>t=>n=>r=>i=>o=>V((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(bs(e)(t)(n)(r)(o).windows),$_=e=>Pt(t=>bt(ir,t).length>1?E("Just",(()=>{const n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),bt(ir,t));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";c()})()):T)(Jf($o)(vt(k.compare)(e))),Q_=e=>{const t=V(r=>r.id)(e),n=b_(t);return[...V(C_)($_(t)),...V(S_)(at(r=>!Ci(r)(n),St(e)(A_)))]},q_=e=>{const t=k_(V(r=>x(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];c()})()))(e)),n=r=>i=>o=>{if(Ci(o)(i))return[wn("ScheduleCycle",[...bt(ke.foldr,i),o])];if(Ci(o)(r))return[];const u=L_(o)(t);if(u.tag==="Nothing")return[];if(u.tag==="Just")return St(u._1)(n(Z(k)(o)()(r))(Z(k)(o)()(i)));c()};return St(e)(r=>n($)($)(r.id))},H_={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:100,minTokenDuration:1.4,tokenReadSecPerChar:.06,nodeEasing:Ng,edgeEasing:yg,tokenEasing:mg},Y_=e=>t=>{if(t.tag==="Structural")return Pt(n=>n)([Si(t._1.from)(e)?T:E("Just",wn("UnknownKeyframe",t._1.from)),Si(t._1.to)(e)?T:E("Just",wn("UnknownKeyframe",t._1.to))]);if(t.tag==="DataFlow")return[...Pt(n=>n)([Si(t._1.keyframe)(e)?T:E("Just",wn("UnknownKeyframe",t._1.keyframe))]),...Q_(t._1.events),...q_(t._1.events)];c()},V_=e=>t=>{const n=St(t)(Y_(e));return n.length===0?kt("Right",void 0):kt("Left",n)},ks=e=>t=>n=>y(W_(e)(t))([])(Dt(r=>i=>({event:i,holdPre:i.kind.tag==="SendToken"?(()=>{const o=r-1|0;return o>=0&&o<n.length&&n[o].kind.tag==="SendToken"&&n[o].kind._1.to===i.kind._1.from})()?0:.18:0,holdPost:i.kind.tag==="SendToken"?(()=>{const o=r+1|0;return o>=0&&o<n.length&&n[o].kind.tag==="SendToken"&&n[o].kind._1.from===i.kind._1.to})()?0:.18:0}))(n)),O_=e=>t=>n=>{const r=ks(e)(t)(n.events);return r.length===0?e.gap:y(fn)(0)(V(i=>i.endT)(r))+e.gap},F_=e=>t=>n=>r=>i=>{if(i.tag==="Structural")return bs(e)(t)(n)(r)(i._1).duration;if(i.tag==="DataFlow")return O_(e)(t)(i._1);c()},X_=e=>t=>n=>r=>i=>y(o=>u=>{const s=F_(e)(t)(n)(r)(u);return{acc:de(o.acc)({startT:o.t,endT:o.t+s,scene:u}),t:o.t+s}})({acc:[],t:0})(i).acc,U_=e=>t=>n=>r=>V((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(Pt(D_)(ks(e)(t)(r.events))),K_=e=>t=>n=>r=>i=>{if(i.scene.tag==="Structural")return B_(e)(t)(n)(r)(i)(i.scene._1);if(i.scene.tag==="DataFlow")return U_(e)(t)(i)(i.scene._1);c()},Z_=e=>t=>n=>{const r=0<t.keyframes.length?E("Just",t.keyframes[0]):T;if(r.tag==="Nothing")return kt("Left",[E_]);if(r.tag==="Just"){const i=r._1,o=Wg(V(a=>x(a.id,a))(t.keyframes)),u=o_(t),s=V_(o)(t.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return f=>kt("Left",a)}if(s.tag==="Right"){const a=s._1;return f=>f(a)}c()})()(()=>{const a=X_(e)(n)(o)(u)(t.scenes),f=a.length-1|0,g=f>=0&&f<a.length?a[f].endT:0,d=vt(l=>_=>lt.compare(l.startT)(_.startT))(St(a)(K_(e)(n)(o)(u)));return kt("Right",{totalDuration:g,windows:d,spans:a,keyframes:o,initialKeyframe:i.id,timing:e,layout:n,cameraSpans:i_(as)(n)(g)([...G_(n)(u)(o)(a),...R_(n)(u)(d)]),cameraConfig:as})})}c()},xr=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Ls=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},io=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},j_=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},t1=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},e1=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},n1=te(k)(At),r1=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},o1=te(k)(At),i1=te(k)(At),u1=e=>t=>n=>r=>{const i=an(e),o=i.w/xr(1e-4)(t.zoom)/2,u=i.h/xr(1e-4)(t.zoom)/2,s=n.y-t.center.y,a=n.x-t.center.x;return{...t,center:{x:o<=1e-4?t.center.x+0*r*.35:a<0?t.center.x+a/(1+-a/o)*r*.35:t.center.x+a/(1+a/o)*r*.35,y:u<=1e-4?t.center.y+0*r*.35:s<0?t.center.y+s/(1+-s/u)*r*.35:t.center.y+s/(1+s/u)*r*.35}}},Ii=e=>t=>{const n=Ls(t)(e.keyframes);if(n.tag==="Nothing")return $;if(n.tag==="Just")return n._1.nodes;c()},Di=e=>t=>{const n=Ls(t)(e.keyframes);if(n.tag==="Nothing")return $;if(n.tag==="Just")return n._1.edges;c()},s1=e=>t=>n=>sn(r=>r.endT<=t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,e),a1=e=>t=>n=>sn(r=>r.endT<=t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,e),c1=e=>t=>n=>sn(r=>r.startT>t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,e),f1=e=>t=>n=>sn(r=>r.startT>t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,e),g1=e=>t=>{const n=Pi(e)(t);if(n.tag==="AtKeyframe")return ie(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return ie(3)(n._2)==="kf-"?"":n._2;c()},Es=e=>t=>n=>ge(r=>n(r)&&t>=r.startT&&t<r.endT)(e),_1=e=>{const t=io(0)(1)(e/.2),n=io(0)(1)((1-e)/.2);return t*t*(3-2*t)*n*n*(3-2*n)},d1=e=>t=>{if(t.tag==="Travelling"){const n=j_(t._1.edge)(e.edges);if(n.tag==="Just"){const r=Xu(n._1)(t._1.progress);return r.tag==="Just"?E("Just",{dot:r._1,weight:_1(t._1.progress)}):T}if(n.tag==="Nothing")return T;c()}return T},l1=e=>t=>{const n=Pi(e)(t);if(n.tag==="AtKeyframe")return Ii(e)(n._1);if(n.tag==="InTransition")return Ne(k.compare,me,Ii(e)(n._1),Ii(e)(n._2));c()},h1=e=>t=>{const n=Pi(e)(t);if(n.tag==="AtKeyframe")return Di(e)(n._1);if(n.tag==="InTransition")return Ne(k.compare,me,Di(e)(n._1),Di(e)(n._2));c()},p1=e=>t=>{const n=an(e),r=n.h/xr(1e-4)(t.zoom),i=n.w/xr(1e-4)(t.zoom);return{...t,center:{x:i>=n.w?n.x+n.w/2:io(n.x+i/2)(n.x+n.w-i/2)(t.center.x),y:r>=n.h?n.y+n.h/2:io(n.y+r/2)(n.y+n.h-r/2)(t.center.y)}}},uo=e=>t=>{const n=e.endT-e.startT;return n<=0?1:xr(0)(t1(1)((t-e.startT)/n))},m1=e=>t=>n=>r=>{const i=Es(e.windows)(t)(o=>o.target.tag==="EdgeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=fi(e.timing.edgeEasing)(uo(i._1)(t)),u=i._1.target.tag==="EdgeWindow"?i._1.target._2:Ei("Extend",ms);if(u.tag==="Retract")return eo("Retracting",u._1,o);if(u.tag==="Extend")return eo("Extending",u._1,o);c()}if(i.tag==="Nothing")return f1(e.windows)(t)(r)||s1(e.windows)(t)(r)?ys:e1(r)(n)?w_:ys;c()},y1=e=>t=>{const n=h1(e)(t);return n1(V(r=>x(r,m1(e)(t)(n)(r)))((()=>{const r=i=>{if(i.tag==="Leaf")return $;if(i.tag==="Node")return Ft("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));c()};return bt(ke.foldr,r(e.layout.edges))})()))},J1=e=>t=>n=>r=>{const i=Es(e.windows)(t)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=uo(i._1)(t),u=i._1.target.tag==="NodeWindow"?i._1.target._2:Ts;if(u==="PlopIn")return no("PloppingIn",o);if(u==="PlopOut")return no("PloppingOut",o);c()}if(i.tag==="Nothing")return c1(e.windows)(t)(r)||a1(e.windows)(t)(r)?ps:r1(r)(n)?T_:ps;c()},N1=e=>t=>{const n=l1(e)(t);return o1(V(r=>x(r,J1(e)(t)(n)(r)))((()=>{const r=i=>{if(i.tag==="Leaf")return $;if(i.tag==="Node")return Ft("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));c()};return bt(ke.foldr,r(e.layout.nodes))})()))},x1=e=>t=>n=>t.target.tag==="TokenWindow"?x(t.target._1,n<t.startT?Li:n>=t.endT?ls:ro("Travelling",{edge:t.target._2,direction:t.target._3,progress:fi(e.timing.tokenEasing)(uo(t)(n)),labels:t.target._6,source:t.target._4,target:t.target._5,holdPre:t.target._7,holdPost:t.target._8})):t.target.tag==="FillWindow"?x(t.target._1,n<t.startT?Li:n>=t.endT?ls:ro("Filling",{node:t.target._2,progress:uo(t)(n),labels:t.target._3})):x("",Li),v1=e=>t=>i1(V(n=>x1(e)(n)(t))(at(n=>n.target.tag==="TokenWindow"||n.target.tag==="FillWindow",e.windows))),T1=e=>t=>{const n=Pt(d1(e))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,zt("Cons",i._4,r(i._6,o)));c()};return bt(Yt.foldr,r(t.tokens,Qt))})());return 0<n.length?E("Just",n[0]):T},w1=e=>t=>{const n=T1(e)(t);if(n.tag==="Nothing")return t.camera;if(n.tag==="Just")return u1(e)(t.camera)(n._1.dot)(n._1.weight);c()},b1=e=>t=>{const n={nodes:N1(e)(t),edges:y1(e)(t),tokens:v1(e)(t),camera:u_(e.cameraConfig)(e.layout)(e.cameraSpans)(t),frameTitle:g1(e)(t)};return{...n,camera:p1(e.layout)(w1(e.layout)(n))}};let Gi=null;function k1(){return Gi||(typeof document>"u"?null:(Gi=document.createElement("canvas").getContext("2d"),Gi))}const Cs=new Map,L1=e=>t=>n=>r=>()=>{const i=`${n} ${t}px ${e}|${r}`,o=Cs.get(i);if(o!==void 0)return o;const u=k1();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return Cs.set(i,s),s},so=(()=>{const e=cn(`\r
|
|
3
|
-
`)(" "),
|
|
4
|
-
`)(" "),n=(()=>{const r=
|
|
5
|
-
`)(o._1))(Mi(i)),s=y(a=>f=>vr(a)(Jn(f)))(0)(u);return{...o._2,size:x(ct(s>i?Rn((s+2|0)+e.cellW|0,e.cellW):r),ct(vr(1)(Rn(u.length+e.cellH|0,e.cellH))))}})(n)}},D1=e=>t=>n=>({...n,nodes:V(r=>{const i=S1(r.id)(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:x(C1(r.size._1)(ct(vr(1)(ur(xf((i._1+32)/e))))),r.size._2)};c()})(n.nodes)}),G1=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},M1=e=>{const t=e.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(a>=t){u=!1,s=f;continue}const g=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const N=_,J=h;if(N>=t){p=!1,m=J;continue}if(a>=0&&a<e.length){if(N>=0&&N<e.length){_=N+1|0,h=(()=>{const v=e[a].position,w=e[a].size,L=e[N].position,b=e[N].size;return v._1<L._1+b._1&&L._1<v._1+w._1&&v._2<L._2+b._2&&L._2<v._2+w._2})()?J+1|0:J;continue}_=N+1|0,h=J;continue}p=!1,m=J}return m};i=a+1|0,o=g(a+1|0)(f)}return s})(0)(0)},Ps=e=>y(t=>n=>t+Ig(n.start)(n.end))(0)(e.segments),W1=e=>t=>n=>({crossingCount:y(r=>i=>r+i.jumps.length|0)(0)(t),bendCount:y(r=>i=>r+i.bends.length|0)(0)(t),totalEdgeLength:y(r=>i=>r+Ps(i))(0)(t),maxEdgeLength:y(r=>i=>G1(r)(Ps(i)))(0)(t),nodeOverlapCount:M1(e),constraintViolations:n,jumpCount:y(r=>i=>r+i.jumps.length|0)(0)(t)}),Rs=e=>e,Yn=te(ot)(At),xt=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=ot.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Is=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},it=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},ut=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Ue=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},A1=e=>t=>{const n=ot.compare(e._1)(t._1);return n==="LT"?Ae:n==="GT"?ze:ot.compare(e._2)(t._2)},Vn=e=>t=>{const n=ot.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},z1=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),B1=e=>e,ao=Rs("Regular"),co=Rs("Critical"),Ds=e=>t=>{const n=y(u=>s=>Z(k)(s.node)(s)(u))($)(t),r=1.25*ct(4),i=(u,s,a)=>(f=>g=>d=>{let l=f,_=g,h=d,p=!0,m;for(;p;){const N=l,J=_,v=h;if(v.critical){p=!1,m=v;continue}const w=Ht(b=>T,b=>S=>E("Just",{head:b,tail:S}),N),L=Ht(b=>T,b=>S=>E("Just",{head:b,tail:S}),J);if(w.tag==="Just"&&L.tag==="Just"){const b=w._1.head>L._1.head-u&&w._1.head<L._1.head+u?{...v,critical:!0}:w._1.head>L._1.head-r&&w._1.head<L._1.head+r?{...v,conflicts:v.conflicts+1|0}:v;if(b.critical){p=!1,m=b;continue}if(w._1.head<=L._1.head){l=w._1.tail,_=J,h=b;continue}l=N,_=L._1.tail,h=b;continue}p=!1,m=v}return m})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(ut(y(ut)(-1e18)(s.incoming))(y(ut)(-1e18)(s.outgoing))-it(y(it)(1e18)(s.incoming))(y(it)(1e18)(s.outgoing))<.001||ut(y(ut)(-1e18)(a.incoming))(y(ut)(-1e18)(a.outgoing))-it(y(it)(1e18)(a.incoming))(y(it)(1e18)(a.outgoing))<.001)return[];const f=i(u,s.outgoing,a.incoming),g=i(u,a.outgoing,s.incoming);if(f.critical||g.critical)return[...f.critical?[{src:a.id,tgt:s.id,weight:1,kind:co}]:[],...g.critical?[{src:s.id,tgt:a.id,weight:1,kind:co}]:[]];const d=it(y(it)(1e18)(s.incoming))(y(it)(1e18)(s.outgoing)),l=ut(y(ut)(-1e18)(s.incoming))(y(ut)(-1e18)(s.outgoing)),_=it(y(it)(1e18)(a.incoming))(y(it)(1e18)(a.outgoing)),h=ut(y(ut)(-1e18)(a.incoming))(y(ut)(-1e18)(a.outgoing)),p=(1*f.conflicts|0)+(16*(y(N=>J=>J>h?N:J>=_?N+1|0:N)(0)(s.outgoing)+y(N=>J=>J>l?N:J>=d?N+1|0:N)(0)(a.incoming)|0)|0)|0,m=(1*g.conflicts|0)+(16*(y(N=>J=>J>l?N:J>=d?N+1|0:N)(0)(a.outgoing)+y(N=>J=>J>h?N:J>=_?N+1|0:N)(0)(s.incoming)|0)|0)|0;return p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:ao}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:ao}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:ao},{src:a.id,tgt:s.id,weight:0,kind:ao}]:[]};return y(u=>s=>y(a=>f=>Z(k)(f._1)(f._2)(a))(u)((()=>{const a=y(R=>P=>{const et=P.edge.from.node+"|"+(()=>{if(P.edge.from.port.tag==="Just")return P.edge.from.port._1;if(P.edge.from.port.tag==="Nothing")return"_auto_"+P.edge.id;c()})(),K=Ue(et)(R.entries);if(K.tag==="Nothing")return{...R,entries:Z(k)(et)({id:0,members:[P.edge.id],incoming:[P.fromPos._1],outgoing:[P.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(R.entries),order:[...R.order,et]};if(K.tag==="Just")return{...R,entries:Z(k)(et)({...K._1,members:[...K._1.members,P.edge.id],incoming:[...pn(B=>B<P.fromPos._1)(K._1.incoming).init,P.fromPos._1,...pn(B=>B<=P.fromPos._1)(K._1.incoming).rest],outgoing:[...pn(B=>B<P.toPos._1)(K._1.outgoing).init,P.toPos._1,...pn(B=>B<=P.toPos._1)(K._1.outgoing).rest]})(R.entries)};c()})({entries:$,order:[]})(s._2),f=Dt(R=>P=>({...P,id:R}))(Pt(R=>Ue(R)(a.entries))(a.order));if(f.length===0)return[];const g=y(R=>P=>R.prev.tag==="Just"&&P-R.prev._1<1e-9?R:{prev:E("Just",P),out:[...R.out,P]})({prev:T,out:[]})(vt(lt.compare)([...St(f)(R=>R.incoming),...St(f)(R=>R.outgoing)])).out,d=g.length<2?.2*r:.2*y(R=>P=>{if(R.prev.tag==="Nothing")return{prev:E("Just",P),mn:R.mn};if(R.prev.tag==="Just")return{prev:E("Just",P),mn:it(R.mn)(P-R.prev._1)};c()})({prev:T,mn:1e18})(g).mn,l={segments:f,deps:(()=>{const R=f.length;return St(St(qt(0,R-2|0))(P=>St(qt(P+1|0,R-1|0))(et=>[x(P,et)])))(P=>P._1>=0&&P._1<f.length?P._2>=0&&P._2<f.length?o(d,f[P._1],f[P._2]):[]:[])})()},_=at(R=>{if(R.kind==="Critical")return!0;if(R.kind==="Regular")return!1;c()},l.deps),h=(()=>{if(_.length<2)return l;const R=Yn((()=>{const q=l.segments;return V(M=>x(M.id,M.mark))((()=>{const M=q.length,C=D=>{let G=D,Y=!0,X;for(;Y;){const H=G,Q=ge(W=>{const U=xt(W)(H.inWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;c()})(H.remaining);if(Q.tag==="Nothing"){Y=!1,X=H;continue}if(Q.tag==="Just"){const W=Q._1;G={...H,inWeight:y(U=>F=>Tt(ot)(Zt)(F.tgt)(-F.weight)(U))(H.inWeight)((()=>{const U=xt(W)(H.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),marks:Z(ot)(W)(H.nextSource)(H.marks),nextSource:H.nextSource+1|0,outWeight:y(U=>F=>Tt(ot)(Zt)(F.src)(-F.weight)(U))(H.outWeight)((()=>{const U=xt(W)(H.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),remaining:at(U=>U!==W,H.remaining)};continue}c()}return X},I=D=>{let G=D,Y=!0,X;for(;Y;){const H=G,Q=ge(W=>{const U=xt(W)(H.outWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;c()})(H.remaining);if(Q.tag==="Nothing"){Y=!1,X=H;continue}if(Q.tag==="Just"){const W=Q._1;G={...H,inWeight:y(U=>F=>Tt(ot)(Zt)(F.tgt)(-F.weight)(U))(H.inWeight)((()=>{const U=xt(W)(H.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),marks:Z(ot)(W)(H.nextSink)(H.marks),nextSink:H.nextSink-1|0,outWeight:y(U=>F=>Tt(ot)(Zt)(F.src)(-F.weight)(U))(H.outWeight)((()=>{const U=xt(W)(H.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;c()})()),remaining:at(U=>U!==W,H.remaining)};continue}c()}return X};return(D=>{let G=D,Y=!0,X;for(;Y;){const H=C(I(G));if(H.remaining.length===0){Y=!1,X=V(Q=>{const W=xt(Q.id)(H.marks),U=(()=>{if(W.tag==="Nothing")return Q.id;if(W.tag==="Just")return W._1;c()})();return{...Q,mark:U<M?(U+M|0)+1|0:U}})(q);continue}G=(()=>{const Q=U=>{const F=xt(U)(H.outWeight),_t=xt(U)(H.inWeight);return(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;c()})()-(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;c()})()|0},W=vt(U=>F=>ot.compare(Q(F))(Q(U)))(H.remaining);if(0<W.length){const U=W[0];return{...H,inWeight:y(F=>_t=>Tt(ot)(Zt)(_t.tgt)(-_t.weight)(F))(H.inWeight)((()=>{const F=xt(U)(H.depsBySrc);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;c()})()),marks:Z(ot)(U)(H.nextSource)(H.marks),nextSource:H.nextSource+1|0,outWeight:y(F=>_t=>Tt(ot)(Zt)(_t.src)(-_t.weight)(F))(H.outWeight)((()=>{const F=xt(U)(H.depsByTgt);if(F.tag==="Nothing")return[];if(F.tag==="Just")return F._1;c()})()),remaining:at(F=>F!==U,H.remaining)}}return H})()}return X})({remaining:V(D=>D.id)(q),marks:$,inWeight:y(D=>G=>Tt(ot)(Zt)(G.tgt)(G.weight)(D))($)(_),outWeight:y(D=>G=>Tt(ot)(Zt)(G.src)(G.weight)(D))($)(_),depsBySrc:y(D=>G=>Tt(ot)(se)(G.src)([G])(D))($)(_),depsByTgt:y(D=>G=>Tt(ot)(se)(G.tgt)([G])(D))($)(_),nextSink:M-1|0,nextSource:M+1|0})})())})()),P=at(q=>{const M=xt(q.src)(R),C=xt(q.tgt)(R);return(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})()>(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;c()})()},_);if(P.length===0)return l;const et=y(q=>M=>{if(Be(Qo)(M.src)(q.decisions)||Be(Qo)(M.tgt)(q.decisions))return q;const C=xt(M.src)(q.segMap),I=xt(M.tgt)(q.segMap);if(C.tag==="Just"&&I.tag==="Just"){const D=(C._1.incoming.length+C._1.outgoing.length|0)>2&&(I._1.incoming.length+I._1.outgoing.length|0)<=2,G=D?I._1:C._1;return{decisions:[...q.decisions,G.id],segMap:Z(ot)(G.id)({...G,splitBy:E("Just",D?C._1.id:I._1.id)})(q.segMap)}}return q})({decisions:[],segMap:Yn(V(q=>x(q.id,q))(l.segments))})(P),K=et.segMap,B=y(q=>M=>{const C=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(M.outgoing)),I=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(M.outgoing)),D=at(Q=>Q.a.startPosition<=I&&Q.a.endPosition>=C,Dt(Q=>W=>({i:Q,a:W}))(q.freeAreas));if(D.length===0){const Q={...M,incoming:vt(lt.compare)(M.incoming),outgoing:vt(lt.compare)([(C+I)/2]),splitPartner:E("Just",q.nextId)},W={id:q.nextId,incoming:vt(lt.compare)([(C+I)/2]),mark:0,members:M.members,outgoing:vt(lt.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:E("Just",M.id)};return{segMap:Z(ot)(W.id)(W)(Z(ot)(Q.id)(Q)(q.segMap)),freeAreas:q.freeAreas,nextId:q.nextId+1|0}}const G=0<D.length?E("Just",D[0]):T,Y=(()=>{if(G.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(G.tag==="Just"){if(D.length===1)return G._1;const Q=V(W=>({c:W,rating:(()=>{const U=(W.a.startPosition+W.a.endPosition)/2,F=[U],_t=[U],pt=y((()=>{const ht=q.segMap;return wt=>It=>{const dt=xt(It.tgt)(ht);if(dt.tag==="Nothing")return wt;if(dt.tag==="Just"){const Mt=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),mt=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),gt=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F)),rt=(()=>{const Et=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),Rt=y(Wt=>oe=>oe>mt?Wt:oe>=Mt?Wt+1|0:Wt)(0)(F)+y(Wt=>oe=>oe>Et?Wt:oe>=gt?Wt+1|0:Wt)(0)(dt._1.incoming)|0,nr=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F)),Sn=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),Pn=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),rr=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),We=y(Wt=>oe=>oe>Sn?Wt:oe>=nr?Wt+1|0:Wt)(0)(dt._1.outgoing)+y(Wt=>oe=>oe>rr?Wt:oe>=Pn?Wt+1|0:Wt)(0)(M.incoming)|0;return Rt===We?Rt>0?{...wt,deps:wt.deps+2|0,crossings:wt.crossings+Rt|0}:wt:{...wt,deps:wt.deps+1|0,crossings:wt.crossings+Vn(Rt)(We)|0}})(),nt=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),st=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),yt=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),Jt=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Ct=y(Et=>Rt=>Rt>st?Et:Rt>=nt?Et+1|0:Et)(0)(M.outgoing)+y(Et=>Rt=>Rt>Jt?Et:Rt>=yt?Et+1|0:Et)(0)(dt._1.incoming)|0,$t=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),re=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Ve=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),er=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),on=y(Et=>Rt=>Rt>re?Et:Rt>=$t?Et+1|0:Et)(0)(dt._1.outgoing)+y(Et=>Rt=>Rt>er?Et:Rt>=Ve?Et+1|0:Et)(0)(_t)|0;return Ct===on?Ct>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Ct|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Vn(Ct)(on)|0}}c()}})())(y((()=>{const ht=q.segMap;return wt=>It=>{const dt=xt(It.src)(ht);if(dt.tag==="Nothing")return wt;if(dt.tag==="Just"){const Mt=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),mt=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),gt=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F)),rt=(()=>{const Et=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),Rt=y(Wt=>oe=>oe>mt?Wt:oe>=Mt?Wt+1|0:Wt)(0)(F)+y(Wt=>oe=>oe>Et?Wt:oe>=gt?Wt+1|0:Wt)(0)(dt._1.incoming)|0,nr=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F)),Sn=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),Pn=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),rr=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),We=y(Wt=>oe=>oe>Sn?Wt:oe>=nr?Wt+1|0:Wt)(0)(dt._1.outgoing)+y(Wt=>oe=>oe>rr?Wt:oe>=Pn?Wt+1|0:Wt)(0)(M.incoming)|0;return Rt===We?Rt>0?{...wt,deps:wt.deps+2|0,crossings:wt.crossings+Rt|0}:wt:{...wt,deps:wt.deps+1|0,crossings:wt.crossings+Vn(Rt)(We)|0}})(),nt=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),st=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),yt=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),Jt=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Ct=y(Et=>Rt=>Rt>st?Et:Rt>=nt?Et+1|0:Et)(0)(M.outgoing)+y(Et=>Rt=>Rt>Jt?Et:Rt>=yt?Et+1|0:Et)(0)(dt._1.incoming)|0,$t=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),re=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Ve=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),er=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),on=y(Et=>Rt=>Rt>re?Et:Rt>=$t?Et+1|0:Et)(0)(dt._1.outgoing)+y(Et=>Rt=>Rt>er?Et:Rt>=Ve?Et+1|0:Et)(0)(_t)|0;return Ct===on?Ct>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Ct|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Vn(Ct)(on)|0}}c()}})())({crossings:0,deps:0})(at(ht=>ht.tgt===M.id,l.deps)))(at(ht=>ht.src===M.id,l.deps)),ft=(()=>{if(M.splitBy.tag==="Just")return xt(M.splitBy._1)(q.segMap);if(M.splitBy.tag==="Nothing")return T;c()})();if(ft.tag==="Just")return{...pt,deps:pt.deps+2|0,crossings:(()=>{const ht=it(y(it)(1e18)(ft._1.incoming))(y(it)(1e18)(ft._1.outgoing)),wt=it(y(it)(1e18)(_t))(y(it)(1e18)(M.outgoing)),It=ut(y(ut)(-1e18)(ft._1.incoming))(y(ut)(-1e18)(ft._1.outgoing)),dt=ut(y(ut)(-1e18)(_t))(y(ut)(-1e18)(M.outgoing)),Mt=it(y(it)(1e18)(M.incoming))(y(it)(1e18)(F));return pt.crossings+(()=>{const mt=it(y(it)(1e18)(ft._1.incoming))(y(it)(1e18)(ft._1.outgoing)),gt=ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(F)),rt=ut(y(ut)(-1e18)(ft._1.incoming))(y(ut)(-1e18)(ft._1.outgoing));return((y(nt=>st=>st>It?nt:st>=ht?nt+1|0:nt)(0)(F)+y(nt=>st=>st>gt?nt:st>=Mt?nt+1|0:nt)(0)(ft._1.incoming)|0)+y(nt=>st=>st>dt?nt:st>=wt?nt+1|0:nt)(0)(ft._1.outgoing)|0)+y(nt=>st=>st>rt?nt:st>=mt?nt+1|0:nt)(0)(_t)|0})()|0})()};if(ft.tag==="Nothing")return pt;c()})()}))(D);return y(W=>U=>U.rating.crossings<W.rating.crossings||!(U.rating.crossings>W.rating.crossings)&&(U.rating.deps<W.rating.deps||!(U.rating.deps>W.rating.deps)&&U.c.a.size>W.c.a.size)?U:W)(0<Q.length?Q[0]:{c:G._1,rating:{crossings:1e6,deps:1e6}})(Q).c}c()})(),X={...M,incoming:vt(lt.compare)(M.incoming),outgoing:vt(lt.compare)([(Y.a.startPosition+Y.a.endPosition)/2]),splitPartner:E("Just",q.nextId)},H={id:q.nextId,incoming:vt(lt.compare)([(Y.a.startPosition+Y.a.endPosition)/2]),mark:0,members:M.members,outgoing:vt(lt.compare)(M.outgoing),slot:0,splitBy:T,splitPartner:E("Just",M.id)};return{segMap:Z(ot)(H.id)(H)(Z(ot)(X.id)(X)(q.segMap)),freeAreas:(()=>{if(Y.i>=0&&Y.i<q.freeAreas.length){const Q=Eu(Xt,T,Y.i,q.freeAreas),W=(()=>{if(Q.tag==="Nothing")return q.freeAreas;if(Q.tag==="Just")return Q._1;c()})();if(q.freeAreas[Y.i].size/2<d)return W;const U=(q.freeAreas[Y.i].startPosition+q.freeAreas[Y.i].endPosition)/2,F=U-d,_t=U+d;return[...Y.i<1?[]:Gt(0,Y.i,W),...q.freeAreas[Y.i].startPosition<=F?[{startPosition:q.freeAreas[Y.i].startPosition,endPosition:F,size:F-q.freeAreas[Y.i].startPosition}]:[],..._t<=q.freeAreas[Y.i].endPosition?[{startPosition:_t,endPosition:q.freeAreas[Y.i].endPosition,size:q.freeAreas[Y.i].endPosition-_t}]:[],...Y.i<1?W:Gt(Y.i,W.length,W)]}return q.freeAreas})(),nextId:q.nextId+1|0}})({segMap:K,freeAreas:(()=>{const q=vt(lt.compare)([...St(l.segments)(M=>M.incoming),...St(l.segments)(M=>M.outgoing)]);return Pt(B1)(ye(M=>C=>C-M>=2*d?E("Just",{startPosition:M+d,endPosition:C-d,size:C-M-2*d}):T,q,Gt(1,q.length,q)))})(),nextId:l.segments.length})(vt(q=>M=>lt.compare(ut(y(ut)(-1e18)(q.incoming))(y(ut)(-1e18)(q.outgoing))-it(y(it)(1e18)(q.incoming))(y(it)(1e18)(q.outgoing)))(ut(y(ut)(-1e18)(M.incoming))(y(ut)(-1e18)(M.outgoing))-it(y(it)(1e18)(M.incoming))(y(it)(1e18)(M.outgoing))))(Pt(q=>xt(q)(K))(et.decisions)));return{segments:(()=>{const q=(M,C)=>{if(M.tag==="Leaf")return C;if(M.tag==="Node")return q(M._5,zt("Cons",M._4,q(M._6,C)));c()};return bt(Yt.foldr,q(B.segMap,Qt))})(),deps:(()=>{const q=B.segMap,M=(D,G)=>{if(D.tag==="Leaf")return G;if(D.tag==="Node")return M(D._5,zt("Cons",D._4,M(D._6,G)));c()},C=bt(Yt.foldr,M(q,Qt)),I=C.length;return[...St(St(qt(0,I-2|0))(D=>St(qt(D+1|0,I-1|0))(G=>[x(D,G)])))(D=>D._1>=0&&D._1<C.length?D._2>=0&&D._2<C.length?C[D._1].splitPartner.tag!=="Nothing"&&C[D._1].splitPartner.tag==="Just"&&C[D._1].splitPartner._1===C[D._2].id||C[D._2].splitPartner.tag!=="Nothing"&&C[D._2].splitPartner.tag==="Just"&&C[D._2].splitPartner._1===C[D._1].id?[]:o(d,C[D._1],C[D._2]):[]:[]),...St(C)(D=>D.splitBy.tag==="Just"&&D.splitPartner.tag==="Just"&&(()=>{const G=xt(D.splitPartner._1)(q);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;c()})()&&(()=>{const G=xt(D.splitBy._1)(q);if(G.tag==="Nothing")return!1;if(G.tag==="Just")return!0;c()})()?[{src:D.id,tgt:D.splitBy._1,weight:1,kind:co},{src:D.splitBy._1,tgt:D.splitPartner._1,weight:1,kind:co}]:[])]})()}})(),p=h.segments,m=p.length,N=R=>{let P=R,et=!0,K;for(;et;){const B=P,q=ge(M=>{const C=xt(M)(B.inWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;c()})(B.remaining);if(q.tag==="Nothing"){et=!1,K=B;continue}if(q.tag==="Just"){const M=q._1;P={...B,inWeight:y(C=>I=>Tt(ot)(Zt)(I.tgt)(-I.weight)(C))(B.inWeight)((()=>{const C=xt(M)(B.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),marks:Z(ot)(M)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:y(C=>I=>Tt(ot)(Zt)(I.src)(-I.weight)(C))(B.outWeight)((()=>{const C=xt(M)(B.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),remaining:at(C=>C!==M,B.remaining)};continue}c()}return K},J=R=>{let P=R,et=!0,K;for(;et;){const B=P,q=ge(M=>{const C=xt(M)(B.outWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;c()})(B.remaining);if(q.tag==="Nothing"){et=!1,K=B;continue}if(q.tag==="Just"){const M=q._1;P={...B,inWeight:y(C=>I=>Tt(ot)(Zt)(I.tgt)(-I.weight)(C))(B.inWeight)((()=>{const C=xt(M)(B.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),marks:Z(ot)(M)(B.nextSink)(B.marks),nextSink:B.nextSink-1|0,outWeight:y(C=>I=>Tt(ot)(Zt)(I.src)(-I.weight)(C))(B.outWeight)((()=>{const C=xt(M)(B.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;c()})()),remaining:at(C=>C!==M,B.remaining)};continue}c()}return K},v=(R=>{let P=R,et=!0,K;for(;et;){const B=N(J(P));if(B.remaining.length===0){et=!1,K=V(q=>{const M=xt(q.id)(B.marks),C=(()=>{if(M.tag==="Nothing")return q.id;if(M.tag==="Just")return M._1;c()})();return{...q,mark:C<m?(C+m|0)+1|0:C}})(p);continue}P=(()=>{const q=C=>{const I=xt(C)(B.outWeight),D=xt(C)(B.inWeight);return(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})()-(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;c()})()|0},M=vt(C=>I=>ot.compare(q(I))(q(C)))(B.remaining);if(0<M.length){const C=M[0];return{...B,inWeight:y(I=>D=>Tt(ot)(Zt)(D.tgt)(-D.weight)(I))(B.inWeight)((()=>{const I=xt(C)(B.depsBySrc);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;c()})()),marks:Z(ot)(C)(B.nextSource)(B.marks),nextSource:B.nextSource+1|0,outWeight:y(I=>D=>Tt(ot)(Zt)(D.src)(-D.weight)(I))(B.outWeight)((()=>{const I=xt(C)(B.depsByTgt);if(I.tag==="Nothing")return[];if(I.tag==="Just")return I._1;c()})()),remaining:at(I=>I!==C,B.remaining)}}return B})()}return K})({remaining:V(R=>R.id)(p),marks:$,inWeight:y(R=>P=>Tt(ot)(Zt)(P.tgt)(P.weight)(R))($)(h.deps),outWeight:y(R=>P=>Tt(ot)(Zt)(P.src)(P.weight)(R))($)(h.deps),depsBySrc:y(R=>P=>Tt(ot)(se)(P.src)([P])(R))($)(h.deps),depsByTgt:y(R=>P=>Tt(ot)(se)(P.tgt)([P])(R))($)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),w=(()=>{const R=(()=>{const K=Yn(V(B=>x(B.id,B.mark))(v));return{segments:v,deps:Pt(B=>(()=>{if(B.kind==="Critical")return!0;if(B.kind==="Regular")return!1;c()})()?E("Just",B):(()=>{const q=xt(B.src)(K),M=xt(B.tgt)(K);return(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;c()})()>(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})()})()?B.weight===0?T:E("Just",{src:B.tgt,tgt:B.src,weight:B.weight,kind:B.kind}):E("Just",B))(h.deps)}})(),P=y(K=>B=>Tt(ot)(Zt)(B.tgt)(1)(K))($)(R.deps),et=(K=>{let B=K,q=!0,M;for(;q;){const C=B,I=Ht(D=>T,D=>G=>E("Just",{head:D,tail:G}),C.queue);if(I.tag==="Nothing"){q=!1,M=C;continue}if(I.tag==="Just"){B=y((()=>{const D=xt(I._1.head)(C.slots),G=(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;c()})();return Y=>X=>{const H=xt(X)(Y.inDegree),Q=(()=>{if(H.tag==="Nothing")return-1;if(H.tag==="Just")return H._1-1|0;c()})();return{...Y,slots:Z(ot)(X)(Is((()=>{const W=xt(X)(Y.slots);if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;c()})())(G+1|0))(Y.slots),inDegree:Z(ot)(X)(Q)(Y.inDegree),queue:Q===0?[...Y.queue,X]:Y.queue}}})())({...C,queue:I._1.tail})((()=>{const D=xt(I._1.head)(C.adj);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})());continue}c()}return M})({slots:Yn(V(K=>x(K.id,0))(R.segments)),inDegree:P,adj:y(K=>B=>Tt(ot)(se)(B.src)([B.tgt])(K))($)(R.deps),queue:V(K=>K.id)(at(K=>{const B=xt(K.id)(P);if(B.tag==="Nothing")return!0;if(B.tag==="Just")return B._1===0;c()},R.segments))});return vt(K=>B=>ot.compare(K.slot)(B.slot))(V(K=>({...K,slot:(()=>{const B=xt(K.id)(et.slots);if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;c()})()}))(R.segments))})(),L=1+y(R=>P=>Is(R)(P.slot))(0)(w)|0,b=St(w)(R=>R.members),S=at(R=>Be(Fe)(R.edge.id)(b),e),A=y(ut)(-1e18)(V(R=>R.fromPos._2)(S)),O=y(it)(1e18)(V(R=>R.toPos._2)(S));if(A>O){const R=Yn(V(P=>x(P.id,P))(w));return Te(V(P=>V(et=>x(et,{slot:P.slot,slotCount:L,gapTop:O,gapBottom:A,partner:(()=>{if(P.splitPartner.tag==="Just"){const K=xt(P.splitPartner._1)(R);if(K.tag==="Just")return E("Just",{slot:K._1.slot,splitX:0<K._1.incoming.length?K._1.incoming[0]:0});if(K.tag==="Nothing")return T;c()}if(P.splitPartner.tag==="Nothing")return T;c()})()}))(P.members))(at(P=>{if(P.splitPartner.tag==="Just"){const et=xt(P.splitPartner._1)(R);return!(et.tag==="Just"&&(()=>{if(et._1.splitBy.tag==="Nothing")return!1;if(et._1.splitBy.tag==="Just")return!0;c()})())}if(P.splitPartner.tag==="Nothing")return!0;c()},w)))}const j=Yn(V(R=>x(R.id,R))(w));return Te(V(R=>V(P=>x(P,{slot:R.slot,slotCount:L,gapTop:A,gapBottom:O,partner:(()=>{if(R.splitPartner.tag==="Just"){const et=xt(R.splitPartner._1)(j);if(et.tag==="Just")return E("Just",{slot:et._1.slot,splitX:0<et._1.incoming.length?et._1.incoming[0]:0});if(et.tag==="Nothing")return T;c()}if(R.splitPartner.tag==="Nothing")return T;c()})()}))(R.members))(at(R=>{if(R.splitPartner.tag==="Just"){const P=xt(R.splitPartner._1)(j);return!(P.tag==="Just"&&(()=>{if(P._1.splitBy.tag==="Nothing")return!1;if(P._1.splitBy.tag==="Just")return!0;c()})())}if(R.splitPartner.tag==="Nothing")return!0;c()},w)))})()))($)(z1(y(u=>s=>{const a=Ue(s.edge.from.node)(n);if(a.tag==="Just"){const f=Ue(s.edge.to.node)(n);return f.tag==="Just"&&a._1.layer!==f._1.layer?Tt(ot)(se)(Vn(a._1.layer)(f._1.layer))([s])(u):u}return u})($)((()=>{const u=s=>x((()=>{const a=Ue(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Ue(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return vt(s=>a=>A1(u(s))(u(a)))(e)})())))},$1=e=>t=>{const n=Ds(e)(t),r=y(i=>o=>Z(k)(o.node)(o)(i))($)(t);return y(i=>o=>{const u=Ue(o.edge.from.node)(r);if(u.tag==="Just"){const s=Ue(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=Ue(o.edge.id)(n);if(a.tag==="Just")return Z(ot)(Vn(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})($)(e)},Gs=e=>e,Ut=Gs("H"),Kt=Gs("V"),Ms=At.foldMap((()=>{const e={append:t=>n=>t||n};return{mempty:!1,Semigroup0:()=>e}})()),ee=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},ne=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Tr=e=>t=>n=>r=>Ms(i=>n>=i.x&&n<i.x+i.w&&t>i.y&&e<i.y+i.h)(r),fo=e=>t=>n=>r=>Tr(ee(t)(n))(ne(t)(n))(r)(e),go=ct(4),Q1=Pu(e=>{if(e.direction==="H"){const t=ee(e.start._1)(e.end._1);return[{x:t,y:e.start._2-1,w:ne(e.start._1)(e.end._1)-t,h:2}]}if(e.direction==="V"){const t=ee(e.start._2)(e.end._2);return[{x:e.start._1-1,y:t,w:2,h:ne(e.start._2)(e.end._2)-t}]}c()}),Ws=Su(e=>!(e.start._1===e.end._1&&e.start._2===e.end._2)),q1=e=>t=>n=>{const r=Ht(i=>T,i=>o=>E("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[{start:e.start,end:n.end,direction:e.direction}];if(r.tag==="Just"){const i=(r._1.head.direction==="H"?e.direction==="H":r._1.head.direction==="V"&&e.direction==="V")?[{start:e.start,end:r._1.head.end,direction:e.direction}]:[e,r._1.head],o=mf(r._1.tail);if(o.tag==="Nothing"){const u=i.length-1|0;return u>=0&&u<i.length&&(i[u].direction==="H"?n.direction==="H":i[u].direction==="V"&&n.direction==="V")?[...(()=>{const s=i.length-1|0;return s<1?[]:Gt(0,s,i)})(),{start:i[u].start,end:n.end,direction:n.direction}]:[...i,n]}if(o.tag==="Just")return(o._1.last.direction==="H"?n.direction==="H":o._1.last.direction==="V"&&n.direction==="V")?[...i,...o._1.init,{start:o._1.last.start,end:n.end,direction:n.direction}]:[...i,...r._1.tail,n]}c()},Wi=e=>{const t=r=>i=>{const o=Ht(u=>T,u=>s=>E("Just",{head:u,tail:s}),i);if(o.tag==="Nothing")return[r];if(o.tag==="Just")return(r.direction==="H"?o._1.head.direction==="H":r.direction==="V"&&o._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==o._1.head.end._1-o._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==o._1.head.end._2-o._1.head.start._2>=0;c()})()?t({start:r.start,end:o._1.head.end,direction:r.direction})(o._1.tail):[r,...t(o._1.head)(o._1.tail)];c()},n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return t(n._1.head)(n._1.tail);c()},wr=e=>t=>n=>r=>Ms(i=>n>=i.y&&n<i.y+i.h&&t>i.x&&e<i.x+i.w)(r),br=e=>t=>n=>r=>wr(ee(t)(n))(ne(t)(n))(r)(e),H1=e=>t=>n=>r=>{const i=n+2|0,o=i<1?t:Gt(i,t.length,t),u=n<1?[]:Gt(0,n,t),s=(n+1|0)===(r-1|0),a=n===0,f=n>=0&&n<t.length?E("Just",t[n]):T;if(f.tag==="Just"){const g=n+1|0,d=g>=0&&g<t.length?E("Just",t[g]):T;if(d.tag==="Just"){const l=f._1.start._1===d._1.end._1&&(!a||f._1.direction==="V")&&(!s||d._1.direction==="V")&&!fo(e)(ee(f._1.start._2)(d._1.end._2))(ne(f._1.start._2)(d._1.end._2))(f._1.start._1)?E("Just",[...u,{start:f._1.start,end:d._1.end,direction:Kt},...o]):T,_=f._1.start._2===d._1.end._2&&(!a||f._1.direction==="H")&&(!s||d._1.direction==="H")&&!br(e)(ee(f._1.start._1)(d._1.end._1))(ne(f._1.start._1)(d._1.end._1))(f._1.start._2)?E("Just",[...u,{start:f._1.start,end:d._1.end,direction:Ut},...o]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;c()}if(f.tag==="Nothing")return T;c()},Y1=e=>t=>{const n=t.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+1|0)>=n){o=!1,u=t;continue}const a=H1(e)(t)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}c()}return u})(0)},V1=e=>t=>n=>r=>{const i=(l,_,h)=>!fo(e)(ee(_)(h))(ne(_)(h))(l),o=n+3|0,u=o<1?t:Gt(o,t.length,t),s=n<1?[]:Gt(0,n,t),a=(n+2|0)===(r-1|0),f=n===0,g=(l,_,h)=>!br(e)(ee(_)(h))(ne(_)(h))(l),d=n>=0&&n<t.length?E("Just",t[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<t.length?E("Just",t[l]):T;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!f||d._1.direction==="V")&&(!a||_._1.direction==="V")&&i(d._1.start._1,d._1.start._2,_._1.end._2)?E("Just",[...s,{start:d._1.start,end:_._1.end,direction:Kt},...u]):d._1.start._2===_._1.end._2&&(!f||d._1.direction==="H")&&(!a||_._1.direction==="H")&&g(d._1.start._2,d._1.start._1,_._1.end._1)?E("Just",[...s,{start:d._1.start,end:_._1.end,direction:Ut},...u]):T,p=(!f||d._1.direction==="V")&&(!a||_._1.direction==="H")&&i(d._1.start._1,d._1.start._2,_._1.end._2)&&g(_._1.end._2,d._1.start._1,_._1.end._1)?E("Just",[...s,{start:d._1.start,end:x(d._1.start._1,_._1.end._2),direction:Kt},{start:x(d._1.start._1,_._1.end._2),end:_._1.end,direction:Ut},...u]):T,m=(!f||d._1.direction==="H")&&(!a||_._1.direction==="V")&&g(d._1.start._2,d._1.start._1,_._1.end._1)&&i(_._1.end._1,d._1.start._2,_._1.end._2)?E("Just",[...s,{start:d._1.start,end:x(_._1.end._1,d._1.start._2),direction:Ut},{start:x(_._1.end._1,d._1.start._2),end:_._1.end,direction:Kt},...u]):T,N=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?N:h}if(_.tag==="Nothing")return T;c()}if(d.tag==="Nothing")return T;c()},O1=e=>t=>{const n=t.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+2|0)>=n){o=!1,u=t;continue}const a=V1(e)(t)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}c()}return u})(0)},F1=e=>{const t=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=Wi(Ws(Y1(e)(O1(e)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>t(Wi(Ws(n)))},X1=e=>t=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=at(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>i&&a.x<o,e);if(r>n){const a=vt(f=>g=>lt.compare(f.x)(g.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=vt(a=>f=>lt.compare(f.x)(a.x))(V(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},U1=e=>t=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=at(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>i&&a.y<o,e);if(r>n){const a=vt(f=>g=>lt.compare(f.y)(g.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=vt(a=>f=>lt.compare(f.y)(a.y))(V(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},K1=e=>t=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=at(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>i&&a.x<o,e);if(r>n){const a=vt(f=>g=>lt.compare(g.x)(f.x))(V(f=>({...f,x:f.x+f.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=vt(a=>f=>lt.compare(a.x)(f.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},Z1=e=>t=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=at(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>i&&a.y<o,e);if(r>n){const a=vt(f=>g=>lt.compare(g.y)(f.y))(V(f=>({...f,y:f.y+f.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=vt(a=>f=>lt.compare(a.y)(f.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},As=e=>t=>n=>{let r=e,i=t,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o;if(g>100){u=!1,s=f;continue}if(!a(f+g)){u=!1,s=f+g;continue}if(!a(f-g)){u=!1,s=f-g;continue}r=a,i=f,o=g+1}return s},zs=e=>t=>n=>r=>i=>{const o=ee(t)(n),u=ne(t)(n);if(!Tr(o)(u)(r)(e))return r;if(!Tr(o)(u)(i)(e))return i;const s=(r+i)/2;return Tr(o)(u)(s)(e)?As(a=>Tr(o)(u)(a)(e))(s)(1):s},j1=e=>t=>n=>r=>i=>{const o=ee(t)(n),u=ne(t)(n);if(!wr(o)(u)(r)(e))return r;if(!wr(o)(u)(i)(e))return i;const s=(r+i)/2;return wr(o)(u)(s)(e)?As(a=>wr(o)(u)(a)(e))(s)(1):s},td=e=>t=>n=>r=>{const i=ee(t)(n),o=ne(t)(n),u=at(f=>r>=f.x&&r<f.x+f.w&&f.y+f.h>i&&f.y<o,e),s=y(f=>g=>ne(f)(g.x+g.w+4))(r+4)(u),a=y(f=>g=>ee(f)(g.x-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},ed=e=>t=>n=>r=>{const i=ee(t)(n),o=ne(t)(n),u=at(f=>r>=f.y&&r<f.y+f.h&&f.x+f.w>i&&f.x<o,e),s=y(f=>g=>ne(f)(g.y+g.h+4))(r+4)(u),a=y(f=>g=>ee(f)(g.y-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},nd=e=>t=>n=>r=>i=>o=>u=>{const s=(()=>{if(r==="South")return x(i._1,i._2+4);if(r==="North")return x(i._1,i._2-4);if(r==="East")return x(i._1+4,i._2);if(r==="West")return x(i._1-4,i._2);c()})(),a=(()=>{if(o==="South")return x(u._1,u._2+4);if(o==="North")return x(u._1,u._2-4);if(o==="East")return x(u._1+4,u._2);if(o==="West")return x(u._1-4,u._2);c()})(),f=(L,b,S)=>!fo(t)(ee(b)(S))(ne(b)(S))(L),g=(L,b,S)=>!fo(n)(ee(b)(S))(ne(b)(S))(L),d=(L,b,S,A)=>e.tag==="Just"&&!br(n)(ee(L)(b))(ne(L)(b))(e._1)?e._1:j1(t)(L)(b)(S)(A),l=(L,b,S,A)=>{if(L===S){const j=td(t)(b)(A)(L),R=U1(t)(L)(b)(A),P=Z1(t)(L)(b)(A);return[{start:x(L,b),end:x(L,R),direction:Kt},{start:x(L,R),end:x(j,R),direction:Ut},{start:x(j,R),end:x(j,P),direction:Kt},{start:x(j,P),end:x(S,P),direction:Ut},{start:x(S,P),end:x(S,A),direction:Kt}]}const O=d(L,S,b,A);return[{start:x(L,b),end:x(L,O),direction:Kt},{start:x(L,O),end:x(S,O),direction:Ut},{start:x(S,O),end:x(S,A),direction:Kt}]},_=(L,b,S,A)=>{if(b===A){const j=ed(t)(L)(S)(b),R=X1(t)(b)(L)(S),P=K1(t)(b)(L)(S);return[{start:x(L,b),end:x(R,b),direction:Ut},{start:x(R,b),end:x(R,j),direction:Kt},{start:x(R,j),end:x(P,j),direction:Ut},{start:x(P,j),end:x(P,A),direction:Kt},{start:x(P,A),end:x(S,A),direction:Ut}]}const O=zs(t)(b)(A)(L)(S);return[{start:x(L,b),end:x(O,b),direction:Ut},{start:x(O,b),end:x(O,A),direction:Kt},{start:x(O,A),end:x(S,A),direction:Ut}]},h=(L,b,S)=>!br(t)(ee(b)(S))(ne(b)(S))(L),p=(L,b,S)=>!br(n)(ee(b)(S))(ne(b)(S))(L),m=(L,b,S,A)=>{if(p(b,L,S)&&g(S,b,A))return[{start:x(L,b),end:x(S,b),direction:Ut},{start:x(S,b),end:x(S,A),direction:Kt}];const O=zs(t)(b)(A)(L)(S);return[{start:x(L,b),end:x(O,b),direction:Ut},{start:x(O,b),end:x(O,A),direction:Kt},{start:x(O,A),end:x(S,A),direction:Ut}]},N=(L,b,S,A)=>{if(g(L,b,A)&&p(A,L,S))return[{start:x(L,b),end:x(L,A),direction:Kt},{start:x(L,A),end:x(S,A),direction:Ut}];const O=d(L,S,b,A);return[{start:x(L,b),end:x(L,O),direction:Kt},{start:x(L,O),end:x(S,O),direction:Ut},{start:x(S,O),end:x(S,A),direction:Kt}]},J=(()=>{if(r==="South")return o==="North"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Kt}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?N(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return o==="South"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Kt}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?N(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return o==="West"?s._2===a._2&&h(s._2,s._1,a._1)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Ut}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Ut}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),v=(()=>{if(r==="South"||r==="North")return Kt;if(r==="East"||r==="West")return Ut;c()})(),w={start:x(a._1,a._2),end:x(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return Kt;if(o==="East"||o==="West")return Ut;c()})()};return s._1===a._1&&s._2===a._2?[{start:x(i._1,i._2),end:x(u._1,u._2),direction:v}]:q1({start:x(i._1,i._2),end:x(s._1,s._2),direction:v})(J)(w)},rd=V(e=>({x:e.position._1*go-2,y:e.position._2*go-2,w:e.size._1*go+4,h:e.size._2*go+4})),Bs=te(k)(At),Ke=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},od=te(k)(At),$s=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},id=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e._1)(o._3._1);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(e._2==="North"){if(o._3._2==="North"){r=!1,i=E("Just",o._4);continue}n=o._5;continue}if(o._3._2==="North"){n=o._6;continue}if(e._2==="South"){if(o._3._2==="South"){r=!1,i=E("Just",o._4);continue}n=o._5;continue}if(o._3._2==="South"){n=o._6;continue}if(e._2==="East"){if(o._3._2==="East"){r=!1,i=E("Just",o._4);continue}n=o._5;continue}if(o._3._2==="East"){n=o._6;continue}if(e._2==="West"&&o._3._2==="West"){r=!1,i=E("Just",o._4);continue}}c()}return i},ud=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Qs=e=>t=>{const n=t.position._1+t.size._1,r=t.position._2*2+t.size._2,i=t.position._1*2+t.size._1,o=t.position._2+t.size._2;if(e==="South")return x(i,o*2);if(e==="North")return x(i,t.position._2*2);if(e==="East")return x(n*2,r);if(e==="West")return x(t.position._1*2,r);c()},Ai=e=>t=>{const n=ct(4);if(e==="South")return{lo:t.position._1*n,hi:(t.position._1+t.size._1)*n};if(e==="North")return{lo:t.position._1*n,hi:(t.position._1+t.size._1)*n};if(e==="East")return{lo:t.position._2*n,hi:(t.position._2+t.size._2)*n};if(e==="West")return{lo:t.position._2*n,hi:(t.position._2+t.size._2)*n};c()},qs=e=>t=>y(n=>r=>Tt(e)(se)(t(r))([r])(n))($),Hs=e=>t=>n=>r=>{const i=(e==="South"||e==="North")&&(t==="East"||t==="West")&&(()=>{if(e==="South")return r._2>n._2;if(e==="North")return r._2<n._2;if(e==="East")return r._2>n._2;if(e==="West")return r._2<n._2;c()})()&&(()=>{if(t==="East")return n._1>r._1;if(t==="West"||t==="North")return n._1<r._1;if(t==="South")return n._1>r._1;c()})(),o=(e==="East"||e==="West")&&(t==="North"||t==="South")&&(()=>{if(e==="South")return r._1>n._1;if(e==="North")return r._1<n._1;if(e==="East")return r._1>n._1;if(e==="West")return r._1<n._1;c()})()&&(()=>{if(t==="East")return n._2>r._2;if(t==="West"||t==="North")return n._2<r._2;if(t==="South")return n._2>r._2;c()})();return(e==="South"?t==="North"&&n._1===r._1&&r._2>n._2:e==="North"?t==="South"&&n._1===r._1&&r._2<n._2:e==="East"?t==="West"&&n._2===r._2&&r._1>n._1:e==="West"&&t==="East"&&n._2===r._2&&r._1<n._1)?0:i||o?1:2},Ys=e=>t=>{const n=e.hi-e.lo,r=(e.lo+e.hi)/2,i=t.length;return i===0?$:Bs(i===1?V(o=>x(o,r))(t):Dt(o=>u=>x(u,e.lo+ct(o+1|0)*n/ct(i+1|0)))(t))},Vs=e=>t=>n=>r=>i=>{const o=qs(k)(_=>_.to.node)(e),u=qs(k)(_=>_.from.node)(e),s=y(_=>h=>Z(k)(h.node)(h)(_))($)(t),a=(_,h,p)=>{const m=Ke(_)(s);if(m.tag==="Nothing")return x(0,0);if(m.tag==="Just"){const N=Ke(_)(n);if(N.tag==="Nothing"){const J=ct(4);if(p==="South")return x(m._1.position._1*J+m._1.size._1*J/2,(m._1.position._2+m._1.size._2)*J);if(p==="North")return x(m._1.position._1*J+m._1.size._1*J/2,m._1.position._2*J);if(p==="East")return x((m._1.position._1+m._1.size._1)*J,m._1.position._2*J+m._1.size._2*J/2);if(p==="West")return x(m._1.position._1*J,m._1.position._2*J+m._1.size._2*J/2);c()}if(N.tag==="Just"){const J=ge(v=>v.id===h)(N._1);if(J.tag==="Nothing"){const v=ct(4);if(p==="South")return x(m._1.position._1*v+m._1.size._1*v/2,(m._1.position._2+m._1.size._2)*v);if(p==="North")return x(m._1.position._1*v+m._1.size._1*v/2,m._1.position._2*v);if(p==="East")return x((m._1.position._1+m._1.size._1)*v,m._1.position._2*v+m._1.size._2*v/2);if(p==="West")return x(m._1.position._1*v,m._1.position._2*v+m._1.size._2*v/2);c()}if(J.tag==="Just"){const v=ct(4);if(J._1.side==="North")return x(m._1.position._1*v+ct(J._1.offset)*v,m._1.position._2*v);if(J._1.side==="South")return x(m._1.position._1*v+ct(J._1.offset)*v,(m._1.position._2+m._1.size._2)*v);if(J._1.side==="East")return x((m._1.position._1+m._1.size._1)*v,m._1.position._2*v+ct(J._1.offset)*v);if(J._1.side==="West")return x(m._1.position._1*v,m._1.position._2*v+ct(J._1.offset)*v)}}}c()},f=od(St(r)(_=>{if(_.nodes.length<=2)return[];const h=ct(4);if(1<_.nodes.length){const p=Ke(_.nodes[1])(s);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return V(N=>x(N,m))(ye(N=>J=>_.edgeId+":"+N+"->"+J,_.nodes,Gt(1,_.nodes.length,_.nodes)))}c()}return[]})),g=_=>{const h=Ke(_.from.node)(s),p=Ke(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,N=p._1,J=vt(v=>w=>ot.compare(v.score)(w.score))(V(v=>{const w=v._1,L=v._2;return{from:w,to:L,score:(()=>{const b=(j,R,P,et,K)=>{const B=Ai(j)(R),q=Ai(j)(P);return B.lo<q.hi&&q.lo<B.hi&&(w==="South"?L==="North"&&K._2>et._2:w==="North"?L==="South"&&K._2<et._2:w==="East"?L==="West"&&K._1>et._1:w==="West"&&L==="East"&&K._1<et._1)?0:Hs(w)(L)(et)(K)},S=Qs(w)(m),A=Qs(L)(N),O=Hs(w)(L)(S)(A);return(()=>{if(O>0){if(w==="South")return L==="North"?b(ce,m,N,S,A)*10|0:O*10|0;if(w==="North")return L==="South"?b(ae,m,N,S,A)*10|0:O*10|0;if(w==="East")return L==="West"?b(xn,m,N,S,A)*10|0:O*10|0;if(w==="West"&&L==="East")return b(vn,m,N,S,A)*10|0}return O*10|0})()+(w==="South"?L==="North"?0:15:w==="North"?L==="South"?0:15:w==="East"?L==="West"?5:15:w==="West"&&L==="East"?5:15)|0})()}})([x(ce,ae),x(xn,ae),x(vn,ae),x(ce,xn),x(ce,vn),x(ae,ce),x(ae,xn),x(ae,vn),x(xn,ce),x(vn,ce),x(xn,vn),x(vn,xn)]));if(0<J.length)return{from:J[0].from,to:J[0].to}}return{from:ce,to:ae}},d=Bs(V(_=>x(_.id,g(_)))(e)),l=(_,h,p,m,N,J)=>{const v=ct(4),w=Ke(h)(s);if(w.tag==="Nothing")return x(0,0);if(w.tag==="Just"){const L=id(x(p,_))(i);if(L.tag==="Just"){const b=w._1.position._1*v+L._1,S=ct(4);if(_==="South")return x(b,(w._1.position._2+w._1.size._2)*S);if(_==="North")return x(b,w._1.position._2*S);if(_==="East")return x((w._1.position._1+w._1.size._1)*S,b);if(_==="West")return x(w._1.position._1*S,b);c()}if(L.tag==="Nothing"){const b=Ai(_)(w._1),S=(b.lo+b.hi)/2,A=$s(p)(Ys(b)(V(R=>R.id)(vt(R=>P=>lt.compare(N(_)(R))(N(_)(P)))(at(R=>{const P=$s(R.id)(d);if(P.tag==="Just"){const et=J(P._1);return et==="North"?_==="North":et==="South"?_==="South":et==="East"?_==="East":et==="West"&&_==="West"}if(P.tag==="Nothing")return!0;c()},(()=>{const R=Ke(h)(m);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;c()})()))))),O=(()=>{if(A.tag==="Nothing")return S;if(A.tag==="Just")return A._1;c()})(),j=ct(4);if(_==="South")return x(O,(w._1.position._2+w._1.size._2)*j);if(_==="North")return x(O,w._1.position._2*j);if(_==="East")return x((w._1.position._1+w._1.size._1)*j,O);if(_==="West")return x(w._1.position._1*j,O)}}c()};return V(_=>{const h=ud(_.edge.id)(f);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:ie(3)(_.edge.from.node)==="$d:"?x(h._1,_.fromPos._2):_.fromPos,toPos:ie(3)(_.edge.to.node)==="$d:"?x(h._1,_.toPos._2):_.toPos};c()})(V(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,ce),toPos:a(_.to.node,_.to.port._1,ae),fromSide:ce,toSide:ae};const h=g(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,p=>m=>{const N=Ke(m.to.node)(s);if(N.tag==="Nothing")return 0;if(N.tag==="Just"){const J=ct(4);if(p==="South"||p==="North")return N._1.position._1*J+N._1.size._1*J/2;if(p==="East"||p==="West")return N._1.position._2*J+N._1.size._2*J/2}c()},p=>p.from),toPos:l(h.to,_.to.node,_.id,o,p=>m=>{const N=Ke(m.from.node)(s);if(N.tag==="Nothing")return 0;if(N.tag==="Just"){const J=ct(4);if(p==="South"||p==="North")return N._1.position._1*J+N._1.size._1*J/2;if(p==="East"||p==="West")return N._1.position._2*J+N._1.size._2*J/2}c()},p=>p.to),fromSide:h.from,toSide:h.to}})(e))},Os=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},On=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},sd=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),zi=e=>t=>e.gapTop+1*ct(4)+ct(t)*2.5*ct(4),ad=e=>t=>{const n=Os(t.edge.id)(e);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return E("Just",{slot1Y:zi(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:zi(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;c()}if(n.tag==="Nothing")return T;c()},cd=e=>t=>{const n=y(r=>i=>Z(k)(i.node)(i)(r))($)(t);return Te(Dt(r=>i=>{const o=On(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return Dt(s=>a=>{const f=i.edges.length,g=ct(4),d=u.position._1*g,l=u.position._2*g,_=u.size._2*g,h=ct((2*f|0)+1|0),p=l+_*ct(f-s|0)/h,m=l+_*ct((f+1|0)+s|0)/h,N=d-g*2.5*ct(s+1|0),J=[{start:x(d,p),end:x(N,p),direction:Ut},{start:x(N,p),end:x(N,m),direction:Kt},{start:x(N,m),end:x(d,m),direction:Ut}];return{edge:a.id,segments:J,bends:ye(v=>w=>v.end,J,Gt(1,3,J)),bendType:[],jumps:[],reversed:!1}})(i.edges)}c()})(V(r=>({node:r._1,edges:r._2}))(sd(y(r=>i=>Tt(k)(se)(i.from.node)([i])(r))($)(e)))))},fd=e=>t=>{const n=y(o=>u=>Z(k)(u.node)(u)(o))($)(t),r=o=>{const u=On(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;c()},i=o=>{const u=On(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;c()};return vt(o=>u=>{const s=ot.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=lt.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?lt.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(e)},he=e=>{const t=ct(4);return{x:e.position._1*t-2,y:e.position._2*t-2,w:e.size._1*t+4,h:e.size._2*t+4}},gd=e=>e.from.node===e.to.node,_d=e=>t=>n=>r=>{const i=F1(n)(nd(e)(t)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:ye(o=>u=>o.end,i,Gt(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},dd=e=>t=>n=>r=>{const i=[{start:x(r.fromPos._1,r.fromPos._2),end:x(r.fromPos._1,e.slot1Y),direction:Kt},{start:x(r.fromPos._1,e.slot1Y),end:x(e.splitX,e.slot1Y),direction:Ut},{start:x(e.splitX,e.slot1Y),end:x(e.splitX,e.slot2Y),direction:Kt},{start:x(e.splitX,e.slot2Y),end:x(r.toPos._1,e.slot2Y),direction:Ut},{start:x(r.toPos._1,e.slot2Y),end:x(r.toPos._1,r.toPos._2),direction:Kt}];return{edge:r.edge.id,segments:i,bends:ye(o=>u=>o.end,i,Gt(1,5,i)),bendType:[],jumps:[],reversed:!1}},ld=e=>t=>n=>{const r=On(e.edge.from.node)(n);if(r.tag==="Just"){const o=On(e.edge.to.node)(n);return o.tag==="Just"?at(u=>!(u.h===he(r._1).h&&u.w===he(r._1).w&&u.x===he(r._1).x&&u.y===he(r._1).y)&&!(u.h===he(o._1).h&&u.w===he(o._1).w&&u.x===he(o._1).x&&u.y===he(o._1).y),t):at(u=>!(u.h===he(r._1).h&&u.w===he(r._1).w&&u.x===he(r._1).x&&u.y===he(r._1).y),t)}const i=On(e.edge.to.node)(n);return i.tag==="Just"?at(o=>!(o.h===he(i._1).h&&o.w===he(i._1).w&&o.x===he(i._1).x&&o.y===he(i._1).y),t):at(o=>!0,t)},hd=e=>t=>{const n=Os(t.edge.id)(e);if(n.tag==="Just")return E("Just",zi(n._1)(n._1.slot));if(n.tag==="Nothing")return T;c()},pd=e=>t=>n=>r=>i=>{const o=y(f=>g=>Z(k)(g.node)(g)(f))($)(t),u=rd(t),s=Vs(at(f=>f.from.node!==f.to.node,e))(t)(n)(r)(i),a=Ds(s)(t);return[...cd(at(gd,e))(t),...y(f=>g=>{const d=ld(g)(u)(o),l=[...d,...f.edgeObstacles],_=ad(a)(g),h=(()=>{if(_.tag==="Just")return dd(_._1)(d)(l)(g);if(_.tag==="Nothing")return _d(hd(a)(g))(d)(l)(g);c()})();return{results:[...f.results,h],edgeObstacles:[...f.edgeObstacles,...Q1(h.segments)]}})({results:[],edgeObstacles:[]})(fd(s)(t)).results]},gn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},_n=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},md=e=>t=>n=>{if(e.start._1!==t.start._1)return T;const r=_n(gn(e.start._2)(e.end._2))(gn(t.start._2)(t.end._2)),i=gn(_n(e.start._2)(e.end._2))(_n(t.start._2)(t.end._2));return r<i?E("Just",{position:x(e.start._1,(r+i)/2),crossingEdge:n}):T},yd=e=>t=>n=>{if(e.start._2!==t.start._2)return T;const r=_n(gn(e.start._1)(e.end._1))(gn(t.start._1)(t.end._1)),i=gn(_n(e.start._1)(e.end._1))(_n(t.start._1)(t.end._1));return r<i?E("Just",{position:x((r+i)/2,e.start._2),crossingEdge:n}):T},Jd=e=>t=>n=>{if(e.direction==="H")return yd(e)(t)(n);if(e.direction==="V")return md(e)(t)(n);c()},Nd=e=>t=>n=>{const r=e+1|0,i=r<1?n:Gt(r,n.length,n);return St(t.segments)(o=>St(i)(u=>Pt(s=>Jd(o)(s)(u.edge))(at(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},xd=e=>t=>n=>t.start._1>gn(e.start._1)(e.end._1)&&t.start._1<_n(e.start._1)(e.end._1)&&e.start._2>gn(t.start._2)(t.end._2)&&e.start._2<_n(t.start._2)(t.end._2)?E("Just",{position:x(t.start._1,e.start._2),crossingEdge:n}):T,vd=e=>t=>St(at(n=>n.direction==="H",e.segments))(n=>St(t)(r=>Pt(i=>xd(n)(i)(r.edge))(at(i=>i.direction==="V",r.segments)))),Td=e=>t=>n=>[...vd(t)(at(r=>r.edge!==t.edge,n)),...Nd(e)(t)(n)],_o=(()=>{const e={eq:t=>n=>t._1===n._1&&(t._2==="North"?n._2==="North":t._2==="South"?n._2==="South":t._2==="East"?n._2==="East":t._2==="West"&&n._2==="West")};return{compare:t=>n=>{const r=k.compare(t._1)(n._1);if(r==="LT")return Ae;if(r==="GT")return ze;if(t._2==="North")return n._2==="North"?Oe:Ae;if(n._2==="North")return ze;if(t._2==="South")return n._2==="South"?Oe:Ae;if(n._2==="South")return ze;if(t._2==="East")return n._2==="East"?Oe:Ae;if(n._2==="East")return ze;if(t._2==="West"&&n._2==="West")return Oe;c()},Eq0:()=>e}})(),wd=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=_o.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},bd=te(k)(At),Bi=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},kd=te(_o)(At),Fs=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),Fn=e=>t=>n=>r=>{const i=wd(x(t,n))(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;c()},Xs=e=>t=>n=>{const r=bd(Te(V(u=>Dt(s=>a=>x(a,s))(u))(e))),i=(u,s)=>{if(u==="South"){const a=Bi(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}if(u==="North"){const a=Bi(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}return 0},o=u=>y(s=>a=>Ne(_o.compare,me,kd(V(f=>x(x(f._1,u),f._2))(Fs(Ys({lo:0,hi:(()=>{const f=Bi(a._1)(n);if(f.tag==="Just")return f._1._1;if(f.tag==="Nothing")return ie(3)(a._1)==="$d:"?0:1;c()})()})(V(f=>f.id)(vt(f=>g=>ot.compare(i(u,f))(i(u,g)))(a._2)))))),s))($)(Fs(y(s=>a=>a.from.node===a.to.node?s:u==="South"?Tt(k)(se)(a.from.node)([a])(s):u==="North"?Tt(k)(se)(a.to.node)([a])(s):s)($)(t)));return Ne(_o.compare,me,o(ae),o(ce))},Us=e=>e,Ks=e=>e,Zs=e=>e,Ld=y(e=>t=>Z(k)(t)()(e))($),Ed=(()=>{const e=Ie.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return E("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._3,n(r._6,i)));c()};return n(t,Qt)})())})(),tt=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Le=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},$e=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Se=te(k)(At),$i=Sf(k),kr=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),js=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Cd=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Sd=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=ot.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},ta=Zs("VDown"),ea=Zs("VUp"),Pd=Ks("ForwardPhase"),Rd=Ks("StackPhase"),na=Us("HRight"),ra=Us("HLeft"),Id=e=>t=>n=>{const r=y(u=>s=>Tt(k)(Zt)(s.tgt)(1)(u))($)(e),i=Ed(Ld([...V(u=>u.src)(e),...V(u=>u.tgt)(e),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,zt("Cons",s._4,u(s._6,a)));c()};return bt(Yt.foldr,u(t,Qt))})()])),o=y(u=>s=>Tt(k)(se)(s.src)([{target:s.tgt,sep:s.sep}])(u))($)(e);return(u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,N=Ht(J=>T,J=>v=>E("Just",{head:J,tail:v}),h);if(N.tag==="Nothing"){l=!1,_=m;continue}if(N.tag==="Just"){const J=tt(N._1.head)(m),v=(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})(),w=y(L=>b=>{const S=tt(b.target)(L.result),A=v+b.sep,O=tt(b.target)(L.indeg),j=(()=>{if(O.tag==="Nothing")return-1;if(O.tag==="Just")return O._1-1|0;c()})();return{newQueue:j===0?[...L.newQueue,b.target]:L.newQueue,result:Z(k)(b.target)((()=>{if(S.tag==="Nothing")return A;if(S.tag==="Just"){if(n==="VDown")return Le(S._1)(A);if(n==="VUp")return $e(S._1)(A)}c()})())(L.result),indeg:Z(k)(b.target)(j)(L.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const L=tt(N._1.head)(o);if(L.tag==="Nothing")return[];if(L.tag==="Just")return L._1;c()})());f=[...N._1.tail,...w.newQueue],g=w.indeg,d=w.result;continue}c()}return _})(at(u=>{const s=tt(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},i))($)(y(u=>s=>Z(k)(s)(0)(u))($)(i))},Dd=e=>{const t=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return t(o._5,zt("Cons",o._4,t(o._6,u)));c()},n=bt(Yt.foldr,t(e,Qt)),r=y(Le)(999999)(n);if(r===0||n.length===0)return e;const i=o=>{if(o.tag==="Leaf")return $;if(o.tag==="Node")return Ft("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));c()};return i(e)},Gd=e=>t=>{const n=(i,o,u)=>ie(3)(o)==="$d:"&&Cu(s=>ie(3)(s)==="$d:",(()=>{const s=tt(o)(e.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;c()})()),r=i=>o=>u=>s=>a=>f=>g=>{let d=i,l=o,_=s,h=f,p=g,m=!0,N;for(;m;){const J=d,v=l,w=_,L=h,b=p,S=v.length;if(b>=S){m=!1,N=J;continue}const A=b>=0&&b<v.length?E("Just",v[b]):T,O=(()=>{if(A.tag==="Nothing")return"";if(A.tag==="Just")return A._1;c()})(),j=n(e,O);if(b===(S-1|0)||j){const R=(()=>{if(j){const P=tt(O)(e.preds),et=(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;c()})();if(0<et.length){const K=w-1|0,B=tt(et[0])(e.nodeIndex);if(B.tag==="Nothing")return K;if(B.tag==="Just")return B._1;c()}}return w-1|0})();d=y(P=>et=>{if(et>=0&&et<v.length){const K=v[et];return n(e,K)?P:y(B=>q=>{const M=tt(q)(e.nodeIndex),C=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;c()})();return C<L||C>R?Z(k)(q+"\u2192"+K)()(B):B})(P)((()=>{const B=tt(K)(e.preds);if(B.tag==="Nothing")return[];if(B.tag==="Just")return B._1;c()})())}return n(e,"")?P:y(K=>B=>{const q=tt(B)(e.nodeIndex),M=(()=>{if(q.tag==="Nothing")return 0;if(q.tag==="Just")return q._1;c()})();return M<L||M>R?Z(k)(B+"\u2192")()(K):K})(P)((()=>{const K=tt("")(e.preds);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;c()})())})(J)(qt(0,b)),l=v,_=w,h=R,p=b+1|0;continue}d=J,l=v,_=w,h=L,p=b+1|0}return N};return t.length<3?$:y(i=>o=>{if(o>=0&&o<t.length){const u=t[o];return r(i)((()=>{const s=o+1|0;return s>=0&&s<t.length?t[s]:[]})())(u)(u.length)(o)(0)(0)}return r(i)((()=>{const u=o+1|0;return u>=0&&u<t.length?t[u]:[]})())([])(0)(o)(0)(0)})($)(qt(1,t.length-2|0))},oa=e=>{const t=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return t(o._5,zt("Cons",o._4,t(o._6,u)));c()},n=t(e,Qt),r=o=>u=>{let s=o,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=$e(d)(l._1),a=l._2;continue}c()}return g},i=o=>u=>{let s=o,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=Le(d)(l._1),a=l._2;continue}c()}return g};return r(-999999)(n)-i(999999)(n)},Lr=e=>t=>(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(a===t){u=!1,s=f;continue}i=(()=>{const g=tt(a)(e.align);if(g.tag==="Nothing")return t;if(g.tag==="Just")return g._1;c()})(),o=[...f,a]}return s})((()=>{const n=tt(t)(e.align);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;c()})())([t]),Md=e=>t=>n=>r=>i=>o=>u=>s=>a=>f=>g=>{const d=(C,I,D)=>{const G=C.from.node===I?C.from.port:C.to.node===I?C.to.port:T;if(G.tag==="Just"){const Y=tt(I)(i);if(Y.tag==="Just"){const X=ge(H=>H.id===G._1)(Y._1);if(X.tag==="Just"){const H=ct(X._1.offset)*ct(4);return D==="North"||D==="South"?H:0}if(X.tag==="Nothing"){const H=tt(I)(r),Q=Fn(u)(C.id)(D)((()=>{if(H.tag==="Nothing")return .5;if(H.tag==="Just")return H._1._1/2;c()})());return D==="North"||D==="South"?Q:0}c()}if(Y.tag==="Nothing"){const X=tt(I)(r),H=Fn(u)(C.id)(D)((()=>{if(X.tag==="Nothing")return .5;if(X.tag==="Just")return X._1._1/2;c()})());return D==="North"||D==="South"?H:0}c()}if(G.tag==="Nothing"){const Y=tt(I)(r),X=Fn(u)(C.id)(D)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;c()})());return D==="North"||D==="South"?X:0}c()},l=(C,I)=>{if(C.from.node===I){if(g==="HRight")return ce;if(g==="HLeft")return ae;c()}if(g==="HRight")return ae;if(g==="HLeft")return ce;c()},_=(C,I,D)=>y(G=>Y=>Z(k)(Y)((()=>{const X=tt(Y)(G);if(X.tag==="Nothing")return 0+I;if(X.tag==="Just")return X._1+I;c()})())(G))(D)(Lr(a)(C)),h=(()=>{if(g==="HRight")return n;if(g==="HLeft")return le(n);c()})(),p=C=>{const I=tt(C)(r);if(I.tag==="Nothing")return 1;if(I.tag==="Just")return I._1._1;c()},m=Se(Te(Dt(C=>I=>V(D=>x(D,C))(I))(n))),N=(C,I)=>ie(3)(C)==="$d:"&&ie(3)(I)==="$d:"||ie(3)(C)==="$d:"||ie(3)(I)==="$d:"?10:ct(e.nodeGap),J=y(C=>I=>$i(D=>E("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})(),I]))(I.to.node)(C))($)(o),v=y(C=>I=>$i(D=>E("Just",[...(()=>{if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})(),I]))(I.from.node)(C))($)(o),w=Te(n),L=y(C=>I=>{const D=tt(I)(a.root),G=(()=>{if(D.tag==="Nothing")return I;if(D.tag==="Just")return D._1;c()})();return I===G?C:$i(Y=>E("Just",(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;c()})()&&ie(3)(I)==="$d:"))(G)(C)})(Se(V(C=>x(C,!0))(Mn(k.compare)((()=>{const C=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return C(I._5,zt("Cons",I._4,C(I._6,D)));c()};return bt(Yt.foldr,C(a.root,Qt))})()))))(w),b=(C,I)=>{const D=C.free,G=tt(D)(a.root),Y=(()=>{if(G.tag==="Nothing")return D;if(G.tag==="Just")return G._1;c()})(),X=tt(Y)(L),H=(()=>{if(X.tag==="Nothing")return!0;if(X.tag==="Just")return X._1;c()})();return y(Q=>W=>{if(Q.edge.tag==="Just")return Q;if(Q.edge.tag==="Nothing"){if((()=>{const ft=tt(Y)(I.su);return!H&&(()=>{const ht=tt(W.from.node)(m);return W.from.node!==W.to.node&&(()=>{const wt=tt(W.to.node)(m);return(()=>{if(ht.tag==="Nothing")return-1;if(ht.tag==="Just")return ht._1;c()})()===(()=>{if(wt.tag==="Nothing")return-1;if(wt.tag==="Just")return wt._1;c()})()})()})()||(()=>{if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;c()})()})())return Q;const U=W.from.node===D?W.to.node:W.from.node,F=tt(U)(a.root),_t=(()=>{if(F.tag==="Nothing")return U;if(F.tag==="Just")return F._1;c()})(),pt=_t!==Y;return pt&&(()=>{const ft=tt(_t)(I.blockFinished);if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;c()})()?{...Q,edge:E("Just",W),hasEdges:!0}:{...Q,hasEdges:Q.hasEdges||pt}}c()})({edge:T,hasEdges:!1})((()=>{if(C.isRoot){if(g==="HRight"){const Q=tt(D)(J);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()}if(g==="HLeft"){const Q=tt(D)(v);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1}c()}if(g==="HRight"){const Q=tt(D)(v);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()}if(g==="HLeft"){const Q=tt(D)(J);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1}c()})())},S=(C,I,D,G)=>{const Y=(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})(),X={free:I,isRoot:D},H=b(X,G);if(H.edge.tag==="Nothing")return H.hasEdges?{thresh:Y,state:{...G,queue:[...G.queue,X]}}:{thresh:Y,state:G};if(H.edge.tag==="Just"){const Q=H.edge._1.from.node===I?H.edge._1.to.node:H.edge._1.from.node;return{thresh:(()=>{const W=tt((()=>{const pt=tt(Q)(a.root);if(pt.tag==="Nothing")return Q;if(pt.tag==="Just")return pt._1;c()})())(G.x),U=tt(Q)(s),F=tt(I)(s),_t=(()=>{if(W.tag==="Just")return W._1;if(W.tag==="Nothing")return T;c()})();return(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;c()})()+(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;c()})()+d(H.edge._1,Q,(()=>{if(D){if(g==="HRight")return ce;if(g==="HLeft")return ae;c()}if(g==="HRight")return ae;if(g==="HLeft")return ce;c()})())-(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;c()})()-d(H.edge._1,I,(()=>{if(D){if(g==="HRight")return ae;if(g==="HLeft")return ce;c()}if(g==="HRight")return ce;if(g==="HLeft")return ae;c()})())})(),state:{...G,su:Z(k)((()=>{const W=tt(H.edge._1.from.node)(a.root);if(W.tag==="Nothing")return H.edge._1.from.node;if(W.tag==="Just")return W._1;c()})())(!0)(Z(k)((()=>{const W=tt(H.edge._1.to.node)(a.root);if(W.tag==="Nothing")return H.edge._1.to.node;if(W.tag==="Just")return W._1;c()})())(!0)(G.su))}}}c()},A=(C,I,D,G)=>{const Y=I===C,X=tt(I)(a.align),H=(()=>{if(X.tag==="Nothing")return I===C;if(X.tag==="Just")return X._1===C;c()})();if(!(Y||H))return{thresh:D,state:G};const Q=(()=>{if(f==="VDown")return Y&&D<=-1e18;if(f==="VUp")return Y&&D>=1e18;c()})()?S(C,I,!0,G):{thresh:D,state:G};return(()=>{if(f==="VDown")return Q.thresh<=-1e18&&H;if(f==="VUp")return Q.thresh>=1e18&&H;c()})()?S(C,I,!1,Q.state):Q},O=C=>I=>D=>{const G=tt(D)(t.nodeIndex),Y=(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;c()})(),X=ge(F=>Be(Fe)(D)(F))(h),H=(()=>{if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()})(),Q=H.length;if((()=>{if(f==="VDown")return Y<=0;if(f==="VUp")return Y>=(Q-1|0);c()})()){const F=A(C,D,I.thresh,I.st);return{...I,st:F.state,thresh:F.thresh}}const W=(()=>{if(f==="VDown")return Y-1|0;if(f==="VUp")return Y+1|0;c()})(),U=W>=0&&W<H.length?E("Just",H[W]):T;if(U.tag==="Nothing")return I;if(U.tag==="Just"){const F=tt(U._1)(a.root),_t=(()=>{if(F.tag==="Nothing")return U._1;if(F.tag==="Just")return F._1;c()})(),pt=A(C,D,I.thresh,j(_t)(I.st)),ft=(()=>{const re=tt(C)(pt.state.sink);if(re.tag==="Nothing")return C===C;if(re.tag==="Just")return re._1===C;c()})()?{...pt.state,sink:Z(k)(C)((()=>{const re=tt(_t)(pt.state.sink);if(re.tag==="Nothing")return _t;if(re.tag==="Just")return re._1;c()})())(pt.state.sink)}:pt.state,ht=tt(_t)(ft.sink),wt=(()=>{if(ht.tag==="Nothing")return _t;if(ht.tag==="Just")return ht._1;c()})(),It=tt(C)(ft.sink),dt=(()=>{if(It.tag==="Nothing")return C;if(It.tag==="Just")return It._1;c()})();if(dt===wt){const re=tt(_t)(ft.x),Ve=(()=>{if(re.tag==="Just")return re._1;if(re.tag==="Nothing")return T;c()})(),er=(()=>{if(Ve.tag==="Nothing")return 0;if(Ve.tag==="Just")return Ve._1;c()})(),on=tt(C)(ft.x),Et=(()=>{if(on.tag==="Just")return on._1;if(on.tag==="Nothing")return T;c()})(),Rt=(()=>{if(Et.tag==="Nothing")return 0;if(Et.tag==="Just")return Et._1;c()})(),nr=N(D,U._1),Sn=tt(U._1)(s),Pn=tt(D)(s),rr=(()=>{if(Sn.tag==="Nothing")return 0;if(Sn.tag==="Just")return Sn._1;c()})()-(()=>{if(Pn.tag==="Nothing")return 0;if(Pn.tag==="Just")return Pn._1;c()})();if(f==="VDown"){const We=$e(er+rr+p(U._1)+nr)(pt.thresh);return{st:{...ft,x:Z(k)(C)(E("Just",I.initial?We:$e(Rt)(We)))(ft.x)},initial:!1,thresh:pt.thresh}}if(f==="VUp"){const We=Le(er+rr-nr-p(D))(pt.thresh);return{st:{...ft,x:Z(k)(C)(E("Just",I.initial?We:Le(Rt)(We)))(ft.x)},initial:!1,thresh:pt.thresh}}c()}const Mt=tt(_t)(ft.x),mt=(()=>{if(Mt.tag==="Just")return Mt._1;if(Mt.tag==="Nothing")return T;c()})(),gt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})(),rt=tt(C)(ft.x),nt=(()=>{if(rt.tag==="Just")return rt._1;if(rt.tag==="Nothing")return T;c()})(),st=(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})(),yt=ct(e.nodeGap),Jt=tt(D)(s),Ct=tt(U._1)(s),$t=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()-(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1;c()})();return{st:{...ft,classEdges:[...ft.classEdges,{src:dt,tgt:wt,sep:(()=>{if(f==="VDown")return st+$t-gt-p(U._1)-yt;if(f==="VUp")return st+$t+p(D)+yt-gt;c()})()}]},initial:I.initial,thresh:pt.thresh}}c()},j=C=>I=>{const D=tt(C)(I.x),G=(()=>{if(D.tag==="Just")return D._1;if(D.tag==="Nothing")return T;c()})();if(G.tag==="Just")return I;if(G.tag==="Nothing"){const Y=y(O(C))({st:{...I,x:Z(k)(C)(E("Just",0))(I.x)},initial:!0,thresh:(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})()})(Lr(a)(C));return{...Y.st,blockFinished:Z(k)(C)(!0)(Y.st.blockFinished)}}c()},R=y(C=>I=>y(D=>G=>{const Y=tt(G)(a.root),X=(()=>{if(Y.tag==="Nothing")return G;if(Y.tag==="Just")return Y._1;c()})();return X===G?j(X)(D):D})(C)((()=>{if(f==="VDown")return I;if(f==="VUp")return le(I);c()})()))({x:Se(V(C=>x(C,T))(w)),sink:Se(V(C=>x(C,C))(w)),classEdges:[],su:$,blockFinished:$,queue:[]})(h),P=Id(R.classEdges)(R.sink)(f),et=(C,I,D,G)=>{const Y=tt(I)(G),X=tt(I)(s);return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()+(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()+d(C,I,D)},K=Se(V(C=>x(C,!0))(Mn(k.compare)((()=>{const C=(I,D)=>{if(I.tag==="Leaf")return D;if(I.tag==="Node")return C(I._5,zt("Cons",I._4,C(I._6,D)));c()};return bt(Yt.foldr,C(a.root,Qt))})()))),B=C=>I=>D=>{const G=b(D,{su:I.su,blockFinished:K}),Y={phase:C,ppFree:D.free,ppIsRoot:D.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const X=tt((()=>{const H=tt(D.free)(a.root);if(H.tag==="Nothing")return D.free;if(H.tag==="Just")return H._1;c()})())(I.su);if(X.tag==="Nothing")return!1;if(X.tag==="Just")return X._1;c()})(),hasEdges:G.hasEdges,candCount:(()=>{if(D.isRoot){if(g==="HRight"){const X=tt(D.free)(J);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(g==="HLeft"){const X=tt(D.free)(v);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()}if(g==="HRight"){const X=tt(D.free)(v);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length;c()}if(g==="HLeft"){const X=tt(D.free)(J);if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1.length}c()})()};if(G.edge.tag==="Nothing")return{...I,stack:[...I.stack,D],trace:[...I.trace,Y],x:I.x};if(G.edge.tag==="Just"){const X=G.edge._1.from.node===D.free?x(G.edge._1.from.node,G.edge._1.to.node):x(G.edge._1.to.node,G.edge._1.from.node),H=et(G.edge._1,X._1,l(G.edge._1,X._1),I.x)-et(G.edge._1,X._2,l(G.edge._1,X._2),I.x),Q=tt(X._1)(a.root),W=(()=>{if(Q.tag==="Nothing")return X._1;if(Q.tag==="Just")return Q._1;c()})(),U={...Y,edgeId:E("Just",G.edge._1.id),delta:H};if(H>0&&H<1e300){const F=y(ft=>ht=>{const wt=tt(ht)(m),It=(()=>{if(wt.tag==="Nothing")return-1;if(wt.tag==="Just")return wt._1;c()})();if(It>=0&&It<n.length){const mt=n[It],gt=tt(ht)(t.nodeIndex),rt=(()=>{if(gt.tag==="Nothing")return-2;if(gt.tag==="Just")return gt._1-1|0;c()})();return rt>=0&&rt<mt.length?Le(ft)((()=>{const nt=tt(ht)(I.x),st=tt(ht)(s),yt=tt(mt[rt])(I.x),Jt=tt(mt[rt])(s);return(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;c()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()+p(mt[rt])+N(ht,mt[rt]))})()):ft}const dt=tt(ht)(t.nodeIndex),Mt=(()=>{if(dt.tag==="Nothing")return-2;if(dt.tag==="Just")return dt._1-1|0;c()})();return Mt>=0&&Mt<0?Le(ft)((()=>{const mt=tt(ht)(I.x),gt=tt(ht)(s),rt=tt([][Mt])(I.x),nt=tt([][Mt])(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()-((()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+p([][Mt])+N(ht,[][Mt]))})()):ft})(H)(Lr(a)(W)),_t=F>0?-F:0,pt={...I,x:F>0?_(W,_t,I.x):I.x,trace:[...I.trace,{...U,avail:F,shift:_t}]};return F>0?pt:{...pt,stack:[...pt.stack,D]}}if(H<0&&-H<1e300){const F=y(ft=>ht=>{const wt=tt(ht)(m),It=(()=>{if(wt.tag==="Nothing")return-1;if(wt.tag==="Just")return wt._1;c()})();if(It>=0&&It<n.length){const mt=n[It],gt=tt(ht)(t.nodeIndex),rt=(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1+1|0;c()})();return rt>=0&&rt<mt.length?Le(ft)((()=>{const nt=tt(mt[rt])(I.x),st=tt(mt[rt])(s),yt=tt(ht)(I.x),Jt=tt(ht)(s);return(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;c()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;c()})()+p(ht)+N(ht,mt[rt]))})()):ft}const dt=tt(ht)(t.nodeIndex),Mt=(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1+1|0;c()})();return Mt>=0&&Mt<0?Le(ft)((()=>{const mt=tt([][Mt])(I.x),gt=tt([][Mt])(s),rt=tt(ht)(I.x),nt=tt(ht)(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()-((()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;c()})()+p(ht)+N(ht,[][Mt]))})()):ft})(-H)(Lr(a)(W)),_t=F>0?F:0,pt={...I,x:F>0?_(W,_t,I.x):I.x,trace:[...I.trace,{...U,avail:F,shift:_t}]};return F>0?pt:{...pt,stack:[...pt.stack,D]}}return{...I,stack:[...I.stack,D],trace:[...I.trace,U],x:I.x}}c()},q=y(B(Pd))({x:Se(V(C=>x(C,(()=>{const I=tt(C)(a.root),D=(()=>{if(I.tag==="Nothing")return C;if(I.tag==="Just")return I._1;c()})(),G=tt(D)(R.x),Y=tt((()=>{const H=tt(D)(R.sink);if(H.tag==="Nothing")return D;if(H.tag==="Just")return H._1;c()})())(P),X=(()=>{if(G.tag==="Just")return G._1;if(G.tag==="Nothing")return T;c()})();return(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()+(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()})()))(w)),su:R.su,stack:[],trace:[]})(R.queue),M=y(B(Rd))({...q,stack:[]})(le(q.stack));return{x:M.x,queue:R.queue,trace:M.trace}},Wd=e=>t=>n=>r=>i=>o=>u=>s=>a=>f=>g=>Md(e)(t)(n)(r)(i)(o)(u)(s)(a)(f)(g).x,Ad=e=>t=>n=>r=>i=>o=>{const u=(a,f,g)=>{const d=tt(f)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;c()})(),_=a.from.node===f?a.from.port:a.to.node===f?a.to.port:T;if(_.tag==="Just"){const h=tt(f)(t);if(h.tag==="Just"){const p=ge(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=ct(p._1.offset)*ct(4);return g==="North"||g==="South"?m:0}if(p.tag==="Nothing"){const m=Fn(i)(a.id)(g)(l);return g==="North"||g==="South"?m:0}c()}if(h.tag==="Nothing"){const p=Fn(i)(a.id)(g)(l);return g==="North"||g==="South"?p:0}c()}if(_.tag==="Nothing"){const h=Fn(i)(a.id)(g)(l);return g==="North"||g==="South"?h:0}c()},s=a=>f=>g=>d=>{let l=a,_=f,h=g,p=d,m=!0,N;for(;m;){const J=l,v=_,w=h,L=Ht(b=>T,b=>S=>E("Just",{head:b,tail:S}),p);if(L.tag==="Nothing"){m=!1,N=J;continue}if(L.tag==="Just"){const b=L._1.head,S=ge(O=>O.from.node===w&&O.to.node===b||O.from.node===b&&O.to.node===w)(r),A=(()=>{if(S.tag==="Nothing")return v+0;if(S.tag==="Just")return v+(u(S._1,w,S._1.from.node===w?ce:ae)-u(S._1,b,S._1.from.node===b?ce:ae));c()})();l=Z(k)(b)(A)(J),_=A,h=b,p=L._1.tail;continue}c()}return N};return y(a=>f=>{const g=Ht(_=>T,_=>h=>E("Just",{head:_,tail:h}),Lr(e)(f)),d=(()=>{if(g.tag==="Nothing")return Z(k)(f)(0)($);if(g.tag==="Just")return s(Z(k)(g._1.head)(0)($))(0)(g._1.head)(g._1.tail);c()})(),l=y(_=>h=>$e(_)(-h._2))(0)(kr(d));return y(_=>h=>Z(k)(h._1)(h._2+l)(_))(a)(kr(d))})($)(Mn(k.compare)((()=>{const a=(f,g)=>{if(f.tag==="Leaf")return g;if(f.tag==="Node")return a(f._5,zt("Cons",f._4,a(f._6,g)));c()};return bt(Yt.foldr,a(e.root,Qt))})()))},zd=e=>t=>n=>r=>i=>{const o=Te(t),u=y(s=>a=>{const f=y(g=>d=>{const l=(()=>{if(i==="HRight"){const m=tt(d)(e.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()}if(i==="HLeft"){const m=tt(d)(e.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}c()})(),_=l.length;if(_===0)return g;const h=Rn(_-1|0,2),p=Rn(_,2);return y(m=>N=>{if((()=>{const J=tt(d)(m.align);if(J.tag==="Nothing")return d!==d;if(J.tag==="Just")return J._1!==d;c()})())return m;if(N>=0&&N<l.length){const J=tt(l[N])(e.nodeIndex),v=(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})();if(!(js(l[N]+"\u2192"+d)(n)||js(d+"\u2192"+l[N])(n))&&(()=>{if(r==="VDown")return m.r<v;if(r==="VUp")return m.r>v;c()})()){const w=tt(l[N])(m.root),L=(()=>{if(w.tag==="Nothing")return l[N];if(w.tag==="Just")return w._1;c()})();return{root:Z(k)(d)(L)(m.root),align:Z(k)(l[N])(d)(Z(k)(d)(L)(m.align)),r:v}}}return m})(g)((()=>{if(r==="VDown")return qt(h,p);if(r==="VUp")return le(qt(h,p));c()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;c()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return le(a);c()})());return{root:f.root,align:f.align}})({root:Se(V(s=>x(s,s))(o)),align:Se(V(s=>x(s,s))(o))})((()=>{if(i==="HRight")return t;if(i==="HLeft")return le(t);c()})());return{root:u.root,align:u.align}},lo=e=>t=>n=>r=>i=>o=>u=>s=>a=>f=>{const g=zd(t)(n)(s)(a)(f),d=Ad(g)(i)(r)(o)(u)(f);return Cf()(l=>_=>E("Just",(()=>{const h=tt(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;c()})()))(Wd(e)(t)(n)(r)(i)(o)(u)(d)(g)(a)(f))},ia=e=>t=>Dt(n=>r=>y(i=>o=>o>=0&&o<t.length?o>=0&&o<e.length?i+t[o]+e[o]:i+t[o]+0:o>=0&&o<e.length?i+1+e[o]:i+1)(0)((()=>{const i=qt(0,t.length-1|0);return n<1?[]:Gt(0,n,i)})()))(t),Bd=e=>t=>n=>r=>i=>o=>u=>{const s=Cd(0)(t.length-1|0),a=ct(e.layerGap),f=u(gf(s,a)),g=$1(Vs(i)(f)(r)(o)($))(f);return V(d=>{const l=Sd(d)(g);return l.tag==="Just"&&l._1>0?$e(a)(2+ct(l._1-1|0)*2.5):a})(qt(0,s-1|0))},ua=e=>t=>n=>r=>Cu(i=>y(o=>u=>{if(!o.ok)return o;const s=tt(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})(),f=tt(u)(n),g=(()=>{if(f.tag==="Nothing")return a+1;if(f.tag==="Just")return a+f._1._1;c()})();return a+1e-4>o.pos&&g+1e-4>o.pos?{ok:!0,pos:g}:{ok:!1,pos:o.pos}})({ok:!0,pos:-1e18})(i).ok,t),$d=e=>t=>n=>r=>{const i=vt(o=>u=>lt.compare(o.w)(u.w))(V(o=>({l:o,w:oa(o)}))(at(ua()(t)(n),r)));return 0<i.length?E("Just",i[0].l):T},Qd=e=>t=>{const n=Se(Te(V(Dt(i=>o=>x(o,i)))(e))),r=i=>vt(o=>u=>ot.compare((()=>{const s=tt(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})())((()=>{const s=tt(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return $;if(o.tag==="Node")return Ft("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));c()};return i(y(o=>u=>Tt(k)(se)(u.to.node)([u.from.node])(o))($)(t))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return $;if(o.tag==="Node")return Ft("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));c()};return i(y(o=>u=>Tt(k)(se)(u.from.node)([u.to.node])(o))($)(t))})(),nodeIndex:n}},qd=e=>t=>{const n=vt(d=>l=>lt.compare(d.w)(l.w))(Dt(d=>l=>({i:d,l,w:oa(l)}))(t)),r=0<n.length?E("Just",n[0]):T,i=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;c()})(),o=i>=0&&i<t.length?E("Just",t[i]):T,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const N=_,J=h;if(J.tag==="Nil"){p=!1,m=N;continue}if(J.tag==="Cons"){_=Le(N)(J._1),h=J._2;continue}c()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,zt("Cons",l._4,d(l._6,_)));c()};return d(o._1,Qt)})());if(o.tag==="Nothing")return 0;c()})(),s=d=>y(l=>_=>$e(l)((()=>{const h=tt(_._1)(e);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;c()})()))(-999999)(kr(d)),a=i>=0&&i<t.length?E("Just",t[i]):T,f=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;c()})(),g=ye(d=>l=>{const _=h=>{if(h.tag==="Leaf")return $;if(h.tag==="Node")return Ft("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));c()};return _(d)},t,Dt(d=>l=>Oo(d)(2)===0?u-(_=>h=>{let p=_,m=h,N=!0,J;for(;N;){const v=p,w=m;if(w.tag==="Nil"){N=!1,J=v;continue}if(w.tag==="Cons"){p=Le(v)(w._1),m=w._2;continue}c()}return J})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,zt("Cons",h._4,_(h._6,p)));c()};return _(l,Qt)})()):f-s(l))(t));return Dd(y(d=>l=>{const _=vt(lt.compare)(Pt(tt(l))(g));return Z(k)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})($)(Mn(k.compare)(Te(V(d=>{const l=_=>{if(_.tag==="Leaf")return $;if(_.tag==="Node")return Ft("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));c()};return bt(ke.foldr,l(d))})(g)))))},Hd=e=>t=>n=>r=>i=>o=>{const u=Qd(t)(i),s=Gd(u)(t),a={nodeGap:e.nodeGap*4|0},f=Ne(k.compare,me,Se(V(_=>x(_,x(0,1)))(at(_=>ie(3)(_)==="$d:",Te(t)))),(()=>{const _=h=>{if(h.tag==="Leaf")return $;if(h.tag==="Node")return Ft("Node",h._1,h._2,h._3,x(h._4._1*ct(4),h._4._2),_(h._5),_(h._6));c()};return _(n)})()),g=[lo(a)(u)(t)(f)(r)(i)(o)(s)(ta)(na),lo(a)(u)(t)(f)(r)(i)(o)(s)(ea)(na),lo(a)(u)(t)(f)(r)(i)(o)(s)(ta)(ra),lo(a)(u)(t)(f)(r)(i)(o)(s)(ea)(ra)],d=qd(f)(g);if(ua()(t)(f)(d))return d;const l=$d()(t)(f)(g);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return g[0];c()},Yd=e=>t=>n=>r=>{const i=_f(T,Gc,o=>o.node===t?E("Just",o.position):T,e);if(i.tag==="Nothing")return e;if(i.tag==="Just"){const o=i._1;return V(u=>u.node===n?{...u,position:x(o._1+r._1,o._2+r._2)}:u)(e)}c()},Vd=e=>t=>n=>r=>{const i=at(u=>Be(Fe)(u.node)(t),e),o=(()=>{if(n==="Vertical"){if(r==="Start")return y(u=>s=>Le(u)(s.position._1))(99999)(i);if(r==="End")return y(u=>s=>$e(u)(s.position._1))(0)(i);if(r==="Center"){const u=y(s=>a=>s+a.position._1)(0)(i);return i.length===0?0:u/ct(i.length)}c()}if(n==="Horizontal"){if(r==="Start")return y(u=>s=>Le(u)(s.position._2))(99999)(i);if(r==="End")return y(u=>s=>$e(u)(s.position._2))(0)(i);if(r==="Center"){const u=y(s=>a=>s+a.position._2)(0)(i);return i.length===0?0:u/ct(i.length)}}c()})();return V(u=>{if(Be(Fe)(u.node)(t)){if(n==="Vertical")return{...u,position:x(o,u.position._2)};if(n==="Horizontal")return{...u,position:x(u.position._1,o)};c()}return u})(e)},Od=e=>t=>y(n=>r=>{if(r.tag==="Lock"){const i=r._1.node,o=r._1.position;return V(u=>u.node===i?{...u,position:o}:u)(n)}return r.tag==="AlignGroup"?Vd(n)(V(Lu)(r._1.nodes))(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Yd(n)(r._1.anchor)(r._1.target)(r._1.offset):n})(t)(e),Fd=e=>t=>n=>r=>i=>o=>u=>s=>{const a=Se(V(_=>x(_._1,_._2))(kr(r))),f=V(V(Lu))(n),g=V(_=>y(h=>p=>$e(h)((()=>{const m=tt(p)(a);if(m.tag==="Nothing")return 1;if(m.tag==="Just")return m._1._2;c()})()))(1)(_))(f),d=Hd(e)(f)(a)(Se(V(_=>x(_._1,_._2))(kr(i))))(o)(s),l=ia(Bd(e)(n)(r)(i)(o)(u)(_=>{const h=ia(_)(g);return Te(Dt(p=>m=>Dt(N=>J=>({node:J,position:x((()=>{const v=tt(J)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;c()})()/ct(4)})(),p>=0&&p<h.length?h[p]:0),size:(()=>{const v=ie(3)(J)==="$d:"?x(0,1):x(1,1),w=tt(J)(a);if(w.tag==="Nothing")return v;if(w.tag==="Just")return w._1;c()})(),layer:p,order:N}))(m))(f))}))(g);return Od(t)(Te(Dt(_=>h=>Dt(p=>m=>({node:m,position:x((()=>{const N=tt(m)(d);return(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()/ct(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const N=ie(3)(m)==="$d:"?x(0,1):x(1,1),J=tt(m)(a);if(J.tag==="Nothing")return N;if(J.tag==="Just")return J._1;c()})(),layer:_,order:p}))(h))(f)))},Qi=li(Zr)(Nn(32)),sa=li(Zr)(Nn(31)),Er=(()=>{const e=Pg("25214903917");if(e.tag==="Nothing")return Zu;if(e.tag==="Just")return e._1;c()})(),Cr=di(li(Zr)(Nn(48)))(Zr),Xd=e=>{const t=Rg(e);return yr(ju((()=>{if(t.tag==="Nothing")return Zu;if(t.tag==="Just")return t._1;c()})())(Er))(Cr)},qi=Nn(11),ho=e=>t=>{const n=yr(Ur(Kr(t)(Er))(qi))(Cr);return x((()=>{const r=Wu(Lg(hi(n)(Nn(48-e|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()})(),n)},Ud=e=>{const t=ho(26)(e),n=ho(27)(t._2);return x((ct(t._1)*Yo(2)(27)+ct(n._1))/Yo(2)(53),n._2)},Kd=e=>t=>{const n=y(r=>i=>{const o=Ud(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:e})(t);return x(V(r=>r.x)(vt(r=>i=>lt.compare(r.k)(i.k))(ye(r=>i=>({x:r,k:i}),t,n.rs))),n.finalR)},Zd=e=>{const t=yr(Ur(Kr(e)(Er))(qi))(Cr),n=yr(Ur(Kr(t)(Er))(qi))(Cr);return x(Ur(Kr((()=>{const r=hi(t)(Nn(16));return ts.compare(r)(sa)!=="LT"?di(r)(Qi):r})())(Qi))((()=>{const r=hi(n)(Nn(16));return ts.compare(r)(sa)!=="LT"?di(r)(Qi):r})()),n)},Sr=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},po=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Hi=te(k)(At),Qe=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},mo=te(k)(At),jd=nf($o),tl=y(cr)(0),el=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},aa=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},nl=e=>t=>n=>r=>i=>Hi(y(o=>u=>{const s=vt(a=>f=>ot.compare((()=>{const g=Sr(a.id)(i);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})())((()=>{const g=Sr(f.id)(i);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})()))(at(a=>po(a.to.node)(n),at(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...Dt(a=>f=>x(f.id,ct((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(e).ranks),rl=e=>t=>n=>r=>i=>Hi(y(o=>u=>{const s=vt(f=>g=>{const d=ot.compare((()=>{const l=Qe(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Qe(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})());return d==="EQ"?ot.compare((()=>{const l=Sr(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Sr(g.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})()):d})(at(f=>po(f.from.node)(n),at(f=>f.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...Dt(f=>g=>x(g.id,ct((o.rankSum+a|0)-f|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(e).ranks),Yi=e=>t=>n=>{const r=mo(Dt(s=>a=>x(a,s))(e)),i=mo(Dt(s=>a=>x(a,s))(t)),o=Pt(s=>{const a=Qe(s.from.node)(r),f=Qe(s.to.node)(i);if(a.tag==="Just"&&f.tag==="Just")return E("Just",x(a._1,f._1));const g=Qe(s.from.node)(i),d=Qe(s.to.node)(r);return g.tag==="Just"&&d.tag==="Just"?E("Just",x(d._1,g._1)):T})(n),u=o.length;return y(s=>a=>y(f=>g=>a>=0&&a<o.length&&g>=0&&g<o.length&&((o[a]._1-o[g]._1|0)*(o[a]._2-o[g]._2|0)|0)<0?f+1|0:f)(s)(qt(a+1|0,u-1|0)))(0)(qt(0,u-2|0))},ol=e=>t=>n=>r=>i=>{const o=u=>s=>{let a=u,f=s,g=!0,d;for(;g;){const l=a,_=f;if(_>=(l.length-1|0)){g=!1,d=l;continue}const h=_>=0&&_<l.length?E("Just",l[_]):T,p=_+1|0;if(p>=0&&p<l.length&&h.tag==="Just"){const m=h._1,N=l[p];if(sn(L=>L.before===m&&L.after===N,i)){a=l,f=_+1|0;continue}if((()=>{const L=Qe(m)(e),b=Qe(N)(e);return L.tag==="Just"&&b.tag==="Just"&&L._1<b._1})()){a=l,f=_+1|0;continue}const J=Gn(Xt,T,_,N,l),v=(()=>{if(J.tag==="Just")return Gn(Xt,T,_+1|0,m,J._1);if(J.tag==="Nothing")return T;c()})(),w=(()=>{if(v.tag==="Nothing")return l;if(v.tag==="Just")return v._1;c()})();if(Yi(n)(w)(r)<Yi(n)(l)(r)){a=w,f=_+1|0;continue}a=l,f=_+1|0;continue}g=!1,d=l}return d};return(u=>{let s=u,a=!0,f;for(;a;){const g=s,d=o(g)(0);if(jd(d)(g)){a=!1,f=g;continue}s=d}return f})(t)},yo=e=>t=>y(n=>r=>{if(r>=0&&r<e.length){const i=e[r],o=r+1|0;if(o>=0&&o<e.length)return n+Yi(i)(e[o])(t)|0}return n})(0)(qt(0,e.length-2|0)),il=e=>t=>n=>{const r=Pt(f=>f.tag==="OrderConstraint"?E("Just",{before:f._1.before,after:f._1.after}):T)(e.constraints),i=f=>y(g=>d=>{const l=d.after,_=d.before,h=Dn(Xt,T,m=>m===_,g),p=Dn(Xt,T,m=>m===l,g);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Eu(Xt,T,h._1,g),N=(()=>{if(m.tag==="Nothing")return g;if(m.tag==="Just")return m._1;c()})(),J=lf(Xt,T,p._1,_,N);if(J.tag==="Nothing")return N;if(J.tag==="Just")return J._1;c()}return g})(f)(r),o=Hi(Dt(f=>g=>x(g.id,f))(n)),u=(f,g,d)=>{const l=f.length;return y(_=>h=>{const p=g?h-1|0:h+1|0,m=p>=0&&p<_._1.length?E("Just",_._1[p]):T;if(m.tag==="Just"){const N=h>=0&&h<_._1.length?E("Just",_._1[h]):T;if(N.tag==="Just"){const J=mo(Dt(S=>A=>x(A,S))(m._1)),v=mo(Dt(S=>A=>x(A,S))(N._1)),w=g?nl(m._1)(J)(v)(n)(o):rl(m._1)(J)(v)(n)(o),L=y(S=>A=>{const O=Pt(R=>Sr(R.id)(w))(at(g?R=>R.to.node===A._2&&po(R.from.node)(J):R=>R.from.node===A._2&&po(R.to.node)(J),n));if(O.length===0)return{...S,items:[...S.items,{n:A._2,key:T,origIdx:A._1}]};const j=ho(24)(S.r);return{items:[...S.items,{n:A._2,key:E("Just",(tl(O)+(ct(j._1)*4172325152040912e-24-.03500000014901161))/ct(O.length)),origIdx:A._1}],r:j._2}})({items:[],r:_._2})(Dt(In)(N._1)),b=Gn(Xt,T,h,ol(e.modelOrder)(i(V(S=>S.n)(vt(S=>A=>{const O=Qe(S.n)(e.modelOrder),j=Qe(A.n)(e.modelOrder);if(O.tag==="Just"&&j.tag==="Just"){const R=ot.compare(O._1)(j._1);return R==="EQ"?lt.compare(S.key)(A.key):R}return lt.compare(S.key)(A.key)})((()=>{const S=L.items,A=O=>j=>{let R=O,P=j,et=!0,K;for(;et;){const B=R,q=P;if(B>=0&&B<S.length){if(S[B].key.tag==="Just"){et=!1,K=S[B].key._1;continue}if(S[B].key.tag==="Nothing"){R=B+1|0,P=q;continue}c()}et=!1,K=q}return K};return(O=>j=>R=>{let P=O,et=j,K=R,B=!0,q;for(;B;){const M=P,C=et,I=K;if(M>=0&&M<S.length){if(S[M].key.tag==="Just"){P=M+1|0,et=S[M].key._1,K=[...I,{n:S[M].n,key:S[M].key._1,origIdx:S[M].origIdx}];continue}if(S[M].key.tag==="Nothing"){const D=(C+A(M+1|0)(C+1))/2;P=M+1|0,et=D,K=[...I,{n:S[M].n,key:D,origIdx:S[M].origIdx}];continue}c()}B=!1,q=I}return q})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(b.tag==="Just")return x(b._1,L.r);if(b.tag==="Nothing")return x(_._1,_._2);c()}if(N.tag==="Nothing")return x(_._1,_._2);c()}if(m.tag==="Nothing")return x(_._1,_._2);c()})(x(f,d))(g?qt(1,l-1|0):le(qt(0,l-2|0)))},s=y(f=>g=>Z(k)(g.from.node)()(Z(k)(g.to.node)()(f)))($)(n),a=y(f=>g=>{if(f.result.crossings===0)return f;const d=J=>v=>w=>L=>{let b=J,S=v,A=w,O=L,j=!0,R;for(;j;){const P=b,et=S,K=A,B=O;if(K===0){j=!1,R={layout:P,crossings:0,random:B};continue}const q=u(P,et,B),M=yo(q._1)(n);if(M<K){b=q._1,S=!et,A=M,O=q._2;continue}j=!1,R={layout:P,crossings:K,random:q._2}}return R},l=ho(1)(f.result.random),_=l._1!==0,h=e.modelOrder.tag==="Leaf",p=(f.firstTry||f.secondTry)&&!h?f.firstTry:_,m=(()=>{if(!h){const L=u(t,p,l._2);return d(L._1)(!p)(yo(L._1)(n))(L._2)}const J=p?0:el(0)(t.length-1|0),v=J>=0&&J<t.length?E("Just",t[J]):T;if(v.tag==="Just"&&v._1.length>1){const L=at(b=>aa(b)(s),v._1);if(L.length>1){const b=Kd(l._2)(L),S=b._1,A=Gn(Xt,T,J,i(y(O=>j=>aa(j)(s)?O.idx>=0&&O.idx<S.length?{idx:O.idx+1|0,result:[...O.result,S[O.idx]]}:{idx:O.idx,result:[...O.result,j]}:{idx:O.idx,result:[...O.result,j]})({idx:0,result:[]})(v._1).result),t);if(A.tag==="Just"){const O=u(A._1,p,b._2);return d(O._1)(!p)(yo(O._1)(n))(O._2)}}}const w=u(t,p,l._2);return d(w._1)(!p)(yo(w._1)(n))(w._2)})(),N=f.secondTry?!1:f.secondTry;return f.firstTry?{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:f.firstTry,secondTry:N}})({result:{layout:t,crossings:1e9,random:yr(ju(Zd(Xd(1))._1)(Er))(Cr)},firstTry:e.modelOrder.tag!=="Leaf",secondTry:!1})(qt(1,e.iterations)).result;return t.length<=0||e.iterations<=0?t:a.layout},ul=e=>e,ca=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},pe=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Xn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Pr=(()=>{const e={eq:t=>n=>t._1===n._1&&t._2===n._2};return{compare:t=>n=>{const r=k.compare(t._1)(n._1);return r==="LT"?Ae:r==="GT"?ze:k.compare(t._2)(n._2)},Eq0:()=>e}})(),sl=te(k)(At),al=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=Pr.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},cl=ul("Greedy"),Vi=e=>t=>n=>y(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===t&&!ca(i.to.node)(r.marks)){const o=pe(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;c()})(),s=Z(k)(i.to.node)(u)(r.inDeg);return(()=>{const a=pe(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!Be(Fe)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===t&&!ca(i.from.node)(r.marks)){const o=pe(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;c()})(),s=Z(k)(i.from.node)(u)(r.outDeg);return(()=>{const a=pe(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!Be(Fe)(i.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,i.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:at(r=>r!==t,n.remaining)})(e),fl=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(k)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(k)(t._1.node)(0)(e);if(t._1.pin.tag==="LastLayer")return Z(k)(t._1.node)(99999)(e)}return e})($),fa=e=>t=>n=>{const r=pe(t)(e),i=pe(n)(e);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},ga=e=>t=>n=>r=>{if(Xn(n)(r.visited)||Xn(n)(r.visiting))return r;const i=y(gl(e)(t)(n))({...r,visiting:Z(k)(n)()(r.visiting)})((()=>{const o=pe(n)(t);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;c()})());return{...i,visiting:ar(k)(n)(i.visiting),visited:Z(k)(n)()(i.visited)}},gl=e=>t=>n=>r=>i=>fa(e)(n)(i)?{...r,backEdges:Z(Pr)(x(n,i))()(r.backEdges)}:Xn(i)(r.visiting)?{...r,backEdges:Z(Pr)(x(n,i))()(r.backEdges)}:Xn(i)(r.visited)?r:ga(e)(t)(i)(r),_l=e=>t=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,N=Ht(J=>T,J=>v=>E("Just",{head:J,tail:v}),m.sinks);if(N.tag==="Just"){_=Vi(n)(N._1.head)({...m,sinks:N._1.tail,marks:Z(k)(N._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(N.tag==="Nothing"){const J=Ht(v=>T,v=>w=>E("Just",{head:v,tail:w}),m.sources);if(J.tag==="Just"){_=Vi(n)(J._1.head)({...m,sources:J._1.tail,marks:Z(k)(J._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(J.tag==="Nothing"){const v=L=>{const b=pe(L)(m.outDeg),S=pe(L)(m.inDeg);return(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;c()})()|0},w=vt(L=>b=>{const S=ot.compare(v(b))(v(L));return S==="EQ"?ot.compare((()=>{const A=pe(L)(t);if(A.tag==="Nothing")return 1e6;if(A.tag==="Just")return A._1;c()})())((()=>{const A=pe(b)(t);if(A.tag==="Nothing")return 1e6;if(A.tag==="Just")return A._1;c()})()):S})(m.remaining);if(0<w.length){const L=w[0];_=Vi(n)(L)({...m,remaining:at(b=>b!==L,m.remaining),marks:Z(k)(L)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}c()}return p},i=Mn(k.compare)([...V(l=>l.from.node)(n),...V(l=>l.to.node)(n)]),o=at(l=>l.from.node!==l.to.node,n),u=y(l=>_=>Tt(k)(Zt)(_.to.node)(1)(l))($)(o),s=y(l=>_=>Tt(k)(Zt)(_.from.node)(1)(l))($)(o),a=at(l=>{const _=pe(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},i),f=at(l=>{const _=pe(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},i),g=i.length+1|0,d=y(l=>_=>{const h=pe(_)(l);return h.tag==="Just"&&h._1<0?Z(k)(_)(h._1+g|0)(l):l})(r({remaining:at(l=>!Be(Fe)(l)(a)&&!Be(Fe)(l)(f),i),marks:$,inDeg:u,outDeg:s,sources:a,sinks:f,nextLeft:1,nextRight:-1}).marks)(i);return y(l=>_=>{if(_.from.node===_.to.node)return l;if(fa(e)(_.from.node)(_.to.node))return Z(Pr)(x(_.from.node,_.to.node))()(l);const h=pe(_.from.node)(d),p=pe(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?Z(Pr)(x(_.from.node,_.to.node))()(l):l})($)(n)},dl=y(e=>t=>Tt(k)(se)(t.from.node)([t.to.node])(e))($),ll=e=>t=>{const n=dl(t),r=Mn(k.compare)([...V(o=>o.from.node)(t),...V(o=>o.to.node)(t)]),i=y(o=>u=>Z(k)(u.to.node)()(o))($)(t);return y(o=>u=>ga(e)(n)(u)(o))({visiting:$,visited:$,backEdges:$})([...at(o=>!Xn(o)(i),r),...at(o=>Xn(o)(i),r)]).backEdges},hl=e=>t=>n=>r=>{const i=sl(Dt(s=>a=>x(a,s))(t)),o=fl(n),u=(()=>{if(e==="DepthFirst")return ll(o)(r);if(e==="Greedy")return _l(o)(i)(r);c()})();return{edges:V(s=>al(x(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},_a=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},pl=e=>t=>n=>y(r=>i=>{const o=_a(i.from.node)(e),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})(),s=_a(i.to.node)(e),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;c()})();if(a<=1)return{...r,edges:[...r.edges,i],chains:[...r.chains,{edgeId:i.id,nodes:[i.from.node,i.to.node]}]};const f=i.id,g=V(l=>"$d:"+f+":"+ue(l))(qt(1,a-1|0)),d=[i.from.node,...g,i.to.node];return{...r,layers:y(l=>_=>{const h=_._2,p=yf(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;c()})(r.layers)(ye(In,qt(1,a-1|0),g)),edges:[...r.edges,...ye(l=>_=>({id:f+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port}}),d,Gt(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(t),Oi=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},fe=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Vt=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Rr=e=>t=>{const n=ot.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},bn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=ot.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Jo=te(k)(At),Un=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=ot.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},ml=(()=>{const e={eq:n=>r=>n.delta===r.delta&&n.eid===r.eid&&n.src===r.src&&n.tgt===r.tgt&&n.weight===r.weight},t={compare:n=>r=>{const i=ot.compare(n.delta)(r.delta);if(i==="LT"||i==="GT"||i!=="EQ")return i;const o=ot.compare(n.eid)(r.eid);if(o==="LT"||o==="GT"||o!=="EQ")return o;const u=k.compare(n.src)(r.src);if(u==="LT"||u==="GT"||u!=="EQ")return u;const s=k.compare(n.tgt)(r.tgt);if(s==="LT"||s==="GT"||s!=="EQ")return s;const a=ot.compare(n.weight)(r.weight);return a==="LT"||a==="GT"||a!=="EQ"?a:Oe},Eq0:()=>e};return y(n=>r=>Z(t)(r)()(n))($)})(),yl=y(e=>t=>Z(k)(t)()(e))($),Jl=te(ot)(At),Nl=e=>t=>Ne(k.compare,me,e,t),xl=e=>y(t=>n=>({base:(()=>{const r=i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=Oi(g)(d._1),s=d._2;continue}c()}return f};return(t.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,zt("Cons",o._4,i(o._6,u)));c()};return i(n,Qt)})())|0)+1|0})(),result:[...t.result,(()=>{if(t.base===0)return n;const r=i=>{if(i.tag==="Leaf")return $;if(i.tag==="Node")return Ft("Node",i._1,i._2,i._3,i._4+t.base|0,r(i._5),r(i._6));c()};return r(n)})()]}))({base:0,result:[]})(e).result,vl=e=>t=>{const n=o=>{let u=o,s=!0,a;for(;s;){const f=u,g=Ht(d=>T,d=>l=>E("Just",{head:d,tail:l}),f.queue);if(g.tag==="Nothing"){s=!1,a=f;continue}if(g.tag==="Just"){if(fe(g._1.head)(f.removedNodes)){u={...f,queue:g._1.tail};continue}const d=ge(l=>!fe(l.src+"\u2192"+l.tgt)(f.removedEdges)&&(l.src===g._1.head||l.tgt===g._1.head))(t);if(d.tag==="Nothing"){u={...f,queue:g._1.tail};continue}if(d.tag==="Just"){const l=d._1.src===g._1.head?d._1.tgt:d._1.src,_={...f,degree:Z(k)(l)((()=>{const h=Vt(l)(f.degree);if(h.tag==="Nothing")return-1;if(h.tag==="Just")return h._1-1|0;c()})())(f.degree),removedNodes:Z(k)(g._1.head)()(f.removedNodes),removedEdges:Z(k)(d._1.src+"\u2192"+d._1.tgt)()(f.removedEdges),record:[...f.record,{node:g._1.head,neighbour:l,viaSrc:d._1.src===g._1.head}],queue:g._1.tail};if((()=>{const h=Vt(l)(_.degree);return(()=>{if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1===1;c()})()&&!fe(l)(_.removedNodes)})()){u={..._,queue:[..._.queue,l]};continue}u=_;continue}}c()}return a},r=y(o=>u=>Tt(k)(Zt)(u.src)(1)(Tt(k)(Zt)(u.tgt)(1)(o)))($)(t),i=n({degree:r,removedNodes:$,removedEdges:$,record:[],queue:at(o=>{const u=Vt(o)(r);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;c()},e)});return{coreNodes:at(o=>!fe(o)(i.removedNodes),e),coreEdges:at(o=>!fe(o.src+"\u2192"+o.tgt)(i.removedEdges),t),removed:i.record}},Tl=e=>t=>y(n=>r=>{const i=Vt(r.neighbour)(n),o=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})();return Z(k)(r.node)(r.viaSrc?o-1|0:o+1|0)(n)})(t)(le(e)),da=e=>t=>n=>{const r=y(o=>u=>{const s=da(e)(u.src===t?u.tgt:u.src)({...o.st,edgeVisited:Z(ot)(u.eid)()(o.st.edgeVisited)});return{lowest:Rr(o.lowest)(s.lowest),st:s.st}})({lowest:1e9,st:n})(at(o=>bn(o.eid)(n.treeEdge)&&(o.src===t||o.tgt===t)&&!bn(o.eid)(n.edgeVisited),e)),i=Rr(r.lowest)(r.st.postOrder);return{lowest:i,st:{...r.st,poID:Z(k)(t)(r.st.postOrder)(r.st.poID),lowestPoID:Z(k)(t)(i)(r.st.lowestPoID),postOrder:r.st.postOrder+1|0}}},la=e=>t=>n=>da(t)(0<e.length?e[0]:"")({...n,edgeVisited:$,postOrder:1,poID:$,lowestPoID:$}).st,ha=e=>t=>{const n=y(r=>i=>Rr(r)((()=>{const o=Vt(i)(t);if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})()))(1e9)(e);return Jo(V(r=>x(r,(()=>{const i=Vt(r)(t);if(i.tag==="Nothing")return-n;if(i.tag==="Just")return i._1-n|0;c()})()))(e))},Fi=e=>t=>{const n=Vt(t)(e.poID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},pa=e=>t=>{const n=Vt(t)(e.lowestPoID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},wl=e=>t=>ge(n=>{const r=Un(n.eid)(t.cutvalue);return bn(n.eid)(t.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<0;c()})()})(e),we=e=>t=>{const n=Vt(t)(e.layer);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;c()},bl=e=>t=>y(n=>r=>{if(fe(r.src)(t.treeNode)===fe(r.tgt)(t.treeNode))return n;const i=(we(t)(r.tgt)-we(t)(r.src)|0)-r.delta|0;return i<n.slack?{edge:E("Just",r),slack:i}:n})({edge:T,slack:1e9})(e).edge,Xi=e=>t=>n=>{const r={...n,treeNode:Z(k)(t)()(n.treeNode)};return y(i=>o=>{if(bn(o.eid)(i.st.edgeVisited))return i;const u={...i.st,edgeVisited:Z(ot)(o.eid)()(i.st.edgeVisited)},s=(fe(o.src)(u.treeNode)&&!fe(o.tgt)(u.treeNode)?o.src===o.src:fe(o.tgt)(u.treeNode)&&!fe(o.src)(u.treeNode)?o.src===o.tgt:o.src===o.src)?o.tgt:o.src;if(bn(o.eid)(u.treeEdge)){if(fe(s)(u.treeNode))return{...i,st:u};const a=Xi(e)(s)(u);return{count:i.count+a.count|0,st:a.st}}if(!fe(s)(u.treeNode)&&o.delta===(we(u)(o.tgt)-we(u)(o.src)|0)){const a=Xi(e)(s)({...u,treeEdge:Z(ot)(o.eid)()(u.treeEdge)});return{count:i.count+a.count|0,st:a.st}}return{...i,st:u}})({count:1,st:r})(at(i=>(i.src===t||i.tgt===t)&&!bn(i.eid)(r.edgeVisited),e))},No=e=>t=>n=>{const r=Fi(e)(n.src),i=Fi(e)(n.tgt),o=Fi(e)(t);return pa(e)(n.src)<=o&&o<=r&&pa(e)(n.tgt)<=o&&o<=i?r>=i:r<i},kl=e=>t=>({layer:Jo(V(n=>x(n,0))(e)),treeNode:$,treeEdge:$,poID:$,lowestPoID:$,cutvalue:$,postOrder:1,edgeVisited:$}),Ll=e=>t=>n=>at(r=>bn(r.eid)(t.treeEdge)&&(r.src===n||r.tgt===n),e),El=e=>t=>n=>{let r=e,i=t,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o,d=Xi(f)(0<a.length?a[0]:"")({...g,edgeVisited:$,treeNode:$,treeEdge:$});if(d.count>=a.length){u=!1,s=d.st;continue}const l=bl(f)(d.st);if(l.tag==="Nothing"){u=!1,s=d.st;continue}if(l.tag==="Just"){const _=(we(d.st)(l._1.tgt)-we(d.st)(l._1.src)|0)-l._1.delta|0,h=fe(l._1.tgt)(d.st.treeNode)?-_:_;r=a,i=f,o={...d.st,layer:y(p=>m=>fe(m)(d.st.treeNode)?Z(k)(m)(we(d.st)(m)+h|0)(p):p)(d.st.layer)(a)};continue}c()}return s},Cl=e=>t=>n=>y(r=>i=>{if(No(n)(i.src)(t)&&!No(n)(i.tgt)(t)){const o=(we(n)(i.tgt)-we(n)(i.src)|0)-i.delta|0;if(o<r.slack)return{edge:E("Just",i),slack:o}}return r})({edge:T,slack:1e9})(e).edge,Sl=e=>t=>{const n=y(i=>o=>Tt(k)(se)(o.tgt)([o.src])(Tt(k)(se)(o.src)([o.tgt])(i)))($)(t),r=i=>o=>u=>{let s=i,a=o,f=u,g=!0,d;for(;g;){const l=s,_=a,h=f,p=Ht(m=>T,m=>N=>E("Just",{head:m,tail:N}),l);if(p.tag==="Nothing"){g=!1,d={nodes:h};continue}if(p.tag==="Just"){if(fe(p._1.head)(_)){s=p._1.tail,a=_,f=h;continue}s=[...p._1.tail,...(()=>{const m=Vt(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()})()],a=Z(k)(p._1.head)()(_),f=[...h,p._1.head];continue}c()}return d};return y(i=>o=>{if(fe(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:y(s=>a=>Z(k)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:$,components:[]})(e).components},Pl=e=>t=>n=>r=>{const i=r.tgt,o=r.src;return y(u=>s=>{if((()=>{const a=Un(s.eid)(t.cutvalue);if(a.tag==="Just")return!0;if(a.tag==="Nothing")return!1;c()})()){const a=Un(s.eid)(t.cutvalue),f=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()})();return o===s.src||i===s.tgt?u-(f-s.weight|0)|0:u+(f-s.weight|0)|0}return n===o?s.src===n?u+s.weight|0:u-s.weight|0:s.src===n?u-s.weight|0:u+s.weight|0})(r.weight)(at(u=>u.eid!==r.eid&&(u.src===n||u.tgt===n),e))},Rl=e=>t=>n=>(r=>i=>{let o=r,u=i,s=!0,a;for(;s;){const f=o,g=u,d=Vt(g)(f.unknown),l=(()=>{if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;c()})();if(l.length===1){const _=l[0].src===g?l[0].tgt:l[0].src;o={unknown:(()=>{const h=Vt(_)(f.unknown),p=(()=>{if(h.tag==="Just")return Z(k)(_)(at(N=>N.eid!==l[0].eid,h._1))(f.unknown);if(h.tag==="Nothing")return f.unknown;c()})(),m=Vt(g)(p);if(m.tag==="Just")return Z(k)(g)(at(N=>N.eid!==l[0].eid,m._1))(p);if(m.tag==="Nothing")return p;c()})(),cutvalue:Z(ot)(l[0].eid)(Pl(e)(f)(g)(l[0]))(f.cutvalue)},u=_;continue}s=!1,a=f}return a})(t)(n),ma=e=>t=>n=>{const r={unknown:Jo(V(i=>x(i,bt(ke.foldr,ml(Ll(t)(n)(i)))))(e)),cutvalue:$};return{...n,cutvalue:y(Rl(t))(r)(at(i=>{const o=Vt(i)(r.unknown);if(o.tag==="Nothing")return!1;if(o.tag==="Just")return o._1.length===1;c()},e)).cutvalue}},Il=e=>t=>n=>r=>i=>{const o={...i,treeEdge:Z(ot)(r.eid)()(ar(ot)(n.eid)(i.treeEdge))},u=(we(o)(r.tgt)-we(o)(r.src)|0)-r.delta|0,s=No(o)(r.tgt)(n)?-u:u;return ma(e)(t)(la(e)(t)({...o,layer:y(a=>f=>No(o)(f)(n)?a:Z(k)(f)(we(o)(f)+s|0)(a))(o.layer)(e)}))},Dl=e=>t=>n=>r=>(i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(g===0){a=!1,f=d;continue}const l=wl(n)(d);if(l.tag==="Nothing"){a=!1,f=d;continue}if(l.tag==="Just"){const _=Cl(n)(l._1)(d);if(_.tag==="Nothing"){a=!1,f=d;continue}if(_.tag==="Just"){u=g-1|0,s=Il(t)(n)(l._1)(_._1)(d);continue}}c()}return f})(e)(r),Gl=e=>t=>n=>ma(e)(t)(la(e)(t)(El(e)(t)(n))),ya=e=>y(t=>n=>Tt(k)(se)(e(n))([n])(t))($),Ml=e=>t=>n=>{const r=u=>s=>a=>f=>{let g=u,d=s,l=a,_=f,h=!0,p;for(;h;){const m=g,N=d,J=l,v=_,w=Ht(L=>T,L=>b=>E("Just",{head:L,tail:b}),J);if(w.tag==="Nothing"){h=!1,p=v;continue}if(w.tag==="Just"){const L=we(v)(w._1.head),b=y(S=>A=>{const O=Vt(A.tgt)(S.incident),j=(()=>{if(O.tag==="Nothing")return-1;if(O.tag==="Just")return O._1-1|0;c()})();return{st:{...S.st,layer:Z(k)(A.tgt)(Oi(we(S.st)(A.tgt))(L+A.delta|0))(S.st.layer)},incident:Z(k)(A.tgt)(j)(S.incident),queue:j===0?[...S.queue,A.tgt]:S.queue}})({st:v,incident:N,queue:w._1.tail})((()=>{const S=Vt(w._1.head)(m);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})());g=m,d=b.incident,l=b.queue,_=b.st;continue}c()}return p},i=ya(u=>u.tgt)(t),o=Jo(V(u=>x(u,(()=>{const s=Vt(u)(i);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.length;c()})()))(e));return r(ya(u=>u.src)(t))(o)(at(u=>{const s=Vt(u)(o);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},e))(n)},Ja=e=>t=>{const n=Dt(i=>o=>({src:o.src,tgt:o.tgt,delta:1,weight:1,eid:i}))(t),r=Ml(e)(n)(kl(e)(n));return n.length===0?r.layer:Dl(4*e.length|0)(e)(n)(Gl(e)(n)(r)).layer},Wl=e=>t=>{const n=yl(e),r=at(o=>fe(o.src)(n)&&fe(o.tgt)(n),t);if(e.length<40)return ha(e)(Ja(e)(r));const i=vl(e)(r);return ha(e)(Tl(i.removed)(Ja(i.coreNodes)(i.coreEdges)))},Al=e=>t=>n=>{const r=y(o=>u=>Tt(k)(Zt)(u.tgt)(1)(o))($)(t),i=y(o=>u=>Tt(k)(Zt)(u.src)(1)(o))($)(t);return y(o=>u=>{const s=Vt(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();if((()=>{const J=Vt(u)(i);return(()=>{if(J.tag==="Nothing")return a!==0;if(J.tag==="Just")return a!==J._1;c()})()||a===0})())return o;const f=Vt(u)(o.layers),g=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;c()})(),d=o.layers,l=y(J=>v=>v.tgt===u?{...J,mIn:Rr(J.mIn)((()=>{const w=Vt(u)(d),L=Vt(v.src)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;c()})()|0})())}:v.src===u?{...J,mOut:Rr(J.mOut)((()=>{const w=Vt(v.tgt)(d),L=Vt(u)(d);return(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})()-(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;c()})()|0})())}:J)({mIn:1e9,mOut:1e9})(t),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return o;const p=(g-_|0)+1|0,m=(g+h|0)-1|0;if(m<p)return o;const N=y(J=>v=>{const w=Un(v)(o.filling),L=(()=>{if(w.tag==="Nothing")return 0;if(w.tag==="Just")return w._1;c()})();return L<J.bestFill?{best:v,bestFill:L}:J})({best:g,bestFill:(()=>{const J=Un(g)(o.filling);if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;c()})()})(qt(p,m));return N.best===g?o:{layers:Z(k)(u)(N.best)(o.layers),filling:Z(ot)(g)((()=>{const J=Un(g)(o.filling);if(J.tag==="Nothing")return-1;if(J.tag==="Just")return J._1-1|0;c()})())(Z(ot)(N.best)(N.bestFill+1|0)(o.filling))}})({layers:n,filling:Jl(V(o=>x(o,y(u=>s=>(()=>{const a=Vt(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===o})()?u+1|0:u)(0)(e)))(qt(0,y(o=>u=>Oi(o)((()=>{const s=Vt(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(0)(e))))})(e).layers},zl=e=>t=>Al(e)(Dt(n=>r=>({src:r.src,tgt:r.tgt,delta:1,weight:1,eid:n}))(t))(y(Nl)($)(xl(V(n=>Wl(n)(t))(Sl(e)(t))))),Bl=e=>e,kn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},xo=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Na=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),$l=Bl("NetworkSimplex"),Ql=e=>t=>y(n=>r=>{const i=y(xo)(0)(Pt(o=>kn(o)(n))(r));return y(o=>u=>Z(k)(u)(i)(o))(n)(r)})(t)(e),ql=e=>t=>({layers:V(n=>at(r=>{const i=kn(r)(t);return i.tag==="Nothing"?!1:i.tag==="Just"&&i._1===n},e))(qt(0,(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(f.tag==="Nil"){u=!1,s=a;continue}if(f.tag==="Cons"){i=xo(a)(f._1),o=f._2;continue}c()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._4,n(r._6,i)));c()};return n(t,Qt)})()))),nodeLayer:t}),Hl=e=>t=>n=>{const r=y(i=>o=>Z(k)(o)(!0)(i))($)(t);return y(i=>o=>Z(k)(o._1)(o._2)(i))(zl(t)(Pt(i=>i.from.node===i.to.node||(()=>{const o=kn(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;c()})()||(()=>{const o=kn(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;c()})()?T:E("Just",{src:i.from.node,tgt:i.to.node}))(e)))(Na(n))},Yl=e=>t=>n=>r=>{const i=s=>a=>{const f=kn(a)(s);if(f.tag==="Just")return s;if(f.tag==="Nothing"){const g=at(l=>l!==a,(()=>{const l=kn(a)(e);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;c()})()),d=y(i)(s)(g);return Z(k)(a)(1+y(xo)(0)(Pt(l=>kn(l)(d))(g))|0)(d)}c()},o=y(i)($)(n),u=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=xo(_)(h._1),g=h._2;continue}c()}return l})(1)((()=>{const s=(a,f)=>{if(a.tag==="Leaf")return f;if(a.tag==="Node")return s(a._5,zt("Cons",a._4,s(a._6,f)));c()};return s(o,Qt)})());return y(s=>a=>Z(k)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return $;if(a.tag==="Node")return Ft("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));c()};return s(o)})())(Na(r))},Vl=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(k)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(k)(t._1.node)(0)(e)}return e})($),Ol=y(e=>t=>Tt(k)(se)(t.to.node)([t.from.node])(e))($),Fl=y(e=>t=>Tt(k)(se)(t.from.node)([t.to.node])(e))($),Xl=e=>t=>n=>r=>{const i=Fl(n),o=Ol(n),u=Vl(t);return ql(r)(Ql(Pt(s=>s.tag==="SameLayer"?E("Just",s._1.nodes):T)(t))((()=>{if(e==="LongestPath")return Yl(i)(o)(r)(u);if(e==="NetworkSimplex")return Hl(n)(r)(u);c()})()))},Ul=te(k)(At),Kl=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},xa=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},va=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Ir=te(k)(At),Zl=te(k)(At),Ta=(()=>{const e=V(t=>({start:t.end,end:t.start,direction:t.direction}));return t=>le(e(t))})(),jl=e=>t=>n=>r=>{const i=Ul(V(u=>x(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=Kl(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return V(u=>{if(u.nodes.length<=2){const g=xa(u.edgeId)(i);if(g.tag==="Just"){const d=o(u);return{...g._1,edge:u.edgeId,segments:d?Ta(g._1.segments):g._1.segments,reversed:d}}if(g.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};c()}const s=St(Pt(g=>xa(g)(i))(ye(g=>d=>u.edgeId+":"+g+"->"+d,u.nodes,Gt(1,u.nodes.length,u.nodes))))(g=>g.segments),a=o(u),f=Wi(a?Ta(s):s);return{edge:u.edgeId,segments:f,bends:ye(g=>d=>g.end,f,Gt(1,f.length,f)),bendType:[],jumps:[],reversed:a}})(e)},t0={layers:[],edges:[],chains:[]},e0={nodeGap:3,layerGap:2,iterations:8,layerer:$l,cycleBreaker:cl},n0=e=>({pos:x(0,0),size:x(y(t=>n=>va(t)(n.position._1+n.size._1))(0)(e),y(t=>n=>va(t)(n.position._2+n.size._2))(0)(e))}),r0=e=>t=>{const n=at(o=>ie(3)(o.node)!=="$d:",t.placements),r=jl(t.withDummies.chains)(t.acyclic.reversedEdges)(Zl(V(o=>x(o.id,x(o.from.node,o.to.node)))(e.edges)))(pd(t.withDummies.edges)(t.placements)(Ir(V(o=>x(o.id,o.ports))(e.nodes)))(t.withDummies.chains)(Xs(t.ordered)(at(o=>o.from.node!==o.to.node,t.withDummies.edges))((()=>{const o=u=>{if(u.tag==="Leaf")return $;if(u.tag==="Node")return Ft("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),o(u._5),o(u._6));c()};return o(Ir(V(u=>x(u.id,u.size))(e.nodes)))})()))),i=Dt(o=>u=>({...u,jumps:Td(o)(u)(r)}))(r);return{nodes:n,edges:i,boundingBox:n0(n),metrics:W1(n)(i)(0)}},o0=e=>t=>n=>{const r=Ir(V(o=>x(o.id,o.size))(t.nodes)),i={...n,placements:Fd({nodeGap:e.nodeGap,layerGap:e.layerGap})(t.constraints)(n.ordered)(r)(Ir(V(o=>x(o.id,o.ports))(t.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Xs(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return $;if(u.tag==="Node")return Ft("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),o(u._5),o(u._6));c()};return o(r)})()))};return{pipeline:i,result:r0(t)(i)}},i0=e=>t=>n=>o0(e)(t)({...n,ordered:il({iterations:e.iterations,constraints:t.constraints,modelOrder:Ir(Dt(r=>i=>x(i.id,r))(t.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),u0=e=>t=>n=>i0(e)(t)({...n,withDummies:pl(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),s0=e=>t=>{const n=V(i=>i.id)(t.nodes),r=hl(e.cycleBreaker)(n)(t.constraints)(t.edges);return u0(e)(t)({acyclic:r,layered:Xl(e.layerer)(t.constraints)(r.edges)(n),withDummies:t0,ordered:[],placements:[]})},a0=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},c0=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},wa=te(k)(At),f0=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},g0=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},_0=y(e=>t=>Z(k)(t)()(e))($),d0=y(e=>t=>Z(k)(t)()(e))($),l0=qr.traverse(bu),Ui=te(k)(At),h0=e=>t=>n=>{const r=ge(i=>i.id===n)(e.graph.edges);if(r.tag==="Just")return E("Just",r._1);if(r.tag==="Nothing")return a0(n)(t);c()},p0=e=>t=>n=>({x:n.position._1*e,y:n.position._2*e,w:n.size._1*e,h:n.size._2*e,label:(()=>{const r=c0(n.node)(t);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return n.node;c()})()}),m0=e=>({id:e,size:x(1,1),ports:[],label:E("Just",e)}),y0=e=>t=>n=>x(n.node,p0(e)(t)(n)),J0=e=>wa(Pt(t=>E("Just",x(t.edge,{id:t.edge,from:{node:t.from,port:T},to:{node:t.to,port:T}})))(St(e.scenes)(t=>t.tag==="DataFlow"?Pt(n=>n.kind.tag==="SendToken"?E("Just",n.kind._1):T)(t._1.events):[]))),ba=e=>{const t=Ag(e),n=at(i=>f0(i.id)(t.nodes),e.graph.nodes),r=at(i=>g0(i.id)(t.edges),e.graph.edges);return{nodes:[...n,...V(m0)(bt(ke.foldr,Xe(k.compare,t.nodes,_0(V(i=>i.id)(n)))))],edges:[...r,...Pt(h0(e)(J0(e)))(bt(ke.foldr,Xe(k.compare,t.edges,d0(V(i=>i.id)(r)))))],constraints:e.graph.constraints}},N0=e=>{const t=l0(n=>{const r=L1("Ilisarniq, ui-sans-serif, system-ui, sans-serif")(11)("500")(so((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})()));return()=>{const i=r();return x(n.id,i)}})(ba(e).nodes);return()=>{const n=t();return Ui(n)}},x0=e=>t=>{const n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),t.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*e,y:n._1.head.start._2*e},...V(r=>({x:r.end._1*e,y:r.end._2*e}))([n._1.head,...n._1.tail])];c()},v0=e=>t=>x(t.edge,x0(e)(t)),T0=e=>t=>n=>({nodes:Ui(V(y0(ct(4)*e)(t))(n.nodes)),edges:wa(V(v0(e))(n.edges)),chipExtras:$}),w0=ct(4)*8,b0=e=>t=>{const n=D1(w0)(e)(I1(R1)(ba(t)));return T0(8)(Ui(V(r=>x(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;c()})()))(n.nodes)))(s0(e0)(n).result)},ka=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},k0=e=>t=>n=>{const r=e<.05?e:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=ka(s._3)(n),f=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};c()})(),g=f.vx+(180*(s._4.x-f.x)-22*f.vx)*r,d=f.vy+(180*(s._4.y-f.y)-22*f.vy)*r;return Z(k)(s._3)({x:f.x+g*r,y:f.y+d*r,vx:g,vy:d})(i(u,s._5))})(),s._6);c()},o=i($,t);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const f=u(s,a._5),g=ka(a._3)(o);if(g.tag==="Just")return Z(k)(a._3)({...a._4,x:g._1.x,y:g._1.y})(f);if(g.tag==="Nothing")return Z(k)(a._3)(a._4)(f);c()})(),a._6);c()};return u($,t)})()}};(function(){var e={},t="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",f="Sequential",g="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",N="Finalized",J="Forked";function v(G,Y,X,H){this.tag=G,this._1=Y,this._2=X,this._3=H}function w(G){var Y=function(X,H,Q){return new v(G,X,H,Q)};return Y.tag=G,Y}function L(G){return new v(t,void 0)}function b(G){try{G()}catch(Y){setTimeout(function(){throw Y},0)}}function S(G,Y,X){try{return Y(X())}catch(H){return G(H)}}function A(G,Y,X){try{return Y(X)()}catch(H){return X(G(H))(),L}}var O=(function(){var G=1024,Y=0,X=0,H=new Array(G),Q=!1;function W(){var U;for(Q=!0;Y!==0;)Y--,U=H[X],H[X]=void 0,X=(X+1)%G,U();Q=!1}return{isDraining:function(){return Q},enqueue:function(U){var F;Y===G&&(F=Q,W(),Q=F),H[(X+Y)%G]=U,Y++,Q||W()}}})();function j(G){var Y={},X=0,H=0;return{register:function(Q){var W=X++;Q.onComplete({rethrow:!0,handler:function(U){return function(){H--,delete Y[W]}}})(),Y[W]=Q,H++},isEmpty:function(){return H===0},killAll:function(Q,W){return function(){if(H===0)return W();var U=0,F={};function _t(ft){F[ft]=Y[ft].kill(Q,function(ht){return function(){delete F[ft],U--,G.isLeft(ht)&&G.fromLeft(ht)&&setTimeout(function(){throw G.fromLeft(ht)},0),U===0&&W()}})()}for(var pt in Y)Y.hasOwnProperty(pt)&&(U++,_t(pt));return Y={},X=0,H=0,function(ft){return new v(i,function(){for(var ht in F)F.hasOwnProperty(ht)&&F[ht]()})}}}}}var R=0,P=1,et=2,K=3,B=4,q=5,M=6;function C(G,Y,X){var H=0,Q=R,W=X,U=null,F=null,_t=null,pt=null,ft=null,ht=0,wt=0,It=null,dt=!0;function Mt(nt){for(var st,yt,Jt;;)switch(st=null,yt=null,Jt=null,Q){case et:Q=P;try{W=_t(W),pt===null?_t=null:(_t=pt._1,pt=pt._2)}catch($t){Q=q,U=G.left($t),W=null}break;case K:G.isLeft(W)?(Q=q,U=W,W=null):_t===null?Q=q:(Q=et,W=G.fromRight(W));break;case P:switch(W.tag){case u:_t&&(pt=new v(_,_t,pt)),_t=W._2,Q=P,W=W._1;break;case t:_t===null?(Q=q,W=G.right(W._1)):(Q=et,W=W._1);break;case i:Q=K,W=S(G.left,G.right,W._1);break;case o:Q=B,W=A(G.left,W._1,function($t){return function(){H===nt&&(H++,O.enqueue(function(){H===nt+1&&(Q=K,W=$t,Mt(H))}))}});return;case n:Q=q,U=G.left(W._1),W=null;break;case r:_t===null?ft=new v(_,W,ft,F):ft=new v(_,W,new v(_,new v(h,_t,pt),ft,F),F),_t=null,pt=null,Q=P,W=W._1;break;case s:ht++,_t===null?ft=new v(_,W,ft,F):ft=new v(_,W,new v(_,new v(h,_t,pt),ft,F),F),_t=null,pt=null,Q=P,W=W._1;break;case a:Q=K,st=C(G,Y,W._2),Y&&Y.register(st),W._1&&st.run(),W=G.right(st);break;case f:Q=P,W=D(G,Y,W._1);break}break;case q:if(_t=null,pt=null,ft===null)Q=M,W=F||U||W;else switch(st=ft._3,Jt=ft._1,ft=ft._2,Jt.tag){case r:F&&F!==st&&ht===0?Q=q:U&&(Q=P,W=Jt._2(G.fromLeft(U)),U=null);break;case h:F&&F!==st&&ht===0||U?Q=q:(_t=Jt._1,pt=Jt._2,Q=et,W=G.fromRight(W));break;case s:ht--,U===null&&(yt=G.fromRight(W),ft=new v(_,new v(p,Jt._2,yt),ft,st),(F===st||ht>0)&&(Q=P,W=Jt._3(yt)));break;case p:ft=new v(_,new v(N,W,U),ft,F),Q=P,F&&F!==st&&ht===0?W=Jt._1.killed(G.fromLeft(F))(Jt._2):U?W=Jt._1.failed(G.fromLeft(U))(Jt._2):W=Jt._1.completed(G.fromRight(W))(Jt._2),U=null,ht++;break;case m:ht++,ft=new v(_,new v(N,W,U),ft,F),Q=P,W=Jt._1;break;case N:ht--,Q=q,W=Jt._1,U=Jt._2;break}break;case M:for(var Ct in It)It.hasOwnProperty(Ct)&&(dt=dt&&It[Ct].rethrow,b(It[Ct].handler(W)));It=null,F&&U?setTimeout(function(){throw G.fromLeft(U)},0):G.isLeft(W)&&dt&&setTimeout(function(){if(dt)throw G.fromLeft(W)},0);return;case R:Q=P;break;case B:return}}function mt(nt){return function(){if(Q===M)return dt=dt&&nt.rethrow,nt.handler(W)(),function(){};var st=wt++;return It=It||{},It[st]=nt,function(){It!==null&&delete It[st]}}}function gt(nt,st){return function(){if(Q===M)return st(G.right(void 0))(),function(){};var yt=mt({rethrow:!1,handler:function(){return st(G.right(void 0))}})();switch(Q){case R:F=G.left(nt),Q=M,W=F,Mt(H);break;case B:F===null&&(F=G.left(nt)),ht===0&&(Q===B&&(ft=new v(_,new v(m,W(nt)),ft,F)),Q=q,W=null,U=null,Mt(++H));break;default:F===null&&(F=G.left(nt)),ht===0&&(Q=q,W=null,U=null)}return yt}}function rt(nt){return function(){var st=mt({rethrow:!1,handler:nt})();return Q===R&&Mt(H),st}}return{kill:gt,join:rt,onComplete:mt,isSuspended:function(){return Q===R},run:function(){Q===R&&(O.isDraining()?Mt(H):O.enqueue(function(){Mt(H)}))}}}function I(G,Y,X,H){var Q=0,W={},U=0,F={},_t=new Error("[ParAff] Early exit"),pt=null,ft=e;function ht(mt,gt,rt){var nt=gt,st=null,yt=null,Jt=0,Ct={},$t,re;t:for(;;)switch($t=null,nt.tag){case J:if(nt._3===e&&($t=W[nt._1],Ct[Jt++]=$t.kill(mt,function(Ve){return function(){Jt--,Jt===0&&rt(Ve)()}})),st===null)break t;nt=st._2,yt===null?st=null:(st=yt._1,yt=yt._2);break;case g:nt=nt._2;break;case d:case l:st&&(yt=new v(_,st,yt)),st=nt,nt=nt._1;break}if(Jt===0)rt(G.right(void 0))();else for(re=0,$t=Jt;re<$t;re++)Ct[re]=Ct[re]();return Ct}function wt(mt,gt,rt){var nt,st,yt,Jt,Ct,$t;for(G.isLeft(mt)?(nt=mt,st=null):(st=mt,nt=null);;){if(yt=null,Jt=null,Ct=null,$t=null,pt!==null)return;if(gt===null){H(nt||st)();return}if(gt._3!==e)return;switch(gt.tag){case g:nt===null?(gt._3=G.right(gt._1(G.fromRight(st))),st=gt._3):gt._3=nt;break;case d:if(yt=gt._1._3,Jt=gt._2._3,nt){if(gt._3=nt,Ct=!0,$t=U++,F[$t]=ht(_t,nt===yt?gt._2:gt._1,function(){return function(){delete F[$t],Ct?Ct=!1:rt===null?wt(nt,null,null):wt(nt,rt._1,rt._2)}}),Ct){Ct=!1;return}}else{if(yt===e||Jt===e)return;st=G.right(G.fromRight(yt)(G.fromRight(Jt))),gt._3=st}break;case l:if(yt=gt._1._3,Jt=gt._2._3,yt===e&&G.isLeft(Jt)||Jt===e&&G.isLeft(yt))return;if(yt!==e&&G.isLeft(yt)&&Jt!==e&&G.isLeft(Jt))nt=st===yt?Jt:yt,st=null,gt._3=nt;else if(gt._3=st,Ct=!0,$t=U++,F[$t]=ht(_t,st===yt?gt._2:gt._1,function(){return function(){delete F[$t],Ct?Ct=!1:rt===null?wt(st,null,null):wt(st,rt._1,rt._2)}}),Ct){Ct=!1;return}break}rt===null?gt=null:(gt=rt._1,rt=rt._2)}}function It(mt){return function(gt){return function(){delete W[mt._1],mt._3=gt,wt(gt,mt._2._1,mt._2._2)}}}function dt(){var mt=P,gt=X,rt=null,nt=null,st,yt;t:for(;;)switch(st=null,yt=null,mt){case P:switch(gt.tag){case g:rt&&(nt=new v(_,rt,nt)),rt=new v(g,gt._1,e,e),gt=gt._2;break;case d:rt&&(nt=new v(_,rt,nt)),rt=new v(d,e,gt._2,e),gt=gt._1;break;case l:rt&&(nt=new v(_,rt,nt)),rt=new v(l,e,gt._2,e),gt=gt._1;break;default:yt=Q++,mt=q,st=gt,gt=new v(J,yt,new v(_,rt,nt),e),st=C(G,Y,st),st.onComplete({rethrow:!1,handler:It(gt)})(),W[yt]=st,Y&&Y.register(st)}break;case q:if(rt===null)break t;rt._1===e?(rt._1=gt,mt=P,gt=rt._2,rt._2=e):(rt._2=gt,gt=rt,nt===null?rt=null:(rt=nt._1,nt=nt._2))}for(ft=gt,yt=0;yt<Q;yt++)W[yt].run()}function Mt(mt,gt){pt=G.left(mt);var rt;for(var nt in F)if(F.hasOwnProperty(nt)){rt=F[nt];for(nt in rt)rt.hasOwnProperty(nt)&&rt[nt]()}F=null;var st=ht(mt,ft,gt);return function(yt){return new v(o,function(Jt){return function(){for(var Ct in st)st.hasOwnProperty(Ct)&&st[Ct]();return L}})}}return dt(),function(mt){return new v(o,function(gt){return function(){return Mt(mt,gt)}})}}function D(G,Y,X){return new v(o,function(H){return function(){return I(G,Y,X,H)}})}return v.EMPTY=e,v.Pure=w(t),v.Throw=w(n),v.Catch=w(r),v.Sync=w(i),v.Async=w(o),v.Bind=w(u),v.Bracket=w(s),v.Fork=w(a),v.Seq=w(f),v.ParMap=w(g),v.ParApply=w(d),v.ParAlt=w(l),v.Fiber=C,v.Supervisor=j,v.Scheduler=O,v.nonCanceler=L,v})();let Ki=null;function L0(){return Ki||(typeof document>"u"?null:(Ki=document.createElement("canvas").getContext("2d"),Ki))}const La=new Map,Ea=e=>t=>n=>r=>{const i=`${n} ${t}px ${e}|${r}`,o=La.get(i);if(o!==void 0)return o;const u=L0();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return La.set(i,s),s},E0=e=>()=>e.clip("evenodd"),C0=e=>t=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(t.tile,.001))),r=Math.max(2,Math.round(t.tile*n)),i=document.createElement("canvas");i.width=r,i.height=r;const o=i.getContext("2d");o.scale(n,n),o.fillStyle=t.bgCss,o.fillRect(0,0,t.tile,t.tile),o.fillStyle=t.dotCss,o.beginPath(),o.arc(t.tile/2,t.tile/2,t.dotR,0,2*Math.PI),o.fill();const u=e.createPattern(i,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().scaleSelf(1/n,1/n)),e.save(),e.fillStyle=u,e.fillRect(t.vx,t.vy,t.vw,t.vh),e.restore()},S0=e=>t=>n=>r=>i=>o=>()=>{if(typeof e.roundRect=="function")e.roundRect(t,n,r,i,o);else{const u=Math.min(o,r/2,i/2);e.moveTo(t+u,n),e.lineTo(t+r-u,n),e.quadraticCurveTo(t+r,n,t+r,n+u),e.lineTo(t+r,n+i-u),e.quadraticCurveTo(t+r,n+i,t+r-u,n+i),e.lineTo(t+u,n+i),e.quadraticCurveTo(t,n+i,t,n+i-u),e.lineTo(t,n+u),e.quadraticCurveTo(t,n,t+u,n),e.closePath()}},P0=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Zi=e=>t=>n=>{const r=t.stroke;return()=>{const i=r.value,o=Hf(e)(n);if(i!==n)return o(),t.stroke.value=n}},R0=e=>t=>n=>{const r=t.font;return()=>{const i=r.value,o=eg(e)(n);if(i!==n)return o(),t.font.value=n}},Dr=e=>t=>n=>{const r=t.fill;return()=>{const i=r.value,o=qf(e)(n);if(i!==n)return o(),t.fill.value=n}},vo=e=>t=>{const n=t.length,r=o=>{if(o>=n)return()=>{};const u=o>=0&&o<t.length?t[o]:0;if(u===1){const s=Xf(e)((()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})())((()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===2){const s=Ff(e)((()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})())((()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===3){const s=rg(e)({cpx:(()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})(),cpy:(()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})(),x:(()=>{const f=o+3|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=o+4|0;return f>=0&&f<t.length?t[f]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=og(e)({cp1x:(()=>{const f=o+1|0;return f>=0&&f<t.length?t[f]:0})(),cp1y:(()=>{const f=o+2|0;return f>=0&&f<t.length?t[f]:0})(),cp2x:(()=>{const f=o+3|0;return f>=0&&f<t.length?t[f]:0})(),cp2y:(()=>{const f=o+4|0;return f>=0&&f<t.length?t[f]:0})(),x:(()=>{const f=o+5|0;return f>=0&&f<t.length?t[f]:0})(),y:(()=>{const f=o+6|0;return f>=0&&f<t.length?t[f]:0})()}),a=r(o+7|0);return()=>(s(),a())}if(u===5){const s=Uf(e),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=Qu(e);return()=>(i(),r(0)())},I0=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),D0=e=>t=>{const n=Zf(e)({x:0,y:0,width:t.width,height:t.height});return()=>{n();const r=I0();return{ctx:e,surface:t,styleCache:r,maskDepth:{value:0}}}},G0={map:e=>t=>n=>{const r=t(n);return()=>{const i=r();return e(i)}}},M0=e=>ue(e.weight)+" "+xu(e.size)+"px Ilisarniq, ui-sans-serif, system-ui, sans-serif",qe=e=>{const t=xu(ct(e.a)/255);return e.a>=255?"rgb("+ue(e.r)+","+ue(e.g)+","+ue(e.b)+")":"rgba("+ue(e.r)+","+ue(e.g)+","+ue(e.b)+","+t+")"},W0=e=>t=>n=>r=>{const i=Dr(e)(n)(qe(r));return()=>(i(),Kf(e)({x:0,y:0,width:t.width,height:t.height})())},A0=e=>t=>n=>{const r=t.font;return()=>(r.value="",t.fill.value="",t.stroke.value="",C0(e)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:qe(n.bgColor),dotCss:qe(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},z0=e=>t=>n=>r=>{const i=Dr(e)(t)(qe(r));return()=>(i(),vo(e)(n)(),jo(e)())},B0=e=>t=>n=>r=>i=>{const o=Dr(e)(t)(qe(r));return()=>(o(),Zi(e)(t)(qe(i.color))(),Xo(e)(i.width)(),Fr(e)((()=>{if(i.lineJoin==="RoundJoin")return Or;if(i.lineJoin==="BevelJoin")return oi;if(i.lineJoin==="MiterJoin")return ii;c()})())(),ci(e)((()=>{if(i.lineCap==="ButtCap")return ai;if(i.lineCap==="RoundCap")return ui;if(i.lineCap==="SquareCap")return si;c()})())(),vo(e)(n)(),jo(e)(),Zo(e)())},$0=e=>t=>n=>r=>i=>o=>{const u=Qu(e);return()=>{if(u(),S0(e)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(Dr(e)(t)(qe(i._1.color))(),jo(e)()):i.tag==="Nothing"||c(),o.tag==="Just")return Zi(e)(t)(qe(o._1.color))(),Xo(e)(o._1.width)(),Fr(e)((()=>{if(o._1.lineJoin==="RoundJoin")return Or;if(o._1.lineJoin==="BevelJoin")return oi;if(o._1.lineJoin==="MiterJoin")return ii;c()})())(),ci(e)((()=>{if(o._1.lineCap==="ButtCap")return ai;if(o._1.lineCap==="RoundCap")return ui;if(o._1.lineCap==="SquareCap")return si;c()})())(),Zo(e)();o.tag!=="Nothing"&&c()}},Q0=e=>t=>n=>r=>{const i=Zi(e)(t)(qe(r.color));return()=>(i(),Xo(e)(r.width)(),Fr(e)((()=>{if(r.lineJoin==="RoundJoin")return Or;if(r.lineJoin==="BevelJoin")return oi;if(r.lineJoin==="MiterJoin")return ii;c()})())(),ci(e)((()=>{if(r.lineCap==="ButtCap")return ai;if(r.lineCap==="RoundCap")return ui;if(r.lineCap==="SquareCap")return si;c()})())(),vo(e)(n)(),Zo(e)())},q0=e=>t=>n=>{const r=Dr(e)(t)(qe(n.color));return()=>(r(),R0(e)(t)(M0(n.font))(),hg(e)((()=>{if(n.align==="AlignLeft")return cg;if(n.align==="AlignCenter")return gg;if(n.align==="AlignRight")return fg;c()})())(),lg(e)((()=>{if(n.baseline==="BaselineTop")return ig;if(n.baseline==="BaselineMiddle")return ug;if(n.baseline==="BaselineAlphabetic")return sg;if(n.baseline==="BaselineBottom")return ag;c()})())(),ng(e)(n.content)(n.x)(n.y)())},Ca={apply:e=>t=>n=>{const r=e(n),i=t(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>G0},H0={bind:e=>t=>n=>{const r=e(n);return()=>{const i=r();return t(i)(n)()}},Apply0:()=>Ca},Y0=e=>t=>n=>{const r=P0(t.width/n.vw)(t.height/n.vh),i=qu(e)({translateX:(t.width-n.vw*r)/2-n.vx*r,translateY:(t.height-n.vh*r)/2-n.vy*r});return()=>(i(),ti(e)({scaleX:r,scaleY:r})(),Fr(e)(Or)())},V0={pure:e=>t=>()=>e,Apply0:()=>Ca},O0={Applicative0:()=>V0,Bind1:()=>H0},Sa={fillPath:e=>t=>n=>{const r=z0(n.ctx)(n.styleCache)(e)(t.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:e=>t=>n=>{const r=Q0(n.ctx)(n.styleCache)(e)(t),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:e=>t=>n=>r=>{const i=B0(r.ctx)(r.styleCache)(e)(t.color)(n),o=r.maskDepth;return()=>{if(o.value===0)return i()}},drawRoundedRect:e=>t=>n=>r=>i=>{const o=$0(i.ctx)(i.styleCache)(e)(t)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:e=>t=>{const n=q0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},pushTransform:e=>t=>{const n=dr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",qu(t.ctx)({translateX:e.tx,translateY:e.ty})(),ti(t.ctx)({scaleX:e.sx,scaleY:e.sy})()}},popTransform:e=>{const t=lr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushClip:e=>t=>n=>{const r=dr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",vo(n.ctx)(e)(),t==="NonZero")return Of(n.ctx)();if(t==="EvenOdd")return E0(n.ctx)();c()}}},popClip:e=>{const t=lr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushBlend:e=>t=>{const n=dr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0){if(n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",e==="Normal")return Yu(t.ctx)(_g)();if(e==="Difference")return Yu(t.ctx)(dg)();c()}}},popBlend:e=>{const t=lr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushAlpha:e=>t=>{const n=dr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",Vf(t.ctx)(e)()}},popAlpha:e=>{const t=lr(e.ctx),n=e.maskDepth;return()=>{if(n.value===0)return t(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value=""}},pushLayer:e=>t=>{if(e==="LayerNodeMask"){const n=t.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:e=>{const t=e.maskDepth;return()=>{const n=t.value,r=n-1|0;if(n>0)return e.maskDepth.value=r}},setViewport:e=>t=>{const n=Y0(t.ctx)(t.surface)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:e=>t=>{const n=W0(t.ctx)(t.surface)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:e=>t=>{const n=A0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},measureText:e=>t=>n=>{const r=Ea(e.family)(e.size)(e.weight)(so(t));return()=>r},Monad0:()=>O0};function F0(e,t){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function X0(e){const t=e.length,n=new Array(t);for(let r=0;r<t;r++){const i=e[r],o=e[(r+1)%t];n[r]={a:i,b:o,len:F0(i,o)}}return n}function U0(e,t,n){let r=0;for(let i=0;i<e.length;i++){const o=e[i],u=r,s=u+o.len;if(n<=s){const a=o.len>1e-6?(n-u)/o.len:0;return{x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a}}r=s}return t.length>0?t[t.length-1]:{x:0,y:0}}function Pa(e,t){if(t.length===0)return[];const n=X0(t);let r=0;for(let o=0;o<n.length;o++)r+=n[o].len;const i=new Array(e);for(let o=0;o<e;o++)i[o]=U0(n,t,o*r/e);return i}function K0(e,t){const n=t.length;if(n===0)return t;const r=(e%n+n)%n|0,i=new Array(n);for(let o=0;o<n;o++)i[o]=t[(o+r)%n];return i}function Z0(e,t){const n=t.length;if(n===0)return t;let r=0,i=1/0;for(let o=0;o<n;o++){let u=0;for(let s=0;s<n;s++){const a=e[s]||{x:0,y:0},f=t[(s+o)%n]||{x:0,y:0},g=a.x-f.x,d=a.y-f.y;u+=g*g+d*d}u<i&&(i=u,r=o)}return K0(r,t)}const Ra=e=>t=>n=>{const r=Pa(e,t),i=Pa(e,n),o=Z0(r,i);return{from:r,to:o}};function Ia(e){const t=e.length;if(t===0)return{x:0,y:0};let n=0,r=0;for(let i=0;i<t;i++)n+=e[i].x,r+=e[i].y;return{x:n/t,y:r/t}}function j0(e,t){const n=t.x-e.x,r=t.y-e.y,i=Math.sqrt(n*n+r*r);return i<=1e-4?{x:1,y:0}:{x:n/i,y:r/i}}function th(e,t){const n=t.length;if(n===0)return t;const r=new Array(n);for(let i=0;i<n;i++){const o=t[((i-1)%n+n)%n],u=t[((i+1)%n+n)%n],s=t[i];r[i]={x:s.x+((o.x+u.x)/2-s.x)*e,y:s.y+((o.y+u.y)/2-s.y)*e}}return r}function eh(e){return e<0?0:e>1?1:e}const Da=e=>t=>n=>r=>{const i=t.length;if(i===0)return[];const o=Ia(t),u=Ia(n),s=j0(o,u),a=new Array(i);let f=1/0,g=-1/0;for(let _=0;_<i;_++){const h=t[_],p=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=p,p<f&&(f=p),p>g&&(g=p)}const d=g-f;let l=new Array(i);for(let _=0;_<i;_++){const h=t[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-f)/d),N=Math.max(1e-4,1-m),J=eh((e-m)/N),v=J*J*(3-2*J);l[_]={x:h.x+(p.x-h.x)*v,y:h.y+(p.y-h.y)*v}}for(let _=0;_<r.smoothPasses;_++)l=th(.5,l);return l},nh=e=>e,Ga=e=>e,To=e=>e,Ma=e=>e,rh=e=>e,Wa=e=>e,Aa=e=>e,za=Aa("BaselineTop"),Gr=Aa("BaselineMiddle"),wo=Wa("AlignLeft"),ji=Wa("AlignCenter"),He=rh("RoundJoin"),dn=Ma("ButtCap"),Ba=Ma("RoundCap"),oh=To("LayerPolyOut"),ih=To("LayerPolyIn"),uh=To("LayerNodeMask"),sh=To("LayerOverlay"),$a=Ga("NonZero"),ah=Ga("EvenOdd"),ch=nh("Difference"),Kn={r:255,g:255,b:255,a:255},Ze={r:26,g:26,b:26,a:255},tu=(e,t,n)=>({tag:e,_1:t,_2:n}),je=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Mr=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Qa=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Ln=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},Ee=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},tn=(()=>{const e=Ie.unfoldr(yn);return t=>e(De("IterNode",t,mn))})(),eu=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},qa=te(k)(At),Ha=y(cr)(0),bo=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},Ya=e=>{const t=e.Monad0().Bind1(),n=e.popTransform,r=e.popAlpha;return i=>o=>u=>s=>a=>t.bind(e.pushAlpha(i.fadeAlpha))(()=>t.bind(e.pushTransform({tx:o*(1-i.popScale),ty:u*(1-i.popScale),sx:i.popScale,sy:i.popScale}))(()=>t.bind(e.pushTransform({tx:0,ty:s.y*(1-i.flipY),sx:1,sy:i.flipY}))(()=>t.bind(a)(()=>t.bind(n)(()=>t.bind(n)(()=>r))))))},en=e=>{const t=e.Apply0();return n=>y(r=>i=>t.apply(t.Functor0().map(o=>Nu)(r))(n(i)))(e.pure())},fh=e=>({x:e.x,y:e.y,w:e.w,h:e.h}),gh=y(e=>t=>e+t.len)(0),_h=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return[];if(t.tag==="Just")return[1,t._1.head.x,t._1.head.y,...St(Gt(1,e.length,e))(n=>[2,n.x,n.y]),5];c()},dh=e=>t=>{const n=e.y+e.h-6,r=e.y+6,i=e.x+14,o=e.x+e.w-14,u=y(Mr)(0)(V(s=>i-10<s.x+s.w+12&&o+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?je((s.x+s.w+12-(i-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(t));return{...e,x:e.x+u*.7071067811865476,y:e.y-u*.7071067811865476}},lh={r:26,g:26,b:26,a:255},hh={r:214,g:211,b:209,a:255},Va=e=>t=>{const n=je(t)(je(e.w/2)(e.h/2));return[1,e.x+n,e.y,2,e.x+e.w-n,e.y,3,e.x+e.w,e.y,e.x+e.w,e.y+n,2,e.x+e.w,e.y+e.h-n,3,e.x+e.w,e.y+e.h,e.x+e.w-n,e.y+e.h,2,e.x+n,e.y+e.h,3,e.x,e.y+e.h,e.x,e.y+e.h-n,2,e.x,e.y+n,3,e.x,e.y,e.x+n,e.y,5]},ph=e=>t=>n=>y(r=>i=>{const o=Qa(i)(t);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=dh(o._1)(r.obstacles);return{acc:Z(k)(i)(u)(r.acc),obstacles:de(r.obstacles)(u)}}c()})({acc:$,obstacles:n})(e).acc,mh=e=>{const t=Ht(n=>T,n=>r=>E("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return[];if(t.tag==="Just")return[1,t._1.head.x,t._1.head.y,...St(t._1.tail)(n=>[2,n.x,n.y])];c()},ko=e=>{if(e.tag==="Hidden")return{alpha:0,scale:0};if(e.tag==="Visible")return{alpha:1,scale:1};if(e.tag==="PloppingIn")return{alpha:e._1>0?1:0,scale:hr(8)(.6)(Ln(0)(1)(e._1))};if(e.tag==="PloppingOut")return{alpha:e._1<1?1:0,scale:hr(8)(.6)(Ln(0)(1)(1-e._1))};c()},Oa=e=>t=>St(tn(e.nodes))(n=>{const r=Ee(n._1)(t.nodes);return r.tag==="Just"&&ko(r._1).alpha>0?Va(n._2)(7):[]}),yh=e=>t=>n=>[1,e.vx,e.vy,2,e.vx+e.vw,e.vy,2,e.vx+e.vw,e.vy+e.vh,2,e.vx,e.vy+e.vh,5,...Oa(t)(n)],Lo=e=>t=>n=>V(r=>{const i=ct(r)/ct(n);return{x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i}})(qt(0,n-1|0)),Jh=e=>t=>{const n=i=>(i.x-t.x)*(i.x-t.x)+(i.y-t.y)*(i.y-t.y),r=y(i=>o=>n(o)<n(i)?o:i)({x:e.x,y:e.y})([{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x,y:e.y+e.h},{x:e.x+e.w,y:e.y+e.h}]);return V(i=>{const o=ct(i)/5;return{x:r.x+(t.x-r.x)*o,y:r.y+(t.y-r.y)*o}})([1,2,3,4])},Fa=e=>{const t=vi(`
|
|
6
|
-
`)(
|
|
7
|
-
`)(a.label===""?s:a.label),d=g.length===0?[""]:g,l=a.y+a.h/2-ct(d.length)*13.2/2+6.6,_=ko(f),h=a.x+a.w/2,p=a.y+a.h/2,m=r.bind(e.pushAlpha(_.alpha))(()=>r.bind(e.pushTransform({tx:h*(1-_.scale),ty:p*(1-_.scale),sx:_.scale,sy:_.scale}))(()=>r.bind(e.drawRoundedRect({x:a.x,y:a.y,w:a.w,h:a.h})(7)(E("Just",{color:Kn,flat:!1}))(E("Just",{color:Ze,width:1.25,lineJoin:He,lineCap:dn})))(()=>r.bind(i(N=>e.drawText({x:a.x+a.w/2,y:l+ct(N._1)*13.2,content:N._2,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},color:Ze,align:ji,baseline:Gr}))(Dt(In)(d)))(()=>r.bind(o)(()=>u)))));return _.alpha>0?m:n.pure()}},Xa=e=>{const t=Nh(e),n=e.Monad0().Applicative0(),r=en(n);return i=>o=>r(u=>{const s=Ee(u._1)(o.nodes);if(s.tag==="Just")return t(u._1)(u._2)(s._1);if(s.tag==="Nothing")return n.pure();c()})(tn(i.nodes))},ru=e=>t=>{const n=t.y-e.y,r=t.x-e.x;return Wn(r*r+n*n)},xh=e=>ye(t=>n=>({a:t,b:n,len:ru(t)(n)}),e,Gt(1,e.length,e)),vh=e=>t=>{const n=t.length-1|0,r=n>=0&&n<t.length?E("Just",t[n]):T,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];c()})(),o=0<t.length?E("Just",t[0]):T,u=(()=>{if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return{x:0,y:0};c()})(),s=t.length;return s<3?t:[u,...St(qt(1,s-2|0))(a=>{const f=a+1|0,g=f>=0&&f<t.length?E("Just",t[f]):T,d=a>=0&&a<t.length?E("Just",t[a]):T,l=a-1|0,_=l>=0&&l<t.length?E("Just",t[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&g.tag==="Just"){const h=d._1,p=ru(h)(g._1),m=ru(_._1)(h),N=je(e)(p/2),J=je(e)(m/2),v=p>0?N/p:0,w=h.x+(g._1.x-h.x)*v,L=h.y+(g._1.y-h.y)*v,b=m>0?J/m:0,S=h.x+(_._1.x-h.x)*b,A=h.y+(_._1.y-h.y)*b;return V(O=>{const j=ct(O)/ct(10),R=1-j;return{x:R*R*S+2*R*j*h.x+j*j*w,y:R*R*A+2*R*j*h.y+j*j*L}})(qt(0,10))}return[]}),...i]},Th=e=>{const t=e.Monad0(),n=t.Bind1(),r=t.Applicative0(),i=en(r);return o=>u=>s=>a=>f=>g=>{const d=wi(g).length,l=ct(d+1|0),_=m=>{const N=(s*l-ct(m))/1.5,J=N<0?0:N>1?1:N;return J*J*(3-2*J)},h=(m=>{let N=m,J=!0,v;for(;J;){const w=N;if(w>=d){J=!1,v=w;continue}if(_(w)>=1){N=w+1|0;continue}J=!1,v=w}return v})(0),p=h>=d?[]:pn(m=>_(m)>0)(qt(h,d-1|0)).init;return n.bind((()=>{const m=e.drawText({x:a,y:f,content:ie(h)(g),font:o,color:u,align:wo,baseline:Gr});return h>0?m:r.pure()})())(()=>i(m=>n.bind(e.measureText(o)(ie(m)(g)))(N=>{const J=_(m);return e.drawText({x:a+N,y:f-(1-J)*10,content:ie(1)(mr(Jn(ie(m)(g)))(g)),font:o,color:{...u,a:ur(Gu(J*ct(u.a)))},align:wo,baseline:Gr})}))(p))}},Eo=e=>t=>n=>r=>{const i=V(h=>ct(eu(1)(wi(h).length)))(r),o=Mr(1)(y(cr)(0)(i)),u=Mr(.05)(1-t-n),s=e<t?0:e>1-n?1:(e-t)/u,a=s*o,f=eu(1)(r.length),g=(h=>p=>m=>{let N=h,J=p,v=m,w=!0,L;for(;w;){const b=N,S=J,A=Ht(O=>T,O=>j=>E("Just",{head:O,tail:j}),v);if(A.tag==="Nothing"){w=!1,L=eu(0)(f-1|0);continue}if(A.tag==="Just"){if(S+A._1.head>=a){w=!1,L=b;continue}N=b+1|0,J=S+A._1.head,v=A._1.tail;continue}c()}return L})(0)(0)(i),d=y(cr)(0)(g<1?[]:Gt(0,g,i)),l=d/o;if(g>=0&&g<i.length){const h=(d+i[g])/o;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(h<=l)return 1;const p=(s-l)/(h-l);return p<0?0:p>1?1:p})()}}const _=(d+1)/o;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(_<=l)return 1;const h=(s-l)/(_-l);return h<0?0:h>1?1:h})()}},wh=e=>{const t=e.Monad0();return n=>r=>i=>t.Bind1().bind(e.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Eo(r)(0)(0)(i).line))(o=>{const u=o+28;return t.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},bh=e=>{const t=e.Monad0(),n=t.Bind1(),r=wh(e),i=t.Applicative0(),o=qr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>qa(Pt(f=>f)(a)))(o(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const f=Ee(a._2._1.node)(u.nodes);if(f.tag==="Just")return n.bind(r(f._1)(a._2._1.progress)(a._2._1.labels))(g=>i.pure(E("Just",x(a._1,g))));if(f.tag==="Nothing")return i.pure(T);c()}return i.pure(T)})(tn(s.tokens)))},Ua=e=>t=>V(n=>{const r=6.283185307179586*ct(n)/ct(64);return{x:e.x+t*Ho(r),y:e.y+t*Vo(r)}})(qt(0,63)),ou=e=>t=>{const n=.5522847498*t;return[1,e.x+t,e.y,4,e.x+t,e.y+n,e.x+n,e.y+t,e.x,e.y+t,4,e.x-n,e.y+t,e.x-t,e.y+n,e.x-t,e.y,4,e.x-t,e.y-n,e.x-n,e.y-t,e.x,e.y-t,4,e.x+n,e.y-t,e.x+t,e.y-n,e.x+t,e.y,5]},kh=e=>{const t=e.Monad0().Bind1(),n=e.popAlpha;return r=>i=>o=>u=>s=>a=>f=>{const g={x:o.x+o.w/2,y:o.y+o.h/2},d=Mr(.05)(1-a-f),l=s<a?0:s>1-f?1:(s-a)/d,_={x:u.x+u.w/2,y:u.y+u.h/2},h=(p,m)=>t.bind(e.pushAlpha(m))(()=>t.bind(e.fillStrokePath(ou(p)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:He,lineCap:dn}))(()=>n));return l<.5?h(g,(()=>{const p=l*2;return 1-(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})()):h(_,(()=>{const p=(l-.5)*2;return(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})())}},Lh={r:255,g:235,b:130,a:255},Eh=e=>{const t=e.length;return t===0?{x:0,y:0}:{x:Ha(V(n=>n.x)(e))/ct(t),y:Ha(V(n=>n.y)(e))/ct(t)}},Ka=e=>t=>n=>{const r=hr(6)(.55)(Ln(0)(1)((1-e)/.06)),i=e>.94,o=i&&n>1e-4,u=hr(6)(.55)(Ln(0)(1)(e/.06)),s=e<.06,a=s&&t>1e-4,f=i&&n<=1e-4;return{popScale:a?u:o?r:1,flipY:s&&t<=1e-4?u:f?r:1,fadeAlpha:(()=>{if(a){const g=e/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}if(o){const g=(1-e)/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}return 1})()}},Ch=e=>{const t=e.Monad0().Bind1(),n=Ya(e);return r=>i=>o=>u=>{const s=Ka(o)(0)(0),a={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},f=Eo(o)(0)(0)(u);return t.bind(e.measureText(a)(f.line))(g=>{const d={r:26,g:26,b:26,a:90},l=i.x+i.w/2,_=g+28,h=i.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,i.y],N={x:l,y:h+12.6};return n(s)(l-_/2)(h+25.2)(N)(t.bind(e.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(E("Just",{color:hh,flat:!0}))(T))(()=>t.bind(e.drawRoundedRect({x:p,y:h,w:_,h:25.2})(6)(E("Just",{color:Lh,flat:!0}))(E("Just",{color:d,width:1,lineJoin:He,lineCap:dn})))(()=>t.bind(e.strokePath(m)({color:d,width:1,lineJoin:He,lineCap:dn}))(()=>e.drawText({x:l,y:N.y,content:f.line,font:a,color:Ze,align:ji,baseline:Gr})))))})}},Za={r:0,g:0,b:0,a:0},Sh=e=>t=>e.backgroundDots({viewport:{vx:t.x,vy:t.y,vw:t.w,vh:t.h},bgColor:Za,dotColor:lh,tile:1.6,dotRadius:.25}),Ph={r:214,g:211,b:209,a:255},ja={r:255,g:255,b:255,a:255},tc=e=>{const t=e.Monad0().Bind1();return n=>r=>n?t.bind(e.clearBackground(Za))(()=>e.setViewport(r)):t.bind(e.setViewport(r))(()=>e.backgroundDots({viewport:r,bgColor:ja,dotColor:Ph,tile:12,dotRadius:.7}))},Rh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=t.Bind1(),i=e.popClip,o=e.popTransform,u=e.popAlpha;return s=>a=>f=>{const g=ko(f),d={...a,y:a.y+5},l=d.x+d.w/2,_=d.y+d.h/2,h=r.bind(e.pushAlpha(g.alpha))(()=>r.bind(e.pushTransform({tx:l*(1-g.scale),ty:_*(1-g.scale),sx:g.scale,sy:g.scale}))(()=>r.bind(e.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(E("Just",{color:ja,flat:!0}))(T))(()=>r.bind((()=>{const p=r.bind(e.pushClip(Va(d)(7))($a))(()=>r.bind(Sh(e)(d))(()=>i));return s?p:n.pure()})())(()=>r.bind(e.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(T)(E("Just",{color:Ze,width:1.25,lineJoin:He,lineCap:dn})))(()=>r.bind(o)(()=>u))))));return g.alpha>0?h:n.pure()}},ec=e=>{const t=Rh(e),n=e.Monad0().Applicative0(),r=en(n);return i=>o=>u=>r(s=>{const a=Ee(s._1)(u.nodes);if(a.tag==="Just")return t(i)(s._2)(a._1);if(a.tag==="Nothing")return n.pure();c()})(tn(o.nodes))},Ih=e=>{const t=e.Monad0().Applicative0();return n=>{const r=n.length-1|0,i=r<1?[]:Gt(0,r,n),o=i.length-1|0,u=o>=0&&o<i.length?E("Just",i[o]):T,s=n.length-1|0;if(s>=0&&s<n.length&&u.tag==="Just"){const a=n[s].y-u._1.y,f=n[s].x-u._1.x,g=Wn(f*f+a*a),d=a/g,l=-d,_=f/g,h=n[s].x+_*.875,p=n[s].y+d*.875,m=p-d*8.75,N=h-_*8.75,J=[1,h,p,2,N+l*4.375,m+_*4.375,2,N-l*4.375,m-_*4.375,5];return g<=1e-4?t.pure():e.fillPath(J)({color:Ze,flat:!0})}return t.pure()}},Co=e=>t=>n=>r=>i=>V(o=>{const u=n+(r-n)*(ct(o)/ct(i));return{x:e.x+t*Ho(u),y:e.y+t*Vo(u)}})(qt(0,i-1|0)),nc=e=>t=>{const n=je(e)(je(t.w/2)(t.h/2));return[...Lo({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(6),...Co({x:t.x+t.w-n,y:t.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Lo({x:t.x+t.w,y:t.y+n})({x:t.x+t.w,y:t.y+t.h-n})(6),...Co({x:t.x+t.w-n,y:t.y+t.h-n})(n)(0)(1.5707963267948966)(12),...Lo({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(6),...Co({x:t.x+n,y:t.y+t.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Lo({x:t.x,y:t.y+t.h-n})({x:t.x,y:t.y+n})(6),...Co({x:t.x+n,y:t.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},Dh=e=>t=>n=>y(r=>i=>{const o=r.pos+i.len,u=n<o?(n-r.pos)/i.len:1,s={x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u},a=t>r.pos?(t-r.pos)/i.len:0,f={x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a},g=r.points.length-1|0,d=g>=0&&g<r.points.length?(()=>{const l=r.points[g].x-f.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[g].y-f.y;return _<0?-_<1e-4:_<1e-4})()})()?de(r.points)(s):[...r.points,f,s]:[f,s];return i.len<=0||o<=t||r.pos>=n?{...r,pos:o}:{pos:o,points:d}})({pos:0,points:[]})(e).points,Gh=e=>t=>n=>{const r=Ht(i=>T,i=>o=>E("Just",{head:i,tail:o}),e);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=xh(e),o=gh(i),u=Ln(0)(o)(t*o),s=Ln(0)(o)(n*o);return s<=u?[]:Dh(i)(u)(s)}c()},Mh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=Ih(e);return i=>o=>u=>{const s=vh(8)(o);if(u.hi<=u.lo)return n.pure();const a=Gh(s)(u.lo)(u.hi);return a.length===0?n.pure():t.Bind1().bind(e.strokePath(mh(a))({color:Ze,width:.9375,lineJoin:He,lineCap:Ba}))(()=>r(a))}},rc=e=>{const t=Mh(e),n=e.Monad0().Applicative0(),r=en(n);return i=>o=>r(u=>{const s=bo(u._1)(o.edges);if(s.tag==="Just")return t(u._1)(u._2)((()=>{if(s._1.tag==="Retracted")return{lo:0,hi:0};if(s._1.tag==="Extended")return{lo:0,hi:1};if(s._1.tag==="Extending")return{lo:0,hi:s._1._2};if(s._1.tag==="Retracting"){if(s._1._1==="FromSource")return{lo:s._1._2,hi:1};if(s._1._1==="FromTarget")return{lo:0,hi:1-s._1._2};if(s._1._1==="FromBoth")return{lo:s._1._2/2,hi:1-s._1._2/2}}c()})());if(s.tag==="Nothing")return n.pure();c()})(tn(i.edges))},oc=e=>t=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:t.x+t.w/2,y:t.y+t.h/2},a=0<e.length?E("Just",e[0]):T,f=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return s;c()})(),g=e.length-1|0,d=g>=0&&g<e.length?E("Just",e[g]):T,l=(()=>{if(d.tag==="Just")return d._1;if(d.tag==="Nothing")return u;c()})(),_=Ra(128)(nc(5)(nu(2)(t)))(Ua(f)(6)),h=Mr(.05)(1-i-o),p=r<i?0:r>1-o?1:(r-i)/h,m=f.x-s.x,N=2*(()=>{const K=f.y-s.y;return(m<0?-m:m)+(K<0?-K:K)})(),J=l.x-u.x,v=2*(()=>{const K=l.y-u.y;return(J<0?-J:J)+(K<0?-K:K)})(),w=N+gi(e)+v,L=w<=1e-4?1:1-v/w,b=w<=1e-4?0:N/w,S=L-b,A=Ra(128)(Ua(l)(6))(nc(5)(nu(2)(n))),O={maxDelay:.4,smoothPasses:2},j=Xu(e)(Ln(0)(1)(S<=1e-4?0:(p-b)/S)),R=(()=>{if(j.tag==="Just")return j._1;if(j.tag==="Nothing")return f;c()})(),P=(()=>{if(L>=1)return 0;const K=(p-L)/(1-L),B=K<0?0:K>1?1:K;return B*B*(3-2*B)})(),et=(()=>{if(b<=1e-4)return 1;const K=p/b,B=K<0?0:K>1?1:K;return B*B*(3-2*B)})();return p<b?tu("PolyShape",Da(et)(_.from)(_.to)(O)):p>=L?tu("PolyShape",Da(P)(A.from)(A.to)(O)):tu("CircleShape",R,6)},Wh=e=>t=>n=>r=>i=>o=>u=>s=>a=>{const f=oc(r)(i)(o)(u)(s)(a);if(f.tag==="CircleShape")return e.fillStrokePath(ou(f._1)(f._2))({color:t,flat:!0})({color:n,width:1,lineJoin:He,lineCap:dn});if(f.tag==="PolyShape")return f._1.length>=3?e.fillStrokePath(_h(f._1))({color:t,flat:!0})({color:n,width:1,lineJoin:He,lineCap:dn}):e.Monad0().Applicative0().pure();c()},ic=e=>{const t=kh(e),n=e.Monad0().Applicative0(),r=en(n);return i=>o=>u=>s=>r(a=>{if(a._2.tag==="Travelling"){const f=Ee(a._2._1.target)(i.nodes),g=Ee(a._2._1.source)(i.nodes);if(g.tag==="Just"&&f.tag==="Just"){const d=bo(a._2._1.edge)(i.edges);if(d.tag==="Just")return Wh(e)(u)(s)((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return le(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);if(d.tag==="Nothing")return t(u)(s)(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);c()}return n.pure()}if(a._2.tag==="Filling"){const f=Ee(a._2._1.node)(i.nodes);if(f.tag==="Just")return e.drawRoundedRect((()=>{const g=nu(2)(f._1);return{x:g.x,y:g.y,w:g.w,h:g.h}})())(5)(E("Just",{color:u,flat:!0}))(E("Just",{color:s,width:1,lineJoin:He,lineCap:dn}));if(f.tag==="Nothing")return n.pure();c()}return n.pure()})(tn(o.tokens))},uc=e=>{const t=e.Monad0(),n=t.Bind1(),r=ic(e),i=e.popClip,o=e.popBlend,u=e.popLayer,s=t.Applicative0(),a=en(s);return f=>g=>n.bind(e.pushLayer(ih))(()=>n.bind(e.pushBlend(ch))(()=>n.bind(e.pushClip(Oa(f)(g))($a))(()=>n.bind(r(f)(g)(Kn)(Kn))(()=>n.bind(i)(()=>n.bind(o)(()=>n.bind(u)(()=>n.bind(e.pushLayer(uh))(()=>n.bind(a(d=>{const l=Ee(d._1)(g.nodes);return l.tag==="Just"&&ko(l._1).alpha>0?e.drawRoundedRect({x:d._2.x,y:d._2.y,w:d._2.w,h:d._2.h})(7)(E("Just",{color:Kn,flat:!1}))(T):s.pure()})(tn(f.nodes)))(()=>u)))))))))},sc=e=>{const t=e.Monad0().Bind1(),n=ic(e),r=e.popClip,i=e.popLayer;return o=>u=>s=>t.bind(e.pushLayer(oh))(()=>t.bind(e.pushClip(yh(o)(u)(s))(ah))(()=>t.bind(n(u)(s)(Ze)(Kn))(()=>t.bind(r)(()=>i))))},ac=e=>t=>n=>r=>i=>o=>{const u=oc(e)(t)(n)(r)(i)(o);if(u.tag==="PolyShape")return Eh(u._1);if(u.tag==="CircleShape")return u._1;c()},Ah=e=>{const t=Ya(e),n=e.Monad0(),r=n.Bind1(),i=en(n.Applicative0()),o=Th(e);return u=>s=>a=>f=>g=>d=>l=>_=>{const h=Eo(f)(g)(d)(St(l)(Fa)),p=h.line,m=h.phaseInLabel/.45,N=m<0?0:m>1?1:m,J=_.w,v=_.y,w=_.x,L=w+14,b=_.h,S=v+b/2;return t(Ka(f)(g)(d))(w)(v+b)({x:w+J/2,y:S})(r.bind(i(A=>e.fillPath(ou(A)(1.5))({color:Ze,flat:!0}))(Jh(_)(ac(u)(s)(a)(f)(g)(d))))(()=>r.bind(e.drawRoundedRect({x:w,y:v,w:J,h:b})(3)(E("Just",{color:Ze,flat:!0}))(T))(()=>o({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Kn)(N)(L)(S)(p))))}},cc=e=>{const t=Ah(e),n=e.Monad0(),r=n.Applicative0(),i=Ch(e),o=n.Bind1(),u=en(r),s=e.popLayer;return a=>f=>g=>o.bind(e.pushLayer(sh))(()=>o.bind(u(d=>{if(d._2.tag==="Travelling"){if(d._2._1.labels.length!==0){const l=Ee(d._2._1.target)(a.nodes),_=Ee(d._2._1.source)(a.nodes),h=bo(d._2._1.edge)(a.edges),p=Qa(d._1)(g);if(p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just"&&l.tag==="Just")return t((()=>{if(d._2._1.direction==="Forward")return h._1;if(d._2._1.direction==="Backward")return le(h._1);c()})())(_._1)(l._1)(d._2._1.progress)(d._2._1.holdPre)(d._2._1.holdPost)(d._2._1.labels)(p._1)}return r.pure()}if(d._2.tag==="Filling"&&d._2._1.labels.length!==0){const l=Ee(d._2._1.node)(a.nodes);if(l.tag==="Just")return i(a)(l._1)(d._2._1.progress)(d._2._1.labels);if(l.tag==="Nothing")return r.pure();c()}return r.pure()})(tn(f.tokens)))(()=>s))},zh=e=>{const t=e.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const f=ac(n)(r)(i)(o)(u)(s);return t.Bind1().bind(e.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Eo(o)(u)(s)(St(a)(Fa)).line))(g=>t.Applicative0().pure({x:f.x+14+g/2-g/2-14,y:f.y-6-8-6.6-6,w:g+28,h:25.2}))}},Bh=e=>{const t=e.Monad0(),n=t.Bind1(),r=zh(e),i=t.Applicative0(),o=qr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>qa(Pt(f=>f)(a)))(o(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const f=Ee(a._2._1.target)(u.nodes),g=Ee(a._2._1.source)(u.nodes),d=bo(a._2._1.edge)(u.edges);if(d.tag==="Just"&&g.tag==="Just"&&f.tag==="Just")return n.bind(r((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return le(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>i.pure(E("Just",x(a._1,l))))}return i.pure(T)})(tn(s.tokens)))},fc=e=>{const t=e.Monad0(),n=t.Bind1(),r=Bh(e),i=bh(e);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>t.Applicative0().pure(ph((()=>{const f=g=>{if(g.tag==="Leaf")return $;if(g.tag==="Node")return Ft("Node",g._1,g._2,g._3,void 0,f(g._5),f(g._6));c()};return vt(k.compare)(bt(ke.foldr,f(s)))})())(s)([...V(fh)((()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,zt("Cons",g._4,f(g._6,d)));c()};return bt(Yt.foldr,f(o.nodes,Qt))})()),...(()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,zt("Cons",g._4,f(g._6,d)));c()};return bt(Yt.foldr,f(a,Qt))})()]))))},$h=e=>{const t=fc(e),n=cc(e);return r=>i=>e.Monad0().Bind1().bind(t(r)(i))(o=>n(r)(i)(o))},So=e=>t=>n=>{const r=fs(t)(n.camera);return{vx:r.x-e.padding,vy:r.y-e.padding-40,vw:r.w+2*e.padding,vh:r.h+2*e.padding+40}},gc=e=>{const t=e.Monad0(),n=t.Bind1();return r=>i=>{if(r==="")return t.Applicative0().pure();const o=i.vh/720,u=15*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600};return n.bind(e.measureText(s)(r))(a=>{const f=i.vy+12*o,g=u+6*o*2,d=a+11*o*2,l=i.vx+i.vw/2;return n.bind(e.drawRoundedRect({x:l-d/2,y:f,w:d,h:g})(g/2)(E("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(E("Just",{color:{r:0,g:0,b:0,a:255},width:1*o,lineJoin:He,lineCap:Ba})))(()=>e.drawText({x:l,y:f+g/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:ji,baseline:Gr}))})}},Qh=e=>{const t=e.Monad0().Bind1(),n=tc(e),r=rc(e),i=ec(e),o=Xa(e),u=sc(e),s=uc(e),a=$h(e),f=gc(e);return g=>d=>l=>{const _=So(g)(d)(l);return t.bind(n(g.transparentBg)(_))(()=>t.bind(r(d)(l))(()=>t.bind(i(g.halftoneShadows)(d)(l))(()=>t.bind(o(d)(l))(()=>t.bind(u(_)(d)(l))(()=>t.bind(s(d)(l))(()=>t.bind(a(d)(l))(()=>t.bind(g.watermark===""?e.Monad0().Applicative0().pure():e.drawText({x:_.vx+6,y:_.vy+6,content:g.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:wo,baseline:za}))(()=>f(l.frameTitle)(_)))))))))}},qh=e=>{const t=e.Monad0().Bind1(),n=tc(e),r=rc(e),i=ec(e),o=Xa(e),u=sc(e),s=uc(e),a=cc(e),f=gc(e);return g=>d=>l=>_=>{const h=So(g)(d)(l);return t.bind(n(g.transparentBg)(h))(()=>t.bind(r(d)(l))(()=>t.bind(i(g.halftoneShadows)(d)(l))(()=>t.bind(o(d)(l))(()=>t.bind(u(h)(d)(l))(()=>t.bind(s(d)(l))(()=>t.bind(a(d)(l)(_))(()=>t.bind(g.watermark===""?e.Monad0().Applicative0().pure():e.drawText({x:h.vx+6,y:h.vy+6,content:g.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:wo,baseline:za}))(()=>f(l.frameTitle)(h)))))))))}},_c=e=>t=>n=>{const r=lt.compare(e)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;c()})(),o=lt.compare(t)(i);if(o==="LT"||o==="EQ")return t;if(o==="GT")return i;c()},Hh=fc(Sa),Yh=qh(Sa),Vh=e=>{const t=e.vx+e.vw-4,n=e.vy+e.vh-4,r=e.vx+4,i=e.vy+4,o=u=>{if(u.tag==="Leaf")return $;if(u.tag==="Node")return Ft("Node",u._1,u._2,u._3,{...u._4,x:_c(r)(t-u._4.w)(u._4.x),y:_c(i)(n-u._4.h)(u._4.y)},o(u._5),o(u._6));c()};return o},Oh=e=>t=>n=>r=>i=>o=>{const u={padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""},s=D0(e)(t);return()=>{const a=s(),f=Hh(n)(r)(a)(),g=k0(i)(Vh(So(u)(n)(r))(f))(o);return Yh(u)(n)(r)(g.applied)(a)(),g.springs}},ln=e=>"rgb("+ue(e.r)+","+ue(e.g)+","+ue(e.b)+")",Po=_r(fr("Fixed",gr(0)(20)(4))),Fh=e=>"translate("+Po(e.tx)+","+Po(e.ty)+") scale("+Po(e.sx)+","+Po(e.sy)+")",Nt=_r(fr("Fixed",gr(0)(20)(2))),iu=e=>{const t=[];let n=0;for(;n<e.length;){const r=n,i=r>=0&&r<e.length?E("Just",e[r]):T;if(i.tag==="Nothing"){n=e.length;continue}if(i.tag==="Just"){if(i._1===1){t.push("M"),t.push(Nt((()=>{const o=r+1|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+2|0;return o>=0&&o<e.length?e[o]:0})())),n=r+3|0;continue}if(i._1===2){t.push("L"),t.push(Nt((()=>{const o=r+1|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+2|0;return o>=0&&o<e.length?e[o]:0})())),n=r+3|0;continue}if(i._1===3){t.push("Q"),t.push(Nt((()=>{const o=r+1|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+2|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+3|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+4|0;return o>=0&&o<e.length?e[o]:0})())),n=r+5|0;continue}if(i._1===4){t.push("C"),t.push(Nt((()=>{const o=r+1|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+2|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+3|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+4|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+5|0;return o>=0&&o<e.length?e[o]:0})())),t.push(Nt((()=>{const o=r+6|0;return o>=0&&o<e.length?e[o]:0})())),n=r+7|0;continue}if(i._1===5){t.push("Z"),n=r+1|0;continue}n=e.length;continue}c()}return Ti(" ")(t)},Xh={map:e=>t=>n=>{const r=t(n);return()=>{const i=r();return e(i)}}},Uh=(()=>{const e=cn("&")("&"),t=cn("<")("<"),n=(()=>{const r=cn(">")(">"),i=(()=>{const o=cn('"')(""");return u=>o(r(u))})();return o=>i(t(o))})();return r=>n(e(r))})(),xe=e=>t=>{const n=t.maskDepth;return()=>{n.value===0&&t.out.push(e)}},dc={apply:e=>t=>n=>{const r=e(n),i=t(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>Xh},Kh={bind:e=>t=>n=>{const r=e(n);return()=>{const i=r();return t(i)(n)()}},Apply0:()=>dc},Zh={pure:e=>t=>()=>e,Apply0:()=>dc},jh={Applicative0:()=>Zh,Bind1:()=>Kh},tp=e=>t=>'<defs><pattern id="'+e+'" x="0" y="0" width="'+Nt(t.tile)+'" height="'+Nt(t.tile)+'" patternUnits="userSpaceOnUse">'+(t.bgColor.a===0?"":'<rect width="'+Nt(t.tile)+'" height="'+Nt(t.tile)+'" fill="'+ln(t.bgColor)+'" fill-opacity="'+Nt(ct(t.bgColor.a)/255)+'"/>')+'<circle cx="'+Nt(t.tile/2)+'" cy="'+Nt(t.tile/2)+'" r="'+Nt(t.dotRadius)+'" fill="'+ln(t.dotColor)+'"/></pattern></defs><rect x="'+Nt(t.viewport.vx)+'" y="'+Nt(t.viewport.vy)+'" width="'+Nt(t.viewport.vw)+'" height="'+Nt(t.viewport.vh)+'" fill="url(#'+e+')"/>',lc=e=>t=>'<path d="'+iu(e)+'" fill="'+ln(t)+'" fill-opacity="'+Nt(ct(t.a)/255)+'"/>',ep=e=>t=>n=>r=>'<rect x="'+Nt(e.x)+'" y="'+Nt(e.y)+'" width="'+Nt(e.w)+'" height="'+Nt(e.h)+'" rx="'+Nt(t)+'"'+(()=>{if(n.tag==="Just")return' fill="'+ln(n._1.color)+'" fill-opacity="'+Nt(ct(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';c()})()+(()=>{if(r.tag==="Just")return' stroke="'+ln(r._1.color)+'" stroke-opacity="'+Nt(ct(r._1.color.a)/255)+'" stroke-width="'+Nt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";c()})()+'"';if(r.tag==="Nothing")return"";c()})()+"/>",hc=e=>t=>'<path d="'+iu(e)+'" fill="none" stroke="'+ln(t.color)+'" stroke-opacity="'+Nt(ct(t.color.a)/255)+'" stroke-width="'+Nt(t.width)+'" stroke-linejoin="'+(()=>{if(t.lineJoin==="RoundJoin")return"round";if(t.lineJoin==="BevelJoin")return"bevel";if(t.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(t.lineCap==="ButtCap")return"butt";if(t.lineCap==="RoundCap")return"round";if(t.lineCap==="SquareCap")return"square";c()})()+'"/>',np=e=>'<text x="'+Nt(e.x)+'" y="'+Nt(e.y)+'"'+(()=>{if(e.baseline==="BaselineTop")return' dy="0.8em"';if(e.baseline==="BaselineMiddle")return' dy="0.32em"';if(e.baseline==="BaselineAlphabetic"||e.baseline==="BaselineBottom")return"";c()})()+' fill="'+ln(e.color)+'" fill-opacity="'+Nt(ct(e.color.a)/255)+'" font-size="'+Nt(e.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+ue(e.font.weight)+'" text-anchor="'+(()=>{if(e.align==="AlignLeft")return"start";if(e.align==="AlignCenter")return"middle";if(e.align==="AlignRight")return"end";c()})()+'">'+Uh(so(e.content))+"</text>",rp=Qh({fillPath:e=>t=>xe(lc(e)(t.color)),strokePath:e=>t=>xe(hc(e)(t)),fillStrokePath:e=>t=>n=>xe(lc(e)(t.color)+hc(e)(n)),drawRoundedRect:e=>t=>n=>r=>xe(ep(e)(t)(n)(r)),drawText:e=>xe(np(e)),pushTransform:e=>xe((()=>{const t='transform="'+Fh(e)+'"';return t===""?"<g>":"<g "+t+">"})()),popTransform:xe("</g>"),pushClip:e=>t=>n=>{const r=n.clipCounter;return()=>{const i=r.value;n.clipCounter.value=i+1|0;const o="clip"+ue(i);return xe((()=>{const u='clip-path="url(#'+o+')"';return'<defs><clipPath id="'+o+'"><path d="'+iu(e)+'"'+(()=>{if(t==="EvenOdd")return' clip-rule="evenodd"';if(t==="NonZero")return"";c()})()+"/></clipPath></defs>"+(u===""?"<g>":"<g "+u+">")})())(n)()}},popClip:xe("</g>"),pushBlend:e=>xe((()=>{const t=(()=>{if(e==="Normal")return'style="mix-blend-mode: normal"';if(e==="Difference")return'style="mix-blend-mode: difference"';c()})();return t===""?"<g>":"<g "+t+">"})()),popBlend:xe("</g>"),pushAlpha:e=>xe((()=>{const t='opacity="'+Nt(e)+'"';return t===""?"<g>":"<g "+t+">"})()),popAlpha:xe("</g>"),pushLayer:e=>t=>{const n=(()=>{if(e==="LayerNodeMask"){const r=t.maskDepth;return()=>{const i=r.value;t.maskDepth.value=i+1|0}}return()=>{}})();return()=>{n(),t.out.push("<g>")}},popLayer:e=>{const t=e.maskDepth;return()=>{const n=t.value,r=n-1|0;n>0&&(e.maskDepth.value=r),e.out.push("</g>")}},setViewport:e=>t=>()=>{},clearBackground:e=>t=>xe('<rect x="'+Nt(t.viewport.vx)+'" y="'+Nt(t.viewport.vy)+'" width="'+Nt(t.viewport.vw)+'" height="'+Nt(t.viewport.vh)+'" fill="'+ln(e)+'" opacity="'+Nt(ct(e.a)/255)+'"/>')(t),backgroundDots:e=>t=>{const n=t.patternCounter;return()=>{const r=n.value;return t.patternCounter.value=r+1|0,xe(tp("bg-dots-"+ue(r))(e))(t)()}},measureText:e=>t=>n=>{const r=Ea(e.family)(e.size)(e.weight)(so(t));return()=>r},Monad0:()=>jh}),op=e=>t=>{const n={padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""},r=So(n)(e)(t);return{viewBox:Nt(r.vx)+" "+Nt(r.vy)+" "+Nt(r.vw)+" "+Nt(r.vh),body:(()=>{const i=[],o={value:0},u={value:0},s={value:0};return rp(n)(e)(t)({out:i,maskDepth:o,clipCounter:u,patternCounter:s,viewport:r})(),Ti("")(i)})()}},Wr=e=>({bind:t=>n=>r=>e.Bind1().bind(t(r))(i=>n(i._1)(i._2)),Apply0:()=>pc(e)}),pc=e=>{const t=e.Bind1().Apply0().Functor0(),n={map:r=>i=>o=>t.map(u=>x(r(u._1),u._2))(i(o))};return{apply:(()=>{const r=Wr(e);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Ar(e).pure(u(s))))})(),Functor0:()=>n}},Ar=e=>({pure:t=>n=>e.Applicative0().pure(x(t,n)),Apply0:()=>pc(e)}),ip=e=>{const t={Applicative0:()=>Ar(e),Bind1:()=>Wr(e)};return{state:n=>r=>e.Applicative0().pure(n(r)),Monad0:()=>t}},uu=(e,t)=>({tag:e,_1:t}),En=(e,t)=>({tag:e,_1:t}),be=ip(un),Bt=Wr(un),Ce=be.state(e=>x(e,e)),nn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},hn=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},_e=Ar(un),up=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=E("Just",o._4);continue}}c()}return i},sp=(()=>{const e=Ie.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return E("Just",x(t._1,t._2));c()});return t=>e((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._3,n(r._6,i)));c()};return n(t,Qt)})())})(),ap=e=>t=>{let n=t,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=k.compare(e)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},su=e=>t=>n=>y(r=>i=>e.Bind1().bind(r)(o=>t(o)(i)))(e.Applicative0().pure(n)),cp=y(e=>t=>Z(k)(t)()(e))($),fp=(()=>{const e=(t=>n=>{let r=t,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=Z(k)(a._1)()(s),i=a._2;continue}c()}return u})($);return t=>e((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,zt("Cons",r._3,n(r._6,i)));c()};return n(t,Qt)})())})(),mc=jc(_e)(At),gp=e=>uu("Par",e),yc=e=>uu("Seq",e),_p=e=>t=>n=>{const r=Dn(Xt,T,i=>i._1===e,n);if(r.tag==="Just"){const i=Gn(Xt,T,r._1,x(e,t),n);if(i.tag==="Nothing")return n;if(i.tag==="Just")return i._1;c()}if(r.tag==="Nothing")return de(n)(x(e,t));c()},dp=e=>t=>V(n=>n._1===e?x(n._1,{...n._2,label:E("Just",t)}):x(n._1,n._2)),Ge=e=>be.state(t=>x(void 0,(()=>{if(t.error.tag==="Just")return t;if(t.error.tag==="Nothing")return{...t,error:E("Just",{msg:e,line:t.currentLine,column:t.currentColumn})};c()})())),lp=e=>Bt.bind(Ce)(t=>{const n=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ue(t.kfCounter);if(sn(i=>i.id===n,t.keyframes))return Ge("duplicate frame name "+n);const r={...t,keyframes:de(t.keyframes)({id:n,nodes:t.currNodes,edges:t.currEdges}),kfCounter:t.kfCounter+1|0,currentKf:E("Just",n)};return be.state(i=>x(void 0,r))}),hp=e=>t=>{const n=t.from+"->"+t.to,r=t.newFrom+"->"+t.newTo,i=kt("Left","cannot repoint "+t.from+"\u2192"+t.to+": edge does not exist"),o=nn(n)(e.currEdges)?kt("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>kt("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}c()})()(()=>{const u="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": unknown node "+t.newFrom;if(!hn(t.newFrom)(e.currNodes))return kt("Left",u);const s="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": unknown node "+t.newTo;if(!hn(t.newTo)(e.currNodes))return kt("Left",s);const a="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": target edge already exists";return n!==r&&nn(r)(e.currEdges)?kt("Left",a):kt("Right",{nextCurrEdges:Z(k)(r)()(ar(k)(n)(e.currEdges)),newId:r,newEdge:{id:r,from:{node:t.newFrom,port:T},to:{node:t.newTo,port:T}}})})},pp={graphNodes:[],graphEdges:$,currNodes:$,currEdges:$,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T},Jc=e=>t=>Bt.bind(Ce)(n=>{const r="ev-"+ue(n.eventCounter);return Bt.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return be.state(o=>x(void 0,i))})())(()=>_e.pure({events:[{id:r,kind:t,when:e}],firstId:E("Just",r),lastId:E("Just",r)}))}),mp=e=>t=>{if(t.tag==="Token"){const n=t._1;return Bt.bind(Ce)(r=>{const i=!hn(n.from)(r.currNodes),o=!hn(n.to)(r.currNodes);if(i||o)return Bt.bind(Ge(i?o?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:o?"token references unknown node: "+n.to:"token references unknown node: "))(()=>_e.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return nn(s)(r.currEdges)?Jc(e)(ns("SendToken",{from:n.from,to:n.to,edge:s,direction:Gg,labels:n.labels})):nn(u)(r.currEdges)?Jc(e)(ns("SendToken",{from:n.from,to:n.to,edge:u,direction:Mg,labels:n.labels})):Bt.bind(Ge("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>_e.pure({events:[],firstId:T,lastId:T}))})}return _e.pure({events:[],firstId:T,lastId:T})},yp=e=>Pt(t=>up(t)(e.graphEdges))(bt(ir,sp(e.currEdges))),Jp=e=>t=>{const n=at(i=>i.from.node===t.id||i.to.node===t.id,yp(e)),r=su(Bc)(i=>o=>{const u=o.from+"->"+t.id,s=t.id+"->"+o.to,a=o.from+"->"+o.to,f="via "+o.from+" "+o.to+": no edge "+o.from+"\u2192"+t.id;if(!nn(u)(e.currEdges))return kt("Left",f);const g="via "+o.from+" "+o.to+": no edge "+t.id+"\u2192"+o.to;if(!nn(s)(e.currEdges))return kt("Left",g);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return nn(a)(e.currEdges)||ap(a)(i.synthesized)?kt("Left",d):kt("Right",{consumed:Z(k)(u)()(Z(k)(s)()(i.consumed)),synthesized:Z(k)(a)({id:a,from:{node:o.from,port:T},to:{node:o.to,port:T}})(i.synthesized)})})({consumed:$,synthesized:$})(t.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>kt("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}c()})()(i=>{const o=i.consumed,u=at(s=>!nn(s.id)(o),n);return u.length===0?kt("Right",{nextCurrEdges:Ne(k.compare,me,Xe(k.compare,e.currEdges,cp(V(s=>s.id)(n))),fp((()=>{const s=a=>{if(a.tag==="Leaf")return $;if(a.tag==="Node")return Ft("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));c()};return s(i.synthesized)})())),synthesized:i.synthesized}):kt("Left","cannot delete node "+t.id+": still connected ("+Ti(", ")(V(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+t.id+"'s endpoints.")})},Nc=e=>{if(e.tag==="Leaf")return[e._1];if(e.tag==="Par"||e.tag==="Seq")return St(e._1)(Nc);c()},Np=e=>({nodes:V($r)(e.graphNodes),edges:(()=>{const t=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return t(n._5,zt("Cons",n._4,t(n._6,r)));c()};return bt(Yt.foldr,t(e.graphEdges,Qt))})(),constraints:[]}),xp=e=>{if(e.tag==="AddNode"){const t=e._1;return be.state(n=>x(void 0,{...n,graphNodes:_p(t.id)({id:t.id,size:x(1,1),ports:[],label:E("Just",t.label)})(n.graphNodes),currNodes:Z(k)(t.id)()(n.currNodes)}))}if(e.tag==="DelNode"){const t=e._1;return Bt.bind(Ce)(n=>{if(!hn(t.id)(n.currNodes))return Ge("cannot delete node "+t.id+": does not exist");const r=Jp(n)(t);if(r.tag==="Left")return Ge(r._1);if(r.tag==="Right"){const i=r._1;return be.state(o=>x(void 0,{...o,currNodes:ar(k)(t.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:Ne(k.compare,me,i.synthesized,o.graphEdges)}))}c()})}if(e.tag==="ModNode"){const t=e._1;return Bt.bind(Ce)(n=>{if(!hn(t.id)(n.currNodes))return Ge("cannot modify node "+t.id+": does not exist");if(t.label.tag==="Just"){const r=t.label._1;return be.state(i=>x(void 0,{...i,graphNodes:dp(t.id)(r)(i.graphNodes)}))}if(t.label.tag==="Nothing")return _e.pure();c()})}if(e.tag==="AddEdge"){const t=e._1;return Bt.bind(Ce)(n=>{const r=!hn(t.from)(n.currNodes),i=!hn(t.to)(n.currNodes);if(r||i)return Ge("cannot add edge "+t.from+"\u2192"+t.to+": unknown node "+(r?i?t.from+", "+t.to:t.from:i?t.to:""));const o=t.from+"->"+t.to;return be.state(u=>x(void 0,{...u,graphEdges:Z(k)(o)({id:o,from:{node:t.from,port:T},to:{node:t.to,port:T}})(u.graphEdges),currEdges:Z(k)(o)()(u.currEdges)}))})}if(e.tag==="DelEdge"){const t=e._1;return Bt.bind(Ce)(n=>{const r=t.from+"->"+t.to;return nn(r)(n.currEdges)?be.state(i=>x(void 0,{...i,currEdges:ar(k)(r)(i.currEdges)})):Ge("cannot delete edge "+t.from+"\u2192"+t.to+": does not exist")})}if(e.tag==="RepointEdge"){const t=e._1;return Bt.bind(Ce)(n=>{const r=hp(n)(t);if(r.tag==="Left")return Ge(r._1);if(r.tag==="Right"){const i=r._1;return be.state(o=>x(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:Z(k)(i.newId)(i.newEdge)(o.graphEdges)}))}c()})}return _e.pure()},vp=e=>Bt.bind(be.state(t=>x(void 0,{...t,currentLine:e.line,currentColumn:e.column})))(()=>xp(e.op)),Tp=e=>t=>Bt.bind(mc(vp)(t))(()=>Bt.bind(Ce)(n=>{const r=e.tag==="Just"&&e._1!==""?e._1:"kf-"+ue(n.kfCounter);if(sn(o=>o.id===r,n.keyframes))return Ge("duplicate frame name "+r);const i={...n,keyframes:de(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:E("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return de(n.scenes)(rs("Structural",{from:n.currentKf._1,to:r,focus:T}));c()})()};return be.state(o=>x(void 0,i))})),wp=e=>t=>{const n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return _e.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return Bt.bind(zr(e)(n._1.head))(i=>Bt.bind(su({Applicative0:()=>Ar(un),Bind1:()=>Wr(un)})(o=>u=>Bt.bind(zr((()=>{if(o.lastId.tag==="Just")return pi("After",o.lastId._1);if(o.lastId.tag==="Nothing")return e;c()})())(u))(s=>_e.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return E("Just",o.firstId._1);if(o.firstId.tag==="Nothing")return s.firstId;c()})(),lastId:(()=>{if(s.lastId.tag==="Just")return E("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return o.lastId;c()})()})))(i)(r))(o=>_e.pure(o)))}c()},bp=e=>t=>{const n=Ht(r=>T,r=>i=>E("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return _e.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return Bt.bind(zr(e)(n._1.head))(i=>Bt.bind(kp((()=>{if(i.firstId.tag==="Just")return pi("With",i.firstId._1);if(i.firstId.tag==="Nothing")return e;c()})())(r))(o=>_e.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return E("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;c()})()})))}c()},zr=e=>t=>{if(t.tag==="Leaf"){const n=t._1;return Bt.bind(be.state(r=>x(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>mp(e)(n.op))}if(t.tag==="Seq")return wp(e)(t._1);if(t.tag==="Par")return bp(e)(t._1);c()},kp=e=>su({Applicative0:()=>Ar(un),Bind1:()=>Wr(un)})(t=>n=>Bt.bind(zr(e)(n))(r=>_e.pure({events:[...t.events,...r.events],firstId:(()=>{if(t.firstId.tag==="Just")return E("Just",t.firstId._1);if(t.firstId.tag==="Nothing")return r.firstId;c()})(),lastId:(()=>{if(r.lastId.tag==="Just")return E("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return t.lastId;c()})()})))({events:[],firstId:T,lastId:T}),Lp=e=>Bt.bind(Ce)(t=>{if(t.currentKf.tag==="Nothing")return Ge("flow ops before any structural frame");if(t.currentKf.tag==="Just"){const n=t.currentKf._1;return Bt.bind(zr(Dg)(e))(r=>Bt.bind(Ce)(i=>{const o={...i,scenes:de(i.scenes)(rs("DataFlow",{keyframe:n,events:r.events,focus:T}))};return be.state(u=>x(void 0,o))}))}c()}),Ep=e=>Bt.bind(Ce)(t=>{if(t.error.tag==="Just")return _e.pure();if(t.error.tag==="Nothing"){const n=Nc(e.ops),r=at(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",n),i=at(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge"),n);return Bt.bind((()=>{const o=Tp(e.name)(r);return r.length!==0?o:_e.pure()})())(()=>Bt.bind((()=>{const o=lp(e.name);return r.length===0&&i.length!==0?o:_e.pure()})())(()=>{const o=Lp(e.ops);return i.length!==0?o:_e.pure()}))}c()}),Cp=e=>Bt.bind(mc(Ep)(e.frames))(()=>Bt.bind(Ce)(t=>_e.pure((()=>{if(t.error.tag==="Just")return kt("Left",t.error._1);if(t.error.tag==="Nothing")return kt("Right",{seed:e.seed,graph:Np(t),keyframes:t.keyframes,scenes:t.scenes});c()})())))(pp)._1,Zn=(e,t)=>({tag:"ParseError",_1:e,_2:t}),z=(e,t,n)=>({tag:"ParseState",_1:e,_2:t,_3:n}),Ro=(e,t,n)=>({tag:e,_1:t,_2:n}),Sp=e=>Ro("More",e),Pp=e=>Ro("Lift",e),xc={map:e=>t=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,f)=>r(g=>u(a,e(f)))))},Rp={alt:e=>t=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(f=>e(z(s,a,!1),r,i,(g,d)=>{const l=g._3;return r(_=>l?o(g,d):t(n,r,i,o,u))},u))},Functor0:()=>xc},Ip=e=>{const t=e.Monad0();return n=>r=>{const i=o=>{let u=o,s=!0,a;for(;s;){const f=u();if(f.tag==="More"){u=f._1;continue}if(f.tag==="Lift"){s=!1,a=t.Bind1().Apply0().Functor0().map(ku)(f._1);continue}if(f.tag==="Stop"){s=!1,a=t.Applicative0().pure(or("Done",x(f._2,f._1)));continue}c()}return a};return e.tailRecM(i)(o=>r(n,Sp,Pp,(u,s)=>Ro("Stop",u,kt("Left",s)),(u,s)=>Ro("Stop",u,kt("Right",s))))}},vc=(e,t,n,r,i)=>i(e,e._2),Dp={index:0,line:1,column:1},Gp=(e=>{const t=Ip(e);return n=>r=>e.Monad0().Bind1().Apply0().Functor0().map(Qr)(t(z(n,Dp,!1))(r))})(Fc),Tc={apply:e=>t=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,f)=>r(g=>{const d=n._3&&!a._3?z(a._1,a._2,!0):a;return t(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?z(l._1,l._2,!0):l,f(_))))}))),Functor0:()=>xc},wc={pure:e=>(t,n,r,i,o)=>o(t,e),Apply0:()=>Tc},Mp={bind:e=>t=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,f)=>r(g=>t(f)(n._3&&!a._3?z(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>Tc},Wp={Applicative0:()=>wc,Bind1:()=>Mp},Io=e=>(t,n,r,i,o)=>n(u=>vc(t,n,r,i,(s,a)=>n(f=>i(t._3&&!s._3?z(s._1,s._2,!0):s,Zn(e,a))))),Ap={empty:Io("No alternative"),Alt0:()=>Rp},zp={Applicative0:()=>wc,Plus1:()=>Ap},Pe=(e=>t=>{const n=t.Plus1().Alt0(),r=t.Applicative0();return i=>e.tailRecM(o=>e.Monad0().Bind1().bind(n.alt(n.Functor0().map(ku)(i))(r.pure(or("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return or("Loop",zt("Cons",u._1,o));if(u.tag==="Done")return or("Done",(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=zt("Cons",h._1,_),g=h._2;continue}c()}return l})(Qt)(o));c()})())))(Qt)})({tailRecM:e=>t=>(n,r,i,o,u)=>{const s=(a,f,g)=>e(f)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?z(d._1,d._2,!0):d;if(l.tag==="Loop")return g===0?r(h=>s(_,l._1,30)):s(_,l._1,g-1|0);if(l.tag==="Done")return u(_,l._1);c()});return s(n,t,30)},Monad0:()=>Wp})(zp),Lt=e=>t=>{const n=Io("Expected "+t);return(r,i,o,u,s)=>{const a=r._1,f=r._2;return i(g=>e(z(a,f,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},au=e=>(t,n,r,i,o)=>{const u=t._3,s=t._1,a=t._2;return n(f=>{const g=(d,l)=>{const _=d._3;return n(h=>_?i(z(d._1,d._2,u),l):o(t,void 0))};return n(d=>n(l=>e(z(s,a,!1),n,r,(_,h)=>g(z(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>Io("Negated parser succeeded")(_,n,r,g,(N,J)=>n(v=>o(_._3&&!N._3?z(N._1,N._2,!0):N,J))))))))})},Bp=e=>{const t=e.foldr(n=>r=>{if(r.tag==="Nothing")return E("Just",n);if(r.tag==="Just")return E("Just",(i,o,u,s,a)=>{const f=i._1,g=i._2;return o(d=>n(z(f,g,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});c()})(T);return n=>{const r=t(n);if(r.tag==="Nothing")return Io("No alternative");if(r.tag==="Just")return r._1;c()}},$p=e=>t=>n=>(r,i,o,u,s)=>i(a=>i(f=>i(g=>i(d=>e(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?z(l._1,l._2,!0):l;return n(m,i,o,u,(N,J)=>i(v=>{const w=m._3&&!N._3?z(N._1,N._2,!0):N;return i(L=>i(b=>{const S=r._3&&!w._3?z(w._1,w._2,!0):w;return t(S,i,o,u,(A,O)=>i(j=>s(S._3&&!A._3?z(A._1,A._2,!0):A,J)))}))}))}))))))),cu=e=>t=>n=>{if(t===10)return{index:e.index+1|0,line:e.line+1|0,column:1};if(t===13){const r=J_()(n);return r.tag==="Just"&&r._1===10?{index:e.index+1|0,line:e.line,column:e.column}:{index:e.index+1|0,line:e.line+1|0,column:1}}return t===9?{index:e.index+1|0,line:e.line,column:(e.column+8|0)-Oo(e.column-1|0)(8)|0}:{index:e.index+1|0,line:e.line,column:e.column+1|0}},Qp=e=>t=>n=>{let r=e,i=t,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o,d=to(f);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?cu(a)(d._1.head)(g):cu(a)(d._1.head)(d._1.tail),i=d._1.tail,o=g;continue}c()}return s},Ot=e=>(t,n,r,i,o)=>{const u=to(t._1);if(u.tag==="Nothing")return i(t,Zn("Unexpected EOF",t._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(t,Zn("Expected Char",t._2));if(u._1.head>=0&&u._1.head<=65535){const s=gs(u._1.head);return e(s)?o(z(u._1.tail,cu(t._2)(u._1.head)(u._1.tail),!0),s):i(t,Zn("Predicate unsatisfied",t._2))}}c()},bc=(e,t,n,r,i)=>e._1===""?i(z(e._1,e._2,!0),void 0):r(e,Zn("Expected EOF",e._2)),qp=e=>(t,n,r,i,o)=>{const u=e(t._1);if(u.tag==="Left")return i(t,Zn(u._1,t._2));if(u.tag==="Right")return o(z(u._1.remainder,Qp(t._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);c()},jn=e=>qp(t=>{const n=wg(e)(t);return n.tag==="Just"?kt("Right",{value:e,consumed:e,remainder:n._1}):kt("Left","Expected "+Dc(e))}),Hp=Ot(e=>!0),kc=Bp(At),Lc=(()=>{const e=Ot(t=>t===" "||t===" "||t===`
|
|
8
|
-
`||
|
|
9
|
-
`)),g=
|
|
10
|
-
`||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(f=>r(g=>
|
|
11
|
-
`:_==="t"?" ":_==="r"?"\r":_))))})))})(),
|
|
12
|
-
`);return(
|
|
13
|
-
`&&et!=="\r"&&et!=="#"&&et!=="}")),P=w._3&&!A._3?z(A._1,A._2,!0):A;return d(et=>R(P,d,l,J,(K,B)=>d(q=>h(P._3&&!K._3?z(K._1,K._2,!0):K,s_(zn(bt(Yt.foldr,B)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(t._3&&!s._3?z(s._1,s._2,!0):s,n,r,i,o))))})(),Xp=(e,t,n,r,i)=>{const o=e._1,u=e._2;return t(s=>Ec(z(o,u,!1),t,n,(a,f)=>{const g=a._3;return t(d=>g?r(a,f):gu(e,t,n,r,i))},i))},Br=Ot(e=>e>="0"&&e<="9"),ve=(()=>{const e=Lt(Ot(t=>t==="_"))("'_'");return(t,n,r,i,o)=>n(u=>{const s=(g,d)=>n(l=>{const _=Pe((()=>{const p=Lt(Ot(N=>N==="_"))("'_'"),m=Lt(Ot(N=>N==="-"))("'-'");return(N,J,v,w,L)=>{const b=N._1,S=N._2;return J(A=>Do(z(b,S,!1),J,v,(O,j)=>{const R=O._3;return J(P=>{if(R)return w(O,j);const et=N._1,K=N._2;return J(B=>Br(z(et,K,!1),J,v,(q,M)=>{const C=q._3;return J(I=>{if(C)return w(q,M);const D=N._1,G=N._2;return J(Y=>p(z(D,G,!1),J,v,(X,H)=>{const Q=X._3;return J(W=>Q?w(X,H):m(N,J,v,w,L))},L))})},L))})},L))}})()),h=t._3&&!g._3?z(g._1,g._2,!0):g;return n(p=>_(h,n,r,i,(m,N)=>n(J=>o(h._3&&!m._3?z(m._1,m._2,!0):m,_i(d)+zn(bt(Yt.foldr,N))))))}),a=t._1,f=t._2;return n(g=>Do(z(a,f,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):e(t,n,r,i,s))},s))})})(),Up=Lt((e,t,n,r,i)=>{const o=e._1,u=e._2;return t(s=>gu(z(o,u,!1),t,n,(a,f)=>{const g=a._3;return t(d=>g?r(a,f):ve(e,t,n,r,i))},i))})("frame name (identifier or quoted string)"),Kp=(e,t,n,r,i)=>t(o=>ve(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Cn(f,t,n,r,(d,l)=>t(_=>{const h=Lt((m,N,J,v,w)=>{const L=m._1,b=m._2;return N(S=>jn("->")(z(L,b,!1),N,J,(A,O)=>{const j=A._3;return N(R=>j?v(A,O):jn("<-")(m,N,J,v,w))},w))})("'->' or '<-'"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Cn(w,t,n,r,(b,S)=>t(A=>{const O=Lt(ve)("target node identifier"),j=w._3&&!b._3?z(b._1,b._2,!0):b;return t(R=>O(j,t,n,r,(P,et)=>t(K=>{const B=Pe((M,C,I,D,G)=>{const Y=M._3;return C(X=>C(H=>Cn(M,C,I,(Q,W)=>D(z(Q._1,Q._2,Y),W),(Q,W)=>C(U=>C(F=>{const _t=M._3&&!Q._3?z(Q._1,Q._2,!0):Q;return Xp(_t,C,I,(pt,ft)=>D(z(pt._1,pt._2,Y),ft),(pt,ft)=>C(ht=>G(_t._3&&!pt._3?z(pt._1,pt._2,!0):pt,ft)))})))))}),q=j._3&&!P._3?z(P._1,P._2,!0):P;return t(M=>B(q,t,n,r,(C,I)=>t(D=>(()=>{if(J==="<-"){const Y=En("Token",{from:et,to:s,labels:bt(Yt.foldr,I)});return(X,H,Q,W,U)=>U(X,Y)}const G=En("Token",{from:s,to:et,labels:bt(Yt.foldr,I)});return(Y,X,H,Q,W)=>W(Y,G)})()(q._3&&!C._3?z(C._1,C._2,!0):C,t,n,r,i))))})))})))})))})))}))),Zp=(e,t,n,r,i)=>t(o=>Br(e,t,n,r,(u,s)=>t(a=>{const f=Pe(Br),g=e._3&&!u._3?z(u._1,u._2,!0):u;return t(d=>f(g,t,n,r,(l,_)=>t(h=>{const p=Tf(_i(s)+zn(bt(Yt.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(N,J,v,w,L)=>L(N,m)}if(p.tag==="Nothing")return(m,N,J,v,w)=>w(m,0);c()})()(g._3&&!l._3?z(l._1,l._2,!0):l,t,n,r,i)})))}))),Go=e=>(t,n,r,i,o)=>{const u=t._3;return n(s=>jn(e)(t,n,r,(a,f)=>i(z(a._1,a._2,u),f),(a,f)=>n(g=>{const d=au((()=>{const _=Lt(Ot(p=>p==="_"))("'_'"),h=Lt(Ot(p=>p==="-"))("'-'");return(p,m,N,J,v)=>{const w=p._1,L=p._2;return m(b=>Do(z(w,L,!1),m,N,(S,A)=>{const O=S._3;return m(j=>{if(O)return J(S,A);const R=p._1,P=p._2;return m(et=>Br(z(R,P,!1),m,N,(K,B)=>{const q=K._3;return m(M=>{if(q)return J(K,B);const C=p._1,I=p._2;return m(D=>_(z(C,I,!1),m,N,(G,Y)=>{const X=G._3;return m(H=>X?J(G,Y):h(p,m,N,J,v))},v))})},v))})},v))}})()),l=t._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>{const N=l._3&&!h._3?z(h._1,h._2,!0):h;return n(J=>Re(N,n,r,(v,w)=>i(z(v._1,v._2,u),w),(v,w)=>n(L=>o(N._3&&!v._3?z(v._1,v._2,!0):v,e))))})))})))},jp=(e,t,n,r,i)=>t(o=>Me(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Go("via")(f,t,n,r,(d,l)=>t(_=>{const h=f._3&&!d._3?z(d._1,d._2,!0):d;return t(p=>ve(h,t,n,r,(m,N)=>t(J=>{const v=h._3&&!m._3?z(m._1,m._2,!0):m;return t(w=>Me(v,t,n,r,(L,b)=>t(S=>{const A=v._3&&!L._3?z(L._1,L._2,!0):L;return t(O=>ve(A,t,n,r,(j,R)=>t(P=>i(A._3&&!j._3?z(j._1,j._2,!0):j,{from:N,to:R}))))})))})))})))}))),tr=e=>(t,n,r,i,o)=>{const u=t._3;return n(s=>jn(e)(t,n,r,(a,f)=>i(z(a._1,a._2,u),f),(a,f)=>n(g=>{const d=au((()=>{const _=Lt(Ot(p=>p==="_"))("'_'"),h=Lt(Ot(p=>p==="-"))("'-'");return(p,m,N,J,v)=>{const w=p._1,L=p._2;return m(b=>Do(z(w,L,!1),m,N,(S,A)=>{const O=S._3;return m(j=>{if(O)return J(S,A);const R=p._1,P=p._2;return m(et=>Br(z(R,P,!1),m,N,(K,B)=>{const q=K._3;return m(M=>{if(q)return J(K,B);const C=p._1,I=p._2;return m(D=>_(z(C,I,!1),m,N,(G,Y)=>{const X=G._3;return m(H=>X?J(G,Y):h(p,m,N,J,v))},v))})},v))})},v))}})()),l=t._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?z(h._1,h._2,!0):h,void 0))))})))},tm=(e,t,n,r,i)=>t(o=>tr("+edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Me(w,t,n,r,(b,S)=>t(A=>{const O=Lt(ve)("target node identifier"),j=w._3&&!b._3?z(b._1,b._2,!0):b;return t(R=>O(j,t,n,r,(P,et)=>t(K=>i(j._3&&!P._3?z(P._1,P._2,!0):P,En("AddEdge",{from:J,to:et})))))})))})))})))}))),em=(e,t,n,r,i)=>t(o=>tr("+node")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Fp(w,t,n,r,(b,S)=>t(A=>i(w._3&&!b._3?z(b._1,b._2,!0):b,En("AddNode",{id:J,label:S})))))})))})))}))),nm=(e,t,n,r,i)=>t(o=>tr("-edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Me(w,t,n,r,(b,S)=>t(A=>{const O=Lt(ve)("target node identifier"),j=w._3&&!b._3?z(b._1,b._2,!0):b;return t(R=>O(j,t,n,r,(P,et)=>t(K=>i(j._3&&!P._3?z(P._1,P._2,!0):P,En("DelEdge",{from:J,to:et})))))})))})))})))}))),rm=(e,t,n,r,i)=>t(o=>tr("-node")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=Pe((b,S,A,O,j)=>{const R=b._3;return jp(b,S,A,(P,et)=>O(z(P._1,P._2,R),et),j)}),L=p._3&&!N._3?z(N._1,N._2,!0):N;return t(b=>w(L,t,n,r,(S,A)=>t(O=>i(L._3&&!S._3?z(S._1,S._2,!0):S,En("DelNode",{id:J,via:bt(Yt.foldr,A)})))))})))})))}))),om=(e,t,n,r,i)=>t(o=>tr("~edge")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Me(f,t,n,r,(d,l)=>t(_=>{const h=Lt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Me(w,t,n,r,(b,S)=>t(A=>{const O=Lt(ve)("target node identifier"),j=w._3&&!b._3?z(b._1,b._2,!0):b;return t(R=>O(j,t,n,r,(P,et)=>t(K=>{const B=j._3&&!P._3?z(P._1,P._2,!0):P;return t(q=>Re(B,t,n,r,(M,C)=>t(I=>{const D=Lt(jn("->"))("'->'"),G=B._3&&!M._3?z(M._1,M._2,!0):M;return t(Y=>D(G,t,n,r,(X,H)=>t(Q=>{const W=G._3&&!X._3?z(X._1,X._2,!0):X;return t(U=>Re(W,t,n,r,(F,_t)=>t(pt=>{const ft=Lt(ve)("new source node identifier"),ht=W._3&&!F._3?z(F._1,F._2,!0):F;return t(wt=>ft(ht,t,n,r,(It,dt)=>t(Mt=>{const mt=ht._3&&!It._3?z(It._1,It._2,!0):It;return t(gt=>Me(mt,t,n,r,(rt,nt)=>t(st=>{const yt=Lt(ve)("new target node identifier"),Jt=mt._3&&!rt._3?z(rt._1,rt._2,!0):rt;return t(Ct=>yt(Jt,t,n,r,($t,re)=>t(Ve=>i(Jt._3&&!$t._3?z($t._1,$t._2,!0):$t,En("RepointEdge",{from:J,to:et,newFrom:dt,newTo:re})))))})))})))})))})))})))})))})))})))})))}))),im=(e,t,n,r,i)=>t(o=>vc(e,t,n,r,(u,s)=>t(a=>{const f=Lt(kc([em,rm,om,tm,nm,Kp]))("statement (+node, -node, +edge, -edge, ~edge, or 'a -> b')"),g=e._3&&!u._3?z(u._1,u._2,!0):u;return t(d=>f(g,t,n,r,(l,_)=>t(h=>i(g._3&&!l._3?z(l._1,l._2,!0):l,uu("Leaf",{op:_,line:s.line,column:s.column})))))}))),um=(e,t,n,r,i)=>t(o=>tr("seed")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Cn(f,t,n,r,(d,l)=>t(_=>{const h=Lt(Zp)("integer (seed value)"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return t(m=>h(p,t,n,r,(N,J)=>t(v=>{const w=p._3&&!N._3?z(N._1,N._2,!0):N;return t(L=>Re(w,t,n,r,(b,S)=>t(A=>i(w._3&&!b._3?z(b._1,b._2,!0):b,J))))})))})))}))),_u=$p((()=>{const e=Lt(Ot(t=>t==="{"))("'{'");return(t,n,r,i,o)=>n(u=>n(s=>e(t,n,r,i,(a,f)=>n(g=>n(d=>{const l=t._3&&!a._3?z(a._1,a._2,!0):a;return Re(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())(Lt((()=>{const e=Lt(Ot(t=>t==="}"))("'}'");return(t,n,r,i,o)=>n(u=>n(s=>Re(t,n,r,i,(a,f)=>n(g=>n(d=>{const l=t._3&&!a._3?z(a._1,a._2,!0):a;return e(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),sm=(e,t,n,r,i)=>t(o=>Go("seq")(e,t,n,r,(u,s)=>t(a=>_u(du(yc))(e._3&&!u._3?z(u._1,u._2,!0):u,t,n,r,i)))),am=(e,t,n,r,i)=>t(o=>Go("par")(e,t,n,r,(u,s)=>t(a=>_u(du(gp))(e._3&&!u._3?z(u._1,u._2,!0):u,t,n,r,i)))),du=e=>{const t=Pe(cm());return(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,f)=>r(g=>u(n._3&&!a._3?z(a._1,a._2,!0):a,e(bt(Yt.foldr,f))))))},cm=Rc(()=>{const e=au(Lt(Ot(t=>t==="}"))("'}'"));return(t,n,r,i,o)=>n(u=>{const s=t._3;return n(a=>n(f=>Re(t,n,r,(g,d)=>i(z(g._1,g._2,s),d),(g,d)=>n(l=>n(_=>{const h=t._3&&!g._3?z(g._1,g._2,!0):g;return e(h,n,r,(p,m)=>i(z(p._1,p._2,s),m),(p,m)=>n(N=>{const J=h._3&&!p._3?z(p._1,p._2,!0):p;return n(v=>{const w=kc([(b,S,A,O,j)=>{const R=b._3;return am(b,S,A,(P,et)=>O(z(P._1,P._2,R),et),j)},(b,S,A,O,j)=>{const R=b._3;return sm(b,S,A,(P,et)=>O(z(P._1,P._2,R),et),j)},im]),L=t._3&&!J._3?z(J._1,J._2,!0):J;return n(b=>w(L,n,r,i,(S,A)=>n(O=>{const j=L._3&&!S._3?z(S._1,S._2,!0):S;return n(R=>Cn(j,n,r,i,(P,et)=>n(K=>{const B=j._3&&!P._3?z(P._1,P._2,!0):P;return n(q=>Yp(B,n,r,i,(M,C)=>n(I=>o(B._3&&!M._3?z(M._1,M._2,!0):M,A))))})))})))})}))})))))})}),fm=(e,t,n,r,i)=>t(o=>Go("frame")(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>Up(f,t,n,r,(d,l)=>t(_=>{const h=f._3&&!d._3?z(d._1,d._2,!0):d;return t(p=>Re(h,t,n,r,(m,N)=>t(J=>{const v=_u(du(yc)),w=h._3&&!m._3?z(m._1,m._2,!0):m;return t(L=>v(w,t,n,r,(b,S)=>t(A=>{const O=w._3&&!b._3?z(b._1,b._2,!0):b;return t(j=>Re(O,t,n,r,(R,P)=>t(et=>i(O._3&&!R._3?z(R._1,R._2,!0):R,{name:E("Just",l),ops:S}))))})))})))})))}))),gm=(e,t,n,r,i)=>t(o=>Re(e,t,n,r,(u,s)=>t(a=>{const f=e._3&&!u._3?z(u._1,u._2,!0):u;return t(g=>{const d=(h,p)=>t(m=>{const N=Pe(fm),J=f._3&&!h._3?z(h._1,h._2,!0):h;return t(v=>N(J,t,n,r,(w,L)=>t(b=>{const S=J._3&&!w._3?z(w._1,w._2,!0):w;return t(A=>Re(S,t,n,r,(O,j)=>t(R=>{const P=Lt(bc)("'frame' or end of input"),et=S._3&&!O._3?z(O._1,O._2,!0):O;return t(K=>P(et,t,n,r,(B,q)=>t(M=>i(et._3&&!B._3?z(B._1,B._2,!0):B,{seed:(()=>{if(p.tag==="Just")return p._1;if(p.tag==="Nothing")return 0;c()})(),frames:bt(Yt.foldr,L)}))))})))})))}),l=f._1,_=f._2;return t(h=>t(p=>um(z(l,_,!1),t,n,(m,N)=>{const J=m._3;return t(v=>J?r(m,N):d(f,T))},(m,N)=>t(J=>d(m,E("Just",N))))))})}))),_m=e=>{const t=Gp(e)(gm);if(t.tag==="Left")return kt("Left",{msg:t._1._1,line:t._1._2.line,column:t._1._2.column});if(t.tag==="Right")return kt("Right",t._1);c()},dm=e=>{const t=_m(e);if(t.tag==="Left")return kt("Left",t._1.msg);if(t.tag==="Right")return kt("Right",t._1);c()};function lu(e,t,n,r){if(typeof window<"u"){var i=window[n];if(i!=null&&r instanceof i)return t(r)}for(var o=r;o!=null;){var u=Object.getPrototypeOf(o),s=u.constructor.name;if(s===n)return t(r);if(s==="Object")return e;o=u}return e}function Mo(e){return function(t){return function(n){return function(){n.setAttribute(e,t)}}}}function lm(e){return function(t){return function(){t.textContent=e}}}function hm(e){return function(){return function(t){return e(t)()}}}function pm(e){return function(t){return function(n){return function(r){return function(){return r.addEventListener(e,t,n)}}}}}const mm=function(){return window};function ym(e){return function(t){return function(){t.value=e}}}function Jm(e){return function(){return e.valueAsNumber}}function Nm(e){return function(){return e.value}}function xm(e){return function(t){return function(){return t.requestAnimationFrame(e)}}}const vm=e=>e,Tm=e=>()=>e.clientWidth||0,wm=()=>window.devicePixelRatio||1,hu=(e,t)=>{t.innerHTML=e},bm=(e,t,n)=>{e.style.setProperty(t,n)},km=(e,t)=>e.querySelector(`[data-mg="${t}"]`),Lm=e=>t=>e===t,Em=e=>e,Cm=At.foldMap(If),Cc=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},Sm=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},Pm=Em("CanvasRenderer"),Rm=e=>t=>{const n=e-t*ct(ur(Gu(e/t)));return t<=0?0:n<0?n+t:n},Im=e=>t=>{const n=N0(e);return()=>{const r=n(),i=Z_(H_)(e)(b0(r)(e));if(i.tag==="Left")return Bu("[markgraf] precompute failed")();if(i.tag==="Right")return t(i._1)();c()}},Dm=e=>y(t=>n=>{const r=e(n);return()=>(t(),r())})(()=>{}),Gm=`
|
|
1
|
+
var F2=(function(Wi){"use strict";function hf(t){let e=0,n;return()=>{if(e===2)return n;if(e===1)throw new Error("Binding demanded before initialized");return e=1,n=t(),e=2,n}}function c(){throw new Error("Failed pattern match")}function Fn(t,e){return e>0?Math.floor(t/e):e<0?-Math.floor(t/-e):0}const pe=t=>e=>t,O=function(t){return function(e){for(var n=e.length,r=new Array(n),i=0;i<n;i++)r[i]=t(e[i]);return r}},pf={map:O},Fu=t=>t,St=typeof Array.prototype.flatMap=="function"?function(t){return function(e){return t.flatMap(e)}}:function(t){return function(e){for(var n=[],r=t.length,i=0;i<r;i++)for(var o=e(t[i]),u=o.length,s=0;s<u;s++)n.push(o[s]);return n}},fe=function(t){return t.toString()},Bu=function(t){var e=t.toString();return isNaN(e+".0")?e:e+".0"},mf=function(t){var e=t.length;return'"'+t.replace(/[\0-\x1F\x7F"\\]/g,function(n,r){switch(n){case'"':case"\\":return"\\"+n;case"\x07":return"\\a";case"\b":return"\\b";case"\f":return"\\f";case`
|
|
2
|
+
`:return"\\n";case"\r":return"\\r";case" ":return"\\t";case"\v":return"\\v"}var i=r+1,o=i<e&&t[i]>="0"&&t[i]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+o})+'"'},Vi=t=>t,me=Vi("LT"),Ne=Vi("GT"),we=Vi("EQ"),L=(t,e)=>({tag:t,_1:e}),T=L("Nothing"),jt=t=>L("Just",t),Mu=t=>{if(t.tag==="Nothing")return!0;if(t.tag==="Just")return!1;c()},Nf=t=>{if(t.tag==="Nothing")return!1;if(t.tag==="Just")return!0;c()},Et=(t,e)=>({tag:t,_1:e}),yf=t=>Et("Right",t),Jf={map:t=>e=>{if(e.tag==="Left")return Et("Left",e._1);if(e.tag==="Right")return Et("Right",t(e._1));c()}},$u={apply:t=>e=>{if(t.tag==="Left")return Et("Left",t._1);if(t.tag==="Right"){if(e.tag==="Left")return Et("Left",e._1);if(e.tag==="Right")return Et("Right",t._1(e._1))}c()},Functor0:()=>Jf},xf={bind:t=>{if(t.tag==="Left"){const e=t._1;return n=>Et("Left",e)}if(t.tag==="Right"){const e=t._1;return n=>n(e)}c()},Apply0:()=>$u},Tf={pure:yf,Apply0:()=>$u},vf={Applicative0:()=>Tf,Bind1:()=>xf},wf=t=>t,Lf={map:t=>e=>t(e)},zu={apply:t=>e=>t(e),Functor0:()=>Lf},bf={bind:t=>e=>e(t),Apply0:()=>zu},Ef={pure:wf,Apply0:()=>zu},dn={Applicative0:()=>Ef,Bind1:()=>bf},kf=function(t){return function(){return t}},Gf={apply:t=>e=>()=>{const n=t(),r=e();return Ui.pure(n(r))()},Functor0:()=>Cf},Ui={pure:kf,Apply0:()=>Gf},Cf={map:t=>e=>()=>{const n=e();return t(n)}},fr=(t,e)=>({tag:t,_1:e}),Ou=t=>fr("Loop",t),Sf={tailRecM:t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="Loop"){r=t(u._1);continue}if(u.tag==="Done"){i=!1,o=u._1;continue}c()}return o};return n=>e(t(n))},Monad0:()=>dn},Qf=(function(t){return function(e){return function(n){return function(){return t(e,n)}}}})(function(t,e){return e.push(t)}),Pf=(t,e)=>({tag:"Iterator",_1:t,_2:e}),Df=t=>e=>n=>()=>{let r=!1;const i=e._2;for(;!r;){const o=i.value,u=e._1(o);if(u.tag==="Just"&&t(u._1)){n.push(u._1),e._2.value;const s=e._2.value;e._2.value=s+1|0;continue}r=!0}},Af=t=>e=>()=>{let n=!1;const r=t._2;for(;!n;){const i=r.value,o=r.value;r.value=o+1|0;const u=t._1(i);if(u.tag==="Just"){e(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}c()}},gr=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=i-1;o>=0;o--)r=t(n[o])(r);return r}}},J=function(t){return function(e){return function(n){for(var r=e,i=n.length,o=0;o<i;o++)r=t(r)(n[o]);return r}}},If=t=>{const e=t.Apply0();return n=>r=>n.foldr(i=>{const o=r(i);return u=>e.apply(e.Functor0().map(s=>Fu)(o))(u)})(t.pure())},Dt={foldr:gr,foldl:J,foldMap:t=>{const e=t.mempty;return n=>Dt.foldr(r=>i=>t.Semigroup0().append(n(r))(i))(e)}},w=(t,e)=>({tag:"Tuple",_1:t,_2:e}),Bn=t=>e=>w(t,e),Yr=t=>t._2,Xr=t=>t._1,At=function(t){return function(e){for(var n=e.length,r=Array(n),i=0;i<n;i++)r[i]=t(i)(e[i]);return r}};var Yi=function(t){return function(e){return t===e}};const Rf=Yi,Ff=Yi,Xi=Yi,Bf=function(t){return function(e){return function(n){if(e.length!==n.length)return!1;for(var r=0;r<e.length;r++)if(!t(e[r])(n[r]))return!1;return!0}}},ze={eq:Xi},Mf={eq:Ff},_r={eq:Rf};var Ki=function(t){return function(e){return function(n){return function(r){return function(i){return r<i?t:r===i?e:n}}}}};const $f=Ki,zf=Ki,C={compare:Ki(me)(we)(Ne),Eq0:()=>ze},dt={compare:zf(me)(we)(Ne),Eq0:()=>Mf},nt={compare:$f(me)(we)(Ne),Eq0:()=>_r},qu=function(t){return t},Of=(function(){function t(i){return[i]}function e(i){return function(o){return[i,o]}}function n(i){return function(o){return function(u){return[i,o,u]}}}function r(i){return function(o){return i.concat(o)}}return function(i){return function(o){return function(u){return function(s){return function(a){function f(g,d){switch(d-g){case 0:return u([]);case 1:return o(t)(s(a[g]));case 2:return i(o(e)(s(a[g])))(s(a[g+1]));case 3:return i(i(o(n)(s(a[g])))(s(a[g+1])))(s(a[g+2]));default:var l=g+Math.floor((d-g)/4)*2;return i(o(r)(f(g,l)))(f(l,d))}}return f(0,a.length)}}}}}})(),qf=t=>t,dr={traverse:t=>{const e=t.Apply0();return Of(e.apply)(e.Functor0().map)(t.pure)},sequence:t=>dr.traverse(t)(qf),Functor0:()=>pf,Foldable1:()=>Dt},Ht=function(t,e){for(var n=t>e?-1:1,r=new Array(n*(e-t)+1),i=t,o=0;i!==e;)r[o++]=i,i+=n;return r[o]=i,r};var Hf=function(t,e){if(t<1)return[];var n=new Array(t);return n.fill(e)},Wf=function(t,e){for(var n=[],r=0,i=0;i<t;i++)n[r++]=e;return n};const Vf=typeof Array.prototype.fill=="function"?Hf:Wf,bt=(function(){function t(i,o){this.head=i,this.tail=o}var e={};function n(i){return function(o){return new t(i,o)}}function r(i){for(var o=[],u=0,s=i;s!==e;)o[u++]=s.head,s=s.tail;return o}return function(i,o){return r(i(n)(e)(o))}})(),Bt=function(t,e,n){return n.length===0?t({}):e(n[0])(n.slice(1))},Uf=function(t,e,n,r){for(var i=0;i<r.length;i++){var o=n(r[i]);if(e(o))return o}return t},Mn=function(t,e,n,r){for(var i=0,o=r.length;i<o;i++)if(n(r[i]))return t(i);return e},Yf=function(t,e,n,r){for(var i=r.length-1;i>=0;i--)if(n(r[i]))return t(i);return e},Xf=function(t,e,n,r,i){if(n<0||n>i.length)return e;var o=i.slice();return o.splice(n,0,r),t(o)},Hu=function(t,e,n,r){if(n<0||n>=r.length)return e;var i=r.slice();return i.splice(n,1),t(i)},$n=function(t,e,n,r,i){if(n<0||n>=i.length)return e;var o=i.slice();return o[n]=r,t(o)},de=function(t){return t.slice().reverse()},Le=function(t){if(t.length<=1e4)return Array.prototype.concat.apply([],t);for(var e=[],n=0,r=t.length;n<r;n++)for(var i=t[n],o=0,u=i.length;o<u;o++)e.push(i[o]);return e},ct=function(t,e){return e.filter(t)},Kf=(function(){function t(e,n,r,i,o,u){var s,a,f,g,d,l,_;for(s=o+(u-o>>1),s-o>1&&t(e,n,i,r,o,s),u-s>1&&t(e,n,i,r,s,u),a=o,f=s,g=o;a<s&&f<u;)d=i[a],l=i[f],_=n(e(d)(l)),_>0?(r[g++]=l,++f):(r[g++]=d,++a);for(;a<s;)r[g++]=i[a++];for(;f<u;)r[g++]=i[f++]}return function(e,n,r){var i;return r.length<2?r:(i=r.slice(0),t(e,n,i,r.slice(0),0,r.length),i)}})(),It=function(t,e,n){return n.slice(t,e)},ye=function(t,e,n){for(var r=e.length<n.length?e.length:n.length,i=new Array(r),o=0;o<r;o++)i[o]=t(e[o])(n[o]);return i},Ze=function(t,e){for(var n=e.length,r=0;r<n;r++)if(t(e[r]))return!0;return!1},Wu=function(t,e){for(var n=e.length,r=0;r<n;r++)if(!t(e[r]))return!1;return!0},vt=t=>e=>Kf(t,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;c()},e),jf=t=>e=>vt(n=>r=>t.compare(e(n))(e(r))),oe=t=>e=>(()=>{const n=Qf(e);return()=>{const r=[...t];return n(r)(),r}})()(),Vu=t=>{if(t.length===0)return t.length-1|0,T;const e=t.length-1|0;return e>=0&&e<t.length?L("Just",{init:It(0,t.length-1|0,t),last:t[e]}):T},Zf=t=>e=>n=>t>=0&&t<n.length?$n(jt,T,t,e(n[t]),n):T,Tn=t=>e=>{const n=(r=>{let i=r,o=!0,u;for(;o;){const s=i;if(s>=0&&s<e.length){if(t(e[s])){i=s+1|0;continue}o=!1,u=L("Just",s);continue}o=!1,u=T}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:e}:{init:It(0,n._1,e),rest:It(n._1,e.length,e)};if(n.tag==="Nothing")return{init:e,rest:[]};c()},zn=t=>e=>{const n=vt(r=>i=>t(r._2)(i._2))(At(Bn)(e));return 0<n.length?O(Yr)(jf(nt)(Xr)((()=>{const r=[n[0]];for(const i of n){const o=t((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;c()})())(i._2);(o==="LT"||o==="GT"||o!=="EQ")&&r.push(i)}return r})())):[]},tg=t=>e=>{const n=[],r=Pf(i=>i>=0&&i<e.length?L("Just",e[i]):T,{value:0});return Af(r)(i=>()=>{const o=[];o.push(i),Df(t(i))(r)(o)(),n.push(o)})(),n},ge=t=>e=>{const n=Mn(jt,T,t,e);return n.tag==="Just"?L("Just",e[n._1]):T},Uu=t=>e=>ct(t,e),ke=t=>e=>n=>{const r=Mn(jt,T,i=>t.eq(i)(e),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;c()},Yu=t=>e=>St(e)(t),xt=t=>Yu(e=>{const n=t(e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];c()}),Xu=isFinite;function eg(t,e,n,r){var i=parseFloat(t);return e(i)?n(i):r}const On=Math.abs,ji=Math.ceil,Zi=Math.cos,Ku=Math.exp,ju=Math.floor,to=function(t){return function(e){return Math.pow(t,e)}},Zu=Math.round,eo=Math.sin,qn=Math.sqrt,ng=function(t){return function(e){return function(n){return(n|0)===n?t(n):e}}},ot=function(t){return t},rg=(function(t){return function(e){return function(n){var r;n<11?r="[0-"+(n-1).toString()+"]":n===11?r="[0-9a]":r="[0-9a-"+String.fromCharCode(86+n)+"]";var i=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(o){if(i.test(o)){var u=parseInt(o,n);return(u|0)===u?t(u):e}else return e}}}})(jt)(T)(10),ts=ng(jt)(T),vn=t=>{if(!Xu(t))return 0;if(t>=ot(2147483647))return 2147483647;if(t<=ot(-2147483648))return-2147483648;const e=ts(t);if(e.tag==="Nothing")return 0;if(e.tag==="Just")return e._1;c()},Mt=(t,e,n)=>({tag:t,_1:e,_2:n}),qt=Mt("Nil"),Wt={foldr:t=>e=>{const n=Wt.foldl(i=>o=>t(o)(i))(e),r=(i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=Mt("Cons",d._1,g),s=d._2;continue}c()}return f})(qt);return i=>n(r(i))},foldl:t=>e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=t(s)(a._1),i=a._2;continue}c()}return u},foldMap:t=>{const e=t.mempty;return n=>Wt.foldl(r=>{const i=t.Semigroup0().append(r);return o=>i(n(o))})(e)}},ig=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);u.push(n(a));var f=r(a);if(t(f))return u;s=e(f)}}}}}}},og=t=>{if(t.tag==="Just")return t._1;c()},ug={unfoldr1:ig(Mu)(og)(Xr)(Yr)},sg=function(t){return function(e){return function(n){return function(r){return function(i){return function(o){for(var u=[],s=o;;){var a=i(s);if(t(a))return u;var f=e(a);u.push(n(f)),s=r(f)}}}}}}},ag=t=>{if(t.tag==="Just")return t._1;c()},Re={unfoldr:sg(Mu)(ag)(Xr)(Yr),Unfoldable10:()=>ug},$t=(t,e,n,r,i,o,u)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u}),Fe=(t,e,n,r)=>({tag:t,_1:e,_2:n,_3:r}),Kr=(t,e,n)=>({tag:"Split",_1:t,_2:e,_3:n}),es=(t,e,n)=>({tag:"SplitLast",_1:t,_2:e,_3:n}),M=$t("Leaf"),wn=Fe("IterLeaf"),te=(t,e,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return $t("Node",1,1,t,e,n,r);if(r.tag==="Node")return $t("Node",1+r._1|0,1+r._2|0,t,e,n,r);c()}if(n.tag==="Node"){if(r.tag==="Leaf")return $t("Node",1+n._1|0,1+n._2|0,t,e,n,r);if(r.tag==="Node")return $t("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,t,e,n,r)}c()},Je=(t,e,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?$t("Node",1,1,t,e,M,M):r.tag==="Node"&&r._1>1?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?te(r._5._3,r._5._4,te(t,e,n,r._5._5),te(r._3,r._4,r._5._6,r._6)):te(r._3,r._4,te(t,e,n,r._5),r._6):te(t,e,n,r);if(n.tag==="Node")return r.tag==="Node"?r._1>(n._1+1|0)?r._5.tag==="Node"&&(()=>{if(r._6.tag==="Leaf")return r._5._1>0;if(r._6.tag==="Node")return r._5._1>r._6._1;c()})()?te(r._5._3,r._5._4,te(t,e,n,r._5._5),te(r._3,r._4,r._5._6,r._6)):te(r._3,r._4,te(t,e,n,r._5),r._6):n._1>(r._1+1|0)?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?te(n._6._3,n._6._4,te(n._3,n._4,n._5,n._6._5),te(t,e,n._6._6,r)):te(n._3,n._4,n._5,te(t,e,n._6,r)):te(t,e,n,r):r.tag==="Leaf"&&n._1>1?n._6.tag==="Node"&&(()=>{if(n._5.tag==="Leaf")return 0<=n._6._1;if(n._5.tag==="Node")return n._5._1<=n._6._1;c()})()?te(n._6._3,n._6._4,te(n._3,n._4,n._5,n._6._5),te(t,e,n._6._6,r)):te(n._3,n._4,n._5,te(t,e,n._6,r)):te(t,e,n,r);c()},Hn=(t,e,n)=>{if(n.tag==="Leaf")return Kr(T,M,M);if(n.tag==="Node"){const r=t(e)(n._3);if(r==="LT"){const i=Hn(t,e,n._5);return Kr(i._1,i._2,Je(n._3,n._4,i._3,n._6))}if(r==="GT"){const i=Hn(t,e,n._6);return Kr(i._1,Je(n._3,n._4,n._5,i._2),i._3)}if(r==="EQ")return Kr(L("Just",n._4),n._5,n._6)}c()},ns=(t,e,n,r)=>{if(r.tag==="Leaf")return es(t,e,n);if(r.tag==="Node"){const i=ns(r._3,r._4,r._5,r._6);return es(i._1,i._2,Je(t,e,n,i._3))}c()},lr=(t,e)=>{if(t.tag==="Leaf")return e;if(t.tag==="Node"){const n=ns(t._3,t._4,t._5,t._6);return Je(n._1,n._2,n._3,e)}c()},tn=(t,e,n)=>{if(e.tag==="Leaf")return M;if(n.tag==="Leaf")return e;if(n.tag==="Node"){const r=Hn(t,n._3,e);return lr(tn(t,r._2,n._5),tn(t,r._3,n._6))}c()},jr=(t,e,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return M;if(r.tag==="Node"){const i=Hn(t,r._3,n),o=jr(t,e,i._2,r._5),u=jr(t,e,i._3,r._6);if(i._1.tag==="Just")return Je(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return lr(o,u)}c()},xe=(t,e,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const i=Hn(t,r._3,n),o=xe(t,e,i._2,r._5),u=xe(t,e,i._3,r._6);if(i._1.tag==="Just")return Je(r._3,e(i._1._1)(r._4),o,u);if(i._1.tag==="Nothing")return Je(r._3,r._4,o,u)}c()},cg=t=>e=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node"){const i=e(r._3)(r._4);if(i.tag==="Just")return Je(r._3,i._1,n(r._5),n(r._6));if(i.tag==="Nothing")return lr(n(r._5),n(r._6))}c()};return n},Ln=(t=>e=>n=>{let r=n,i=!0,o;for(;i;){const u=r;if(u.tag==="IterLeaf"){i=!1,o=e();continue}if(u.tag==="IterEmit"){i=!1,o=t(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){f=Fe("IterEmit",h._3,h._4,_),g=h._5;continue}f=Fe("IterEmit",h._3,h._4,Fe("IterNode",h._6,_)),g=h._5;continue}c()}return l})(u._2)(u._1);continue}c()}return o})((t,e,n)=>L("Just",w(w(t,e),n)))(t=>T),Tt=t=>e=>n=>r=>{const i=o=>{if(o.tag==="Leaf")return $t("Node",1,1,n,r,M,M);if(o.tag==="Node"){const u=t.compare(n)(o._3);if(u==="LT")return Je(o._3,o._4,i(o._5),o._6);if(u==="GT")return Je(o._3,o._4,o._5,i(o._6));if(u==="EQ")return $t("Node",o._1,o._2,n,e(o._4)(r),o._5,o._6)}c()};return i},K=t=>e=>n=>{const r=i=>{if(i.tag==="Leaf")return $t("Node",1,1,e,n,M,M);if(i.tag==="Node"){const o=t.compare(e)(i._3);if(o==="LT")return Je(i._3,i._4,r(i._5),i._6);if(o==="GT")return Je(i._3,i._4,i._5,r(i._6));if(o==="EQ")return $t("Node",i._1,i._2,e,n,i._5,i._6)}c()};return r},Vt=t=>e=>e.foldl(n=>r=>K(t)(r._1)(r._2)(n))(M),hr=t=>e=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node"){const i=t.compare(e)(r._3);if(i==="LT")return Je(r._3,r._4,n(r._5),r._6);if(i==="GT")return Je(r._3,r._4,r._5,n(r._6));if(i==="EQ")return lr(r._5,r._6)}c()};return n},fg=t=>{const e=t.compare;return n=>r=>i=>{const o=Hn(e,r,i),u=n(o._1);if(u.tag==="Nothing")return lr(o._2,o._3);if(u.tag==="Just")return Je(r,u._1,o._2,o._3);c()}},Zt=function(t){return function(e){return t+e|0}},Wn=function(t){return function(e){return t+e}},no=function(t){return function(e){if(e===0)return 0;var n=Math.abs(e);return(t%n+n)%n}},gg=function(t){return function(e){return t+e}},ue=function(t){return function(e){return t.length===0?e:e.length===0?t:t.concat(e)}},_g={append:gg},dg={mempty:"",Semigroup0:()=>_g},lg=null;function hg(t,e,n){return t==null?e:n(t)}function R2(t){return t}function ro(t){return function(e){return function(n){return t.apply(n,[e])}}}const pg=ro(Number.prototype.toPrecision),mg=ro(Number.prototype.toFixed),Ng=ro(Number.prototype.toExponential),pr=(t,e)=>({tag:t,_1:e}),mr=t=>e=>n=>{const r=nt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=nt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},Nr=t=>{if(t.tag==="Precision")return pg(t._1);if(t.tag==="Fixed")return mg(t._1);if(t.tag==="Exponential")return Ng(t._1);c()},rs=function(t){return function(){console.log(t)}};function is(){return Date.now()}function yg(t){return function(){return t.getContext("2d")}}function Jg(t){return function(){return t.width}}function xg(t){return function(){return t.height}}function Tg(t){return function(e){return function(){t.width=e}}}function vg(t){return function(e){return function(){t.height=e}}}function io(t){return function(e){return function(){t.lineWidth=e}}}function wg(t){return function(e){return function(){t.fillStyle=e}}}function Lg(t){return function(e){return function(){t.strokeStyle=e}}}function oo(t){return function(e){return function(){t.lineCap=e}}}function uo(t){return function(e){return function(){t.lineJoin=e}}}function bg(t){return function(e){return function(){t.globalCompositeOperation=e}}}function Eg(t){return function(e){return function(){t.globalAlpha=e}}}function os(t){return function(){t.beginPath()}}function so(t){return function(){t.stroke()}}function ao(t){return function(){t.fill()}}function kg(t){return function(){t.clip()}}function Gg(t){return function(e){return function(n){return function(){t.lineTo(e,n)}}}}function Cg(t){return function(e){return function(n){return function(){t.moveTo(e,n)}}}}function Sg(t){return function(){t.closePath()}}function Qg(t){return function(e){return function(){t.fillRect(e.x,e.y,e.width,e.height)}}}function Pg(t){return function(e){return function(){t.clearRect(e.x,e.y,e.width,e.height)}}}function co(t){return function(e){return function(){t.scale(e.scaleX,e.scaleY)}}}function us(t){return function(e){return function(){t.translate(e.translateX,e.translateY)}}}function Dg(t){return function(e){return function(){t.textAlign=e}}}function Ag(t){return function(e){return function(){t.textBaseline=e}}}function Ig(t){return function(e){return function(){t.font=e}}}function Rg(t){return function(e){return function(n){return function(r){return function(){t.fillText(e,n,r)}}}}}function yr(t){return function(){t.save()}}function Jr(t){return function(){t.restore()}}function Fg(t){return function(e){return function(){t.quadraticCurveTo(e.cpx,e.cpy,e.x,e.y)}}}function Bg(t){return function(e){return function(){t.bezierCurveTo(e.cp1x,e.cp1y,e.cp2x,e.cp2y,e.x,e.y)}}}const ss=t=>t,fo=t=>t,go=t=>t,_o=t=>t,Zr=t=>t,Mg=Zr("BaselineTop"),$g=Zr("BaselineMiddle"),zg=Zr("BaselineAlphabetic"),Og=Zr("BaselineBottom"),qg=_o("AlignLeft"),Hg=_o("AlignRight"),Wg=_o("AlignCenter"),lo=go("BevelJoin"),ti=go("RoundJoin"),ho=go("MiterJoin"),po=fo("Round"),mo=fo("Square"),No=fo("Butt"),Vg=ss("SourceOver"),Ug=ss("Difference"),Yg=t=>e=>Ag(t)((()=>{if(e==="BaselineTop")return"top";if(e==="BaselineHanging")return"hanging";if(e==="BaselineMiddle")return"middle";if(e==="BaselineAlphabetic")return"alphabetic";if(e==="BaselineIdeographic")return"ideographic";if(e==="BaselineBottom")return"bottom";c()})()),Xg=t=>e=>Dg(t)((()=>{if(e==="AlignLeft")return"left";if(e==="AlignRight")return"right";if(e==="AlignCenter")return"center";if(e==="AlignStart")return"start";if(e==="AlignEnd")return"end";c()})()),ei=t=>e=>{if(e==="BevelJoin")return uo(t)("bevel");if(e==="RoundJoin")return uo(t)("round");if(e==="MiterJoin")return uo(t)("miter");c()},yo=t=>e=>{if(e==="Round")return oo(t)("round");if(e==="Square")return oo(t)("square");if(e==="Butt")return oo(t)("butt");c()},as=t=>e=>bg(t)((()=>{if(e==="SourceOver")return"source-over";if(e==="SourceIn")return"source-in";if(e==="SourceOut")return"source-out";if(e==="SourceAtop")return"source-atop";if(e==="DestinationOver")return"destination-over";if(e==="DestinationIn")return"destination-in";if(e==="DestinationOut")return"destination-out";if(e==="DestinationAtop")return"destination-atop";if(e==="Lighter")return"lighter";if(e==="Copy")return"copy";if(e==="Xor")return"xor";if(e==="Multiply")return"multiply";if(e==="Screen")return"screen";if(e==="Overlay")return"overlay";if(e==="Darken")return"darken";if(e==="Lighten")return"lighten";if(e==="ColorDodge")return"color-dodge";if(e==="ColorBurn")return"color-burn";if(e==="HardLight")return"hard-light";if(e==="SoftLight")return"soft-light";if(e==="Difference")return"difference";if(e==="Exclusion")return"exclusion";if(e==="Hue")return"hue";if(e==="Saturation")return"saturation";if(e==="Color")return"color";if(e==="Luminosity")return"luminosity";c()})()),Ge={foldr:t=>e=>{const n=Wt.foldr(t)(e);return r=>n((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,Mt("Cons",o._3,i(o._6,u)));c()};return i(r,qt)})())}},ni=t=>t,Kg=t=>t,jg=ni("Linear"),Zg=ni("EaseInOutQuad"),t_=ni("EaseOutExpo"),e_=ni("SpringBouncy"),xr=t=>e=>n=>{const r=qn(1-e*e),i=t*r;return 1-Ku(-e*t*n)*(Zi(i*n)+e/r*eo(i*n))},n_=t=>{const e=dt.compare(0)(t),n=(()=>{if(e==="LT")return t;if(e==="EQ"||e==="GT")return 0;c()})(),r=dt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;c()},Jo=t=>e=>(()=>{if(t==="Linear")return Kg;if(t==="EaseInQuad")return n=>n*n;if(t==="EaseOutQuad")return n=>1-(1-n)*(1-n);if(t==="EaseInOutQuad")return n=>n<.5?2*n*n:1-2*(1-n)*(1-n);if(t==="EaseInCubic")return n=>n*n*n;if(t==="EaseOutCubic")return n=>1-(1-n)*(1-n)*(1-n);if(t==="EaseInOutCubic")return n=>n<.5?4*n*n*n:1-(-2*n+2)*(-2*n+2)*(-2*n+2)/2;if(t==="EaseOutExpo")return n=>n>=1?1:1-to(2)(-10*n);if(t==="Spring")return n=>1-(1+6*n)*Ku(-6*n);if(t==="SpringBouncy")return xr(6)(.7);c()})()(n_(e)),cs=J(Wn)(0),r_=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},fs=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},gs=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},_s=t=>e=>{const n=ye(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,f=s.x-u.x;return qn(f*f+a*a)})()}),t,It(1,t.length,t)),r=cs(O(u=>u.len)(n)),i=r_(0)(r)(e*r),o=u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,N=Bt(y=>T,y=>x=>L("Just",{head:y,tail:x}),h);if(N.tag==="Nothing"){const y=t.length-1|0;if(y>=0&&y<t.length){l=!1,_=t[y];continue}l=!1,_=m;continue}if(N.tag==="Just"){if(p<=N._1.head.len){const y=N._1.head.len<=0?0:p/N._1.head.len;l=!1,_={x:N._1.head.a.x+(N._1.head.b.x-N._1.head.a.x)*y,y:N._1.head.a.y+(N._1.head.b.y-N._1.head.a.y)*y};continue}f=N._1.tail,g=p-N._1.head.len,d=m;continue}c()}return _};return 0<t.length?L("Just",o(n)(i)(t[0])):T},xo=t=>cs(ye(e=>n=>{const r=n.y-e.y,i=n.x-e.x;return qn(i*i+r*r)},t,It(1,t.length,t))),ln=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),[...(()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._4,n(r._6,i)));c()};return St(bt(Wt.foldr,n(t.nodes,qt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})(),...Le((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._4,n(r._6,i)));c()};return bt(Wt.foldr,n(t.edges,qt))})()),...Le((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._4,n(r._6,i)));c()};return bt(Wt.foldr,n(t.chipExtras,qt))})())]);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:fs(r.minX)(i.x),minY:fs(r.minY)(i.y),maxX:gs(r.maxX)(i.x),maxY:gs(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},Tr=function(t){return function(e){if(t>=0&&t<e.length)return e.charAt(t);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},bn=function(t){return t.join("")},To=function(t){return t.split("")},vo=function(t){return t},En=function(t){return t.length},ds=function(t){return function(e){return e.substr(0,t)}},vr=function(t){return function(e){return e.substring(t)}},i_=function(t){return function(e){return{before:e.substring(0,t),after:e.substring(t)}}},o_=t=>e=>{const n=i_(En(t))(e);return n.before===t?L("Just",n.after):T},u_=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},s_=t=>e=>n=>{try{var r=BigInt(n);return t(r)}catch{return e}},kn=t=>BigInt(t),a_=t=>Number(t),ri=t=>e=>t+e,ii=t=>e=>t*e,wo=t=>e=>t-e,ls=0n,oi=1n,hs=t=>e=>t^e,wr=t=>e=>t&e,Lo=t=>e=>t<<e,bo=t=>e=>t>>e,c_=t=>e=>t==e,f_=t=>e=>t===e?0:t>e?1:-1,g_={eq:c_},ps={compare:t=>e=>{const n=f_(t)(e);return n===1?Ne:n===0?we:me},Eq0:()=>g_},__=u_(jt)(T),d_=s_(jt)(T),l_=t=>e=>On(t._1-e._1)+On(t._2-e._2),ui=t=>t,se=ui("North"),ae=ui("South"),Oe=ui("East"),Gn=ui("West"),ms=t=>t,Ns=(t,e)=>({tag:t,_1:e}),ys=(t,e)=>({tag:t,_1:e}),Eo=(t,e)=>({tag:t,_1:e}),h_=Eo("First"),p_=ms("Forward"),m_=ms("Backward"),N_=Vt(C)(Dt),y_=t=>gr(e=>n=>({nodes:xe(C.compare,pe,e.nodes,n.nodes),edges:xe(C.compare,pe,e.edges,n.edges)}))({nodes:M,edges:M})(t.keyframes),J_=t=>e=>({entering:{nodes:tn(C.compare,e.nodes,t.nodes),edges:tn(C.compare,e.edges,t.edges)},leaving:{nodes:tn(C.compare,t.nodes,e.nodes),edges:tn(C.compare,t.edges,e.edges)},surviving:{nodes:jr(C.compare,pe,t.nodes,e.nodes),edges:jr(C.compare,pe,t.edges,e.edges)}}),Js=t=>t,ko=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},Cn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Vn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Un=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Go=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},x_=J(t=>e=>K(C)(e)()(t))(M),T_=J(t=>e=>K(C)(e)()(t))(M),v_=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),xs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ts=Vt(C)(Dt),w_=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},L_=Js("Hold"),b_=Js("Gap"),E_=t=>e=>n=>{const r=n.center.y-e.center.y,i=n.center.x-e.center.x,o=qn(i*i+r*r),u=n.zoom-e.zoom,s=u<0?-u:u;return ko(t.minTransition)(t.maxTransition)(Cn(t.panSpeed<=0?t.minTransition:o/t.panSpeed)(t.zoomSpeed<=0?t.minTransition:s/t.zoomSpeed))},k_=J(t=>e=>{const n=t.length-1|0;return n>=0&&n<t.length&&t[n]===e?t:oe(t)(e)})([]),Co=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:Vn(r.minX)(i.x),minY:Vn(r.minY)(i.y),maxX:Cn(r.maxX)(i.x),maxY:Cn(r.maxY)(i.y)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x,maxY:e._1.head.y})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},vs=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return T;if(e.tag==="Just")return L("Just",Co(t));c()},G_=t=>e=>n=>x_(St(bt(Ge.foldr,n))(r=>{const i=Un(r)(t);if(i.tag==="Just")return ct(o=>!Go(o)(e),[i._1.source,i._1.target]);if(i.tag==="Nothing")return[];c()})),C_=t=>e=>n=>{const r=Jo(t.easing)(ko(0)(1)(n.endT<=n.startT?1:(e-n.startT)/(n.endT-n.startT)));return{center:{x:n.fromCam.center.x+(n.toCam.center.x-n.fromCam.center.x)*r,y:n.fromCam.center.y+(n.toCam.center.y-n.fromCam.center.y)*r},zoom:n.fromCam.zoom+(n.toCam.zoom-n.fromCam.zoom)*r}},S_=t=>e=>n=>r=>{const i=(u,s)=>Vn(E_(t)(u.toCam)(s.toCam))(u.endT-u.startT),o=J(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:L("Just",s)};if(u.pending.tag==="Just")return!(s.fromCam.zoom===s.toCam.zoom&&s.fromCam.center.x===s.toCam.center.x&&s.fromCam.center.y===s.toCam.center.y)||(()=>{const a=u.pending._1.toCam.center.x-s.toCam.center.x;return(a<0?-a<8:a<8)&&(()=>{const f=u.pending._1.toCam.center.y-s.toCam.center.y;return(f<0?-f<8:f<8)&&(()=>{const g=u.pending._1.toCam.zoom-s.toCam.zoom;return g<0?-g<.08:g<.08})()})()})()||i(u.pending._1,s)<=0?{acc:oe(u.acc)(u.pending._1),pending:L("Just",s)}:{acc:oe(oe(u.acc)({...u.pending._1,endT:s.startT-i(u.pending._1,s)}))({startT:s.startT-i(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam}),pending:L("Just",s)};c()})({acc:[],pending:T})(r);if(o.pending.tag==="Nothing")return o.acc;if(o.pending.tag==="Just")return oe(o.acc)(o.pending._1);c()},Q_=t=>t.kind.tag==="SendToken"?L("Just",w(t.kind._1.edge,{source:t.kind._1.from,target:t.kind._1.to})):T,P_=t=>t.tag==="DataFlow"?xt(Q_)(t._1.events):[],D_=t=>e=>T_(xt(n=>Go(n._2.source)(e)||Go(n._2.target)(e)?L("Just",n._1):T)(v_(t))),A_=t=>e=>{const n=r=>{const i=Yf(jt,T,o=>o.kind==="Hold",r<1?[]:It(0,r,e));if(i.tag==="Just")return i._1>=0&&i._1<e.length?L("Just",e[i._1].cam):T;if(i.tag==="Nothing")return T;c()};return At(r=>i=>{if(i.kind==="Hold")return{startT:i.startT,endT:i.endT,fromCam:i.cam,toCam:i.cam};if(i.kind==="Gap")return{startT:i.startT,endT:i.endT,fromCam:(()=>{const o=n(r);if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;c()})(),toCam:(()=>{const o=n(r),u=(()=>{if(o.tag==="Nothing")return t;if(o.tag==="Just")return o._1;c()})(),s=r+1|0,a=Mn(jt,T,f=>f.kind==="Hold",s<1?e:It(s,e.length,e));if(a.tag==="Just"){const f=(r+1|0)+a._1|0;return f>=0&&f<e.length?e[f].cam:u}if(a.tag==="Nothing")return u;c()})()};c()})(e)},ws={padding:24,easing:t_,minZoom:.9,maxZoom:2.5,panSpeed:700,zoomSpeed:1.5,minTransition:.3,maxTransition:1.4},I_=t=>e=>n=>{const r=e.w+n*2,i=e.h+n*2,o=ln(t);return r<=0||i<=0||o.w<=0||o.h<=0?1:Vn(o.w/r)(o.h/i)},So=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(e.tag==="Just"){const n=J(r=>i=>({minX:Vn(r.minX)(i.x),minY:Vn(r.minY)(i.y),maxX:Cn(r.maxX)(i.x+i.w),maxY:Cn(r.maxY)(i.y+i.h)}))({minX:e._1.head.x,minY:e._1.head.y,maxX:e._1.head.x+e._1.head.w,maxY:e._1.head.y+e._1.head.h})(e._1.tail);return{x:n.minX,y:n.minY,w:n.maxX-n.minX,h:n.maxY-n.minY}}c()},Ls=t=>e=>n=>{if(n.tag==="Leaf")return ln(t);const r=D_(e)(n),i=[...xt(o=>{const u=xs(o)(t.nodes);return u.tag==="Just"?L("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})(bt(Ge.foldr,xe(C.compare,pe,n,G_(e)(n)(r)))),...xt(o=>{const u=Un(o)(t.edges);return u.tag==="Just"?L("Just",Co(u._1)):T})(bt(Ge.foldr,r)),...xt(o=>{const u=Un(o)(t.chipExtras);if(u.tag==="Just")return vs(u._1);if(u.tag==="Nothing")return T;c()})(bt(Ge.foldr,r))];return i.length===0?ln(t):So(i)},R_=t=>e=>n=>r=>{const i=[...xt(o=>o)([(()=>{const o=Un(n)(t.edges);return o.tag==="Just"?L("Just",Co(o._1)):T})(),(()=>{const o=Un(n)(t.chipExtras);if(o.tag==="Just")return vs(o._1);if(o.tag==="Nothing")return T;c()})()]),...(()=>{const o=Un(n)(e);if(o.tag==="Just")return xt(u=>{const s=xs(u)(t.nodes);return s.tag==="Just"?L("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):T})([o._1.source,o._1.target]);if(o.tag==="Nothing")return[];c()})()];return i.length===0?Ls(t)(e)(r):So(i)},F_=J(t=>e=>{const n=t.length-1|0,r=n>=0&&n<t.length?L("Just",t[n]):T;return r.tag==="Just"&&r._1.fromCam.zoom===r._1.toCam.zoom&&r._1.fromCam.center.x===r._1.toCam.center.x&&r._1.fromCam.center.y===r._1.toCam.center.y&&e.fromCam.zoom===e.toCam.zoom&&e.fromCam.center.x===e.toCam.center.x&&e.fromCam.center.y===e.toCam.center.y&&(()=>{const i=r._1.toCam.center.x-e.toCam.center.x;return(i<0?-i<8:i<8)&&(()=>{const o=r._1.toCam.center.y-e.toCam.center.y;return(o<0?-o<8:o<8)&&(()=>{const u=r._1.toCam.zoom-e.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?oe((()=>{const i=t.length-1|0;return i<1?[]:It(0,i,t)})())({...r._1,endT:e.endT}):oe(t)(e)})([]),bs=t=>e=>{const n=ln(t),r=n.w/Cn(1e-4)(e.zoom),i=n.h/Cn(1e-4)(e.zoom);return{x:e.center.x-r/2,y:e.center.y-i/2,w:r,h:i}},B_=t=>xe(C.compare,pe,Ts(O(e=>w(e.id,{source:e.from.node,target:e.to.node}))(t.graph.edges)),Ts(St(t.scenes)(P_))),Qo=t=>e=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:ko(t.minZoom)(t.maxZoom)(I_(e)(n)(t.padding))}),M_=t=>e=>n=>r=>{const i=Qo(t)(e)(ln(e)),o=ct(u=>u>=0&&u<=n,k_(vt(dt.compare)([0,n,...St(r)(u=>[u.startT,u.endT])])));return S_(t)(e)(i)(F_(A_(i)(xt(u=>{const s=(u._1+u._2)/2;if(u._2<=u._1)return T;const a=J(w_)(0)(O(g=>g.priority)(ct(g=>g.startT<=s&&s<g.endT,r))),f=O(g=>g.bbox)(ct(g=>g.priority===a,ct(g=>g.startT<=s&&s<g.endT,r)));return f.length===0?L("Just",{kind:b_,startT:u._1,endT:u._2,cam:i}):L("Just",{kind:L_,startT:u._1,endT:u._2,cam:Qo(t)(e)(So(f))})})(ye(Bn,o,It(1,o.length,o))))))},$_=t=>e=>n=>r=>{const i=ge(o=>r>=o.startT&&r<o.endT)(n);if(i.tag==="Just")return C_(t)(r)(i._1);if(i.tag==="Nothing"){const o=n.length-1|0;if(o>=0&&o<n.length&&r>=n[o].endT)return n[o].toCam;const u=Qo(t)(e)(ln(e));return 0<n.length?n[0].fromCam:u}c()};function Lr(t){return t.charCodeAt(0)}function Es(t){return String.fromCharCode(t)}const hn=function(t){return function(e){return function(n){return n.replace(new RegExp(t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),e)}}},Po=function(t){return function(e){return e.split(t)}},z_=function(t){return t.trim()},si=function(t){return function(e){return e.join(t)}};var O_=typeof Array.from=="function",q_=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",H_=typeof String.prototype.fromCodePoint=="function",W_=typeof String.prototype.codePointAt=="function";const V_=function(t){return W_?function(e){return e.codePointAt(0)}:t},U_=function(t){return H_?String.fromCodePoint:t},Y_=function(t){return function(e){return q_?function(n){for(var r="",i=n[Symbol.iterator](),o=0;o<e;++o){var u=i.next();if(u.done)return r;r+=u.value}return r}:t(e)}},X_=function(t){return function(e){return O_?function(n){return Array.from(n,e)}:t}},ai=t=>{const e=En(t);if(e===0)return T;if(e===1)return L("Just",{head:Lr(Tr(0)(t)),tail:""});const n=Lr(Tr(1)(t)),r=Lr(Tr(0)(t));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?L("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:vr(2)(t)}):L("Just",{head:r,tail:vr(1)(t)})},K_=t=>{const e=ai(t);return e.tag==="Just"?L("Just",w(e._1.head,e._1.tail)):T},j_=t=>Re.unfoldr(K_)(t),ks=V_(t=>{const e=Lr(Tr(0)(t));if(55296<=e&&e<=56319&&En(t)>1){const n=Lr(Tr(1)(t));if(56320<=n&&n<=57343)return(((e-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return e}),Do=X_(j_)(ks),Ao=t=>vo(t>=0&&t<=65535?Es(t):t<0?"\0":"\uFFFF"),Z_=U_(t=>t<=65535?Ao(t):Ao(Fn(t-65536|0,1024)+55296|0)+Ao(no(t-65536|0)(1024)+56320|0)),Gs=t=>e=>{if(t<1)return"";const n=ai(e);return n.tag==="Just"?Z_(n._1.head)+Gs(t-1|0)(n._1.tail):e},ce=Y_(Gs),t1=t=>e=>e===""?T:L("Just",ks(e)),ci=(t,e,n)=>({tag:t,_1:e,_2:n}),e1=()=>({tag:"ExtendFromSource"}),fi=(t,e)=>({tag:t,_1:e}),Io=t=>t,gi=(t,e)=>({tag:t,_1:e}),Ro=gi("NotYet"),Cs=gi("Consumed"),n1=Io("FromSource"),Ss=Io("FromTarget"),r1=Io("FromBoth"),Qs=fi("Hidden"),i1=fi("Visible"),Ps=e1(),Ds=ci("Retracted"),o1=ci("Extended"),Fo=(t,e)=>({tag:t,_1:e}),Yn=(t,e,n)=>({tag:t,_1:e,_2:n}),As=t=>t,Sn=(t,e)=>({tag:t,_1:e}),Xn=(t,e,n,r,i,o,u,s,a)=>({tag:t,_1:e,_2:n,_3:r,_4:i,_5:o,_6:u,_7:s,_8:a}),Is=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},_i=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},pn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},br=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Rs=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Fs=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Kn=(()=>{const t=Re.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return L("Just",w(e._1,e._2));c()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._3,n(r._6,i)));c()};return n(e,qt)})())})(),u1=J(t=>e=>K(C)(e)()(t))(M),Bo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},s1=Vt(C)(Dt),a1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Mo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},c1=Sn("NoKeyframes"),f1=t=>Sn("DuplicateEventId",t),g1=t=>Sn("UnknownEvent",t),Bs=As("PlopIn"),_1=As("PlopOut"),d1=t=>e=>xt(n=>{if(n.target.tag==="NodeWindow"||n.target.tag==="EdgeWindow")return T;if(n.target.tag==="TokenWindow")return L("Just",{startT:n.startT,endT:n.endT,bbox:R_(t)(e)(n.target._2)(M),priority:1});if(n.target.tag==="FillWindow")return L("Just",{startT:n.startT,endT:n.endT,bbox:Ls(t)(e)($t("Node",1,1,n.target._2,void 0,M,M)),priority:1});c()}),l1=t=>e=>n=>r=>i=>{const o=ot(J(f=>g=>f+Do(g).length|0)(0)(n.labels))*t.tokenReadSecPerChar,u=f=>{const g=Is(f)(e.nodes);if(g.tag==="Just")return{x:g._1.x+g._1.w/2,y:g._1.y+g._1.h/2};if(g.tag==="Nothing")return{x:0,y:0};c()},s=_i(n.edge)(e.edges),a=(()=>{if(s.tag==="Just"){const f=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return de(s._1);c()})(),g=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return de(s._1);c()})(),d=u(n.from),l=g.length-1|0;return(2*(()=>{const _=0<f.length?f[0]:u(n.from),h=_.x-d.x,p=_.y-d.y;return(h<0?-h:h)+(p<0?-p:p)})()+xo(s._1)+2*(()=>{const _=l>=0&&l<g.length?g[l]:u(n.to),h=u(n.to),p=h.x-_.x,m=h.y-_.y;return(p<0?-p:p)+(m<0?-m:m)})())/t.tokenSpeed}if(s.tag==="Nothing")return 0/t.tokenSpeed;c()})();return t.tokenSpeed<=0?t.minTokenDuration:pn(t.minTokenDuration)(pn(a)(o)/pn(.05)(1-r-i))},h1=t=>{if(t.event.kind.tag==="SendToken")return L("Just",{startT:t.startT,endT:t.endT,target:Xn("TokenWindow",t.event.id,t.event.kind._1.edge,t.event.kind._1.direction,t.event.kind._1.from,t.event.kind._1.to,t.event.kind._1.labels,t.holdPre,t.holdPost)});if(t.event.kind.tag==="FillNodeWithoutTransition")return L("Just",{startT:t.startT,endT:t.endT,target:Xn("FillWindow",t.event.id,t.event.kind._1.node,t.event.kind._1.labels)});c()},p1=t=>e=>n=>xt(r=>{const i=xt(o=>Is(o)(t.nodes))(bt(Ge.foldr,(()=>{if(r.scene.tag==="Structural")return xe(C.compare,pe,(()=>{const o=br(r.scene._1.from)(n);if(o.tag==="Nothing")return M;if(o.tag==="Just")return o._1.nodes;c()})(),(()=>{const o=br(r.scene._1.to)(n);if(o.tag==="Nothing")return M;if(o.tag==="Just")return o._1.nodes;c()})());if(r.scene.tag==="DataFlow"){const o=br(r.scene._1.keyframe)(n);if(o.tag==="Nothing")return M;if(o.tag==="Just")return o._1.nodes}c()})()));return i.length===0?T:L("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const o=J(u=>s=>({minX:Rs(u.minX)(s.x),minY:Rs(u.minY)(s.y),maxX:pn(u.maxX)(s.x+s.w),maxY:pn(u.maxY)(s.y+s.h)}))(0<i.length?{minX:i[0].x,minY:i[0].y,maxX:i[0].x+i[0].w,maxY:i[0].y+i[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(It(1,i.length,i));return{x:o.minX,y:o.minY,w:o.maxX-o.minX,h:o.maxY-o.minY}})(),priority:0})}),m1=t=>e=>n=>{const r=_i(n)(t);if(r.tag==="Nothing")return Ss;if(r.tag==="Just"){const i=Fs(r._1.target)(e);return Fs(r._1.source)(e)?i?r1:n1:Ss}c()},N1=t=>e=>n=>r=>{const i=(()=>{if(r.event.when.tag==="First")return 0;if(r.event.when.tag==="At")return r.event.when._1;if(r.event.when.tag==="After"){const o=r.event.when._1,u=ge(s=>s.event.id===o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.endT;c()}if(r.event.when.tag==="With"){const o=r.event.when._1,u=ge(s=>s.event.id===o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.startT}c()})();return oe(n)({startT:i,endT:(()=>{if(r.event.kind.tag==="SendToken")return i+l1(t)(e)(r.event.kind._1)(r.holdPre)(r.holdPost);if(r.event.kind.tag==="FillNodeWithoutTransition")return i+t.plop;c()})(),event:r.event,holdPre:r.holdPre,holdPost:r.holdPost})},$o=t=>e=>{if(e<0)return Yn("AtKeyframe",t.initialKeyframe);if(e>=t.totalDuration){const r=t.spans.length-1|0;return r>=0&&r<t.spans.length?Yn("AtKeyframe",(()=>{if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;c()})()):Yn("AtKeyframe",t.initialKeyframe)}const n=ge(r=>e>=r.startT&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return Yn("InTransition",n._1.scene._1.from,n._1.scene._1.to);if(n._1.scene.tag==="DataFlow")return Yn("AtKeyframe",n._1.scene._1.keyframe);c()}if(n.tag==="Nothing")return Yn("AtKeyframe",t.initialKeyframe);c()},y1=t=>{if(t.when.tag==="First")return[];if(t.when.tag==="At")return[];if(t.when.tag==="After")return[t.when._1];if(t.when.tag==="With")return[t.when._1];c()},Ms={id:"",nodes:M,edges:M},J1=t=>e=>J_((()=>{const n=br(e.from)(t);if(n.tag==="Nothing")return Ms;if(n.tag==="Just")return n._1;c()})())((()=>{const n=br(e.to)(t);if(n.tag==="Nothing")return Ms;if(n.tag==="Just")return n._1;c()})()),zo=t=>e=>n=>r=>{const i=_i(r)(n.edges);if(i.tag==="Just")return t<=0?e:pn(e)(xo(i._1)/t);if(i.tag==="Nothing")return e;c()},$s=t=>e=>n=>r=>i=>{const o=t.plop,u=J1(n)(i),s=O(_=>({startT:0,endT:0+zo(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Xn("EdgeWindow",_,Fo("Extend",Ps))}))(Kn(u.entering.edges)),a=O(_=>({startT:0,endT:o,target:Xn("NodeWindow",_,Bs)}))(Kn(u.entering.nodes)),f=J(pn)(0)(O(_=>zo(t.edgeSpeed)(t.minEdgeDuration)(e)(_))(Kn(u.leaving.edges))),g=_=>Ze(h=>{const p=_i(h)(r);if(p.tag==="Just")return p._1.source===_||p._1.target===_;if(p.tag==="Nothing")return!1;c()},Kn(u.leaving.edges))?f:0,d=O(_=>({startT:g(_),endT:g(_)+t.plop,target:Xn("NodeWindow",_,_1)}))(Kn(u.leaving.nodes)),l=O(_=>({startT:0,endT:zo(t.edgeSpeed)(t.minEdgeDuration)(e)(_),target:Xn("EdgeWindow",_,Fo("Retract",m1(r)(u.leaving.nodes)(_)))}))(Kn(u.leaving.edges));return{duration:(()=>{const _=vt(dt.compare)([...O(p=>p.endT)(l),...O(p=>p.endT)(d),...O(p=>p.endT)(a),...O(p=>p.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+t.gap:t.gap})(),windows:[...l,...d,...a,...s]}},x1=t=>e=>n=>r=>i=>o=>O((()=>{const u=i.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())($s(t)(e)(n)(r)(o).windows),T1=t=>xt(e=>bt(gr,e).length>1?L("Just",(()=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),bt(gr,e));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";c()})()):T)(tg(Xi)(vt(C.compare)(t))),v1=t=>{const e=O(r=>r.id)(t),n=u1(e);return[...O(f1)(T1(e)),...O(g1)(ct(r=>!Bo(r)(n),St(t)(y1)))]},w1=t=>{const e=s1(O(r=>w(r.id,(()=>{if(r.when.tag==="First")return[];if(r.when.tag==="At")return[];if(r.when.tag==="After")return[r.when._1];if(r.when.tag==="With")return[r.when._1];c()})()))(t)),n=r=>i=>o=>{if(Bo(o)(i))return[Sn("ScheduleCycle",[...bt(Ge.foldr,i),o])];if(Bo(o)(r))return[];const u=a1(o)(e);if(u.tag==="Nothing")return[];if(u.tag==="Just")return St(u._1)(n(K(C)(o)()(r))(K(C)(o)()(i)));c()};return St(t)(r=>n(M)(M)(r.id))},L1={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:100,minTokenDuration:1.4,tokenReadSecPerChar:.06,nodeEasing:e_,edgeEasing:Zg,tokenEasing:jg},b1=t=>e=>{if(e.tag==="Structural")return xt(n=>n)([Mo(e._1.from)(t)?T:L("Just",Sn("UnknownKeyframe",e._1.from)),Mo(e._1.to)(t)?T:L("Just",Sn("UnknownKeyframe",e._1.to))]);if(e.tag==="DataFlow")return[...xt(n=>n)([Mo(e._1.keyframe)(t)?T:L("Just",Sn("UnknownKeyframe",e._1.keyframe))]),...v1(e._1.events),...w1(e._1.events)];c()},E1=t=>e=>{const n=St(e)(b1(t));return n.length===0?Et("Right",void 0):Et("Left",n)},zs=t=>e=>n=>J(N1(t)(e))([])(At(r=>i=>({event:i,holdPre:i.kind.tag==="SendToken"?(()=>{const o=r-1|0;return o>=0&&o<n.length&&n[o].kind.tag==="SendToken"&&n[o].kind._1.to===i.kind._1.from})()?0:.18:0,holdPost:i.kind.tag==="SendToken"?(()=>{const o=r+1|0;return o>=0&&o<n.length&&n[o].kind.tag==="SendToken"&&n[o].kind._1.from===i.kind._1.to})()?0:.18:0}))(n)),k1=t=>e=>n=>{const r=zs(t)(e)(n.events);return r.length===0?t.gap:J(pn)(0)(O(i=>i.endT)(r))+t.gap},G1=t=>e=>n=>r=>i=>{if(i.tag==="Structural")return $s(t)(e)(n)(r)(i._1).duration;if(i.tag==="DataFlow")return k1(t)(e)(i._1);c()},C1=t=>e=>n=>r=>i=>J(o=>u=>{const s=G1(t)(e)(n)(r)(u);return{acc:oe(o.acc)({startT:o.t,endT:o.t+s,scene:u}),t:o.t+s}})({acc:[],t:0})(i).acc,S1=t=>e=>n=>r=>O((()=>{const i=n.startT;return o=>({...o,startT:o.startT+i,endT:o.endT+i})})())(xt(h1)(zs(t)(e)(r.events))),Q1=t=>e=>n=>r=>i=>{if(i.scene.tag==="Structural")return x1(t)(e)(n)(r)(i)(i.scene._1);if(i.scene.tag==="DataFlow")return S1(t)(e)(i)(i.scene._1);c()},P1=t=>e=>n=>{const r=0<e.keyframes.length?L("Just",e.keyframes[0]):T;if(r.tag==="Nothing")return Et("Left",[c1]);if(r.tag==="Just"){const i=r._1,o=N_(O(a=>w(a.id,a))(e.keyframes)),u=B_(e),s=E1(o)(e.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return f=>Et("Left",a)}if(s.tag==="Right"){const a=s._1;return f=>f(a)}c()})()(()=>{const a=C1(t)(n)(o)(u)(e.scenes),f=a.length-1|0,g=f>=0&&f<a.length?a[f].endT:0,d=vt(l=>_=>dt.compare(l.startT)(_.startT))(St(a)(Q1(t)(n)(o)(u)));return Et("Right",{totalDuration:g,windows:d,spans:a,keyframes:o,initialKeyframe:i.id,timing:t,layout:n,cameraSpans:M_(ws)(n)(g)([...p1(n)(u)(o)(a),...d1(n)(u)(d)]),cameraConfig:ws})})}c()},Er=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Os=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},di=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},D1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},A1=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},I1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},R1=Vt(C)(Dt),F1=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},B1=Vt(C)(Dt),M1=Vt(C)(Dt),$1=t=>e=>n=>r=>{const i=ln(t),o=i.w/Er(1e-4)(e.zoom)/2,u=i.h/Er(1e-4)(e.zoom)/2,s=n.y-e.center.y,a=n.x-e.center.x;return{...e,center:{x:o<=1e-4?e.center.x+0*r*.35:a<0?e.center.x+a/(1+-a/o)*r*.35:e.center.x+a/(1+a/o)*r*.35,y:u<=1e-4?e.center.y+0*r*.35:s<0?e.center.y+s/(1+-s/u)*r*.35:e.center.y+s/(1+s/u)*r*.35}}},Oo=t=>e=>{const n=Os(e)(t.keyframes);if(n.tag==="Nothing")return M;if(n.tag==="Just")return n._1.nodes;c()},qo=t=>e=>{const n=Os(e)(t.keyframes);if(n.tag==="Nothing")return M;if(n.tag==="Just")return n._1.edges;c()},z1=t=>e=>n=>Ze(r=>r.endT<=e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,t),O1=t=>e=>n=>Ze(r=>r.endT<=e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,t),q1=t=>e=>n=>Ze(r=>r.startT>e&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,t),H1=t=>e=>n=>Ze(r=>r.startT>e&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,t),W1=t=>e=>{const n=$o(t)(e);if(n.tag==="AtKeyframe")return ce(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return ce(3)(n._2)==="kf-"?"":n._2;c()},qs=t=>e=>n=>ge(r=>n(r)&&e>=r.startT&&e<r.endT)(t),V1=t=>{const e=di(0)(1)(t/.2),n=di(0)(1)((1-t)/.2);return e*e*(3-2*e)*n*n*(3-2*n)},U1=t=>e=>{if(e.tag==="Travelling"){const n=D1(e._1.edge)(t.edges);if(n.tag==="Just"){const r=_s(n._1)(e._1.progress);return r.tag==="Just"?L("Just",{dot:r._1,weight:V1(e._1.progress)}):T}if(n.tag==="Nothing")return T;c()}return T},Y1=t=>e=>{const n=$o(t)(e);if(n.tag==="AtKeyframe")return Oo(t)(n._1);if(n.tag==="InTransition")return xe(C.compare,pe,Oo(t)(n._1),Oo(t)(n._2));c()},X1=t=>e=>{const n=$o(t)(e);if(n.tag==="AtKeyframe")return qo(t)(n._1);if(n.tag==="InTransition")return xe(C.compare,pe,qo(t)(n._1),qo(t)(n._2));c()},K1=t=>e=>{const n=ln(t),r=n.h/Er(1e-4)(e.zoom),i=n.w/Er(1e-4)(e.zoom);return{...e,center:{x:i>=n.w?n.x+n.w/2:di(n.x+i/2)(n.x+n.w-i/2)(e.center.x),y:r>=n.h?n.y+n.h/2:di(n.y+r/2)(n.y+n.h-r/2)(e.center.y)}}},li=t=>e=>{const n=t.endT-t.startT;return n<=0?1:Er(0)(A1(1)((e-t.startT)/n))},j1=t=>e=>n=>r=>{const i=qs(t.windows)(e)(o=>o.target.tag==="EdgeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=Jo(t.timing.edgeEasing)(li(i._1)(e)),u=i._1.target.tag==="EdgeWindow"?i._1.target._2:Fo("Extend",Ps);if(u.tag==="Retract")return ci("Retracting",u._1,o);if(u.tag==="Extend")return ci("Extending",u._1,o);c()}if(i.tag==="Nothing")return H1(t.windows)(e)(r)||z1(t.windows)(e)(r)?Ds:I1(r)(n)?o1:Ds;c()},Z1=t=>e=>{const n=X1(t)(e);return R1(O(r=>w(r,j1(t)(e)(n)(r)))((()=>{const r=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));c()};return bt(Ge.foldr,r(t.layout.edges))})()))},td=t=>e=>n=>r=>{const i=qs(t.windows)(e)(o=>o.target.tag==="NodeWindow"&&o.target._1===r);if(i.tag==="Just"){const o=li(i._1)(e),u=i._1.target.tag==="NodeWindow"?i._1.target._2:Bs;if(u==="PlopIn")return fi("PloppingIn",o);if(u==="PlopOut")return fi("PloppingOut",o);c()}if(i.tag==="Nothing")return q1(t.windows)(e)(r)||O1(t.windows)(e)(r)?Qs:F1(r)(n)?i1:Qs;c()},ed=t=>e=>{const n=Y1(t)(e);return B1(O(r=>w(r,td(t)(e)(n)(r)))((()=>{const r=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,void 0,r(i._5),r(i._6));c()};return bt(Ge.foldr,r(t.layout.nodes))})()))},nd=t=>e=>n=>e.target.tag==="TokenWindow"?w(e.target._1,n<e.startT?Ro:n>=e.endT?Cs:gi("Travelling",{edge:e.target._2,direction:e.target._3,progress:Jo(t.timing.tokenEasing)(li(e)(n)),labels:e.target._6,source:e.target._4,target:e.target._5,holdPre:e.target._7,holdPost:e.target._8})):e.target.tag==="FillWindow"?w(e.target._1,n<e.startT?Ro:n>=e.endT?Cs:gi("Filling",{node:e.target._2,progress:li(e)(n),labels:e.target._3})):w("",Ro),rd=t=>e=>M1(O(n=>nd(t)(n)(e))(ct(n=>n.target.tag==="TokenWindow"||n.target.tag==="FillWindow",t.windows))),id=t=>e=>{const n=xt(U1(t))((()=>{const r=(i,o)=>{if(i.tag==="Leaf")return o;if(i.tag==="Node")return r(i._5,Mt("Cons",i._4,r(i._6,o)));c()};return bt(Wt.foldr,r(e.tokens,qt))})());return 0<n.length?L("Just",n[0]):T},od=t=>e=>{const n=id(t)(e);if(n.tag==="Nothing")return e.camera;if(n.tag==="Just")return $1(t)(e.camera)(n._1.dot)(n._1.weight);c()},ud=t=>e=>{const n={nodes:ed(t)(e),edges:Z1(t)(e),tokens:rd(t)(e),camera:$_(t.cameraConfig)(t.layout)(t.cameraSpans)(e),frameTitle:W1(t)(e)};return{...n,camera:K1(t.layout)(od(t.layout)(n))}},Hs=t=>t,Ws=Hs("RunText"),sd=Hs("RunCode"),Vs=t=>e=>n=>e.length===0?n:oe(n)({style:t,text:bn(e)}),ad=t=>({style:(()=>{if(t.style==="RunText")return sd;if(t.style==="RunCode")return Ws;c()})(),buf:[],runs:Vs(t.style)(t.buf)(t.runs)}),cd=t=>e=>0<e.length?{...t,buf:oe(t.buf)(e[0])}:{...t,buf:oe(t.buf)("\\")},fd=t=>e=>{let n=t,r=e,i=!0,o;for(;i;){const u=n,s=Bt(a=>T,a=>f=>L("Just",{head:a,tail:f}),r);if(s.tag==="Nothing"){i=!1,o=u;continue}if(s.tag==="Just"){if(s._1.head==="\\"){n=cd(u)(s._1.tail),r=It(1,s._1.tail.length,s._1.tail);continue}if(s._1.head==="`"){n=ad(u),r=s._1.tail;continue}n={...u,buf:oe(u.buf)(s._1.head)},r=s._1.tail;continue}c()}return o},Us=t=>{const e=fd({style:Ws,buf:[],runs:[]})(To(t));return Vs(e.style)(e.buf)(e.runs)};let Ho=null;function gd(){return Ho||(typeof document>"u"?null:(Ho=document.createElement("canvas").getContext("2d"),Ho))}const Ys=new Map,_d=t=>e=>n=>r=>()=>{const i=`${n} ${e}px ${t}|${r}`,o=Ys.get(i);if(o!==void 0)return o;const u=gd();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return Ys.set(i,s),s},dd=dr.traverse(Ui),ld=J(Wn)(0),kr=(()=>{const t=hn(`\r
|
|
3
|
+
`)(" "),e=hn(`
|
|
4
|
+
`)(" "),n=(()=>{const r=hn("\r")(" "),i=(()=>{const o=hn(" ")(" ");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),hd=t=>e=>{const n=dd(r=>{const i=(()=>{if(r.style==="RunText")return t.text;if(r.style==="RunCode")return t.code;c()})();return _d(i.family)(i.size)(i.weight)(kr(r.text))})(Us(kr(e)));return()=>{const r=n();return ld(r)}},pd={text:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:"500"},code:{family:"'Ioskeley Mono', ui-monospace, SFMono-Regular, Menlo, monospace",size:11,weight:"400"}},Gr=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},md=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Nd=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},yd=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Xs=t=>bn(de(Tn(e=>e===" ")(de(Tn(e=>e===" ")(To(t)).rest)).rest)),Jd=t=>J(e=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?L("Just",n._1):e)(T)(At(Bn)(t)),Wo=t=>e=>{if(t<=0)return[e];if(En(e)<=t)return[e];const n=To(e),r=t<1?[]:It(0,t,n),i=Jd(r);if(i.tag==="Just"){const o=Xs(ds(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(e)),u=Xs(vr(i._1+1|0)(e));return u===""?[o]:[o,...Wo(t)(u)]}if(i.tag==="Nothing"){const o=ds(t)(e),u=vr(t)(e);return u===""?[o]:[o,...Wo(t)(u)]}c()},xd={cellW:7,cellH:3,maxLineWidth:20},Td=t=>e=>{const n=O(o=>w((()=>{if(o.label.tag==="Just")return o.label._1;if(o.label.tag==="Nothing")return o.id;c()})(),o))(e.nodes),r=Gr(1)(Fn((md(t.maxLineWidth)(J(o=>u=>Gr(o)(En(u._1)))(0)(n))+2|0)+t.cellW|0,t.cellW)),i=(r*t.cellW|0)-1|0;return{...e,nodes:O(o=>{if(!(o._2.size._1===1&&o._2.size._2===1))return o._2;const u=St(Po(`
|
|
5
|
+
`)(o._1))(Wo(i)),s=J(a=>f=>Gr(a)(En(f)))(0)(u);return{...o._2,size:w(ot(s>i?Fn((s+2|0)+t.cellW|0,t.cellW):r),ot(Gr(1)(Fn(u.length+t.cellH|0,t.cellH))))}})(n)}},vd=t=>e=>n=>({...n,nodes:O(r=>{const i=yd(r.id)(e);if(i.tag==="Nothing")return r;if(i.tag==="Just")return{...r,size:w(Nd(r.size._1)(ot(Gr(1)(vn(ji((i._1+32)/t))))),r.size._2)};c()})(n.nodes)}),wd=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ld=t=>{const e=t.length;return(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(a>=e){u=!1,s=f;continue}const g=d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const N=_,y=h;if(N>=e){p=!1,m=y;continue}if(a>=0&&a<t.length){if(N>=0&&N<t.length){_=N+1|0,h=(()=>{const x=t[a].position,v=t[a].size,b=t[N].position,E=t[N].size;return x._1<b._1+E._1&&b._1<x._1+v._1&&x._2<b._2+E._2&&b._2<x._2+v._2})()?y+1|0:y;continue}_=N+1|0,h=y;continue}p=!1,m=y}return m};i=a+1|0,o=g(a+1|0)(f)}return s})(0)(0)},Ks=t=>J(e=>n=>e+l_(n.start)(n.end))(0)(t.segments),bd=t=>e=>n=>({crossingCount:J(r=>i=>r+i.jumps.length|0)(0)(e),bendCount:J(r=>i=>r+i.bends.length|0)(0)(e),totalEdgeLength:J(r=>i=>r+Ks(i))(0)(e),maxEdgeLength:J(r=>i=>wd(r)(Ks(i)))(0)(e),nodeOverlapCount:Ld(t),constraintViolations:n,jumpCount:J(r=>i=>r+i.jumps.length|0)(0)(e)}),Vo=t=>t,Yt=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Uo=Vo("LEFT"),Ed=Vo("RIGHT"),js=Vo("UNDEFINED"),kd={eq:t=>e=>t==="LEFT"?e==="LEFT":t==="RIGHT"?e==="RIGHT":t==="UP"?e==="UP":t==="DOWN"?e==="DOWN":t==="UNDEFINED"&&e==="UNDEFINED"},Gd={compare:t=>e=>{if(t==="LEFT")return e==="LEFT"?we:me;if(e==="LEFT")return Ne;if(t==="RIGHT")return e==="RIGHT"?we:me;if(e==="RIGHT")return Ne;if(t==="UP")return e==="UP"?we:me;if(e==="UP")return Ne;if(t==="DOWN")return e==="DOWN"?we:me;if(e==="DOWN")return Ne;if(t==="UNDEFINED"&&e==="UNDEFINED")return we;c()},Eq0:()=>kd},Cd=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){if(t==="LEFT"){if(o._3==="LEFT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="LEFT"){n=o._6;continue}if(t==="RIGHT"){if(o._3==="RIGHT"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="RIGHT"){n=o._6;continue}if(t==="UP"){if(o._3==="UP"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="UP"){n=o._6;continue}if(t==="DOWN"){if(o._3==="DOWN"){r=!1,i=!0;continue}n=o._5;continue}if(o._3==="DOWN"){n=o._6;continue}if(t==="UNDEFINED"&&o._3==="UNDEFINED"){r=!1,i=!0;continue}}c()}return i},Sd={x:0,y:0},qe=t=>e=>n=>{const r=Yt(t)(n.cNodes);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cNodes:K(nt)(t)(e(r._1))(n.cNodes)};c()},Cr=t=>e=>n=>{const r=Yt(t)(n.cGroups);if(r.tag==="Nothing")return n;if(r.tag==="Just")return{...n,cGroups:K(nt)(t)(e(r._1))(n.cGroups)};c()},Qd=t=>J(e=>n=>qe(n)(r=>({...r,hitboxPreCompaction:r.hitbox}))(e))(t)(t.cNodeOrder),Pd=t=>{const e=J(n=>r=>{const i=Yt(r)(t.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just")return J(o=>u=>Tt(nt)(ue)(u)([r])(o))(n)(i._1.constraints);c()})(M)(t.cNodeOrder);return J(n=>r=>qe(r)(i=>({...i,constraints:(()=>{const o=Yt(r)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;c()})()}))(n))(t)(t.cNodeOrder)},Dd=t=>{const e=J(n=>r=>Cr(r)(i=>({...i,outDegree:i.outDegreeReal}))(n))(t)(t.cGroupOrder);return J(n=>r=>qe(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder)},Ad={left:!1,right:!1,up:!1,down:!1},Id={horizontalSpacing:t=>e=>0,verticalSpacing:t=>e=>0},Yo=t=>J(e=>n=>{const r=Yt(n)(e.cGroups);if(r.tag==="Nothing")return e;if(r.tag==="Just"){const i=J(u=>s=>{const a=Yt(s)(e.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just"){if(u.tag==="Nothing")return L("Just",s);if(u.tag==="Just"){const f=Yt(u._1)(e.cNodes);if(f.tag==="Nothing")return L("Just",s);if(f.tag==="Just")return a._1.hitbox.x<f._1.hitbox.x?L("Just",s):L("Just",u._1)}}c()})(T)(r._1.cNodes),o=Cr(n)(u=>({...u,reference:i}))(e);if(i.tag==="Nothing")return o;if(i.tag==="Just"){const u=Yt(i._1)(o.cNodes);if(u.tag==="Nothing")return o;if(u.tag==="Just"){const s=u._1;return J(a=>f=>qe(f)(g=>({...g,cGroupOffset:{x:g.hitbox.x-s.hitbox.x,y:g.hitbox.y-s.hitbox.y}}))(a))(o)(r._1.cNodes)}}}c()})(t)(t.cGroupOrder),be=t=>Yo({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return M;if(n.tag==="Node")return $t("Node",n._1,n._2,n._3,{...n._4,hitbox:{...n._4.hitbox,x:-n._4.hitbox.x-n._4.hitbox.width}},e(n._5),e(n._6));c()};return e(t.cNodes)})()}),He=t=>Yo({...t,cNodes:(()=>{const e=n=>{if(n.tag==="Leaf")return M;if(n.tag==="Node")return $t("Node",n._1,n._2,n._3,{...n._4,hitbox:{x:n._4.hitbox.y,y:n._4.hitbox.x,width:n._4.hitbox.height,height:n._4.hitbox.width},cGroupOffset:{x:n._4.cGroupOffset.y,y:n._4.cGroupOffset.x}},e(n._5),e(n._6));c()};return e(t.cNodes)})()}),Zs=t=>{const e=J(n=>r=>Cr(r)(i=>({...i,outDegree:0,outDegreeReal:0,incomingConstraints:[]}))(n))(t)(t.cGroupOrder);return J(n=>r=>{const i=Yt(r)(n.cNodes);if(i.tag==="Nothing")return n;if(i.tag==="Just"){if(i._1.cGroup.tag==="Nothing")return n;if(i._1.cGroup.tag==="Just"){const o=i._1.cGroup._1;return J(u=>s=>{const a=Yt(s)(u.cNodes);if(a.tag==="Nothing")return u;if(a.tag==="Just")return a._1.cGroup.tag==="Just"&&a._1.cGroup._1!==o?Cr(a._1.cGroup._1)(f=>({...f,outDegree:f.outDegree+1|0,outDegreeReal:f.outDegreeReal+1|0}))(Cr(o)(f=>ke(_r)(s)(f.incomingConstraints)?f:{...f,incomingConstraints:[...f.incomingConstraints,s]})(u)):u;c()})(n)(i._1.constraints)}}c()})(e)(e.cNodeOrder)},hi=t=>{const e=Pd(t.cGraph);return{...t,cGraph:Zs(J(n=>r=>qe(r)(i=>({...i,startPos:-1e308}))(n))(e)(e.cNodeOrder))}},Rd=t=>e=>J(n=>r=>{if(t==="LEFT"||t==="UP"){const o=r._2;return qe(r._1)(u=>({...u,constraints:[...u.constraints,o]}))(n)}const i=r._1;return qe(r._2)(o=>({...o,constraints:[...o.constraints,i]}))(n)})(e)(t==="LEFT"||t==="RIGHT"?e.predefinedHorizontalConstraints:e.predefinedVerticalConstraints),Pe=t=>{const e={...t,cGraph:Rd(t.direction)({...t.cGraph,cNodes:(()=>{const n=r=>{if(r.tag==="Leaf")return M;if(r.tag==="Node")return $t("Node",r._1,r._2,r._3,{...r._4,constraints:[]},n(r._5),n(r._6));c()};return n(t.cGraph.cNodes)})()})};return{...e,cGraph:Zs((()=>{if(e.constraintAlgorithm.tag==="Nothing")return e.cGraph;if(e.constraintAlgorithm.tag==="Just")return e.constraintAlgorithm._1(e);c()})())}},Fd=t=>e=>n=>{const r={...n,direction:e};if(t==="UNDEFINED")return e==="LEFT"?Pe(r):e==="RIGHT"?Pe({...r,cGraph:be(r.cGraph)}):e==="UP"?Pe({...r,cGraph:He(r.cGraph)}):e==="DOWN"?Pe({...r,cGraph:be(He(r.cGraph))}):r;if(t==="LEFT")return e==="RIGHT"?hi({...r,cGraph:be(r.cGraph)}):e==="UP"?Pe({...r,cGraph:He(r.cGraph)}):e==="DOWN"?Pe({...r,cGraph:be(He(r.cGraph))}):r;if(t==="RIGHT")return e==="LEFT"?hi({...r,cGraph:be(r.cGraph)}):e==="UP"?Pe({...r,cGraph:He(be(r.cGraph))}):e==="DOWN"?Pe({...r,cGraph:be(He(be(r.cGraph)))}):r;if(t==="UP")return e==="LEFT"?Pe({...r,cGraph:He(r.cGraph)}):e==="RIGHT"?Pe({...r,cGraph:be(He(r.cGraph))}):e==="DOWN"?hi({...r,cGraph:be(r.cGraph)}):r;if(t==="DOWN")return e==="LEFT"?Pe({...r,cGraph:He(be(r.cGraph))}):e==="RIGHT"?Pe({...r,cGraph:be(He(be(r.cGraph)))}):e==="UP"?hi({...r,cGraph:be(r.cGraph)}):r;c()},ta=t=>e=>e.finished||!Cd(t)(e.cGraph.supportedDirections)||(t==="LEFT"?e.direction==="LEFT":t==="RIGHT"?e.direction==="RIGHT":t==="UP"?e.direction==="UP":t==="DOWN"?e.direction==="DOWN":t==="UNDEFINED"&&e.direction==="UNDEFINED")?e:Fd(e.direction)(t)(e),Bd=t=>{if(t.finished)return t;const e=t.direction==="UNDEFINED"?ta(Uo)(t):t,n={...e,cGraph:Dd(e.cGraph)};if(n.compactionAlgorithm.tag==="Nothing")return n;if(n.compactionAlgorithm.tag==="Just")return n.compactionAlgorithm._1(n);c()},ea=t=>e=>n=>{const r=Yt(t)(n.cNodes),i=Yt(e)(n.cGroups);return r.tag==="Just"&&i.tag==="Just"?(()=>{if(r._1.cGroup.tag==="Nothing")return!1;if(r._1.cGroup.tag==="Just")return!0;c()})()&&(r._1.cGroup.tag==="Nothing"||!(r._1.cGroup.tag==="Just"&&r._1.cGroup._1===e))?n:{...n,cNodes:K(nt)(t)({...r._1,cGroup:L("Just",e)})(n.cNodes),cGroups:K(nt)(e)({...i._1,cNodes:ke(_r)(t)(i._1.cNodes)?i._1.cNodes:[...i._1.cNodes,t],reference:(()=>{if(i._1.reference.tag==="Nothing")return L("Just",t);if(i._1.reference.tag==="Just")return L("Just",i._1.reference._1);c()})()})(n.cGroups)}:n},na=t=>e=>({id:e.nextCNodeId,graph:{...e,cNodes:K(nt)(e.nextCNodeId)({id:e.nextCNodeId,origin:t.origin,kind:t.kind,cGroup:T,cGroupOffset:Sd,hitbox:t.hitbox,hitboxPreCompaction:t.hitbox,constraints:[],startPos:-1e308})(e.cNodes),cNodeOrder:[...e.cNodeOrder,e.nextCNodeId],nextCNodeId:e.nextCNodeId+1|0}}),Xo=t=>e=>{const n=e.nextCGroupId;return{id:n,graph:J(r=>i=>ea(i)(n)(r))({...e,cGroups:K(nt)(n)({id:n,master:t.master,cNodes:[],startPos:-1e308,incomingConstraints:[],outDegree:0,outDegreeReal:0,reference:T,delta:0,deltaNormalized:0})(e.cGroups),cGroupOrder:[...e.cGroupOrder,n],nextCGroupId:n+1|0})(t.nodes)}},Md=t=>J(e=>n=>{const r=Yt(n)(e.cNodes);return r.tag==="Just"&&r._1.cGroup.tag==="Nothing"?Xo({master:T,nodes:[n]})(e).graph:e})(t)(t.cNodeOrder),$d=t=>({cGraph:Qd(Md(Yo(t))),direction:js,compactionAlgorithm:T,constraintAlgorithm:T,spacingsHandler:Id,lockFun:T,finished:!1}),pi=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ra=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},zd=t=>e=>n=>r=>i=>({id:t,representedEdges:[i],affectedBends:[e,n],hitbox:{x:pi(e._1)(n._1),y:pi(e._2)(n._2),width:On(e._1-n._1),height:On(e._2-n._2)},ignoreSpacing:Ad,potentialGroupParents:(()=>{if(r.tag==="Nothing")return[];if(r.tag==="Just")return[r._1];c()})(),aPort:T}),Od=t=>e=>{const n=pi(t.hitbox.x)(e.hitbox.x),r=pi(t.hitbox.y)(e.hitbox.y);return{...t,representedEdges:[...t.representedEdges,...e.representedEdges],affectedBends:[...t.affectedBends,...e.affectedBends],potentialGroupParents:[...t.potentialGroupParents,...e.potentialGroupParents],hitbox:{x:n,y:r,width:ra(t.hitbox.x+t.hitbox.width)(e.hitbox.x+e.hitbox.width)-n,height:ra(t.hitbox.y+t.hitbox.height)(e.hitbox.y+e.hitbox.height)-r},ignoreSpacing:{left:t.ignoreSpacing.left||e.ignoreSpacing.left,right:t.ignoreSpacing.right||e.ignoreSpacing.right,up:t.ignoreSpacing.up||e.ignoreSpacing.up,down:t.ignoreSpacing.down||e.ignoreSpacing.down},aPort:(()=>{if(t.aPort.tag==="Just")return t.aPort;if(t.aPort.tag==="Nothing")return e.aPort;c()})()}},qd=t=>e=>On(t.hitbox.x-e.hitbox.x)<=1e-4&&e.hitbox.y-(t.hitbox.y+t.hitbox.height)<=1e-4&&t.hitbox.y-(e.hitbox.y+e.hitbox.height)<=1e-4,Hd=t=>e=>On(t.hitbox.x-e.hitbox.x)<=1e-4?dt.compare(t.hitbox.y)(e.hitbox.y):t.hitbox.x<e.hitbox.x?me:Ne,ia=(t,e)=>({tag:t,_1:e}),en=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Wd=J(t=>e=>K(Gd)(e)()(t))(M),oa=Vt(C)(Dt),Ko=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Vd=t=>xt(e=>{if(e.direction==="V")return L("Just",{start:e.start,end:e.end});if(e.direction==="H")return T;c()})(t.segments),ua=t=>e=>n=>{if(n.tag==="Just"){const r=en(e)(t);if(r.tag==="Just"){const i=ge(o=>o.id===n._1)(r._1);if(i.tag==="Just")return i._1.side;if(i.tag==="Nothing")return Oe;c()}if(r.tag==="Nothing")return Oe;c()}if(n.tag==="Nothing")return Oe;c()},Ud=t=>e=>{const n=na({origin:L("Just",ia("SegmentOrigin",e)),kind:L("Just","vs"),hitbox:e.hitbox})(t.cGraph);return{...t,cGraph:(()=>{if(0<e.potentialGroupParents.length){const r=Yt(e.potentialGroupParents[0])(n.graph.cNodes);if(r.tag==="Just"){if(r._1.cGroup.tag==="Just")return ea(n.id)(r._1.cGroup._1)(n.graph);if(r._1.cGroup.tag==="Nothing")return n.graph;c()}if(r.tag==="Nothing")return n.graph;c()}return Xo({master:L("Just",n.id),nodes:[n.id]})(n.graph).graph})(),edgeToCs:J(r=>i=>Tt(C)(ue)(i)([n.id])(r))(t.edgeToCs)(e.representedEdges)}},Yd=t=>e=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),vt(Hd)(t));if(n.tag==="Nothing")return e;if(n.tag==="Just"){const r=J(i=>o=>qd(i.survivor)(o)?{...i,survivor:Od(i.survivor)(o)}:{survivor:o,merged:[...i.merged,i.survivor]})({survivor:n._1.head,merged:[]})(n._1.tail);return J(Ud)(e)([...r.merged,r.survivor])}c()},Xd=t=>({cGraph:{cNodes:M,cNodeOrder:[],cGroups:M,cGroupOrder:[],supportedDirections:Wd([js,Uo,Ed]),predefinedHorizontalConstraints:[],predefinedVerticalConstraints:[],nextCNodeId:0,nextCGroupId:0},nodeToC:M,edgeToCs:M}),Kd=t=>e=>J(n=>r=>{const i=na({origin:L("Just",ia("NodeOrigin",r.node)),kind:T,hitbox:{x:r.position._1,y:r.position._2,width:r.size._1,height:r.size._2}})(n.cGraph);return{...n,cGraph:Xo({master:L("Just",i.id),nodes:[i.id]})(i.graph).graph,nodeToC:K(C)(r.node)(i.id)(n.nodeToC)}})(e)(t),jd=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?K(C)(n.origin._1._1)(n.hitbox.x)(e):e)(M)(xt(e=>Yt(e)(t.cNodes))(t.cNodeOrder)),Zd=t=>J(e=>n=>n.origin.tag==="Just"&&n.origin._1.tag==="NodeOrigin"?K(C)(n.origin._1._1)(n.hitbox.x-n.hitboxPreCompaction.x)(e):e)(M)(xt(e=>Yt(e)(t.cNodes))(t.cNodeOrder)),tl=t=>J(e=>n=>{if(n.origin.tag==="Just"&&n.origin._1.tag==="SegmentOrigin"){const r=n.hitbox.x-n.hitboxPreCompaction.x;return J(i=>o=>K(C)(o)(r)(i))(e)(n.origin._1._1.representedEdges)}return e})(M)(xt(e=>Yt(e)(t.cNodes))(t.cNodeOrder)),sa=t=>{const e=oa(O(n=>w(n.id,n))(t.edges));return xt(n=>{const r=Ko(n.edge)(e);if(r.tag==="Just")return L("Just",{edgeId:n.edge,src:r._1.from.node,tgt:r._1.to.node,srcSide:ua(t.ports)(r._1.from.node)(r._1.from.port),tgtSide:ua(t.ports)(r._1.to.node)(r._1.to.port),path:n});if(r.tag==="Nothing")return T;c()})(t.paths)},el=t=>e=>{const n=xt(r=>{if((r.srcSide==="North"||r.srcSide==="South")&&(r.tgtSide==="North"||r.tgtSide==="South"))return T;const i=en(r.src)(t.nodeToC);if(i.tag==="Just"){const o=en(r.tgt)(t.nodeToC);if(o.tag==="Just"){const u=Yt(i._1)(t.cGraph.cNodes);if(u.tag==="Just"){const s=Yt(o._1)(t.cGraph.cNodes);if(s.tag==="Just"){if(u._1.cGroup.tag==="Just"){if(s._1.cGroup.tag==="Just")return L("Just",{srcGroup:u._1.cGroup._1,tgtGroup:s._1.cGroup._1,delta:0,weight:100});if(s._1.cGroup.tag==="Nothing")return T;c()}if(u._1.cGroup.tag==="Nothing")return T;c()}if(s.tag==="Nothing")return T;c()}if(u.tag==="Nothing")return T;c()}if(o.tag==="Nothing")return T;c()}if(i.tag==="Nothing")return T;c()})(e);return{sameEdgeVerticalSegments:r=>i=>r.origin.tag==="Just"&&r.origin._1.tag==="SegmentOrigin"&&i.origin.tag==="Just"&&i.origin._1.tag==="SegmentOrigin"&&(()=>{const o=i.origin._1._1;return Ze(u=>ke(ze)(u)(o.representedEdges),r.origin._1._1.representedEdges)})(),vsLNodePair:r=>i=>r.origin.tag==="Just"&&i.origin.tag==="Just"&&(r.origin._1.tag==="SegmentOrigin"?i.origin._1.tag==="NodeOrigin":r.origin._1.tag==="NodeOrigin"&&i.origin._1.tag==="SegmentOrigin"),edgeLengthEdges:r=>n}},nl=t=>e=>n=>r=>i=>o=>{const u=o._1===0,s=zd(i.nextId)(o._2.start)(o._2.end)(u&&(t.srcSide==="North"||t.srcSide==="South")?en(t.src)(M):T)(t.edgeId),a=(()=>{if(u){if(t.srcSide==="North")return{...s,aPort:L("Just",{node:t.src,side:se})};if(t.srcSide==="South")return{...s,aPort:L("Just",{node:t.src,side:ae})};if(e.tag==="Nothing")return s;if(e.tag==="Just")return s.hitbox.y>=e._1.y&&s.hitbox.y+s.hitbox.height<=e._1.y+e._1.height?{...s,ignoreSpacing:{...s.ignoreSpacing,up:!0,down:!0}}:s;c()}return s})();return{nextId:i.nextId+1|0,segments:[...i.segments,(()=>{if(o._1===r){if(n.tag==="Nothing")return a;if(n.tag==="Just")return a.hitbox.y>=n._1.y&&a.hitbox.y+a.hitbox.height<=n._1.y+n._1.height?{...a,ignoreSpacing:{...a.ignoreSpacing,up:!0,down:!0}}:a;c()}return a})()]}},rl=t=>e=>n=>{const r=Vd(n.path);return J(nl(n)((()=>{const i=en(n.src)(t.nodeToC);if(i.tag==="Just"){const o=Yt(i._1)(t.cGraph.cNodes);return o.tag==="Just"?L("Just",o._1.hitbox):T}if(i.tag==="Nothing")return T;c()})())((()=>{const i=en(n.tgt)(t.nodeToC);if(i.tag==="Just"){const o=Yt(i._1)(t.cGraph.cNodes);return o.tag==="Just"?L("Just",o._1.hitbox):T}if(i.tag==="Nothing")return T;c()})())(r.length-1|0))(e)(At(i=>o=>w(i,o))(r))},il=t=>e=>Yd(J(rl(e))({nextId:0,segments:[]})(t).segments)(e),ol=t=>il(sa(t))(Kd(t.nodes)(Xd())),ul=t=>e=>{const n=jd(t),r=Zd(t),i=oa(O(u=>w(u.id,w(u.from.node,u.to.node)))(e.edges)),o=tl(t);return{nodes:O(u=>{const s=en(u.node)(n);if(s.tag==="Just")return{...u,position:w(s._1,u.position._2)};if(s.tag==="Nothing")return u;c()})(e.nodes),edges:O(u=>({...u,bends:(()=>{const s=u.edge;return O(a=>{const f=Ko(s)(o);if(f.tag==="Just")return w(a._1+f._1,a._2);if(f.tag==="Nothing")return a;c()})(u.bends)})(),segments:(()=>{const s=Ko(u.edge)(i);if(s.tag==="Nothing")return u.segments;if(s.tag==="Just"){const a=en(s._1._1)(r),f=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()})()*ot(4),g=en(s._1._2)(r),d=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;c()})()*ot(4),l=Bt(_=>T,_=>h=>L("Just",{head:_,tail:h}),u.segments);if(l.tag==="Nothing")return u.segments;if(l.tag==="Just"){const _={...l._1.head,start:w(l._1.head.start._1+f,l._1.head.start._2)},h=Vu(l._1.tail);if(h.tag==="Nothing")return[{..._,end:w(_.end._1+d,_.end._2)}];if(h.tag==="Just")return[_,...oe(h._1.init)({...h._1.last,end:w(h._1.last.end._1+d,h._1.last.end._2)})]}}c()})()}))(e.paths)}},nn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},jo=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Zo=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},sl=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},al=t=>{const e=t.Eq0();return n=>r=>{const i=s=>{let a=s,f=!0,g;for(;f;){const d=a,l=Bt(_=>T,_=>h=>L("Just",{head:_,tail:h}),d.queue);if(l.tag==="Nothing"){f=!1,g=d;continue}if(l.tag==="Just"){const _=l._1.head;if((p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=!1;continue}if(x.tag==="Node"){const v=t.compare(_)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=!0;continue}}c()}return y})(d.removedNodes)){a={...d,queue:l._1.tail};continue}const h=ge(p=>!nn(p.eid)(d.removedEdges)&&(e.eq(p.src)(_)||e.eq(p.tgt)(_)))(r);if(h.tag==="Nothing"){a={...d,queue:l._1.tail};continue}if(h.tag==="Just"){const p=e.eq(h._1.src)(_)?h._1.tgt:h._1.src,m={...d,degree:K(t)(p)((()=>{const N=(y=>{let x=y,v=!0,b;for(;v;){const E=x;if(E.tag==="Leaf"){v=!1,b=T;continue}if(E.tag==="Node"){const k=t.compare(p)(E._3);if(k==="LT"){x=E._5;continue}if(k==="GT"){x=E._6;continue}if(k==="EQ"){v=!1,b=L("Just",E._4);continue}}c()}return b})(d.degree);if(N.tag==="Nothing")return-1;if(N.tag==="Just")return N._1-1|0;c()})())(d.degree),removedNodes:K(t)(_)()(d.removedNodes),removedEdges:K(nt)(h._1.eid)()(d.removedEdges),record:[...d.record,{node:_,neighbour:p,viaSrc:e.eq(h._1.src)(_)}],queue:l._1.tail};if((()=>{const N=(x=>{let v=x,b=!0,E;for(;b;){const k=v;if(k.tag==="Leaf"){b=!1,E=T;continue}if(k.tag==="Node"){const F=t.compare(p)(k._3);if(F==="LT"){v=k._5;continue}if(F==="GT"){v=k._6;continue}if(F==="EQ"){b=!1,E=L("Just",k._4);continue}}c()}return E})(m.degree),y=x=>{let v=x,b=!0,E;for(;b;){const k=v;if(k.tag==="Leaf"){b=!1,E=!1;continue}if(k.tag==="Node"){const F=t.compare(p)(k._3);if(F==="LT"){v=k._5;continue}if(F==="GT"){v=k._6;continue}if(F==="EQ"){b=!1,E=!0;continue}}c()}return E};return(()=>{if(N.tag==="Nothing")return!1;if(N.tag==="Just")return N._1===1;c()})()&&!y(m.removedNodes)})()){a={...m,queue:[...m.queue,p]};continue}a=m;continue}}c()}return g},o=J(s=>a=>Tt(t)(Zt)(a.src)(1)(Tt(t)(Zt)(a.tgt)(1)(s)))(M)(r),u=i({degree:o,removedNodes:M,removedEdges:M,record:[],queue:ct(s=>{const a=(f=>{let g=f,d=!0,l;for(;d;){const _=g;if(_.tag==="Leaf"){d=!1,l=T;continue}if(_.tag==="Node"){const h=t.compare(s)(_._3);if(h==="LT"){g=_._5;continue}if(h==="GT"){g=_._6;continue}if(h==="EQ"){d=!1,l=L("Just",_._4);continue}}c()}return l})(o);if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1===1;c()},n)});return{coreNodes:ct(s=>!(a=>{let f=a,g=!0,d;for(;g;){const l=f;if(l.tag==="Leaf"){g=!1,d=!1;continue}if(l.tag==="Node"){const _=t.compare(s)(l._3);if(_==="LT"){f=l._5;continue}if(_==="GT"){f=l._6;continue}if(_==="EQ"){g=!1,d=!0;continue}}c()}return d})(u.removedNodes),n),coreEdges:ct(s=>!nn(s.eid)(u.removedEdges),r),removed:u.record}}},cl=t=>e=>n=>J(r=>i=>{const o=i.neighbour,u=(()=>{const s=(a=>{let f=a,g=!0,d;for(;g;){const l=f;if(l.tag==="Leaf"){g=!1,d=T;continue}if(l.tag==="Node"){const _=t.compare(o)(l._3);if(_==="LT"){f=l._5;continue}if(_==="GT"){f=l._6;continue}if(_==="EQ"){g=!1,d=L("Just",l._4);continue}}c()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();return K(t)(i.node)(i.viaSrc?u-1|0:u+1|0)(r)})(n)(de(e)),tu=t=>{const e=t.Eq0();return n=>r=>i=>{const o={...i,treeNode:K(t)(r)()(i.treeNode)};return J(u=>s=>{if(nn(s.eid)(u.st.edgeVisited))return u;const a={...u.st,edgeVisited:K(nt)(s.eid)()(u.st.edgeVisited)},f=e.eq(s.src)((()=>{const g=s.src,d=_=>{let h=_,p=!0,m;for(;p;){const N=h;if(N.tag==="Leaf"){p=!1,m=!1;continue}if(N.tag==="Node"){const y=t.compare(g)(N._3);if(y==="LT"){h=N._5;continue}if(y==="GT"){h=N._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}c()}return m},l=s.tgt;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const N=h;if(N.tag==="Leaf"){p=!1,m=!1;continue}if(N.tag==="Node"){const y=t.compare(l)(N._3);if(y==="LT"){h=N._5;continue}if(y==="GT"){h=N._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}c()}return m})(a.treeNode)})()?s.src:(()=>{const g=s.tgt,d=_=>{let h=_,p=!0,m;for(;p;){const N=h;if(N.tag==="Leaf"){p=!1,m=!1;continue}if(N.tag==="Node"){const y=t.compare(g)(N._3);if(y==="LT"){h=N._5;continue}if(y==="GT"){h=N._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}c()}return m},l=s.src;return d(a.treeNode)&&!(_=>{let h=_,p=!0,m;for(;p;){const N=h;if(N.tag==="Leaf"){p=!1,m=!1;continue}if(N.tag==="Node"){const y=t.compare(l)(N._3);if(y==="LT"){h=N._5;continue}if(y==="GT"){h=N._6;continue}if(y==="EQ"){p=!1,m=!0;continue}}c()}return m})(a.treeNode)})()?s.tgt:s.src)?s.tgt:s.src;if(nn(s.eid)(a.treeEdge)){if((d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=!1;continue}if(p.tag==="Node"){const m=t.compare(f)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=!0;continue}}c()}return h})(a.treeNode))return{...u,st:a};const g=tu(t)(n)(f)(a);return{count:u.count+g.count|0,st:g.st}}if((()=>{const g=l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=!1;continue}if(m.tag==="Node"){const N=t.compare(f)(m._3);if(N==="LT"){_=m._5;continue}if(N==="GT"){_=m._6;continue}if(N==="EQ"){h=!1,p=!0;continue}}c()}return p},d=s.tgt;return!g(a.treeNode)&&(()=>{const l=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(d)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(a.layer),_=s.src,h=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(_)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(a.layer);if(l.tag==="Nothing"){if(h.tag==="Nothing")return s.delta===0;if(h.tag==="Just")return s.delta===-h._1;c()}if(l.tag==="Just"){if(h.tag==="Nothing")return s.delta===(l._1-0|0);if(h.tag==="Just")return s.delta===(l._1-h._1|0)}c()})()})()){const g=tu(t)(n)(f)({...a,treeEdge:K(nt)(s.eid)()(a.treeEdge)});return{count:u.count+g.count|0,st:g.st}}return{...u,st:a}})({count:1,st:o})(ct(u=>(e.eq(u.src)(r)||e.eq(u.tgt)(r))&&!nn(u.eid)(o.edgeVisited),n))}},mi=t=>e=>n=>r=>{const i=r.src,o=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=T;continue}if(m.tag==="Node"){const N=t.compare(i)(m._3);if(N==="LT"){_=m._5;continue}if(N==="GT"){_=m._6;continue}if(N==="EQ"){h=!1,p=L("Just",m._4);continue}}c()}return p})(e.poID),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})(),s=r.tgt,a=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=T;continue}if(m.tag==="Node"){const N=t.compare(s)(m._3);if(N==="LT"){_=m._5;continue}if(N==="GT"){_=m._6;continue}if(N==="EQ"){h=!1,p=L("Just",m._4);continue}}c()}return p})(e.poID),f=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()})(),g=(l=>{let _=l,h=!0,p;for(;h;){const m=_;if(m.tag==="Leaf"){h=!1,p=T;continue}if(m.tag==="Node"){const N=t.compare(n)(m._3);if(N==="LT"){_=m._5;continue}if(N==="GT"){_=m._6;continue}if(N==="EQ"){h=!1,p=L("Just",m._4);continue}}c()}return p})(e.poID),d=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;c()})();return(()=>{const l=r.src,_=(h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=T;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=L("Just",y._4);continue}}c()}return N})(e.lowestPoID);return(()=>{if(_.tag==="Nothing")return 0<=d;if(_.tag==="Just")return _._1<=d;c()})()&&(()=>{const h=r.tgt;return d<=u&&(()=>{const p=(m=>{let N=m,y=!0,x;for(;y;){const v=N;if(v.tag==="Leaf"){y=!1,x=T;continue}if(v.tag==="Node"){const b=t.compare(h)(v._3);if(b==="LT"){N=v._5;continue}if(b==="GT"){N=v._6;continue}if(b==="EQ"){y=!1,x=L("Just",v._4);continue}}c()}return x})(e.lowestPoID);return(()=>{if(p.tag==="Nothing")return 0<=d;if(p.tag==="Just")return p._1<=d;c()})()&&d<=f})()})()})()?u>=f:u<f},fl=t=>{const e=Vt(t)(Dt);return n=>({layer:e(O(r=>w(r,0))(n)),treeNode:M,treeEdge:M,poID:M,lowestPoID:M,cutvalue:M,postOrder:1,edgeVisited:M})},gl=t=>e=>n=>J(r=>i=>{if((()=>{const g=i.src,d=h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=!1;continue}if(y.tag==="Node"){const x=t.compare(g)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=!0;continue}}c()}return N},l=i.tgt,_=h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=!1;continue}if(y.tag==="Node"){const x=t.compare(l)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=!0;continue}}c()}return N};return d(n.treeNode)===_(n.treeNode)})())return r;const o=i.tgt,u=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(o)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(n.layer),s=i.src,a=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(s)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(n.layer),f=(()=>{if(u.tag==="Nothing"){if(a.tag==="Nothing")return-i.delta;if(a.tag==="Just")return-a._1-i.delta|0;c()}if(u.tag==="Just"){if(a.tag==="Nothing")return(u._1-0|0)-i.delta|0;if(a.tag==="Just")return(u._1-a._1|0)-i.delta|0}c()})();return f<r.slack?{edge:L("Just",i),slack:f}:r})({edge:T,slack:1e9})(e).edge,_l=t=>{const e=Vt(t)(Dt);return n=>r=>{const i=J(o=>u=>jo(o)((()=>{const s=(a=>{let f=a,g=!0,d;for(;g;){const l=f;if(l.tag==="Leaf"){g=!1,d=T;continue}if(l.tag==="Node"){const _=t.compare(u)(l._3);if(_==="LT"){f=l._5;continue}if(_==="GT"){f=l._6;continue}if(_==="EQ"){g=!1,d=L("Just",l._4);continue}}c()}return d})(r);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(1e9)(n);return e(O(o=>w(o,(()=>{const u=(s=>{let a=s,f=!0,g;for(;f;){const d=a;if(d.tag==="Leaf"){f=!1,g=T;continue}if(d.tag==="Node"){const l=t.compare(o)(d._3);if(l==="LT"){a=d._5;continue}if(l==="GT"){a=d._6;continue}if(l==="EQ"){f=!1,g=L("Just",d._4);continue}}c()}return g})(r);if(u.tag==="Nothing")return-i;if(u.tag==="Just")return u._1-i|0;c()})()))(n))}},aa=t=>{const e=t.Eq0();return n=>r=>i=>{const o=J(s=>a=>{const f=aa(t)(n)(e.eq(a.src)(r)?a.tgt:a.src)({...s.st,edgeVisited:K(nt)(a.eid)()(s.st.edgeVisited)});return{lowest:jo(s.lowest)(f.lowest),st:f.st}})({lowest:1e9,st:i})(ct(s=>nn(s.eid)(i.treeEdge)&&(e.eq(s.src)(r)||e.eq(s.tgt)(r))&&!nn(s.eid)(i.edgeVisited),n)),u=jo(o.lowest)(o.st.postOrder);return{lowest:u,st:{...o.st,poID:K(t)(r)(o.st.postOrder)(o.st.poID),lowestPoID:K(t)(r)(u)(o.st.lowestPoID),postOrder:o.st.postOrder+1|0}}}},ca=t=>{const e=aa(t);return n=>r=>i=>0<n.length?e(r)(n[0])({...i,edgeVisited:M,postOrder:1,poID:M,lowestPoID:M}).st:i},dl=t=>{const e=t.Eq0();return n=>r=>i=>ct(o=>nn(o.eid)(r.treeEdge)&&(e.eq(o.src)(i)||e.eq(o.tgt)(i)),n)},ll=t=>e=>ge(n=>{const r=Zo(n.eid)(e.cutvalue);return nn(n.eid)(e.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<-1e-10;c()})()})(t),fa=t=>{const e=tu(t);return n=>r=>i=>{const o=0<n.length?L("Just",n[0]):T;if(o.tag==="Nothing")return i;if(o.tag==="Just"){const u=e(r)(o._1)({...i,edgeVisited:M,treeNode:M,treeEdge:M});if(u.count>=n.length)return u.st;const s=gl(t)(r)(u.st);if(s.tag==="Nothing")return u.st;if(s.tag==="Just"){const a=s._1.tgt,f=(h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=T;continue}if(y.tag==="Node"){const x=t.compare(a)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=L("Just",y._4);continue}}c()}return N})(u.st.layer),g=s._1.src,d=(h=>{let p=h,m=!0,N;for(;m;){const y=p;if(y.tag==="Leaf"){m=!1,N=T;continue}if(y.tag==="Node"){const x=t.compare(g)(y._3);if(x==="LT"){p=y._5;continue}if(x==="GT"){p=y._6;continue}if(x==="EQ"){m=!1,N=L("Just",y._4);continue}}c()}return N})(u.st.layer),l=(()=>{if(f.tag==="Nothing"){if(d.tag==="Nothing")return-s._1.delta;if(d.tag==="Just")return-d._1-s._1.delta|0;c()}if(f.tag==="Just"){if(d.tag==="Nothing")return(f._1-0|0)-s._1.delta|0;if(d.tag==="Just")return(f._1-d._1|0)-s._1.delta|0}c()})(),_=(()=>{const h=s._1.tgt;return(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=!1;continue}if(x.tag==="Node"){const v=t.compare(h)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=!0;continue}}c()}return y})(u.st.treeNode)})()?-l:l;return fa(t)(n)(r)({...u.st,layer:J(h=>p=>(m=>{let N=m,y=!0,x;for(;y;){const v=N;if(v.tag==="Leaf"){y=!1,x=!1;continue}if(v.tag==="Node"){const b=t.compare(p)(v._3);if(b==="LT"){N=v._5;continue}if(b==="GT"){N=v._6;continue}if(b==="EQ"){y=!1,x=!0;continue}}c()}return x})(u.st.treeNode)?K(t)(p)((()=>{const m=(N=>{let y=N,x=!0,v;for(;x;){const b=y;if(b.tag==="Leaf"){x=!1,v=T;continue}if(b.tag==="Node"){const E=t.compare(p)(b._3);if(E==="LT"){y=b._5;continue}if(E==="GT"){y=b._6;continue}if(E==="EQ"){x=!1,v=L("Just",b._4);continue}}c()}return v})(u.st.layer);if(m.tag==="Nothing")return 0+_|0;if(m.tag==="Just")return m._1+_|0;c()})())(h):h)(u.st.layer)(n)})}}c()}},hl=t=>e=>n=>r=>J(i=>o=>{if(mi(t)(r)(o.src)(n)&&!mi(t)(r)(o.tgt)(n)){const u=o.tgt,s=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=T;continue}if(p.tag==="Node"){const m=t.compare(u)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=L("Just",p._4);continue}}c()}return h})(r.layer),a=o.src,f=(d=>{let l=d,_=!0,h;for(;_;){const p=l;if(p.tag==="Leaf"){_=!1,h=T;continue}if(p.tag==="Node"){const m=t.compare(a)(p._3);if(m==="LT"){l=p._5;continue}if(m==="GT"){l=p._6;continue}if(m==="EQ"){_=!1,h=L("Just",p._4);continue}}c()}return h})(r.layer),g=(()=>{if(s.tag==="Nothing"){if(f.tag==="Nothing")return-o.delta;if(f.tag==="Just")return-f._1-o.delta|0;c()}if(s.tag==="Just"){if(f.tag==="Nothing")return(s._1-0|0)-o.delta|0;if(f.tag==="Just")return(s._1-f._1|0)-o.delta|0}c()})();if(g<i.slack)return{edge:L("Just",o),slack:g}}return i})({edge:T,slack:1e9})(e).edge,pl=t=>{const e=t.Eq0();return n=>r=>i=>o=>{const u=o.tgt,s=o.src;return J(a=>f=>{if((()=>{const g=Zo(f.eid)(r.cutvalue);if(g.tag==="Just")return!0;if(g.tag==="Nothing")return!1;c()})()){const g=Zo(f.eid)(r.cutvalue),d=(()=>{if(g.tag==="Nothing")return 0;if(g.tag==="Just")return g._1;c()})();return e.eq(s)(f.src)||e.eq(u)(f.tgt)?a-(d-f.weight):a+(d-f.weight)}return e.eq(i)(s)?e.eq(f.src)(i)?a+f.weight:a-f.weight:e.eq(f.src)(i)?a-f.weight:a+f.weight})(o.weight)(ct(a=>a.eid!==o.eid&&(e.eq(a.src)(i)||e.eq(a.tgt)(i)),n))}},ml=t=>{const e=pl(t);return n=>r=>i=>{const o=(u,s,a)=>{const f=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(u)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(a);if(f.tag==="Just")return K(t)(u)(ct(g=>g.eid!==s.eid,f._1))(a);if(f.tag==="Nothing")return a;c()};return(u=>s=>{let a=u,f=s,g=!0,d;for(;g;){const l=a,_=f,h=(m=>{let N=m,y=!0,x;for(;y;){const v=N;if(v.tag==="Leaf"){y=!1,x=T;continue}if(v.tag==="Node"){const b=t.compare(_)(v._3);if(b==="LT"){N=v._5;continue}if(b==="GT"){N=v._6;continue}if(b==="EQ"){y=!1,x=L("Just",v._4);continue}}c()}return x})(l.unknown),p=(()=>{if(h.tag==="Nothing")return[];if(h.tag==="Just")return h._1;c()})();if(p.length===1){const m=t.Eq0().eq(p[0].src)(_)?p[0].tgt:p[0].src;a={unknown:o(_,p[0],o(m,p[0],l.unknown)),cutvalue:K(nt)(p[0].eid)(e(n)(l)(_)(p[0]))(l.cutvalue)},f=m;continue}g=!1,d=l}return d})(r)(i)}},ga=t=>{const e=t.Eq0(),n=t.Eq0(),r={eq:f=>g=>f.delta===g.delta&&f.eid===g.eid&&n.eq(f.src)(g.src)&&e.eq(f.tgt)(g.tgt)&&f.weight===g.weight},i={compare:f=>g=>{const d=nt.compare(f.delta)(g.delta);if(d==="LT"||d==="GT"||d!=="EQ")return d;const l=nt.compare(f.eid)(g.eid);if(l==="LT"||l==="GT"||l!=="EQ")return l;const _=t.compare(f.src)(g.src);if(_==="LT"||_==="GT"||_!=="EQ")return _;const h=t.compare(f.tgt)(g.tgt);if(h==="LT"||h==="GT"||h!=="EQ")return h;const p=dt.compare(f.weight)(g.weight);return p==="LT"||p==="GT"||p!=="EQ"?p:we},Eq0:()=>r},o=J(f=>g=>K(i)(g)()(f))(M),u=dl(t),s=Vt(t)(Dt),a=ml(t);return f=>g=>d=>{const l={unknown:s(O(_=>w(_,bt(Ge.foldr,o(u(g)(d)(_)))))(f)),cutvalue:M};return{...d,cutvalue:J(a(g))(l)(ct(_=>{const h=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(_)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(l.unknown);if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1.length===1;c()},f)).cutvalue}}},Nl=t=>{const e=ca(t),n=ga(t);return r=>i=>o=>u=>s=>{const a={...s,treeEdge:K(nt)(u.eid)()(hr(nt)(o.eid)(s.treeEdge))},f=u.tgt,g=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(f)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(a.layer),d=u.src,l=(p=>{let m=p,N=!0,y;for(;N;){const x=m;if(x.tag==="Leaf"){N=!1,y=T;continue}if(x.tag==="Node"){const v=t.compare(d)(x._3);if(v==="LT"){m=x._5;continue}if(v==="GT"){m=x._6;continue}if(v==="EQ"){N=!1,y=L("Just",x._4);continue}}c()}return y})(a.layer),_=(()=>{if(g.tag==="Nothing"){if(l.tag==="Nothing")return-u.delta;if(l.tag==="Just")return-l._1-u.delta|0;c()}if(g.tag==="Just"){if(l.tag==="Nothing")return(g._1-0|0)-u.delta|0;if(l.tag==="Just")return(g._1-l._1|0)-u.delta|0}c()})(),h=mi(t)(a)(u.tgt)(o)?-_:_;return n(r)(i)(e(r)(i)({...a,layer:J(p=>m=>mi(t)(a)(m)(o)?p:K(t)(m)((()=>{const N=(y=>{let x=y,v=!0,b;for(;v;){const E=x;if(E.tag==="Leaf"){v=!1,b=T;continue}if(E.tag==="Node"){const k=t.compare(m)(E._3);if(k==="LT"){x=E._5;continue}if(k==="GT"){x=E._6;continue}if(k==="EQ"){v=!1,b=L("Just",E._4);continue}}c()}return b})(a.layer);if(N.tag==="Nothing")return 0+h|0;if(N.tag==="Just")return N._1+h|0;c()})())(p))(a.layer)(r)}))}},yl=t=>{const e=Nl(t);return n=>r=>i=>o=>(u=>s=>{let a=u,f=s,g=!0,d;for(;g;){const l=a,_=f;if(l===0){g=!1,d=_;continue}const h=ll(i)(_);if(h.tag==="Nothing"){g=!1,d=_;continue}if(h.tag==="Just"){const p=hl(t)(i)(h._1)(_);if(p.tag==="Nothing"){g=!1,d=_;continue}if(p.tag==="Just"){a=l-1|0,f=e(r)(i)(h._1)(p._1)(_);continue}}c()}return d})(n)(o)},Jl=t=>{const e=ga(t),n=ca(t),r=fa(t);return i=>o=>u=>e(i)(o)(n(i)(o)(r(i)(o)(u)))},_a=t=>e=>J(n=>r=>Tt(t)(ue)(e(r))([r])(n))(M),xl=t=>{const e=Vt(t)(Dt);return n=>r=>i=>{const o=a=>f=>g=>d=>{let l=a,_=f,h=g,p=d,m=!0,N;for(;m;){const y=l,x=_,v=h,b=p,E=Bt(k=>T,k=>F=>L("Just",{head:k,tail:F}),v);if(E.tag==="Nothing"){m=!1,N=b;continue}if(E.tag==="Just"){const k=E._1.head,F=(Q=>{let S=Q,Z=!0,V;for(;Z;){const R=S;if(R.tag==="Leaf"){Z=!1,V=T;continue}if(R.tag==="Node"){const $=t.compare(k)(R._3);if($==="LT"){S=R._5;continue}if($==="GT"){S=R._6;continue}if($==="EQ"){Z=!1,V=L("Just",R._4);continue}}c()}return V})(b.layer),U=(()=>{if(F.tag==="Nothing")return 0;if(F.tag==="Just")return F._1;c()})(),tt=J(Q=>S=>{const Z=S.tgt,V=($=>{let I=$,G=!0,D;for(;G;){const P=I;if(P.tag==="Leaf"){G=!1,D=T;continue}if(P.tag==="Node"){const A=t.compare(Z)(P._3);if(A==="LT"){I=P._5;continue}if(A==="GT"){I=P._6;continue}if(A==="EQ"){G=!1,D=L("Just",P._4);continue}}c()}return D})(Q.incident),R=(()=>{if(V.tag==="Nothing")return-1;if(V.tag==="Just")return V._1-1|0;c()})();return{st:{...Q.st,layer:K(t)(S.tgt)(sl((()=>{const $=S.tgt,I=(G=>{let D=G,P=!0,A;for(;P;){const H=D;if(H.tag==="Leaf"){P=!1,A=T;continue}if(H.tag==="Node"){const Y=t.compare($)(H._3);if(Y==="LT"){D=H._5;continue}if(Y==="GT"){D=H._6;continue}if(Y==="EQ"){P=!1,A=L("Just",H._4);continue}}c()}return A})(Q.st.layer);if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})())(U+S.delta|0))(Q.st.layer)},incident:K(t)(S.tgt)(R)(Q.incident),queue:R===0?[...Q.queue,S.tgt]:Q.queue}})({st:b,incident:x,queue:E._1.tail})((()=>{const Q=(S=>{let Z=S,V=!0,R;for(;V;){const $=Z;if($.tag==="Leaf"){V=!1,R=T;continue}if($.tag==="Node"){const I=t.compare(k)($._3);if(I==="LT"){Z=$._5;continue}if(I==="GT"){Z=$._6;continue}if(I==="EQ"){V=!1,R=L("Just",$._4);continue}}c()}return R})(y);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})());l=y,_=tt.incident,h=tt.queue,p=tt.st;continue}c()}return N},u=_a(t)(a=>a.tgt)(r),s=e(O(a=>w(a,(()=>{const f=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(u);if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1.length;c()})()))(n));return o(_a(t)(a=>a.src)(r))(s)(ct(a=>{const f=(g=>{let d=g,l=!0,_;for(;l;){const h=d;if(h.tag==="Leaf"){l=!1,_=T;continue}if(h.tag==="Node"){const p=t.compare(a)(h._3);if(p==="LT"){d=h._5;continue}if(p==="GT"){d=h._6;continue}if(p==="EQ"){l=!1,_=L("Just",h._4);continue}}c()}return _})(s);if(f.tag==="Nothing")return!0;if(f.tag==="Just")return f._1===0;c()},n))(i)}},Tl=t=>{const e=fl(t),n=xl(t),r=Jl(t),i=yl(t);return o=>u=>{const s=n(o)(u)(e(o));return u.length===0?s.layer:i(4*o.length|0)(o)(u)(r(o)(u)(s)).layer}},da=t=>{const e=_l(t),n=Tl(t),r=al(t);return i=>o=>{if(i.length===0)return M;if(i.length<40)return e(i)(n(i)(o));const u=r(i)(o);return e(i)(cl(t)(u.removed)(n(u.coreNodes)(u.coreEdges)))}},la=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},eu=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},vl=da(nt),Sr=t=>e=>({...e,edges:[...e.edges,{src:t.src,tgt:t.tgt,delta:t.delta,weight:t.weight,eid:e.nextEid}],nextEid:e.nextEid+1|0}),wl=t=>e=>n=>{if(n.cGroup.tag==="Nothing")return e;if(n.cGroup.tag==="Just"){const r=ot((()=>{const i=la(n.cGroup._1)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;c()})());return qe(n.id)(i=>({...i,hitbox:{...i.hitbox,x:r+i.cGroupOffset.x}}))(e)}c()},Ll=t=>e=>({...e,cGraph:J(wl(t))(e.cGraph)((()=>{const n=e.cGraph;return xt(r=>Yt(r)(n.cNodes))(n.cNodeOrder)})())}),bl=t=>e=>n=>r=>i=>{const o=vn(ji(e.cGroupOffset.x-t.cGroupOffset.x));return Sr({src:i.nextNodeId,tgt:r,delta:eu(0)(-o),weight:1})(Sr({src:i.nextNodeId,tgt:n,delta:eu(0)(o),weight:1})({...i,nodes:[...i.nodes,i.nextNodeId],nextNodeId:i.nextNodeId+1|0}))},El=t=>e=>n=>r=>i=>o=>u=>{const s=eu(0)(vn(ji(n.cGroupOffset.x+n.hitbox.width+(e.direction==="LEFT"||e.direction==="RIGHT"?e.spacingsHandler.horizontalSpacing(n)(r):e.spacingsHandler.verticalSpacing(n)(r))-r.cGroupOffset.x)));return t.sameEdgeVerticalSegments(n)(r)?bl(n)(r)(i)(o)(u):Sr({src:i,tgt:o,delta:s,weight:t.vsLNodePair(n)(r)?2:1})(u)},kl=t=>e=>n=>r=>i=>{const o=Yt(i)(e.cGraph.cNodes);if(o.tag==="Nothing")return r;if(o.tag==="Just")return(n.cGroup.tag==="Nothing"?o._1.cGroup.tag==="Nothing":n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"&&n.cGroup._1===o._1.cGroup._1)?r:n.cGroup.tag==="Just"&&o._1.cGroup.tag==="Just"?El(t)(e)(n)(o._1)(n.cGroup._1)(o._1.cGroup._1)(r):r;c()},Gl=t=>e=>n=>r=>J(kl(t)(e)(r))(n)(r.constraints),Cl=t=>e=>Sr({src:e.srcGroup,tgt:e.tgtGroup,delta:e.delta,weight:e.weight})(t),Sl=t=>{const e=J(i=>o=>Tt(nt)(Zt)(o.tgt)(1)(i))(M)(t.edges),n=ct(i=>{const o=la(i)(e);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return o._1===0;c()},t.nodes);if(n.length<=1)return t;const r=t.nextNodeId;return J(i=>o=>Sr({src:r,tgt:o,delta:1,weight:0})(i))({...t,nodes:[...t.nodes,r],nextNodeId:r+1|0})(n)},Ql=t=>e=>{const n=Sl(J(Cl)(J(Gl(t)(e))({nodes:e.cGraph.cGroupOrder,edges:[],nextNodeId:e.cGraph.nextCGroupId,nextEid:0})((()=>{const r=e.cGraph;return xt(i=>Yt(i)(r.cNodes))(r.cNodeOrder)})()))(t.edgeLengthEdges(e.cGraph)));return{nodes:n.nodes,edges:n.edges}},Pl=t=>e=>{const n=Ql(t)(e);return Ll(vl(n.nodes)(n.edges))(e)},Dl=t=>e=>n=>r=>e.id===r.id||e.cGroup.tag==="Just"&&r.cGroup.tag==="Just"&&e.cGroup._1===r.cGroup._1||!(r.hitbox.x>e.hitbox.x||e.hitbox.x===r.hitbox.x&&e.hitbox.width<r.hitbox.width)||(()=>{const i=t.direction==="LEFT"||t.direction==="RIGHT"?t.spacingsHandler.verticalSpacing(e)(r):t.spacingsHandler.horizontalSpacing(e)(r);return!(r.hitbox.y+r.hitbox.height+i-e.hitbox.y>1e-4&&e.hitbox.y+e.hitbox.height+i-r.hitbox.y>1e-4)})()?n:qe(e.id)(i=>({...i,constraints:[...i.constraints,r.id]}))(n),Al=t=>e=>n=>r=>J(Dl(t)(r))(n)(e),Il=t=>{const e=J(r=>i=>qe(i.id)(o=>({...o,constraints:[]}))(r))(t.cGraph)((()=>{const r=t.cGraph;return xt(i=>Yt(i)(r.cNodes))(r.cNodeOrder)})()),n=xt(r=>Yt(r)(e.cNodes))(e.cNodeOrder);return J(Al(t)(n))(e)(n)},ha=t=>t,Xt=ha("H"),Kt=ha("V"),Rl=t=>w(t._2,t._1),pa=t=>({...t,position:w(t.position._2,t.position._1),size:w(t.size._2,t.size._1)}),Fl=t=>({start:w(t.start._2,t.start._1),end:w(t.end._2,t.end._1),direction:(()=>{if(t.direction==="H")return Kt;if(t.direction==="V")return Xt;c()})()}),ma=t=>({...t,segments:O(Fl)(t.segments),bends:O(Rl)(t.bends)}),Bl=t=>({nodes:O(pa)(t.nodes),edges:t.edges,paths:O(ma)(t.paths),ports:t.ports}),Ml={horizontalSpacing:t=>e=>1,verticalSpacing:t=>e=>1},$l=t=>e=>Pl(e),zl=t=>e=>{const n=Bl(e),r=ol(n),i=ul(ta(Uo)(Bd({...$d(r.cGraph),compactionAlgorithm:L("Just",$l()(el(r)(sa(n)))),constraintAlgorithm:L("Just",Il),spacingsHandler:Ml})).cGraph)({nodes:n.nodes,edges:n.edges,paths:n.paths});return{nodes:O(pa)(i.nodes),edges:O(ma)(i.edges)}},Na=t=>t,jn=Vt(nt)(Dt),wt=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},ya=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ut=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},st=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},rn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ol=t=>e=>{const n=nt.compare(t._1)(e._1);return n==="LT"?me:n==="GT"?Ne:nt.compare(t._2)(e._2)},Zn=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ql=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),Hl=t=>t,Ni=Na("Regular"),yi=Na("Critical"),Ja=t=>e=>{const n=J(u=>s=>K(C)(s.node)(s)(u))(M)(e),r=1.25*ot(4),i=(u,s,a)=>(f=>g=>d=>{let l=f,_=g,h=d,p=!0,m;for(;p;){const N=l,y=_,x=h;if(x.critical){p=!1,m=x;continue}const v=Bt(E=>T,E=>k=>L("Just",{head:E,tail:k}),N),b=Bt(E=>T,E=>k=>L("Just",{head:E,tail:k}),y);if(v.tag==="Just"&&b.tag==="Just"){const E=v._1.head>b._1.head-u&&v._1.head<b._1.head+u?{...x,critical:!0}:v._1.head>b._1.head-r&&v._1.head<b._1.head+r?{...x,conflicts:x.conflicts+1|0}:x;if(E.critical){p=!1,m=E;continue}if(v._1.head<=b._1.head){l=v._1.tail,_=y,h=E;continue}l=N,_=b._1.tail,h=E;continue}p=!1,m=x}return m})(s)(a)({conflicts:0,critical:!1}),o=(u,s,a)=>{if(st(J(st)(-1e18)(s.incoming))(J(st)(-1e18)(s.outgoing))-ut(J(ut)(1e18)(s.incoming))(J(ut)(1e18)(s.outgoing))<.001||st(J(st)(-1e18)(a.incoming))(J(st)(-1e18)(a.outgoing))-ut(J(ut)(1e18)(a.incoming))(J(ut)(1e18)(a.outgoing))<.001)return[];const f=i(u,s.outgoing,a.incoming),g=i(u,a.outgoing,s.incoming);if(f.critical||g.critical)return[...f.critical?[{src:a.id,tgt:s.id,weight:1,kind:yi}]:[],...g.critical?[{src:s.id,tgt:a.id,weight:1,kind:yi}]:[]];const d=ut(J(ut)(1e18)(s.incoming))(J(ut)(1e18)(s.outgoing)),l=st(J(st)(-1e18)(s.incoming))(J(st)(-1e18)(s.outgoing)),_=ut(J(ut)(1e18)(a.incoming))(J(ut)(1e18)(a.outgoing)),h=st(J(st)(-1e18)(a.incoming))(J(st)(-1e18)(a.outgoing)),p=(1*f.conflicts|0)+(16*(J(N=>y=>y>h?N:y>=_?N+1|0:N)(0)(s.outgoing)+J(N=>y=>y>l?N:y>=d?N+1|0:N)(0)(a.incoming)|0)|0)|0,m=(1*g.conflicts|0)+(16*(J(N=>y=>y>l?N:y>=d?N+1|0:N)(0)(a.outgoing)+J(N=>y=>y>h?N:y>=_?N+1|0:N)(0)(s.incoming)|0)|0)|0;return p<m?[{src:s.id,tgt:a.id,weight:m-p|0,kind:Ni}]:p>m?[{src:a.id,tgt:s.id,weight:p-m|0,kind:Ni}]:p>0?[{src:s.id,tgt:a.id,weight:0,kind:Ni},{src:a.id,tgt:s.id,weight:0,kind:Ni}]:[]};return J(u=>s=>J(a=>f=>K(C)(f._1)(f._2)(a))(u)((()=>{const a=J(Q=>S=>{const Z=S.edge.from.node+"|"+(()=>{if(S.edge.from.port.tag==="Just")return S.edge.from.port._1;if(S.edge.from.port.tag==="Nothing")return"_auto_"+S.edge.id;c()})(),V=rn(Z)(Q.entries);if(V.tag==="Nothing")return{...Q,entries:K(C)(Z)({id:0,members:[S.edge.id],incoming:[S.fromPos._1],outgoing:[S.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(Q.entries),order:[...Q.order,Z]};if(V.tag==="Just")return{...Q,entries:K(C)(Z)({...V._1,members:[...V._1.members,S.edge.id],incoming:[...Tn(R=>R<S.fromPos._1)(V._1.incoming).init,S.fromPos._1,...Tn(R=>R<=S.fromPos._1)(V._1.incoming).rest],outgoing:[...Tn(R=>R<S.toPos._1)(V._1.outgoing).init,S.toPos._1,...Tn(R=>R<=S.toPos._1)(V._1.outgoing).rest]})(Q.entries)};c()})({entries:M,order:[]})(s._2),f=At(Q=>S=>({...S,id:Q}))(xt(Q=>rn(Q)(a.entries))(a.order));if(f.length===0)return[];const g=J(Q=>S=>Q.prev.tag==="Just"&&S-Q.prev._1<1e-9?Q:{prev:L("Just",S),out:[...Q.out,S]})({prev:T,out:[]})(vt(dt.compare)([...St(f)(Q=>Q.incoming),...St(f)(Q=>Q.outgoing)])).out,d=g.length<2?.2*r:.2*J(Q=>S=>{if(Q.prev.tag==="Nothing")return{prev:L("Just",S),mn:Q.mn};if(Q.prev.tag==="Just")return{prev:L("Just",S),mn:ut(Q.mn)(S-Q.prev._1)};c()})({prev:T,mn:1e18})(g).mn,l={segments:f,deps:(()=>{const Q=f.length;return St(St(Ht(0,Q-2|0))(S=>St(Ht(S+1|0,Q-1|0))(Z=>[w(S,Z)])))(S=>S._1>=0&&S._1<f.length?S._2>=0&&S._2<f.length?o(d,f[S._1],f[S._2]):[]:[])})()},_=ct(Q=>{if(Q.kind==="Critical")return!0;if(Q.kind==="Regular")return!1;c()},l.deps),h=(()=>{if(_.length<2)return l;const Q=jn((()=>{const $=l.segments;return O(I=>w(I.id,I.mark))((()=>{const I=$.length,G=P=>{let A=P,H=!0,Y;for(;H;){const W=A,q=ge(B=>{const j=wt(B)(W.inWeight);if(j.tag==="Nothing")return!0;if(j.tag==="Just")return j._1===0;c()})(W.remaining);if(q.tag==="Nothing"){H=!1,Y=W;continue}if(q.tag==="Just"){const B=q._1;A={...W,inWeight:J(j=>X=>Tt(nt)(Zt)(X.tgt)(-X.weight)(j))(W.inWeight)((()=>{const j=wt(B)(W.depsBySrc);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;c()})()),marks:K(nt)(B)(W.nextSource)(W.marks),nextSource:W.nextSource+1|0,outWeight:J(j=>X=>Tt(nt)(Zt)(X.src)(-X.weight)(j))(W.outWeight)((()=>{const j=wt(B)(W.depsByTgt);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;c()})()),remaining:ct(j=>j!==B,W.remaining)};continue}c()}return Y},D=P=>{let A=P,H=!0,Y;for(;H;){const W=A,q=ge(B=>{const j=wt(B)(W.outWeight);if(j.tag==="Nothing")return!0;if(j.tag==="Just")return j._1===0;c()})(W.remaining);if(q.tag==="Nothing"){H=!1,Y=W;continue}if(q.tag==="Just"){const B=q._1;A={...W,inWeight:J(j=>X=>Tt(nt)(Zt)(X.tgt)(-X.weight)(j))(W.inWeight)((()=>{const j=wt(B)(W.depsBySrc);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;c()})()),marks:K(nt)(B)(W.nextSink)(W.marks),nextSink:W.nextSink-1|0,outWeight:J(j=>X=>Tt(nt)(Zt)(X.src)(-X.weight)(j))(W.outWeight)((()=>{const j=wt(B)(W.depsByTgt);if(j.tag==="Nothing")return[];if(j.tag==="Just")return j._1;c()})()),remaining:ct(j=>j!==B,W.remaining)};continue}c()}return Y};return(P=>{let A=P,H=!0,Y;for(;H;){const W=G(D(A));if(W.remaining.length===0){H=!1,Y=O(q=>{const B=wt(q.id)(W.marks),j=(()=>{if(B.tag==="Nothing")return q.id;if(B.tag==="Just")return B._1;c()})();return{...q,mark:j<I?(j+I|0)+1|0:j}})($);continue}A=(()=>{const q=j=>{const X=wt(j)(W.outWeight),_t=wt(j)(W.inWeight);return(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()-(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;c()})()|0},B=vt(j=>X=>nt.compare(q(X))(q(j)))(W.remaining);if(0<B.length){const j=B[0];return{...W,inWeight:J(X=>_t=>Tt(nt)(Zt)(_t.tgt)(-_t.weight)(X))(W.inWeight)((()=>{const X=wt(j)(W.depsBySrc);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()})()),marks:K(nt)(j)(W.nextSource)(W.marks),nextSource:W.nextSource+1|0,outWeight:J(X=>_t=>Tt(nt)(Zt)(_t.src)(-_t.weight)(X))(W.outWeight)((()=>{const X=wt(j)(W.depsByTgt);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;c()})()),remaining:ct(X=>X!==j,W.remaining)}}return W})()}return Y})({remaining:O(P=>P.id)($),marks:M,inWeight:J(P=>A=>Tt(nt)(Zt)(A.tgt)(A.weight)(P))(M)(_),outWeight:J(P=>A=>Tt(nt)(Zt)(A.src)(A.weight)(P))(M)(_),depsBySrc:J(P=>A=>Tt(nt)(ue)(A.src)([A])(P))(M)(_),depsByTgt:J(P=>A=>Tt(nt)(ue)(A.tgt)([A])(P))(M)(_),nextSink:I-1|0,nextSource:I+1|0})})())})()),S=ct($=>{const I=wt($.src)(Q),G=wt($.tgt)(Q);return(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})()>(()=>{if(G.tag==="Nothing")return 0;if(G.tag==="Just")return G._1;c()})()},_);if(S.length===0)return l;const Z=J($=>I=>{if(ke(_r)(I.src)($.decisions)||ke(_r)(I.tgt)($.decisions))return $;const G=wt(I.src)($.segMap),D=wt(I.tgt)($.segMap);if(G.tag==="Just"&&D.tag==="Just"){const P=(G._1.incoming.length+G._1.outgoing.length|0)>2&&(D._1.incoming.length+D._1.outgoing.length|0)<=2,A=P?D._1:G._1;return{decisions:[...$.decisions,A.id],segMap:K(nt)(A.id)({...A,splitBy:L("Just",P?G._1.id:D._1.id)})($.segMap)}}return $})({decisions:[],segMap:jn(O($=>w($.id,$))(l.segments))})(S),V=Z.segMap,R=J($=>I=>{const G=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(I.outgoing)),D=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(I.outgoing)),P=ct(q=>q.a.startPosition<=D&&q.a.endPosition>=G,At(q=>B=>({i:q,a:B}))($.freeAreas));if(P.length===0){const q={...I,incoming:vt(dt.compare)(I.incoming),outgoing:vt(dt.compare)([(G+D)/2]),splitPartner:L("Just",$.nextId)},B={id:$.nextId,incoming:vt(dt.compare)([(G+D)/2]),mark:0,members:I.members,outgoing:vt(dt.compare)(I.outgoing),slot:0,splitBy:T,splitPartner:L("Just",I.id)};return{segMap:K(nt)(B.id)(B)(K(nt)(q.id)(q)($.segMap)),freeAreas:$.freeAreas,nextId:$.nextId+1|0}}const A=0<P.length?L("Just",P[0]):T,H=(()=>{if(A.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(A.tag==="Just"){if(P.length===1)return A._1;const q=O(B=>({c:B,rating:(()=>{const j=(B.a.startPosition+B.a.endPosition)/2,X=[j],_t=[j],pt=J((()=>{const ht=$.segMap;return Lt=>Pt=>{const lt=wt(Pt.tgt)(ht);if(lt.tag==="Nothing")return Lt;if(lt.tag==="Just"){const Rt=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),mt=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),gt=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X)),it=(()=>{const Gt=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),Qt=J(Ft=>ie=>ie>mt?Ft:ie>=Rt?Ft+1|0:Ft)(0)(X)+J(Ft=>ie=>ie>Gt?Ft:ie>=gt?Ft+1|0:Ft)(0)(lt._1.incoming)|0,ar=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X)),In=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),Rn=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),cr=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),$e=J(Ft=>ie=>ie>In?Ft:ie>=ar?Ft+1|0:Ft)(0)(lt._1.outgoing)+J(Ft=>ie=>ie>cr?Ft:ie>=Rn?Ft+1|0:Ft)(0)(I.incoming)|0;return Qt===$e?Qt>0?{...Lt,deps:Lt.deps+2|0,crossings:Lt.crossings+Qt|0}:Lt:{...Lt,deps:Lt.deps+1|0,crossings:Lt.crossings+Zn(Qt)($e)|0}})(),rt=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),at=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),Nt=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),yt=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),Ct=J(Gt=>Qt=>Qt>at?Gt:Qt>=rt?Gt+1|0:Gt)(0)(I.outgoing)+J(Gt=>Qt=>Qt>yt?Gt:Qt>=Nt?Gt+1|0:Gt)(0)(lt._1.incoming)|0,Ot=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),re=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),je=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),sr=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),_n=J(Gt=>Qt=>Qt>re?Gt:Qt>=Ot?Gt+1|0:Gt)(0)(lt._1.outgoing)+J(Gt=>Qt=>Qt>sr?Gt:Qt>=je?Gt+1|0:Gt)(0)(_t)|0;return Ct===_n?Ct>0?{...it,deps:it.deps+2|0,crossings:it.crossings+Ct|0}:it:{...it,deps:it.deps+1|0,crossings:it.crossings+Zn(Ct)(_n)|0}}c()}})())(J((()=>{const ht=$.segMap;return Lt=>Pt=>{const lt=wt(Pt.src)(ht);if(lt.tag==="Nothing")return Lt;if(lt.tag==="Just"){const Rt=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),mt=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),gt=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X)),it=(()=>{const Gt=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),Qt=J(Ft=>ie=>ie>mt?Ft:ie>=Rt?Ft+1|0:Ft)(0)(X)+J(Ft=>ie=>ie>Gt?Ft:ie>=gt?Ft+1|0:Ft)(0)(lt._1.incoming)|0,ar=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X)),In=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),Rn=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),cr=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),$e=J(Ft=>ie=>ie>In?Ft:ie>=ar?Ft+1|0:Ft)(0)(lt._1.outgoing)+J(Ft=>ie=>ie>cr?Ft:ie>=Rn?Ft+1|0:Ft)(0)(I.incoming)|0;return Qt===$e?Qt>0?{...Lt,deps:Lt.deps+2|0,crossings:Lt.crossings+Qt|0}:Lt:{...Lt,deps:Lt.deps+1|0,crossings:Lt.crossings+Zn(Qt)($e)|0}})(),rt=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),at=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),Nt=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),yt=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),Ct=J(Gt=>Qt=>Qt>at?Gt:Qt>=rt?Gt+1|0:Gt)(0)(I.outgoing)+J(Gt=>Qt=>Qt>yt?Gt:Qt>=Nt?Gt+1|0:Gt)(0)(lt._1.incoming)|0,Ot=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),re=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),je=ut(J(ut)(1e18)(lt._1.incoming))(J(ut)(1e18)(lt._1.outgoing)),sr=st(J(st)(-1e18)(lt._1.incoming))(J(st)(-1e18)(lt._1.outgoing)),_n=J(Gt=>Qt=>Qt>re?Gt:Qt>=Ot?Gt+1|0:Gt)(0)(lt._1.outgoing)+J(Gt=>Qt=>Qt>sr?Gt:Qt>=je?Gt+1|0:Gt)(0)(_t)|0;return Ct===_n?Ct>0?{...it,deps:it.deps+2|0,crossings:it.crossings+Ct|0}:it:{...it,deps:it.deps+1|0,crossings:it.crossings+Zn(Ct)(_n)|0}}c()}})())({crossings:0,deps:0})(ct(ht=>ht.tgt===I.id,l.deps)))(ct(ht=>ht.src===I.id,l.deps)),ft=(()=>{if(I.splitBy.tag==="Just")return wt(I.splitBy._1)($.segMap);if(I.splitBy.tag==="Nothing")return T;c()})();if(ft.tag==="Just")return{...pt,deps:pt.deps+2|0,crossings:(()=>{const ht=ut(J(ut)(1e18)(ft._1.incoming))(J(ut)(1e18)(ft._1.outgoing)),Lt=ut(J(ut)(1e18)(_t))(J(ut)(1e18)(I.outgoing)),Pt=st(J(st)(-1e18)(ft._1.incoming))(J(st)(-1e18)(ft._1.outgoing)),lt=st(J(st)(-1e18)(_t))(J(st)(-1e18)(I.outgoing)),Rt=ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(X));return pt.crossings+(()=>{const mt=ut(J(ut)(1e18)(ft._1.incoming))(J(ut)(1e18)(ft._1.outgoing)),gt=st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(X)),it=st(J(st)(-1e18)(ft._1.incoming))(J(st)(-1e18)(ft._1.outgoing));return((J(rt=>at=>at>Pt?rt:at>=ht?rt+1|0:rt)(0)(X)+J(rt=>at=>at>gt?rt:at>=Rt?rt+1|0:rt)(0)(ft._1.incoming)|0)+J(rt=>at=>at>lt?rt:at>=Lt?rt+1|0:rt)(0)(ft._1.outgoing)|0)+J(rt=>at=>at>it?rt:at>=mt?rt+1|0:rt)(0)(_t)|0})()|0})()};if(ft.tag==="Nothing")return pt;c()})()}))(P);return J(B=>j=>j.rating.crossings<B.rating.crossings||!(j.rating.crossings>B.rating.crossings)&&(j.rating.deps<B.rating.deps||!(j.rating.deps>B.rating.deps)&&j.c.a.size>B.c.a.size)?j:B)(0<q.length?q[0]:{c:A._1,rating:{crossings:1e6,deps:1e6}})(q).c}c()})(),Y={...I,incoming:vt(dt.compare)(I.incoming),outgoing:vt(dt.compare)([(H.a.startPosition+H.a.endPosition)/2]),splitPartner:L("Just",$.nextId)},W={id:$.nextId,incoming:vt(dt.compare)([(H.a.startPosition+H.a.endPosition)/2]),mark:0,members:I.members,outgoing:vt(dt.compare)(I.outgoing),slot:0,splitBy:T,splitPartner:L("Just",I.id)};return{segMap:K(nt)(W.id)(W)(K(nt)(Y.id)(Y)($.segMap)),freeAreas:(()=>{if(H.i>=0&&H.i<$.freeAreas.length){const q=Hu(jt,T,H.i,$.freeAreas),B=(()=>{if(q.tag==="Nothing")return $.freeAreas;if(q.tag==="Just")return q._1;c()})();if($.freeAreas[H.i].size/2<d)return B;const j=($.freeAreas[H.i].startPosition+$.freeAreas[H.i].endPosition)/2,X=j-d,_t=j+d;return[...H.i<1?[]:It(0,H.i,B),...$.freeAreas[H.i].startPosition<=X?[{startPosition:$.freeAreas[H.i].startPosition,endPosition:X,size:X-$.freeAreas[H.i].startPosition}]:[],..._t<=$.freeAreas[H.i].endPosition?[{startPosition:_t,endPosition:$.freeAreas[H.i].endPosition,size:$.freeAreas[H.i].endPosition-_t}]:[],...H.i<1?B:It(H.i,B.length,B)]}return $.freeAreas})(),nextId:$.nextId+1|0}})({segMap:V,freeAreas:(()=>{const $=vt(dt.compare)([...St(l.segments)(I=>I.incoming),...St(l.segments)(I=>I.outgoing)]);return xt(Hl)(ye(I=>G=>G-I>=2*d?L("Just",{startPosition:I+d,endPosition:G-d,size:G-I-2*d}):T,$,It(1,$.length,$)))})(),nextId:l.segments.length})(vt($=>I=>dt.compare(st(J(st)(-1e18)($.incoming))(J(st)(-1e18)($.outgoing))-ut(J(ut)(1e18)($.incoming))(J(ut)(1e18)($.outgoing)))(st(J(st)(-1e18)(I.incoming))(J(st)(-1e18)(I.outgoing))-ut(J(ut)(1e18)(I.incoming))(J(ut)(1e18)(I.outgoing))))(xt($=>wt($)(V))(Z.decisions)));return{segments:(()=>{const $=(I,G)=>{if(I.tag==="Leaf")return G;if(I.tag==="Node")return $(I._5,Mt("Cons",I._4,$(I._6,G)));c()};return bt(Wt.foldr,$(R.segMap,qt))})(),deps:(()=>{const $=R.segMap,I=(P,A)=>{if(P.tag==="Leaf")return A;if(P.tag==="Node")return I(P._5,Mt("Cons",P._4,I(P._6,A)));c()},G=bt(Wt.foldr,I($,qt)),D=G.length;return[...St(St(Ht(0,D-2|0))(P=>St(Ht(P+1|0,D-1|0))(A=>[w(P,A)])))(P=>P._1>=0&&P._1<G.length?P._2>=0&&P._2<G.length?G[P._1].splitPartner.tag!=="Nothing"&&G[P._1].splitPartner.tag==="Just"&&G[P._1].splitPartner._1===G[P._2].id||G[P._2].splitPartner.tag!=="Nothing"&&G[P._2].splitPartner.tag==="Just"&&G[P._2].splitPartner._1===G[P._1].id?[]:o(d,G[P._1],G[P._2]):[]:[]),...St(G)(P=>P.splitBy.tag==="Just"&&P.splitPartner.tag==="Just"&&(()=>{const A=wt(P.splitPartner._1)($);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;c()})()&&(()=>{const A=wt(P.splitBy._1)($);if(A.tag==="Nothing")return!1;if(A.tag==="Just")return!0;c()})()?[{src:P.id,tgt:P.splitBy._1,weight:1,kind:yi},{src:P.splitBy._1,tgt:P.splitPartner._1,weight:1,kind:yi}]:[])]})()}})(),p=h.segments,m=p.length,N=Q=>{let S=Q,Z=!0,V;for(;Z;){const R=S,$=ge(I=>{const G=wt(I)(R.inWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;c()})(R.remaining);if($.tag==="Nothing"){Z=!1,V=R;continue}if($.tag==="Just"){const I=$._1;S={...R,inWeight:J(G=>D=>Tt(nt)(Zt)(D.tgt)(-D.weight)(G))(R.inWeight)((()=>{const G=wt(I)(R.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),marks:K(nt)(I)(R.nextSource)(R.marks),nextSource:R.nextSource+1|0,outWeight:J(G=>D=>Tt(nt)(Zt)(D.src)(-D.weight)(G))(R.outWeight)((()=>{const G=wt(I)(R.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),remaining:ct(G=>G!==I,R.remaining)};continue}c()}return V},y=Q=>{let S=Q,Z=!0,V;for(;Z;){const R=S,$=ge(I=>{const G=wt(I)(R.outWeight);if(G.tag==="Nothing")return!0;if(G.tag==="Just")return G._1===0;c()})(R.remaining);if($.tag==="Nothing"){Z=!1,V=R;continue}if($.tag==="Just"){const I=$._1;S={...R,inWeight:J(G=>D=>Tt(nt)(Zt)(D.tgt)(-D.weight)(G))(R.inWeight)((()=>{const G=wt(I)(R.depsBySrc);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),marks:K(nt)(I)(R.nextSink)(R.marks),nextSink:R.nextSink-1|0,outWeight:J(G=>D=>Tt(nt)(Zt)(D.src)(-D.weight)(G))(R.outWeight)((()=>{const G=wt(I)(R.depsByTgt);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;c()})()),remaining:ct(G=>G!==I,R.remaining)};continue}c()}return V},x=(Q=>{let S=Q,Z=!0,V;for(;Z;){const R=N(y(S));if(R.remaining.length===0){Z=!1,V=O($=>{const I=wt($.id)(R.marks),G=(()=>{if(I.tag==="Nothing")return $.id;if(I.tag==="Just")return I._1;c()})();return{...$,mark:G<m?(G+m|0)+1|0:G}})(p);continue}S=(()=>{const $=G=>{const D=wt(G)(R.outWeight),P=wt(G)(R.inWeight);return(()=>{if(D.tag==="Nothing")return 0;if(D.tag==="Just")return D._1;c()})()-(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;c()})()|0},I=vt(G=>D=>nt.compare($(D))($(G)))(R.remaining);if(0<I.length){const G=I[0];return{...R,inWeight:J(D=>P=>Tt(nt)(Zt)(P.tgt)(-P.weight)(D))(R.inWeight)((()=>{const D=wt(G)(R.depsBySrc);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),marks:K(nt)(G)(R.nextSource)(R.marks),nextSource:R.nextSource+1|0,outWeight:J(D=>P=>Tt(nt)(Zt)(P.src)(-P.weight)(D))(R.outWeight)((()=>{const D=wt(G)(R.depsByTgt);if(D.tag==="Nothing")return[];if(D.tag==="Just")return D._1;c()})()),remaining:ct(D=>D!==G,R.remaining)}}return R})()}return V})({remaining:O(Q=>Q.id)(p),marks:M,inWeight:J(Q=>S=>Tt(nt)(Zt)(S.tgt)(S.weight)(Q))(M)(h.deps),outWeight:J(Q=>S=>Tt(nt)(Zt)(S.src)(S.weight)(Q))(M)(h.deps),depsBySrc:J(Q=>S=>Tt(nt)(ue)(S.src)([S])(Q))(M)(h.deps),depsByTgt:J(Q=>S=>Tt(nt)(ue)(S.tgt)([S])(Q))(M)(h.deps),nextSink:m-1|0,nextSource:m+1|0}),v=(()=>{const Q=(()=>{const V=jn(O(R=>w(R.id,R.mark))(x));return{segments:x,deps:xt(R=>(()=>{if(R.kind==="Critical")return!0;if(R.kind==="Regular")return!1;c()})()?L("Just",R):(()=>{const $=wt(R.src)(V),I=wt(R.tgt)(V);return(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})()>(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})()})()?R.weight===0?T:L("Just",{src:R.tgt,tgt:R.src,weight:R.weight,kind:R.kind}):L("Just",R))(h.deps)}})(),S=J(V=>R=>Tt(nt)(Zt)(R.tgt)(1)(V))(M)(Q.deps),Z=(V=>{let R=V,$=!0,I;for(;$;){const G=R,D=Bt(P=>T,P=>A=>L("Just",{head:P,tail:A}),G.queue);if(D.tag==="Nothing"){$=!1,I=G;continue}if(D.tag==="Just"){R=J((()=>{const P=wt(D._1.head)(G.slots),A=(()=>{if(P.tag==="Nothing")return 0;if(P.tag==="Just")return P._1;c()})();return H=>Y=>{const W=wt(Y)(H.inDegree),q=(()=>{if(W.tag==="Nothing")return-1;if(W.tag==="Just")return W._1-1|0;c()})();return{...H,slots:K(nt)(Y)(ya((()=>{const B=wt(Y)(H.slots);if(B.tag==="Nothing")return 0;if(B.tag==="Just")return B._1;c()})())(A+1|0))(H.slots),inDegree:K(nt)(Y)(q)(H.inDegree),queue:q===0?[...H.queue,Y]:H.queue}}})())({...G,queue:D._1.tail})((()=>{const P=wt(D._1.head)(G.adj);if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;c()})());continue}c()}return I})({slots:jn(O(V=>w(V.id,0))(Q.segments)),inDegree:S,adj:J(V=>R=>Tt(nt)(ue)(R.src)([R.tgt])(V))(M)(Q.deps),queue:O(V=>V.id)(ct(V=>{const R=wt(V.id)(S);if(R.tag==="Nothing")return!0;if(R.tag==="Just")return R._1===0;c()},Q.segments))});return vt(V=>R=>nt.compare(V.slot)(R.slot))(O(V=>({...V,slot:(()=>{const R=wt(V.id)(Z.slots);if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;c()})()}))(Q.segments))})(),b=1+J(Q=>S=>ya(Q)(S.slot))(0)(v)|0,E=St(v)(Q=>Q.members),k=ct(Q=>ke(ze)(Q.edge.id)(E),t),F=J(st)(-1e18)(O(Q=>Q.fromPos._2)(k)),U=J(ut)(1e18)(O(Q=>Q.toPos._2)(k));if(F>U){const Q=jn(O(S=>w(S.id,S))(v));return Le(O(S=>O(Z=>w(Z,{slot:S.slot,slotCount:b,gapTop:U,gapBottom:F,partner:(()=>{if(S.splitPartner.tag==="Just"){const V=wt(S.splitPartner._1)(Q);if(V.tag==="Just")return L("Just",{slot:V._1.slot,splitX:0<V._1.incoming.length?V._1.incoming[0]:0});if(V.tag==="Nothing")return T;c()}if(S.splitPartner.tag==="Nothing")return T;c()})()}))(S.members))(ct(S=>{if(S.splitPartner.tag==="Just"){const Z=wt(S.splitPartner._1)(Q);return!(Z.tag==="Just"&&(()=>{if(Z._1.splitBy.tag==="Nothing")return!1;if(Z._1.splitBy.tag==="Just")return!0;c()})())}if(S.splitPartner.tag==="Nothing")return!0;c()},v)))}const tt=jn(O(Q=>w(Q.id,Q))(v));return Le(O(Q=>O(S=>w(S,{slot:Q.slot,slotCount:b,gapTop:F,gapBottom:U,partner:(()=>{if(Q.splitPartner.tag==="Just"){const Z=wt(Q.splitPartner._1)(tt);if(Z.tag==="Just")return L("Just",{slot:Z._1.slot,splitX:0<Z._1.incoming.length?Z._1.incoming[0]:0});if(Z.tag==="Nothing")return T;c()}if(Q.splitPartner.tag==="Nothing")return T;c()})()}))(Q.members))(ct(Q=>{if(Q.splitPartner.tag==="Just"){const S=wt(Q.splitPartner._1)(tt);return!(S.tag==="Just"&&(()=>{if(S._1.splitBy.tag==="Nothing")return!1;if(S._1.splitBy.tag==="Just")return!0;c()})())}if(Q.splitPartner.tag==="Nothing")return!0;c()},v)))})()))(M)(ql(J(u=>s=>{const a=rn(s.edge.from.node)(n);if(a.tag==="Just"){const f=rn(s.edge.to.node)(n);return f.tag==="Just"&&a._1.layer!==f._1.layer?Tt(nt)(ue)(Zn(a._1.layer)(f._1.layer))([s])(u):u}return u})(M)((()=>{const u=s=>w((()=>{const a=rn(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=rn(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return vt(s=>a=>Ol(u(s))(u(a)))(t)})())))},Wl=t=>e=>{const n=Ja(t)(e),r=J(i=>o=>K(C)(o.node)(o)(i))(M)(e);return J(i=>o=>{const u=rn(o.edge.from.node)(r);if(u.tag==="Just"){const s=rn(o.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=rn(o.edge.id)(n);if(a.tag==="Just")return K(nt)(Zn(u._1.layer)(s._1.layer))(a._1.slotCount)(i)}return i}return i})(M)(t)},xa=Dt.foldMap((()=>{const t={append:e=>n=>e||n};return{mempty:!1,Semigroup0:()=>t}})()),ee=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},ne=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Qr=t=>e=>n=>r=>xa(i=>n>=i.x&&n<i.x+i.w&&e>i.y&&t<i.y+i.h)(r),Ji=t=>e=>n=>r=>Qr(ee(e)(n))(ne(e)(n))(r)(t),xi=ot(4),Vl=Yu(t=>{if(t.direction==="H"){const e=ee(t.start._1)(t.end._1);return[{x:e,y:t.start._2-1,w:ne(t.start._1)(t.end._1)-e,h:2}]}if(t.direction==="V"){const e=ee(t.start._2)(t.end._2);return[{x:t.start._1-1,y:e,w:2,h:ne(t.start._2)(t.end._2)-e}]}c()}),Ta=Uu(t=>!(t.start._1===t.end._1&&t.start._2===t.end._2)),Ul=t=>e=>n=>{const r=Bt(i=>T,i=>o=>L("Just",{head:i,tail:o}),e);if(r.tag==="Nothing")return[{start:t.start,end:n.end,direction:t.direction}];if(r.tag==="Just"){const i=(r._1.head.direction==="H"?t.direction==="H":r._1.head.direction==="V"&&t.direction==="V")?[{start:t.start,end:r._1.head.end,direction:t.direction}]:[t,r._1.head],o=Vu(r._1.tail);if(o.tag==="Nothing"){const u=i.length-1|0;return u>=0&&u<i.length&&(i[u].direction==="H"?n.direction==="H":i[u].direction==="V"&&n.direction==="V")?[...(()=>{const s=i.length-1|0;return s<1?[]:It(0,s,i)})(),{start:i[u].start,end:n.end,direction:n.direction}]:[...i,n]}if(o.tag==="Just")return(o._1.last.direction==="H"?n.direction==="H":o._1.last.direction==="V"&&n.direction==="V")?[...i,...o._1.init,{start:o._1.last.start,end:n.end,direction:n.direction}]:[...i,...r._1.tail,n]}c()},nu=t=>{const e=r=>i=>{const o=Bt(u=>T,u=>s=>L("Just",{head:u,tail:s}),i);if(o.tag==="Nothing")return[r];if(o.tag==="Just")return(r.direction==="H"?o._1.head.direction==="H":r.direction==="V"&&o._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==o._1.head.end._1-o._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==o._1.head.end._2-o._1.head.start._2>=0;c()})()?e({start:r.start,end:o._1.head.end,direction:r.direction})(o._1.tail):[r,...e(o._1.head)(o._1.tail)];c()},n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return e(n._1.head)(n._1.tail);c()},Pr=t=>e=>n=>r=>xa(i=>n>=i.y&&n<i.y+i.h&&e>i.x&&t<i.x+i.w)(r),Dr=t=>e=>n=>r=>Pr(ee(e)(n))(ne(e)(n))(r)(t),Yl=t=>e=>n=>r=>{const i=n+2|0,o=i<1?e:It(i,e.length,e),u=n<1?[]:It(0,n,e),s=(n+1|0)===(r-1|0),a=n===0,f=n>=0&&n<e.length?L("Just",e[n]):T;if(f.tag==="Just"){const g=n+1|0,d=g>=0&&g<e.length?L("Just",e[g]):T;if(d.tag==="Just"){const l=f._1.start._1===d._1.end._1&&(!a||f._1.direction==="V")&&(!s||d._1.direction==="V")&&!Ji(t)(ee(f._1.start._2)(d._1.end._2))(ne(f._1.start._2)(d._1.end._2))(f._1.start._1)?L("Just",[...u,{start:f._1.start,end:d._1.end,direction:Kt},...o]):T,_=f._1.start._2===d._1.end._2&&(!a||f._1.direction==="H")&&(!s||d._1.direction==="H")&&!Dr(t)(ee(f._1.start._1)(d._1.end._1))(ne(f._1.start._1)(d._1.end._1))(f._1.start._2)?L("Just",[...u,{start:f._1.start,end:d._1.end,direction:Xt},...o]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;c()}if(f.tag==="Nothing")return T;c()},Xl=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+1|0)>=n){o=!1,u=e;continue}const a=Yl(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}c()}return u})(0)},Kl=t=>e=>n=>r=>{const i=(l,_,h)=>!Ji(t)(ee(_)(h))(ne(_)(h))(l),o=n+3|0,u=o<1?e:It(o,e.length,e),s=n<1?[]:It(0,n,e),a=(n+2|0)===(r-1|0),f=n===0,g=(l,_,h)=>!Dr(t)(ee(_)(h))(ne(_)(h))(l),d=n>=0&&n<e.length?L("Just",e[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<e.length?L("Just",e[l]):T;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!f||d._1.direction==="V")&&(!a||_._1.direction==="V")&&i(d._1.start._1,d._1.start._2,_._1.end._2)?L("Just",[...s,{start:d._1.start,end:_._1.end,direction:Kt},...u]):d._1.start._2===_._1.end._2&&(!f||d._1.direction==="H")&&(!a||_._1.direction==="H")&&g(d._1.start._2,d._1.start._1,_._1.end._1)?L("Just",[...s,{start:d._1.start,end:_._1.end,direction:Xt},...u]):T,p=(!f||d._1.direction==="V")&&(!a||_._1.direction==="H")&&i(d._1.start._1,d._1.start._2,_._1.end._2)&&g(_._1.end._2,d._1.start._1,_._1.end._1)?L("Just",[...s,{start:d._1.start,end:w(d._1.start._1,_._1.end._2),direction:Kt},{start:w(d._1.start._1,_._1.end._2),end:_._1.end,direction:Xt},...u]):T,m=(!f||d._1.direction==="H")&&(!a||_._1.direction==="V")&&g(d._1.start._2,d._1.start._1,_._1.end._1)&&i(_._1.end._1,d._1.start._2,_._1.end._2)?L("Just",[...s,{start:d._1.start,end:w(_._1.end._1,d._1.start._2),direction:Xt},{start:w(_._1.end._1,d._1.start._2),end:_._1.end,direction:Kt},...u]):T,N=p.tag==="Nothing"?m:p;return h.tag==="Nothing"?N:h}if(_.tag==="Nothing")return T;c()}if(d.tag==="Nothing")return T;c()},jl=t=>e=>{const n=e.length;return(r=>{let i=r,o=!0,u;for(;o;){const s=i;if((s+2|0)>=n){o=!1,u=e;continue}const a=Kl(t)(e)(s)(n);if(a.tag==="Just"){o=!1,u=a._1;continue}if(a.tag==="Nothing"){i=s+1|0;continue}c()}return u})(0)},Zl=t=>{const e=n=>{let r=n,i=!0,o;for(;i;){const u=r,s=nu(Ta(Xl(t)(jl(t)(u))));if(s.length<u.length){r=s;continue}i=!1,o=s}return o};return n=>e(nu(Ta(n)))},th=t=>e=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=ct(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=vt(f=>g=>dt.compare(f.x)(g.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=vt(a=>f=>dt.compare(f.x)(a.x))(O(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},eh=t=>e=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=ct(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=vt(f=>g=>dt.compare(f.y)(g.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=vt(a=>f=>dt.compare(f.y)(a.y))(O(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},nh=t=>e=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=ct(a=>e>=a.y&&e<a.y+a.h&&a.x+a.w>i&&a.x<o,t);if(r>n){const a=vt(f=>g=>dt.compare(g.x)(f.x))(O(f=>({...f,x:f.x+f.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=vt(a=>f=>dt.compare(a.x)(f.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},rh=t=>e=>n=>r=>{const i=ee(n)(r),o=ne(n)(r),u=ct(a=>e>=a.x&&e<a.x+a.w&&a.y+a.h>i&&a.y<o,t);if(r>n){const a=vt(f=>g=>dt.compare(g.y)(f.y))(O(f=>({...f,y:f.y+f.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=vt(a=>f=>dt.compare(a.y)(f.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},va=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o;if(g>100){u=!1,s=f;continue}if(!a(f+g)){u=!1,s=f+g;continue}if(!a(f-g)){u=!1,s=f-g;continue}r=a,i=f,o=g+1}return s},wa=t=>e=>n=>r=>i=>{const o=ee(e)(n),u=ne(e)(n);if(!Qr(o)(u)(r)(t))return r;if(!Qr(o)(u)(i)(t))return i;const s=(r+i)/2;return Qr(o)(u)(s)(t)?va(a=>Qr(o)(u)(a)(t))(s)(1):s},ih=t=>e=>n=>r=>i=>{const o=ee(e)(n),u=ne(e)(n);if(!Pr(o)(u)(r)(t))return r;if(!Pr(o)(u)(i)(t))return i;const s=(r+i)/2;return Pr(o)(u)(s)(t)?va(a=>Pr(o)(u)(a)(t))(s)(1):s},oh=t=>e=>n=>r=>{const i=ee(e)(n),o=ne(e)(n),u=ct(f=>r>=f.x&&r<f.x+f.w&&f.y+f.h>i&&f.y<o,t),s=J(f=>g=>ne(f)(g.x+g.w+4))(r+4)(u),a=J(f=>g=>ee(f)(g.x-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},uh=t=>e=>n=>r=>{const i=ee(e)(n),o=ne(e)(n),u=ct(f=>r>=f.y&&r<f.y+f.h&&f.x+f.w>i&&f.x<o,t),s=J(f=>g=>ne(f)(g.y+g.h+4))(r+4)(u),a=J(f=>g=>ee(f)(g.y-4))(r-4)(u);return(()=>{const f=s-r,g=a-r;return(f<0?-f:f)<=(g<0?-g:g)})()?s:a},sh=t=>e=>n=>r=>i=>o=>u=>{const s=(()=>{if(r==="South")return w(i._1,i._2+4);if(r==="North")return w(i._1,i._2-4);if(r==="East")return w(i._1+4,i._2);if(r==="West")return w(i._1-4,i._2);c()})(),a=(()=>{if(o==="South")return w(u._1,u._2+4);if(o==="North")return w(u._1,u._2-4);if(o==="East")return w(u._1+4,u._2);if(o==="West")return w(u._1-4,u._2);c()})(),f=(b,E,k)=>!Ji(e)(ee(E)(k))(ne(E)(k))(b),g=(b,E,k)=>!Ji(n)(ee(E)(k))(ne(E)(k))(b),d=(b,E,k,F)=>t.tag==="Just"&&!Dr(n)(ee(b)(E))(ne(b)(E))(t._1)?t._1:ih(e)(b)(E)(k)(F),l=(b,E,k,F)=>{if(b===k){const tt=oh(e)(E)(F)(b),Q=eh(e)(b)(E)(F),S=rh(e)(b)(E)(F);return[{start:w(b,E),end:w(b,Q),direction:Kt},{start:w(b,Q),end:w(tt,Q),direction:Xt},{start:w(tt,Q),end:w(tt,S),direction:Kt},{start:w(tt,S),end:w(k,S),direction:Xt},{start:w(k,S),end:w(k,F),direction:Kt}]}const U=d(b,k,E,F);return[{start:w(b,E),end:w(b,U),direction:Kt},{start:w(b,U),end:w(k,U),direction:Xt},{start:w(k,U),end:w(k,F),direction:Kt}]},_=(b,E,k,F)=>{if(E===F){const tt=uh(e)(b)(k)(E),Q=th(e)(E)(b)(k),S=nh(e)(E)(b)(k);return[{start:w(b,E),end:w(Q,E),direction:Xt},{start:w(Q,E),end:w(Q,tt),direction:Kt},{start:w(Q,tt),end:w(S,tt),direction:Xt},{start:w(S,tt),end:w(S,F),direction:Kt},{start:w(S,F),end:w(k,F),direction:Xt}]}const U=wa(e)(E)(F)(b)(k);return[{start:w(b,E),end:w(U,E),direction:Xt},{start:w(U,E),end:w(U,F),direction:Kt},{start:w(U,F),end:w(k,F),direction:Xt}]},h=(b,E,k)=>!Dr(e)(ee(E)(k))(ne(E)(k))(b),p=(b,E,k)=>!Dr(n)(ee(E)(k))(ne(E)(k))(b),m=(b,E,k,F)=>{if(p(E,b,k)&&g(k,E,F))return[{start:w(b,E),end:w(k,E),direction:Xt},{start:w(k,E),end:w(k,F),direction:Kt}];const U=wa(e)(E)(F)(b)(k);return[{start:w(b,E),end:w(U,E),direction:Xt},{start:w(U,E),end:w(U,F),direction:Kt},{start:w(U,F),end:w(k,F),direction:Xt}]},N=(b,E,k,F)=>{if(g(b,E,F)&&p(F,b,k))return[{start:w(b,E),end:w(b,F),direction:Kt},{start:w(b,F),end:w(k,F),direction:Xt}];const U=d(b,k,E,F);return[{start:w(b,E),end:w(b,U),direction:Kt},{start:w(b,U),end:w(k,U),direction:Xt},{start:w(k,U),end:w(k,F),direction:Kt}]},y=(()=>{if(r==="South")return o==="North"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:w(s._1,s._2),end:w(a._1,a._2),direction:Kt}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?N(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return o==="South"?s._1===a._1&&f(s._1,s._2,a._2)?[{start:w(s._1,s._2),end:w(a._1,a._2),direction:Kt}]:l(s._1,s._2,a._1,a._2):o==="East"||o==="West"?N(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return o==="West"?s._2===a._2&&h(s._2,s._1,a._1)?[{start:w(s._1,s._2),end:w(a._1,a._2),direction:Xt}]:_(s._1,s._2,a._1,a._2):o==="North"||o==="South"?m(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(o==="East")return s._2===a._2&&h(s._2,s._1,a._1)?[{start:w(s._1,s._2),end:w(a._1,a._2),direction:Xt}]:_(s._1,s._2,a._1,a._2);if(o==="North"||o==="South")return m(s._1,s._2,a._1,a._2)}return l(s._1,s._2,a._1,a._2)})(),x=(()=>{if(r==="South"||r==="North")return Kt;if(r==="East"||r==="West")return Xt;c()})(),v={start:w(a._1,a._2),end:w(u._1,u._2),direction:(()=>{if(o==="South"||o==="North")return Kt;if(o==="East"||o==="West")return Xt;c()})()};return s._1===a._1&&s._2===a._2?[{start:w(i._1,i._2),end:w(u._1,u._2),direction:x}]:Ul({start:w(i._1,i._2),end:w(s._1,s._2),direction:x})(y)(v)},ah=O(t=>({x:t.position._1*xi-2,y:t.position._2*xi-2,w:t.size._1*xi+4,h:t.size._2*xi+4})),La=Vt(C)(Dt),on=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},ch=Vt(C)(Dt),ba=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},fh=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t._1)(o._3._1);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(t._2==="North"){if(o._3._2==="North"){r=!1,i=L("Just",o._4);continue}n=o._5;continue}if(o._3._2==="North"){n=o._6;continue}if(t._2==="South"){if(o._3._2==="South"){r=!1,i=L("Just",o._4);continue}n=o._5;continue}if(o._3._2==="South"){n=o._6;continue}if(t._2==="East"){if(o._3._2==="East"){r=!1,i=L("Just",o._4);continue}n=o._5;continue}if(o._3._2==="East"){n=o._6;continue}if(t._2==="West"&&o._3._2==="West"){r=!1,i=L("Just",o._4);continue}}c()}return i},gh=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ea=t=>e=>{const n=e.position._1+e.size._1,r=e.position._2*2+e.size._2,i=e.position._1*2+e.size._1,o=e.position._2+e.size._2;if(t==="South")return w(i,o*2);if(t==="North")return w(i,e.position._2*2);if(t==="East")return w(n*2,r);if(t==="West")return w(e.position._1*2,r);c()},ru=t=>e=>{const n=ot(4);if(t==="South")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="North")return{lo:e.position._1*n,hi:(e.position._1+e.size._1)*n};if(t==="East")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};if(t==="West")return{lo:e.position._2*n,hi:(e.position._2+e.size._2)*n};c()},ka=t=>e=>J(n=>r=>Tt(t)(ue)(e(r))([r])(n))(M),Ga=t=>e=>n=>r=>{const i=(t==="South"||t==="North")&&(e==="East"||e==="West")&&(()=>{if(t==="South")return r._2>n._2;if(t==="North")return r._2<n._2;if(t==="East")return r._2>n._2;if(t==="West")return r._2<n._2;c()})()&&(()=>{if(e==="East")return n._1>r._1;if(e==="West"||e==="North")return n._1<r._1;if(e==="South")return n._1>r._1;c()})(),o=(t==="East"||t==="West")&&(e==="North"||e==="South")&&(()=>{if(t==="South")return r._1>n._1;if(t==="North")return r._1<n._1;if(t==="East")return r._1>n._1;if(t==="West")return r._1<n._1;c()})()&&(()=>{if(e==="East")return n._2>r._2;if(e==="West"||e==="North")return n._2<r._2;if(e==="South")return n._2>r._2;c()})();return(t==="South"?e==="North"&&n._1===r._1&&r._2>n._2:t==="North"?e==="South"&&n._1===r._1&&r._2<n._2:t==="East"?e==="West"&&n._2===r._2&&r._1>n._1:t==="West"&&e==="East"&&n._2===r._2&&r._1<n._1)?0:i||o?1:2},Ca=t=>e=>{const n=t.hi-t.lo,r=(t.lo+t.hi)/2,i=e.length;return i===0?M:La(i===1?O(o=>w(o,r))(e):At(o=>u=>w(u,t.lo+ot(o+1|0)*n/ot(i+1|0)))(e))},Sa=t=>e=>n=>r=>i=>{const o=ka(C)(_=>_.to.node)(t),u=ka(C)(_=>_.from.node)(t),s=J(_=>h=>K(C)(h.node)(h)(_))(M)(e),a=(_,h,p)=>{const m=on(_)(s);if(m.tag==="Nothing")return w(0,0);if(m.tag==="Just"){const N=on(_)(n);if(N.tag==="Nothing"){const y=ot(4);if(p==="South")return w(m._1.position._1*y+m._1.size._1*y/2,(m._1.position._2+m._1.size._2)*y);if(p==="North")return w(m._1.position._1*y+m._1.size._1*y/2,m._1.position._2*y);if(p==="East")return w((m._1.position._1+m._1.size._1)*y,m._1.position._2*y+m._1.size._2*y/2);if(p==="West")return w(m._1.position._1*y,m._1.position._2*y+m._1.size._2*y/2);c()}if(N.tag==="Just"){const y=ge(x=>x.id===h)(N._1);if(y.tag==="Nothing"){const x=ot(4);if(p==="South")return w(m._1.position._1*x+m._1.size._1*x/2,(m._1.position._2+m._1.size._2)*x);if(p==="North")return w(m._1.position._1*x+m._1.size._1*x/2,m._1.position._2*x);if(p==="East")return w((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+m._1.size._2*x/2);if(p==="West")return w(m._1.position._1*x,m._1.position._2*x+m._1.size._2*x/2);c()}if(y.tag==="Just"){const x=ot(4);if(y._1.side==="North")return w(m._1.position._1*x+ot(y._1.offset)*x,m._1.position._2*x);if(y._1.side==="South")return w(m._1.position._1*x+ot(y._1.offset)*x,(m._1.position._2+m._1.size._2)*x);if(y._1.side==="East")return w((m._1.position._1+m._1.size._1)*x,m._1.position._2*x+ot(y._1.offset)*x);if(y._1.side==="West")return w(m._1.position._1*x,m._1.position._2*x+ot(y._1.offset)*x)}}}c()},f=ch(St(r)(_=>{if(_.nodes.length<=2)return[];const h=ot(4);if(1<_.nodes.length){const p=on(_.nodes[1])(s);if(p.tag==="Nothing")return[];if(p.tag==="Just"){const m=p._1.position._1*h+p._1.size._1*h/2;return O(N=>w(N,m))(ye(N=>y=>_.edgeId+":"+N+"->"+y,_.nodes,It(1,_.nodes.length,_.nodes)))}c()}return[]})),g=_=>{const h=on(_.from.node)(s),p=on(_.to.node)(s);if(h.tag==="Just"&&p.tag==="Just"){const m=h._1,N=p._1,y=vt(x=>v=>nt.compare(x.score)(v.score))(O(x=>{const v=x._1,b=x._2;return{from:v,to:b,score:(()=>{const E=(tt,Q,S,Z,V)=>{const R=ru(tt)(Q),$=ru(tt)(S);return R.lo<$.hi&&$.lo<R.hi&&(v==="South"?b==="North"&&V._2>Z._2:v==="North"?b==="South"&&V._2<Z._2:v==="East"?b==="West"&&V._1>Z._1:v==="West"&&b==="East"&&V._1<Z._1)?0:Ga(v)(b)(Z)(V)},k=Ea(v)(m),F=Ea(b)(N),U=Ga(v)(b)(k)(F);return(()=>{if(U>0){if(v==="South")return b==="North"?E(ae,m,N,k,F)*10|0:U*10|0;if(v==="North")return b==="South"?E(se,m,N,k,F)*10|0:U*10|0;if(v==="East")return b==="West"?E(Oe,m,N,k,F)*10|0:U*10|0;if(v==="West"&&b==="East")return E(Gn,m,N,k,F)*10|0}return U*10|0})()+(v==="South"?b==="North"?0:15:v==="North"?b==="South"?0:15:v==="East"?b==="West"?5:15:v==="West"&&b==="East"?5:15)|0})()}})([w(ae,se),w(Oe,se),w(Gn,se),w(ae,Oe),w(ae,Gn),w(se,ae),w(se,Oe),w(se,Gn),w(Oe,ae),w(Gn,ae),w(Oe,Gn),w(Gn,Oe)]));if(0<y.length)return{from:y[0].from,to:y[0].to}}return{from:ae,to:se}},d=La(O(_=>w(_.id,g(_)))(t)),l=(_,h,p,m,N,y)=>{const x=ot(4),v=on(h)(s);if(v.tag==="Nothing")return w(0,0);if(v.tag==="Just"){const b=fh(w(p,_))(i);if(b.tag==="Just"){const E=v._1.position._1*x+b._1,k=ot(4);if(_==="South")return w(E,(v._1.position._2+v._1.size._2)*k);if(_==="North")return w(E,v._1.position._2*k);if(_==="East")return w((v._1.position._1+v._1.size._1)*k,E);if(_==="West")return w(v._1.position._1*k,E);c()}if(b.tag==="Nothing"){const E=ru(_)(v._1),k=(E.lo+E.hi)/2,F=ba(p)(Ca(E)(O(Q=>Q.id)(vt(Q=>S=>dt.compare(N(_)(Q))(N(_)(S)))(ct(Q=>{const S=ba(Q.id)(d);if(S.tag==="Just"){const Z=y(S._1);return Z==="North"?_==="North":Z==="South"?_==="South":Z==="East"?_==="East":Z==="West"&&_==="West"}if(S.tag==="Nothing")return!0;c()},(()=>{const Q=on(h)(m);if(Q.tag==="Nothing")return[];if(Q.tag==="Just")return Q._1;c()})()))))),U=(()=>{if(F.tag==="Nothing")return k;if(F.tag==="Just")return F._1;c()})(),tt=ot(4);if(_==="South")return w(U,(v._1.position._2+v._1.size._2)*tt);if(_==="North")return w(U,v._1.position._2*tt);if(_==="East")return w((v._1.position._1+v._1.size._1)*tt,U);if(_==="West")return w(v._1.position._1*tt,U)}}c()};return O(_=>{const h=gh(_.edge.id)(f);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:ce(3)(_.edge.from.node)==="$d:"?w(h._1,_.fromPos._2):_.fromPos,toPos:ce(3)(_.edge.to.node)==="$d:"?w(h._1,_.toPos._2):_.toPos};c()})(O(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,ae),toPos:a(_.to.node,_.to.port._1,se),fromSide:ae,toSide:se};const h=g(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,p=>m=>{const N=on(m.to.node)(s);if(N.tag==="Nothing")return 0;if(N.tag==="Just"){const y=ot(4);if(p==="South"||p==="North")return N._1.position._1*y+N._1.size._1*y/2;if(p==="East"||p==="West")return N._1.position._2*y+N._1.size._2*y/2}c()},p=>p.from),toPos:l(h.to,_.to.node,_.id,o,p=>m=>{const N=on(m.from.node)(s);if(N.tag==="Nothing")return 0;if(N.tag==="Just"){const y=ot(4);if(p==="South"||p==="North")return N._1.position._1*y+N._1.size._1*y/2;if(p==="East"||p==="West")return N._1.position._2*y+N._1.size._2*y/2}c()},p=>p.to),fromSide:h.from,toSide:h.to}})(t))},Qa=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},tr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},_h=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),iu=t=>e=>t.gapTop+1*ot(4)+ot(e)*2.5*ot(4),dh=t=>e=>{const n=Qa(e.edge.id)(t);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return L("Just",{slot1Y:iu(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:iu(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;c()}if(n.tag==="Nothing")return T;c()},lh=t=>e=>{const n=J(r=>i=>K(C)(i.node)(i)(r))(M)(e);return Le(At(r=>i=>{const o=tr(i.node)(n);if(o.tag==="Nothing")return[];if(o.tag==="Just"){const u=o._1;return At(s=>a=>{const f=i.edges.length,g=ot(4),d=u.position._1*g,l=u.position._2*g,_=u.size._2*g,h=ot((2*f|0)+1|0),p=l+_*ot(f-s|0)/h,m=l+_*ot((f+1|0)+s|0)/h,N=d-g*2.5*ot(s+1|0),y=[{start:w(d,p),end:w(N,p),direction:Xt},{start:w(N,p),end:w(N,m),direction:Kt},{start:w(N,m),end:w(d,m),direction:Xt}];return{edge:a.id,segments:y,bends:ye(x=>v=>x.end,y,It(1,3,y)),bendType:[],jumps:[],reversed:!1}})(i.edges)}c()})(O(r=>({node:r._1,edges:r._2}))(_h(J(r=>i=>Tt(C)(ue)(i.from.node)([i])(r))(M)(t)))))},hh=t=>e=>{const n=J(o=>u=>K(C)(u.node)(u)(o))(M)(e),r=o=>{const u=tr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;c()},i=o=>{const u=tr(o)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;c()};return vt(o=>u=>{const s=nt.compare(i(o.edge.from.node))(i(u.edge.from.node));if(s==="EQ"){const a=dt.compare(r(o.edge.from.node))(r(u.edge.from.node));return a==="EQ"?dt.compare(r(o.edge.to.node))(r(u.edge.to.node)):a}return s})(t)},le=t=>{const e=ot(4);return{x:t.position._1*e-2,y:t.position._2*e-2,w:t.size._1*e+4,h:t.size._2*e+4}},ph=t=>t.from.node===t.to.node,mh=t=>e=>n=>r=>{const i=Zl(n)(sh(t)(e)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:i,bends:ye(o=>u=>o.end,i,It(1,i.length,i)),bendType:[],jumps:[],reversed:!1}},Nh=t=>e=>n=>r=>{const i=[{start:w(r.fromPos._1,r.fromPos._2),end:w(r.fromPos._1,t.slot1Y),direction:Kt},{start:w(r.fromPos._1,t.slot1Y),end:w(t.splitX,t.slot1Y),direction:Xt},{start:w(t.splitX,t.slot1Y),end:w(t.splitX,t.slot2Y),direction:Kt},{start:w(t.splitX,t.slot2Y),end:w(r.toPos._1,t.slot2Y),direction:Xt},{start:w(r.toPos._1,t.slot2Y),end:w(r.toPos._1,r.toPos._2),direction:Kt}];return{edge:r.edge.id,segments:i,bends:ye(o=>u=>o.end,i,It(1,5,i)),bendType:[],jumps:[],reversed:!1}},yh=t=>e=>n=>{const r=tr(t.edge.from.node)(n);if(r.tag==="Just"){const o=tr(t.edge.to.node)(n);return o.tag==="Just"?ct(u=>!(u.h===le(r._1).h&&u.w===le(r._1).w&&u.x===le(r._1).x&&u.y===le(r._1).y)&&!(u.h===le(o._1).h&&u.w===le(o._1).w&&u.x===le(o._1).x&&u.y===le(o._1).y),e):ct(u=>!(u.h===le(r._1).h&&u.w===le(r._1).w&&u.x===le(r._1).x&&u.y===le(r._1).y),e)}const i=tr(t.edge.to.node)(n);return i.tag==="Just"?ct(o=>!(o.h===le(i._1).h&&o.w===le(i._1).w&&o.x===le(i._1).x&&o.y===le(i._1).y),e):ct(o=>!0,e)},Jh=t=>e=>{const n=Qa(e.edge.id)(t);if(n.tag==="Just")return L("Just",iu(n._1)(n._1.slot));if(n.tag==="Nothing")return T;c()},xh=t=>e=>n=>r=>i=>{const o=J(f=>g=>K(C)(g.node)(g)(f))(M)(e),u=ah(e),s=Sa(ct(f=>f.from.node!==f.to.node,t))(e)(n)(r)(i),a=Ja(s)(e);return[...lh(ct(ph,t))(e),...J(f=>g=>{const d=yh(g)(u)(o),l=[...d,...f.edgeObstacles],_=dh(a)(g),h=(()=>{if(_.tag==="Just")return Nh(_._1)(d)(l)(g);if(_.tag==="Nothing")return mh(Jh(a)(g))(d)(l)(g);c()})();return{results:[...f.results,h],edgeObstacles:[...f.edgeObstacles,...Vl(h.segments)]}})({results:[],edgeObstacles:[]})(hh(s)(e)).results]},mn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},Nn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Th=t=>e=>n=>{if(t.start._1!==e.start._1)return T;const r=Nn(mn(t.start._2)(t.end._2))(mn(e.start._2)(e.end._2)),i=mn(Nn(t.start._2)(t.end._2))(Nn(e.start._2)(e.end._2));return r<i?L("Just",{position:w(t.start._1,(r+i)/2),crossingEdge:n}):T},vh=t=>e=>n=>{if(t.start._2!==e.start._2)return T;const r=Nn(mn(t.start._1)(t.end._1))(mn(e.start._1)(e.end._1)),i=mn(Nn(t.start._1)(t.end._1))(Nn(e.start._1)(e.end._1));return r<i?L("Just",{position:w((r+i)/2,t.start._2),crossingEdge:n}):T},wh=t=>e=>n=>{if(t.direction==="H")return vh(t)(e)(n);if(t.direction==="V")return Th(t)(e)(n);c()},Lh=t=>e=>n=>{const r=t+1|0,i=r<1?n:It(r,n.length,n);return St(e.segments)(o=>St(i)(u=>xt(s=>wh(o)(s)(u.edge))(ct(s=>s.direction==="H"?o.direction==="H":s.direction==="V"&&o.direction==="V",u.segments))))},bh=t=>e=>n=>e.start._1>mn(t.start._1)(t.end._1)&&e.start._1<Nn(t.start._1)(t.end._1)&&t.start._2>mn(e.start._2)(e.end._2)&&t.start._2<Nn(e.start._2)(e.end._2)?L("Just",{position:w(e.start._1,t.start._2),crossingEdge:n}):T,Eh=t=>e=>St(ct(n=>n.direction==="H",t.segments))(n=>St(e)(r=>xt(i=>bh(n)(i)(r.edge))(ct(i=>i.direction==="V",r.segments)))),kh=t=>e=>n=>[...Eh(e)(ct(r=>r.edge!==e.edge,n)),...Lh(t)(e)(n)],Ti=(()=>{const t={eq:e=>n=>e._1===n._1&&(e._2==="North"?n._2==="North":e._2==="South"?n._2==="South":e._2==="East"?n._2==="East":e._2==="West"&&n._2==="West")};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);if(r==="LT")return me;if(r==="GT")return Ne;if(e._2==="North")return n._2==="North"?we:me;if(n._2==="North")return Ne;if(e._2==="South")return n._2==="South"?we:me;if(n._2==="South")return Ne;if(e._2==="East")return n._2==="East"?we:me;if(n._2==="East")return Ne;if(e._2==="West"&&n._2==="West")return we;c()},Eq0:()=>t}})(),Gh=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=Ti.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ch=Vt(C)(Dt),ou=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Sh=Vt(Ti)(Dt),Pa=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),er=t=>e=>n=>r=>{const i=Gh(w(e,n))(t);if(i.tag==="Nothing")return r;if(i.tag==="Just")return i._1;c()},Da=t=>e=>n=>{const r=Ch(Le(O(u=>At(s=>a=>w(a,s))(u))(t))),i=(u,s)=>{if(u==="South"){const a=ou(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}if(u==="North"){const a=ou(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;c()}return 0},o=u=>J(s=>a=>xe(Ti.compare,pe,Sh(O(f=>w(w(f._1,u),f._2))(Pa(Ca({lo:0,hi:(()=>{const f=ou(a._1)(n);if(f.tag==="Just")return f._1._1;if(f.tag==="Nothing")return ce(3)(a._1)==="$d:"?0:1;c()})()})(O(f=>f.id)(vt(f=>g=>nt.compare(i(u,f))(i(u,g)))(a._2)))))),s))(M)(Pa(J(s=>a=>a.from.node===a.to.node?s:u==="South"?Tt(C)(ue)(a.from.node)([a])(s):u==="North"?Tt(C)(ue)(a.to.node)([a])(s):s)(M)(e)));return xe(Ti.compare,pe,o(se),o(ae))},Aa=t=>t,Ia=t=>t,Ra=t=>t,Qh=J(t=>e=>K(C)(e)()(t))(M),Ph=(()=>{const t=Re.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return L("Just",w(e._1,e._2));c()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._3,n(r._6,i)));c()};return n(e,qt)})())})(),et=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ce=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},We=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},De=Vt(C)(Dt),uu=fg(C),Ar=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),Fa=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Dh=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Ah=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Ba=Ra("VDown"),Ma=Ra("VUp"),Ih=Ia("ForwardPhase"),Rh=Ia("StackPhase"),$a=Aa("HRight"),za=Aa("HLeft"),Fh=t=>e=>n=>{const r=J(u=>s=>Tt(C)(Zt)(s.tgt)(1)(u))(M)(t),i=Ph(Qh([...O(u=>u.src)(t),...O(u=>u.tgt)(t),...(()=>{const u=(s,a)=>{if(s.tag==="Leaf")return a;if(s.tag==="Node")return u(s._5,Mt("Cons",s._4,u(s._6,a)));c()};return bt(Wt.foldr,u(e,qt))})()])),o=J(u=>s=>Tt(C)(ue)(s.src)([{target:s.tgt,sep:s.sep}])(u))(M)(t);return(u=>s=>a=>{let f=u,g=s,d=a,l=!0,_;for(;l;){const h=f,p=g,m=d,N=Bt(y=>T,y=>x=>L("Just",{head:y,tail:x}),h);if(N.tag==="Nothing"){l=!1,_=m;continue}if(N.tag==="Just"){const y=et(N._1.head)(m),x=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;c()})(),v=J(b=>E=>{const k=et(E.target)(b.result),F=x+E.sep,U=et(E.target)(b.indeg),tt=(()=>{if(U.tag==="Nothing")return-1;if(U.tag==="Just")return U._1-1|0;c()})();return{newQueue:tt===0?[...b.newQueue,E.target]:b.newQueue,result:K(C)(E.target)((()=>{if(k.tag==="Nothing")return F;if(k.tag==="Just"){if(n==="VDown")return Ce(k._1)(F);if(n==="VUp")return We(k._1)(F)}c()})())(b.result),indeg:K(C)(E.target)(tt)(b.indeg)}})({newQueue:[],result:m,indeg:p})((()=>{const b=et(N._1.head)(o);if(b.tag==="Nothing")return[];if(b.tag==="Just")return b._1;c()})());f=[...N._1.tail,...v.newQueue],g=v.indeg,d=v.result;continue}c()}return _})(ct(u=>{const s=et(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;c()},i))(M)(J(u=>s=>K(C)(s)(0)(u))(M)(i))},Bh=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Mt("Cons",o._4,e(o._6,u)));c()},n=bt(Wt.foldr,e(t,qt)),r=J(Ce)(999999)(n);if(r===0||n.length===0)return t;const i=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,o._4-r,i(o._5),i(o._6));c()};return i(t)},Mh=t=>e=>{const n=(i,o,u)=>ce(3)(o)==="$d:"&&Wu(s=>ce(3)(s)==="$d:",(()=>{const s=et(o)(t.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;c()})()),r=i=>o=>u=>s=>a=>f=>g=>{let d=i,l=o,_=s,h=f,p=g,m=!0,N;for(;m;){const y=d,x=l,v=_,b=h,E=p,k=x.length;if(E>=k){m=!1,N=y;continue}const F=E>=0&&E<x.length?L("Just",x[E]):T,U=(()=>{if(F.tag==="Nothing")return"";if(F.tag==="Just")return F._1;c()})(),tt=n(t,U);if(E===(k-1|0)||tt){const Q=(()=>{if(tt){const S=et(U)(t.preds),Z=(()=>{if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;c()})();if(0<Z.length){const V=v-1|0,R=et(Z[0])(t.nodeIndex);if(R.tag==="Nothing")return V;if(R.tag==="Just")return R._1;c()}}return v-1|0})();d=J(S=>Z=>{if(Z>=0&&Z<x.length){const V=x[Z];return n(t,V)?S:J(R=>$=>{const I=et($)(t.nodeIndex),G=(()=>{if(I.tag==="Nothing")return 0;if(I.tag==="Just")return I._1;c()})();return G<b||G>Q?K(C)($+"\u2192"+V)()(R):R})(S)((()=>{const R=et(V)(t.preds);if(R.tag==="Nothing")return[];if(R.tag==="Just")return R._1;c()})())}return n(t,"")?S:J(V=>R=>{const $=et(R)(t.nodeIndex),I=(()=>{if($.tag==="Nothing")return 0;if($.tag==="Just")return $._1;c()})();return I<b||I>Q?K(C)(R+"\u2192")()(V):V})(S)((()=>{const V=et("")(t.preds);if(V.tag==="Nothing")return[];if(V.tag==="Just")return V._1;c()})())})(y)(Ht(0,E)),l=x,_=v,h=Q,p=E+1|0;continue}d=y,l=x,_=v,h=b,p=E+1|0}return N};return e.length<3?M:J(i=>o=>{if(o>=0&&o<e.length){const u=e[o];return r(i)((()=>{const s=o+1|0;return s>=0&&s<e.length?e[s]:[]})())(u)(u.length)(o)(0)(0)}return r(i)((()=>{const u=o+1|0;return u>=0&&u<e.length?e[u]:[]})())([])(0)(o)(0)(0)})(M)(Ht(1,e.length-2|0))},Oa=t=>{const e=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return e(o._5,Mt("Cons",o._4,e(o._6,u)));c()},n=e(t,qt),r=o=>u=>{let s=o,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=We(d)(l._1),a=l._2;continue}c()}return g},i=o=>u=>{let s=o,a=u,f=!0,g;for(;f;){const d=s,l=a;if(l.tag==="Nil"){f=!1,g=d;continue}if(l.tag==="Cons"){s=Ce(d)(l._1),a=l._2;continue}c()}return g};return r(-999999)(n)-i(999999)(n)},Ir=t=>e=>(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(a===e){u=!1,s=f;continue}i=(()=>{const g=et(a)(t.align);if(g.tag==="Nothing")return e;if(g.tag==="Just")return g._1;c()})(),o=[...f,a]}return s})((()=>{const n=et(e)(t.align);if(n.tag==="Nothing")return e;if(n.tag==="Just")return n._1;c()})())([e]),$h=t=>e=>n=>r=>i=>o=>u=>s=>a=>f=>g=>{const d=(G,D,P)=>{const A=G.from.node===D?G.from.port:G.to.node===D?G.to.port:T;if(A.tag==="Just"){const H=et(D)(i);if(H.tag==="Just"){const Y=ge(W=>W.id===A._1)(H._1);if(Y.tag==="Just"){const W=ot(Y._1.offset)*ot(4);return P==="North"||P==="South"?W:0}if(Y.tag==="Nothing"){const W=et(D)(r),q=er(u)(G.id)(P)((()=>{if(W.tag==="Nothing")return .5;if(W.tag==="Just")return W._1._1/2;c()})());return P==="North"||P==="South"?q:0}c()}if(H.tag==="Nothing"){const Y=et(D)(r),W=er(u)(G.id)(P)((()=>{if(Y.tag==="Nothing")return .5;if(Y.tag==="Just")return Y._1._1/2;c()})());return P==="North"||P==="South"?W:0}c()}if(A.tag==="Nothing"){const H=et(D)(r),Y=er(u)(G.id)(P)((()=>{if(H.tag==="Nothing")return .5;if(H.tag==="Just")return H._1._1/2;c()})());return P==="North"||P==="South"?Y:0}c()},l=(G,D)=>{if(G.from.node===D){if(g==="HRight")return ae;if(g==="HLeft")return se;c()}if(g==="HRight")return se;if(g==="HLeft")return ae;c()},_=(G,D,P)=>J(A=>H=>K(C)(H)((()=>{const Y=et(H)(A);if(Y.tag==="Nothing")return 0+D;if(Y.tag==="Just")return Y._1+D;c()})())(A))(P)(Ir(a)(G)),h=(()=>{if(g==="HRight")return n;if(g==="HLeft")return de(n);c()})(),p=G=>{const D=et(G)(r);if(D.tag==="Nothing")return 1;if(D.tag==="Just")return D._1._1;c()},m=De(Le(At(G=>D=>O(P=>w(P,G))(D))(n))),N=(G,D)=>ce(3)(G)==="$d:"&&ce(3)(D)==="$d:"||ce(3)(G)==="$d:"||ce(3)(D)==="$d:"?10:ot(t.nodeGap),y=J(G=>D=>uu(P=>L("Just",[...(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;c()})(),D]))(D.to.node)(G))(M)(o),x=J(G=>D=>uu(P=>L("Just",[...(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;c()})(),D]))(D.from.node)(G))(M)(o),v=Le(n),b=J(G=>D=>{const P=et(D)(a.root),A=(()=>{if(P.tag==="Nothing")return D;if(P.tag==="Just")return P._1;c()})();return D===A?G:uu(H=>L("Just",(()=>{if(H.tag==="Nothing")return!0;if(H.tag==="Just")return H._1;c()})()&&ce(3)(D)==="$d:"))(A)(G)})(De(O(G=>w(G,!0))(zn(C.compare)((()=>{const G=(D,P)=>{if(D.tag==="Leaf")return P;if(D.tag==="Node")return G(D._5,Mt("Cons",D._4,G(D._6,P)));c()};return bt(Wt.foldr,G(a.root,qt))})()))))(v),E=(G,D)=>{const P=G.free,A=et(P)(a.root),H=(()=>{if(A.tag==="Nothing")return P;if(A.tag==="Just")return A._1;c()})(),Y=et(H)(b),W=(()=>{if(Y.tag==="Nothing")return!0;if(Y.tag==="Just")return Y._1;c()})();return J(q=>B=>{if(q.edge.tag==="Just")return q;if(q.edge.tag==="Nothing"){if((()=>{const ft=et(H)(D.su);return!W&&(()=>{const ht=et(B.from.node)(m);return B.from.node!==B.to.node&&(()=>{const Lt=et(B.to.node)(m);return(()=>{if(ht.tag==="Nothing")return-1;if(ht.tag==="Just")return ht._1;c()})()===(()=>{if(Lt.tag==="Nothing")return-1;if(Lt.tag==="Just")return Lt._1;c()})()})()})()||(()=>{if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;c()})()})())return q;const j=B.from.node===P?B.to.node:B.from.node,X=et(j)(a.root),_t=(()=>{if(X.tag==="Nothing")return j;if(X.tag==="Just")return X._1;c()})(),pt=_t!==H;return pt&&(()=>{const ft=et(_t)(D.blockFinished);if(ft.tag==="Nothing")return!1;if(ft.tag==="Just")return ft._1;c()})()?{...q,edge:L("Just",B),hasEdges:!0}:{...q,hasEdges:q.hasEdges||pt}}c()})({edge:T,hasEdges:!1})((()=>{if(G.isRoot){if(g==="HRight"){const q=et(P)(y);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;c()}if(g==="HLeft"){const q=et(P)(x);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}c()}if(g==="HRight"){const q=et(P)(x);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;c()}if(g==="HLeft"){const q=et(P)(y);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}c()})())},k=(G,D,P,A)=>{const H=(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})(),Y={free:D,isRoot:P},W=E(Y,A);if(W.edge.tag==="Nothing")return W.hasEdges?{thresh:H,state:{...A,queue:[...A.queue,Y]}}:{thresh:H,state:A};if(W.edge.tag==="Just"){const q=W.edge._1.from.node===D?W.edge._1.to.node:W.edge._1.from.node;return{thresh:(()=>{const B=et((()=>{const pt=et(q)(a.root);if(pt.tag==="Nothing")return q;if(pt.tag==="Just")return pt._1;c()})())(A.x),j=et(q)(s),X=et(D)(s),_t=(()=>{if(B.tag==="Just")return B._1;if(B.tag==="Nothing")return T;c()})();return(()=>{if(_t.tag==="Nothing")return 0;if(_t.tag==="Just")return _t._1;c()})()+(()=>{if(j.tag==="Nothing")return 0;if(j.tag==="Just")return j._1;c()})()+d(W.edge._1,q,(()=>{if(P){if(g==="HRight")return ae;if(g==="HLeft")return se;c()}if(g==="HRight")return se;if(g==="HLeft")return ae;c()})())-(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;c()})()-d(W.edge._1,D,(()=>{if(P){if(g==="HRight")return se;if(g==="HLeft")return ae;c()}if(g==="HRight")return ae;if(g==="HLeft")return se;c()})())})(),state:{...A,su:K(C)((()=>{const B=et(W.edge._1.from.node)(a.root);if(B.tag==="Nothing")return W.edge._1.from.node;if(B.tag==="Just")return B._1;c()})())(!0)(K(C)((()=>{const B=et(W.edge._1.to.node)(a.root);if(B.tag==="Nothing")return W.edge._1.to.node;if(B.tag==="Just")return B._1;c()})())(!0)(A.su))}}}c()},F=(G,D,P,A)=>{const H=D===G,Y=et(D)(a.align),W=(()=>{if(Y.tag==="Nothing")return D===G;if(Y.tag==="Just")return Y._1===G;c()})();if(!(H||W))return{thresh:P,state:A};const q=(()=>{if(f==="VDown")return H&&P<=-1e18;if(f==="VUp")return H&&P>=1e18;c()})()?k(G,D,!0,A):{thresh:P,state:A};return(()=>{if(f==="VDown")return q.thresh<=-1e18&&W;if(f==="VUp")return q.thresh>=1e18&&W;c()})()?k(G,D,!1,q.state):q},U=G=>D=>P=>{const A=et(P)(e.nodeIndex),H=(()=>{if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;c()})(),Y=ge(X=>ke(ze)(P)(X))(h),W=(()=>{if(Y.tag==="Nothing")return[];if(Y.tag==="Just")return Y._1;c()})(),q=W.length;if((()=>{if(f==="VDown")return H<=0;if(f==="VUp")return H>=(q-1|0);c()})()){const X=F(G,P,D.thresh,D.st);return{...D,st:X.state,thresh:X.thresh}}const B=(()=>{if(f==="VDown")return H-1|0;if(f==="VUp")return H+1|0;c()})(),j=B>=0&&B<W.length?L("Just",W[B]):T;if(j.tag==="Nothing")return D;if(j.tag==="Just"){const X=et(j._1)(a.root),_t=(()=>{if(X.tag==="Nothing")return j._1;if(X.tag==="Just")return X._1;c()})(),pt=F(G,P,D.thresh,tt(_t)(D.st)),ft=(()=>{const re=et(G)(pt.state.sink);if(re.tag==="Nothing")return G===G;if(re.tag==="Just")return re._1===G;c()})()?{...pt.state,sink:K(C)(G)((()=>{const re=et(_t)(pt.state.sink);if(re.tag==="Nothing")return _t;if(re.tag==="Just")return re._1;c()})())(pt.state.sink)}:pt.state,ht=et(_t)(ft.sink),Lt=(()=>{if(ht.tag==="Nothing")return _t;if(ht.tag==="Just")return ht._1;c()})(),Pt=et(G)(ft.sink),lt=(()=>{if(Pt.tag==="Nothing")return G;if(Pt.tag==="Just")return Pt._1;c()})();if(lt===Lt){const re=et(_t)(ft.x),je=(()=>{if(re.tag==="Just")return re._1;if(re.tag==="Nothing")return T;c()})(),sr=(()=>{if(je.tag==="Nothing")return 0;if(je.tag==="Just")return je._1;c()})(),_n=et(G)(ft.x),Gt=(()=>{if(_n.tag==="Just")return _n._1;if(_n.tag==="Nothing")return T;c()})(),Qt=(()=>{if(Gt.tag==="Nothing")return 0;if(Gt.tag==="Just")return Gt._1;c()})(),ar=N(P,j._1),In=et(j._1)(s),Rn=et(P)(s),cr=(()=>{if(In.tag==="Nothing")return 0;if(In.tag==="Just")return In._1;c()})()-(()=>{if(Rn.tag==="Nothing")return 0;if(Rn.tag==="Just")return Rn._1;c()})();if(f==="VDown"){const $e=We(sr+cr+p(j._1)+ar)(pt.thresh);return{st:{...ft,x:K(C)(G)(L("Just",D.initial?$e:We(Qt)($e)))(ft.x)},initial:!1,thresh:pt.thresh}}if(f==="VUp"){const $e=Ce(sr+cr-ar-p(P))(pt.thresh);return{st:{...ft,x:K(C)(G)(L("Just",D.initial?$e:Ce(Qt)($e)))(ft.x)},initial:!1,thresh:pt.thresh}}c()}const Rt=et(_t)(ft.x),mt=(()=>{if(Rt.tag==="Just")return Rt._1;if(Rt.tag==="Nothing")return T;c()})(),gt=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})(),it=et(G)(ft.x),rt=(()=>{if(it.tag==="Just")return it._1;if(it.tag==="Nothing")return T;c()})(),at=(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})(),Nt=ot(t.nodeGap),yt=et(P)(s),Ct=et(j._1)(s),Ot=(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()-(()=>{if(Ct.tag==="Nothing")return 0;if(Ct.tag==="Just")return Ct._1;c()})();return{st:{...ft,classEdges:[...ft.classEdges,{src:lt,tgt:Lt,sep:(()=>{if(f==="VDown")return at+Ot-gt-p(j._1)-Nt;if(f==="VUp")return at+Ot+p(P)+Nt-gt;c()})()}]},initial:D.initial,thresh:pt.thresh}}c()},tt=G=>D=>{const P=et(G)(D.x),A=(()=>{if(P.tag==="Just")return P._1;if(P.tag==="Nothing")return T;c()})();if(A.tag==="Just")return D;if(A.tag==="Nothing"){const H=J(U(G))({st:{...D,x:K(C)(G)(L("Just",0))(D.x)},initial:!0,thresh:(()=>{if(f==="VDown")return-1e18;if(f==="VUp")return 1e18;c()})()})(Ir(a)(G));return{...H.st,blockFinished:K(C)(G)(!0)(H.st.blockFinished)}}c()},Q=J(G=>D=>J(P=>A=>{const H=et(A)(a.root),Y=(()=>{if(H.tag==="Nothing")return A;if(H.tag==="Just")return H._1;c()})();return Y===A?tt(Y)(P):P})(G)((()=>{if(f==="VDown")return D;if(f==="VUp")return de(D);c()})()))({x:De(O(G=>w(G,T))(v)),sink:De(O(G=>w(G,G))(v)),classEdges:[],su:M,blockFinished:M,queue:[]})(h),S=Fh(Q.classEdges)(Q.sink)(f),Z=(G,D,P,A)=>{const H=et(D)(A),Y=et(D)(s);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;c()})()+(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()+d(G,D,P)},V=De(O(G=>w(G,!0))(zn(C.compare)((()=>{const G=(D,P)=>{if(D.tag==="Leaf")return P;if(D.tag==="Node")return G(D._5,Mt("Cons",D._4,G(D._6,P)));c()};return bt(Wt.foldr,G(a.root,qt))})()))),R=G=>D=>P=>{const A=E(P,{su:D.su,blockFinished:V}),H={phase:G,ppFree:P.free,ppIsRoot:P.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const Y=et((()=>{const W=et(P.free)(a.root);if(W.tag==="Nothing")return P.free;if(W.tag==="Just")return W._1;c()})())(D.su);if(Y.tag==="Nothing")return!1;if(Y.tag==="Just")return Y._1;c()})(),hasEdges:A.hasEdges,candCount:(()=>{if(P.isRoot){if(g==="HRight"){const Y=et(P.free)(y);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;c()}if(g==="HLeft"){const Y=et(P.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}c()}if(g==="HRight"){const Y=et(P.free)(x);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length;c()}if(g==="HLeft"){const Y=et(P.free)(y);if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1.length}c()})()};if(A.edge.tag==="Nothing")return{...D,stack:[...D.stack,P],trace:[...D.trace,H],x:D.x};if(A.edge.tag==="Just"){const Y=A.edge._1.from.node===P.free?w(A.edge._1.from.node,A.edge._1.to.node):w(A.edge._1.to.node,A.edge._1.from.node),W=Z(A.edge._1,Y._1,l(A.edge._1,Y._1),D.x)-Z(A.edge._1,Y._2,l(A.edge._1,Y._2),D.x),q=et(Y._1)(a.root),B=(()=>{if(q.tag==="Nothing")return Y._1;if(q.tag==="Just")return q._1;c()})(),j={...H,edgeId:L("Just",A.edge._1.id),delta:W};if(W>0&&W<1e300){const X=J(ft=>ht=>{const Lt=et(ht)(m),Pt=(()=>{if(Lt.tag==="Nothing")return-1;if(Lt.tag==="Just")return Lt._1;c()})();if(Pt>=0&&Pt<n.length){const mt=n[Pt],gt=et(ht)(e.nodeIndex),it=(()=>{if(gt.tag==="Nothing")return-2;if(gt.tag==="Just")return gt._1-1|0;c()})();return it>=0&&it<mt.length?Ce(ft)((()=>{const rt=et(ht)(D.x),at=et(ht)(s),Nt=et(mt[it])(D.x),yt=et(mt[it])(s);return(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(at.tag==="Nothing")return 0;if(at.tag==="Just")return at._1;c()})()-((()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;c()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+p(mt[it])+N(ht,mt[it]))})()):ft}const lt=et(ht)(e.nodeIndex),Rt=(()=>{if(lt.tag==="Nothing")return-2;if(lt.tag==="Just")return lt._1-1|0;c()})();return Rt>=0&&Rt<0?Ce(ft)((()=>{const mt=et(ht)(D.x),gt=et(ht)(s),it=et([][Rt])(D.x),rt=et([][Rt])(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()-((()=>{if(it.tag==="Nothing")return 0;if(it.tag==="Just")return it._1;c()})()+(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+p([][Rt])+N(ht,[][Rt]))})()):ft})(W)(Ir(a)(B)),_t=X>0?-X:0,pt={...D,x:X>0?_(B,_t,D.x):D.x,trace:[...D.trace,{...j,avail:X,shift:_t}]};return X>0?pt:{...pt,stack:[...pt.stack,P]}}if(W<0&&-W<1e300){const X=J(ft=>ht=>{const Lt=et(ht)(m),Pt=(()=>{if(Lt.tag==="Nothing")return-1;if(Lt.tag==="Just")return Lt._1;c()})();if(Pt>=0&&Pt<n.length){const mt=n[Pt],gt=et(ht)(e.nodeIndex),it=(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1+1|0;c()})();return it>=0&&it<mt.length?Ce(ft)((()=>{const rt=et(mt[it])(D.x),at=et(mt[it])(s),Nt=et(ht)(D.x),yt=et(ht)(s);return(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+(()=>{if(at.tag==="Nothing")return 0;if(at.tag==="Just")return at._1;c()})()-((()=>{if(Nt.tag==="Nothing")return 0;if(Nt.tag==="Just")return Nt._1;c()})()+(()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;c()})()+p(ht)+N(ht,mt[it]))})()):ft}const lt=et(ht)(e.nodeIndex),Rt=(()=>{if(lt.tag==="Nothing")return 0;if(lt.tag==="Just")return lt._1+1|0;c()})();return Rt>=0&&Rt<0?Ce(ft)((()=>{const mt=et([][Rt])(D.x),gt=et([][Rt])(s),it=et(ht)(D.x),rt=et(ht)(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;c()})()+(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;c()})()-((()=>{if(it.tag==="Nothing")return 0;if(it.tag==="Just")return it._1;c()})()+(()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;c()})()+p(ht)+N(ht,[][Rt]))})()):ft})(-W)(Ir(a)(B)),_t=X>0?X:0,pt={...D,x:X>0?_(B,_t,D.x):D.x,trace:[...D.trace,{...j,avail:X,shift:_t}]};return X>0?pt:{...pt,stack:[...pt.stack,P]}}return{...D,stack:[...D.stack,P],trace:[...D.trace,j],x:D.x}}c()},$=J(R(Ih))({x:De(O(G=>w(G,(()=>{const D=et(G)(a.root),P=(()=>{if(D.tag==="Nothing")return G;if(D.tag==="Just")return D._1;c()})(),A=et(P)(Q.x),H=et((()=>{const W=et(P)(Q.sink);if(W.tag==="Nothing")return P;if(W.tag==="Just")return W._1;c()})())(S),Y=(()=>{if(A.tag==="Just")return A._1;if(A.tag==="Nothing")return T;c()})();return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;c()})()+(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;c()})()})()))(v)),su:Q.su,stack:[],trace:[]})(Q.queue),I=J(R(Rh))({...$,stack:[]})(de($.stack));return{x:I.x,queue:Q.queue,trace:I.trace}},zh=t=>e=>n=>r=>i=>o=>u=>s=>a=>f=>g=>$h(t)(e)(n)(r)(i)(o)(u)(s)(a)(f)(g).x,Oh=t=>e=>n=>r=>i=>o=>{const u=(a,f,g)=>{const d=et(f)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;c()})(),_=a.from.node===f?a.from.port:a.to.node===f?a.to.port:T;if(_.tag==="Just"){const h=et(f)(e);if(h.tag==="Just"){const p=ge(m=>m.id===_._1)(h._1);if(p.tag==="Just"){const m=ot(p._1.offset)*ot(4);return g==="North"||g==="South"?m:0}if(p.tag==="Nothing"){const m=er(i)(a.id)(g)(l);return g==="North"||g==="South"?m:0}c()}if(h.tag==="Nothing"){const p=er(i)(a.id)(g)(l);return g==="North"||g==="South"?p:0}c()}if(_.tag==="Nothing"){const h=er(i)(a.id)(g)(l);return g==="North"||g==="South"?h:0}c()},s=a=>f=>g=>d=>{let l=a,_=f,h=g,p=d,m=!0,N;for(;m;){const y=l,x=_,v=h,b=Bt(E=>T,E=>k=>L("Just",{head:E,tail:k}),p);if(b.tag==="Nothing"){m=!1,N=y;continue}if(b.tag==="Just"){const E=b._1.head,k=ge(U=>U.from.node===v&&U.to.node===E||U.from.node===E&&U.to.node===v)(r),F=(()=>{if(k.tag==="Nothing")return x+0;if(k.tag==="Just")return x+(u(k._1,v,k._1.from.node===v?ae:se)-u(k._1,E,k._1.from.node===E?ae:se));c()})();l=K(C)(E)(F)(y),_=F,h=E,p=b._1.tail;continue}c()}return N};return J(a=>f=>{const g=Bt(_=>T,_=>h=>L("Just",{head:_,tail:h}),Ir(t)(f)),d=(()=>{if(g.tag==="Nothing")return K(C)(f)(0)(M);if(g.tag==="Just")return s(K(C)(g._1.head)(0)(M))(0)(g._1.head)(g._1.tail);c()})(),l=J(_=>h=>We(_)(-h._2))(0)(Ar(d));return J(_=>h=>K(C)(h._1)(h._2+l)(_))(a)(Ar(d))})(M)(zn(C.compare)((()=>{const a=(f,g)=>{if(f.tag==="Leaf")return g;if(f.tag==="Node")return a(f._5,Mt("Cons",f._4,a(f._6,g)));c()};return bt(Wt.foldr,a(t.root,qt))})()))},qh=t=>e=>n=>r=>i=>{const o=Le(e),u=J(s=>a=>{const f=J(g=>d=>{const l=(()=>{if(i==="HRight"){const m=et(d)(t.preds);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()}if(i==="HLeft"){const m=et(d)(t.succs);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1}c()})(),_=l.length;if(_===0)return g;const h=Fn(_-1|0,2),p=Fn(_,2);return J(m=>N=>{if((()=>{const y=et(d)(m.align);if(y.tag==="Nothing")return d!==d;if(y.tag==="Just")return y._1!==d;c()})())return m;if(N>=0&&N<l.length){const y=et(l[N])(t.nodeIndex),x=(()=>{if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;c()})();if(!(Fa(l[N]+"\u2192"+d)(n)||Fa(d+"\u2192"+l[N])(n))&&(()=>{if(r==="VDown")return m.r<x;if(r==="VUp")return m.r>x;c()})()){const v=et(l[N])(m.root),b=(()=>{if(v.tag==="Nothing")return l[N];if(v.tag==="Just")return v._1;c()})();return{root:K(C)(d)(b)(m.root),align:K(C)(l[N])(d)(K(C)(d)(b)(m.align)),r:x}}}return m})(g)((()=>{if(r==="VDown")return Ht(h,p);if(r==="VUp")return de(Ht(h,p));c()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;c()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return de(a);c()})());return{root:f.root,align:f.align}})({root:De(O(s=>w(s,s))(o)),align:De(O(s=>w(s,s))(o))})((()=>{if(i==="HRight")return e;if(i==="HLeft")return de(e);c()})());return{root:u.root,align:u.align}},vi=t=>e=>n=>r=>i=>o=>u=>s=>a=>f=>{const g=qh(e)(n)(s)(a)(f),d=Oh(g)(i)(r)(o)(u)(f);return cg()(l=>_=>L("Just",(()=>{const h=et(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;c()})()))(zh(t)(e)(n)(r)(i)(o)(u)(d)(g)(a)(f))},qa=t=>e=>At(n=>r=>J(i=>o=>o>=0&&o<e.length?o>=0&&o<t.length?i+e[o]+t[o]:i+e[o]+0:o>=0&&o<t.length?i+1+t[o]:i+1)(0)((()=>{const i=Ht(0,e.length-1|0);return n<1?[]:It(0,n,i)})()))(e),Hh=t=>e=>n=>r=>i=>o=>u=>{const s=Dh(0)(e.length-1|0),a=ot(t.layerGap),f=u(Vf(s,a)),g=Wl(Sa(i)(f)(r)(o)(M))(f);return O(d=>{const l=Ah(d)(g);return l.tag==="Just"&&l._1>0?We(a)(2+ot(l._1-1|0)*2.5):a})(Ht(0,s-1|0))},Ha=t=>e=>n=>r=>Wu(i=>J(o=>u=>{if(!o.ok)return o;const s=et(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})(),f=et(u)(n),g=(()=>{if(f.tag==="Nothing")return a+1;if(f.tag==="Just")return a+f._1._1;c()})();return a+1e-4>o.pos&&g+1e-4>o.pos?{ok:!0,pos:g}:{ok:!1,pos:o.pos}})({ok:!0,pos:-1e18})(i).ok,e),Wh=t=>e=>n=>r=>{const i=vt(o=>u=>dt.compare(o.w)(u.w))(O(o=>({l:o,w:Oa(o)}))(ct(Ha()(e)(n),r)));return 0<i.length?L("Just",i[0].l):T},Vh=t=>e=>{const n=De(Le(O(At(i=>o=>w(o,i)))(t))),r=i=>vt(o=>u=>nt.compare((()=>{const s=et(o)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})())((()=>{const s=et(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(i);return{preds:(()=>{const i=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));c()};return i(J(o=>u=>Tt(C)(ue)(u.to.node)([u.from.node])(o))(M)(e))})(),succs:(()=>{const i=o=>{if(o.tag==="Leaf")return M;if(o.tag==="Node")return $t("Node",o._1,o._2,o._3,r(o._4),i(o._5),i(o._6));c()};return i(J(o=>u=>Tt(C)(ue)(u.from.node)([u.to.node])(o))(M)(e))})(),nodeIndex:n}},Uh=t=>e=>{const n=vt(d=>l=>dt.compare(d.w)(l.w))(At(d=>l=>({i:d,l,w:Oa(l)}))(e)),r=0<n.length?L("Just",n[0]):T,i=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;c()})(),o=i>=0&&i<e.length?L("Just",e[i]):T,u=(()=>{if(o.tag==="Just")return(d=>l=>{let _=d,h=l,p=!0,m;for(;p;){const N=_,y=h;if(y.tag==="Nil"){p=!1,m=N;continue}if(y.tag==="Cons"){_=Ce(N)(y._1),h=y._2;continue}c()}return m})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,Mt("Cons",l._4,d(l._6,_)));c()};return d(o._1,qt)})());if(o.tag==="Nothing")return 0;c()})(),s=d=>J(l=>_=>We(l)((()=>{const h=et(_._1)(t);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;c()})()))(-999999)(Ar(d)),a=i>=0&&i<e.length?L("Just",e[i]):T,f=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;c()})(),g=ye(d=>l=>{const _=h=>{if(h.tag==="Leaf")return M;if(h.tag==="Node")return $t("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));c()};return _(d)},e,At(d=>l=>no(d)(2)===0?u-(_=>h=>{let p=_,m=h,N=!0,y;for(;N;){const x=p,v=m;if(v.tag==="Nil"){N=!1,y=x;continue}if(v.tag==="Cons"){p=Ce(x)(v._1),m=v._2;continue}c()}return y})(999999)((()=>{const _=(h,p)=>{if(h.tag==="Leaf")return p;if(h.tag==="Node")return _(h._5,Mt("Cons",h._4,_(h._6,p)));c()};return _(l,qt)})()):f-s(l))(e));return Bh(J(d=>l=>{const _=vt(dt.compare)(xt(et(l))(g));return K(C)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(M)(zn(C.compare)(Le(O(d=>{const l=_=>{if(_.tag==="Leaf")return M;if(_.tag==="Node")return $t("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));c()};return bt(Ge.foldr,l(d))})(g)))))},Yh=t=>e=>n=>r=>i=>o=>{const u=Vh(e)(i),s=Mh(u)(e),a={nodeGap:t.nodeGap*4|0},f=xe(C.compare,pe,De(O(_=>w(_,w(0,1)))(ct(_=>ce(3)(_)==="$d:",Le(e)))),(()=>{const _=h=>{if(h.tag==="Leaf")return M;if(h.tag==="Node")return $t("Node",h._1,h._2,h._3,w(h._4._1*ot(4),h._4._2),_(h._5),_(h._6));c()};return _(n)})()),g=[vi(a)(u)(e)(f)(r)(i)(o)(s)(Ba)($a),vi(a)(u)(e)(f)(r)(i)(o)(s)(Ma)($a),vi(a)(u)(e)(f)(r)(i)(o)(s)(Ba)(za),vi(a)(u)(e)(f)(r)(i)(o)(s)(Ma)(za)],d=Uh(f)(g);if(Ha()(e)(f)(d))return d;const l=Wh()(e)(f)(g);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return g[0];c()},Xh=t=>e=>n=>r=>{const i=Uf(T,Nf,o=>o.node===e?L("Just",o.position):T,t);if(i.tag==="Nothing")return t;if(i.tag==="Just"){const o=i._1;return O(u=>u.node===n?{...u,position:w(o._1+r._1,o._2+r._2)}:u)(t)}c()},Kh=t=>e=>n=>r=>{const i=ct(u=>ke(ze)(u.node)(e),t),o=(()=>{if(n==="Vertical"){if(r==="Start")return J(u=>s=>Ce(u)(s.position._1))(99999)(i);if(r==="End")return J(u=>s=>We(u)(s.position._1))(0)(i);if(r==="Center"){const u=J(s=>a=>s+a.position._1)(0)(i);return i.length===0?0:u/ot(i.length)}c()}if(n==="Horizontal"){if(r==="Start")return J(u=>s=>Ce(u)(s.position._2))(99999)(i);if(r==="End")return J(u=>s=>We(u)(s.position._2))(0)(i);if(r==="Center"){const u=J(s=>a=>s+a.position._2)(0)(i);return i.length===0?0:u/ot(i.length)}}c()})();return O(u=>{if(ke(ze)(u.node)(e)){if(n==="Vertical")return{...u,position:w(o,u.position._2)};if(n==="Horizontal")return{...u,position:w(u.position._1,o)};c()}return u})(t)},jh=t=>e=>J(n=>r=>{if(r.tag==="Lock"){const i=r._1.node,o=r._1.position;return O(u=>u.node===i?{...u,position:o}:u)(n)}return r.tag==="AlignGroup"?Kh(n)(O(qu)(r._1.nodes))(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?Xh(n)(r._1.anchor)(r._1.target)(r._1.offset):n})(e)(t),Zh=t=>e=>n=>r=>i=>o=>u=>s=>{const a=De(O(_=>w(_._1,_._2))(Ar(r))),f=O(O(qu))(n),g=O(_=>J(h=>p=>We(h)((()=>{const m=et(p)(a);if(m.tag==="Nothing")return 1;if(m.tag==="Just")return m._1._2;c()})()))(1)(_))(f),d=Yh(t)(f)(a)(De(O(_=>w(_._1,_._2))(Ar(i))))(o)(s),l=qa(Hh(t)(n)(r)(i)(o)(u)(_=>{const h=qa(_)(g);return Le(At(p=>m=>At(N=>y=>({node:y,position:w((()=>{const x=et(y)(d);return(()=>{if(x.tag==="Nothing")return 0;if(x.tag==="Just")return x._1;c()})()/ot(4)})(),p>=0&&p<h.length?h[p]:0),size:(()=>{const x=ce(3)(y)==="$d:"?w(0,1):w(1,1),v=et(y)(a);if(v.tag==="Nothing")return x;if(v.tag==="Just")return v._1;c()})(),layer:p,order:N}))(m))(f))}))(g);return jh(e)(Le(At(_=>h=>At(p=>m=>({node:m,position:w((()=>{const N=et(m)(d);return(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;c()})()/ot(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const N=ce(3)(m)==="$d:"?w(0,1):w(1,1),y=et(m)(a);if(y.tag==="Nothing")return N;if(y.tag==="Just")return y._1;c()})(),layer:_,order:p}))(h))(f)))},su=Lo(oi)(kn(32)),Wa=Lo(oi)(kn(31)),Rr=(()=>{const t=__("25214903917");if(t.tag==="Nothing")return ls;if(t.tag==="Just")return t._1;c()})(),Fr=wo(Lo(oi)(kn(48)))(oi),t0=t=>{const e=d_(t);return wr(hs((()=>{if(e.tag==="Nothing")return ls;if(e.tag==="Just")return e._1;c()})())(Rr))(Fr)},au=kn(11),wi=t=>e=>{const n=wr(ri(ii(e)(Rr))(au))(Fr);return w((()=>{const r=ts(a_(bo(n)(kn(48-t|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;c()})(),n)},e0=t=>{const e=wi(26)(t),n=wi(27)(e._2);return w((ot(e._1)*to(2)(27)+ot(n._1))/to(2)(53),n._2)},n0=t=>e=>{const n=J(r=>i=>{const o=e0(r.finalR);return{rs:[...r.rs,o._1],finalR:o._2}})({rs:[],finalR:t})(e);return w(O(r=>r.x)(vt(r=>i=>dt.compare(r.k)(i.k))(ye(r=>i=>({x:r,k:i}),e,n.rs))),n.finalR)},r0=t=>{const e=wr(ri(ii(t)(Rr))(au))(Fr),n=wr(ri(ii(e)(Rr))(au))(Fr);return w(ri(ii((()=>{const r=bo(e)(kn(16));return ps.compare(r)(Wa)!=="LT"?wo(r)(su):r})())(su))((()=>{const r=bo(n)(kn(16));return ps.compare(r)(Wa)!=="LT"?wo(r)(su):r})()),n)},Br=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Li=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},cu=Vt(C)(Dt),Ve=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},bi=Vt(C)(Dt),i0=Bf(Xi),o0=J(Wn)(0),u0=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},Va=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},s0=t=>e=>n=>r=>i=>cu(J(o=>u=>{const s=vt(a=>f=>nt.compare((()=>{const g=Br(a.id)(i);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})())((()=>{const g=Br(f.id)(i);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;c()})()))(ct(a=>Li(a.to.node)(n),ct(a=>a.from.node===u,r)));return{ranks:[...o.ranks,...At(a=>f=>w(f.id,ot((o.rankSum+a|0)+1|0)))(s)],rankSum:o.rankSum+s.length|0}})({ranks:[],rankSum:0})(t).ranks),a0=t=>e=>n=>r=>i=>cu(J(o=>u=>{const s=vt(f=>g=>{const d=nt.compare((()=>{const l=Ve(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Ve(f.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;c()})());return d==="EQ"?nt.compare((()=>{const l=Br(f.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})())((()=>{const l=Br(g.id)(i);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;c()})()):d})(ct(f=>Li(f.from.node)(n),ct(f=>f.to.node===u,r))),a=s.length;return{ranks:[...o.ranks,...At(f=>g=>w(g.id,ot((o.rankSum+a|0)-f|0)))(s)],rankSum:o.rankSum+a|0}})({ranks:[],rankSum:0})(t).ranks),fu=t=>e=>n=>{const r=bi(At(s=>a=>w(a,s))(t)),i=bi(At(s=>a=>w(a,s))(e)),o=xt(s=>{const a=Ve(s.from.node)(r),f=Ve(s.to.node)(i);if(a.tag==="Just"&&f.tag==="Just")return L("Just",w(a._1,f._1));const g=Ve(s.from.node)(i),d=Ve(s.to.node)(r);return g.tag==="Just"&&d.tag==="Just"?L("Just",w(d._1,g._1)):T})(n),u=o.length;return J(s=>a=>J(f=>g=>a>=0&&a<o.length&&g>=0&&g<o.length&&((o[a]._1-o[g]._1|0)*(o[a]._2-o[g]._2|0)|0)<0?f+1|0:f)(s)(Ht(a+1|0,u-1|0)))(0)(Ht(0,u-2|0))},c0=t=>e=>n=>r=>i=>{const o=u=>s=>{let a=u,f=s,g=!0,d;for(;g;){const l=a,_=f;if(_>=(l.length-1|0)){g=!1,d=l;continue}const h=_>=0&&_<l.length?L("Just",l[_]):T,p=_+1|0;if(p>=0&&p<l.length&&h.tag==="Just"){const m=h._1,N=l[p];if(Ze(b=>b.before===m&&b.after===N,i)){a=l,f=_+1|0;continue}if((()=>{const b=Ve(m)(t),E=Ve(N)(t);return b.tag==="Just"&&E.tag==="Just"&&b._1<E._1})()){a=l,f=_+1|0;continue}const y=$n(jt,T,_,N,l),x=(()=>{if(y.tag==="Just")return $n(jt,T,_+1|0,m,y._1);if(y.tag==="Nothing")return T;c()})(),v=(()=>{if(x.tag==="Nothing")return l;if(x.tag==="Just")return x._1;c()})();if(fu(n)(v)(r)<fu(n)(l)(r)){a=v,f=_+1|0;continue}a=l,f=_+1|0;continue}g=!1,d=l}return d};return(u=>{let s=u,a=!0,f;for(;a;){const g=s,d=o(g)(0);if(i0(d)(g)){a=!1,f=g;continue}s=d}return f})(e)},Ei=t=>e=>J(n=>r=>{if(r>=0&&r<t.length){const i=t[r],o=r+1|0;if(o>=0&&o<t.length)return n+fu(i)(t[o])(e)|0}return n})(0)(Ht(0,t.length-2|0)),f0=t=>e=>n=>{const r=xt(f=>f.tag==="OrderConstraint"?L("Just",{before:f._1.before,after:f._1.after}):T)(t.constraints),i=f=>J(g=>d=>{const l=d.after,_=d.before,h=Mn(jt,T,m=>m===_,g),p=Mn(jt,T,m=>m===l,g);if(h.tag==="Just"&&p.tag==="Just"&&h._1>p._1){const m=Hu(jt,T,h._1,g),N=(()=>{if(m.tag==="Nothing")return g;if(m.tag==="Just")return m._1;c()})(),y=Xf(jt,T,p._1,_,N);if(y.tag==="Nothing")return N;if(y.tag==="Just")return y._1;c()}return g})(f)(r),o=cu(At(f=>g=>w(g.id,f))(n)),u=(f,g,d)=>{const l=f.length;return J(_=>h=>{const p=g?h-1|0:h+1|0,m=p>=0&&p<_._1.length?L("Just",_._1[p]):T;if(m.tag==="Just"){const N=h>=0&&h<_._1.length?L("Just",_._1[h]):T;if(N.tag==="Just"){const y=bi(At(k=>F=>w(F,k))(m._1)),x=bi(At(k=>F=>w(F,k))(N._1)),v=g?s0(m._1)(y)(x)(n)(o):a0(m._1)(y)(x)(n)(o),b=J(k=>F=>{const U=xt(Q=>Br(Q.id)(v))(ct(g?Q=>Q.to.node===F._2&&Li(Q.from.node)(y):Q=>Q.from.node===F._2&&Li(Q.to.node)(y),n));if(U.length===0)return{...k,items:[...k.items,{n:F._2,key:T,origIdx:F._1}]};const tt=wi(24)(k.r);return{items:[...k.items,{n:F._2,key:L("Just",(o0(U)+(ot(tt._1)*4172325152040912e-24-.03500000014901161))/ot(U.length)),origIdx:F._1}],r:tt._2}})({items:[],r:_._2})(At(Bn)(N._1)),E=$n(jt,T,h,c0(t.modelOrder)(i(O(k=>k.n)(vt(k=>F=>{const U=Ve(k.n)(t.modelOrder),tt=Ve(F.n)(t.modelOrder);if(U.tag==="Just"&&tt.tag==="Just"){const Q=nt.compare(U._1)(tt._1);return Q==="EQ"?dt.compare(k.key)(F.key):Q}return dt.compare(k.key)(F.key)})((()=>{const k=b.items,F=U=>tt=>{let Q=U,S=tt,Z=!0,V;for(;Z;){const R=Q,$=S;if(R>=0&&R<k.length){if(k[R].key.tag==="Just"){Z=!1,V=k[R].key._1;continue}if(k[R].key.tag==="Nothing"){Q=R+1|0,S=$;continue}c()}Z=!1,V=$}return V};return(U=>tt=>Q=>{let S=U,Z=tt,V=Q,R=!0,$;for(;R;){const I=S,G=Z,D=V;if(I>=0&&I<k.length){if(k[I].key.tag==="Just"){S=I+1|0,Z=k[I].key._1,V=[...D,{n:k[I].n,key:k[I].key._1,origIdx:k[I].origIdx}];continue}if(k[I].key.tag==="Nothing"){const P=(G+F(I+1|0)(G+1))/2;S=I+1|0,Z=P,V=[...D,{n:k[I].n,key:P,origIdx:k[I].origIdx}];continue}c()}R=!1,$=D}return $})(0)(-1)([])})()))))(m._1)(n)(r),_._1);if(E.tag==="Just")return w(E._1,b.r);if(E.tag==="Nothing")return w(_._1,_._2);c()}if(N.tag==="Nothing")return w(_._1,_._2);c()}if(m.tag==="Nothing")return w(_._1,_._2);c()})(w(f,d))(g?Ht(1,l-1|0):de(Ht(0,l-2|0)))},s=J(f=>g=>K(C)(g.from.node)()(K(C)(g.to.node)()(f)))(M)(n),a=J(f=>g=>{if(f.result.crossings===0)return f;const d=y=>x=>v=>b=>{let E=y,k=x,F=v,U=b,tt=!0,Q;for(;tt;){const S=E,Z=k,V=F,R=U;if(V===0){tt=!1,Q={layout:S,crossings:0,random:R};continue}const $=u(S,Z,R),I=Ei($._1)(n);if(I<V){E=$._1,k=!Z,F=I,U=$._2;continue}tt=!1,Q={layout:S,crossings:V,random:$._2}}return Q},l=wi(1)(f.result.random),_=l._1!==0,h=t.modelOrder.tag==="Leaf",p=(f.firstTry||f.secondTry)&&!h?f.firstTry:_,m=(()=>{if(!h){const b=u(e,p,l._2);return d(b._1)(!p)(Ei(b._1)(n))(b._2)}const y=p?0:u0(0)(e.length-1|0),x=y>=0&&y<e.length?L("Just",e[y]):T;if(x.tag==="Just"&&x._1.length>1){const b=ct(E=>Va(E)(s),x._1);if(b.length>1){const E=n0(l._2)(b),k=E._1,F=$n(jt,T,y,i(J(U=>tt=>Va(tt)(s)?U.idx>=0&&U.idx<k.length?{idx:U.idx+1|0,result:[...U.result,k[U.idx]]}:{idx:U.idx,result:[...U.result,tt]}:{idx:U.idx,result:[...U.result,tt]})({idx:0,result:[]})(x._1).result),e);if(F.tag==="Just"){const U=u(F._1,p,E._2);return d(U._1)(!p)(Ei(U._1)(n))(U._2)}}}const v=u(e,p,l._2);return d(v._1)(!p)(Ei(v._1)(n))(v._2)})(),N=f.secondTry?!1:f.secondTry;return f.firstTry?{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:!1,secondTry:!0}:{result:m.crossings<f.result.crossings?{layout:m.layout,crossings:m.crossings,random:m.random}:{...f.result,random:m.random},firstTry:f.firstTry,secondTry:N}})({result:{layout:e,crossings:1e9,random:wr(hs(r0(t0(1))._1)(Rr))(Fr)},firstTry:t.modelOrder.tag!=="Leaf",secondTry:!1})(Ht(1,t.iterations)).result;return e.length<=0||t.iterations<=0?e:a.layout},g0=t=>t,Ua=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},he=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},nr=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Mr=(()=>{const t={eq:e=>n=>e._1===n._1&&e._2===n._2};return{compare:e=>n=>{const r=C.compare(e._1)(n._1);return r==="LT"?me:r==="GT"?Ne:C.compare(e._2)(n._2)},Eq0:()=>t}})(),_0=Vt(C)(Dt),d0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=Mr.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},l0=g0("Greedy"),gu=t=>e=>n=>J(r=>i=>{if(i.from.node===i.to.node)return r;if(i.from.node===e&&!Ua(i.to.node)(r.marks)){const o=he(i.to.node)(r.inDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;c()})(),s=K(C)(i.to.node)(u)(r.inDeg);return(()=>{const a=he(i.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!ke(ze)(i.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,i.to.node]}:{...r,inDeg:s}}if(i.to.node===e&&!Ua(i.from.node)(r.marks)){const o=he(i.from.node)(r.outDeg),u=(()=>{if(o.tag==="Nothing")return-1;if(o.tag==="Just")return o._1-1|0;c()})(),s=K(C)(i.from.node)(u)(r.outDeg);return(()=>{const a=he(i.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;c()})()&&!ke(ze)(i.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,i.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:ct(r=>r!==e,n.remaining)})(t),h0=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return K(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return K(C)(e._1.node)(0)(t);if(e._1.pin.tag==="LastLayer")return K(C)(e._1.node)(99999)(t)}return t})(M),Ya=t=>e=>n=>{const r=he(e)(t),i=he(n)(t);return r.tag==="Just"&&i.tag==="Just"&&r._1>i._1},Xa=t=>e=>n=>r=>{if(nr(n)(r.visited)||nr(n)(r.visiting))return r;const i=J(p0(t)(e)(n))({...r,visiting:K(C)(n)()(r.visiting)})((()=>{const o=he(n)(e);if(o.tag==="Nothing")return[];if(o.tag==="Just")return o._1;c()})());return{...i,visiting:hr(C)(n)(i.visiting),visited:K(C)(n)()(i.visited)}},p0=t=>e=>n=>r=>i=>Ya(t)(n)(i)?{...r,backEdges:K(Mr)(w(n,i))()(r.backEdges)}:nr(i)(r.visiting)?{...r,backEdges:K(Mr)(w(n,i))()(r.backEdges)}:nr(i)(r.visited)?r:Xa(t)(e)(i)(r),m0=t=>e=>n=>{const r=l=>{let _=l,h=!0,p;for(;h;){const m=_,N=Bt(y=>T,y=>x=>L("Just",{head:y,tail:x}),m.sinks);if(N.tag==="Just"){_=gu(n)(N._1.head)({...m,sinks:N._1.tail,marks:K(C)(N._1.head)(m.nextRight)(m.marks),nextRight:m.nextRight-1|0});continue}if(N.tag==="Nothing"){const y=Bt(x=>T,x=>v=>L("Just",{head:x,tail:v}),m.sources);if(y.tag==="Just"){_=gu(n)(y._1.head)({...m,sources:y._1.tail,marks:K(C)(y._1.head)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}if(y.tag==="Nothing"){const x=b=>{const E=he(b)(m.outDeg),k=he(b)(m.inDeg);return(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;c()})()-(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;c()})()|0},v=vt(b=>E=>{const k=nt.compare(x(E))(x(b));return k==="EQ"?nt.compare((()=>{const F=he(b)(e);if(F.tag==="Nothing")return 1e6;if(F.tag==="Just")return F._1;c()})())((()=>{const F=he(E)(e);if(F.tag==="Nothing")return 1e6;if(F.tag==="Just")return F._1;c()})()):k})(m.remaining);if(0<v.length){const b=v[0];_=gu(n)(b)({...m,remaining:ct(E=>E!==b,m.remaining),marks:K(C)(b)(m.nextLeft)(m.marks),nextLeft:m.nextLeft+1|0});continue}h=!1,p=m;continue}}c()}return p},i=zn(C.compare)([...O(l=>l.from.node)(n),...O(l=>l.to.node)(n)]),o=ct(l=>l.from.node!==l.to.node,n),u=J(l=>_=>Tt(C)(Zt)(_.to.node)(1)(l))(M)(o),s=J(l=>_=>Tt(C)(Zt)(_.from.node)(1)(l))(M)(o),a=ct(l=>{const _=he(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},i),f=ct(l=>{const _=he(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;c()},i),g=i.length+1|0,d=J(l=>_=>{const h=he(_)(l);return h.tag==="Just"&&h._1<0?K(C)(_)(h._1+g|0)(l):l})(r({remaining:ct(l=>!ke(ze)(l)(a)&&!ke(ze)(l)(f),i),marks:M,inDeg:u,outDeg:s,sources:a,sinks:f,nextLeft:1,nextRight:-1}).marks)(i);return J(l=>_=>{if(_.from.node===_.to.node)return l;if(Ya(t)(_.from.node)(_.to.node))return K(Mr)(w(_.from.node,_.to.node))()(l);const h=he(_.from.node)(d),p=he(_.to.node)(d);return h.tag==="Just"&&p.tag==="Just"&&h._1>p._1?K(Mr)(w(_.from.node,_.to.node))()(l):l})(M)(n)},N0=J(t=>e=>Tt(C)(ue)(e.from.node)([e.to.node])(t))(M),y0=t=>e=>{const n=N0(e),r=zn(C.compare)([...O(o=>o.from.node)(e),...O(o=>o.to.node)(e)]),i=J(o=>u=>K(C)(u.to.node)()(o))(M)(e);return J(o=>u=>Xa(t)(n)(u)(o))({visiting:M,visited:M,backEdges:M})([...ct(o=>!nr(o)(i),r),...ct(o=>nr(o)(i),r)]).backEdges},J0=t=>e=>n=>r=>{const i=_0(At(s=>a=>w(a,s))(e)),o=h0(n),u=(()=>{if(t==="DepthFirst")return y0(o)(r);if(t==="Greedy")return m0(o)(i)(r);c()})();return{edges:O(s=>d0(w(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},Ka=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},x0=t=>e=>n=>J(r=>i=>{const o=Ka(i.from.node)(t),u=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;c()})(),s=Ka(i.to.node)(t),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;c()})();if(a<=1)return{...r,edges:[...r.edges,i],chains:[...r.chains,{edgeId:i.id,nodes:[i.from.node,i.to.node]}]};const f=i.id,g=O(l=>"$d:"+f+":"+fe(l))(Ht(1,a-1|0)),d=[i.from.node,...g,i.to.node];return{...r,layers:J(l=>_=>{const h=_._2,p=Zf(u+_._1|0)(m=>[...m,h])(l);if(p.tag==="Nothing")return l;if(p.tag==="Just")return p._1;c()})(r.layers)(ye(Bn,Ht(1,a-1|0),g)),edges:[...r.edges,...ye(l=>_=>({id:f+":"+l+"->"+_,from:{node:l,port:i.from.port},to:{node:_,port:i.to.port}}),d,It(1,d.length,d))],chains:[...r.chains,{edgeId:i.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(e),ja=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},T0=J(t=>e=>K(C)(e)()(t))(M),ki=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},v0=da(C),Ue=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Za=t=>e=>{const n=nt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},_u=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=nt.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},w0=Vt(nt)(Dt),L0=t=>e=>xe(C.compare,pe,t,e),tc=At(t=>e=>({src:e.src,tgt:e.tgt,delta:1,weight:1,eid:t})),b0=t=>J(e=>n=>({base:(()=>{const r=i=>o=>{let u=i,s=o,a=!0,f;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,f=g;continue}if(d.tag==="Cons"){u=ja(g)(d._1),s=d._2;continue}c()}return f};return(e.base+r(0)((()=>{const i=(o,u)=>{if(o.tag==="Leaf")return u;if(o.tag==="Node")return i(o._5,Mt("Cons",o._4,i(o._6,u)));c()};return i(n,qt)})())|0)+1|0})(),result:[...e.result,(()=>{if(e.base===0)return n;const r=i=>{if(i.tag==="Leaf")return M;if(i.tag==="Node")return $t("Node",i._1,i._2,i._3,i._4+e.base|0,r(i._5),r(i._6));c()};return r(n)})()]}))({base:0,result:[]})(t).result,E0=t=>e=>{const n=T0(t);return v0(t)(tc(ct(r=>ki(r.src)(n)&&ki(r.tgt)(n),e)))},k0=t=>e=>{const n=J(i=>o=>Tt(C)(ue)(o.tgt)([o.src])(Tt(C)(ue)(o.src)([o.tgt])(i)))(M)(e),r=i=>o=>u=>{let s=i,a=o,f=u,g=!0,d;for(;g;){const l=s,_=a,h=f,p=Bt(m=>T,m=>N=>L("Just",{head:m,tail:N}),l);if(p.tag==="Nothing"){g=!1,d={nodes:h};continue}if(p.tag==="Just"){if(ki(p._1.head)(_)){s=p._1.tail,a=_,f=h;continue}s=[...p._1.tail,...(()=>{const m=Ue(p._1.head)(n);if(m.tag==="Nothing")return[];if(m.tag==="Just")return m._1;c()})()],a=K(C)(p._1.head)()(_),f=[...h,p._1.head];continue}c()}return d};return J(i=>o=>{if(ki(o)(i.visited))return i;const u=r([o])(i.visited)([]);return{...i,visited:J(s=>a=>K(C)(a)()(s))(i.visited)(u.nodes),components:[...i.components,u.nodes]}})({visited:M,components:[]})(t).components},G0=t=>e=>n=>{const r=J(o=>u=>Tt(C)(Zt)(u.tgt)(1)(o))(M)(e),i=J(o=>u=>Tt(C)(Zt)(u.src)(1)(o))(M)(e);return J(o=>u=>{const s=Ue(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})();if((()=>{const y=Ue(u)(i);return(()=>{if(y.tag==="Nothing")return a!==0;if(y.tag==="Just")return a!==y._1;c()})()||a===0})())return o;const f=Ue(u)(o.layers),g=(()=>{if(f.tag==="Nothing")return 0;if(f.tag==="Just")return f._1;c()})(),d=o.layers,l=J(y=>x=>x.tgt===u?{...y,mIn:Za(y.mIn)((()=>{const v=Ue(u)(d),b=Ue(x.src)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;c()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()|0})())}:x.src===u?{...y,mOut:Za(y.mOut)((()=>{const v=Ue(x.tgt)(d),b=Ue(u)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;c()})()-(()=>{if(b.tag==="Nothing")return 0;if(b.tag==="Just")return b._1;c()})()|0})())}:y)({mIn:1e9,mOut:1e9})(e),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return o;const p=(g-_|0)+1|0,m=(g+h|0)-1|0;if(m<p)return o;const N=J(y=>x=>{const v=_u(x)(o.filling),b=(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;c()})();return b<y.bestFill?{best:x,bestFill:b}:y})({best:g,bestFill:(()=>{const y=_u(g)(o.filling);if(y.tag==="Nothing")return 0;if(y.tag==="Just")return y._1;c()})()})(Ht(p,m));return N.best===g?o:{layers:K(C)(u)(N.best)(o.layers),filling:K(nt)(g)((()=>{const y=_u(g)(o.filling);if(y.tag==="Nothing")return-1;if(y.tag==="Just")return y._1-1|0;c()})())(K(nt)(N.best)(N.bestFill+1|0)(o.filling))}})({layers:n,filling:w0(O(o=>w(o,J(u=>s=>(()=>{const a=Ue(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===o})()?u+1|0:u)(0)(t)))(Ht(0,J(o=>u=>ja(o)((()=>{const s=Ue(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;c()})()))(0)(t))))})(t).layers},C0=t=>e=>G0(t)(tc(e))(J(L0)(M)(b0(O(n=>E0(n)(e))(k0(t)(e))))),S0=t=>t,Qn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Gi=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},ec=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),Q0=S0("NetworkSimplex"),P0=t=>e=>J(n=>r=>{const i=J(Gi)(0)(xt(o=>Qn(o)(n))(r));return J(o=>u=>K(C)(u)(i)(o))(n)(r)})(e)(t),D0=t=>e=>({layers:O(n=>ct(r=>{const i=Qn(r)(e);return i.tag==="Nothing"?!1:i.tag==="Just"&&i._1===n},t))(Ht(0,(n=>r=>{let i=n,o=r,u=!0,s;for(;u;){const a=i,f=o;if(f.tag==="Nil"){u=!1,s=a;continue}if(f.tag==="Cons"){i=Gi(a)(f._1),o=f._2;continue}c()}return s})(0)((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._4,n(r._6,i)));c()};return n(e,qt)})()))),nodeLayer:e}),A0=t=>e=>n=>{const r=J(i=>o=>K(C)(o)(!0)(i))(M)(e);return J(i=>o=>K(C)(o._1)(o._2)(i))(C0(e)(xt(i=>i.from.node===i.to.node||(()=>{const o=Qn(i.from.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;c()})()||(()=>{const o=Qn(i.to.node)(r);if(o.tag==="Nothing")return!0;if(o.tag==="Just")return!o._1;c()})()?T:L("Just",{src:i.from.node,tgt:i.to.node}))(t)))(ec(n))},I0=t=>e=>n=>r=>{const i=s=>a=>{const f=Qn(a)(s);if(f.tag==="Just")return s;if(f.tag==="Nothing"){const g=ct(l=>l!==a,(()=>{const l=Qn(a)(t);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;c()})()),d=J(i)(s)(g);return K(C)(a)(1+J(Gi)(0)(xt(l=>Qn(l)(d))(g))|0)(d)}c()},o=J(i)(M)(n),u=(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=Gi(_)(h._1),g=h._2;continue}c()}return l})(1)((()=>{const s=(a,f)=>{if(a.tag==="Leaf")return f;if(a.tag==="Node")return s(a._5,Mt("Cons",a._4,s(a._6,f)));c()};return s(o,qt)})());return J(s=>a=>K(C)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return M;if(a.tag==="Node")return $t("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));c()};return s(o)})())(ec(r))},R0=J(t=>e=>{if(e.tag==="LayerConstraint"){if(e._1.pin.tag==="SpecificLayer")return K(C)(e._1.node)(e._1.pin._1)(t);if(e._1.pin.tag==="FirstLayer")return K(C)(e._1.node)(0)(t)}return t})(M),F0=J(t=>e=>Tt(C)(ue)(e.to.node)([e.from.node])(t))(M),B0=J(t=>e=>Tt(C)(ue)(e.from.node)([e.to.node])(t))(M),M0=t=>e=>n=>r=>{const i=B0(n),o=F0(n),u=R0(e);return D0(r)(P0(xt(s=>s.tag==="SameLayer"?L("Just",s._1.nodes):T)(e))((()=>{if(t==="LongestPath")return I0(i)(o)(r)(u);if(t==="NetworkSimplex")return A0(n)(r)(u);c()})()))},$0=Vt(C)(Dt),z0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},nc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},rc=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},$r=Vt(C)(Dt),O0=Vt(C)(Dt),ic=(()=>{const t=O(e=>({start:e.end,end:e.start,direction:e.direction}));return e=>de(t(e))})(),q0=t=>e=>n=>r=>{const i=$0(O(u=>w(u.edge,u))(r)),o=u=>0<u.nodes.length&&(()=>{const s=z0(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return O(u=>{if(u.nodes.length<=2){const g=nc(u.edgeId)(i);if(g.tag==="Just"){const d=o(u);return{...g._1,edge:u.edgeId,segments:d?ic(g._1.segments):g._1.segments,reversed:d}}if(g.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};c()}const s=St(xt(g=>nc(g)(i))(ye(g=>d=>u.edgeId+":"+g+"->"+d,u.nodes,It(1,u.nodes.length,u.nodes))))(g=>g.segments),a=o(u),f=nu(a?ic(s):s);return{edge:u.edgeId,segments:f,bends:ye(g=>d=>g.end,f,It(1,f.length,f)),bendType:[],jumps:[],reversed:a}})(t)},H0={layers:[],edges:[],chains:[]},W0={nodeGap:3,layerGap:2,iterations:8,layerer:Q0,cycleBreaker:l0,compactPostRouting:!0},V0=t=>({pos:w(0,0),size:w(J(e=>n=>rc(e)(n.position._1+n.size._1))(0)(t),J(e=>n=>rc(e)(n.position._2+n.size._2))(0)(t))}),U0=t=>e=>n=>{const r=$r(O(f=>w(f.id,f.ports))(e.nodes)),i=ct(f=>ce(3)(f.node)!=="$d:",n.placements),o=q0(n.withDummies.chains)(n.acyclic.reversedEdges)(O0(O(f=>w(f.id,w(f.from.node,f.to.node)))(e.edges)))(xh(n.withDummies.edges)(n.placements)(r)(n.withDummies.chains)(Da(n.ordered)(ct(f=>f.from.node!==f.to.node,n.withDummies.edges))((()=>{const f=g=>{if(g.tag==="Leaf")return M;if(g.tag==="Node")return $t("Node",g._1,g._2,g._3,w(g._4._1*4,g._4._2),f(g._5),f(g._6));c()};return f($r(O(g=>w(g.id,g.size))(e.nodes)))})()))),u=t.compactPostRouting?zl()({nodes:i,edges:e.edges,paths:o,ports:r}):{nodes:i,edges:o},s=u.edges,a=At(f=>g=>({...g,jumps:kh(f)(g)(s)}))(s);return{nodes:u.nodes,edges:a,boundingBox:V0(u.nodes),metrics:bd(u.nodes)(a)(0)}},Y0=t=>e=>n=>{const r=$r(O(o=>w(o.id,o.size))(e.nodes)),i={...n,placements:Zh({nodeGap:t.nodeGap,layerGap:t.layerGap})(e.constraints)(n.ordered)(r)($r(O(o=>w(o.id,o.ports))(e.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Da(n.ordered)(n.withDummies.edges)((()=>{const o=u=>{if(u.tag==="Leaf")return M;if(u.tag==="Node")return $t("Node",u._1,u._2,u._3,w(u._4._1*4,u._4._2),o(u._5),o(u._6));c()};return o(r)})()))};return{pipeline:i,result:U0(t)(e)(i)}},X0=t=>e=>n=>Y0(t)(e)({...n,ordered:f0({iterations:t.iterations,constraints:e.constraints,modelOrder:$r(At(r=>i=>w(i.id,r))(e.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),K0=t=>e=>n=>X0(t)(e)({...n,withDummies:x0(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),j0=t=>e=>{const n=O(i=>i.id)(e.nodes),r=J0(t.cycleBreaker)(n)(e.constraints)(e.edges);return K0(t)(e)({acyclic:r,layered:M0(t.layerer)(e.constraints)(r.edges)(n),withDummies:H0,ordered:[],placements:[]})},Z0=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},tp=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},oc=Vt(C)(Dt),ep=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},np=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},rp=J(t=>e=>K(C)(e)()(t))(M),ip=J(t=>e=>K(C)(e)()(t))(M),op=dr.traverse(Ui),du=Vt(C)(Dt),up=t=>e=>n=>{const r=ge(i=>i.id===n)(t.graph.edges);if(r.tag==="Just")return L("Just",r._1);if(r.tag==="Nothing")return Z0(n)(e);c()},sp=t=>e=>n=>({x:n.position._1*t,y:n.position._2*t,w:n.size._1*t,h:n.size._2*t,label:(()=>{const r=tp(n.node)(e);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return n.node;c()})()}),ap=t=>({id:t,size:w(1,1),ports:[],label:L("Just",t)}),cp=t=>e=>n=>w(n.node,sp(t)(e)(n)),fp=t=>oc(xt(e=>L("Just",w(e.edge,{id:e.edge,from:{node:e.from,port:T},to:{node:e.to,port:T}})))(St(t.scenes)(e=>e.tag==="DataFlow"?xt(n=>n.kind.tag==="SendToken"?L("Just",n.kind._1):T)(e._1.events):[]))),uc=t=>{const e=y_(t),n=ct(i=>ep(i.id)(e.nodes),t.graph.nodes),r=ct(i=>np(i.id)(e.edges),t.graph.edges);return{nodes:[...n,...O(ap)(bt(Ge.foldr,tn(C.compare,e.nodes,rp(O(i=>i.id)(n)))))],edges:[...r,...xt(up(t)(fp(t)))(bt(Ge.foldr,tn(C.compare,e.edges,ip(O(i=>i.id)(r)))))],constraints:t.graph.constraints}},gp=t=>{const e=op(n=>{const r=hd(pd)((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;c()})());return()=>{const i=r();return w(n.id,i)}})(uc(t).nodes);return()=>{const n=e();return du(n)}},_p=t=>e=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),e.segments);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[{x:n._1.head.start._1*t,y:n._1.head.start._2*t},...O(r=>({x:r.end._1*t,y:r.end._2*t}))([n._1.head,...n._1.tail])];c()},dp=t=>e=>w(e.edge,_p(t)(e)),lp=t=>e=>n=>({nodes:du(O(cp(ot(4)*t)(e))(n.nodes)),edges:oc(O(dp(t))(n.edges)),chipExtras:M}),hp=ot(4)*8,pp=t=>e=>{const n=vd(hp)(t)(Td(xd)(uc(e)));return lp(8)(du(O(r=>w(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;c()})()))(n.nodes)))(j0(W0)(n).result)},sc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},mp=t=>e=>n=>{const r=t<.05?t:.05,i=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return i((()=>{const a=sc(s._3)(n),f=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};c()})(),g=f.vx+(180*(s._4.x-f.x)-22*f.vx)*r,d=f.vy+(180*(s._4.y-f.y)-22*f.vy)*r;return K(C)(s._3)({x:f.x+g*r,y:f.y+d*r,vx:g,vy:d})(i(u,s._5))})(),s._6);c()},o=i(M,e);return{springs:o,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const f=u(s,a._5),g=sc(a._3)(o);if(g.tag==="Just")return K(C)(a._3)({...a._4,x:g._1.x,y:g._1.y})(f);if(g.tag==="Nothing")return K(C)(a._3)(a._4)(f);c()})(),a._6);c()};return u(M,e)})()}};(function(){var t={},e="Pure",n="Throw",r="Catch",i="Sync",o="Async",u="Bind",s="Bracket",a="Fork",f="Sequential",g="Map",d="Apply",l="Alt",_="Cons",h="Resume",p="Release",m="Finalizer",N="Finalized",y="Forked";function x(A,H,Y,W){this.tag=A,this._1=H,this._2=Y,this._3=W}function v(A){var H=function(Y,W,q){return new x(A,Y,W,q)};return H.tag=A,H}function b(A){return new x(e,void 0)}function E(A){try{A()}catch(H){setTimeout(function(){throw H},0)}}function k(A,H,Y){try{return H(Y())}catch(W){return A(W)}}function F(A,H,Y){try{return H(Y)()}catch(W){return Y(A(W))(),b}}var U=(function(){var A=1024,H=0,Y=0,W=new Array(A),q=!1;function B(){var j;for(q=!0;H!==0;)H--,j=W[Y],W[Y]=void 0,Y=(Y+1)%A,j();q=!1}return{isDraining:function(){return q},enqueue:function(j){var X;H===A&&(X=q,B(),q=X),W[(Y+H)%A]=j,H++,q||B()}}})();function tt(A){var H={},Y=0,W=0;return{register:function(q){var B=Y++;q.onComplete({rethrow:!0,handler:function(j){return function(){W--,delete H[B]}}})(),H[B]=q,W++},isEmpty:function(){return W===0},killAll:function(q,B){return function(){if(W===0)return B();var j=0,X={};function _t(ft){X[ft]=H[ft].kill(q,function(ht){return function(){delete X[ft],j--,A.isLeft(ht)&&A.fromLeft(ht)&&setTimeout(function(){throw A.fromLeft(ht)},0),j===0&&B()}})()}for(var pt in H)H.hasOwnProperty(pt)&&(j++,_t(pt));return H={},Y=0,W=0,function(ft){return new x(i,function(){for(var ht in X)X.hasOwnProperty(ht)&&X[ht]()})}}}}}var Q=0,S=1,Z=2,V=3,R=4,$=5,I=6;function G(A,H,Y){var W=0,q=Q,B=Y,j=null,X=null,_t=null,pt=null,ft=null,ht=0,Lt=0,Pt=null,lt=!0;function Rt(rt){for(var at,Nt,yt;;)switch(at=null,Nt=null,yt=null,q){case Z:q=S;try{B=_t(B),pt===null?_t=null:(_t=pt._1,pt=pt._2)}catch(Ot){q=$,j=A.left(Ot),B=null}break;case V:A.isLeft(B)?(q=$,j=B,B=null):_t===null?q=$:(q=Z,B=A.fromRight(B));break;case S:switch(B.tag){case u:_t&&(pt=new x(_,_t,pt)),_t=B._2,q=S,B=B._1;break;case e:_t===null?(q=$,B=A.right(B._1)):(q=Z,B=B._1);break;case i:q=V,B=k(A.left,A.right,B._1);break;case o:q=R,B=F(A.left,B._1,function(Ot){return function(){W===rt&&(W++,U.enqueue(function(){W===rt+1&&(q=V,B=Ot,Rt(W))}))}});return;case n:q=$,j=A.left(B._1),B=null;break;case r:_t===null?ft=new x(_,B,ft,X):ft=new x(_,B,new x(_,new x(h,_t,pt),ft,X),X),_t=null,pt=null,q=S,B=B._1;break;case s:ht++,_t===null?ft=new x(_,B,ft,X):ft=new x(_,B,new x(_,new x(h,_t,pt),ft,X),X),_t=null,pt=null,q=S,B=B._1;break;case a:q=V,at=G(A,H,B._2),H&&H.register(at),B._1&&at.run(),B=A.right(at);break;case f:q=S,B=P(A,H,B._1);break}break;case $:if(_t=null,pt=null,ft===null)q=I,B=X||j||B;else switch(at=ft._3,yt=ft._1,ft=ft._2,yt.tag){case r:X&&X!==at&&ht===0?q=$:j&&(q=S,B=yt._2(A.fromLeft(j)),j=null);break;case h:X&&X!==at&&ht===0||j?q=$:(_t=yt._1,pt=yt._2,q=Z,B=A.fromRight(B));break;case s:ht--,j===null&&(Nt=A.fromRight(B),ft=new x(_,new x(p,yt._2,Nt),ft,at),(X===at||ht>0)&&(q=S,B=yt._3(Nt)));break;case p:ft=new x(_,new x(N,B,j),ft,X),q=S,X&&X!==at&&ht===0?B=yt._1.killed(A.fromLeft(X))(yt._2):j?B=yt._1.failed(A.fromLeft(j))(yt._2):B=yt._1.completed(A.fromRight(B))(yt._2),j=null,ht++;break;case m:ht++,ft=new x(_,new x(N,B,j),ft,X),q=S,B=yt._1;break;case N:ht--,q=$,B=yt._1,j=yt._2;break}break;case I:for(var Ct in Pt)Pt.hasOwnProperty(Ct)&&(lt=lt&&Pt[Ct].rethrow,E(Pt[Ct].handler(B)));Pt=null,X&&j?setTimeout(function(){throw A.fromLeft(j)},0):A.isLeft(B)&<&&setTimeout(function(){if(lt)throw A.fromLeft(B)},0);return;case Q:q=S;break;case R:return}}function mt(rt){return function(){if(q===I)return lt=lt&&rt.rethrow,rt.handler(B)(),function(){};var at=Lt++;return Pt=Pt||{},Pt[at]=rt,function(){Pt!==null&&delete Pt[at]}}}function gt(rt,at){return function(){if(q===I)return at(A.right(void 0))(),function(){};var Nt=mt({rethrow:!1,handler:function(){return at(A.right(void 0))}})();switch(q){case Q:X=A.left(rt),q=I,B=X,Rt(W);break;case R:X===null&&(X=A.left(rt)),ht===0&&(q===R&&(ft=new x(_,new x(m,B(rt)),ft,X)),q=$,B=null,j=null,Rt(++W));break;default:X===null&&(X=A.left(rt)),ht===0&&(q=$,B=null,j=null)}return Nt}}function it(rt){return function(){var at=mt({rethrow:!1,handler:rt})();return q===Q&&Rt(W),at}}return{kill:gt,join:it,onComplete:mt,isSuspended:function(){return q===Q},run:function(){q===Q&&(U.isDraining()?Rt(W):U.enqueue(function(){Rt(W)}))}}}function D(A,H,Y,W){var q=0,B={},j=0,X={},_t=new Error("[ParAff] Early exit"),pt=null,ft=t;function ht(mt,gt,it){var rt=gt,at=null,Nt=null,yt=0,Ct={},Ot,re;t:for(;;)switch(Ot=null,rt.tag){case y:if(rt._3===t&&(Ot=B[rt._1],Ct[yt++]=Ot.kill(mt,function(je){return function(){yt--,yt===0&&it(je)()}})),at===null)break t;rt=at._2,Nt===null?at=null:(at=Nt._1,Nt=Nt._2);break;case g:rt=rt._2;break;case d:case l:at&&(Nt=new x(_,at,Nt)),at=rt,rt=rt._1;break}if(yt===0)it(A.right(void 0))();else for(re=0,Ot=yt;re<Ot;re++)Ct[re]=Ct[re]();return Ct}function Lt(mt,gt,it){var rt,at,Nt,yt,Ct,Ot;for(A.isLeft(mt)?(rt=mt,at=null):(at=mt,rt=null);;){if(Nt=null,yt=null,Ct=null,Ot=null,pt!==null)return;if(gt===null){W(rt||at)();return}if(gt._3!==t)return;switch(gt.tag){case g:rt===null?(gt._3=A.right(gt._1(A.fromRight(at))),at=gt._3):gt._3=rt;break;case d:if(Nt=gt._1._3,yt=gt._2._3,rt){if(gt._3=rt,Ct=!0,Ot=j++,X[Ot]=ht(_t,rt===Nt?gt._2:gt._1,function(){return function(){delete X[Ot],Ct?Ct=!1:it===null?Lt(rt,null,null):Lt(rt,it._1,it._2)}}),Ct){Ct=!1;return}}else{if(Nt===t||yt===t)return;at=A.right(A.fromRight(Nt)(A.fromRight(yt))),gt._3=at}break;case l:if(Nt=gt._1._3,yt=gt._2._3,Nt===t&&A.isLeft(yt)||yt===t&&A.isLeft(Nt))return;if(Nt!==t&&A.isLeft(Nt)&&yt!==t&&A.isLeft(yt))rt=at===Nt?yt:Nt,at=null,gt._3=rt;else if(gt._3=at,Ct=!0,Ot=j++,X[Ot]=ht(_t,at===Nt?gt._2:gt._1,function(){return function(){delete X[Ot],Ct?Ct=!1:it===null?Lt(at,null,null):Lt(at,it._1,it._2)}}),Ct){Ct=!1;return}break}it===null?gt=null:(gt=it._1,it=it._2)}}function Pt(mt){return function(gt){return function(){delete B[mt._1],mt._3=gt,Lt(gt,mt._2._1,mt._2._2)}}}function lt(){var mt=S,gt=Y,it=null,rt=null,at,Nt;t:for(;;)switch(at=null,Nt=null,mt){case S:switch(gt.tag){case g:it&&(rt=new x(_,it,rt)),it=new x(g,gt._1,t,t),gt=gt._2;break;case d:it&&(rt=new x(_,it,rt)),it=new x(d,t,gt._2,t),gt=gt._1;break;case l:it&&(rt=new x(_,it,rt)),it=new x(l,t,gt._2,t),gt=gt._1;break;default:Nt=q++,mt=$,at=gt,gt=new x(y,Nt,new x(_,it,rt),t),at=G(A,H,at),at.onComplete({rethrow:!1,handler:Pt(gt)})(),B[Nt]=at,H&&H.register(at)}break;case $:if(it===null)break t;it._1===t?(it._1=gt,mt=S,gt=it._2,it._2=t):(it._2=gt,gt=it,rt===null?it=null:(it=rt._1,rt=rt._2))}for(ft=gt,Nt=0;Nt<q;Nt++)B[Nt].run()}function Rt(mt,gt){pt=A.left(mt);var it;for(var rt in X)if(X.hasOwnProperty(rt)){it=X[rt];for(rt in it)it.hasOwnProperty(rt)&&it[rt]()}X=null;var at=ht(mt,ft,gt);return function(Nt){return new x(o,function(yt){return function(){for(var Ct in at)at.hasOwnProperty(Ct)&&at[Ct]();return b}})}}return lt(),function(mt){return new x(o,function(gt){return function(){return Rt(mt,gt)}})}}function P(A,H,Y){return new x(o,function(W){return function(){return D(A,H,Y,W)}})}return x.EMPTY=t,x.Pure=v(e),x.Throw=v(n),x.Catch=v(r),x.Sync=v(i),x.Async=v(o),x.Bind=v(u),x.Bracket=v(s),x.Fork=v(a),x.Seq=v(f),x.ParMap=v(g),x.ParApply=v(d),x.ParAlt=v(l),x.Fiber=G,x.Supervisor=tt,x.Scheduler=U,x.nonCanceler=b,x})();let lu=null;function Np(){return lu||(typeof document>"u"?null:(lu=document.createElement("canvas").getContext("2d"),lu))}const ac=new Map,cc=t=>e=>n=>r=>{const i=`${n} ${e}px ${t}|${r}`,o=ac.get(i);if(o!==void 0)return o;const u=Np();if(!u)return r.length*e*.62;u.font=`${n} ${e}px ${t}`;const s=u.measureText(r).width;return ac.set(i,s),s},yp=t=>()=>t.clip("evenodd"),Jp=t=>e=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(e.tile,.001))),r=Math.max(2,Math.round(e.tile*n)),i=document.createElement("canvas");i.width=r,i.height=r;const o=i.getContext("2d");o.scale(n,n),o.fillStyle=e.bgCss,o.fillRect(0,0,e.tile,e.tile),o.fillStyle=e.dotCss,o.beginPath(),o.arc(e.tile/2,e.tile/2,e.dotR,0,2*Math.PI),o.fill();const u=t.createPattern(i,"repeat");u&&typeof u.setTransform=="function"&&u.setTransform(new DOMMatrix().scaleSelf(1/n,1/n)),t.save(),t.fillStyle=u,t.fillRect(e.vx,e.vy,e.vw,e.vh),t.restore()},xp=t=>e=>n=>r=>i=>o=>()=>{if(typeof t.roundRect=="function")t.roundRect(e,n,r,i,o);else{const u=Math.min(o,r/2,i/2);t.moveTo(e+u,n),t.lineTo(e+r-u,n),t.quadraticCurveTo(e+r,n,e+r,n+u),t.lineTo(e+r,n+i-u),t.quadraticCurveTo(e+r,n+i,e+r-u,n+i),t.lineTo(e+u,n+i),t.quadraticCurveTo(e,n+i,e,n+i-u),t.lineTo(e,n+u),t.quadraticCurveTo(e,n,e+u,n),t.closePath()}},Tp=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},hu=t=>e=>n=>{const r=e.stroke;return()=>{const i=r.value,o=Lg(t)(n);if(i!==n)return o(),e.stroke.value=n}},vp=t=>e=>n=>{const r=e.font;return()=>{const i=r.value,o=Ig(t)(n);if(i!==n)return o(),e.font.value=n}},zr=t=>e=>n=>{const r=e.fill;return()=>{const i=r.value,o=wg(t)(n);if(i!==n)return o(),e.fill.value=n}},Ci=t=>e=>{const n=e.length,r=o=>{if(o>=n)return()=>{};const u=o>=0&&o<e.length?e[o]:0;if(u===1){const s=Cg(t)((()=>{const f=o+1|0;return f>=0&&f<e.length?e[f]:0})())((()=>{const f=o+2|0;return f>=0&&f<e.length?e[f]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===2){const s=Gg(t)((()=>{const f=o+1|0;return f>=0&&f<e.length?e[f]:0})())((()=>{const f=o+2|0;return f>=0&&f<e.length?e[f]:0})()),a=r(o+3|0);return()=>(s(),a())}if(u===3){const s=Fg(t)({cpx:(()=>{const f=o+1|0;return f>=0&&f<e.length?e[f]:0})(),cpy:(()=>{const f=o+2|0;return f>=0&&f<e.length?e[f]:0})(),x:(()=>{const f=o+3|0;return f>=0&&f<e.length?e[f]:0})(),y:(()=>{const f=o+4|0;return f>=0&&f<e.length?e[f]:0})()}),a=r(o+5|0);return()=>(s(),a())}if(u===4){const s=Bg(t)({cp1x:(()=>{const f=o+1|0;return f>=0&&f<e.length?e[f]:0})(),cp1y:(()=>{const f=o+2|0;return f>=0&&f<e.length?e[f]:0})(),cp2x:(()=>{const f=o+3|0;return f>=0&&f<e.length?e[f]:0})(),cp2y:(()=>{const f=o+4|0;return f>=0&&f<e.length?e[f]:0})(),x:(()=>{const f=o+5|0;return f>=0&&f<e.length?e[f]:0})(),y:(()=>{const f=o+6|0;return f>=0&&f<e.length?e[f]:0})()}),a=r(o+7|0);return()=>(s(),a())}if(u===5){const s=Sg(t),a=r(o+1|0);return()=>(s(),a())}return()=>{}},i=os(t);return()=>(i(),r(0)())},wp=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),Lp=t=>e=>{const n=Pg(t)({x:0,y:0,width:e.width,height:e.height});return()=>{n();const r=wp();return{ctx:t,surface:e,styleCache:r,maskDepth:{value:0}}}},bp={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},Ep=t=>fe(t.weight)+" "+Bu(t.size)+"px Ilisarniq, ui-sans-serif, system-ui, sans-serif",Ye=t=>{const e=Bu(ot(t.a)/255);return t.a>=255?"rgb("+fe(t.r)+","+fe(t.g)+","+fe(t.b)+")":"rgba("+fe(t.r)+","+fe(t.g)+","+fe(t.b)+","+e+")"},kp=t=>e=>n=>r=>{const i=zr(t)(n)(Ye(r));return()=>(i(),Qg(t)({x:0,y:0,width:e.width,height:e.height})())},Gp=t=>e=>n=>{const r=e.font;return()=>(r.value="",e.fill.value="",e.stroke.value="",Jp(t)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:Ye(n.bgColor),dotCss:Ye(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},Cp=t=>e=>n=>r=>{const i=zr(t)(e)(Ye(r));return()=>(i(),Ci(t)(n)(),ao(t)())},Sp=t=>e=>n=>r=>i=>{const o=zr(t)(e)(Ye(r));return()=>(o(),hu(t)(e)(Ye(i.color))(),io(t)(i.width)(),ei(t)((()=>{if(i.lineJoin==="RoundJoin")return ti;if(i.lineJoin==="BevelJoin")return lo;if(i.lineJoin==="MiterJoin")return ho;c()})())(),yo(t)((()=>{if(i.lineCap==="ButtCap")return No;if(i.lineCap==="RoundCap")return po;if(i.lineCap==="SquareCap")return mo;c()})())(),Ci(t)(n)(),ao(t)(),so(t)())},Qp=t=>e=>n=>r=>i=>o=>{const u=os(t);return()=>{if(u(),xp(t)(n.x)(n.y)(n.w)(n.h)(r)(),i.tag==="Just"?(zr(t)(e)(Ye(i._1.color))(),ao(t)()):i.tag==="Nothing"||c(),o.tag==="Just")return hu(t)(e)(Ye(o._1.color))(),io(t)(o._1.width)(),ei(t)((()=>{if(o._1.lineJoin==="RoundJoin")return ti;if(o._1.lineJoin==="BevelJoin")return lo;if(o._1.lineJoin==="MiterJoin")return ho;c()})())(),yo(t)((()=>{if(o._1.lineCap==="ButtCap")return No;if(o._1.lineCap==="RoundCap")return po;if(o._1.lineCap==="SquareCap")return mo;c()})())(),so(t)();o.tag!=="Nothing"&&c()}},Pp=t=>e=>n=>r=>{const i=hu(t)(e)(Ye(r.color));return()=>(i(),io(t)(r.width)(),ei(t)((()=>{if(r.lineJoin==="RoundJoin")return ti;if(r.lineJoin==="BevelJoin")return lo;if(r.lineJoin==="MiterJoin")return ho;c()})())(),yo(t)((()=>{if(r.lineCap==="ButtCap")return No;if(r.lineCap==="RoundCap")return po;if(r.lineCap==="SquareCap")return mo;c()})())(),Ci(t)(n)(),so(t)())},Dp=t=>e=>n=>{const r=zr(t)(e)(Ye(n.color));return()=>(r(),vp(t)(e)(Ep(n.font))(),Xg(t)((()=>{if(n.align==="AlignLeft")return qg;if(n.align==="AlignCenter")return Wg;if(n.align==="AlignRight")return Hg;c()})())(),Yg(t)((()=>{if(n.baseline==="BaselineTop")return Mg;if(n.baseline==="BaselineMiddle")return $g;if(n.baseline==="BaselineAlphabetic")return zg;if(n.baseline==="BaselineBottom")return Og;c()})())(),Rg(t)(n.content)(n.x)(n.y)())},fc={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>bp},Ap={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>fc},Ip=t=>e=>n=>{const r=Tp(e.width/n.vw)(e.height/n.vh),i=us(t)({translateX:(e.width-n.vw*r)/2-n.vx*r,translateY:(e.height-n.vh*r)/2-n.vy*r});return()=>(i(),co(t)({scaleX:r,scaleY:r})(),ei(t)(ti)())},Rp={pure:t=>e=>()=>t,Apply0:()=>fc},Fp={Applicative0:()=>Rp,Bind1:()=>Ap},gc={fillPath:t=>e=>n=>{const r=Cp(n.ctx)(n.styleCache)(t)(e.color),i=n.maskDepth;return()=>{if(i.value===0)return r()}},strokePath:t=>e=>n=>{const r=Pp(n.ctx)(n.styleCache)(t)(e),i=n.maskDepth;return()=>{if(i.value===0)return r()}},fillStrokePath:t=>e=>n=>r=>{const i=Sp(r.ctx)(r.styleCache)(t)(e.color)(n),o=r.maskDepth;return()=>{if(o.value===0)return i()}},drawRoundedRect:t=>e=>n=>r=>i=>{const o=Qp(i.ctx)(i.styleCache)(t)(e)(n)(r),u=i.maskDepth;return()=>{if(u.value===0)return o()}},drawText:t=>e=>{const n=Dp(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},pushTransform:t=>e=>{const n=yr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",us(e.ctx)({translateX:t.tx,translateY:t.ty})(),co(e.ctx)({scaleX:t.sx,scaleY:t.sy})()}},popTransform:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushClip:t=>e=>n=>{const r=yr(n.ctx),i=n.maskDepth;return()=>{if(i.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",Ci(n.ctx)(t)(),e==="NonZero")return kg(n.ctx)();if(e==="EvenOdd")return yp(n.ctx)();c()}}},popClip:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushBlend:t=>e=>{const n=yr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0){if(n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",t==="Normal")return as(e.ctx)(Vg)();if(t==="Difference")return as(e.ctx)(Ug)();c()}}},popBlend:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushAlpha:t=>e=>{const n=yr(e.ctx),r=e.maskDepth;return()=>{if(r.value===0)return n(),e.styleCache.font.value="",e.styleCache.fill.value="",e.styleCache.stroke.value="",Eg(e.ctx)(t)()}},popAlpha:t=>{const e=Jr(t.ctx),n=t.maskDepth;return()=>{if(n.value===0)return e(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value=""}},pushLayer:t=>e=>{if(t==="LayerNodeMask"){const n=e.maskDepth;return()=>{const r=n.value;n.value=r+1|0}}return()=>{}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;if(n>0)return t.maskDepth.value=r}},setViewport:t=>e=>{const n=Ip(e.ctx)(e.surface)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:t=>e=>{const n=kp(e.ctx)(e.surface)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:t=>e=>{const n=Gp(e.ctx)(e.styleCache)(t),r=e.maskDepth;return()=>{if(r.value===0)return n()}},measureText:t=>e=>n=>{const r=cc(t.family)(t.size)(t.weight)(kr(e));return()=>r},Monad0:()=>Fp};function Bp(t,e){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function Mp(t){const e=t.length,n=new Array(e);for(let r=0;r<e;r++){const i=t[r],o=t[(r+1)%e];n[r]={a:i,b:o,len:Bp(i,o)}}return n}function $p(t,e,n){let r=0;for(let i=0;i<t.length;i++){const o=t[i],u=r,s=u+o.len;if(n<=s){const a=o.len>1e-6?(n-u)/o.len:0;return{x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a}}r=s}return e.length>0?e[e.length-1]:{x:0,y:0}}function _c(t,e){if(e.length===0)return[];const n=Mp(e);let r=0;for(let o=0;o<n.length;o++)r+=n[o].len;const i=new Array(t);for(let o=0;o<t;o++)i[o]=$p(n,e,o*r/t);return i}function zp(t,e){const n=e.length;if(n===0)return e;const r=(t%n+n)%n|0,i=new Array(n);for(let o=0;o<n;o++)i[o]=e[(o+r)%n];return i}function Op(t,e){const n=e.length;if(n===0)return e;let r=0,i=1/0;for(let o=0;o<n;o++){let u=0;for(let s=0;s<n;s++){const a=t[s]||{x:0,y:0},f=e[(s+o)%n]||{x:0,y:0},g=a.x-f.x,d=a.y-f.y;u+=g*g+d*d}u<i&&(i=u,r=o)}return zp(r,e)}const dc=t=>e=>n=>{const r=_c(t,e),i=_c(t,n),o=Op(r,i);return{from:r,to:o}};function lc(t){const e=t.length;if(e===0)return{x:0,y:0};let n=0,r=0;for(let i=0;i<e;i++)n+=t[i].x,r+=t[i].y;return{x:n/e,y:r/e}}function qp(t,e){const n=e.x-t.x,r=e.y-t.y,i=Math.sqrt(n*n+r*r);return i<=1e-4?{x:1,y:0}:{x:n/i,y:r/i}}function Hp(t,e){const n=e.length;if(n===0)return e;const r=new Array(n);for(let i=0;i<n;i++){const o=e[((i-1)%n+n)%n],u=e[((i+1)%n+n)%n],s=e[i];r[i]={x:s.x+((o.x+u.x)/2-s.x)*t,y:s.y+((o.y+u.y)/2-s.y)*t}}return r}function Wp(t){return t<0?0:t>1?1:t}const hc=t=>e=>n=>r=>{const i=e.length;if(i===0)return[];const o=lc(e),u=lc(n),s=qp(o,u),a=new Array(i);let f=1/0,g=-1/0;for(let _=0;_<i;_++){const h=e[_],p=(h.x-o.x)*s.x+(h.y-o.y)*s.y;a[_]=p,p<f&&(f=p),p>g&&(g=p)}const d=g-f;let l=new Array(i);for(let _=0;_<i;_++){const h=e[_],p=n[_];if(p===void 0){l[_]=h;continue}const m=d<=1e-4?0:r.maxDelay*(1-(a[_]-f)/d),N=Math.max(1e-4,1-m),y=Wp((t-m)/N),x=y*y*(3-2*y);l[_]={x:h.x+(p.x-h.x)*x,y:h.y+(p.y-h.y)*x}}for(let _=0;_<r.smoothPasses;_++)l=Hp(.5,l);return l},Vp=t=>t,pc=t=>t,Si=t=>t,mc=t=>t,Up=t=>t,Nc=t=>t,yc=t=>t,Jc=yc("BaselineTop"),Or=yc("BaselineMiddle"),Qi=Nc("AlignLeft"),pu=Nc("AlignCenter"),Xe=Up("RoundJoin"),yn=mc("ButtCap"),xc=mc("RoundCap"),Yp=Si("LayerPolyOut"),Xp=Si("LayerPolyIn"),Kp=Si("LayerNodeMask"),jp=Si("LayerOverlay"),Tc=pc("NonZero"),Zp=pc("EvenOdd"),tm=Vp("Difference"),rr={r:255,g:255,b:255,a:255},un={r:26,g:26,b:26,a:255},mu=(t,e,n)=>({tag:t,_1:e,_2:n}),sn=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},qr=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},vc=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},Pn=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},Se=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},an=(()=>{const t=Re.unfoldr(Ln);return e=>t(Fe("IterNode",e,wn))})(),Nu=t=>e=>{const n=nt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},wc=Vt(C)(Dt),Lc=J(Wn)(0),Pi=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},bc=t=>{const e=t.Monad0().Bind1(),n=t.popTransform,r=t.popAlpha;return i=>o=>u=>s=>a=>e.bind(t.pushAlpha(i.fadeAlpha))(()=>e.bind(t.pushTransform({tx:o*(1-i.popScale),ty:u*(1-i.popScale),sx:i.popScale,sy:i.popScale}))(()=>e.bind(t.pushTransform({tx:0,ty:s.y*(1-i.flipY),sx:1,sy:i.flipY}))(()=>e.bind(a)(()=>e.bind(n)(()=>e.bind(n)(()=>r))))))},cn=t=>{const e=t.Apply0();return n=>J(r=>i=>e.apply(e.Functor0().map(o=>Fu)(r))(n(i)))(t.pure())},em=t=>({x:t.x,y:t.y,w:t.w,h:t.h}),nm=J(t=>e=>t+e.len)(0),rm=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(It(1,t.length,t))(n=>[2,n.x,n.y]),5];c()},im=t=>e=>{const n=t.y+t.h-6,r=t.y+6,i=t.x+14,o=t.x+t.w-14,u=J(qr)(0)(O(s=>i-10<s.x+s.w+12&&o+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?sn((s.x+s.w+12-(i-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(e));return{...t,x:t.x+u*.7071067811865476,y:t.y-u*.7071067811865476}},om={r:26,g:26,b:26,a:255},um={r:214,g:211,b:209,a:255},Ec=t=>e=>{const n=sn(e)(sn(t.w/2)(t.h/2));return[1,t.x+n,t.y,2,t.x+t.w-n,t.y,3,t.x+t.w,t.y,t.x+t.w,t.y+n,2,t.x+t.w,t.y+t.h-n,3,t.x+t.w,t.y+t.h,t.x+t.w-n,t.y+t.h,2,t.x+n,t.y+t.h,3,t.x,t.y+t.h,t.x,t.y+t.h-n,2,t.x,t.y+n,3,t.x,t.y,t.x+n,t.y,5]},sm=t=>e=>n=>J(r=>i=>{const o=vc(i)(e);if(o.tag==="Nothing")return r;if(o.tag==="Just"){const u=im(o._1)(r.obstacles);return{acc:K(C)(i)(u)(r.acc),obstacles:oe(r.obstacles)(u)}}c()})({acc:M,obstacles:n})(t).acc,am=t=>{const e=Bt(n=>T,n=>r=>L("Just",{head:n,tail:r}),t);if(e.tag==="Nothing")return[];if(e.tag==="Just")return[1,e._1.head.x,e._1.head.y,...St(e._1.tail)(n=>[2,n.x,n.y])];c()},Di=t=>{if(t.tag==="Hidden")return{alpha:0,scale:0};if(t.tag==="Visible")return{alpha:1,scale:1};if(t.tag==="PloppingIn")return{alpha:t._1>0?1:0,scale:xr(8)(.6)(Pn(0)(1)(t._1))};if(t.tag==="PloppingOut")return{alpha:t._1<1?1:0,scale:xr(8)(.6)(Pn(0)(1)(1-t._1))};c()},kc=t=>e=>St(an(t.nodes))(n=>{const r=Se(n._1)(e.nodes);return r.tag==="Just"&&Di(r._1).alpha>0?Ec(n._2)(7):[]}),cm=t=>e=>n=>[1,t.vx,t.vy,2,t.vx+t.vw,t.vy,2,t.vx+t.vw,t.vy+t.vh,2,t.vx,t.vy+t.vh,5,...kc(e)(n)],Ai=t=>e=>n=>O(r=>{const i=ot(r)/ot(n);return{x:t.x+(e.x-t.x)*i,y:t.y+(e.y-t.y)*i}})(Ht(0,n-1|0)),fm=t=>e=>{const n=i=>(i.x-e.x)*(i.x-e.x)+(i.y-e.y)*(i.y-e.y),r=J(i=>o=>n(o)<n(i)?o:i)({x:t.x,y:t.y})([{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x,y:t.y+t.h},{x:t.x+t.w,y:t.y+t.h}]);return O(i=>{const o=ot(i)/5;return{x:r.x+(e.x-r.x)*o,y:r.y+(e.y-r.y)*o}})([1,2,3,4])},Gc=t=>{const e=Po(`
|
|
6
|
+
`)(t);return e.length===0?[""]:e},yu=t=>e=>{const n=sn(t)(sn(e.w/2)(e.h/2));return{...e,x:e.x+n,y:e.y+n,w:e.w-2*n,h:e.h-2*n}},gm=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=cn(n),o=t.popTransform,u=t.popAlpha;return s=>a=>f=>{const g=Po(`
|
|
7
|
+
`)(a.label===""?s:a.label),d=g.length===0?[""]:g,l=a.y+a.h/2-ot(d.length)*13.2/2+6.6,_=Di(f),h=a.x+a.w/2,p=a.y+a.h/2,m=r.bind(t.pushAlpha(_.alpha))(()=>r.bind(t.pushTransform({tx:h*(1-_.scale),ty:p*(1-_.scale),sx:_.scale,sy:_.scale}))(()=>r.bind(t.drawRoundedRect({x:a.x,y:a.y,w:a.w,h:a.h})(7)(L("Just",{color:rr,flat:!1}))(L("Just",{color:un,width:1.25,lineJoin:Xe,lineCap:yn})))(()=>r.bind(i(N=>t.drawText({x:a.x+a.w/2,y:l+ot(N._1)*13.2,content:N._2,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},color:un,align:pu,baseline:Or}))(At(Bn)(d)))(()=>r.bind(o)(()=>u)))));return _.alpha>0?m:n.pure()}},Cc=t=>{const e=gm(t),n=t.Monad0().Applicative0(),r=cn(n);return i=>o=>r(u=>{const s=Se(u._1)(o.nodes);if(s.tag==="Just")return e(u._1)(u._2)(s._1);if(s.tag==="Nothing")return n.pure();c()})(an(i.nodes))},Ju=t=>e=>{const n=e.y-t.y,r=e.x-t.x;return qn(r*r+n*n)},_m=t=>ye(e=>n=>({a:e,b:n,len:Ju(e)(n)}),t,It(1,t.length,t)),dm=t=>e=>{const n=e.length-1|0,r=n>=0&&n<e.length?L("Just",e[n]):T,i=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];c()})(),o=0<e.length?L("Just",e[0]):T,u=(()=>{if(o.tag==="Just")return o._1;if(o.tag==="Nothing")return{x:0,y:0};c()})(),s=e.length;return s<3?e:[u,...St(Ht(1,s-2|0))(a=>{const f=a+1|0,g=f>=0&&f<e.length?L("Just",e[f]):T,d=a>=0&&a<e.length?L("Just",e[a]):T,l=a-1|0,_=l>=0&&l<e.length?L("Just",e[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&g.tag==="Just"){const h=d._1,p=Ju(h)(g._1),m=Ju(_._1)(h),N=sn(t)(p/2),y=sn(t)(m/2),x=p>0?N/p:0,v=h.x+(g._1.x-h.x)*x,b=h.y+(g._1.y-h.y)*x,E=m>0?y/m:0,k=h.x+(_._1.x-h.x)*E,F=h.y+(_._1.y-h.y)*E;return O(U=>{const tt=ot(U)/ot(10),Q=1-tt;return{x:Q*Q*k+2*Q*tt*h.x+tt*tt*v,y:Q*Q*F+2*Q*tt*h.y+tt*tt*b}})(Ht(0,10))}return[]}),...i]},lm=t=>{const e=t.Monad0(),n=e.Bind1(),r=e.Applicative0(),i=cn(r);return o=>u=>s=>a=>f=>g=>{const d=Do(g).length,l=ot(d+1|0),_=m=>{const N=(s*l-ot(m))/1.5,y=N<0?0:N>1?1:N;return y*y*(3-2*y)},h=(m=>{let N=m,y=!0,x;for(;y;){const v=N;if(v>=d){y=!1,x=v;continue}if(_(v)>=1){N=v+1|0;continue}y=!1,x=v}return x})(0),p=h>=d?[]:Tn(m=>_(m)>0)(Ht(h,d-1|0)).init;return n.bind((()=>{const m=t.drawText({x:a,y:f,content:ce(h)(g),font:o,color:u,align:Qi,baseline:Or});return h>0?m:r.pure()})())(()=>i(m=>n.bind(t.measureText(o)(ce(m)(g)))(N=>{const y=_(m);return t.drawText({x:a+N,y:f-(1-y)*10,content:ce(1)(vr(En(ce(m)(g)))(g)),font:o,color:{...u,a:vn(ju(y*ot(u.a)))},align:Qi,baseline:Or})}))(p))}},Ii=t=>e=>n=>r=>{const i=O(h=>ot(Nu(1)(Do(h).length)))(r),o=qr(1)(J(Wn)(0)(i)),u=qr(.05)(1-e-n),s=t<e?0:t>1-n?1:(t-e)/u,a=s*o,f=Nu(1)(r.length),g=(h=>p=>m=>{let N=h,y=p,x=m,v=!0,b;for(;v;){const E=N,k=y,F=Bt(U=>T,U=>tt=>L("Just",{head:U,tail:tt}),x);if(F.tag==="Nothing"){v=!1,b=Nu(0)(f-1|0);continue}if(F.tag==="Just"){if(k+F._1.head>=a){v=!1,b=E;continue}N=E+1|0,y=k+F._1.head,x=F._1.tail;continue}c()}return b})(0)(0)(i),d=J(Wn)(0)(g<1?[]:It(0,g,i)),l=d/o;if(g>=0&&g<i.length){const h=(d+i[g])/o;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(h<=l)return 1;const p=(s-l)/(h-l);return p<0?0:p>1?1:p})()}}const _=(d+1)/o;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(_<=l)return 1;const h=(s-l)/(_-l);return h<0?0:h>1?1:h})()}},hm=t=>{const e=t.Monad0();return n=>r=>i=>e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Ii(r)(0)(0)(i).line))(o=>{const u=o+28;return e.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},pm=t=>{const e=t.Monad0(),n=e.Bind1(),r=hm(t),i=e.Applicative0(),o=dr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>wc(xt(f=>f)(a)))(o(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const f=Se(a._2._1.node)(u.nodes);if(f.tag==="Just")return n.bind(r(f._1)(a._2._1.progress)(a._2._1.labels))(g=>i.pure(L("Just",w(a._1,g))));if(f.tag==="Nothing")return i.pure(T);c()}return i.pure(T)})(an(s.tokens)))},Sc=t=>e=>O(n=>{const r=6.283185307179586*ot(n)/ot(64);return{x:t.x+e*Zi(r),y:t.y+e*eo(r)}})(Ht(0,63)),xu=t=>e=>{const n=.5522847498*e;return[1,t.x+e,t.y,4,t.x+e,t.y+n,t.x+n,t.y+e,t.x,t.y+e,4,t.x-n,t.y+e,t.x-e,t.y+n,t.x-e,t.y,4,t.x-e,t.y-n,t.x-n,t.y-e,t.x,t.y-e,4,t.x+n,t.y-e,t.x+e,t.y-n,t.x+e,t.y,5]},mm=t=>{const e=t.Monad0().Bind1(),n=t.popAlpha;return r=>i=>o=>u=>s=>a=>f=>{const g={x:o.x+o.w/2,y:o.y+o.h/2},d=qr(.05)(1-a-f),l=s<a?0:s>1-f?1:(s-a)/d,_={x:u.x+u.w/2,y:u.y+u.h/2},h=(p,m)=>e.bind(t.pushAlpha(m))(()=>e.bind(t.fillStrokePath(xu(p)(6))({color:r,flat:!0})({color:i,width:1,lineJoin:Xe,lineCap:yn}))(()=>n));return l<.5?h(g,(()=>{const p=l*2;return 1-(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})()):h(_,(()=>{const p=(l-.5)*2;return(p<0?0:p>1?1:p)*(p<0?0:p>1?1:p)*(p<0?3:p>1?1:3-2*p)})())}},Nm={r:255,g:235,b:130,a:255},ym=t=>{const e=t.length;return e===0?{x:0,y:0}:{x:Lc(O(n=>n.x)(t))/ot(e),y:Lc(O(n=>n.y)(t))/ot(e)}},Qc=t=>e=>n=>{const r=xr(6)(.55)(Pn(0)(1)((1-t)/.06)),i=t>.94,o=i&&n>1e-4,u=xr(6)(.55)(Pn(0)(1)(t/.06)),s=t<.06,a=s&&e>1e-4,f=i&&n<=1e-4;return{popScale:a?u:o?r:1,flipY:s&&e<=1e-4?u:f?r:1,fadeAlpha:(()=>{if(a){const g=t/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}if(o){const g=(1-t)/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}return 1})()}},Jm=t=>{const e=t.Monad0().Bind1(),n=bc(t);return r=>i=>o=>u=>{const s=Qc(o)(0)(0),a={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},f=Ii(o)(0)(0)(u);return e.bind(t.measureText(a)(f.line))(g=>{const d={r:26,g:26,b:26,a:90},l=i.x+i.w/2,_=g+28,h=i.y-25.2-14,p=l-_/2,m=[1,l,h+25.2,2,l,i.y],N={x:l,y:h+12.6};return n(s)(l-_/2)(h+25.2)(N)(e.bind(t.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(L("Just",{color:um,flat:!0}))(T))(()=>e.bind(t.drawRoundedRect({x:p,y:h,w:_,h:25.2})(6)(L("Just",{color:Nm,flat:!0}))(L("Just",{color:d,width:1,lineJoin:Xe,lineCap:yn})))(()=>e.bind(t.strokePath(m)({color:d,width:1,lineJoin:Xe,lineCap:yn}))(()=>t.drawText({x:l,y:N.y,content:f.line,font:a,color:un,align:pu,baseline:Or})))))})}},Pc={r:0,g:0,b:0,a:0},xm=t=>e=>t.backgroundDots({viewport:{vx:e.x,vy:e.y,vw:e.w,vh:e.h},bgColor:Pc,dotColor:om,tile:1.6,dotRadius:.25}),Tm={r:214,g:211,b:209,a:255},Dc={r:255,g:255,b:255,a:255},Ac=t=>{const e=t.Monad0().Bind1();return n=>r=>n?e.bind(t.clearBackground(Pc))(()=>t.setViewport(r)):e.bind(t.setViewport(r))(()=>t.backgroundDots({viewport:r,bgColor:Dc,dotColor:Tm,tile:12,dotRadius:.7}))},vm=t=>{const e=t.Monad0(),n=e.Applicative0(),r=e.Bind1(),i=t.popClip,o=t.popTransform,u=t.popAlpha;return s=>a=>f=>{const g=Di(f),d={...a,y:a.y+5},l=d.x+d.w/2,_=d.y+d.h/2,h=r.bind(t.pushAlpha(g.alpha))(()=>r.bind(t.pushTransform({tx:l*(1-g.scale),ty:_*(1-g.scale),sx:g.scale,sy:g.scale}))(()=>r.bind(t.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(L("Just",{color:Dc,flat:!0}))(T))(()=>r.bind((()=>{const p=r.bind(t.pushClip(Ec(d)(7))(Tc))(()=>r.bind(xm(t)(d))(()=>i));return s?p:n.pure()})())(()=>r.bind(t.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(T)(L("Just",{color:un,width:1.25,lineJoin:Xe,lineCap:yn})))(()=>r.bind(o)(()=>u))))));return g.alpha>0?h:n.pure()}},Ic=t=>{const e=vm(t),n=t.Monad0().Applicative0(),r=cn(n);return i=>o=>u=>r(s=>{const a=Se(s._1)(u.nodes);if(a.tag==="Just")return e(i)(s._2)(a._1);if(a.tag==="Nothing")return n.pure();c()})(an(o.nodes))},wm=t=>{const e=t.Monad0().Applicative0();return n=>{const r=n.length-1|0,i=r<1?[]:It(0,r,n),o=i.length-1|0,u=o>=0&&o<i.length?L("Just",i[o]):T,s=n.length-1|0;if(s>=0&&s<n.length&&u.tag==="Just"){const a=n[s].y-u._1.y,f=n[s].x-u._1.x,g=qn(f*f+a*a),d=a/g,l=-d,_=f/g,h=n[s].x+_*.875,p=n[s].y+d*.875,m=p-d*8.75,N=h-_*8.75,y=[1,h,p,2,N+l*4.375,m+_*4.375,2,N-l*4.375,m-_*4.375,5];return g<=1e-4?e.pure():t.fillPath(y)({color:un,flat:!0})}return e.pure()}},Ri=t=>e=>n=>r=>i=>O(o=>{const u=n+(r-n)*(ot(o)/ot(i));return{x:t.x+e*Zi(u),y:t.y+e*eo(u)}})(Ht(0,i-1|0)),Rc=t=>e=>{const n=sn(t)(sn(e.w/2)(e.h/2));return[...Ai({x:e.x+n,y:e.y})({x:e.x+e.w-n,y:e.y})(6),...Ri({x:e.x+e.w-n,y:e.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...Ai({x:e.x+e.w,y:e.y+n})({x:e.x+e.w,y:e.y+e.h-n})(6),...Ri({x:e.x+e.w-n,y:e.y+e.h-n})(n)(0)(1.5707963267948966)(12),...Ai({x:e.x+e.w-n,y:e.y+e.h})({x:e.x+n,y:e.y+e.h})(6),...Ri({x:e.x+n,y:e.y+e.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...Ai({x:e.x,y:e.y+e.h-n})({x:e.x,y:e.y+n})(6),...Ri({x:e.x+n,y:e.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},Lm=t=>e=>n=>J(r=>i=>{const o=r.pos+i.len,u=n<o?(n-r.pos)/i.len:1,s={x:i.a.x+(i.b.x-i.a.x)*u,y:i.a.y+(i.b.y-i.a.y)*u},a=e>r.pos?(e-r.pos)/i.len:0,f={x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a},g=r.points.length-1|0,d=g>=0&&g<r.points.length?(()=>{const l=r.points[g].x-f.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[g].y-f.y;return _<0?-_<1e-4:_<1e-4})()})()?oe(r.points)(s):[...r.points,f,s]:[f,s];return i.len<=0||o<=e||r.pos>=n?{...r,pos:o}:{pos:o,points:d}})({pos:0,points:[]})(t).points,bm=t=>e=>n=>{const r=Bt(i=>T,i=>o=>L("Just",{head:i,tail:o}),t);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const i=_m(t),o=nm(i),u=Pn(0)(o)(e*o),s=Pn(0)(o)(n*o);return s<=u?[]:Lm(i)(u)(s)}c()},Em=t=>{const e=t.Monad0(),n=e.Applicative0(),r=wm(t);return i=>o=>u=>{const s=dm(8)(o);if(u.hi<=u.lo)return n.pure();const a=bm(s)(u.lo)(u.hi);return a.length===0?n.pure():e.Bind1().bind(t.strokePath(am(a))({color:un,width:.9375,lineJoin:Xe,lineCap:xc}))(()=>r(a))}},Fc=t=>{const e=Em(t),n=t.Monad0().Applicative0(),r=cn(n);return i=>o=>r(u=>{const s=Pi(u._1)(o.edges);if(s.tag==="Just")return e(u._1)(u._2)((()=>{if(s._1.tag==="Retracted")return{lo:0,hi:0};if(s._1.tag==="Extended")return{lo:0,hi:1};if(s._1.tag==="Extending")return{lo:0,hi:s._1._2};if(s._1.tag==="Retracting"){if(s._1._1==="FromSource")return{lo:s._1._2,hi:1};if(s._1._1==="FromTarget")return{lo:0,hi:1-s._1._2};if(s._1._1==="FromBoth")return{lo:s._1._2/2,hi:1-s._1._2/2}}c()})());if(s.tag==="Nothing")return n.pure();c()})(an(i.edges))},Bc=t=>e=>n=>r=>i=>o=>{const u={x:n.x+n.w/2,y:n.y+n.h/2},s={x:e.x+e.w/2,y:e.y+e.h/2},a=0<t.length?L("Just",t[0]):T,f=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return s;c()})(),g=t.length-1|0,d=g>=0&&g<t.length?L("Just",t[g]):T,l=(()=>{if(d.tag==="Just")return d._1;if(d.tag==="Nothing")return u;c()})(),_=dc(128)(Rc(5)(yu(2)(e)))(Sc(f)(6)),h=qr(.05)(1-i-o),p=r<i?0:r>1-o?1:(r-i)/h,m=f.x-s.x,N=2*(()=>{const V=f.y-s.y;return(m<0?-m:m)+(V<0?-V:V)})(),y=l.x-u.x,x=2*(()=>{const V=l.y-u.y;return(y<0?-y:y)+(V<0?-V:V)})(),v=N+xo(t)+x,b=v<=1e-4?1:1-x/v,E=v<=1e-4?0:N/v,k=b-E,F=dc(128)(Sc(l)(6))(Rc(5)(yu(2)(n))),U={maxDelay:.4,smoothPasses:2},tt=_s(t)(Pn(0)(1)(k<=1e-4?0:(p-E)/k)),Q=(()=>{if(tt.tag==="Just")return tt._1;if(tt.tag==="Nothing")return f;c()})(),S=(()=>{if(b>=1)return 0;const V=(p-b)/(1-b),R=V<0?0:V>1?1:V;return R*R*(3-2*R)})(),Z=(()=>{if(E<=1e-4)return 1;const V=p/E,R=V<0?0:V>1?1:V;return R*R*(3-2*R)})();return p<E?mu("PolyShape",hc(Z)(_.from)(_.to)(U)):p>=b?mu("PolyShape",hc(S)(F.from)(F.to)(U)):mu("CircleShape",Q,6)},km=t=>e=>n=>r=>i=>o=>u=>s=>a=>{const f=Bc(r)(i)(o)(u)(s)(a);if(f.tag==="CircleShape")return t.fillStrokePath(xu(f._1)(f._2))({color:e,flat:!0})({color:n,width:1,lineJoin:Xe,lineCap:yn});if(f.tag==="PolyShape")return f._1.length>=3?t.fillStrokePath(rm(f._1))({color:e,flat:!0})({color:n,width:1,lineJoin:Xe,lineCap:yn}):t.Monad0().Applicative0().pure();c()},Mc=t=>{const e=mm(t),n=t.Monad0().Applicative0(),r=cn(n);return i=>o=>u=>s=>r(a=>{if(a._2.tag==="Travelling"){const f=Se(a._2._1.target)(i.nodes),g=Se(a._2._1.source)(i.nodes);if(g.tag==="Just"&&f.tag==="Just"){const d=Pi(a._2._1.edge)(i.edges);if(d.tag==="Just")return km(t)(u)(s)((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return de(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);if(d.tag==="Nothing")return e(u)(s)(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);c()}return n.pure()}if(a._2.tag==="Filling"){const f=Se(a._2._1.node)(i.nodes);if(f.tag==="Just")return t.drawRoundedRect((()=>{const g=yu(2)(f._1);return{x:g.x,y:g.y,w:g.w,h:g.h}})())(5)(L("Just",{color:u,flat:!0}))(L("Just",{color:s,width:1,lineJoin:Xe,lineCap:yn}));if(f.tag==="Nothing")return n.pure();c()}return n.pure()})(an(o.tokens))},$c=t=>{const e=t.Monad0(),n=e.Bind1(),r=Mc(t),i=t.popClip,o=t.popBlend,u=t.popLayer,s=e.Applicative0(),a=cn(s);return f=>g=>n.bind(t.pushLayer(Xp))(()=>n.bind(t.pushBlend(tm))(()=>n.bind(t.pushClip(kc(f)(g))(Tc))(()=>n.bind(r(f)(g)(rr)(rr))(()=>n.bind(i)(()=>n.bind(o)(()=>n.bind(u)(()=>n.bind(t.pushLayer(Kp))(()=>n.bind(a(d=>{const l=Se(d._1)(g.nodes);return l.tag==="Just"&&Di(l._1).alpha>0?t.drawRoundedRect({x:d._2.x,y:d._2.y,w:d._2.w,h:d._2.h})(7)(L("Just",{color:rr,flat:!1}))(T):s.pure()})(an(f.nodes)))(()=>u)))))))))},zc=t=>{const e=t.Monad0().Bind1(),n=Mc(t),r=t.popClip,i=t.popLayer;return o=>u=>s=>e.bind(t.pushLayer(Yp))(()=>e.bind(t.pushClip(cm(o)(u)(s))(Zp))(()=>e.bind(n(u)(s)(un)(rr))(()=>e.bind(r)(()=>i))))},Oc=t=>e=>n=>r=>i=>o=>{const u=Bc(t)(e)(n)(r)(i)(o);if(u.tag==="PolyShape")return ym(u._1);if(u.tag==="CircleShape")return u._1;c()},Gm=t=>{const e=bc(t),n=t.Monad0(),r=n.Bind1(),i=cn(n.Applicative0()),o=lm(t);return u=>s=>a=>f=>g=>d=>l=>_=>{const h=Ii(f)(g)(d)(St(l)(Gc)),p=h.line,m=h.phaseInLabel/.45,N=m<0?0:m>1?1:m,y=_.w,x=_.y,v=_.x,b=v+14,E=_.h,k=x+E/2;return e(Qc(f)(g)(d))(v)(x+E)({x:v+y/2,y:k})(r.bind(i(F=>t.fillPath(xu(F)(1.5))({color:un,flat:!0}))(fm(_)(Oc(u)(s)(a)(f)(g)(d))))(()=>r.bind(t.drawRoundedRect({x:v,y:x,w:y,h:E})(3)(L("Just",{color:un,flat:!0}))(T))(()=>o({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(rr)(N)(b)(k)(p))))}},qc=t=>{const e=Gm(t),n=t.Monad0(),r=n.Applicative0(),i=Jm(t),o=n.Bind1(),u=cn(r),s=t.popLayer;return a=>f=>g=>o.bind(t.pushLayer(jp))(()=>o.bind(u(d=>{if(d._2.tag==="Travelling"){if(d._2._1.labels.length!==0){const l=Se(d._2._1.target)(a.nodes),_=Se(d._2._1.source)(a.nodes),h=Pi(d._2._1.edge)(a.edges),p=vc(d._1)(g);if(p.tag==="Just"&&h.tag==="Just"&&_.tag==="Just"&&l.tag==="Just")return e((()=>{if(d._2._1.direction==="Forward")return h._1;if(d._2._1.direction==="Backward")return de(h._1);c()})())(_._1)(l._1)(d._2._1.progress)(d._2._1.holdPre)(d._2._1.holdPost)(d._2._1.labels)(p._1)}return r.pure()}if(d._2.tag==="Filling"&&d._2._1.labels.length!==0){const l=Se(d._2._1.node)(a.nodes);if(l.tag==="Just")return i(a)(l._1)(d._2._1.progress)(d._2._1.labels);if(l.tag==="Nothing")return r.pure();c()}return r.pure()})(an(f.tokens)))(()=>s))},Cm=t=>{const e=t.Monad0();return n=>r=>i=>o=>u=>s=>a=>{const f=Oc(n)(r)(i)(o)(u)(s);return e.Bind1().bind(t.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Ii(o)(u)(s)(St(a)(Gc)).line))(g=>e.Applicative0().pure({x:f.x+14+g/2-g/2-14,y:f.y-6-8-6.6-6,w:g+28,h:25.2}))}},Sm=t=>{const e=t.Monad0(),n=e.Bind1(),r=Cm(t),i=e.Applicative0(),o=dr.traverse(i);return u=>s=>n.Apply0().Functor0().map(a=>wc(xt(f=>f)(a)))(o(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const f=Se(a._2._1.target)(u.nodes),g=Se(a._2._1.source)(u.nodes),d=Pi(a._2._1.edge)(u.edges);if(d.tag==="Just"&&g.tag==="Just"&&f.tag==="Just")return n.bind(r((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return de(d._1);c()})())(g._1)(f._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>i.pure(L("Just",w(a._1,l))))}return i.pure(T)})(an(s.tokens)))},Hc=t=>{const e=t.Monad0(),n=e.Bind1(),r=Sm(t),i=pm(t);return o=>u=>n.bind(r(o)(u))(s=>n.bind(i(o)(u))(a=>e.Applicative0().pure(sm((()=>{const f=g=>{if(g.tag==="Leaf")return M;if(g.tag==="Node")return $t("Node",g._1,g._2,g._3,void 0,f(g._5),f(g._6));c()};return vt(C.compare)(bt(Ge.foldr,f(s)))})())(s)([...O(em)((()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,Mt("Cons",g._4,f(g._6,d)));c()};return bt(Wt.foldr,f(o.nodes,qt))})()),...(()=>{const f=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return f(g._5,Mt("Cons",g._4,f(g._6,d)));c()};return bt(Wt.foldr,f(a,qt))})()]))))},Qm=t=>{const e=Hc(t),n=qc(t);return r=>i=>t.Monad0().Bind1().bind(e(r)(i))(o=>n(r)(i)(o))},Fi=t=>e=>n=>{const r=bs(e)(n.camera);return{vx:r.x-t.padding,vy:r.y-t.padding-40,vw:r.w+2*t.padding,vh:r.h+2*t.padding+40}},Wc=t=>{const e=t.Monad0(),n=e.Bind1();return r=>i=>{if(r==="")return e.Applicative0().pure();const o=i.vh/720,u=15*o,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600};return n.bind(t.measureText(s)(r))(a=>{const f=i.vy+12*o,g=u+6*o*2,d=a+11*o*2,l=i.vx+i.vw/2;return n.bind(t.drawRoundedRect({x:l-d/2,y:f,w:d,h:g})(g/2)(L("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(L("Just",{color:{r:0,g:0,b:0,a:255},width:1*o,lineJoin:Xe,lineCap:xc})))(()=>t.drawText({x:l,y:f+g/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:pu,baseline:Or}))})}},Pm=t=>{const e=t.Monad0().Bind1(),n=Ac(t),r=Fc(t),i=Ic(t),o=Cc(t),u=zc(t),s=$c(t),a=Qm(t),f=Wc(t);return g=>d=>l=>{const _=Fi(g)(d)(l);return e.bind(n(g.transparentBg)(_))(()=>e.bind(r(d)(l))(()=>e.bind(i(g.halftoneShadows)(d)(l))(()=>e.bind(o(d)(l))(()=>e.bind(u(_)(d)(l))(()=>e.bind(s(d)(l))(()=>e.bind(a(d)(l))(()=>e.bind(g.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:_.vx+6,y:_.vy+6,content:g.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:Qi,baseline:Jc}))(()=>f(l.frameTitle)(_)))))))))}},Dm=t=>{const e=t.Monad0().Bind1(),n=Ac(t),r=Fc(t),i=Ic(t),o=Cc(t),u=zc(t),s=$c(t),a=qc(t),f=Wc(t);return g=>d=>l=>_=>{const h=Fi(g)(d)(l);return e.bind(n(g.transparentBg)(h))(()=>e.bind(r(d)(l))(()=>e.bind(i(g.halftoneShadows)(d)(l))(()=>e.bind(o(d)(l))(()=>e.bind(u(h)(d)(l))(()=>e.bind(s(d)(l))(()=>e.bind(a(d)(l)(_))(()=>e.bind(g.watermark===""?t.Monad0().Applicative0().pure():t.drawText({x:h.vx+6,y:h.vy+6,content:g.watermark,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:9,weight:600},color:{r:180,g:180,b:180,a:255},align:Qi,baseline:Jc}))(()=>f(l.frameTitle)(h)))))))))}},Vc=t=>e=>n=>{const r=dt.compare(t)(n),i=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return t;c()})(),o=dt.compare(e)(i);if(o==="LT"||o==="EQ")return e;if(o==="GT")return i;c()},Am=Hc(gc),Im=Dm(gc),Rm=t=>{const e=t.vx+t.vw-4,n=t.vy+t.vh-4,r=t.vx+4,i=t.vy+4,o=u=>{if(u.tag==="Leaf")return M;if(u.tag==="Node")return $t("Node",u._1,u._2,u._3,{...u._4,x:Vc(r)(e-u._4.w)(u._4.x),y:Vc(i)(n-u._4.h)(u._4.y)},o(u._5),o(u._6));c()};return o},Fm=t=>e=>n=>r=>i=>o=>{const u={padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""},s=Lp(t)(e);return()=>{const a=s(),f=Am(n)(r)(a)(),g=mp(i)(Rm(Fi(u)(n)(r))(f))(o);return Im(u)(n)(r)(g.applied)(a)(),g.springs}},Jn=t=>"rgb("+fe(t.r)+","+fe(t.g)+","+fe(t.b)+")",Bi=Nr(pr("Fixed",mr(0)(20)(4))),Bm=t=>"translate("+Bi(t.tx)+","+Bi(t.ty)+") scale("+Bi(t.sx)+","+Bi(t.sy)+")",Jt=Nr(pr("Fixed",mr(0)(20)(2))),Tu=t=>{const e=[];let n=0;for(;n<t.length;){const r=n,i=r>=0&&r<t.length?L("Just",t[r]):T;if(i.tag==="Nothing"){n=t.length;continue}if(i.tag==="Just"){if(i._1===1){e.push("M"),e.push(Jt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===2){e.push("L"),e.push(Jt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),n=r+3|0;continue}if(i._1===3){e.push("Q"),e.push(Jt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),n=r+5|0;continue}if(i._1===4){e.push("C"),e.push(Jt((()=>{const o=r+1|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+2|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+3|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+4|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+5|0;return o>=0&&o<t.length?t[o]:0})())),e.push(Jt((()=>{const o=r+6|0;return o>=0&&o<t.length?t[o]:0})())),n=r+7|0;continue}if(i._1===5){e.push("Z"),n=r+1|0;continue}n=t.length;continue}c()}return si(" ")(e)},Mm={map:t=>e=>n=>{const r=e(n);return()=>{const i=r();return t(i)}}},vu=(()=>{const t=hn("&")("&"),e=hn("<")("<"),n=(()=>{const r=hn(">")(">"),i=(()=>{const o=hn('"')(""");return u=>o(r(u))})();return o=>i(e(o))})();return r=>n(t(r))})(),$m=t=>{if(t.style==="RunText")return"<tspan>"+vu(t.text)+"</tspan>";if(t.style==="RunCode")return`<tspan font-family="'Ioskeley Mono', ui-monospace, SFMono-Regular, Menlo, monospace" font-weight="400">`+vu(t.text)+"</tspan>";c()},Te=t=>e=>{const n=e.maskDepth;return()=>{n.value===0&&e.out.push(t)}},Uc={apply:t=>e=>n=>{const r=t(n),i=e(n);return()=>{const o=r(),u=i();return o(u)}},Functor0:()=>Mm},zm={bind:t=>e=>n=>{const r=t(n);return()=>{const i=r();return e(i)(n)()}},Apply0:()=>Uc},Om={pure:t=>e=>()=>t,Apply0:()=>Uc},qm={Applicative0:()=>Om,Bind1:()=>zm},Hm=t=>e=>'<defs><pattern id="'+t+'" x="0" y="0" width="'+Jt(e.tile)+'" height="'+Jt(e.tile)+'" patternUnits="userSpaceOnUse">'+(e.bgColor.a===0?"":'<rect width="'+Jt(e.tile)+'" height="'+Jt(e.tile)+'" fill="'+Jn(e.bgColor)+'" fill-opacity="'+Jt(ot(e.bgColor.a)/255)+'"/>')+'<circle cx="'+Jt(e.tile/2)+'" cy="'+Jt(e.tile/2)+'" r="'+Jt(e.dotRadius)+'" fill="'+Jn(e.dotColor)+'"/></pattern></defs><rect x="'+Jt(e.viewport.vx)+'" y="'+Jt(e.viewport.vy)+'" width="'+Jt(e.viewport.vw)+'" height="'+Jt(e.viewport.vh)+'" fill="url(#'+t+')"/>',Yc=t=>e=>'<path d="'+Tu(t)+'" fill="'+Jn(e)+'" fill-opacity="'+Jt(ot(e.a)/255)+'"/>',Wm=t=>e=>n=>r=>'<rect x="'+Jt(t.x)+'" y="'+Jt(t.y)+'" width="'+Jt(t.w)+'" height="'+Jt(t.h)+'" rx="'+Jt(e)+'"'+(()=>{if(n.tag==="Just")return' fill="'+Jn(n._1.color)+'" fill-opacity="'+Jt(ot(n._1.color.a)/255)+'"';if(n.tag==="Nothing")return' fill="none"';c()})()+(()=>{if(r.tag==="Just")return' stroke="'+Jn(r._1.color)+'" stroke-opacity="'+Jt(ot(r._1.color.a)/255)+'" stroke-width="'+Jt(r._1.width)+'" stroke-linejoin="'+(()=>{if(r._1.lineJoin==="RoundJoin")return"round";if(r._1.lineJoin==="BevelJoin")return"bevel";if(r._1.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(r._1.lineCap==="ButtCap")return"butt";if(r._1.lineCap==="RoundCap")return"round";if(r._1.lineCap==="SquareCap")return"square";c()})()+'"';if(r.tag==="Nothing")return"";c()})()+"/>",Xc=t=>e=>'<path d="'+Tu(t)+'" fill="none" stroke="'+Jn(e.color)+'" stroke-opacity="'+Jt(ot(e.color.a)/255)+'" stroke-width="'+Jt(e.width)+'" stroke-linejoin="'+(()=>{if(e.lineJoin==="RoundJoin")return"round";if(e.lineJoin==="BevelJoin")return"bevel";if(e.lineJoin==="MiterJoin")return"miter";c()})()+'" stroke-linecap="'+(()=>{if(e.lineCap==="ButtCap")return"butt";if(e.lineCap==="RoundCap")return"round";if(e.lineCap==="SquareCap")return"square";c()})()+'"/>',Vm=t=>{const e=Us(kr(t.content));return'<text x="'+Jt(t.x)+'" y="'+Jt(t.y)+'"'+(()=>{if(t.baseline==="BaselineTop")return' dy="0.8em"';if(t.baseline==="BaselineMiddle")return' dy="0.32em"';if(t.baseline==="BaselineAlphabetic"||t.baseline==="BaselineBottom")return"";c()})()+' fill="'+Jn(t.color)+'" fill-opacity="'+Jt(ot(t.color.a)/255)+'" font-size="'+Jt(t.font.size)+'" font-family="Ilisarniq, ui-sans-serif, system-ui, sans-serif" font-weight="'+fe(t.font.weight)+'" text-anchor="'+(()=>{if(t.align==="AlignLeft")return"start";if(t.align==="AlignCenter")return"middle";if(t.align==="AlignRight")return"end";c()})()+'">'+(e.length===1&&e[0].style==="RunText"?vu(e[0].text):si("")(O($m)(e)))+"</text>"},Um=Pm({fillPath:t=>e=>Te(Yc(t)(e.color)),strokePath:t=>e=>Te(Xc(t)(e)),fillStrokePath:t=>e=>n=>Te(Yc(t)(e.color)+Xc(t)(n)),drawRoundedRect:t=>e=>n=>r=>Te(Wm(t)(e)(n)(r)),drawText:t=>Te(Vm(t)),pushTransform:t=>Te((()=>{const e='transform="'+Bm(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popTransform:Te("</g>"),pushClip:t=>e=>n=>{const r=n.clipCounter;return()=>{const i=r.value;n.clipCounter.value=i+1|0;const o="clip"+fe(i);return Te((()=>{const u='clip-path="url(#'+o+')"';return'<defs><clipPath id="'+o+'"><path d="'+Tu(t)+'"'+(()=>{if(e==="EvenOdd")return' clip-rule="evenodd"';if(e==="NonZero")return"";c()})()+"/></clipPath></defs>"+(u===""?"<g>":"<g "+u+">")})())(n)()}},popClip:Te("</g>"),pushBlend:t=>Te((()=>{const e=(()=>{if(t==="Normal")return'style="mix-blend-mode: normal"';if(t==="Difference")return'style="mix-blend-mode: difference"';c()})();return e===""?"<g>":"<g "+e+">"})()),popBlend:Te("</g>"),pushAlpha:t=>Te((()=>{const e='opacity="'+Jt(t)+'"';return e===""?"<g>":"<g "+e+">"})()),popAlpha:Te("</g>"),pushLayer:t=>e=>{const n=(()=>{if(t==="LayerNodeMask"){const r=e.maskDepth;return()=>{const i=r.value;e.maskDepth.value=i+1|0}}return()=>{}})();return()=>{n(),e.out.push("<g>")}},popLayer:t=>{const e=t.maskDepth;return()=>{const n=e.value,r=n-1|0;n>0&&(t.maskDepth.value=r),t.out.push("</g>")}},setViewport:t=>e=>()=>{},clearBackground:t=>e=>Te('<rect x="'+Jt(e.viewport.vx)+'" y="'+Jt(e.viewport.vy)+'" width="'+Jt(e.viewport.vw)+'" height="'+Jt(e.viewport.vh)+'" fill="'+Jn(t)+'" opacity="'+Jt(ot(t.a)/255)+'"/>')(e),backgroundDots:t=>e=>{const n=e.patternCounter;return()=>{const r=n.value;return e.patternCounter.value=r+1|0,Te(Hm("bg-dots-"+fe(r))(t))(e)()}},measureText:t=>e=>n=>{const r=cc(t.family)(t.size)(t.weight)(kr(e));return()=>r},Monad0:()=>qm}),Ym=t=>e=>{const n={padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""},r=Fi(n)(t)(e);return{viewBox:Jt(r.vx)+" "+Jt(r.vy)+" "+Jt(r.vw)+" "+Jt(r.vh),body:(()=>{const i=[],o={value:0},u={value:0},s={value:0};return Um(n)(t)(e)({out:i,maskDepth:o,clipCounter:u,patternCounter:s,viewport:r})(),si("")(i)})()}},Hr=t=>({bind:e=>n=>r=>t.Bind1().bind(e(r))(i=>n(i._1)(i._2)),Apply0:()=>Kc(t)}),Kc=t=>{const e=t.Bind1().Apply0().Functor0(),n={map:r=>i=>o=>e.map(u=>w(r(u._1),u._2))(i(o))};return{apply:(()=>{const r=Hr(t);return i=>o=>r.bind(i)(u=>r.bind(o)(s=>Wr(t).pure(u(s))))})(),Functor0:()=>n}},Wr=t=>({pure:e=>n=>t.Applicative0().pure(w(e,n)),Apply0:()=>Kc(t)}),Xm=t=>{const e={Applicative0:()=>Wr(t),Bind1:()=>Hr(t)};return{state:n=>r=>t.Applicative0().pure(n(r)),Monad0:()=>e}},wu=(t,e)=>({tag:t,_1:e}),Dn=(t,e)=>({tag:t,_1:e}),Ee=Xm(dn),zt=Hr(dn),Qe=Ee.state(t=>w(t,t)),fn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},xn=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},_e=Wr(dn),Km=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=T;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=L("Just",o._4);continue}}c()}return i},jm=(()=>{const t=Re.unfoldr(e=>{if(e.tag==="Nil")return T;if(e.tag==="Cons")return L("Just",w(e._1,e._2));c()});return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._3,n(r._6,i)));c()};return n(e,qt)})())})(),Zm=t=>e=>{let n=e,r=!0,i;for(;r;){const o=n;if(o.tag==="Leaf"){r=!1,i=!1;continue}if(o.tag==="Node"){const u=C.compare(t)(o._3);if(u==="LT"){n=o._5;continue}if(u==="GT"){n=o._6;continue}if(u==="EQ"){r=!1,i=!0;continue}}c()}return i},Lu=t=>e=>n=>J(r=>i=>t.Bind1().bind(r)(o=>e(o)(i)))(t.Applicative0().pure(n)),tN=J(t=>e=>K(C)(e)()(t))(M),eN=(()=>{const t=(e=>n=>{let r=e,i=n,o=!0,u;for(;o;){const s=r,a=i;if(a.tag==="Nil"){o=!1,u=s;continue}if(a.tag==="Cons"){r=K(C)(a._1)()(s),i=a._2;continue}c()}return u})(M);return e=>t((()=>{const n=(r,i)=>{if(r.tag==="Leaf")return i;if(r.tag==="Node")return n(r._5,Mt("Cons",r._3,n(r._6,i)));c()};return n(e,qt)})())})(),jc=If(_e)(Dt),nN=t=>wu("Par",t),Zc=t=>wu("Seq",t),rN=t=>e=>n=>{const r=Mn(jt,T,i=>i._1===t,n);if(r.tag==="Just"){const i=$n(jt,T,r._1,w(t,e),n);if(i.tag==="Nothing")return n;if(i.tag==="Just")return i._1;c()}if(r.tag==="Nothing")return oe(n)(w(t,e));c()},iN=t=>e=>O(n=>n._1===t?w(n._1,{...n._2,label:L("Just",e)}):w(n._1,n._2)),Be=t=>Ee.state(e=>w(void 0,(()=>{if(e.error.tag==="Just")return e;if(e.error.tag==="Nothing")return{...e,error:L("Just",{msg:t,line:e.currentLine,column:e.currentColumn})};c()})())),oN=t=>zt.bind(Qe)(e=>{const n=t.tag==="Just"&&t._1!==""?t._1:"kf-"+fe(e.kfCounter);if(Ze(i=>i.id===n,e.keyframes))return Be("duplicate frame name "+n);const r={...e,keyframes:oe(e.keyframes)({id:n,nodes:e.currNodes,edges:e.currEdges}),kfCounter:e.kfCounter+1|0,currentKf:L("Just",n)};return Ee.state(i=>w(void 0,r))}),uN=t=>e=>{const n=e.from+"->"+e.to,r=e.newFrom+"->"+e.newTo,i=Et("Left","cannot repoint "+e.from+"\u2192"+e.to+": edge does not exist"),o=fn(n)(t.currEdges)?Et("Right",void 0):i;return(()=>{if(o.tag==="Left"){const u=o._1;return s=>Et("Left",u)}if(o.tag==="Right"){const u=o._1;return s=>s(u)}c()})()(()=>{const u="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newFrom;if(!xn(e.newFrom)(t.currNodes))return Et("Left",u);const s="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": unknown node "+e.newTo;if(!xn(e.newTo)(t.currNodes))return Et("Left",s);const a="cannot repoint "+e.from+"\u2192"+e.to+" to "+e.newFrom+"\u2192"+e.newTo+": target edge already exists";return n!==r&&fn(r)(t.currEdges)?Et("Left",a):Et("Right",{nextCurrEdges:K(C)(r)()(hr(C)(n)(t.currEdges)),newId:r,newEdge:{id:r,from:{node:e.newFrom,port:T},to:{node:e.newTo,port:T}}})})},sN={graphNodes:[],graphEdges:M,currNodes:M,currEdges:M,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T},tf=t=>e=>zt.bind(Qe)(n=>{const r="ev-"+fe(n.eventCounter);return zt.bind((()=>{const i={...n,eventCounter:n.eventCounter+1|0};return Ee.state(o=>w(void 0,i))})())(()=>_e.pure({events:[{id:r,kind:e,when:t}],firstId:L("Just",r),lastId:L("Just",r)}))}),aN=t=>e=>{if(e.tag==="Token"){const n=e._1;return zt.bind(Qe)(r=>{const i=!xn(n.from)(r.currNodes),o=!xn(n.to)(r.currNodes);if(i||o)return zt.bind(Be(i?o?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:o?"token references unknown node: "+n.to:"token references unknown node: "))(()=>_e.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return fn(s)(r.currEdges)?tf(t)(Ns("SendToken",{from:n.from,to:n.to,edge:s,direction:p_,labels:n.labels})):fn(u)(r.currEdges)?tf(t)(Ns("SendToken",{from:n.from,to:n.to,edge:u,direction:m_,labels:n.labels})):zt.bind(Be("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>_e.pure({events:[],firstId:T,lastId:T}))})}return _e.pure({events:[],firstId:T,lastId:T})},cN=t=>xt(e=>Km(e)(t.graphEdges))(bt(gr,jm(t.currEdges))),fN=t=>e=>{const n=ct(i=>i.from.node===e.id||i.to.node===e.id,cN(t)),r=Lu(vf)(i=>o=>{const u=o.from+"->"+e.id,s=e.id+"->"+o.to,a=o.from+"->"+o.to,f="via "+o.from+" "+o.to+": no edge "+o.from+"\u2192"+e.id;if(!fn(u)(t.currEdges))return Et("Left",f);const g="via "+o.from+" "+o.to+": no edge "+e.id+"\u2192"+o.to;if(!fn(s)(t.currEdges))return Et("Left",g);const d="via "+o.from+" "+o.to+": would create "+o.from+"\u2192"+o.to+" but it already exists";return fn(a)(t.currEdges)||Zm(a)(i.synthesized)?Et("Left",d):Et("Right",{consumed:K(C)(u)()(K(C)(s)()(i.consumed)),synthesized:K(C)(a)({id:a,from:{node:o.from,port:T},to:{node:o.to,port:T}})(i.synthesized)})})({consumed:M,synthesized:M})(e.via);return(()=>{if(r.tag==="Left"){const i=r._1;return o=>Et("Left",i)}if(r.tag==="Right"){const i=r._1;return o=>o(i)}c()})()(i=>{const o=i.consumed,u=ct(s=>!fn(s.id)(o),n);return u.length===0?Et("Right",{nextCurrEdges:xe(C.compare,pe,tn(C.compare,t.currEdges,tN(O(s=>s.id)(n))),eN((()=>{const s=a=>{if(a.tag==="Leaf")return M;if(a.tag==="Node")return $t("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));c()};return s(i.synthesized)})())),synthesized:i.synthesized}):Et("Left","cannot delete node "+e.id+": still connected ("+si(", ")(O(s=>s.from.node+"\u2192"+s.to.node)(u))+"). Use -edge to drop them or `via a b` to merge "+e.id+"'s endpoints.")})},ef=t=>{if(t.tag==="Leaf")return[t._1];if(t.tag==="Par"||t.tag==="Seq")return St(t._1)(ef);c()},gN=t=>({nodes:O(Yr)(t.graphNodes),edges:(()=>{const e=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return e(n._5,Mt("Cons",n._4,e(n._6,r)));c()};return bt(Wt.foldr,e(t.graphEdges,qt))})(),constraints:[]}),_N=t=>{if(t.tag==="AddNode"){const e=t._1;return Ee.state(n=>w(void 0,{...n,graphNodes:rN(e.id)({id:e.id,size:w(1,1),ports:[],label:L("Just",e.label)})(n.graphNodes),currNodes:K(C)(e.id)()(n.currNodes)}))}if(t.tag==="DelNode"){const e=t._1;return zt.bind(Qe)(n=>{if(!xn(e.id)(n.currNodes))return Be("cannot delete node "+e.id+": does not exist");const r=fN(n)(e);if(r.tag==="Left")return Be(r._1);if(r.tag==="Right"){const i=r._1;return Ee.state(o=>w(void 0,{...o,currNodes:hr(C)(e.id)(o.currNodes),currEdges:i.nextCurrEdges,graphEdges:xe(C.compare,pe,i.synthesized,o.graphEdges)}))}c()})}if(t.tag==="ModNode"){const e=t._1;return zt.bind(Qe)(n=>{if(!xn(e.id)(n.currNodes))return Be("cannot modify node "+e.id+": does not exist");if(e.label.tag==="Just"){const r=e.label._1;return Ee.state(i=>w(void 0,{...i,graphNodes:iN(e.id)(r)(i.graphNodes)}))}if(e.label.tag==="Nothing")return _e.pure();c()})}if(t.tag==="AddEdge"){const e=t._1;return zt.bind(Qe)(n=>{const r=!xn(e.from)(n.currNodes),i=!xn(e.to)(n.currNodes);if(r||i)return Be("cannot add edge "+e.from+"\u2192"+e.to+": unknown node "+(r?i?e.from+", "+e.to:e.from:i?e.to:""));const o=e.from+"->"+e.to;return Ee.state(u=>w(void 0,{...u,graphEdges:K(C)(o)({id:o,from:{node:e.from,port:T},to:{node:e.to,port:T}})(u.graphEdges),currEdges:K(C)(o)()(u.currEdges)}))})}if(t.tag==="DelEdge"){const e=t._1;return zt.bind(Qe)(n=>{const r=e.from+"->"+e.to;return fn(r)(n.currEdges)?Ee.state(i=>w(void 0,{...i,currEdges:hr(C)(r)(i.currEdges)})):Be("cannot delete edge "+e.from+"\u2192"+e.to+": does not exist")})}if(t.tag==="RepointEdge"){const e=t._1;return zt.bind(Qe)(n=>{const r=uN(n)(e);if(r.tag==="Left")return Be(r._1);if(r.tag==="Right"){const i=r._1;return Ee.state(o=>w(void 0,{...o,currEdges:i.nextCurrEdges,graphEdges:K(C)(i.newId)(i.newEdge)(o.graphEdges)}))}c()})}return _e.pure()},dN=t=>zt.bind(Ee.state(e=>w(void 0,{...e,currentLine:t.line,currentColumn:t.column})))(()=>_N(t.op)),lN=t=>e=>zt.bind(jc(dN)(e))(()=>zt.bind(Qe)(n=>{const r=t.tag==="Just"&&t._1!==""?t._1:"kf-"+fe(n.kfCounter);if(Ze(o=>o.id===r,n.keyframes))return Be("duplicate frame name "+r);const i={...n,keyframes:oe(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:L("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return oe(n.scenes)(ys("Structural",{from:n.currentKf._1,to:r,focus:T}));c()})()};return Ee.state(o=>w(void 0,i))})),hN=t=>e=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return _e.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return zt.bind(Vr(t)(n._1.head))(i=>zt.bind(Lu({Applicative0:()=>Wr(dn),Bind1:()=>Hr(dn)})(o=>u=>zt.bind(Vr((()=>{if(o.lastId.tag==="Just")return Eo("After",o.lastId._1);if(o.lastId.tag==="Nothing")return t;c()})())(u))(s=>_e.pure({events:[...o.events,...s.events],firstId:(()=>{if(o.firstId.tag==="Just")return L("Just",o.firstId._1);if(o.firstId.tag==="Nothing")return s.firstId;c()})(),lastId:(()=>{if(s.lastId.tag==="Just")return L("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return o.lastId;c()})()})))(i)(r))(o=>_e.pure(o)))}c()},pN=t=>e=>{const n=Bt(r=>T,r=>i=>L("Just",{head:r,tail:i}),e);if(n.tag==="Nothing")return _e.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return zt.bind(Vr(t)(n._1.head))(i=>zt.bind(mN((()=>{if(i.firstId.tag==="Just")return Eo("With",i.firstId._1);if(i.firstId.tag==="Nothing")return t;c()})())(r))(o=>_e.pure({events:[...i.events,...o.events],firstId:i.firstId,lastId:(()=>{if(i.lastId.tag==="Just")return L("Just",i.lastId._1);if(i.lastId.tag==="Nothing")return o.lastId;c()})()})))}c()},Vr=t=>e=>{if(e.tag==="Leaf"){const n=e._1;return zt.bind(Ee.state(r=>w(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>aN(t)(n.op))}if(e.tag==="Seq")return hN(t)(e._1);if(e.tag==="Par")return pN(t)(e._1);c()},mN=t=>Lu({Applicative0:()=>Wr(dn),Bind1:()=>Hr(dn)})(e=>n=>zt.bind(Vr(t)(n))(r=>_e.pure({events:[...e.events,...r.events],firstId:(()=>{if(e.firstId.tag==="Just")return L("Just",e.firstId._1);if(e.firstId.tag==="Nothing")return r.firstId;c()})(),lastId:(()=>{if(r.lastId.tag==="Just")return L("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return e.lastId;c()})()})))({events:[],firstId:T,lastId:T}),NN=t=>zt.bind(Qe)(e=>{if(e.currentKf.tag==="Nothing")return Be("flow ops before any structural frame");if(e.currentKf.tag==="Just"){const n=e.currentKf._1;return zt.bind(Vr(h_)(t))(r=>zt.bind(Qe)(i=>{const o={...i,scenes:oe(i.scenes)(ys("DataFlow",{keyframe:n,events:r.events,focus:T}))};return Ee.state(u=>w(void 0,o))}))}c()}),yN=t=>zt.bind(Qe)(e=>{if(e.error.tag==="Just")return _e.pure();if(e.error.tag==="Nothing"){const n=ef(t.ops),r=ct(o=>o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge",n),i=ct(o=>!(o.op.tag==="AddNode"||o.op.tag==="DelNode"||o.op.tag==="ModNode"||o.op.tag==="AddEdge"||o.op.tag==="DelEdge"||o.op.tag==="RepointEdge"),n);return zt.bind((()=>{const o=lN(t.name)(r);return r.length!==0?o:_e.pure()})())(()=>zt.bind((()=>{const o=oN(t.name);return r.length===0&&i.length!==0?o:_e.pure()})())(()=>{const o=NN(t.ops);return i.length!==0?o:_e.pure()}))}c()}),JN=t=>zt.bind(jc(yN)(t.frames))(()=>zt.bind(Qe)(e=>_e.pure((()=>{if(e.error.tag==="Just")return Et("Left",e.error._1);if(e.error.tag==="Nothing")return Et("Right",{seed:t.seed,graph:gN(e),keyframes:e.keyframes,scenes:e.scenes});c()})())))(sN)._1,ir=(t,e)=>({tag:"ParseError",_1:t,_2:e}),z=(t,e,n)=>({tag:"ParseState",_1:t,_2:e,_3:n}),Mi=(t,e,n)=>({tag:t,_1:e,_2:n}),xN=t=>Mi("More",t),TN=t=>Mi("Lift",t),nf={map:t=>e=>(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,f)=>r(g=>u(a,t(f)))))},vN={alt:t=>e=>(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(f=>t(z(s,a,!1),r,i,(g,d)=>{const l=g._3;return r(_=>l?o(g,d):e(n,r,i,o,u))},u))},Functor0:()=>nf},wN=t=>{const e=t.Monad0();return n=>r=>{const i=o=>{let u=o,s=!0,a;for(;s;){const f=u();if(f.tag==="More"){u=f._1;continue}if(f.tag==="Lift"){s=!1,a=e.Bind1().Apply0().Functor0().map(Ou)(f._1);continue}if(f.tag==="Stop"){s=!1,a=e.Applicative0().pure(fr("Done",w(f._2,f._1)));continue}c()}return a};return t.tailRecM(i)(o=>r(n,xN,TN,(u,s)=>Mi("Stop",u,Et("Left",s)),(u,s)=>Mi("Stop",u,Et("Right",s))))}},rf=(t,e,n,r,i)=>i(t,t._2),LN={index:0,line:1,column:1},bN=(t=>{const e=wN(t);return n=>r=>t.Monad0().Bind1().Apply0().Functor0().map(Xr)(e(z(n,LN,!1))(r))})(Sf),of={apply:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,f)=>r(g=>{const d=n._3&&!a._3?z(a._1,a._2,!0):a;return e(d,r,i,o,(l,_)=>r(h=>u(d._3&&!l._3?z(l._1,l._2,!0):l,f(_))))}))),Functor0:()=>nf},uf={pure:t=>(e,n,r,i,o)=>o(e,t),Apply0:()=>of},EN={bind:t=>e=>(n,r,i,o,u)=>r(s=>t(n,r,i,o,(a,f)=>r(g=>e(f)(n._3&&!a._3?z(a._1,a._2,!0):a,r,i,o,u)))),Apply0:()=>of},kN={Applicative0:()=>uf,Bind1:()=>EN},$i=t=>(e,n,r,i,o)=>n(u=>rf(e,n,r,i,(s,a)=>n(f=>i(e._3&&!s._3?z(s._1,s._2,!0):s,ir(t,a))))),GN={empty:$i("No alternative"),Alt0:()=>vN},CN={Applicative0:()=>uf,Plus1:()=>GN},Ae=(t=>e=>{const n=e.Plus1().Alt0(),r=e.Applicative0();return i=>t.tailRecM(o=>t.Monad0().Bind1().bind(n.alt(n.Functor0().map(Ou)(i))(r.pure(fr("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return fr("Loop",Mt("Cons",u._1,o));if(u.tag==="Done")return fr("Done",(s=>a=>{let f=s,g=a,d=!0,l;for(;d;){const _=f,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){f=Mt("Cons",h._1,_),g=h._2;continue}c()}return l})(qt)(o));c()})())))(qt)})({tailRecM:t=>e=>(n,r,i,o,u)=>{const s=(a,f,g)=>t(f)(a,r,i,o,(d,l)=>{const _=a._3&&!d._3?z(d._1,d._2,!0):d;if(l.tag==="Loop")return g===0?r(h=>s(_,l._1,30)):s(_,l._1,g-1|0);if(l.tag==="Done")return u(_,l._1);c()});return s(n,e,30)},Monad0:()=>kN})(CN),kt=t=>e=>{const n=$i("Expected "+e);return(r,i,o,u,s)=>{const a=r._1,f=r._2;return i(g=>t(z(a,f,!1),i,o,(d,l)=>{const _=d._3;return i(h=>_?u(d,l):n(r,i,o,u,s))},s))}},bu=t=>(e,n,r,i,o)=>{const u=e._3,s=e._1,a=e._2;return n(f=>{const g=(d,l)=>{const _=d._3;return n(h=>_?i(z(d._1,d._2,u),l):o(e,void 0))};return n(d=>n(l=>t(z(s,a,!1),n,r,(_,h)=>g(z(_._1,_._2,!1),h),(_,h)=>n(p=>n(m=>$i("Negated parser succeeded")(_,n,r,g,(N,y)=>n(x=>o(_._3&&!N._3?z(N._1,N._2,!0):N,y))))))))})},SN=t=>{const e=t.foldr(n=>r=>{if(r.tag==="Nothing")return L("Just",n);if(r.tag==="Just")return L("Just",(i,o,u,s,a)=>{const f=i._1,g=i._2;return o(d=>n(z(f,g,!1),o,u,(l,_)=>{const h=l._3;return o(p=>h?s(l,_):r._1(i,o,u,s,a))},a))});c()})(T);return n=>{const r=e(n);if(r.tag==="Nothing")return $i("No alternative");if(r.tag==="Just")return r._1;c()}},QN=t=>e=>n=>(r,i,o,u,s)=>i(a=>i(f=>i(g=>i(d=>t(r,i,o,u,(l,_)=>i(h=>i(p=>{const m=r._3&&!l._3?z(l._1,l._2,!0):l;return n(m,i,o,u,(N,y)=>i(x=>{const v=m._3&&!N._3?z(N._1,N._2,!0):N;return i(b=>i(E=>{const k=r._3&&!v._3?z(v._1,v._2,!0):v;return e(k,i,o,u,(F,U)=>i(tt=>s(k._3&&!F._3?z(F._1,F._2,!0):F,y)))}))}))}))))))),Eu=t=>e=>n=>{if(e===10)return{index:t.index+1|0,line:t.line+1|0,column:1};if(e===13){const r=t1()(n);return r.tag==="Just"&&r._1===10?{index:t.index+1|0,line:t.line,column:t.column}:{index:t.index+1|0,line:t.line+1|0,column:1}}return e===9?{index:t.index+1|0,line:t.line,column:(t.column+8|0)-no(t.column-1|0)(8)|0}:{index:t.index+1|0,line:t.line,column:t.column+1|0}},PN=t=>e=>n=>{let r=t,i=e,o=n,u=!0,s;for(;u;){const a=r,f=i,g=o,d=ai(f);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?Eu(a)(d._1.head)(g):Eu(a)(d._1.head)(d._1.tail),i=d._1.tail,o=g;continue}c()}return s},Ut=t=>(e,n,r,i,o)=>{const u=ai(e._1);if(u.tag==="Nothing")return i(e,ir("Unexpected EOF",e._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return i(e,ir("Expected Char",e._2));if(u._1.head>=0&&u._1.head<=65535){const s=Es(u._1.head);return t(s)?o(z(u._1.tail,Eu(e._2)(u._1.head)(u._1.tail),!0),s):i(e,ir("Predicate unsatisfied",e._2))}}c()},sf=(t,e,n,r,i)=>t._1===""?i(z(t._1,t._2,!0),void 0):r(t,ir("Expected EOF",t._2)),DN=t=>(e,n,r,i,o)=>{const u=t(e._1);if(u.tag==="Left")return i(e,ir(u._1,e._2));if(u.tag==="Right")return o(z(u._1.remainder,PN(e._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);c()},or=t=>DN(e=>{const n=o_(t)(e);return n.tag==="Just"?Et("Right",{value:t,consumed:t,remainder:n._1}):Et("Left","Expected "+mf(t))}),AN=Ut(t=>!0),af=SN(Dt),cf=(()=>{const t=Ut(e=>e===" "||e===" "||e===`
|
|
8
|
+
`||e==="\r");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(f=>o(e._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),ku=(t,e,n,r,i)=>e(o=>or("#")(t,e,n,r,(u,s)=>e(a=>{const f=Ae(Ut(d=>d!==`
|
|
9
|
+
`)),g=t._3&&!u._3?z(u._1,u._2,!0):u;return e(d=>f(g,e,n,r,(l,_)=>e(h=>i(g._3&&!l._3?z(l._1,l._2,!0):l,void 0))))}))),IN=kt((()=>{const t=kt(Ut(n=>n==="}"))("'}'"),e=Ut(n=>n===`
|
|
10
|
+
`||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(f=>r(g=>t(z(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(N=>ku(z(h,p,!1),r,i,(y,x)=>{const v=y._3;return r(b=>{if(v)return o(y,x);const E=n._1,k=n._2;return r(F=>r(U=>e(z(E,k,!1),r,i,(tt,Q)=>{const S=tt._3;return r(Z=>S?o(tt,Q):sf(n,r,i,o,u))},(tt,Q)=>r(S=>u(tt,void 0)))))})},(y,x)=>r(v=>u(y,void 0)))))}),(d,l)=>r(_=>u(z(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Ie=(()=>{const t=Ae((e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>cf(z(u,s,!1),n,r,(f,g)=>{const d=f._3;return n(l=>d?i(f,g):ku(e,n,r,i,o))},o))});return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(f=>o(e._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),Me=(t,e,n,r,i)=>e(o=>{const u=(f,g)=>e(d=>Ie(t._3&&!f._3?z(f._1,f._2,!0):f,e,n,r,i)),s=t._1,a=t._2;return e(f=>cf(z(s,a,!1),e,n,(g,d)=>{const l=g._3;return e(_=>l?r(g,d):ku(t,e,n,r,u))},u))}),ff=(()=>{const t=kt(Ut(e=>e==="|"))("'|'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(f=>{const g=Ae(Ut(l=>l!=="|")),d=e._3&&!s._3?z(s._1,s._2,!0):s;return n(l=>g(d,n,r,i,(_,h)=>n(p=>{const m=kt(kt(Ut(y=>y==="|"))("'|'"))("closing '|'"),N=d._3&&!_._3?z(_._1,_._2,!0):_;return n(y=>m(N,n,r,i,(x,v)=>n(b=>o(N._3&&!x._3?z(x._1,x._2,!0):x,bn(bt(Wt.foldr,h))))))})))})))})(),zi=Ut(t=>t>="a"&&t<="z"||t>="A"&&t<="Z"),An=(()=>{const t=Ae(Ut(e=>e===" "||e===" "));return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(f=>o(e._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),RN=(()=>{const t=kt(Ut(e=>e==="\\"))("'\\\\'");return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(f=>{const g=e._3&&!s._3?z(s._1,s._2,!0):s;return n(d=>AN(g,n,r,i,(l,_)=>n(h=>o(g._3&&!l._3?z(l._1,l._2,!0):l,_==="n"?`
|
|
11
|
+
`:_==="t"?" ":_==="r"?"\r":_))))})))})(),FN=(()=>{const t=Ut(e=>e!=='"'&&e!=="\\"&&e!==`
|
|
12
|
+
`);return(e,n,r,i,o)=>{const u=e._1,s=e._2;return n(a=>RN(z(u,s,!1),n,r,(f,g)=>n(d=>t(e,n,r,i,o)),o))}})(),Gu=(()=>{const t=kt(Ut(e=>e==='"'))(`'"'`);return(e,n,r,i,o)=>n(u=>t(e,n,r,i,(s,a)=>n(f=>{const g=Ae(FN),d=e._3&&!s._3?z(s._1,s._2,!0):s;return n(l=>g(d,n,r,i,(_,h)=>n(p=>{const m=kt(kt(Ut(y=>y==='"'))(`'"'`))(`closing '"' (unterminated string)`),N=d._3&&!_._3?z(_._1,_._2,!0):_;return n(y=>m(N,n,r,i,(x,v)=>n(b=>o(N._3&&!x._3?z(x._1,x._2,!0):x,bn(bt(Wt.foldr,h))))))})))})))})(),BN=(()=>{const t=kt(Ut(e=>e===":"))("':'");return(e,n,r,i,o)=>n(u=>An(e,n,r,i,(s,a)=>n(f=>kt((g,d,l,_,h)=>{const p=g._1,m=g._2;return d(N=>{const y=(x,v)=>{const b=x._3;return d(E=>{if(b)return _(x,v);const k=g._1,F=g._2;return d(U=>ff(z(k,F,!1),d,l,(tt,Q)=>{const S=tt._3;return d(Z=>S?_(tt,Q):Gu(g,d,l,_,h))},h))})};return d(x=>t(z(p,m,!1),d,l,y,(v,b)=>d(E=>d(k=>An(v,d,l,y,(F,U)=>d(tt=>{const Q=Ae(Ut(Z=>Z!==`
|
|
13
|
+
`&&Z!=="\r"&&Z!=="#"&&Z!=="}")),S=v._3&&!F._3?z(F._1,F._2,!0):F;return d(Z=>Q(S,d,l,y,(V,R)=>d($=>h(S._3&&!V._3?z(V._1,V._2,!0):V,z_(bn(bt(Wt.foldr,R)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(e._3&&!s._3?z(s._1,s._2,!0):s,n,r,i,o))))})(),MN=(t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>ff(z(o,u,!1),e,n,(a,f)=>{const g=a._3;return e(d=>g?r(a,f):Gu(t,e,n,r,i))},i))},Ur=Ut(t=>t>="0"&&t<="9"),ve=(()=>{const t=kt(Ut(e=>e==="_"))("'_'");return(e,n,r,i,o)=>n(u=>{const s=(g,d)=>n(l=>{const _=Ae((()=>{const p=kt(Ut(N=>N==="_"))("'_'"),m=kt(Ut(N=>N==="-"))("'-'");return(N,y,x,v,b)=>{const E=N._1,k=N._2;return y(F=>zi(z(E,k,!1),y,x,(U,tt)=>{const Q=U._3;return y(S=>{if(Q)return v(U,tt);const Z=N._1,V=N._2;return y(R=>Ur(z(Z,V,!1),y,x,($,I)=>{const G=$._3;return y(D=>{if(G)return v($,I);const P=N._1,A=N._2;return y(H=>p(z(P,A,!1),y,x,(Y,W)=>{const q=Y._3;return y(B=>q?v(Y,W):m(N,y,x,v,b))},b))})},b))})},b))}})()),h=e._3&&!g._3?z(g._1,g._2,!0):g;return n(p=>_(h,n,r,i,(m,N)=>n(y=>o(h._3&&!m._3?z(m._1,m._2,!0):m,vo(d)+bn(bt(Wt.foldr,N))))))}),a=e._1,f=e._2;return n(g=>zi(z(a,f,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?i(d,l):t(e,n,r,i,s))},s))})})(),$N=kt((t,e,n,r,i)=>{const o=t._1,u=t._2;return e(s=>Gu(z(o,u,!1),e,n,(a,f)=>{const g=a._3;return e(d=>g?r(a,f):ve(t,e,n,r,i))},i))})("frame name (identifier or quoted string)"),zN=(t,e,n,r,i)=>e(o=>ve(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>An(f,e,n,r,(d,l)=>e(_=>{const h=kt((m,N,y,x,v)=>{const b=m._1,E=m._2;return N(k=>or("->")(z(b,E,!1),N,y,(F,U)=>{const tt=F._3;return N(Q=>tt?x(F,U):or("<-")(m,N,y,x,v))},v))})("'->' or '<-'"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>An(v,e,n,r,(E,k)=>e(F=>{const U=kt(ve)("target node identifier"),tt=v._3&&!E._3?z(E._1,E._2,!0):E;return e(Q=>U(tt,e,n,r,(S,Z)=>e(V=>{const R=Ae((I,G,D,P,A)=>{const H=I._3;return G(Y=>G(W=>An(I,G,D,(q,B)=>P(z(q._1,q._2,H),B),(q,B)=>G(j=>G(X=>{const _t=I._3&&!q._3?z(q._1,q._2,!0):q;return MN(_t,G,D,(pt,ft)=>P(z(pt._1,pt._2,H),ft),(pt,ft)=>G(ht=>A(_t._3&&!pt._3?z(pt._1,pt._2,!0):pt,ft)))})))))}),$=tt._3&&!S._3?z(S._1,S._2,!0):S;return e(I=>R($,e,n,r,(G,D)=>e(P=>(()=>{if(y==="<-"){const H=Dn("Token",{from:Z,to:s,labels:bt(Wt.foldr,D)});return(Y,W,q,B,j)=>j(Y,H)}const A=Dn("Token",{from:s,to:Z,labels:bt(Wt.foldr,D)});return(H,Y,W,q,B)=>B(H,A)})()($._3&&!G._3?z(G._1,G._2,!0):G,e,n,r,i))))})))})))})))})))}))),ON=(t,e,n,r,i)=>e(o=>Ur(t,e,n,r,(u,s)=>e(a=>{const f=Ae(Ur),g=t._3&&!u._3?z(u._1,u._2,!0):u;return e(d=>f(g,e,n,r,(l,_)=>e(h=>{const p=rg(vo(s)+bn(bt(Wt.foldr,_)));return(()=>{if(p.tag==="Just"){const m=p._1;return(N,y,x,v,b)=>b(N,m)}if(p.tag==="Nothing")return(m,N,y,x,v)=>v(m,0);c()})()(g._3&&!l._3?z(l._1,l._2,!0):l,e,n,r,i)})))}))),Oi=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>or(t)(e,n,r,(a,f)=>i(z(a._1,a._2,u),f),(a,f)=>n(g=>{const d=bu((()=>{const _=kt(Ut(p=>p==="_"))("'_'"),h=kt(Ut(p=>p==="-"))("'-'");return(p,m,N,y,x)=>{const v=p._1,b=p._2;return m(E=>zi(z(v,b,!1),m,N,(k,F)=>{const U=k._3;return m(tt=>{if(U)return y(k,F);const Q=p._1,S=p._2;return m(Z=>Ur(z(Q,S,!1),m,N,(V,R)=>{const $=V._3;return m(I=>{if($)return y(V,R);const G=p._1,D=p._2;return m(P=>_(z(G,D,!1),m,N,(A,H)=>{const Y=A._3;return m(W=>Y?y(A,H):h(p,m,N,y,x))},x))})},x))})},x))}})()),l=e._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>{const N=l._3&&!h._3?z(h._1,h._2,!0):h;return n(y=>Ie(N,n,r,(x,v)=>i(z(x._1,x._2,u),v),(x,v)=>n(b=>o(N._3&&!x._3?z(x._1,x._2,!0):x,t))))})))})))},qN=(t,e,n,r,i)=>e(o=>Me(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Oi("via")(f,e,n,r,(d,l)=>e(_=>{const h=f._3&&!d._3?z(d._1,d._2,!0):d;return e(p=>ve(h,e,n,r,(m,N)=>e(y=>{const x=h._3&&!m._3?z(m._1,m._2,!0):m;return e(v=>Me(x,e,n,r,(b,E)=>e(k=>{const F=x._3&&!b._3?z(b._1,b._2,!0):b;return e(U=>ve(F,e,n,r,(tt,Q)=>e(S=>i(F._3&&!tt._3?z(tt._1,tt._2,!0):tt,{from:N,to:Q}))))})))})))})))}))),ur=t=>(e,n,r,i,o)=>{const u=e._3;return n(s=>or(t)(e,n,r,(a,f)=>i(z(a._1,a._2,u),f),(a,f)=>n(g=>{const d=bu((()=>{const _=kt(Ut(p=>p==="_"))("'_'"),h=kt(Ut(p=>p==="-"))("'-'");return(p,m,N,y,x)=>{const v=p._1,b=p._2;return m(E=>zi(z(v,b,!1),m,N,(k,F)=>{const U=k._3;return m(tt=>{if(U)return y(k,F);const Q=p._1,S=p._2;return m(Z=>Ur(z(Q,S,!1),m,N,(V,R)=>{const $=V._3;return m(I=>{if($)return y(V,R);const G=p._1,D=p._2;return m(P=>_(z(G,D,!1),m,N,(A,H)=>{const Y=A._3;return m(W=>Y?y(A,H):h(p,m,N,y,x))},x))})},x))})},x))}})()),l=e._3&&!a._3?z(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,p)=>i(z(h._1,h._2,u),p),(h,p)=>n(m=>o(l._3&&!h._3?z(h._1,h._2,!0):h,void 0))))})))},HN=(t,e,n,r,i)=>e(o=>ur("+edge")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>Me(v,e,n,r,(E,k)=>e(F=>{const U=kt(ve)("target node identifier"),tt=v._3&&!E._3?z(E._1,E._2,!0):E;return e(Q=>U(tt,e,n,r,(S,Z)=>e(V=>i(tt._3&&!S._3?z(S._1,S._2,!0):S,Dn("AddEdge",{from:y,to:Z})))))})))})))})))}))),WN=(t,e,n,r,i)=>e(o=>ur("+node")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>BN(v,e,n,r,(E,k)=>e(F=>i(v._3&&!E._3?z(E._1,E._2,!0):E,Dn("AddNode",{id:y,label:k})))))})))})))}))),VN=(t,e,n,r,i)=>e(o=>ur("-edge")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>Me(v,e,n,r,(E,k)=>e(F=>{const U=kt(ve)("target node identifier"),tt=v._3&&!E._3?z(E._1,E._2,!0):E;return e(Q=>U(tt,e,n,r,(S,Z)=>e(V=>i(tt._3&&!S._3?z(S._1,S._2,!0):S,Dn("DelEdge",{from:y,to:Z})))))})))})))})))}))),UN=(t,e,n,r,i)=>e(o=>ur("-node")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=Ae((E,k,F,U,tt)=>{const Q=E._3;return qN(E,k,F,(S,Z)=>U(z(S._1,S._2,Q),Z),tt)}),b=p._3&&!N._3?z(N._1,N._2,!0):N;return e(E=>v(b,e,n,r,(k,F)=>e(U=>i(b._3&&!k._3?z(k._1,k._2,!0):k,Dn("DelNode",{id:y,via:bt(Wt.foldr,F)})))))})))})))}))),YN=(t,e,n,r,i)=>e(o=>ur("~edge")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>Me(f,e,n,r,(d,l)=>e(_=>{const h=kt(ve)("source node identifier"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>Me(v,e,n,r,(E,k)=>e(F=>{const U=kt(ve)("target node identifier"),tt=v._3&&!E._3?z(E._1,E._2,!0):E;return e(Q=>U(tt,e,n,r,(S,Z)=>e(V=>{const R=tt._3&&!S._3?z(S._1,S._2,!0):S;return e($=>Ie(R,e,n,r,(I,G)=>e(D=>{const P=kt(or("->"))("'->'"),A=R._3&&!I._3?z(I._1,I._2,!0):I;return e(H=>P(A,e,n,r,(Y,W)=>e(q=>{const B=A._3&&!Y._3?z(Y._1,Y._2,!0):Y;return e(j=>Ie(B,e,n,r,(X,_t)=>e(pt=>{const ft=kt(ve)("new source node identifier"),ht=B._3&&!X._3?z(X._1,X._2,!0):X;return e(Lt=>ft(ht,e,n,r,(Pt,lt)=>e(Rt=>{const mt=ht._3&&!Pt._3?z(Pt._1,Pt._2,!0):Pt;return e(gt=>Me(mt,e,n,r,(it,rt)=>e(at=>{const Nt=kt(ve)("new target node identifier"),yt=mt._3&&!it._3?z(it._1,it._2,!0):it;return e(Ct=>Nt(yt,e,n,r,(Ot,re)=>e(je=>i(yt._3&&!Ot._3?z(Ot._1,Ot._2,!0):Ot,Dn("RepointEdge",{from:y,to:Z,newFrom:lt,newTo:re})))))})))})))})))})))})))})))})))})))})))}))),XN=(t,e,n,r,i)=>e(o=>rf(t,e,n,r,(u,s)=>e(a=>{const f=kt(af([WN,UN,YN,HN,VN,zN]))("statement (+node, -node, +edge, -edge, ~edge, or 'a -> b')"),g=t._3&&!u._3?z(u._1,u._2,!0):u;return e(d=>f(g,e,n,r,(l,_)=>e(h=>i(g._3&&!l._3?z(l._1,l._2,!0):l,wu("Leaf",{op:_,line:s.line,column:s.column})))))}))),KN=(t,e,n,r,i)=>e(o=>ur("seed")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>An(f,e,n,r,(d,l)=>e(_=>{const h=kt(ON)("integer (seed value)"),p=f._3&&!d._3?z(d._1,d._2,!0):d;return e(m=>h(p,e,n,r,(N,y)=>e(x=>{const v=p._3&&!N._3?z(N._1,N._2,!0):N;return e(b=>Ie(v,e,n,r,(E,k)=>e(F=>i(v._3&&!E._3?z(E._1,E._2,!0):E,y))))})))})))}))),Cu=QN((()=>{const t=kt(Ut(e=>e==="{"))("'{'");return(e,n,r,i,o)=>n(u=>n(s=>t(e,n,r,i,(a,f)=>n(g=>n(d=>{const l=e._3&&!a._3?z(a._1,a._2,!0):a;return Ie(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())(kt((()=>{const t=kt(Ut(e=>e==="}"))("'}'");return(e,n,r,i,o)=>n(u=>n(s=>Ie(e,n,r,i,(a,f)=>n(g=>n(d=>{const l=e._3&&!a._3?z(a._1,a._2,!0):a;return t(l,n,r,i,(_,h)=>n(p=>o(l._3&&!_._3?z(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),jN=(t,e,n,r,i)=>e(o=>Oi("seq")(t,e,n,r,(u,s)=>e(a=>Cu(Su(Zc))(t._3&&!u._3?z(u._1,u._2,!0):u,e,n,r,i)))),ZN=(t,e,n,r,i)=>e(o=>Oi("par")(t,e,n,r,(u,s)=>e(a=>Cu(Su(nN))(t._3&&!u._3?z(u._1,u._2,!0):u,e,n,r,i)))),Su=t=>{const e=Ae(t2());return(n,r,i,o,u)=>r(s=>e(n,r,i,o,(a,f)=>r(g=>u(n._3&&!a._3?z(a._1,a._2,!0):a,t(bt(Wt.foldr,f))))))},t2=hf(()=>{const t=bu(kt(Ut(e=>e==="}"))("'}'"));return(e,n,r,i,o)=>n(u=>{const s=e._3;return n(a=>n(f=>Ie(e,n,r,(g,d)=>i(z(g._1,g._2,s),d),(g,d)=>n(l=>n(_=>{const h=e._3&&!g._3?z(g._1,g._2,!0):g;return t(h,n,r,(p,m)=>i(z(p._1,p._2,s),m),(p,m)=>n(N=>{const y=h._3&&!p._3?z(p._1,p._2,!0):p;return n(x=>{const v=af([(E,k,F,U,tt)=>{const Q=E._3;return ZN(E,k,F,(S,Z)=>U(z(S._1,S._2,Q),Z),tt)},(E,k,F,U,tt)=>{const Q=E._3;return jN(E,k,F,(S,Z)=>U(z(S._1,S._2,Q),Z),tt)},XN]),b=e._3&&!y._3?z(y._1,y._2,!0):y;return n(E=>v(b,n,r,i,(k,F)=>n(U=>{const tt=b._3&&!k._3?z(k._1,k._2,!0):k;return n(Q=>An(tt,n,r,i,(S,Z)=>n(V=>{const R=tt._3&&!S._3?z(S._1,S._2,!0):S;return n($=>IN(R,n,r,i,(I,G)=>n(D=>o(R._3&&!I._3?z(I._1,I._2,!0):I,F))))})))})))})}))})))))})}),e2=(t,e,n,r,i)=>e(o=>Oi("frame")(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>$N(f,e,n,r,(d,l)=>e(_=>{const h=f._3&&!d._3?z(d._1,d._2,!0):d;return e(p=>Ie(h,e,n,r,(m,N)=>e(y=>{const x=Cu(Su(Zc)),v=h._3&&!m._3?z(m._1,m._2,!0):m;return e(b=>x(v,e,n,r,(E,k)=>e(F=>{const U=v._3&&!E._3?z(E._1,E._2,!0):E;return e(tt=>Ie(U,e,n,r,(Q,S)=>e(Z=>i(U._3&&!Q._3?z(Q._1,Q._2,!0):Q,{name:L("Just",l),ops:k}))))})))})))})))}))),n2=(t,e,n,r,i)=>e(o=>Ie(t,e,n,r,(u,s)=>e(a=>{const f=t._3&&!u._3?z(u._1,u._2,!0):u;return e(g=>{const d=(h,p)=>e(m=>{const N=Ae(e2),y=f._3&&!h._3?z(h._1,h._2,!0):h;return e(x=>N(y,e,n,r,(v,b)=>e(E=>{const k=y._3&&!v._3?z(v._1,v._2,!0):v;return e(F=>Ie(k,e,n,r,(U,tt)=>e(Q=>{const S=kt(sf)("'frame' or end of input"),Z=k._3&&!U._3?z(U._1,U._2,!0):U;return e(V=>S(Z,e,n,r,(R,$)=>e(I=>i(Z._3&&!R._3?z(R._1,R._2,!0):R,{seed:(()=>{if(p.tag==="Just")return p._1;if(p.tag==="Nothing")return 0;c()})(),frames:bt(Wt.foldr,b)}))))})))})))}),l=f._1,_=f._2;return e(h=>e(p=>KN(z(l,_,!1),e,n,(m,N)=>{const y=m._3;return e(x=>y?r(m,N):d(f,T))},(m,N)=>e(y=>d(m,L("Just",N))))))})}))),r2=t=>{const e=bN(t)(n2);if(e.tag==="Left")return Et("Left",{msg:e._1._1,line:e._1._2.line,column:e._1._2.column});if(e.tag==="Right")return Et("Right",e._1);c()},i2=t=>{const e=r2(t);if(e.tag==="Left")return Et("Left",e._1.msg);if(e.tag==="Right")return Et("Right",e._1);c()};function Qu(t,e,n,r){if(typeof window<"u"){var i=window[n];if(i!=null&&r instanceof i)return e(r)}for(var o=r;o!=null;){var u=Object.getPrototypeOf(o),s=u.constructor.name;if(s===n)return e(r);if(s==="Object")return t;o=u}return t}function qi(t){return function(e){return function(n){return function(){n.setAttribute(t,e)}}}}function o2(t){return function(e){return function(){e.textContent=t}}}function u2(t){return function(){return function(e){return t(e)()}}}function s2(t){return function(e){return function(n){return function(r){return function(){return r.addEventListener(t,e,n)}}}}}const a2=function(){return window};function c2(t){return function(e){return function(){e.value=t}}}function f2(t){return function(){return t.valueAsNumber}}function g2(t){return function(){return t.value}}function _2(t){return function(e){return function(){return e.requestAnimationFrame(t)}}}const d2=t=>t,l2=t=>()=>t.clientWidth||0,h2=()=>window.devicePixelRatio||1,Pu=(t,e)=>{e.innerHTML=t},p2=(t,e,n)=>{t.style.setProperty(e,n)},m2=(t,e)=>t.querySelector(`[data-mg="${e}"]`),N2=t=>e=>t===e,y2=t=>t,J2=Dt.foldMap(dg),gf=t=>e=>{const n=dt.compare(t)(e);if(n==="LT"||n==="EQ")return t;if(n==="GT")return e;c()},x2=t=>e=>{const n=dt.compare(t)(e);if(n==="LT")return e;if(n==="EQ"||n==="GT")return t;c()},T2=y2("CanvasRenderer"),v2=t=>e=>{const n=t-e*ot(vn(ju(t/e)));return e<=0?0:n<0?n+e:n},w2=t=>e=>{const n=gp(t);return()=>{const r=n(),i=P1(L1)(t)(pp(r)(t));if(i.tag==="Left")return rs("[markgraf] precompute failed")();if(i.tag==="Right")return e(i._1)();c()}},L2=t=>J(e=>n=>{const r=t(n);return()=>(e(),r())})(()=>{}),b2=`
|
|
14
14
|
<canvas data-mg="stage" tabindex="0"></canvas>
|
|
15
15
|
<div data-mg="play-overlay" aria-hidden="true"></div>
|
|
16
16
|
<div data-mg="bar">
|
|
@@ -27,4 +27,4 @@ var Vm=(function(Ao){"use strict";function Rc(e){let t=0,n;return()=>{if(t===2)r
|
|
|
27
27
|
<option value="2">2\xD7</option>
|
|
28
28
|
</select>
|
|
29
29
|
</div>
|
|
30
|
-
`,
|
|
30
|
+
`,gn=t=>e=>n=>()=>{const r=m2(t,e),i=hg(r,T,jt);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&c()},E2=t=>e=>{const n=e.totalDuration<=0?1:e.totalDuration,r=J2(i=>'<span class="mg-tick" style="left:'+Nr(pr("Fixed",mr(0)(20)(2)))(100*i.startT/n)+'%" data-label="'+(()=>{if(i.scene.tag==="Structural")return i.scene._1.to;if(i.scene.tag==="DataFlow")return i.scene._1.keyframe;c()})()+'"></span>')(e.spans);return gn(t)("ticks")(i=>()=>Pu(r,i))},k2=t=>e=>n=>gn(t)("scrub")(r=>{const i=Qu(T,jt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:c2(fe(vn(Zu(e/n*1e3))))(i._1);c()}),Du=t=>e=>n=>{const r=u2(i=>n);return()=>{const i=r();return s2(t)(i)(!1)(e)()}},Au=t=>e=>n=>r=>i=>o=>{const u=ud(n)(gf(o)(n.totalDuration));if(e==="CanvasRenderer")return()=>{const s=is(),a=i.value;i.value=s;const f=d2(t),g=bs(n.layout)(u.camera),d=g.w+48,l=g.h+48,_=l2(t)(),h=d<=0?_:_*l/d,p=h2(),m=_*p,N=h*p,y=Jg(f)(),x=xg(f)(),v=Tg(f)(m);y!==m&&v();const b=vg(f)(N);x!==N&&b(),p2(t,"height",fe(vn(Zu(h)))+"px");const E=yg(f)();yr(E)(),co(E)({scaleX:p,scaleY:p})();const k=r.value,F=Fm(E)({width:_,height:h})(n.layout)(u)(a===0?0:(s-a)/1e3)(k)();return r.value=F,Jr(E)()};if(e==="SvgRenderer"){const s=Ym(n.layout)(u),a=qi("viewBox")(s.viewBox)(t);return()=>(a(),qi("preserveAspectRatio")("xMidYMid meet")(t)(),Pu(s.body,t))}c()},_f=t=>{const e=i2(t);if(e.tag==="Left")return Et("Left",e._1);if(e.tag==="Right"){const n=JN(e._1);if(n.tag==="Left")return Et("Left",n._1.msg);if(n.tag==="Right")return Et("Right",n._1)}c()},G2=t=>{const e=_f(t);if(e.tag==="Left")return e._1;if(e.tag==="Right")return lg;c()},Iu=t=>e=>{const n=ge(r=>r.startT<=e&&e<r.endT)(t.spans);if(n.tag==="Just"){if(n._1.scene.tag==="Structural")return n._1.scene._1.to;if(n._1.scene.tag==="DataFlow")return n._1.scene._1.keyframe;c()}if(n.tag==="Nothing"){const r=t.spans.length-1|0;if(r>=0&&r<t.spans.length){if(t.spans[r].scene.tag==="Structural")return t.spans[r].scene._1.to;if(t.spans[r].scene.tag==="DataFlow")return t.spans[r].scene._1.keyframe;c()}return""}c()},C2=t=>e=>gn(t)("speed")(n=>{const r=Qu(T,jt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return Du("change")(n)((()=>{const i=g2(r._1);return()=>{const o=i(),u=eg(o,Xu,jt,T);if(u.tag==="Just")return e(u._1)();u.tag!=="Nothing"&&c()}})());c()}),S2=t=>e=>n=>gn(t)("scrub")(r=>{const i=Qu(T,jt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return Du("input")(r)((()=>{const o=f2(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*e.totalDuration)()}})());c()}),Q2=t=>e=>n=>{const r=E2(t)(e);return()=>{r(),gn(t)("play")(i=>qi("data-mg-playing")("1")(i))(),C2(t)(n.setSpeed)(),gn(t)("play")(i=>Du("click")(i)(n.toggle))(),S2(t)(e)(n)(),n.subscribe(i=>{const o=k2(t)(i.time)(e.totalDuration);return()=>(o(),gn(t)("time")(u=>o2(Nr(pr("Fixed",mr(0)(20)(2)))(i.time)+" / "+Nr(pr("Fixed",mr(0)(20)(2)))(e.totalDuration))(u))(),gn(t)("play")(u=>qi("data-mg-playing")(i.playing?"1":"0")(u))())})()}},P2=t=>e=>n=>()=>{let r=1,i=!0,o=!1,u=0,s=0;const a={value:M},f={value:0};let g=!1,d=[];Au(t)(n)(e)(a)(f)(0)();const l=y=>()=>{const x=d,v=i,b={time:y,keyframe:Iu(e)(y),playing:v};return L2(E=>E(b))(x)()},_=()=>(i=!1,l(u)()),h=()=>{if(!g&&(o=!1,i)){const y=is(),x=s;s=y;const v=r,b=u,E=v2(x===0?b+0*v:b+(y-x)/1e3*v)(e.totalDuration+.8);return u=E,Au(t)(n)(e)(a)(f)(E)(),l(E)(),p()}},p=()=>{if(!g&&!o){o=!0;const y=a2();_2(h)(y)()}},m=()=>(s=0,i=!0,p()),N=()=>(i||m(),l(u)());return m(),{play:N,pause:_,toggle:()=>i?_():N(),seek:y=>{const x=x2(0)(gf(e.totalDuration)(y));return()=>(u=x,s=0,Au(t)(n)(e)(a)(f)(x)(),l(x)())},setSpeed:y=>()=>r=y,currentTime:()=>u,currentKeyframe:()=>{const y=u;return Iu(e)(y)},isPlaying:()=>i,duration:e.totalDuration,subscribe:y=>()=>{d=oe(d)(y);const x=u,v=i;y({time:x,keyframe:Iu(e)(x),playing:v})();const b=Uu(E=>!N2(E)(y));return()=>{d=b(d)}},destroy:()=>g=!0}},df=t=>e=>{const n=_f(e);if(n.tag==="Left")return rs("[markgraf] parse failed: "+n._1);if(n.tag==="Right")return w2(n._1)(r=>()=>(Pu(b2,t),gn(t)("stage")(i=>{const o=P2(i)(r)(T2);return()=>{const u=o();return Q2(t)(r)(u)()}})()));c()},D2=t=>{const e=t.getAttribute("data-markgraf-src-b64");if(e)try{return decodeURIComponent(escape(atob(e)))}catch{return atob(e)}return t.getAttribute("data-markgraf-src")||t.textContent||""};let Ke=null;const Ru=t=>t.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",A2=t=>{const e=t.querySelector('[data-mg="play"]');if(!e)return;e.addEventListener("click",()=>{queueMicrotask(()=>{Ru(t)?(Ke&&Ke!==t&&Ru(Ke)&&Ke.querySelector('[data-mg="play"]').click(),Ke=t):Ke===t&&(Ke=null)})});const n=r=>{r.preventDefault(),e.click()};t.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},I2=t=>{if(t.dataset.markgrafMounted==="1")return;t.dataset.markgrafMounted="1";const e=D2(t);t.textContent="",df(t)(e)(),Ke===null?Ke=t:Ru(t)&&t.querySelector('[data-mg="play"]').click(),A2(t)},Hi=(t=document)=>{t.querySelectorAll("[data-markgraf]").forEach(I2)},lf=()=>{document.addEventListener("keydown",t=>{if(t.code!=="Space"&&t.key!==" ")return;const e=t.target,n=e&&e.closest?.("[data-markgraf]");if(!n){const i=e?.tagName,o=(e?.type||"").toLowerCase();if(e?.isContentEditable||i==="TEXTAREA"||i==="SELECT"||i==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(o))return}const r=n||Ke||document.querySelector("[data-markgraf]");r&&(t.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};if(typeof window<"u"){const t=e=>{const n=G2(e);return n==null?{ok:!0}:{ok:!1,error:n}};window.markgraf={mount:(e,n)=>df(e)(n)(),mountAll:Hi,tryParse:t},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Hi(),lf()}):(Hi(),lf())}return Wi.mountAll=Hi,Object.defineProperty(Wi,Symbol.toStringTag,{value:"Module"}),Wi})({});
|