@markgrafhq/markgraf-embed 0.1.2 → 0.1.4

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.
@@ -1,16 +1,16 @@
1
- var mm=(function(ko){"use strict";function cc(e){let t=0,n;return()=>{if(t===2)return n;if(t===1)throw new Error("Binding demanded before initialized");return t=1,n=e(),t=2,n}}function f(){throw new Error("Failed pattern match")}function En(e,t){return t>0?Math.floor(e/t):t<0?-Math.floor(e/-t):0}const Te=function(e){return e.toString()},fu=function(e){var t=e.toString();return isNaN(t+".0")?t:t+".0"},fc=function(e){var t=e.length;return'"'+e.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 o=r+1,i=o<t&&e[o]>="0"&&e[o]<="9"?"\\&":"";return"\\"+n.charCodeAt(0).toString(10)+i})+'"'},bo=e=>e,Re=bo("LT"),Qe=bo("GT"),Fe=bo("EQ"),b=(e,t)=>({tag:e,_1:t}),T=b("Nothing"),Kt=e=>b("Just",e),gu=e=>{if(e.tag==="Nothing")return!0;if(e.tag==="Just")return!1;f()},gc=e=>{if(e.tag==="Nothing")return!1;if(e.tag==="Just")return!0;f()},wt=(e,t)=>({tag:e,_1:t}),_c=e=>wt("Right",e),dc={map:e=>t=>{if(t.tag==="Left")return wt("Left",t._1);if(t.tag==="Right")return wt("Right",e(t._1));f()}},_u={apply:e=>t=>{if(e.tag==="Left")return wt("Left",e._1);if(e.tag==="Right"){if(t.tag==="Left")return wt("Left",t._1);if(t.tag==="Right")return wt("Right",e._1(t._1))}f()},Functor0:()=>dc},lc={bind:e=>{if(e.tag==="Left"){const t=e._1;return n=>wt("Left",t)}if(e.tag==="Right"){const t=e._1;return n=>n(t)}f()},Apply0:()=>_u},hc={pure:_c,Apply0:()=>_u},pc={Applicative0:()=>hc,Bind1:()=>lc},he=e=>t=>e,V=function(e){return function(t){for(var n=t.length,r=new Array(n),o=0;o<n;o++)r[o]=e(t[o]);return r}},mc={map:V},du=e=>e,jn=function(e){return function(t){return function(n){for(var r=t,o=n.length,i=o-1;i>=0;i--)r=e(n[i])(r);return r}}},y=function(e){return function(t){return function(n){for(var r=t,o=n.length,i=0;i<o;i++)r=e(r)(n[i]);return r}}},yc=e=>{const t=e.Apply0();return n=>r=>n.foldr(o=>{const i=r(o);return u=>t.apply(t.Functor0().map(s=>du)(i))(u)})(e.pure())},It={foldr:jn,foldl:y,foldMap:e=>{const t=e.mempty;return n=>It.foldr(r=>o=>e.Semigroup0().append(n(r))(o))(t)}},lu=isFinite;function Jc(e,t,n,r){var o=parseFloat(e);return t(o)?n(o):r}const hu=Math.abs,Nc=Math.ceil,Eo=Math.cos,pu=Math.exp,mu=Math.floor,Co=function(e){return function(t){return Math.pow(e,t)}},yu=Math.round,So=Math.sin,Cn=Math.sqrt,xc=function(e){return function(t){return function(n){return(n|0)===n?e(n):t}}},_t=function(e){return e},vc=(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 o=new RegExp("^[\\+\\-]?"+r+"+$","i");return function(i){if(o.test(i)){var u=parseInt(i,n);return(u|0)===u?e(u):t}else return t}}}})(Kt)(T)(10),Ju=xc(Kt)(T),tr=e=>{if(!lu(e))return 0;if(e>=_t(2147483647))return 2147483647;if(e<=_t(-2147483648))return-2147483648;const t=Ju(e);if(t.tag==="Nothing")return 0;if(t.tag==="Just")return t._1;f()},x=(e,t)=>({tag:"Tuple",_1:e,_2:t}),Sn=e=>t=>x(e,t),Po=e=>e._2,Mr=e=>e._1,Qt=(e,t,n)=>({tag:e,_1:t,_2:n}),Bt=Qt("Nil"),qt={foldr:e=>t=>{const n=qt.foldl(o=>i=>e(i)(o))(t),r=(o=>i=>{let u=o,s=i,a=!0,c;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,c=g;continue}if(d.tag==="Cons"){u=Qt("Cons",d._1,g),s=d._2;continue}f()}return c})(Bt);return o=>n(r(o))},foldl:e=>t=>n=>{let r=t,o=n,i=!0,u;for(;i;){const s=r,a=o;if(a.tag==="Nil"){i=!1,u=s;continue}if(a.tag==="Cons"){r=e(s)(a._1),o=a._2;continue}f()}return u},foldMap:e=>{const t=e.mempty;return n=>qt.foldl(r=>{const o=e.Semigroup0().append(r);return i=>o(n(i))})(t)}},Tc=function(e){return function(t){return function(n){return function(r){return function(o){return function(i){for(var u=[],s=i;;){var a=o(s);u.push(n(a));var c=r(a);if(e(c))return u;s=t(c)}}}}}}},Lc=e=>{if(e.tag==="Just")return e._1;f()},wc={unfoldr1:Tc(gu)(Lc)(Mr)(Po)},kc=function(e){return function(t){return function(n){return function(r){return function(o){return function(i){for(var u=[],s=i;;){var a=o(s);if(e(a))return u;var c=t(a);u.push(n(c)),s=r(c)}}}}}}},bc=e=>{if(e.tag==="Just")return e._1;f()},Pe={unfoldr:kc(gu)(bc)(Mr)(Po),Unfoldable10:()=>wc},Yt=(e,t,n,r,o,i,u)=>({tag:e,_1:t,_2:n,_3:r,_4:o,_5:i,_6:u}),Ge=(e,t,n,r)=>({tag:e,_1:t,_2:n,_3:r}),Wr=(e,t,n)=>({tag:"Split",_1:e,_2:t,_3:n}),Nu=(e,t,n)=>({tag:"SplitLast",_1:e,_2:t,_3:n}),D=Yt("Leaf"),_n=Ge("IterLeaf"),Zt=(e,t,n,r)=>{if(n.tag==="Leaf"){if(r.tag==="Leaf")return Yt("Node",1,1,e,t,n,r);if(r.tag==="Node")return Yt("Node",1+r._1|0,1+r._2|0,e,t,n,r);f()}if(n.tag==="Node"){if(r.tag==="Leaf")return Yt("Node",1+n._1|0,1+n._2|0,e,t,n,r);if(r.tag==="Node")return Yt("Node",n._1>r._1?1+n._1|0:1+r._1|0,(1+n._2|0)+r._2|0,e,t,n,r)}f()},fe=(e,t,n,r)=>{if(n.tag==="Leaf")return r.tag==="Leaf"?Yt("Node",1,1,e,t,D,D):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;f()})()?Zt(r._5._3,r._5._4,Zt(e,t,n,r._5._5),Zt(r._3,r._4,r._5._6,r._6)):Zt(r._3,r._4,Zt(e,t,n,r._5),r._6):Zt(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;f()})()?Zt(r._5._3,r._5._4,Zt(e,t,n,r._5._5),Zt(r._3,r._4,r._5._6,r._6)):Zt(r._3,r._4,Zt(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;f()})()?Zt(n._6._3,n._6._4,Zt(n._3,n._4,n._5,n._6._5),Zt(e,t,n._6._6,r)):Zt(n._3,n._4,n._5,Zt(e,t,n._6,r)):Zt(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;f()})()?Zt(n._6._3,n._6._4,Zt(n._3,n._4,n._5,n._6._5),Zt(e,t,n._6._6,r)):Zt(n._3,n._4,n._5,Zt(e,t,n._6,r)):Zt(e,t,n,r);f()},Pn=(e,t,n)=>{if(n.tag==="Leaf")return Wr(T,D,D);if(n.tag==="Node"){const r=e(t)(n._3);if(r==="LT"){const o=Pn(e,t,n._5);return Wr(o._1,o._2,fe(n._3,n._4,o._3,n._6))}if(r==="GT"){const o=Pn(e,t,n._6);return Wr(o._1,fe(n._3,n._4,n._5,o._2),o._3)}if(r==="EQ")return Wr(b("Just",n._4),n._5,n._6)}f()},xu=(e,t,n,r)=>{if(r.tag==="Leaf")return Nu(e,t,n);if(r.tag==="Node"){const o=xu(r._3,r._4,r._5,r._6);return Nu(o._1,o._2,fe(e,t,n,o._3))}f()},Gn=(e,t)=>{if(e.tag==="Leaf")return t;if(e.tag==="Node"){const n=xu(e._3,e._4,e._5,e._6);return fe(n._1,n._2,n._3,t)}f()},He=(e,t,n)=>{if(t.tag==="Leaf")return D;if(n.tag==="Leaf")return t;if(n.tag==="Node"){const r=Pn(e,n._3,t);return Gn(He(e,r._2,n._5),He(e,r._3,n._6))}f()},Rr=(e,t,n,r)=>{if(n.tag==="Leaf"||r.tag==="Leaf")return D;if(r.tag==="Node"){const o=Pn(e,r._3,n),i=Rr(e,t,o._2,r._5),u=Rr(e,t,o._3,r._6);if(o._1.tag==="Just")return fe(r._3,t(o._1._1)(r._4),i,u);if(o._1.tag==="Nothing")return Gn(i,u)}f()},pe=(e,t,n,r)=>{if(n.tag==="Leaf")return r;if(r.tag==="Leaf")return n;if(r.tag==="Node"){const o=Pn(e,r._3,n),i=pe(e,t,o._2,r._5),u=pe(e,t,o._3,r._6);if(o._1.tag==="Just")return fe(r._3,t(o._1._1)(r._4),i,u);if(o._1.tag==="Nothing")return fe(r._3,r._4,i,u)}f()},Ec=e=>t=>n=>{const r=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node"){const i=e.compare(n)(o._3);if(i==="LT")return fe(o._3,o._4,r(o._5),o._6);if(i==="GT")return fe(o._3,o._4,o._5,r(o._6));if(i==="EQ"){const u=t(o._4);if(u.tag==="Nothing")return Gn(o._5,o._6);if(u.tag==="Just")return Yt("Node",o._1,o._2,o._3,u._1,o._5,o._6)}}f()};return r},Cc=e=>t=>{const n=r=>{if(r.tag==="Leaf")return D;if(r.tag==="Node"){const o=t(r._3)(r._4);if(o.tag==="Just")return fe(r._3,o._1,n(r._5),n(r._6));if(o.tag==="Nothing")return Gn(n(r._5),n(r._6))}f()};return n},dn=(e=>t=>n=>{let r=n,o=!0,i;for(;o;){const u=r;if(u.tag==="IterLeaf"){o=!1,i=t();continue}if(u.tag==="IterEmit"){o=!1,i=e(u._1,u._2,u._3);continue}if(u.tag==="IterNode"){r=(s=>a=>{let c=s,g=a,d=!0,l;for(;d;){const _=c,h=g;if(h.tag==="Leaf"){d=!1,l=_;continue}if(h.tag==="Node"){if(h._6.tag==="Leaf"){c=Ge("IterEmit",h._3,h._4,_),g=h._5;continue}c=Ge("IterEmit",h._3,h._4,Ge("IterNode",h._6,_)),g=h._5;continue}f()}return l})(u._2)(u._1);continue}f()}return i})((e,t,n)=>b("Just",x(x(e,t),n)))(e=>T),xt=e=>t=>n=>r=>{const o=i=>{if(i.tag==="Leaf")return Yt("Node",1,1,n,r,D,D);if(i.tag==="Node"){const u=e.compare(n)(i._3);if(u==="LT")return fe(i._3,i._4,o(i._5),i._6);if(u==="GT")return fe(i._3,i._4,i._5,o(i._6));if(u==="EQ")return Yt("Node",i._1,i._2,n,t(i._4)(r),i._5,i._6)}f()};return o},Z=e=>t=>n=>{const r=o=>{if(o.tag==="Leaf")return Yt("Node",1,1,t,n,D,D);if(o.tag==="Node"){const i=e.compare(t)(o._3);if(i==="LT")return fe(o._3,o._4,r(o._5),o._6);if(i==="GT")return fe(o._3,o._4,o._5,r(o._6));if(i==="EQ")return Yt("Node",o._1,o._2,t,n,o._5,o._6)}f()};return r},jt=e=>t=>t.foldl(n=>r=>Z(e)(r._1)(r._2)(n))(D),er=e=>t=>{const n=r=>{if(r.tag==="Leaf")return D;if(r.tag==="Node"){const o=e.compare(t)(r._3);if(o==="LT")return fe(r._3,r._4,n(r._5),r._6);if(o==="GT")return fe(r._3,r._4,r._5,n(r._6));if(o==="EQ")return Gn(r._5,r._6)}f()};return n},Sc=e=>{const t=e.compare;return n=>r=>o=>{const i=Pn(t,r,o),u=n(i._1);if(u.tag==="Nothing")return Gn(i._2,i._3);if(u.tag==="Just")return fe(r,u._1,i._2,i._3);f()}},Ut=function(e){return function(t){return e+t|0}},nr=function(e){return function(t){return e+t}},Go=function(e){return function(t){if(t===0)return 0;var n=Math.abs(t);return(e%n+n)%n}},Pc=function(e){return function(t){return e+t}},ie=function(e){return function(t){return e.length===0?t:t.length===0?e:e.concat(t)}},Gc={append:Pc},zc={mempty:"",Semigroup0:()=>Gc};function Mc(e,t,n){return e==null?t:n(e)}var zo=function(e){return function(t){return e===t}};const Wc=zo,Rc=zo,Mo=zo,Qc=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}}},Ve={eq:Mo},Ic={eq:Rc},Wo={eq:Wc};var Ro=function(e){return function(t){return function(n){return function(r){return function(o){return r<o?e:r===o?t:n}}}}};const Bc=Ro,Ac=Ro,w={compare:Ro(Re)(Fe)(Qe),Eq0:()=>Ve},lt={compare:Ac(Re)(Fe)(Qe),Eq0:()=>Ic},ot={compare:Bc(Re)(Fe)(Qe),Eq0:()=>Wo};function Qo(e){return function(t){return function(n){return e.apply(n,[t])}}}const Dc=Qo(Number.prototype.toPrecision),qc=Qo(Number.prototype.toFixed),Yc=Qo(Number.prototype.toExponential),Io=(e,t)=>({tag:e,_1:t}),Bo=e=>t=>n=>{const r=ot.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;f()})(),i=ot.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;f()},Ao=e=>{if(e.tag==="Precision")return Dc(e._1);if(e.tag==="Fixed")return qc(e._1);if(e.tag==="Exponential")return Yc(e._1);f()},vu=function(e){return function(){console.log(e)}};function Tu(){return Date.now()}function $c(e){return function(){return e.getContext("2d")}}function Fc(e){return function(){return e.width}}function Hc(e){return function(){return e.height}}function Vc(e){return function(t){return function(){e.width=t}}}function Xc(e){return function(t){return function(){e.height=t}}}function Do(e){return function(t){return function(){e.lineWidth=t}}}function Oc(e){return function(t){return function(){e.fillStyle=t}}}function Uc(e){return function(t){return function(){e.strokeStyle=t}}}function qo(e){return function(t){return function(){e.lineCap=t}}}function Yo(e){return function(t){return function(){e.lineJoin=t}}}function Kc(e){return function(t){return function(){e.globalCompositeOperation=t}}}function Zc(e){return function(t){return function(){e.globalAlpha=t}}}function Lu(e){return function(){e.beginPath()}}function $o(e){return function(){e.stroke()}}function Fo(e){return function(){e.fill()}}function jc(e){return function(){e.clip()}}function tf(e){return function(t){return function(n){return function(){e.lineTo(t,n)}}}}function ef(e){return function(t){return function(n){return function(){e.moveTo(t,n)}}}}function nf(e){return function(){e.closePath()}}function rf(e){return function(t){return function(){e.fillRect(t.x,t.y,t.width,t.height)}}}function of(e){return function(t){return function(){e.clearRect(t.x,t.y,t.width,t.height)}}}function Ho(e){return function(t){return function(){e.scale(t.scaleX,t.scaleY)}}}function wu(e){return function(t){return function(){e.translate(t.translateX,t.translateY)}}}function uf(e){return function(t){return function(){e.textAlign=t}}}function sf(e){return function(t){return function(){e.textBaseline=t}}}function af(e){return function(t){return function(){e.font=t}}}function cf(e){return function(t){return function(n){return function(r){return function(){e.fillText(t,n,r)}}}}}function rr(e){return function(){e.save()}}function or(e){return function(){e.restore()}}function ff(e){return function(t){return function(){e.quadraticCurveTo(t.cpx,t.cpy,t.x,t.y)}}}function gf(e){return function(t){return function(){e.bezierCurveTo(t.cp1x,t.cp1y,t.cp2x,t.cp2y,t.x,t.y)}}}const ku=e=>e,Vo=e=>e,Xo=e=>e,Oo=e=>e,Qr=e=>e,_f=Qr("BaselineTop"),df=Qr("BaselineMiddle"),lf=Qr("BaselineAlphabetic"),hf=Qr("BaselineBottom"),pf=Oo("AlignLeft"),mf=Oo("AlignRight"),yf=Oo("AlignCenter"),Uo=Xo("BevelJoin"),Ir=Xo("RoundJoin"),Ko=Xo("MiterJoin"),Zo=Vo("Round"),jo=Vo("Square"),ti=Vo("Butt"),Jf=ku("SourceOver"),Nf=ku("Difference"),xf=e=>t=>sf(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";f()})()),vf=e=>t=>uf(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";f()})()),Br=e=>t=>{if(t==="BevelJoin")return Yo(e)("bevel");if(t==="RoundJoin")return Yo(e)("round");if(t==="MiterJoin")return Yo(e)("miter");f()},ei=e=>t=>{if(t==="Round")return qo(e)("round");if(t==="Square")return qo(e)("square");if(t==="Butt")return qo(e)("butt");f()},bu=e=>t=>Kc(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";f()})()),Ct=typeof Array.prototype.flatMap=="function"?function(e){return function(t){return e.flatMap(t)}}:function(e){return function(t){for(var n=[],r=e.length,o=0;o<r;o++)for(var i=t(e[o]),u=i.length,s=0;s<u;s++)n.push(i[s]);return n}},Tf=e=>e,Lf={map:e=>t=>e(t)},Eu={apply:e=>t=>e(t),Functor0:()=>Lf},wf={bind:e=>t=>t(e),Apply0:()=>Eu},kf={pure:Tf,Apply0:()=>Eu},rn={Applicative0:()=>kf,Bind1:()=>wf},bf=function(e){return function(){return e}},Ef={apply:e=>t=>()=>{const n=e(),r=t();return Cu.pure(n(r))()},Functor0:()=>Cf},Cu={pure:bf,Apply0:()=>Ef},Cf={map:e=>t=>()=>{const n=t();return e(n)}},ir=(e,t)=>({tag:e,_1:t}),Su=e=>ir("Loop",e),Sf={tailRecM:e=>{const t=n=>{let r=n,o=!0,i;for(;o;){const u=r;if(u.tag==="Loop"){r=e(u._1);continue}if(u.tag==="Done"){o=!1,i=u._1;continue}f()}return i};return n=>t(e(n))},Monad0:()=>rn},Pf=(function(e){return function(t){return function(n){return function(){return e(t,n)}}}})(function(e,t){return t.push(e)}),Gf=(e,t)=>({tag:"Iterator",_1:e,_2:t}),zf=e=>t=>n=>()=>{let r=!1;const o=t._2;for(;!r;){const i=o.value,u=t._1(i);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}},Mf=e=>t=>()=>{let n=!1;const r=e._2;for(;!n;){const o=r.value,i=r.value;r.value=i+1|0;const u=e._1(o);if(u.tag==="Just"){t(u._1)();continue}if(u.tag==="Nothing"){n=!0;continue}f()}},zt=function(e){return function(t){for(var n=t.length,r=Array(n),o=0;o<n;o++)r[o]=e(o)(t[o]);return r}},Pu=function(e){return e},Wf=(function(){function e(o){return[o]}function t(o){return function(i){return[o,i]}}function n(o){return function(i){return function(u){return[o,i,u]}}}function r(o){return function(i){return o.concat(i)}}return function(o){return function(i){return function(u){return function(s){return function(a){function c(g,d){switch(d-g){case 0:return u([]);case 1:return i(e)(s(a[g]));case 2:return o(i(t)(s(a[g])))(s(a[g+1]));case 3:return o(o(i(n)(s(a[g])))(s(a[g+1])))(s(a[g+2]));default:var l=g+Math.floor((d-g)/4)*2;return o(i(r)(c(g,l)))(c(l,d))}}return c(0,a.length)}}}}}})(),Rf=e=>e,Ar={traverse:e=>{const t=e.Apply0();return Wf(t.apply)(t.Functor0().map)(e.pure)},sequence:e=>Ar.traverse(e)(Rf),Functor0:()=>mc,Foldable1:()=>It},$t=function(e,t){for(var n=e>t?-1:1,r=new Array(n*(t-e)+1),o=e,i=0;o!==t;)r[i++]=o,o+=n;return r[i]=o,r};var Qf=function(e,t){if(e<1)return[];var n=new Array(e);return n.fill(t)},If=function(e,t){for(var n=[],r=0,o=0;o<e;o++)n[r++]=t;return n};const Bf=typeof Array.prototype.fill=="function"?Qf:If,Lt=(function(){function e(o,i){this.head=o,this.tail=i}var t={};function n(o){return function(i){return new e(o,i)}}function r(o){for(var i=[],u=0,s=o;s!==t;)i[u++]=s.head,s=s.tail;return i}return function(o,i){return r(o(n)(t)(i))}})(),Ft=function(e,t,n){return n.length===0?e({}):t(n[0])(n.slice(1))},Af=function(e,t,n,r){for(var o=0;o<r.length;o++){var i=n(r[o]);if(t(i))return i}return e},ur=function(e,t,n,r){for(var o=0,i=r.length;o<i;o++)if(n(r[o]))return e(o);return t},Df=function(e,t,n,r){for(var o=r.length-1;o>=0;o--)if(n(r[o]))return e(o);return t},qf=function(e,t,n,r,o){if(n<0||n>o.length)return t;var i=o.slice();return i.splice(n,0,r),e(i)},Gu=function(e,t,n,r){if(n<0||n>=r.length)return t;var o=r.slice();return o.splice(n,1),e(o)},sr=function(e,t,n,r,o){if(n<0||n>=o.length)return t;var i=o.slice();return i[n]=r,e(i)},_e=function(e){return e.slice().reverse()},Ne=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 o=e[n],i=0,u=o.length;i<u;i++)t.push(o[i]);return t},at=function(e,t){return t.filter(e)},Yf=(function(){function e(t,n,r,o,i,u){var s,a,c,g,d,l,_;for(s=i+(u-i>>1),s-i>1&&e(t,n,o,r,i,s),u-s>1&&e(t,n,o,r,s,u),a=i,c=s,g=i;a<s&&c<u;)d=o[a],l=o[c],_=n(t(d)(l)),_>0?(r[g++]=l,++c):(r[g++]=d,++a);for(;a<s;)r[g++]=o[a++];for(;c<u;)r[g++]=o[c++]}return function(t,n,r){var o;return r.length<2?r:(o=r.slice(0),e(t,n,o,r.slice(0),0,r.length),o)}})(),Mt=function(e,t,n){return n.slice(e,t)},me=function(e,t,n){for(var r=t.length<n.length?t.length:n.length,o=new Array(r),i=0;i<r;i++)o[i]=e(t[i])(n[i]);return o},on=function(e,t){for(var n=t.length,r=0;r<n;r++)if(e(t[r]))return!0;return!1},zu=function(e,t){for(var n=t.length,r=0;r<n;r++)if(!e(t[r]))return!1;return!0},vt=e=>t=>Yf(e,n=>{if(n==="GT")return 1;if(n==="EQ")return 0;if(n==="LT")return-1;f()},t),$f=e=>t=>vt(n=>r=>e.compare(t(n))(t(r))),ye=e=>t=>(()=>{const n=Pf(t);return()=>{const r=[...e];return n(r)(),r}})()(),Ff=e=>{if(e.length===0)return e.length-1|0,T;const t=e.length-1|0;return t>=0&&t<e.length?b("Just",{init:Mt(0,e.length-1|0,e),last:e[t]}):T},Hf=e=>t=>n=>e>=0&&e<n.length?sr(Kt,T,e,t(n[e]),n):T,ln=e=>t=>{const n=(r=>{let o=r,i=!0,u;for(;i;){const s=o;if(s>=0&&s<t.length){if(e(t[s])){o=s+1|0;continue}i=!1,u=b("Just",s);continue}i=!1,u=T}return u})(0);if(n.tag==="Just")return n._1===0?{init:[],rest:t}:{init:Mt(0,n._1,t),rest:Mt(n._1,t.length,t)};if(n.tag==="Nothing")return{init:t,rest:[]};f()},zn=e=>t=>{const n=vt(r=>o=>e(r._2)(o._2))(zt(Sn)(t));return 0<n.length?V(Po)($f(ot)(Mr)((()=>{const r=[n[0]];for(const o of n){const i=e((()=>{const u=r.length-1|0;if(u>=0&&u<r.length)return r[u]._2;f()})())(o._2);(i==="LT"||i==="GT"||i!=="EQ")&&r.push(o)}return r})())):[]},Vf=e=>t=>{const n=[],r=Gf(o=>o>=0&&o<t.length?b("Just",t[o]):T,{value:0});return Mf(r)(o=>()=>{const i=[];i.push(o),zf(e(o))(r)(i)(),n.push(i)})(),n},ge=e=>t=>{const n=ur(Kt,T,e,t);return n.tag==="Just"?b("Just",t[n._1]):T},Xf=e=>t=>at(e,t),Ie=e=>t=>n=>{const r=ur(Kt,T,o=>e.eq(o)(t),n);if(r.tag==="Nothing")return!1;if(r.tag==="Just")return!0;f()},Mu=e=>t=>Ct(t)(e),St=e=>Mu(t=>{const n=e(t);if(n.tag==="Nothing")return[];if(n.tag==="Just")return[n._1];f()}),Le={foldr:e=>t=>{const n=qt.foldr(e)(t);return r=>n((()=>{const o=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return o(i._5,Qt("Cons",i._3,o(i._6,u)));f()};return o(r,Bt)})())}},Dr=e=>e,Of=e=>e,Uf=Dr("Linear"),Kf=Dr("EaseInOutQuad"),Zf=Dr("EaseOutExpo"),jf=Dr("SpringBouncy"),ar=e=>t=>n=>{const r=Cn(1-t*t),o=e*r;return 1-pu(-t*e*n)*(Eo(o*n)+t/r*So(o*n))},tg=e=>{const t=lt.compare(0)(e),n=(()=>{if(t==="LT")return e;if(t==="EQ"||t==="GT")return 0;f()})(),r=lt.compare(1)(n);if(r==="LT"||r==="EQ")return 1;if(r==="GT")return n;f()},ni=e=>t=>(()=>{if(e==="Linear")return Of;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-Co(2)(-10*n);if(e==="Spring")return n=>1-(1+6*n)*pu(-6*n);if(e==="SpringBouncy")return ar(6)(.7);f()})()(tg(t)),Wu=y(nr)(0),eg=e=>t=>n=>{const r=lt.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;f()})(),i=lt.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;f()},Ru=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},Qu=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},Iu=e=>t=>{const n=me(u=>s=>({a:u,b:s,len:(()=>{const a=s.y-u.y,c=s.x-u.x;return Cn(c*c+a*a)})()}),e,Mt(1,e.length,e)),r=Wu(V(u=>u.len)(n)),o=eg(0)(r)(t*r),i=u=>s=>a=>{let c=u,g=s,d=a,l=!0,_;for(;l;){const h=c,m=g,p=d,J=Ft(N=>T,N=>v=>b("Just",{head:N,tail:v}),h);if(J.tag==="Nothing"){const N=e.length-1|0;if(N>=0&&N<e.length){l=!1,_=e[N];continue}l=!1,_=p;continue}if(J.tag==="Just"){if(m<=J._1.head.len){const N=J._1.head.len<=0?0:m/J._1.head.len;l=!1,_={x:J._1.head.a.x+(J._1.head.b.x-J._1.head.a.x)*N,y:J._1.head.a.y+(J._1.head.b.y-J._1.head.a.y)*N};continue}c=J._1.tail,g=m-J._1.head.len,d=p;continue}f()}return _};return 0<e.length?b("Just",i(n)(o)(e[0])):T},ri=e=>Wu(me(t=>n=>{const r=n.y-t.y,o=n.x-t.x;return Cn(o*o+r*r)},e,Mt(1,e.length,e))),un=e=>{const t=Ft(n=>T,n=>r=>b("Just",{head:n,tail:r}),[...(()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Qt("Cons",r._4,n(r._6,o)));f()};return Ct(Lt(qt.foldr,n(e.nodes,Bt)))(r=>[{x:r.x,y:r.y},{x:r.x+r.w,y:r.y+r.h}])})(),...Ne((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Qt("Cons",r._4,n(r._6,o)));f()};return Lt(qt.foldr,n(e.edges,Bt))})()),...Ne((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Qt("Cons",r._4,n(r._6,o)));f()};return Lt(qt.foldr,n(e.chipExtras,Bt))})())]);if(t.tag==="Nothing")return{x:0,y:0,w:0,h:0};if(t.tag==="Just"){const n=y(r=>o=>({minX:Ru(r.minX)(o.x),minY:Ru(r.minY)(o.y),maxX:Qu(r.maxX)(o.x),maxY:Qu(r.maxY)(o.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}}f()},cr=function(e){return function(t){if(e>=0&&e<t.length)return t.charAt(e);throw new Error("Data.String.Unsafe.charAt: Invalid index.")}},Mn=function(e){return e.join("")},Bu=function(e){return e.split("")},oi=function(e){return e},hn=function(e){return e.length},Au=function(e){return function(t){return t.substr(0,e)}},fr=function(e){return function(t){return t.substring(e)}},ng=function(e){return function(t){return{before:t.substring(0,e),after:t.substring(e)}}},rg=e=>t=>{const n=ng(hn(e))(t);return n.before===e?b("Just",n.after):T},og=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},ig=e=>t=>n=>{try{var r=BigInt(n);return e(r)}catch{return t}},pn=e=>BigInt(e),ug=e=>Number(e),qr=e=>t=>e+t,Yr=e=>t=>e*t,ii=e=>t=>e-t,Du=0n,$r=1n,qu=e=>t=>e^t,gr=e=>t=>e&t,ui=e=>t=>e<<t,si=e=>t=>e>>t,sg=e=>t=>e==t,ag=e=>t=>e===t?0:e>t?1:-1,cg={eq:sg},Yu={compare:e=>t=>{const n=ag(e)(t);return n===1?Qe:n===0?Fe:Re},Eq0:()=>cg},fg=og(Kt)(T),gg=ig(Kt)(T),_g=e=>t=>hu(e._1-t._1)+hu(e._2-t._2),Fr=e=>e,ue=Fr("North"),se=Fr("South"),mn=Fr("East"),yn=Fr("West"),$u=e=>e,Fu=(e,t)=>({tag:e,_1:t}),Hu=(e,t)=>({tag:e,_1:t}),ai=(e,t)=>({tag:e,_1:t}),dg=ai("First"),lg=$u("Forward"),hg=$u("Backward"),pg=jt(w)(It),mg=e=>jn(t=>n=>({nodes:pe(w.compare,he,t.nodes,n.nodes),edges:pe(w.compare,he,t.edges,n.edges)}))({nodes:D,edges:D})(e.keyframes),yg=e=>t=>({entering:{nodes:He(w.compare,t.nodes,e.nodes),edges:He(w.compare,t.edges,e.edges)},leaving:{nodes:He(w.compare,e.nodes,t.nodes),edges:He(w.compare,e.edges,t.edges)},surviving:{nodes:Rr(w.compare,he,e.nodes,t.nodes),edges:Rr(w.compare,he,e.edges,t.edges)}}),Vu=e=>e,ci=e=>t=>n=>{const r=lt.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;f()})(),i=lt.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;f()},Jn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},Wn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},Rn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},fi=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Jg=y(e=>t=>Z(w)(t)()(e))(D),Ng=y(e=>t=>Z(w)(t)()(e))(D),xg=(()=>{const e=Pe.unfoldr(dn);return t=>e(Ge("IterNode",t,_n))})(),Xu=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Ou=jt(w)(It),vg=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},Tg=Vu("Hold"),Lg=Vu("Gap"),wg=e=>t=>n=>{const r=n.center.y-t.center.y,o=n.center.x-t.center.x,i=Cn(o*o+r*r),u=n.zoom-t.zoom,s=u<0?-u:u;return ci(e.minTransition)(e.maxTransition)(Jn(e.panSpeed<=0?e.minTransition:i/e.panSpeed)(e.zoomSpeed<=0?e.minTransition:s/e.zoomSpeed))},kg=y(e=>t=>{const n=e.length-1|0;return n>=0&&n<e.length&&e[n]===t?e:ye(e)(t)})([]),gi=e=>{const t=Ft(n=>T,n=>r=>b("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=>o=>({minX:Wn(r.minX)(o.x),minY:Wn(r.minY)(o.y),maxX:Jn(r.maxX)(o.x),maxY:Jn(r.maxY)(o.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}}f()},Uu=e=>{const t=Ft(n=>T,n=>r=>b("Just",{head:n,tail:r}),e);if(t.tag==="Nothing")return T;if(t.tag==="Just")return b("Just",gi(e));f()},bg=e=>t=>n=>Jg(Ct(Lt(Le.foldr,n))(r=>{const o=Rn(r)(e);if(o.tag==="Just")return at(i=>!fi(i)(t),[o._1.source,o._1.target]);if(o.tag==="Nothing")return[];f()})),Eg=e=>t=>n=>{const r=ni(e.easing)(ci(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}},Cg=e=>t=>n=>r=>{const o=(u,s)=>Wn(wg(e)(u.toCam)(s.toCam))(u.endT-u.startT),i=y(u=>s=>{if(u.pending.tag==="Nothing")return{acc:u.acc,pending:b("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 c=u.pending._1.toCam.center.y-s.toCam.center.y;return(c<0?-c<8:c<8)&&(()=>{const g=u.pending._1.toCam.zoom-s.toCam.zoom;return g<0?-g<.08:g<.08})()})()})()||o(u.pending._1,s)<=0?{acc:ye(u.acc)(u.pending._1),pending:b("Just",s)}:{acc:ye(ye(u.acc)({...u.pending._1,endT:s.startT-o(u.pending._1,s)}))({startT:s.startT-o(u.pending._1,s),endT:s.startT,fromCam:u.pending._1.toCam,toCam:s.toCam}),pending:b("Just",s)};f()})({acc:[],pending:T})(r);if(i.pending.tag==="Nothing")return i.acc;if(i.pending.tag==="Just")return ye(i.acc)(i.pending._1);f()},Sg=e=>e.kind.tag==="SendToken"?b("Just",x(e.kind._1.edge,{source:e.kind._1.from,target:e.kind._1.to})):T,Pg=e=>e.tag==="DataFlow"?St(Sg)(e._1.events):[],Gg=e=>t=>Ng(St(n=>fi(n._2.source)(t)||fi(n._2.target)(t)?b("Just",n._1):T)(xg(e))),zg=e=>t=>{const n=r=>{const o=Df(Kt,T,i=>i.kind==="Hold",r<1?[]:Mt(0,r,t));if(o.tag==="Just")return o._1>=0&&o._1<t.length?b("Just",t[o._1].cam):T;if(o.tag==="Nothing")return T;f()};return zt(r=>o=>{if(o.kind==="Hold")return{startT:o.startT,endT:o.endT,fromCam:o.cam,toCam:o.cam};if(o.kind==="Gap")return{startT:o.startT,endT:o.endT,fromCam:(()=>{const i=n(r);if(i.tag==="Nothing")return e;if(i.tag==="Just")return i._1;f()})(),toCam:(()=>{const i=n(r),u=(()=>{if(i.tag==="Nothing")return e;if(i.tag==="Just")return i._1;f()})(),s=r+1|0,a=ur(Kt,T,c=>c.kind==="Hold",s<1?t:Mt(s,t.length,t));if(a.tag==="Just"){const c=(r+1|0)+a._1|0;return c>=0&&c<t.length?t[c].cam:u}if(a.tag==="Nothing")return u;f()})()};f()})(t)},Ku={padding:24,easing:Zf,minZoom:.9,maxZoom:2.5,panSpeed:700,zoomSpeed:1.5,minTransition:.3,maxTransition:1.4},Mg=e=>t=>n=>{const r=t.w+n*2,o=t.h+n*2,i=un(e);return r<=0||o<=0||i.w<=0||i.h<=0?1:Wn(i.w/r)(i.h/o)},_i=e=>{const t=Ft(n=>T,n=>r=>b("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=>o=>({minX:Wn(r.minX)(o.x),minY:Wn(r.minY)(o.y),maxX:Jn(r.maxX)(o.x+o.w),maxY:Jn(r.maxY)(o.y+o.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}}f()},Zu=e=>t=>n=>{if(n.tag==="Leaf")return un(e);const r=Gg(t)(n),o=[...St(i=>{const u=Xu(i)(e.nodes);return u.tag==="Just"?b("Just",{x:u._1.x,y:u._1.y,w:u._1.w,h:u._1.h}):T})(Lt(Le.foldr,pe(w.compare,he,n,bg(t)(n)(r)))),...St(i=>{const u=Rn(i)(e.edges);return u.tag==="Just"?b("Just",gi(u._1)):T})(Lt(Le.foldr,r)),...St(i=>{const u=Rn(i)(e.chipExtras);if(u.tag==="Just")return Uu(u._1);if(u.tag==="Nothing")return T;f()})(Lt(Le.foldr,r))];return o.length===0?un(e):_i(o)},Wg=e=>t=>n=>r=>{const o=[...St(i=>i)([(()=>{const i=Rn(n)(e.edges);return i.tag==="Just"?b("Just",gi(i._1)):T})(),(()=>{const i=Rn(n)(e.chipExtras);if(i.tag==="Just")return Uu(i._1);if(i.tag==="Nothing")return T;f()})()]),...(()=>{const i=Rn(n)(t);if(i.tag==="Just")return St(u=>{const s=Xu(u)(e.nodes);return s.tag==="Just"?b("Just",{x:s._1.x,y:s._1.y,w:s._1.w,h:s._1.h}):T})([i._1.source,i._1.target]);if(i.tag==="Nothing")return[];f()})()];return o.length===0?Zu(e)(t)(r):_i(o)},Rg=y(e=>t=>{const n=e.length-1|0,r=n>=0&&n<e.length?b("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 o=r._1.toCam.center.x-t.toCam.center.x;return(o<0?-o<8:o<8)&&(()=>{const i=r._1.toCam.center.y-t.toCam.center.y;return(i<0?-i<8:i<8)&&(()=>{const u=r._1.toCam.zoom-t.toCam.zoom;return u<0?-u<.08:u<.08})()})()})()?ye((()=>{const o=e.length-1|0;return o<1?[]:Mt(0,o,e)})())({...r._1,endT:t.endT}):ye(e)(t)})([]),ju=e=>t=>{const n=un(e),r=n.w/Jn(1e-4)(t.zoom),o=n.h/Jn(1e-4)(t.zoom);return{x:t.center.x-r/2,y:t.center.y-o/2,w:r,h:o}},Qg=e=>pe(w.compare,he,Ou(V(t=>x(t.id,{source:t.from.node,target:t.to.node}))(e.graph.edges)),Ou(Ct(e.scenes)(Pg))),di=e=>t=>n=>({center:{x:n.x+n.w/2,y:n.y+n.h/2},zoom:ci(e.minZoom)(e.maxZoom)(Mg(t)(n)(e.padding))}),Ig=e=>t=>n=>r=>{const o=di(e)(t)(un(t)),i=at(u=>u>=0&&u<=n,kg(vt(lt.compare)([0,n,...Ct(r)(u=>[u.startT,u.endT])])));return Cg(e)(t)(o)(Rg(zg(o)(St(u=>{const s=(u._1+u._2)/2;if(u._2<=u._1)return T;const a=y(vg)(0)(V(g=>g.priority)(at(g=>g.startT<=s&&s<g.endT,r))),c=V(g=>g.bbox)(at(g=>g.priority===a,at(g=>g.startT<=s&&s<g.endT,r)));return c.length===0?b("Just",{kind:Lg,startT:u._1,endT:u._2,cam:o}):b("Just",{kind:Tg,startT:u._1,endT:u._2,cam:di(e)(t)(_i(c))})})(me(Sn,i,Mt(1,i.length,i))))))},Bg=e=>t=>n=>r=>{const o=ge(i=>r>=i.startT&&r<i.endT)(n);if(o.tag==="Just")return Eg(e)(r)(o._1);if(o.tag==="Nothing"){const i=n.length-1|0;if(i>=0&&i<n.length&&r>=n[i].endT)return n[i].toCam;const u=di(e)(t)(un(t));return 0<n.length?n[0].fromCam:u}f()};function _r(e){return e.charCodeAt(0)}function ts(e){return String.fromCharCode(e)}const Hr=function(e){return function(t){return function(n){return n.replace(new RegExp(e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),t)}}},li=function(e){return function(t){return t.split(e)}},Ag=function(e){return e.trim()},Dg=function(e){return function(t){return t.join(e)}};var qg=typeof Array.from=="function",Yg=typeof Symbol<"u"&&Symbol!=null&&typeof Symbol.iterator<"u"&&typeof String.prototype[Symbol.iterator]=="function",$g=typeof String.prototype.fromCodePoint=="function",Fg=typeof String.prototype.codePointAt=="function";const Hg=function(e){return Fg?function(t){return t.codePointAt(0)}:e},Vg=function(e){return $g?String.fromCodePoint:e},Xg=function(e){return function(t){return Yg?function(n){for(var r="",o=n[Symbol.iterator](),i=0;i<t;++i){var u=o.next();if(u.done)return r;r+=u.value}return r}:e(t)}},Og=function(e){return function(t){return qg?function(n){return Array.from(n,t)}:e}},Vr=e=>{const t=hn(e);if(t===0)return T;if(t===1)return b("Just",{head:_r(cr(0)(e)),tail:""});const n=_r(cr(1)(e)),r=_r(cr(0)(e));return 55296<=r&&r<=56319&&56320<=n&&n<=57343?b("Just",{head:(((r-55296|0)*1024|0)+(n-56320|0)|0)+65536|0,tail:fr(2)(e)}):b("Just",{head:r,tail:fr(1)(e)})},Ug=e=>{const t=Vr(e);return t.tag==="Just"?b("Just",x(t._1.head,t._1.tail)):T},Kg=e=>Pe.unfoldr(Ug)(e),es=Hg(e=>{const t=_r(cr(0)(e));if(55296<=t&&t<=56319&&hn(e)>1){const n=_r(cr(1)(e));if(56320<=n&&n<=57343)return(((t-55296|0)*1024|0)+(n-56320|0)|0)+65536|0}return t}),hi=Og(Kg)(es),pi=e=>oi(e>=0&&e<=65535?ts(e):e<0?"\0":"\uFFFF"),Zg=Vg(e=>e<=65535?pi(e):pi(En(e-65536|0,1024)+55296|0)+pi(Go(e-65536|0)(1024)+56320|0)),ns=e=>t=>{if(e<1)return"";const n=Vr(t);return n.tag==="Just"?Zg(n._1.head)+ns(e-1|0)(n._1.tail):t},oe=Xg(ns),jg=e=>t=>t===""?T:b("Just",es(t)),Xr=(e,t,n)=>({tag:e,_1:t,_2:n}),t_=()=>({tag:"ExtendFromSource"}),Or=(e,t)=>({tag:e,_1:t}),mi=e=>e,Ur=(e,t)=>({tag:e,_1:t}),yi=Ur("NotYet"),rs=Ur("Consumed"),e_=mi("FromSource"),os=mi("FromTarget"),n_=mi("FromBoth"),is=Or("Hidden"),r_=Or("Visible"),us=t_(),ss=Xr("Retracted"),o_=Xr("Extended"),Ji=(e,t)=>({tag:e,_1:t}),Qn=(e,t,n)=>({tag:e,_1:t,_2:n}),as=e=>e,Nn=(e,t)=>({tag:e,_1:t}),In=(e,t,n,r,o,i,u,s,a)=>({tag:e,_1:t,_2:n,_3:r,_4:o,_5:i,_6:u,_7:s,_8:a}),cs=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Kr=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},sn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},dr=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},fs=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},gs=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Bn=(()=>{const e=Pe.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return b("Just",x(t._1,t._2));f()});return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Qt("Cons",r._3,n(r._6,o)));f()};return n(t,Bt)})())})(),i_=y(e=>t=>Z(w)(t)()(e))(D),Ni=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},u_=jt(w)(It),s_=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},xi=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},a_=Nn("NoKeyframes"),c_=e=>Nn("DuplicateEventId",e),f_=e=>Nn("UnknownEvent",e),_s=as("PlopIn"),g_=as("PlopOut"),__=e=>t=>St(n=>{if(n.target.tag==="NodeWindow"||n.target.tag==="EdgeWindow")return T;if(n.target.tag==="TokenWindow")return b("Just",{startT:n.startT,endT:n.endT,bbox:Wg(e)(t)(n.target._2)(D),priority:1});if(n.target.tag==="FillWindow")return b("Just",{startT:n.startT,endT:n.endT,bbox:Zu(e)(t)(Yt("Node",1,1,n.target._2,void 0,D,D)),priority:1});f()}),d_=e=>t=>n=>r=>o=>{const i=_t(y(c=>g=>c+hi(g).length|0)(0)(n.labels))*e.tokenReadSecPerChar,u=c=>{const g=cs(c)(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};f()},s=Kr(n.edge)(t.edges),a=(()=>{if(s.tag==="Just"){const c=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return _e(s._1);f()})(),g=(()=>{if(n.direction==="Forward")return s._1;if(n.direction==="Backward")return _e(s._1);f()})(),d=u(n.from),l=g.length-1|0;return(2*(()=>{const _=0<c.length?c[0]:u(n.from),h=_.x-d.x,m=_.y-d.y;return(h<0?-h:h)+(m<0?-m:m)})()+ri(s._1)+2*(()=>{const _=l>=0&&l<g.length?g[l]:u(n.to),h=u(n.to),m=h.x-_.x,p=h.y-_.y;return(m<0?-m:m)+(p<0?-p:p)})())/e.tokenSpeed}if(s.tag==="Nothing")return 0/e.tokenSpeed;f()})();return e.tokenSpeed<=0?e.minTokenDuration:sn(e.minTokenDuration)(sn(a)(i)/sn(.05)(1-r-o))},l_=e=>{if(e.event.kind.tag==="SendToken")return b("Just",{startT:e.startT,endT:e.endT,target:In("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 b("Just",{startT:e.startT,endT:e.endT,target:In("FillWindow",e.event.id,e.event.kind._1.node,e.event.kind._1.labels)});f()},h_=e=>t=>n=>St(r=>{const o=St(i=>cs(i)(e.nodes))(Lt(Le.foldr,(()=>{if(r.scene.tag==="Structural")return pe(w.compare,he,(()=>{const i=dr(r.scene._1.from)(n);if(i.tag==="Nothing")return D;if(i.tag==="Just")return i._1.nodes;f()})(),(()=>{const i=dr(r.scene._1.to)(n);if(i.tag==="Nothing")return D;if(i.tag==="Just")return i._1.nodes;f()})());if(r.scene.tag==="DataFlow"){const i=dr(r.scene._1.keyframe)(n);if(i.tag==="Nothing")return D;if(i.tag==="Just")return i._1.nodes}f()})()));return o.length===0?T:b("Just",{startT:r.startT,endT:r.endT,bbox:(()=>{const i=y(u=>s=>({minX:fs(u.minX)(s.x),minY:fs(u.minY)(s.y),maxX:sn(u.maxX)(s.x+s.w),maxY:sn(u.maxY)(s.y+s.h)}))(0<o.length?{minX:o[0].x,minY:o[0].y,maxX:o[0].x+o[0].w,maxY:o[0].y+o[0].h}:{minX:0,minY:0,maxX:0,maxY:0})(Mt(1,o.length,o));return{x:i.minX,y:i.minY,w:i.maxX-i.minX,h:i.maxY-i.minY}})(),priority:0})}),p_=e=>t=>n=>{const r=Kr(n)(e);if(r.tag==="Nothing")return os;if(r.tag==="Just"){const o=gs(r._1.target)(t);return gs(r._1.source)(t)?o?n_:e_:os}f()},m_=e=>t=>n=>r=>{const o=(()=>{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 i=r.event.when._1,u=ge(s=>s.event.id===i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.endT;f()}if(r.event.when.tag==="With"){const i=r.event.when._1,u=ge(s=>s.event.id===i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.startT}f()})();return ye(n)({startT:o,endT:(()=>{if(r.event.kind.tag==="SendToken")return o+d_(e)(t)(r.event.kind._1)(r.holdPre)(r.holdPost);if(r.event.kind.tag==="FillNodeWithoutTransition")return o+e.plop;f()})(),event:r.event,holdPre:r.holdPre,holdPost:r.holdPost})},vi=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;f()})()):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);f()}if(n.tag==="Nothing")return Qn("AtKeyframe",e.initialKeyframe);f()},y_=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];f()},ds={id:"",nodes:D,edges:D},J_=e=>t=>yg((()=>{const n=dr(t.from)(e);if(n.tag==="Nothing")return ds;if(n.tag==="Just")return n._1;f()})())((()=>{const n=dr(t.to)(e);if(n.tag==="Nothing")return ds;if(n.tag==="Just")return n._1;f()})()),Ti=e=>t=>n=>r=>{const o=Kr(r)(n.edges);if(o.tag==="Just")return e<=0?t:sn(t)(ri(o._1)/e);if(o.tag==="Nothing")return t;f()},ls=e=>t=>n=>r=>o=>{const i=e.plop,u=J_(n)(o),s=V(_=>({startT:0,endT:0+Ti(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:In("EdgeWindow",_,Ji("Extend",us))}))(Bn(u.entering.edges)),a=V(_=>({startT:0,endT:i,target:In("NodeWindow",_,_s)}))(Bn(u.entering.nodes)),c=y(sn)(0)(V(_=>Ti(e.edgeSpeed)(e.minEdgeDuration)(t)(_))(Bn(u.leaving.edges))),g=_=>on(h=>{const m=Kr(h)(r);if(m.tag==="Just")return m._1.source===_||m._1.target===_;if(m.tag==="Nothing")return!1;f()},Bn(u.leaving.edges))?c:0,d=V(_=>({startT:g(_),endT:g(_)+e.plop,target:In("NodeWindow",_,g_)}))(Bn(u.leaving.nodes)),l=V(_=>({startT:0,endT:Ti(e.edgeSpeed)(e.minEdgeDuration)(t)(_),target:In("EdgeWindow",_,Ji("Retract",p_(r)(u.leaving.nodes)(_)))}))(Bn(u.leaving.edges));return{duration:(()=>{const _=vt(lt.compare)([...V(m=>m.endT)(l),...V(m=>m.endT)(d),...V(m=>m.endT)(a),...V(m=>m.endT)(s)]),h=_.length-1|0;return h>=0&&h<_.length?_[h]+e.gap:e.gap})(),windows:[...l,...d,...a,...s]}},N_=e=>t=>n=>r=>o=>i=>V((()=>{const u=o.startT;return s=>({...s,startT:s.startT+u,endT:s.endT+u})})())(ls(e)(t)(n)(r)(i).windows),x_=e=>St(t=>Lt(jn,t).length>1?b("Just",(()=>{const n=Ft(r=>T,r=>o=>b("Just",{head:r,tail:o}),Lt(jn,t));if(n.tag==="Just")return n._1.head;if(n.tag==="Nothing")return"";f()})()):T)(Vf(Mo)(vt(w.compare)(e))),v_=e=>{const t=V(r=>r.id)(e),n=i_(t);return[...V(c_)(x_(t)),...V(f_)(at(r=>!Ni(r)(n),Ct(e)(y_)))]},T_=e=>{const t=u_(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];f()})()))(e)),n=r=>o=>i=>{if(Ni(i)(o))return[Nn("ScheduleCycle",[...Lt(Le.foldr,o),i])];if(Ni(i)(r))return[];const u=s_(i)(t);if(u.tag==="Nothing")return[];if(u.tag==="Just")return Ct(u._1)(n(Z(w)(i)()(r))(Z(w)(i)()(o)));f()};return Ct(e)(r=>n(D)(D)(r.id))},L_={plop:.5,gap:.5,edgeSpeed:350,minEdgeDuration:.3,tokenSpeed:100,minTokenDuration:1.4,tokenReadSecPerChar:.06,nodeEasing:jf,edgeEasing:Kf,tokenEasing:Uf},w_=e=>t=>{if(t.tag==="Structural")return St(n=>n)([xi(t._1.from)(e)?T:b("Just",Nn("UnknownKeyframe",t._1.from)),xi(t._1.to)(e)?T:b("Just",Nn("UnknownKeyframe",t._1.to))]);if(t.tag==="DataFlow")return[...St(n=>n)([xi(t._1.keyframe)(e)?T:b("Just",Nn("UnknownKeyframe",t._1.keyframe))]),...v_(t._1.events),...T_(t._1.events)];f()},k_=e=>t=>{const n=Ct(t)(w_(e));return n.length===0?wt("Right",void 0):wt("Left",n)},hs=e=>t=>n=>y(m_(e)(t))([])(zt(r=>o=>({event:o,holdPre:o.kind.tag==="SendToken"?(()=>{const i=r-1|0;return i>=0&&i<n.length&&n[i].kind.tag==="SendToken"&&n[i].kind._1.to===o.kind._1.from})()?0:.18:0,holdPost:o.kind.tag==="SendToken"?(()=>{const i=r+1|0;return i>=0&&i<n.length&&n[i].kind.tag==="SendToken"&&n[i].kind._1.from===o.kind._1.to})()?0:.18:0}))(n)),b_=e=>t=>n=>{const r=hs(e)(t)(n.events);return r.length===0?e.gap:y(sn)(0)(V(o=>o.endT)(r))+e.gap},E_=e=>t=>n=>r=>o=>{if(o.tag==="Structural")return ls(e)(t)(n)(r)(o._1).duration;if(o.tag==="DataFlow")return b_(e)(t)(o._1);f()},C_=e=>t=>n=>r=>o=>y(i=>u=>{const s=E_(e)(t)(n)(r)(u);return{acc:ye(i.acc)({startT:i.t,endT:i.t+s,scene:u}),t:i.t+s}})({acc:[],t:0})(o).acc,S_=e=>t=>n=>r=>V((()=>{const o=n.startT;return i=>({...i,startT:i.startT+o,endT:i.endT+o})})())(St(l_)(hs(e)(t)(r.events))),P_=e=>t=>n=>r=>o=>{if(o.scene.tag==="Structural")return N_(e)(t)(n)(r)(o)(o.scene._1);if(o.scene.tag==="DataFlow")return S_(e)(t)(o)(o.scene._1);f()},G_=e=>t=>n=>{const r=0<t.keyframes.length?b("Just",t.keyframes[0]):T;if(r.tag==="Nothing")return wt("Left",[a_]);if(r.tag==="Just"){const o=r._1,i=pg(V(a=>x(a.id,a))(t.keyframes)),u=Qg(t),s=k_(i)(t.scenes);return(()=>{if(s.tag==="Left"){const a=s._1;return c=>wt("Left",a)}if(s.tag==="Right"){const a=s._1;return c=>c(a)}f()})()(()=>{const a=C_(e)(n)(i)(u)(t.scenes),c=a.length-1|0,g=c>=0&&c<a.length?a[c].endT:0,d=vt(l=>_=>lt.compare(l.startT)(_.startT))(Ct(a)(P_(e)(n)(i)(u)));return wt("Right",{totalDuration:g,windows:d,spans:a,keyframes:i,initialKeyframe:o.id,timing:e,layout:n,cameraSpans:Ig(Ku)(n)(g)([...h_(n)(u)(i)(a),...__(n)(u)(d)]),cameraConfig:Ku})})}f()},lr=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},ps=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Zr=e=>t=>n=>{const r=lt.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;f()})(),i=lt.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;f()},z_=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},M_=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},W_=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},R_=jt(w)(It),Q_=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},I_=jt(w)(It),B_=jt(w)(It),A_=e=>t=>n=>r=>{const o=un(e),i=o.w/lr(1e-4)(t.zoom)/2,u=o.h/lr(1e-4)(t.zoom)/2,s=n.y-t.center.y,a=n.x-t.center.x;return{...t,center:{x:i<=1e-4?t.center.x+0*r*.35:a<0?t.center.x+a/(1+-a/i)*r*.35:t.center.x+a/(1+a/i)*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}}},Li=e=>t=>{const n=ps(t)(e.keyframes);if(n.tag==="Nothing")return D;if(n.tag==="Just")return n._1.nodes;f()},wi=e=>t=>{const n=ps(t)(e.keyframes);if(n.tag==="Nothing")return D;if(n.tag==="Just")return n._1.edges;f()},D_=e=>t=>n=>on(r=>r.endT<=t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Retract"&&r.target._1===n,e),q_=e=>t=>n=>on(r=>r.endT<=t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopOut"&&r.target._1===n,e),Y_=e=>t=>n=>on(r=>r.startT>t&&r.target.tag==="NodeWindow"&&r.target._2==="PlopIn"&&r.target._1===n,e),$_=e=>t=>n=>on(r=>r.startT>t&&r.target.tag==="EdgeWindow"&&r.target._2.tag==="Extend"&&r.target._1===n,e),F_=e=>t=>{const n=vi(e)(t);if(n.tag==="AtKeyframe")return oe(3)(n._1)==="kf-"?"":n._1;if(n.tag==="InTransition")return oe(3)(n._2)==="kf-"?"":n._2;f()},ms=e=>t=>n=>ge(r=>n(r)&&t>=r.startT&&t<r.endT)(e),H_=e=>{const t=Zr(0)(1)(e/.2),n=Zr(0)(1)((1-e)/.2);return t*t*(3-2*t)*n*n*(3-2*n)},V_=e=>t=>{if(t.tag==="Travelling"){const n=z_(t._1.edge)(e.edges);if(n.tag==="Just"){const r=Iu(n._1)(t._1.progress);return r.tag==="Just"?b("Just",{dot:r._1,weight:H_(t._1.progress)}):T}if(n.tag==="Nothing")return T;f()}return T},X_=e=>t=>{const n=vi(e)(t);if(n.tag==="AtKeyframe")return Li(e)(n._1);if(n.tag==="InTransition")return pe(w.compare,he,Li(e)(n._1),Li(e)(n._2));f()},O_=e=>t=>{const n=vi(e)(t);if(n.tag==="AtKeyframe")return wi(e)(n._1);if(n.tag==="InTransition")return pe(w.compare,he,wi(e)(n._1),wi(e)(n._2));f()},U_=e=>t=>{const n=un(e),r=n.h/lr(1e-4)(t.zoom),o=n.w/lr(1e-4)(t.zoom);return{...t,center:{x:o>=n.w?n.x+n.w/2:Zr(n.x+o/2)(n.x+n.w-o/2)(t.center.x),y:r>=n.h?n.y+n.h/2:Zr(n.y+r/2)(n.y+n.h-r/2)(t.center.y)}}},jr=e=>t=>{const n=e.endT-e.startT;return n<=0?1:lr(0)(M_(1)((t-e.startT)/n))},K_=e=>t=>n=>r=>{const o=ms(e.windows)(t)(i=>i.target.tag==="EdgeWindow"&&i.target._1===r);if(o.tag==="Just"){const i=ni(e.timing.edgeEasing)(jr(o._1)(t)),u=o._1.target.tag==="EdgeWindow"?o._1.target._2:Ji("Extend",us);if(u.tag==="Retract")return Xr("Retracting",u._1,i);if(u.tag==="Extend")return Xr("Extending",u._1,i);f()}if(o.tag==="Nothing")return $_(e.windows)(t)(r)||D_(e.windows)(t)(r)?ss:W_(r)(n)?o_:ss;f()},Z_=e=>t=>{const n=O_(e)(t);return R_(V(r=>x(r,K_(e)(t)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Yt("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));f()};return Lt(Le.foldr,r(e.layout.edges))})()))},j_=e=>t=>n=>r=>{const o=ms(e.windows)(t)(i=>i.target.tag==="NodeWindow"&&i.target._1===r);if(o.tag==="Just"){const i=jr(o._1)(t),u=o._1.target.tag==="NodeWindow"?o._1.target._2:_s;if(u==="PlopIn")return Or("PloppingIn",i);if(u==="PlopOut")return Or("PloppingOut",i);f()}if(o.tag==="Nothing")return Y_(e.windows)(t)(r)||q_(e.windows)(t)(r)?is:Q_(r)(n)?r_:is;f()},t1=e=>t=>{const n=X_(e)(t);return I_(V(r=>x(r,j_(e)(t)(n)(r)))((()=>{const r=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Yt("Node",o._1,o._2,o._3,void 0,r(o._5),r(o._6));f()};return Lt(Le.foldr,r(e.layout.nodes))})()))},e1=e=>t=>n=>t.target.tag==="TokenWindow"?x(t.target._1,n<t.startT?yi:n>=t.endT?rs:Ur("Travelling",{edge:t.target._2,direction:t.target._3,progress:ni(e.timing.tokenEasing)(jr(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?yi:n>=t.endT?rs:Ur("Filling",{node:t.target._2,progress:jr(t)(n),labels:t.target._3})):x("",yi),n1=e=>t=>B_(V(n=>e1(e)(n)(t))(at(n=>n.target.tag==="TokenWindow"||n.target.tag==="FillWindow",e.windows))),r1=e=>t=>{const n=St(V_(e))((()=>{const r=(o,i)=>{if(o.tag==="Leaf")return i;if(o.tag==="Node")return r(o._5,Qt("Cons",o._4,r(o._6,i)));f()};return Lt(qt.foldr,r(t.tokens,Bt))})());return 0<n.length?b("Just",n[0]):T},o1=e=>t=>{const n=r1(e)(t);if(n.tag==="Nothing")return t.camera;if(n.tag==="Just")return A_(e)(t.camera)(n._1.dot)(n._1.weight);f()},i1=e=>t=>{const n={nodes:t1(e)(t),edges:Z_(e)(t),tokens:n1(e)(t),camera:Bg(e.cameraConfig)(e.layout)(e.cameraSpans)(t),frameTitle:F_(e)(t)};return{...n,camera:U_(e.layout)(o1(e.layout)(n))}};let ki=null;function u1(){return ki||(typeof document>"u"?null:(ki=document.createElement("canvas").getContext("2d"),ki))}const ys=new Map,s1=e=>t=>n=>r=>()=>{const o=`${n} ${t}px ${e}|${r}`,i=ys.get(o);if(i!==void 0)return i;const u=u1();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return ys.set(o,s),s},Js=(()=>{const e=Hr(`\r
3
- `)(" "),t=Hr(`
4
- `)(" "),n=(()=>{const r=Hr("\r")(" "),o=(()=>{const i=Hr(" ")(" ");return u=>i(r(u))})();return i=>o(t(i))})();return r=>n(e(r))})(),hr=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},a1=e=>t=>{const n=ot.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},c1=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},f1=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Ns=e=>Mn(_e(ln(t=>t===" ")(_e(ln(t=>t===" ")(Bu(e)).rest)).rest)),g1=e=>y(t=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?b("Just",n._1):t)(T)(zt(Sn)(e)),bi=e=>t=>{if(e<=0)return[t];if(hn(t)<=e)return[t];const n=Bu(t),r=e<1?[]:Mt(0,e,n),o=g1(r);if(o.tag==="Just"){const i=Ns(Au(!(o._1>=0&&o._1<r.length)||r[o._1]===" "?o._1:o._1+1|0)(t)),u=Ns(fr(o._1+1|0)(t));return u===""?[i]:[i,...bi(e)(u)]}if(o.tag==="Nothing"){const i=Au(e)(t),u=fr(e)(t);return u===""?[i]:[i,...bi(e)(u)]}f()},_1={cellW:7,cellH:3,maxLineWidth:20},d1=e=>t=>{const n=V(i=>x((()=>{if(i.label.tag==="Just")return i.label._1;if(i.label.tag==="Nothing")return i.id;f()})(),i))(t.nodes),r=hr(1)(En((a1(e.maxLineWidth)(y(i=>u=>hr(i)(hn(u._1)))(0)(n))+2|0)+e.cellW|0,e.cellW)),o=(r*e.cellW|0)-1|0;return{...t,nodes:V(i=>{if(!(i._2.size._1===1&&i._2.size._2===1))return i._2;const u=Ct(li(`
5
- `)(i._1))(bi(o)),s=y(a=>c=>hr(a)(hn(c)))(0)(u);return{...i._2,size:x(_t(s>o?En((s+2|0)+e.cellW|0,e.cellW):r),_t(hr(1)(En(u.length+e.cellH|0,e.cellH))))}})(n)}},l1=e=>t=>n=>({...n,nodes:V(r=>{const o=f1(r.id)(t);if(o.tag==="Nothing")return r;if(o.tag==="Just")return{...r,size:x(c1(r.size._1)(_t(hr(1)(tr(Nc((o._1+32)/e))))),r.size._2)};f()})(n.nodes)}),h1=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},p1=e=>{const t=e.length;return(n=>r=>{let o=n,i=r,u=!0,s;for(;u;){const a=o,c=i;if(a>=t){u=!1,s=c;continue}const g=d=>l=>{let _=d,h=l,m=!0,p;for(;m;){const J=_,N=h;if(J>=t){m=!1,p=N;continue}if(a>=0&&a<e.length){if(J>=0&&J<e.length){_=J+1|0,h=(()=>{const v=e[a].position,L=e[a].size,E=e[J].position,k=e[J].size;return v._1<E._1+k._1&&E._1<v._1+L._1&&v._2<E._2+k._2&&E._2<v._2+L._2})()?N+1|0:N;continue}_=J+1|0,h=N;continue}m=!1,p=N}return p};o=a+1|0,i=g(a+1|0)(c)}return s})(0)(0)},xs=e=>y(t=>n=>t+_g(n.start)(n.end))(0)(e.segments),m1=e=>t=>n=>({crossingCount:y(r=>o=>r+o.jumps.length|0)(0)(t),bendCount:y(r=>o=>r+o.bends.length|0)(0)(t),totalEdgeLength:y(r=>o=>r+xs(o))(0)(t),maxEdgeLength:y(r=>o=>h1(r)(xs(o)))(0)(t),nodeOverlapCount:p1(e),constraintViolations:n,jumpCount:y(r=>o=>r+o.jumps.length|0)(0)(t)}),vs=e=>e,An=jt(ot)(It),Nt=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=ot.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Ts=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},it=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},ut=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},Xe=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},y1=e=>t=>{const n=ot.compare(e._1)(t._1);return n==="LT"?Re:n==="GT"?Qe:ot.compare(e._2)(t._2)},Dn=e=>t=>{const n=ot.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},J1=(()=>{const e=Pe.unfoldr(dn);return t=>e(Ge("IterNode",t,_n))})(),N1=e=>e,to=vs("Regular"),eo=vs("Critical"),Ls=e=>t=>{const n=y(u=>s=>Z(w)(s.node)(s)(u))(D)(t),r=1.25*_t(4),o=(u,s,a)=>(c=>g=>d=>{let l=c,_=g,h=d,m=!0,p;for(;m;){const J=l,N=_,v=h;if(v.critical){m=!1,p=v;continue}const L=Ft(k=>T,k=>S=>b("Just",{head:k,tail:S}),J),E=Ft(k=>T,k=>S=>b("Just",{head:k,tail:S}),N);if(L.tag==="Just"&&E.tag==="Just"){const k=L._1.head>E._1.head-u&&L._1.head<E._1.head+u?{...v,critical:!0}:L._1.head>E._1.head-r&&L._1.head<E._1.head+r?{...v,conflicts:v.conflicts+1|0}:v;if(k.critical){m=!1,p=k;continue}if(L._1.head<=E._1.head){l=L._1.tail,_=N,h=k;continue}l=J,_=E._1.tail,h=k;continue}m=!1,p=v}return p})(s)(a)({conflicts:0,critical:!1}),i=(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 c=o(u,s.outgoing,a.incoming),g=o(u,a.outgoing,s.incoming);if(c.critical||g.critical)return[...c.critical?[{src:a.id,tgt:s.id,weight:1,kind:eo}]:[],...g.critical?[{src:s.id,tgt:a.id,weight:1,kind:eo}]:[]];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)),m=(1*c.conflicts|0)+(16*(y(J=>N=>N>h?J:N>=_?J+1|0:J)(0)(s.outgoing)+y(J=>N=>N>l?J:N>=d?J+1|0:J)(0)(a.incoming)|0)|0)|0,p=(1*g.conflicts|0)+(16*(y(J=>N=>N>l?J:N>=d?J+1|0:J)(0)(a.outgoing)+y(J=>N=>N>h?J:N>=_?J+1|0:J)(0)(s.incoming)|0)|0)|0;return m<p?[{src:s.id,tgt:a.id,weight:p-m|0,kind:to}]:m>p?[{src:a.id,tgt:s.id,weight:m-p|0,kind:to}]:m>0?[{src:s.id,tgt:a.id,weight:0,kind:to},{src:a.id,tgt:s.id,weight:0,kind:to}]:[]};return y(u=>s=>y(a=>c=>Z(w)(c._1)(c._2)(a))(u)((()=>{const a=y(G=>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;f()})(),K=Xe(et)(G.entries);if(K.tag==="Nothing")return{...G,entries:Z(w)(et)({id:0,members:[P.edge.id],incoming:[P.fromPos._1],outgoing:[P.toPos._1],slot:0,mark:0,splitBy:T,splitPartner:T})(G.entries),order:[...G.order,et]};if(K.tag==="Just")return{...G,entries:Z(w)(et)({...K._1,members:[...K._1.members,P.edge.id],incoming:[...ln(A=>A<P.fromPos._1)(K._1.incoming).init,P.fromPos._1,...ln(A=>A<=P.fromPos._1)(K._1.incoming).rest],outgoing:[...ln(A=>A<P.toPos._1)(K._1.outgoing).init,P.toPos._1,...ln(A=>A<=P.toPos._1)(K._1.outgoing).rest]})(G.entries)};f()})({entries:D,order:[]})(s._2),c=zt(G=>P=>({...P,id:G}))(St(G=>Xe(G)(a.entries))(a.order));if(c.length===0)return[];const g=y(G=>P=>G.prev.tag==="Just"&&P-G.prev._1<1e-9?G:{prev:b("Just",P),out:[...G.out,P]})({prev:T,out:[]})(vt(lt.compare)([...Ct(c)(G=>G.incoming),...Ct(c)(G=>G.outgoing)])).out,d=g.length<2?.2*r:.2*y(G=>P=>{if(G.prev.tag==="Nothing")return{prev:b("Just",P),mn:G.mn};if(G.prev.tag==="Just")return{prev:b("Just",P),mn:it(G.mn)(P-G.prev._1)};f()})({prev:T,mn:1e18})(g).mn,l={segments:c,deps:(()=>{const G=c.length;return Ct(Ct($t(0,G-2|0))(P=>Ct($t(P+1|0,G-1|0))(et=>[x(P,et)])))(P=>P._1>=0&&P._1<c.length?P._2>=0&&P._2<c.length?i(d,c[P._1],c[P._2]):[]:[])})()},_=at(G=>{if(G.kind==="Critical")return!0;if(G.kind==="Regular")return!1;f()},l.deps),h=(()=>{if(_.length<2)return l;const G=An((()=>{const Y=l.segments;return V(R=>x(R.id,R.mark))((()=>{const R=Y.length,C=M=>{let W=M,H=!0,O;for(;H;){const $=W,q=ge(Q=>{const U=Nt(Q)($.inWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;f()})($.remaining);if(q.tag==="Nothing"){H=!1,O=$;continue}if(q.tag==="Just"){const Q=q._1;W={...$,inWeight:y(U=>X=>xt(ot)(Ut)(X.tgt)(-X.weight)(U))($.inWeight)((()=>{const U=Nt(Q)($.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;f()})()),marks:Z(ot)(Q)($.nextSource)($.marks),nextSource:$.nextSource+1|0,outWeight:y(U=>X=>xt(ot)(Ut)(X.src)(-X.weight)(U))($.outWeight)((()=>{const U=Nt(Q)($.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;f()})()),remaining:at(U=>U!==Q,$.remaining)};continue}f()}return O},z=M=>{let W=M,H=!0,O;for(;H;){const $=W,q=ge(Q=>{const U=Nt(Q)($.outWeight);if(U.tag==="Nothing")return!0;if(U.tag==="Just")return U._1===0;f()})($.remaining);if(q.tag==="Nothing"){H=!1,O=$;continue}if(q.tag==="Just"){const Q=q._1;W={...$,inWeight:y(U=>X=>xt(ot)(Ut)(X.tgt)(-X.weight)(U))($.inWeight)((()=>{const U=Nt(Q)($.depsBySrc);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;f()})()),marks:Z(ot)(Q)($.nextSink)($.marks),nextSink:$.nextSink-1|0,outWeight:y(U=>X=>xt(ot)(Ut)(X.src)(-X.weight)(U))($.outWeight)((()=>{const U=Nt(Q)($.depsByTgt);if(U.tag==="Nothing")return[];if(U.tag==="Just")return U._1;f()})()),remaining:at(U=>U!==Q,$.remaining)};continue}f()}return O};return(M=>{let W=M,H=!0,O;for(;H;){const $=C(z(W));if($.remaining.length===0){H=!1,O=V(q=>{const Q=Nt(q.id)($.marks),U=(()=>{if(Q.tag==="Nothing")return q.id;if(Q.tag==="Just")return Q._1;f()})();return{...q,mark:U<R?(U+R|0)+1|0:U}})(Y);continue}W=(()=>{const q=U=>{const X=Nt(U)($.outWeight),gt=Nt(U)($.inWeight);return(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;f()})()-(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;f()})()|0},Q=vt(U=>X=>ot.compare(q(X))(q(U)))($.remaining);if(0<Q.length){const U=Q[0];return{...$,inWeight:y(X=>gt=>xt(ot)(Ut)(gt.tgt)(-gt.weight)(X))($.inWeight)((()=>{const X=Nt(U)($.depsBySrc);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;f()})()),marks:Z(ot)(U)($.nextSource)($.marks),nextSource:$.nextSource+1|0,outWeight:y(X=>gt=>xt(ot)(Ut)(gt.src)(-gt.weight)(X))($.outWeight)((()=>{const X=Nt(U)($.depsByTgt);if(X.tag==="Nothing")return[];if(X.tag==="Just")return X._1;f()})()),remaining:at(X=>X!==U,$.remaining)}}return $})()}return O})({remaining:V(M=>M.id)(Y),marks:D,inWeight:y(M=>W=>xt(ot)(Ut)(W.tgt)(W.weight)(M))(D)(_),outWeight:y(M=>W=>xt(ot)(Ut)(W.src)(W.weight)(M))(D)(_),depsBySrc:y(M=>W=>xt(ot)(ie)(W.src)([W])(M))(D)(_),depsByTgt:y(M=>W=>xt(ot)(ie)(W.tgt)([W])(M))(D)(_),nextSink:R-1|0,nextSource:R+1|0})})())})()),P=at(Y=>{const R=Nt(Y.src)(G),C=Nt(Y.tgt)(G);return(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;f()})()>(()=>{if(C.tag==="Nothing")return 0;if(C.tag==="Just")return C._1;f()})()},_);if(P.length===0)return l;const et=y(Y=>R=>{if(Ie(Wo)(R.src)(Y.decisions)||Ie(Wo)(R.tgt)(Y.decisions))return Y;const C=Nt(R.src)(Y.segMap),z=Nt(R.tgt)(Y.segMap);if(C.tag==="Just"&&z.tag==="Just"){const M=(C._1.incoming.length+C._1.outgoing.length|0)>2&&(z._1.incoming.length+z._1.outgoing.length|0)<=2,W=M?z._1:C._1;return{decisions:[...Y.decisions,W.id],segMap:Z(ot)(W.id)({...W,splitBy:b("Just",M?C._1.id:z._1.id)})(Y.segMap)}}return Y})({decisions:[],segMap:An(V(Y=>x(Y.id,Y))(l.segments))})(P),K=et.segMap,A=y(Y=>R=>{const C=it(y(it)(1e18)(R.incoming))(y(it)(1e18)(R.outgoing)),z=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(R.outgoing)),M=at(q=>q.a.startPosition<=z&&q.a.endPosition>=C,zt(q=>Q=>({i:q,a:Q}))(Y.freeAreas));if(M.length===0){const q={...R,incoming:vt(lt.compare)(R.incoming),outgoing:vt(lt.compare)([(C+z)/2]),splitPartner:b("Just",Y.nextId)},Q={id:Y.nextId,incoming:vt(lt.compare)([(C+z)/2]),mark:0,members:R.members,outgoing:vt(lt.compare)(R.outgoing),slot:0,splitBy:T,splitPartner:b("Just",R.id)};return{segMap:Z(ot)(Q.id)(Q)(Z(ot)(q.id)(q)(Y.segMap)),freeAreas:Y.freeAreas,nextId:Y.nextId+1|0}}const W=0<M.length?b("Just",M[0]):T,H=(()=>{if(W.tag==="Nothing")return{i:0,a:{startPosition:0,endPosition:0,size:0}};if(W.tag==="Just"){if(M.length===1)return W._1;const q=V(Q=>({c:Q,rating:(()=>{const U=(Q.a.startPosition+Q.a.endPosition)/2,X=[U],gt=[U],pt=y((()=>{const ht=Y.segMap;return Tt=>Gt=>{const dt=Nt(Gt.tgt)(ht);if(dt.tag==="Nothing")return Tt;if(dt.tag==="Just"){const Wt=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)),ft=it(y(it)(1e18)(R.incoming))(y(it)(1e18)(X)),rt=(()=>{const bt=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(X)),Pt=y(Rt=>re=>re>mt?Rt:re>=Wt?Rt+1|0:Rt)(0)(X)+y(Rt=>re=>re>bt?Rt:re>=ft?Rt+1|0:Rt)(0)(dt._1.incoming)|0,Kn=it(y(it)(1e18)(R.incoming))(y(it)(1e18)(X)),kn=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(X)),bn=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),Zn=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),We=y(Rt=>re=>re>kn?Rt:re>=Kn?Rt+1|0:Rt)(0)(dt._1.outgoing)+y(Rt=>re=>re>Zn?Rt:re>=bn?Rt+1|0:Rt)(0)(R.incoming)|0;return Pt===We?Pt>0?{...Tt,deps:Tt.deps+2|0,crossings:Tt.crossings+Pt|0}:Tt:{...Tt,deps:Tt.deps+1|0,crossings:Tt.crossings+Dn(Pt)(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)(gt))(y(it)(1e18)(R.outgoing)),Jt=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),Et=y(bt=>Pt=>Pt>st?bt:Pt>=nt?bt+1|0:bt)(0)(R.outgoing)+y(bt=>Pt=>Pt>Jt?bt:Pt>=yt?bt+1|0:bt)(0)(dt._1.incoming)|0,Dt=it(y(it)(1e18)(gt))(y(it)(1e18)(R.outgoing)),ne=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),$e=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),Un=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),nn=y(bt=>Pt=>Pt>ne?bt:Pt>=Dt?bt+1|0:bt)(0)(dt._1.outgoing)+y(bt=>Pt=>Pt>Un?bt:Pt>=$e?bt+1|0:bt)(0)(gt)|0;return Et===nn?Et>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Et|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Dn(Et)(nn)|0}}f()}})())(y((()=>{const ht=Y.segMap;return Tt=>Gt=>{const dt=Nt(Gt.src)(ht);if(dt.tag==="Nothing")return Tt;if(dt.tag==="Just"){const Wt=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)),ft=it(y(it)(1e18)(R.incoming))(y(it)(1e18)(X)),rt=(()=>{const bt=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(X)),Pt=y(Rt=>re=>re>mt?Rt:re>=Wt?Rt+1|0:Rt)(0)(X)+y(Rt=>re=>re>bt?Rt:re>=ft?Rt+1|0:Rt)(0)(dt._1.incoming)|0,Kn=it(y(it)(1e18)(R.incoming))(y(it)(1e18)(X)),kn=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(X)),bn=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),Zn=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),We=y(Rt=>re=>re>kn?Rt:re>=Kn?Rt+1|0:Rt)(0)(dt._1.outgoing)+y(Rt=>re=>re>Zn?Rt:re>=bn?Rt+1|0:Rt)(0)(R.incoming)|0;return Pt===We?Pt>0?{...Tt,deps:Tt.deps+2|0,crossings:Tt.crossings+Pt|0}:Tt:{...Tt,deps:Tt.deps+1|0,crossings:Tt.crossings+Dn(Pt)(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)(gt))(y(it)(1e18)(R.outgoing)),Jt=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),Et=y(bt=>Pt=>Pt>st?bt:Pt>=nt?bt+1|0:bt)(0)(R.outgoing)+y(bt=>Pt=>Pt>Jt?bt:Pt>=yt?bt+1|0:bt)(0)(dt._1.incoming)|0,Dt=it(y(it)(1e18)(gt))(y(it)(1e18)(R.outgoing)),ne=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),$e=it(y(it)(1e18)(dt._1.incoming))(y(it)(1e18)(dt._1.outgoing)),Un=ut(y(ut)(-1e18)(dt._1.incoming))(y(ut)(-1e18)(dt._1.outgoing)),nn=y(bt=>Pt=>Pt>ne?bt:Pt>=Dt?bt+1|0:bt)(0)(dt._1.outgoing)+y(bt=>Pt=>Pt>Un?bt:Pt>=$e?bt+1|0:bt)(0)(gt)|0;return Et===nn?Et>0?{...rt,deps:rt.deps+2|0,crossings:rt.crossings+Et|0}:rt:{...rt,deps:rt.deps+1|0,crossings:rt.crossings+Dn(Et)(nn)|0}}f()}})())({crossings:0,deps:0})(at(ht=>ht.tgt===R.id,l.deps)))(at(ht=>ht.src===R.id,l.deps)),ct=(()=>{if(R.splitBy.tag==="Just")return Nt(R.splitBy._1)(Y.segMap);if(R.splitBy.tag==="Nothing")return T;f()})();if(ct.tag==="Just")return{...pt,deps:pt.deps+2|0,crossings:(()=>{const ht=it(y(it)(1e18)(ct._1.incoming))(y(it)(1e18)(ct._1.outgoing)),Tt=it(y(it)(1e18)(gt))(y(it)(1e18)(R.outgoing)),Gt=ut(y(ut)(-1e18)(ct._1.incoming))(y(ut)(-1e18)(ct._1.outgoing)),dt=ut(y(ut)(-1e18)(gt))(y(ut)(-1e18)(R.outgoing)),Wt=it(y(it)(1e18)(R.incoming))(y(it)(1e18)(X));return pt.crossings+(()=>{const mt=it(y(it)(1e18)(ct._1.incoming))(y(it)(1e18)(ct._1.outgoing)),ft=ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(X)),rt=ut(y(ut)(-1e18)(ct._1.incoming))(y(ut)(-1e18)(ct._1.outgoing));return((y(nt=>st=>st>Gt?nt:st>=ht?nt+1|0:nt)(0)(X)+y(nt=>st=>st>ft?nt:st>=Wt?nt+1|0:nt)(0)(ct._1.incoming)|0)+y(nt=>st=>st>dt?nt:st>=Tt?nt+1|0:nt)(0)(ct._1.outgoing)|0)+y(nt=>st=>st>rt?nt:st>=mt?nt+1|0:nt)(0)(gt)|0})()|0})()};if(ct.tag==="Nothing")return pt;f()})()}))(M);return y(Q=>U=>U.rating.crossings<Q.rating.crossings||!(U.rating.crossings>Q.rating.crossings)&&(U.rating.deps<Q.rating.deps||!(U.rating.deps>Q.rating.deps)&&U.c.a.size>Q.c.a.size)?U:Q)(0<q.length?q[0]:{c:W._1,rating:{crossings:1e6,deps:1e6}})(q).c}f()})(),O={...R,incoming:vt(lt.compare)(R.incoming),outgoing:vt(lt.compare)([(H.a.startPosition+H.a.endPosition)/2]),splitPartner:b("Just",Y.nextId)},$={id:Y.nextId,incoming:vt(lt.compare)([(H.a.startPosition+H.a.endPosition)/2]),mark:0,members:R.members,outgoing:vt(lt.compare)(R.outgoing),slot:0,splitBy:T,splitPartner:b("Just",R.id)};return{segMap:Z(ot)($.id)($)(Z(ot)(O.id)(O)(Y.segMap)),freeAreas:(()=>{if(H.i>=0&&H.i<Y.freeAreas.length){const q=Gu(Kt,T,H.i,Y.freeAreas),Q=(()=>{if(q.tag==="Nothing")return Y.freeAreas;if(q.tag==="Just")return q._1;f()})();if(Y.freeAreas[H.i].size/2<d)return Q;const U=(Y.freeAreas[H.i].startPosition+Y.freeAreas[H.i].endPosition)/2,X=U-d,gt=U+d;return[...H.i<1?[]:Mt(0,H.i,Q),...Y.freeAreas[H.i].startPosition<=X?[{startPosition:Y.freeAreas[H.i].startPosition,endPosition:X,size:X-Y.freeAreas[H.i].startPosition}]:[],...gt<=Y.freeAreas[H.i].endPosition?[{startPosition:gt,endPosition:Y.freeAreas[H.i].endPosition,size:Y.freeAreas[H.i].endPosition-gt}]:[],...H.i<1?Q:Mt(H.i,Q.length,Q)]}return Y.freeAreas})(),nextId:Y.nextId+1|0}})({segMap:K,freeAreas:(()=>{const Y=vt(lt.compare)([...Ct(l.segments)(R=>R.incoming),...Ct(l.segments)(R=>R.outgoing)]);return St(N1)(me(R=>C=>C-R>=2*d?b("Just",{startPosition:R+d,endPosition:C-d,size:C-R-2*d}):T,Y,Mt(1,Y.length,Y)))})(),nextId:l.segments.length})(vt(Y=>R=>lt.compare(ut(y(ut)(-1e18)(Y.incoming))(y(ut)(-1e18)(Y.outgoing))-it(y(it)(1e18)(Y.incoming))(y(it)(1e18)(Y.outgoing)))(ut(y(ut)(-1e18)(R.incoming))(y(ut)(-1e18)(R.outgoing))-it(y(it)(1e18)(R.incoming))(y(it)(1e18)(R.outgoing))))(St(Y=>Nt(Y)(K))(et.decisions)));return{segments:(()=>{const Y=(R,C)=>{if(R.tag==="Leaf")return C;if(R.tag==="Node")return Y(R._5,Qt("Cons",R._4,Y(R._6,C)));f()};return Lt(qt.foldr,Y(A.segMap,Bt))})(),deps:(()=>{const Y=A.segMap,R=(M,W)=>{if(M.tag==="Leaf")return W;if(M.tag==="Node")return R(M._5,Qt("Cons",M._4,R(M._6,W)));f()},C=Lt(qt.foldr,R(Y,Bt)),z=C.length;return[...Ct(Ct($t(0,z-2|0))(M=>Ct($t(M+1|0,z-1|0))(W=>[x(M,W)])))(M=>M._1>=0&&M._1<C.length?M._2>=0&&M._2<C.length?C[M._1].splitPartner.tag!=="Nothing"&&C[M._1].splitPartner.tag==="Just"&&C[M._1].splitPartner._1===C[M._2].id||C[M._2].splitPartner.tag!=="Nothing"&&C[M._2].splitPartner.tag==="Just"&&C[M._2].splitPartner._1===C[M._1].id?[]:i(d,C[M._1],C[M._2]):[]:[]),...Ct(C)(M=>M.splitBy.tag==="Just"&&M.splitPartner.tag==="Just"&&(()=>{const W=Nt(M.splitPartner._1)(Y);if(W.tag==="Nothing")return!1;if(W.tag==="Just")return!0;f()})()&&(()=>{const W=Nt(M.splitBy._1)(Y);if(W.tag==="Nothing")return!1;if(W.tag==="Just")return!0;f()})()?[{src:M.id,tgt:M.splitBy._1,weight:1,kind:eo},{src:M.splitBy._1,tgt:M.splitPartner._1,weight:1,kind:eo}]:[])]})()}})(),m=h.segments,p=m.length,J=G=>{let P=G,et=!0,K;for(;et;){const A=P,Y=ge(R=>{const C=Nt(R)(A.inWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;f()})(A.remaining);if(Y.tag==="Nothing"){et=!1,K=A;continue}if(Y.tag==="Just"){const R=Y._1;P={...A,inWeight:y(C=>z=>xt(ot)(Ut)(z.tgt)(-z.weight)(C))(A.inWeight)((()=>{const C=Nt(R)(A.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;f()})()),marks:Z(ot)(R)(A.nextSource)(A.marks),nextSource:A.nextSource+1|0,outWeight:y(C=>z=>xt(ot)(Ut)(z.src)(-z.weight)(C))(A.outWeight)((()=>{const C=Nt(R)(A.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;f()})()),remaining:at(C=>C!==R,A.remaining)};continue}f()}return K},N=G=>{let P=G,et=!0,K;for(;et;){const A=P,Y=ge(R=>{const C=Nt(R)(A.outWeight);if(C.tag==="Nothing")return!0;if(C.tag==="Just")return C._1===0;f()})(A.remaining);if(Y.tag==="Nothing"){et=!1,K=A;continue}if(Y.tag==="Just"){const R=Y._1;P={...A,inWeight:y(C=>z=>xt(ot)(Ut)(z.tgt)(-z.weight)(C))(A.inWeight)((()=>{const C=Nt(R)(A.depsBySrc);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;f()})()),marks:Z(ot)(R)(A.nextSink)(A.marks),nextSink:A.nextSink-1|0,outWeight:y(C=>z=>xt(ot)(Ut)(z.src)(-z.weight)(C))(A.outWeight)((()=>{const C=Nt(R)(A.depsByTgt);if(C.tag==="Nothing")return[];if(C.tag==="Just")return C._1;f()})()),remaining:at(C=>C!==R,A.remaining)};continue}f()}return K},v=(G=>{let P=G,et=!0,K;for(;et;){const A=J(N(P));if(A.remaining.length===0){et=!1,K=V(Y=>{const R=Nt(Y.id)(A.marks),C=(()=>{if(R.tag==="Nothing")return Y.id;if(R.tag==="Just")return R._1;f()})();return{...Y,mark:C<p?(C+p|0)+1|0:C}})(m);continue}P=(()=>{const Y=C=>{const z=Nt(C)(A.outWeight),M=Nt(C)(A.inWeight);return(()=>{if(z.tag==="Nothing")return 0;if(z.tag==="Just")return z._1;f()})()-(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;f()})()|0},R=vt(C=>z=>ot.compare(Y(z))(Y(C)))(A.remaining);if(0<R.length){const C=R[0];return{...A,inWeight:y(z=>M=>xt(ot)(Ut)(M.tgt)(-M.weight)(z))(A.inWeight)((()=>{const z=Nt(C)(A.depsBySrc);if(z.tag==="Nothing")return[];if(z.tag==="Just")return z._1;f()})()),marks:Z(ot)(C)(A.nextSource)(A.marks),nextSource:A.nextSource+1|0,outWeight:y(z=>M=>xt(ot)(Ut)(M.src)(-M.weight)(z))(A.outWeight)((()=>{const z=Nt(C)(A.depsByTgt);if(z.tag==="Nothing")return[];if(z.tag==="Just")return z._1;f()})()),remaining:at(z=>z!==C,A.remaining)}}return A})()}return K})({remaining:V(G=>G.id)(m),marks:D,inWeight:y(G=>P=>xt(ot)(Ut)(P.tgt)(P.weight)(G))(D)(h.deps),outWeight:y(G=>P=>xt(ot)(Ut)(P.src)(P.weight)(G))(D)(h.deps),depsBySrc:y(G=>P=>xt(ot)(ie)(P.src)([P])(G))(D)(h.deps),depsByTgt:y(G=>P=>xt(ot)(ie)(P.tgt)([P])(G))(D)(h.deps),nextSink:p-1|0,nextSource:p+1|0}),L=(()=>{const G=(()=>{const K=An(V(A=>x(A.id,A.mark))(v));return{segments:v,deps:St(A=>(()=>{if(A.kind==="Critical")return!0;if(A.kind==="Regular")return!1;f()})()?b("Just",A):(()=>{const Y=Nt(A.src)(K),R=Nt(A.tgt)(K);return(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;f()})()>(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;f()})()})()?A.weight===0?T:b("Just",{src:A.tgt,tgt:A.src,weight:A.weight,kind:A.kind}):b("Just",A))(h.deps)}})(),P=y(K=>A=>xt(ot)(Ut)(A.tgt)(1)(K))(D)(G.deps),et=(K=>{let A=K,Y=!0,R;for(;Y;){const C=A,z=Ft(M=>T,M=>W=>b("Just",{head:M,tail:W}),C.queue);if(z.tag==="Nothing"){Y=!1,R=C;continue}if(z.tag==="Just"){A=y((()=>{const M=Nt(z._1.head)(C.slots),W=(()=>{if(M.tag==="Nothing")return 0;if(M.tag==="Just")return M._1;f()})();return H=>O=>{const $=Nt(O)(H.inDegree),q=(()=>{if($.tag==="Nothing")return-1;if($.tag==="Just")return $._1-1|0;f()})();return{...H,slots:Z(ot)(O)(Ts((()=>{const Q=Nt(O)(H.slots);if(Q.tag==="Nothing")return 0;if(Q.tag==="Just")return Q._1;f()})())(W+1|0))(H.slots),inDegree:Z(ot)(O)(q)(H.inDegree),queue:q===0?[...H.queue,O]:H.queue}}})())({...C,queue:z._1.tail})((()=>{const M=Nt(z._1.head)(C.adj);if(M.tag==="Nothing")return[];if(M.tag==="Just")return M._1;f()})());continue}f()}return R})({slots:An(V(K=>x(K.id,0))(G.segments)),inDegree:P,adj:y(K=>A=>xt(ot)(ie)(A.src)([A.tgt])(K))(D)(G.deps),queue:V(K=>K.id)(at(K=>{const A=Nt(K.id)(P);if(A.tag==="Nothing")return!0;if(A.tag==="Just")return A._1===0;f()},G.segments))});return vt(K=>A=>ot.compare(K.slot)(A.slot))(V(K=>({...K,slot:(()=>{const A=Nt(K.id)(et.slots);if(A.tag==="Nothing")return 0;if(A.tag==="Just")return A._1;f()})()}))(G.segments))})(),E=1+y(G=>P=>Ts(G)(P.slot))(0)(L)|0,k=Ct(L)(G=>G.members),S=at(G=>Ie(Ve)(G.edge.id)(k),e),I=y(ut)(-1e18)(V(G=>G.fromPos._2)(S)),F=y(it)(1e18)(V(G=>G.toPos._2)(S));if(I>F){const G=An(V(P=>x(P.id,P))(L));return Ne(V(P=>V(et=>x(et,{slot:P.slot,slotCount:E,gapTop:F,gapBottom:I,partner:(()=>{if(P.splitPartner.tag==="Just"){const K=Nt(P.splitPartner._1)(G);if(K.tag==="Just")return b("Just",{slot:K._1.slot,splitX:0<K._1.incoming.length?K._1.incoming[0]:0});if(K.tag==="Nothing")return T;f()}if(P.splitPartner.tag==="Nothing")return T;f()})()}))(P.members))(at(P=>{if(P.splitPartner.tag==="Just"){const et=Nt(P.splitPartner._1)(G);return!(et.tag==="Just"&&(()=>{if(et._1.splitBy.tag==="Nothing")return!1;if(et._1.splitBy.tag==="Just")return!0;f()})())}if(P.splitPartner.tag==="Nothing")return!0;f()},L)))}const j=An(V(G=>x(G.id,G))(L));return Ne(V(G=>V(P=>x(P,{slot:G.slot,slotCount:E,gapTop:I,gapBottom:F,partner:(()=>{if(G.splitPartner.tag==="Just"){const et=Nt(G.splitPartner._1)(j);if(et.tag==="Just")return b("Just",{slot:et._1.slot,splitX:0<et._1.incoming.length?et._1.incoming[0]:0});if(et.tag==="Nothing")return T;f()}if(G.splitPartner.tag==="Nothing")return T;f()})()}))(G.members))(at(G=>{if(G.splitPartner.tag==="Just"){const P=Nt(G.splitPartner._1)(j);return!(P.tag==="Just"&&(()=>{if(P._1.splitBy.tag==="Nothing")return!1;if(P._1.splitBy.tag==="Just")return!0;f()})())}if(G.splitPartner.tag==="Nothing")return!0;f()},L)))})()))(D)(J1(y(u=>s=>{const a=Xe(s.edge.from.node)(n);if(a.tag==="Just"){const c=Xe(s.edge.to.node)(n);return c.tag==="Just"&&a._1.layer!==c._1.layer?xt(ot)(ie)(Dn(a._1.layer)(c._1.layer))([s])(u):u}return u})(D)((()=>{const u=s=>x((()=>{const a=Xe(s.edge.from.node)(n);return a.tag==="Just"?a._1.layer:1e6})(),(()=>{const a=Xe(s.edge.from.node)(n);return a.tag==="Just"?a._1.order:1e6})());return vt(s=>a=>y1(u(s))(u(a)))(e)})())))},x1=e=>t=>{const n=Ls(e)(t),r=y(o=>i=>Z(w)(i.node)(i)(o))(D)(t);return y(o=>i=>{const u=Xe(i.edge.from.node)(r);if(u.tag==="Just"){const s=Xe(i.edge.to.node)(r);if(s.tag==="Just"&&u._1.layer!==s._1.layer){const a=Xe(i.edge.id)(n);if(a.tag==="Just")return Z(ot)(Dn(u._1.layer)(s._1.layer))(a._1.slotCount)(o)}return o}return o})(D)(e)},ws=e=>e,Xt=ws("H"),Ot=ws("V"),ks=It.foldMap((()=>{const e={append:t=>n=>t||n};return{mempty:!1,Semigroup0:()=>e}})()),te=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},ee=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},pr=e=>t=>n=>r=>ks(o=>n>=o.x&&n<o.x+o.w&&t>o.y&&e<o.y+o.h)(r),no=e=>t=>n=>r=>pr(te(t)(n))(ee(t)(n))(r)(e),ro=_t(4),v1=Mu(e=>{if(e.direction==="H"){const t=te(e.start._1)(e.end._1);return[{x:t,y:e.start._2-1,w:ee(e.start._1)(e.end._1)-t,h:2}]}if(e.direction==="V"){const t=te(e.start._2)(e.end._2);return[{x:e.start._1-1,y:t,w:2,h:ee(e.start._2)(e.end._2)-t}]}f()}),bs=Xf(e=>!(e.start._1===e.end._1&&e.start._2===e.end._2)),T1=e=>t=>n=>{const r=Ft(o=>T,o=>i=>b("Just",{head:o,tail:i}),t);if(r.tag==="Nothing")return[{start:e.start,end:n.end,direction:e.direction}];if(r.tag==="Just"){const o=(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],i=Ff(r._1.tail);if(i.tag==="Nothing"){const u=o.length-1|0;return u>=0&&u<o.length&&(o[u].direction==="H"?n.direction==="H":o[u].direction==="V"&&n.direction==="V")?[...(()=>{const s=o.length-1|0;return s<1?[]:Mt(0,s,o)})(),{start:o[u].start,end:n.end,direction:n.direction}]:[...o,n]}if(i.tag==="Just")return(i._1.last.direction==="H"?n.direction==="H":i._1.last.direction==="V"&&n.direction==="V")?[...o,...i._1.init,{start:i._1.last.start,end:n.end,direction:n.direction}]:[...o,...r._1.tail,n]}f()},Ei=e=>{const t=r=>o=>{const i=Ft(u=>T,u=>s=>b("Just",{head:u,tail:s}),o);if(i.tag==="Nothing")return[r];if(i.tag==="Just")return(r.direction==="H"?i._1.head.direction==="H":r.direction==="V"&&i._1.head.direction==="V")&&(()=>{if(r.direction==="H")return r.end._1-r.start._1>=0==i._1.head.end._1-i._1.head.start._1>=0;if(r.direction==="V")return r.end._2-r.start._2>=0==i._1.head.end._2-i._1.head.start._2>=0;f()})()?t({start:r.start,end:i._1.head.end,direction:r.direction})(i._1.tail):[r,...t(i._1.head)(i._1.tail)];f()},n=Ft(r=>T,r=>o=>b("Just",{head:r,tail:o}),e);if(n.tag==="Nothing")return[];if(n.tag==="Just")return t(n._1.head)(n._1.tail);f()},mr=e=>t=>n=>r=>ks(o=>n>=o.y&&n<o.y+o.h&&t>o.x&&e<o.x+o.w)(r),yr=e=>t=>n=>r=>mr(te(t)(n))(ee(t)(n))(r)(e),L1=e=>t=>n=>r=>{const o=n+2|0,i=o<1?t:Mt(o,t.length,t),u=n<1?[]:Mt(0,n,t),s=(n+1|0)===(r-1|0),a=n===0,c=n>=0&&n<t.length?b("Just",t[n]):T;if(c.tag==="Just"){const g=n+1|0,d=g>=0&&g<t.length?b("Just",t[g]):T;if(d.tag==="Just"){const l=c._1.start._1===d._1.end._1&&(!a||c._1.direction==="V")&&(!s||d._1.direction==="V")&&!no(e)(te(c._1.start._2)(d._1.end._2))(ee(c._1.start._2)(d._1.end._2))(c._1.start._1)?b("Just",[...u,{start:c._1.start,end:d._1.end,direction:Ot},...i]):T,_=c._1.start._2===d._1.end._2&&(!a||c._1.direction==="H")&&(!s||d._1.direction==="H")&&!yr(e)(te(c._1.start._1)(d._1.end._1))(ee(c._1.start._1)(d._1.end._1))(c._1.start._2)?b("Just",[...u,{start:c._1.start,end:d._1.end,direction:Xt},...i]):T;return l.tag==="Nothing"?_:l}if(d.tag==="Nothing")return T;f()}if(c.tag==="Nothing")return T;f()},w1=e=>t=>{const n=t.length;return(r=>{let o=r,i=!0,u;for(;i;){const s=o;if((s+1|0)>=n){i=!1,u=t;continue}const a=L1(e)(t)(s)(n);if(a.tag==="Just"){i=!1,u=a._1;continue}if(a.tag==="Nothing"){o=s+1|0;continue}f()}return u})(0)},k1=e=>t=>n=>r=>{const o=(l,_,h)=>!no(e)(te(_)(h))(ee(_)(h))(l),i=n+3|0,u=i<1?t:Mt(i,t.length,t),s=n<1?[]:Mt(0,n,t),a=(n+2|0)===(r-1|0),c=n===0,g=(l,_,h)=>!yr(e)(te(_)(h))(ee(_)(h))(l),d=n>=0&&n<t.length?b("Just",t[n]):T;if(d.tag==="Just"){const l=n+2|0,_=l>=0&&l<t.length?b("Just",t[l]):T;if(_.tag==="Just"){const h=d._1.start._1===_._1.end._1&&(!c||d._1.direction==="V")&&(!a||_._1.direction==="V")&&o(d._1.start._1,d._1.start._2,_._1.end._2)?b("Just",[...s,{start:d._1.start,end:_._1.end,direction:Ot},...u]):d._1.start._2===_._1.end._2&&(!c||d._1.direction==="H")&&(!a||_._1.direction==="H")&&g(d._1.start._2,d._1.start._1,_._1.end._1)?b("Just",[...s,{start:d._1.start,end:_._1.end,direction:Xt},...u]):T,m=(!c||d._1.direction==="V")&&(!a||_._1.direction==="H")&&o(d._1.start._1,d._1.start._2,_._1.end._2)&&g(_._1.end._2,d._1.start._1,_._1.end._1)?b("Just",[...s,{start:d._1.start,end:x(d._1.start._1,_._1.end._2),direction:Ot},{start:x(d._1.start._1,_._1.end._2),end:_._1.end,direction:Xt},...u]):T,p=(!c||d._1.direction==="H")&&(!a||_._1.direction==="V")&&g(d._1.start._2,d._1.start._1,_._1.end._1)&&o(_._1.end._1,d._1.start._2,_._1.end._2)?b("Just",[...s,{start:d._1.start,end:x(_._1.end._1,d._1.start._2),direction:Xt},{start:x(_._1.end._1,d._1.start._2),end:_._1.end,direction:Ot},...u]):T,J=m.tag==="Nothing"?p:m;return h.tag==="Nothing"?J:h}if(_.tag==="Nothing")return T;f()}if(d.tag==="Nothing")return T;f()},b1=e=>t=>{const n=t.length;return(r=>{let o=r,i=!0,u;for(;i;){const s=o;if((s+2|0)>=n){i=!1,u=t;continue}const a=k1(e)(t)(s)(n);if(a.tag==="Just"){i=!1,u=a._1;continue}if(a.tag==="Nothing"){o=s+1|0;continue}f()}return u})(0)},E1=e=>{const t=n=>{let r=n,o=!0,i;for(;o;){const u=r,s=Ei(bs(w1(e)(b1(e)(u))));if(s.length<u.length){r=s;continue}o=!1,i=s}return i};return n=>t(Ei(bs(n)))},C1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=at(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>o&&a.x<i,e);if(r>n){const a=vt(c=>g=>lt.compare(c.x)(g.x))(u);return 0<a.length?a[0].x-1:(n+r)/2}const s=vt(a=>c=>lt.compare(c.x)(a.x))(V(a=>({...a,x:a.x+a.w}))(u));return 0<s.length?s[0].x+1:(n+r)/2},S1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=at(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>o&&a.y<i,e);if(r>n){const a=vt(c=>g=>lt.compare(c.y)(g.y))(u);return 0<a.length?a[0].y-1:(n+r)/2}const s=vt(a=>c=>lt.compare(c.y)(a.y))(V(a=>({...a,y:a.y+a.h}))(u));return 0<s.length?s[0].y+1:(n+r)/2},P1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=at(a=>t>=a.y&&t<a.y+a.h&&a.x+a.w>o&&a.x<i,e);if(r>n){const a=vt(c=>g=>lt.compare(g.x)(c.x))(V(c=>({...c,x:c.x+c.w}))(u));return 0<a.length?a[0].x:(n+r)/2}const s=vt(a=>c=>lt.compare(a.x)(c.x))(u);return 0<s.length?s[0].x-1:(n+r)/2},G1=e=>t=>n=>r=>{const o=te(n)(r),i=ee(n)(r),u=at(a=>t>=a.x&&t<a.x+a.w&&a.y+a.h>o&&a.y<i,e);if(r>n){const a=vt(c=>g=>lt.compare(g.y)(c.y))(V(c=>({...c,y:c.y+c.h}))(u));return 0<a.length?a[0].y:(n+r)/2}const s=vt(a=>c=>lt.compare(a.y)(c.y))(u);return 0<s.length?s[0].y-1:(n+r)/2},Es=e=>t=>n=>{let r=e,o=t,i=n,u=!0,s;for(;u;){const a=r,c=o,g=i;if(g>100){u=!1,s=c;continue}if(!a(c+g)){u=!1,s=c+g;continue}if(!a(c-g)){u=!1,s=c-g;continue}r=a,o=c,i=g+1}return s},Cs=e=>t=>n=>r=>o=>{const i=te(t)(n),u=ee(t)(n);if(!pr(i)(u)(r)(e))return r;if(!pr(i)(u)(o)(e))return o;const s=(r+o)/2;return pr(i)(u)(s)(e)?Es(a=>pr(i)(u)(a)(e))(s)(1):s},z1=e=>t=>n=>r=>o=>{const i=te(t)(n),u=ee(t)(n);if(!mr(i)(u)(r)(e))return r;if(!mr(i)(u)(o)(e))return o;const s=(r+o)/2;return mr(i)(u)(s)(e)?Es(a=>mr(i)(u)(a)(e))(s)(1):s},M1=e=>t=>n=>r=>{const o=te(t)(n),i=ee(t)(n),u=at(c=>r>=c.x&&r<c.x+c.w&&c.y+c.h>o&&c.y<i,e),s=y(c=>g=>ee(c)(g.x+g.w+4))(r+4)(u),a=y(c=>g=>te(c)(g.x-4))(r-4)(u);return(()=>{const c=s-r,g=a-r;return(c<0?-c:c)<=(g<0?-g:g)})()?s:a},W1=e=>t=>n=>r=>{const o=te(t)(n),i=ee(t)(n),u=at(c=>r>=c.y&&r<c.y+c.h&&c.x+c.w>o&&c.x<i,e),s=y(c=>g=>ee(c)(g.y+g.h+4))(r+4)(u),a=y(c=>g=>te(c)(g.y-4))(r-4)(u);return(()=>{const c=s-r,g=a-r;return(c<0?-c:c)<=(g<0?-g:g)})()?s:a},R1=e=>t=>n=>r=>o=>i=>u=>{const s=(()=>{if(r==="South")return x(o._1,o._2+4);if(r==="North")return x(o._1,o._2-4);if(r==="East")return x(o._1+4,o._2);if(r==="West")return x(o._1-4,o._2);f()})(),a=(()=>{if(i==="South")return x(u._1,u._2+4);if(i==="North")return x(u._1,u._2-4);if(i==="East")return x(u._1+4,u._2);if(i==="West")return x(u._1-4,u._2);f()})(),c=(E,k,S)=>!no(t)(te(k)(S))(ee(k)(S))(E),g=(E,k,S)=>!no(n)(te(k)(S))(ee(k)(S))(E),d=(E,k,S,I)=>e.tag==="Just"&&!yr(n)(te(E)(k))(ee(E)(k))(e._1)?e._1:z1(t)(E)(k)(S)(I),l=(E,k,S,I)=>{if(E===S){const j=M1(t)(k)(I)(E),G=S1(t)(E)(k)(I),P=G1(t)(E)(k)(I);return[{start:x(E,k),end:x(E,G),direction:Ot},{start:x(E,G),end:x(j,G),direction:Xt},{start:x(j,G),end:x(j,P),direction:Ot},{start:x(j,P),end:x(S,P),direction:Xt},{start:x(S,P),end:x(S,I),direction:Ot}]}const F=d(E,S,k,I);return[{start:x(E,k),end:x(E,F),direction:Ot},{start:x(E,F),end:x(S,F),direction:Xt},{start:x(S,F),end:x(S,I),direction:Ot}]},_=(E,k,S,I)=>{if(k===I){const j=W1(t)(E)(S)(k),G=C1(t)(k)(E)(S),P=P1(t)(k)(E)(S);return[{start:x(E,k),end:x(G,k),direction:Xt},{start:x(G,k),end:x(G,j),direction:Ot},{start:x(G,j),end:x(P,j),direction:Xt},{start:x(P,j),end:x(P,I),direction:Ot},{start:x(P,I),end:x(S,I),direction:Xt}]}const F=Cs(t)(k)(I)(E)(S);return[{start:x(E,k),end:x(F,k),direction:Xt},{start:x(F,k),end:x(F,I),direction:Ot},{start:x(F,I),end:x(S,I),direction:Xt}]},h=(E,k,S)=>!yr(t)(te(k)(S))(ee(k)(S))(E),m=(E,k,S)=>!yr(n)(te(k)(S))(ee(k)(S))(E),p=(E,k,S,I)=>{if(m(k,E,S)&&g(S,k,I))return[{start:x(E,k),end:x(S,k),direction:Xt},{start:x(S,k),end:x(S,I),direction:Ot}];const F=Cs(t)(k)(I)(E)(S);return[{start:x(E,k),end:x(F,k),direction:Xt},{start:x(F,k),end:x(F,I),direction:Ot},{start:x(F,I),end:x(S,I),direction:Xt}]},J=(E,k,S,I)=>{if(g(E,k,I)&&m(I,E,S))return[{start:x(E,k),end:x(E,I),direction:Ot},{start:x(E,I),end:x(S,I),direction:Xt}];const F=d(E,S,k,I);return[{start:x(E,k),end:x(E,F),direction:Ot},{start:x(E,F),end:x(S,F),direction:Xt},{start:x(S,F),end:x(S,I),direction:Ot}]},N=(()=>{if(r==="South")return i==="North"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Ot}]:l(s._1,s._2,a._1,a._2):i==="East"||i==="West"?J(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="North")return i==="South"?s._1===a._1&&c(s._1,s._2,a._2)?[{start:x(s._1,s._2),end:x(a._1,a._2),direction:Ot}]:l(s._1,s._2,a._1,a._2):i==="East"||i==="West"?J(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="East")return i==="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:Xt}]:_(s._1,s._2,a._1,a._2):i==="North"||i==="South"?p(s._1,s._2,a._1,a._2):l(s._1,s._2,a._1,a._2);if(r==="West"){if(i==="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:Xt}]:_(s._1,s._2,a._1,a._2);if(i==="North"||i==="South")return p(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 Ot;if(r==="East"||r==="West")return Xt;f()})(),L={start:x(a._1,a._2),end:x(u._1,u._2),direction:(()=>{if(i==="South"||i==="North")return Ot;if(i==="East"||i==="West")return Xt;f()})()};return s._1===a._1&&s._2===a._2?[{start:x(o._1,o._2),end:x(u._1,u._2),direction:v}]:T1({start:x(o._1,o._2),end:x(s._1,s._2),direction:v})(N)(L)},Q1=V(e=>({x:e.position._1*ro-2,y:e.position._2*ro-2,w:e.size._1*ro+4,h:e.size._2*ro+4})),Ss=jt(w)(It),Oe=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},I1=jt(w)(It),Ps=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},B1=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e._1)(i._3._1);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(e._2==="North"){if(i._3._2==="North"){r=!1,o=b("Just",i._4);continue}n=i._5;continue}if(i._3._2==="North"){n=i._6;continue}if(e._2==="South"){if(i._3._2==="South"){r=!1,o=b("Just",i._4);continue}n=i._5;continue}if(i._3._2==="South"){n=i._6;continue}if(e._2==="East"){if(i._3._2==="East"){r=!1,o=b("Just",i._4);continue}n=i._5;continue}if(i._3._2==="East"){n=i._6;continue}if(e._2==="West"&&i._3._2==="West"){r=!1,o=b("Just",i._4);continue}}f()}return o},A1=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Gs=e=>t=>{const n=t.position._1+t.size._1,r=t.position._2*2+t.size._2,o=t.position._1*2+t.size._1,i=t.position._2+t.size._2;if(e==="South")return x(o,i*2);if(e==="North")return x(o,t.position._2*2);if(e==="East")return x(n*2,r);if(e==="West")return x(t.position._1*2,r);f()},Ci=e=>t=>{const n=_t(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};f()},zs=e=>t=>y(n=>r=>xt(e)(ie)(t(r))([r])(n))(D),Ms=e=>t=>n=>r=>{const o=(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;f()})()&&(()=>{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;f()})(),i=(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;f()})()&&(()=>{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;f()})();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:o||i?1:2},Ws=e=>t=>{const n=e.hi-e.lo,r=(e.lo+e.hi)/2,o=t.length;return o===0?D:Ss(o===1?V(i=>x(i,r))(t):zt(i=>u=>x(u,e.lo+_t(i+1|0)*n/_t(o+1|0)))(t))},Rs=e=>t=>n=>r=>o=>{const i=zs(w)(_=>_.to.node)(e),u=zs(w)(_=>_.from.node)(e),s=y(_=>h=>Z(w)(h.node)(h)(_))(D)(t),a=(_,h,m)=>{const p=Oe(_)(s);if(p.tag==="Nothing")return x(0,0);if(p.tag==="Just"){const J=Oe(_)(n);if(J.tag==="Nothing"){const N=_t(4);if(m==="South")return x(p._1.position._1*N+p._1.size._1*N/2,(p._1.position._2+p._1.size._2)*N);if(m==="North")return x(p._1.position._1*N+p._1.size._1*N/2,p._1.position._2*N);if(m==="East")return x((p._1.position._1+p._1.size._1)*N,p._1.position._2*N+p._1.size._2*N/2);if(m==="West")return x(p._1.position._1*N,p._1.position._2*N+p._1.size._2*N/2);f()}if(J.tag==="Just"){const N=ge(v=>v.id===h)(J._1);if(N.tag==="Nothing"){const v=_t(4);if(m==="South")return x(p._1.position._1*v+p._1.size._1*v/2,(p._1.position._2+p._1.size._2)*v);if(m==="North")return x(p._1.position._1*v+p._1.size._1*v/2,p._1.position._2*v);if(m==="East")return x((p._1.position._1+p._1.size._1)*v,p._1.position._2*v+p._1.size._2*v/2);if(m==="West")return x(p._1.position._1*v,p._1.position._2*v+p._1.size._2*v/2);f()}if(N.tag==="Just"){const v=_t(4);if(N._1.side==="North")return x(p._1.position._1*v+_t(N._1.offset)*v,p._1.position._2*v);if(N._1.side==="South")return x(p._1.position._1*v+_t(N._1.offset)*v,(p._1.position._2+p._1.size._2)*v);if(N._1.side==="East")return x((p._1.position._1+p._1.size._1)*v,p._1.position._2*v+_t(N._1.offset)*v);if(N._1.side==="West")return x(p._1.position._1*v,p._1.position._2*v+_t(N._1.offset)*v)}}}f()},c=I1(Ct(r)(_=>{if(_.nodes.length<=2)return[];const h=_t(4);if(1<_.nodes.length){const m=Oe(_.nodes[1])(s);if(m.tag==="Nothing")return[];if(m.tag==="Just"){const p=m._1.position._1*h+m._1.size._1*h/2;return V(J=>x(J,p))(me(J=>N=>_.edgeId+":"+J+"->"+N,_.nodes,Mt(1,_.nodes.length,_.nodes)))}f()}return[]})),g=_=>{const h=Oe(_.from.node)(s),m=Oe(_.to.node)(s);if(h.tag==="Just"&&m.tag==="Just"){const p=h._1,J=m._1,N=vt(v=>L=>ot.compare(v.score)(L.score))(V(v=>{const L=v._1,E=v._2;return{from:L,to:E,score:(()=>{const k=(j,G,P,et,K)=>{const A=Ci(j)(G),Y=Ci(j)(P);return A.lo<Y.hi&&Y.lo<A.hi&&(L==="South"?E==="North"&&K._2>et._2:L==="North"?E==="South"&&K._2<et._2:L==="East"?E==="West"&&K._1>et._1:L==="West"&&E==="East"&&K._1<et._1)?0:Ms(L)(E)(et)(K)},S=Gs(L)(p),I=Gs(E)(J),F=Ms(L)(E)(S)(I);return(()=>{if(F>0){if(L==="South")return E==="North"?k(se,p,J,S,I)*10|0:F*10|0;if(L==="North")return E==="South"?k(ue,p,J,S,I)*10|0:F*10|0;if(L==="East")return E==="West"?k(mn,p,J,S,I)*10|0:F*10|0;if(L==="West"&&E==="East")return k(yn,p,J,S,I)*10|0}return F*10|0})()+(L==="South"?E==="North"?0:15:L==="North"?E==="South"?0:15:L==="East"?E==="West"?5:15:L==="West"&&E==="East"?5:15)|0})()}})([x(se,ue),x(mn,ue),x(yn,ue),x(se,mn),x(se,yn),x(ue,se),x(ue,mn),x(ue,yn),x(mn,se),x(yn,se),x(mn,yn),x(yn,mn)]));if(0<N.length)return{from:N[0].from,to:N[0].to}}return{from:se,to:ue}},d=Ss(V(_=>x(_.id,g(_)))(e)),l=(_,h,m,p,J,N)=>{const v=_t(4),L=Oe(h)(s);if(L.tag==="Nothing")return x(0,0);if(L.tag==="Just"){const E=B1(x(m,_))(o);if(E.tag==="Just"){const k=L._1.position._1*v+E._1,S=_t(4);if(_==="South")return x(k,(L._1.position._2+L._1.size._2)*S);if(_==="North")return x(k,L._1.position._2*S);if(_==="East")return x((L._1.position._1+L._1.size._1)*S,k);if(_==="West")return x(L._1.position._1*S,k);f()}if(E.tag==="Nothing"){const k=Ci(_)(L._1),S=(k.lo+k.hi)/2,I=Ps(m)(Ws(k)(V(G=>G.id)(vt(G=>P=>lt.compare(J(_)(G))(J(_)(P)))(at(G=>{const P=Ps(G.id)(d);if(P.tag==="Just"){const et=N(P._1);return et==="North"?_==="North":et==="South"?_==="South":et==="East"?_==="East":et==="West"&&_==="West"}if(P.tag==="Nothing")return!0;f()},(()=>{const G=Oe(h)(p);if(G.tag==="Nothing")return[];if(G.tag==="Just")return G._1;f()})()))))),F=(()=>{if(I.tag==="Nothing")return S;if(I.tag==="Just")return I._1;f()})(),j=_t(4);if(_==="South")return x(F,(L._1.position._2+L._1.size._2)*j);if(_==="North")return x(F,L._1.position._2*j);if(_==="East")return x((L._1.position._1+L._1.size._1)*j,F);if(_==="West")return x(L._1.position._1*j,F)}}f()};return V(_=>{const h=A1(_.edge.id)(c);if(h.tag==="Nothing")return _;if(h.tag==="Just")return{..._,fromPos:oe(3)(_.edge.from.node)==="$d:"?x(h._1,_.fromPos._2):_.fromPos,toPos:oe(3)(_.edge.to.node)==="$d:"?x(h._1,_.toPos._2):_.toPos};f()})(V(_=>{if(_.from.port.tag==="Just"&&_.to.port.tag==="Just")return{edge:_,fromPos:a(_.from.node,_.from.port._1,se),toPos:a(_.to.node,_.to.port._1,ue),fromSide:se,toSide:ue};const h=g(_);return{edge:_,fromPos:l(h.from,_.from.node,_.id,u,m=>p=>{const J=Oe(p.to.node)(s);if(J.tag==="Nothing")return 0;if(J.tag==="Just"){const N=_t(4);if(m==="South"||m==="North")return J._1.position._1*N+J._1.size._1*N/2;if(m==="East"||m==="West")return J._1.position._2*N+J._1.size._2*N/2}f()},m=>m.from),toPos:l(h.to,_.to.node,_.id,i,m=>p=>{const J=Oe(p.from.node)(s);if(J.tag==="Nothing")return 0;if(J.tag==="Just"){const N=_t(4);if(m==="South"||m==="North")return J._1.position._1*N+J._1.size._1*N/2;if(m==="East"||m==="West")return J._1.position._2*N+J._1.size._2*N/2}f()},m=>m.to),fromSide:h.from,toSide:h.to}})(e))},Qs=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},qn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},D1=(()=>{const e=Pe.unfoldr(dn);return t=>e(Ge("IterNode",t,_n))})(),Si=e=>t=>e.gapTop+1*_t(4)+_t(t)*2.5*_t(4),q1=e=>t=>{const n=Qs(t.edge.id)(e);if(n.tag==="Just"){if(n._1.partner.tag==="Just")return b("Just",{slot1Y:Si(n._1)(n._1.slot),splitX:n._1.partner._1.splitX,slot2Y:Si(n._1)(n._1.partner._1.slot)});if(n._1.partner.tag==="Nothing")return T;f()}if(n.tag==="Nothing")return T;f()},Y1=e=>t=>{const n=y(r=>o=>Z(w)(o.node)(o)(r))(D)(t);return Ne(zt(r=>o=>{const i=qn(o.node)(n);if(i.tag==="Nothing")return[];if(i.tag==="Just"){const u=i._1;return zt(s=>a=>{const c=o.edges.length,g=_t(4),d=u.position._1*g,l=u.position._2*g,_=u.size._2*g,h=_t((2*c|0)+1|0),m=l+_*_t(c-s|0)/h,p=l+_*_t((c+1|0)+s|0)/h,J=d-g*2.5*_t(s+1|0),N=[{start:x(d,m),end:x(J,m),direction:Xt},{start:x(J,m),end:x(J,p),direction:Ot},{start:x(J,p),end:x(d,p),direction:Xt}];return{edge:a.id,segments:N,bends:me(v=>L=>v.end,N,Mt(1,3,N)),bendType:[],jumps:[],reversed:!1}})(o.edges)}f()})(V(r=>({node:r._1,edges:r._2}))(D1(y(r=>o=>xt(w)(ie)(o.from.node)([o])(r))(D)(e)))))},$1=e=>t=>{const n=y(i=>u=>Z(w)(u.node)(u)(i))(D)(t),r=i=>{const u=qn(i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.position._1;f()},o=i=>{const u=qn(i)(n);if(u.tag==="Nothing")return 0;if(u.tag==="Just")return u._1.layer;f()};return vt(i=>u=>{const s=ot.compare(o(i.edge.from.node))(o(u.edge.from.node));if(s==="EQ"){const a=lt.compare(r(i.edge.from.node))(r(u.edge.from.node));return a==="EQ"?lt.compare(r(i.edge.to.node))(r(u.edge.to.node)):a}return s})(e)},de=e=>{const t=_t(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}},F1=e=>e.from.node===e.to.node,H1=e=>t=>n=>r=>{const o=E1(n)(R1(e)(t)(n)(r.fromSide)(r.fromPos)(r.toSide)(r.toPos));return{edge:r.edge.id,segments:o,bends:me(i=>u=>i.end,o,Mt(1,o.length,o)),bendType:[],jumps:[],reversed:!1}},V1=e=>t=>n=>r=>{const o=[{start:x(r.fromPos._1,r.fromPos._2),end:x(r.fromPos._1,e.slot1Y),direction:Ot},{start:x(r.fromPos._1,e.slot1Y),end:x(e.splitX,e.slot1Y),direction:Xt},{start:x(e.splitX,e.slot1Y),end:x(e.splitX,e.slot2Y),direction:Ot},{start:x(e.splitX,e.slot2Y),end:x(r.toPos._1,e.slot2Y),direction:Xt},{start:x(r.toPos._1,e.slot2Y),end:x(r.toPos._1,r.toPos._2),direction:Ot}];return{edge:r.edge.id,segments:o,bends:me(i=>u=>i.end,o,Mt(1,5,o)),bendType:[],jumps:[],reversed:!1}},X1=e=>t=>n=>{const r=qn(e.edge.from.node)(n);if(r.tag==="Just"){const i=qn(e.edge.to.node)(n);return i.tag==="Just"?at(u=>!(u.h===de(r._1).h&&u.w===de(r._1).w&&u.x===de(r._1).x&&u.y===de(r._1).y)&&!(u.h===de(i._1).h&&u.w===de(i._1).w&&u.x===de(i._1).x&&u.y===de(i._1).y),t):at(u=>!(u.h===de(r._1).h&&u.w===de(r._1).w&&u.x===de(r._1).x&&u.y===de(r._1).y),t)}const o=qn(e.edge.to.node)(n);return o.tag==="Just"?at(i=>!(i.h===de(o._1).h&&i.w===de(o._1).w&&i.x===de(o._1).x&&i.y===de(o._1).y),t):at(i=>!0,t)},O1=e=>t=>{const n=Qs(t.edge.id)(e);if(n.tag==="Just")return b("Just",Si(n._1)(n._1.slot));if(n.tag==="Nothing")return T;f()},U1=e=>t=>n=>r=>o=>{const i=y(c=>g=>Z(w)(g.node)(g)(c))(D)(t),u=Q1(t),s=Rs(at(c=>c.from.node!==c.to.node,e))(t)(n)(r)(o),a=Ls(s)(t);return[...Y1(at(F1,e))(t),...y(c=>g=>{const d=X1(g)(u)(i),l=[...d,...c.edgeObstacles],_=q1(a)(g),h=(()=>{if(_.tag==="Just")return V1(_._1)(d)(l)(g);if(_.tag==="Nothing")return H1(O1(a)(g))(d)(l)(g);f()})();return{results:[...c.results,h],edgeObstacles:[...c.edgeObstacles,...v1(h.segments)]}})({results:[],edgeObstacles:[]})($1(s)(t)).results]},an=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},cn=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},K1=e=>t=>n=>{if(e.start._1!==t.start._1)return T;const r=cn(an(e.start._2)(e.end._2))(an(t.start._2)(t.end._2)),o=an(cn(e.start._2)(e.end._2))(cn(t.start._2)(t.end._2));return r<o?b("Just",{position:x(e.start._1,(r+o)/2),crossingEdge:n}):T},Z1=e=>t=>n=>{if(e.start._2!==t.start._2)return T;const r=cn(an(e.start._1)(e.end._1))(an(t.start._1)(t.end._1)),o=an(cn(e.start._1)(e.end._1))(cn(t.start._1)(t.end._1));return r<o?b("Just",{position:x((r+o)/2,e.start._2),crossingEdge:n}):T},j1=e=>t=>n=>{if(e.direction==="H")return Z1(e)(t)(n);if(e.direction==="V")return K1(e)(t)(n);f()},td=e=>t=>n=>{const r=e+1|0,o=r<1?n:Mt(r,n.length,n);return Ct(t.segments)(i=>Ct(o)(u=>St(s=>j1(i)(s)(u.edge))(at(s=>s.direction==="H"?i.direction==="H":s.direction==="V"&&i.direction==="V",u.segments))))},ed=e=>t=>n=>t.start._1>an(e.start._1)(e.end._1)&&t.start._1<cn(e.start._1)(e.end._1)&&e.start._2>an(t.start._2)(t.end._2)&&e.start._2<cn(t.start._2)(t.end._2)?b("Just",{position:x(t.start._1,e.start._2),crossingEdge:n}):T,nd=e=>t=>Ct(at(n=>n.direction==="H",e.segments))(n=>Ct(t)(r=>St(o=>ed(n)(o)(r.edge))(at(o=>o.direction==="V",r.segments)))),rd=e=>t=>n=>[...nd(t)(at(r=>r.edge!==t.edge,n)),...td(e)(t)(n)],oo=(()=>{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=w.compare(t._1)(n._1);if(r==="LT")return Re;if(r==="GT")return Qe;if(t._2==="North")return n._2==="North"?Fe:Re;if(n._2==="North")return Qe;if(t._2==="South")return n._2==="South"?Fe:Re;if(n._2==="South")return Qe;if(t._2==="East")return n._2==="East"?Fe:Re;if(n._2==="East")return Qe;if(t._2==="West"&&n._2==="West")return Fe;f()},Eq0:()=>e}})(),od=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=oo.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},id=jt(w)(It),Pi=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},ud=jt(oo)(It),Is=(()=>{const e=Pe.unfoldr(dn);return t=>e(Ge("IterNode",t,_n))})(),Yn=e=>t=>n=>r=>{const o=od(x(t,n))(e);if(o.tag==="Nothing")return r;if(o.tag==="Just")return o._1;f()},Bs=e=>t=>n=>{const r=id(Ne(V(u=>zt(s=>a=>x(a,s))(u))(e))),o=(u,s)=>{if(u==="South"){const a=Pi(s.to.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;f()}if(u==="North"){const a=Pi(s.from.node)(r);if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;f()}return 0},i=u=>y(s=>a=>pe(oo.compare,he,ud(V(c=>x(x(c._1,u),c._2))(Is(Ws({lo:0,hi:(()=>{const c=Pi(a._1)(n);if(c.tag==="Just")return c._1._1;if(c.tag==="Nothing")return oe(3)(a._1)==="$d:"?0:1;f()})()})(V(c=>c.id)(vt(c=>g=>ot.compare(o(u,c))(o(u,g)))(a._2)))))),s))(D)(Is(y(s=>a=>a.from.node===a.to.node?s:u==="South"?xt(w)(ie)(a.from.node)([a])(s):u==="North"?xt(w)(ie)(a.to.node)([a])(s):s)(D)(t)));return pe(oo.compare,he,i(ue),i(se))},As=e=>e,Ds=e=>e,qs=e=>e,sd=y(e=>t=>Z(w)(t)()(e))(D),ad=(()=>{const e=Pe.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return b("Just",x(t._1,t._2));f()});return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Qt("Cons",r._3,n(r._6,o)));f()};return n(t,Bt)})())})(),tt=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},we=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},Be=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},Ee=jt(w)(It),Gi=Sc(w),Jr=(()=>{const e=Pe.unfoldr(dn);return t=>e(Ge("IterNode",t,_n))})(),Ys=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},cd=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},fd=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=ot.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},$s=qs("VDown"),Fs=qs("VUp"),gd=Ds("ForwardPhase"),_d=Ds("StackPhase"),Hs=As("HRight"),Vs=As("HLeft"),dd=e=>t=>n=>{const r=y(u=>s=>xt(w)(Ut)(s.tgt)(1)(u))(D)(e),o=ad(sd([...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,Qt("Cons",s._4,u(s._6,a)));f()};return Lt(qt.foldr,u(t,Bt))})()])),i=y(u=>s=>xt(w)(ie)(s.src)([{target:s.tgt,sep:s.sep}])(u))(D)(e);return(u=>s=>a=>{let c=u,g=s,d=a,l=!0,_;for(;l;){const h=c,m=g,p=d,J=Ft(N=>T,N=>v=>b("Just",{head:N,tail:v}),h);if(J.tag==="Nothing"){l=!1,_=p;continue}if(J.tag==="Just"){const N=tt(J._1.head)(p),v=(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;f()})(),L=y(E=>k=>{const S=tt(k.target)(E.result),I=v+k.sep,F=tt(k.target)(E.indeg),j=(()=>{if(F.tag==="Nothing")return-1;if(F.tag==="Just")return F._1-1|0;f()})();return{newQueue:j===0?[...E.newQueue,k.target]:E.newQueue,result:Z(w)(k.target)((()=>{if(S.tag==="Nothing")return I;if(S.tag==="Just"){if(n==="VDown")return we(S._1)(I);if(n==="VUp")return Be(S._1)(I)}f()})())(E.result),indeg:Z(w)(k.target)(j)(E.indeg)}})({newQueue:[],result:p,indeg:m})((()=>{const E=tt(J._1.head)(i);if(E.tag==="Nothing")return[];if(E.tag==="Just")return E._1;f()})());c=[...J._1.tail,...L.newQueue],g=L.indeg,d=L.result;continue}f()}return _})(at(u=>{const s=tt(u)(r);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;f()},o))(D)(y(u=>s=>Z(w)(s)(0)(u))(D)(o))},ld=e=>{const t=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return t(i._5,Qt("Cons",i._4,t(i._6,u)));f()},n=Lt(qt.foldr,t(e,Bt)),r=y(we)(999999)(n);if(r===0||n.length===0)return e;const o=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Yt("Node",i._1,i._2,i._3,i._4-r,o(i._5),o(i._6));f()};return o(e)},hd=e=>t=>{const n=(o,i,u)=>oe(3)(i)==="$d:"&&zu(s=>oe(3)(s)==="$d:",(()=>{const s=tt(i)(e.preds);if(s.tag==="Nothing")return[];if(s.tag==="Just")return s._1;f()})()),r=o=>i=>u=>s=>a=>c=>g=>{let d=o,l=i,_=s,h=c,m=g,p=!0,J;for(;p;){const N=d,v=l,L=_,E=h,k=m,S=v.length;if(k>=S){p=!1,J=N;continue}const I=k>=0&&k<v.length?b("Just",v[k]):T,F=(()=>{if(I.tag==="Nothing")return"";if(I.tag==="Just")return I._1;f()})(),j=n(e,F);if(k===(S-1|0)||j){const G=(()=>{if(j){const P=tt(F)(e.preds),et=(()=>{if(P.tag==="Nothing")return[];if(P.tag==="Just")return P._1;f()})();if(0<et.length){const K=L-1|0,A=tt(et[0])(e.nodeIndex);if(A.tag==="Nothing")return K;if(A.tag==="Just")return A._1;f()}}return L-1|0})();d=y(P=>et=>{if(et>=0&&et<v.length){const K=v[et];return n(e,K)?P:y(A=>Y=>{const R=tt(Y)(e.nodeIndex),C=(()=>{if(R.tag==="Nothing")return 0;if(R.tag==="Just")return R._1;f()})();return C<E||C>G?Z(w)(Y+"\u2192"+K)()(A):A})(P)((()=>{const A=tt(K)(e.preds);if(A.tag==="Nothing")return[];if(A.tag==="Just")return A._1;f()})())}return n(e,"")?P:y(K=>A=>{const Y=tt(A)(e.nodeIndex),R=(()=>{if(Y.tag==="Nothing")return 0;if(Y.tag==="Just")return Y._1;f()})();return R<E||R>G?Z(w)(A+"\u2192")()(K):K})(P)((()=>{const K=tt("")(e.preds);if(K.tag==="Nothing")return[];if(K.tag==="Just")return K._1;f()})())})(N)($t(0,k)),l=v,_=L,h=G,m=k+1|0;continue}d=N,l=v,_=L,h=E,m=k+1|0}return J};return t.length<3?D:y(o=>i=>{if(i>=0&&i<t.length){const u=t[i];return r(o)((()=>{const s=i+1|0;return s>=0&&s<t.length?t[s]:[]})())(u)(u.length)(i)(0)(0)}return r(o)((()=>{const u=i+1|0;return u>=0&&u<t.length?t[u]:[]})())([])(0)(i)(0)(0)})(D)($t(1,t.length-2|0))},Xs=e=>{const t=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return t(i._5,Qt("Cons",i._4,t(i._6,u)));f()},n=t(e,Bt),r=i=>u=>{let s=i,a=u,c=!0,g;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,g=d;continue}if(l.tag==="Cons"){s=Be(d)(l._1),a=l._2;continue}f()}return g},o=i=>u=>{let s=i,a=u,c=!0,g;for(;c;){const d=s,l=a;if(l.tag==="Nil"){c=!1,g=d;continue}if(l.tag==="Cons"){s=we(d)(l._1),a=l._2;continue}f()}return g};return r(-999999)(n)-o(999999)(n)},Nr=e=>t=>(n=>r=>{let o=n,i=r,u=!0,s;for(;u;){const a=o,c=i;if(a===t){u=!1,s=c;continue}o=(()=>{const g=tt(a)(e.align);if(g.tag==="Nothing")return t;if(g.tag==="Just")return g._1;f()})(),i=[...c,a]}return s})((()=>{const n=tt(t)(e.align);if(n.tag==="Nothing")return t;if(n.tag==="Just")return n._1;f()})())([t]),pd=e=>t=>n=>r=>o=>i=>u=>s=>a=>c=>g=>{const d=(C,z,M)=>{const W=C.from.node===z?C.from.port:C.to.node===z?C.to.port:T;if(W.tag==="Just"){const H=tt(z)(o);if(H.tag==="Just"){const O=ge($=>$.id===W._1)(H._1);if(O.tag==="Just"){const $=_t(O._1.offset)*_t(4);return M==="North"||M==="South"?$:0}if(O.tag==="Nothing"){const $=tt(z)(r),q=Yn(u)(C.id)(M)((()=>{if($.tag==="Nothing")return .5;if($.tag==="Just")return $._1._1/2;f()})());return M==="North"||M==="South"?q:0}f()}if(H.tag==="Nothing"){const O=tt(z)(r),$=Yn(u)(C.id)(M)((()=>{if(O.tag==="Nothing")return .5;if(O.tag==="Just")return O._1._1/2;f()})());return M==="North"||M==="South"?$:0}f()}if(W.tag==="Nothing"){const H=tt(z)(r),O=Yn(u)(C.id)(M)((()=>{if(H.tag==="Nothing")return .5;if(H.tag==="Just")return H._1._1/2;f()})());return M==="North"||M==="South"?O:0}f()},l=(C,z)=>{if(C.from.node===z){if(g==="HRight")return se;if(g==="HLeft")return ue;f()}if(g==="HRight")return ue;if(g==="HLeft")return se;f()},_=(C,z,M)=>y(W=>H=>Z(w)(H)((()=>{const O=tt(H)(W);if(O.tag==="Nothing")return 0+z;if(O.tag==="Just")return O._1+z;f()})())(W))(M)(Nr(a)(C)),h=(()=>{if(g==="HRight")return n;if(g==="HLeft")return _e(n);f()})(),m=C=>{const z=tt(C)(r);if(z.tag==="Nothing")return 1;if(z.tag==="Just")return z._1._1;f()},p=Ee(Ne(zt(C=>z=>V(M=>x(M,C))(z))(n))),J=(C,z)=>oe(3)(C)==="$d:"&&oe(3)(z)==="$d:"||oe(3)(C)==="$d:"||oe(3)(z)==="$d:"?10:_t(e.nodeGap),N=y(C=>z=>Gi(M=>b("Just",[...(()=>{if(M.tag==="Nothing")return[];if(M.tag==="Just")return M._1;f()})(),z]))(z.to.node)(C))(D)(i),v=y(C=>z=>Gi(M=>b("Just",[...(()=>{if(M.tag==="Nothing")return[];if(M.tag==="Just")return M._1;f()})(),z]))(z.from.node)(C))(D)(i),L=Ne(n),E=y(C=>z=>{const M=tt(z)(a.root),W=(()=>{if(M.tag==="Nothing")return z;if(M.tag==="Just")return M._1;f()})();return z===W?C:Gi(H=>b("Just",(()=>{if(H.tag==="Nothing")return!0;if(H.tag==="Just")return H._1;f()})()&&oe(3)(z)==="$d:"))(W)(C)})(Ee(V(C=>x(C,!0))(zn(w.compare)((()=>{const C=(z,M)=>{if(z.tag==="Leaf")return M;if(z.tag==="Node")return C(z._5,Qt("Cons",z._4,C(z._6,M)));f()};return Lt(qt.foldr,C(a.root,Bt))})()))))(L),k=(C,z)=>{const M=C.free,W=tt(M)(a.root),H=(()=>{if(W.tag==="Nothing")return M;if(W.tag==="Just")return W._1;f()})(),O=tt(H)(E),$=(()=>{if(O.tag==="Nothing")return!0;if(O.tag==="Just")return O._1;f()})();return y(q=>Q=>{if(q.edge.tag==="Just")return q;if(q.edge.tag==="Nothing"){if((()=>{const ct=tt(H)(z.su);return!$&&(()=>{const ht=tt(Q.from.node)(p);return Q.from.node!==Q.to.node&&(()=>{const Tt=tt(Q.to.node)(p);return(()=>{if(ht.tag==="Nothing")return-1;if(ht.tag==="Just")return ht._1;f()})()===(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;f()})()})()})()||(()=>{if(ct.tag==="Nothing")return!1;if(ct.tag==="Just")return ct._1;f()})()})())return q;const U=Q.from.node===M?Q.to.node:Q.from.node,X=tt(U)(a.root),gt=(()=>{if(X.tag==="Nothing")return U;if(X.tag==="Just")return X._1;f()})(),pt=gt!==H;return pt&&(()=>{const ct=tt(gt)(z.blockFinished);if(ct.tag==="Nothing")return!1;if(ct.tag==="Just")return ct._1;f()})()?{...q,edge:b("Just",Q),hasEdges:!0}:{...q,hasEdges:q.hasEdges||pt}}f()})({edge:T,hasEdges:!1})((()=>{if(C.isRoot){if(g==="HRight"){const q=tt(M)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;f()}if(g==="HLeft"){const q=tt(M)(v);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}f()}if(g==="HRight"){const q=tt(M)(v);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1;f()}if(g==="HLeft"){const q=tt(M)(N);if(q.tag==="Nothing")return[];if(q.tag==="Just")return q._1}f()})())},S=(C,z,M,W)=>{const H=(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;f()})(),O={free:z,isRoot:M},$=k(O,W);if($.edge.tag==="Nothing")return $.hasEdges?{thresh:H,state:{...W,queue:[...W.queue,O]}}:{thresh:H,state:W};if($.edge.tag==="Just"){const q=$.edge._1.from.node===z?$.edge._1.to.node:$.edge._1.from.node;return{thresh:(()=>{const Q=tt((()=>{const pt=tt(q)(a.root);if(pt.tag==="Nothing")return q;if(pt.tag==="Just")return pt._1;f()})())(W.x),U=tt(q)(s),X=tt(z)(s),gt=(()=>{if(Q.tag==="Just")return Q._1;if(Q.tag==="Nothing")return T;f()})();return(()=>{if(gt.tag==="Nothing")return 0;if(gt.tag==="Just")return gt._1;f()})()+(()=>{if(U.tag==="Nothing")return 0;if(U.tag==="Just")return U._1;f()})()+d($.edge._1,q,(()=>{if(M){if(g==="HRight")return se;if(g==="HLeft")return ue;f()}if(g==="HRight")return ue;if(g==="HLeft")return se;f()})())-(()=>{if(X.tag==="Nothing")return 0;if(X.tag==="Just")return X._1;f()})()-d($.edge._1,z,(()=>{if(M){if(g==="HRight")return ue;if(g==="HLeft")return se;f()}if(g==="HRight")return se;if(g==="HLeft")return ue;f()})())})(),state:{...W,su:Z(w)((()=>{const Q=tt($.edge._1.from.node)(a.root);if(Q.tag==="Nothing")return $.edge._1.from.node;if(Q.tag==="Just")return Q._1;f()})())(!0)(Z(w)((()=>{const Q=tt($.edge._1.to.node)(a.root);if(Q.tag==="Nothing")return $.edge._1.to.node;if(Q.tag==="Just")return Q._1;f()})())(!0)(W.su))}}}f()},I=(C,z,M,W)=>{const H=z===C,O=tt(z)(a.align),$=(()=>{if(O.tag==="Nothing")return z===C;if(O.tag==="Just")return O._1===C;f()})();if(!(H||$))return{thresh:M,state:W};const q=(()=>{if(c==="VDown")return H&&M<=-1e18;if(c==="VUp")return H&&M>=1e18;f()})()?S(C,z,!0,W):{thresh:M,state:W};return(()=>{if(c==="VDown")return q.thresh<=-1e18&&$;if(c==="VUp")return q.thresh>=1e18&&$;f()})()?S(C,z,!1,q.state):q},F=C=>z=>M=>{const W=tt(M)(t.nodeIndex),H=(()=>{if(W.tag==="Nothing")return 0;if(W.tag==="Just")return W._1;f()})(),O=ge(X=>Ie(Ve)(M)(X))(h),$=(()=>{if(O.tag==="Nothing")return[];if(O.tag==="Just")return O._1;f()})(),q=$.length;if((()=>{if(c==="VDown")return H<=0;if(c==="VUp")return H>=(q-1|0);f()})()){const X=I(C,M,z.thresh,z.st);return{...z,st:X.state,thresh:X.thresh}}const Q=(()=>{if(c==="VDown")return H-1|0;if(c==="VUp")return H+1|0;f()})(),U=Q>=0&&Q<$.length?b("Just",$[Q]):T;if(U.tag==="Nothing")return z;if(U.tag==="Just"){const X=tt(U._1)(a.root),gt=(()=>{if(X.tag==="Nothing")return U._1;if(X.tag==="Just")return X._1;f()})(),pt=I(C,M,z.thresh,j(gt)(z.st)),ct=(()=>{const ne=tt(C)(pt.state.sink);if(ne.tag==="Nothing")return C===C;if(ne.tag==="Just")return ne._1===C;f()})()?{...pt.state,sink:Z(w)(C)((()=>{const ne=tt(gt)(pt.state.sink);if(ne.tag==="Nothing")return gt;if(ne.tag==="Just")return ne._1;f()})())(pt.state.sink)}:pt.state,ht=tt(gt)(ct.sink),Tt=(()=>{if(ht.tag==="Nothing")return gt;if(ht.tag==="Just")return ht._1;f()})(),Gt=tt(C)(ct.sink),dt=(()=>{if(Gt.tag==="Nothing")return C;if(Gt.tag==="Just")return Gt._1;f()})();if(dt===Tt){const ne=tt(gt)(ct.x),$e=(()=>{if(ne.tag==="Just")return ne._1;if(ne.tag==="Nothing")return T;f()})(),Un=(()=>{if($e.tag==="Nothing")return 0;if($e.tag==="Just")return $e._1;f()})(),nn=tt(C)(ct.x),bt=(()=>{if(nn.tag==="Just")return nn._1;if(nn.tag==="Nothing")return T;f()})(),Pt=(()=>{if(bt.tag==="Nothing")return 0;if(bt.tag==="Just")return bt._1;f()})(),Kn=J(M,U._1),kn=tt(U._1)(s),bn=tt(M)(s),Zn=(()=>{if(kn.tag==="Nothing")return 0;if(kn.tag==="Just")return kn._1;f()})()-(()=>{if(bn.tag==="Nothing")return 0;if(bn.tag==="Just")return bn._1;f()})();if(c==="VDown"){const We=Be(Un+Zn+m(U._1)+Kn)(pt.thresh);return{st:{...ct,x:Z(w)(C)(b("Just",z.initial?We:Be(Pt)(We)))(ct.x)},initial:!1,thresh:pt.thresh}}if(c==="VUp"){const We=we(Un+Zn-Kn-m(M))(pt.thresh);return{st:{...ct,x:Z(w)(C)(b("Just",z.initial?We:we(Pt)(We)))(ct.x)},initial:!1,thresh:pt.thresh}}f()}const Wt=tt(gt)(ct.x),mt=(()=>{if(Wt.tag==="Just")return Wt._1;if(Wt.tag==="Nothing")return T;f()})(),ft=(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;f()})(),rt=tt(C)(ct.x),nt=(()=>{if(rt.tag==="Just")return rt._1;if(rt.tag==="Nothing")return T;f()})(),st=(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;f()})(),yt=_t(e.nodeGap),Jt=tt(M)(s),Et=tt(U._1)(s),Dt=(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;f()})()-(()=>{if(Et.tag==="Nothing")return 0;if(Et.tag==="Just")return Et._1;f()})();return{st:{...ct,classEdges:[...ct.classEdges,{src:dt,tgt:Tt,sep:(()=>{if(c==="VDown")return st+Dt-ft-m(U._1)-yt;if(c==="VUp")return st+Dt+m(M)+yt-ft;f()})()}]},initial:z.initial,thresh:pt.thresh}}f()},j=C=>z=>{const M=tt(C)(z.x),W=(()=>{if(M.tag==="Just")return M._1;if(M.tag==="Nothing")return T;f()})();if(W.tag==="Just")return z;if(W.tag==="Nothing"){const H=y(F(C))({st:{...z,x:Z(w)(C)(b("Just",0))(z.x)},initial:!0,thresh:(()=>{if(c==="VDown")return-1e18;if(c==="VUp")return 1e18;f()})()})(Nr(a)(C));return{...H.st,blockFinished:Z(w)(C)(!0)(H.st.blockFinished)}}f()},G=y(C=>z=>y(M=>W=>{const H=tt(W)(a.root),O=(()=>{if(H.tag==="Nothing")return W;if(H.tag==="Just")return H._1;f()})();return O===W?j(O)(M):M})(C)((()=>{if(c==="VDown")return z;if(c==="VUp")return _e(z);f()})()))({x:Ee(V(C=>x(C,T))(L)),sink:Ee(V(C=>x(C,C))(L)),classEdges:[],su:D,blockFinished:D,queue:[]})(h),P=dd(G.classEdges)(G.sink)(c),et=(C,z,M,W)=>{const H=tt(z)(W),O=tt(z)(s);return(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;f()})()+(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;f()})()+d(C,z,M)},K=Ee(V(C=>x(C,!0))(zn(w.compare)((()=>{const C=(z,M)=>{if(z.tag==="Leaf")return M;if(z.tag==="Node")return C(z._5,Qt("Cons",z._4,C(z._6,M)));f()};return Lt(qt.foldr,C(a.root,Bt))})()))),A=C=>z=>M=>{const W=k(M,{su:z.su,blockFinished:K}),H={phase:C,ppFree:M.free,ppIsRoot:M.isRoot,edgeId:T,delta:0,avail:0,shift:0,freeSu:(()=>{const O=tt((()=>{const $=tt(M.free)(a.root);if($.tag==="Nothing")return M.free;if($.tag==="Just")return $._1;f()})())(z.su);if(O.tag==="Nothing")return!1;if(O.tag==="Just")return O._1;f()})(),hasEdges:W.hasEdges,candCount:(()=>{if(M.isRoot){if(g==="HRight"){const O=tt(M.free)(N);if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1.length;f()}if(g==="HLeft"){const O=tt(M.free)(v);if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1.length}f()}if(g==="HRight"){const O=tt(M.free)(v);if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1.length;f()}if(g==="HLeft"){const O=tt(M.free)(N);if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1.length}f()})()};if(W.edge.tag==="Nothing")return{...z,stack:[...z.stack,M],trace:[...z.trace,H],x:z.x};if(W.edge.tag==="Just"){const O=W.edge._1.from.node===M.free?x(W.edge._1.from.node,W.edge._1.to.node):x(W.edge._1.to.node,W.edge._1.from.node),$=et(W.edge._1,O._1,l(W.edge._1,O._1),z.x)-et(W.edge._1,O._2,l(W.edge._1,O._2),z.x),q=tt(O._1)(a.root),Q=(()=>{if(q.tag==="Nothing")return O._1;if(q.tag==="Just")return q._1;f()})(),U={...H,edgeId:b("Just",W.edge._1.id),delta:$};if($>0&&$<1e300){const X=y(ct=>ht=>{const Tt=tt(ht)(p),Gt=(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;f()})();if(Gt>=0&&Gt<n.length){const mt=n[Gt],ft=tt(ht)(t.nodeIndex),rt=(()=>{if(ft.tag==="Nothing")return-2;if(ft.tag==="Just")return ft._1-1|0;f()})();return rt>=0&&rt<mt.length?we(ct)((()=>{const nt=tt(ht)(z.x),st=tt(ht)(s),yt=tt(mt[rt])(z.x),Jt=tt(mt[rt])(s);return(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;f()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;f()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;f()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;f()})()+m(mt[rt])+J(ht,mt[rt]))})()):ct}const dt=tt(ht)(t.nodeIndex),Wt=(()=>{if(dt.tag==="Nothing")return-2;if(dt.tag==="Just")return dt._1-1|0;f()})();return Wt>=0&&Wt<0?we(ct)((()=>{const mt=tt(ht)(z.x),ft=tt(ht)(s),rt=tt([][Wt])(z.x),nt=tt([][Wt])(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;f()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;f()})()-((()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;f()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;f()})()+m([][Wt])+J(ht,[][Wt]))})()):ct})($)(Nr(a)(Q)),gt=X>0?-X:0,pt={...z,x:X>0?_(Q,gt,z.x):z.x,trace:[...z.trace,{...U,avail:X,shift:gt}]};return X>0?pt:{...pt,stack:[...pt.stack,M]}}if($<0&&-$<1e300){const X=y(ct=>ht=>{const Tt=tt(ht)(p),Gt=(()=>{if(Tt.tag==="Nothing")return-1;if(Tt.tag==="Just")return Tt._1;f()})();if(Gt>=0&&Gt<n.length){const mt=n[Gt],ft=tt(ht)(t.nodeIndex),rt=(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1+1|0;f()})();return rt>=0&&rt<mt.length?we(ct)((()=>{const nt=tt(mt[rt])(z.x),st=tt(mt[rt])(s),yt=tt(ht)(z.x),Jt=tt(ht)(s);return(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;f()})()+(()=>{if(st.tag==="Nothing")return 0;if(st.tag==="Just")return st._1;f()})()-((()=>{if(yt.tag==="Nothing")return 0;if(yt.tag==="Just")return yt._1;f()})()+(()=>{if(Jt.tag==="Nothing")return 0;if(Jt.tag==="Just")return Jt._1;f()})()+m(ht)+J(ht,mt[rt]))})()):ct}const dt=tt(ht)(t.nodeIndex),Wt=(()=>{if(dt.tag==="Nothing")return 0;if(dt.tag==="Just")return dt._1+1|0;f()})();return Wt>=0&&Wt<0?we(ct)((()=>{const mt=tt([][Wt])(z.x),ft=tt([][Wt])(s),rt=tt(ht)(z.x),nt=tt(ht)(s);return(()=>{if(mt.tag==="Nothing")return 0;if(mt.tag==="Just")return mt._1;f()})()+(()=>{if(ft.tag==="Nothing")return 0;if(ft.tag==="Just")return ft._1;f()})()-((()=>{if(rt.tag==="Nothing")return 0;if(rt.tag==="Just")return rt._1;f()})()+(()=>{if(nt.tag==="Nothing")return 0;if(nt.tag==="Just")return nt._1;f()})()+m(ht)+J(ht,[][Wt]))})()):ct})(-$)(Nr(a)(Q)),gt=X>0?X:0,pt={...z,x:X>0?_(Q,gt,z.x):z.x,trace:[...z.trace,{...U,avail:X,shift:gt}]};return X>0?pt:{...pt,stack:[...pt.stack,M]}}return{...z,stack:[...z.stack,M],trace:[...z.trace,U],x:z.x}}f()},Y=y(A(gd))({x:Ee(V(C=>x(C,(()=>{const z=tt(C)(a.root),M=(()=>{if(z.tag==="Nothing")return C;if(z.tag==="Just")return z._1;f()})(),W=tt(M)(G.x),H=tt((()=>{const $=tt(M)(G.sink);if($.tag==="Nothing")return M;if($.tag==="Just")return $._1;f()})())(P),O=(()=>{if(W.tag==="Just")return W._1;if(W.tag==="Nothing")return T;f()})();return(()=>{if(O.tag==="Nothing")return 0;if(O.tag==="Just")return O._1;f()})()+(()=>{if(H.tag==="Nothing")return 0;if(H.tag==="Just")return H._1;f()})()})()))(L)),su:G.su,stack:[],trace:[]})(G.queue),R=y(A(_d))({...Y,stack:[]})(_e(Y.stack));return{x:R.x,queue:G.queue,trace:R.trace}},md=e=>t=>n=>r=>o=>i=>u=>s=>a=>c=>g=>pd(e)(t)(n)(r)(o)(i)(u)(s)(a)(c)(g).x,yd=e=>t=>n=>r=>o=>i=>{const u=(a,c,g)=>{const d=tt(c)(n),l=(()=>{if(d.tag==="Nothing")return .5;if(d.tag==="Just")return d._1._1/2;f()})(),_=a.from.node===c?a.from.port:a.to.node===c?a.to.port:T;if(_.tag==="Just"){const h=tt(c)(t);if(h.tag==="Just"){const m=ge(p=>p.id===_._1)(h._1);if(m.tag==="Just"){const p=_t(m._1.offset)*_t(4);return g==="North"||g==="South"?p:0}if(m.tag==="Nothing"){const p=Yn(o)(a.id)(g)(l);return g==="North"||g==="South"?p:0}f()}if(h.tag==="Nothing"){const m=Yn(o)(a.id)(g)(l);return g==="North"||g==="South"?m:0}f()}if(_.tag==="Nothing"){const h=Yn(o)(a.id)(g)(l);return g==="North"||g==="South"?h:0}f()},s=a=>c=>g=>d=>{let l=a,_=c,h=g,m=d,p=!0,J;for(;p;){const N=l,v=_,L=h,E=Ft(k=>T,k=>S=>b("Just",{head:k,tail:S}),m);if(E.tag==="Nothing"){p=!1,J=N;continue}if(E.tag==="Just"){const k=E._1.head,S=ge(F=>F.from.node===L&&F.to.node===k||F.from.node===k&&F.to.node===L)(r),I=(()=>{if(S.tag==="Nothing")return v+0;if(S.tag==="Just")return v+(u(S._1,L,S._1.from.node===L?se:ue)-u(S._1,k,S._1.from.node===k?se:ue));f()})();l=Z(w)(k)(I)(N),_=I,h=k,m=E._1.tail;continue}f()}return J};return y(a=>c=>{const g=Ft(_=>T,_=>h=>b("Just",{head:_,tail:h}),Nr(e)(c)),d=(()=>{if(g.tag==="Nothing")return Z(w)(c)(0)(D);if(g.tag==="Just")return s(Z(w)(g._1.head)(0)(D))(0)(g._1.head)(g._1.tail);f()})(),l=y(_=>h=>Be(_)(-h._2))(0)(Jr(d));return y(_=>h=>Z(w)(h._1)(h._2+l)(_))(a)(Jr(d))})(D)(zn(w.compare)((()=>{const a=(c,g)=>{if(c.tag==="Leaf")return g;if(c.tag==="Node")return a(c._5,Qt("Cons",c._4,a(c._6,g)));f()};return Lt(qt.foldr,a(e.root,Bt))})()))},Jd=e=>t=>n=>r=>o=>{const i=Ne(t),u=y(s=>a=>{const c=y(g=>d=>{const l=(()=>{if(o==="HRight"){const p=tt(d)(e.preds);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;f()}if(o==="HLeft"){const p=tt(d)(e.succs);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1}f()})(),_=l.length;if(_===0)return g;const h=En(_-1|0,2),m=En(_,2);return y(p=>J=>{if((()=>{const N=tt(d)(p.align);if(N.tag==="Nothing")return d!==d;if(N.tag==="Just")return N._1!==d;f()})())return p;if(J>=0&&J<l.length){const N=tt(l[J])(e.nodeIndex),v=(()=>{if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;f()})();if(!(Ys(l[J]+"\u2192"+d)(n)||Ys(d+"\u2192"+l[J])(n))&&(()=>{if(r==="VDown")return p.r<v;if(r==="VUp")return p.r>v;f()})()){const L=tt(l[J])(p.root),E=(()=>{if(L.tag==="Nothing")return l[J];if(L.tag==="Just")return L._1;f()})();return{root:Z(w)(d)(E)(p.root),align:Z(w)(l[J])(d)(Z(w)(d)(E)(p.align)),r:v}}}return p})(g)((()=>{if(r==="VDown")return $t(h,m);if(r==="VUp")return _e($t(h,m));f()})())})({root:s.root,align:s.align,r:(()=>{if(r==="VDown")return-1;if(r==="VUp")return 999999;f()})()})((()=>{if(r==="VDown")return a;if(r==="VUp")return _e(a);f()})());return{root:c.root,align:c.align}})({root:Ee(V(s=>x(s,s))(i)),align:Ee(V(s=>x(s,s))(i))})((()=>{if(o==="HRight")return t;if(o==="HLeft")return _e(t);f()})());return{root:u.root,align:u.align}},io=e=>t=>n=>r=>o=>i=>u=>s=>a=>c=>{const g=Jd(t)(n)(s)(a)(c),d=yd(g)(o)(r)(i)(u)(c);return Cc()(l=>_=>b("Just",(()=>{const h=tt(l)(d);if(h.tag==="Nothing")return _+0;if(h.tag==="Just")return _+h._1;f()})()))(md(e)(t)(n)(r)(o)(i)(u)(d)(g)(a)(c))},Os=e=>t=>zt(n=>r=>y(o=>i=>i>=0&&i<t.length?i>=0&&i<e.length?o+t[i]+e[i]:o+t[i]+0:i>=0&&i<e.length?o+1+e[i]:o+1)(0)((()=>{const o=$t(0,t.length-1|0);return n<1?[]:Mt(0,n,o)})()))(t),Nd=e=>t=>n=>r=>o=>i=>u=>{const s=cd(0)(t.length-1|0),a=_t(e.layerGap),c=u(Bf(s,a)),g=x1(Rs(o)(c)(r)(i)(D))(c);return V(d=>{const l=fd(d)(g);return l.tag==="Just"&&l._1>0?Be(a)(2+_t(l._1-1|0)*2.5):a})($t(0,s-1|0))},Us=e=>t=>n=>r=>zu(o=>y(i=>u=>{if(!i.ok)return i;const s=tt(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})(),c=tt(u)(n),g=(()=>{if(c.tag==="Nothing")return a+1;if(c.tag==="Just")return a+c._1._1;f()})();return a+1e-4>i.pos&&g+1e-4>i.pos?{ok:!0,pos:g}:{ok:!1,pos:i.pos}})({ok:!0,pos:-1e18})(o).ok,t),xd=e=>t=>n=>r=>{const o=vt(i=>u=>lt.compare(i.w)(u.w))(V(i=>({l:i,w:Xs(i)}))(at(Us()(t)(n),r)));return 0<o.length?b("Just",o[0].l):T},vd=e=>t=>{const n=Ee(Ne(V(zt(o=>i=>x(i,o)))(e))),r=o=>vt(i=>u=>ot.compare((()=>{const s=tt(i)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})())((()=>{const s=tt(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})()))(o);return{preds:(()=>{const o=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Yt("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));f()};return o(y(i=>u=>xt(w)(ie)(u.to.node)([u.from.node])(i))(D)(t))})(),succs:(()=>{const o=i=>{if(i.tag==="Leaf")return D;if(i.tag==="Node")return Yt("Node",i._1,i._2,i._3,r(i._4),o(i._5),o(i._6));f()};return o(y(i=>u=>xt(w)(ie)(u.from.node)([u.to.node])(i))(D)(t))})(),nodeIndex:n}},Td=e=>t=>{const n=vt(d=>l=>lt.compare(d.w)(l.w))(zt(d=>l=>({i:d,l,w:Xs(l)}))(t)),r=0<n.length?b("Just",n[0]):T,o=(()=>{if(r.tag==="Just")return r._1.i;if(r.tag==="Nothing")return 0;f()})(),i=o>=0&&o<t.length?b("Just",t[o]):T,u=(()=>{if(i.tag==="Just")return(d=>l=>{let _=d,h=l,m=!0,p;for(;m;){const J=_,N=h;if(N.tag==="Nil"){m=!1,p=J;continue}if(N.tag==="Cons"){_=we(J)(N._1),h=N._2;continue}f()}return p})(999999)((()=>{const d=(l,_)=>{if(l.tag==="Leaf")return _;if(l.tag==="Node")return d(l._5,Qt("Cons",l._4,d(l._6,_)));f()};return d(i._1,Bt)})());if(i.tag==="Nothing")return 0;f()})(),s=d=>y(l=>_=>Be(l)((()=>{const h=tt(_._1)(e);if(h.tag==="Nothing")return _._2+1;if(h.tag==="Just")return _._2+h._1._1;f()})()))(-999999)(Jr(d)),a=o>=0&&o<t.length?b("Just",t[o]):T,c=(()=>{if(a.tag==="Just")return s(a._1);if(a.tag==="Nothing")return 0;f()})(),g=me(d=>l=>{const _=h=>{if(h.tag==="Leaf")return D;if(h.tag==="Node")return Yt("Node",h._1,h._2,h._3,h._4+l,_(h._5),_(h._6));f()};return _(d)},t,zt(d=>l=>Go(d)(2)===0?u-(_=>h=>{let m=_,p=h,J=!0,N;for(;J;){const v=m,L=p;if(L.tag==="Nil"){J=!1,N=v;continue}if(L.tag==="Cons"){m=we(v)(L._1),p=L._2;continue}f()}return N})(999999)((()=>{const _=(h,m)=>{if(h.tag==="Leaf")return m;if(h.tag==="Node")return _(h._5,Qt("Cons",h._4,_(h._6,m)));f()};return _(l,Bt)})()):c-s(l))(t));return ld(y(d=>l=>{const _=vt(lt.compare)(St(tt(l))(g));return Z(w)(l)(_.length===4?1<_.length&&2<_.length?(_[1]+_[2])/2:0:0<_.length?_[0]:0)(d)})(D)(zn(w.compare)(Ne(V(d=>{const l=_=>{if(_.tag==="Leaf")return D;if(_.tag==="Node")return Yt("Node",_._1,_._2,_._3,void 0,l(_._5),l(_._6));f()};return Lt(Le.foldr,l(d))})(g)))))},Ld=e=>t=>n=>r=>o=>i=>{const u=vd(t)(o),s=hd(u)(t),a={nodeGap:e.nodeGap*4|0},c=pe(w.compare,he,Ee(V(_=>x(_,x(0,1)))(at(_=>oe(3)(_)==="$d:",Ne(t)))),(()=>{const _=h=>{if(h.tag==="Leaf")return D;if(h.tag==="Node")return Yt("Node",h._1,h._2,h._3,x(h._4._1*_t(4),h._4._2),_(h._5),_(h._6));f()};return _(n)})()),g=[io(a)(u)(t)(c)(r)(o)(i)(s)($s)(Hs),io(a)(u)(t)(c)(r)(o)(i)(s)(Fs)(Hs),io(a)(u)(t)(c)(r)(o)(i)(s)($s)(Vs),io(a)(u)(t)(c)(r)(o)(i)(s)(Fs)(Vs)],d=Td(c)(g);if(Us()(t)(c)(d))return d;const l=xd()(t)(c)(g);if(l.tag==="Just")return l._1;if(l.tag==="Nothing")return g[0];f()},wd=e=>t=>n=>r=>{const o=Af(T,gc,i=>i.node===t?b("Just",i.position):T,e);if(o.tag==="Nothing")return e;if(o.tag==="Just"){const i=o._1;return V(u=>u.node===n?{...u,position:x(i._1+r._1,i._2+r._2)}:u)(e)}f()},kd=e=>t=>n=>r=>{const o=at(u=>Ie(Ve)(u.node)(t),e),i=(()=>{if(n==="Vertical"){if(r==="Start")return y(u=>s=>we(u)(s.position._1))(99999)(o);if(r==="End")return y(u=>s=>Be(u)(s.position._1))(0)(o);if(r==="Center"){const u=y(s=>a=>s+a.position._1)(0)(o);return o.length===0?0:u/_t(o.length)}f()}if(n==="Horizontal"){if(r==="Start")return y(u=>s=>we(u)(s.position._2))(99999)(o);if(r==="End")return y(u=>s=>Be(u)(s.position._2))(0)(o);if(r==="Center"){const u=y(s=>a=>s+a.position._2)(0)(o);return o.length===0?0:u/_t(o.length)}}f()})();return V(u=>{if(Ie(Ve)(u.node)(t)){if(n==="Vertical")return{...u,position:x(i,u.position._2)};if(n==="Horizontal")return{...u,position:x(u.position._1,i)};f()}return u})(e)},bd=e=>t=>y(n=>r=>{if(r.tag==="Lock"){const o=r._1.node,i=r._1.position;return V(u=>u.node===o?{...u,position:i}:u)(n)}return r.tag==="AlignGroup"?kd(n)(V(Pu)(r._1.nodes))(r._1.axis)(r._1.alignment):r.tag==="RelativePosition"?wd(n)(r._1.anchor)(r._1.target)(r._1.offset):n})(t)(e),Ed=e=>t=>n=>r=>o=>i=>u=>s=>{const a=Ee(V(_=>x(_._1,_._2))(Jr(r))),c=V(V(Pu))(n),g=V(_=>y(h=>m=>Be(h)((()=>{const p=tt(m)(a);if(p.tag==="Nothing")return 1;if(p.tag==="Just")return p._1._2;f()})()))(1)(_))(c),d=Ld(e)(c)(a)(Ee(V(_=>x(_._1,_._2))(Jr(o))))(i)(s),l=Os(Nd(e)(n)(r)(o)(i)(u)(_=>{const h=Os(_)(g);return Ne(zt(m=>p=>zt(J=>N=>({node:N,position:x((()=>{const v=tt(N)(d);return(()=>{if(v.tag==="Nothing")return 0;if(v.tag==="Just")return v._1;f()})()/_t(4)})(),m>=0&&m<h.length?h[m]:0),size:(()=>{const v=oe(3)(N)==="$d:"?x(0,1):x(1,1),L=tt(N)(a);if(L.tag==="Nothing")return v;if(L.tag==="Just")return L._1;f()})(),layer:m,order:J}))(p))(c))}))(g);return bd(t)(Ne(zt(_=>h=>zt(m=>p=>({node:p,position:x((()=>{const J=tt(p)(d);return(()=>{if(J.tag==="Nothing")return 0;if(J.tag==="Just")return J._1;f()})()/_t(4)})(),_>=0&&_<l.length?l[_]:0),size:(()=>{const J=oe(3)(p)==="$d:"?x(0,1):x(1,1),N=tt(p)(a);if(N.tag==="Nothing")return J;if(N.tag==="Just")return N._1;f()})(),layer:_,order:m}))(h))(c)))},zi=ui($r)(pn(32)),Ks=ui($r)(pn(31)),xr=(()=>{const e=fg("25214903917");if(e.tag==="Nothing")return Du;if(e.tag==="Just")return e._1;f()})(),vr=ii(ui($r)(pn(48)))($r),Cd=e=>{const t=gg(e);return gr(qu((()=>{if(t.tag==="Nothing")return Du;if(t.tag==="Just")return t._1;f()})())(xr))(vr)},Mi=pn(11),uo=e=>t=>{const n=gr(qr(Yr(t)(xr))(Mi))(vr);return x((()=>{const r=Ju(ug(si(n)(pn(48-e|0))));if(r.tag==="Nothing")return 0;if(r.tag==="Just")return r._1;f()})(),n)},Sd=e=>{const t=uo(26)(e),n=uo(27)(t._2);return x((_t(t._1)*Co(2)(27)+_t(n._1))/Co(2)(53),n._2)},Pd=e=>t=>{const n=y(r=>o=>{const i=Sd(r.finalR);return{rs:[...r.rs,i._1],finalR:i._2}})({rs:[],finalR:e})(t);return x(V(r=>r.x)(vt(r=>o=>lt.compare(r.k)(o.k))(me(r=>o=>({x:r,k:o}),t,n.rs))),n.finalR)},Gd=e=>{const t=gr(qr(Yr(e)(xr))(Mi))(vr),n=gr(qr(Yr(t)(xr))(Mi))(vr);return x(qr(Yr((()=>{const r=si(t)(pn(16));return Yu.compare(r)(Ks)!=="LT"?ii(r)(zi):r})())(zi))((()=>{const r=si(n)(pn(16));return Yu.compare(r)(Ks)!=="LT"?ii(r)(zi):r})()),n)},Tr=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},so=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Wi=jt(w)(It),Ae=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},ao=jt(w)(It),zd=Qc(Mo),Md=y(nr)(0),Wd=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},Zs=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Rd=e=>t=>n=>r=>o=>Wi(y(i=>u=>{const s=vt(a=>c=>ot.compare((()=>{const g=Tr(a.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;f()})())((()=>{const g=Tr(c.id)(o);if(g.tag==="Nothing")return 1e6;if(g.tag==="Just")return g._1;f()})()))(at(a=>so(a.to.node)(n),at(a=>a.from.node===u,r)));return{ranks:[...i.ranks,...zt(a=>c=>x(c.id,_t((i.rankSum+a|0)+1|0)))(s)],rankSum:i.rankSum+s.length|0}})({ranks:[],rankSum:0})(e).ranks),Qd=e=>t=>n=>r=>o=>Wi(y(i=>u=>{const s=vt(c=>g=>{const d=ot.compare((()=>{const l=Ae(g.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;f()})())((()=>{const l=Ae(c.from.node)(n);if(l.tag==="Nothing")return-1;if(l.tag==="Just")return l._1;f()})());return d==="EQ"?ot.compare((()=>{const l=Tr(c.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;f()})())((()=>{const l=Tr(g.id)(o);if(l.tag==="Nothing")return 1e6;if(l.tag==="Just")return l._1;f()})()):d})(at(c=>so(c.from.node)(n),at(c=>c.to.node===u,r))),a=s.length;return{ranks:[...i.ranks,...zt(c=>g=>x(g.id,_t((i.rankSum+a|0)-c|0)))(s)],rankSum:i.rankSum+a|0}})({ranks:[],rankSum:0})(e).ranks),Ri=e=>t=>n=>{const r=ao(zt(s=>a=>x(a,s))(e)),o=ao(zt(s=>a=>x(a,s))(t)),i=St(s=>{const a=Ae(s.from.node)(r),c=Ae(s.to.node)(o);if(a.tag==="Just"&&c.tag==="Just")return b("Just",x(a._1,c._1));const g=Ae(s.from.node)(o),d=Ae(s.to.node)(r);return g.tag==="Just"&&d.tag==="Just"?b("Just",x(d._1,g._1)):T})(n),u=i.length;return y(s=>a=>y(c=>g=>a>=0&&a<i.length&&g>=0&&g<i.length&&((i[a]._1-i[g]._1|0)*(i[a]._2-i[g]._2|0)|0)<0?c+1|0:c)(s)($t(a+1|0,u-1|0)))(0)($t(0,u-2|0))},Id=e=>t=>n=>r=>o=>{const i=u=>s=>{let a=u,c=s,g=!0,d;for(;g;){const l=a,_=c;if(_>=(l.length-1|0)){g=!1,d=l;continue}const h=_>=0&&_<l.length?b("Just",l[_]):T,m=_+1|0;if(m>=0&&m<l.length&&h.tag==="Just"){const p=h._1,J=l[m];if(on(E=>E.before===p&&E.after===J,o)){a=l,c=_+1|0;continue}if((()=>{const E=Ae(p)(e),k=Ae(J)(e);return E.tag==="Just"&&k.tag==="Just"&&E._1<k._1})()){a=l,c=_+1|0;continue}const N=sr(Kt,T,_,J,l),v=(()=>{if(N.tag==="Just")return sr(Kt,T,_+1|0,p,N._1);if(N.tag==="Nothing")return T;f()})(),L=(()=>{if(v.tag==="Nothing")return l;if(v.tag==="Just")return v._1;f()})();if(Ri(n)(L)(r)<Ri(n)(l)(r)){a=L,c=_+1|0;continue}a=l,c=_+1|0;continue}g=!1,d=l}return d};return(u=>{let s=u,a=!0,c;for(;a;){const g=s,d=i(g)(0);if(zd(d)(g)){a=!1,c=g;continue}s=d}return c})(t)},co=e=>t=>y(n=>r=>{if(r>=0&&r<e.length){const o=e[r],i=r+1|0;if(i>=0&&i<e.length)return n+Ri(o)(e[i])(t)|0}return n})(0)($t(0,e.length-2|0)),Bd=e=>t=>n=>{const r=St(c=>c.tag==="OrderConstraint"?b("Just",{before:c._1.before,after:c._1.after}):T)(e.constraints),o=c=>y(g=>d=>{const l=d.after,_=d.before,h=ur(Kt,T,p=>p===_,g),m=ur(Kt,T,p=>p===l,g);if(h.tag==="Just"&&m.tag==="Just"&&h._1>m._1){const p=Gu(Kt,T,h._1,g),J=(()=>{if(p.tag==="Nothing")return g;if(p.tag==="Just")return p._1;f()})(),N=qf(Kt,T,m._1,_,J);if(N.tag==="Nothing")return J;if(N.tag==="Just")return N._1;f()}return g})(c)(r),i=Wi(zt(c=>g=>x(g.id,c))(n)),u=(c,g,d)=>{const l=c.length;return y(_=>h=>{const m=g?h-1|0:h+1|0,p=m>=0&&m<_._1.length?b("Just",_._1[m]):T;if(p.tag==="Just"){const J=h>=0&&h<_._1.length?b("Just",_._1[h]):T;if(J.tag==="Just"){const N=ao(zt(S=>I=>x(I,S))(p._1)),v=ao(zt(S=>I=>x(I,S))(J._1)),L=g?Rd(p._1)(N)(v)(n)(i):Qd(p._1)(N)(v)(n)(i),E=y(S=>I=>{const F=St(G=>Tr(G.id)(L))(at(g?G=>G.to.node===I._2&&so(G.from.node)(N):G=>G.from.node===I._2&&so(G.to.node)(N),n));if(F.length===0)return{...S,items:[...S.items,{n:I._2,key:T,origIdx:I._1}]};const j=uo(24)(S.r);return{items:[...S.items,{n:I._2,key:b("Just",(Md(F)+(_t(j._1)*4172325152040912e-24-.03500000014901161))/_t(F.length)),origIdx:I._1}],r:j._2}})({items:[],r:_._2})(zt(Sn)(J._1)),k=sr(Kt,T,h,Id(e.modelOrder)(o(V(S=>S.n)(vt(S=>I=>{const F=Ae(S.n)(e.modelOrder),j=Ae(I.n)(e.modelOrder);if(F.tag==="Just"&&j.tag==="Just"){const G=ot.compare(F._1)(j._1);return G==="EQ"?lt.compare(S.key)(I.key):G}return lt.compare(S.key)(I.key)})((()=>{const S=E.items,I=F=>j=>{let G=F,P=j,et=!0,K;for(;et;){const A=G,Y=P;if(A>=0&&A<S.length){if(S[A].key.tag==="Just"){et=!1,K=S[A].key._1;continue}if(S[A].key.tag==="Nothing"){G=A+1|0,P=Y;continue}f()}et=!1,K=Y}return K};return(F=>j=>G=>{let P=F,et=j,K=G,A=!0,Y;for(;A;){const R=P,C=et,z=K;if(R>=0&&R<S.length){if(S[R].key.tag==="Just"){P=R+1|0,et=S[R].key._1,K=[...z,{n:S[R].n,key:S[R].key._1,origIdx:S[R].origIdx}];continue}if(S[R].key.tag==="Nothing"){const M=(C+I(R+1|0)(C+1))/2;P=R+1|0,et=M,K=[...z,{n:S[R].n,key:M,origIdx:S[R].origIdx}];continue}f()}A=!1,Y=z}return Y})(0)(-1)([])})()))))(p._1)(n)(r),_._1);if(k.tag==="Just")return x(k._1,E.r);if(k.tag==="Nothing")return x(_._1,_._2);f()}if(J.tag==="Nothing")return x(_._1,_._2);f()}if(p.tag==="Nothing")return x(_._1,_._2);f()})(x(c,d))(g?$t(1,l-1|0):_e($t(0,l-2|0)))},s=y(c=>g=>Z(w)(g.from.node)()(Z(w)(g.to.node)()(c)))(D)(n),a=y(c=>g=>{if(c.result.crossings===0)return c;const d=N=>v=>L=>E=>{let k=N,S=v,I=L,F=E,j=!0,G;for(;j;){const P=k,et=S,K=I,A=F;if(K===0){j=!1,G={layout:P,crossings:0,random:A};continue}const Y=u(P,et,A),R=co(Y._1)(n);if(R<K){k=Y._1,S=!et,I=R,F=Y._2;continue}j=!1,G={layout:P,crossings:K,random:Y._2}}return G},l=uo(1)(c.result.random),_=l._1!==0,h=e.modelOrder.tag==="Leaf",m=(c.firstTry||c.secondTry)&&!h?c.firstTry:_,p=(()=>{if(!h){const E=u(t,m,l._2);return d(E._1)(!m)(co(E._1)(n))(E._2)}const N=m?0:Wd(0)(t.length-1|0),v=N>=0&&N<t.length?b("Just",t[N]):T;if(v.tag==="Just"&&v._1.length>1){const E=at(k=>Zs(k)(s),v._1);if(E.length>1){const k=Pd(l._2)(E),S=k._1,I=sr(Kt,T,N,o(y(F=>j=>Zs(j)(s)?F.idx>=0&&F.idx<S.length?{idx:F.idx+1|0,result:[...F.result,S[F.idx]]}:{idx:F.idx,result:[...F.result,j]}:{idx:F.idx,result:[...F.result,j]})({idx:0,result:[]})(v._1).result),t);if(I.tag==="Just"){const F=u(I._1,m,k._2);return d(F._1)(!m)(co(F._1)(n))(F._2)}}}const L=u(t,m,l._2);return d(L._1)(!m)(co(L._1)(n))(L._2)})(),J=c.secondTry?!1:c.secondTry;return c.firstTry?{result:p.crossings<c.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...c.result,random:p.random},firstTry:!1,secondTry:!0}:{result:p.crossings<c.result.crossings?{layout:p.layout,crossings:p.crossings,random:p.random}:{...c.result,random:p.random},firstTry:c.firstTry,secondTry:J}})({result:{layout:t,crossings:1e9,random:gr(qu(Gd(Cd(1))._1)(xr))(vr)},firstTry:e.modelOrder.tag!=="Leaf",secondTry:!1})($t(1,e.iterations)).result;return t.length<=0||e.iterations<=0?t:a.layout},Ad=e=>e,js=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},le=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},$n=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Lr=(()=>{const e={eq:t=>n=>t._1===n._1&&t._2===n._2};return{compare:t=>n=>{const r=w.compare(t._1)(n._1);return r==="LT"?Re:r==="GT"?Qe:w.compare(t._2)(n._2)},Eq0:()=>e}})(),Dd=jt(w)(It),qd=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=Lr.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Yd=Ad("Greedy"),Qi=e=>t=>n=>y(r=>o=>{if(o.from.node===o.to.node)return r;if(o.from.node===t&&!js(o.to.node)(r.marks)){const i=le(o.to.node)(r.inDeg),u=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;f()})(),s=Z(w)(o.to.node)(u)(r.inDeg);return(()=>{const a=le(o.to.node)(r.outDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;f()})()&&!Ie(Ve)(o.to.node)(r.sources)})()?{...r,inDeg:s,sources:[...r.sources,o.to.node]}:{...r,inDeg:s}}if(o.to.node===t&&!js(o.from.node)(r.marks)){const i=le(o.from.node)(r.outDeg),u=(()=>{if(i.tag==="Nothing")return-1;if(i.tag==="Just")return i._1-1|0;f()})(),s=Z(w)(o.from.node)(u)(r.outDeg);return(()=>{const a=le(o.from.node)(r.inDeg);return u<=0&&(()=>{if(a.tag==="Nothing")return!1;if(a.tag==="Just")return a._1>0;f()})()&&!Ie(Ve)(o.from.node)(r.sinks)})()?{...r,outDeg:s,sinks:[...r.sinks,o.from.node]}:{...r,outDeg:s}}return r})({...n,remaining:at(r=>r!==t,n.remaining)})(e),$d=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(w)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(w)(t._1.node)(0)(e);if(t._1.pin.tag==="LastLayer")return Z(w)(t._1.node)(99999)(e)}return e})(D),ta=e=>t=>n=>{const r=le(t)(e),o=le(n)(e);return r.tag==="Just"&&o.tag==="Just"&&r._1>o._1},ea=e=>t=>n=>r=>{if($n(n)(r.visited)||$n(n)(r.visiting))return r;const o=y(Fd(e)(t)(n))({...r,visiting:Z(w)(n)()(r.visiting)})((()=>{const i=le(n)(t);if(i.tag==="Nothing")return[];if(i.tag==="Just")return i._1;f()})());return{...o,visiting:er(w)(n)(o.visiting),visited:Z(w)(n)()(o.visited)}},Fd=e=>t=>n=>r=>o=>ta(e)(n)(o)?{...r,backEdges:Z(Lr)(x(n,o))()(r.backEdges)}:$n(o)(r.visiting)?{...r,backEdges:Z(Lr)(x(n,o))()(r.backEdges)}:$n(o)(r.visited)?r:ea(e)(t)(o)(r),Hd=e=>t=>n=>{const r=l=>{let _=l,h=!0,m;for(;h;){const p=_,J=Ft(N=>T,N=>v=>b("Just",{head:N,tail:v}),p.sinks);if(J.tag==="Just"){_=Qi(n)(J._1.head)({...p,sinks:J._1.tail,marks:Z(w)(J._1.head)(p.nextRight)(p.marks),nextRight:p.nextRight-1|0});continue}if(J.tag==="Nothing"){const N=Ft(v=>T,v=>L=>b("Just",{head:v,tail:L}),p.sources);if(N.tag==="Just"){_=Qi(n)(N._1.head)({...p,sources:N._1.tail,marks:Z(w)(N._1.head)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}if(N.tag==="Nothing"){const v=E=>{const k=le(E)(p.outDeg),S=le(E)(p.inDeg);return(()=>{if(k.tag==="Nothing")return 0;if(k.tag==="Just")return k._1;f()})()-(()=>{if(S.tag==="Nothing")return 0;if(S.tag==="Just")return S._1;f()})()|0},L=vt(E=>k=>{const S=ot.compare(v(k))(v(E));return S==="EQ"?ot.compare((()=>{const I=le(E)(t);if(I.tag==="Nothing")return 1e6;if(I.tag==="Just")return I._1;f()})())((()=>{const I=le(k)(t);if(I.tag==="Nothing")return 1e6;if(I.tag==="Just")return I._1;f()})()):S})(p.remaining);if(0<L.length){const E=L[0];_=Qi(n)(E)({...p,remaining:at(k=>k!==E,p.remaining),marks:Z(w)(E)(p.nextLeft)(p.marks),nextLeft:p.nextLeft+1|0});continue}h=!1,m=p;continue}}f()}return m},o=zn(w.compare)([...V(l=>l.from.node)(n),...V(l=>l.to.node)(n)]),i=at(l=>l.from.node!==l.to.node,n),u=y(l=>_=>xt(w)(Ut)(_.to.node)(1)(l))(D)(i),s=y(l=>_=>xt(w)(Ut)(_.from.node)(1)(l))(D)(i),a=at(l=>{const _=le(l)(u);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;f()},o),c=at(l=>{const _=le(l)(s);if(_.tag==="Nothing")return!0;if(_.tag==="Just")return _._1===0;f()},o),g=o.length+1|0,d=y(l=>_=>{const h=le(_)(l);return h.tag==="Just"&&h._1<0?Z(w)(_)(h._1+g|0)(l):l})(r({remaining:at(l=>!Ie(Ve)(l)(a)&&!Ie(Ve)(l)(c),o),marks:D,inDeg:u,outDeg:s,sources:a,sinks:c,nextLeft:1,nextRight:-1}).marks)(o);return y(l=>_=>{if(_.from.node===_.to.node)return l;if(ta(e)(_.from.node)(_.to.node))return Z(Lr)(x(_.from.node,_.to.node))()(l);const h=le(_.from.node)(d),m=le(_.to.node)(d);return h.tag==="Just"&&m.tag==="Just"&&h._1>m._1?Z(Lr)(x(_.from.node,_.to.node))()(l):l})(D)(n)},Vd=y(e=>t=>xt(w)(ie)(t.from.node)([t.to.node])(e))(D),Xd=e=>t=>{const n=Vd(t),r=zn(w.compare)([...V(i=>i.from.node)(t),...V(i=>i.to.node)(t)]),o=y(i=>u=>Z(w)(u.to.node)()(i))(D)(t);return y(i=>u=>ea(e)(n)(u)(i))({visiting:D,visited:D,backEdges:D})([...at(i=>!$n(i)(o),r),...at(i=>$n(i)(o),r)]).backEdges},Od=e=>t=>n=>r=>{const o=Dd(zt(s=>a=>x(a,s))(t)),i=$d(n),u=(()=>{if(e==="DepthFirst")return Xd(i)(r);if(e==="Greedy")return Hd(i)(o)(r);f()})();return{edges:V(s=>qd(x(s.from.node,s.to.node))(u)?{...s,from:s.to,to:s.from}:s)(r),reversedEdges:u}},na=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Ud=e=>t=>n=>y(r=>o=>{const i=na(o.from.node)(e),u=(()=>{if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;f()})(),s=na(o.to.node)(e),a=(()=>{if(s.tag==="Nothing")return-u;if(s.tag==="Just")return s._1-u|0;f()})();if(a<=1)return{...r,edges:[...r.edges,o],chains:[...r.chains,{edgeId:o.id,nodes:[o.from.node,o.to.node]}]};const c=o.id,g=V(l=>"$d:"+c+":"+Te(l))($t(1,a-1|0)),d=[o.from.node,...g,o.to.node];return{...r,layers:y(l=>_=>{const h=_._2,m=Hf(u+_._1|0)(p=>[...p,h])(l);if(m.tag==="Nothing")return l;if(m.tag==="Just")return m._1;f()})(r.layers)(me(Sn,$t(1,a-1|0),g)),edges:[...r.edges,...me(l=>_=>({id:c+":"+l+"->"+_,from:{node:l,port:o.from.port},to:{node:_,port:o.to.port}}),d,Mt(1,d.length,d))],chains:[...r.chains,{edgeId:o.id,nodes:d}]}})({layers:n,edges:[],chains:[]})(t),Ii=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},ae=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Ht=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},wr=e=>t=>{const n=ot.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},xn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=ot.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},fo=jt(w)(It),Fn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=ot.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Kd=(()=>{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 o=ot.compare(n.delta)(r.delta);if(o==="LT"||o==="GT"||o!=="EQ")return o;const i=ot.compare(n.eid)(r.eid);if(i==="LT"||i==="GT"||i!=="EQ")return i;const u=w.compare(n.src)(r.src);if(u==="LT"||u==="GT"||u!=="EQ")return u;const s=w.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:Fe},Eq0:()=>e};return y(n=>r=>Z(t)(r)()(n))(D)})(),Zd=y(e=>t=>Z(w)(t)()(e))(D),jd=jt(ot)(It),tl=e=>t=>pe(w.compare,he,e,t),el=e=>y(t=>n=>({base:(()=>{const r=o=>i=>{let u=o,s=i,a=!0,c;for(;a;){const g=u,d=s;if(d.tag==="Nil"){a=!1,c=g;continue}if(d.tag==="Cons"){u=Ii(g)(d._1),s=d._2;continue}f()}return c};return(t.base+r(0)((()=>{const o=(i,u)=>{if(i.tag==="Leaf")return u;if(i.tag==="Node")return o(i._5,Qt("Cons",i._4,o(i._6,u)));f()};return o(n,Bt)})())|0)+1|0})(),result:[...t.result,(()=>{if(t.base===0)return n;const r=o=>{if(o.tag==="Leaf")return D;if(o.tag==="Node")return Yt("Node",o._1,o._2,o._3,o._4+t.base|0,r(o._5),r(o._6));f()};return r(n)})()]}))({base:0,result:[]})(e).result,nl=e=>t=>{const n=i=>{let u=i,s=!0,a;for(;s;){const c=u,g=Ft(d=>T,d=>l=>b("Just",{head:d,tail:l}),c.queue);if(g.tag==="Nothing"){s=!1,a=c;continue}if(g.tag==="Just"){if(ae(g._1.head)(c.removedNodes)){u={...c,queue:g._1.tail};continue}const d=ge(l=>!ae(l.src+"\u2192"+l.tgt)(c.removedEdges)&&(l.src===g._1.head||l.tgt===g._1.head))(t);if(d.tag==="Nothing"){u={...c,queue:g._1.tail};continue}if(d.tag==="Just"){const l=d._1.src===g._1.head?d._1.tgt:d._1.src,_={...c,degree:Z(w)(l)((()=>{const h=Ht(l)(c.degree);if(h.tag==="Nothing")return-1;if(h.tag==="Just")return h._1-1|0;f()})())(c.degree),removedNodes:Z(w)(g._1.head)()(c.removedNodes),removedEdges:Z(w)(d._1.src+"\u2192"+d._1.tgt)()(c.removedEdges),record:[...c.record,{node:g._1.head,neighbour:l,viaSrc:d._1.src===g._1.head}],queue:g._1.tail};if((()=>{const h=Ht(l)(_.degree);return(()=>{if(h.tag==="Nothing")return!1;if(h.tag==="Just")return h._1===1;f()})()&&!ae(l)(_.removedNodes)})()){u={..._,queue:[..._.queue,l]};continue}u=_;continue}}f()}return a},r=y(i=>u=>xt(w)(Ut)(u.src)(1)(xt(w)(Ut)(u.tgt)(1)(i)))(D)(t),o=n({degree:r,removedNodes:D,removedEdges:D,record:[],queue:at(i=>{const u=Ht(i)(r);if(u.tag==="Nothing")return!1;if(u.tag==="Just")return u._1===1;f()},e)});return{coreNodes:at(i=>!ae(i)(o.removedNodes),e),coreEdges:at(i=>!ae(i.src+"\u2192"+i.tgt)(o.removedEdges),t),removed:o.record}},rl=e=>t=>y(n=>r=>{const o=Ht(r.neighbour)(n),i=(()=>{if(o.tag==="Nothing")return 0;if(o.tag==="Just")return o._1;f()})();return Z(w)(r.node)(r.viaSrc?i-1|0:i+1|0)(n)})(t)(_e(e)),ra=e=>t=>n=>{const r=y(i=>u=>{const s=ra(e)(u.src===t?u.tgt:u.src)({...i.st,edgeVisited:Z(ot)(u.eid)()(i.st.edgeVisited)});return{lowest:wr(i.lowest)(s.lowest),st:s.st}})({lowest:1e9,st:n})(at(i=>xn(i.eid)(n.treeEdge)&&(i.src===t||i.tgt===t)&&!xn(i.eid)(n.edgeVisited),e)),o=wr(r.lowest)(r.st.postOrder);return{lowest:o,st:{...r.st,poID:Z(w)(t)(r.st.postOrder)(r.st.poID),lowestPoID:Z(w)(t)(o)(r.st.lowestPoID),postOrder:r.st.postOrder+1|0}}},oa=e=>t=>n=>ra(t)(0<e.length?e[0]:"")({...n,edgeVisited:D,postOrder:1,poID:D,lowestPoID:D}).st,ia=e=>t=>{const n=y(r=>o=>wr(r)((()=>{const i=Ht(o)(t);if(i.tag==="Nothing")return 0;if(i.tag==="Just")return i._1;f()})()))(1e9)(e);return fo(V(r=>x(r,(()=>{const o=Ht(r)(t);if(o.tag==="Nothing")return-n;if(o.tag==="Just")return o._1-n|0;f()})()))(e))},Bi=e=>t=>{const n=Ht(t)(e.poID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;f()},ua=e=>t=>{const n=Ht(t)(e.lowestPoID);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;f()},ol=e=>t=>ge(n=>{const r=Fn(n.eid)(t.cutvalue);return xn(n.eid)(t.treeEdge)&&(()=>{if(r.tag==="Nothing")return!1;if(r.tag==="Just")return r._1<0;f()})()})(e),xe=e=>t=>{const n=Ht(t)(e.layer);if(n.tag==="Nothing")return 0;if(n.tag==="Just")return n._1;f()},il=e=>t=>y(n=>r=>{if(ae(r.src)(t.treeNode)===ae(r.tgt)(t.treeNode))return n;const o=(xe(t)(r.tgt)-xe(t)(r.src)|0)-r.delta|0;return o<n.slack?{edge:b("Just",r),slack:o}:n})({edge:T,slack:1e9})(e).edge,Ai=e=>t=>n=>{const r={...n,treeNode:Z(w)(t)()(n.treeNode)};return y(o=>i=>{if(xn(i.eid)(o.st.edgeVisited))return o;const u={...o.st,edgeVisited:Z(ot)(i.eid)()(o.st.edgeVisited)},s=(ae(i.src)(u.treeNode)&&!ae(i.tgt)(u.treeNode)?i.src===i.src:ae(i.tgt)(u.treeNode)&&!ae(i.src)(u.treeNode)?i.src===i.tgt:i.src===i.src)?i.tgt:i.src;if(xn(i.eid)(u.treeEdge)){if(ae(s)(u.treeNode))return{...o,st:u};const a=Ai(e)(s)(u);return{count:o.count+a.count|0,st:a.st}}if(!ae(s)(u.treeNode)&&i.delta===(xe(u)(i.tgt)-xe(u)(i.src)|0)){const a=Ai(e)(s)({...u,treeEdge:Z(ot)(i.eid)()(u.treeEdge)});return{count:o.count+a.count|0,st:a.st}}return{...o,st:u}})({count:1,st:r})(at(o=>(o.src===t||o.tgt===t)&&!xn(o.eid)(r.edgeVisited),e))},go=e=>t=>n=>{const r=Bi(e)(n.src),o=Bi(e)(n.tgt),i=Bi(e)(t);return ua(e)(n.src)<=i&&i<=r&&ua(e)(n.tgt)<=i&&i<=o?r>=o:r<o},ul=e=>t=>({layer:fo(V(n=>x(n,0))(e)),treeNode:D,treeEdge:D,poID:D,lowestPoID:D,cutvalue:D,postOrder:1,edgeVisited:D}),sl=e=>t=>n=>at(r=>xn(r.eid)(t.treeEdge)&&(r.src===n||r.tgt===n),e),al=e=>t=>n=>{let r=e,o=t,i=n,u=!0,s;for(;u;){const a=r,c=o,g=i,d=Ai(c)(0<a.length?a[0]:"")({...g,edgeVisited:D,treeNode:D,treeEdge:D});if(d.count>=a.length){u=!1,s=d.st;continue}const l=il(c)(d.st);if(l.tag==="Nothing"){u=!1,s=d.st;continue}if(l.tag==="Just"){const _=(xe(d.st)(l._1.tgt)-xe(d.st)(l._1.src)|0)-l._1.delta|0,h=ae(l._1.tgt)(d.st.treeNode)?-_:_;r=a,o=c,i={...d.st,layer:y(m=>p=>ae(p)(d.st.treeNode)?Z(w)(p)(xe(d.st)(p)+h|0)(m):m)(d.st.layer)(a)};continue}f()}return s},cl=e=>t=>n=>y(r=>o=>{if(go(n)(o.src)(t)&&!go(n)(o.tgt)(t)){const i=(xe(n)(o.tgt)-xe(n)(o.src)|0)-o.delta|0;if(i<r.slack)return{edge:b("Just",o),slack:i}}return r})({edge:T,slack:1e9})(e).edge,fl=e=>t=>{const n=y(o=>i=>xt(w)(ie)(i.tgt)([i.src])(xt(w)(ie)(i.src)([i.tgt])(o)))(D)(t),r=o=>i=>u=>{let s=o,a=i,c=u,g=!0,d;for(;g;){const l=s,_=a,h=c,m=Ft(p=>T,p=>J=>b("Just",{head:p,tail:J}),l);if(m.tag==="Nothing"){g=!1,d={nodes:h};continue}if(m.tag==="Just"){if(ae(m._1.head)(_)){s=m._1.tail,a=_,c=h;continue}s=[...m._1.tail,...(()=>{const p=Ht(m._1.head)(n);if(p.tag==="Nothing")return[];if(p.tag==="Just")return p._1;f()})()],a=Z(w)(m._1.head)()(_),c=[...h,m._1.head];continue}f()}return d};return y(o=>i=>{if(ae(i)(o.visited))return o;const u=r([i])(o.visited)([]);return{...o,visited:y(s=>a=>Z(w)(a)()(s))(o.visited)(u.nodes),components:[...o.components,u.nodes]}})({visited:D,components:[]})(e).components},gl=e=>t=>n=>r=>{const o=r.tgt,i=r.src;return y(u=>s=>{if((()=>{const a=Fn(s.eid)(t.cutvalue);if(a.tag==="Just")return!0;if(a.tag==="Nothing")return!1;f()})()){const a=Fn(s.eid)(t.cutvalue),c=(()=>{if(a.tag==="Nothing")return 0;if(a.tag==="Just")return a._1;f()})();return i===s.src||o===s.tgt?u-(c-s.weight|0)|0:u+(c-s.weight|0)|0}return n===i?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))},_l=e=>t=>n=>(r=>o=>{let i=r,u=o,s=!0,a;for(;s;){const c=i,g=u,d=Ht(g)(c.unknown),l=(()=>{if(d.tag==="Nothing")return[];if(d.tag==="Just")return d._1;f()})();if(l.length===1){const _=l[0].src===g?l[0].tgt:l[0].src;i={unknown:(()=>{const h=Ht(_)(c.unknown),m=(()=>{if(h.tag==="Just")return Z(w)(_)(at(J=>J.eid!==l[0].eid,h._1))(c.unknown);if(h.tag==="Nothing")return c.unknown;f()})(),p=Ht(g)(m);if(p.tag==="Just")return Z(w)(g)(at(J=>J.eid!==l[0].eid,p._1))(m);if(p.tag==="Nothing")return m;f()})(),cutvalue:Z(ot)(l[0].eid)(gl(e)(c)(g)(l[0]))(c.cutvalue)},u=_;continue}s=!1,a=c}return a})(t)(n),sa=e=>t=>n=>{const r={unknown:fo(V(o=>x(o,Lt(Le.foldr,Kd(sl(t)(n)(o)))))(e)),cutvalue:D};return{...n,cutvalue:y(_l(t))(r)(at(o=>{const i=Ht(o)(r.unknown);if(i.tag==="Nothing")return!1;if(i.tag==="Just")return i._1.length===1;f()},e)).cutvalue}},dl=e=>t=>n=>r=>o=>{const i={...o,treeEdge:Z(ot)(r.eid)()(er(ot)(n.eid)(o.treeEdge))},u=(xe(i)(r.tgt)-xe(i)(r.src)|0)-r.delta|0,s=go(i)(r.tgt)(n)?-u:u;return sa(e)(t)(oa(e)(t)({...i,layer:y(a=>c=>go(i)(c)(n)?a:Z(w)(c)(xe(i)(c)+s|0)(a))(i.layer)(e)}))},ll=e=>t=>n=>r=>(o=>i=>{let u=o,s=i,a=!0,c;for(;a;){const g=u,d=s;if(g===0){a=!1,c=d;continue}const l=ol(n)(d);if(l.tag==="Nothing"){a=!1,c=d;continue}if(l.tag==="Just"){const _=cl(n)(l._1)(d);if(_.tag==="Nothing"){a=!1,c=d;continue}if(_.tag==="Just"){u=g-1|0,s=dl(t)(n)(l._1)(_._1)(d);continue}}f()}return c})(e)(r),hl=e=>t=>n=>sa(e)(t)(oa(e)(t)(al(e)(t)(n))),aa=e=>y(t=>n=>xt(w)(ie)(e(n))([n])(t))(D),pl=e=>t=>n=>{const r=u=>s=>a=>c=>{let g=u,d=s,l=a,_=c,h=!0,m;for(;h;){const p=g,J=d,N=l,v=_,L=Ft(E=>T,E=>k=>b("Just",{head:E,tail:k}),N);if(L.tag==="Nothing"){h=!1,m=v;continue}if(L.tag==="Just"){const E=xe(v)(L._1.head),k=y(S=>I=>{const F=Ht(I.tgt)(S.incident),j=(()=>{if(F.tag==="Nothing")return-1;if(F.tag==="Just")return F._1-1|0;f()})();return{st:{...S.st,layer:Z(w)(I.tgt)(Ii(xe(S.st)(I.tgt))(E+I.delta|0))(S.st.layer)},incident:Z(w)(I.tgt)(j)(S.incident),queue:j===0?[...S.queue,I.tgt]:S.queue}})({st:v,incident:J,queue:L._1.tail})((()=>{const S=Ht(L._1.head)(p);if(S.tag==="Nothing")return[];if(S.tag==="Just")return S._1;f()})());g=p,d=k.incident,l=k.queue,_=k.st;continue}f()}return m},o=aa(u=>u.tgt)(t),i=fo(V(u=>x(u,(()=>{const s=Ht(u)(o);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1.length;f()})()))(e));return r(aa(u=>u.src)(t))(i)(at(u=>{const s=Ht(u)(i);if(s.tag==="Nothing")return!0;if(s.tag==="Just")return s._1===0;f()},e))(n)},ca=e=>t=>{const n=zt(o=>i=>({src:i.src,tgt:i.tgt,delta:1,weight:1,eid:o}))(t),r=pl(e)(n)(ul(e)(n));return n.length===0?r.layer:ll(4*e.length|0)(e)(n)(hl(e)(n)(r)).layer},ml=e=>t=>{const n=Zd(e),r=at(i=>ae(i.src)(n)&&ae(i.tgt)(n),t);if(e.length<40)return ia(e)(ca(e)(r));const o=nl(e)(r);return ia(e)(rl(o.removed)(ca(o.coreNodes)(o.coreEdges)))},yl=e=>t=>n=>{const r=y(i=>u=>xt(w)(Ut)(u.tgt)(1)(i))(D)(t),o=y(i=>u=>xt(w)(Ut)(u.src)(1)(i))(D)(t);return y(i=>u=>{const s=Ht(u)(r),a=(()=>{if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})();if((()=>{const N=Ht(u)(o);return(()=>{if(N.tag==="Nothing")return a!==0;if(N.tag==="Just")return a!==N._1;f()})()||a===0})())return i;const c=Ht(u)(i.layers),g=(()=>{if(c.tag==="Nothing")return 0;if(c.tag==="Just")return c._1;f()})(),d=i.layers,l=y(N=>v=>v.tgt===u?{...N,mIn:wr(N.mIn)((()=>{const L=Ht(u)(d),E=Ht(v.src)(d);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;f()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;f()})()|0})())}:v.src===u?{...N,mOut:wr(N.mOut)((()=>{const L=Ht(v.tgt)(d),E=Ht(u)(d);return(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;f()})()-(()=>{if(E.tag==="Nothing")return 0;if(E.tag==="Just")return E._1;f()})()|0})())}:N)({mIn:1e9,mOut:1e9})(t),_=l.mIn===1e9?-1:l.mIn,h=l.mOut===1e9?-1:l.mOut;if(_<0||h<0)return i;const m=(g-_|0)+1|0,p=(g+h|0)-1|0;if(p<m)return i;const J=y(N=>v=>{const L=Fn(v)(i.filling),E=(()=>{if(L.tag==="Nothing")return 0;if(L.tag==="Just")return L._1;f()})();return E<N.bestFill?{best:v,bestFill:E}:N})({best:g,bestFill:(()=>{const N=Fn(g)(i.filling);if(N.tag==="Nothing")return 0;if(N.tag==="Just")return N._1;f()})()})($t(m,p));return J.best===g?i:{layers:Z(w)(u)(J.best)(i.layers),filling:Z(ot)(g)((()=>{const N=Fn(g)(i.filling);if(N.tag==="Nothing")return-1;if(N.tag==="Just")return N._1-1|0;f()})())(Z(ot)(J.best)(J.bestFill+1|0)(i.filling))}})({layers:n,filling:jd(V(i=>x(i,y(u=>s=>(()=>{const a=Ht(s)(n);return a.tag==="Nothing"?!1:a.tag==="Just"&&a._1===i})()?u+1|0:u)(0)(e)))($t(0,y(i=>u=>Ii(i)((()=>{const s=Ht(u)(n);if(s.tag==="Nothing")return 0;if(s.tag==="Just")return s._1;f()})()))(0)(e))))})(e).layers},Jl=e=>t=>yl(e)(zt(n=>r=>({src:r.src,tgt:r.tgt,delta:1,weight:1,eid:n}))(t))(y(tl)(D)(el(V(n=>ml(n)(t))(fl(e)(t))))),Nl=e=>e,vn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},_o=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},fa=(()=>{const e=Pe.unfoldr(dn);return t=>e(Ge("IterNode",t,_n))})(),xl=Nl("NetworkSimplex"),vl=e=>t=>y(n=>r=>{const o=y(_o)(0)(St(i=>vn(i)(n))(r));return y(i=>u=>Z(w)(u)(o)(i))(n)(r)})(t)(e),Tl=e=>t=>({layers:V(n=>at(r=>{const o=vn(r)(t);return o.tag==="Nothing"?!1:o.tag==="Just"&&o._1===n},e))($t(0,(n=>r=>{let o=n,i=r,u=!0,s;for(;u;){const a=o,c=i;if(c.tag==="Nil"){u=!1,s=a;continue}if(c.tag==="Cons"){o=_o(a)(c._1),i=c._2;continue}f()}return s})(0)((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Qt("Cons",r._4,n(r._6,o)));f()};return n(t,Bt)})()))),nodeLayer:t}),Ll=e=>t=>n=>{const r=y(o=>i=>Z(w)(i)(!0)(o))(D)(t);return y(o=>i=>Z(w)(i._1)(i._2)(o))(Jl(t)(St(o=>o.from.node===o.to.node||(()=>{const i=vn(o.from.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;f()})()||(()=>{const i=vn(o.to.node)(r);if(i.tag==="Nothing")return!0;if(i.tag==="Just")return!i._1;f()})()?T:b("Just",{src:o.from.node,tgt:o.to.node}))(e)))(fa(n))},wl=e=>t=>n=>r=>{const o=s=>a=>{const c=vn(a)(s);if(c.tag==="Just")return s;if(c.tag==="Nothing"){const g=at(l=>l!==a,(()=>{const l=vn(a)(e);if(l.tag==="Nothing")return[];if(l.tag==="Just")return l._1;f()})()),d=y(o)(s)(g);return Z(w)(a)(1+y(_o)(0)(St(l=>vn(l)(d))(g))|0)(d)}f()},i=y(o)(D)(n),u=(s=>a=>{let c=s,g=a,d=!0,l;for(;d;){const _=c,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=_o(_)(h._1),g=h._2;continue}f()}return l})(1)((()=>{const s=(a,c)=>{if(a.tag==="Leaf")return c;if(a.tag==="Node")return s(a._5,Qt("Cons",a._4,s(a._6,c)));f()};return s(i,Bt)})());return y(s=>a=>Z(w)(a._1)(a._2)(s))((()=>{const s=a=>{if(a.tag==="Leaf")return D;if(a.tag==="Node")return Yt("Node",a._1,a._2,a._3,u-a._4|0,s(a._5),s(a._6));f()};return s(i)})())(fa(r))},kl=y(e=>t=>{if(t.tag==="LayerConstraint"){if(t._1.pin.tag==="SpecificLayer")return Z(w)(t._1.node)(t._1.pin._1)(e);if(t._1.pin.tag==="FirstLayer")return Z(w)(t._1.node)(0)(e)}return e})(D),bl=y(e=>t=>xt(w)(ie)(t.to.node)([t.from.node])(e))(D),El=y(e=>t=>xt(w)(ie)(t.from.node)([t.to.node])(e))(D),Cl=e=>t=>n=>r=>{const o=El(n),i=bl(n),u=kl(t);return Tl(r)(vl(St(s=>s.tag==="SameLayer"?b("Just",s._1.nodes):T)(t))((()=>{if(e==="LongestPath")return wl(o)(i)(r)(u);if(e==="NetworkSimplex")return Ll(n)(r)(u);f()})()))},Sl=jt(w)(It),Pl=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},ga=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},_a=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},kr=jt(w)(It),Gl=jt(w)(It),da=(()=>{const e=V(t=>({start:t.end,end:t.start,direction:t.direction}));return t=>_e(e(t))})(),zl=e=>t=>n=>r=>{const o=Sl(V(u=>x(u.edge,u))(r)),i=u=>0<u.nodes.length&&(()=>{const s=Pl(u.edgeId)(n);return s.tag==="Just"&&u.nodes[0]!==s._1._1})();return V(u=>{if(u.nodes.length<=2){const g=ga(u.edgeId)(o);if(g.tag==="Just"){const d=i(u);return{...g._1,edge:u.edgeId,segments:d?da(g._1.segments):g._1.segments,reversed:d}}if(g.tag==="Nothing")return{edge:u.edgeId,segments:[],bends:[],bendType:[],jumps:[],reversed:!1};f()}const s=Ct(St(g=>ga(g)(o))(me(g=>d=>u.edgeId+":"+g+"->"+d,u.nodes,Mt(1,u.nodes.length,u.nodes))))(g=>g.segments),a=i(u),c=Ei(a?da(s):s);return{edge:u.edgeId,segments:c,bends:me(g=>d=>g.end,c,Mt(1,c.length,c)),bendType:[],jumps:[],reversed:a}})(e)},Ml={layers:[],edges:[],chains:[]},Wl={nodeGap:3,layerGap:2,iterations:8,layerer:xl,cycleBreaker:Yd},Rl=e=>({pos:x(0,0),size:x(y(t=>n=>_a(t)(n.position._1+n.size._1))(0)(e),y(t=>n=>_a(t)(n.position._2+n.size._2))(0)(e))}),Ql=e=>t=>{const n=at(i=>oe(3)(i.node)!=="$d:",t.placements),r=zl(t.withDummies.chains)(t.acyclic.reversedEdges)(Gl(V(i=>x(i.id,x(i.from.node,i.to.node)))(e.edges)))(U1(t.withDummies.edges)(t.placements)(kr(V(i=>x(i.id,i.ports))(e.nodes)))(t.withDummies.chains)(Bs(t.ordered)(at(i=>i.from.node!==i.to.node,t.withDummies.edges))((()=>{const i=u=>{if(u.tag==="Leaf")return D;if(u.tag==="Node")return Yt("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),i(u._5),i(u._6));f()};return i(kr(V(u=>x(u.id,u.size))(e.nodes)))})()))),o=zt(i=>u=>({...u,jumps:rd(i)(u)(r)}))(r);return{nodes:n,edges:o,boundingBox:Rl(n),metrics:m1(n)(o)(0)}},Il=e=>t=>n=>{const r=kr(V(i=>x(i.id,i.size))(t.nodes)),o={...n,placements:Ed({nodeGap:e.nodeGap,layerGap:e.layerGap})(t.constraints)(n.ordered)(r)(kr(V(i=>x(i.id,i.ports))(t.nodes)))(n.withDummies.edges)(n.withDummies.chains)(Bs(n.ordered)(n.withDummies.edges)((()=>{const i=u=>{if(u.tag==="Leaf")return D;if(u.tag==="Node")return Yt("Node",u._1,u._2,u._3,x(u._4._1*4,u._4._2),i(u._5),i(u._6));f()};return i(r)})()))};return{pipeline:o,result:Ql(t)(o)}},Bl=e=>t=>n=>Il(e)(t)({...n,ordered:Bd({iterations:e.iterations,constraints:t.constraints,modelOrder:kr(zt(r=>o=>x(o.id,r))(t.nodes))})(n.withDummies.layers)(n.withDummies.edges)}),Al=e=>t=>n=>Bl(e)(t)({...n,withDummies:Ud(n.layered.nodeLayer)(n.acyclic.edges)(n.layered.layers)}),Dl=e=>t=>{const n=V(o=>o.id)(t.nodes),r=Od(e.cycleBreaker)(n)(t.constraints)(t.edges);return Al(e)(t)({acyclic:r,layered:Cl(e.layerer)(t.constraints)(r.edges)(n),withDummies:Ml,ordered:[],placements:[]})},ql=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Yl=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},la=jt(w)(It),$l=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Fl=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Hl=y(e=>t=>Z(w)(t)()(e))(D),Vl=y(e=>t=>Z(w)(t)()(e))(D),Xl=Ar.traverse(Cu),Di=jt(w)(It),Ol=e=>t=>n=>{const r=ge(o=>o.id===n)(e.graph.edges);if(r.tag==="Just")return b("Just",r._1);if(r.tag==="Nothing")return ql(n)(t);f()},Ul=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=Yl(n.node)(t);if(r.tag==="Just")return r._1;if(r.tag==="Nothing")return n.node;f()})()}),Kl=e=>({id:e,size:x(1,1),ports:[],label:b("Just",e)}),Zl=e=>t=>n=>x(n.node,Ul(e)(t)(n)),jl=e=>la(St(t=>b("Just",x(t.edge,{id:t.edge,from:{node:t.from,port:T},to:{node:t.to,port:T}})))(Ct(e.scenes)(t=>t.tag==="DataFlow"?St(n=>n.kind.tag==="SendToken"?b("Just",n.kind._1):T)(t._1.events):[]))),ha=e=>{const t=mg(e),n=at(o=>$l(o.id)(t.nodes),e.graph.nodes),r=at(o=>Fl(o.id)(t.edges),e.graph.edges);return{nodes:[...n,...V(Kl)(Lt(Le.foldr,He(w.compare,t.nodes,Hl(V(o=>o.id)(n)))))],edges:[...r,...St(Ol(e)(jl(e)))(Lt(Le.foldr,He(w.compare,t.edges,Vl(V(o=>o.id)(r)))))],constraints:e.graph.constraints}},t0=e=>{const t=Xl(n=>{const r=s1("Ilisarniq, ui-sans-serif, system-ui, sans-serif")(11)("500")(Js((()=>{if(n.label.tag==="Just")return n.label._1;if(n.label.tag==="Nothing")return n.id;f()})()));return()=>{const o=r();return x(n.id,o)}})(ha(e).nodes);return()=>{const n=t();return Di(n)}},e0=e=>t=>{const n=Ft(r=>T,r=>o=>b("Just",{head:r,tail:o}),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])];f()},n0=e=>t=>x(t.edge,e0(e)(t)),r0=e=>t=>n=>({nodes:Di(V(Zl(_t(4)*e)(t))(n.nodes)),edges:la(V(n0(e))(n.edges)),chipExtras:D}),o0=_t(4)*8,i0=e=>t=>{const n=l1(o0)(e)(d1(_1)(ha(t)));return r0(8)(Di(V(r=>x(r.id,(()=>{if(r.label.tag==="Just")return r.label._1;if(r.label.tag==="Nothing")return r.id;f()})()))(n.nodes)))(Dl(Wl)(n).result)},pa=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},u0=e=>t=>n=>{const r=e<.05?e:.05,o=(u,s)=>{if(s.tag==="Leaf")return u;if(s.tag==="Node")return o((()=>{const a=pa(s._3)(n),c=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return{x:s._4.x,y:s._4.y,vx:0,vy:0};f()})(),g=c.vx+(180*(s._4.x-c.x)-22*c.vx)*r,d=c.vy+(180*(s._4.y-c.y)-22*c.vy)*r;return Z(w)(s._3)({x:c.x+g*r,y:c.y+d*r,vx:g,vy:d})(o(u,s._5))})(),s._6);f()},i=o(D,t);return{springs:i,applied:(()=>{const u=(s,a)=>{if(a.tag==="Leaf")return s;if(a.tag==="Node")return u((()=>{const c=u(s,a._5),g=pa(a._3)(i);if(g.tag==="Just")return Z(w)(a._3)({...a._4,x:g._1.x,y:g._1.y})(c);if(g.tag==="Nothing")return Z(w)(a._3)(a._4)(c);f()})(),a._6);f()};return u(D,t)})()}};(function(){var e={},t="Pure",n="Throw",r="Catch",o="Sync",i="Async",u="Bind",s="Bracket",a="Fork",c="Sequential",g="Map",d="Apply",l="Alt",_="Cons",h="Resume",m="Release",p="Finalizer",J="Finalized",N="Forked";function v(W,H,O,$){this.tag=W,this._1=H,this._2=O,this._3=$}function L(W){var H=function(O,$,q){return new v(W,O,$,q)};return H.tag=W,H}function E(W){return new v(t,void 0)}function k(W){try{W()}catch(H){setTimeout(function(){throw H},0)}}function S(W,H,O){try{return H(O())}catch($){return W($)}}function I(W,H,O){try{return H(O)()}catch($){return O(W($))(),E}}var F=(function(){var W=1024,H=0,O=0,$=new Array(W),q=!1;function Q(){var U;for(q=!0;H!==0;)H--,U=$[O],$[O]=void 0,O=(O+1)%W,U();q=!1}return{isDraining:function(){return q},enqueue:function(U){var X;H===W&&(X=q,Q(),q=X),$[(O+H)%W]=U,H++,q||Q()}}})();function j(W){var H={},O=0,$=0;return{register:function(q){var Q=O++;q.onComplete({rethrow:!0,handler:function(U){return function(){$--,delete H[Q]}}})(),H[Q]=q,$++},isEmpty:function(){return $===0},killAll:function(q,Q){return function(){if($===0)return Q();var U=0,X={};function gt(ct){X[ct]=H[ct].kill(q,function(ht){return function(){delete X[ct],U--,W.isLeft(ht)&&W.fromLeft(ht)&&setTimeout(function(){throw W.fromLeft(ht)},0),U===0&&Q()}})()}for(var pt in H)H.hasOwnProperty(pt)&&(U++,gt(pt));return H={},O=0,$=0,function(ct){return new v(o,function(){for(var ht in X)X.hasOwnProperty(ht)&&X[ht]()})}}}}}var G=0,P=1,et=2,K=3,A=4,Y=5,R=6;function C(W,H,O){var $=0,q=G,Q=O,U=null,X=null,gt=null,pt=null,ct=null,ht=0,Tt=0,Gt=null,dt=!0;function Wt(nt){for(var st,yt,Jt;;)switch(st=null,yt=null,Jt=null,q){case et:q=P;try{Q=gt(Q),pt===null?gt=null:(gt=pt._1,pt=pt._2)}catch(Dt){q=Y,U=W.left(Dt),Q=null}break;case K:W.isLeft(Q)?(q=Y,U=Q,Q=null):gt===null?q=Y:(q=et,Q=W.fromRight(Q));break;case P:switch(Q.tag){case u:gt&&(pt=new v(_,gt,pt)),gt=Q._2,q=P,Q=Q._1;break;case t:gt===null?(q=Y,Q=W.right(Q._1)):(q=et,Q=Q._1);break;case o:q=K,Q=S(W.left,W.right,Q._1);break;case i:q=A,Q=I(W.left,Q._1,function(Dt){return function(){$===nt&&($++,F.enqueue(function(){$===nt+1&&(q=K,Q=Dt,Wt($))}))}});return;case n:q=Y,U=W.left(Q._1),Q=null;break;case r:gt===null?ct=new v(_,Q,ct,X):ct=new v(_,Q,new v(_,new v(h,gt,pt),ct,X),X),gt=null,pt=null,q=P,Q=Q._1;break;case s:ht++,gt===null?ct=new v(_,Q,ct,X):ct=new v(_,Q,new v(_,new v(h,gt,pt),ct,X),X),gt=null,pt=null,q=P,Q=Q._1;break;case a:q=K,st=C(W,H,Q._2),H&&H.register(st),Q._1&&st.run(),Q=W.right(st);break;case c:q=P,Q=M(W,H,Q._1);break}break;case Y:if(gt=null,pt=null,ct===null)q=R,Q=X||U||Q;else switch(st=ct._3,Jt=ct._1,ct=ct._2,Jt.tag){case r:X&&X!==st&&ht===0?q=Y:U&&(q=P,Q=Jt._2(W.fromLeft(U)),U=null);break;case h:X&&X!==st&&ht===0||U?q=Y:(gt=Jt._1,pt=Jt._2,q=et,Q=W.fromRight(Q));break;case s:ht--,U===null&&(yt=W.fromRight(Q),ct=new v(_,new v(m,Jt._2,yt),ct,st),(X===st||ht>0)&&(q=P,Q=Jt._3(yt)));break;case m:ct=new v(_,new v(J,Q,U),ct,X),q=P,X&&X!==st&&ht===0?Q=Jt._1.killed(W.fromLeft(X))(Jt._2):U?Q=Jt._1.failed(W.fromLeft(U))(Jt._2):Q=Jt._1.completed(W.fromRight(Q))(Jt._2),U=null,ht++;break;case p:ht++,ct=new v(_,new v(J,Q,U),ct,X),q=P,Q=Jt._1;break;case J:ht--,q=Y,Q=Jt._1,U=Jt._2;break}break;case R:for(var Et in Gt)Gt.hasOwnProperty(Et)&&(dt=dt&&Gt[Et].rethrow,k(Gt[Et].handler(Q)));Gt=null,X&&U?setTimeout(function(){throw W.fromLeft(U)},0):W.isLeft(Q)&&dt&&setTimeout(function(){if(dt)throw W.fromLeft(Q)},0);return;case G:q=P;break;case A:return}}function mt(nt){return function(){if(q===R)return dt=dt&&nt.rethrow,nt.handler(Q)(),function(){};var st=Tt++;return Gt=Gt||{},Gt[st]=nt,function(){Gt!==null&&delete Gt[st]}}}function ft(nt,st){return function(){if(q===R)return st(W.right(void 0))(),function(){};var yt=mt({rethrow:!1,handler:function(){return st(W.right(void 0))}})();switch(q){case G:X=W.left(nt),q=R,Q=X,Wt($);break;case A:X===null&&(X=W.left(nt)),ht===0&&(q===A&&(ct=new v(_,new v(p,Q(nt)),ct,X)),q=Y,Q=null,U=null,Wt(++$));break;default:X===null&&(X=W.left(nt)),ht===0&&(q=Y,Q=null,U=null)}return yt}}function rt(nt){return function(){var st=mt({rethrow:!1,handler:nt})();return q===G&&Wt($),st}}return{kill:ft,join:rt,onComplete:mt,isSuspended:function(){return q===G},run:function(){q===G&&(F.isDraining()?Wt($):F.enqueue(function(){Wt($)}))}}}function z(W,H,O,$){var q=0,Q={},U=0,X={},gt=new Error("[ParAff] Early exit"),pt=null,ct=e;function ht(mt,ft,rt){var nt=ft,st=null,yt=null,Jt=0,Et={},Dt,ne;t:for(;;)switch(Dt=null,nt.tag){case N:if(nt._3===e&&(Dt=Q[nt._1],Et[Jt++]=Dt.kill(mt,function($e){return function(){Jt--,Jt===0&&rt($e)()}})),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(W.right(void 0))();else for(ne=0,Dt=Jt;ne<Dt;ne++)Et[ne]=Et[ne]();return Et}function Tt(mt,ft,rt){var nt,st,yt,Jt,Et,Dt;for(W.isLeft(mt)?(nt=mt,st=null):(st=mt,nt=null);;){if(yt=null,Jt=null,Et=null,Dt=null,pt!==null)return;if(ft===null){$(nt||st)();return}if(ft._3!==e)return;switch(ft.tag){case g:nt===null?(ft._3=W.right(ft._1(W.fromRight(st))),st=ft._3):ft._3=nt;break;case d:if(yt=ft._1._3,Jt=ft._2._3,nt){if(ft._3=nt,Et=!0,Dt=U++,X[Dt]=ht(gt,nt===yt?ft._2:ft._1,function(){return function(){delete X[Dt],Et?Et=!1:rt===null?Tt(nt,null,null):Tt(nt,rt._1,rt._2)}}),Et){Et=!1;return}}else{if(yt===e||Jt===e)return;st=W.right(W.fromRight(yt)(W.fromRight(Jt))),ft._3=st}break;case l:if(yt=ft._1._3,Jt=ft._2._3,yt===e&&W.isLeft(Jt)||Jt===e&&W.isLeft(yt))return;if(yt!==e&&W.isLeft(yt)&&Jt!==e&&W.isLeft(Jt))nt=st===yt?Jt:yt,st=null,ft._3=nt;else if(ft._3=st,Et=!0,Dt=U++,X[Dt]=ht(gt,st===yt?ft._2:ft._1,function(){return function(){delete X[Dt],Et?Et=!1:rt===null?Tt(st,null,null):Tt(st,rt._1,rt._2)}}),Et){Et=!1;return}break}rt===null?ft=null:(ft=rt._1,rt=rt._2)}}function Gt(mt){return function(ft){return function(){delete Q[mt._1],mt._3=ft,Tt(ft,mt._2._1,mt._2._2)}}}function dt(){var mt=P,ft=O,rt=null,nt=null,st,yt;t:for(;;)switch(st=null,yt=null,mt){case P:switch(ft.tag){case g:rt&&(nt=new v(_,rt,nt)),rt=new v(g,ft._1,e,e),ft=ft._2;break;case d:rt&&(nt=new v(_,rt,nt)),rt=new v(d,e,ft._2,e),ft=ft._1;break;case l:rt&&(nt=new v(_,rt,nt)),rt=new v(l,e,ft._2,e),ft=ft._1;break;default:yt=q++,mt=Y,st=ft,ft=new v(N,yt,new v(_,rt,nt),e),st=C(W,H,st),st.onComplete({rethrow:!1,handler:Gt(ft)})(),Q[yt]=st,H&&H.register(st)}break;case Y:if(rt===null)break t;rt._1===e?(rt._1=ft,mt=P,ft=rt._2,rt._2=e):(rt._2=ft,ft=rt,nt===null?rt=null:(rt=nt._1,nt=nt._2))}for(ct=ft,yt=0;yt<q;yt++)Q[yt].run()}function Wt(mt,ft){pt=W.left(mt);var rt;for(var nt in X)if(X.hasOwnProperty(nt)){rt=X[nt];for(nt in rt)rt.hasOwnProperty(nt)&&rt[nt]()}X=null;var st=ht(mt,ct,ft);return function(yt){return new v(i,function(Jt){return function(){for(var Et in st)st.hasOwnProperty(Et)&&st[Et]();return E}})}}return dt(),function(mt){return new v(i,function(ft){return function(){return Wt(mt,ft)}})}}function M(W,H,O){return new v(i,function($){return function(){return z(W,H,O,$)}})}return v.EMPTY=e,v.Pure=L(t),v.Throw=L(n),v.Catch=L(r),v.Sync=L(o),v.Async=L(i),v.Bind=L(u),v.Bracket=L(s),v.Fork=L(a),v.Seq=L(c),v.ParMap=L(g),v.ParApply=L(d),v.ParAlt=L(l),v.Fiber=C,v.Supervisor=j,v.Scheduler=F,v.nonCanceler=E,v})();let qi=null;function s0(){return qi||(typeof document>"u"?null:(qi=document.createElement("canvas").getContext("2d"),qi))}const ma=new Map,a0=e=>t=>n=>r=>{const o=`${n} ${t}px ${e}|${r}`,i=ma.get(o);if(i!==void 0)return i;const u=s0();if(!u)return r.length*t*.62;u.font=`${n} ${t}px ${e}`;const s=u.measureText(r).width;return ma.set(o,s),s},c0=e=>()=>e.clip("evenodd"),f0=e=>t=>()=>{const n=Math.max(8,Math.ceil(8/Math.max(t.tile,.001))),r=Math.max(2,Math.round(t.tile*n)),o=document.createElement("canvas");o.width=r,o.height=r;const i=o.getContext("2d");i.scale(n,n),i.fillStyle=t.bgCss,i.fillRect(0,0,t.tile,t.tile),i.fillStyle=t.dotCss,i.beginPath(),i.arc(t.tile/2,t.tile/2,t.dotR,0,2*Math.PI),i.fill();const u=e.createPattern(o,"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()},g0=e=>t=>n=>r=>o=>i=>()=>{if(typeof e.roundRect=="function")e.roundRect(t,n,r,o,i);else{const u=Math.min(i,r/2,o/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+o-u),e.quadraticCurveTo(t+r,n+o,t+r-u,n+o),e.lineTo(t+u,n+o),e.quadraticCurveTo(t,n+o,t,n+o-u),e.lineTo(t,n+u),e.quadraticCurveTo(t,n,t+u,n),e.closePath()}},_0=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},Yi=e=>t=>n=>{const r=t.stroke;return()=>{const o=r.value,i=Uc(e)(n);if(o!==n)return i(),t.stroke.value=n}},d0=e=>t=>n=>{const r=t.font;return()=>{const o=r.value,i=af(e)(n);if(o!==n)return i(),t.font.value=n}},br=e=>t=>n=>{const r=t.fill;return()=>{const o=r.value,i=Oc(e)(n);if(o!==n)return i(),t.fill.value=n}},lo=e=>t=>{const n=t.length,r=i=>{if(i>=n)return()=>{};const u=i>=0&&i<t.length?t[i]:0;if(u===1){const s=ef(e)((()=>{const c=i+1|0;return c>=0&&c<t.length?t[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<t.length?t[c]:0})()),a=r(i+3|0);return()=>(s(),a())}if(u===2){const s=tf(e)((()=>{const c=i+1|0;return c>=0&&c<t.length?t[c]:0})())((()=>{const c=i+2|0;return c>=0&&c<t.length?t[c]:0})()),a=r(i+3|0);return()=>(s(),a())}if(u===3){const s=ff(e)({cpx:(()=>{const c=i+1|0;return c>=0&&c<t.length?t[c]:0})(),cpy:(()=>{const c=i+2|0;return c>=0&&c<t.length?t[c]:0})(),x:(()=>{const c=i+3|0;return c>=0&&c<t.length?t[c]:0})(),y:(()=>{const c=i+4|0;return c>=0&&c<t.length?t[c]:0})()}),a=r(i+5|0);return()=>(s(),a())}if(u===4){const s=gf(e)({cp1x:(()=>{const c=i+1|0;return c>=0&&c<t.length?t[c]:0})(),cp1y:(()=>{const c=i+2|0;return c>=0&&c<t.length?t[c]:0})(),cp2x:(()=>{const c=i+3|0;return c>=0&&c<t.length?t[c]:0})(),cp2y:(()=>{const c=i+4|0;return c>=0&&c<t.length?t[c]:0})(),x:(()=>{const c=i+5|0;return c>=0&&c<t.length?t[c]:0})(),y:(()=>{const c=i+6|0;return c>=0&&c<t.length?t[c]:0})()}),a=r(i+7|0);return()=>(s(),a())}if(u===5){const s=nf(e),a=r(i+1|0);return()=>(s(),a())}return()=>{}},o=Lu(e);return()=>(o(),r(0)())},l0=()=>({font:{value:""},fill:{value:""},stroke:{value:""}}),h0=e=>t=>{const n=of(e)({x:0,y:0,width:t.width,height:t.height});return()=>{n();const r=l0();return{ctx:e,surface:t,styleCache:r,maskDepth:{value:0}}}},p0={map:e=>t=>n=>{const r=t(n);return()=>{const o=r();return e(o)}}},m0=e=>Te(e.weight)+" "+fu(e.size)+"px Ilisarniq, ui-sans-serif, system-ui, sans-serif",De=e=>{const t=fu(_t(e.a)/255);return e.a>=255?"rgb("+Te(e.r)+","+Te(e.g)+","+Te(e.b)+")":"rgba("+Te(e.r)+","+Te(e.g)+","+Te(e.b)+","+t+")"},y0=e=>t=>n=>r=>{const o=br(e)(n)(De(r));return()=>(o(),rf(e)({x:0,y:0,width:t.width,height:t.height})())},J0=e=>t=>n=>{const r=t.font;return()=>(r.value="",t.fill.value="",t.stroke.value="",f0(e)({vx:n.viewport.vx,vy:n.viewport.vy,vw:n.viewport.vw,vh:n.viewport.vh,bgCss:De(n.bgColor),dotCss:De(n.dotColor),tile:n.tile,dotR:n.dotRadius})())},N0=e=>t=>n=>r=>{const o=br(e)(t)(De(r));return()=>(o(),lo(e)(n)(),Fo(e)())},x0=e=>t=>n=>r=>o=>{const i=br(e)(t)(De(r));return()=>(i(),Yi(e)(t)(De(o.color))(),Do(e)(o.width)(),Br(e)((()=>{if(o.lineJoin==="RoundJoin")return Ir;if(o.lineJoin==="BevelJoin")return Uo;if(o.lineJoin==="MiterJoin")return Ko;f()})())(),ei(e)((()=>{if(o.lineCap==="ButtCap")return ti;if(o.lineCap==="RoundCap")return Zo;if(o.lineCap==="SquareCap")return jo;f()})())(),lo(e)(n)(),Fo(e)(),$o(e)())},v0=e=>t=>n=>r=>o=>i=>{const u=Lu(e);return()=>{if(u(),g0(e)(n.x)(n.y)(n.w)(n.h)(r)(),o.tag==="Just"?(br(e)(t)(De(o._1.color))(),Fo(e)()):o.tag==="Nothing"||f(),i.tag==="Just")return Yi(e)(t)(De(i._1.color))(),Do(e)(i._1.width)(),Br(e)((()=>{if(i._1.lineJoin==="RoundJoin")return Ir;if(i._1.lineJoin==="BevelJoin")return Uo;if(i._1.lineJoin==="MiterJoin")return Ko;f()})())(),ei(e)((()=>{if(i._1.lineCap==="ButtCap")return ti;if(i._1.lineCap==="RoundCap")return Zo;if(i._1.lineCap==="SquareCap")return jo;f()})())(),$o(e)();i.tag!=="Nothing"&&f()}},T0=e=>t=>n=>r=>{const o=Yi(e)(t)(De(r.color));return()=>(o(),Do(e)(r.width)(),Br(e)((()=>{if(r.lineJoin==="RoundJoin")return Ir;if(r.lineJoin==="BevelJoin")return Uo;if(r.lineJoin==="MiterJoin")return Ko;f()})())(),ei(e)((()=>{if(r.lineCap==="ButtCap")return ti;if(r.lineCap==="RoundCap")return Zo;if(r.lineCap==="SquareCap")return jo;f()})())(),lo(e)(n)(),$o(e)())},L0=e=>t=>n=>{const r=br(e)(t)(De(n.color));return()=>(r(),d0(e)(t)(m0(n.font))(),vf(e)((()=>{if(n.align==="AlignLeft")return pf;if(n.align==="AlignCenter")return yf;if(n.align==="AlignRight")return mf;f()})())(),xf(e)((()=>{if(n.baseline==="BaselineTop")return _f;if(n.baseline==="BaselineMiddle")return df;if(n.baseline==="BaselineAlphabetic")return lf;if(n.baseline==="BaselineBottom")return hf;f()})())(),cf(e)(n.content)(n.x)(n.y)())},ya={apply:e=>t=>n=>{const r=e(n),o=t(n);return()=>{const i=r(),u=o();return i(u)}},Functor0:()=>p0},w0={bind:e=>t=>n=>{const r=e(n);return()=>{const o=r();return t(o)(n)()}},Apply0:()=>ya},k0=e=>t=>n=>{const r=_0(t.width/n.vw)(t.height/n.vh),o=wu(e)({translateX:(t.width-n.vw*r)/2-n.vx*r,translateY:(t.height-n.vh*r)/2-n.vy*r});return()=>(o(),Ho(e)({scaleX:r,scaleY:r})(),Br(e)(Ir)())},b0={pure:e=>t=>()=>e,Apply0:()=>ya},E0={Applicative0:()=>b0,Bind1:()=>w0},Ja={fillPath:e=>t=>n=>{const r=N0(n.ctx)(n.styleCache)(e)(t.color),o=n.maskDepth;return()=>{if(o.value===0)return r()}},strokePath:e=>t=>n=>{const r=T0(n.ctx)(n.styleCache)(e)(t),o=n.maskDepth;return()=>{if(o.value===0)return r()}},fillStrokePath:e=>t=>n=>r=>{const o=x0(r.ctx)(r.styleCache)(e)(t.color)(n),i=r.maskDepth;return()=>{if(i.value===0)return o()}},drawRoundedRect:e=>t=>n=>r=>o=>{const i=v0(o.ctx)(o.styleCache)(e)(t)(n)(r),u=o.maskDepth;return()=>{if(u.value===0)return i()}},drawText:e=>t=>{const n=L0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},pushTransform:e=>t=>{const n=rr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",wu(t.ctx)({translateX:e.tx,translateY:e.ty})(),Ho(t.ctx)({scaleX:e.sx,scaleY:e.sy})()}},popTransform:e=>{const t=or(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=rr(n.ctx),o=n.maskDepth;return()=>{if(o.value===0){if(r(),n.styleCache.font.value="",n.styleCache.fill.value="",n.styleCache.stroke.value="",lo(n.ctx)(e)(),t==="NonZero")return jc(n.ctx)();if(t==="EvenOdd")return c0(n.ctx)();f()}}},popClip:e=>{const t=or(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=rr(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 bu(t.ctx)(Jf)();if(e==="Difference")return bu(t.ctx)(Nf)();f()}}},popBlend:e=>{const t=or(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=rr(t.ctx),r=t.maskDepth;return()=>{if(r.value===0)return n(),t.styleCache.font.value="",t.styleCache.fill.value="",t.styleCache.stroke.value="",Zc(t.ctx)(e)()}},popAlpha:e=>{const t=or(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=k0(t.ctx)(t.surface)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},clearBackground:e=>t=>{const n=y0(t.ctx)(t.surface)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},backgroundDots:e=>t=>{const n=J0(t.ctx)(t.styleCache)(e),r=t.maskDepth;return()=>{if(r.value===0)return n()}},measureText:e=>t=>n=>{const r=a0(e.family)(e.size)(e.weight)(Js(t));return()=>r},Monad0:()=>E0};function C0(e,t){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function S0(e){const t=e.length,n=new Array(t);for(let r=0;r<t;r++){const o=e[r],i=e[(r+1)%t];n[r]={a:o,b:i,len:C0(o,i)}}return n}function P0(e,t,n){let r=0;for(let o=0;o<e.length;o++){const i=e[o],u=r,s=u+i.len;if(n<=s){const a=i.len>1e-6?(n-u)/i.len:0;return{x:i.a.x+(i.b.x-i.a.x)*a,y:i.a.y+(i.b.y-i.a.y)*a}}r=s}return t.length>0?t[t.length-1]:{x:0,y:0}}function Na(e,t){if(t.length===0)return[];const n=S0(t);let r=0;for(let i=0;i<n.length;i++)r+=n[i].len;const o=new Array(e);for(let i=0;i<e;i++)o[i]=P0(n,t,i*r/e);return o}function G0(e,t){const n=t.length;if(n===0)return t;const r=(e%n+n)%n|0,o=new Array(n);for(let i=0;i<n;i++)o[i]=t[(i+r)%n];return o}function z0(e,t){const n=t.length;if(n===0)return t;let r=0,o=1/0;for(let i=0;i<n;i++){let u=0;for(let s=0;s<n;s++){const a=e[s]||{x:0,y:0},c=t[(s+i)%n]||{x:0,y:0},g=a.x-c.x,d=a.y-c.y;u+=g*g+d*d}u<o&&(o=u,r=i)}return G0(r,t)}const xa=e=>t=>n=>{const r=Na(e,t),o=Na(e,n),i=z0(r,o);return{from:r,to:i}};function va(e){const t=e.length;if(t===0)return{x:0,y:0};let n=0,r=0;for(let o=0;o<t;o++)n+=e[o].x,r+=e[o].y;return{x:n/t,y:r/t}}function M0(e,t){const n=t.x-e.x,r=t.y-e.y,o=Math.sqrt(n*n+r*r);return o<=1e-4?{x:1,y:0}:{x:n/o,y:r/o}}function W0(e,t){const n=t.length;if(n===0)return t;const r=new Array(n);for(let o=0;o<n;o++){const i=t[((o-1)%n+n)%n],u=t[((o+1)%n+n)%n],s=t[o];r[o]={x:s.x+((i.x+u.x)/2-s.x)*e,y:s.y+((i.y+u.y)/2-s.y)*e}}return r}function R0(e){return e<0?0:e>1?1:e}const Ta=e=>t=>n=>r=>{const o=t.length;if(o===0)return[];const i=va(t),u=va(n),s=M0(i,u),a=new Array(o);let c=1/0,g=-1/0;for(let _=0;_<o;_++){const h=t[_],m=(h.x-i.x)*s.x+(h.y-i.y)*s.y;a[_]=m,m<c&&(c=m),m>g&&(g=m)}const d=g-c;let l=new Array(o);for(let _=0;_<o;_++){const h=t[_],m=n[_];if(m===void 0){l[_]=h;continue}const p=d<=1e-4?0:r.maxDelay*(1-(a[_]-c)/d),J=Math.max(1e-4,1-p),N=R0((e-p)/J),v=N*N*(3-2*N);l[_]={x:h.x+(m.x-h.x)*v,y:h.y+(m.y-h.y)*v}}for(let _=0;_<r.smoothPasses;_++)l=W0(.5,l);return l},Q0=e=>e,La=e=>e,ho=e=>e,wa=e=>e,I0=e=>e,ka=e=>e,ba=e=>e,B0=ba("BaselineTop"),Er=ba("BaselineMiddle"),$i=ka("AlignLeft"),Fi=ka("AlignCenter"),qe=I0("RoundJoin"),fn=wa("ButtCap"),Ea=wa("RoundCap"),A0=ho("LayerPolyOut"),D0=ho("LayerPolyIn"),q0=ho("LayerNodeMask"),Y0=ho("LayerOverlay"),Ca=La("NonZero"),$0=La("EvenOdd"),F0=Q0("Difference"),Hn={r:255,g:255,b:255,a:255},Ue={r:26,g:26,b:26,a:255},Hi=(e,t,n)=>({tag:e,_1:t,_2:n}),Ke=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},Cr=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},Sa=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Tn=e=>t=>n=>{const r=lt.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;f()})(),i=lt.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;f()},ke=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Ze=(()=>{const e=Pe.unfoldr(dn);return t=>e(Ge("IterNode",t,_n))})(),Vi=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;f()},Pa=jt(w)(It),Ga=y(nr)(0),po=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},za=e=>{const t=e.Monad0().Bind1(),n=e.popTransform,r=e.popAlpha;return o=>i=>u=>s=>a=>t.bind(e.pushAlpha(o.fadeAlpha))(()=>t.bind(e.pushTransform({tx:i*(1-o.popScale),ty:u*(1-o.popScale),sx:o.popScale,sy:o.popScale}))(()=>t.bind(e.pushTransform({tx:0,ty:s.y*(1-o.flipY),sx:1,sy:o.flipY}))(()=>t.bind(a)(()=>t.bind(n)(()=>t.bind(n)(()=>r))))))},je=e=>{const t=e.Apply0();return n=>y(r=>o=>t.apply(t.Functor0().map(i=>du)(r))(n(o)))(e.pure())},H0=e=>({x:e.x,y:e.y,w:e.w,h:e.h}),V0=y(e=>t=>e+t.len)(0),X0=e=>{const t=Ft(n=>T,n=>r=>b("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,...Ct(Mt(1,e.length,e))(n=>[2,n.x,n.y]),5];f()},O0=e=>t=>{const n=e.y+e.h-6,r=e.y+6,o=e.x+14,i=e.x+e.w-14,u=y(Cr)(0)(V(s=>o-10<s.x+s.w+12&&i+10>s.x-12&&r-10<s.y+s.h+12&&n+10>s.y-12?Ke((s.x+s.w+12-(o-10))/.7071067811865476)((n+10-(s.y-12))/.7071067811865476):0)(t));return{...e,x:e.x+u*.7071067811865476,y:e.y-u*.7071067811865476}},U0={r:26,g:26,b:26,a:255},K0={r:214,g:211,b:209,a:255},Ma=e=>t=>{const n=Ke(t)(Ke(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]},Z0=e=>t=>n=>y(r=>o=>{const i=Sa(o)(t);if(i.tag==="Nothing")return r;if(i.tag==="Just"){const u=O0(i._1)(r.obstacles);return{acc:Z(w)(o)(u)(r.acc),obstacles:ye(r.obstacles)(u)}}f()})({acc:D,obstacles:n})(e).acc,j0=e=>{const t=Ft(n=>T,n=>r=>b("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,...Ct(t._1.tail)(n=>[2,n.x,n.y])];f()},mo=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:ar(8)(.6)(Tn(0)(1)(e._1))};if(e.tag==="PloppingOut")return{alpha:e._1<1?1:0,scale:ar(8)(.6)(Tn(0)(1)(1-e._1))};f()},Wa=e=>t=>Ct(Ze(e.nodes))(n=>{const r=ke(n._1)(t.nodes);return r.tag==="Just"&&mo(r._1).alpha>0?Ma(n._2)(7):[]}),th=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,...Wa(t)(n)],yo=e=>t=>n=>V(r=>{const o=_t(r)/_t(n);return{x:e.x+(t.x-e.x)*o,y:e.y+(t.y-e.y)*o}})($t(0,n-1|0)),eh=e=>t=>{const n=o=>(o.x-t.x)*(o.x-t.x)+(o.y-t.y)*(o.y-t.y),r=y(o=>i=>n(i)<n(o)?i:o)({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(o=>{const i=_t(o)/5;return{x:r.x+(t.x-r.x)*i,y:r.y+(t.y-r.y)*i}})([1,2,3,4])},Ra=e=>{const t=li(`
6
- `)(e);return t.length===0?[""]:t},Xi=e=>t=>{const n=Ke(e)(Ke(t.w/2)(t.h/2));return{...t,x:t.x+n,y:t.y+n,w:t.w-2*n,h:t.h-2*n}},nh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=t.Bind1(),o=je(n),i=e.popTransform,u=e.popAlpha;return s=>a=>c=>{const g=li(`
7
- `)(a.label===""?s:a.label),d=g.length===0?[""]:g,l=a.y+a.h/2-_t(d.length)*13.2/2+6.6,_=mo(c),h=a.x+a.w/2,m=a.y+a.h/2,p=r.bind(e.pushAlpha(_.alpha))(()=>r.bind(e.pushTransform({tx:h*(1-_.scale),ty:m*(1-_.scale),sx:_.scale,sy:_.scale}))(()=>r.bind(e.drawRoundedRect({x:a.x,y:a.y,w:a.w,h:a.h})(7)(b("Just",{color:Hn,flat:!1}))(b("Just",{color:Ue,width:1.25,lineJoin:qe,lineCap:fn})))(()=>r.bind(o(J=>e.drawText({x:a.x+a.w/2,y:l+_t(J._1)*13.2,content:J._2,font:{family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},color:Ue,align:Fi,baseline:Er}))(zt(Sn)(d)))(()=>r.bind(i)(()=>u)))));return _.alpha>0?p:n.pure()}},rh=e=>{const t=nh(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>r(u=>{const s=ke(u._1)(i.nodes);if(s.tag==="Just")return t(u._1)(u._2)(s._1);if(s.tag==="Nothing")return n.pure();f()})(Ze(o.nodes))},Oi=e=>t=>{const n=t.y-e.y,r=t.x-e.x;return Cn(r*r+n*n)},oh=e=>me(t=>n=>({a:t,b:n,len:Oi(t)(n)}),e,Mt(1,e.length,e)),ih=e=>t=>{const n=t.length-1|0,r=n>=0&&n<t.length?b("Just",t[n]):T,o=(()=>{if(r.tag==="Just")return[r._1];if(r.tag==="Nothing")return[];f()})(),i=0<t.length?b("Just",t[0]):T,u=(()=>{if(i.tag==="Just")return i._1;if(i.tag==="Nothing")return{x:0,y:0};f()})(),s=t.length;return s<3?t:[u,...Ct($t(1,s-2|0))(a=>{const c=a+1|0,g=c>=0&&c<t.length?b("Just",t[c]):T,d=a>=0&&a<t.length?b("Just",t[a]):T,l=a-1|0,_=l>=0&&l<t.length?b("Just",t[l]):T;if(_.tag==="Just"&&d.tag==="Just"&&g.tag==="Just"){const h=d._1,m=Oi(h)(g._1),p=Oi(_._1)(h),J=Ke(e)(m/2),N=Ke(e)(p/2),v=m>0?J/m:0,L=h.x+(g._1.x-h.x)*v,E=h.y+(g._1.y-h.y)*v,k=p>0?N/p:0,S=h.x+(_._1.x-h.x)*k,I=h.y+(_._1.y-h.y)*k;return V(F=>{const j=_t(F)/_t(10),G=1-j;return{x:G*G*S+2*G*j*h.x+j*j*L,y:G*G*I+2*G*j*h.y+j*j*E}})($t(0,10))}return[]}),...o]},uh=e=>{const t=e.Monad0(),n=t.Bind1(),r=t.Applicative0(),o=je(r);return i=>u=>s=>a=>c=>g=>{const d=hi(g).length,l=_t(d+1|0),_=p=>{const J=(s*l-_t(p))/1.5,N=J<0?0:J>1?1:J;return N*N*(3-2*N)},h=(p=>{let J=p,N=!0,v;for(;N;){const L=J;if(L>=d){N=!1,v=L;continue}if(_(L)>=1){J=L+1|0;continue}N=!1,v=L}return v})(0),m=h>=d?[]:ln(p=>_(p)>0)($t(h,d-1|0)).init;return n.bind((()=>{const p=e.drawText({x:a,y:c,content:oe(h)(g),font:i,color:u,align:$i,baseline:Er});return h>0?p:r.pure()})())(()=>o(p=>n.bind(e.measureText(i)(oe(p)(g)))(J=>{const N=_(p);return e.drawText({x:a+J,y:c-(1-N)*10,content:oe(1)(fr(hn(oe(p)(g)))(g)),font:i,color:{...u,a:tr(mu(N*_t(u.a)))},align:$i,baseline:Er})}))(m))}},Jo=e=>t=>n=>r=>{const o=V(h=>_t(Vi(1)(hi(h).length)))(r),i=Cr(1)(y(nr)(0)(o)),u=Cr(.05)(1-t-n),s=e<t?0:e>1-n?1:(e-t)/u,a=s*i,c=Vi(1)(r.length),g=(h=>m=>p=>{let J=h,N=m,v=p,L=!0,E;for(;L;){const k=J,S=N,I=Ft(F=>T,F=>j=>b("Just",{head:F,tail:j}),v);if(I.tag==="Nothing"){L=!1,E=Vi(0)(c-1|0);continue}if(I.tag==="Just"){if(S+I._1.head>=a){L=!1,E=k;continue}J=k+1|0,N=S+I._1.head,v=I._1.tail;continue}f()}return E})(0)(0)(o),d=y(nr)(0)(g<1?[]:Mt(0,g,o)),l=d/i;if(g>=0&&g<o.length){const h=(d+o[g])/i;return{line:g>=0&&g<r.length?r[g]:"",phaseInLabel:(()=>{if(h<=l)return 1;const m=(s-l)/(h-l);return m<0?0:m>1?1:m})()}}const _=(d+1)/i;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})()}},sh=e=>{const t=e.Monad0();return n=>r=>o=>t.Bind1().bind(e.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Jo(r)(0)(0)(o).line))(i=>{const u=i+28;return t.Applicative0().pure({x:n.x+n.w/2-u/2,y:n.y-25.2-14,w:u,h:25.2})})},ah=e=>{const t=e.Monad0(),n=t.Bind1(),r=sh(e),o=t.Applicative0(),i=Ar.traverse(o);return u=>s=>n.Apply0().Functor0().map(a=>Pa(St(c=>c)(a)))(i(a=>{if(a._2.tag==="Filling"&&a._2._1.labels.length!==0){const c=ke(a._2._1.node)(u.nodes);if(c.tag==="Just")return n.bind(r(c._1)(a._2._1.progress)(a._2._1.labels))(g=>o.pure(b("Just",x(a._1,g))));if(c.tag==="Nothing")return o.pure(T);f()}return o.pure(T)})(Ze(s.tokens)))},Qa=e=>t=>V(n=>{const r=6.283185307179586*_t(n)/_t(64);return{x:e.x+t*Eo(r),y:e.y+t*So(r)}})($t(0,63)),Ui=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]},ch=e=>{const t=e.Monad0().Bind1(),n=e.popAlpha;return r=>o=>i=>u=>s=>a=>c=>{const g={x:i.x+i.w/2,y:i.y+i.h/2},d=Cr(.05)(1-a-c),l=s<a?0:s>1-c?1:(s-a)/d,_={x:u.x+u.w/2,y:u.y+u.h/2},h=(m,p)=>t.bind(e.pushAlpha(p))(()=>t.bind(e.fillStrokePath(Ui(m)(6))({color:r,flat:!0})({color:o,width:1,lineJoin:qe,lineCap:fn}))(()=>n));return l<.5?h(g,(()=>{const m=l*2;return 1-(m<0?0:m>1?1:m)*(m<0?0:m>1?1:m)*(m<0?3:m>1?1:3-2*m)})()):h(_,(()=>{const m=(l-.5)*2;return(m<0?0:m>1?1:m)*(m<0?0:m>1?1:m)*(m<0?3:m>1?1:3-2*m)})())}},fh={r:255,g:235,b:130,a:255},gh=e=>{const t=e.length;return t===0?{x:0,y:0}:{x:Ga(V(n=>n.x)(e))/_t(t),y:Ga(V(n=>n.y)(e))/_t(t)}},Ia=e=>t=>n=>{const r=ar(6)(.55)(Tn(0)(1)((1-e)/.06)),o=e>.94,i=o&&n>1e-4,u=ar(6)(.55)(Tn(0)(1)(e/.06)),s=e<.06,a=s&&t>1e-4,c=o&&n<=1e-4;return{popScale:a?u:i?r:1,flipY:s&&t<=1e-4?u:c?r:1,fadeAlpha:(()=>{if(a){const g=e/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}if(i){const g=(1-e)/.06;return g<0?.55:g>1?1:.55+.44999999999999996*g}return 1})()}},_h=e=>{const t=e.Monad0().Bind1(),n=za(e);return r=>o=>i=>u=>{const s=Ia(i)(0)(0),a={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500},c=Jo(i)(0)(0)(u);return t.bind(e.measureText(a)(c.line))(g=>{const d={r:26,g:26,b:26,a:90},l=o.x+o.w/2,_=g+28,h=o.y-25.2-14,m=l-_/2,p=[1,l,h+25.2,2,l,o.y],J={x:l,y:h+12.6};return n(s)(l-_/2)(h+25.2)(J)(t.bind(e.drawRoundedRect({x:l-_/2,y:h+1.5,w:_,h:25.2})(6)(b("Just",{color:K0,flat:!0}))(T))(()=>t.bind(e.drawRoundedRect({x:m,y:h,w:_,h:25.2})(6)(b("Just",{color:fh,flat:!0}))(b("Just",{color:d,width:1,lineJoin:qe,lineCap:fn})))(()=>t.bind(e.strokePath(p)({color:d,width:1,lineJoin:qe,lineCap:fn}))(()=>e.drawText({x:l,y:J.y,content:c.line,font:a,color:Ue,align:Fi,baseline:Er})))))})}},Ba={r:0,g:0,b:0,a:0},dh=e=>t=>e.backgroundDots({viewport:{vx:t.x,vy:t.y,vw:t.w,vh:t.h},bgColor:Ba,dotColor:U0,tile:1.6,dotRadius:.25}),lh={r:214,g:211,b:209,a:255},Aa={r:255,g:255,b:255,a:255},hh=e=>{const t=e.Monad0().Bind1();return n=>r=>n?t.bind(e.clearBackground(Ba))(()=>e.setViewport(r)):t.bind(e.setViewport(r))(()=>e.backgroundDots({viewport:r,bgColor:Aa,dotColor:lh,tile:12,dotRadius:.7}))},ph=e=>{const t=e.Monad0(),n=t.Applicative0(),r=t.Bind1(),o=e.popClip,i=e.popTransform,u=e.popAlpha;return s=>a=>c=>{const g=mo(c),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)(b("Just",{color:Aa,flat:!0}))(T))(()=>r.bind((()=>{const m=r.bind(e.pushClip(Ma(d)(7))(Ca))(()=>r.bind(dh(e)(d))(()=>o));return s?m:n.pure()})())(()=>r.bind(e.drawRoundedRect({x:d.x,y:d.y,w:d.w,h:d.h})(7)(T)(b("Just",{color:Ue,width:1.25,lineJoin:qe,lineCap:fn})))(()=>r.bind(i)(()=>u))))));return g.alpha>0?h:n.pure()}},mh=e=>{const t=ph(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>u=>r(s=>{const a=ke(s._1)(u.nodes);if(a.tag==="Just")return t(o)(s._2)(a._1);if(a.tag==="Nothing")return n.pure();f()})(Ze(i.nodes))},yh=e=>{const t=e.Monad0().Applicative0();return n=>{const r=n.length-1|0,o=r<1?[]:Mt(0,r,n),i=o.length-1|0,u=i>=0&&i<o.length?b("Just",o[i]):T,s=n.length-1|0;if(s>=0&&s<n.length&&u.tag==="Just"){const a=n[s].y-u._1.y,c=n[s].x-u._1.x,g=Cn(c*c+a*a),d=a/g,l=-d,_=c/g,h=n[s].x+_*.875,m=n[s].y+d*.875,p=m-d*8.75,J=h-_*8.75,N=[1,h,m,2,J+l*4.375,p+_*4.375,2,J-l*4.375,p-_*4.375,5];return g<=1e-4?t.pure():e.fillPath(N)({color:Ue,flat:!0})}return t.pure()}},No=e=>t=>n=>r=>o=>V(i=>{const u=n+(r-n)*(_t(i)/_t(o));return{x:e.x+t*Eo(u),y:e.y+t*So(u)}})($t(0,o-1|0)),Da=e=>t=>{const n=Ke(e)(Ke(t.w/2)(t.h/2));return[...yo({x:t.x+n,y:t.y})({x:t.x+t.w-n,y:t.y})(6),...No({x:t.x+t.w-n,y:t.y+n})(n)(4.71238898038469)(6.283185307179586)(12),...yo({x:t.x+t.w,y:t.y+n})({x:t.x+t.w,y:t.y+t.h-n})(6),...No({x:t.x+t.w-n,y:t.y+t.h-n})(n)(0)(1.5707963267948966)(12),...yo({x:t.x+t.w-n,y:t.y+t.h})({x:t.x+n,y:t.y+t.h})(6),...No({x:t.x+n,y:t.y+t.h-n})(n)(1.5707963267948966)(3.141592653589793)(12),...yo({x:t.x,y:t.y+t.h-n})({x:t.x,y:t.y+n})(6),...No({x:t.x+n,y:t.y+n})(n)(3.141592653589793)(4.71238898038469)(12)]},Jh=e=>t=>n=>y(r=>o=>{const i=r.pos+o.len,u=n<i?(n-r.pos)/o.len:1,s={x:o.a.x+(o.b.x-o.a.x)*u,y:o.a.y+(o.b.y-o.a.y)*u},a=t>r.pos?(t-r.pos)/o.len:0,c={x:o.a.x+(o.b.x-o.a.x)*a,y:o.a.y+(o.b.y-o.a.y)*a},g=r.points.length-1|0,d=g>=0&&g<r.points.length?(()=>{const l=r.points[g].x-c.x;return(l<0?-l<1e-4:l<1e-4)&&(()=>{const _=r.points[g].y-c.y;return _<0?-_<1e-4:_<1e-4})()})()?ye(r.points)(s):[...r.points,c,s]:[c,s];return o.len<=0||i<=t||r.pos>=n?{...r,pos:i}:{pos:i,points:d}})({pos:0,points:[]})(e).points,Nh=e=>t=>n=>{const r=Ft(o=>T,o=>i=>b("Just",{head:o,tail:i}),e);if(r.tag==="Nothing")return[];if(r.tag==="Just"){const o=oh(e),i=V0(o),u=Tn(0)(i)(t*i),s=Tn(0)(i)(n*i);return s<=u?[]:Jh(o)(u)(s)}f()},xh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=yh(e);return o=>i=>u=>{const s=ih(8)(i);if(u.hi<=u.lo)return n.pure();const a=Nh(s)(u.lo)(u.hi);return a.length===0?n.pure():t.Bind1().bind(e.strokePath(j0(a))({color:Ue,width:.9375,lineJoin:qe,lineCap:Ea}))(()=>r(a))}},vh=e=>{const t=xh(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>r(u=>{const s=po(u._1)(i.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}}f()})());if(s.tag==="Nothing")return n.pure();f()})(Ze(o.edges))},qa=e=>t=>n=>r=>o=>i=>{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?b("Just",e[0]):T,c=(()=>{if(a.tag==="Just")return a._1;if(a.tag==="Nothing")return s;f()})(),g=e.length-1|0,d=g>=0&&g<e.length?b("Just",e[g]):T,l=(()=>{if(d.tag==="Just")return d._1;if(d.tag==="Nothing")return u;f()})(),_=xa(128)(Da(5)(Xi(2)(t)))(Qa(c)(6)),h=Cr(.05)(1-o-i),m=r<o?0:r>1-i?1:(r-o)/h,p=c.x-s.x,J=2*(()=>{const K=c.y-s.y;return(p<0?-p:p)+(K<0?-K:K)})(),N=l.x-u.x,v=2*(()=>{const K=l.y-u.y;return(N<0?-N:N)+(K<0?-K:K)})(),L=J+ri(e)+v,E=L<=1e-4?1:1-v/L,k=L<=1e-4?0:J/L,S=E-k,I=xa(128)(Qa(l)(6))(Da(5)(Xi(2)(n))),F={maxDelay:.4,smoothPasses:2},j=Iu(e)(Tn(0)(1)(S<=1e-4?0:(m-k)/S)),G=(()=>{if(j.tag==="Just")return j._1;if(j.tag==="Nothing")return c;f()})(),P=(()=>{if(E>=1)return 0;const K=(m-E)/(1-E),A=K<0?0:K>1?1:K;return A*A*(3-2*A)})(),et=(()=>{if(k<=1e-4)return 1;const K=m/k,A=K<0?0:K>1?1:K;return A*A*(3-2*A)})();return m<k?Hi("PolyShape",Ta(et)(_.from)(_.to)(F)):m>=E?Hi("PolyShape",Ta(P)(I.from)(I.to)(F)):Hi("CircleShape",G,6)},Th=e=>t=>n=>r=>o=>i=>u=>s=>a=>{const c=qa(r)(o)(i)(u)(s)(a);if(c.tag==="CircleShape")return e.fillStrokePath(Ui(c._1)(c._2))({color:t,flat:!0})({color:n,width:1,lineJoin:qe,lineCap:fn});if(c.tag==="PolyShape")return c._1.length>=3?e.fillStrokePath(X0(c._1))({color:t,flat:!0})({color:n,width:1,lineJoin:qe,lineCap:fn}):e.Monad0().Applicative0().pure();f()},Ya=e=>{const t=ch(e),n=e.Monad0().Applicative0(),r=je(n);return o=>i=>u=>s=>r(a=>{if(a._2.tag==="Travelling"){const c=ke(a._2._1.target)(o.nodes),g=ke(a._2._1.source)(o.nodes);if(g.tag==="Just"&&c.tag==="Just"){const d=po(a._2._1.edge)(o.edges);if(d.tag==="Just")return Th(e)(u)(s)((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return _e(d._1);f()})())(g._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);if(d.tag==="Nothing")return t(u)(s)(g._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost);f()}return n.pure()}if(a._2.tag==="Filling"){const c=ke(a._2._1.node)(o.nodes);if(c.tag==="Just")return e.drawRoundedRect((()=>{const g=Xi(2)(c._1);return{x:g.x,y:g.y,w:g.w,h:g.h}})())(5)(b("Just",{color:u,flat:!0}))(b("Just",{color:s,width:1,lineJoin:qe,lineCap:fn}));if(c.tag==="Nothing")return n.pure();f()}return n.pure()})(Ze(i.tokens))},Lh=e=>{const t=e.Monad0(),n=t.Bind1(),r=Ya(e),o=e.popClip,i=e.popBlend,u=e.popLayer,s=t.Applicative0(),a=je(s);return c=>g=>n.bind(e.pushLayer(D0))(()=>n.bind(e.pushBlend(F0))(()=>n.bind(e.pushClip(Wa(c)(g))(Ca))(()=>n.bind(r(c)(g)(Hn)(Hn))(()=>n.bind(o)(()=>n.bind(i)(()=>n.bind(u)(()=>n.bind(e.pushLayer(q0))(()=>n.bind(a(d=>{const l=ke(d._1)(g.nodes);return l.tag==="Just"&&mo(l._1).alpha>0?e.drawRoundedRect({x:d._2.x,y:d._2.y,w:d._2.w,h:d._2.h})(7)(b("Just",{color:Hn,flat:!1}))(T):s.pure()})(Ze(c.nodes)))(()=>u)))))))))},wh=e=>{const t=e.Monad0().Bind1(),n=Ya(e),r=e.popClip,o=e.popLayer;return i=>u=>s=>t.bind(e.pushLayer(A0))(()=>t.bind(e.pushClip(th(i)(u)(s))($0))(()=>t.bind(n(u)(s)(Ue)(Hn))(()=>t.bind(r)(()=>o))))},$a=e=>t=>n=>r=>o=>i=>{const u=qa(e)(t)(n)(r)(o)(i);if(u.tag==="PolyShape")return gh(u._1);if(u.tag==="CircleShape")return u._1;f()},kh=e=>{const t=za(e),n=e.Monad0(),r=n.Bind1(),o=je(n.Applicative0()),i=uh(e);return u=>s=>a=>c=>g=>d=>l=>_=>{const h=Jo(c)(g)(d)(Ct(l)(Ra)),m=h.line,p=h.phaseInLabel/.45,J=p<0?0:p>1?1:p,N=_.w,v=_.y,L=_.x,E=L+14,k=_.h,S=v+k/2;return t(Ia(c)(g)(d))(L)(v+k)({x:L+N/2,y:S})(r.bind(o(I=>e.fillPath(Ui(I)(1.5))({color:Ue,flat:!0}))(eh(_)($a(u)(s)(a)(c)(g)(d))))(()=>r.bind(e.drawRoundedRect({x:L,y:v,w:N,h:k})(3)(b("Just",{color:Ue,flat:!0}))(T))(()=>i({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Hn)(J)(E)(S)(m))))}},bh=e=>{const t=kh(e),n=e.Monad0(),r=n.Applicative0(),o=_h(e),i=n.Bind1(),u=je(r),s=e.popLayer;return a=>c=>g=>i.bind(e.pushLayer(Y0))(()=>i.bind(u(d=>{if(d._2.tag==="Travelling"){if(d._2._1.labels.length!==0){const l=ke(d._2._1.target)(a.nodes),_=ke(d._2._1.source)(a.nodes),h=po(d._2._1.edge)(a.edges),m=Sa(d._1)(g);if(m.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 _e(h._1);f()})())(_._1)(l._1)(d._2._1.progress)(d._2._1.holdPre)(d._2._1.holdPost)(d._2._1.labels)(m._1)}return r.pure()}if(d._2.tag==="Filling"&&d._2._1.labels.length!==0){const l=ke(d._2._1.node)(a.nodes);if(l.tag==="Just")return o(a)(l._1)(d._2._1.progress)(d._2._1.labels);if(l.tag==="Nothing")return r.pure();f()}return r.pure()})(Ze(c.tokens)))(()=>s))},Eh=e=>{const t=e.Monad0();return n=>r=>o=>i=>u=>s=>a=>{const c=$a(n)(r)(o)(i)(u)(s);return t.Bind1().bind(e.measureText({family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:11,weight:500})(Jo(i)(u)(s)(Ct(a)(Ra)).line))(g=>t.Applicative0().pure({x:c.x+14+g/2-g/2-14,y:c.y-6-8-6.6-6,w:g+28,h:25.2}))}},Ch=e=>{const t=e.Monad0(),n=t.Bind1(),r=Eh(e),o=t.Applicative0(),i=Ar.traverse(o);return u=>s=>n.Apply0().Functor0().map(a=>Pa(St(c=>c)(a)))(i(a=>{if(a._2.tag==="Travelling"&&a._2._1.labels.length!==0){const c=ke(a._2._1.target)(u.nodes),g=ke(a._2._1.source)(u.nodes),d=po(a._2._1.edge)(u.edges);if(d.tag==="Just"&&g.tag==="Just"&&c.tag==="Just")return n.bind(r((()=>{if(a._2._1.direction==="Forward")return d._1;if(a._2._1.direction==="Backward")return _e(d._1);f()})())(g._1)(c._1)(a._2._1.progress)(a._2._1.holdPre)(a._2._1.holdPost)(a._2._1.labels))(l=>o.pure(b("Just",x(a._1,l))))}return o.pure(T)})(Ze(s.tokens)))},Sh=e=>{const t=e.Monad0(),n=t.Bind1(),r=Ch(e),o=ah(e);return i=>u=>n.bind(r(i)(u))(s=>n.bind(o(i)(u))(a=>t.Applicative0().pure(Z0((()=>{const c=g=>{if(g.tag==="Leaf")return D;if(g.tag==="Node")return Yt("Node",g._1,g._2,g._3,void 0,c(g._5),c(g._6));f()};return vt(w.compare)(Lt(Le.foldr,c(s)))})())(s)([...V(H0)((()=>{const c=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return c(g._5,Qt("Cons",g._4,c(g._6,d)));f()};return Lt(qt.foldr,c(i.nodes,Bt))})()),...(()=>{const c=(g,d)=>{if(g.tag==="Leaf")return d;if(g.tag==="Node")return c(g._5,Qt("Cons",g._4,c(g._6,d)));f()};return Lt(qt.foldr,c(a,Bt))})()]))))},Fa=e=>t=>n=>{const r=ju(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}},Ph=e=>{const t=e.Monad0(),n=t.Bind1();return r=>o=>{if(r==="")return t.Applicative0().pure();const i=o.vh/720,u=15*i,s={family:"Ilisarniq, ui-sans-serif, system-ui, sans-serif",size:u,weight:600};return n.bind(e.measureText(s)(r))(a=>{const c=o.vy+12*i,g=u+6*i*2,d=a+11*i*2,l=o.vx+o.vw/2;return n.bind(e.drawRoundedRect({x:l-d/2,y:c,w:d,h:g})(g/2)(b("Just",{color:{r:255,g:255,b:255,a:240},flat:!0}))(b("Just",{color:{r:0,g:0,b:0,a:255},width:1*i,lineJoin:qe,lineCap:Ea})))(()=>e.drawText({x:l,y:c+g/2,content:r,font:s,color:{r:28,g:30,b:36,a:255},align:Fi,baseline:Er}))})}},Gh=e=>{const t=e.Monad0().Bind1(),n=hh(e),r=vh(e),o=mh(e),i=rh(e),u=wh(e),s=Lh(e),a=bh(e),c=Ph(e);return g=>d=>l=>_=>{const h=Fa(g)(d)(l);return t.bind(n(g.transparentBg)(h))(()=>t.bind(r(d)(l))(()=>t.bind(o(g.halftoneShadows)(d)(l))(()=>t.bind(i(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:$i,baseline:B0}))(()=>c(l.frameTitle)(h)))))))))}},Ha=e=>t=>n=>{const r=lt.compare(e)(n),o=(()=>{if(r==="LT")return n;if(r==="EQ"||r==="GT")return e;f()})(),i=lt.compare(t)(o);if(i==="LT"||i==="EQ")return t;if(i==="GT")return o;f()},zh=Sh(Ja),Mh=Gh(Ja),Wh=e=>{const t=e.vx+e.vw-4,n=e.vy+e.vh-4,r=e.vx+4,o=e.vy+4,i=u=>{if(u.tag==="Leaf")return D;if(u.tag==="Node")return Yt("Node",u._1,u._2,u._3,{...u._4,x:Ha(r)(t-u._4.w)(u._4.x),y:Ha(o)(n-u._4.h)(u._4.y)},i(u._5),i(u._6));f()};return i},Rh=e=>t=>n=>r=>o=>i=>{const u={padding:24,transparentBg:!1,halftoneShadows:!0,watermark:""},s=h0(e)(t);return()=>{const a=s(),c=zh(n)(r)(a)(),g=u0(o)(Wh(Fa(u)(n)(r))(c))(i);return Mh(u)(n)(r)(g.applied)(a)(),g.springs}},Sr=e=>({bind:t=>n=>r=>e.Bind1().bind(t(r))(o=>n(o._1)(o._2)),Apply0:()=>Va(e)}),Va=e=>{const t=e.Bind1().Apply0().Functor0(),n={map:r=>o=>i=>t.map(u=>x(r(u._1),u._2))(o(i))};return{apply:(()=>{const r=Sr(e);return o=>i=>r.bind(o)(u=>r.bind(i)(s=>Pr(e).pure(u(s))))})(),Functor0:()=>n}},Pr=e=>({pure:t=>n=>e.Applicative0().pure(x(t,n)),Apply0:()=>Va(e)}),Qh=e=>{const t={Applicative0:()=>Pr(e),Bind1:()=>Sr(e)};return{state:n=>r=>e.Applicative0().pure(n(r)),Monad0:()=>t}},Ki=(e,t)=>({tag:e,_1:t}),Ln=(e,t)=>({tag:e,_1:t}),ve=Qh(rn),At=Sr(rn),be=ve.state(e=>x(e,e)),tn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},gn=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},ce=Pr(rn),Ih=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=T;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=b("Just",i._4);continue}}f()}return o},Bh=(()=>{const e=Pe.unfoldr(t=>{if(t.tag==="Nil")return T;if(t.tag==="Cons")return b("Just",x(t._1,t._2));f()});return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Qt("Cons",r._3,n(r._6,o)));f()};return n(t,Bt)})())})(),Ah=e=>t=>{let n=t,r=!0,o;for(;r;){const i=n;if(i.tag==="Leaf"){r=!1,o=!1;continue}if(i.tag==="Node"){const u=w.compare(e)(i._3);if(u==="LT"){n=i._5;continue}if(u==="GT"){n=i._6;continue}if(u==="EQ"){r=!1,o=!0;continue}}f()}return o},Zi=e=>t=>n=>y(r=>o=>e.Bind1().bind(r)(i=>t(i)(o)))(e.Applicative0().pure(n)),Dh=y(e=>t=>Z(w)(t)()(e))(D),qh=(()=>{const e=(t=>n=>{let r=t,o=n,i=!0,u;for(;i;){const s=r,a=o;if(a.tag==="Nil"){i=!1,u=s;continue}if(a.tag==="Cons"){r=Z(w)(a._1)()(s),o=a._2;continue}f()}return u})(D);return t=>e((()=>{const n=(r,o)=>{if(r.tag==="Leaf")return o;if(r.tag==="Node")return n(r._5,Qt("Cons",r._3,n(r._6,o)));f()};return n(t,Bt)})())})(),Xa=yc(ce)(It),Yh=e=>Ki("Par",e),Oa=e=>Ki("Seq",e),ze=e=>ve.state(t=>x(void 0,(()=>{if(t.error.tag==="Just")return t;if(t.error.tag==="Nothing")return{...t,error:b("Just",{msg:e,line:t.currentLine,column:t.currentColumn})};f()})())),$h=e=>At.bind(be)(t=>{const n=e.tag==="Just"&&e._1!==""?e._1:"kf-"+Te(t.kfCounter);if(on(o=>o.id===n,t.keyframes))return ze("duplicate frame name "+n);const r={...t,keyframes:ye(t.keyframes)({id:n,nodes:t.currNodes,edges:t.currEdges}),kfCounter:t.kfCounter+1|0,currentKf:b("Just",n)};return ve.state(o=>x(void 0,r))}),Fh=e=>t=>{const n=t.from+"->"+t.to,r=t.newFrom+"->"+t.newTo,o=wt("Left","cannot repoint "+t.from+"\u2192"+t.to+": edge does not exist"),i=tn(n)(e.currEdges)?wt("Right",void 0):o;return(()=>{if(i.tag==="Left"){const u=i._1;return s=>wt("Left",u)}if(i.tag==="Right"){const u=i._1;return s=>s(u)}f()})()(()=>{const u="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": unknown node "+t.newFrom;if(!gn(t.newFrom)(e.currNodes))return wt("Left",u);const s="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": unknown node "+t.newTo;if(!gn(t.newTo)(e.currNodes))return wt("Left",s);const a="cannot repoint "+t.from+"\u2192"+t.to+" to "+t.newFrom+"\u2192"+t.newTo+": target edge already exists";return n!==r&&tn(r)(e.currEdges)?wt("Left",a):wt("Right",{nextCurrEdges:Z(w)(r)()(er(w)(n)(e.currEdges)),newId:r,newEdge:{id:r,from:{node:t.newFrom,port:T},to:{node:t.newTo,port:T}}})})},Hh={graphNodes:D,graphEdges:D,currNodes:D,currEdges:D,keyframes:[],scenes:[],kfCounter:0,eventCounter:0,currentKf:T,currentLine:0,currentColumn:0,error:T},Ua=e=>t=>At.bind(be)(n=>{const r="ev-"+Te(n.eventCounter);return At.bind((()=>{const o={...n,eventCounter:n.eventCounter+1|0};return ve.state(i=>x(void 0,o))})())(()=>ce.pure({events:[{id:r,kind:t,when:e}],firstId:b("Just",r),lastId:b("Just",r)}))}),Vh=e=>t=>{if(t.tag==="Token"){const n=t._1;return At.bind(be)(r=>{const o=!gn(n.from)(r.currNodes),i=!gn(n.to)(r.currNodes);if(o||i)return At.bind(ze(o?i?"token references unknown node: "+n.from+", "+n.to:"token references unknown node: "+n.from:i?"token references unknown node: "+n.to:"token references unknown node: "))(()=>ce.pure({events:[],firstId:T,lastId:T}));const u=n.to+"->"+n.from,s=n.from+"->"+n.to;return tn(s)(r.currEdges)?Ua(e)(Fu("SendToken",{from:n.from,to:n.to,edge:s,direction:lg,labels:n.labels})):tn(u)(r.currEdges)?Ua(e)(Fu("SendToken",{from:n.from,to:n.to,edge:u,direction:hg,labels:n.labels})):At.bind(ze("token "+n.from+"\u2192"+n.to+": no edge between "+n.from+" and "+n.to))(()=>ce.pure({events:[],firstId:T,lastId:T}))})}return ce.pure({events:[],firstId:T,lastId:T})},Xh=e=>St(t=>Ih(t)(e.graphEdges))(Lt(jn,Bh(e.currEdges))),Oh=e=>t=>{const n=at(o=>o.from.node===t.id||o.to.node===t.id,Xh(e)),r=Zi(pc)(o=>i=>{const u=i.from+"->"+t.id,s=t.id+"->"+i.to,a=i.from+"->"+i.to,c="via "+i.from+" "+i.to+": no edge "+i.from+"\u2192"+t.id;if(!tn(u)(e.currEdges))return wt("Left",c);const g="via "+i.from+" "+i.to+": no edge "+t.id+"\u2192"+i.to;if(!tn(s)(e.currEdges))return wt("Left",g);const d="via "+i.from+" "+i.to+": would create "+i.from+"\u2192"+i.to+" but it already exists";return tn(a)(e.currEdges)||Ah(a)(o.synthesized)?wt("Left",d):wt("Right",{consumed:Z(w)(u)()(Z(w)(s)()(o.consumed)),synthesized:Z(w)(a)({id:a,from:{node:i.from,port:T},to:{node:i.to,port:T}})(o.synthesized)})})({consumed:D,synthesized:D})(t.via);return(()=>{if(r.tag==="Left"){const o=r._1;return i=>wt("Left",o)}if(r.tag==="Right"){const o=r._1;return i=>i(o)}f()})()(o=>{const i=o.consumed,u=at(s=>!tn(s.id)(i),n);return u.length===0?wt("Right",{nextCurrEdges:pe(w.compare,he,He(w.compare,e.currEdges,Dh(V(s=>s.id)(n))),qh((()=>{const s=a=>{if(a.tag==="Leaf")return D;if(a.tag==="Node")return Yt("Node",a._1,a._2,a._3,void 0,s(a._5),s(a._6));f()};return s(o.synthesized)})())),synthesized:o.synthesized}):wt("Left","cannot delete node "+t.id+": still connected ("+Dg(", ")(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.")})},Ka=e=>{if(e.tag==="Leaf")return[e._1];if(e.tag==="Par"||e.tag==="Seq")return Ct(e._1)(Ka);f()},Uh=e=>({nodes:(()=>{const t=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return t(n._5,Qt("Cons",n._4,t(n._6,r)));f()};return Lt(qt.foldr,t(e.graphNodes,Bt))})(),edges:(()=>{const t=(n,r)=>{if(n.tag==="Leaf")return r;if(n.tag==="Node")return t(n._5,Qt("Cons",n._4,t(n._6,r)));f()};return Lt(qt.foldr,t(e.graphEdges,Bt))})(),constraints:[]}),Kh=e=>{if(e.tag==="AddNode"){const t=e._1;return ve.state(n=>x(void 0,{...n,graphNodes:Z(w)(t.id)({id:t.id,size:x(1,1),ports:[],label:b("Just",t.label)})(n.graphNodes),currNodes:Z(w)(t.id)()(n.currNodes)}))}if(e.tag==="DelNode"){const t=e._1;return At.bind(be)(n=>{if(!gn(t.id)(n.currNodes))return ze("cannot delete node "+t.id+": does not exist");const r=Oh(n)(t);if(r.tag==="Left")return ze(r._1);if(r.tag==="Right"){const o=r._1;return ve.state(i=>x(void 0,{...i,currNodes:er(w)(t.id)(i.currNodes),currEdges:o.nextCurrEdges,graphEdges:pe(w.compare,he,o.synthesized,i.graphEdges)}))}f()})}if(e.tag==="ModNode"){const t=e._1;return At.bind(be)(n=>{if(!gn(t.id)(n.currNodes))return ze("cannot modify node "+t.id+": does not exist");if(t.label.tag==="Just"){const r=t.label._1;return ve.state(o=>x(void 0,{...o,graphNodes:Ec(w)(i=>b("Just",{...i,label:b("Just",r)}))(t.id)(o.graphNodes)}))}if(t.label.tag==="Nothing")return ce.pure();f()})}if(e.tag==="AddEdge"){const t=e._1;return At.bind(be)(n=>{const r=!gn(t.from)(n.currNodes),o=!gn(t.to)(n.currNodes);if(r||o)return ze("cannot add edge "+t.from+"\u2192"+t.to+": unknown node "+(r?o?t.from+", "+t.to:t.from:o?t.to:""));const i=t.from+"->"+t.to;return ve.state(u=>x(void 0,{...u,graphEdges:Z(w)(i)({id:i,from:{node:t.from,port:T},to:{node:t.to,port:T}})(u.graphEdges),currEdges:Z(w)(i)()(u.currEdges)}))})}if(e.tag==="DelEdge"){const t=e._1;return At.bind(be)(n=>{const r=t.from+"->"+t.to;return tn(r)(n.currEdges)?ve.state(o=>x(void 0,{...o,currEdges:er(w)(r)(o.currEdges)})):ze("cannot delete edge "+t.from+"\u2192"+t.to+": does not exist")})}if(e.tag==="RepointEdge"){const t=e._1;return At.bind(be)(n=>{const r=Fh(n)(t);if(r.tag==="Left")return ze(r._1);if(r.tag==="Right"){const o=r._1;return ve.state(i=>x(void 0,{...i,currEdges:o.nextCurrEdges,graphEdges:Z(w)(o.newId)(o.newEdge)(i.graphEdges)}))}f()})}return ce.pure()},Zh=e=>At.bind(ve.state(t=>x(void 0,{...t,currentLine:e.line,currentColumn:e.column})))(()=>Kh(e.op)),jh=e=>t=>At.bind(Xa(Zh)(t))(()=>At.bind(be)(n=>{const r=e.tag==="Just"&&e._1!==""?e._1:"kf-"+Te(n.kfCounter);if(on(i=>i.id===r,n.keyframes))return ze("duplicate frame name "+r);const o={...n,keyframes:ye(n.keyframes)({id:r,nodes:n.currNodes,edges:n.currEdges}),kfCounter:n.kfCounter+1|0,currentKf:b("Just",r),scenes:(()=>{if(n.currentKf.tag==="Nothing")return n.scenes;if(n.currentKf.tag==="Just")return ye(n.scenes)(Hu("Structural",{from:n.currentKf._1,to:r,focus:T}));f()})()};return ve.state(i=>x(void 0,o))})),tp=e=>t=>{const n=Ft(r=>T,r=>o=>b("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return ce.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return At.bind(Gr(e)(n._1.head))(o=>At.bind(Zi({Applicative0:()=>Pr(rn),Bind1:()=>Sr(rn)})(i=>u=>At.bind(Gr((()=>{if(i.lastId.tag==="Just")return ai("After",i.lastId._1);if(i.lastId.tag==="Nothing")return e;f()})())(u))(s=>ce.pure({events:[...i.events,...s.events],firstId:(()=>{if(i.firstId.tag==="Just")return b("Just",i.firstId._1);if(i.firstId.tag==="Nothing")return s.firstId;f()})(),lastId:(()=>{if(s.lastId.tag==="Just")return b("Just",s.lastId._1);if(s.lastId.tag==="Nothing")return i.lastId;f()})()})))(o)(r))(i=>ce.pure(i)))}f()},ep=e=>t=>{const n=Ft(r=>T,r=>o=>b("Just",{head:r,tail:o}),t);if(n.tag==="Nothing")return ce.pure({events:[],firstId:T,lastId:T});if(n.tag==="Just"){const r=n._1.tail;return At.bind(Gr(e)(n._1.head))(o=>At.bind(np((()=>{if(o.firstId.tag==="Just")return ai("With",o.firstId._1);if(o.firstId.tag==="Nothing")return e;f()})())(r))(i=>ce.pure({events:[...o.events,...i.events],firstId:o.firstId,lastId:(()=>{if(o.lastId.tag==="Just")return b("Just",o.lastId._1);if(o.lastId.tag==="Nothing")return i.lastId;f()})()})))}f()},Gr=e=>t=>{if(t.tag==="Leaf"){const n=t._1;return At.bind(ve.state(r=>x(void 0,{...r,currentLine:n.line,currentColumn:n.column})))(()=>Vh(e)(n.op))}if(t.tag==="Seq")return tp(e)(t._1);if(t.tag==="Par")return ep(e)(t._1);f()},np=e=>Zi({Applicative0:()=>Pr(rn),Bind1:()=>Sr(rn)})(t=>n=>At.bind(Gr(e)(n))(r=>ce.pure({events:[...t.events,...r.events],firstId:(()=>{if(t.firstId.tag==="Just")return b("Just",t.firstId._1);if(t.firstId.tag==="Nothing")return r.firstId;f()})(),lastId:(()=>{if(r.lastId.tag==="Just")return b("Just",r.lastId._1);if(r.lastId.tag==="Nothing")return t.lastId;f()})()})))({events:[],firstId:T,lastId:T}),rp=e=>At.bind(be)(t=>{if(t.currentKf.tag==="Nothing")return ze("flow ops before any structural frame");if(t.currentKf.tag==="Just"){const n=t.currentKf._1;return At.bind(Gr(dg)(e))(r=>At.bind(be)(o=>{const i={...o,scenes:ye(o.scenes)(Hu("DataFlow",{keyframe:n,events:r.events,focus:T}))};return ve.state(u=>x(void 0,i))}))}f()}),op=e=>At.bind(be)(t=>{if(t.error.tag==="Just")return ce.pure();if(t.error.tag==="Nothing"){const n=Ka(e.ops),r=at(i=>i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge",n),o=at(i=>!(i.op.tag==="AddNode"||i.op.tag==="DelNode"||i.op.tag==="ModNode"||i.op.tag==="AddEdge"||i.op.tag==="DelEdge"||i.op.tag==="RepointEdge"),n);return At.bind((()=>{const i=jh(e.name)(r);return r.length!==0?i:ce.pure()})())(()=>At.bind((()=>{const i=$h(e.name);return r.length===0&&o.length!==0?i:ce.pure()})())(()=>{const i=rp(e.ops);return o.length!==0?i:ce.pure()}))}f()}),ip=e=>At.bind(Xa(op)(e.frames))(()=>At.bind(be)(t=>ce.pure((()=>{if(t.error.tag==="Just")return wt("Left",t.error._1);if(t.error.tag==="Nothing")return wt("Right",{seed:e.seed,graph:Uh(t),keyframes:t.keyframes,scenes:t.scenes});f()})())))(Hh)._1,Vn=(e,t)=>({tag:"ParseError",_1:e,_2:t}),B=(e,t,n)=>({tag:"ParseState",_1:e,_2:t,_3:n}),xo=(e,t,n)=>({tag:e,_1:t,_2:n}),up=e=>xo("More",e),sp=e=>xo("Lift",e),Za={map:e=>t=>(n,r,o,i,u)=>r(s=>t(n,r,o,i,(a,c)=>r(g=>u(a,e(c)))))},ap={alt:e=>t=>(n,r,o,i,u)=>{const s=n._1,a=n._2;return r(c=>e(B(s,a,!1),r,o,(g,d)=>{const l=g._3;return r(_=>l?i(g,d):t(n,r,o,i,u))},u))},Functor0:()=>Za},cp=e=>{const t=e.Monad0();return n=>r=>{const o=i=>{let u=i,s=!0,a;for(;s;){const c=u();if(c.tag==="More"){u=c._1;continue}if(c.tag==="Lift"){s=!1,a=t.Bind1().Apply0().Functor0().map(Su)(c._1);continue}if(c.tag==="Stop"){s=!1,a=t.Applicative0().pure(ir("Done",x(c._2,c._1)));continue}f()}return a};return e.tailRecM(o)(i=>r(n,up,sp,(u,s)=>xo("Stop",u,wt("Left",s)),(u,s)=>xo("Stop",u,wt("Right",s))))}},ja=(e,t,n,r,o)=>o(e,e._2),fp={index:0,line:1,column:1},gp=(e=>{const t=cp(e);return n=>r=>e.Monad0().Bind1().Apply0().Functor0().map(Mr)(t(B(n,fp,!1))(r))})(Sf),tc={apply:e=>t=>(n,r,o,i,u)=>r(s=>e(n,r,o,i,(a,c)=>r(g=>{const d=n._3&&!a._3?B(a._1,a._2,!0):a;return t(d,r,o,i,(l,_)=>r(h=>u(d._3&&!l._3?B(l._1,l._2,!0):l,c(_))))}))),Functor0:()=>Za},ec={pure:e=>(t,n,r,o,i)=>i(t,e),Apply0:()=>tc},_p={bind:e=>t=>(n,r,o,i,u)=>r(s=>e(n,r,o,i,(a,c)=>r(g=>t(c)(n._3&&!a._3?B(a._1,a._2,!0):a,r,o,i,u)))),Apply0:()=>tc},dp={Applicative0:()=>ec,Bind1:()=>_p},vo=e=>(t,n,r,o,i)=>n(u=>ja(t,n,r,o,(s,a)=>n(c=>o(t._3&&!s._3?B(s._1,s._2,!0):s,Vn(e,a))))),lp={empty:vo("No alternative"),Alt0:()=>ap},hp={Applicative0:()=>ec,Plus1:()=>lp},Ce=(e=>t=>{const n=t.Plus1().Alt0(),r=t.Applicative0();return o=>e.tailRecM(i=>e.Monad0().Bind1().bind(n.alt(n.Functor0().map(Su)(o))(r.pure(ir("Done",void 0))))(u=>r.pure((()=>{if(u.tag==="Loop")return ir("Loop",Qt("Cons",u._1,i));if(u.tag==="Done")return ir("Done",(s=>a=>{let c=s,g=a,d=!0,l;for(;d;){const _=c,h=g;if(h.tag==="Nil"){d=!1,l=_;continue}if(h.tag==="Cons"){c=Qt("Cons",h._1,_),g=h._2;continue}f()}return l})(Bt)(i));f()})())))(Bt)})({tailRecM:e=>t=>(n,r,o,i,u)=>{const s=(a,c,g)=>e(c)(a,r,o,i,(d,l)=>{const _=a._3&&!d._3?B(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);f()});return s(n,t,30)},Monad0:()=>dp})(hp),kt=e=>t=>{const n=vo("Expected "+t);return(r,o,i,u,s)=>{const a=r._1,c=r._2;return o(g=>e(B(a,c,!1),o,i,(d,l)=>{const _=d._3;return o(h=>_?u(d,l):n(r,o,i,u,s))},s))}},ji=e=>(t,n,r,o,i)=>{const u=t._3,s=t._1,a=t._2;return n(c=>{const g=(d,l)=>{const _=d._3;return n(h=>_?o(B(d._1,d._2,u),l):i(t,void 0))};return n(d=>n(l=>e(B(s,a,!1),n,r,(_,h)=>g(B(_._1,_._2,!1),h),(_,h)=>n(m=>n(p=>vo("Negated parser succeeded")(_,n,r,g,(J,N)=>n(v=>i(_._3&&!J._3?B(J._1,J._2,!0):J,N))))))))})},pp=e=>{const t=e.foldr(n=>r=>{if(r.tag==="Nothing")return b("Just",n);if(r.tag==="Just")return b("Just",(o,i,u,s,a)=>{const c=o._1,g=o._2;return i(d=>n(B(c,g,!1),i,u,(l,_)=>{const h=l._3;return i(m=>h?s(l,_):r._1(o,i,u,s,a))},a))});f()})(T);return n=>{const r=t(n);if(r.tag==="Nothing")return vo("No alternative");if(r.tag==="Just")return r._1;f()}},mp=e=>t=>n=>(r,o,i,u,s)=>o(a=>o(c=>o(g=>o(d=>e(r,o,i,u,(l,_)=>o(h=>o(m=>{const p=r._3&&!l._3?B(l._1,l._2,!0):l;return n(p,o,i,u,(J,N)=>o(v=>{const L=p._3&&!J._3?B(J._1,J._2,!0):J;return o(E=>o(k=>{const S=r._3&&!L._3?B(L._1,L._2,!0):L;return t(S,o,i,u,(I,F)=>o(j=>s(S._3&&!I._3?B(I._1,I._2,!0):I,N)))}))}))}))))))),tu=e=>t=>n=>{if(t===10)return{index:e.index+1|0,line:e.line+1|0,column:1};if(t===13){const r=jg()(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)-Go(e.column-1|0)(8)|0}:{index:e.index+1|0,line:e.line,column:e.column+1|0}},yp=e=>t=>n=>{let r=e,o=t,i=n,u=!0,s;for(;u;){const a=r,c=o,g=i,d=Vr(c);if(d.tag==="Nothing"){u=!1,s=a;continue}if(d.tag==="Just"){r=d._1.tail===""?tu(a)(d._1.head)(g):tu(a)(d._1.head)(d._1.tail),o=d._1.tail,i=g;continue}f()}return s},Vt=e=>(t,n,r,o,i)=>{const u=Vr(t._1);if(u.tag==="Nothing")return o(t,Vn("Unexpected EOF",t._2));if(u.tag==="Just"){if(u._1.head<0||u._1.head>65535)return o(t,Vn("Expected Char",t._2));if(u._1.head>=0&&u._1.head<=65535){const s=ts(u._1.head);return e(s)?i(B(u._1.tail,tu(t._2)(u._1.head)(u._1.tail),!0),s):o(t,Vn("Predicate unsatisfied",t._2))}}f()},nc=(e,t,n,r,o)=>e._1===""?o(B(e._1,e._2,!0),void 0):r(e,Vn("Expected EOF",e._2)),Jp=e=>(t,n,r,o,i)=>{const u=e(t._1);if(u.tag==="Left")return o(t,Vn(u._1,t._2));if(u.tag==="Right")return i(B(u._1.remainder,yp(t._2)(u._1.consumed)(u._1.remainder),u._1.consumed!==""),u._1.value);f()},Xn=e=>Jp(t=>{const n=rg(e)(t);return n.tag==="Just"?wt("Right",{value:e,consumed:e,remainder:n._1}):wt("Left","Expected "+fc(e))}),Np=Vt(e=>!0),rc=pp(It),oc=(()=>{const e=Vt(t=>t===" "||t===" "||t===`
8
- `||t==="\r");return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(c=>i(t._3&&!s._3?B(s._1,s._2,!0):s,void 0))))})(),eu=(e,t,n,r,o)=>t(i=>Xn("#")(e,t,n,r,(u,s)=>t(a=>{const c=Ce(Vt(d=>d!==`
9
- `)),g=e._3&&!u._3?B(u._1,u._2,!0):u;return t(d=>c(g,t,n,r,(l,_)=>t(h=>o(g._3&&!l._3?B(l._1,l._2,!0):l,void 0))))}))),xp=kt((()=>{const e=kt(Vt(n=>n==="}"))("'}'"),t=Vt(n=>n===`
10
- `||n==="\r");return(n,r,o,i,u)=>{const s=n._1,a=n._2;return r(c=>r(g=>e(B(s,a,!1),r,o,(d,l)=>r(_=>{const h=n._1,m=n._2;return r(p=>r(J=>eu(B(h,m,!1),r,o,(N,v)=>{const L=N._3;return r(E=>{if(L)return i(N,v);const k=n._1,S=n._2;return r(I=>r(F=>t(B(k,S,!1),r,o,(j,G)=>{const P=j._3;return r(et=>P?i(j,G):nc(n,r,o,i,u))},(j,G)=>r(P=>u(j,void 0)))))})},(N,v)=>r(L=>u(N,void 0)))))}),(d,l)=>r(_=>u(B(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Se=(()=>{const e=Ce((t,n,r,o,i)=>{const u=t._1,s=t._2;return n(a=>oc(B(u,s,!1),n,r,(c,g)=>{const d=c._3;return n(l=>d?o(c,g):eu(t,n,r,o,i))},i))});return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(c=>i(t._3&&!s._3?B(s._1,s._2,!0):s,void 0))))})(),Me=(e,t,n,r,o)=>t(i=>{const u=(c,g)=>t(d=>Se(e._3&&!c._3?B(c._1,c._2,!0):c,t,n,r,o)),s=e._1,a=e._2;return t(c=>oc(B(s,a,!1),t,n,(g,d)=>{const l=g._3;return t(_=>l?r(g,d):eu(e,t,n,r,u))},u))}),ic=(()=>{const e=kt(Vt(t=>t==="|"))("'|'");return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(c=>{const g=Ce(Vt(l=>l!=="|")),d=t._3&&!s._3?B(s._1,s._2,!0):s;return n(l=>g(d,n,r,o,(_,h)=>n(m=>{const p=kt(kt(Vt(N=>N==="|"))("'|'"))("closing '|'"),J=d._3&&!_._3?B(_._1,_._2,!0):_;return n(N=>p(J,n,r,o,(v,L)=>n(E=>i(J._3&&!v._3?B(v._1,v._2,!0):v,Mn(Lt(qt.foldr,h))))))})))})))})(),To=Vt(e=>e>="a"&&e<="z"||e>="A"&&e<="Z"),wn=(()=>{const e=Ce(Vt(t=>t===" "||t===" "));return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(c=>i(t._3&&!s._3?B(s._1,s._2,!0):s,void 0))))})(),vp=(()=>{const e=kt(Vt(t=>t==="\\"))("'\\\\'");return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(c=>{const g=t._3&&!s._3?B(s._1,s._2,!0):s;return n(d=>Np(g,n,r,o,(l,_)=>n(h=>i(g._3&&!l._3?B(l._1,l._2,!0):l,_==="n"?`
11
- `:_==="t"?" ":_==="r"?"\r":_))))})))})(),Tp=(()=>{const e=Vt(t=>t!=='"'&&t!=="\\"&&t!==`
12
- `);return(t,n,r,o,i)=>{const u=t._1,s=t._2;return n(a=>vp(B(u,s,!1),n,r,(c,g)=>n(d=>e(t,n,r,o,i)),i))}})(),nu=(()=>{const e=kt(Vt(t=>t==='"'))(`'"'`);return(t,n,r,o,i)=>n(u=>e(t,n,r,o,(s,a)=>n(c=>{const g=Ce(Tp),d=t._3&&!s._3?B(s._1,s._2,!0):s;return n(l=>g(d,n,r,o,(_,h)=>n(m=>{const p=kt(kt(Vt(N=>N==='"'))(`'"'`))(`closing '"' (unterminated string)`),J=d._3&&!_._3?B(_._1,_._2,!0):_;return n(N=>p(J,n,r,o,(v,L)=>n(E=>i(J._3&&!v._3?B(v._1,v._2,!0):v,Mn(Lt(qt.foldr,h))))))})))})))})(),Lp=(()=>{const e=kt(Vt(t=>t===":"))("':'");return(t,n,r,o,i)=>n(u=>wn(t,n,r,o,(s,a)=>n(c=>kt((g,d,l,_,h)=>{const m=g._1,p=g._2;return d(J=>{const N=(v,L)=>{const E=v._3;return d(k=>{if(E)return _(v,L);const S=g._1,I=g._2;return d(F=>ic(B(S,I,!1),d,l,(j,G)=>{const P=j._3;return d(et=>P?_(j,G):nu(g,d,l,_,h))},h))})};return d(v=>e(B(m,p,!1),d,l,N,(L,E)=>d(k=>d(S=>wn(L,d,l,N,(I,F)=>d(j=>{const G=Ce(Vt(et=>et!==`
13
- `&&et!=="\r"&&et!=="#"&&et!=="}")),P=L._3&&!I._3?B(I._1,I._2,!0):I;return d(et=>G(P,d,l,N,(K,A)=>d(Y=>h(P._3&&!K._3?B(K._1,K._2,!0):K,Ag(Mn(Lt(qt.foldr,A)))))))}))))))})})('label ("\u2026", : rest-of-line, or |\u2026|)')(t._3&&!s._3?B(s._1,s._2,!0):s,n,r,o,i))))})(),wp=(e,t,n,r,o)=>{const i=e._1,u=e._2;return t(s=>ic(B(i,u,!1),t,n,(a,c)=>{const g=a._3;return t(d=>g?r(a,c):nu(e,t,n,r,o))},o))},zr=Vt(e=>e>="0"&&e<="9"),Je=(()=>{const e=kt(Vt(t=>t==="_"))("'_'");return(t,n,r,o,i)=>n(u=>{const s=(g,d)=>n(l=>{const _=Ce((()=>{const m=kt(Vt(J=>J==="_"))("'_'"),p=kt(Vt(J=>J==="-"))("'-'");return(J,N,v,L,E)=>{const k=J._1,S=J._2;return N(I=>To(B(k,S,!1),N,v,(F,j)=>{const G=F._3;return N(P=>{if(G)return L(F,j);const et=J._1,K=J._2;return N(A=>zr(B(et,K,!1),N,v,(Y,R)=>{const C=Y._3;return N(z=>{if(C)return L(Y,R);const M=J._1,W=J._2;return N(H=>m(B(M,W,!1),N,v,(O,$)=>{const q=O._3;return N(Q=>q?L(O,$):p(J,N,v,L,E))},E))})},E))})},E))}})()),h=t._3&&!g._3?B(g._1,g._2,!0):g;return n(m=>_(h,n,r,o,(p,J)=>n(N=>i(h._3&&!p._3?B(p._1,p._2,!0):p,oi(d)+Mn(Lt(qt.foldr,J))))))}),a=t._1,c=t._2;return n(g=>To(B(a,c,!1),n,r,(d,l)=>{const _=d._3;return n(h=>_?o(d,l):e(t,n,r,o,s))},s))})})(),kp=kt((e,t,n,r,o)=>{const i=e._1,u=e._2;return t(s=>nu(B(i,u,!1),t,n,(a,c)=>{const g=a._3;return t(d=>g?r(a,c):Je(e,t,n,r,o))},o))})("frame name (identifier or quoted string)"),bp=(e,t,n,r,o)=>t(i=>Je(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>wn(c,t,n,r,(d,l)=>t(_=>{const h=kt((p,J,N,v,L)=>{const E=p._1,k=p._2;return J(S=>Xn("->")(B(E,k,!1),J,N,(I,F)=>{const j=I._3;return J(G=>j?v(I,F):Xn("<-")(p,J,N,v,L))},L))})("'->' or '<-'"),m=c._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>h(m,t,n,r,(J,N)=>t(v=>{const L=m._3&&!J._3?B(J._1,J._2,!0):J;return t(E=>wn(L,t,n,r,(k,S)=>t(I=>{const F=kt(Je)("target node identifier"),j=L._3&&!k._3?B(k._1,k._2,!0):k;return t(G=>F(j,t,n,r,(P,et)=>t(K=>{const A=Ce((R,C,z,M,W)=>{const H=R._3;return C(O=>C($=>wn(R,C,z,(q,Q)=>M(B(q._1,q._2,H),Q),(q,Q)=>C(U=>C(X=>{const gt=R._3&&!q._3?B(q._1,q._2,!0):q;return wp(gt,C,z,(pt,ct)=>M(B(pt._1,pt._2,H),ct),(pt,ct)=>C(ht=>W(gt._3&&!pt._3?B(pt._1,pt._2,!0):pt,ct)))})))))}),Y=j._3&&!P._3?B(P._1,P._2,!0):P;return t(R=>A(Y,t,n,r,(C,z)=>t(M=>(()=>{if(N==="<-"){const H=Ln("Token",{from:et,to:s,labels:Lt(qt.foldr,z)});return(O,$,q,Q,U)=>U(O,H)}const W=Ln("Token",{from:s,to:et,labels:Lt(qt.foldr,z)});return(H,O,$,q,Q)=>Q(H,W)})()(Y._3&&!C._3?B(C._1,C._2,!0):C,t,n,r,o))))})))})))})))})))}))),Ep=(e,t,n,r,o)=>t(i=>zr(e,t,n,r,(u,s)=>t(a=>{const c=Ce(zr),g=e._3&&!u._3?B(u._1,u._2,!0):u;return t(d=>c(g,t,n,r,(l,_)=>t(h=>{const m=vc(oi(s)+Mn(Lt(qt.foldr,_)));return(()=>{if(m.tag==="Just"){const p=m._1;return(J,N,v,L,E)=>E(J,p)}if(m.tag==="Nothing")return(p,J,N,v,L)=>L(p,0);f()})()(g._3&&!l._3?B(l._1,l._2,!0):l,t,n,r,o)})))}))),Lo=e=>(t,n,r,o,i)=>{const u=t._3;return n(s=>Xn(e)(t,n,r,(a,c)=>o(B(a._1,a._2,u),c),(a,c)=>n(g=>{const d=ji((()=>{const _=kt(Vt(m=>m==="_"))("'_'"),h=kt(Vt(m=>m==="-"))("'-'");return(m,p,J,N,v)=>{const L=m._1,E=m._2;return p(k=>To(B(L,E,!1),p,J,(S,I)=>{const F=S._3;return p(j=>{if(F)return N(S,I);const G=m._1,P=m._2;return p(et=>zr(B(G,P,!1),p,J,(K,A)=>{const Y=K._3;return p(R=>{if(Y)return N(K,A);const C=m._1,z=m._2;return p(M=>_(B(C,z,!1),p,J,(W,H)=>{const O=W._3;return p($=>O?N(W,H):h(m,p,J,N,v))},v))})},v))})},v))}})()),l=t._3&&!a._3?B(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,m)=>o(B(h._1,h._2,u),m),(h,m)=>n(p=>{const J=l._3&&!h._3?B(h._1,h._2,!0):h;return n(N=>Se(J,n,r,(v,L)=>o(B(v._1,v._2,u),L),(v,L)=>n(E=>i(J._3&&!v._3?B(v._1,v._2,!0):v,e))))})))})))},Cp=(e,t,n,r,o)=>t(i=>Me(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Lo("via")(c,t,n,r,(d,l)=>t(_=>{const h=c._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>Je(h,t,n,r,(p,J)=>t(N=>{const v=h._3&&!p._3?B(p._1,p._2,!0):p;return t(L=>Me(v,t,n,r,(E,k)=>t(S=>{const I=v._3&&!E._3?B(E._1,E._2,!0):E;return t(F=>Je(I,t,n,r,(j,G)=>t(P=>o(I._3&&!j._3?B(j._1,j._2,!0):j,{from:J,to:G}))))})))})))})))}))),On=e=>(t,n,r,o,i)=>{const u=t._3;return n(s=>Xn(e)(t,n,r,(a,c)=>o(B(a._1,a._2,u),c),(a,c)=>n(g=>{const d=ji((()=>{const _=kt(Vt(m=>m==="_"))("'_'"),h=kt(Vt(m=>m==="-"))("'-'");return(m,p,J,N,v)=>{const L=m._1,E=m._2;return p(k=>To(B(L,E,!1),p,J,(S,I)=>{const F=S._3;return p(j=>{if(F)return N(S,I);const G=m._1,P=m._2;return p(et=>zr(B(G,P,!1),p,J,(K,A)=>{const Y=K._3;return p(R=>{if(Y)return N(K,A);const C=m._1,z=m._2;return p(M=>_(B(C,z,!1),p,J,(W,H)=>{const O=W._3;return p($=>O?N(W,H):h(m,p,J,N,v))},v))})},v))})},v))}})()),l=t._3&&!a._3?B(a._1,a._2,!0):a;return n(_=>d(l,n,r,(h,m)=>o(B(h._1,h._2,u),m),(h,m)=>n(p=>i(l._3&&!h._3?B(h._1,h._2,!0):h,void 0))))})))},Sp=(e,t,n,r,o)=>t(i=>On("+edge")(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Me(c,t,n,r,(d,l)=>t(_=>{const h=kt(Je)("source node identifier"),m=c._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>h(m,t,n,r,(J,N)=>t(v=>{const L=m._3&&!J._3?B(J._1,J._2,!0):J;return t(E=>Me(L,t,n,r,(k,S)=>t(I=>{const F=kt(Je)("target node identifier"),j=L._3&&!k._3?B(k._1,k._2,!0):k;return t(G=>F(j,t,n,r,(P,et)=>t(K=>o(j._3&&!P._3?B(P._1,P._2,!0):P,Ln("AddEdge",{from:N,to:et})))))})))})))})))}))),Pp=(e,t,n,r,o)=>t(i=>On("+node")(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Me(c,t,n,r,(d,l)=>t(_=>{const h=kt(Je)("node identifier"),m=c._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>h(m,t,n,r,(J,N)=>t(v=>{const L=m._3&&!J._3?B(J._1,J._2,!0):J;return t(E=>Lp(L,t,n,r,(k,S)=>t(I=>o(L._3&&!k._3?B(k._1,k._2,!0):k,Ln("AddNode",{id:N,label:S})))))})))})))}))),Gp=(e,t,n,r,o)=>t(i=>On("-edge")(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Me(c,t,n,r,(d,l)=>t(_=>{const h=kt(Je)("source node identifier"),m=c._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>h(m,t,n,r,(J,N)=>t(v=>{const L=m._3&&!J._3?B(J._1,J._2,!0):J;return t(E=>Me(L,t,n,r,(k,S)=>t(I=>{const F=kt(Je)("target node identifier"),j=L._3&&!k._3?B(k._1,k._2,!0):k;return t(G=>F(j,t,n,r,(P,et)=>t(K=>o(j._3&&!P._3?B(P._1,P._2,!0):P,Ln("DelEdge",{from:N,to:et})))))})))})))})))}))),zp=(e,t,n,r,o)=>t(i=>On("-node")(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Me(c,t,n,r,(d,l)=>t(_=>{const h=kt(Je)("node identifier"),m=c._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>h(m,t,n,r,(J,N)=>t(v=>{const L=Ce((k,S,I,F,j)=>{const G=k._3;return Cp(k,S,I,(P,et)=>F(B(P._1,P._2,G),et),j)}),E=m._3&&!J._3?B(J._1,J._2,!0):J;return t(k=>L(E,t,n,r,(S,I)=>t(F=>o(E._3&&!S._3?B(S._1,S._2,!0):S,Ln("DelNode",{id:N,via:Lt(qt.foldr,I)})))))})))})))}))),Mp=(e,t,n,r,o)=>t(i=>On("~edge")(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>Me(c,t,n,r,(d,l)=>t(_=>{const h=kt(Je)("source node identifier"),m=c._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>h(m,t,n,r,(J,N)=>t(v=>{const L=m._3&&!J._3?B(J._1,J._2,!0):J;return t(E=>Me(L,t,n,r,(k,S)=>t(I=>{const F=kt(Je)("target node identifier"),j=L._3&&!k._3?B(k._1,k._2,!0):k;return t(G=>F(j,t,n,r,(P,et)=>t(K=>{const A=j._3&&!P._3?B(P._1,P._2,!0):P;return t(Y=>Se(A,t,n,r,(R,C)=>t(z=>{const M=kt(Xn("->"))("'->'"),W=A._3&&!R._3?B(R._1,R._2,!0):R;return t(H=>M(W,t,n,r,(O,$)=>t(q=>{const Q=W._3&&!O._3?B(O._1,O._2,!0):O;return t(U=>Se(Q,t,n,r,(X,gt)=>t(pt=>{const ct=kt(Je)("new source node identifier"),ht=Q._3&&!X._3?B(X._1,X._2,!0):X;return t(Tt=>ct(ht,t,n,r,(Gt,dt)=>t(Wt=>{const mt=ht._3&&!Gt._3?B(Gt._1,Gt._2,!0):Gt;return t(ft=>Me(mt,t,n,r,(rt,nt)=>t(st=>{const yt=kt(Je)("new target node identifier"),Jt=mt._3&&!rt._3?B(rt._1,rt._2,!0):rt;return t(Et=>yt(Jt,t,n,r,(Dt,ne)=>t($e=>o(Jt._3&&!Dt._3?B(Dt._1,Dt._2,!0):Dt,Ln("RepointEdge",{from:N,to:et,newFrom:dt,newTo:ne})))))})))})))})))})))})))})))})))})))})))}))),Wp=(e,t,n,r,o)=>t(i=>ja(e,t,n,r,(u,s)=>t(a=>{const c=kt(rc([Pp,zp,Mp,Sp,Gp,bp]))("statement (+node, -node, +edge, -edge, ~edge, or 'a -> b')"),g=e._3&&!u._3?B(u._1,u._2,!0):u;return t(d=>c(g,t,n,r,(l,_)=>t(h=>o(g._3&&!l._3?B(l._1,l._2,!0):l,Ki("Leaf",{op:_,line:s.line,column:s.column})))))}))),Rp=(e,t,n,r,o)=>t(i=>On("seed")(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>wn(c,t,n,r,(d,l)=>t(_=>{const h=kt(Ep)("integer (seed value)"),m=c._3&&!d._3?B(d._1,d._2,!0):d;return t(p=>h(m,t,n,r,(J,N)=>t(v=>{const L=m._3&&!J._3?B(J._1,J._2,!0):J;return t(E=>Se(L,t,n,r,(k,S)=>t(I=>o(L._3&&!k._3?B(k._1,k._2,!0):k,N))))})))})))}))),ru=mp((()=>{const e=kt(Vt(t=>t==="{"))("'{'");return(t,n,r,o,i)=>n(u=>n(s=>e(t,n,r,o,(a,c)=>n(g=>n(d=>{const l=t._3&&!a._3?B(a._1,a._2,!0):a;return Se(l,n,r,o,(_,h)=>n(m=>i(l._3&&!_._3?B(_._1,_._2,!0):_,h)))})))))})())(kt((()=>{const e=kt(Vt(t=>t==="}"))("'}'");return(t,n,r,o,i)=>n(u=>n(s=>Se(t,n,r,o,(a,c)=>n(g=>n(d=>{const l=t._3&&!a._3?B(a._1,a._2,!0):a;return e(l,n,r,o,(_,h)=>n(m=>i(l._3&&!_._3?B(_._1,_._2,!0):_,h)))})))))})())("closing '}'")),Qp=(e,t,n,r,o)=>t(i=>Lo("seq")(e,t,n,r,(u,s)=>t(a=>ru(ou(Oa))(e._3&&!u._3?B(u._1,u._2,!0):u,t,n,r,o)))),Ip=(e,t,n,r,o)=>t(i=>Lo("par")(e,t,n,r,(u,s)=>t(a=>ru(ou(Yh))(e._3&&!u._3?B(u._1,u._2,!0):u,t,n,r,o)))),ou=e=>{const t=Ce(Bp());return(n,r,o,i,u)=>r(s=>t(n,r,o,i,(a,c)=>r(g=>u(n._3&&!a._3?B(a._1,a._2,!0):a,e(Lt(qt.foldr,c))))))},Bp=cc(()=>{const e=ji(kt(Vt(t=>t==="}"))("'}'"));return(t,n,r,o,i)=>n(u=>{const s=t._3;return n(a=>n(c=>Se(t,n,r,(g,d)=>o(B(g._1,g._2,s),d),(g,d)=>n(l=>n(_=>{const h=t._3&&!g._3?B(g._1,g._2,!0):g;return e(h,n,r,(m,p)=>o(B(m._1,m._2,s),p),(m,p)=>n(J=>{const N=h._3&&!m._3?B(m._1,m._2,!0):m;return n(v=>{const L=rc([(k,S,I,F,j)=>{const G=k._3;return Ip(k,S,I,(P,et)=>F(B(P._1,P._2,G),et),j)},(k,S,I,F,j)=>{const G=k._3;return Qp(k,S,I,(P,et)=>F(B(P._1,P._2,G),et),j)},Wp]),E=t._3&&!N._3?B(N._1,N._2,!0):N;return n(k=>L(E,n,r,o,(S,I)=>n(F=>{const j=E._3&&!S._3?B(S._1,S._2,!0):S;return n(G=>wn(j,n,r,o,(P,et)=>n(K=>{const A=j._3&&!P._3?B(P._1,P._2,!0):P;return n(Y=>xp(A,n,r,o,(R,C)=>n(z=>i(A._3&&!R._3?B(R._1,R._2,!0):R,I))))})))})))})}))})))))})}),Ap=(e,t,n,r,o)=>t(i=>Lo("frame")(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>kp(c,t,n,r,(d,l)=>t(_=>{const h=c._3&&!d._3?B(d._1,d._2,!0):d;return t(m=>Se(h,t,n,r,(p,J)=>t(N=>{const v=ru(ou(Oa)),L=h._3&&!p._3?B(p._1,p._2,!0):p;return t(E=>v(L,t,n,r,(k,S)=>t(I=>{const F=L._3&&!k._3?B(k._1,k._2,!0):k;return t(j=>Se(F,t,n,r,(G,P)=>t(et=>o(F._3&&!G._3?B(G._1,G._2,!0):G,{name:b("Just",l),ops:S}))))})))})))})))}))),Dp=(e,t,n,r,o)=>t(i=>Se(e,t,n,r,(u,s)=>t(a=>{const c=e._3&&!u._3?B(u._1,u._2,!0):u;return t(g=>{const d=(h,m)=>t(p=>{const J=Ce(Ap),N=c._3&&!h._3?B(h._1,h._2,!0):h;return t(v=>J(N,t,n,r,(L,E)=>t(k=>{const S=N._3&&!L._3?B(L._1,L._2,!0):L;return t(I=>Se(S,t,n,r,(F,j)=>t(G=>{const P=kt(nc)("'frame' or end of input"),et=S._3&&!F._3?B(F._1,F._2,!0):F;return t(K=>P(et,t,n,r,(A,Y)=>t(R=>o(et._3&&!A._3?B(A._1,A._2,!0):A,{seed:(()=>{if(m.tag==="Just")return m._1;if(m.tag==="Nothing")return 0;f()})(),frames:Lt(qt.foldr,E)}))))})))})))}),l=c._1,_=c._2;return t(h=>t(m=>Rp(B(l,_,!1),t,n,(p,J)=>{const N=p._3;return t(v=>N?r(p,J):d(c,T))},(p,J)=>t(N=>d(p,b("Just",J))))))})}))),qp=e=>{const t=gp(e)(Dp);if(t.tag==="Left")return wt("Left",{msg:t._1._1,line:t._1._2.line,column:t._1._2.column});if(t.tag==="Right")return wt("Right",t._1);f()},Yp=e=>{const t=qp(e);if(t.tag==="Left")return wt("Left",t._1.msg);if(t.tag==="Right")return wt("Right",t._1);f()};function iu(e,t,n,r){if(typeof window<"u"){var o=window[n];if(o!=null&&r instanceof o)return t(r)}for(var i=r;i!=null;){var u=Object.getPrototypeOf(i),s=u.constructor.name;if(s===n)return t(r);if(s==="Object")return e;i=u}return e}function uu(e){return function(t){return function(n){return function(){n.setAttribute(e,t)}}}}function $p(e){return function(t){return function(){t.textContent=e}}}function Fp(e){return function(){return function(t){return e(t)()}}}function Hp(e){return function(t){return function(n){return function(r){return function(){return r.addEventListener(e,t,n)}}}}}const Vp=function(){return window};function Xp(e){return function(t){return function(){t.value=e}}}function Op(e){return function(){return e.valueAsNumber}}function Up(e){return function(){return e.value}}function Kp(e){return function(t){return function(){return t.requestAnimationFrame(e)}}}const Zp=e=>e,jp=e=>()=>e.clientWidth||0,tm=()=>window.devicePixelRatio||1,uc=(e,t)=>{t.innerHTML=e},em=(e,t,n)=>{e.style.setProperty(t,n)},nm=(e,t)=>e.querySelector(`[data-mg="${t}"]`),rm=It.foldMap(zc),om=e=>t=>{const n=lt.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;f()},im=e=>t=>{const n=e-t*_t(tr(mu(e/t)));return t<=0?0:n<0?n+t:n},um=`
1
+ var Vm=(function(Ao){"use strict";function Rc(e){let t=0,n;return()=>{if(t===2)return n;if(t===1)throw new Error("Binding demanded before initialized");return t=1,n=e(),t=2,n}}function c(){throw new Error("Failed pattern match")}function Rn(e,t){return t>0?Math.floor(e/t):t<0?-Math.floor(e/-t):0}const me=e=>t=>e,V=function(e){return function(t){for(var n=t.length,r=new Array(n),i=0;i<n;i++)r[i]=e(t[i]);return r}},Ic={map:V},Nu=e=>e,St=typeof Array.prototype.flatMap=="function"?function(e){return function(t){return e.flatMap(t)}}:function(e){return function(t){for(var n=[],r=e.length,i=0;i<r;i++)for(var o=t(e[i]),u=o.length,s=0;s<u;s++)n.push(o[s]);return n}},ue=function(e){return e.toString()},xu=function(e){var t=e.toString();return isNaN(t+".0")?t:t+".0"},Dc=function(e){var t=e.length;return'"'+e.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<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
+ `)(" "),t=cn(`
4
+ `)(" "),n=(()=>{const r=cn("\r")(" "),i=(()=>{const o=cn(" ")(" ");return u=>o(r(u))})();return o=>i(t(o))})();return r=>n(e(r))})(),vr=e=>t=>{const n=ot.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},E1=e=>t=>{const n=ot.compare(e)(t);if(n==="LT"||n==="EQ")return e;if(n==="GT")return t;c()},C1=e=>t=>{const n=lt.compare(e)(t);if(n==="LT")return t;if(n==="EQ"||n==="GT")return e;c()},S1=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},Ss=e=>zn(le(pn(t=>t===" ")(le(pn(t=>t===" ")(Uu(e)).rest)).rest)),P1=e=>y(t=>n=>n._1>0&&(n._2===" "||n._2==="-"||n._2==="_"||n._2===".")?E("Just",n._1):t)(T)(Dt(In)(e)),Mi=e=>t=>{if(e<=0)return[t];if(Jn(t)<=e)return[t];const n=Uu(t),r=e<1?[]:Gt(0,e,n),i=P1(r);if(i.tag==="Just"){const o=Ss(Ku(!(i._1>=0&&i._1<r.length)||r[i._1]===" "?i._1:i._1+1|0)(t)),u=Ss(mr(i._1+1|0)(t));return u===""?[o]:[o,...Mi(e)(u)]}if(i.tag==="Nothing"){const o=Ku(e)(t),u=mr(e)(t);return u===""?[o]:[o,...Mi(e)(u)]}c()},R1={cellW:7,cellH:3,maxLineWidth:20},I1=e=>t=>{const n=V(o=>x((()=>{if(o.label.tag==="Just")return o.label._1;if(o.label.tag==="Nothing")return o.id;c()})(),o))(t.nodes),r=vr(1)(Rn((E1(e.maxLineWidth)(y(o=>u=>vr(o)(Jn(u._1)))(0)(n))+2|0)+e.cellW|0,e.cellW)),i=(r*e.cellW|0)-1|0;return{...t,nodes:V(o=>{if(!(o._2.size._1===1&&o._2.size._2===1))return o._2;const u=St(vi(`
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
+ `)(e);return t.length===0?[""]:t},nu=e=>t=>{const n=je(e)(je(t.w/2)(t.h/2));return{...t,x:t.x+n,y:t.y+n,w:t.w-2*n,h:t.h-2*n}},Nh=e=>{const t=e.Monad0(),n=t.Applicative0(),r=t.Bind1(),i=en(n),o=e.popTransform,u=e.popAlpha;return s=>a=>f=>{const g=vi(`
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("&")("&amp;"),t=cn("<")("&lt;"),n=(()=>{const r=cn(">")("&gt;"),i=(()=>{const o=cn('"')("&quot;");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
+ `||t==="\r");return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>o(t._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),fu=(e,t,n,r,i)=>t(o=>jn("#")(e,t,n,r,(u,s)=>t(a=>{const f=Pe(Ot(d=>d!==`
9
+ `)),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,void 0))))}))),Yp=Lt((()=>{const e=Lt(Ot(n=>n==="}"))("'}'"),t=Ot(n=>n===`
10
+ `||n==="\r");return(n,r,i,o,u)=>{const s=n._1,a=n._2;return r(f=>r(g=>e(z(s,a,!1),r,i,(d,l)=>r(_=>{const h=n._1,p=n._2;return r(m=>r(N=>fu(z(h,p,!1),r,i,(J,v)=>{const w=J._3;return r(L=>{if(w)return o(J,v);const b=n._1,S=n._2;return r(A=>r(O=>t(z(b,S,!1),r,i,(j,R)=>{const P=j._3;return r(et=>P?o(j,R):bc(n,r,i,o,u))},(j,R)=>r(P=>u(j,void 0)))))})},(J,v)=>r(w=>u(J,void 0)))))}),(d,l)=>r(_=>u(z(s,a,!1),void 0)))))}})())("newline or '}' (statements end at the end of the line)"),Re=(()=>{const e=Pe((t,n,r,i,o)=>{const u=t._1,s=t._2;return n(a=>Lc(z(u,s,!1),n,r,(f,g)=>{const d=f._3;return n(l=>d?i(f,g):fu(t,n,r,i,o))},o))});return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>o(t._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),Me=(e,t,n,r,i)=>t(o=>{const u=(f,g)=>t(d=>Re(e._3&&!f._3?z(f._1,f._2,!0):f,t,n,r,i)),s=e._1,a=e._2;return t(f=>Lc(z(s,a,!1),t,n,(g,d)=>{const l=g._3;return t(_=>l?r(g,d):fu(e,t,n,r,u))},u))}),Ec=(()=>{const e=Lt(Ot(t=>t==="|"))("'|'");return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>{const g=Pe(Ot(l=>l!=="|")),d=t._3&&!s._3?z(s._1,s._2,!0):s;return n(l=>g(d,n,r,i,(_,h)=>n(p=>{const m=Lt(Lt(Ot(J=>J==="|"))("'|'"))("closing '|'"),N=d._3&&!_._3?z(_._1,_._2,!0):_;return n(J=>m(N,n,r,i,(v,w)=>n(L=>o(N._3&&!v._3?z(v._1,v._2,!0):v,zn(bt(Yt.foldr,h))))))})))})))})(),Do=Ot(e=>e>="a"&&e<="z"||e>="A"&&e<="Z"),Cn=(()=>{const e=Pe(Ot(t=>t===" "||t===" "));return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>o(t._3&&!s._3?z(s._1,s._2,!0):s,void 0))))})(),Vp=(()=>{const e=Lt(Ot(t=>t==="\\"))("'\\\\'");return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>{const g=t._3&&!s._3?z(s._1,s._2,!0):s;return n(d=>Hp(g,n,r,i,(l,_)=>n(h=>o(g._3&&!l._3?z(l._1,l._2,!0):l,_==="n"?`
11
+ `:_==="t"?" ":_==="r"?"\r":_))))})))})(),Op=(()=>{const e=Ot(t=>t!=='"'&&t!=="\\"&&t!==`
12
+ `);return(t,n,r,i,o)=>{const u=t._1,s=t._2;return n(a=>Vp(z(u,s,!1),n,r,(f,g)=>n(d=>e(t,n,r,i,o)),o))}})(),gu=(()=>{const e=Lt(Ot(t=>t==='"'))(`'"'`);return(t,n,r,i,o)=>n(u=>e(t,n,r,i,(s,a)=>n(f=>{const g=Pe(Op),d=t._3&&!s._3?z(s._1,s._2,!0):s;return n(l=>g(d,n,r,i,(_,h)=>n(p=>{const m=Lt(Lt(Ot(J=>J==='"'))(`'"'`))(`closing '"' (unterminated string)`),N=d._3&&!_._3?z(_._1,_._2,!0):_;return n(J=>m(N,n,r,i,(v,w)=>n(L=>o(N._3&&!v._3?z(v._1,v._2,!0):v,zn(bt(Yt.foldr,h))))))})))})))})(),Fp=(()=>{const e=Lt(Ot(t=>t===":"))("':'");return(t,n,r,i,o)=>n(u=>Cn(t,n,r,i,(s,a)=>n(f=>Lt((g,d,l,_,h)=>{const p=g._1,m=g._2;return d(N=>{const J=(v,w)=>{const L=v._3;return d(b=>{if(L)return _(v,w);const S=g._1,A=g._2;return d(O=>Ec(z(S,A,!1),d,l,(j,R)=>{const P=j._3;return d(et=>P?_(j,R):gu(g,d,l,_,h))},h))})};return d(v=>e(z(p,m,!1),d,l,J,(w,L)=>d(b=>d(S=>Cn(w,d,l,J,(A,O)=>d(j=>{const R=Pe(Ot(et=>et!==`
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=`
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 mm=(function(ko){"use strict";function cc(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
- `,en=e=>t=>n=>()=>{const r=nm(e,t),o=Mc(r,T,Kt);if(o.tag==="Just")return n(o._1)();o.tag!=="Nothing"&&f()},sm=e=>t=>{const n=t.totalDuration<=0?1:t.totalDuration,r=rm(o=>'<span class="mg-tick" style="left:'+Ao(Io("Fixed",Bo(0)(20)(2)))(100*o.startT/n)+'%" data-label="'+(()=>{if(o.scene.tag==="Structural")return o.scene._1.to;if(o.scene.tag==="DataFlow")return o.scene._1.keyframe;f()})()+'"></span>')(t.spans);return en(e)("ticks")(o=>()=>uc(r,o))},am=e=>t=>n=>en(e)("scrub")(r=>{const o=iu(T,Kt,"HTMLInputElement",r);if(o.tag==="Nothing")return()=>{};if(o.tag==="Just")return n<=0?()=>{}:Xp(Te(tr(yu(t/n*1e3))))(o._1);f()}),su=e=>t=>n=>{const r=Fp(o=>n);return()=>{const o=r();return Hp(e)(o)(!1)(t)()}},au=e=>t=>n=>r=>o=>{const i=om(o)(t.totalDuration),u=i1(t)(i);return()=>{const s=Tu(),a=r.value;return r.value=s,en(e)("stage")(c=>{const g=t.layout,d=Zp(c),l=ju(g)(u.camera),_=l.w+48,h=l.h+48,m=jp(c);return()=>{const p=m(),J=_<=0?p:p*h/_,N=tm(),v=p*N,L=J*N,E=Fc(d)(),k=Hc(d)(),S=Vc(d)(v);E!==v&&S();const I=Xc(d)(L);k!==L&&I(),em(c,"height",Te(tr(yu(J)))+"px");const F=$c(d)();rr(F)(),Ho(F)({scaleX:N,scaleY:N})();const j=n.value,G=Rh(F)({width:p,height:J})(g)(u)(a===0?0:(s-a)/1e3)(j)();return n.value=G,or(F)()}})(),en(e)("time")(c=>$p(Ao(Io("Fixed",Bo(0)(20)(2)))(i)+" / "+Ao(Io("Fixed",Bo(0)(20)(2)))(t.totalDuration))(c))()}},cm=e=>{const t=Yp(e);if(t.tag==="Left")return wt("Left",t._1);if(t.tag==="Right"){const n=ip(t._1);if(n.tag==="Left")return wt("Left",n._1.msg);if(n.tag==="Right")return wt("Right",n._1)}f()},fm=e=>t=>en(e)("speed")(n=>{const r=iu(T,Kt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return su("change")(n)((()=>{const o=Up(r._1);return()=>{const i=o(),u=Jc(i,lu,Kt,T);if(u.tag==="Just")return t.value=u._1;u.tag!=="Nothing"&&f()}})());f()}),gm=e=>t=>n=>r=>o=>i=>en(e)("scrub")(u=>{const s=iu(T,Kt,"HTMLInputElement",u);if(s.tag==="Nothing")return()=>{};if(s.tag==="Just")return su("input")(u)((()=>{const a=Op(s._1);return()=>{const c=a()/1e3*i.totalDuration;return n.value=!1,t.value=c,au(e)(i)(r)(o)(c)(),en(e)("play")(g=>uu("data-mg-playing")("0")(g))()}})());f()}),_m=e=>t=>n=>en(e)("play")(r=>su("click")(r)(()=>{const o=!t.value;if(t.value=o,uu("data-mg-playing")(o?"1":"0")(r)(),o)return n()})),dm=e=>t=>()=>{const n={value:1},r={value:!0};let o=!1;const i={value:0};let u=0;const s={value:D},a={value:0};sm(e)(t)(),au(e)(t)(s)(a)(0)(),en(e)("play")(l=>uu("data-mg-playing")("1")(l))();const c=()=>{if(o=!1,r.value){const l=Tu(),_=u;u=l;const h=n.value,m=i.value,p=im(_===0?m+0*h:m+(l-_)/1e3*h)(t.totalDuration+.8);return i.value=p,au(e)(t)(s)(a)(p)(),am(e)(p)(t.totalDuration)(),g()}},g=()=>{if(!o){o=!0;const l=Vp();Kp(c)(l)()}},d=()=>(u=0,g());return fm(e)(n)(),_m(e)(r)(d)(),gm(e)(i)(r)(s)(a)(t)(),d()},sc=e=>t=>{const n=cm(t);if(n.tag==="Left")return vu("[markgraf] parse failed: "+n._1);if(n.tag==="Right"){const r=n._1;return()=>{uc(um,e);const o=t0(r)(),i=G_(L_)(r)(i0(o)(r));if(i.tag==="Left")return vu("[markgraf] precompute failed")();if(i.tag==="Right")return dm(e)(i._1)();f()}}f()},lm=e=>{const t=e.getAttribute("data-markgraf-src-b64");if(t)try{return decodeURIComponent(escape(atob(t)))}catch{return atob(t)}return e.getAttribute("data-markgraf-src")||e.textContent||""};let Ye=null;const cu=e=>e.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",hm=e=>{const t=e.querySelector('[data-mg="play"]');if(!t)return;t.addEventListener("click",()=>{queueMicrotask(()=>{cu(e)?(Ye&&Ye!==e&&cu(Ye)&&Ye.querySelector('[data-mg="play"]').click(),Ye=e):Ye===e&&(Ye=null)})});const n=r=>{r.preventDefault(),t.click()};e.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},pm=e=>{if(e.dataset.markgrafMounted==="1")return;e.dataset.markgrafMounted="1";const t=lm(e);e.textContent="",sc(e)(t)(),Ye===null?Ye=e:cu(e)&&e.querySelector('[data-mg="play"]').click(),hm(e)},wo=(e=document)=>{e.querySelectorAll("[data-markgraf]").forEach(pm)},ac=()=>{document.addEventListener("keydown",e=>{if(e.code!=="Space"&&e.key!==" ")return;const t=e.target,n=t&&t.closest?.("[data-markgraf]");if(!n){const o=t?.tagName,i=(t?.type||"").toLowerCase();if(t?.isContentEditable||o==="TEXTAREA"||o==="SELECT"||o==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(i))return}const r=n||Ye||document.querySelector("[data-markgraf]");r&&(e.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};return typeof window<"u"&&(window.markgraf={mount:(e,t)=>sc(e)(t)(),mountAll:wo},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{wo(),ac()}):(wo(),ac())),ko.mountAll=wo,Object.defineProperty(ko,Symbol.toStringTag,{value:"Module"}),ko})({});
30
+ `,rn=e=>t=>n=>()=>{const r=km(e,t),i=Df(r,T,Xt);if(i.tag==="Just")return n(i._1)();i.tag!=="Nothing"&&c()},Mm=e=>t=>{const n=t.totalDuration<=0?1:t.totalDuration,r=Cm(i=>'<span class="mg-tick" style="left:'+_r(fr("Fixed",gr(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>')(t.spans);return rn(e)("ticks")(i=>()=>hu(r,i))},Wm=e=>t=>n=>rn(e)("scrub")(r=>{const i=lu(T,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return n<=0?()=>{}:ym(ue(ur(Mu(t/n*1e3))))(i._1);c()}),pu=e=>t=>n=>{const r=hm(i=>n);return()=>{const i=r();return pm(e)(i)(!1)(t)()}},mu=e=>t=>n=>r=>i=>o=>{const u=b1(n)(Cc(o)(n.totalDuration));if(t==="CanvasRenderer")return()=>{const s=$u(),a=i.value;i.value=s;const f=vm(e),g=fs(n.layout)(u.camera),d=g.w+48,l=g.h+48,_=Tm(e)(),h=d<=0?_:_*l/d,p=wm(),m=_*p,N=h*p,J=zf(f)(),v=Bf(f)(),w=$f(f)(m);J!==m&&w();const L=Qf(f)(N);v!==N&&L(),bm(e,"height",ue(ur(Mu(h)))+"px");const b=Af(f)();dr(b)(),ti(b)({scaleX:p,scaleY:p})();const S=r.value,A=Oh(b)({width:_,height:h})(n.layout)(u)(a===0?0:(s-a)/1e3)(S)();return r.value=A,lr(b)()};if(t==="SvgRenderer"){const s=op(n.layout)(u),a=Mo("viewBox")(s.viewBox)(e);return()=>(a(),Mo("preserveAspectRatio")("xMidYMid meet")(e)(),hu(s.body,e))}c()},Am=e=>{const t=dm(e);if(t.tag==="Left")return kt("Left",t._1);if(t.tag==="Right"){const n=Cp(t._1);if(n.tag==="Left")return kt("Left",n._1.msg);if(n.tag==="Right")return kt("Right",n._1)}c()},yu=e=>t=>{const n=ge(r=>r.startT<=t&&t<r.endT)(e.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=e.spans.length-1|0;if(r>=0&&r<e.spans.length){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()}return""}c()},zm=e=>t=>rn(e)("speed")(n=>{const r=lu(T,Xt,"HTMLSelectElement",n);if(r.tag==="Nothing")return()=>{};if(r.tag==="Just")return pu("change")(n)((()=>{const i=Nm(r._1);return()=>{const o=i(),u=Nf(o,Ru,Xt,T);if(u.tag==="Just")return t(u._1)();u.tag!=="Nothing"&&c()}})());c()}),Bm=e=>t=>n=>rn(e)("scrub")(r=>{const i=lu(T,Xt,"HTMLInputElement",r);if(i.tag==="Nothing")return()=>{};if(i.tag==="Just")return pu("input")(r)((()=>{const o=Jm(i._1);return()=>{const u=o();return n.pause(),n.seek(u/1e3*t.totalDuration)()}})());c()}),$m=e=>t=>n=>{const r=Mm(e)(t);return()=>{r(),rn(e)("play")(i=>Mo("data-mg-playing")("1")(i))(),zm(e)(n.setSpeed)(),rn(e)("play")(i=>pu("click")(i)(n.toggle))(),Bm(e)(t)(n)(),n.subscribe(i=>{const o=Wm(e)(i.time)(t.totalDuration);return()=>(o(),rn(e)("time")(u=>lm(_r(fr("Fixed",gr(0)(20)(2)))(i.time)+" / "+_r(fr("Fixed",gr(0)(20)(2)))(t.totalDuration))(u))(),rn(e)("play")(u=>Mo("data-mg-playing")(i.playing?"1":"0")(u))())})()}},Qm=e=>t=>n=>()=>{let r=1,i=!0,o=!1,u=0,s=0;const a={value:$},f={value:0};let g=!1,d=[];mu(e)(n)(t)(a)(f)(0)();const l=J=>()=>{const v=d,w=i,L={time:J,keyframe:yu(t)(J),playing:w};return Dm(b=>b(L))(v)()},_=()=>(i=!1,l(u)()),h=()=>{if(!g&&(o=!1,i)){const J=$u(),v=s;s=J;const w=r,L=u,b=Rm(v===0?L+0*w:L+(J-v)/1e3*w)(t.totalDuration+.8);return u=b,mu(e)(n)(t)(a)(f)(b)(),l(b)(),p()}},p=()=>{if(!g&&!o){o=!0;const J=mm();xm(h)(J)()}},m=()=>(s=0,i=!0,p()),N=()=>(i||m(),l(u)());return m(),{play:N,pause:_,toggle:()=>i?_():N(),seek:J=>{const v=Sm(0)(Cc(t.totalDuration)(J));return()=>(u=v,s=0,mu(e)(n)(t)(a)(f)(v)(),l(v)())},setSpeed:J=>()=>r=J,currentTime:()=>u,currentKeyframe:()=>{const J=u;return yu(t)(J)},isPlaying:()=>i,duration:t.totalDuration,subscribe:J=>()=>{d=de(d)(J);const v=u,w=i;J({time:v,keyframe:yu(t)(v),playing:w})();const L=Su(b=>!Lm(b)(J));return()=>{d=L(d)}},destroy:()=>g=!0}},Sc=e=>t=>{const n=Am(t);if(n.tag==="Left")return Bu("[markgraf] parse failed: "+n._1);if(n.tag==="Right")return Im(n._1)(r=>()=>(hu(Gm,e),rn(e)("stage")(i=>{const o=Qm(i)(r)(Pm);return()=>{const u=o();return $m(e)(r)(u)()}})()));c()},qm=e=>{const t=e.getAttribute("data-markgraf-src-b64");if(t)try{return decodeURIComponent(escape(atob(t)))}catch{return atob(t)}return e.getAttribute("data-markgraf-src")||e.textContent||""};let Ye=null;const Ju=e=>e.querySelector('[data-mg="play"]')?.dataset.mgPlaying==="1",Hm=e=>{const t=e.querySelector('[data-mg="play"]');if(!t)return;t.addEventListener("click",()=>{queueMicrotask(()=>{Ju(e)?(Ye&&Ye!==e&&Ju(Ye)&&Ye.querySelector('[data-mg="play"]').click(),Ye=e):Ye===e&&(Ye=null)})});const n=r=>{r.preventDefault(),t.click()};e.querySelector('[data-mg="stage"]')?.addEventListener("click",n)},Ym=e=>{if(e.dataset.markgrafMounted==="1")return;e.dataset.markgrafMounted="1";const t=qm(e);e.textContent="",Sc(e)(t)(),Ye===null?Ye=e:Ju(e)&&e.querySelector('[data-mg="play"]').click(),Hm(e)},Wo=(e=document)=>{e.querySelectorAll("[data-markgraf]").forEach(Ym)},Pc=()=>{document.addEventListener("keydown",e=>{if(e.code!=="Space"&&e.key!==" ")return;const t=e.target,n=t&&t.closest?.("[data-markgraf]");if(!n){const i=t?.tagName,o=(t?.type||"").toLowerCase();if(t?.isContentEditable||i==="TEXTAREA"||i==="SELECT"||i==="INPUT"&&!["range","checkbox","radio","button","submit","reset"].includes(o))return}const r=n||Ye||document.querySelector("[data-markgraf]");r&&(e.preventDefault(),r.querySelector('[data-mg="play"]')?.click())})};return typeof window<"u"&&(window.markgraf={mount:(e,t)=>Sc(e)(t)(),mountAll:Wo},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Wo(),Pc()}):(Wo(),Pc())),Ao.mountAll=Wo,Object.defineProperty(Ao,Symbol.toStringTag,{value:"Module"}),Ao})({});